@camstack/addon-admin-ui 1.2.374 → 1.2.376
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonAssetIcon-B3Nf3xlx.js → AddonAssetIcon-Cud5lR3B.js} +1 -1
- package/dist/assets/AddonIntegrationBody-BJoK1WtG.js +1 -0
- package/dist/assets/Addons-0I-H6wRy.js +4 -0
- package/dist/assets/{AdminTabs-BcE-Q0tO.js → AdminTabs-DW1QntZA.js} +1 -1
- package/dist/assets/AiProfiles-C7wn83G9.js +3 -0
- package/dist/assets/{BrokerForm-nF-ssRGh.js → BrokerForm-DcikWKOe.js} +1 -1
- package/dist/assets/{Build-CuTxMnpV.js → Build-BuOzMfAD.js} +4 -4
- package/dist/assets/{Calendars-B3HYs0JU.js → Calendars-BNl-qJy5.js} +1 -1
- package/dist/assets/Cluster-BxwWtO0x.js +1 -0
- package/dist/assets/ClusterStepModel-COyT2Do_.js +1 -0
- package/dist/assets/{CompositionEditor-BS_jFILf.js → CompositionEditor-BPUfy0TZ.js} +1 -1
- package/dist/assets/{CompositionEditorPage-d2NmF7hL.js → CompositionEditorPage-DxvwB3Qy.js} +1 -1
- package/dist/assets/Data-DL7sR8sH.js +1 -0
- package/dist/assets/DetectionIntelligence-BlLb-7CS.js +1 -0
- package/dist/assets/DeviceDetail-BMkuPSGu.js +2 -0
- package/dist/assets/{DeviceDoActionFields-C3lawEZ6.js → DeviceDoActionFields-PTEW3aqC.js} +1 -1
- package/dist/assets/{Devices-Bi_w3OGa.js → Devices-UQMmWlzH.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-CDnqLk2A.js → EmbedPlayerPage-CqIDyxIL.js} +1 -1
- package/dist/assets/Events-Bkn2VPhI.js +1 -0
- package/dist/assets/Identity-BsjuGmza.js +1 -0
- package/dist/assets/IntegrationDetail-Bagk_zPv.js +1 -0
- package/dist/assets/Integrations-DeSeAkOe.js +1 -0
- package/dist/assets/Integrations-DfhbAB6e.js +1 -0
- package/dist/assets/Locations-6d5dgF9l.js +3 -0
- package/dist/assets/{Logs-B_2PKsST.js → Logs-BQyecoHW.js} +1 -1
- package/dist/assets/MyAccess-SDzBPB3d.js +2 -0
- package/dist/assets/Network-DLpptopR.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-xFAQ20so.js → NodeAddonsSettingsPanel-9YJiVbGW.js} +1 -1
- package/dist/assets/Notifications-DnG1GBXi.js +1 -0
- package/dist/assets/{Plates-DcCJBtJq.js → Plates-C0I3ZvkE.js} +1 -1
- package/dist/assets/Recordings-Cvuw6tle.js +1 -0
- package/dist/assets/{ScanNetworkModal-DuIQym22.js → ScanNetworkModal-HuKKCk0w.js} +1 -1
- package/dist/assets/{Scenes-CgiGYYQy.js → Scenes-BYjFKWR7.js} +1 -1
- package/dist/assets/SessionsList-D_o5ldnu.js +2 -0
- package/dist/assets/{Showroom-CF1Qu7mr.js → Showroom-CQvaY_jP.js} +1 -1
- package/dist/assets/{System-DvOg-3a-.js → System-DcPLWIa8.js} +1 -1
- package/dist/assets/{Terminal-742YDR-F.js → Terminal-BWRiENjg.js} +5 -5
- package/dist/assets/{Viewer-0fo1xtXq.js → Viewer-Cft96zqh.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-u191sqrt.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Dd-TqyZf.js} +1 -1
- package/dist/assets/{authed-media-BaRjbtMq.js → authed-media-BrQwnIKg.js} +1 -1
- package/dist/assets/{debounced-invalidate-BOR3Wuyx.js → debounced-invalidate-B1K_w6Jo.js} +1 -1
- package/dist/assets/{device-integration-icon-5T12cCTw.js → device-integration-icon-DjhcO5Mw.js} +1 -1
- package/dist/assets/device-picker-model-CH-I2K5P.js +1 -0
- package/dist/assets/{face-bbox-BEIyL1yX.js → face-bbox-blnk4r2t.js} +1 -1
- package/dist/assets/{hostInit-C3KwadjS.js → hostInit-B4sEmccI.js} +1 -1
- package/dist/assets/index-BFj2tWAZ.js +4 -0
- package/dist/assets/index-Cs7_OxI3.css +2 -0
- package/dist/assets/location-owned-usage-Bi8xehnJ.js +1 -0
- package/dist/assets/{mf-entry-bootstrap-0-801b692c.js → mf-entry-bootstrap-0-2aaecc24.js} +2 -2
- package/dist/assets/mount-CH-I2K5P.js +1 -0
- package/dist/assets/notification-schedule-field-Ir3FHTsJ.js +1 -0
- package/dist/assets/remoteEntry-BVsqlEoo.js +1 -0
- package/dist/assets/{src-BTX2jfA7.js → src-D6dd9GMR.js} +16 -16
- package/dist/assets/{use-scenes-feed-DqzF-2_b.js → use-scenes-feed-nkW4bIU9.js} +1 -1
- package/dist/assets/{use-stationary-objects-BPLoE6ig.js → use-stationary-objects-DCqSZqWi.js} +1 -1
- package/dist/assets/useEventInvalidation-CH-I2K5P.js +1 -0
- package/dist/assets/{useNodeUrlSelection-s67zn-kU.js → useNodeUrlSelection-B0_QlYa-.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Ds3l678P.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-gh0BZGsc.js} +2 -2
- package/dist/index.html +6 -6
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/AddonIntegrationBody-BhLL7FoP.js +0 -1
- package/dist/assets/Addons-BX4RGdki.js +0 -4
- package/dist/assets/AiProfiles-Bu0zedHk.js +0 -3
- package/dist/assets/Cluster-CjOkqkYw.js +0 -1
- package/dist/assets/ClusterStepModel-B9pwzZ_M.js +0 -1
- package/dist/assets/Data-BjabNrW5.js +0 -1
- package/dist/assets/DetectionIntelligence-Drsxk61A.js +0 -1
- package/dist/assets/DeviceDetail-UKHvJh8G.js +0 -2
- package/dist/assets/Events-BoFeLCPi.js +0 -1
- package/dist/assets/Identity-riQA9K3r.js +0 -1
- package/dist/assets/IntegrationDetail-DYz00LhA.js +0 -1
- package/dist/assets/Integrations-Dj59hlDo.js +0 -1
- package/dist/assets/Integrations-x5pgUuxU.js +0 -1
- package/dist/assets/Locations-BveQrqYZ.js +0 -3
- package/dist/assets/MyAccess-C_eIFq1z.js +0 -2
- package/dist/assets/Network-CpuyFLhq.js +0 -1
- package/dist/assets/Notifications-DbeLe6-5.js +0 -1
- package/dist/assets/Recordings-1_ShsTqb.js +0 -1
- package/dist/assets/SessionsList-B-6hhNIP.js +0 -2
- package/dist/assets/device-picker-model-D8gNhpYS.js +0 -1
- package/dist/assets/index-BWu66tVw.js +0 -4
- package/dist/assets/index-MfQ6ok9_.css +0 -2
- package/dist/assets/location-owned-usage-B6a7vInb.js +0 -1
- package/dist/assets/mount-D8gNhpYS.js +0 -1
- package/dist/assets/notification-schedule-field-CyG86j1n.js +0 -1
- package/dist/assets/remoteEntry-CUnRKStz.js +0 -1
- package/dist/assets/useEventInvalidation-D8gNhpYS.js +0 -1
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{W as d,Z as f,_t as p,at as m,ct as h,st as g,vt as _}from"./player-overlays-B7T46vDu.js";import{Ad as v,An as y,Cn as b,Dn as x,En as S,Fn as C,Ft as w,Hd as T,Hl as E,Hu as D,I as O,In as k,It as A,Nn as j,Ou as M,Sn as N,Tn as P,Vu as F,Wd as I,ed as ee,en as te,gd as L,gn as ne,id as R,iu as re,kd as z,la as B,sf as V,td as H,tr as U,xn as W,zd as G}from"./src-BTX2jfA7.js";import{t as ie}from"./boxes-CBxcgWPC.js";import{t as ae}from"./send-Cx-d7NnY.js";import{Wn as K}from"./client-BBcQuaON.js";import{t as q}from"./useTranslation-Bc5yH9V9.js";import"./mount-D8gNhpYS.js";import{t as J}from"./AdminPage-BSFohA3i.js";import{t as oe}from"./AdminTabs-BcE-Q0tO.js";var se=_(`message-square-plus`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]);n();var ce=[`llm`,`listProfiles`],le=[`llm`,`listProfileKinds`],ue=[`llm`,`getDefaults`],de=[`llm`,`listRuntimeNodes`],fe=[`llm`,`listModelCatalog`],pe=[`llm`,`getUsage`],me=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],he=new Map(Object.entries({openai:I,anthropic:I,google:I,"openai-compatible":ee,"managed-local":T,"apple-foundation":T}));function ge(e){return he.get(e)??null}function Y(e){return typeof e==`string`&&e.length>0?e:void 0}function X(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);return Number.isFinite(t)?t:void 0}}function Z(e){return e===!0}function _e(e){return{model:e.model,baseUrl:e.baseUrl,apiKey:e.apiKey,supportsVision:e.supportsVision,temperature:e.temperature,topP:e.topP,topK:e.topK,maxTokens:e.maxTokens,contextLength:e.contextLength,systemPrompt:e.systemPrompt,timeoutMs:e.timeoutMs,connectTimeoutMs:e.connectTimeoutMs,firstTokenTimeoutMs:e.firstTokenTimeoutMs,idleTimeoutMs:e.idleTimeoutMs,retryEnabled:e.retry.enabled,retryMaxAttempts:e.retry.maxAttempts,toolsEnabled:e.toolsEnabled,contextSize:e.runtime?.contextSize,gpuLayers:e.runtime?.gpuLayers,threads:e.runtime?.threads,parallel:e.runtime?.parallel,idleStopMinutes:e.runtime?.idleStopMinutes,batchSize:e.runtime?.batchSize,ubatchSize:e.runtime?.ubatchSize,flashAttention:e.runtime?.flashAttention,mlock:e.runtime?.mlock,noMmap:e.runtime?.noMmap,cacheTypeK:e.runtime?.cacheTypeK,cacheTypeV:e.runtime?.cacheTypeV,extraArgs:xe(e.runtime?.extraArgs??[])}}var ve=[`f32`,`f16`,`q8_0`,`q5_1`,`q5_0`,`q4_1`,`q4_0`];function ye(e){return typeof e==`string`&&ve.includes(e)?e:void 0}function be(e){let t=[],n=``,r=null;for(let i of e){if(r!==null){i===r?r=null:n+=i;continue}if(i===`"`||i===`'`){r=i;continue}if(/\s/.test(i)){n!==``&&t.push(n),n=``;continue}n+=i}return n!==``&&t.push(n),t}function xe(e){return e.map(e=>/\s/.test(e)?`"${e}"`:e).join(` `)}var Se=[`--jinja`,`--cont-batching`];function Ce(e,t,n){let r=X(e.threads),i=X(e.batchSize),a=X(e.ubatchSize),o=ye(e.cacheTypeK),s=ye(e.cacheTypeV);return{nodeId:t,engine:`llama-cpp`,model:n,extraArgs:[...be(Y(e.extraArgs)??``)],contextSize:X(e.contextSize)??4096,gpuLayers:X(e.gpuLayers)??0,...r===void 0?{}:{threads:r},parallel:X(e.parallel)??1,...i===void 0?{}:{batchSize:i},...a===void 0?{}:{ubatchSize:a},flashAttention:Z(e.flashAttention),mlock:Z(e.mlock),noMmap:Z(e.noMmap),...o===void 0?{}:{cacheTypeK:o},...s===void 0?{}:{cacheTypeV:s},autoStart:Z(e.autoStart),idleStopMinutes:X(e.idleStopMinutes)??30}}function we(e,t,n,r,i){let a={id:n?.id??crypto.randomUUID(),name:t,kind:e,addonId:`ai`,enabled:n?.enabled??!0,model:Y(r.model)??n?.model??``,supportsVision:i?.supportsVision??Z(r.supportsVision),timeoutMs:X(r.timeoutMs)??K.totalMs,connectTimeoutMs:X(r.connectTimeoutMs)??K.connectMs,firstTokenTimeoutMs:X(r.firstTokenTimeoutMs)??K.firstTokenMs,idleTimeoutMs:X(r.idleTimeoutMs)??K.idleMs,retry:{enabled:Z(r.retryEnabled),maxAttempts:X(r.retryMaxAttempts)??1},toolsEnabled:Z(r.toolsEnabled)},o=Y(r.baseUrl),s=Y(r.apiKey),c=X(r.temperature),l=X(r.topP),u=X(r.topK),d=X(r.maxTokens),f=X(r.contextLength),p=Y(r.systemPrompt);return{...a,...o===void 0?{}:{baseUrl:o},...s===void 0?{}:{apiKey:s},...c===void 0?{}:{temperature:c},...l===void 0?{}:{topP:l},...u===void 0?{}:{topK:u},...d===void 0?{}:{maxTokens:d},...f===void 0?{}:{contextLength:f},...p===void 0?{}:{systemPrompt:p},...i===void 0?{}:{model:i.modelId,runtime:Ce(r,i.nodeId,i.model)}}}function Te(e){let t=new Map;for(let n of e){let e=t.get(n.addonId)??[];e.push(n),t.set(n.addonId,e)}return[...t.entries()].map(([e,t])=>({addonId:e,kinds:t}))}var Ee=`apple-system`;function De(e,t,n,r){return{...we(`apple-foundation`,e,t,n),model:Ee,supportsVision:!1,appleFoundation:{nodeId:r}}}var Oe={deviceNotEligible:{key:`ai.appleNotEligible`,text:`not eligible`,tone:`default`},appleIntelligenceNotEnabled:{key:`ai.appleIntelligenceOff`,text:`Apple Intelligence off`,tone:`warning`},modelNotReady:{key:`ai.appleModelNotReady`,text:`model downloading`,tone:`warning`},osTooOld:{key:`ai.appleOsTooOld`,text:`macOS too old`,tone:`default`},helperMissing:{key:`ai.appleHelperMissing`,text:`helper missing`,tone:`danger`},helperCrashed:{key:`ai.appleHelperCrashed`,text:`helper crashed`,tone:`danger`}};function ke(e){let t=t=>({nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleUnknown`,labelDefault:`unknown`,detail:t,tone:`default`});if(!e.reachable)return t(e.error??null);let n=e.apple;if(n===void 0)return t(null);switch(n.state){case`available`:return{nodeId:e.nodeId,selectable:!0,labelKey:`ai.appleAvailable`,labelDefault:`available`,detail:`macOS ${n.osVersion} · ${n.imageInput?`text + images`:`text only`}`,tone:`success`};case`unavailable`:{let t=Oe[n.reason];return{nodeId:e.nodeId,selectable:!1,labelKey:t.key,labelDefault:t.text,detail:n.detail,tone:t.tone}}case`unsupported-platform`:return{nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleNotMac`,labelDefault:`not a Mac`,detail:n.platform,tone:`default`};case`unknown`:return t(n.error)}}var Ae=2e3;function Q(e){return`${(e/1e9).toFixed(2)} GB`}function je(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Me({nodeId:e,value:t,onChange:n}){let{t:o}=q(),u=m(),[d,f]=s(``),[p,h]=s(null),[g,_]=s(!1),v=a({queryKey:fe,queryFn:()=>u.trpcClient.llm.listModelCatalog.query({})}),y=a({queryKey:[`llm`,`listNodeModels`,e],queryFn:()=>u.trpcClient.llm.listNodeModels.query({nodeId:e})}),b=c({mutationFn:e=>u.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{h(e),_(!1),e.ok&&n({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),x=c({mutationFn:t=>u.trpcClient.llm.installModel.mutate({nodeId:e,model:t}),onSuccess:()=>{_(!0),y.refetch()}}),S=a({queryKey:de,enabled:x.isPending,refetchInterval:x.isPending?Ae:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(t=>t.nodeId===e)?.status?.download,w=i(()=>{let t=(v.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${Q(e.sizeBytes)}`})),n=(y.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(t=>({value:`node:${t.file}`,label:o(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:t.file,size:Q(t.sizeBytes),node:e})})),r=p?.ok===!0?[{value:`custom`,label:`${p.label} · ${Q(p.totalBytes)}`}]:[];return[{value:``,label:o(`ai.selectModel`,`Select a model…`)},...t,...n,...r]},[v.data,y.data,p,e,o]),T=e=>{if(e===``){n(null);return}if(e===`custom`){if(p?.ok!==!0)return;n({model:p.model,modelId:p.label,supportsVision:p.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),r=v.data?.find(e=>e.id===t);n({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:r?.purpose===`vision`});return}let t=e.slice(5),r=y.data?.find(e=>e.file===t);r?.path!==void 0&&n({model:{kind:`path`,path:r.path},modelId:t,supportsVision:!1})},O=e=>{d.trim()!==``&&b.mutate({ref:d.trim(),...e===void 0?{}:{maxBytes:e}})};return r(`div`,{className:`space-y-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-model`,children:o(`ai.model`,`Model`)}),l(C,{id:`ai-model`,value:je(t),options:w,onChange:e=>T(e.target.value)})]}),r(`div`,{className:`rounded-md border border-border bg-surface-subtle px-3 py-2.5`,children:[l(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:o(`ai.hfTitle`,`Add a model from Hugging Face`)}),l(`p`,{className:`mb-2 text-[10px] leading-relaxed text-foreground-subtle`,children:o(`ai.hfHint`,`Paste a GGUF file URL, or type org/repo — add :QUANT (e.g. unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M) when the repo publishes more than one quantization.`)}),r(`div`,{className:`flex gap-2`,children:[l(E,{value:d,onChange:e=>f(e.target.value),placeholder:`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),O())}}),r(k,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||b.isPending,onClick:()=>O(),children:[b.isPending?l(L,{className:`h-3.5 w-3.5 animate-spin`}):l(D,{className:`h-3.5 w-3.5`}),o(`ai.hfCheck`,`Check`)]})]}),b.isError&&l(`p`,{className:`mt-2 text-[11px] text-danger`,children:b.error instanceof Error?b.error.message:o(`common.error`,`Error`)}),p?.ok===!1&&r(`div`,{className:`mt-2 rounded-md border border-danger/40 bg-danger/10 px-2.5 py-2`,children:[l(`p`,{className:`text-[11px] text-danger`,children:p.message}),p.candidates!==void 0&&p.candidates.length>0&&l(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:p.candidates.map(e=>l(`button`,{type:`button`,className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] text-foreground hover:border-primary/50`,onClick:()=>{let t=`${d.trim().split(`:`)[0]??``}:${e}`;f(t),b.mutate({ref:t})},children:e},e))}),p.requiredBytes!==void 0&&l(k,{size:`sm`,variant:`secondary`,type:`button`,className:`mt-2`,onClick:()=>O(p.requiredBytes),children:o(`ai.hfOverride`,`Install anyway ({{size}})`,{size:Q(p.requiredBytes)})})]}),p?.ok===!0&&r(`div`,{className:`mt-2 rounded-md border border-border bg-surface px-2.5 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[l(`span`,{className:`text-[11px] font-medium text-foreground`,children:p.label}),l(U,{variant:p.purpose===`vision`?`info`:`default`,children:p.purpose}),l(U,{variant:`default`,children:Q(p.totalBytes)})]}),p.extraFilenames.length>0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:o(`ai.hfExtras`,`Also downloads: {{files}}`,{files:p.extraFilenames.join(`, `)})}),r(`div`,{className:`mt-2 flex items-center gap-2`,children:[r(k,{size:`sm`,type:`button`,disabled:x.isPending||g,onClick:()=>x.mutate(p.model),children:[x.isPending?l(L,{className:`h-3.5 w-3.5 animate-spin`}):l(G,{className:`h-3.5 w-3.5`}),g?o(`ai.hfInstalled`,`Downloaded`):o(`ai.hfInstall`,`Download to {{node}}`,{node:e})]}),S!==void 0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:S.phase===`verifying`?o(`ai.hfVerifying`,`verifying {{file}}…`,{file:S.file}):o(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:S.file,index:S.fileIndex,count:S.fileCount,done:Q(S.downloadedBytes),total:S.totalBytes===void 0?``:` / ${Q(S.totalBytes)}`})})]}),x.isError&&l(`p`,{className:`mt-1.5 text-[11px] text-danger`,children:x.error instanceof Error?x.error.message:o(`common.error`,`Error`)})]})]})]})}function Ne({value:e,onChange:t}){let{t:n}=q(),i=m(),o=a({queryKey:de,queryFn:()=>i.trpcClient.llm.listRuntimeNodes.query({})});return r(`div`,{children:[l(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:n(`ai.appleNode`,`Mac that runs it`)}),o.isPending&&r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[l(L,{className:`h-3.5 w-3.5 animate-spin`}),n(`ai.appleAsking`,`Asking the nodes…`)]}),o.isError&&l(`p`,{className:`text-[11px] text-danger`,children:o.error instanceof Error?o.error.message:n(`ai.runtimesFailed`,`Failed to read runtime nodes`)}),o.isSuccess&&o.data.length===0&&l(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}),o.isSuccess&&o.data.length>0&&l(`div`,{role:`radiogroup`,className:`space-y-1.5`,children:o.data.map(i=>{let a=ke(i),o=a.nodeId===e;return r(`button`,{type:`button`,role:`radio`,"aria-checked":o,disabled:!a.selectable&&!o,onClick:()=>t(a.nodeId),className:`flex w-full items-center justify-between gap-2 rounded-md border px-3 py-2 text-left text-xs transition-colors disabled:cursor-not-allowed disabled:opacity-60 ${o?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[r(`span`,{className:`min-w-0`,children:[l(`span`,{className:`block font-medium text-foreground`,children:a.nodeId}),a.detail!==null&&l(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:a.detail})]}),l(U,{variant:a.tone,children:n(a.labelKey,a.labelDefault)})]},a.nodeId)})}),l(`p`,{className:`mt-1.5 text-[10px] leading-relaxed text-foreground-subtle`,children:n(`ai.appleHint`,`Text only for now — notification titles and summaries. Apple refuses prompts framed as surveillance; when it does, the next profile in the chain answers instead.`)})]})}n();function Pe({kind:e,className:t}){let n=ge(e.kind);return n===null?l(`span`,{className:t,children:e.icon}):l(n,{className:t})}function Fe({kinds:e,onPick:t,onCancel:n}){let{t:a}=q(),o=i(()=>Te(e),[e]);return l(W,{open:!0,onOpenChange:e=>!e&&n(),children:r(b,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(S,{children:l(x,{children:a(`ai.chooseKind`,`Choose a profile type`)})}),r(N,{className:`space-y-4 pr-1`,children:[o.length===0&&l(`p`,{className:`text-xs text-foreground-subtle`,children:a(`ai.noKinds`,`No AI provider is installed.`)}),o.map(e=>r(`div`,{children:[l(`div`,{className:`mb-1.5 text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:e.addonId}),l(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:e.kinds.map(n=>r(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs transition-colors hover:border-primary/50 hover:bg-surface-hover`,children:[l(Pe,{kind:n,className:`h-5 w-5 text-foreground-subtle`}),l(`span`,{className:`font-medium text-foreground`,children:n.label})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]}),l(P,{children:l(k,{size:`sm`,variant:`secondary`,type:`button`,onClick:n,children:a(`common.cancel`,`Cancel`)})})]})})}function Ie({kind:e,existing:t,onSave:n,onCancel:a,saving:c,error:u}){let{t:d}=q(),f=e.kind===`managed-local`,p=e.kind===`apple-foundation`,[m,h]=s(t?.appleFoundation?.nodeId??null),[g,_]=s(t?.name??e.label),[v,y]=s(()=>t===null?{}:_e(t)),[C,w]=s(t?.runtime?.nodeId??`hub`),[T,D]=s(()=>t?.runtime===void 0?null:{model:t.runtime.model,modelId:t.model,supportsVision:t.supportsVision}),A=i(()=>be(Y(v.extraArgs)??``),[v.extraArgs]),j=()=>{if(p){if(m===null)return;n(De(g,t,v,m));return}if(!f){n(we(e.kind,g,t,v));return}T!==null&&n(we(e.kind,g,t,v,{nodeId:C,model:T.model,modelId:T.modelId,supportsVision:T.supportsVision}))},M=c||g.trim()===``||f&&T===null||p&&m===null;return l(W,{open:!0,onOpenChange:e=>!e&&a(),children:r(b,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(S,{children:r(x,{className:`flex items-center gap-2`,children:[l(Pe,{kind:e,className:`h-4 w-4 text-foreground-subtle`}),t===null?d(`ai.newProfile`,`New {{kind}} profile`,{kind:e.label}):d(`ai.editProfile`,`Edit {{name}}`,{name:t.name})]})}),r(N,{className:`space-y-3 pr-1`,children:[u!==null&&l(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:u}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-profile-name`,children:d(`ai.name`,`Name`)}),l(E,{id:`ai-profile-name`,value:g,onChange:e=>_(e.target.value),placeholder:e.label})]}),f&&r(o,{children:[l(O,{selectedNodeId:C,onSelect:w,label:d(`ai.runtimeNode`,`Runtime node`),alwaysShow:!0}),l(Me,{nodeId:C,value:T,onChange:D}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-extra-args`,children:d(`ai.extraArgs`,`Additional llama-server arguments`)}),l(E,{id:`ai-extra-args`,value:Y(v.extraArgs)??``,onChange:e=>y({...v,extraArgs:e.target.value}),placeholder:Se.join(` `)}),A.length>0&&l(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:A.map((e,t)=>l(U,{variant:`default`,children:e},`${e}-${String(t)}`))}),l(`p`,{className:`mt-1 text-[10px] leading-relaxed text-foreground-subtle`,children:d(`ai.extraArgsHint`,`Flags this form does not already own. Vision models generally need --jinja; some language-only models do not like it. Context size, GPU layers, parallel slots, flash attention and the KV-cache types are set in the fields below — repeating one here is rejected at start.`)})]})]}),p&&l(Ne,{value:m,onChange:h}),l(ne,{schema:e.configSchema,values:v,onChange:y}),t!==null&&l(`p`,{className:`text-[10px] text-foreground-subtle`,children:d(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)})]}),r(P,{children:[f&&T===null&&l(U,{variant:`warning`,children:d(`ai.pickModelFirst`,`pick a model`)}),p&&m===null&&l(U,{variant:`warning`,children:d(`ai.pickAppleNodeFirst`,`pick a Mac`)}),l(k,{size:`sm`,variant:`secondary`,type:`button`,onClick:a,children:d(`common.cancel`,`Cancel`)}),r(k,{size:`sm`,type:`button`,disabled:M,onClick:j,children:[c&&l(L,{className:`h-3.5 w-3.5 animate-spin`}),t===null?d(`ai.createProfile`,`Create profile`):d(`ai.saveChanges`,`Save changes`)]})]})]})})}n();function Le(e){return[{key:`name`,header:e.t(`ai.colProfile`,`Profile`),render:t=>{let n=e.kindByName.get(t.kind);return r(`span`,{className:`flex items-center gap-2`,children:[l(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface`,title:n?.label??t.kind,children:n===void 0?l(`span`,{className:`text-xs text-foreground-subtle`,children:`?`}):l(Pe,{kind:n,className:`h-4 w-4 text-foreground-subtle`})}),r(`span`,{className:`min-w-0`,children:[l(`span`,{className:`block truncate text-sm font-medium text-foreground`,children:t.name}),e.testResult?.id===t.id&&l(`span`,{className:`block truncate text-[10px] ${e.testResult.ok?`text-success`:`text-danger`}`,children:e.testResult.text})]})]})}},{key:`kind`,header:e.t(`ai.colKind`,`Kind`),nowrap:!0,render:t=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.kindByName.get(t.kind)?.label??t.kind})},{key:`model`,header:e.t(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.model})},{key:`vision`,header:e.t(`ai.colVision`,`Vision`),align:`center`,nowrap:!0,render:t=>t.supportsVision?l(U,{variant:`info`,style:`outline`,children:e.t(`ai.vision`,`vision`)}):l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`})},{key:`node`,header:e.t(`ai.colNode`,`Node`),nowrap:!0,render:e=>e.runtime===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(U,{variant:`default`,children:e.runtime.nodeId})},{key:`enabled`,header:e.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:t=>l(te,{checked:t.enabled,onCheckedChange:()=>e.onToggle(t),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:t=>r(`span`,{className:`flex items-center justify-end gap-1`,children:[l(k,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onTest(t),title:e.t(`ai.test`,`Test`),children:e.testingId===t.id?l(L,{className:`h-3.5 w-3.5 animate-spin`}):l(ae,{className:`h-3.5 w-3.5`})}),l(k,{size:`sm`,variant:`ghost`,type:`button`,disabled:!e.kindByName.has(t.kind),onClick:()=>e.onEdit(t),title:e.t(`common.edit`,`Edit`),children:l(R,{className:`h-3.5 w-3.5`})}),l(k,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDelete(t),title:e.t(`common.delete`,`Delete`),children:l(g,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function Re(){let{t:e}=q(),t=m(),[n,o]=s({mode:`closed`}),[u,d]=s(null),[f,p]=s(null),h=a({queryKey:ce,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),g=a({queryKey:le,queryFn:async()=>(await t.trpcClient.llm.listProfileKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),_=()=>{h.refetch()},v=c({mutationFn:e=>t.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{o({mode:`closed`}),p(null),_()},onError:t=>p(t instanceof Error?t.message:e(`ai.saveFailed`,`Save failed`))}),b=c({mutationFn:e=>t.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:_}),x=c({mutationFn:e=>t.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>d({id:t.id,ok:e.ok,text:e.ok?`${e.text} (${String(e.usage.outputTokens)} tok, ${String(e.latencyMs)}ms)`:`${e.code}: ${e.message}`})}),S=h.data??[],C=i(()=>g.data??[],[g.data]),T=i(()=>{let e=new Map;for(let t of C)e.set(t.kind,t);return e},[C]);return r(J,{icon:M,title:e(`ai.profilesTitle`,`AI profiles`),subtitle:e(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),actions:r(k,{size:`sm`,type:`button`,onClick:()=>{p(null),o({mode:`pick-kind`})},children:[l(H,{className:`h-3.5 w-3.5`}),e(`ai.addProfile`,`Add profile`)]}),children:[h.isError&&l(j,{title:e(`ai.loadFailed`,`Failed to load profiles`),message:h.error instanceof Error?h.error.message:e(`common.error`,`Error`),onRetry:()=>void h.refetch()}),l(ze,{profiles:S}),h.isLoading&&l(`div`,{className:`flex items-center justify-center py-16`,children:l(L,{className:`h-6 w-6 animate-spin text-primary`})}),!h.isLoading&&S.length===0&&l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}),S.length>0&&l(y,{children:l(w,{columns:Le({kindByName:T,testResult:u,testingId:x.isPending?x.variables?.id??null:null,t:e,onToggle:e=>v.mutate({...e,enabled:!e.enabled,apiKey:`__redacted__`}),onTest:e=>x.mutate(e),onEdit:e=>{let t=T.get(e.kind);t!==void 0&&(p(null),o({mode:`form`,kind:t,profile:e}))},onDelete:e=>b.mutate(e)}),rows:S,rowKey:e=>e.id,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:`max-h-[60vh]`})}),n.mode===`pick-kind`&&l(Fe,{kinds:C,onCancel:()=>o({mode:`closed`}),onPick:e=>o({mode:`form`,kind:e,profile:null})}),n.mode===`form`&&l(Ie,{kind:n.kind,existing:n.profile,saving:v.isPending,error:f,onSave:e=>v.mutate(e),onCancel:()=>o({mode:`closed`})})]})}function ze({profiles:e}){let{t}=q(),n=m(),i=a({queryKey:ue,queryFn:()=>n.trpcClient.llm.getDefaults.query({})}),o=c({mutationFn:e=>n.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{i.refetch()}}),s=e=>(i.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,u=e=>e===`vision`?t(`ai.defaultVision`,`Default vision profile`):t(`ai.defaultText`,`Default text profile`);return l(y,{children:l(`div`,{className:`grid gap-4 p-4 sm:grid-cols-2`,children:me.map(({purpose:n,visionOnly:i})=>{let a=i?e.filter(e=>e.supportsVision):e,c=s(n),d=e.find(e=>e.id===c);return r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`llm-default-${n}`,children:u(n)}),r(`select`,{id:`llm-default-${n}`,"aria-label":u(n),className:`h-7 w-full rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:c,onChange:e=>o.mutate({purpose:n,profileId:e.target.value===``?null:e.target.value}),children:[l(`option`,{value:``,children:t(`ai.none`,`None`)}),c!==``&&!a.some(e=>e.id===c)&&l(`option`,{value:c,children:d?.name??c}),a.map(e=>r(`option`,{value:e.id,children:[e.name,` · `,e.model]},e.id))]}),c!==``&&d===void 0&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:t(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&l(`p`,{className:`mt-1 text-[10px] text-warning`,children:t(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:String(o.error)})]},n)})})})}n();var Be=5e3;function Ve(e){return`${(e/1e9).toFixed(1)} GB`}function He(){let{t:e}=q(),t=m(),n=a({queryKey:de,refetchInterval:Be,queryFn:()=>t.trpcClient.llm.listRuntimeNodes.query({})}),o=i(()=>[{key:`node`,header:e(`ai.colNode`,`Node`),render:e=>l(`span`,{className:`text-sm font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:e(`ai.colState`,`State`),nowrap:!0,render:t=>r(`span`,{className:`flex items-center gap-1.5`,children:[l(U,{variant:t.reachable?`success`:`danger`,children:t.reachable?t.status?.state??e(`ai.ready`,`ready`):e(`ai.unreachable`,`unreachable`)}),t.status?.downloadProgress!==void 0&&l(U,{variant:`info`,children:`${String(Math.round(t.status.downloadProgress*100))}%`})]})},{key:`model`,header:e(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:e(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.disk===void 0?`—`:Ve(e.disk.modelsBytes)})},{key:`apple`,header:e(`ai.colApple`,`Apple on-device`),render:t=>{let n=ke(t);return r(`span`,{className:`flex flex-col items-start gap-0.5`,children:[l(U,{variant:n.tone,children:e(n.labelKey,n.labelDefault)}),n.detail!==null&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n.detail})]})}},{key:`error`,header:e(`ai.colError`,`Error`),render:e=>e.error===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(`span`,{className:`text-[11px] text-danger`,children:e.error})}],[e]),s=n.data??[];return r(J,{icon:F,title:e(`ai.runtimesTitle`,`Managed runtimes`),subtitle:e(`ai.runtimesSubtitle`,`Nodes advertising the llm-runtime capability: what each has loaded, what it is downloading, and how much model data sits on its disk.`),children:[n.isError&&l(j,{title:e(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:n.error instanceof Error?n.error.message:e(`common.error`,`Error`),onRetry:()=>void n.refetch()}),s.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):l(y,{children:l(w,{columns:o,rows:s,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:A})})]})}var Ue=f(`/addon/ai/test-chat`),We=f(`/addon/ai/test-chat/chats`),Ge=6e5;function Ke(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),Ge)}function qe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Je(e){if(!qe(e))return null;let t=e.kind;return t!==`snapshot`&&t!==`track`||typeof e.mimeType!=`string`||typeof e.sizeBytes!=`number`?null:{kind:t,mimeType:e.mimeType,sizeBytes:e.sizeBytes,...typeof e.mediaKind==`string`?{mediaKind:e.mediaKind}:{},...typeof e.capturedAt==`number`?{capturedAt:e.capturedAt}:{},...typeof e.thumbnailBase64==`string`?{thumbnailBase64:e.thumbnailBase64}:{}}}var Ye=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function Xe(e){let t;try{t=JSON.parse(e)}catch{return null}if(!qe(t))return null;switch(t.kind){case`status`:{let e=Ye.find(e=>e===t.phase);return e===void 0?null:{kind:`status`,phase:e}}case`meta`:return typeof t.profileName!=`string`||typeof t.model!=`string`?null:{kind:`meta`,profileName:t.profileName,model:t.model,mediaSent:Je(t.mediaSent),streamed:t.streamed===!0,firstTokenTimeoutMs:typeof t.firstTokenTimeoutMs==`number`?t.firstTokenTimeoutMs:0};case`token`:return typeof t.text==`string`?{kind:`token`,text:t.text}:null;case`done`:return{kind:`done`,inputTokens:typeof t.inputTokens==`number`?t.inputTokens:0,outputTokens:typeof t.outputTokens==`number`?t.outputTokens:0,latencyMs:typeof t.latencyMs==`number`?t.latencyMs:0,truncated:t.truncated===!0,...typeof t.conversationId==`string`?{conversationId:t.conversationId}:{}};case`error`:return{kind:`error`,code:typeof t.code==`string`?t.code:`adapter-error`,message:typeof t.message==`string`?t.message:`the provider returned an error`};default:return null}}async function*Ze(e){let t=e.getReader(),n=new TextDecoder,r=``;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;r+=n.decode(i,{stream:!0});let a=r.indexOf(`
|
|
2
|
-
`);for(;a>=0;){let e=r.slice(0,a).trim();if(r=r.slice(a+1),e.length>0){let t=Xe(e);t!==null&&(yield t)}a=r.indexOf(`
|
|
3
|
-
`)}}let e=r.trim();if(e.length>0){let t=Xe(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function Qe(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function $e(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function et(e){return e.messages.map((t,n)=>{let r=t.mediaSent??void 0;return{id:`${e.id}-${String(n)}`,role:t.role,content:t.content,...t.attachment===void 0?{}:{attachmentRef:t.attachment,attachmentKind:t.attachment.kind},...r===void 0?{}:{attachment:r}}})}function tt(e){let t=e.sizeBytes<1024*1024?`${(e.sizeBytes/1024).toFixed(0)} KB`:`${(e.sizeBytes/(1024*1024)).toFixed(1)} MB`,n=[e.kind===`snapshot`?`camera snapshot`:`track best-shot`,t];return e.mediaKind!==void 0&&n.push(e.mediaKind),e.capturedAt!==void 0&&n.push(new Date(e.capturedAt).toLocaleTimeString()),n.join(` · `)}function nt(e,t){switch(e){case`resolving-image`:return`fetching the picture…`;case`connecting`:return`connecting to the provider…`;case`first-token-wait`:return t>0?`the model is loading / thinking — a cold load can take minutes (up to ${String(Math.round(t/1e3))}s)`:`the model is loading / thinking — a cold load can take minutes`;case`streaming`:return`answering…`}}n();var rt=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],it=360*60*1e3,at=40,ot=160,$={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function st(){let{t:n}=q(),o=m(),[c,d]=s(``),[f,_]=s(``),[b,x]=s(``),[S,w]=s([]),[T,D]=s(null),[O,A]=s(`none`),[M,N]=s(`throwaway`),[P,F]=s(null),[I,ee]=s([]),[te,L]=s(null),[ne,R]=s(null),z=t(null);u(()=>()=>z.current?.abort(),[]);let B=e(async()=>{let e=await fetch(We,{credentials:`same-origin`});e.ok&&ee((await e.json()).chats??[])},[]);u(()=>{M===`persistent`&&B()},[M,B]);let H=a({queryKey:ce,queryFn:()=>o.trpcClient.llm.listProfiles.query({})}),U=i(()=>(H.data??[]).filter(e=>e.enabled),[H.data]),W=U.find(e=>e.id===c)??null,G=ne!==null,ie=e(async(e,t)=>{let r=new AbortController;z.current=r,L(null);let i=Ke(W??{});R({...$,firstTokenTimeoutMs:i??0});let a=``,o=null,s,l=null,u=null,d;try{let n=await fetch(Ue,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:r.signal,body:JSON.stringify({profileId:c,messages:e,...f.trim()===``?{}:{system:f.trim()},...t===void 0?{}:{attachment:t},...i===void 0?{}:{firstTokenTimeoutMs:i},...M===`persistent`?{persist:!0,...P===null?{}:{conversationId:P}}:{}})});if(!n.ok||n.body===null){let e=await n.text().catch(()=>``);throw Error(e.length>0?e:`HTTP ${String(n.status)}`)}for await(let e of Ze(n.body))switch(e.kind){case`status`:R(t=>({...t??$,phase:e.phase}));break;case`meta`:o=e.mediaSent,s=e.model,R(t=>({...t??$,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:a+=e.text,R(e=>({...e??$,text:a}));break;case`done`:u={outputTokens:e.outputTokens,latencyMs:e.latencyMs},d=e.conversationId;break;case`error`:l=`${e.code}: ${e.message}`;break}}catch(e){r.signal.aborted||L(e instanceof Error?e.message:n(`common.error`,`Error`))}finally{z.current=null,R(null)}d!==void 0&&(F(d),B());let p=r.signal.aborted&&a.length>0;l===null&&a.length===0&&!p||w(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:l??a,...l===null?{}:{failed:!0},...o===null?{}:{attachment:o},...s!==void 0&&l===null?{model:s}:{},...u===null?{}:u}])},[M,P,W,c,B,f,n]),K=e(()=>{let e=b.trim();if(e===``||c===``||G)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...T===null?{}:{attachmentLabel:T.label,attachmentKind:T.ref.kind}},n=[...S,t];w(n),x(``);let r=T?.ref;D(null),A(`none`),ie(M===`persistent`&&P!==null?[{role:`user`,content:e}]:Qe(n),r)},[M,P,b,T,c,ie,G,S]),oe=()=>z.current?.abort(),le=()=>{z.current?.abort(),w([]),D(null),x(``),L(null),R(null),F(null)},ue=async e=>{z.current?.abort();let t=await fetch(`${We}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();F(e),w(et(n)),R(null),L(null)};return r(J,{icon:v,title:n(`ai.testTitle`,`Test chat`),subtitle:n(M===`persistent`?`ai.testSubtitlePersistent`:`ai.testSubtitle`,M===`persistent`?`Conversations are saved for you and can be reopened. Throwaway mode is still available.`:`A throwaway conversation with one profile. Attach a live camera snapshot or a recent track to check the model can actually read a picture. Nothing is saved — only the usage row.`),actions:r(k,{size:`sm`,variant:`secondary`,type:`button`,disabled:S.length===0&&T===null,onClick:le,children:[l(g,{className:`h-3.5 w-3.5`}),n(`ai.clearChat`,`Clear`)]}),children:[r(y,{className:`space-y-3 p-4`,children:[r(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-profile`,children:n(`ai.profile`,`Profile`)}),l(C,{id:`ai-test-profile`,value:c,onChange:e=>d(e.target.value),options:[{value:``,label:n(`ai.selectProfile`,`Select a profile…`)},...U.map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.supportsVision?` · vision`:``}`}))]}),U.length===0&&!H.isLoading&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:n(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-system`,children:n(`ai.systemPrompt`,`System prompt (optional)`)}),l(E,{id:`ai-test-system`,value:f,onChange:e=>_(e.target.value),placeholder:n(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l(k,{size:`sm`,variant:M===`throwaway`?`primary`:`outline`,type:`button`,onClick:()=>{N(`throwaway`),F(null)},children:n(`ai.throwawayMode`,`Throwaway`)}),l(k,{size:`sm`,variant:M===`persistent`?`primary`:`outline`,type:`button`,onClick:()=>N(`persistent`),children:n(`ai.saveConversation`,`Save conversation`)})]}),M===`persistent`&&r(`div`,{className:`space-y-2`,children:[l(`div`,{className:`flex items-center gap-2`,children:r(k,{size:`sm`,variant:`secondary`,type:`button`,onClick:le,children:[l(se,{className:`h-3.5 w-3.5`}),n(`ai.newChat`,`New chat`)]})}),I.length>0&&l(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:I.map(e=>l(`button`,{type:`button`,onClick:()=>void ue(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover ${e.id===P?`bg-primary/10`:``}`,children:l(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.title})},e.id))})]}),l(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`ai.streamNote`,`The answer streams as the model produces it. A cold model can take a while to load — the status line says which phase it is in.`)}),W!==null&&!W.supportsVision&&l(`p`,{className:`text-[10px] text-warning`,children:n(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]}),te!==null&&l(j,{title:n(`ai.chatFailed`,`The test call failed`),message:te}),l(ct,{turns:S,live:ne}),r(y,{className:`space-y-2 p-3`,children:[T!==null&&r(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-surface px-2.5 py-1.5`,children:[T.ref.kind===`snapshot`?l(p,{className:`h-3.5 w-3.5 text-foreground-subtle`}):l(V,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-foreground`,children:T.label}),l(k,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>D(null),children:l(re,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(k,{size:`sm`,variant:O===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>A(O===`snapshot`?`none`:`snapshot`),children:[l(p,{className:`h-3.5 w-3.5`}),n(`ai.attachSnapshot`,`Camera snapshot`)]}),r(k,{size:`sm`,variant:O===`track`?`primary`:`outline`,type:`button`,onClick:()=>A(O===`track`?`none`:`track`),children:[l(V,{className:`h-3.5 w-3.5`}),n(`ai.attachTrack`,`Recent track`)]})]}),O===`snapshot`&&l(dt,{onPick:e=>{D({ref:{kind:`snapshot`,deviceId:e.id},label:n(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:e.name})}),A(`none`)}}),O===`track`&&l(pt,{onPick:(e,t)=>{D({ref:{kind:`track`,trackId:e.trackId,deviceId:e.deviceId},label:n(`ai.trackOf`,`{{class}} on {{name}}`,{class:e.label??e.className,name:t})}),A(`none`)}}),r(`div`,{className:`flex items-center gap-2`,children:[l(E,{value:b,onChange:e=>x(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),K())},placeholder:n(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":n(`ai.message`,`Message`)}),G?r(k,{size:`sm`,variant:`secondary`,type:`button`,onClick:oe,children:[l(h,{className:`h-3.5 w-3.5`}),n(`ai.stop`,`Stop`)]}):r(k,{size:`sm`,type:`button`,disabled:b.trim()===``||c===``,onClick:K,children:[l(ae,{className:`h-3.5 w-3.5`}),n(`ai.send`,`Send`)]})]})]})]})}function ct({turns:e,live:t}){let{t:n}=q();return e.length===0&&t===null?l(`div`,{className:`py-12 text-center text-xs text-foreground-subtle`,children:n(`ai.chatEmpty`,`Pick a profile, optionally attach a camera snapshot or a recent track, and send a message. Nothing here is saved.`)}):l(y,{children:r(`div`,{className:`max-h-[50vh] space-y-2 overflow-y-auto p-3`,children:[e.map(e=>l(lt,{turn:e},e.id)),t!==null&&r(`div`,{className:`space-y-1`,children:[t.mediaSent!==null&&l(ut,{attachment:t.mediaSent}),t.text.length>0&&l(lt,{turn:{id:`live`,role:`assistant`,content:t.text},streaming:!0}),r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[l(L,{className:`h-3.5 w-3.5 animate-spin`}),nt(t.phase,t.firstTokenTimeoutMs)]})]})]})})}function lt({turn:e,streaming:t=!1}){let n=e.role===`user`,i=e.failed===!0?`border-danger/40 bg-danger/10`:`border-border bg-surface`;return l(`div`,{className:`flex ${n?`justify-end`:`justify-start`}`,children:r(`div`,{className:`max-w-[85%] rounded-lg border px-3 py-2 ${n?`border-primary/40 bg-primary/10`:i}`,children:[r(`p`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:[e.content,t&&l(`span`,{className:`ml-0.5 animate-pulse text-primary`,children:`▌`})]}),e.attachment!==void 0&&l(ut,{attachment:e.attachment}),e.attachmentLabel!==void 0&&r(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachmentKind===`track`?l(V,{className:`h-3 w-3`}):l(p,{className:`h-3 w-3`}),e.attachmentLabel]}),e.attachment!==void 0&&r(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachment.kind===`snapshot`?l(p,{className:`h-3 w-3`}):l(V,{className:`h-3 w-3`}),tt(e.attachment)]}),e.model!==void 0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`${e.model} · ${String(e.outputTokens??0)} tok · ${String(e.latencyMs??0)} ms`})]})})}function ut({attachment:e}){let t=$e(e);return t===null?null:l(`img`,{src:t,alt:`sent to the model`,className:`mt-1 max-h-32 rounded-md border border-border object-contain`})}function dt({onPick:e}){let{t}=q(),n=B({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?l(L,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):r.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noCameras`,`No camera found.`)}):l(`div`,{className:`grid max-h-56 grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-4`,children:r.map(t=>l(ft,{device:t,onPick:e},t.id))})}function ft({device:e,onPick:t}){let{src:n}=d(e.id,{width:ot});return r(`button`,{type:`button`,onClick:()=>t(e),className:`overflow-hidden rounded-md border border-border bg-surface text-left transition-colors hover:border-primary/50`,children:[l(`span`,{className:`block aspect-video w-full bg-background-elevated`,children:n!==null&&l(`img`,{src:n,alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),r(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[!e.online&&l(U,{variant:`warning`,children:`off`}),l(`span`,{className:`truncate text-[10px] text-foreground`,children:e.name})]})]})}function pt({onPick:e}){let{t}=q(),n=m(),o=B({isCamera:!0,projection:`slim`}),s=i(()=>(o.data??[]).map(e=>e.id),[o.data]),c=i(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),u=a({queryKey:[...rt,s.length],enabled:s.length>0,queryFn:()=>n.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...s],since:Date.now()-it,limit:at,projection:`slim`})});if(o.isLoading||u.isLoading)return l(L,{className:`h-4 w-4 animate-spin text-foreground-subtle`});let d=u.data?.tracks??[];return d.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noTracks`,`No track in the last 6 hours.`)}):l(`div`,{className:`max-h-56 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:d.map(t=>r(`button`,{type:`button`,onClick:()=>e(t,c.get(t.deviceId)??String(t.deviceId)),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover`,children:[l(V,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:t.label??t.className}),l(`span`,{className:`shrink-0 text-foreground-subtle`,children:c.get(t.deviceId)??t.deviceId}),l(`span`,{className:`shrink-0 text-foreground-subtle`,children:new Date(t.lastSeen).toLocaleTimeString()})]},t.trackId))})}n();var mt=1440*60*1e3,ht=[1,7,30,90];function gt(){let{t:e}=q(),t=m(),[n,o]=s(7),c=i(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(n-1)*mt},[n]),u=a({queryKey:ce,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),d=a({queryKey:[...pe,n],queryFn:()=>t.trpcClient.llm.getUsage.query({since:c})}),f=i(()=>{let e=new Map;for(let t of u.data??[])e.set(t.id,t.name);return e},[u.data]),p=i(()=>[{key:`day`,header:e(`ai.colDay`,`Day`),nowrap:!0,render:e=>e.day},{key:`consumer`,header:e(`ai.colConsumer`,`Consumer`),nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.consumer})},{key:`profile`,header:e(`ai.colProfile`,`Profile`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:f.get(e.profileId)??e.profileId})},{key:`calls`,header:e(`ai.colCalls`,`Calls`),align:`right`,nowrap:!0,render:e=>String(e.calls)},{key:`okErr`,header:e(`ai.colOkErr`,`OK / err`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:e.errorCalls>0?`text-danger`:void 0,children:`${String(e.okCalls)} / ${String(e.errorCalls)}`})},{key:`tokens`,header:e(`ai.colTokens`,`In / out tok`),align:`right`,nowrap:!0,render:e=>`${String(e.inputTokens)} / ${String(e.outputTokens)}`},{key:`latency`,header:e(`ai.colAvgMs`,`Avg ms`),align:`right`,nowrap:!0,render:e=>String(Math.round(e.avgLatencyMs))}],[f,e]),h=d.data??[];return r(J,{icon:z,title:e(`ai.usageTitle`,`Usage`),subtitle:e(`ai.usageSubtitle`,`Server-side rollup per day, consumer and profile — never raw call rows. Errors are counted, so a profile that always fails is visible here before a feature reports it.`),actions:l(`div`,{className:`w-40`,children:l(C,{"aria-label":e(`ai.window`,`Window`),value:String(n),options:ht.map(t=>({value:String(t),label:e(`ai.lastDays`,`Last {{days}} days`,{days:t})})),onChange:e=>o(Number(e.target.value))})}),children:[d.isError&&l(j,{title:e(`ai.usageFailed`,`Failed to read usage`),message:d.error instanceof Error?d.error.message:e(`common.error`,`Error`),onRetry:()=>void d.refetch()}),h.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noUsage`,`No AI calls in this window.`)}):l(y,{children:l(w,{columns:p,rows:h,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,mobileMode:`scroll`,maxBodyHeight:A})})]})}function _t(){let{t:e}=q();return l(`div`,{className:`flex flex-col p-4`,children:l(oe,{tabs:[{id:`profiles`,label:e(`ai.tabProfiles`,`Profiles`),icon:ie,content:l(Re,{})},{id:`runtimes`,label:e(`ai.tabRuntimes`,`Runtimes`),icon:F,content:l(He,{})},{id:`usage`,label:e(`ai.tabUsage`,`Usage`),icon:z,content:l(gt,{})},{id:`test`,label:e(`ai.tabTest`,`Test`),icon:v,content:l(st,{})}]})})}export{_t as AiProfilesPage,_t as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,V as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as d,gt as f,ht as p,st as m,vt as h}from"./player-overlays-B7T46vDu.js";import{$d as g,$l as _,Ac as v,Bo as y,Bt as b,Ds as x,Fs as S,Ft as C,Gs as w,Hd as T,Hl as E,Hu as D,Id as O,In as k,It as A,Jo as ee,Ju as j,Ko as te,Lt as M,M as ne,Oc as re,Qc as ie,Ql as ae,Sf as oe,Uu as se,Vt as ce,Vu as le,Xu as ue,Yo as de,Yu as fe,Zs as pe,_t as me,ar as he,gd as N,hn as ge,id as _e,ir as ve,iu as P,jc as ye,kc as be,la as xe,nf as F,or as Se,qn as I,qo as Ce,sf as we,sr as Te,vt as Ee,yu as L,zo as De}from"./src-BTX2jfA7.js";import{n as Oe,t as R}from"./format-size-DKWzYrUJ.js";import{Jr as ke,Kr as Ae,Zr as je,qr as Me}from"./client-BBcQuaON.js";import{t as z}from"./useTranslation-Bc5yH9V9.js";import{$ as Ne}from"./index-BWu66tVw.js";import{t as Pe}from"./NodeAddonsSettingsPanel-xFAQ20so.js";import{d as Fe,f as Ie,g as Le,m as Re,n as ze,t as Be}from"./node-color-map-ChrpDB9I.js";import{n as Ve,r as He,t as Ue}from"./useNodeUrlSelection-s67zn-kU.js";var We=h(`memory-stick`,[[`path`,{d:`M12 12v-2`,key:`fwoke6`}],[`path`,{d:`M12 18v-2`,key:`qj6yno`}],[`path`,{d:`M16 12v-2`,key:`heuere`}],[`path`,{d:`M16 18v-2`,key:`s1ct0w`}],[`path`,{d:`M2 11h1.5`,key:`15p63e`}],[`path`,{d:`M20 18v-2`,key:`12ehxp`}],[`path`,{d:`M20.5 11H22`,key:`khsy7a`}],[`path`,{d:`M4 18v-2`,key:`1c3oqr`}],[`path`,{d:`M8 12v-2`,key:`1mwtfd`}],[`path`,{d:`M8 18v-2`,key:`qcmpov`}],[`rect`,{x:`2`,y:`6`,width:`20`,height:`10`,rx:`2`,key:`1qcswk`}]]);n();var Ge=`system-config-cluster`;function Ke(){return l(ge,{trpc:d().trpcClient,addonId:`system-config`,nodeId:`hub`,sectionIds:[Ge],bare:!0})}function qe(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function Je(e){return e===`running`?`running`:e===`crashed`||e===`failed`?`error`:`stopped`}var Ye=[`trace`,`debug`,`info`,`warn`,`error`];function Xe({proc:e,nodeId:t,defaultExpanded:n,activePanel:i,onTogglePanel:a}){let o=e.services??[],s=o.length===1,[u,d]=c(s||n),[m,h]=c(null),[g,_]=c(`info`),v=e.name.includes(`(core)`),y=Ce(),b=ee(),x=de(),S=async e=>{h(e);try{await y.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{h(null)}},C=async()=>{h(e.name);try{await b.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{h(null)}},w=async n=>{let r=`${t}/${e.name}`;try{await x.mutateAsync({nodeId:r,level:n}),_(n)}catch(e){console.error(`Failed to set log level:`,e)}};return r(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[r(`div`,{role:s?void 0:`button`,tabIndex:s?void 0:0,onClick:s?void 0:()=>d(!u),onKeyDown:s?void 0:e=>{(e.key===`Enter`||e.key===` `)&&d(!u)},className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${s?``:`hover:bg-muted/40 cursor-pointer`}`,children:[s?l(`span`,{className:`h-3 w-3 shrink-0`}):l(u?f:p,{className:`h-3 w-3 text-muted-foreground shrink-0`}),v?l(le,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(we,{className:`h-3.5 w-3.5 text-warning shrink-0`}),l(`span`,{className:`text-xs font-semibold min-w-0 flex-1 basis-full truncate sm:basis-auto`,children:e.name}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:[`PID `,e.pid]}),l(ne,{status:Je(e.state),label:e.state}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:[e.cpuPercent,`% CPU`]}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:R(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:qe(e.uptimeSeconds)}),!v&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(ve,{children:[l(Te,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:g}),l(he,{align:`end`,className:`min-w-[70px] py-0.5`,children:Ye.map(e=>l(Se,{onClick:()=>w(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===g?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:C,disabled:m===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:l(j,{className:`h-3 w-3 ${m===e.name?`animate-spin`:``}`})})]})]}),u&&o.length>0&&l(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),l(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&r(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-info/10 text-info truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&r(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[l(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:l(se,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:l(ue,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>S(e.addonId),disabled:m===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:l(j,{className:`h-3 w-3 ${m===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(Ee,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(me,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),u&&o.length===0&&l(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function Ze({nodeId:e,processes:t}){let[n,r]=c(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):l(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>l(Xe,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}var Qe={system:0,managed:1,root:2};n();function $e(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function et(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function tt({nodeId:e}){let t=s(),n=_(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:i}=y({nodeId:e}),o=n?.processes??i,c=a(()=>o?[...o]:[],[o]),u=a(()=>[{key:`classification`,header:`Class`,sortValue:e=>Qe[e.classification],render:e=>l(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`root`?`bg-info/20 text-info`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})},{key:`pid`,header:`PID`,align:`right`,sortValue:e=>e.pid,render:e=>l(`span`,{className:`font-mono`,children:e.pid})},{key:`ppid`,header:`PPID`,align:`right`,sortValue:e=>e.ppid,render:e=>l(`span`,{className:`font-mono text-foreground-subtle`,children:e.ppid})},{key:`addonId`,header:`Addon`,sortValue:e=>e.addonId,render:e=>l(`span`,{className:`text-foreground-subtle text-[11px]`,children:e.addonId??`—`})},{key:`command`,header:`Command`,nowrap:!1,render:e=>l(`span`,{className:`font-mono text-[10px] text-foreground-subtle break-all`,children:et(e.command)})},{key:`cpuPercent`,header:`CPU%`,align:`right`,sortValue:e=>e.cpuPercent,render:e=>e.cpuPercent.toFixed(1)},{key:`memoryRssBytes`,header:`RSS`,align:`right`,sortValue:e=>e.memoryRssBytes,render:e=>R(e.memoryRssBytes)},{key:`uptimeSec`,header:`Uptime`,align:`right`,sortValue:e=>e.uptimeSec,render:e=>l(`span`,{className:`text-foreground-subtle`,children:$e(e.uptimeSec)})}],[]);return r(`div`,{className:`space-y-4`,children:[l(`div`,{className:`flex items-start justify-end gap-4`,children:r(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[l(fe,{className:`h-3 w-3`}),` Refresh`]})}),l(C,{columns:u,rows:c,rowKey:e=>e.pid,minWidthPx:880,mobileMode:`cards`,maxBodyHeight:A,emptyMessage:`Scanning…`})]})}var B={width:320,height:64},nt=.8,V=Math.ceil(8*nt-3)+1,H=B.width+34,U=B.height+V+1+11,rt=V+B.height+1+3+Math.ceil(8*nt),it=[1,2,5,10],at=[1,2,4,8,16,32,64,128,256,512,1024],ot=[1,1.5,2,2.5,3,4,5],W=[4,3,5,2],st=1e-9;function ct(e,t){if(!Number.isFinite(e)||e<=0)return!1;if(t===`bytes`){if(!Number.isInteger(e))return!1;let t=e/1024**Math.floor(Math.log(e)/Math.log(1024));return ot.some(e=>Math.abs(t-e)<st)}let n=e/10**Math.floor(Math.log10(e));return ot.some(e=>Math.abs(n-e)<st)}function lt(e,t,n){let r=0;for(let t of e)t!==null&&t>r&&(r=t);if(r<=t)return t;if(n===`bytes`){let e=1024**Math.floor(Math.log(r)/Math.log(1024));for(let t of at){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of it){let t=e*i;if(t>=r)return t}return 10*i}function ut(e,t){if(!Number.isFinite(e)||e<=0)return[];let n=W.find(n=>ct(e/n,t))??W[W.length-1],r=e/n,i=[];for(let e=1;e<=n;e++)i.push(r*e);return i}var dt=2.5;function ft(e){return e*dt}function G(e,t,n,r){if(e.length===0)return[];let i=e[0].atMs,a=e.at(-1).atMs-i,o=n<=0?1:n,s=r!==void 0&&r>0?r:null;return e.map((r,c)=>{let l=a>0?(r.atMs-i)/a*t.width:c/Math.max(1,e.length-1)*t.width,u=c>0?e[c-1]:void 0;return{x:l,y:r.value===null?null:t.height-Math.min(r.value,n)/o*t.height,gapBefore:s!==null&&u!==void 0&&r.atMs-u.atMs>s}})}function pt(e){let t=[],n=!1;for(let r of e){if(r.y===null){n=!1;continue}r.gapBefore&&(n=!1),t.push(`${n?`L`:`M`}${r.x.toFixed(1)},${r.y.toFixed(1)}`),n=!0}return t.join(` `)}function mt(e,t){let n=[],r=[],i=()=>{if(r.length<2){r=[];return}let e=r.map((e,t)=>`${t===0?`M`:`L`}${e.x.toFixed(1)},${e.top.toFixed(1)}`),t=[...r].reverse().map(e=>`L${e.x.toFixed(1)},${e.bottom.toFixed(1)}`);n.push(`${e.join(` `)} ${t.join(` `)} Z`),r=[]};for(let n=0;n<e.length;n++){let a=e[n],o=t[n];if(!a||!o||a.y===null||o.y===null){i();continue}(a.gapBefore||o.gapBefore)&&i(),r.push({x:a.x,top:a.y,bottom:o.y})}return i(),n.join(` `)}function ht(e,t,n=3){if(e.length<2||n<2)return[];let r=e[0].atMs,i=e.at(-1).atMs-r;if(i<=0)return[];let a=[];for(let e=0;e<n;e++){let o=e/(n-1);a.push({atMs:r+i*o,x:o*t.width,anchor:e===0?`start`:e===n-1?`end`:`middle`})}return a}function K(e){return e.length<2?0:Math.max(0,e.at(-1).atMs-e[0].atMs)}function gt(e){let t=[];for(let n=1;n<e.length;n++){let r=e[n];r.gapBefore&&t.push({fromX:e[n-1].x,toX:r.x})}return t}function _t(e,t){if(e.length===0)return null;let n=0,r=1/0;for(let i=0;i<e.length;i++){let a=Math.abs(e[i].x-t);a<r&&(r=a,n=i)}return n}n();var q={main:`var(--color-chart-series-a)`,gc:`var(--color-chart-series-b)`},J=B,vt={height:U};function yt({title:e,points:n,mainLabel:s,gcLabel:u,formatValue:d,emptyMessage:f,gapMs:p}){let m=i(),h=t(null),[g,_]=c(null),v=a(()=>{let e=n.map(e=>({atMs:e.atMs,value:e.main===null||e.gc===null?null:e.main+e.gc})),t=n.map(e=>({atMs:e.atMs,value:e.main})),r=lt(e.map(e=>e.value),25,`linear`),i=G(e,J,r,p),a=G(t,J,r,p),o=a.map(e=>({x:e.x,y:e.y===null?null:J.height,gapBefore:e.gapBefore}));return{max:r,ticks:ut(r,`linear`),upper:i,middle:a,base:o,gaps:gt(i),times:ht(e,J),spanMs:K(e)}},[n,p]),y=n.at(-1),b=g===null?void 0:n[g.index],x=b??y;return n.length===0||v.upper.every(e=>e.y===null)?l(X,{title:e,children:l(kt,{message:f})}):l(X,{title:e,legend:r(o,{children:[l(Ot,{color:q.main,label:s}),l(Ot,{color:q.gc,label:u})]}),readout:x&&x.main!==null&&x.gc!==null?r(o,{children:[b!==void 0&&l(Dt,{atMs:b.atMs,spanMs:v.spanMs}),l(Z,{color:q.main,text:d(x.main)}),l(Z,{color:q.gc,text:d(x.gc)})]}):null,children:r(`svg`,{ref:h,viewBox:`0 0 ${H} ${U}`,preserveAspectRatio:`none`,className:`w-full`,style:vt,role:`img`,"aria-label":`${e}: ${s} and ${u} over time`,onMouseLeave:()=>_(null),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();if(t.width===0)return;let n=(e.clientX-t.left)/t.width*H-34,r=_t(v.upper,n);r!==null&&_({index:r,xPx:v.upper[r].x})},children:[l(bt,{ticks:v.ticks,max:v.max,formatValue:d}),l(Et,{ticks:v.times,spanMs:v.spanMs}),r(`g`,{transform:`translate(34,${V})`,clipPath:`url(#${m})`,children:[l(`clipPath`,{id:m,children:l(`rect`,{x:0,y:0,width:J.width,height:J.height})}),l(xt,{spans:v.gaps}),l(`path`,{d:mt(v.middle,v.base),fill:q.main,fillOpacity:.85}),l(`path`,{d:mt(v.upper,v.middle),fill:q.gc,fillOpacity:.85,stroke:`var(--color-surface, transparent)`,strokeWidth:2}),l(`path`,{d:pt(v.upper),fill:`none`,stroke:q.gc,strokeWidth:2}),g!==null&&l(`line`,{x1:g.xPx,x2:g.xPx,y1:0,y2:J.height,stroke:`currentColor`,strokeWidth:1,className:`text-foreground-subtle`})]})]})})}function Y({title:e,points:n,formatValue:i,emptyMessage:s,axisFloor:u,axisScale:d=`linear`,gapMs:f}){let p=t(null),[m,h]=c(null),g=a(()=>{let e=lt(n.map(e=>e.value),u,d),t=G(n,J,e,f);return{max:e,ticks:ut(e,d),projected:t,gaps:gt(t),times:ht(n,J),spanMs:K(n)}},[n,u,d,f]),_=m===null?void 0:n[m.index],v=_??n.at(-1)??void 0;return n.length===0||g.projected.every(e=>e.y===null)?l(X,{title:e,children:l(kt,{message:s})}):l(X,{title:e,readout:v&&v.value!==null?r(o,{children:[_!==void 0&&l(Dt,{atMs:_.atMs,spanMs:g.spanMs}),l(Z,{color:q.main,text:i(v.value)})]}):null,children:r(`svg`,{ref:p,viewBox:`0 0 ${H} ${U}`,preserveAspectRatio:`none`,className:`w-full`,style:vt,role:`img`,"aria-label":e,onMouseLeave:()=>h(null),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();if(t.width===0)return;let n=(e.clientX-t.left)/t.width*H-34,r=_t(g.projected,n);r!==null&&h({index:r,xPx:g.projected[r].x})},children:[l(bt,{ticks:g.ticks,max:g.max,formatValue:i}),l(Et,{ticks:g.times,spanMs:g.spanMs}),r(`g`,{transform:`translate(34,${V})`,children:[l(xt,{spans:g.gaps}),l(`path`,{d:pt(g.projected),fill:`none`,stroke:q.main,strokeWidth:2}),m!==null&&l(`line`,{x1:m.xPx,x2:m.xPx,y1:0,y2:J.height,stroke:`currentColor`,strokeWidth:1,className:`text-foreground-subtle`})]})]})})}function bt({ticks:e,max:t,formatValue:n}){let i=t<=0?1:t;return l(`g`,{className:`text-foreground-subtle`,children:e.map(e=>{let t=V+J.height-e/i*J.height;return r(`g`,{children:[l(`line`,{x1:34,x2:34+J.width,y1:t,y2:t,stroke:`currentColor`,strokeWidth:.5,strokeOpacity:.3}),l(`text`,{x:0,y:t+3,fontSize:8,fill:`currentColor`,children:n(e)})]},e)})})}function xt({spans:e}){return e.length===0?null:l(`g`,{className:`text-foreground-subtle`,children:e.map(e=>l(`rect`,{x:e.fromX,y:0,width:Math.max(1,e.toX-e.fromX),height:J.height,fill:`currentColor`,fillOpacity:.12,children:l(`title`,{children:`No samples in this interval — nothing was measured, nothing is drawn.`})},`${e.fromX}-${e.toX}`))})}var St=10*6e4,Ct={hour:`2-digit`,minute:`2-digit`},wt={hour:`2-digit`,minute:`2-digit`,second:`2-digit`};function Tt(e,t){return new Date(e).toLocaleTimeString(void 0,t<St?wt:Ct)}function Et({ticks:e,spanMs:t}){return e.length===0?null:l(`g`,{className:`text-foreground-subtle`,children:e.map(e=>l(`text`,{x:34+e.x,y:rt,fontSize:8,textAnchor:e.anchor,fill:`currentColor`,children:Tt(e.atMs,t)},e.atMs))})}function Dt({atMs:e,spanMs:t}){return l(`span`,{className:`text-[10px] tabular-nums text-foreground-subtle`,children:Tt(e,t)})}function X({title:e,legend:t,readout:n,children:i}){return r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`flex items-baseline justify-between gap-2 mb-1`,children:[l(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:e}),l(`div`,{className:`flex items-center gap-2`,children:n})]}),i,t&&l(`div`,{className:`flex items-center gap-3 mt-1`,children:t})]})}function Ot({color:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1 text-[9px] text-foreground-subtle`,children:[l(`span`,{className:`inline-block h-2 w-2 rounded-[2px]`,style:{backgroundColor:e}}),t]})}function Z({color:e,text:t}){return r(`span`,{className:`inline-flex items-center gap-1 text-[11px] tabular-nums text-foreground`,children:[l(`span`,{className:`inline-block h-2 w-2 rounded-[2px]`,style:{backgroundColor:e}}),t]})}function kt({message:e}){return l(`div`,{className:`h-16 flex items-center justify-center rounded border border-dashed border-border text-[10px] text-foreground-subtle text-center px-2`,children:e})}function At(e,t){let n=e.at(-1);return n===void 0?[t]:t.atMs>n.atMs?[...e,t]:e.some(e=>e.atMs===t.atMs)?e:[...e,t].toSorted((e,t)=>e.atMs-t.atMs)}function jt(e,t,n,r){let i=e.get(t),a=At(i?.points??[],r);if(i!==void 0&&a===i.points)return e;let o=new Map(e);return o.set(t,{key:t,kind:n,points:a.slice(Math.max(0,a.length-720))}),o}function Mt(e,t,n){let r=e;for(let e of je(t,n))r=jt(r,e.key,e.kind,e.point);return r}function Nt(e,t){let n=e;for(let e of t)for(let t of e.points)n=jt(n,e.key,e.kind,t);return n}function Pt(e){let t=null;for(let n of e.values()){let e=n.points.at(-1);e!==void 0&&(t===null||e.atMs>t)&&(t=e.atMs)}return t}var Ft=12e4;function It(e,t){return e===null?!1:t-e>Ft}function Lt(e){let t=e=>{let t=e.points.at(-1);return t===void 0?-1:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.key.localeCompare(n.key):r})}function Rt(e){for(let t of e.values()){let e=t.points.at(-1);if(e&&e.cpuMainPercent!==null)return!0}return!1}var zt={key:`cpu`,dir:`desc`};function Bt(e){let t=e.points.at(-1);return t===void 0?null:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent}function Vt(e){return e.points.at(-1)?.memoryRssBytes??null}function Ht(e,t,n){let r=n.trim().toLowerCase();return r===``?!0:e.toLowerCase().includes(r)||t.toLowerCase().includes(r)}function Ut(e,t){return t===`memory`?Vt(e):Bt(e)}function Wt(e,t,n){let r=e.filter(e=>t.selectedKeys.size>0&&!t.selectedKeys.has(e.key)?!1:Ht(n(e),e.key,t.search)),i=(e,t)=>e.key.localeCompare(t.key);return[...r].toSorted((e,r)=>{if(t.sort.key===`name`){let a=n(e).localeCompare(n(r)),o=t.sort.dir===`asc`?a:-a;return o===0?i(e,r):o}let a=Ut(e,t.sort.key),o=Ut(r,t.sort.key);if(a===null&&o===null)return i(e,r);if(a===null)return 1;if(o===null)return-1;let s=t.sort.dir===`desc`?o-a:a-o;return s===0?i(e,r):s})}n();function Gt(e,n=720){let r=_(`metrics.node-processes-snapshot`,t=>t.nodeId===e),[i,a]=c(new Map),[o,s]=c(void 0),l=t(null),{data:d,isPending:f}=De({forNodeId:e,sinceMs:o,maxPoints:n});u(()=>{d!==void 0&&a(e=>{let t=Nt(e,d.series);return l.current=Pt(t),t})},[d]);let p=r?.timestamp;u(()=>{r==null||p===void 0||(It(l.current,p)&&s(l.current??0),a(e=>{let t=Mt(e,r.processes,p);return l.current=Pt(t),t}))},[p]),u(()=>{a(new Map),s(void 0),l.current=null},[e]);let m=0;for(let e of i.values())m=Math.max(m,e.points.length);return{series:Lt(i),sampleCount:m,threadSplitAvailable:Rt(i),loadingRetained:f,durable:d?.durable??null,bucketMs:d?.bucketMs??null,cadenceMs:d?.cadenceMs??null,retainedSamples:d?.retainedSamples??null}}var Kt=`__unclaimed__`;function qt(e,t){return{kind:e,deviceId:t,cpu:0,cpuKnown:!0,rss:0,rssKnown:!0,count:0,roles:new Set}}function Jt(e,t){return{key:e,kind:t.kind,deviceId:t.deviceId,cpuSeconds:t.cpuKnown?Math.round(t.cpu*100)/100:null,rssBytes:t.rssKnown?t.rss:null,unitCount:t.count,roles:[...t.roles].sort()}}function Yt(e,t){let n=new Map,r=new Set;for(let t of e){t.pid!==void 0&&r.add(t.pid);let e=t.deviceId!==null&&t.attribution!==`unattributable`,i=e?`device:${t.deviceId}`:`shared:${t.role}`,a=n.get(i)??qt(e?`camera`:`shared`,e?t.deviceId:null);a.count+=1,a.roles.add(t.role),t.cpuSeconds===void 0?a.cpuKnown=!1:a.cpu+=t.cpuSeconds,t.rssBytes===void 0?a.rssKnown=!1:a.rss+=t.rssBytes,n.set(i,a)}let i=[...n.entries()].map(([e,t])=>Jt(e,t));if(t===void 0)return i;let a=t.filter(e=>!r.has(e.pid));if(a.length===0)return i;let o=qt(`unclaimed`,null);for(let e of a)o.count+=1,o.rss+=e.memoryRssBytes;return o.cpuKnown=!1,[...i,Jt(Kt,o)]}var Xt=[{family:`decode`,attribution:`measured`,unit:`one forked decode-worker child per decode SESSION`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/session-decode/fork-decode-worker.ts:118`,`packages/addon-pipeline/src/session-decode/fork-decode-worker.ts:131`,`packages/addon-pipeline/src/pipeline-runner/index.ts:2765`,`packages/types/src/process/child-cost-registry.ts:188`]},{family:`transcode`,attribution:`measured`,unit:`one ffmpeg child per (camera, encode plan)`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/stream-broker/stream-broker/egress-transcode-manager.ts:960`,`packages/addon-pipeline/src/stream-broker/stream-broker/transcode-egress.ts:282`,`packages/addon-pipeline/src/stream-broker/stream-broker/transcode-egress.ts:324`,`packages/types/src/ffmpeg/sharing-key.ts:139`]},{family:`recording`,attribution:`measured`,unit:`one passthrough ffmpeg per (camera, profile)`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:33`,`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:217`,`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:279`,`packages/addon-pipeline/src/recorder/addon/recording-controller.ts:1710`]},{family:`detection`,attribution:`accounted`,unit:`a SHARED inference pool per (node, runtime, device) — no per-camera process`,perCamera:!1,wiredToday:!0,missingLink:"Nothing is missing for COUNTING — per-camera inference milliseconds, processed/shed frames and bytes-to-pool are already accumulated. What is missing is any basis for CPU seconds: `deviceId` reaches the pool as a diagnostic label and selects nothing, so cost can only ever be apportioned, never measured. Since 2026-08-27 the pool DECLARES this itself, contributing `deviceId: null` + `attribution: unattributable` rather than leaving an observer to infer it — the renunciation is data, and it is still refused by the chart gate.",evidence:[`packages/addon-pipeline/src/detection-pipeline/provider.ts:540`,`packages/addon-pipeline/src/detection-pipeline/engine/shared-inference-pool.ts:413`,`packages/types/src/interfaces/inference-engine.ts:24`,`packages/addon-pipeline/src/pipeline-runner/timing-sampler.ts:63`,`packages/addon-pipeline/src/pipeline-runner/runner.ts:353`,`packages/addon-pipeline/src/pipeline-runner/runner.ts:849`,`packages/addon-pipeline/src/pipeline-runner/frame-lazy-metrics.ts:100`]},{family:`streaming`,attribution:`measured`,unit:"one StreamBroker per `${deviceId}/${camStreamId}`, with an exact RTP ring byte counter",perCamera:!0,wiredToday:!1,missingLink:"The ffmpeg-backed ingest is now reported per camera, but that is the minority path. `rtpRingBytes` — the exact figure for the in-process case — is maintained on every push and drop and is still private and absent from `getStats()`. The three `EncodedRingBuffer`s track packets and duration and have no byte accumulator at all; the only byte figure they offer is `preRollBudgetBytes`, which is a BUDGET, not an occupancy.",evidence:[`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:2895`,`packages/addon-pipeline/src/stream-broker/rtsp/ffmpeg-push-reader.ts:189`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:494`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:498`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:2505`,`packages/addon-pipeline/src/stream-broker/stream-broker/pre-roll.ts:269`]}];function Zt(e){return e.attribution===`measured`&&e.wiredToday}function Qt(){let e=new Set;for(let t of Xt)Zt(t)&&e.add(t.family);return e}var $t=Qt();function en(e){return!$t.has(e.role)||e.deviceId===null?!1:e.attribution===`measured`}function tn(e){return`${e.addonId}${e.role}${e.unit}${e.pid??`-`}`}function nn(){return{cpuSeconds:0,cpuKnown:!0,rssBytes:0,rssKnown:!0,unitCount:0,roles:new Set}}function rn(e,t,n){if(t.cpuSeconds===void 0)return null;if(e===void 0)return t.startedAtMs===void 0||t.startedAtMs<n?null:t.cpuSeconds;if(e.cpuSeconds===void 0||e.startedAtMs===void 0||t.startedAtMs===void 0||e.startedAtMs!==t.startedAtMs)return null;let r=t.cpuSeconds-e.cpuSeconds;return r<0?null:r}function an(e){return Math.round(e*10)/10}function on(e,t){let n=t.atMs-e.atMs;if(n<=0)return[];let r=n/1e3,i=new Map;for(let t of e.entries)en(t)&&i.set(tn(t),t);let a=new Map,o=new Set;for(let n of t.entries){if(!en(n)||n.deviceId===null)continue;let t=tn(n);o.add(t);let r=a.get(n.deviceId)??nn();r.unitCount+=1,r.roles.add(n.role);let s=rn(i.get(t),n,e.atMs);s===null?r.cpuKnown=!1:r.cpuSeconds+=s,n.rssBytes===void 0?r.rssKnown=!1:r.rssBytes+=n.rssBytes,a.set(n.deviceId,r)}for(let[e,t]of i){if(o.has(e)||t.deviceId===null)continue;let n=a.get(t.deviceId);n!==void 0&&(n.cpuKnown=!1)}return[...a.entries()].map(([e,n])=>({deviceId:e,point:{atMs:t.atMs,cpuPercent:n.cpuKnown?an(n.cpuSeconds/r*100):null,rssBytes:n.rssKnown?n.rssBytes:null,unitCount:n.unitCount,roles:[...n.roles].toSorted()}}))}function sn(e,t){if(t.length===0)return e;let n=new Map(e);for(let e of t){let t=n.get(e.deviceId),r=t?.points.at(-1);if(r!==void 0&&e.point.atMs<=r.atMs)continue;let i=[...t?.points??[],e.point];n.set(e.deviceId,{deviceId:e.deviceId,points:i.slice(Math.max(0,i.length-720))})}return n}function cn(e){let t=e=>{for(let t=e.points.length-1;t>=0;t--){let n=e.points[t]?.cpuPercent;if(n!=null)return n}return-1};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.deviceId-n.deviceId:r})}function ln(e){let t=e.indexOf(`@`);return t===-1?{addonId:e,nodeId:null}:{addonId:e.slice(0,t),nodeId:e.slice(t+1)}}function un(e,t){let n=ln(e);return n.nodeId===null?t.isHub:n.nodeId===t.nodeId}function dn(e,t){return e.filter(e=>un(e.addonId,t))}n();function fn(e){let n=_(`metrics.node-processes-snapshot`,t=>t.nodeId===e.nodeId),r=ie(void 0,{staleTime:1/0,refetchOnWindowFocus:!1}),[i,a]=c(new Map),o=t(null),s=t(r.refetch);s.current=r.refetch;let l=n?.timestamp;u(()=>{l!==void 0&&s.current()},[l]),u(()=>{a(new Map),o.current=null},[e.nodeId,e.isHub]);let d=r.data,f=r.dataUpdatedAt;u(()=>{if(d===void 0||f===0)return;let t={atMs:f,entries:dn(d,e)},n=o.current;if(o.current=t,n===null)return;let r=on(n,t);r.length!==0&&a(e=>sn(e,r))},[d,f,e.nodeId,e.isHub]);let p=d===void 0?[]:dn(d,e),m=n?.processes,h=Yt(p,m);return{series:cn(i),unclaimed:h.find(e=>e.kind===`unclaimed`)??null,loading:r.isPending,error:r.error===null?null:r.error.message}}function pn(e){let t=new Map;for(let n of e){let e=n.name?.trim();e===void 0||e===``||t.set(n.id,e)}return t}var mn=25,hn=64*1024*1024,gn=1e4;function _n({scope:e,cadenceMs:t}){let{t:n}=z(),i=fn(e),{data:a=[]}=xe({isCamera:!0,projection:`slim`}),o=pn(a),s=ft(t??gn);return r(`section`,{className:`space-y-3`,children:[i.error!==null&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[l(L,{className:`h-3 w-3 mt-0.5 shrink-0`}),l(`span`,{children:n(`cameraLoad.readFailed`,`Could not read the load contributions: {{error}}. This is a failed read, NOT an idle cluster.`,{error:i.error})})]}),l(yn,{unclaimed:i.unclaimed}),i.series.length===0&&i.error===null&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:i.loading?n(`cameraLoad.loading`,`Reading what the addons report…`):n(`cameraLoad.waitingWindow`,`No per-camera window yet.`)}),l(`div`,{className:`space-y-3`,children:i.series.map(e=>r(`div`,{className:`rounded-lg border border-border p-3`,children:[r(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[l(vn,{deviceId:e.deviceId,name:o.get(e.deviceId)}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`cameraLoad.unitCount`,`{{count}} unit(s): {{roles}}`,{count:e.points.at(-1)?.unitCount??0,roles:(e.points.at(-1)?.roles??[]).join(`, `)})})]}),r(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[l(Y,{title:n(`cameraLoad.cpuTitle`,`CPU % of one core (delta)`),points:e.points.map(e=>({atMs:e.atMs,value:e.cpuPercent})),formatValue:e=>`${e.toFixed(1)}%`,axisFloor:mn,gapMs:s,emptyMessage:n(`cameraLoad.cpuUnavailable`,`No measurable window yet.`)}),l(Y,{title:n(`cameraLoad.memoryTitle`,`Memory RSS`),points:e.points.map(e=>({atMs:e.atMs,value:e.rssBytes})),formatValue:R,axisFloor:hn,axisScale:`bytes`,gapMs:s,emptyMessage:n(`cameraLoad.memoryUnavailable`,`No memory reported.`)})]})]},e.deviceId))})]})}function vn({deviceId:e,name:t}){let{t:n}=z();return t===void 0?l(`span`,{className:`text-xs font-medium text-foreground`,children:n(`cameraLoad.deviceLabel`,`Camera {{deviceId}}`,{deviceId:e})}):r(`span`,{className:`flex items-baseline gap-1.5 min-w-0`,children:[l(`span`,{className:`text-xs font-medium text-foreground truncate`,children:t}),r(`span`,{className:`shrink-0 text-[10px] font-mono text-foreground-subtle`,children:[`#`,e]})]})}function yn({unclaimed:e}){let{t}=z();return e===null||e.unitCount===0?null:l(`div`,{className:`flex items-center gap-2`,children:l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full bg-warning/10 text-warning font-medium tabular-nums`,children:t(`cameraLoad.unclaimedBadge`,`{{count}} unclaimed · {{rss}}`,{count:e.unitCount,rss:e.rssBytes===null?`—`:R(e.rssBytes)})})})}n();var bn=256*1024*1024,xn=1e4;function Sn({nodeId:e,isHub:t}){let{t:n}=z(),{series:i,sampleCount:o,threadSplitAvailable:s,loadingRetained:u,bucketMs:d,cadenceMs:f}=Gt(e),[p,m]=c(``),[h,g]=c(new Set),[_,v]=c(zt),y=e=>e.key===`__root__`?n(`clusterLoad.bucketRoot`,`Node supervisor`):e.key===`__unattributed__`?n(`clusterLoad.bucketUnattributed`,`Unattributed processes`):e.key,b=ft(d??f??xn),x=a(()=>Wt(i,{search:p,selectedKeys:h,sort:_},y),[i,p,h,_]),S=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return r(`div`,{className:`space-y-4`,children:[l(Cn,{bucketMs:d,cadenceMs:f}),!s&&o>0&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/40 bg-warning/5 px-3 py-2 text-[11px] text-warning`,children:[l(L,{className:`h-3 w-3 mt-0.5 shrink-0`}),l(`span`,{children:n(`clusterLoad.noThreadSplit`,`No thread-level CPU split on this node — /proc/<pid>/task is Linux-only, and the first sample after a restart has no window to measure. CPU below falls back to the ps lifetime AVERAGE, which is not a rate.`)})]}),o===0&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:u?n(`clusterLoad.loadingRetained`,`Reading the retained series from this node…`):n(`clusterLoad.waitingFirstSample`,`No retained samples for this node — waiting for the next snapshot (up to 20s). The chart needs two to draw a rate.`)}),i.length>0&&r(`div`,{className:`space-y-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`label`,{className:`relative flex-1 min-w-[160px]`,children:[l(D,{className:`pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-foreground-subtle`}),l(`input`,{type:`search`,value:p,onChange:e=>m(e.target.value),placeholder:n(`clusterLoad.searchPlaceholder`,`Find a runner…`),"aria-label":n(`clusterLoad.searchLabel`,`Find a runner`),className:`w-full rounded border border-border bg-background py-1 pl-7 pr-2 text-[11px] text-foreground placeholder:text-foreground-subtle`})]}),l(wn,{sort:_,onChange:v})]}),r(`div`,{className:`flex flex-wrap items-center gap-1`,children:[i.map(e=>{let t=h.has(e.key);return l(`button`,{type:`button`,"aria-pressed":t,onClick:()=>S(e.key),className:`rounded-full border px-2 py-0.5 text-[10px] transition-colors ${t?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:y(e)},e.key)}),h.size>0&&r(`button`,{type:`button`,onClick:()=>g(new Set),className:`inline-flex items-center gap-1 rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground`,children:[l(P,{className:`h-2.5 w-2.5`}),n(`clusterLoad.clearFilter`,`All runners`)]})]})]}),i.length>0&&x.length===0&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:n(`clusterLoad.noMatches`,`No runner matches this search on {{count}} present. The node is reporting — the filter is hiding them.`,{count:i.length})}),l(`div`,{className:`space-y-3`,children:x.map(e=>r(`div`,{className:`rounded-lg border border-border p-3`,children:[r(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[l(`span`,{className:`text-xs font-medium text-foreground`,children:y(e)}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`clusterLoad.processCount`,`{{count}} process(es)`,{count:e.points.at(-1)?.processCount??0})})]}),r(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[l(yt,{title:s?n(`clusterLoad.cpuTitle`,`CPU % of one core`):n(`clusterLoad.cpuTitleLifetime`,`CPU % (ps lifetime average)`),mainLabel:n(`clusterLoad.seriesMain`,`Main threads`),gcLabel:n(`clusterLoad.seriesGc`,`GC / V8 helpers`),points:e.points.map(e=>({atMs:e.atMs,main:e.cpuMainPercent,gc:e.cpuGcPercent})),formatValue:e=>`${e.toFixed(0)}%`,gapMs:b,emptyMessage:n(`clusterLoad.cpuUnavailable`,`No thread split on this node. Lifetime average: {{avg}}%`,{avg:(e.points.at(-1)?.cpuLifetimePercent??0).toFixed(1)})}),l(Y,{title:n(`clusterLoad.memoryTitle`,`Memory RSS`),points:e.points.map(e=>({atMs:e.atMs,value:e.memoryRssBytes})),formatValue:R,axisFloor:bn,axisScale:`bytes`,gapMs:b,emptyMessage:n(`clusterLoad.memoryUnavailable`,`No memory samples yet.`)})]})]},e.key))}),l(_n,{scope:{nodeId:e,isHub:t},cadenceMs:f})]})}function Cn({bucketMs:e,cadenceMs:t}){let{t:n}=z();return e===null?null:l(`p`,{className:`text-[10px] text-foreground-subtle`,children:t!==null&&e>t?n(`clusterLoad.captionBucket`,`1 point = {{bucket}}s (bucket MAXIMUM, not a mean)`,{bucket:Math.round(e/1e3)}):n(`clusterLoad.captionRaw`,`1 point = 1 snapshot`)})}function wn({sort:e,onChange:t}){let{t:n}=z(),i=[{key:`cpu`,label:n(`clusterLoad.sortCpu`,`CPU`)},{key:`memory`,label:n(`clusterLoad.sortMemory`,`Memory`)},{key:`name`,label:n(`clusterLoad.sortName`,`Name`)}];return r(`div`,{className:`flex items-center gap-1`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`clusterLoad.sortBy`,`Sort by`)}),i.map(n=>{let i=e.key===n.key;return r(`button`,{type:`button`,"aria-pressed":i,onClick:()=>t(i?{key:n.key,dir:e.dir===`desc`?`asc`:`desc`}:{key:n.key,dir:n.key===`name`?`asc`:`desc`}),className:`rounded border px-1.5 py-0.5 text-[10px] transition-colors ${i?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:[n.label,i&&(e.dir===`desc`?` ↓`:` ↑`)]},n.key)})]})}var Tn=`No per-node settings on this node. Every other setting these addons expose is one value for the whole cluster — edit those in System → Settings, not here.`;function En({nodeId:e,addonIds:t}){return t.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):l(`div`,{className:`w-full py-2`,children:l(Pe,{nodeId:e,addonIds:t,level:`global`,fieldScope:`perNode`,emptyMessage:Tn,selfTabbed:!0})})}n();function Dn({nodeId:e,addons:t}){let n=s(),{data:r,isLoading:i}=x({nodeId:e}),o=a(()=>{let e=new Map;for(let n of t)for(let t of n.capabilities){let r=e.get(t)??[];r.push(n.id),e.set(t,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[t]),c=pe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return o.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):l(C,{columns:[{key:`capName`,header:`Capability`,width:`w-1/2`,sortValue:e=>e.capName,render:e=>l(`span`,{className:`font-medium`,children:e.capName})},{key:`provider`,header:`Bound provider`,render:t=>{let n=r?.[t.capName]??t.providers[0]??``,a=t.providers.length===1;return l(`select`,{value:n,onChange:n=>c.mutate({nodeId:e,capName:t.capName,addonId:n.target.value}),disabled:a||c.isPending||i,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:a?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:t.providers.map(e=>l(`option`,{value:e,children:e},e))})}}],rows:o,rowKey:e=>e.capName,minWidthPx:520,mobileMode:`cards`,maxBodyHeight:A})}function On({transport:e}){if(e===void 0)return l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`—`});let t=e===`tls`;return l(`span`,{title:t?`Connected over mutual TLS (hub-CA certificate)`:`Connected over the clear mesh port — enroll this agent with a join token`,className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${t?`bg-success/10 text-success`:`bg-warning/10 text-warning`}`,children:t?`TLS`:`clear`})}n();function kn(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function An(e){let[t,n]=c(!1),[i,a]=c(e.name),o=s(),u=te({onSuccess:()=>{o.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),d=(e.localIps??[]).filter(e=>!e.includes(`:`)),f=(e.localIps??[]).filter(e=>e.includes(`:`)),p=async()=>{if(!i.trim()||i===e.name){n(!1);return}try{await u.mutateAsync({nodeId:e.nodeId,name:i.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},m=[[`Node ID`,l(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?r(`div`,{className:`flex items-center gap-1.5`,children:[l(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&p(),e.key===`Escape`&&n(!1)},disabled:u.isPending,autoFocus:!0}),l(`button`,{onClick:()=>void p(),disabled:u.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:l(F,{className:`h-3.5 w-3.5`})}),l(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:l(P,{className:`h-3.5 w-3.5`})})]}):r(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&l(`button`,{onClick:()=>{a(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:l(_e,{className:`h-3 w-3`})})]})],[`Hostname`,l(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Root Package`,e.rootPackage?r(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):l(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,r(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,r(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,l(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,l(`span`,{className:`text-xs`,children:kn(e.uptime)})],[`Engines`,e.engines.length>0?l(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,children:e},e))}):l(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return e.isHub||m.push([`Mesh transport`,l(On,{transport:e.meshTransport})]),d.length>0&&m.push([`IPv4`,l(`div`,{className:`flex flex-wrap gap-1.5`,children:d.map((e,t)=>l(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),f.length>0&&m.push([`IPv6`,l(`div`,{className:`flex flex-wrap gap-1.5`,children:f.map((e,t)=>l(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),l(`div`,{className:`py-2`,children:l(`table`,{className:`w-full text-sm`,children:l(`tbody`,{children:m.map(([e,t],n)=>r(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[l(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),l(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}n();function jn({nodeId:e,value:t,detectedHosts:n,status:i,errorMessage:a,onCommit:o}){let[s,d]=c(t??``);u(()=>{d(t??``)},[t]);let f=n[0],p=f===void 0?`auto-detect`:`auto: ${f}`,m=i===`pending`,h=s.trim(),_=h!==(t??``),v=_&&!m,y=()=>{v&&o(e,h.length>0?h:null)};return r(`div`,{className:`flex items-center gap-1.5`,children:[l(E,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:p,value:s,disabled:m,onChange:e=>d(e.target.value),onBlur:y,onKeyDown:e=>{e.key===`Enter`&&y(),e.key===`Escape`&&d(t??``)},className:`w-36`}),r(k,{variant:`outline`,size:`sm`,onClick:y,disabled:!v,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,children:[m?l(N,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):l(F,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!_&&!m&&i===`success`&&l(F,{className:`h-3.5 w-3.5 shrink-0 text-success`,"aria-label":`Saved`,role:`img`}),i===`error`&&l(`span`,{title:a??`Failed to save reachable host`,children:l(g,{className:`h-3.5 w-3.5 shrink-0 text-danger`,"aria-label":a??`Failed to save reachable host`,role:`img`})})]})}n();function Mn(e){let t=Me.safeParse(Re(e,`color`));return t.success?t.data:null}function Nn(e,t){return t.variables?.agentNodeId===e?t.isPending?`pending`:t.isError?`error`:t.isSuccess?`success`:`idle`:`idle`}function Pn({nodeId:e,detectedHosts:t}){let{t:n}=z(),i=s(),o=S(void 0),c=w({onSuccess:()=>Fe(i)}),u=w({onSuccess:()=>Fe(i)}),d=a(()=>o.data?.find(t=>t.nodeId===e)?.settings,[o.data,e]),f=Mn(d)??(o.isLoading?null:ke(e)),p=Le(d,`reachableHost`),m=Nn(e,c),h=m===`error`?Ie(c.error):null,g=t.filter(e=>!e.includes(`:`)),_=t=>{t!==f&&u.mutate({agentNodeId:e,color:t})};return r(`div`,{className:`rounded-lg border border-border bg-surface/40 divide-y divide-border px-3`,children:[l(M,{label:n(`nodes.general.nodeColour`,`Node colour`),children:l(`div`,{role:`group`,"aria-label":n(`nodes.general.nodeColourGroup`,`Node colour`),className:`flex flex-wrap gap-2`,children:Ae.map(e=>{let t=f===e;return l(k,{type:`button`,role:`radio`,"aria-checked":t,"aria-label":e,variant:`outline`,size:`sm`,disabled:o.isLoading||u.isPending,title:e,onClick:()=>_(e),className:`h-6 w-6 min-w-6 shrink-0 rounded-full border-0 p-0 ${ce(e)} ${t?`ring-2 ring-primary ring-offset-2 ring-offset-background`:`opacity-80 hover:opacity-100`}`,children:l(`span`,{className:`sr-only`,children:e})},e)})})}),l(M,{label:n(`nodes.general.reachableHost`,`Reachable host`),children:l(jn,{nodeId:e,value:p,detectedHosts:g,status:m,errorMessage:h,onCommit:(e,t)=>{c.mutate({agentNodeId:e,reachableHost:t})}})})]})}n();var Fn=[[`serverManagement`,`getServerPackageStatus`]];function In({label:e,tone:t}){return l(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${{neutral:`bg-surface-muted text-foreground-subtle`,ok:`bg-success/15 text-success`,info:`bg-info/15 text-info`,warn:`bg-warning/15 text-warning`,error:`bg-danger/15 text-danger`}[t]}`,children:e})}function Q({label:e,value:t}){return r(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[l(`span`,{className:`text-foreground-subtle`,children:e}),l(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function Ln({runningVersion:e,latestVersion:t,seedVersion:n,nodeRuntimeVersion:i,labelRunning:a,labelLatest:o,labelSeed:s,labelRuntime:c}){return l(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-sm`,children:[{key:`running`,label:a,value:e},{key:`latest`,label:o,value:t},{key:`seed`,label:s,value:n},{key:`runtime`,label:c,value:i}].map(({key:e,label:t,value:n})=>r(`span`,{className:`inline-flex items-baseline gap-1`,children:[l(`span`,{className:`text-foreground-subtle`,children:t}),l(`span`,{className:`font-mono text-foreground`,children:n??`—`})]},e))})}var Rn={ok:`border-success/40 bg-success/10 text-success`,warn:`border-warning/40 bg-warning/10 text-warning`,error:`border-danger/40 bg-danger/10 text-danger`};function zn(e){return e.outcome===`failed`?`error`:(e.outcome,e.accepted?`ok`:`warn`)}function Bn(e,t){let n=t instanceof Error?t.message:String(t);return`${e(`serverManagement.outcomeDropped`,`The connection dropped and the result could not be confirmed. The node may be restarting — re-check the version above.`)} — ${n}`}function Vn({node:t}){let{t:n}=z(),i=s(),a=I(),[o,u]=c(!1),[d,f]=c(null),p=t.isHub?void 0:{nodeId:t.id},m=v(p,{refetchInterval:1e4,enabled:t.isOnline,retry:1}),h=m.data??null,g=e(()=>{i.invalidateQueries({queryKey:Fn})},[i]),_=be({onSettled:g}),y=re({onSettled:g}),b=ye({onSettled:g}),x=e(async()=>{if(h?.latestVersion==null){f({tone:`warn`,text:n(`serverManagement.outcomeNoTarget`,`No target version is known for this node — run "Check for update" first.`)});return}if(await a({title:n(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:n(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:h.packageName,version:h.latestVersion,node:t.name}),confirmLabel:n(`serverManagement.confirmUpdateAction`,`Update & restart`)})){f(null);try{let e=await y.mutateAsync({version:h.latestVersion,...p});f({tone:zn(e),text:e.message}),e.restarting&&u(!0)}catch(e){f({tone:`warn`,text:Bn(n,e)})}}},[y,a,t.name,p,h,n]),S=e(async()=>{if(await a({title:n(`serverManagement.confirmRestartTitle`,`Restart node`),message:n(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:t.name}),confirmLabel:n(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})){f(null);try{let e=await b.mutateAsync(p);f({tone:zn(e),text:e.message}),e.restarting&&u(!0)}catch(e){f({tone:`warn`,text:Bn(n,e)})}}},[a,t.name,b,p,n]),C=()=>{switch(h?.bootMode){case`data-root`:return{label:n(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:n(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:n(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},w=()=>{if(h==null)return null;switch(h.updateState){case`checking`:return{label:n(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:n(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:n(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return h.restartRequired===!0?{label:n(`serverManagement.stateRestartRequired`,`restart required`),tone:`warn`}:h.updateAvailable?{label:n(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:n(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},T=h?.bootMode===`workspace`,E=t.isOnline&&h!=null&&!T&&h.updateAvailable&&h.updateState===`idle`&&!y.isPending,D=t.isOnline&&h!=null&&h.updateState===`idle`&&!b.isPending,O=t.isOnline?w():null;return r(`div`,{className:`space-y-4 py-2`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[l(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:h?.packageName??t.rootPackage?.name??`@camstack/server`}),t.isOnline&&h!=null&&l(In,{...C()})]}),O!=null&&l(In,{...O})]}),!t.isOnline&&l(Q,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage?.version??null}),t.isOnline&&m.isLoading&&r(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[l(N,{className:`h-4 w-4 animate-spin`}),n(`common.loading`,`Loading…`)]}),t.isOnline&&m.isError&&r(`div`,{className:`space-y-1.5`,children:[l(`p`,{className:`text-sm text-danger`,children:n(`serverManagement.loadError`,`Could not load the node root-package status.`)}),t.rootPackage!=null&&l(Q,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage.version})]}),t.isOnline&&h!=null&&r(`div`,{className:`space-y-1.5`,children:[l(Ln,{runningVersion:h.runningVersion,latestVersion:h.latestVersion,seedVersion:h.seedVersion,nodeRuntimeVersion:h.nodeRuntimeVersion,labelRunning:n(`serverManagement.runningVersionShort`,`Running`),labelLatest:n(`serverManagement.latestVersionShort`,`Latest`),labelSeed:n(`serverManagement.imageSeedShort`,`Seed`),labelRuntime:n(`serverManagement.nodeRuntimeVersionShort`,`Node.js`)}),h.pendingVersion!=null&&l(Q,{label:n(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:h.pendingVersion}),h.installedVersion!=null&&h.installedVersion!==h.runningVersion&&l(Q,{label:n(`serverManagement.installedVersion`,`Installed on disk (runs after restart)`),value:h.installedVersion})]}),t.isOnline&&h?.imageContract?.state===`behind-series`&&r(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs leading-relaxed text-danger`,children:[l(`p`,{className:`mb-0.5 font-semibold`,children:n(`serverManagement.imageContractDiverged`,`Container image diverges from the deployment contract`)}),l(`p`,{children:h.imageContract.message})]}),t.isOnline&&T&&l(`p`,{className:`text-xs text-foreground-subtle`,children:n(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),d!=null&&l(`p`,{role:`status`,className:`rounded border px-2 py-1.5 text-xs leading-relaxed ${Rn[d.tone]}`,children:d.text}),o&&r(`div`,{className:`flex items-center gap-2 text-sm text-warning`,children:[l(N,{className:`h-4 w-4 animate-spin`}),n(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),t.isOnline&&r(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:_.isPending||h?.updateState===`staging`,onClick:()=>_.mutate(p),children:[_.isPending?l(N,{className:`h-3.5 w-3.5 animate-spin`}):l(fe,{className:`h-3.5 w-3.5`}),n(`serverManagement.checkForUpdate`,`Check for update`)]}),E&&r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void x(),children:[y.isPending?l(N,{className:`h-3.5 w-3.5 animate-spin`}):l(oe,{className:`h-3.5 w-3.5`}),n(`serverManagement.updateTo`,`Update to {{version}}`,{version:h?.latestVersion??``})]}),r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!D,onClick:()=>void S(),children:[b.isPending?l(N,{className:`h-3.5 w-3.5 animate-spin`}):l(j,{className:`h-3.5 w-3.5`}),n(`serverManagement.restart`,`Restart`)]})]}),t.isOnline&&h?.lastCheckedAtMs!=null&&r(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[l(Oe,{className:`h-3 w-3`}),n(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(h.lastCheckedAtMs).toLocaleString()})]})]})}n();function Hn({node:t}){let n=d(),i=s(),[a,o]=c(`info`),[u,f]=c(!1),[p,h]=c(null),g=t.processes??[],_=t.addons.map(e=>e.id),[v,y]=c(!1),[b,x]=c(null),S=e(async()=>{if(v||t.isHub)return;let e=(t.localIps??[]).find(e=>!e.includes(`:`));if(e===void 0){x(`No LAN IPv4 on this node — open its :4444 URL by hand.`);return}y(!0),x(null);try{let r=await n.trpcClient.addons.custom.mutate({addonId:`system-config`,action:`mintAgentUiUnlockTicket`,input:{nodeId:t.id,dashboardBaseUrl:`http://${e}:4444/`}}),i=typeof r.dashboardUrl==`string`?r.dashboardUrl:typeof r.ticket==`string`?`http://${e}:4444/?ticket=${encodeURIComponent(r.ticket)}`:null;if(i===null){x(`Hub did not return an unlock ticket.`);return}window.open(i,`_blank`,`noopener,noreferrer`)}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(!1)}},[t.id,t.isHub,t.localIps,v,n.trpcClient]),C=async()=>{if(!u){f(!0),h(null);try{await n.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:t.id}).catch(()=>void 0);let e=await n.trpcClient.clusterNodes.forgetNode.mutate({nodeId:t.id});h({tone:e.stillListed?`warn`:`ok`,text:e.message}),e.stillListed||i.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}catch(e){h({tone:`warn`,text:`Forget failed: ${e instanceof Error?e.message:String(e)}`})}finally{f(!1)}}};return t.isOnline?r(`div`,{className:`border border-border rounded-xl`,children:[r(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3 bg-muted/30 border-b border-border rounded-t-xl`,children:[r(`div`,{className:`flex min-w-0 flex-1 basis-full items-center gap-x-2 gap-y-1 sm:basis-auto sm:flex-initial`,children:[l(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success shrink-0`}),l(`span`,{className:`text-sm font-semibold shrink-0`,children:t.name}),r(`span`,{className:`text-xs text-muted-foreground min-w-0 truncate`,children:[t.cpuModel??t.platform,` ·`,` `,t.memoryMB>0?`${Math.round(t.memoryMB/1024)}GB`:``,` · `,t.arch]})]}),t.engines.map(e=>l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium shrink-0`,children:e},e)),!t.isHub&&l(On,{transport:t.meshTransport}),r(`div`,{className:`flex min-w-0 flex-wrap items-center justify-end gap-x-3 gap-y-1 text-xs text-muted-foreground w-full sm:ml-auto sm:w-auto`,children:[!t.isHub&&r(`button`,{type:`button`,onClick:()=>void S(),disabled:v,title:`Open this agent's status dashboard (unlocks with a short-lived hub ticket)`,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-xs text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[l(O,{className:`h-3 w-3`}),v?`Opening…`:`Open dashboard`]}),r(`span`,{className:`flex items-center gap-1`,children:[l(T,{className:`h-3 w-3`}),` `,t.cpuPercent,`%`]}),r(`span`,{className:`flex items-center gap-1`,children:[l(We,{className:`h-3 w-3`}),` `,t.memoryPercent,`%`]})]})]}),b!==null&&l(`p`,{role:`status`,className:`px-4 pt-2 text-xs text-warning`,children:b}),l(`div`,{className:`sticky top-0 z-20 flex border-b border-border px-4 bg-background overflow-x-auto`,children:[`info`,`forks`,`processes`,`load`,`settings`,`capabilities`].map(e=>l(`button`,{onClick:()=>o(e),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${a===e?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:e===`info`?`General`:e===`forks`?`Forks (${g.length})`:e===`processes`?`Processes`:e===`load`?`Load`:e===`settings`?`Settings`:`Capabilities`},e))}),r(`div`,{className:`px-4 py-2`,children:[a===`info`&&r(`div`,{className:`space-y-3`,children:[l(An,{nodeId:t.id,name:t.name,hostname:t.hostname,platform:t.platform,arch:t.arch,cpuModel:t.cpuModel,cpuCores:t.cpuCores,memoryMB:t.memoryMB,engines:t.engines,isHub:t.isHub,uptime:t.uptime,localIps:t.localIps,rootPackage:t.rootPackage,meshTransport:t.meshTransport}),l(Pn,{nodeId:t.id,detectedHosts:t.localIps??[]}),l(`div`,{className:`border-t border-border pt-1`,children:l(Vn,{node:{id:t.id,name:t.name,isHub:t.isHub,isOnline:t.isOnline,rootPackage:t.rootPackage??null}})})]}),a===`forks`&&l(Ze,{nodeId:t.id,processes:g}),a===`processes`&&l(tt,{nodeId:t.id}),a===`load`&&l(Sn,{nodeId:t.id,isHub:t.isHub}),a===`settings`&&l(En,{nodeId:t.id,addonIds:_}),a===`capabilities`&&l(Dn,{nodeId:t.id,addons:t.addons})]})]}):r(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[r(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3 bg-muted/30`,children:[l(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive shrink-0`}),l(`span`,{className:`text-sm font-semibold shrink-0`,children:t.name}),r(`span`,{className:`text-xs text-muted-foreground min-w-0 truncate`,children:[t.cpuModel??t.platform,` ·`,` `,t.memoryMB>0?`${Math.round(t.memoryMB/1024)}GB`:``,` · `,t.arch]}),t.engines.map(e=>l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,children:e},e)),t.rootPackage&&r(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[t.rootPackage.name,`@`,t.rootPackage.version]}),l(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),r(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[r(`span`,{className:`text-xs text-muted-foreground`,children:[t.lastSeen?`Last seen ${new Date(t.lastSeen).toLocaleString()} — `:``,t.addons.length,` addon`,t.addons.length===1?``:`s`,` assigned; will resume when node reconnects`]}),r(`button`,{type:`button`,onClick:()=>void C(),disabled:u,title:`Forget this node — removes its saved history and pipeline assignments`,className:`flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-border text-muted-foreground hover:text-destructive hover:border-destructive/50 disabled:opacity-50 transition-colors`,children:[l(m,{className:`h-3 w-3`}),u?`Forgetting…`:`Forget node`]})]}),p!=null&&l(`p`,{role:`status`,className:`px-4 pb-3 text-xs leading-relaxed ${p.tone===`ok`?`text-success`:`text-warning`}`,children:p.text})]})}n();function Un({nodes:e,selected:t,onSelect:n}){let{t:i}=z(),o=Ve(e),s=S(void 0),c=a(()=>Be(s.data),[s.data]);return t===null?l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-xs text-foreground-subtle`,children:i(`cluster.noNodes`,`No nodes in this cluster yet.`)}):r(`div`,{className:`flex flex-col gap-3`,children:[o.length>1&&l(`div`,{className:`flex flex-wrap items-center gap-1.5`,role:`tablist`,"aria-label":i(`cluster.nodeSelectorLabel`,`Nodes`),children:o.map(e=>l(b,{nodeName:e.name,colorId:ze(c,e.id),emphasized:e.id===t.id,onSelect:()=>n(e.id),trailing:e.isOnline?void 0:l(`span`,{className:`text-[10px] text-destructive`,children:i(`cluster.offline`,`offline`)})},e.id))}),l(Hn,{node:t})]})}var $=3,Wn=7e3;function Gn(e){return[...e].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1)}function Kn(e){return e.isHub?{}:{nodeId:e.id}}function qn(e){return e.updateState===`staging`||e.updateState===`pending-restart`||e.pendingVersion!==null?!0:!e.updateAvailable}async function Jn(e,t){let n=Kn(e),r=`no answer`;for(let i=1;i<=$;i+=1)try{let r=await t.readStatus(n);return qn(r)?{nodeId:e.id,nodeName:e.name,outcome:`applied`,detail:`Connection dropped, and the node confirms the update landed (state ${r.updateState}, running ${r.runningVersion??`unknown`}).`}:{nodeId:e.id,nodeName:e.name,outcome:`failed`,detail:`Connection dropped and the node came back unchanged (still ${r.runningVersion??`unknown`}, update still available). Nothing was staged.`}}catch(e){r=e instanceof Error?e.message:String(e),i<$&&await t.wait(Wn)}return{nodeId:e.id,nodeName:e.name,outcome:`unconfirmed`,detail:`Connection dropped and the node could not be confirmed after ${$} attempts (${r}). It may be restarting — re-check this node.`}}function Yn(e){return e.accepted?`applied`:e.outcome===`failed`?`failed`:`refused`}async function Xn(e,t){let n=[];for(let r of Gn(e))try{let e=await t.apply(Kn(r));n.push({nodeId:r.id,nodeName:r.name,outcome:Yn(e),detail:e.message})}catch{n.push(await Jn(r,t))}return n}n();function Zn(){let{nodes:e,isLoading:t}=ae(),n=a(()=>e??[],[e]);return{nodes:n,isLoading:t&&n.length===0}}var Qn={applied:`border-success/40 bg-success/10 text-success`,refused:`border-warning/40 bg-warning/10 text-warning`,failed:`border-danger/40 bg-danger/10 text-danger`,unconfirmed:`border-warning/40 bg-warning/10 text-warning`};function $n(){let{t}=z(),n=I(),{nodes:i,isLoading:o}=Zn(),[s,f]=Ne(),{selection:p,selectNode:m}=Ue(i),h=p.node,g=a(()=>i.filter(e=>e.isOnline),[i]),_=g.length,v=i.filter(e=>!e.isOnline).length,y=re(),b=d(),[x,S]=c(!1),[C,w]=c([]),T=s.get(`unlockNode`),E=s.get(`returnTo`),[D,O]=c(null);u(()=>{if(T===null||E===null)return;let e=!1;return(async()=>{try{let t=await b.trpcClient.addons.custom.mutate({addonId:`system-config`,action:`mintAgentUiUnlockTicket`,input:{nodeId:T,dashboardBaseUrl:E}});if(e)return;let n=t.ticket,r=typeof t.dashboardUrl==`string`?t.dashboardUrl:typeof n==`string`?(()=>{let e=new URL(E);return e.searchParams.set(`ticket`,n),e.toString()})():null;if(r===null){O(`Could not mint an unlock ticket.`);return}let i=new URLSearchParams(s);i.delete(`unlockNode`),i.delete(`returnTo`),f(i,{replace:!0}),window.location.assign(r)}catch(t){e||O(t instanceof Error?t.message:String(t))}})(),()=>{e=!0}},[T,E,s,f,b.trpcClient]);let k=e(async()=>{let e=g.map(e=>({id:e.id,name:e.name,isHub:e.isHub}));if(await n({title:t(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:t(`serverManagement.confirmUpdateAllBody`,`Update and restart every online node, agents first, hub last. Up-to-date nodes are skipped; this page reconnects when the hub comes back.`),confirmLabel:t(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){S(!0),w([]);try{w(await Xn(e,{apply:e=>y.mutateAsync(e),readStatus:e=>b.trpcClient.serverManagement.getServerPackageStatus.query(e),wait:e=>new Promise(t=>setTimeout(t,e))}))}finally{S(!1)}}},[y,n,g,b,t]);return r(`div`,{className:`flex flex-col gap-4 p-4`,children:[r(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[r(`div`,{className:`flex items-center gap-2`,children:[_>0&&r(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[_,` online`]}),v>0&&r(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[v,` offline`]})]}),l(`div`,{className:`flex items-center gap-2`,children:_>1&&r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,disabled:x,title:t(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void k(),children:[x?l(N,{className:`h-3.5 w-3.5 animate-spin`}):l(oe,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateAll`,`Update all nodes`)]})})]}),C.length>0&&l(`ul`,{"aria-label":`update-all-report`,className:`flex flex-col gap-1 text-xs`,children:C.map(e=>r(`li`,{"data-outcome":e.outcome,className:`rounded border px-2 py-1 ${Qn[e.outcome]}`,children:[l(`span`,{className:`font-medium`,children:e.nodeName}),l(`span`,{className:`mx-1 uppercase tracking-wide`,children:e.outcome}),l(`span`,{className:`opacity-80`,children:e.detail})]},e.nodeId))}),D!==null&&r(`p`,{role:`alert`,className:`rounded border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:[`Unlock from agent failed: `,D]}),l(Ke,{}),o?l(`div`,{className:`flex items-center justify-center py-12 text-muted-foreground`,children:`Loading cluster topology...`}):r(`div`,{className:`flex flex-col gap-3`,children:[l(He,{staleNodeId:p.staleNodeId,shownNodeName:h?.name??``}),l(Un,{nodes:i,selected:h,onSelect:m})]})]})}export{$n as ClusterPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-Cyuzqnbw.js";import{I as t,K as n,Q as r,S as i,W as a,b as o,i as s,o as c,p as l,q as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{A as p,B as m,D as h,E as g,M as _,O as v,R as y,T as b,at as x,b as S,gt as C,ht as w,k as T,st as E,ut as D,v as O,vt as k,y as A}from"./player-overlays-B7T46vDu.js";import{$d as j,$l as M,$s as N,$t as ee,Bs as P,Bt as F,C as I,Cn as L,Dn as te,E as ne,En as re,F as ie,Fn as R,Fs as z,Ft as B,H as ae,Hd as V,Hl as oe,Hs as se,In as H,Is as ce,It as le,L as ue,Ls as de,Md as fe,Ms as pe,Nn as me,Ns as he,O as ge,Os as _e,Ou as ve,Pn as ye,Pt as U,Ql as be,Qs as xe,Ru as Se,S as Ce,Sn as we,T as Te,Tf as Ee,Tn as De,Tt as Oe,Ul as ke,Us as Ae,V as je,Vs as Me,Vu as Ne,Wl as Pe,Ws as Fe,Wu as Ie,Xu as Le,Yu as Re,Zl as W,_s as ze,ac as Be,an as Ve,bn as He,bs as Ue,cu as We,dn as Ge,dt as Ke,ec as qe,en as Je,eu as Ye,fu as Xe,gd as Ze,gs as Qe,hd as $e,hs as et,in as tt,iu as nt,js as rt,kd as it,ks as at,la as ot,ln as st,lr as ct,md as lt,mn as ut,ms as dt,nc as ft,nf as pt,nu as mt,on as ht,pn as G,pr as gt,ps as _t,qn as vt,r as yt,rc as bt,rd as xt,rn as St,ru as Ct,sn as wt,tc as Tt,tn as Et,tr as K,tu as Dt,un as Ot,ur as kt,vs as At,vt as jt,w as Mt,wn as Nt,ws as Pt,xn as Ft,xs as It,yd as Lt,ys as Rt,yu as zt,zs as Bt}from"./src-BTX2jfA7.js";import{t as Vt}from"./crop-DEIlVeIH.js";import{t as Ht}from"./layers-DSe93_v-.js";import{An as Ut,Br as Wt,Dn as Gt,En as Kt,Mn as qt,On as Jt,Tn as Yt,c as Xt,fi as Zt,jn as Qt,kn as $t,l as en,m as tn,vi as nn,wn as rn,zr as an}from"./client-BBcQuaON.js";import{n as on}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{$ as sn,H as cn,Y as ln,it as un}from"./index-BWu66tVw.js";import"./useEventInvalidation-D8gNhpYS.js";import{t as dn}from"./NodeAddonsSettingsPanel-xFAQ20so.js";import{_ as fn,a as pn,c as mn,d as hn,f as gn,h as _n,i as vn,l as yn,n as bn,o as xn,p as Sn,r as Cn,s as wn,t as Tn,u as En,v as Dn}from"./node-color-map-ChrpDB9I.js";var On=k(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),kn=k(`crown`,[[`path`,{d:`M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z`,key:`1vdc57`}],[`path`,{d:`M5 21h14`,key:`11awu3`}]]),An=k(`pin-off`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]),jn=k(`scale`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`m19 8 3 8a5 5 0 0 1-6 0zV7`,key:`zcdpyk`}],[`path`,{d:`M3 7h1a17 17 0 0 0 8-2 17 17 0 0 0 8 2h1`,key:`1yorad`}],[`path`,{d:`m5 8 3 8a5 5 0 0 1-6 0zV7`,key:`eua70x`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}]]),Mn=k(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]),Nn=`step`,Pn=[Nn,`acc`];function Fn(e,t){return`${e}/${t}`}function In(e,t,n){let r=n.step!==null&&e.includes(n.step),i=n.acc!==null&&t.includes(n.acc);return{stepId:r?n.step:null,acceleratorId:i?n.acc:null,staleStepId:n.step!==null&&n.step!==``&&!r&&e.length>0?n.step:null}}function Ln(e){if(e==null)return null;if(typeof e==`number`)return e>0?e:null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function Rn(e){return e}function zn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function Bn(e,t){return typeof e==`boolean`?e:Rn(t)}function Vn(e,t){return{pipeline:Bn(zn(e,`detect`),t),audio:Bn(zn(e,`audio`),t),ingest:Bn(zn(e,`ingest`),t)}}function Hn(e,t,n){let r=e?.find(e=>e.nodeId===t);return Vn(r?.settings,n)}function Un({selectedNodeId:e,onSelect:t,refreshToken:n}){let{nodes:r}=be(),{data:a}=rt(void 0),{data:s}=z(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=r??[],u=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return i(`div`,{className:`flex flex-col h-full`,children:[i(`button`,{type:`button`,onClick:()=>t(Lo),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:[d(un,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[d(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Assignments, load balancing, roles`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(n=>{let r=e===n.id,a=c.get(n.id)??0,l=n.isHub?Ne:V,u=Hn(s,n.id,n.isHub),f=n.isOnline?null:Ke(Ln(n.lastSeen));return i(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[d(l,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-danger flex-shrink-0`}),n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),i(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[i(`span`,{children:[n.cpuCores,` cores`]}),d(`span`,{children:`•`}),i(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),a>0&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[d(Xe,{className:`h-2.5 w-2.5`}),a]})]}),!n.isOnline&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{className:`text-danger`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[d(K,{variant:u.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),d(K,{variant:u.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),i(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[i(`span`,{children:[u,` online`]}),f>0&&i(`span`,{className:`text-danger`,children:[f,` offline`]})]})]})}function Wn({nodeId:e,refreshToken:t}){let{nodes:n}=be(),r=n?.find(t=>t.id===e),a=M(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?i(`div`,{className:`px-6 py-4 border-b border-border`,children:[i(`div`,{className:`flex items-center gap-2 mb-1`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-danger/10 text-danger`,children:`offline`}),r.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),i(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[d(`span`,{children:r.cpuModel??`CPU`}),d(`span`,{children:`•`}),i(`span`,{children:[r.cpuCores,` cores`]}),d(`span`,{children:`•`}),i(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),d(`span`,{children:`•`}),i(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),d(`span`,{children:`•`}),i(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&i(o,{children:[d(`span`,{children:`•`}),d(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):d(`div`,{className:`px-6 py-4 border-b border-border`,children:i(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}var Gn=[`assignments`,`tree`,`engines`,`logs`];r();var Kn=1024,qn=65536;function Jn(e,t,n){let r=e.trim();if(r.length===0)return{value:null,error:null};let i=Number(r);return Number.isInteger(i)?i<t?{value:null,error:`at least ${t}`}:i>n?{value:null,error:`at most ${n}`}:{value:i,error:null}:{value:null,error:`whole number`}}function Yn({nodeId:e,decodeBudgetMb:t,maxLiveDecodeWorkers:n,status:r,errorMessage:a,onCommit:o}){let[s,c]=u(t===null?``:String(t)),[l,p]=u(n===null?``:String(n));f(()=>{c(t===null?``:String(t))},[t]),f(()=>{p(n===null?``:String(n))},[n]);let m=Jn(s,Kn,qn),h=Jn(l,1,32),g=r===`pending`,_=m.value!==t||h.value!==n,v=m.error!==null||h.error!==null,y=_&&!v&&!g,b=()=>{y&&o(e,{decodeBudgetMb:m.value,maxLiveDecodeWorkers:h.value})};return i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(oe,{"aria-label":`Decode budget MB for ${e}`,type:`number`,inputMode:`numeric`,min:Kn,max:qn,placeholder:`auto`,value:s,disabled:g,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:`w-20`}),d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`MB`}),d(oe,{"aria-label":`Max decode workers for ${e}`,type:`number`,inputMode:`numeric`,min:1,max:32,placeholder:`auto`,value:l,disabled:g,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:`w-20`}),d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`workers`}),i(H,{variant:`outline`,size:`sm`,onClick:b,disabled:!y,"aria-label":`Save decode limits for ${e}`,title:`Save decode limits`,children:[g?d(Ze,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):d(pt,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),m.error===null?null:i(`span`,{className:`text-[11px] text-danger`,children:[`budget: `,m.error]}),h.error===null?null:i(`span`,{className:`text-[11px] text-danger`,children:[`workers: `,h.error]}),!_&&!g&&r===`success`&&d(pt,{className:`h-3.5 w-3.5 shrink-0 text-success`,"aria-label":`Saved`,role:`img`}),r===`error`&&d(`span`,{title:a??`Failed to save decode limits`,children:d(j,{className:`h-3.5 w-3.5 shrink-0 text-danger`,"aria-label":`Save failed`,role:`img`})})]})}r();function Xn(e,t){return t.variables?.agentNodeId===e?t.isPending?`pending`:t.isError?`error`:t.isSuccess?`success`:`idle`:`idle`}function Zn({nodeId:e}){let t=c(),n=z(void 0),r=se({onSuccess:()=>hn(t)}),o=a(()=>n.data?.find(t=>t.nodeId===e)?.settings,[n.data,e]),s=Sn(o,`decodeBudgetMb`),l=Sn(o,`maxLiveDecodeWorkers`),u=Xn(e,r),f=u===`error`?gn(r.error):null;return i(U,{headingId:`node-decode-limits`,title:`Decode limits`,icon:it,children:[d(`p`,{className:`${y} border-b border-border px-3 py-1.5 sm:px-4`,children:`How much live decode this node may run. Blank uses the cluster default, else half this node's RAM. The runner picks up changes on its next lease refresh.`}),d(`div`,{className:`px-3 py-2 sm:px-4`,children:d(Yn,{nodeId:e,decodeBudgetMb:s,maxLiveDecodeWorkers:l,status:u,errorMessage:f,onCommit:(e,t)=>r.mutate({agentNodeId:e,...t})})})]})}r();function Qn({refreshToken:e,nodeId:t}){let[n,r]=u(new Map),{nodes:o}=W();Dt(`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:s}=It(void 0),c=a(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),l=a(()=>{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]),f=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=a(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of l.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let a=e>0?r/e:0;return{totalAgents:o.length,onlineAgents:o.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[l,o]);if(t){let e=l.get(t);return i(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),i(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[d(q,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),d(q,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),d(q,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),d(q,{label:`Queue`,value:e?String(e.queueDepth):`—`}),d(q,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...l.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return i(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),i(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[d(q,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),d(q,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),d(q,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),d(q,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),d(q,{label:`Queue depth`,value:String(p.queueDepth)})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[480px]`,children:[d(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),d(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),d(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),d(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),d(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),d(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),i(`tbody`,{children:[m.map(([e,t])=>i(`tr`,{className:`border-t border-border`,children:[d(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&d(`tr`,{children:d(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function q({label:e,value:t}){return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[d(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),d(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}var $n={active:!1,pinned:!1,nodeId:null,reason:``};function er(e,t){return e.deviceName.localeCompare(t.deviceName)||e.deviceId-t.deviceId}function tr(e,t,n){let r=new Map(t.map(e=>[e.deviceId,e])),i=new Map(n.map(e=>[e.deviceId,e]));return e.map(e=>{let t=r.get(e.id),n=i.get(e.id),a=t?{active:!0,pinned:t.pinned,nodeId:t.agentNodeId,reason:t.reason??``}:$n,o=n?{active:!0,pinned:n.pinned,nodeId:n.nodeId,reason:``}:$n;return{deviceId:e.id,deviceName:e.name,disabled:e.disabled===!0,pipeline:a,detection:a,decoder:$n,audio:o}}).toSorted(er)}function nr(e,t,n){return{active:e!==null,pinned:t,nodeId:e,reason:n??``}}function rr(e,t){let n=new Map(t.map(e=>[e.deviceId,e.assignment]));return e.map(e=>{let t=n.get(e.deviceId);return t===void 0?e:{...e,detection:nr(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:nr(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:nr(t.audioNodeId,t.pinned.audio,t.reasons.audio)}})}function ir(e,t,n){let r=(t,n,r)=>({active:t!==null&&t===e,pinned:n,nodeId:t,reason:r??``});return t.map(({deviceId:e,assignment:t})=>({deviceId:e,deviceName:n(e),detection:r(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:r(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:r(t.audioNodeId,t.pinned.audio,t.reasons.audio)})).filter(e=>e.detection.active||e.decoder.active||e.audio.active).toSorted(er)}function ar(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>{let n=t.get(e);return n!==void 0&&n!==``?n:e}}function or(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>t.get(e)??`Camera ${e}`}function sr(e,t,n){return[{value:`auto`,label:`Auto`},...[...new Set([...e.nodeId===null?[]:[e.nodeId],...t.map(e=>e.id)])].map(e=>({value:e,label:`Pin → ${n(e)}`}))]}function cr({roleLabel:e,state:t,nameOf:n,colorByNodeId:r,emphasizeOnNodeId:i}){if(t.nodeId===null)return null;let a=t.nodeId,o=i===void 0?!1:t.active&&a===i;return d(F,{roleLabel:e,nodeName:n(a),colorId:bn(r,a),emphasized:o,pinned:t.pinned})}function lr({detection:e,decoder:t,audio:n,nameOf:r,colorByNodeId:a,emphasizeOnNodeId:o}){let s=(e,t)=>d(cr,{roleLabel:e,state:t,nameOf:r,colorByNodeId:a,emphasizeOnNodeId:o},e);return i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[s(`Detection`,e),s(`Decode`,t),s(`Audio`,n)]})}function ur({snap:e}){if(e===void 0)return d(`div`,{className:`flex h-8 items-center text-[11px] text-foreground-subtle`,title:`No metrics in the last 10 s — the camera has no session running`,children:`no live data`});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=Oe(t);return i(`div`,{className:`flex h-8 min-w-0 flex-col justify-center font-mono text-[10px] leading-tight tabular-nums`,children:[i(`span`,{className:`inline-flex min-w-0 items-center gap-1 ${c.textColor}`,children:[d(ie,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate font-semibold uppercase tracking-wider`,children:c.label}),d(`span`,{className:`text-foreground`,children:n.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[`/`,o.toFixed(0),` fps`]})]}),i(`span`,{className:`truncate text-foreground-subtle`,children:[d(`span`,{className:`text-foreground`,children:r.toFixed(0)}),` ms`,a>0&&i(`span`,{className:`ml-1 text-warning`,children:[`q`,a]}),i(`span`,{className:s>0?`ml-1 text-warning`:`ml-1`,children:[`drops `,s]})]})]})}r();var dr=1e4,fr=5e3;function pr(e){let[t,n]=u(new Map);return Dt(`pipeline.camera-metrics-snapshot`,t=>{let r=t.data;typeof r.deviceId==`number`&&(e!==void 0&&r.nodeId!==e||n(e=>new Map(e).set(r.deviceId,r)))}),f(()=>{if(t.size===0)return;let e=setInterval(()=>{n(e=>{let t=Date.now()-dr,n=[...e].filter(([,e])=>e.timestamp>=t);return n.length===e.size?e:new Map(n)})},fr);return()=>clearInterval(e)},[t.size]),t}var mr=3e5;function hr({state:e,onlineNodes:t,nameOf:n,pending:r,onChange:i}){return d(R,{"aria-label":`Node pin`,title:`Auto lets each session pick its node; a pin keeps the camera on one node.`,value:e.pinned&&e.nodeId!==null?e.nodeId:`auto`,disabled:r,options:[...sr(e,t,n)],onChange:e=>i(e.target.value)})}function gr({deviceId:e,nodeId:t}){let n=c(),{data:r}=pe({deviceId:e},{refetchOnMount:`always`}),{data:i}=at({nodeId:t},{staleTime:mr}),a=N({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(r===void 0||i===void 0)return d(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`accelerator: …`});let o=i.devices??[],s=o.filter(e=>e.enabled),l=r?.deviceKey??`auto`,u=l!==`auto`&&!s.some(e=>e.key===l),f=o.find(e=>e.key===l),p=[{value:`auto`,label:`Any accelerator`},...u?[{value:l,label:`${f?`${G(f)} (${l})`:l} (not enabled)`}]:[],...s.map(e=>({value:e.key,label:`${G(e)} · ${e.format}`}))];return d(R,{"aria-label":`Inference device pin`,title:`Pin detection to one accelerator of the node, or let each session pick.`,value:l,disabled:a.isPending,options:p,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value})})}r();function _r(e){let t=n(null);return e.nodeId!==null&&(t.current=e),t.current}function vr({deviceId:e,state:t,...n}){let r=_r(t);return i(`div`,{className:`grid w-80 grid-cols-2 gap-1.5`,children:[d(hr,{state:t,...n}),r?.nodeId==null?d(R,{"aria-label":`Inference device pin (no node yet)`,title:`An accelerator is pinned on the camera's node; this camera has not run on one yet.`,disabled:!0,defaultValue:`auto`,options:[{value:`auto`,label:`Any accelerator`}]}):d(gr,{deviceId:e,nodeId:r.nodeId})]})}function yr({state:e,nameOf:t}){let n=_r(e);if(n?.nodeId==null)return d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`— no session yet`});let r=e.active&&e.nodeId!==null,a=n.pinned?`pinned`:`auto · ${n.reason||`capacity`}`;return i(`div`,{className:`flex w-40 min-w-0 flex-col leading-tight`,title:n.pinned?void 0:`An unpinned camera is placed again at every session start, so this can change between sessions.`,children:[i(`span`,{className:`flex min-w-0 items-center gap-1.5 text-xs`,children:[d(`span`,{"aria-hidden":!0,className:`h-1.5 w-1.5 shrink-0 rounded-full ${r?`bg-success`:`bg-foreground-subtle/40`}`}),d(`span`,{className:`truncate font-medium ${r?`text-foreground`:`text-foreground-muted`}`,children:t(n.nodeId)})]}),d(`span`,{className:`truncate pl-3 text-[10px] ${n.pinned?`text-warning`:`text-foreground-subtle`}`,children:r?a:`${a} · idle, last session`})]})}function br({deviceId:e,deviceName:t}){let[n,r]=u(!1);return i(o,{children:[d(ke,{icon:Le,variant:`ghost`,size:`sm`,"aria-label":`Stream brokers of ${t}`,title:`Stream brokers & clients`,onClick:()=>r(!0)}),d(Ft,{open:n,onOpenChange:r,children:i(L,{width:`lg`,scroll:`body`,placement:`sheet-on-mobile`,children:[d(re,{children:i(te,{children:[t,` — stream brokers & clients`]})}),d(we,{children:n&&d(He,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:e,instanceId:`pipeline-row/${e}`,config:{variant:`compact`}})})]})})]})}function xr(e){return e.hasFreshMetrics?`active`:e.hasPipelineAssignment?`recently-active`:`inactive`}function Sr(e,t){return t.size===0?!0:t.has(e)}var Cr=[{value:`active`,label:`Active`},{value:`recently-active`,label:`Recently active`},{value:`inactive`,label:`Inactive`}];r();var wr=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`];function Tr(e){for(let t of[`getPipelineAssignments`,`getAudioAssignments`,`getCameraStatuses`])e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,t]]})}function Er(){let e=c();yt([`pipelineOrchestrator`,`getPipelineAssignments`],wr),yt([`pipelineOrchestrator`,`getAudioAssignments`],wr),yt([`pipelineOrchestrator`,`getCameraStatuses`],wr);let{data:t}=ot({isCamera:!0,projection:`slim`}),{data:n}=rt(void 0),{data:r}=Ue(void 0),{data:o}=Pt({}),{data:s}=z(void 0),{nodes:l}=W(),f=pr(),p=a(()=>ar(l),[l]),m=a(()=>Tn(s),[s]),h=a(()=>l.filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[l]),g=a(()=>rr(tr((t??[]).map(e=>({id:e.id,name:e.name,disabled:e.disabled})),n??[],r??[]),o??[]),[t,n,r,o]),[_,v]=u(()=>new Set),y=a(()=>g.filter(e=>Sr(xr({hasPipelineAssignment:e.pipeline.active,hasFreshMetrics:f.has(e.deviceId)}),_)),[g,f,_]),b=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},x=()=>Tr(e),C=At({onSuccess:x}),w=bt({onSuccess:x}),T=C.isPending||w.isPending,E=[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>i(`div`,{className:`flex w-44 min-w-0 items-center gap-1.5`,children:[d(`span`,{className:`min-w-0 truncate text-xs font-medium text-foreground`,title:e.deviceName,children:e.deviceName}),e.disabled&&d(K,{variant:`default`,children:`off`})]})},{key:`placement`,header:`Placement`,width:`w-80`,notSortableReason:`A pair of controls — editing one would move the row under the cursor.`,render:e=>d(vr,{deviceId:e.deviceId,state:e.pipeline,onlineNodes:h,nameOf:p,pending:T,onChange:t=>t===`auto`?w.mutate({deviceId:e.deviceId}):C.mutate({deviceId:e.deviceId,agentNodeId:t})})},{key:`roles`,header:`Roles here`,notSortableReason:`A set of roles has no single order.`,render:e=>d(lr,{detection:e.detection,decoder:e.decoder,audio:e.audio,nameOf:p,colorByNodeId:m})},{key:`resolved`,header:`Running on`,width:`w-40`,sortValue:e=>e.pipeline.nodeId===null?null:p(e.pipeline.nodeId),render:e=>d(yr,{state:e.pipeline,nameOf:p})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>f.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(ur,{snap:f.get(e.deviceId)})},{key:`brokers`,header:``,align:`right`,width:`w-10`,notSortableReason:`An action`,render:e=>d(br,{deviceId:e.deviceId,deviceName:e.deviceName})}],D=t===void 0?`Loading cameras…`:g.length===0?`No cameras`:`No cameras match this activity filter.`;return i(`div`,{className:`flex flex-col gap-2`,children:[d(`nav`,{"aria-label":`Filter by camera activity`,"data-testid":`assignments-activity-filter`,children:d(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:Cr.map(e=>{let t=_.has(e.value);return d(`button`,{type:`button`,"aria-pressed":t,"data-testid":`assignments-activity-${e.value}`,className:Pe(A,t?O:S),onClick:()=>b(e.value),children:e.label},e.value)})})}),d(B,{columns:E,rows:y,rowKey:e=>e.deviceId,minWidthPx:920,mobileMode:`scroll`,maxBodyHeight:le,emptyMessage:D})]})}r();function Dr({nodeId:e}){let t=c();yt([`pipelineOrchestrator`,`getCameraStatuses`],wr);let{data:n}=Pt({}),{data:r}=z(void 0),{data:i}=ot({isCamera:!0,projection:`slim`}),{nodes:o}=W(),s=pr(),l=a(()=>ar(o),[o]),u=a(()=>Tn(r),[r]),f=a(()=>ir(e,n??[],or((i??[]).map(e=>({id:e.id,name:e.name})))),[e,n,i]),p=o.filter(t=>t.isOnline&&t.id!==e),m=()=>Tr(t),h=At({onSuccess:m}),g=bt({onSuccess:m}),_=ze({onSuccess:m}),v=ft({onSuccess:m}),y=e=>[...e.detection.active?p.map(t=>({id:`detect-${t.id}`,label:`Move detection to ${t.name}`,onClick:()=>h.mutate({deviceId:e.deviceId,agentNodeId:t.id})})):[],...e.audio.active?p.map(t=>({id:`audio-${t.id}`,label:`Move audio to ${t.name}`,onClick:()=>_.mutate({deviceId:e.deviceId,nodeId:t.id})})):[],{id:`unpin-detect`,label:`Unpin detection`,hidden:!(e.detection.active&&e.detection.pinned),separatorBefore:!0,onClick:()=>g.mutate({deviceId:e.deviceId})},{id:`unpin-audio`,label:`Unpin audio`,hidden:!(e.audio.active&&e.audio.pinned),onClick:()=>v.mutate({deviceId:e.deviceId})}];return d(B,{columns:[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>d(`span`,{className:`block w-44 truncate text-xs font-medium text-foreground`,title:e.deviceName,children:e.deviceName})},{key:`roles`,header:`Roles here`,notSortableReason:`A set of roles has no single order.`,render:t=>d(lr,{detection:t.detection,decoder:t.decoder,audio:t.audio,nameOf:l,colorByNodeId:u,emphasizeOnNodeId:e})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>s.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(ur,{snap:s.get(e.deviceId)})},{key:`actions`,header:``,align:`right`,width:`w-10`,notSortableReason:`Actions`,render:e=>d(ue,{items:y(e),title:`Move ${e.deviceName}`})}],rows:f,rowKey:e=>e.deviceId,minWidthPx:560,mobileMode:`scroll`,maxBodyHeight:le,emptyMessage:n===void 0?`Loading cameras…`:`No camera runs on this node right now`})}function Or({nodeId:e,refreshToken:t}){let{nodes:n}=W(),r=n.find(t=>t.id===e)?.name??e;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(Qn,{refreshToken:t,nodeId:e}),i(`div`,{className:`space-y-2`,children:[i(`div`,{children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:[`Cameras on `,r]}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`The roles each camera runs here right now. Move a role or unpin it from the row menu; pins for every camera are on Cluster → Assignments.`})]}),d(Dr,{nodeId:e})]})]})}r();function kr(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Ar({nodeId:e,refreshToken:t}){let n=c(),r=vt(),o=dt({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:s}=et({nodeId:e}),l=M(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??s??null,u=l===null;yt([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:f}=Be({nodeId:e}),{values:p}=Ye(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),m=a(()=>p.filter(e=>e.metrics.phase===`active`).length,[p]),h=t=>{let n=f??[];if(n.length===0){o.mutate({nodeId:e,engine:t,force:!1});return}(async()=>{await r({title:`Kill engine`,message:`${String(n.length)} camera(s) are dispatching through this engine. Killing it drops their in-flight work and forces a respawn on the next frame.`,confirmLabel:`Kill engine`,variant:`danger`})&&o.mutate({nodeId:e,engine:t,force:!0})})()};return i(`div`,{className:`space-y-6`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(l??[]).length,` engine(s) resident in RAM. `,(f??[]).length,` `,`camera(s) attached, `,m,` actively dispatching frames. Refreshes every 5s.`]})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[640px]`,children:[d(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),d(`th`,{className:`text-left px-3 py-2`,children:`Models`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),d(`th`,{className:`w-20`})]})}),i(`tbody`,{children:[u&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!u&&(l??[]).map(e=>{let t=e.kind===`device-pool`;return i(`tr`,{className:`border-t border-border ${t?`bg-primary/[0.05]`:``}`,children:[d(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[d(t?Ht:V,{className:`h-3 w-3`}),t?`pool`:`runtime`]})}),d(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[d(Ct,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),d(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?d(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>d(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),d(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),d(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?d(`span`,{className:`text-foreground-subtle`,children:kr(e.idleMs,e.idleTtlMs)}):d(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:(f??[]).length}),d(`td`,{className:`px-3 py-2 text-right`,children:t?d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):i(H,{variant:`ghost`,size:`sm`,disabled:o.isPending,onClick:()=>h(e.engine),className:`text-danger hover:bg-danger/10 hover:text-danger`,children:[d(E,{className:`h-3.5 w-3.5`}),`Kill`]})})]},e.engineKey)}),!u&&(l??[]).length===0&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),i(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[d(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,d(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,d(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),o.isError&&d(me,{message:`Kill failed: ${o.error instanceof Error?o.error.message:`unknown error`}`})]})}var jr=`pipeline-runner`,Mr=200;function Nr({nodeId:e}){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(jt,{agentId:e,addonId:jr,limit:Mr,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}r();function Pr({nodeId:e,title:t}){let{data:n}=cn(),{data:r}=rt(void 0),o=a(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),s=a(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),c=pr(e),l=a(()=>{let e=[];for(let t of c.values())s&&!s.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[c,s]);return l.length===0?i(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):i(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[i(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[d(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:l.length})]}),d(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,n=Oe(e.metrics.phase);return i(`div`,{title:`${t} · ${n.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${n.badgeClass}`,children:[d(ie,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),d(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),d(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),d(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}function Fr(e,t,n){return e.map(e=>{if(e.key===t)return e;let r=e.steps[n];if(!r||r.settings===void 0)return e;let{settings:i,...a}=r,o={...e.steps};return Object.keys(a).length>0?o[n]=a:delete o[n],{...e,steps:o}})}function Ir(e,t,n){let r=e.filter(e=>e.key!==t).toSorted((e,t)=>e.key.localeCompare(t.key)),i=[...r.filter(e=>!e.enabled),...r.filter(e=>e.enabled),...e.filter(e=>e.key===t)],a;for(let e of i){let t=e.steps?.[n]?.settings;!t||Object.keys(t).length===0||(a={...a,...t})}return a}function Lr(e){let t={};for(let n of e){let e=Object.keys(n.steps).length>0;t[n.key]={enabled:n.enabled,weight:Math.max(1,n.weight),...n.maxSessions!==null&&n.maxSessions>0?{maxSessions:n.maxSessions}:{},...e?{steps:n.steps}:{}}}return t}var Rr=`pipeline-orchestrator`;function zr({addonId:e,highlightLabel:t}){let n=Jt(e),{data:r}=kt({addonId:Rr});if(n.length===0)return null;let a=Qt(r??null)[e]??{};return i(`section`,{className:`space-y-1.5 border-t border-border/60 pt-3`,"aria-label":`Cluster-wide settings`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:m,children:`Cluster-wide settings`}),d(ln,{to:Uo(e),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Edit in Cluster → Settings ›`})]}),n.map(e=>i(`div`,{className:`${T} rounded px-2 ${t===e.label?`bg-primary/5 ring-1 ring-primary/40`:``}`,children:[d(`span`,{className:p,children:e.label}),d(`span`,{className:_,children:d(`span`,{className:`font-mono text-xs text-foreground`,children:String(a[e.key]??e.default)})})]},e.key)),d(`p`,{className:y,children:`One value for every node and camera — this step writes into a shared index.`})]})}function Br({rows:e}){return i(`div`,{className:`space-y-1.5`,"data-testid":`effective-models`,children:[d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.map(e=>i(`li`,{className:`${b} flex flex-wrap items-baseline gap-x-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-foreground-muted`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:e.modelId??`—`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.sourceLabel})]},e.id))}),d(`p`,{className:y,children:`To change a model, open that accelerator's cell in the table.`})]})}r();function Vr(e,n){let[r,i]=sn(),o=r.get(Nn),s=r.get(`acc`),c=a(()=>In(e,n,{step:o,acc:s}),[e,n,o,s]),l=t(e=>{i(t=>{let n=new URLSearchParams(t);return e(n),n},{replace:!0})},[i]);return{selection:c,open:t(e=>l(t=>{t.set(Nn,e.stepId),e.acceleratorId===void 0?t.delete(`acc`):t.set(`acc`,e.acceleratorId)}),[l]),close:t(()=>l(e=>{e.delete(Nn),e.delete(`acc`)}),[l])}}function Hr(e,t){for(let n of e?.slots??[])for(let e of n.addons)if(e.id===t)return e;return null}function Ur(e){return e.split(`.`)[0]??e}function Wr(e,t,n){return{id:Fn(e,n.key),nodeId:e,deviceKey:n.key,device:n,label:`${Ur(t)} · ${G(n)}`,shortLabel:`${Ur(t)} · ${ut(n)}`,nodeLabel:Ur(t),disabled:!n.enabled}}function Gr(e,t,n,r=!1){return n.filter(e=>r||e.enabled).map(n=>Wr(e,t,n))}function Kr(e,t,n=!1){return e.flatMap(e=>{let r=t[e.id]??[];if(n)return r.map(t=>Wr(e.id,e.name,t));let i=r.filter(e=>e.enabled&&e.available);if(i.length>0)return i.map(t=>Wr(e.id,e.name,t));let a=r.find(e=>e.available)??r[0];return a===void 0?[]:[Wr(e.id,e.name,a)]})}function qr(e,t,n){return{modelId:st({catalog:e,device:t.device,base:n.nodePin,override:n.cameraPin}),source:n.cameraPin===void 0?n.nodePin===void 0?`default`:`node`:`camera`}}function Jr(e,t,n){let r=Hr(e,`object-detection`);if(r===null)return;let i=st({catalog:r,device:t.device,base:t.device.steps?.[`object-detection`]?.modelId,override:n});if(i===void 0)return;let a=r.models.find(e=>e.id===i);return{modelId:i,name:a?.name??i,supplies:a?.suppliesSteps??[]}}function Yr(e,t,n){return!an(e)||n===void 0?!1:Wt(e,t,n.supplies).effective}function Xr(e,t){return e!==null&&Ot(e.models,t.device.format)}function Zr(e){return Xr(e.addon,e.acc)?e.clusterModelId===void 0?{kind:`enabled`,modelId:e.model.modelId??`Auto`,overridden:e.model.source===`camera`,...e.rootName===void 0?{}:{suppliedByRoot:e.rootName},...e.jumpTo===void 0?{}:{jumpTo:e.jumpTo}}:{kind:`enabled`,modelId:e.clusterModelId,clusterWide:!0}:e.gatedOn?e.jumpTo===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:e.jumpTo}:{kind:`na`}}function Qr(e){return Object.values(e).reduce((e,t)=>e+t.filter(e=>!e.enabled).length,0)}function $r(e){if(e===null)return[];let t=(e.configSchema??[]).flatMap(e=>`label`in e&&typeof e.label==`string`?[e.label]:[]),n=Jt(e.id).map(e=>e.label);return[...new Set([...t,...n])]}function ei(e){return e.flatMap(e=>[{node:e,depth:0},...ei(e.children).map(e=>({node:e.node,depth:e.depth+1}))])}function ti(e,t){return e.flatMap(e=>{let n=ti(e.children,t);return t.has(e.addonId)||n.length>0?[{...e,children:n}]:[]})}r();function ni(e){return{agentNodeId:e.nodeId,nodeLabel:e.nodeLabel,engineLabel:e.device.format,deviceKey:e.deviceKey,deviceLabel:G(e.device),detail:e.device.defaultModelId,disabled:e.disabled}}function ri({tree:e,searchRows:r,accelerators:o,cellState:s,stepBadge:c,disabledCount:l,showDisabled:f,onShowDisabledChange:p,dirty:m,onDiscard:h,summary:g,toolbar:_,label:v,renderDetail:b}){let x=vt(),S=ee(),{selection:C,open:w,close:T}=Vr(a(()=>ei(e).map(e=>e.node.addonId),[e]),a(()=>o.map(e=>e.id),[o])),[E,D]=u(``),[O,k]=u(null),[A,j]=u(null),M=n(null),N=n(null),P=n(null),F=n(null),L=a(()=>I(r,E),[r,E]),te=a(()=>E.trim()===``?e:ti(e,new Set(L.map(e=>e.addonId))),[e,L,E]),re=e=>L.find(t=>t.addonId===e)?.matchedField??null,ie=a(()=>o.map(ni),[o]),R=e=>o.find(t=>t.nodeId===e.agentNodeId&&t.deviceKey===e.deviceKey),z=o.find(e=>e.id===C.acceleratorId)??null,B=C.stepId!==null,V=t(async e=>{if(m){if(!await x({title:`Discard unsaved changes?`,message:`This step has changes that are not saved yet.`,confirmLabel:`Discard`,variant:`danger`}))return;h()}e()},[x,m,h]),oe=()=>{requestAnimationFrame(()=>F.current?.focus())},se=(e,t,n=!1)=>{if(e===C.stepId&&(t?.id??null)===C.acceleratorId){n&&oe();return}let r=()=>{k(re(e)),w({stepId:e,...t===void 0?{}:{acceleratorId:t.id}}),n&&oe()};e===C.stepId?r():V(r)},H=()=>{let e=C.stepId;V(()=>{if(T(),e!==null){let t=z===null?null:ae({agentNodeId:z.nodeId,deviceKey:z.deviceKey});requestAnimationFrame(()=>M.current?.focusCell(e,t))}})},ce=e=>{if(e.key===`Enter`){let t=L[0];if(t===void 0)return;e.preventDefault(),se(t.addonId,void 0,!0)}else e.key===`Escape`&&D(``)},le=S?d(ne,{onClick:H}):d(ke,{icon:nt,variant:`ghost`,size:`sm`,"aria-label":`Close`,onClick:H});return i(`div`,{ref:N,className:`space-y-2`,onKeyDown:e=>{let t=e.target instanceof HTMLElement&&e.target.dataset.r!==void 0;e.key===`/`&&t&&(e.preventDefault(),P.current?.focus()),e.key===`Escape`&&t&&B&&(e.preventDefault(),H())},children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`div`,{className:`min-w-0 basis-full sm:basis-auto`,children:g}),d(`input`,{ref:P,type:`search`,value:E,onChange:e=>D(e.target.value),onKeyDown:ce,placeholder:`Filter steps or settings /`,"aria-label":`Filter steps or settings`,className:`h-9 w-56 rounded-md border border-border bg-background px-2 text-xs text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30 md:h-7`}),l>0&&i(`label`,{className:`inline-flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(Et,{checked:f,onChange:e=>p(e.target.checked)}),`Show disabled accelerators (`,l,`)`]}),_]}),C.staleStepId!==null&&i(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:[`The link names a step this pipeline does not have (`,C.staleStepId,`).`]}),te.length===0?i(`p`,{className:`${y} rounded-md border border-dashed border-border px-3 py-4 text-center`,children:[`No step matches “`,E,`”.`]}):d(je,{ref:M,tree:te,agents:ie,label:v,getCellState:(e,t)=>{let n=R(t);return n===void 0?{kind:`na`}:s(e,n)},onCellClick:(e,t,n)=>se(e,R(t),n),onStepClick:(e,t)=>se(e,void 0,t),...c===void 0?{}:{stepBadge:c},selectedCell:B&&C.stepId!==null&&z!==null?{addonId:C.stepId,agentNodeId:z.nodeId,deviceKey:z.deviceKey}:null,fallbackNodeId:A,onFallbackNodeChange:j,reserveRightPx:B&&!S?432:0}),d(ge,{open:B,anchor:N,onClose:H,label:`Step settings`,children:C.stepId!==null&&b({stepId:C.stepId,accelerator:z,matchedField:O,closeButton:le,onEscape:H,headingRef:e=>{F.current=e}})})]})}r();function ii(e){f(()=>{if(e===null)return;let t=document.getElementById(e);t===null||typeof t.scrollIntoView!=`function`||t.scrollIntoView({block:`center`,behavior:`smooth`})},[e])}r();function ai(e,t){let n=e.filter(e=>e.steps?.[t]?.settings!==void 0),r=e=>e.toSorted((e,t)=>e.key.localeCompare(t.key));return r(n.filter(e=>e.enabled))[0]?.key??r(n)[0]?.key??r(e.filter(e=>e.enabled))[0]?.key??e[0]?.key}function oi(e,t){let n=t.settings===void 0?void 0:ai(e,t.stepId),r=e.map(e=>{let r={...e.steps},i=r[t.stepId]??{},a=t.models[e.key],o=t.jumps[e.key],s=e.key===n&&t.settings!==void 0?Object.keys(t.settings).length>0?t.settings:void 0:i.settings,c=a===void 0?i.modelId:a??void 0,l=o===void 0?i.jumpDeviceKey:o||void 0,u={...c===void 0?{}:{modelId:c},...s===void 0?{}:{settings:s},...l===void 0?{}:{jumpDeviceKey:l}};return Object.keys(u).length>0?r[t.stepId]=u:delete r[t.stepId],{key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:r}});return n===void 0?r:Fr(r,n,t.stepId)}function si(e,t,n){if(t===null)return 0;let r=Object.entries(t.models).filter(([n,r])=>(r??void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.modelId).length,i=Object.entries(t.jumps).filter(([n,r])=>(r||void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.jumpDeviceKey).length,a=new Set([...Object.keys(n),...Object.keys(t.settings??{})]),o=t.settings===void 0?0:[...a].filter(e=>!tn(n[e],t.settings?.[e])).length;return r+i+o}function ci({nodeId:e,nodeName:t,toolbar:n}){let r=c(),s=at({nodeId:e},{refetchOnMount:`always`}),l=_t({nodeId:e},{refetchOnMount:`always`}),f=Ut(kt({addonId:`pipeline-orchestrator`}).data??null),p=s.data?.devices??[],h=l.data??null,[g,_]=u(null),[v,b]=u(null),[x,S]=u(null),C=Ae({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),w=a(()=>h?Ce(h):[],[h]),T=a(()=>ei(w),[w]),[E,D]=u(!1),O=a(()=>Gr(e,t,p,E),[e,t,p,E]),k=a(()=>Gr(e,t,p),[e,t,p]),A=k.length>=2,j=(e,t)=>(t===void 0?void 0:Ir(p,t.deviceKey,e))??{},M=(e,t,n)=>{let r=n??t.device.steps?.[e?.id??``]?.jumpDeviceKey;if(r!==void 0&&r!==``)return k.find(e=>e.deviceKey===r);if(!Xr(e,t))return k.filter(n=>n.id!==t.id&&Xr(e,n)).toSorted((e,t)=>e.deviceKey.localeCompare(t.deviceKey))[0]},N=(e,t)=>{let n=Hr(h,e),r=Ko(e),i=Jr(h,t),a=j(e,t),o=M(n,t);return Zr({addon:n,acc:t,gatedOn:n?.enabledByDefault??!0,model:n?qr(n,t,{nodePin:t.device.steps?.[e]?.modelId}):{modelId:void 0,source:`default`},...Yr(e,a,i)&&i?{rootName:i.name}:{},...r?{clusterModelId:f[e]??r.defaultModelId}:{},...o?{jumpTo:ut(o.device)}:{}})},ee=T.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:$r(Hr(h,e.addonId))}));if(s.isLoading||l.isLoading)return d(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:`Loading pipeline…`});if(h===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Catalog unavailable.`});let P=i(`span`,{className:y,children:[`Accelerators:`,` `,d(`span`,{className:`text-foreground`,children:k.length>0?k.map(e=>ut(e.device)).join(` · `):`none enabled`}),p.some(e=>!e.enabled)&&i(o,{children:[` `,`— off:`,` `,p.filter(e=>!e.enabled).map(ut).join(`, `)]}),` `,`·`,` `,d(ln,{to:Wo(),className:`text-primary hover:underline`,children:`Cluster → Load balancing ›`})]});return d(ri,{tree:w,searchRows:ee,accelerators:O,cellState:N,disabledCount:p.filter(e=>!e.enabled).length,showDisabled:E,onShowDisabledChange:D,dirty:g!==null&&si(p,g,j(g.stepId,O[0]))>0,onDiscard:()=>_(null),summary:P,...n===void 0?{}:{toolbar:n},label:`Detection steps`,renderDetail:({stepId:n,accelerator:r,matchedField:a,closeButton:s,onEscape:c,headingRef:l})=>{let u=Hr(h,n);if(u===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No step selected.`});let f=g?.stepId===n?g:null,w=r??k[0]??O[0],T=j(n,w),E=f?.settings??T,D=si(p,f,T),N=e=>{S(null),_(t=>({...t?.stepId===n?t:{stepId:n,models:{},jumps:{}},...e}))},ee=Ko(n),P=Ve(u),F=w===void 0?void 0:Jr(h,w),I=e=>{let t=f?.models[e.deviceKey];return t===void 0?e.device.steps?.[n]?.modelId:t??void 0},L=w===void 0?void 0:qr(u,w,{nodePin:I(w)}).modelId,te=O.length>1&&O.some(e=>!tn(j(n,e),T)),ne=e=>{let t=I(e),r=qr(u,e,{nodePin:t}),a=Jr(h,e),s=Yr(n,f?.settings??j(n,e),a),c=f?.jumps[e.deviceKey],l=M(u,e,c),p=Xr(u,e)?s&&a?d(St,{rootModel:a,stepModelId:r.modelId}):void 0:i(o,{children:[`No `,e.device.format,` build of this step.`,` `,l?`It runs on ${l.shortLabel} instead.`:`It does not run here.`]}),m=A?i(`label`,{className:`block space-y-1`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:`Run on`}),d(R,{"aria-label":`Run on`,value:c??e.device.steps?.[n]?.jumpDeviceKey??``,options:[{value:``,label:`Auto (this accelerator, or the next one that can run it)`},...k.filter(t=>t.id!==e.id).map(e=>({value:e.deviceKey,label:`${e.label} · ${e.device.format}`}))],onChange:t=>N({jumps:{...f?.jumps,[e.deviceKey]:t.target.value}})}),d(`span`,{className:y,children:`Routes this step (and its child steps) to another accelerator of this node.`})]}):void 0;return{label:e.label,format:e.device.format,modelId:r.modelId,source:r.source===`node`?`node`:`default`,sourceLabel:r.source===`node`?`node pin`:`hardware default`,models:Ge(u.models??[],e.device.format),defaultModelId:u.defaultModelIdByFormat?.[e.device.format]??u.defaultModelId,expanded:v===e.id,onToggle:()=>b(t=>t===e.id?null:e.id),onChangeModel:t=>N({models:{...f?.models,[e.deviceKey]:t}}),...t===void 0?{}:{onReset:()=>N({models:{...f?.models,[e.deviceKey]:null}}),resetLabel:`Reset to hardware default`},...p===void 0?{}:{note:p},...m===void 0?{}:{extra:m},changed:f?.models[e.deviceKey]!==void 0||c!==void 0}},re=()=>{f!==null&&C.mutate({agentNodeId:e,inferenceDevices:Lr(oi(p,f))},{onSuccess:()=>{_(null),S({kind:`saved`})},onError:e=>S({kind:`error`,error:e.message})})};return d(Te,{ref:l,title:r===null?`${u.name} · ${t}`:`${u.name} · ${r.label}`,subtitle:r===null?`${u.slot} · every accelerator of ${t}`:`${u.slot} · ${r.device.format} · base for every camera that lands here`,leading:s,onEscape:c,saveBar:{dirtyCount:D,saving:C.isPending,status:x?.kind??null,...x?.error===void 0?{}:{error:x.error},onSave:re,onDiscard:()=>_(null)},children:i(`div`,{className:`space-y-3`,children:[i(`section`,{className:`space-y-2`,"aria-label":`Model`,children:[d(`h3`,{className:m,children:`Model`}),ee!==null&&w!==void 0?d(qo,{step:ee,engineFormat:w.device.format,runnableModelIds:Ge(u.models??[],w.device.format).map(e=>e.id)}):O.length===0?i(`p`,{className:y,children:[`No accelerator is enabled on this node —`,` `,d(ln,{to:Wo(),className:`text-primary hover:underline`,children:`enable one in Cluster → Load balancing`}),`.`]}):r===null?d(Br,{rows:O.map(e=>{let t=qr(u,e,{nodePin:I(e)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:t.source===`node`?`node pin`:`hardware default`}})}):d(Mt,{...ne(r)},r.id)]}),(P.length>0||F!==void 0)&&ee===null&&i(`section`,{"aria-label":`Settings`,className:`space-y-2 border-t border-border/60 pt-2`,children:[i(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`settings-scope`,children:[`Node-wide: these settings apply on every accelerator of `,t,`.`]}),te&&d(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-2 py-1 text-[11px] text-warning`,children:`This step's settings differ between this node's accelerators. Saving makes the values shown here node-wide.`}),d(li,{addon:u,fields:P,settings:E,modelId:tt(u,L,E,F),root:F,highlight:a,onChange:e=>N({settings:e})})]}),d(zr,{addonId:n,highlightLabel:a})]})})}})}function li({addon:e,fields:t,settings:n,modelId:r,root:i,highlight:a,onChange:o}){let s=t.find(e=>`label`in e&&e.label===a)?.key??null;return ii(s===null?null:wt(s)),d(ht,{addon:e,fields:t,layers:{node:n},target:`node`,labels:{node:`Node`},modelId:r,...i===void 0?{}:{rootModel:i},highlightKey:s,onChangeLayer:o})}r();function ui({nodeId:e,refreshToken:t}){let n=vt(),[r,a]=u(null),{nodes:s}=W(),c=s.find(t=>t.id===e)?.name??e,l=Bt({onSuccess:e=>{a(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),f=async()=>{await n({title:`Reset ${c} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(a(null),l.mutate({agentNodeId:e}))};return i(`div`,{className:`space-y-2`,children:[d(Pr,{nodeId:e}),d(ci,{nodeId:e,nodeName:c,toolbar:i(o,{children:[r&&d(`span`,{className:`text-[11px] text-success`,children:r}),l.isError&&d(`span`,{className:`text-[11px] text-danger`,children:l.error instanceof Error?l.error.message:`Reset failed`}),d(H,{variant:`outline`,size:`sm`,onClick:()=>{f()},disabled:l.isPending,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:l.isPending?`Resetting…`:`Reset to default`})]})})]})}var di=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],fi=`decoder-nodeav`,pi=`ntab`,mi={decoder:`engine`},hi={engine:`Engine & decoder`},gi=`Nothing here is set per node. Cluster-wide values are on Cluster → Settings.`;function _i({nodeId:e,refreshToken:t}){let[n,r]=sn(),{nodes:a}=W(),o=a.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??fi,s=[...di,o],c=n.get(pi),l={assignments:{id:`assignments`,label:`Assignments`,order:-10,content:d(Or,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:`Pipeline`,order:39,content:d(ui,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:`Warm instances`,order:180,content:d(Ar,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:`Logs`,order:300,content:d(Nr,{nodeId:e})}},u=Gn.map(e=>l[e]);return i(`div`,{className:`flex flex-col h-full`,children:[d(Wn,{nodeId:e,refreshToken:t}),d(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6`,children:d(dn,{nodeId:e,addonIds:s,level:`global`,fieldScope:`perNode`,emptyMessage:gi,tabAliases:mi,tabLabelOverrides:hi,extraTabs:u,schemaTabExtras:[{tabId:`engine`,placement:`before`,content:d(Zn,{nodeId:e})}],activeTab:c===null?null:mi[c]??c,onActiveTabChange:e=>r(t=>{let n=new URLSearchParams(t);n.set(pi,e);for(let e of Pn)n.delete(e);return n},{replace:!0})})})]})}function vi(){return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`min-w-0`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Camera placement`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pin a camera to a node, or to one accelerator of its node; Auto lets each session pick. Decode always runs with detection. Load, shares and caps are on Load balancing.`})]}),d(Er,{})]})}function yi(e){return`${Math.round(e*100)}%`}function bi(e){return`${e} session${e===1?``:`s`}`}var xi={"intel-npu":`Intel NPU`,"intel-igpu":`Intel iGPU`,"amd-igpu":`AMD iGPU (WebGPU)`,"amd-npu":`AMD XDNA NPU`,"x86-cpu":`CPU`,"arm-cpu":`CPU`,"apple-ane":`Apple Neural Engine`,coral:`Coral Edge TPU`},Si={"intel-core-ultra":`Intel Core Ultra`,"intel-n-series":`Intel N-series`,"apple-m-base":`Apple M (base)`,"apple-m-pro":`Apple M Pro / Max / Ultra`,"amd-phoenix":`AMD Ryzen Phoenix / Hawk Point`,unknown:`Not measured`};function Ci(e){return e===null?`—`:xi[e]??e}function wi(e){return e===null?`—`:Si[e]??e}function Ti(e){switch(e.kind){case`capacity`:return`Capacity ${bi(e.sessions)} ≥ min ${e.minSessions}.`;case`tie-faster`:return`As accurate as ${e.over} (within ${yi(e.recallDelta)} recall) and faster.`;case`stepped-down`:return`${e.from} would not fit the load on ${e.limitedBy}; ${e.to} is the most accurate that does.`;case`no-fit-lightest`:return`No model reaches ${bi(e.minSessions)} per device; the one with the most capacity (${bi(e.sessions)}) is used.`;case`derived-latency`:return`${e.modelId}: latency estimated from a similar chip, not measured on this one.`;case`cpu-device`:return`CPU fallback device: picked on its own.`;case`coral-untouched`:return`Coral: left as is (no YOLOv9 build exists for it).`;case`device-disabled`:return`Disabled: not changed.`;case`device-unavailable`:return`Not available on the node right now: not changed.`;case`node-offline`:return`Node offline: nothing on it will change.`;case`no-hardware-facts`:return`Hardware could not be read: nothing on this node will change.`;case`no-measured-data`:return`This hardware has no measured data: nothing on this node will change.`;case`no-family-build`:return`No YOLOv9 build for the ${e.format} format: not changed.`;case`kept-custom-pin`:return`Custom model ${e.modelId} is pinned on ${e.deviceKey}: Auto tune skips this device.`}}function Ei(e,t){switch(e.kind){case`detector-store-cluster-wide`:return`Per-camera detector thresholds are not tied to a node, so they are cleared for every camera — including cameras that run on skipped nodes (${e.skippedNodes.map(t).join(`, `)}).`;case`detector-store-unreadable`:return`Per-camera detector thresholds could not be read (${e.error}); those will not be cleared.`;case`coral-enabled`:return`${t(e.nodeId)}: the Coral (${e.deviceKey}) is enabled and keeps running its SSD model, which finds far fewer people than YOLOv9. Consider disabling it.`;case`custom-pin-kept`:return e.deviceId===null?`${t(e.nodeId)}: custom model ${e.modelId} pinned on ${e.deviceKey??`—`} — Auto tune skips this node device.`:`Camera ${e.deviceId} pins custom model ${e.modelId} on ${t(e.nodeId)} — Auto tune keeps that override and its thresholds.`;case`custom-registry-unreadable`:return`The custom-model registry could not be read (${e.error}): every pin to a model outside the measured catalog is kept.`}}function Di(e){let t=e.nodeChanges.reduce((e,t)=>e+t.modelPins.length,0),n=e.nodeChanges.reduce((e,t)=>e+t.thresholds.length,0),r=new Set([...e.cameraClears.map(e=>e.deviceId),...e.detectorStoreClears.map(e=>e.deviceId)]);return{modelChanges:t,thresholdClears:n,cameraOverrideClears:e.cameraClears.length,detectorStoreClears:e.detectorStoreClears.length,camerasTouched:r.size}}function Oi(e){let t=Di(e);return t.modelChanges+t.thresholdClears+t.cameraOverrideClears+t.detectorStoreClears===0}function ki(e,t,n){let r=e.nodeChanges.find(e=>e.nodeId===t&&e.deviceKey===n)?.modelPins.find(e=>e.stepId===`object-detection`);return r===void 0?null:{before:r.before,after:r.after}}function Ai(e,t){return e?.kind===`node-benchmark`?`measured on this node, ${new Date(e.measuredAtMs).toLocaleDateString(t,{day:`numeric`,month:`short`})}`:`from the latency table — benchmark this node to measure it`}r();var ji=[.3,.4,.5];function Mi(e){return ji.some(t=>t===e)}var Ni=[1,2,3,4,6,8];function Pi({plan:e,node:t,nodeName:n}){return i(`section`,{className:h,"data-testid":`auto-tune-node-${t.nodeId}`,children:[i(`header`,{className:`${v} flex flex-wrap items-center gap-2`,children:[d(V,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${m} min-w-0 flex-1`,children:n(t.nodeId)}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[wi(t.hardwareClass),t.cpuModel===null?``:` · ${t.cpuModel}`]}),t.skipped?d(K,{variant:`warning`,children:`Not changed`}):t.acceleratorModelId!==null&&d(K,{variant:`info`,children:t.acceleratorModelId})]}),t.reasons.length>0&&d(`ul`,{className:`px-3 pt-2 text-[11px] text-foreground-muted`,children:t.reasons.map((e,t)=>d(`li`,{children:Ti(e)},t))}),d(`div`,{className:`overflow-x-auto`,children:i(`table`,{className:`w-full text-xs`,children:[d(`thead`,{children:i(`tr`,{className:`text-left text-[11px] text-foreground-subtle`,children:[d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Device`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Capacity`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Detector`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Why`})]})}),d(`tbody`,{children:t.devices.map(n=>{let r=ki(e,t.nodeId,n.deviceKey);return i(`tr`,{className:`border-t border-border align-top`,children:[i(`td`,{className:`px-3 py-1.5`,children:[d(`div`,{className:`font-mono text-foreground`,children:n.deviceKey}),d(`div`,{className:`text-[11px] text-foreground-subtle`,children:Ci(n.accelerator)})]}),i(`td`,{className:`px-3 py-1.5 text-foreground-muted`,children:[n.chosen===null?`—`:`${n.chosen.capacitySessions} session${n.chosen.capacitySessions===1?``:`s`} at ${e.cameraFps} fps`,n.chosen!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n.chosen.fps,` fps, `,Math.round(e.headroom*100),`% kept free`,d(`div`,{children:Ai(n.chosen.source)})]})]}),d(`td`,{className:`px-3 py-1.5`,children:n.chosen===null?d(`span`,{className:`text-foreground-subtle`,children:`unchanged`}):r!==null&&r.before!==r.after?i(`span`,{children:[d(`span`,{className:`text-foreground-subtle`,children:r.before??`default`}),` → `,d(`span`,{className:`font-medium text-foreground`,children:r.after})]}):d(`span`,{className:`text-foreground`,children:n.chosen.modelId})}),d(`td`,{className:`px-3 py-1.5 text-[11px] text-foreground-muted`,children:n.reasons.map((e,t)=>d(`div`,{children:Ti(e)},t))})]},n.deviceKey)})})]})})]})}function Fi({plan:e,nameOf:t,nodeName:n}){return i(`div`,{className:`flex flex-col gap-3 text-xs`,"data-testid":`auto-tune-change-list`,children:[i(`div`,{children:[d(`div`,{className:m,children:`Node settings`}),e.nodeChanges.length===0?d(`div`,{className:`text-foreground-subtle`,children:`No change.`}):d(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:e.nodeChanges.flatMap(e=>[...e.modelPins.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: `,t.before??`default`,` → `,t.after??`step default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/pin`)),...e.thresholds.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: reset `,t.keys.join(`, `),` to the model default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/thr`))])})]}),i(`div`,{children:[d(`div`,{className:m,children:`Camera overrides cleared`}),e.cameraClears.length===0&&e.detectorStoreClears.length===0?d(`div`,{className:`text-foreground-subtle`,children:`None.`}):i(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:[e.cameraClears.map((e,r)=>i(`li`,{children:[t(e.deviceId),` — `,n(e.nodeId),e.deviceKey===null?` (whole pipeline)`:` · ${e.deviceKey}`,` — `,e.stepId,e.modelIdBefore===null?``:`: model ${e.modelIdBefore} removed`,e.keys.length>0?`; ${e.keys.join(`, `)} reset`:``]},`c${r}`)),e.detectorStoreClears.map(e=>i(`li`,{children:[t(e.deviceId),` — detector thresholds: `,e.keys.join(`, `),` reset`]},`d${e.deviceId}`))]})]})]})}function Ii({result:e}){return e.kind===`refused`?d(`div`,{className:`text-xs text-warning`,children:`Another apply is already running.`}):e.kind===`stale`?d(`div`,{className:`text-xs text-warning`,children:`The configuration changed since the plan was shown. Review the updated plan below and apply again.`}):i(`ul`,{className:`text-xs`,"data-testid":`auto-tune-result`,children:[e.kind===`aborted`&&d(`li`,{className:`text-danger`,children:`A model could not be downloaded: nothing was changed.`}),e.phases.map(e=>i(`li`,{className:e.ok?`text-foreground-muted`:`text-danger`,children:[e.ok?`✓`:`✗`,` `,e.phase,`: `,e.detail]},e.phase))]})}function Li(){let e=c(),[t,n]=u(.4),[r,o]=u(2),[s,l]=u(!1),[f,p]=u(!1),[g,_]=u(null),{data:y}=cn(),b=a(()=>new Map((y??[]).map(e=>[e.id,e.name])),[y]),x=e=>b.get(e)??`Camera ${e}`,{nodes:S}=W(),C=a(()=>ar(S),[S]),w=ce({headroom:t,minSessionsPerDevice:r},{enabled:s,refetchOnWindowFocus:!1}),T=Qe({onSuccess:t=>{_(t),p(!1),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),t.kind===`applied`&&w.refetch()}}),E=g?.kind===`stale`?g.plan:w.data,D=E===void 0?null:Di(E);return i(`div`,{className:`flex flex-col gap-3`,"data-testid":`cluster-auto-tune`,children:[i(`section`,{className:h,children:[i(`header`,{className:`${v} flex flex-wrap items-center gap-2`,children:[d(ve,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${m} min-w-0 flex-1`,children:`Auto tune`})]}),i(`div`,{className:`flex flex-col gap-2 px-3 py-2 text-xs text-foreground-muted`,children:[d(`p`,{children:`Picks, for every accelerator, the most accurate YOLOv9 detector that still carries at least the chosen number of cameras at once, from the node's hardware and measured speeds. Nothing is measured or estimated about your cameras' activity. Applying it sets those models and clears every model and threshold override — node level and per camera — so each model runs its own default thresholds. Enabled steps, devices, pins, recording, notifications, zones and rules are not touched. There is no undo.`}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`Keep free`}),d(R,{"aria-label":`Share of each accelerator kept free`,value:String(t),options:ji.map(e=>({value:String(e),label:`${Math.round(e*100)}% of each accelerator`})),onChange:e=>{let t=Number(e.target.value);Mi(t)&&n(t)}})]}),i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`At least`}),d(R,{"aria-label":`Minimum parallel sessions per device`,value:String(r),options:Ni.map(e=>({value:String(e),label:`${e} camera${e===1?``:`s`} at once per accelerator`})),onChange:e=>{let t=Number(e.target.value);Ni.some(e=>e===t)&&o(t)}})]}),d(H,{size:`sm`,variant:`secondary`,onClick:()=>{_(null),l(!0),s&&w.refetch()},children:w.isFetching?`Computing…`:E===void 0?`Compute plan`:`Recompute`}),E!==void 0&&d(H,{size:`sm`,disabled:Oi(E),onClick:()=>p(!0),children:`Apply…`})]}),w.error!==null&&d(`div`,{className:`text-danger`,children:w.error.message}),g!==null&&d(Ii,{result:g}),D!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[D.modelChanges,` model change(s), `,D.thresholdClears,` node threshold reset(s), `,D.cameraOverrideClears+D.detectorStoreClears,` camera override(s) on `,D.camerasTouched,` camera(s).`]})]})]}),E?.warnings.map((e,t)=>d(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:Ei(e,C)},t)),E?.nodes.map(e=>d(Pi,{plan:E,node:e,nodeName:C},e.nodeId)),E!==void 0&&d(Ft,{open:f,onOpenChange:p,children:i(L,{width:`lg`,scroll:`body`,children:[i(re,{children:[d(te,{children:`Apply auto tune?`}),d(Nt,{children:`These are all the changes. Every override listed is removed and cannot be restored.`})]}),d(we,{children:d(Fi,{plan:E,nameOf:x,nodeName:C})}),i(De,{children:[d(H,{variant:`ghost`,onClick:()=>p(!1),children:`Cancel`}),d(H,{variant:`danger`,disabled:T.isPending,onClick:()=>T.mutate({planHash:E.planHash,headroom:t,minSessionsPerDevice:r}),children:T.isPending?`Applying…`:`Apply`})]})]})})]})}var Ri={disabled:`switched off — not a dispatch target`,unavailable:`the node probe does not see it (unplugged or still provisioning)`,"cannot-host-camera-root":`its engine format has no object-detection root model`,"accelerator-preferred":`CPU fallback — it never competes while an accelerator is serving`};function zi(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function Bi(e){return e===void 0?!1:e.load.devices.reduce((e,t)=>e+t.attachedCameras,0)>=e.load.attachedCameras}function Vi(e,t,n){let r=e.filter(e=>e.exclusion===null).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.map(e=>{let i=t.get(e.key)??(n?0:null),a=e.weight>0?e.weight:1;return{key:e.key,label:G(e),format:e.format,sessions:i,weight:a,weightSharePct:e.exclusion===null?zi(a,r):null,maxSessions:e.maxSessions,atCap:e.maxSessions!==null&&i!==null&&i>=e.maxSessions,available:e.available,enabled:e.enabled,exclusion:e.exclusion}}).toSorted((e,t)=>e.exclusion===null==(t.exclusion===null)?e.key.localeCompare(t.key):e.exclusion===null?-1:1)}function Hi(e){let t=new Map(e.loads.map(e=>[e.nodeId,e])),n=e.nodes.filter(e=>e.isOnline&&e.detectEnabled).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.nodes.map(r=>{let i=t.get(r.id),a=Vi(e.devicesByNode[r.id]??[],new Map((i?.load.devices??[]).map(e=>[e.deviceKey,e.attachedCameras])),Bi(i)),o=r.isOnline&&r.detectEnabled,s=r.weight>0?r.weight:1,c=i?.load.attachedCameras??null;return{nodeId:r.id,name:r.name,isOnline:r.isOnline,detectEnabled:r.detectEnabled,reported:i!==void 0,attachedCameras:c,activeCameras:i?.load.activeCameras??null,maxCameras:r.maxCameras,capacityPct:c!==null&&r.maxCameras!==null&&r.maxCameras>0?zi(c,r.maxCameras):null,queueDepthTotal:i?.load.queueDepthTotal??null,avgInferenceTimeMs:i?.load.avgInferenceTimeMs??null,score:i?.score??null,weight:s,weightSharePct:o?zi(s,n):null,decodeHwaccel:i?.decodeHwaccel??null,devices:a,eligibleDeviceCount:a.filter(e=>e.exclusion===null).length}})}r();var Ui=2e4,Wi=3e5;function Gi({stats:e,targetWeights:t}){let{nodes:n}=W(),r=x().trpcClient,o=Rt(void 0,{placeholderData:l,staleTime:Ui,refetchInterval:Ui,refetchOnWindowFocus:!0}),c=z(void 0,{staleTime:Wi}),u=a(()=>n.map(e=>e.id),[n]),f=s({queries:u.map(e=>({queryKey:on(mt.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Wi,refetchOnWindowFocus:!1,placeholderData:l}))}),p=a(()=>{let e={};return u.forEach((t,n)=>{let r=f[n]?.data;r&&(e[t]=r.devices)}),e},[u,f.map(e=>e.dataUpdatedAt).join(`|`)]),m=a(()=>{let e=new Map;for(let t of c.data??[])e.set(t.nodeId,t.settings);return e},[c.data]),h=a(()=>n.map(e=>{let n=m.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:Vn(n,e.isHub).pipeline,weight:t?.[e.id]??Sn(n,`detectWeight`)??1,maxCameras:Sn(n,`maxCameras`)}}),[n,m,t]),_=o.data??[],v=a(()=>Hi({nodes:h,loads:_,devicesByNode:p}),[h,_,p]),y=v.reduce((e,t)=>e+(t.attachedCameras??0),0),b=v.reduce((e,t)=>e+(t.activeCameras??0),0),S=o.dataUpdatedAt>0?Date.now()-o.dataUpdatedAt:null,C=new Map((e?.nodes??[]).map(e=>[e.nodeId,e]));return d(U,{headingId:`load-balancing-node-load`,title:`Node load`,icon:Ee,actions:i(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[b,` running · `,y,` attached ·`,` `,o.data===void 0?`reading…`:`${S===null?`—`:`${Math.round(S/1e3)}s`} old`]}),children:d(`div`,{className:g,children:v.length===0?d(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):d(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:v.map(e=>d(Ki,{row:e,placed:C.get(e.nodeId)},e.nodeId))})})})}function Ki({row:e,placed:t}){let n=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[d(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),d(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&d(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`no detect`}),!e.reported&&e.isOnline&&i(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`,children:[d(zt,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&i(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[d(We,{className:`h-2.5 w-2.5`}),` offline`]})]}),i(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[d(J,{label:`Running / attached`,value:n,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),d(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`The node share (automatic or manual) normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),d(J,{label:`Actual share (1 h)`,value:t?.observedShare===null||t===void 0?`—`:`${Math.round(t.observedShare*100)}%`,title:`Time-weighted share of the cluster's PARALLEL detection sessions this node carried over the last hour — the quantity a share holds. '—' = no session ran here in the window.`}),d(J,{label:`Peak · yields`,value:t===void 0?`—`:`${t.peakSessions} · ${t.yieldsAway}`,title:`Most sessions this node ran at once in the last hour, and how many share turns it handed to another node because it was full or drowning.`}),d(J,{label:`Score · queue`,value:e.score===null?`—`:`${e.score} · ${e.queueDepthTotal??0}`,title:`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`}),e.capacityPct!==null&&d(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&d(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&d(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),d(qi,{row:e})]})}function qi({row:e}){return e.devices.length===0?d(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):i(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[i(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[d(it,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&d(`span`,{className:`ml-1 normal-case tracking-normal text-amber-400`,title:`No device is a camera-root candidate on this node — sessions run on the runner's default (CPU) pool.`,children:`none in play · runner default pool`})]}),d(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>d(Ji,{device:e},e.key))})]})}function Ji({device:e}){let t=e.exclusion;return i(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[d(V,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),d(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?i(o,{children:[i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,title:e.sessions===null?`Not known: the node did not report, or runs a session no device accounts for.`:void 0,children:[`· `,e.sessions??`—`,` session`,e.sessions===1?``:`s`,e.maxSessions===null?``:`/${e.maxSessions}`]}),e.atCap&&d(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):i(`span`,{className:`truncate text-foreground-subtle/80`,title:Ri[t],children:[`excluded — `,Ri[t]]})]})}function J({label:e,value:t,title:n}){return i(`div`,{className:`min-w-0`,title:n,children:[d(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function Yi(e){return{nodes:Object.fromEntries(e.map(e=>[e.nodeId,Math.max(1,e.weight)])),devices:{}}}function Xi(e){let t={},n={};for(let r of e.nodes){if(r.share===null||r.share<=0)continue;t[r.nodeId]=r.share;let e=Object.fromEntries(r.devices.filter(e=>e.share>0).map(e=>[e.deviceKey,e.share]));Object.keys(e).length>0&&(n[r.nodeId]=e)}return{nodes:t,devices:n}}function Zi(e){return Object.fromEntries(e.nodes.map(e=>[e.nodeId,Object.fromEntries(e.devices.map(e=>[e.deviceKey,e.suggestedMaxSessions]))]))}function Qi(e){return e.reason===`disabled`?`${e.deviceKey} is not enabled on any node — sessions ignore this pin`:`no node offers ${e.deviceKey} — sessions ignore this pin`}function $i(e,t){if(t===void 0||t.source===`manual`||t.autoPending)return{nodes:e,readOnly:t!==void 0&&t.source!==`manual`};let n=new Map(t.nodes.map(e=>[e.nodeId,e.configuredPct]));return{nodes:e.map(e=>({...e,weight:Math.round(n.get(e.id)??e.weight)})),readOnly:!0}}function ea(e,t){let n=e.nodes.filter(e=>!e.eligible);if(n.length===0)return null;let r=e.nodes.filter(e=>e.eligible).map(e=>`${t(e.nodeId)} ${Math.round(e.effectivePct)}%`).join(`, `);return`${n.map(e=>t(e.nodeId)).join(`, `)} cannot take sessions — ${n.length===1?`its share goes`:`their shares go`} to the others: ${r}`}var ta=[{value:`hardware`,label:`Hardware`,hint:`Each node’s share follows what its accelerators can carry at their Auto tune models, from the measured speed of its hardware. No load is measured or estimated.`},{value:`benchmark`,label:`Benchmark`,hint:`Each node’s share follows its own node-benchmark results. A node without results uses its hardware capacity instead, and says so.`},{value:`manual`,label:`Manual`,hint:`The sliders below, as you set them.`}];function na(e){return e===`no-benchmark-results`?`no benchmark results yet — sized from hardware`:e===`partial-benchmark-results`?`benchmark results miss some of its accelerators — sized from hardware`:null}function ra(e,t){if(e.source!==`benchmark`)return null;let n=e.nodes.filter(e=>e.capacityFallback!==null);return n.length===0?null:n.map(e=>`${t(e.nodeId)}: ${na(e.capacityFallback)??``}`).join(` · `)}r();function ia(e,t,n){return Math.min(Math.max(e,t),n)}function aa(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function oa(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:ia(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function sa(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function ca({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:a,footnote:s,readOnly:c=!1}){let[l,p]=u(()=>aa(e)),[m,h]=u(new Set);f(()=>{p(aa(e)),h(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let g=e.map(e=>e.id),_=e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=(e,t)=>{p(n=>oa(n,e,t,m,g))},y=()=>{let t=sa(l,g,m),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...m]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:a??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let b=e.length===1;return i(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=l[e.id]??0,a=m.has(e.id);return i(`div`,{className:`flex items-center gap-3`,children:[d(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),d(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:c||t||a||b,onChange:t=>v(e.id,Number(t.target.value)),onPointerUp:()=>y(),onKeyUp:()=>y(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),i(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),!c&&d(`button`,{type:`button`,onClick:()=>_(e.id),disabled:t||b,"aria-pressed":a,title:a?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${a?`text-amber-400`:`text-foreground-subtle`}`,children:d(a?lt:$e,{className:`h-3.5 w-3.5`})})]},e.id)}),d(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:s??d(o,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}function la(e){let t=e.steps?.[`object-detection`]?.modelId;return typeof t==`string`&&t.length>0?t:typeof e.defaultModelId==`string`&&e.defaultModelId.length>0?e.defaultModelId:null}r();function ua(e){let t=G(e),n=e.backend.toLowerCase(),r=e.device.toLowerCase();return e.key===`cpu`||r===`cpu`?{label:t,Icon:V,hue:`slate`}:r===`npu`?{label:t,Icon:Ct,hue:`sky`}:r===`gpu`||r===`igpu`?{label:t,Icon:On,hue:`violet`}:n===`edgetpu`?{label:t,Icon:Mn,hue:`emerald`}:{label:t,Icon:V,hue:`slate`}}var da={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function fa({nodeId:e,nodeName:t,isOnline:n,suggestedMaxSessions:r,autoDeviceShares:s}){let l=c(),{data:p,isLoading:m}=at({nodeId:e},{refetchInterval:15e3}),h=Ae({onSettled:()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),g=p?.devices??[],_=p?.reachable??n,[v,y]=u({});f(()=>{y(Object.fromEntries(g.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[g.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let b=a(()=>g.filter(e=>v[e.key]?.enabled??e.enabled).length,[g,v]),[x,S]=u(null),C=x??b>0,T=t=>{let n=g.map(e=>{let n=t[e.key]??E(e);return{key:e.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});h.mutate({agentNodeId:e,inferenceDevices:Lr(n)})},E=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),D=e=>{if(!e.available)return;let t=v[e.key]??E(e),n={...v,[e.key]:{...t,enabled:!t.enabled}};y(n),T(n)},O=(e,t)=>{let n=v[e.key]??E(e),r={...v,[e.key]:{...n,maxSessions:t}};y(r),T(r)},k=a(()=>g.filter(e=>(v[e.key]?.enabled??e.enabled)&&e.available),[g,v]),A=a(()=>k.map(e=>({id:e.key,name:ua(e).label,weight:s===void 0?v[e.key]?.weight??e.weight:Math.round(s[e.key]??0)})),[k,v,s]);return i(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[i(`button`,{type:`button`,onClick:()=>S(!C),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":C,children:[d(w,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${C?`rotate-90`:``}`}),d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t}),d(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:_?b>=2?i(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[d(Ht,{className:`h-3.5 w-3.5`}),b,` accelerators`]}):b===1?d(`span`,{className:`text-foreground-subtle`,children:`single default`}):d(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):i(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[d(We,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),C&&i(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[_?m&&g.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):g.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`}):d(`ul`,{className:`space-y-2`,children:g.map(e=>{let t=ua(e),n=v[e.key]??E(e),a=n.enabled&&e.available,s=la({defaultModelId:e.defaultModelId,steps:n.steps});return i(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?a?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[d(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${da[t.hue]}`,children:d(t.Icon,{className:`h-4.5 w-4.5`})}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),d(K,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&d(K,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`font-mono`,children:e.key}),s!==null&&i(o,{children:[d(`span`,{"aria-hidden":!0,children:`·`}),i(`span`,{children:[`root model`,` `,d(`span`,{className:`font-mono text-foreground/80`,children:s})]})]})]})]}),a&&i(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),d(`input`,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);O(e,r!=null&&r>0?r:null)},disabled:h.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),a&&d(pa,{suggested:r?.[e.key]??null,current:n.maxSessions,pending:h.isPending,onApply:t=>O(e,t)}),d(Je,{checked:a,onCheckedChange:()=>D(e),disabled:!e.available||h.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):d(ma,{}),_&&k.length>=2&&i(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[i(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[d(jn,{className:`h-3.5 w-3.5`}),`Accelerator share`]}),d(ca,{nodes:A,pending:h.isPending,onCommitWeights:e=>{let t={...v};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}y(t),T(t)},weightLabel:`Accelerator share`,readOnly:s!==void 0,footnote:s===void 0?d(o,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`}):d(o,{children:`Automatic: each accelerator's share follows its measured throughput at its model. Switch the node shares to manual to set them yourself.`})})]}),h.isError&&i(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,h.error instanceof Error?h.error.message:`unknown error`]})]})]})}function pa({suggested:e,current:t,pending:n,onApply:r}){return e===null||e<1||e===t?null:i(H,{variant:`ghost`,size:`sm`,onClick:()=>r(e),disabled:n,title:`Advisory cap from the measured throughput at the suggested model, with the headroom kept free. Applying it writes this device's cap.`,children:[`use `,e]})}function ma(){return i(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[d(We,{className:`h-6 w-6 text-foreground-subtle/60`}),d(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),d(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}r();var ha=3600*1e3,ga=2e4,_a=.4;function va({refreshToken:e,onOpenAutoTune:t}){let n=c(),{nodes:r}=W(),s=z(void 0),f=ot({isCamera:!0,projection:`slim`}),p=he({windowMs:ha},{refetchInterval:ga,placeholderData:l}).data,m=_e(void 0,{refetchInterval:ga,placeholderData:l}).data,h=()=>{hn(n),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},_=xe({onSuccess:h}),v=qe({onSuccess:()=>{h(),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getEffectiveShares`]]})}}),x=Fe({onSuccess:h}),S=de(),[C,w]=u(!1),T=m?.source,E=T===`benchmark`?`benchmark`:`hardware`,D=Tt({headroom:_a,source:E},{enabled:C,staleTime:1/0}),O=D.data,k=a(()=>{let e=new Map((s.data??[]).map(e=>[e.nodeId,e.settings]));return r.filter(t=>Vn(e.get(t.id),t.isHub).pipeline).map(t=>{let n=e.get(t.id);return{id:t.id,name:t.name,isOnline:t.isOnline,weight:Sn(n,`detectWeight`)??1,maxCameras:Sn(n,`maxCameras`)}})},[r,s.data]),A=e=>r.find(t=>t.id===e)?.name??e,j=or((f.data??[]).map(e=>({id:e.id,name:e.name}))),M=O?Zi(O):void 0,N=$i(k,m),ee=T!==`manual`,P=e=>{if(m===void 0||m.source===`manual`||m.autoPending)return;let t=m.nodes.find(t=>t.nodeId===e);return t===void 0?void 0:Object.fromEntries(t.devices.map(e=>[e.deviceKey,e.configuredPct]))},F=m?ea(m,A):null,I=m?ra(m,A):null,L=ta.find(e=>e.value===T)?.hint;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(dn,{nodeId:`hub`,addonIds:[pn],level:`global`,sectionIds:[`load`],title:`Placement policy`,description:`How a new detection session picks its node and device, and what happens when a node falls behind. 'Honour shares' (default) holds the shares below for PARALLEL sessions.`}),d(Qn,{refreshToken:e}),d(Gi,{stats:p,...m!==void 0&&m.source!==`manual`&&!m.autoPending?{targetWeights:Object.fromEntries(m.nodes.map(e=>[e.nodeId,e.configuredPct]))}:{}}),d(U,{headingId:`load-balancing-node-shares`,title:`Node shares`,icon:jn,actions:i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`div`,{role:`radiogroup`,"aria-label":`Share source`,className:`flex items-center gap-1`,children:ta.map(e=>d(H,{role:`radio`,"aria-checked":T===e.value,variant:T===e.value?`primary`:`outline`,size:`sm`,title:e.hint,disabled:v.isPending||m===void 0,onClick:()=>{T!==e.value&&v.mutate({source:e.value})},children:e.label},e.value))}),i(H,{variant:`outline`,size:`sm`,onClick:()=>{w(!0),C&&D.refetch()},disabled:D.isFetching,children:[d(Lt,{className:`h-3.5 w-3.5`}),D.isFetching?`Suggesting…`:E===`benchmark`?`Suggest from benchmark`:`Suggest from hardware`]}),i(H,{variant:`ghost`,size:`sm`,onClick:t,children:[d(ve,{className:`h-3.5 w-3.5`}),`Auto tune`]}),i(H,{variant:`outline`,size:`sm`,onClick:()=>S.mutate(void 0),disabled:S.isPending,title:`Move standing (always-on) cameras that are no longer on their best node. Pinned cameras never move; on-motion sessions are placed per session anyway.`,children:[d(Ct,{className:`h-3.5 w-3.5`}),S.isPending?`Rebalancing…`:`Rebalance`]})]}),children:i(`div`,{className:`${g} space-y-3`,children:[L!==void 0&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:L}),p&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Policy:`,` `,d(K,{variant:p.policy===`share`?`info`:`default`,children:p.policy===`share`?`honour shares`:`least-loaded`}),` `,`· cluster peak `,p.clusterPeakSessions,` parallel sessions in the last hour`,p.policy===`least-loaded`&&` · under least-loaded an idle node always wins, so shares only bite once nodes are busy`]}),d(ca,{nodes:N.nodes,pending:_.isPending,readOnly:N.readOnly,onCommitWeights:e=>_.mutate(Yi(e)),weightLabel:`Node share`,...N.readOnly?{footnote:m?.autoPending?d(o,{children:`Automatic shares are being computed from the cluster's measured capacity; the stored values are used meanwhile.`}):i(o,{children:[T===`benchmark`?`Benchmark: each node's share follows its measured capacity from node benchmark results (hardware capacity where it has none)`:`Hardware: each node's share follows its capacity at its Auto tune model, from the measured speed of its hardware`,`, recomputed whenever a node or accelerator is added, removed, switched on or off, or changes model`,m?.computedAt==null?``:` — last at ${new Date(m.computedAt).toLocaleTimeString()}${m.trigger===null?``:` (${m.trigger})`}`,`.`]})}:{}}),F!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:F}),I!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`benchmark-fallback-note`,children:I}),v.isError&&d(me,{message:`Failed to switch shares: ${v.error instanceof Error?v.error.message:`unknown error`}`}),_.isError&&d(me,{message:`Failed to save shares: ${_.error instanceof Error?_.error.message:`unknown error`}`}),i(`details`,{className:`rounded-md border border-border`,children:[d(`summary`,{className:`${b} cursor-pointer text-xs text-foreground`,children:`Max concurrent sessions (advanced)`}),d(`ul`,{className:`divide-y divide-border border-t border-border`,children:k.map(e=>i(`li`,{className:`${b} flex items-center gap-2`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:e.name}),d(oe,{type:`number`,min:1,placeholder:`∞`,defaultValue:e.maxCameras??``,"aria-label":`Max concurrent sessions for ${e.name}`,className:`w-20 text-right`,disabled:x.isPending,onBlur:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10),i=r!==null&&r>0?r:null;i!==e.maxCameras&&x.mutate({agentNodeId:e.id,maxCameras:i})}})]},e.id))}),d(`p`,{className:`${b} ${y} border-t border-border`,children:`A hard cap on the sessions a node runs at once (always-on cameras count too). A node at its cap is never chosen; under shares its turn goes to a free node. Empty = unlimited.`})]})]})}),D.isError&&d(me,{message:`Suggestion failed: ${D.error instanceof Error?D.error.message:`unknown error`}`}),O&&d(ya,{suggestion:O,nameOf:A,pending:_.isPending,...ee?{}:{onApply:()=>_.mutate(Xi(O))}}),d(U,{headingId:`load-balancing-accelerators`,title:`Accelerators`,icon:V,children:d(`div`,{className:`${g} space-y-2`,children:k.length===0?d(ye,{title:`No detect-capable nodes`,description:`Enable detection on a node in Roles & nodes to configure its accelerators.`}):k.map(e=>d(fa,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline,...M?.[e.id]===void 0?{}:{suggestedMaxSessions:M[e.id]},...P(e.id)===void 0?{}:{autoDeviceShares:P(e.id)}},e.id))})}),p!==void 0&&p.stalePins.length>0&&d(ba,{stats:p,cameraName:j})]})}function ya({suggestion:e,nameOf:t,pending:n,onApply:r}){return i(U,{headingId:`load-balancing-suggestion`,title:e.source===`benchmark`?`Suggested from benchmark`:`Suggested from hardware`,icon:Lt,...r===void 0?{}:{actions:d(H,{size:`sm`,onClick:r,disabled:n,children:`Apply suggested shares`})},children:[d(`ul`,{className:`divide-y divide-border`,children:e.nodes.map(e=>i(`li`,{className:`${b} space-y-0.5`,children:[i(`div`,{className:`flex items-baseline gap-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:t(e.nodeId)}),d(`span`,{className:`tabular-nums text-foreground`,children:e.share===null?`skipped`:`${e.share}%`})]}),i(`p`,{className:y,children:[na(e.capacityFallback)===null?``:`${na(e.capacityFallback)} · `,e.skippedReason===null?`≈ ${e.capacitySessions} parallel sessions · ${e.devices.map(e=>`${e.deviceKey} ${e.share}% (${e.modelId??`—`}${e.measured?``:`, estimated`}, cap ${e.suggestedMaxSessions??`—`})`).join(` · `)}`:`not part of the suggestion — ${e.skippedReason}`]})]},e.nodeId))}),i(`p`,{className:`${b} ${y} border-t border-border`,children:[`Shares in proportion to each node's capacity in parallel sessions —`,` `,e.source===`benchmark`?`measured by node benchmarks, or from the hardware table where a node has no results`:`at the models Auto tune picks (at least ${e.minSessionsPerDevice} per accelerator), from the measured speed of each node's hardware`,`, counted in `,e.cameraFps,` fps sessions with`,` `,Math.round(e.headroom*100),`% kept free. No load is measured or estimated.`,r===void 0?`Automatic shares already follow this; the caps are advisory — apply each from its accelerator row.`:`Applying writes the node and accelerator shares; the caps are advisory — apply each from its accelerator row.`]})]})}function ba({stats:e,cameraName:t}){let n=c(),r=N({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPlacementStats`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});return d(U,{headingId:`load-balancing-stale-pins`,title:`Stale device pins`,icon:An,children:d(`ul`,{className:`divide-y divide-border`,children:e.stalePins.map(e=>i(`li`,{className:`${b} flex items-center gap-2`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[d(`p`,{className:`truncate text-xs text-foreground`,title:t(e.deviceId),children:t(e.deviceId)}),d(`p`,{className:y,children:Qi(e)})]}),d(H,{variant:`outline`,size:`sm`,disabled:r.isPending,onClick:()=>r.mutate({deviceId:e.deviceId,deviceKey:`auto`}),children:`Clear pin`})]},e.deviceId))})})}function xa({node:e,emphasis:t=!1}){let n=e.isHub?Ne:V;return i(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[d(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),d(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),i(`div`,{className:`min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[d(`span`,{className:`truncate`,children:e.name}),e.isHub&&d(K,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&d(K,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}function Sa({nodes:e,actions:t}){return d(B,{columns:[{key:`node`,header:`Node`,sortValue:e=>e.name,render:e=>d(xa,{node:e})},...vn.map(e=>({key:e.key,header:e.label,align:`center`,notSortableReason:`A switch — sorting would move the row while it is being changed.`,render:n=>d(Je,{"aria-label":`${e.label} on ${n.name}`,title:e.hint,checked:En(n.effective,e.key),disabled:t.capabilityPending,onCheckedChange:r=>t.onToggleCapability(n.id,e.key,r)})}))],rows:e,rowKey:e=>e.id,bordered:!1,minWidthPx:720,mobileMode:`scroll`,rowClassName:e=>e.isOnline?void 0:`opacity-60`,emptyMessage:`No cluster nodes reporting yet.`})}function Ca({roleValues:e,options:t,pending:n,onRoleChange:r}){let a=t.map(e=>({value:e.id,label:e.id===`hub`?`${e.name} (default)`:e.name}));return d(`ul`,{className:`divide-y divide-border`,children:yn.map(t=>i(`li`,{className:`${b} flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[i(`div`,{className:`min-w-0 flex-1 basis-56`,children:[d(`div`,{className:`text-xs font-medium text-foreground`,children:Dn(t)}),d(`p`,{className:y,children:fn(t)})]}),d(`div`,{className:`w-full sm:w-48`,children:d(R,{"aria-label":`${Dn(t)} node`,value:e[t],disabled:n,options:a,onChange:e=>r(t,e.target.value)})})]},t))})}r();function wa(){let e=c(),{nodes:t}=W(),n=z(void 0),r=kt({addonId:pn}),o=kt({addonId:wn}),s=kt({addonId:Cn}),l=()=>hn(e),u=Me({onSuccess:l}),f=gt({onSuccess:l}),p=a(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),m=a(()=>t.map(e=>{let t=p.get(e.id),n=Vn(t,e.isHub);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n}}),[t,p]),h={ingestNode:_n(r.data,`ingestNode`,`hub`),recordingNode:_n(o.data,mn,`hub`),audioNode:_n(r.data,`audioNode`,`hub`),motionNode:_n(r.data,`motionNode`,`hub`),postProcessingNode:_n(s.data,xn,`hub`)},g=a(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id),n=e=>t.find(t=>t.id===e)?.name||e;return[...new Set([`hub`,...yn.map(e=>h[e]),...e])].filter(e=>e.length>0).map(e=>({id:e,name:n(e)}))},[t,h]),_=n.isLoading||r.isLoading||o.isLoading||s.isLoading,v=(e,t,n)=>{u.mutate({agentNodeId:e,[t]:n})},b=(e,t)=>{if(e===`recordingNode`){f.mutate({addonId:wn,patch:{[mn]:t}});return}if(e===`postProcessingNode`){f.mutate({addonId:Cn,patch:{[xn]:t}});return}f.mutate({addonId:pn,patch:{[e]:t}})},x={capabilityPending:u.isPending,onToggleCapability:v};return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[i(U,{headingId:`roles-nodes-cluster-roles`,title:`Cluster roles`,icon:kn,actions:_?d(Ze,{className:`h-3.5 w-3.5 animate-spin text-foreground-subtle`,"aria-label":`Loading`}):null,children:[d(`p`,{className:`${y} border-b border-border px-3 py-1.5 sm:px-4`,children:`One node holds each role for every camera. Detection shares and caps are on Load balancing.`}),d(Ca,{roleValues:h,options:g,pending:f.isPending,onRoleChange:b})]}),d(U,{headingId:`roles-nodes-node-capabilities`,title:`Node capabilities`,icon:Ne,children:d(Sa,{nodes:m,actions:x})})]})}var Ta=`pipeline-analytics`,Ea=`face-gallery`,Da=`pipeline-orchestrator`,Oa=`pipeline-runner`,ka=`audio-analyzer`;function Aa(e){return[...Yt.filter(t=>t.stepId===e).map(e=>Gt(e.stepId)),...Kt.filter(t=>t.stepId===e).map(e=>$t(e.stepId,e.key))]}var ja=`faces`,Ma=`semantic-search`,Na=[{id:ja,title:`Faces & recognition`,hint:`The face encoder for every node, the smallest faces worth embedding, keeping and auto-assigning, and how a face is matched to a person.`,panels:[{addonId:Da,fieldKeys:Aa(`face-embedding`)},{addonId:Ta,capability:Ea}]},{id:Ma,title:`Semantic search`,hint:`The image encoder behind "search by description". One for the whole cluster: changing it hides existing results until the index is rebuilt.`,panels:[{addonId:Da,fieldKeys:Aa(`clip-embedding`)}]},{id:en,title:`Enrichment crop`,hint:`How the crop handed to face, plate and search models is cut from the frame.`,panels:[{addonId:Da,sectionIds:[en]}]},{id:Xt,title:`Full-resolution crops`,hint:`How long each camera keeps full-resolution pixels so a late crop (snapshot, face, plate) is sharp instead of cut from the small detection frame.`,panels:[{addonId:Da,sectionIds:[Xt]}]},{id:`runner-defaults`,title:`Runner defaults`,hint:`Values every node's detection runner and audio analyzer use. A node's own decode limits (Roles & nodes) take precedence.`,panels:[{addonId:Oa,fieldScope:`cluster`},{addonId:ka,fieldScope:`cluster`}]},{id:`failover`,title:`Failover`,hint:`What happens to cameras when a node disconnects and comes back.`,panels:[{addonId:Da,sectionIds:[`failover`]}]}],Pa={"cluster-step-models":ja};function Fa(e){return e===`clip-embedding`?Ma:ja}r();var Ia=2500,La={faces:Ie,"semantic-search":ve,"detail-crop":Vt,"native-lease":Ht,"runner-defaults":V,failover:Se};function Ra(e){f(()=>{if(e===null)return;let t=Pa[e]??e,n=`[data-cluster-settings-card="${CSS.escape(t)}"]`,r=()=>{let e=document.querySelector(n);return e===null?!1:(e.scrollIntoView({block:`start`,behavior:`smooth`}),e.classList.add(`ring-2`,`ring-primary/60`),setTimeout(()=>e.classList.remove(`ring-2`,`ring-primary/60`),Ia),!0)};if(r())return;let i=new MutationObserver(()=>{r()&&i.disconnect()});return i.observe(document.body,{childList:!0,subtree:!0}),()=>i.disconnect()},[e])}function za({section:e}){return d(`div`,{"data-cluster-settings-card":e.id,className:`rounded-lg`,children:d(U,{headingId:`cluster-settings-${e.id}`,title:e.title,...La[e.id]===void 0?{}:{icon:La[e.id]},children:i(`div`,{className:`${g} space-y-3`,children:[d(`p`,{className:y,children:e.hint}),e.panels.map(e=>d(dn,{nodeId:`hub`,addonIds:[e.addonId],level:`global`,hideSectionChrome:!0,omitSectionIds:[`cluster`,`load`],emptyMessage:`Not available — the addon that owns these settings did not answer.`,...e.capability===void 0?{}:{capability:e.capability},...e.sectionIds===void 0?{}:{sectionIds:e.sectionIds},...e.fieldKeys===void 0?{}:{fieldKeys:e.fieldKeys},...e.fieldScope===void 0?{}:{fieldScope:e.fieldScope}},`${e.addonId}:${e.capability??``}`))]})})})}function Ba({refreshToken:e}){let[t]=sn();return Ra(t.get(Vo)),d(`div`,{className:`space-y-3 sm:space-y-4`,children:Na.map(e=>d(za,{section:e},e.id))})}var Va=`pipeline-orchestrator`,Ha=200;function Ua(){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(jt,{addonId:Va,limit:Ha,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}var Wa=[{id:`assignments`,label:`Assignments`},{id:`load-balancing`,label:`Load balancing`},{id:`auto-tune`,label:`Auto tune`},{id:`roles-nodes`,label:`Roles`},{id:`settings`,label:`Settings`},{id:`logs`,label:`Logs`}];function Ga(e){return Wa.some(t=>t.id===e)}function Ka({refreshToken:e}){let[t,n]=sn(),r=t.get(Bo),a=Ga(r)?r:`assignments`,o=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(Bo,e),n.delete(Vo),n},{replace:!0})};return i(`div`,{className:`flex flex-col h-full`,children:[i(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),d(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Camera assignments, load balancing, the detector recommendation, cluster roles and settings.`})]}),d(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Wa.map(e=>d(`button`,{type:`button`,onClick:()=>o(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${a===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),i(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[a===`assignments`&&d(vi,{}),a===`load-balancing`&&d(va,{refreshToken:e,onOpenAutoTune:()=>o(`auto-tune`)}),a===`auto-tune`&&d(Li,{}),a===`roles-nodes`&&d(wa,{}),a===`settings`&&d(Ba,{refreshToken:e}),a===`logs`&&d(Ua,{})]})]})}var qa=`armed:`;function Ja(e){return e.assignment.reasons.detection?.startsWith(qa)===!0}function Ya(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!Ja(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function Xa(e){let t=[],n=[],{assignment:r,detection:i,broker:a}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),r.detectionNodeId===null&&i===null&&!Ja(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let o=e.degraded??[];if(o.length>0){let e=[...new Set(o.map(e=>e.stage))].join(`, `);n.push({code:`status-unreadable`,severity:`warning`,message:`Could not read ${e} for this camera — those blocks are unknown, not empty (a switch read that failed does NOT mean nothing is switched off)`})}n.push(...$a(e.cameraSensors));for(let e of a?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function Za(e){return e.state===`unreadable`&&qt.state===`unreadable`&&e.reason===qt.reason}function Qa(e){switch(e.state){case`ready`:return null;case`missing`:return{code:`camera-sensor-missing`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is missing`};case`offline`:return{code:`camera-sensor-offline`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) is ${e.reason}`};case`unsupported`:return{code:`camera-sensor-unsupported`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) cannot drive motion: ${e.reason}`};case`unreadable`:return{code:`camera-sensor-unreadable`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is unreadable: ${e.reason}`}}}function $a(e){if(e===void 0||e.state===`not-configured`)return[];if(e.state===`unreadable`)return Za(e)?[]:[{code:`camera-sensors-unreadable`,severity:`warning`,message:`Camera sensors unreadable: ${e.reason}`}];let t=e.sensors.flatMap(e=>{let t=Qa(e);return t===null?[]:[t]}),n=e.notForwarded===void 0?t:[eo(e.notForwarded),...t];return e.notEnforced===void 0?n:[{code:`camera-sensors-not-enforced`,severity:`warning`,message:`Confirm / Replace cannot suppress this camera's own motion until its provider is updated`},...n]}function eo(e){return{code:`camera-sensors-not-forwarded`,severity:`warning`,message:e===`onboard-not-listed`?`Camera sensors are attached but never fire: add "Camera sensors" (onboard) to this camera's motion sources`:`Camera sensors are attached but never fire: this camera has no active detection`}}function to(e){return e===void 0?`status unavailable from this node`:e.state===`not-configured`?`none attached`:e.state===`unreadable`?`unknown — ${e.reason}`:e.sensors.map(ro).join(`, `)}function no(e){return e.mode===`in-addition`?``:` · ${e.mode}`}function ro(e){return`${io(e)}${no(e)}`}function io(e){switch(e.state){case`ready`:return`${e.name} (#${e.deviceId})`;case`offline`:return`${e.name} (#${e.deviceId}) — ${e.reason}`;case`unsupported`:return`${e.name} (#${e.deviceId}) — unsupported`;case`missing`:case`unreadable`:return`${e.addonId}/${e.stableId} — ${e.state}`}}function ao(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function oo(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function so(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function co(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var lo={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function uo(e){if(!ao(e)||!Array.isArray(e.sections))return lo;let t=Zt(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)co(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:oo(n(`detectionFps`)),motionSources:so(n(`motionSources`)),motionFps:oo(n(`motionFps`)),motionCooldownMs:oo(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function fo(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...fo(r.children,t+1));return n}function X({title:e,children:t}){return i(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[d(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),d(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return i(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[d(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),d(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&d(po,{})]})}function po(){return d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var mo={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return d(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${mo[e]}`,children:t})}function $({children:e}){return d(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function ho({icon:e,label:t,nodeId:n,pinned:r,reason:a,overridden:s}){return i(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[d(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),d(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?d(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):i(o,{children:[d(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?i(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[d(xt,{className:`h-2.5 w-2.5`}),` manual`]}):i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,a!==void 0&&a.length>0?a:`capacity`]}),s&&d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function go({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return i(X,{title:`Where it runs`,children:[d(ho,{icon:V,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),d(ho,{icon:fe,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),d(ho,{icon:D,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),d(ho,{icon:Le,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),d(`div`,{className:`mt-1.5`,children:i(`select`,{value:o,disabled:r,"aria-label":`Detection placement pin`,onChange:e=>a(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[d(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>i(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function _o(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function vo(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function yo(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function bo({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:a,cameraSensors:s}){let c=vo(t,n.detectionStreamProfile),l=vo(t,n.motionStreamProfile),u=n.motionSources.includes(`analyzer`);return i(X,{title:`Streams & motion`,children:[i(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),d(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:yo(n.detectionFps)}),i(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.map(rn).join(` + `):`none`,r===!1&&` · inactive`]}),d(Z,{label:`Camera sensors`,children:to(s)}),u&&i(o,{children:[i(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,l!==void 0&&` · ${l.width}×${l.height} ${l.codec}`]}),i(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[yo(n.motionFps),a!==null&&` · live ${a.toFixed(1)}`]})]}),d(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),d(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?d($,{children:`No streams registered`}):e.map(e=>i(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[d(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,_o(e)]},e.camStreamId))})]})}function xo({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return i(X,{title:`Pipeline steps`,children:[e===void 0?d($,{children:`Resolving…`}):e.length===0?d($,{children:`No steps configured`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>d(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:i(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&d(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&i(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),d(`div`,{className:`mt-1`,children:i(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var So={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function Co({detection:e,live:t,detectionMode:n,modeOverridden:r}){if(e===null)return i(X,{title:`Detection runtime`,children:[d(Z,{label:`Mode`,overridden:r,children:n??`—`}),d($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,u=Oe(a),f=a===`active`&&o===0;return i(X,{title:`Detection runtime`,children:[i(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[i(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${u.badgeClass}`,children:[d(ie,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&d(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),d(Z,{label:`Mode`,overridden:r,children:n??`—`}),i(Z,{label:`FPS`,children:[d(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),i(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&i(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&i(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),i(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),i(Z,{label:`Provisioning`,children:[d(Q,{tone:So[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&i(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function wo({broker:e}){return e===null?d(X,{title:`Stream broker`,children:d($,{children:`Broker stage inactive or unreachable`})}):i(X,{title:`Stream broker`,children:[e.profiles.length===0?d($,{children:`No broker profiles`}):d(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return i(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),d(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),i(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),i(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps===null?`—`:e.inFps.toFixed(0),`fps`]}),i(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),i(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[i(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),i(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function To({decoder:e}){return e===null?d(X,{title:`Decoder`,children:d($,{children:`Decoder stage inactive or unreachable`})}):d(X,{title:`Decoder`,children:d(Z,{label:`Node`,children:e.nodeId})})}r();var Eo=`pipeline-orchestrator`,Do={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},Oo={healthy:`Healthy`,idle:`Idle`,error:`Error`};function ko({problems:e}){return d(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>i(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[d(zt,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),d(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function Ao({deviceId:e,name:t,online:n,status:r,live:o,onlineNodes:s}){let l=c(),{data:u}=ct({addonId:Eo,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=P({deviceId:e},{staleTime:3e4}),p=a(()=>uo(u),[u]),m=a(()=>f===void 0?void 0:fo(f.steps),[f]),h=a(()=>r===void 0?[]:Xa(r),[r]),g=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},_=At({onSuccess:g}),v=bt({onSuccess:g}),y=t=>{t===`auto`?v.mutate({deviceId:e}):_.mutate({deviceId:e,agentNodeId:t})},b=r===void 0?`idle`:Ya(r),x=h.some(e=>e.severity===`error`),S=h.length>0,C=x?`border-danger/50`:S?`border-warning/40`:`border-border`;return i(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${C} bg-background overflow-hidden`,children:[i(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[d(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${x?`bg-danger`:Do[b]}`,title:x?`Error`:Oo[b],"aria-label":x?`Error`:Oo[b],role:`img`}),d(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&d(Q,{tone:`danger`,children:`offline`}),i(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&d(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),r?.recording!=null&&(r.recording.active?i(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&i(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),h.length>0&&d(ko,{problems:h}),r===void 0?d(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):i(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[d(go,{assignment:r.assignment,settings:p,onlineNodes:s,pinPending:_.isPending||v.isPending,onDetectionPinChange:y}),d(Co,{detection:r.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),d(xo,{steps:m,audioModelId:f?.audio?.modelId??null,audioEnabled:r.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),d(bo,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:p,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null,cameraSensors:r.cameraSensors}),d(wo,{broker:r.broker}),d(To,{decoder:r.decoder})]})]})}r();var jo=5e3,Mo=1e4,No=5e3;function Po(e){let t=c(),{data:n,isLoading:r}=cn(),{data:i,isLoading:o}=Pt({},{refetchInterval:jo}),{nodes:s}=W();f(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[l,d]=u(new Map);Dt(nn.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&d(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),f(()=>{if(l.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-Mo,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},No);return()=>clearInterval(e)},[l.size]);let p=a(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:a(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,p]),liveMetrics:l,onlineNodes:a(()=>(s??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[s]),isLoading:r||o}}r();function Fo({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:o}=Po(e),s=a(()=>[...t.map(e=>{let t=e.status===void 0?[]:Xa(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),c=a(()=>{let e=0,t=0;for(let r of s)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,n]);return o&&t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):d(`div`,{className:`h-full overflow-y-auto`,children:i(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[i(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[i(`span`,{children:[d(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),i(`span`,{children:[d(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),i(`span`,{children:[d(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),d(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>d(Ao,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}var Io=e({CLUSTER_NODE_ID:()=>Lo,PipelinePage:()=>zo});r();var Lo=`__cluster__`;function Ro(e){return e===`cameras`?`cameras`:`nodes`}function zo(){let[e,t]=sn(),n=Ro(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[a,s]=u(0),[c,l]=u(!1);return f(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Lo},{replace:!0})},[n,e,t]),i(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[i(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[i(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[d(`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`}),d(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),d(`div`,{className:`flex items-center gap-2`,children:i(`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:[d(Re,{className:`h-3.5 w-3.5`}),`Refresh`]})})]}),n===`nodes`&&i(`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:[i(`span`,{children:[c?`Hide`:`Show`,` node list`]}),d(C,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),d(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?i(o,{children:[d(`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:d(Un,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:a})}),d(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?d(Ka,{refreshToken:a}):d(_i,{nodeId:r,refreshToken:a})})]}):d(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:d(Fo,{refreshToken:a})})})]})}var Bo=`ctab`,Vo=`section`;function Ho(e,t){let n=new URLSearchParams({view:`nodes`,node:Lo,[Bo]:e});return t!==void 0&&n.set(Vo,t),`/system/pipeline?${n.toString()}`}function Uo(e){return Ho(`settings`,Fa(e))}function Wo(){return Ho(`load-balancing`)}var Go=`pipeline-orchestrator`;function Ko(e){return Yt.find(t=>t.stepId===e)??null}function qo({step:e,engineFormat:t,runnableModelIds:n}){let{data:r}=kt({addonId:Go}),a=Ut(r??null)[e.stepId]??e.defaultModelId,o=e.options.find(e=>e.id===a)?.label??a,s=n.length>0&&!n.includes(a);return i(`div`,{className:`space-y-2 rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`span`,{className:`font-medium text-foreground`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:o}),d(`span`,{title:`One value for the whole cluster — this step writes into a shared vector index, where two encoders make similarity scores meaningless.`,className:`rounded border border-primary/40 bg-primary/10 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-primary`,children:`cluster-wide`}),d(ln,{to:Uo(e.stepId),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Change in Cluster → Settings ›`})]}),i(`p`,{className:y,children:[`One model for every node and camera: `,e.indexName,` only matches vectors from the model that made them.`]}),s&&i(`p`,{className:`rounded border border-warning/40 bg-warning/10 px-2 py-1 text-[10px] leading-snug text-warning`,children:[`This accelerator's engine (`,t,`) ships no build of `,d(`b`,{children:a}),`. It refuses this step rather than run a different encoder — a substitute would put a second feature space into `,e.indexName,`.`]})]})}export{zr as _,ri as a,Hr as c,Jr as d,Xr as f,Br as g,Yr as h,ii as i,ei as l,qr as m,Ko as n,Kr as o,$r as p,Io as r,Zr as s,qo as t,Qr as u,Ir as v,Pn as y};
|