@camstack/addon-admin-ui 1.1.36 → 1.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddLocationWizard-fU39g28j.js → AddLocationWizard-RRlx3cRe.js} +1 -1
- package/dist/assets/{AddonCollectionPage-2R4sBcnH.js → AddonCollectionPage-CWvsH8SQ.js} +1 -1
- package/dist/assets/{Addons-OPXB9gcH.js → Addons-CAzgXiLH.js} +1 -1
- package/dist/assets/{AdminTabs-DZ8fjA_E.js → AdminTabs-CiYcSYbj.js} +1 -1
- package/dist/assets/{BrokerForm-DxBh4Ab_.js → BrokerForm-B9Pyef82.js} +1 -1
- package/dist/assets/{Capabilities-BowvKc7g.js → Capabilities-DLYbrJz4.js} +1 -1
- package/dist/assets/{CapabilityBadges-Cb2taM1G.js → CapabilityBadges-DgQBa83l.js} +1 -1
- package/dist/assets/Cluster-DTY2DUrV.js +1 -0
- package/dist/assets/{Dashboard-DwJvs0Hh.js → Dashboard-BB_7zhcP.js} +1 -1
- package/dist/assets/{Data-zUHS7p4f.js → Data-D56cbbtl.js} +1 -1
- package/dist/assets/{DetectionIntelligence-BneZGPL8.js → DetectionIntelligence-CvHAORbN.js} +1 -1
- package/dist/assets/DeviceDetail-WSoEsPnD.js +2 -0
- package/dist/assets/{Devices-BPv3cLJV.js → Devices-K_L5xpp2.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-B-sPclrx.js → EmbedPlayerPage-Br4TfZLq.js} +1 -1
- package/dist/assets/{FormBuilder-BHrYFTqO.js → FormBuilder-inLQWViM.js} +1 -1
- package/dist/assets/Identity-CUzVP34n.js +1 -0
- package/dist/assets/{IntegrationDetail-CASAMzWi.js → IntegrationDetail-ogpWJl32.js} +1 -1
- package/dist/assets/{Integrations-CFNCpTGQ.js → Integrations-CFtirtyU.js} +1 -1
- package/dist/assets/{Integrations-BK8yyBnE.js → Integrations-CJV1Uy9R.js} +1 -1
- package/dist/assets/{Logs-B1uh5BYK.js → Logs-CQf1pQ47.js} +1 -1
- package/dist/assets/{MyAccess-Brl1MiDm.js → MyAccess-Cn7kN9Oc.js} +1 -1
- package/dist/assets/{Network-CcZYSjnr.js → Network-Cb5KR0mO.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-DTTq6Ljf.js → NodeAddonsSettingsPanel-Cpl4rjtk.js} +1 -1
- package/dist/assets/{NotificationTargets-Bji4H-RC.js → NotificationTargets-BOs4Ypzw.js} +1 -1
- package/dist/assets/Pipeline-Bsjgzu7B.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-CKAT3JFX.js → PrivacyMaskSettings-aLsRsfB3.js} +1 -1
- package/dist/assets/{ProviderIcon-KQShdlru.js → ProviderIcon-x3ks3Cgc.js} +1 -1
- package/dist/assets/{ScanNetworkModal-mQF_it2k.js → ScanNetworkModal-DrMPFU3B.js} +1 -1
- package/dist/assets/{Settings-Bq1sSX7Z.js → Settings-DnOYBfde.js} +1 -1
- package/dist/assets/{Showroom-inuhv53W.js → Showroom-v8sUA896.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BAi3eQvB.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DjSJzFMJ.js} +1 -1
- package/dist/assets/{build-cluster-graph-DlOB4sV_.js → build-cluster-graph-DIEEuf36.js} +2 -2
- package/dist/assets/circle-check-big-CLMjysyy.js +1 -0
- package/dist/assets/{copy-C3o1fFh1.js → copy-BRliESit.js} +1 -1
- package/dist/assets/{download-D2Hdt3_T.js → download-BuixOtcX.js} +1 -1
- package/dist/assets/{hostInit-BKnQjzgs.js → hostInit-BWL1MjJX.js} +1 -1
- package/dist/assets/index-CdAVDEco.js +4 -0
- package/dist/assets/{index-DO0772OA.css → index-DC5LZGUt.css} +1 -1
- package/dist/assets/{key-round-Jz1W_Dm_.js → key-round-DovZ-dE_.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-b853eab9.js → mf-entry-bootstrap-0-145aa705.js} +2 -2
- package/dist/assets/{pencil-CFG04wDY.js → pencil-D2v4UbT5.js} +1 -1
- package/dist/assets/plus-DMWGd7B0.js +1 -0
- package/dist/assets/{radio-Bvao3n8m.js → radio-BXRkVjee.js} +1 -1
- package/dist/assets/{refresh-cw-B3eKxMWT.js → refresh-cw-B_eIWqpa.js} +1 -1
- package/dist/assets/remoteEntry-Ccem7OUi.js +1 -0
- package/dist/assets/{rotate-ccw-g29vnwke.js → rotate-ccw-BWUd8OlD.js} +1 -1
- package/dist/assets/rotate-cw-BNKHRv84.js +1 -0
- package/dist/assets/search-DNeYxEqb.js +1 -0
- package/dist/assets/{server-BrIBBG6H.js → server-CcpmRIQF.js} +1 -1
- package/dist/assets/{sparkles-ARuuvyj1.js → sparkles-Bs3uod4E.js} +1 -1
- package/dist/assets/square-BelYTwAy.js +1 -0
- package/dist/assets/{square-check-big-piMyzaVk.js → square-check-big-O_vP3vWT.js} +1 -1
- package/dist/assets/{src-Dp6qXTLR.js → src-cK1rmJgB.js} +4 -4
- package/dist/assets/{upload-CZGhOSU5.js → upload-CW3eN_Z6.js} +1 -1
- package/dist/assets/{useDevice-D09Wge-X.js → useDevice-CNqajtmH.js} +1 -1
- package/dist/assets/{useEventInvalidation-NEk-4cPL.js → useEventInvalidation-ycuHWtpd.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-rJ2O9jZ3.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BIUGfAw_.js} +2 -2
- package/dist/assets/{wifi-CyY3elJf.js → wifi-Yyiz1n_M.js} +1 -1
- package/dist/assets/{zap-l_Zh2jBY.js → zap-GMWRUOGp.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/Cluster-Dvu3Qmr3.js +0 -1
- package/dist/assets/DeviceDetail-D55afT28.js +0 -2
- package/dist/assets/Identity-4N-nfSAK.js +0 -1
- package/dist/assets/Pipeline-Bj4liIat.js +0 -1
- package/dist/assets/circle-check-big-Bcoiv1yk.js +0 -1
- package/dist/assets/index-CpCNvkGK.js +0 -4
- package/dist/assets/plus-Bc_u_j_c.js +0 -1
- package/dist/assets/remoteEntry-xYIBqMy5.js +0 -1
- package/dist/assets/rotate-cw-B3yeEqVR.js +0 -1
- package/dist/assets/search-ChyM3D_C.js +0 -1
- package/dist/assets/square-BM303wp_.js +0 -1
package/dist/assets/{NodeAddonsSettingsPanel-DTTq6Ljf.js → NodeAddonsSettingsPanel-Cpl4rjtk.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Ft as e,Wr as t,at as n,mt as r,nn as i,ot as a}from"./src-
|
|
1
|
+
import{Ft as e,Wr as t,at as n,mt as r,nn as i,ot as a}from"./src-cK1rmJgB.js";import{H as o,I as s,K as c,Q as l,S as u,W as d,i as f,k as p,o as m,p as h,q as g,t as _,x as v,z as y}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{I as b}from"./src-BXL7z3gT.js";import{p as ee}from"./player-overlays-CpsGl45o.js";import{n as te,r as x,t as ne}from"./SchemaTabBar-DhsmEGyn.js";import{t as S}from"./FormBuilder-inLQWViM.js";l();var C=p(function({addonId:e,schema:t,serverValues:n,onImmediateSave:r,onStateChange:i,onAction:a,disabled:l},u){let f=x({schema:t,serverValues:n,onImmediateSave:s(t=>r(e,t),[e,r]),onDeferredSave:s(()=>{},[])});o(u,()=>({flush:()=>{let e={};for(let t of f.pendingKeys)e[t]=f.values[t];return f.handleDiscard(f.pendingKeys),e},discard:()=>f.resetAll()}),[f]);let p=f.pendingKeys,m=p.join(`|`),h=d(()=>p.map(e=>`${e}=${JSON.stringify(f.values[e])}`).join(`,`),[p,f.values]),g=c(i);y(()=>{g.current=i},[i]),y(()=>{let t={};for(let e of p)t[e]=f.values[e];g.current({addonId:e,pendingKeys:p,pendingValues:t})},[e,m,h]);let _=d(()=>{if(a)return(t,n,r)=>a(e,t,n,r)},[e,a]);return v(S,{schema:t,values:f.values,onChange:f.handleChange,disabled:l,onAction:_})});l();function w(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>w(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function T(e,t){return{...e,fields:e.fields.map(e=>w(e,t))}}function re(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>T(e,t))},values:t}}function E({nodeId:o,addonIds:l,level:p,deviceId:y,capability:x,sectionIds:S,sectionTab:C,extraTabs:w,title:T,description:E}){let D=m(),O=ee().trpcClient,k=a(),A=n(),j=t(),M=i(),N=e(),P=!!(w&&w.length>0),[F,ae]=g(null);if(p===`device`&&!y)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);let I=o??`hub`,L=f({queries:l.map(e=>({queryKey:[[`addonSettings`,p===`global`?`getGlobalSettings`:`getDeviceSettings`],{addonId:e,nodeId:I,deviceId:y??null,cap:x??null}],queryFn:async()=>p===`global`?{addonId:e,result:await O.addonSettings.getGlobalSettings.query({addonId:e,nodeId:I,...x?{cap:x}:{}})}:{addonId:e,result:await O.addonSettings.getDeviceSettings.query({addonId:e,deviceId:y,nodeId:I})},placeholderData:h}))}),R=L.some(e=>e.isLoading),z=L.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),B=d(()=>{let e=new Set;for(let t of L){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[z+`::`+L.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),V=d(()=>new Map((w??[]).map(e=>[e.id,e])),[w]),H=d(()=>{if(!P)return[];let e=[...new Set([...B,...(w??[]).map(e=>e.id)])],t=e=>{let t=V.get(e);if(t?.order!==void 0)return t.order;let n=b[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[P,B,w,V]),oe=d(()=>{let e=new Map;for(let t of B){let n=b[t];e.set(t,n?.label??t.charAt(0).toUpperCase()+t.slice(1))}for(let t of w??[])e.set(t.id,t.label);return e},[B,w]),U=P?F&&H.includes(F)?F:H[0]??null:null,W=U!==null&&V.has(U),G=P?U&&!W?U:void 0:C,{data:K}=r(void 0),se=d(()=>{let e=new Map;for(let t of K??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[K]),q=c(new Map),J=d(()=>{let e=S?new Set(S):null,t=[];for(let n of L){if(!n.data)continue;let r=n.data.result??q.current.get(n.data.addonId)??null;if(n.data.result!==null&&q.current.set(n.data.addonId,n.data.result),r===null)continue;let{schema:i,values:a}=re(r),o=i.sections.filter(t=>e?e.has(t.id):!0);if(o.length===0)continue;let s={...r,sections:r.sections.filter(t=>e?e.has(t.id):!0)},c={...i,sections:o};t.push({addonId:n.data.addonId,schemaWithValues:s,schema:c,serverValues:a})}return t},[z,S]),[Y,ce]=g(new Map),le=s(e=>{ce(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),X=c(new Map),ue=s(e=>t=>{t?X.current.set(e,t):X.current.delete(e)},[]),Z=s(async(e,t)=>{p===`global`?await k.mutateAsync({addonId:e,nodeId:I,patch:t}):await A.mutateAsync({addonId:e,deviceId:y,nodeId:I,patch:t}),D.invalidateQueries({queryKey:[[`addonSettings`]]})},[k,A,I,p,y,D]),de=s(async(e,t,n,r)=>{let i=I;try{switch(t){case`reprobe-engine`:await j.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-hwaccel`:await M.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await N.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await O.addons.custom.mutate({addonId:e,action:t,input:r});return D.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[j,M,N,I,D,O]),fe=s((e,t)=>{Z(e,t)},[Z]),Q=_({mutationFn:async()=>{let e=[];for(let t of J){let n=Y.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(p===`global`?await k.mutateAsync({addonId:e,nodeId:I,patch:t}):await A.mutateAsync({addonId:e,deviceId:y,nodeId:I,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)X.current.get(t)?.discard();D.invalidateQueries({queryKey:[[`addonSettings`]]})}}),pe=s(()=>{for(let e of X.current.values())e.discard()},[]),me=d(()=>{let e=0;for(let t of J){let n=Y.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[J,Y]),he=d(()=>{let e=new Map;for(let t of J){let n=Y.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[J,Y]);if(R)return v(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let $=U&&W?V.get(U):void 0;if(!P&&J.length===0)return u(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:[`No addons in `,l.length>0?`[${l.join(`, `)}]`:`the current selection`,` `,`expose `,p,`-level settings on this node.`]});let ge=Q.isPending;return u(`div`,{className:`space-y-4`,children:[(T||E)&&u(`div`,{className:`border-b border-border pb-2`,children:[T&&v(`h2`,{className:`text-sm font-semibold text-foreground`,children:T}),E&&v(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:E})]}),P&&v(ne,{tabs:H.map(e=>({id:e,label:oe.get(e)??e})),activeId:U,onChange:ae,pendingByTab:he}),Q.isError&&u(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed: `,String(Q.error?.message??Q.error)]}),$?$.content:(()=>{let e=G?J.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===G).length,0):0,t=G!==null&&e<=1,n=J.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>G?(e.tab??`general`)===G:!0).map(e=>t?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i});return n.length===0?v(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:`Nothing to configure here for this node.`}):v(ie,{entries:n,paneStates:Y,displayNames:se,disabled:ge,setPaneRef:ue,onPaneStateChange:le,onImmediateSave:fe,onAction:de,inline:P||!!C})})(),!R&&v(te,{pendingCount:me,onSave:()=>Q.mutate(),onDiscard:pe,saving:ge})]})}function ie({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:i,onPaneStateChange:a,onImmediateSave:o,onAction:s,inline:c}){let l=d(()=>[...e].toSorted((e,t)=>{if(e.addonId===`system-config`)return-1;if(t.addonId===`system-config`)return 1;let r=n.get(e.addonId)??e.addonId,i=n.get(t.addonId)??t.addonId;return r.localeCompare(i)}),[e,n]),[f,p]=g(l[0]?.addonId??``);y(()=>{l.length!==0&&(l.find(e=>e.addonId===f)||p(l[0].addonId))},[l,f]);let m=l.find(e=>e.addonId===f)??l[0];if(!m)return null;let h=d(()=>s?(e,t,n,r)=>s(e,t,n,r):void 0,[s]),_=e=>v(C,{ref:i(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:o,onStateChange:a,onAction:h,disabled:r},e.addonId);return l.length===1||c?v(`div`,{className:`flex flex-col gap-4`,children:l.map(_)}):u(`div`,{className:`flex flex-col gap-3`,children:[v(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:l.map(e=>{let r=n.get(e.addonId)??e.addonId,i=e.addonId===m.addonId,a=(t.get(e.addonId)?.pendingKeys.length??0)>0;return u(`button`,{type:`button`,onClick:()=>p(e.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${i?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[r,a&&v(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),v(`div`,{className:`space-y-2`,children:l.map(e=>v(`div`,{style:e.addonId===m.addonId?void 0:{display:`none`},children:_(e)},e.addonId))})]})}export{E as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{$i as e,Aa as t,Da as n,Ea as r,S as i,Sa as a,Ta as o,ja as s,ka as c,wa as l,xa as u}from"./src-Dp6qXTLR.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-CpsGl45o.js";import{t as y}from"./circle-check-big-Bcoiv1yk.js";import{t as b}from"./pencil-CFG04wDY.js";import{t as x}from"./plus-Bc_u_j_c.js";import{t as S}from"./search-ChyM3D_C.js";import{R as C,V as w,j as T,s as E,x as D}from"./index-CpCNvkGK.js";import{t as O}from"./AdminPage-BwmGKnRf.js";var k=w(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]);d();var A=e=>typeof e==`string`&&e.length>0;function j(e){return{levels:e.levels,formats:e.format,bodyMaxLen:e.bodyMaxLen,attachmentSlots:e.attachments.mediaTypes,attachmentMode:e.attachments.mode,attachmentMax:e.attachments.max,attachmentMaxBytes:e.attachments.maxBytes,maxActions:e.actions,showActions:e.actions>0,showClickUrl:e.clickUrl,showSound:e.sound,showTtl:e.ttl,showTag:!0}}function M(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function N(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];A(i)&&n.push({mediaType:r,url:i})}return n}function P(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=A(r.label),i=A(r.url);!t&&!i||n.push({id:`test-${n.length+1}`,label:t?r.label:`Action ${n.length+1}`,...i?{url:r.url}:{}})}return n}function F(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=N(e,t.attachmentUrls),i=P(e,t.actions),a=e.ttl&&A(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:M(e,t.format),priority:I(t.priority),...A(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&A(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&A(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...A(t.tag)?{tag:t.tag}:{}}}function I(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function L(e){return e.levels.find(e=>e.flags?.critical===!0)||e.levels.filter(e=>typeof e.ordinal==`number`).sort((e,t)=>t.ordinal-e.ordinal)[0]}function R(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var z={image:`https://example.com/sample.jpg`,video:`https://example.com/sample.mp4`,gif:`https://example.com/sample.gif`,audio:`https://example.com/sample.mp3`,icon:`https://example.com/icon.png`};function B(e,t){let n=R(e);switch(t){case`minimal`:return{...n,body:`Test notification`};case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)};case`critical`:{let t=L(e);return{...n,body:`Critical test notification`,priority:5,level:t?.id??``}}case`everything`:{let t={},n=0;for(let r of e.attachments.mediaTypes){if(n>=e.attachments.max)break;t[r]=z[r],n+=1}let r=Array.from({length:e.actions},(e,t)=>({label:`Action ${t+1}`,url:`https://example.com/action/${t+1}`}));return{level:``,priority:4,format:e.format.includes(`markdown`)?`markdown`:e.format.includes(`html`)?`html`:e.format[0]??`text`,title:`Everything the kind supports`,body:`This sample fills every control the kind advertises.`,attachmentUrls:t,actions:r,clickUrl:e.clickUrl?`https://example.com/open`:``,sound:e.sound?`default`:``,ttl:e.ttl?`3600`:``,tag:`camstack-test`}}}}var V=[{id:`minimal`,label:`Minimal (body only)`},{id:`everything`,label:`Everything supported`},{id:`overflow`,label:`Overflow`},{id:`critical`,label:`Critical`}],H=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,U=`block text-[11px] font-medium text-foreground mb-1`;function W({target:e,kind:n,open:i,onClose:c}){let d=v(),m=p(()=>j(n.caps),[n.caps]),[y,b]=h(()=>R(n.caps)),[x,S]=h(null),C=p(()=>F(n.caps,y),[n.caps,y]),w=y.body.length,T=w>m.bodyMaxLen,E=e=>b(t=>({...t,...e})),O=g({mutationFn:()=>d.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:F(n.caps,y)}),onMutate:()=>S(null),onSuccess:e=>S(e),onError:e=>S({success:!1,error:e instanceof Error?e.message:`Test failed`})}),A=e=>{b(B(n.caps,e)),S(null)},M=(e,t,n)=>{let r=y.actions.length>0?[...y.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},E({actions:r})};return _(u,{open:i,onOpenChange:e=>!e&&c(),children:f(a,{width:`lg`,className:`!max-w-2xl`,children:[_(o,{children:f(r,{children:[`Test "`,e.name,`" (`,n.label,`)`]})}),f(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[_(`div`,{className:`flex flex-wrap gap-1.5`,children:V.map(e=>_(s,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>A(e.id),children:e.label},e.id))}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.levels.length>0&&f(`div`,{children:[_(`label`,{className:U,children:`Level`}),f(`select`,{className:H,value:y.level,onChange:e=>E({level:e.target.value}),children:[_(`option`,{value:``,children:`— derive from priority —`}),m.levels.map(e=>f(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=m.levels.find(e=>e.id===y.level);return e?f(`div`,{className:`mt-1 space-y-1`,children:[e.description&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),f(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&_(t,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&_(t,{variant:`info`,children:`silent`}),e.flags?.noPush&&_(t,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&f(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),f(`div`,{children:[f(`label`,{className:U,children:[`Priority (ordinal): `,y.priority]}),_(`input`,{type:`range`,min:1,max:5,step:1,value:y.priority,onChange:e=>E({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),m.formats.length>0&&f(`div`,{children:[_(`label`,{className:U,children:`Format`}),_(`div`,{className:`flex flex-wrap gap-2`,children:m.formats.map(e=>f(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[_(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:y.format===e,onChange:()=>E({format:e})}),e]},e))})]}),f(`div`,{children:[_(`label`,{className:U,children:`Title`}),_(`input`,{className:H,value:y.title,onChange:e=>E({title:e.target.value})})]}),f(`div`,{children:[f(`label`,{className:U,children:[`Body`,` `,f(`span`,{className:T?`text-danger`:`text-foreground-subtle`,children:[`(`,w,`/`,m.bodyMaxLen,T?` — overflow`:``,`)`]})]}),_(`textarea`,{className:`${H} min-h-[80px] resize-y`,value:y.body,onChange:e=>E({body:e.target.value})})]}),m.attachmentSlots.length>0&&f(`div`,{children:[f(`label`,{className:U,children:[`Attachments`,` `,f(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,m.attachmentMode,`, max `,m.attachmentMax,m.attachmentMaxBytes?`, ≤${Math.round(m.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),_(`div`,{className:`space-y-1.5`,children:m.attachmentSlots.map(e=>f(`div`,{className:`flex items-center gap-2`,children:[_(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),_(`input`,{className:H,placeholder:`${e} URL`,value:y.attachmentUrls[e]??``,onChange:t=>E({attachmentUrls:{...y.attachmentUrls,[e]:t.target.value}})})]},e))})]}),m.showActions&&f(`div`,{children:[f(`label`,{className:U,children:[`Actions (up to `,m.maxActions,`)`]}),_(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(m.maxActions,3)},(e,t)=>f(`div`,{className:`flex items-center gap-2`,children:[_(`input`,{className:H,placeholder:`label`,value:y.actions[t]?.label??``,onChange:e=>M(t,`label`,e.target.value)}),_(`input`,{className:H,placeholder:`url`,value:y.actions[t]?.url??``,onChange:e=>M(t,`url`,e.target.value)})]},t))})]}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.showClickUrl&&f(`div`,{children:[_(`label`,{className:U,children:`Click URL`}),_(`input`,{className:H,value:y.clickUrl,onChange:e=>E({clickUrl:e.target.value})})]}),m.showSound&&f(`div`,{children:[_(`label`,{className:U,children:`Sound`}),_(`input`,{className:H,value:y.sound,onChange:e=>E({sound:e.target.value})})]}),m.showTtl&&f(`div`,{children:[_(`label`,{className:U,children:`TTL (seconds)`}),_(`input`,{className:H,type:`number`,value:y.ttl,onChange:e=>E({ttl:e.target.value})})]}),m.showTag&&f(`div`,{children:[_(`label`,{className:U,children:`Tag`}),_(`input`,{className:H,value:y.tag,onChange:e=>E({tag:e.target.value})})]})]}),x&&_(G,{result:x}),f(`details`,{className:`text-[10px]`,children:[_(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),_(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(C,null,2)})]})]}),f(l,{children:[_(s,{variant:`secondary`,size:`sm`,type:`button`,onClick:c,children:`Close`}),f(s,{size:`sm`,type:`button`,disabled:O.isPending||y.body.length===0,onClick:()=>O.mutate(),children:[O.isPending?_(D,{className:`h-3.5 w-3.5 animate-spin`}):_(k,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function G({result:e}){let t=e.renderedAs;return f(`div`,{className:`rounded-md border px-3 py-2 text-xs ${e.success?`border-success/40 bg-success/10`:`border-danger/40 bg-danger/10`}`,"data-testid":`test-result`,children:[f(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?_(y,{className:`h-3.5 w-3.5 text-success`}):_(T,{className:`h-3.5 w-3.5 text-danger`}),_(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&_(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&f(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[_(`dt`,{children:`Resolved level`}),_(`dd`,{className:`text-foreground`,children:t.level}),_(`dt`,{children:`Format sent`}),_(`dd`,{className:`text-foreground`,children:t.format}),_(`dt`,{children:`Attachments sent`}),_(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),_(`dt`,{children:`Actions sent`}),_(`dd`,{className:`text-foreground`,children:t.actionsSent}),_(`dt`,{children:`Truncated`}),_(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),_(`dt`,{children:`Dropped`}),_(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function K(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.addonId);e?e.push(r):(n.set(r.addonId,[r]),t.push(r.addonId))}return t.map(e=>({addonId:e,kinds:n.get(e)??[]}))}function q(e){let t=[],n=e=>{for(let r of e){if(r.type===`password`){t.push(r.key);continue}if(r.type===`group`){n(r.fields);continue}if(r.type===`sub-tabs`)for(let e of r.tabs)n(e.fields)}};for(let t of e.sections)n(t.fields);return t}function J(e,t,n){let r=new Set(n),i={};for(let[n,a]of Object.entries(e)){if(!r.has(n)){i[n]=a;continue}a==null||a===``||a!==t[n]&&(i[n]=a)}return i}function Y(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}d();var X=[`notificationOutput`,`listTargets`],Z=[`notificationOutput`,`listTargetKinds`];function Q(){let r=v(),[i,a]=h({mode:`closed`}),[o,l]=h(null),u=m({queryKey:X,queryFn:()=>r.trpcClient.notificationOutput.listTargets.query({})}),d=m({queryKey:Z,queryFn:async()=>(await r.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),y=p(()=>d.data??[],[d.data]),S=p(()=>{let e=new Map;for(let t of y)e.set(t.kind,t);return e},[y]),w=g({mutationFn:e=>r.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:e.target.addonId,targetId:e.target.id,enabled:e.enabled}),onSuccess:()=>void u.refetch()}),T=g({mutationFn:e=>r.trpcClient.notificationOutput.deleteTarget.mutate({addonId:e.addonId,targetId:e.id}),onSuccess:()=>void u.refetch()}),A=o?S.get(o.kind):void 0;return f(O,{icon:C,title:`Notification Targets`,subtitle:`Deliver notifications to ntfy, Pushover, Telegram, Home Assistant and more. Each target's kind declares its capabilities; the test panel shows exactly what a message degrades to.`,actions:f(s,{size:`sm`,type:`button`,onClick:()=>a({mode:`pick-kind`}),children:[_(x,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[u.isLoading&&_(`div`,{className:`flex items-center justify-center py-16`,children:_(D,{className:`h-6 w-6 animate-spin text-primary`})}),u.isError&&!u.isLoading&&_(e,{title:`Failed to load targets`,message:u.error instanceof Error?u.error.message:`Unknown error`,onRetry:()=>void u.refetch()}),!u.isLoading&&!u.isError&&(u.data??[]).length===0&&_(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification targets yet. Click "Add target" to configure one.`}),(u.data??[]).length>0&&_(c,{children:_(`ul`,{className:`divide-y divide-border`,children:(u.data??[]).map(e=>{let r=S.get(e.kind);return f(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[_(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:r?.label??e.kind,children:r?.icon??`🔔`}),f(`div`,{className:`min-w-0 flex-1`,children:[_(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),_(`div`,{className:`text-[11px] text-foreground-subtle`,children:r?.label??e.kind})]}),!e.enabled&&_(t,{variant:`warning`,children:`disabled`}),_(n,{checked:e.enabled,onCheckedChange:t=>w.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),_(s,{size:`sm`,variant:`ghost`,type:`button`,disabled:!r,onClick:()=>l(e),title:`Test`,children:_(k,{className:`h-3.5 w-3.5`})}),_(s,{size:`sm`,variant:`ghost`,type:`button`,disabled:!r,onClick:()=>r&&a({mode:`form`,kind:r,target:e}),title:`Edit`,children:_(b,{className:`h-3.5 w-3.5`})}),_(s,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>T.mutate(e),title:`Delete`,children:_(E,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),i.mode===`pick-kind`&&_($,{kinds:y,onCancel:()=>a({mode:`closed`}),onPick:e=>a({mode:`form`,kind:e,target:null})}),i.mode===`form`&&_(ee,{kind:i.kind,target:i.target,onCancel:()=>a({mode:`closed`}),onSaved:()=>{a({mode:`closed`}),u.refetch()}}),o&&A&&_(W,{target:o,kind:A,open:!0,onClose:()=>l(null)})]})}function $({kinds:e,onPick:n,onCancel:r}){let i=p(()=>K(e),[e]);return f(c,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[_(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),_(s,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),i.length===0&&_(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification providers are installed. Install the notifiers addon (or connect Home Assistant) to add targets.`}),i.map(e=>f(`div`,{children:[_(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),_(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(r=>f(`button`,{type:`button`,onClick:()=>n(r),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[_(`span`,{className:`text-lg`,children:r.icon}),_(`span`,{className:`font-medium text-foreground`,children:r.label}),r.supportsDiscovery&&_(t,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${r.kind}`))})]},e.addonId))]})}function ee({kind:e,target:t,onSaved:n,onCancel:r}){let a=v(),o=p(()=>q(e.configSchema),[e.configSchema]),l=p(()=>t?.config??{},[t]),[u,d]=h(t?.name??e.label),[m,y]=h(()=>t?Y(t.config,o):{}),[b,x]=h(null),[C,w]=h(null),T=g({mutationFn:()=>a.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:m}),onSuccess:e=>x(e),onError:e=>w(e instanceof Error?e.message:`Discovery failed`)}),E=g({mutationFn:()=>{let n=J(m,l,o),r={id:t?.id??`${e.kind}-${Date.now()}`,name:u,kind:e.kind,addonId:e.addonId,enabled:t?.enabled??!0,config:n};return a.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:r})},onSuccess:n,onError:e=>w(e instanceof Error?e.message:`Save failed`)}),O=e=>{d(e.suggestedName),y(t=>({...t,...e.config})),x(null)};return f(c,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[f(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[_(`span`,{className:`text-lg`,children:e.icon}),t?`Edit ${t.name}`:`Add ${e.label} target`]}),_(s,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),C&&_(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:C}),f(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),_(`input`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,value:u,onChange:e=>d(e.target.value)})]}),e.supportsDiscovery&&f(`div`,{className:`space-y-2`,children:[f(s,{size:`sm`,variant:`outline`,type:`button`,disabled:T.isPending,onClick:()=>{w(null),T.mutate()},children:[T.isPending?_(D,{className:`h-3.5 w-3.5 animate-spin`}):_(S,{className:`h-3.5 w-3.5`}),`Discover`]}),b&&b.length===0&&_(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),b&&b.length>0&&_(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:b.map((e,t)=>f(`button`,{type:`button`,onClick:()=>O(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[_(`span`,{className:`text-foreground`,children:e.suggestedName}),_(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),o.length>0&&t&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Secret fields are hidden. Leave them blank to keep the stored value; type a new value to replace it.`}),_(i,{schema:e.configSchema,values:m,onChange:y}),f(`div`,{className:`flex justify-end gap-2`,children:[_(s,{variant:`secondary`,size:`sm`,type:`button`,onClick:r,children:`Cancel`}),f(s,{size:`sm`,type:`button`,disabled:E.isPending||u.trim().length===0,onClick:()=>{w(null),E.mutate()},children:[E.isPending&&_(D,{className:`h-3.5 w-3.5 animate-spin`}),t?`Save changes`:`Create target`]})]})]})}export{Q as NotificationTargetsPage,Q as default};
|
|
1
|
+
import{Aa as e,Ca as t,Da as n,Ea as r,Ma as i,Oa as a,S as o,Sa as s,Ta as c,ea as l,ja as u}from"./src-cK1rmJgB.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-CpsGl45o.js";import{t as y}from"./circle-check-big-CLMjysyy.js";import{t as b}from"./pencil-D2v4UbT5.js";import{t as x}from"./plus-DMWGd7B0.js";import{t as S}from"./search-DNeYxEqb.js";import{R as C,V as w,j as T,s as E,x as D}from"./index-CdAVDEco.js";import{t as O}from"./AdminPage-BwmGKnRf.js";var k=w(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]);d();var A=e=>typeof e==`string`&&e.length>0;function j(e){return{levels:e.levels,formats:e.format,bodyMaxLen:e.bodyMaxLen,attachmentSlots:e.attachments.mediaTypes,attachmentMode:e.attachments.mode,attachmentMax:e.attachments.max,attachmentMaxBytes:e.attachments.maxBytes,maxActions:e.actions,showActions:e.actions>0,showClickUrl:e.clickUrl,showSound:e.sound,showTtl:e.ttl,showTag:!0}}function M(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function N(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];A(i)&&n.push({mediaType:r,url:i})}return n}function P(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=A(r.label),i=A(r.url);!t&&!i||n.push({id:`test-${n.length+1}`,label:t?r.label:`Action ${n.length+1}`,...i?{url:r.url}:{}})}return n}function F(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=N(e,t.attachmentUrls),i=P(e,t.actions),a=e.ttl&&A(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:M(e,t.format),priority:I(t.priority),...A(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&A(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&A(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...A(t.tag)?{tag:t.tag}:{}}}function I(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function L(e){return e.levels.find(e=>e.flags?.critical===!0)||e.levels.filter(e=>typeof e.ordinal==`number`).sort((e,t)=>t.ordinal-e.ordinal)[0]}function R(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var z={image:`https://example.com/sample.jpg`,video:`https://example.com/sample.mp4`,gif:`https://example.com/sample.gif`,audio:`https://example.com/sample.mp3`,icon:`https://example.com/icon.png`};function B(e,t){let n=R(e);switch(t){case`minimal`:return{...n,body:`Test notification`};case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)};case`critical`:{let t=L(e);return{...n,body:`Critical test notification`,priority:5,level:t?.id??``}}case`everything`:{let t={},n=0;for(let r of e.attachments.mediaTypes){if(n>=e.attachments.max)break;t[r]=z[r],n+=1}let r=Array.from({length:e.actions},(e,t)=>({label:`Action ${t+1}`,url:`https://example.com/action/${t+1}`}));return{level:``,priority:4,format:e.format.includes(`markdown`)?`markdown`:e.format.includes(`html`)?`html`:e.format[0]??`text`,title:`Everything the kind supports`,body:`This sample fills every control the kind advertises.`,attachmentUrls:t,actions:r,clickUrl:e.clickUrl?`https://example.com/open`:``,sound:e.sound?`default`:``,ttl:e.ttl?`3600`:``,tag:`camstack-test`}}}}var V=[{id:`minimal`,label:`Minimal (body only)`},{id:`everything`,label:`Everything supported`},{id:`overflow`,label:`Overflow`},{id:`critical`,label:`Critical`}],H=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,U=`block text-[11px] font-medium text-foreground mb-1`;function W({target:e,kind:a,open:o,onClose:l}){let d=v(),m=p(()=>j(a.caps),[a.caps]),[y,b]=h(()=>R(a.caps)),[x,S]=h(null),C=p(()=>F(a.caps,y),[a.caps,y]),w=y.body.length,T=w>m.bodyMaxLen,E=e=>b(t=>({...t,...e})),O=g({mutationFn:()=>d.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:F(a.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(a.caps,e)),S(null)},M=(e,t,n)=>{let r=y.actions.length>0?[...y.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},E({actions:r})};return _(s,{open:o,onOpenChange:e=>!e&&l(),children:f(t,{width:`lg`,className:`!max-w-2xl`,children:[_(r,{children:f(n,{children:[`Test "`,e.name,`" (`,a.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=>E({level:e.target.value}),children:[_(`option`,{value:``,children:`— derive from priority —`}),m.levels.map(e=>f(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=m.levels.find(e=>e.id===y.level);return e?f(`div`,{className:`mt-1 space-y-1`,children:[e.description&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),f(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&_(u,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&_(u,{variant:`info`,children:`silent`}),e.flags?.noPush&&_(u,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&f(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),f(`div`,{children:[f(`label`,{className:U,children:[`Priority (ordinal): `,y.priority]}),_(`input`,{type:`range`,min:1,max:5,step:1,value:y.priority,onChange:e=>E({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),m.formats.length>0&&f(`div`,{children:[_(`label`,{className:U,children:`Format`}),_(`div`,{className:`flex flex-wrap gap-2`,children:m.formats.map(e=>f(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[_(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:y.format===e,onChange:()=>E({format:e})}),e]},e))})]}),f(`div`,{children:[_(`label`,{className:U,children:`Title`}),_(`input`,{className:H,value:y.title,onChange:e=>E({title:e.target.value})})]}),f(`div`,{children:[f(`label`,{className:U,children:[`Body`,` `,f(`span`,{className:T?`text-danger`:`text-foreground-subtle`,children:[`(`,w,`/`,m.bodyMaxLen,T?` — overflow`:``,`)`]})]}),_(`textarea`,{className:`${H} min-h-[80px] resize-y`,value:y.body,onChange:e=>E({body:e.target.value})})]}),m.attachmentSlots.length>0&&f(`div`,{children:[f(`label`,{className:U,children:[`Attachments`,` `,f(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,m.attachmentMode,`, max `,m.attachmentMax,m.attachmentMaxBytes?`, ≤${Math.round(m.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),_(`div`,{className:`space-y-1.5`,children:m.attachmentSlots.map(e=>f(`div`,{className:`flex items-center gap-2`,children:[_(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),_(`input`,{className:H,placeholder:`${e} URL`,value:y.attachmentUrls[e]??``,onChange:t=>E({attachmentUrls:{...y.attachmentUrls,[e]:t.target.value}})})]},e))})]}),m.showActions&&f(`div`,{children:[f(`label`,{className:U,children:[`Actions (up to `,m.maxActions,`)`]}),_(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(m.maxActions,3)},(e,t)=>f(`div`,{className:`flex items-center gap-2`,children:[_(`input`,{className:H,placeholder:`label`,value:y.actions[t]?.label??``,onChange:e=>M(t,`label`,e.target.value)}),_(`input`,{className:H,placeholder:`url`,value:y.actions[t]?.url??``,onChange:e=>M(t,`url`,e.target.value)})]},t))})]}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.showClickUrl&&f(`div`,{children:[_(`label`,{className:U,children:`Click URL`}),_(`input`,{className:H,value:y.clickUrl,onChange:e=>E({clickUrl:e.target.value})})]}),m.showSound&&f(`div`,{children:[_(`label`,{className:U,children:`Sound`}),_(`input`,{className:H,value:y.sound,onChange:e=>E({sound:e.target.value})})]}),m.showTtl&&f(`div`,{children:[_(`label`,{className:U,children:`TTL (seconds)`}),_(`input`,{className:H,type:`number`,value:y.ttl,onChange:e=>E({ttl:e.target.value})})]}),m.showTag&&f(`div`,{children:[_(`label`,{className:U,children:`Tag`}),_(`input`,{className:H,value:y.tag,onChange:e=>E({tag:e.target.value})})]})]}),x&&_(G,{result:x}),f(`details`,{className:`text-[10px]`,children:[_(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),_(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(C,null,2)})]})]}),f(c,{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?_(D,{className:`h-3.5 w-3.5 animate-spin`}):_(k,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function G({result:e}){let t=e.renderedAs;return f(`div`,{className:`rounded-md border px-3 py-2 text-xs ${e.success?`border-success/40 bg-success/10`:`border-danger/40 bg-danger/10`}`,"data-testid":`test-result`,children:[f(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?_(y,{className:`h-3.5 w-3.5 text-success`}):_(T,{className:`h-3.5 w-3.5 text-danger`}),_(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&_(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&f(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[_(`dt`,{children:`Resolved level`}),_(`dd`,{className:`text-foreground`,children:t.level}),_(`dt`,{children:`Format sent`}),_(`dd`,{className:`text-foreground`,children:t.format}),_(`dt`,{children:`Attachments sent`}),_(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),_(`dt`,{children:`Actions sent`}),_(`dd`,{className:`text-foreground`,children:t.actionsSent}),_(`dt`,{children:`Truncated`}),_(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),_(`dt`,{children:`Dropped`}),_(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function K(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.addonId);e?e.push(r):(n.set(r.addonId,[r]),t.push(r.addonId))}return t.map(e=>({addonId:e,kinds:n.get(e)??[]}))}function q(e){let t=[],n=e=>{for(let r of e){if(r.type===`password`){t.push(r.key);continue}if(r.type===`group`){n(r.fields);continue}if(r.type===`sub-tabs`)for(let e of r.tabs)n(e.fields)}};for(let t of e.sections)n(t.fields);return t}function J(e,t,n){let r=new Set(n),i={};for(let[n,a]of Object.entries(e)){if(!r.has(n)){i[n]=a;continue}a==null||a===``||a!==t[n]&&(i[n]=a)}return i}function Y(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}d();var X=[`notificationOutput`,`listTargets`],Z=[`notificationOutput`,`listTargetKinds`];function Q(){let t=v(),[n,r]=h({mode:`closed`}),[o,s]=h(null),c=m({queryKey:X,queryFn:()=>t.trpcClient.notificationOutput.listTargets.query({})}),d=m({queryKey:Z,queryFn:async()=>(await t.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),y=p(()=>d.data??[],[d.data]),S=p(()=>{let e=new Map;for(let t of y)e.set(t.kind,t);return e},[y]),w=g({mutationFn:e=>t.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:e.target.addonId,targetId:e.target.id,enabled:e.enabled}),onSuccess:()=>void c.refetch()}),T=g({mutationFn:e=>t.trpcClient.notificationOutput.deleteTarget.mutate({addonId:e.addonId,targetId:e.id}),onSuccess:()=>void c.refetch()}),A=o?S.get(o.kind):void 0;return f(O,{icon:C,title:`Notification Targets`,subtitle:`Deliver notifications to ntfy, Pushover, Telegram, Home Assistant and more. Each target's kind declares its capabilities; the test panel shows exactly what a message degrades to.`,actions:f(i,{size:`sm`,type:`button`,onClick:()=>r({mode:`pick-kind`}),children:[_(x,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[c.isLoading&&_(`div`,{className:`flex items-center justify-center py-16`,children:_(D,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&_(l,{title:`Failed to load targets`,message:c.error instanceof Error?c.error.message:`Unknown error`,onRetry:()=>void c.refetch()}),!c.isLoading&&!c.isError&&(c.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.`}),(c.data??[]).length>0&&_(e,{children:_(`ul`,{className:`divide-y divide-border`,children:(c.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&&_(u,{variant:`warning`,children:`disabled`}),_(a,{checked:e.enabled,onCheckedChange:t=>w.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),_(i,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>s(e),title:`Test`,children:_(k,{className:`h-3.5 w-3.5`})}),_(i,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>t&&r({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:()=>T.mutate(e),title:`Delete`,children:_(E,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),n.mode===`pick-kind`&&_($,{kinds:y,onCancel:()=>r({mode:`closed`}),onPick:e=>r({mode:`form`,kind:e,target:null})}),n.mode===`form`&&_(ee,{kind:n.kind,target:n.target,onCancel:()=>r({mode:`closed`}),onSaved:()=>{r({mode:`closed`}),c.refetch()}}),o&&A&&_(W,{target:o,kind:A,open:!0,onClose:()=>s(null)})]})}function $({kinds:t,onPick:n,onCancel:r}){let a=p(()=>K(t),[t]);return f(e,{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:r,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(t=>f(`button`,{type:`button`,onClick:()=>n(t),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:t.icon}),_(`span`,{className:`font-medium text-foreground`,children:t.label}),t.supportsDiscovery&&_(u,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${t.kind}`))})]},e.addonId))]})}function ee({kind:t,target:n,onSaved:r,onCancel:a}){let s=v(),c=p(()=>q(t.configSchema),[t.configSchema]),l=p(()=>n?.config??{},[n]),[u,d]=h(n?.name??t.label),[m,y]=h(()=>n?Y(n.config,c):{}),[b,x]=h(null),[C,w]=h(null),T=g({mutationFn:()=>s.trpcClient.notificationOutput.discoverTargets.query({addonId:t.addonId,kind:t.kind,config:m}),onSuccess:e=>x(e),onError:e=>w(e instanceof Error?e.message:`Discovery failed`)}),E=g({mutationFn:()=>{let e=J(m,l,c),r={id:n?.id??`${t.kind}-${Date.now()}`,name:u,kind:t.kind,addonId:t.addonId,enabled:n?.enabled??!0,config:e};return s.trpcClient.notificationOutput.upsertTarget.mutate({addonId:t.addonId,target:r})},onSuccess:r,onError:e=>w(e instanceof Error?e.message:`Save failed`)}),O=e=>{d(e.suggestedName),y(t=>({...t,...e.config})),x(null)};return f(e,{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:t.icon}),n?`Edit ${n.name}`:`Add ${t.label} target`]}),_(i,{size:`sm`,variant:`ghost`,type:`button`,onClick:a,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)})]}),t.supportsDiscovery&&f(`div`,{className:`space-y-2`,children:[f(i,{size:`sm`,variant:`outline`,type:`button`,disabled:T.isPending,onClick:()=>{w(null),T.mutate()},children:[T.isPending?_(D,{className:`h-3.5 w-3.5 animate-spin`}):_(S,{className:`h-3.5 w-3.5`}),`Discover`]}),b&&b.length===0&&_(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),b&&b.length>0&&_(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:b.map((e,t)=>f(`button`,{type:`button`,onClick:()=>O(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[_(`span`,{className:`text-foreground`,children:e.suggestedName}),_(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),c.length>0&&n&&_(`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:t.configSchema,values:m,onChange:y}),f(`div`,{className:`flex justify-end gap-2`,children:[_(i,{variant:`secondary`,size:`sm`,type:`button`,onClick:a,children:`Cancel`}),f(i,{size:`sm`,type:`button`,disabled:E.isPending||u.trim().length===0,onClick:()=>{w(null),E.mutate()},children:[E.isPending&&_(D,{className:`h-3.5 w-3.5 animate-spin`}),n?`Save changes`:`Create target`]})]})]})}export{Q as NotificationTargetsPage,Q as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{$i as e,Ai as t,Br as n,C as r,Di as i,Ei as a,Fr as o,Gr as s,Hr as c,Jr as l,Kr as u,La as d,Lr as f,Oi as p,Qr as m,Rr as h,Si as g,T as _,Ur as v,Vr as y,Xr as b,Yr as x,Zr as S,_ as C,aa as w,ai as T,bi as E,ca as D,ci as O,da as k,di as A,ei as j,fa as M,fi as N,ia as P,it as F,ja as I,la as ee,mi as te,oa as L,oi as ne,ot as re,pi as ie,qr as ae,ra as oe,ri as se,si as ce,ti as le,ui as ue,wi as de,xi as fe,yi as pe,za as me,zr as he}from"./src-cK1rmJgB.js";import{I as ge,K as _e,Q as R,S as z,T as ve,W as B,a as ye,b as V,o as H,q as U,x as W,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{L as K,V as be}from"./src-BXL7z3gT.js";import{p as xe}from"./player-overlays-CpsGl45o.js";import{t as Se}from"./download-BuixOtcX.js";import{i as Ce,n as we,r as Te,t as Ee}from"./AddLocationWizard-RRlx3cRe.js";import{n as De,r as Oe,t as ke}from"./zap-GMWRUOGp.js";import{i as Ae,r as je}from"./useDevice-CNqajtmH.js";import{t as Me}from"./pencil-D2v4UbT5.js";import{t as Ne}from"./plus-DMWGd7B0.js";import{t as Pe}from"./refresh-cw-B_eIWqpa.js";import{t as Fe}from"./search-DNeYxEqb.js";import{t as Ie}from"./server-CcpmRIQF.js";import{t as Le}from"./square-check-big-O_vP3vWT.js";import{t as Re}from"./square-BelYTwAy.js";import{A as ze,F as Be,G as Ve,M as He,P as Ue,V as We,i as Ge,j as Ke,k as q,o as qe,s as Je,w as Ye,x as J}from"./index-CdAVDEco.js";import{t as Xe}from"./AdminPage-BwmGKnRf.js";import{t as Ze}from"./useEventInvalidation-ycuHWtpd.js";import{a as Qe,c as Y,i as $e,l as et,o as X,r as tt,s as nt,t as rt}from"./build-cluster-graph-DIEEuf36.js";import{n as it}from"./format-size-CO9d3C3-.js";import{t as at}from"./NodeAddonsSettingsPanel-Cpl4rjtk.js";var ot=We(`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`}]]),st=We(`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`}]]),ct=We(`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`}]]),lt=We(`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`}]]);R();function ut(e){return e}function dt(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function ft(e,t){return typeof e==`boolean`?e:ut(t)}function pt(e,t){return{decode:ft(dt(e,`decode`),t),pipeline:ft(dt(e,`detect`),t),audio:ft(dt(e,`audio`),t),ingest:ft(dt(e,`ingest`),t)}}function mt(e,t,n){let r=e?.find(e=>e.nodeId===t);return pt(r?.settings,n)}function ht({selectedNodeId:e,onSelect:t,refreshToken:n}){let{data:r}=o(void 0),{data:i}=T(void 0),{data:a}=ne(void 0),s=new Map;for(let e of i??[])s.set(e.agentNodeId,(s.get(e.agentNodeId)??0)+1);let c=r??[],l=c.filter(e=>e.isOnline).length,u=c.filter(e=>!e.isOnline).length;return z(`div`,{className:`flex flex-col h-full`,children:[z(`button`,{type:`button`,onClick:()=>t(Rr),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:[W(Ye,{className:`h-4 w-4 flex-shrink-0`}),z(`div`,{className:`min-w-0 flex-1`,children:[W(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),W(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),W(`div`,{className:`flex-1 overflow-y-auto`,children:c.map(n=>{let r=e===n.id,i=s.get(n.id)??0,o=n.isHub?Ie:q,c=mt(a,n.id,n.isHub),l=n.isOnline?null:me(et(n.lastSeen));return z(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[W(o,{className:`h-4 w-4 flex-shrink-0`}),z(`div`,{className:`min-w-0 flex-1`,children:[z(`div`,{className:`flex items-center gap-2`,children:[W(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&W(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&W(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&W(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),z(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[z(`span`,{children:[n.cpuCores,` cores`]}),W(`span`,{children:`•`}),z(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),i>0&&z(V,{children:[W(`span`,{children:`•`}),z(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[W(De,{className:`h-2.5 w-2.5`}),i]})]}),!n.isOnline&&z(V,{children:[W(`span`,{children:`•`}),z(`span`,{className:`text-destructive`,children:[`offline`,l===null?``:` · ${l}`]})]})]}),z(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[W(I,{variant:c.decode?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:c.decode?`Decode: enabled`:`Decode: not enabled (agent capability)`,children:`Dec`}),W(I,{variant:c.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:c.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),W(I,{variant:c.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:c.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),z(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[z(`span`,{children:[l,` online`]}),u>0&&z(`span`,{className:`text-destructive`,children:[u,` offline`]})]})]})}function gt({nodeId:e,refreshToken:t}){let{data:n}=o(void 0),r=n?.find(t=>t.id===e),i=P(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?z(`div`,{className:`px-6 py-4 border-b border-border`,children:[z(`div`,{className:`flex items-center gap-2 mb-1`,children:[W(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?W(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):W(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&W(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),z(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[W(`span`,{children:r.cpuModel??`CPU`}),W(`span`,{children:`•`}),z(`span`,{children:[r.cpuCores,` cores`]}),W(`span`,{children:`•`}),z(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),i&&z(V,{children:[W(`span`,{children:`•`}),z(`span`,{children:[i.attachedCameras,` cameras (`,i.activeCameras,` active)`]}),W(`span`,{children:`•`}),z(`span`,{children:[i.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),W(`span`,{children:`•`}),z(`span`,{children:[`queue `,i.queueDepthTotal]}),i.hardware.hasGpu&&z(V,{children:[W(`span`,{children:`•`}),W(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):W(`div`,{className:`px-6 py-4 border-b border-border`,children:z(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function _t({refreshToken:e,nodeId:t}){let[n,r]=U(new Map),{nodes:i}=oe();L(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&r(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:a}=m(void 0),o=B(()=>{let e=new Map;for(let t of a??[])e.set(t.nodeId,t.deviceCount);return e},[a]),s=B(()=>{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=B(()=>{let e=new Map;for(let t of i)e.set(t.id,t.shortName);return e},[i]),l=B(()=>{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 z(`div`,{className:`@container/liveload`,children:[W(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),z(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[W(Z,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),W(Z,{label:`Cameras`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),W(Z,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),W(Z,{label:`Queue`,value:e?String(e.queueDepth):`—`}),W(Z,{label:`Audio`,value:String(o.get(t)??`—`)})]})]})}let u=[...s.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return z(`div`,{className:`@container/liveload`,children:[W(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),z(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[W(Z,{label:`Total agents`,value:`${l.onlineAgents}/${l.totalAgents}`}),W(Z,{label:`Cameras`,value:`${l.activeCameras}/${l.attachedCameras}`}),W(Z,{label:`Total FPS`,value:l.totalFps.toFixed(1)}),W(Z,{label:`Avg inference ms`,value:l.avgInferenceTimeMs.toFixed(0)}),W(Z,{label:`Queue depth`,value:String(l.queueDepth)})]}),W(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:z(`table`,{className:`w-full text-xs min-w-[480px]`,children:[W(`thead`,{className:`bg-surface`,children:z(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[W(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),W(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),W(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),W(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),W(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),W(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),z(`tbody`,{children:[u.map(([e,t])=>z(`tr`,{className:`border-t border-border`,children:[W(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:c.get(e)??e}),W(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),W(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),W(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),W(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),W(`td`,{className:`px-3 py-2 text-right text-foreground`,children:o.get(e)??`—`})]},e)),u.length===0&&W(`tr`,{children:W(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function Z({label:e,value:t}){return z(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[W(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),W(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}R();var vt={active:!1,pinned:!1,nodeId:null,reason:``},yt=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],bt={pipeline:q,decoder:st,audio:Oe},xt={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function St({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let r=H(),[i,a]=U(null),[o,s]=U(null),[c,d]=U(new Map);Ze([`pipelineOrchestrator`,`getPipelineAssignments`],yt),Ze([`pipelineOrchestrator`,`getDecoderAssignments`],yt),Ze([`pipelineOrchestrator`,`getAudioAssignments`],yt);let{data:f}=T(void 0),{data:p}=se(void 0),{data:m}=S(void 0),{nodes:h}=oe(),{data:g}=je();L(`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})}),G(()=>{if(c.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[c.size]);let v=B(()=>{let e=new Map;for(let t of g??[])e.set(t.id,t.name);return e},[g]),y=B(()=>{let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:v.get(e)??`Device ${e}`,pipeline:vt,decoder:vt,audio:vt};return n.set(e,r),r};for(let i of f??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``}})}for(let i of p??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,decoder:{active:e===`cluster`?!0:i.decoderNodeId===t,pinned:i.pinned,nodeId:i.decoderNodeId,reason:i.reason??``}})}for(let i of m??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,audio:{active:e===`cluster`?!0:i.nodeId===t,pinned:i.pinned,nodeId:i.nodeId,reason:`capacity`}})}let i=[...n.values()];return e===`agent`&&(i=i.filter(e=>e.pipeline.active||e.decoder.active||e.audio.active)),i.sort((e,t)=>e.deviceId-t.deviceId),i},[f,p,m,v,e,t]),b=B(()=>(h??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[h]),x=()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})},C=l({onSuccess:x}),w=fe({onSuccess:x}),D=ae({onSuccess:x}),O=E({onSuccess:x}),k=u({onSuccess:x}),A=pe({onSuccess:x}),j=(e,t,n)=>{t===`pipeline`?C.mutate({deviceId:e,agentNodeId:n}):t===`decoder`?D.mutate({deviceId:e,nodeId:n}):k.mutate({deviceId:e,nodeId:n}),a(null)},M=(e,t)=>{t===`pipeline`?w.mutate({deviceId:e}):t===`decoder`?O.mutate({deviceId:e}):A.mutate({deviceId:e}),a(null)};return W(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:z(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[W(`thead`,{className:`bg-surface`,children:z(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&W(`th`,{className:`w-10`}),W(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?z(V,{children:[W(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),W(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):z(V,{children:[W(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),W(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),W(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),W(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),z(`tbody`,{children:[y.map(t=>{let r=c.get(t.deviceId),l=o===t.deviceId;return z(ve.Fragment,{children:[z(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&W(`td`,{className:`px-2 py-2 align-middle`,children:W(`button`,{type:`button`,onClick:()=>s(l?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":l?`Collapse broker details`:`Expand broker details`,children:W(l?Ue:He,{className:`h-3.5 w-3.5`})})}),z(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[W(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),z(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?z(V,{children:[W(`td`,{className:`px-3 py-2 align-middle`,children:W(Ct,{state:t.pipeline,onlineNodes:b,pending:C.isPending||w.isPending,onChange:e=>{e===`auto`?M(t.deviceId,`pipeline`):j(t.deviceId,`pipeline`,e)}})}),W(`td`,{className:`px-3 py-2 align-middle`,children:W(wt,{state:t.pipeline})})]}):z(V,{children:[W(Tt,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:b,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`pipeline`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>a(null),onMove:e=>j(t.deviceId,`pipeline`,e),onUnpin:()=>M(t.deviceId,`pipeline`)}),W(Tt,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:b,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`decoder`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`decoder`?null:{deviceId:t.deviceId,role:`decoder`}),onCloseMenu:()=>a(null),onMove:e=>j(t.deviceId,`decoder`,e),onUnpin:()=>M(t.deviceId,`decoder`)}),W(Tt,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:b,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`audio`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>a(null),onMove:e=>j(t.deviceId,`audio`,e),onUnpin:()=>M(t.deviceId,`audio`)})]}),W(`td`,{className:`px-3 py-2 align-middle`,children:W(Ot,{snap:r})})]}),l&&!n&&z(`tr`,{className:`bg-surface/50`,children:[W(`td`,{}),W(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2`,children:W(_,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})})]})]},t.deviceId)}),y.length===0&&W(`tr`,{children:W(`td`,{colSpan:n?e===`cluster`?4:5:e===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function Ct({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 z(`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:[W(`option`,{value:`auto`,children:`Auto`}),a.map(e=>z(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function wt({state:e}){if(!e.active||!e.nodeId)return W(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let t=e.pinned?`pinned · manual`:`auto · ${e.reason||`capacity`}`;return z(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[W(`span`,{className:`font-mono text-[11px] text-foreground truncate`,title:e.nodeId,children:e.nodeId}),W(`span`,{className:`truncate ${e.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:t,children:t})]})}function Tt({role:e,state:t,mode:n,onlineNodes:r,isMenuOpen:i,onToggleMenu:a,onCloseMenu:o,onMove:s,onUnpin:c}){let l=bt[e],u=r.filter(e=>e.id!==(t.nodeId??``)),d=(t.active||n===`cluster`)&&(u.length>0||t.pinned);return z(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[z(`div`,{className:`flex items-center gap-2 min-w-0`,children:[W(n===`agent`?Et:Dt,{state:t,Icon:l}),W(`div`,{className:`ml-auto shrink-0`,children:d&&W(`button`,{type:`button`,onClick:a,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${xt[e]} actions`,children:W(ot,{className:`h-3 w-3 text-foreground-subtle`})})})]}),i&&d&&W(kt,{title:xt[e],targets:u,pinned:t.pinned,onMove:s,onUnpin:c,onClose:o})]})}function Et({state:e,Icon:t}){return z(`div`,{className:`flex items-center gap-1.5`,children:[W(e.active?Le:Re,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),W(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&W(lt,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Dt({state:e,Icon:t}){return!e.active||!e.nodeId?z(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[W(t,{className:`h-3 w-3`}),W(`span`,{className:`text-[10px] italic`,children:`—`})]}):z(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[W(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),z(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[W(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),W(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?z(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[W(lt,{className:`h-2.5 w-2.5`}),` manual`]}):z(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}function Ot({snap:e}){if(!e)return W(`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=d(t);return z(`div`,{className:`flex flex-col gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0`,children:[z(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${s.textColor}`,children:[W(C,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),W(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:s.label})]}),z(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[W(`span`,{className:`text-foreground`,children:n.toFixed(1)}),z(`span`,{children:[`/`,a.toFixed(0),` fps`]})]}),z(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[W(`span`,{className:`text-foreground`,children:r.toFixed(0)}),W(`span`,{children:` ms`}),i>0&&z(`span`,{className:`text-warning ml-1`,children:[`q`,i]})]}),z(`span`,{className:`whitespace-nowrap truncate ${o>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,W(`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 G(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),z(`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:[W(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&W(`div`,{className:`py-1`,children:t.map(e=>z(`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&&z(`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&&W(`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 z(`div`,{className:`space-y-6`,children:[W(_t,{refreshToken:t,nodeId:e}),z(`div`,{children:[W(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),z(`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.`]})]}),W(St,{mode:`agent`,nodeId:e,compact:!0})]})}R();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=H(),r=c({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:i}=v({nodeId:e}),a=P(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??i??null,o=a===null;Ze([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:s}=de({nodeId:e}),{values:l}=w(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),u=B(()=>l.filter(e=>e.metrics.phase===`active`).length,[l]),d=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 z(`div`,{className:`space-y-6`,children:[z(`div`,{children:[W(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),z(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(a??[]).length,` engine(s) resident in RAM. `,(s??[]).length,` `,`camera(s) attached, `,u,` actively dispatching frames. Refreshes every 5s.`]})]}),W(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:z(`table`,{className:`w-full text-xs min-w-[640px]`,children:[W(`thead`,{className:`bg-surface`,children:z(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[W(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),W(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),W(`th`,{className:`text-left px-3 py-2`,children:`Models`}),W(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),W(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),W(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),W(`th`,{className:`w-20`})]})}),z(`tbody`,{children:[o&&W(`tr`,{children:W(`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 z(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:``}`,children:[W(`td`,{className:`px-3 py-2`,children:z(`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:[W(t?ct:q,{className:`h-3 w-3`}),t?`warm`:`runtime`]})}),W(`td`,{className:`px-3 py-2`,children:z(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[W(ke,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),W(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?W(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):W(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>W(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),W(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),W(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?W(`span`,{className:`text-foreground-subtle`,children:jt(e.idleMs,e.idleTtlMs)}):W(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),W(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(s??[]).length}),W(`td`,{className:`px-3 py-2 text-right`,children:z(`button`,{type:`button`,disabled:r.isPending,onClick:()=>d(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:[W(Je,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!o&&(a??[]).length===0&&W(`tr`,{children:W(`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.`})})]})]})}),z(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[W(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,W(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`]}),r.isError&&z(`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`]})]})}R();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 Q(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?z(`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:[W(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),z(`div`,{className:`flex-1 min-w-0`,children:[z(`div`,{className:`flex items-center gap-2`,children:[W(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),z(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&z(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[W(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:W(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),z(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),W(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:it(c.sizeMB)}),a&&z(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[W(Ke,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?z(`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?W(J,{className:`h-3 w-3 animate-spin`}):W(Je,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):z(`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?W(J,{className:`h-3 w-3 animate-spin`}):W(Se,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function Bt({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=U(!1);return z(`div`,{className:`relative`,children:[z(`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:[W(q,{className:`h-4 w-4 text-primary shrink-0`}),z(`div`,{className:`flex-1 min-w-0`,children:[z(`div`,{className:`flex items-center gap-2`,children:[W(`span`,{className:`text-sm font-medium text-foreground`,children:It(n)}),Q(n)===Q(t)&&W(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),W(`div`,{className:`text-[10px] text-foreground-subtle`,children:Lt(n)})]}),W(Ue,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&W(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let i=Q(e)===Q(n),o=Q(e)===Q(t);return z(`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:[W(q,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),z(`div`,{className:`flex-1`,children:[z(`div`,{className:`flex items-center gap-2`,children:[W(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:It(e)}),o&&W(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),W(`div`,{className:`text-[10px] text-foreground-subtle`,children:Lt(e)})]}),i&&W(ze,{className:`h-4 w-4 text-primary shrink-0`})]},Q(e))})})]})}function Vt({embedded:e=!1,nodeId:t}={}){let r=H(),i=t??`hub`,[a,o]=U(null),[s,c]=U(new Set),[l,u]=U(new Map),[d,p]=U(new Map),[m,g]=U(``),{data:_=[]}=he({nodeId:i}),v=_.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:b}=y({nodeId:i}),x=b,{data:S,isLoading:C}=n({nodeId:i}),w=h(),T=f();L(`model.download.progress`,e=>{let t=e.data,n=typeof t.modelId==`string`?t.modelId:void 0,i=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;n===void 0||i===void 0||(u(e=>{let t=new Map(e);return i===100||i===-1?t.delete(n):t.set(n,{modelId:n,progress:i,totalMB:a}),t}),i===100&&r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let E=x??{runtime:`node`,backend:`cpu`,format:`onnx`},D=v.find(e=>e.format===a)??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),M=ge(async(e,t,n)=>{if(!Pt(n))return;let a=Ft(e,t,n);c(e=>new Set([...e,a])),p(e=>{let t=new Map(e);return t.delete(a),t});try{await w.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){p(t=>new Map([...t,[a,e instanceof Error?e.message:`Download failed`]]))}finally{c(e=>{let t=new Set(e);return t.delete(a),t})}},[w,r,i]),N=ge(async(e,t,n)=>{if(!Pt(n))return;let a=Ft(e,t,n);c(e=>new Set([...e,a])),p(e=>{let t=new Map(e);return t.delete(a),t});try{await T.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){p(t=>new Map([...t,[a,e instanceof Error?e.message:`Delete failed`]]))}finally{c(e=>{let t=new Set(e);return t.delete(a),t})}},[T,r,i]),P=ge(e=>{o(e.format)},[]),F=m.trim()?A.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(m.toLowerCase())||t.id.toLowerCase().includes(m.toLowerCase())||e.name.toLowerCase().includes(m.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):A,I=z(V,{children:[C&&W(`div`,{className:`flex items-center justify-center py-16`,children:W(J,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!C&&k.length===0&&z(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[W(Ce,{className:`h-8 w-8 mb-3 opacity-30`}),W(`span`,{className:`text-sm`,children:`No pipeline steps available`}),W(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!C&&k.length>0&&z(V,{children:[W(Bt,{engines:v,activeEngine:E,viewEngine:D,onSelect:P}),z(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[z(`span`,{children:[W(`span`,{className:`font-semibold text-foreground tabular-nums`,children:j.total}),W(`span`,{className:`ml-1`,children:`compatible models`})]}),W(`span`,{className:`text-border`,children:`|`}),z(`span`,{children:[W(`span`,{className:`font-semibold text-success tabular-nums`,children:j.downloaded}),W(`span`,{className:`ml-1`,children:`downloaded`})]}),W(`span`,{className:`text-border`,children:`|`}),z(`span`,{className:`tabular-nums`,children:[it(j.downloadedSizeMB),W(`span`,{className:`ml-1`,children:`on disk`})]})]}),j.total>5&&z(`div`,{className:`relative`,children:[W(Fe,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),W(`input`,{type:`text`,value:m,onChange:e=>g(e.target.value),placeholder:`Search models...`,className:`w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-surface text-foreground placeholder:text-foreground-subtle/50 focus:outline-none focus:ring-1 focus:ring-primary`})]}),F.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+t.models.filter(e=>e.formats[O]?.downloaded).length,0);return z(`div`,{children:[z(`div`,{className:`flex items-center gap-2 mb-2`,children:[W(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),W(`div`,{className:`flex-1 h-px bg-border`}),z(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),W(`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 W(zt,{addonId:e.id,model:t,format:O,isActive:s.has(n),progress:l.get(t.id),errorMsg:d.get(n),onDownload:()=>M(e.id,t.id,O),onDelete:()=>N(e.id,t.id,O)},`${e.id}/${t.id}`)}))})]},e.id)}),F.length===0&&W(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:m.trim()?z(V,{children:[`No models matching “`,m,`”`]}):z(V,{children:[`No models available for `,It(D),` format`]})})]})]});return e?W(`div`,{className:`space-y-4`,children:I}):W(Xe,{children:I})}function Ht({nodeId:e,refreshToken:t}){return W(Vt,{embedded:!0,nodeId:e})}var Ut=[{concern:`pipeline`,label:`Pipeline`,advisory:!1},{concern:`audio`,label:`Audio`,advisory:!1},{concern:`decode`,label:`Decode`,advisory:!0,advisoryNote:`Advisory: decode currently runs co-located with the stream source (hub). Pins are stored and take effect with Phase-2 stream load-balancing.`}];function Wt(e,t){return e.filter(e=>e.currentNodeId!==t)}var Gt=`This node is not decoder-enabled (enabledDecoderNodes). Pinning detection here strands frames (0 fps) until frame-source-aware placement ships. Enable decode on this node first, or pick a decoder-enabled node.`;function Kt(e,t,n){return t.includes(e)?{verdict:`ok`}:n?{verdict:`warn`,reason:Gt}:{verdict:`block`,reason:Gt}}R();var qt=`pipeline-orchestrator`,Jt=`enabledDecoderNodes`;function Yt(e,t){if(!e||typeof e!=`object`)return;let n=e.sections;if(Array.isArray(n))for(let e of n){if(!e||typeof e!=`object`)continue;let n=e.fields;if(Array.isArray(n))for(let e of n){if(!e||typeof e!=`object`)continue;let n=e;if(n.key!==t)continue;let r=n.value;return Array.isArray(r)&&r.every(e=>typeof e==`string`)?r:void 0}}}function Xt({nodeId:e,nodeName:t,concern:n,open:r,onClose:i}){let a=H(),o=je(),s=T(void 0),c=se(void 0),d=S(void 0),f=F({addonId:qt}),p=l(),m=ae(),h=u(),[g,_]=U(new Set),[v,y]=U(!1),[b,x]=U(null),[C,w]=U([]),[E,D]=U(null),O=Ut.find(e=>e.concern===n),k=B(()=>{let e=new Map;if(n===`pipeline`)for(let t of s.data??[])e.set(t.deviceId,t.agentNodeId);else if(n===`decode`)for(let t of c.data??[])e.set(t.deviceId,t.decoderNodeId);else for(let t of d.data??[])e.set(t.deviceId,t.nodeId);return e},[n,s.data,c.data,d.data]),A=B(()=>(o.data??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,currentNodeId:k.get(e.id)??null})),[o.data,k]),j=B(()=>Wt(A,e),[A,e]),M=Yt(f.data,Jt),N=n===`pipeline`?Kt(e,M??[],!1):{verdict:`ok`},[P,I]=U(!1);if(!r)return null;let ee=N.verdict===`block`,te=N.verdict===`warn`&&!P,L=g.size>0&&!v&&!ee&&!te,ne=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},re=j.length>0&&j.every(e=>g.has(e.deviceId)),ie=()=>{_(re?new Set:new Set(j.map(e=>e.deviceId)))},oe=async t=>{n===`pipeline`?await p.mutateAsync({deviceId:t,agentNodeId:e}):n===`decode`?await m.mutateAsync({deviceId:t,nodeId:e}):await h.mutateAsync({deviceId:t,nodeId:e})},ce=new Map(A.map(e=>[e.deviceId,e.name]));return z(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[W(`div`,{className:`absolute inset-0 bg-black/60`,onClick:i}),z(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col h-[80vh] rounded-xl border border-border bg-background shadow-2xl`,children:[z(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[z(`div`,{className:`min-w-0`,children:[z(`h2`,{className:`text-sm font-semibold text-foreground`,children:[`Batch assign `,O?.label??n,` → `,t]}),z(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:[`Pick the cameras whose `,O?.label.toLowerCase()??n,` should run on this node.`]})]}),W(`button`,{type:`button`,onClick:i,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,"aria-label":`Close`,children:W(Ge,{className:`h-4 w-4`})})]}),z(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[O?.advisory&&O.advisoryNote&&W(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 px-3 py-2 shrink-0`,children:z(`div`,{className:`flex items-start gap-2`,children:[W(qe,{className:`h-3.5 w-3.5 text-warning mt-0.5 shrink-0`}),W(`p`,{className:`text-[11px] text-warning`,children:O.advisoryNote})]})}),N.verdict!==`ok`&&W(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2 shrink-0`,children:z(`div`,{className:`flex items-start gap-2`,children:[W(qe,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),z(`div`,{className:`min-w-0`,children:[W(`p`,{className:`text-[11px] text-destructive`,children:N.reason}),N.verdict===`warn`&&z(`label`,{className:`mt-1 flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[W(`input`,{type:`checkbox`,checked:P,onChange:e=>I(e.target.checked),className:`accent-primary`}),`I understand — assign anyway`]})]})]})}),j.length>0&&z(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle shrink-0`,children:[W(`input`,{type:`checkbox`,"aria-label":`Select all`,checked:re,onChange:ie,className:`accent-primary`}),`Select all (`,j.length,`)`]}),W(`div`,{className:`flex-1 min-h-0 overflow-y-auto rounded-lg border border-border divide-y divide-border`,children:j.length===0?z(`div`,{className:`px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:[`No eligible cameras — all cameras are already assigned to `,t,`.`]}):j.map(e=>z(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground hover:bg-surface-hover cursor-pointer`,children:[W(`input`,{type:`checkbox`,"aria-label":`Select ${e.name}`,checked:g.has(e.deviceId),onChange:()=>ne(e.deviceId),className:`accent-primary`}),W(`span`,{className:`truncate`,children:e.name}),e.currentNodeId&&z(`span`,{className:`ml-auto text-[10px] text-foreground-subtle shrink-0`,children:[`on `,e.currentNodeId]})]},e.deviceId))}),(E!==null||C.length>0)&&z(`div`,{className:`space-y-1 text-[10px] shrink-0`,children:[E!==null&&E>0&&z(`p`,{className:`text-success`,children:[`Assigned `,E,` camera(s) to `,t,`.`]}),C.map(e=>z(`p`,{className:`text-destructive`,children:[e.name,`: `,e.message]},e.deviceId))]})]}),z(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[W(`span`,{className:`text-[10px] text-foreground-subtle`,children:v&&b?`${b.done} / ${b.total}…`:``}),z(`div`,{className:`flex items-center gap-2`,children:[W(`button`,{type:`button`,onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Close`}),z(`button`,{type:`button`,onClick:async()=>{let e=[...g];if(e.length===0)return;y(!0),w([]),D(null),x({done:0,total:e.length});let t=[],n=0;for(let r=0;r<e.length;r+=1){let i=e[r];try{await oe(i),n+=1}catch(e){t.push({deviceId:i,name:ce.get(i)??String(i),message:e instanceof Error?e.message:String(e)})}x({done:r+1,total:e.length})}y(!1),w(t),D(n),_(new Set),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})},disabled:!L,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50 disabled:cursor-not-allowed`,children:[v&&W(J,{className:`h-3.5 w-3.5 animate-spin`}),`Assign `,g.size,` to `,t]})]})]})]})]})}R();function Zt({nodeId:e,title:t}){let{data:n}=je(),{data:r}=T(void 0),i=B(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),a=B(()=>{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]=U(new Map);L(`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}))}),G(()=>{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=B(()=>{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?z(`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`]}):z(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[z(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[W(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),W(`span`,{className:`text-[10px] text-foreground-subtle`,children:c.length})]}),W(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>{let t=i.get(e.deviceId)??`#${e.deviceId}`,n=d(e.metrics.phase);return z(`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:[W(C,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),W(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),W(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),W(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}var Qt={key:`maxCameras`,type:`slider`,label:`Max cameras`,description:`Hard cap on cameras the balancer may assign to this node.`,min:1,max:64,step:1,showValue:!0,showStepper:!0,nullable:!0,nullLabel:`Unlimited`};R();var $t=350;function en(e){return typeof e==`number`&&e>0?Math.floor(e):null}function tn({value:e,pending:t,errorMessage:n,onCommit:i}){let[a,o]=U(e);G(()=>{o(e)},[e]);let s=_e(i);return s.current=i,G(()=>{if(a===e)return;let t=setTimeout(()=>s.current(a),$t);return()=>clearTimeout(t)},[a,e]),z(`div`,{className:`flex items-center gap-3 text-xs text-foreground`,children:[W(`div`,{className:`max-w-md flex-1`,children:W(r,{field:Qt,values:{maxCameras:a},disabled:t,onChange:(e,t)=>o(en(t))})}),t&&W(`span`,{className:`text-[10px] text-muted-foreground animate-pulse`,children:`Saving…`}),n&&z(`span`,{className:`text-[10px] text-destructive`,children:[`Save failed: `,n]})]})}R();var nn=[`pipeline-orchestrator`],rn=[`decoder`];function an(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 on({nodeId:e,refreshToken:t}){let r=H(),[i,a]=U(null),[c,l]=U(null),[u,d]=U(null),[f,p]=U(null),m=(o(void 0).data??[]).find(t=>t.id===e)?.name??e,h=n({nodeId:e},{refetchOnMount:`always`}),g=b({agentNodeId:e},{refetchOnMount:`always`}),_=()=>{r.invalidateQueries({queryKey:[[`addonSettings`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),r.invalidateQueries({queryKey:[[`pipelineExecutor`]]})},v=ue({onSuccess:_}),y=ie({onSuccess:_}),x=s({onSuccess:e=>{_(),p(`Reset done — regenerated default model: ${e.regeneratedModelId}`)}}),S=()=>{window.confirm(`Reset ${m} to hardware-aware defaults?\n\nThis clears the node's global pipeline seed and every per-camera step override, then re-seeds from the hardware default. Existing per-camera customisations on this node are lost.`)&&(p(null),x.mutate({nodeId:e}))},C=h.data??null,w=g.data,T=C?.selectedEngine.format??`coreml`,E=B(()=>C?k(C):[],[C]),O=B(()=>[{agentNodeId:e,engineLabel:T}],[e,T]),A=(e,t)=>{let n=w?.addonDefaults[e];return!an(C,e)?.models.some(e=>!!e.formats[T])||!n?{kind:`na`}:n.enabled?{kind:`enabled`,modelId:n.modelId??`Auto`}:{kind:`disabled`}},j=i&&C?an(C,i.addonId):null,N=t=>{let n=w?.addonDefaults[t]??null;a({addonId:t,agentNodeId:e}),l(n)},P=(t,n)=>{if(!w)return;let r=w.addonDefaults[t],i=an(C,t);if(!r&&!i)return;let a={enabled:n,modelId:r?.modelId??i?.defaultModelId??``,settings:r?.settings??{}};v.mutate({agentNodeId:e,defaults:{...w.addonDefaults,[t]:a}})},F=()=>{a(null),l(null)},I=()=>{!c||!i||!w||v.mutate({agentNodeId:e,defaults:{...w.addonDefaults,[i.addonId]:c}},{onSuccess:F})};if(h.isLoading||g.isLoading)return W(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading pipeline…`});if(h.error)return z(`div`,{className:`text-xs text-red-400`,children:[`Failed to load catalog: `,String(h.error)]});if(!C)return W(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog unavailable for this node (runner offline?).`});let te=i!==null&&j!==null&&c!==null,L=g.data?.maxCameras??null;return z(`div`,{className:`relative h-full w-full space-y-3`,children:[z(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[f&&W(`span`,{className:`text-emerald-400`,children:f}),x.isError&&W(`span`,{className:`text-red-400`,children:x.error instanceof Error?x.error.message:`Reset failed`}),W(`button`,{type:`button`,onClick:S,disabled:x.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 global pipeline seed + per-camera overrides and re-seed from the hardware default`,children:x.isPending?`Resetting…`:`Reset to default`})]}),W(Zt,{nodeId:e}),W(tn,{value:L,pending:y.isPending,errorMessage:y.isError?y.error instanceof Error?y.error.message:`Unknown error`:null,onCommit:t=>y.mutate({agentNodeId:e,maxCameras:t})}),W(at,{nodeId:e,addonIds:nn,level:`global`,sectionIds:rn}),z(`div`,{className:`flex items-center gap-2 text-xs`,children:[W(`span`,{className:`font-medium text-muted-foreground`,children:`Batch assign:`}),W(`button`,{type:`button`,onClick:()=>d(`pipeline`),className:`rounded border border-border bg-surface px-2 py-0.5 text-xs hover:bg-surface-hover`,children:`Pipeline…`}),W(`button`,{type:`button`,onClick:()=>d(`audio`),className:`rounded border border-border bg-surface px-2 py-0.5 text-xs hover:bg-surface-hover`,children:`Audio…`}),W(`button`,{type:`button`,onClick:()=>d(`decode`),className:`rounded border border-border bg-surface px-2 py-0.5 text-xs text-foreground-subtle hover:bg-surface-hover`,children:`Decode… (advisory)`})]}),u&&W(Xt,{nodeId:e,nodeName:m,concern:u,open:u!==null,onClose:()=>d(null)}),W(`div`,{className:te?`pr-[360px]`:``,children:E.length>0?W(D,{tree:E,agents:O,getCellState:A,onCellClick:N,selectedCell:i,onToggleEnabled:P}):W(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),W(M,{open:te,onClose:F,title:j?.name??``,subtitle:i?`${i.agentNodeId} · ${T}`:``,footer:z(V,{children:[W(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:F,children:`Cancel`}),W(`button`,{type:`button`,disabled:!c||!i||v.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:I,children:v.isPending?`Saving…`:`Save`})]}),children:j&&c&&i&&W(ee,{mode:`agent`,addon:j,agentDefault:c,agentNodeId:i.agentNodeId,engineFormat:T,onChangeAgentConfig:e=>l(e)})})]})}var sn=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],cn=`decoder-nodeav`;function ln({nodeId:e,refreshToken:t}){let{data:n}=o(void 0),r=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??cn,i=[...sn,r];return z(`div`,{className:`flex flex-col h-full`,children:[W(gt,{nodeId:e,refreshToken:t}),W(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:W(at,{nodeId:e,addonIds:i,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:W(At,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:W(on,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:W(Mt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:W(Ht,{nodeId:e,refreshToken:t})}]})})]})}var un=`pipeline-orchestrator`,dn=`recorder`,fn=`recordingNodeId`,pn=[`ingestNode`,`recordingNode`,`audioNode`],mn=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline for assigned cameras`},{key:`decode`,label:`Decode`,hint:`Decodes video frames locally (advisory placement)`},{key:`audio`,label:`Audio`,hint:`Handles audio codec + analysis work`},{key:`ingest`,label:`Ingest`,hint:`Terminates camera ingest streams`}];function hn(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function gn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function _n(e,t,n){let r=hn(e,t);return typeof r==`string`&&r.length>0?r:n}function vn(e,t,n){let r=hn(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function yn(e,t){let n=gn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function bn(e,t){let n=gn(e,t);return typeof n==`string`&&n.length>0?n:null}function xn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:`Audio`}function Sn(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:`Node that runs singleton audio work`}function Cn(e,t){return t===`detect`?e.pipeline:e[t]}function wn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}function Tn({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?Be:Ae;return z(`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:[W(u,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),W(`span`,{children:t})]})}R();function En({nodeId:e,value:t,pending:n,onCommit:r}){let[i,a]=U(t===null?``:String(t));G(()=>{a(t===null?``:String(t))},[t]);let o=()=>{let t=Number(i);r(e,Number.isFinite(t)&&t>0?Math.floor(t):null)};return W(`input`,{"aria-label":`Max cameras for ${e}`,type:`number`,min:0,step:1,placeholder:`∞`,value:i,disabled:n,onChange:e=>a(e.target.value),onBlur:o,onKeyDown:e=>{e.key===`Enter`&&o()},className:`w-20 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`})}function Dn({node:e,emphasis:t=!1}){let n=e.isHub?Ie:q;return z(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[W(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),W(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),z(`div`,{className:`min-w-0`,children:[z(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[W(`span`,{className:`truncate`,children:e.name}),e.isHub&&W(I,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&W(I,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),W(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}R();function On({nodeId:e,value:t,detectedHosts:n,pending:r,onCommit:i}){let[a,o]=U(t??``);G(()=>{o(t??``)},[t]);let s=n[0],c=s===void 0?`auto-detect`:`auto: ${s}`,l=()=>{let t=a.trim();i(e,t.length>0?t:null)};return W(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:c,value:a,disabled:r,onChange:e=>o(e.target.value),onBlur:l,onKeyDown:e=>{e.key===`Enter`&&l()},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`})}R();function kn({nodeId:e,weight:t,totalWeight:n,pending:r,onCommit:i}){let[a,o]=U(String(t));G(()=>{o(String(t))},[t]);let s=n>0?t/n:0,c=2*Math.PI*15,l=c*s,u=()=>{let t=Number(a);i(e,Number.isFinite(t)&&t>0?t:null)};return z(`div`,{className:`flex items-center gap-3`,children:[z(`svg`,{viewBox:`0 0 40 40`,className:`h-11 w-11 shrink-0`,"aria-hidden":`true`,children:[W(`circle`,{cx:`20`,cy:`20`,r:15,fill:`none`,className:`stroke-border`,strokeWidth:`4`}),W(`circle`,{cx:`20`,cy:`20`,r:15,fill:`none`,className:`stroke-primary transition-all`,strokeWidth:`4`,strokeDasharray:`${l} ${c-l}`,strokeLinecap:`round`,transform:`rotate(-90 20 20)`}),z(`text`,{x:`20`,y:`23`,textAnchor:`middle`,className:`fill-foreground text-[9px] font-bold`,children:[Math.round(s*100),`%`]})]}),W(`input`,{"aria-label":`Detect weight for ${e}`,type:`number`,min:0,step:.25,value:a,disabled:r,onChange:e=>o(e.target.value),onBlur:u,onKeyDown:e=>{e.key===`Enter`&&u()},className:`w-20 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`})]})}function An({label:e,children:t}){return z(`div`,{className:`flex items-center justify-between gap-3`,children:[W(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function jn({node:e,actions:t}){return z(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[W(Dn,{node:e,emphasis:!0}),W(`div`,{className:`grid grid-cols-2 gap-2`,children:mn.map(n=>W(Tn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Cn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),z(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[W(An,{label:`Detect weight`,children:e.effective.pipeline?W(kn,{nodeId:e.id,weight:e.weight,totalWeight:t.totalWeight,pending:t.weightPending,onCommit:t.onCommitWeight}):W(`span`,{className:`text-[11px] italic text-foreground-subtle`,children:`Detect off`})}),W(An,{label:`Max cameras`,children:W(En,{nodeId:e.id,value:e.maxCameras,pending:t.maxCamerasPending,onCommit:t.onCommitMaxCameras})}),W(An,{label:`Reachable host`,children:W(On,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,pending:t.reachableHostPending,onCommit:t.onCommitReachableHost})})]})]})}function Mn(){return z(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[z(`span`,{className:`inline-flex items-center gap-1.5`,children:[W(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),z(`span`,{className:`inline-flex items-center gap-1.5`,children:[W(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),z(`span`,{className:`inline-flex items-center gap-1.5`,children:[W(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),z(`span`,{className:`inline-flex items-center gap-1.5`,children:[W(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function Nn({nodes:e,actions:t}){return W(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:z(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[W(`thead`,{children:z(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[W(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),mn.map(e=>W(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),W(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Detect weight`}),W(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Max cameras`}),W(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),W(`tbody`,{children:e.map(e=>z(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[W(`td`,{className:`px-4 py-3 align-middle`,children:W(Dn,{node:e})}),mn.map(n=>W(`td`,{className:`px-3 py-3 text-center align-middle`,children:W(Tn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Cn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),W(`td`,{className:`px-4 py-3 align-middle`,children:e.effective.pipeline?W(kn,{nodeId:e.id,weight:e.weight,totalWeight:t.totalWeight,pending:t.weightPending,onCommit:t.onCommitWeight}):W(`span`,{className:`text-[11px] italic text-foreground-subtle`,children:`Detect off`})}),W(`td`,{className:`px-4 py-3 align-middle`,children:W(En,{nodeId:e.id,value:e.maxCameras,pending:t.maxCamerasPending,onCommit:t.onCommitMaxCameras})}),W(`td`,{className:`px-4 py-3 align-middle`,children:W(On,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,pending:t.reachableHostPending,onCommit:t.onCommitReachableHost})})]},e.id))})]})})}function Pn({role:e,value:t,options:n,pending:r,onChange:i}){return z(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[W(`span`,{className:`text-xs font-semibold text-foreground`,children:xn(e)}),W(`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=>W(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),W(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:Sn(e)})]})}function Fn({roleValues:e,options:t,pending:n,lowFpsEnabled:r,fpsMinThreshold:i,onRoleChange:a,onLowFpsToggle:o}){return z(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[pn.map(r=>W(Pn,{role:r,value:e[r],options:t,pending:n,onChange:a},r)),z(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[W(`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`}),z(`span`,{className:`flex flex-col gap-0.5`,children:[W(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),z(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,r?`${i} fps`:`disabled`]})]})]})]})}R();function In(){let e=H(),{nodes:t}=oe(),n=ne(void 0),r=F({addonId:un}),i=F({addonId:dn}),a=()=>wn(e),o=A({onSuccess:a}),s=N({onSuccess:a}),c=ie({onSuccess:a}),l=te({onSuccess:a}),u=re({onSuccess:a}),d=B(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),f=B(()=>t.map(e=>{let t=d.get(e.id),n=pt(t,e.isHub),r=yn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:yn(t,`maxCameras`),reachableHost:bn(t,`reachableHost`),detectedHosts:e.localIps}}),[t,d]),p=f.filter(e=>e.effective.pipeline).reduce((e,t)=>e+t.weight,0),m={ingestNode:_n(r.data,`ingestNode`,`hub`),recordingNode:_n(i.data,fn,`hub`),audioNode:_n(r.data,`audioNode`,`hub`)},h=B(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...pn.map(e=>m[e]),...e])].filter(e=>e.length>0)},[t,m]),g=vn(r.data,`fpsMinThreshold`,0),_=g>0,v=n.isLoading||r.isLoading||i.isLoading,y=(e,t,n)=>{o.mutate({agentNodeId:e,[t]:n})},b=(e,t)=>{if(e===`recordingNode`){u.mutate({addonId:dn,patch:{[fn]:t}});return}u.mutate({addonId:un,patch:{[e]:t}})},x=e=>{u.mutate({addonId:un,patch:{fpsMinThreshold:e?Math.max(1,g):0}})},S={totalWeight:p,capabilityPending:o.isPending,weightPending:s.isPending,maxCamerasPending:c.isPending,reachableHostPending:l.isPending,onToggleCapability:y,onCommitWeight:(e,t)=>s.mutate({agentNodeId:e,detectWeight:t}),onCommitMaxCameras:(e,t)=>c.mutate({agentNodeId:e,maxCameras:t}),onCommitReachableHost:(e,t)=>l.mutate({agentNodeId:e,reachableHost:t})};return z(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[z(`header`,{className:`flex items-start justify-between gap-4`,children:[z(`div`,{className:`space-y-1`,children:[W(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),W(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, tune relative detection weights, set per-node camera ceilings, and choose the singleton cluster roles. Weights are relative shares across detect-capable nodes.`})]}),v&&W(J,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),z(`div`,{className:`space-y-3`,children:[W(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),W(Fn,{roleValues:m,options:h,pending:u.isPending,lowFpsEnabled:_,fpsMinThreshold:g,onRoleChange:b,onLowFpsToggle:x})]}),z(`div`,{className:`space-y-3`,children:[z(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[W(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),W(Mn,{})]}),f.length===0?W(`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.`}):z(V,{children:[W(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:f.map(e=>W(jn,{node:e,actions:S},e.id))}),W(`div`,{className:`hidden @3xl/clustertab:block`,children:W(Nn,{nodes:f,actions:S})})]})]})]})}R();var Ln=!1;function Rn({refreshToken:e}){let t=H(),{data:n}=o(void 0);B(()=>rt(n??[]),[n]);let r=O({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getDecoderAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return z(`div`,{className:`space-y-6`,children:[W(_t,{refreshToken:e}),W(In,{}),Ln,z(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[z(`div`,{className:`min-w-0`,children:[W(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),W(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · decoder · audio assignments per camera. Click the kebab to pin / unpin / move any role; expand the chevron for the per-camera broker drill-down.`})]}),z(`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:[W(ke,{className:`h-3.5 w-3.5`}),r.isPending?`Rebalancing…`:`Rebalance pipelines`]})]}),W(St,{mode:`cluster`})]})}var zn=[`pipeline-orchestrator`];function Bn({refreshToken:e}){return W(`div`,{className:`space-y-4 max-w-3xl`,children:W(at,{nodeId:`hub`,addonIds:zn,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.`})})}R();function Vn({refreshToken:e}){let t=H(),{data:n,isLoading:r}=ce(),[i,a]=U(null),[o,s]=U(``),[c,l]=U(``),u=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},d=g({onSuccess:()=>{a(null),u()}}),f=x({onSuccess:u}),p=e=>{a(e.id),s(e.name),l(e.description??``)},m=()=>{a(null),s(``),l(``)},h=()=>{if(!i)return;let e=c.trim();d.mutate({id:i,name:o.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return W(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let _=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return W(`div`,{className:`space-y-6 max-w-4xl`,children:z(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[z(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[z(`div`,{children:[W(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),W(`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.`})]}),z(`div`,{className:`text-[11px] text-foreground-subtle`,children:[_.length,` template`,_.length===1?``:`s`]})]}),_.length===0?z(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[W(Ne,{className:`h-6 w-6 opacity-40`}),W(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):W(`ul`,{className:`divide-y divide-border`,children:_.map(e=>{let t=i===e.id;return W(`li`,{className:`px-4 py-3 text-xs`,children:z(`div`,{className:`flex items-start gap-3`,children:[W(`div`,{className:`flex-1 min-w-0`,children:t?z(`div`,{className:`space-y-2`,children:[W(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:o,onChange:e=>s(e.target.value),placeholder:`Template name`,autoFocus:!0}),W(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:c,onChange:e=>l(e.target.value),placeholder:`Description (optional)`})]}):z(V,{children:[W(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&W(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),z(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,z(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),W(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?z(V,{children:[z(`button`,{type:`button`,onClick:h,disabled:d.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[W(Be,{className:`h-3 w-3`}),`Save`]}),z(`button`,{type:`button`,onClick:m,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[W(Ge,{className:`h-3 w-3`}),`Cancel`]})]}):z(V,{children:[W(`button`,{type:`button`,onClick:()=>p(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:W(Me,{className:`h-3 w-3`})}),W(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&f.mutate({id:e.id})},disabled:f.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:W(Je,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}R();function Hn(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 Un({nodeId:e,refreshToken:t}){let r=H(),i=xe().trpcClient,[a,s]=U(null),[c,l]=U(null),u=ne(void 0,{refetchOnMount:`always`});Ze([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`,`addon.updated`]);let d=o(void 0,{refetchOnMount:`always`}),f=B(()=>{let e=new Set;for(let t of d.data??[])t.isOnline&&e.add(t.id);return e},[d.data]),p=n({nodeId:e},{refetchOnMount:`always`}),m=B(()=>(u.data??[]).filter(e=>f.has(e.nodeId)).map(e=>e.nodeId),[u.data,f]),h=ye({enabled:m.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`schema-by-agent`,m.join(`,`),t],queryFn:async()=>{let e={};for(let t of m)try{e[t]=(await i.pipelineExecutor.getSchema.query({nodeId:t})).selectedEngine.format}catch{e[t]=`coreml`}return e}}),g=ue({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]}),r.invalidateQueries({queryKey:[[`pipelineExecutor`]]}),r.invalidateQueries({queryKey:[[`addonSettings`]]})}}),_=B(()=>p.data?k(p.data):[],[p.data]),v=B(()=>{let e=u.data??[],t=f;return(t.size===0?[]:e.filter(e=>t.has(e.nodeId))).map(e=>{let t=h.data?.[e.nodeId];return{agentNodeId:e.nodeId,engineLabel:t??`(engine unknown)`}})},[u.data,h.data,f]),y=(e,t)=>{let n=(u.data?.find(e=>e.nodeId===t))?.settings.addonDefaults[e],r=h.data?.[t];return!Hn(p.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=a?u.data?.find(e=>e.nodeId===a.agentNodeId)??null:null,x=a&&p.data?Hn(p.data,a.addonId):null,S=a?h.data?.[a.agentNodeId]??`coreml`:`coreml`,C=()=>{s(null),l(null)},w=(e,t)=>{let n=(u.data?.find(e=>e.nodeId===t))?.settings.addonDefaults[e]??null;s({addonId:e,agentNodeId:t}),l(n)},T=()=>{!c||!a||!b||g.mutate({agentNodeId:a.agentNodeId,defaults:{...b.settings.addonDefaults,[a.addonId]:c}},{onSuccess:C})};if(u.isLoading||p.isLoading)return W(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading agents…`});if(!p.data)return z(`div`,{className:`text-xs text-foreground-subtle`,children:[`Catalog unavailable for `,e,`.`]});let E=a!==null&&x!==null&&c!==null;return z(`div`,{className:`relative h-full w-full space-y-3`,children:[W(Zt,{title:`Cluster cameras`}),W(`div`,{className:E?`pr-[360px]`:``,children:_.length>0&&v.length>0?W(D,{tree:_,agents:v,getCellState:y,onCellClick:w,selectedCell:a}):W(`div`,{className:`text-xs text-foreground-subtle`,children:`No agents or catalog empty.`})}),W(M,{open:E,onClose:C,title:x?.name??``,subtitle:a?`${a.agentNodeId} · ${S}`:``,footer:z(V,{children:[W(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:C,children:`Cancel`}),W(`button`,{type:`button`,disabled:!c||!a||g.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:T,children:g.isPending?`Saving…`:`Save`})]}),children:x&&c&&a&&W(ee,{mode:`agent`,addon:x,agentDefault:c,agentNodeId:a.agentNodeId,engineFormat:S,onChangeAgentConfig:e=>l(e)})})]})}R();function Wn({types:n}){let r=H(),o=e(),{data:s}=p({}),c=i(),l=B(()=>c.data??[],[c.data]),[u,d]=U(null),[f,m]=U(null),h=()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})},g=t({onSuccess:h}),_=a({onSuccess:h}),v=B(()=>{let e=new Map;for(let t of s??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[s]),y=e=>{e.isDefault||g.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},b=async e=>{if(e.isDefault){await o({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 o({title:`Delete location "${e.displayName}"?`,message:`Removes the record; files on disk are untouched.`,confirmLabel:`Delete`,variant:`danger`})&&_.mutate({id:e.id})},x=n.map(e=>l.find(t=>t.id===e)).filter(e=>e!==void 0);return z(`div`,{className:`space-y-3`,children:[x.length===0?W(`p`,{className:`text-[11px] text-foreground-subtle italic`,children:`No storage locations declared for this purpose.`}):x.map(e=>W(Te,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:v.get(e.id)??[],onAdd:e=>d(e),onEdit:e=>m(e),onDelete:e=>{b(e)},onSetDefault:e=>y(e)},e.id)),u!==null&&W(Ee,{initialType:u,onClose:()=>d(null),onCreated:()=>{h(),d(null)}}),f!==null&&W(we,{location:f,onClose:()=>m(null),onSaved:()=>{h(),m(null)}})]})}R();var Gn=`pipeline-analytics`;function Kn(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 qn(){let e=H(),{data:t}=o(void 0),{data:n,isLoading:r}=F({addonId:Gn}),i=Kn(n),a=re({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),s=B(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return z(`div`,{className:`flex flex-col gap-6`,children:[z(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[W(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),W(`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.`}),z(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?W(J,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):W(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:Gn,patch:{postProcessingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:s.map(e=>W(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&W(J,{className:`h-4 w-4 animate-spin text-primary`})]})]}),z(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[W(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),W(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),W(Wn,{types:[`eventMedia`]})]})]})}R();var Jn=`recorder`;function Yn(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 Xn(){let e=H(),{data:t}=o(void 0),{data:n,isLoading:r}=F({addonId:Jn}),i=Yn(n,`recordingNodeId`,`hub`),a=re({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),s=B(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return z(`div`,{className:`flex flex-col gap-6`,children:[z(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[W(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Recording node`}),W(`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.`}),z(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?W(J,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):W(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:Jn,patch:{recordingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:s.map(e=>W(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&W(J,{className:`h-4 w-4 animate-spin text-primary`})]}),i!==`hub`&&z(`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`,` `,W(`span`,{className:`font-medium`,children:i}),`. If the auto-derived host doesn't work, set the recorder's`,W(`span`,{className:`font-medium`,children:` recordingHubHostname`}),` global setting.`]})]}),z(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[W(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Recordings folders`}),W(`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.`}),W(Wn,{types:[`recordings`,`recordingsLow`]})]})]})}R();var Zn=[{id:`assignments`,label:`Assignments`},{id:`pipeline`,label:`Pipeline`},{id:`events`,label:`Events`},{id:`recording`,label:`Recording`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`}];function Qn({refreshToken:e}){let[t,n]=U(`assignments`),{data:r}=o(void 0),i=r?.find(e=>e.isHub&&e.isOnline)?.id??r?.find(e=>e.isOnline)?.id??null;return z(`div`,{className:`flex flex-col h-full`,children:[z(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[W(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),W(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Assignments with live load, cluster-wide settings, pipeline template library, per-camera pipeline overrides.`})]}),W(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Zn.map(e=>W(`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))}),z(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&W(Rn,{refreshToken:e}),t===`pipeline`&&(i?W(Un,{nodeId:i,refreshToken:e}):W(`div`,{className:`text-xs text-foreground-subtle`,children:`No online node available — schema unreachable.`})),t===`events`&&W(qn,{}),t===`recording`&&W(Xn,{}),t===`settings`&&W(Bn,{refreshToken:e}),t===`templates`&&W(Vn,{refreshToken:e})]})]})}function $n(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`}R();var er={healthy:`bg-green-500`,idle:`bg-yellow-400`,error:`bg-red-500`},tr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function nr({health:e}){return W(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${er[e]}`,title:tr[e],"aria-label":tr[e],role:`img`})}function rr({selectedDeviceId:e,onSelect:t}){let{data:n}=je(),{data:r}=le({}),i=B(()=>{let e=new Map;for(let t of r??[])e.set(t.deviceId,t);return e},[r]),a=B(()=>(n??[]).filter(e=>e.isCamera).map(e=>{let t=i.get(e.id);return{deviceId:e.id,name:e.name,health:t===void 0?`idle`:$n(t)}}),[n,i]);return a.length===0?W(`div`,{className:`px-4 py-6 text-center text-[11px] text-foreground-subtle italic`,children:`No cameras found`}):W(`ul`,{className:`divide-y divide-border`,children:a.map(n=>{let r=n.deviceId===e;return W(`li`,{children:z(`button`,{type:`button`,onClick:()=>t(n.deviceId),className:[`w-full flex items-center gap-2.5 px-4 py-3 text-left transition-colors`,r?`bg-surface-active text-foreground`:`hover:bg-surface-hover text-foreground-subtle hover:text-foreground`].join(` `),"aria-pressed":r,children:[W(nr,{health:n.health}),z(`span`,{className:`flex-1 min-w-0`,children:[W(`span`,{className:`block truncate text-[12px] font-medium leading-tight`,children:n.name}),z(`span`,{className:`block text-[10px] text-foreground-subtle leading-tight mt-0.5`,children:[`#`,n.deviceId]})]})]})},n.deviceId)})})}var ir=300,ar=158,or={camera:0,source:1,broker:2,decoder:3,motion:4,detection:4,audio:4,recorder:4};function $(e){return or[e]*ir}function sr(e,t){return e===null||t===null?!1:e!==t}function cr(e){let t=e.profiles.reduce((e,t)=>e+t.subscribers,0),n=e.profiles.reduce((e,t)=>e+t.inFps,0),r=e.profiles.reduce((e,t)=>e+t.outFps,0);return`${t} subs · ${n.toFixed(1)}→${r.toFixed(1)} fps`}function lr(e){return`${e.actualFps.toFixed(1)} fps · q${e.queueDepth} · ${e.avgInferenceMs.toFixed(1)}ms`}function ur(e){return`shm ${e.shm.getFrameHits+e.shm.getFrameMisses>0?Math.round(e.shm.getFrameHits/(e.shm.getFrameHits+e.shm.getFrameMisses)*100):0}% hit`}function dr(e){let t=[],n=[],r=e.decoder===null?0:[e.motion,e.detection,e.audio,e.recording].filter(e=>e!==null).length,i=r>1?(r-1)/2*ar:0,a={id:`camera`,kind:`camera`,nodeId:null,data:{deviceId:e.deviceId},position:{x:$(`camera`),y:i}};t.push(a);let o={id:`source`,kind:`source`,nodeId:null,data:{streams:e.source.streams},position:{x:$(`source`),y:i}};t.push(o),n.push({id:`camera->source`,source:`camera`,target:`source`,crossNode:!1});let s=e.broker;if(s!==null){let e={id:`broker`,kind:`broker`,nodeId:null,data:{profiles:s.profiles,webrtcSessions:s.webrtcSessions,rtspRestream:s.rtspRestream},position:{x:$(`broker`),y:i}};t.push(e),n.push({id:`source->broker`,source:`source`,target:`broker`,crossNode:!1})}let c=e.decoder;if(c!==null){let r={id:`decoder`,kind:`decoder`,nodeId:c.nodeId,data:{nodeId:c.nodeId,formats:c.formats,sessionCount:c.sessionCount,shm:c.shm},position:{x:$(`decoder`),y:i}};t.push(r);let a=s===null?`source`:`broker`,o=s===null?void 0:cr(s),l=s===null?ur(c):o;n.push({id:`${a}->decoder`,source:a,target:`decoder`,crossNode:sr(null,c.nodeId),...l===void 0?{}:{label:l}});let u=0,d=e.motion;if(d!==null){let e={id:`motion`,kind:`motion`,nodeId:null,data:{enabled:d.enabled,fps:d.fps},position:{x:$(`motion`),y:u*ar}};t.push(e),n.push({id:`decoder->motion`,source:`decoder`,target:`motion`,crossNode:!1}),u++}let f=e.detection;if(f!==null){let e={id:`detection`,kind:`detection`,nodeId:f.nodeId,data:{nodeId:f.nodeId,engine:f.engine,phase:f.phase,configuredFps:f.configuredFps,actualFps:f.actualFps,queueDepth:f.queueDepth,avgInferenceMs:f.avgInferenceMs,provisioning:f.provisioning},position:{x:$(`detection`),y:u*ar}};t.push(e),n.push({id:`decoder->detection`,source:`decoder`,target:`detection`,crossNode:sr(c.nodeId,f.nodeId),label:lr(f)}),u++}let p=e.audio;if(p!==null){let e={id:`audio`,kind:`audio`,nodeId:p.nodeId,data:{nodeId:p.nodeId,enabled:p.enabled},position:{x:$(`audio`),y:u*ar}};t.push(e),n.push({id:`decoder->audio`,source:`decoder`,target:`audio`,crossNode:sr(c.nodeId,p.nodeId)}),u++}let m=e.recording;if(m!==null){let e={id:`recorder`,kind:`recorder`,nodeId:null,data:{mode:m.mode,active:m.active,storageBytes:m.storageBytes},position:{x:$(`recorder`),y:u*ar}};t.push(e),n.push({id:`decoder->recorder`,source:`decoder`,target:`recorder`,crossNode:!1})}}return{nodes:t,edges:n}}R();function fr(e){let{data:t,isLoading:n}=j({deviceId:e}),[r,i]=U(void 0);return G(()=>{t!==void 0&&i(t)},[t]),L(K.PipelineCameraMetricsSnapshot,t=>{let n=t.data;n.deviceId===e&&i(e=>e===void 0||e.detection===null?e:{...e,detection:{...e.detection,phase:n.metrics.phase,actualFps:n.metrics.actualFps,queueDepth:n.metrics.queueDepth,avgInferenceMs:n.metrics.avgInferenceTimeMs}})}),L(K.PipelineEngineProvisioning,e=>{let t=e.data;i(n=>{if(n===void 0||n.detection===null)return n;let r=n.detection.nodeId??n.assignment?.detectionNodeId??null;return r===null||e.source.type!==`node`||e.source.id!==r?n:{...n,detection:{...n.detection,provisioning:{state:t.state,error:t.error}}}})}),L(K.MotionAnalysis,t=>{t.source.type!==`device`||t.source.id!==e||i(e=>e===void 0||e.motion===null?e:{...e,motion:{...e.motion,enabled:!0}})}),L(K.StreamBrokerMetricsSnapshot,t=>{let n=t.data;n.deviceId===e&&i(e=>e===void 0||e.broker===null?e:{...e,broker:{...e.broker,profiles:e.broker.profiles.map(e=>e.profile===n.profile?{...e,subscribers:n.stats.encodedSubscribers+n.stats.decodedSubscribers,inFps:n.stats.inputFps,outFps:n.stats.decodeFps}:e)}})}),L(K.PipelineAudioInferenceResult,t=>{t.data.deviceId===e&&i(e=>e===void 0||e.audio===null?e:{...e,audio:{...e.audio,enabled:!0}})}),L(K.RecordingStarted,t=>{t.data.deviceId===e&&i(e=>e===void 0||e.recording===null?e:{...e,recording:{...e.recording,active:!0}})}),L(K.RecordingStopped,t=>{t.data.deviceId===e&&i(e=>e===void 0||e.recording===null?e:{...e,recording:{...e.recording,active:!1}})}),{status:r,isLoading:n}}function pr({data:e}){return z(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[W(X,{type:`source`,position:Y.Right}),z(`div`,{className:`flex items-center gap-2`,children:[W(`span`,{className:`h-2 w-2 rounded-full bg-green-500 shrink-0`,"aria-label":`healthy`}),z(`span`,{className:`text-sm font-semibold truncate`,children:[`Camera #`,e.deviceId]})]}),W(`div`,{className:`text-xs text-muted-foreground mt-1`,children:`source`})]})}function mr(e){return e>0?`bg-green-500`:`bg-yellow-500`}function hr({data:e}){let t=e.streams[0],n=e.streams.length;return z(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[W(X,{type:`target`,position:Y.Left}),W(X,{type:`source`,position:Y.Right}),z(`div`,{className:`flex items-center gap-2`,children:[W(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${mr(n)}`,"aria-label":n>0?`healthy`:`idle`}),W(`span`,{className:`text-sm font-semibold`,children:`Source`}),z(`span`,{className:`text-xs text-muted-foreground`,children:[n,` streams`]})]}),t!==void 0&&z(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[t.codec,` `,t.width,`×`,t.height,` `,t.fps,`fps`]})]})}function gr(e){return e>0?`bg-green-500`:`bg-yellow-500`}function _r({data:e}){let t=e.profiles.reduce((e,t)=>e+t.subscribers,0),n=e.profiles.length;return z(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[W(X,{type:`target`,position:Y.Left}),W(X,{type:`source`,position:Y.Right}),z(`div`,{className:`flex items-center gap-2`,children:[W(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${gr(t)}`,"aria-label":t>0?`healthy`:`idle`}),W(`span`,{className:`text-sm font-semibold`,children:`Broker`}),z(`span`,{className:`text-xs text-muted-foreground`,children:[n,` profiles`]})]}),z(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[t,` subs · WebRTC `,e.webrtcSessions,e.rtspRestream&&` · RTSP`]})]})}function vr(e){return e>0?`bg-green-500`:`bg-yellow-500`}function yr(e,t){let n=e+t;return n>0?Math.round(e/n*100):0}function br({data:e}){let t=yr(e.shm.getFrameHits,e.shm.getFrameMisses),n=e.offline===!0;return z(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2${n?` opacity-50`:``}`,children:[W(X,{type:`target`,position:Y.Left}),W(X,{type:`source`,position:Y.Right}),z(`div`,{className:`flex items-center gap-2`,children:[W(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${vr(e.sessionCount)}`,"aria-label":e.sessionCount>0?`healthy`:`idle`}),W(`span`,{className:`text-sm font-semibold`,children:`Decoder`}),z(`span`,{className:`text-xs text-muted-foreground`,children:[`@`,e.nodeId]}),n&&W(`span`,{className:`text-[9px] font-semibold px-1 py-0.5 rounded bg-destructive/10 text-destructive`,"aria-label":`offline`,children:`offline`})]}),z(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.formats.join(`, `),` · `,e.sessionCount,` sessions`]}),z(`div`,{className:`text-xs text-muted-foreground`,children:[`shm `,t,`% hit`]})]})}function xr(e){return e?`bg-green-500`:`bg-yellow-500`}function Sr({data:e}){return z(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[W(X,{type:`target`,position:Y.Left}),z(`div`,{className:`flex items-center gap-2`,children:[W(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${xr(e.enabled)}`,"aria-label":e.enabled?`enabled`:`disabled`}),W(`span`,{className:`text-sm font-semibold`,children:`Motion`})]}),z(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.enabled?`enabled`:`disabled`,` · `,e.fps,` fps`]})]})}function Cr(e){return e.provisioning.state===`failed`?`bg-red-500`:e.phase===`active`?`bg-green-500`:(e.phase,`bg-yellow-500`)}function wr(e){return e===`ready`?`bg-green-500 text-white`:e===`failed`?`bg-red-500 text-white`:`bg-yellow-500 text-white`}function Tr({data:e}){let t=e.offline===!0;return z(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[180px] px-3 py-2${t?` opacity-50`:``}`,children:[W(X,{type:`target`,position:Y.Left}),z(`div`,{className:`flex items-center gap-2`,children:[W(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${Cr(e)}`,"aria-label":e.phase}),W(`span`,{className:`text-sm font-semibold`,children:`Detection`}),z(`span`,{className:`text-xs text-muted-foreground`,children:[`@`,e.nodeId]}),t&&W(`span`,{className:`text-[9px] font-semibold px-1 py-0.5 rounded bg-destructive/10 text-destructive`,"aria-label":`offline`,children:`offline`})]}),z(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.engine.backend,`·`,e.engine.device,` · `,e.phase]}),z(`div`,{className:`text-xs text-muted-foreground`,children:[e.actualFps.toFixed(1),`/`,e.configuredFps,` fps · q`,e.queueDepth,` ·`,` `,e.avgInferenceMs.toFixed(1),`ms`]}),z(`div`,{className:`flex items-center gap-1 mt-1`,children:[W(`span`,{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded ${wr(e.provisioning.state)}`,"aria-label":`provisioning ${e.provisioning.state}`,children:e.provisioning.state}),e.provisioning.state===`failed`&&e.provisioning.error!==void 0&&W(`span`,{className:`text-[10px] text-red-500 truncate`,children:e.provisioning.error})]})]})}function Er(e){return e?`bg-green-500`:`bg-yellow-500`}function Dr({data:e}){let t=e.offline===!0;return z(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2${t?` opacity-50`:``}`,children:[W(X,{type:`target`,position:Y.Left}),z(`div`,{className:`flex items-center gap-2`,children:[W(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${Er(e.enabled)}`,"aria-label":e.enabled?`enabled`:`disabled`}),W(`span`,{className:`text-sm font-semibold`,children:`Audio`}),z(`span`,{className:`text-xs text-muted-foreground`,children:[`@`,e.nodeId]}),t&&W(`span`,{className:`text-[9px] font-semibold px-1 py-0.5 rounded bg-destructive/10 text-destructive`,"aria-label":`offline`,children:`offline`})]}),W(`div`,{className:`text-xs text-muted-foreground mt-1`,children:e.enabled?`enabled`:`disabled`})]})}function Or(e){return e.mode===`off`?`bg-red-500`:e.active?`bg-green-500`:`bg-yellow-500`}function kr(e){return e>=1073741824?`${(e/1073741824).toFixed(1)} GB`:`${(e/1048576).toFixed(1)} MB`}function Ar({data:e}){return z(`div`,{className:`border border-border rounded-lg bg-background shadow-sm min-w-[160px] px-3 py-2`,children:[W(X,{type:`target`,position:Y.Left}),z(`div`,{className:`flex items-center gap-2`,children:[W(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${Or(e)}`,"aria-label":e.active?`active`:e.mode===`off`?`off`:`inactive`}),W(`span`,{className:`text-sm font-semibold`,children:`Recorder`}),W(`span`,{className:`text-xs text-muted-foreground`,children:e.mode})]}),z(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[e.active?`active`:`inactive`,` · `,kr(e.storageBytes)]})]})}R();var jr={camera:pr,source:hr,broker:_r,decoder:br,motion:Sr,detection:Tr,audio:Dr,recorder:Ar},Mr={stroke:`#f59e0b`,strokeWidth:2},Nr={strokeWidth:1.5},Pr=`camstack-pipeline-flow-layout`,Fr=`Camera → Source → Broker → Decoder → Motion · Detection · Audio · Recorder`,Ir={padding:.2};function Lr({deviceId:e}){let{status:t,isLoading:n}=fr(e),{data:r}=o(void 0),i=B(()=>{let e=new Set;for(let t of r??[])t.isOnline||e.add(t.id);return e},[r]),{computedNodes:a,rfEdges:s}=B(()=>{if(t===void 0)return{computedNodes:[],rfEdges:[]};let e=dr(t);return{computedNodes:e.nodes.map(e=>({id:e.id,type:e.kind,position:{x:e.position.x,y:e.position.y},data:{...e.data,offline:e.nodeId!==null&&i.has(e.nodeId)}})),rfEdges:e.edges.map(e=>({id:e.id,source:e.source,target:e.target,animated:e.crossNode,style:e.crossNode?Mr:Nr,label:e.label}))}},[t,i]),{nodes:c,onNodesChange:l,resetLayout:u}=tt(`${Pr}:${e}`,a);return n?W(`div`,{className:`flex items-center justify-center h-full text-sm text-muted-foreground`,children:`Loading…`}):t===void 0?W(`div`,{className:`flex items-center justify-center h-full text-sm text-muted-foreground`,children:`No pipeline data`}):z(`div`,{className:`w-full h-full relative overflow-hidden`,children:[z(`div`,{className:`absolute top-2 left-2 z-10 max-w-[calc(100%-7rem)] rounded border border-border bg-background/90 px-2 py-1 backdrop-blur-sm`,children:[W(`div`,{className:`text-xs font-semibold text-foreground`,children:`Pipeline flow`}),W(`div`,{className:`text-[10px] text-muted-foreground truncate`,children:Fr})]}),W(`button`,{type:`button`,onClick:u,className:`absolute top-2 right-2 z-10 text-xs px-2 py-1 rounded border border-border bg-background hover:bg-muted`,title:`Restore the automatic layout, discarding dragged positions`,children:`Reset layout`}),z(nt,{nodes:c,edges:s,onNodesChange:l,nodesDraggable:!0,nodeTypes:jr,fitView:!0,fitViewOptions:Ir,minZoom:.2,proOptions:{hideAttribution:!0},children:[W($e,{gap:20,size:1}),W(Qe,{showInteractive:!1})]})]})}R();var Rr=`__cluster__`;function zr(e){return e===`cameras`?`cameras`:`nodes`}function Br(){let[e,t]=Ve(),n=zr(e.get(`view`)),r=e.get(`node`)??`__cluster__`,i=e.get(`camera`),a=i===null?null:parseInt(i,10),[o,s]=U(0),[c,l]=U(!1);return G(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Rr},{replace:!0})},[n,e,t]),z(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[z(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[z(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[W(`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`}),W(`button`,{type:`button`,onClick:()=>{let e={view:`cameras`};a!==null&&(e.camera=String(a)),t(e,{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),z(`button`,{type:`button`,onClick:()=>s(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[W(Pe,{className:`h-3.5 w-3.5`}),`Refresh`]})]}),z(`button`,{type:`button`,onClick:()=>l(e=>!e),"aria-expanded":c,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[z(`span`,{children:[c?`Hide`:`Show`,` `,n===`nodes`?`node list`:`camera list`]}),W(Ue,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),W(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?z(V,{children:[W(`aside`,{className:[c?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:W(ht,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:o})}),W(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?W(Qn,{refreshToken:o}):W(ln,{nodeId:r,refreshToken:o})})]}):z(V,{children:[W(`aside`,{className:[c?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:W(rr,{selectedDeviceId:a,onSelect:e=>{t({view:`cameras`,camera:String(e)},{replace:!0}),l(!1)}})}),W(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:a!==null&&Number.isFinite(a)&&!Number.isNaN(a)?W(Lr,{deviceId:a}):W(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Select a camera to view its pipeline flow`})})]})})]})}export{Br as PipelinePage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Fa as e,Na as t,Pa as n}from"./src-cK1rmJgB.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-CpsGl45o.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(e,{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(e=>{let r=I===e.id,i=e.shape.kind===`polygon`?ne:n;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(e.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 `,e.id]}),u(`span`,{className:`text-foreground-faint capitalize`,children:e.shape.kind})]}),u(`button`,{type:`button`,onClick:()=>ae(e.id),disabled:M,"aria-label":`Delete zone ${String(e.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(t,{className:`h-3.5 w-3.5`})})]},e.id)})}):null]}):u(`p`,{className:`${f} leading-relaxed`,children:`Loading the camera's privacy mask…`})})}):null}export{w as PrivacyMaskSettings};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Q as e,S as t,q as n,x as r}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as i}from"./radio-
|
|
1
|
+
import{Q as e,S as t,q as n,x as r}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as i}from"./radio-BXRkVjee.js";import{t as a}from"./server-CcpmRIQF.js";import{t as o}from"./wifi-Yyiz1n_M.js";import{V as s}from"./index-CdAVDEco.js";var c=s(`cctv`,[[`path`,{d:`M16.75 12h3.632a1 1 0 0 1 .894 1.447l-2.034 4.069a1 1 0 0 1-1.708.134l-2.124-2.97`,key:`ir91b5`}],[`path`,{d:`M17.106 9.053a1 1 0 0 1 .447 1.341l-3.106 6.211a1 1 0 0 1-1.342.447L3.61 12.3a2.92 2.92 0 0 1-1.3-3.91L3.69 5.6a2.92 2.92 0 0 1 3.92-1.3z`,key:`jlp8i1`}],[`path`,{d:`M2 19h3.76a2 2 0 0 0 1.8-1.1L9 15`,key:`19bib8`}],[`path`,{d:`M2 21v-4`,key:`l40lih`}],[`path`,{d:`M7 9h.01`,key:`19b3jx`}]]),l=s(`house`,[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`1d0kgt`}]]);e();var u={frigate:{icon:c,color:`#3b82f6`,label:`Frigate`},scrypted:{icon:a,color:`#a855f7`,label:`Scrypted`},reolink:{icon:i,color:`#06b6d4`,label:`Reolink`},homeassistant:{icon:l,color:`#22d3ee`,label:`Home Assistant`},rtsp:{icon:o,color:`#78716c`,label:`RTSP`},onvif:{icon:o,color:`#78716c`,label:`ONVIF`}},d={sm:`h-4 w-4`,md:`h-5 w-5`,lg:`h-6 w-6`},f={sm:`h-7 w-7`,md:`h-8 w-8`,lg:`h-10 w-10`};function p(e){let t=e.toLowerCase();return t.startsWith(`provider-`)?t.slice(9):t}function m(e){return u[p(e)]??{icon:c,color:`#78716c`,label:e}}function h(e){let t=p(e);return`/api/addon-assets/${e.toLowerCase().startsWith(`provider-`)?e:`provider-${t}`}/assets/icon.svg`}function g({type:e,size:i=`md`,showLabel:a}){let o=m(e),s=o.icon,[c,l]=n(!1),u=h(e);return t(`div`,{className:`flex items-center gap-2`,children:[r(`div`,{className:`flex items-center justify-center rounded-lg ${f[i]}`,style:{backgroundColor:`${o.color}15`},children:c?r(s,{className:d[i],style:{color:o.color}}):r(`img`,{src:u,alt:o.label,className:d[i],onError:()=>l(!0)})}),a&&r(`span`,{className:`text-xs font-medium text-foreground-subtle`,children:o.label})]})}export{g as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{An as e,En as t,Kt as n,Xt as r,Zt as i,gn as a,mn as o,on as s}from"./src-Dp6qXTLR.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-D2Hdt3_T.js";import{t as v}from"./refresh-cw-B3eKxMWT.js";import{D as y,F as b,N as x,V as S,i as C,o as w,x as T}from"./index-CpCNvkGK.js";import{t as E}from"./FormBuilder-BHrYFTqO.js";import{t as D}from"./BrokerForm-DxBh4Ab_.js";var O=S(`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),b=c(()=>{_.current!==null&&(clearInterval(_.current),_.current=null)},[]),x=c(async n=>{b(),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,b]),S=c((e,t)=>{b();let n=async()=>{try{let n=await L(e);if(n.phase===`captured`){b(),x(e);return}if(n.phase===`error`){b(),f.current&&u({kind:`error`,message:n.error??`Login proxy returned an error`,sessionId:e});return}if(n.phase===`cancelled`){b(),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)},[b,x]);g(()=>()=>{b(),p.current!==null&&R(p.current)},[b]);let C=async()=>{b(),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=()=>{b(),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(w,{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(T,{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(T,{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(T,{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(y,{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(T,{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:()=>{C()},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:t,onBack:a}){let[o,s]=m(e===B?`alexa-login`:`existing`),c=r({kind:e}),l=f(()=>V(c.data).filter(t=>t.kind===e),[c.data,e]),u=i(),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=n({}),S=()=>{g&&t(g)},C=async n=>{v.trim().length!==0&&t((await b.mutateAsync({kind:e,name:v.trim(),settings:n,...p===void 0?{}:{addonId:p}})).id)},w=e=>{e===`new`?_(null):b.reset(),s(e)};return d(`div`,{className:`space-y-4`,children:[d(`button`,{type:`button`,onClick:a,className:`inline-flex items-center gap-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[h(x,{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:()=>w(`alexa-login`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${o===`alexa-login`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Login interactively`}),h(`button`,{type:`button`,onClick:()=>w(`existing`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${o===`existing`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Use existing`}),h(`button`,{type:`button`,onClick:()=>w(`new`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${o===`new`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:e===B?`Paste cookie`:`Create new`})]}),o===`alexa-login`&&h(z,{onResolved:t,onCancel:a}),o===`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(T,{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:S,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`})})]}),o===`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=>{C(e).catch(()=>{})},onCancel:a,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:e,onClose:n,scope:r}){let i=s(),[a,o]=m(new Set),[l,u]=m(new Set),{data:p}=t({}),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(T,{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(!e)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(C,{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=o(),r=c(()=>{t(),n.mutate({})},[n,t]);g(()=>{!n.isPending&&!n.data&&r()},[]);let i=f(()=>(n.data?.groups??[]).filter(e=>e.candidates.length>0),[n.data]),a=f(()=>i.reduce((e,t)=>e+t.candidates.length,0),[i]);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&&i.length===0&&h(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:`No devices responded to the scan.`}),!n.isPending&&i.length>0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:[`Found `,a,` device`,a===1?``:`s`,` on the network.`]}),!n.isPending&&i.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:t,onAdopt:n,onReset:r}){let i=e({addonId:t.addonId}).data??null,[o,s]=m({}),l=a(),u=c(()=>{r(),l.mutate({addonId:t.addonId,params:o})},[l,t.addonId,o,r]),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(T,{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(e=>n(t.addonId,e))]})]})})}function J({label:e}){return d(`div`,{className:`flex flex-col items-center py-12`,children:[h(T,{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(w,{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{An as e,En as t,Kt as n,Xt as r,Zt as i,gn as a,mn as o,on as s}from"./src-cK1rmJgB.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-BuixOtcX.js";import{t as v}from"./refresh-cw-B_eIWqpa.js";import{D as y,F as b,N as x,V as S,i as C,o as w,x as T}from"./index-CdAVDEco.js";import{t as E}from"./FormBuilder-inLQWViM.js";import{t as D}from"./BrokerForm-B9Pyef82.js";var O=S(`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),b=c(()=>{_.current!==null&&(clearInterval(_.current),_.current=null)},[]),x=c(async n=>{b(),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,b]),S=c((e,t)=>{b();let n=async()=>{try{let n=await L(e);if(n.phase===`captured`){b(),x(e);return}if(n.phase===`error`){b(),f.current&&u({kind:`error`,message:n.error??`Login proxy returned an error`,sessionId:e});return}if(n.phase===`cancelled`){b(),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)},[b,x]);g(()=>()=>{b(),p.current!==null&&R(p.current)},[b]);let C=async()=>{b(),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=()=>{b(),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(w,{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(T,{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(T,{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(T,{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(y,{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(T,{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:()=>{C()},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:t,onBack:a}){let[o,s]=m(e===B?`alexa-login`:`existing`),c=r({kind:e}),l=f(()=>V(c.data).filter(t=>t.kind===e),[c.data,e]),u=i(),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=n({}),S=()=>{g&&t(g)},C=async n=>{v.trim().length!==0&&t((await b.mutateAsync({kind:e,name:v.trim(),settings:n,...p===void 0?{}:{addonId:p}})).id)},w=e=>{e===`new`?_(null):b.reset(),s(e)};return d(`div`,{className:`space-y-4`,children:[d(`button`,{type:`button`,onClick:a,className:`inline-flex items-center gap-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[h(x,{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:()=>w(`alexa-login`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${o===`alexa-login`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Login interactively`}),h(`button`,{type:`button`,onClick:()=>w(`existing`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${o===`existing`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:`Use existing`}),h(`button`,{type:`button`,onClick:()=>w(`new`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${o===`new`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:e===B?`Paste cookie`:`Create new`})]}),o===`alexa-login`&&h(z,{onResolved:t,onCancel:a}),o===`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(T,{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:S,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`})})]}),o===`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=>{C(e).catch(()=>{})},onCancel:a,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:e,onClose:n,scope:r}){let i=s(),[a,o]=m(new Set),[l,u]=m(new Set),{data:p}=t({}),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(T,{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(!e)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(C,{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=o(),r=c(()=>{t(),n.mutate({})},[n,t]);g(()=>{!n.isPending&&!n.data&&r()},[]);let i=f(()=>(n.data?.groups??[]).filter(e=>e.candidates.length>0),[n.data]),a=f(()=>i.reduce((e,t)=>e+t.candidates.length,0),[i]);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&&i.length===0&&h(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:`No devices responded to the scan.`}),!n.isPending&&i.length>0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:[`Found `,a,` device`,a===1?``:`s`,` on the network.`]}),!n.isPending&&i.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:t,onAdopt:n,onReset:r}){let i=e({addonId:t.addonId}).data??null,[o,s]=m({}),l=a(),u=c(()=>{r(),l.mutate({addonId:t.addonId,params:o})},[l,t.addonId,o,r]),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(T,{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(e=>n(t.addonId,e))]})]})})}function J({label:e}){return d(`div`,{className:`flex flex-col items-center py-12`,children:[h(T,{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(w,{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{Fr as e}from"./src-
|
|
1
|
+
import{Fr as e}from"./src-cK1rmJgB.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-CdAVDEco.js";import{t as i}from"./AdminPage-BwmGKnRf.js";import{t as a}from"./NodeAddonsSettingsPanel-Cpl4rjtk.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};
|