@camstack/addon-admin-ui 1.2.727 → 1.2.729
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/CHANGELOG.md +18 -0
- package/dist/assets/{AccessSection-wSFaqyKS.js → AccessSection-Dc8g_H6r.js} +1 -1
- package/dist/assets/Addons-CXiKEol-.js +5 -0
- package/dist/assets/{AdminPage-LgScsiWj.js → AdminPage-w4zm3PP7.js} +1 -1
- package/dist/assets/{AdminSectionedPage-Cx1I8W-T.js → AdminSectionedPage-tAw_MRKl.js} +1 -1
- package/dist/assets/AiProfiles-DMVp_AuT.js +3 -0
- package/dist/assets/Archive-BZPH9B3P.js +1 -0
- package/dist/assets/{BootstrapSettingsForm-DSKLOpRA.js → BootstrapSettingsForm-bCyo47E7.js} +1 -1
- package/dist/assets/Build-f6pDl5AU.js +51 -0
- package/dist/assets/{Calendars-DMWhQakP.js → Calendars-DD3SzSgj.js} +1 -1
- package/dist/assets/Cluster-s29cQT65.js +1 -0
- package/dist/assets/CompositionBlockEditor-Dx8ac-uz.js +2 -0
- package/dist/assets/{CompositionEditorPage-BqI1uHbZ.js → CompositionEditorPage-DxOsdbKD.js} +1 -1
- package/dist/assets/{Data-BofM8rpS.js → Data-B8rR1_XD.js} +2 -2
- package/dist/assets/DeviceDetail-BuJ6aH1J.js +1 -0
- package/dist/assets/{Devices-xFP7Pnyh.js → Devices-CaKYylxW.js} +1 -1
- package/dist/assets/{EmbedDevicePage-CBgMZcYT.js → EmbedDevicePage-CNQBuLwx.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-BDWglQam.js → EmbedPlayerPage-DLcSALl8.js} +1 -1
- package/dist/assets/History-DxAcSU6p.js +1 -0
- package/dist/assets/Identity-BYiOMNRO.js +1 -0
- package/dist/assets/{InstancesTable-8sjRWeOv.js → InstancesTable-Bon54IX9.js} +1 -1
- package/dist/assets/IntegrationDetail-CJM-C1nv.js +1 -0
- package/dist/assets/{Integrations-BH-Sv4Mc.js → Integrations-D3n8DVIO.js} +2 -2
- package/dist/assets/{Integrations-BSoGHsDK.js → Integrations-ZJdg7svr.js} +1 -1
- package/dist/assets/Library-DRbSkw8-.js +1 -0
- package/dist/assets/Locations--hItE1Mw.js +3 -0
- package/dist/assets/Logs-BIrUbNvp.js +1 -0
- package/dist/assets/{MaskShapeCanvas-DBtNWuSR.js → MaskShapeCanvas-BswXb6mq.js} +1 -1
- package/dist/assets/{MotionZonesSettings-Dw6l_P6h.js → MotionZonesSettings-D1D0t4y_.js} +1 -1
- package/dist/assets/{MyAccess-QO1xS7ju.js → MyAccess-Cnb6NWIc.js} +1 -1
- package/dist/assets/{Network-U7WpoWbE.js → Network-gN13vjDc.js} +1 -1
- package/dist/assets/{NewExportModal-kUxB58Tr.js → NewExportModal-CIlf0MwL.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-CKYvBBXN.js → NodeAddonsSettingsPanel-Cdm9kVuA.js} +1 -1
- package/dist/assets/Notifications-B7t1r8MP.js +1 -0
- package/dist/assets/{Pipeline-CdsdqxA2.js → Pipeline-CGlGNOFm.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-BNIQYYeH.js → PrivacyMaskSettings-CWotYr2C.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-hDPVfhQo.js → SceneMonitorEditor-COuzdEY3.js} +1 -1
- package/dist/assets/SessionsList-BS-i5gS9.js +2 -0
- package/dist/assets/{Showroom-DeZA6KeF.js → Showroom-DVjWdKar.js} +1 -1
- package/dist/assets/{StorageLocationsTable-CshKJzd9.js → StorageLocationsTable-CfA3lTP5.js} +1 -1
- package/dist/assets/System-DUKuDUYl.js +2 -0
- package/dist/assets/TemplateEditorDialog-Bw1Hcq6y.js +1 -0
- package/dist/assets/{Terminal-DfvAO2c4.js → Terminal-BVz2pxLF.js} +4 -4
- package/dist/assets/{TrainingProviders-XsSj8iER.js → TrainingProviders-BNQoAwvE.js} +1 -1
- package/dist/assets/{Viewer-DEhNUn4i.js → Viewer-Di2w3_sl.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-1GIjM1Xe.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-LZXFeWmX.js} +1 -1
- package/dist/assets/{ai-page.helpers-BgaYtFZQ.js → ai-page.helpers-Blv8vMMO.js} +1 -1
- package/dist/assets/{assignment-candidates-wqee9Qzc.js → assignment-candidates-Cu1wWiwM.js} +1 -1
- package/dist/assets/{authed-media-BWbcdqJS.js → authed-media-DGNxqkHt.js} +1 -1
- package/dist/assets/{board-model-B6IJyB8x.js → board-model-BqT-K9_t.js} +1 -1
- package/dist/assets/{camera-block-model-5F2zk2Pj.js → camera-block-model-D5vbEewS.js} +1 -1
- package/dist/assets/{device-integration-icon-DqC6lcvp.js → device-integration-icon-aaltq9T-.js} +1 -1
- package/dist/assets/device-picker-model-6HHz83GI.js +1 -0
- package/dist/assets/dist-CBwl2AV3.js +1169 -0
- package/dist/assets/{dist-BhGq3bv6.js → dist-EjwEggLH.js} +1 -1
- package/dist/assets/{format-SD0TDX1L.js → format-WGDeViun.js} +1 -1
- package/dist/assets/{hostInit-CBhnwuZa.js → hostInit-DJiYsaiE.js} +1 -1
- package/dist/assets/i18n-BJW4xO62.js +1 -0
- package/dist/assets/{icons-BHp7muWn.js → icons-ChXNiO64.js} +1 -1
- package/dist/assets/index-DKr9ed1W.css +2 -0
- package/dist/assets/index-iS5ad_bU.js +7 -0
- package/dist/assets/{linked-devices-model-BuNSmVjC.js → linked-devices-model-BDt0Cyoj.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-e2dee46e.js → mf-entry-bootstrap-0-ae46cb39.js} +2 -2
- package/dist/assets/mount-6HHz83GI.js +1 -0
- package/dist/assets/{notification-rule-status-B8kAY-MG.js → notification-rule-status-BNvwbSsv.js} +1 -1
- package/dist/assets/{player-overlays-KBeT29r4.js → player-overlays-Cp7Gj5VT.js} +1 -1
- package/dist/assets/remoteEntry-DATj8eOT.js +1 -0
- package/dist/assets/src-BnHrKVvq.js +279 -0
- package/dist/assets/src-uL_wvvFJ.js +1169 -0
- package/dist/assets/{sso-popup-DKnk_YJe.js → sso-popup-T48MTk3R.js} +1 -1
- package/dist/assets/{step-inspector-model-Bnhm_mgp.js → step-inspector-model-Ddkf8wB2.js} +1 -1
- package/dist/assets/{use-scenes-feed-CgzVs07Q.js → use-scenes-feed-CYM4vOAm.js} +1 -1
- package/dist/assets/{useAdminDeviceRemoval-BxrEFLk_.js → useAdminDeviceRemoval-B9OIUuQx.js} +1 -1
- package/dist/assets/useDevice-0izRihBG.js +1 -0
- package/dist/assets/useEventInvalidation-6HHz83GI.js +1 -0
- package/dist/assets/useFaultTypeOptions-Dqc8jhWX.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BumQLvYZ.js → useNodeUrlSelection-BVF-k4cB.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DRAJCQxk.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CgbbxEyr.js} +2 -2
- package/dist/index.html +10 -10
- package/dist/server/addon.js +1 -1
- package/package.json +2 -2
- package/dist/assets/Addons-bkr3ufUt.js +0 -5
- package/dist/assets/AiProfiles-DUsHvpUb.js +0 -3
- package/dist/assets/Archive-CFG6lM3C.js +0 -1
- package/dist/assets/Build-CcvdrbK9.js +0 -51
- package/dist/assets/Cluster-B2HBj67T.js +0 -1
- package/dist/assets/CompositionBlockEditor-BNTAxLhN.js +0 -2
- package/dist/assets/DeviceDetail-BGT5UzeM.js +0 -1
- package/dist/assets/History-C7h-Hba7.js +0 -1
- package/dist/assets/Identity-DrPBF_DD.js +0 -1
- package/dist/assets/IntegrationDetail-BGhbgQrH.js +0 -1
- package/dist/assets/Library-eOct7xul.js +0 -1
- package/dist/assets/Locations-HKA-wPxn.js +0 -3
- package/dist/assets/Logs-B_PJFZkB.js +0 -1
- package/dist/assets/Notifications-DChGPTCJ.js +0 -1
- package/dist/assets/SessionsList-CayNWY3N.js +0 -2
- package/dist/assets/System-CJnmLipz.js +0 -2
- package/dist/assets/TemplateEditorDialog-CMfo-woj.js +0 -1
- package/dist/assets/device-picker-model-OGGUkOts.js +0 -1
- package/dist/assets/dist-C6IgE-Fj.js +0 -1234
- package/dist/assets/i18n-CkHf1ol7.js +0 -1
- package/dist/assets/index-BVScunnp.css +0 -2
- package/dist/assets/index-PErHbELp.js +0 -7
- package/dist/assets/mount-OGGUkOts.js +0 -1
- package/dist/assets/remoteEntry-DVELx4S7.js +0 -1
- package/dist/assets/src-BL8KgH_H.js +0 -1234
- package/dist/assets/src-FszuUAOe.js +0 -279
- package/dist/assets/useDevice-4fOtWZjl.js +0 -1
- package/dist/assets/useEventInvalidation-OGGUkOts.js +0 -1
- package/dist/assets/useFaultTypeOptions-DskkOhna.js +0 -1
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{B as e,C as t,J as n,K as r,R as i,S as a,V as o,Y as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ei as d,En as f,Et as p,Hn as m,Kt as h,Ln as g,Q as _,Qi as v,Qt as y,Vn as b,Vr as x,Wi as S,Xn as C,ct as w,ft as T,gr as ee,la as E,nn as D,oa as te,ot as O,tr as k,vr as A}from"./player-overlays-KBeT29r4.js";import{Dl as ne}from"./src-BL8KgH_H.js";import{t as re}from"./chevron-down-CBb-F8DT.js";import{l as j}from"./terminal-BncJ-1sF.js";import{$i as ie,Co as ae,Do as oe,Eo as se,Ia as ce,Mo as le,No as ue,Np as M,Oo as N,So as P,Tp as F,Xi as de,Yi as fe,Zi as I,_o as pe,_r as me,bi as L,bo as R,ct as he,di as z,do as ge,ea as B,fi as V,fo as _e,go as H,hl as ve,ho as ye,im as be,jo as xe,ko as U,lo as Se,lu as Ce,mi as W,mo as we,pi as Te,po as Ee,sm as De,ta as Oe,vo as ke,vr as Ae,wo as je,xo as Me,yt as Ne}from"./src-FszuUAOe.js";import{t as G}from"./useTranslation-BJr-n0es.js";import"./mount-OGGUkOts.js";import{Ei as Pe,Oi as Fe,Si as Ie,vt as Le,yt as Re}from"./index-PErHbELp.js";import{t as K}from"./NodeAddonsSettingsPanel-CKYvBBXN.js";import{t as q}from"./AdminPage-LgScsiWj.js";import{i as ze,r as Be,t as Ve}from"./addon-kind-filter-CEGKkC1O.js";import{n as J,r as He,t as Ue}from"./useNodeUrlSelection-BumQLvYZ.js";function We(e){if(e===void 0)return null;switch(e.state){case`failed`:case`refused`:case`missing`:case`crashed`:return{kind:e.state,...e.reason===void 0?{}:{reason:e.reason}};default:return null}}c();var Y=`a singleton role: Roles & nodes is the one picker for it`,X=[{cap:`pipeline-orchestrator`,addonId:`pipeline-orchestrator`,surface:`pipeline`,sectionIds:[`cluster-step-models`,`face-rescore`,`detail-crop`,`native-lease`,`load`,`failover`]},{cap:`pipeline-orchestrator`,addonId:`pipeline-orchestrator`,surface:`pipeline-roles`,fieldKeys:[`ingestNode`,`audioNode`,`motionNode`],reason:Y},{cap:`face-gallery`,addonId:`pipeline-analytics`,surface:`pipeline`},{cap:`stream-broker`,addonId:`stream-broker`,surface:`pipeline`},{cap:`snapshot`,addonId:`snapshot`,surface:`pipeline`},{cap:`recording`,addonId:`recorder`,surface:`pipeline`},{cap:`recording`,addonId:`recorder`,surface:`pipeline-roles`,fieldKeys:[`recordingNodeId`],reason:Y},{cap:`embedding-encoder`,addonId:`embedding-encoder`,surface:`pipeline`},{cap:`device-history`,addonId:`device-history`,surface:`history`},{cap:`alerts`,addonId:`alert-center`,surface:`notifications`},{cap:`metrics-provider`,addonId:`metrics-native`,surface:`nodes`},{cap:`login-method`,addonId:`auth-webauthn`,surface:`provider-page`},{cap:`llm`,addonId:`ai`,surface:`provider-page`},{cap:`log-destination`,addonId:`console-logging`,surface:`provider-page`},{cap:`core-blocks`,addonId:`core-blocks`,surface:`provider-page`},{cap:`custom-model-registry`,addonId:`model-studio`,surface:`addon-card`},{cap:`osd-manager`,addonId:`osd-manager`,surface:`addon-card`},{cap:`pipeline-analytics`,addonId:`pipeline-analytics`,surface:`addon-card`},{cap:`pipeline-analytics`,addonId:`pipeline-analytics`,surface:`pipeline-roles`,fieldKeys:[`postProcessingNodeId`],reason:Y},{cap:`detection-pipeline`,addonId:`detection-pipeline`,surface:`addon-card`}],Z={pipeline:`/system/pipeline?view=nodes&node=__cluster__&ctab=settings`,"pipeline-roles":`/system/pipeline?view=nodes&node=__cluster__&ctab=roles-nodes`,history:`/system/history`,notifications:`/system/notifications?tab=settings`,nodes:`/system/nodes`};function Ge(e){return e.sectionIds===void 0&&e.fieldKeys===void 0}function Ke(e){return X.filter(t=>t.addonId===e&&Z[t.surface]!==void 0)}function qe(e){let t=X.filter(t=>t.addonId===e),n=new Set(t.filter(e=>e.surface===`addon-card`&&Ge(e)).map(e=>e.cap));return{capabilities:[...new Set(t.map(e=>e.cap))].filter(e=>!n.has(e)),fieldKeys:t.filter(e=>n.has(e.cap)&&e.surface!==`addon-card`).flatMap(e=>e.fieldKeys??[])}}function Je({addonId:e,onOpen:n}){let{t:r}=G(),i=qe(e),o=Ke(e).length>0;return t(u,{children:[a(Ye,{addonId:e,onOpen:n}),a(K,{nodeId:null,addonIds:[e],level:`global`,fieldScope:`cluster`,omitCapabilities:i.capabilities,omitFieldKeys:i.fieldKeys,emptyMessage:o?r(`addons.addonCard.allClusterSettingsElsewhere`,`Its cluster-wide settings are on the page linked above.`):r(`addons.addonCard.thisAddonExposesNoCluster`,`This addon exposes no cluster-wide settings. Anything it can configure is per-node — open it from Cluster → the node → Settings.`)})]})}function Ye({addonId:e,onOpen:n}){let{t:r}=G(),i=[...new Set(Ke(e).map(e=>e.surface))];if(i.length===0)return null;let o=e=>{switch(e){case`pipeline`:return r(`addons.addonCard.surface.pipeline`,`Pipeline → Settings`);case`pipeline-roles`:return r(`addons.addonCard.surface.pipelineRoles`,`Pipeline → Roles & nodes`);case`history`:return r(`addons.addonCard.surface.history`,`History`);case`notifications`:return r(`addons.addonCard.surface.notifications`,`Notifications → Settings`);case`nodes`:return r(`addons.addonCard.surface.nodes`,`Nodes`);default:return e}};return t(`div`,{className:`mb-2 flex flex-wrap items-center gap-2 text-[10px] text-foreground-subtle`,children:[a(`span`,{children:r(`addons.addonCard.settingsElsewhere`,`More of this addon's settings are on:`)}),i.map(e=>{let t=Z[e];return t===void 0?null:a(F,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>n(t),children:o(e)},e)})]})}var Xe={queued:{icon:S,bg:`bg-muted text-foreground-subtle`,labelKey:`addons.addonRowBadge.queued`},updating:{icon:x,bg:`bg-primary/10 text-primary`,labelKey:`addons.addonRowBadge.updating`,spin:!0},"done-pending-restart":{icon:C,bg:`bg-amber-500/10 text-amber-700`,labelKey:`addons.addonRowBadge.pendingRestart`},done:{icon:E,bg:`bg-success/10 text-success`,labelKey:`addons.addonRowBadge.done`},failed:{icon:A,bg:`bg-danger/10 text-danger`,labelKey:`addons.addonRowBadge.failed`}};function Ze({item:e}){let{t:n}=G(),r=Xe[e.status],i=r.icon;return t(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${r.bg}`,title:e.error,children:[a(i,{className:`w-2.5 h-2.5 ${r.spin?`animate-spin`:``}`}),n(r.labelKey)]})}var Q=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),Qe=new Set([`done`,`failed`,`skipped`]);function $e(e){return!Qe.has(e.phase)&&!Q.has(e.jobState)}function et(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=Q.has(e.state);for(let i of e.tasks)r&&i.finishedAtMs!==null&&t-i.finishedAtMs>6e4||n.set(i.packageName,{jobId:e.jobId,packageName:i.packageName,phase:i.phase,fromVersion:i.fromVersion,toVersion:i.toVersion,error:i.error,jobState:e.state,finishedAtMs:i.finishedAtMs})}return n}function tt(){let{data:e}=Me({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=De(ne.AddonsJobProgress,e=>e.job.jobId);return r(()=>{let n=new Map;for(let t of e??[])n.set(t.jobId,t);for(let[e,r]of t)n.set(e,r.job);return et([...n.values()],Date.now())},[e,t])}var nt={queued:{icon:S,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.queued`},fetching:{icon:x,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.fetching`,spin:!0},staged:{icon:x,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.staged`,spin:!0},validating:{icon:x,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.validating`,spin:!0},applying:{icon:x,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.applying`,spin:!0},restarting:{icon:x,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,labelKey:`addons.jobProgress.restarting`,spin:!0},applied:{icon:x,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.finalizing`,spin:!0},done:{icon:E,cls:`bg-success/10 text-success`,labelKey:`addons.jobProgress.updated`},failed:{icon:A,cls:`bg-danger/10 text-danger`,labelKey:`addons.jobProgress.failed`},skipped:{icon:f,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.skipped`}};function rt({progress:e}){let{t:n}=G(),r=nt[e.phase],i=r.icon,o=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return t(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${r.cls}`,title:o,children:[a(i,{className:`w-2.5 h-2.5 ${r.spin?`animate-spin`:``}`}),n(r.labelKey),t(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function it(e,t){return e.filter(e=>e.packageName===t).slice().sort((e,t)=>e.isHub===t.isHub?e.nodeName.localeCompare(t.nodeName):e.isHub?-1:1)}function at(e){let t=e.version===null?``:` ${e.version}`,n=e.isOnline?``:` (offline: removed when it reconnects)`;return`- ${e.nodeName}${t}${n}`}function ot(e,t,n){let r=[`${e} will be uninstalled from ${t.length} node(s). Its runners stop, its capabilities are deregistered and its code is deleted:`,...t.map(at)];return n.length>0&&r.push(`Could not ask: ${n.join(`, `)} — not included.`),r.push(`This cannot be undone.`),r.join(`
|
|
2
|
-
`)}function st(e,t,n){let r=[`${e} will be uninstalled from ${t}: its runners stop and its code is deleted.`];return n.length>0&&r.push(`It stays installed on: ${n.map(e=>e.nodeName).join(`, `)}. Use "Everywhere" to remove it from every node.`),r.push(`This cannot be undone.`),r.join(`
|
|
3
|
-
`)}var ct={uninstalled:`uninstalled`,"not-installed":`was not installed`,refused:`REFUSED`,failed:`FAILED`,"pending-reconnect":`offline — removed when it reconnects`};function lt(e,t){let n=[];for(let r of e.results){let e=r.runnersStopped.length>0?` (stopped ${r.runnersStopped.join(`, `)})`:``;n.push(`${t(r.nodeId)}: ${ct[r.outcome]}${e}`),r.error!==void 0&&n.push(` ${r.error}`);for(let e of r.warnings)n.push(` ${e}`)}return n.join(`
|
|
4
|
-
`)}var ut={},dt=3e4,ft=`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors`;function pt({packageName:e,displayName:n,selectedNode:r,hideNodeAction:i,disabled:o}){let{t:s}=G(),c=l(),u=w(),d=O(),f=R(ut,{staleTime:dt}),p=f.data?.installations??[],m=(f.data?.unreachable??[]).map(e=>e.nodeId),h=it(p,e),g=e=>h.find(t=>t.nodeId===e)?.nodeName??(e===r.id?r.name:e),_=le({onSettled:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addonPages`]]}),c.invalidateQueries({queryKey:[[`capabilities`]]}),c.invalidateQueries({queryKey:[[`nodes`]]})}}),v=async e=>{await d({title:e.success?s(`addons.addonUninstallControls.uninstalled`,`{{displayName}} uninstalled`,{displayName:n}):s(`addons.addonUninstallControls.notEveryNodeWasCleaned`,`{{displayName}}: not every node was cleaned`,{displayName:n}),message:lt(e,g),variant:e.success?`default`:`danger`})},y=async t=>{try{await v(await _.mutateAsync({packageName:e,...t}))}catch(e){await d({title:s(`addons.addonUninstallControls.uninstallFailed`,`Uninstall {{displayName}} failed`,{displayName:n}),message:e instanceof Error?e.message:String(e),variant:`danger`})}},b=async()=>{let e=h.filter(e=>e.nodeId!==r.id);await u({title:s(`addons.addonUninstallControls.uninstallFrom`,`Uninstall {{displayName}} from {{name}}?`,{displayName:n,name:r.name}),message:st(n,r.name,e),confirmLabel:s(`addons.addonUninstallControls.uninstall`,`Uninstall`),variant:`danger`})&&await y(r.isHub?{}:{nodeId:r.id})},x=async()=>{let t=(await f.refetch()).data;if(t===void 0){await d({title:s(`addons.addonUninstallControls.cannotListTheNodes`,`Cannot list the nodes`),message:s(`addons.addonUninstallControls.theHubDidNotAnswer`,`The hub did not answer which nodes have this package — nothing was removed.`),variant:`danger`});return}let r=it(t.installations,e);await u({title:s(`addons.addonUninstallControls.uninstallEverywhere`,`Uninstall {{displayName}} everywhere?`,{displayName:n}),message:ot(n,r,t.unreachable.map(e=>e.nodeId)),confirmLabel:s(`addons.addonUninstallControls.uninstallFromNodeS`,`Uninstall from {{length}} node(s)`,{length:r.length}),variant:`danger`})&&await y({everywhere:!0})},S=_.isPending||o===!0;return t(`div`,{className:`flex items-center gap-1.5`,children:[i!==!0&&t(F,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),b()},disabled:S,className:ft,title:s(`addons.addonUninstallControls.uninstallFrom2`,`Uninstall from {{name}}`,{name:r.name}),children:[a(D,{className:`h-3 w-3`}),_.isPending?s(`addons.addonUninstallControls.removing`,`Removing...`):s(`addons.addonUninstallControls.uninstall`,`Uninstall`)]}),(h.length>1||i===!0||m.length>0)&&t(F,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),x()},disabled:S,className:ft,title:s(`addons.addonUninstallControls.uninstallFromEveryNodeThat`,`Uninstall from every node that has it`),children:[a(j,{className:`h-3 w-3`}),h.length>0?s(`addons.uninstallControls.everywhereCount`,{count:h.length}):s(`addons.uninstallControls.everywhere`)]})]})}function mt(e){return typeof e.deprecated==`string`&&e.deprecated.length>0}function ht(e,t){return t?e:e.filter(e=>e.distTags.includes(`latest`)||!mt(e))}function gt(e){return e.length-ht(e,!1).length}c();function _t({packageName:e,currentVersion:n,installSource:r,onInstall:i,onClose:o,onSelect:c,selectedVersion:l}){let{t:f}=G(),m=r===`upload`||r===`local`,[g,_]=s(!1),{data:v,isLoading:y,isError:b}=H({name:e}),S=v?ht(v,g):[],C=v?gt(v):0;return t(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[a(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:f(`addons.versionPicker.versions`,`Versions`)}),a(F,{variant:`unstyled`,type:`button`,onClick:o,className:`text-foreground-subtle hover:text-foreground`,children:a(p,{className:`h-3 w-3`})})]}),m&&t(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[a(h,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),t(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[a(`span`,{className:`font-semibold`,children:f(`addons.versionPicker.inPlace`,{kind:r===`upload`?f(`addons.versionPicker.uploadedCopy`,`Uploaded copy`):f(`addons.versionPicker.localCopy`,`Local copy`)})}),` `,a(Ie,{i18nKey:`addons.versionPicker.reinstall`,values:{version:n},components:{mono:a(`span`,{className:`font-mono`})}})]})]}),y&&t(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[a(x,{className:`h-3.5 w-3.5 animate-spin`}),f(`addons.versionPicker.loadingVersions`,`Loading versions...`)]}),b&&a(`div`,{className:`px-3 py-4 text-center text-[10px] text-danger`,children:f(`addons.versionPicker.registryError`,`Could not load versions from the registry.`)}),S.length>0&&a(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:S.map(e=>{let r=e.version===n,o=c!==void 0&&e.version===l,s=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),p=t(u,{children:[a(`span`,{className:`font-mono flex-1 text-left ${r?`text-primary font-semibold`:s?`text-amber-400`:`text-foreground`}`,children:e.version}),r&&a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:f(`common.current`)}),e.distTags.map(e=>a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),mt(e)&&a(`span`,{className:`text-[9px] text-red-400 line-through`,children:f(`common.deprecated`)}),a(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return c?t(F,{variant:`unstyled`,type:`button`,"aria-label":f(`addons.versionPicker.select`,`Select {{version}}`,{version:e.version}),onClick:()=>c(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${o?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[p,o?a(E,{className:`h-3 w-3 text-primary shrink-0`}):a(`span`,{className:`w-3 shrink-0`})]},e.version):t(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${r?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[p,a(F,{variant:`unstyled`,type:`button`,onClick:()=>i(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:r?f(`addons.versionPicker.reInstallFromNpm`,`Re-install {{version}} from npm`,{version:e.version}):f(`addons.versionPicker.install`,`Install {{version}}`,{version:e.version}),children:a(d,{className:`h-3 w-3`})})]},e.version)})}),!y&&!b&&v&&v.length===0&&a(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:f(`addons.versionPicker.noVersionsFound`,`No versions found`)}),C>0&&a(F,{type:`button`,variant:`ghost`,size:`sm`,className:`h-auto w-full justify-start rounded-none border-t border-border px-3 py-2 text-left text-[10px] font-normal text-foreground-subtle`,onClick:()=>_(e=>!e),children:g?f(`addons.versionPicker.hideOlder`,`Hide older versions`):f(`addons.versionPicker.showOlder`,`Show older versions ({{count}})`,{count:C})})]})}c();var vt=`device-export`;function yt(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===vt)}function bt(e){return e!==`local`&&e!==`upload`}function xt({isBundle:e,installSource:n,addonId:r,iconPath:i,color:o}){let[c,l]=s(!1),u=o?{backgroundColor:`${o.startsWith(`#`)?o:`#${o}`}26`}:void 0,d=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,f=r&&i?_(`/api/addon-assets/${r}/${i}`):null,p=!!f&&!c;return t(`div`,{className:`relative flex-shrink-0`,children:[a(`div`,{className:`h-8 w-8 rounded-md flex items-center justify-center ${u?``:d}`,style:u,children:p?a(`img`,{src:f,alt:r,className:`h-4 w-4`,onError:()=>l(!0)}):a(e?ee:k,{className:`h-3.5 w-3.5`})}),n===`local`&&a(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),bt(n)&&a(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:a(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:a(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),n===`upload`&&a(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:a(h,{className:`h-2.5 w-2.5 text-white`})})]})}function St({version:e,availableUpdate:n,selectedVersion:r,isUpdating:i,installSource:o,disabled:s,onUpdate:c,onOpenPicker:l,children:u}){let{t:f}=G();if(i)return t(`span`,{className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[a(x,{className:`h-3 w-3 animate-spin`}),f(`addons.addonCard.updating`,`Updating…`)]});if(n){let i=r??n;return t(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[c&&t(F,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:s,className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-semibold border border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:f(`addons.addonCard.updateTo`,`Update to {{target}}`,{target:i}),children:[a(d,{className:`h-3 w-3`}),f(`addons.addonCard.update`,`Update`)]}),t(F,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:s,"aria-label":f(`addons.addonCard.selectVersionToInstall`,`Select version to install`),title:f(`addons.addonCard.installedUpdateAvailableSelectedTap`,`Installed {{version}} — update available. Selected {{target}}; tap to choose another version.`,{version:e,target:i}),className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-bold font-mono border border-amber-500/40 bg-amber-500/15 text-amber-500 hover:bg-amber-500/25 animate-pulse disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[a(`span`,{className:`font-normal opacity-70`,children:e}),a(`span`,{className:`font-normal opacity-70`,children:`→`}),i,a(re,{className:`h-3 w-3`})]}),u]})}return t(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[t(F,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:s,className:[`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,o===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:f(`addons.addonCard.versionTapToViewAll`,`Version {{version}} — tap to view all versions`,{version:e}),children:[e,a(re,{className:`h-3 w-3 opacity-50`})]}),u]})}function Ct({addonId:e}){let t=l(),{data:n=`inherit`}=_e({addonId:e}),r=N({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return a(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>a(F,{variant:`unstyled`,type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}var wt={id:`hub`,name:`Hub`,isHub:!0};function Tt({addon:e,clusterStatus:n,hideVersion:r,availableUpdate:i,blockedUpdate:c,onUpdateServer:d,onUpdate:f,isUpdating:h,jobProgress:_,bundle:v,bulkItem:y,disabledByBulk:b,isSystem:x,selectedNode:S}){let{t:w}=G(),[T,E]=s(!1),[D,O]=s(!1),[k,ne]=s(null);o(()=>{ne(null)},[i]);let j=k??i,[ae,oe]=s(!1),[le,ue]=s(!1),[M,N]=s(`logs`),P=l(),L=Pe(),{manifest:R}=e,he=!v&&!R.protected&&R.removable!==!1,z=!!v,ge=v?.displayName??R.name,V=v?.packageName??R.packageName,_e=v?.version??R.packageVersion??R.version,H=v?.installSource??e.installSource,ve=v?v.bundle?.description??v.addons[0]?.manifest.description:R.description,ye=je({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]})}}),be=pe({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`addonPages`]]}),P.invalidateQueries({queryKey:[[`capabilities`]]}),P.invalidateQueries({queryKey:[[`integrations`]]})}}),xe=se({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`alerts`]]})}}),U=e.health,Se=U?.phase===`failed`&&!U.inGracePeriod,Ce=Se&&U?.nextRetryAt&&!U.retrying,W=We(e.process);return t(`div`,{className:`rounded-md border bg-surface overflow-hidden ${Se?`border-red-500/50`:`border-border`}`,children:[Se&&U&&t(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[a(A,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),t(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-xs font-semibold text-danger`,children:w(`addons.addonCard.failedToLoad`,{attempt:U.retryCount})}),a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:U.lastError?.message??w(`addons.addonCard.unknownError`,`Unknown error`)}),Ce&&U.nextRetryAt&&a(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:w(`addons.addonCard.autoRetryAt`,{time:new Date(U.nextRetryAt).toLocaleTimeString()})})]}),t(F,{variant:`unstyled`,type:`button`,disabled:xe.isPending||U.retrying,onClick:e=>{e.stopPropagation(),xe.mutate({packageName:V})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:w(`addons.addonCard.resetRetryCounterAndForce`,`Reset retry counter and force immediate reload`),children:[a(C,{className:`h-3 w-3 ${xe.isPending||U.retrying?`animate-spin`:``}`}),w(`addons.addonCard.retryNow`,`Retry now`)]})]}),W!==null&&t(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[a(A,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),t(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-xs font-semibold text-danger`,children:w(`addons.addonCard.processProblem.${W.kind}`)}),W.reason!==void 0&&a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:W.reason})]})]}),t(`div`,{className:`flex items-start gap-2.5 px-3 py-2`,children:[a(xt,{isBundle:z||!!R.components&&R.components.length>1,installSource:H,addonId:z?v.addons[0]?.manifest.id:R.id,iconPath:z?v.bundle?.icon??v.addons[0]?.manifest.icon:R.icon,color:z?v.addons[0]?.manifest.color:R.color}),t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`flex items-start justify-between gap-2`,children:[a(`span`,{className:`text-xs font-semibold text-foreground truncate min-w-0`,children:ge}),!r&&a(St,{version:_e,availableUpdate:i,...j===void 0?{}:{selectedVersion:j},isUpdating:h,installSource:H,disabled:b,...f&&j!==void 0?{onUpdate:()=>f(j)}:{},onOpenPicker:()=>O(e=>!e),children:D&&a(_t,{packageName:V,currentVersion:_e,...H?{installSource:H}:{},...i!==void 0&&j!==void 0?{selectedVersion:j,onSelect:e=>{ne(e),O(!1)}}:{},onInstall:e=>{O(!1),be.mutate({packageName:V,version:e})},onClose:()=>O(!1)})})]}),t(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[V!==ge&&a(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:V}),z&&t(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[a(ee,{className:`h-3 w-3`}),v.addons.length]}),x&&t(`span`,{className:`text-[10px] rounded-full bg-amber-500/15 text-amber-700 dark:text-amber-300 px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,title:w(`addons.addonCard.systemPackageUpdatingRestartsThe`,`System package — updating restarts the hub`),children:[a(C,{className:`h-3 w-3`}),w(`addons.addonCard.system`,`System`)]}),y!=null&&a(Ze,{item:y}),c!==void 0&&a(ce,{variant:`warning`,title:w(`addons.addonCard.updateHeldTitle`,{defaultValue:`{{latest}} is held until the server is {{required}} or newer`,latest:c.latestVersion,required:c.requiredServer}),children:w(`addons.addonCard.requiresServer`,{defaultValue:`requires server ≥ {{version}}`,version:c.requiredServer})}),c!==void 0&&d!==void 0&&a(F,{type:`button`,size:`sm`,variant:`secondary`,onClick:d,children:w(`clusterUpdate.updateServer`,`Update server`)}),_!=null&&a(rt,{progress:_})]}),ve&&a(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:ve}),!z&&e.process&&t(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?w(`addons.addonCard.forked`):w(`addons.addonCard.inProcess`)}),e.process.pid!=null&&t(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:W===null?`bg-gray-500/15 text-gray-400`:`bg-red-500/15 text-red-400`}`,children:e.process.state})]})]})]}),!z&&t(`div`,{className:`flex items-center gap-1 px-3 py-1 border-t border-border/50 bg-surface-hover/20`,children:[t(F,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),ye.mutate({addonId:R.id})},disabled:ye.isPending||b,className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors`,children:[a(C,{className:`h-3 w-3 ${ye.isPending?`animate-spin`:``}`}),w(`addons.addonCard.restart`,`Restart`)]}),t(F,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),oe(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${ae?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[a(m,{className:`h-3 w-3`}),w(`addons.addonCard.logs`,`Logs`)]}),!z&&t(F,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),ue(!0)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${le?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[a(g,{className:`h-3 w-3`}),w(`addons.addonCard.settings`,`Settings`)]}),a(`div`,{className:`flex-1`}),he&&a(pt,{packageName:R.packageName,displayName:R.name,selectedNode:S??wt,disabled:b})]}),n&&n.nodes.length>1&&!z&&t(`div`,{className:`border-t border-border px-3 py-1.5 bg-muted/10`,children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:w(`addons.addonCard.clusterDeployment`,`Cluster Deployment`)}),a(`div`,{className:`space-y-1`,children:n.nodes.map(e=>t(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[a(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),a(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),a(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&a(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:w(`addons.addonCard.outdated`)}),e.status===`offline`&&a(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:w(`common.offline`)}),e.synced&&e.status!==`offline`&&a(`span`,{className:`text-[9px] text-success`,children:w(`common.synced`)})]},e.nodeId))})]}),ae&&!z&&t(`div`,{className:`border-t border-border`,children:[t(`div`,{className:`flex items-center px-3 py-0.5 bg-surface-hover/20 border-b border-border/50`,children:[t(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[a(F,{variant:`unstyled`,type:`button`,onClick:()=>N(`logs`),className:`px-2 py-0.5 transition-colors ${M===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:w(`addons.addonCard.logs`,`Logs`)}),a(F,{variant:`unstyled`,type:`button`,onClick:()=>N(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${M===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:w(`addons.addonCard.events`,`Events`)})]}),a(`div`,{className:`flex-1`}),a(F,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),oe(!1)},className:`text-foreground-subtle hover:text-foreground`,children:a(p,{className:`h-3.5 w-3.5`})})]}),M===`logs`&&a(Ae,{addonId:R.id,maxHeight:`max-h-64`,showFilters:!1}),M===`events`&&a(me,{addonId:R.id,category:`addon.*`,maxHeight:`max-h-64`})]}),z&&t(u,{children:[a(F,{variant:`unstyled`,type:`button`,onClick:()=>E(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:a(T?te:re,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),T&&a(`div`,{className:`border-t border-border px-2.5 py-1.5 space-y-1.5`,children:v.addons.map(e=>a(Tt,{addon:e,hideVersion:!0},e.manifest.id))})]}),le&&!z&&a(fe,{open:!0,onOpenChange:e=>!e&&ue(!1),children:t(I,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(B,{children:t(Oe,{className:`flex items-center gap-2`,children:[a(g,{className:`h-4 w-4 text-primary`}),w(`addons.addonCard.settingsTitle`,{name:ge})]})}),t(de,{className:`space-y-4`,children:[a(`div`,{className:`text-[10px] text-foreground-subtle mb-2`,children:w(`addons.addonCard.clusterWideSettingsOneValue`,`Cluster-wide settings — one value for every node. Per-node settings live under Cluster → the node → Settings.`)}),a(Je,{addonId:R.id,onOpen:e=>L(e)}),yt(R)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:w(`addons.addonCard.deviceExport`,`Device export`)}),a(Ne,{addonId:R.id,onOpenDevice:e=>L(`/devices/${e}`)})]}),bt(H)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:w(`addons.addonCard.autoUpdate`,`Auto-Update`)}),a(Ct,{addonId:R.id})]}),R.components&&R.components.length>0&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:w(`addons.addonCard.components`,{count:R.components.length})}),a(`div`,{className:`flex flex-wrap gap-1`,children:R.components.map(e=>a(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]})]}),a(ie,{children:a(F,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>ue(!1),children:w(`common.close`,`Close`)})})]})})]})}c();var Et=`.tgz,.tar.gz,.zip`;function Dt({onUploadSuccess:e}){let{t:r}=G(),[o,c]=s(!1),l=n(null),d=i(async t=>{c(!0);let n=new FormData;n.append(`file`,t);let r=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(_(`/api/addons/upload`),{method:`POST`,headers:{Authorization:`Bearer ${r}`},body:n})).json()).success&&e()}finally{c(!1)}},[e]);return t(u,{children:[a(L,{ref:l,accept:Et,onChange:i(e=>{let t=e.target.files?.[0];t&&d(t),e.target.value=``},[d]),className:`hidden`}),t(F,{variant:`unstyled`,type:`button`,onClick:()=>l.current?.click(),disabled:o,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[o?a(x,{className:`w-3.5 h-3.5 animate-spin`}):a(h,{className:`w-3.5 h-3.5`}),o?r(`addons.addonUploadZone.uploading`,`Uploading...`):r(`addons.addonUploadZone.upload`,`Upload`)]})]})}var Ot=/```[^\n]*\n([\s\S]*?)```/g;function kt(e){let t=[],n=0;for(let r of e.matchAll(Ot)){let i=r.index??0;i>n&&t.push({kind:`text`,body:e.slice(n,i)}),t.push({kind:`code`,body:r[1]??``}),n=i+r[0].length}return n<e.length&&t.push({kind:`text`,body:e.slice(n)}),t}function At(e){let t=e.trim();return t.startsWith(`https://`)||t.startsWith(`http://`)?t:null}function jt(e,t){let n=[],r=/(\*\*[^*]+\*\*|`[^`]+`|\[[^\]]+\]\([^)]+\))/g,i=0,o=0;for(let s of e.matchAll(r)){let r=s.index??0;r>i&&n.push(e.slice(i,r));let c=s[0],l=`${t}-${o}`;if(o+=1,c.startsWith(`**`))n.push(a(`strong`,{children:c.slice(2,-2)},l));else if(c.startsWith("`"))n.push(a(`code`,{className:`font-mono text-[0.9em]`,children:c.slice(1,-1)},l));else{let e=/^\[([^\]]+)\]\(([^)]+)\)$/.exec(c),t=e?.[1]??c,r=e?At(e[2]??``):null;n.push(r?a(`a`,{href:r,target:`_blank`,rel:`noreferrer noopener`,className:`text-primary underline`,children:t},l):a(`span`,{children:t},l))}i=r+c.length}return i<e.length&&n.push(e.slice(i)),n}function Mt(e,t){let n=e.split(`
|
|
5
|
-
`),r=[],i=[],o=[],s=0,c=()=>{if(i.length===0)return;let e=i.join(` `).trim();i=[],e.length!==0&&(r.push(a(`p`,{className:`mb-2 last:mb-0`,children:jt(e,`${t}-p-${s}`)},`${t}-p-${s}`)),s+=1)},l=()=>{if(o.length===0)return;let e=o;o=[],r.push(a(`ul`,{className:`mb-2 list-disc pl-4 last:mb-0`,children:e.map((e,n)=>a(`li`,{children:jt(e,`${t}-li-${s}-${n}`)},`${t}-li-${s}-${n}`))},`${t}-ul-${s}`)),s+=1};for(let e of n){let n=/^(#{1,3})\s+(.*)$/.exec(e),u=/^\s*[-*]\s+(.*)$/.exec(e);if(n){c(),l();let e=n[1]?.length??1,i=jt(n[2]??``,`${t}-h-${s}`),o=e===1?`text-sm font-semibold mb-2`:`text-xs font-semibold mb-1.5 mt-2`;r.push(a(e===1?`h3`:`h4`,{className:o,children:i},`${t}-h-${s}`)),s+=1;continue}if(u){c(),o=[...o,u[1]??``];continue}if(e.trim().length===0){c(),l();continue}l(),i=[...i,e.trim()]}return c(),l(),r}function Nt({markdown:e}){return a(`div`,{className:`text-xs text-foreground leading-relaxed`,children:kt(e).map((e,t)=>e.kind===`code`?a(`pre`,{className:`mb-2 overflow-auto rounded-md bg-surface-hover p-2 font-mono text-[10px] last:mb-0`,children:e.body.replace(/\n$/,``)},`code-${t}`):a(`div`,{children:Mt(e.body,`b${t}`)},`text-${t}`))})}c();function Pt(e){return e.replace(/^@camstack\/(addon-)?/,``)}function Ft(e,t,n){let r=ht(e,n);return r.some(e=>e.version===t)?r:[{version:t,distTags:[],deprecated:void 0},...r]}function It({pending:e,failed:n,body:r,missing:i}){let{t:o}=G();return e?t(`div`,{className:`flex items-center gap-2 py-6 text-xs text-foreground-subtle`,children:[a(x,{className:`h-3.5 w-3.5 animate-spin`}),o(`addons.installDialog.loadingDocument`,`Loading…`)]}):n||r===void 0?a(`p`,{className:`py-4 text-xs text-danger`,children:o(`addons.installDialog.couldNotLoadDocument`,`Could not load this file from the registry.`)}):r.status===`ok`&&r.markdown!==void 0?a(Nt,{markdown:r.markdown}):r.status===`error`?a(`p`,{className:`py-4 text-xs text-danger`,children:o(`addons.installDialog.documentError`,`Could not load this file. {{message}}`,{message:r.message??``})}):a(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:i})}function Lt({target:e,installing:n,installError:r,onClose:i,onInstall:o}){let{t:c}=G(),[l,u]=s(e.version),[d,f]=s(!1),p=H({name:e.name}),m=ye({name:e.name,version:l}),h=p.data??[],g=gt(h),_=Ft(h,l,d),v=m.data;return a(fe,{open:!0,onOpenChange:e=>!e&&i(),children:t(I,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(B,{children:a(Oe,{children:c(`addons.installDialog.title`,`Install {{name}}`,{name:Pt(e.name)})})}),t(de,{className:`space-y-3`,children:[a(`p`,{className:`font-mono text-[10px] text-foreground-subtle`,children:e.name}),e.description.length>0&&a(`p`,{className:`text-xs text-foreground`,children:e.description}),t(`div`,{className:`space-y-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:c(`addons.installDialog.version`,`Version`)}),a(T,{"aria-label":c(`addons.installDialog.version`,`Version`),value:l,options:_.map(e=>({value:e.version,label:mt(e)?c(`addons.installDialog.deprecatedVersion`,`{{version}} (deprecated)`,{version:e.version}):e.version})),onChange:e=>u(e.target.value)}),p.isError&&a(`p`,{className:`text-[10px] text-danger`,children:c(`addons.versionPicker.registryError`,`Could not load versions from the registry.`)}),g>0&&a(F,{type:`button`,variant:`ghost`,size:`sm`,className:`h-auto justify-start px-0 text-[10px] font-normal text-foreground-subtle underline`,onClick:()=>f(e=>!e),children:d?c(`addons.versionPicker.hideOlder`,`Hide older versions`):c(`addons.versionPicker.showOlder`,`Show older versions ({{count}})`,{count:g})})]}),t(z,{defaultValue:`readme`,children:[t(Te,{children:[a(W,{value:`readme`,children:c(`addons.installDialog.readme`,`README`)}),a(W,{value:`changelog`,children:c(`addons.installDialog.changelog`,`CHANGELOG`)})]}),a(V,{value:`readme`,children:a(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border bg-background p-3`,children:a(It,{pending:m.isPending,failed:m.isError,body:v?.readme,missing:c(`addons.installDialog.missingReadme`,`This package has no README.`)})})}),a(V,{value:`changelog`,children:a(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border bg-background p-3`,children:a(It,{pending:m.isPending,failed:m.isError,body:v?.changelog,missing:c(`addons.installDialog.missingChangelog`,`This package has no CHANGELOG.`)})})})]}),r!=null&&r.length>0&&a(`p`,{className:`text-xs text-danger`,children:r})]}),t(ie,{children:[a(F,{type:`button`,variant:`outline`,size:`sm`,onClick:i,children:c(`common.cancel`,`Cancel`)}),a(F,{type:`button`,size:`sm`,disabled:n||l.length===0,onClick:()=>o(e.name,l),children:n?a(x,{className:`h-3.5 w-3.5 animate-spin`}):c(`addons.installDialog.install`,`Install`)})]})]})})}function Rt(e,t){let n=new Map;for(let r of e){if(r.isHub||r.onHub||Re(r.packageName)||!t.isHub&&r.nodeId!==t.id)continue;let e=n.get(r.packageName)??[];e.push(r),n.set(r.packageName,e)}return[...n].map(([e,t])=>({packageName:e,rows:t})).sort((e,t)=>e.packageName.localeCompare(t.packageName))}function zt({selectedNode:e}){let{t:n}=G(),{data:r}=R(ut,{staleTime:dt});if(r===void 0)return null;let i=Rt(r.installations,e),o=r.unreachable.filter(t=>e.isHub||t.nodeId===e.id);return i.length===0&&o.length===0?null:t(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 px-3 py-2.5 space-y-2`,children:[t(`div`,{className:`flex items-center gap-2 text-[11px] font-semibold text-foreground`,children:[a(y,{className:`h-3.5 w-3.5 text-warning`}),e.isHub?n(`addons.nodeOnlyPackagesPanel.installedOnAgentsButNot`,`Installed on agents but not on the hub`):n(`addons.nodeOnlyPackagesPanel.installedOnButNotOn`,`Installed on {{name}} but not on the hub`,{name:e.name})]}),o.length>0&&a(`div`,{className:`text-[10px] text-foreground-subtle`,children:n(`addons.nodeOnlyPackagesPanel.unreachable`,{nodes:o.map(e=>e.nodeId).join(`, `)})}),i.map(n=>t(`div`,{className:`flex items-center justify-between gap-3 flex-wrap rounded-md border border-border bg-surface px-3 py-2`,children:[t(`div`,{className:`min-w-0`,children:[a(`div`,{className:`text-xs font-mono text-foreground break-all`,children:n.packageName}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:n.rows.map(e=>`${e.nodeName}${e.version===null?``:` ${e.version}`}${e.isOnline?``:` (offline)`}`).join(` · `)})]}),a(pt,{packageName:n.packageName,displayName:n.packageName,selectedNode:e,hideNodeAction:e.isHub})]},n.packageName))]})}function Bt({addon:e,installing:n,onInstall:r}){let{t:i}=G();return t(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[a(`div`,{className:`w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0`,children:e.name.replace(`@camstack/addon-`,``).charAt(0).toUpperCase()}),t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[a(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),t(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),a(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&a(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?a(ce,{variant:`success`,icon:a(E,{className:`h-3 w-3`}),children:e.installedVersion??i(`system.capabilityCatalog.installed`,`Installed`)}):t(F,{size:`sm`,onClick:()=>r(e),disabled:n,className:`shrink-0`,children:[n?a(x,{className:`h-3 w-3 animate-spin`}):a(d,{className:`h-3 w-3`}),i(`system.capabilityCatalog.install`,`Install`)]})]})}function Vt({capability:e,installing:n,onInstall:r}){let{t:i}=G(),{data:o,isPending:s,isError:c}=oe({capability:e}),l;if(c)l=a(`div`,{className:`px-3 py-2 text-xs text-danger`,children:i(`system.capabilityCatalog.couldNotSearchTheNpm`,`Could not search the npm catalog right now. Try again in a moment.`)});else if(s||o===void 0)l=t(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground-subtle`,children:[a(x,{className:`h-3 w-3 animate-spin`}),i(`system.capabilityCatalog.searchingTheNpmCatalog`,`Searching the npm catalog…`)]});else{let t=o.filter(e=>!e.installed);l=t.length===0?a(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:o.length===0?i(`system.capabilityCatalog.noPublishedAddonDeclaresThe`,`No published addon declares the "{{capability}}" capability.`,{capability:e}):i(`system.capabilityCatalog.everyPublishedAddonThatDeclares`,`Every published addon that declares "{{capability}}" is already installed.`,{capability:e})}):a(`div`,{className:`divide-y divide-border`,children:t.map(e=>a(Bt,{addon:e,installing:n,onInstall:r},e.name))})}return t(`section`,{className:`rounded-md border border-border bg-surface overflow-hidden`,"aria-label":i(`system.capabilityCatalog.availableToInstall`,`Available to install`),children:[a(`h2`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:i(`system.capabilityCatalog.availableToInstall`,`Available to install`)}),l]})}c();function Ht(e){return e===`npm`||e===`dev`?e:null}var Ut=`rounded-full border border-primary bg-primary/10 px-2 py-0.5 text-[10px] text-foreground`,Wt=`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-muted hover:bg-surface-hover`,Gt=[{seconds:900,label:`15m`},{seconds:3600,label:`1h`},{seconds:21600,label:`6h`},{seconds:43200,label:`12h`},{seconds:86400,label:`24h`}],Kt={id:`hub`,name:`Hub`,isHub:!0,isOnline:!0};function qt(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function Jt(e){return e===`local`?`dev`:`npm`}function Yt(e){let t=e;if(!t?.manifest)return null;let n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??`0.0.0`,capabilities:t.manifest.capabilities??[]},r=t.process,i=r?{pid:r.pid,mode:r.mode===`forked`?`forked`:`in-process`,state:r.state??`unknown`,...r.reason===void 0?{}:{reason:r.reason}}:void 0,a=t.health,o=t.declaration?.execution,s=t.manifest.execution,c=o?.placement??s?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...i?{process:i}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function Xt(e){let t=new Map,n=[];for(let r of e){let e=r.manifest.packageName;if(!e){n.push(r);continue}let i=t.get(e);if(i)i.addons.push(r);else{let n=r.manifest.bundle,i={packageName:e,displayName:n?.displayName??r.manifest.packageDisplayName??r.manifest.name,version:r.manifest.packageVersion,addons:[r],...r.installSource===void 0?{}:{installSource:r.installSource},...n===void 0?{}:{bundle:n}};t.set(e,i)}}let r=[];for(let e of t.values())e.bundle!==void 0||e.addons.length>=2?r.push({bundle:e,representative:e.addons[0]}):r.push(e.addons[0]);return r.push(...n),r}function $(e){return`bundle`in e}function Zt({addons:c,clusterStatus:u,selectedNode:f,onRefresh:p,listPhase:m}){let{t:h}=G(),g=l(),[_,y]=s(``),[S,ee]=s(!1),E=e(_),[D,te]=s(!1),O=n(null);o(()=>{if(!D)return;let e=e=>{O.current&&!O.current.contains(e.target)&&te(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[D]);let{data:k}=P({nodeId:f.id}),A=r(()=>{let e=new Map;for(let t of k??[])t.blockedBy===void 0&&e.set(t.name,t.latestVersion);return e},[k]),ne=r(()=>{let e=new Map;for(let t of k??[]){let n=t.blockedBy?.find(e=>e.kind===`server-too-old`);n!==void 0&&e.set(t.name,{latestVersion:t.latestVersion,requiredServer:n.required})}return e},[k]),re=r(()=>(k??[]).filter(e=>!e.isSystem&&e.blockedBy===void 0).length,[k]),[j,ie]=s(()=>new Set),[ae,se]=s(()=>new Map),ce=i(e=>{ie(t=>new Set(t).add(e))},[]),le=i(e=>{ie(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),N=i((e,t)=>{se(n=>new Map(n).set(e,t))},[]),de=i(e=>{se(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),fe=ue({onMutate:e=>{ce(e.name),de(e.name)},onSuccess:(e,t)=>{le(t.name);let n=e;if(n&&n.success===!1){N(t.name,n.error??`Update failed (no error message returned by server)`);return}g.invalidateQueries({queryKey:[[`addons`]]}),g.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{le(t.name),N(t.name,e instanceof Error?e.message:String(e))}}),I=tt(),me=n(new Set);o(()=>{let e=new Set;for(let[t,n]of I)$e(n)&&e.add(t);let t=[...me.current].some(t=>!e.has(t));me.current=e,t&&(g.invalidateQueries({queryKey:[[`addons`]]}),g.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[I,g]);let{data:L}=Ee(void 0),R=Se({onSuccess:()=>{g.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),he=U({onSuccess:()=>{g.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:z,isFetching:ge}=oe({query:E||void 0},{enabled:D}),B=xe(),{data:V}=we(void 0),_e=V?.requestedAt,[H,ye]=s(null),[be,Ce]=s(!1);o(()=>{if(V?.kind===`framework-bulk-update`&&V.requestedAt!==H){ye(V.requestedAt),Ce(!0);let e=window.setTimeout(()=>Ce(!1),6e3);return()=>window.clearTimeout(e)}},[_e,H,V]),w();let W=i(async()=>{let e=(k??[]).filter(e=>!e.isSystem&&e.blockedBy===void 0);if(e.length!==0){if(!f.isHub){for(let t of e)await fe.mutateAsync({name:t.name,version:t.latestVersion,nodeId:f.id});return}await B.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[f.id]})}},[k,f.id,f.isHub,B,fe]),[Te,De]=s(null),[Oe,ke]=s(null),Ae=e=>{ke(null),De(e)},je=pe({onSuccess:()=>{De(null),ke(null),g.invalidateQueries({queryKey:[[`addons`]]}),g.invalidateQueries({queryKey:[[`addonPages`]]}),g.invalidateQueries({queryKey:[[`capabilities`]]}),g.invalidateQueries({queryKey:[[`integrations`]]})},onError:e=>{ke(e instanceof Error?e.message:`Install failed`)}}),[Me,Ne]=s(`type`),[Pe,Ie]=s(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),Re=e=>{Ie(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[K,q]=Fe(),J=K.get(`capability`),Ue=K.get(`updatable`)===`1`,Y=K.get(`error`)===`1`,X=Ht(K.get(`source`)),Z=ze(K.get(Ve))===`integration`,{data:Ge}=ve(void 0,{enabled:Z}),Ke=r(()=>Ge===void 0?null:new Set(Ge.map(e=>e.addonId)),[Ge]),qe=i(e=>{let t=new URLSearchParams(K);e?t.set(Ve,`integration`):t.delete(Ve),q(t,{replace:!0})},[K,q]),Je=i(e=>{let t=new URLSearchParams(K);e?t.set(`updatable`,`1`):t.delete(`updatable`),q(t,{replace:!0})},[K,q]),Ye=i(e=>{let t=new URLSearchParams(K);e?t.set(`error`,`1`):t.delete(`error`),q(t,{replace:!0})},[K,q]),Xe=i(e=>{let t=new URLSearchParams(K);e===null?t.delete(`source`):t.set(`source`,e),q(t,{replace:!0})},[K,q]),Ze=r(()=>c.filter(e=>We(e.process)!==null).length,[c]),Q=r(()=>{let e=c.filter(e=>!Le(e.manifest.packageName));return f.isHub||(e=e.filter(e=>qt(e.placement,f.isHub))),J&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===J))),Z&&(e=[...Be(e,Ke)]),Ue&&(e=e.filter(e=>{let t=e.manifest.packageName;return t!==void 0&&A.has(t)})),X!==null&&(e=e.filter(e=>Jt(e.installSource)===X)),Y&&(e=e.filter(e=>We(e.process)!==null)),e},[c,f.isHub,J,Ue,X,Y,Z,Ke,A]),Qe=()=>{let e=new URLSearchParams(K);e.delete(`capability`),q(e,{replace:!0})},et=Pe===`flat`?Q:Xt(Q),nt=r(()=>{let e=[...et];switch(Me){case`type`:e.sort((e,t)=>{let n=+!$(e),r=+!$(t);if(n!==r)return n-r;let i=$(e)?e.bundle.displayName:e.manifest.name,a=$(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=$(e)?e.bundle.displayName:e.manifest.name,r=$(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=$(e)?e.bundle.installSource??``:e.installSource??``,r=$(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[et,Me]);return t(`div`,{className:`space-y-3`,children:[a(He,{open:S,onOpenChange:ee}),[...ae.entries()].map(([e,n])=>a(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-2.5 py-1.5 text-[11px]`,children:t(`div`,{className:`flex items-start justify-between gap-3`,children:[t(`div`,{className:`space-y-0.5`,children:[a(`div`,{className:`font-medium text-danger`,children:h(`systemPage.addons.updateFailed`,{name:e})}),a(`div`,{className:`text-foreground-subtle font-mono`,children:n})]}),a(F,{variant:`unstyled`,type:`button`,onClick:()=>de(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:h(`common.dismiss`)})]})},e)),t(`div`,{className:`flex items-center gap-x-2 gap-y-1.5 flex-wrap`,children:[t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.sort`,`Sort:`)}),t(T,{wrapperClassName:`inline-block w-auto`,value:Me,onChange:e=>Ne(e.target.value),children:[a(`option`,{value:`type`,children:h(`admin.system.addons.bundlesFirst`,`Bundles first`)}),a(`option`,{value:`name`,children:h(`admin.system.addons.name`,`Name`)}),a(`option`,{value:`source`,children:h(`admin.system.addons.installSource`,`Install source`)})]})]}),t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.view`,`View:`)}),a(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>a(F,{variant:`unstyled`,type:`button`,onClick:()=>Re(e),className:`px-2 py-1 transition-colors capitalize ${Pe===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?h(`admin.system.addons.groupMultiAddonPackagesInto`,`Group multi-addon packages into a bundle card`):h(`admin.system.addons.showEveryAddonAsIts`,`Show every addon as its own card`),children:e},e))})]}),f.isHub&&t(`div`,{className:`flex items-center gap-1.5`,children:[a(C,{className:`h-3 w-3 text-foreground-subtle`}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.autoUpdate`,`Auto-Update:`)}),a(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>a(F,{variant:`unstyled`,type:`button`,onClick:()=>R.mutate({channel:e}),disabled:R.isPending,className:`px-2 py-1 transition-colors capitalize ${L?.channel===e?e===`off`?`bg-gray-700 text-gray-200`:e===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${e===`off`?``:`border-l border-border`}`,children:e},e))})]}),f.isHub&&t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.checkEvery`,`Check every:`)}),a(T,{wrapperClassName:`inline-block w-auto`,className:`font-medium text-foreground-subtle`,value:L?.updateCheckIntervalSeconds??21600,disabled:he.isPending||L===void 0,onChange:e=>{L!==void 0&&he.mutate({channel:L.channel,updateCheckIntervalSeconds:Number(e.target.value)})},children:Gt.map(e=>a(`option`,{value:e.seconds,children:e.label},e.seconds))})]}),re>0&&t(F,{variant:`unstyled`,type:`button`,onClick:()=>void W(),disabled:B.isPending,className:`flex items-center gap-1 px-2 py-1 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium`,children:[B.isPending?a(x,{className:`w-3 h-3 animate-spin`}):a(d,{className:`w-3 h-3`}),B.isPending?h(`admin.system.addons.updating`,`Updating…`):h(`admin.system.addons.updateAll`,`Update All ({{nonSystemUpdateCount}})`,{nonSystemUpdateCount:re})]})]}),t(`div`,{className:`flex flex-wrap items-center gap-1.5`,role:`group`,"aria-label":h(`admin.system.addons.filterInstalledAddons`,`Filter installed addons`),children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.filter`,`Filter:`)}),[{id:`integrations`,label:h(`admin.system.addons.integrations`,`Integrations`),pressed:Z,toggle:()=>qe(!Z)},{id:`updatable`,label:h(`admin.system.addons.updatable`,`Updatable`),pressed:Ue,toggle:()=>Je(!Ue)},{id:`error`,label:h(`admin.system.addons.inError`,`In error ({{count}})`,{count:Ze}),pressed:Y,toggle:()=>Ye(!Y)},{id:`npm`,label:`npm`,pressed:X===`npm`,toggle:()=>Xe(X===`npm`?null:`npm`)},{id:`dev`,label:h(`admin.system.addons.dev`,`Dev`),pressed:X===`dev`,toggle:()=>Xe(X===`dev`?null:`dev`)}].map(e=>a(F,{variant:`unstyled`,type:`button`,"aria-pressed":e.pressed,onClick:e.toggle,className:e.pressed?Ut:Wt,children:e.label},e.id))]}),t(`div`,{className:`flex flex-col gap-1.5 sm:flex-row sm:items-center sm:gap-2`,children:[t(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:O,children:[a(M,{type:`text`,searchHotkey:!0,value:_,onChange:e=>{y(e.target.value),te(!0)},onFocus:()=>te(!0),placeholder:h(`admin.system.addons.searchAddonsOnNpm`,`Search addons on npm...`),"aria-label":h(`admin.system.addons.searchAddonsOnNpm2`,`Search addons on npm`),disabled:B.isPending,leftSlot:a(b,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),rightSlot:ge?a(x,{className:`h-3 w-3 animate-spin`}):void 0}),D&&z&&z.length>0&&t(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-md border border-border bg-surface shadow-xl overflow-hidden`,children:[z.length>0&&a(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:h(`systemPage.addons.npmResults`,{count:z.length})}),z&&z.length>0&&a(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:z.map(e=>a(Bt,{addon:e,installing:je.isPending,onInstall:e=>Ae({name:e.name,version:e.version,description:e.description})},e.name))})]})]}),a(Dt,{onUploadSuccess:()=>{g.invalidateQueries({queryKey:[[`addons`]]}),p()}})]}),J&&t(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5 rounded-md bg-primary/10 border border-primary/30 text-xs`,children:[a(`span`,{className:`text-foreground-subtle`,children:h(`admin.system.addons.filteringByCapability`,`Filtering by capability:`)}),a(`span`,{className:`font-mono text-primary font-semibold`,children:J}),a(F,{variant:`unstyled`,type:`button`,onClick:Qe,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:h(`admin.system.addons.clear`,`Clear`)})]}),J&&a(Vt,{capability:J,installing:je.isPending,onInstall:e=>Ae({name:e.name,version:e.version,description:e.description})}),J&&Q.length>0&&a(`h2`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:h(`admin.system.addons.installed`,`Installed`)}),be&&t(`div`,{className:`fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg max-w-sm pointer-events-auto`,children:[a(v,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),t(`div`,{children:[a(`div`,{className:`text-[11px] font-semibold text-foreground`,children:h(`admin.system.addons.bulkUpdateCompleted`,`Bulk update completed`)}),a(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:h(`admin.system.addons.systemPackagesUpdatedHubRestarted`,`System packages updated — hub restarted successfully.`)})]})]}),m===`pending`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[a(x,{className:`h-3 w-3 animate-spin`}),h(`admin.system.addons.loadingInstalled`,`Loading installed addons…`)]}),m===`error`&&a(`div`,{className:`text-xs text-danger`,children:h(`admin.system.addons.failedToLoadAddons`,`Failed to load addons`)}),m===`ready`&&Q.length===0&&a(`div`,{className:`text-xs text-foreground-subtle`,children:c.length===0?h(`admin.system.addons.noAddonsInstalled`,`No addons installed`):J?h(`admin.system.addons.noInstalledAddonDeclaresThe`,`No installed addon declares the "{{capabilityFilter}}" capability. Any addon you can install appears under "Available to install" above.`,{capabilityFilter:J}):h(`admin.system.addons.noAddonsCompatibleWithPlacement`,`No addons compatible with {{name}} (placement filter active)`,{name:f.name})}),a(`div`,{className:`space-y-1.5`,children:m===`ready`&&nt.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,n=A.get(t),r=ne.get(t),i=$(e)?e.representative:e,o=n?e=>fe.mutate({name:t,version:e,nodeId:f.id}):void 0,s=I.get(t)??null,c=s!==null&&$e(s);return a(Tt,{addon:i,clusterStatus:u?.[i.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:n,...r===void 0?{}:{blockedUpdate:r},...r===void 0?{}:{onUpdateServer:()=>ee(!0)},isUpdating:j.has(t)||c,jobProgress:s,onUpdate:o,disabledByBulk:B.isPending,selectedNode:f},$(e)?t:e.manifest.id)})}),Te!==null&&a(Lt,{target:Te,installing:je.isPending,installError:Oe,onClose:()=>De(null),onInstall:(e,t)=>je.mutate({packageName:e,version:t})})]})}function Qt(){let{t:e}=G(),r=l(),{data:i}=Ce(void 0),{nodes:s}=be(),{selection:c,selectNode:u,requestedNodeId:d}=Ue(s.length>0?s:[Kt]),f=c.node??Kt,p=f.id,m=s.length>0?c.staleNodeId:null,{data:h,isLoading:g,isError:_}=ke({nodeId:p}),v=ge(),y=ae(),b=v.isPending||y.isPending,x=async()=>{await v.mutateAsync({nodeId:p}),await y.mutateAsync(),r.invalidateQueries({queryKey:[[`addons`]]})},S=n(v);S.current=v;let w=n(d??`hub`);o(()=>{S.current.mutate({nodeId:w.current})},[]);let T=(h??[]).map(Yt).filter(e=>e!==null);return t(q,{children:[t(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[a(he,{selectedNodeId:p,onSelect:u}),t(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[!g&&!_&&a(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:e(`systemPage.addons.installedCount`,{count:T.length})}),t(F,{variant:`unstyled`,type:`button`,onClick:()=>void x(),disabled:b,className:`inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:e(`admin.system.addons.reFetchAddonsCheckNpm`,`Re-fetch addons + check npm for new versions`),children:[a(C,{className:`w-3 h-3 ${b?`animate-spin`:``}`}),e(`admin.system.addons.checkForUpdates`,`Check for updates`)]})]})]}),a(J,{staleNodeId:m,shownNodeName:f.name}),a(zt,{selectedNode:f}),a(Zt,{addons:T,clusterStatus:i,selectedNode:f,onRefresh:()=>void x(),listPhase:g?`pending`:_?`error`:`ready`})]})}export{Qt as AddonsPage};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,t as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bn as d,D as f,Ei as p,Et as m,G as h,L as g,Q as _,Sa as v,Vn as y,Vr as b,bn as x,bt as S,ft as C,hn as w,ma as T,nn as E,ui as D,zn as O}from"./player-overlays-KBeT29r4.js";import{Ri as k}from"./src-BL8KgH_H.js";import{t as A}from"./flask-conical-D7tbJQpj.js";import{t as j}from"./message-square-plus-_aGccjyj.js";import{Aa as M,Gr as N,Hr as P,Ia as F,Kr as I,La as L,Np as ee,Pa as R,Pp as te,Si as ne,Tp as z,Ua as re,dt as B,ha as V,ic as H,ka as U,q as ie,rm as W}from"./src-FszuUAOe.js";import{t as G}from"./i18n-CkHf1ol7.js";import{t as K}from"./useTranslation-BJr-n0es.js";import"./mount-OGGUkOts.js";import{Oi as ae,Tt as q,b as J}from"./index-PErHbELp.js";import{t as Y}from"./AdminSectionedPage-Cx1I8W-T.js";import{t as oe}from"./InstancesTable-8sjRWeOv.js";import{t as se}from"./AdminPage-LgScsiWj.js";import{a as ce,c as le,d as ue,f as de,i as fe,l as X,n as pe,o as me,p as he,r as ge,s as Z,t as _e,u as ve}from"./ai-page.helpers-BgaYtFZQ.js";c();function ye(){let{t}=K(),n=S(),r=M({functionCap:`llm`}).data??[],a=s({queryKey:pe,queryFn:()=>n.trpcClient.llm.getDefaults.query({})}),o=u({mutationFn:e=>n.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{a.refetch()}}),c=e=>(a.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,l=e=>e===`vision`?t(`ai.defaultVision`,`Default vision profile`):t(`ai.defaultText`,`Default text profile`);return i(P,{headingId:`ai-profiles-defaults`,title:t(`ai.defaultsTitle`,`Defaults`),children:i(`div`,{className:`${f} grid gap-4 sm:grid-cols-2`,children:ge.map(({purpose:n,visionOnly:a})=>{let s=a?r.filter(X):r,u=c(n),d=r.find(e=>e.id===u);return e(`div`,{children:[i(ne,{className:`mb-1 block`,htmlFor:`llm-default-${n}`,children:l(n)}),i(C,{id:`llm-default-${n}`,"aria-label":l(n),value:u,onChange:e=>o.mutate({purpose:n,profileId:e.target.value===``?null:e.target.value}),options:[{value:``,label:t(`ai.none`,`None`)},...u!==``&&!s.some(e=>e.id===u)?[{value:u,label:d?.name??u}]:[],...s.map(e=>({value:e.id,label:Z(e)===``?e.name:`${e.name} · ${Z(e)}`}))]}),u!==``&&d===void 0&&i(`p`,{className:`mt-1 text-xs text-danger`,children:t(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&i(`p`,{className:`mt-1 text-xs text-warning`,children:t(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&i(`p`,{className:`mt-1 text-xs text-danger`,children:String(o.error)})]},n)})})})}var be=2e3;function Q(e){return G.t(`system.aiModelPicker.sizeGb`,{value:(e/1e9).toFixed(2)})}function xe(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Se({nodeId:t,value:r,onChange:a}){let{t:c}=K(),l=S(),[d,f]=o(``),[m,h]=o(null),[g,_]=o(!1),v=s({queryKey:_e,queryFn:()=>l.trpcClient.llm.listModelCatalog.query({})}),x=s({queryKey:[`llm`,`listNodeModels`,t],queryFn:()=>l.trpcClient.llm.listNodeModels.query({nodeId:t})}),w=u({mutationFn:e=>l.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{h(e),_(!1),e.ok&&a({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),T=u({mutationFn:e=>l.trpcClient.llm.installModel.mutate({nodeId:t,model:e}),onSuccess:()=>{_(!0),x.refetch()}}),E=s({queryKey:fe,enabled:T.isPending,refetchInterval:T.isPending?be:!1,queryFn:()=>l.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(e=>e.nodeId===t)?.status?.download,D=n(()=>{let e=(v.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${Q(e.sizeBytes)}`})),n=(x.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(e=>({value:`node:${e.file}`,label:c(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:e.file,size:Q(e.sizeBytes),node:t})})),r=m?.ok===!0?[{value:`custom`,label:`${m.label} · ${Q(m.totalBytes)}`}]:[];return[{value:``,label:c(`ai.selectModel`,`Select a model…`)},...e,...n,...r]},[v.data,x.data,m,t,c]),O=e=>{if(e===``){a(null);return}if(e===`custom`){if(m?.ok!==!0)return;a({model:m.model,modelId:m.label,supportsVision:m.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),n=v.data?.find(e=>e.id===t);a({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:n?.purpose===`vision`});return}let t=e.slice(5),n=x.data?.find(e=>e.file===t);n?.path!==void 0&&a({model:{kind:`path`,path:n.path},modelId:t,supportsVision:!1})},k=e=>{d.trim()!==``&&w.mutate({ref:d.trim(),...e===void 0?{}:{maxBytes:e}})};return e(`div`,{className:`space-y-3`,children:[i(B,{label:c(`ai.model`,`Model`),required:!0,children:i(C,{id:`ai-model`,"aria-label":c(`ai.model`,`Model`),value:xe(r),options:D,onChange:e=>O(e.target.value)})}),i(B,{label:c(`ai.hfTitle`,`Add a model from Hugging Face`),description:c(`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.`),children:e(`div`,{className:`flex gap-2`,children:[i(ee,{"aria-label":c(`ai.hfTitle`,`Add a model from Hugging Face`),value:d,onChange:e=>f(e.target.value),placeholder:c(`system.aiModelPicker.unslothQwen3635bA3b`,`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),k())}}),e(z,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||w.isPending,onClick:()=>k(),children:[w.isPending?i(b,{className:`h-3.5 w-3.5 animate-spin`}):i(y,{className:`h-3.5 w-3.5`}),c(`ai.hfCheck`,`Check`)]})]})}),w.isError&&i(R,{message:w.error instanceof Error?w.error.message:c(`common.error`,`Error`)}),m?.ok===!1&&i(R,{message:m.message,action:e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(m.candidates??[]).map(e=>i(z,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{let t=`${d.trim().split(`:`)[0]??``}:${e}`;f(t),w.mutate({ref:t})},children:e},e)),m.requiredBytes!==void 0&&i(z,{size:`sm`,variant:`secondary`,type:`button`,onClick:()=>k(m.requiredBytes),children:c(`ai.hfOverride`,`Install anyway ({{size}})`,{size:Q(m.requiredBytes)})})]})}),m?.ok===!0&&e(`div`,{className:`space-y-2 rounded-md border border-border bg-surface p-2.5`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[i(`span`,{className:`text-[11px] font-medium text-foreground`,children:m.label}),i(F,{variant:m.purpose===`vision`?`info`:`default`,children:m.purpose}),i(F,{variant:`default`,children:Q(m.totalBytes)})]}),m.extraFilenames.length>0&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:c(`ai.hfExtras`,`Also downloads: {{files}}`,{files:m.extraFilenames.join(`, `)})}),e(`div`,{className:`flex items-center gap-2`,children:[e(z,{size:`sm`,type:`button`,disabled:T.isPending||g,onClick:()=>T.mutate(m.model),children:[T.isPending?i(b,{className:`h-3.5 w-3.5 animate-spin`}):i(p,{className:`h-3.5 w-3.5`}),g?c(`ai.hfInstalled`,`Downloaded`):c(`ai.hfInstall`,`Download to {{node}}`,{node:t})]}),E!==void 0&&i(`span`,{className:`text-[10px] text-foreground-subtle`,children:E.phase===`verifying`?c(`ai.hfVerifying`,`verifying {{file}}…`,{file:E.file}):c(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:E.file,index:E.fileIndex,count:E.fileCount,done:Q(E.downloadedBytes),total:E.totalBytes===void 0?``:` / ${Q(E.totalBytes)}`})})]}),T.isError&&i(R,{message:T.error instanceof Error?T.error.message:c(`common.error`,`Error`)})]})]})}function Ce({value:t,onChange:n}){let{t:r}=K(),a=S(),o=s({queryKey:fe,queryFn:()=>a.trpcClient.llm.listRuntimeNodes.query({})});return e(`div`,{children:[i(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:r(`ai.appleNode`,`Mac that runs it`)}),o.isPending&&e(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(b,{className:`h-3.5 w-3.5 animate-spin`}),r(`ai.appleAsking`,`Asking the nodes…`)]}),o.isError&&i(`p`,{className:`text-[11px] text-danger`,children:o.error instanceof Error?o.error.message:r(`ai.runtimesFailed`,`Failed to read runtime nodes`)}),o.isSuccess&&o.data.length===0&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}),o.isSuccess&&o.data.length>0&&i(`div`,{role:`radiogroup`,className:`space-y-1.5`,children:o.data.map(a=>{let o=me(a),s=o.nodeId===t;return e(z,{variant:`unstyled`,type:`button`,role:`radio`,"aria-checked":s,disabled:!o.selectable&&!s,onClick:()=>n(o.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 ${s?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block font-medium text-foreground`,children:o.nodeId}),o.detail!==null&&i(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:o.detail})]}),i(F,{variant:o.tone,children:r(o.labelKey,o.labelDefault)})]},o.nodeId)})}),i(`p`,{className:`mt-1.5 text-[10px] leading-relaxed text-foreground-subtle`,children:r(`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.`)})]})}function we(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Te({providerConfig:e,onProviderConfigChange:t}){return i(Ce,{value:we(e,`nodeId`),onChange:n=>t({...e,nodeId:n})})}function Ee({providerConfig:e,onProviderConfigChange:t,model:n,onModelChange:r}){let a=k.safeParse(e.model),o=a.success?{model:a.data,modelId:n.id,supportsVision:n.supportsVision}:null;return i(Se,{nodeId:we(e,`nodeId`)??`hub`,value:o,onChange:n=>{if(n===null){let{model:n,...i}=e;t(i),r({id:``,supportsVision:!1});return}t({...e,model:n.model}),r({id:n.modelId,supportsVision:n.supportsVision})}})}var De=new Map([[`ai/apple-node`,Te],[`ai/managed-model`,Ee]]);function Oe(e){return De.get(e)??null}c();function $(e,t){let n=e[t];return typeof n==`string`?n:``}function ke({row:a}){let{t:c}=K(),d=S(),f=l(),p=s({queryKey:n(()=>[q,a.addonId,`ai-lead`,a.id],[a]),queryFn:async()=>{let e=d.trpcClient.integrationInstances,[t,n]=await Promise.all([e.describe.query({addonId:a.addonId}),e.getInstance.query({addonId:a.addonId,id:a.id})]);return{description:t,instance:n}}}),[m,h]=o({}),g=t({}),_=t(!1),v=u({mutationFn:e=>d.trpcClient.integrationInstances.updateInstance.mutate({addonId:a.addonId,id:a.id,values:e}),onSuccess:async()=>{await f.invalidateQueries({queryKey:[q]}),await f.invalidateQueries({queryKey:[U]}),h({})}}),y=r(e=>{g.current={...g.current,...e},h(t=>({...t,...e})),!_.current&&(_.current=!0,queueMicrotask(()=>{let e=g.current;g.current={},_.current=!1,v.mutate(e)}))},[v]),x=p.data?.description.kinds?.find(e=>e.id===a.kindId),w=p.data?.instance?.formValues,T=n(()=>({...w,...m}),[w,m]),E=x?.widgets??[],D=E.some(e=>e.placement===`model`),O=n(()=>({...$(T,`nodeId`)===``?{}:{nodeId:$(T,`nodeId`)},...typeof T.modelRef==`object`&&T.modelRef!==null?{model:T.modelRef}:{}}),[T]),k={id:$(T,`model`),supportsVision:T.supportsVision===!0},A=u({mutationFn:()=>d.trpcClient.llm.listModels.mutate({addonId:a.addonId,kind:a.kindId??``,profileId:a.id})});if(p.isPending)return null;if(p.isError)return i(R,{variant:`warning`,message:p.error.message});let j=A.data?.ok===!0?A.data.models:[],M=A.data?.ok===!1?A.data:null,N=e=>{let t=j.find(t=>t.id===e);y({model:e,...t?.features?.vision===void 0?{}:{supportsVision:t.features.vision}})};return e(`div`,{className:`space-y-3`,"data-testid":`ai-profile-lead`,children:[E.map(({id:e})=>{let t=Oe(e);return t===null?i(R,{variant:`warning`,message:c(`ai.unknownWidget`,`This provider needs an editor part this build does not have ({{id}}).`,{id:e})},e):i(t,{providerConfig:O,onProviderConfigChange:e=>y({...$(e,`nodeId`)===$(O,`nodeId`)?{}:{nodeId:$(e,`nodeId`)},...e.model!==void 0&&e.model!==O.model?{modelRef:e.model}:{}}),model:k,onModelChange:e=>y({model:e.id,supportsVision:e.supportsVision})},e)}),!D&&e(B,{label:c(`ai.model`,`Model`),children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(z,{size:`sm`,variant:`secondary`,type:`button`,disabled:A.isPending,onClick:()=>A.mutate(),children:[A.isPending?i(b,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`ai.loadModels`,`Load models`)]}),j.length>0&&i(C,{"aria-label":c(`ai.model`,`Model`),value:k.id,onChange:e=>N(e.target.value),options:[...j.some(e=>e.id===k.id)||k.id===``?[]:[{value:k.id,label:k.id}],...j.map(e=>({value:e.id,label:e.label??e.id}))]})]}),M!==null&&i(`p`,{className:`mt-1 text-xs text-danger`,children:M.message}),A.isError&&i(`p`,{className:`mt-1 text-xs text-danger`,children:A.error.message})]}),v.isError&&i(R,{variant:`warning`,message:v.error.message})]})}c();var Ae=5e3;function je(e){return G.t(`system.aiRuntimes.sizeGb`,{value:(e/1e9).toFixed(1)})}function Me(){let{t}=K(),r=S(),a=s({queryKey:fe,refetchInterval:Ae,queryFn:()=>r.trpcClient.llm.listRuntimeNodes.query({})}),o=n(()=>[{key:`node`,header:t(`ai.colNode`,`Node`),render:e=>i(`span`,{className:`font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:t(`ai.colState`,`State`),nowrap:!0,render:n=>e(`span`,{className:`flex items-center gap-1.5`,children:[i(F,{variant:he(n),children:t(de(n))}),n.status?.downloadProgress!==void 0&&i(F,{variant:`info`,children:`${String(Math.round(n.status.downloadProgress*100))}%`})]})},{key:`model`,header:t(`ai.colModel`,`Model`),render:e=>i(`span`,{className:`text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:t(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums text-foreground-muted`,children:e.disk===void 0?`—`:je(e.disk.modelsBytes)})},{key:`features`,header:t(`ai.colFeature`,`Feature`),render:n=>{let r=ue(n);if(r.length===0)return i(`span`,{className:`text-foreground-subtle`,children:`—`});let a=r.flatMap(e=>e.detail===null?[]:[e.detail]);return e(`span`,{className:`flex flex-col items-start gap-0.5`,children:[i(`span`,{className:`flex flex-wrap gap-1`,children:r.map(e=>i(F,{variant:e.tone,children:t(e.labelKey)},e.id))}),a.length>0&&i(`span`,{className:`text-foreground-subtle`,children:a.join(` · `)})]})}},{key:`error`,header:t(`ai.colError`,`Error`),render:e=>e.error===void 0?i(`span`,{className:`text-foreground-subtle`,children:`—`}):i(`span`,{className:`text-danger`,children:e.error})}],[t]),c=a.data??[];return i(P,{headingId:`ai-runtimes-list`,title:t(`ai.runtimesList`,`Nodes`),children:a.isPending?e(`div`,{className:`${f} space-y-2`,"data-testid":`ai-runtimes-loading`,children:[i(L,{className:`h-8 w-full`}),i(L,{className:`h-8 w-full`})]}):a.isError?i(`div`,{className:f,children:i(R,{title:t(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:a.error instanceof Error?a.error.message:t(`common.error`,`Error`),onRetry:()=>void a.refetch()})}):c.length===0?i(V,{icon:O,title:t(`ai.noRuntimesTitle`,`No runtime nodes`),description:t(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):i(N,{columns:o,rows:c,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,maxBodyHeight:I})})}var Ne=_(`/addon/ai/test-chat`),Pe=_(`/addon/ai/test-chat/chats`),Fe=6e5;function Ie(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),Fe)}function Le(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Re(e){if(!Le(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 ze=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function Be(e){let t;try{t=JSON.parse(e)}catch{return null}if(!Le(t))return null;switch(t.kind){case`status`:{let e=ze.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:Re(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:G.t(`helpers.aiTestChat.providerError`)};default:return null}}async function*Ve(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=Be(e);t!==null&&(yield t)}a=r.indexOf(`
|
|
3
|
-
`)}}let e=r.trim();if(e.length>0){let t=Be(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function He(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function Ue(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function We(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 Ge(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 Ke(e,t){switch(e){case`resolving-image`:return G.t(`helpers.aiTestChat.phaseImage`);case`connecting`:return G.t(`helpers.aiTestChat.phaseConnecting`);case`first-token-wait`:return t>0?G.t(`helpers.aiTestChat.phaseWaitUpTo`,{seconds:Math.round(t/1e3)}):G.t(`helpers.aiTestChat.phaseWait`);case`streaming`:return G.t(`helpers.aiTestChat.phaseAnswering`)}}c();var qe=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],Je=360*60*1e3,Ye=40,Xe=160,Ze={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function Qe(){let{t:s}=K();S();let[c,l]=o(``),[u,p]=o(``),[h,_]=o(``),[y,b]=o([]),[x,D]=o(null),[O,k]=o(`none`),[A,N]=o(`throwaway`),[F,I]=o(null),[L,re]=o([]),[B,V]=o(null),[H,U]=o(null),W=t(null);a(()=>()=>W.current?.abort(),[]);let G=r(async()=>{let e=await fetch(Pe,{credentials:`same-origin`});e.ok&&re((await e.json()).chats??[])},[]);a(()=>{A===`persistent`&&G()},[A,G]);let ae=M({functionCap:`llm`}),q=n(()=>(ae.data??[]).filter(e=>e.enabled),[ae.data]),J=q.find(e=>e.id===c)??null,Y=H!==null,oe=r(async(e,t)=>{let n=new AbortController;W.current=n,V(null);let r=Ie(J===null?{}:ve(J));U({...Ze,firstTokenTimeoutMs:r??0});let i=``,a=null,o,l=null,d=null,f;try{let s=await fetch(Ne,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:n.signal,body:JSON.stringify({profileId:c,messages:e,...u.trim()===``?{}:{system:u.trim()},...t===void 0?{}:{attachment:t},...r===void 0?{}:{firstTokenTimeoutMs:r},...A===`persistent`?{persist:!0,...F===null?{}:{conversationId:F}}:{}})});if(!s.ok||s.body===null){let e=await s.text().catch(()=>``);throw Error(e.length>0?e:`HTTP ${String(s.status)}`)}for await(let e of Ve(s.body))switch(e.kind){case`status`:U(t=>({...t??Ze,phase:e.phase}));break;case`meta`:a=e.mediaSent,o=e.model,U(t=>({...t??Ze,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:i+=e.text,U(e=>({...e??Ze,text:i}));break;case`done`:d={outputTokens:e.outputTokens,latencyMs:e.latencyMs},f=e.conversationId;break;case`error`:l=`${e.code}: ${e.message}`;break}}catch(e){n.signal.aborted||V(e instanceof Error?e.message:s(`common.error`,`Error`))}finally{W.current=null,U(null)}f!==void 0&&(I(f),G());let p=n.signal.aborted&&i.length>0;l===null&&i.length===0&&!p||b(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:l??i,...l===null?{}:{failed:!0},...a===null?{}:{attachment:a},...o!==void 0&&l===null?{model:o}:{},...d===null?{}:d}])},[A,F,J,c,G,u,s]),se=r(()=>{let e=h.trim();if(e===``||c===``||Y)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...x===null?{}:{attachmentLabel:x.label,attachmentKind:x.ref.kind}},n=[...y,t];b(n),_(``);let r=x?.ref;D(null),k(`none`),oe(A===`persistent`&&F!==null?[{role:`user`,content:e}]:He(n),r)},[A,F,h,x,c,oe,Y,y]),ce=()=>W.current?.abort(),le=()=>{W.current?.abort(),b([]),D(null),_(``),V(null),U(null),I(null)},ue=async e=>{W.current?.abort();let t=await fetch(`${Pe}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();I(e),b(We(n)),U(null),V(null)};return e(`div`,{className:g,children:[i(P,{headingId:`ai-test-setup`,title:s(`ai.testSetup`,`Setup`),children:e(`div`,{className:`${f} space-y-3`,children:[e(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[e(`div`,{children:[i(ne,{className:`mb-1 block`,htmlFor:`ai-test-profile`,children:s(`ai.profile`,`Profile`)}),i(C,{id:`ai-test-profile`,value:c,onChange:e=>l(e.target.value),options:[{value:``,label:s(`ai.selectProfile`,`Select a profile…`)},...q.map(e=>({value:e.id,label:`${e.name} · ${Z(e)}${X(e)?` · vision`:``}`}))]}),q.length===0&&!ae.isLoading&&i(`p`,{className:`mt-1 text-xs text-foreground-subtle`,children:s(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),e(`div`,{children:[i(ne,{className:`mb-1 block`,htmlFor:`ai-test-system`,children:s(`ai.systemPrompt`,`System prompt (optional)`)}),i(ee,{id:`ai-test-system`,value:u,onChange:e=>p(e.target.value),placeholder:s(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),i(ie,{label:s(`ai.chatMode`,`Conversation mode`),value:A,options:[{value:`throwaway`,label:s(`ai.throwawayMode`,`Throwaway`)},{value:`persistent`,label:s(`ai.saveConversation`,`Save conversation`)}],onChange:e=>{N(e),e===`throwaway`&&I(null)}}),A===`persistent`&&e(`div`,{className:`space-y-2`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:s(`ai.testSubtitlePersistent`,`Conversations are saved for you and can be reopened. Throwaway mode is still available.`)}),e(z,{size:`sm`,variant:`secondary`,type:`button`,onClick:le,children:[i(j,{className:`h-3.5 w-3.5`}),s(`ai.newChat`,`New chat`)]}),L.length>0&&i(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:L.map(e=>i(`button`,{type:`button`,onClick:()=>void ue(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-xs hover:bg-surface-hover ${e.id===F?`bg-primary/10`:``}`,children:i(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.title})},e.id))})]}),i(`p`,{className:`text-xs text-foreground-subtle`,children:s(`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.`)}),J!==null&&!X(J)&&i(`p`,{className:`text-xs text-warning`,children:s(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]})}),B!==null&&i(R,{title:s(`ai.chatFailed`,`The test call failed`),message:B}),e(P,{headingId:`ai-test-conversation`,title:s(`ai.testConversation`,`Conversation`),actions:e(z,{size:`sm`,variant:`ghost`,type:`button`,disabled:y.length===0&&x===null,onClick:le,children:[i(E,{className:`h-3.5 w-3.5`}),s(`ai.clearChat`,`Clear`)]}),children:[i($e,{turns:y,live:H}),e(`div`,{className:`${f} space-y-2 border-t border-border`,children:[x!==null&&e(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-background px-2.5 py-1.5`,children:[x.ref.kind===`snapshot`?i(T,{className:`h-3.5 w-3.5 text-foreground-subtle`}):i(v,{className:`h-3.5 w-3.5 text-foreground-subtle`}),i(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:x.label}),i(te,{size:`sm`,variant:`ghost`,type:`button`,icon:m,"aria-label":s(`ai.removeAttachment`,`Remove attachment`),onClick:()=>D(null)})]}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(z,{size:`sm`,variant:O===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>k(O===`snapshot`?`none`:`snapshot`),children:[i(T,{className:`h-3.5 w-3.5`}),s(`ai.attachSnapshot`,`Camera snapshot`)]}),e(z,{size:`sm`,variant:O===`track`?`primary`:`outline`,type:`button`,onClick:()=>k(O===`track`?`none`:`track`),children:[i(v,{className:`h-3.5 w-3.5`}),s(`ai.attachTrack`,`Recent track`)]})]}),O===`snapshot`&&i(nt,{onPick:(e,t)=>{D({ref:{kind:`snapshot`,deviceId:e.id},label:s(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:t})}),k(`none`)}}),O===`track`&&i(it,{onPick:(e,t)=>{D({ref:{kind:`track`,trackId:e.trackId,deviceId:e.deviceId},label:s(`ai.trackOf`,`{{class}} on {{name}}`,{class:e.label??e.className,name:t})}),k(`none`)}}),e(`div`,{className:`flex items-center gap-2`,children:[i(ee,{value:h,onChange:e=>_(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),se())},placeholder:s(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":s(`ai.message`,`Message`)}),Y?e(z,{size:`sm`,variant:`secondary`,type:`button`,onClick:ce,children:[i(w,{className:`h-3.5 w-3.5`}),s(`ai.stop`,`Stop`)]}):e(z,{size:`sm`,type:`button`,disabled:h.trim()===``||c===``,onClick:se,children:[i(d,{className:`h-3.5 w-3.5`}),s(`ai.send`,`Send`)]})]})]})]})]})}function $e({turns:t,live:n}){let{t:r}=K();return t.length===0&&n===null?i(V,{icon:A,title:r(`ai.chatEmptyTitle`,`No messages yet`),description:r(`ai.chatEmpty`,`Pick a profile, optionally attach a camera snapshot or a recent track, and send a message. Nothing here is saved.`)}):e(`div`,{className:`max-h-[50vh] space-y-2 overflow-y-auto ${f}`,children:[t.map(e=>i(et,{turn:e},e.id)),n!==null&&e(`div`,{className:`space-y-1`,children:[n.mediaSent!==null&&i(tt,{attachment:n.mediaSent}),n.text.length>0&&i(et,{turn:{id:`live`,role:`assistant`,content:n.text},streaming:!0}),e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(b,{className:`h-3.5 w-3.5 animate-spin`}),Ke(n.phase,n.firstTokenTimeoutMs)]})]})]})}function et({turn:t,streaming:n=!1}){let{t:r}=K(),a=t.role===`user`,o=t.failed===!0?`border-danger/40 bg-danger/10`:`border-border bg-surface`;return i(`div`,{className:`flex ${a?`justify-end`:`justify-start`}`,children:e(`div`,{className:`max-w-[85%] rounded-lg border px-3 py-2 ${a?`border-primary/40 bg-primary/10`:o}`,children:[e(`p`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:[t.content,n&&i(`span`,{className:`ml-0.5 animate-pulse text-primary`,children:`▌`})]}),t.attachment!==void 0&&i(tt,{attachment:t.attachment}),t.attachmentLabel!==void 0&&e(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[t.attachmentKind===`track`?i(v,{className:`h-3 w-3`}):i(T,{className:`h-3 w-3`}),t.attachmentLabel]}),t.attachment!==void 0&&e(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[t.attachment.kind===`snapshot`?i(T,{className:`h-3 w-3`}):i(v,{className:`h-3 w-3`}),Ge(t.attachment)]}),t.model!==void 0&&i(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:r(`system.aiTestChat.tokMs`,`{{model}} · {{value2}} tok · {{value3}} ms`,{model:t.model,value2:String(t.outputTokens??0),value3:String(t.latencyMs??0)})})]})})}function tt({attachment:e}){let{t}=K(),n=Ue(e);return n===null?null:i(`img`,{src:n,alt:t(`system.aiTestChat.sentToTheModel`,`sent to the model`),className:`mt-1 max-h-32 rounded-md border border-border object-contain`})}function nt({onPick:e}){let{t}=K(),n=H({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?i(b,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):r.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noCameras`,`No camera found.`)}):i(`div`,{className:`grid max-h-56 grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-4`,children:r.map(t=>i(rt,{device:t,onPick:e},t.id))})}function rt({device:t,onPick:n}){let{t:r}=K(),a=re(t,`compact`),{src:o}=h(t.id,{width:Xe});return e(`button`,{type:`button`,onClick:()=>n(t,a),className:`overflow-hidden rounded-md border border-border bg-surface text-left transition-colors hover:border-primary/50`,children:[i(`span`,{className:`block aspect-video w-full bg-background-elevated`,children:o!==null&&i(`img`,{src:o,alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),e(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[!t.online&&i(F,{variant:`warning`,children:r(`common.off`)}),i(`span`,{className:`truncate text-[10px] text-foreground`,children:a})]})]})}function it({onPick:t}){let{t:r}=K(),a=S(),o=H({isCamera:!0,projection:`slim`}),c=n(()=>(o.data??[]).map(e=>e.id),[o.data]),l=n(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),u=s({queryKey:[...qe,c.length],enabled:c.length>0,queryFn:()=>a.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...c],since:Date.now()-Je,limit:Ye,projection:`slim`})});if(o.isLoading||u.isLoading)return i(b,{className:`h-4 w-4 animate-spin text-foreground-subtle`});let d=u.data?.tracks??[];return d.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`ai.noTracks`,`No track in the last 6 hours.`)}):i(`div`,{className:`max-h-56 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:d.map(n=>e(`button`,{type:`button`,onClick:()=>t(n,l.get(n.deviceId)??String(n.deviceId)),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover`,children:[i(v,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),i(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:n.label??n.className}),i(`span`,{className:`shrink-0 text-foreground-subtle`,children:l.get(n.deviceId)??n.deviceId}),i(`span`,{className:`shrink-0 text-foreground-subtle`,children:new Date(n.lastSeen).toLocaleTimeString()})]},n.trackId))})}c();var at=1440*60*1e3,ot=[1,7,30,90];function st(){let{t}=K(),r=S(),[a,c]=o(7),l=n(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(a-1)*at},[a]),u=M({functionCap:`llm`}),d=s({queryKey:[...ce,a],queryFn:()=>r.trpcClient.llm.getUsage.query({since:l})}),p=n(()=>{let e=new Map;for(let t of u.data??[])e.set(t.id,t.name);return e},[u.data]),m=n(()=>[{key:`day`,header:t(`ai.colDay`,`Day`),nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:e.day})},{key:`consumer`,header:t(`ai.colConsumer`,`Consumer`),nowrap:!0,render:e=>i(`span`,{className:`text-foreground`,children:e.consumer})},{key:`profile`,header:t(`ai.colProfile`,`Profile`),render:e=>i(`span`,{className:`text-foreground`,children:p.get(e.profileId)??e.profileId})},{key:`calls`,header:t(`ai.colCalls`,`Calls`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:String(e.calls)})},{key:`okErr`,header:t(`ai.colOkErr`,`OK / err`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums ${e.errorCalls>0?`text-danger`:``}`,children:`${String(e.okCalls)} / ${String(e.errorCalls)}`})},{key:`tokens`,header:t(`ai.colTokens`,`In / out tok`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:`${String(e.inputTokens)} / ${String(e.outputTokens)}`})},{key:`latency`,header:t(`ai.colAvgMs`,`Avg ms`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:String(Math.round(e.avgLatencyMs))})}],[p,t]),h=d.data??[],g=i(`div`,{className:`w-36`,children:i(C,{"aria-label":t(`ai.window`,`Window`),value:String(a),options:ot.map(e=>({value:String(e),label:t(`ai.lastDays`,`Last {{days}} days`,{days:e})})),onChange:e=>c(Number(e.target.value))})});return i(P,{headingId:`ai-usage-list`,title:t(`ai.usageList`,`Rollup`),actions:g,children:d.isPending?e(`div`,{className:`${f} space-y-2`,"data-testid":`ai-usage-loading`,children:[i(L,{className:`h-8 w-full`}),i(L,{className:`h-8 w-full`}),i(L,{className:`h-8 w-full`})]}):d.isError?i(`div`,{className:f,children:i(R,{title:t(`ai.usageFailed`,`Failed to read usage`),message:d.error instanceof Error?d.error.message:t(`common.error`,`Error`),onRetry:()=>void d.refetch()})}):h.length===0?i(V,{icon:D,title:t(`ai.noUsage`,`No AI calls in this window.`)}):i(N,{columns:m,rows:h,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,maxBodyHeight:I})})}c();var ct=`llm`,lt=[`profiles`,`runtimes`,`usage`,`test`],ut=[`instance`,`instance-new`];function dt(e){return lt.some(t=>t===e)}function ft(){let{t:e}=K(),t=W(ct),[n]=ae(),r=J(`/system/ai`,{t:e,isAdmin:!0})??{icon:x,title:e(`system.ai`,`AI`)};if(t!==`present`)return i(se,{icon:r.icon,title:r.title,children:i(gt,{presence:t})});let a=n.get(`tab`),o=dt(a)?a:`profiles`,s={profiles:e(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),runtimes: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.`),usage: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.`),test:e(`ai.testSubtitle`,`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.`)};return i(Y,{icon:r.icon,title:r.title,subtitle:s[o],defaultSection:`profiles`,sectionsLabel:`${r.title} sections`,sections:[{id:`profiles`,label:e(`ai.tabProfiles`,`Profiles`),content:i(ht,{}),ownedParams:ut},{id:`runtimes`,label:e(`ai.tabRuntimes`,`Runtimes`),content:i(Me,{})},{id:`usage`,label:e(`ai.tabUsage`,`Usage`),content:i(st,{})},{id:`test`,label:e(`ai.tabTest`,`Test`),content:i(Qe,{})}]})}function pt(e,t,n){let r=e.kind===`instance`?t.get(e.id):void 0;return r===void 0?void 0:n(r)}function mt(e,t){let n=t=>pt(t,e,Z)??``,r=t=>pt(t,e,X)??!1,a=t=>pt(t,e,le)??``;return[{key:`model`,header:t(`ai.colModel`,`Model`),sortValue:n,render:e=>i(`span`,{className:`font-mono text-xs text-foreground-muted`,children:n(e)||`—`})},{key:`vision`,header:t(`ai.colVision`,`Vision`),sortValue:e=>+!!r(e),render:e=>r(e)?i(F,{variant:`info`,children:t(`ai.vision`,`vision`)}):null},{key:`node`,header:t(`ai.colNode`,`Node`),sortValue:a,render:e=>i(`span`,{className:`text-xs text-foreground-muted`,children:a(e)||`—`})}]}function ht(){let{t}=K(),r=M({functionCap:ct}),a=n(()=>new Map((r.data??[]).map(e=>[e.id,e])),[r.data]),o=n(()=>mt(a,t),[a,t]);return e(`div`,{className:g,children:[i(ye,{}),i(oe,{functionCap:ct,icon:x,title:t(`ai.profilesList`,`Profiles`),subtitle:t(`ai.profilesTableSubtitle`,`Each profile is one model endpoint; switch one off to keep it without using it.`),emptyTitle:t(`ai.noProfilesTitle`,`No AI profiles yet`),emptyDescription:t(`ai.noProfilesDescription`,`Add a profile to give features a model to talk to.`),addLabel:t(`ai.addProfile`,`Add profile`),extraColumns:o,lead:e=>i(ke,{row:e})})]})}function gt({presence:t}){let{t:n}=K();return t===`pending`?e(`div`,{className:`space-y-3`,"data-testid":`ai-presence-pending`,children:[i(L,{className:`h-8 w-64`}),i(L,{className:`h-40 w-full`})]}):t===`unknown`?i(R,{title:n(`ai.presenceUnknownTitle`,`Could not check whether AI is installed`),message:n(`ai.presenceUnknown`,`The hub did not answer the capability check. Reload the page to try again.`)}):i(V,{icon:x,title:n(`ai.absentTitle`,`AI is not installed`),description:n(`ai.absentDescription`,`Install the AI addon from System → Addons to add model profiles.`)})}export{ft as AiProfilesPage,ft as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Dt as d,Ei as f,Et as p,Ga as m,Jt as h,Pi as g,Q as _,Qr as v,Qt as y,Vn as b,Vr as x,Wi as S,Xn as C,Y as w,Yr as T,Z as E,Zr as D,_i as ee,bt as O,ct as k,en as A,eo as j,ft as M,gn as N,hn as P,ji as F,la as te,li as I,ma as L,mn as ne,nn as re,no as ie,or as ae,ot as R,ri as z,sa as oe,t as se,to as B,un as ce,ut as le,ya as ue,z as de,zr as fe}from"./player-overlays-KBeT29r4.js";import{Dl as pe,Gc as V,Kc as me,Si as he,yt as ge}from"./src-BL8KgH_H.js";import{t as _e}from"./chevron-down-CBb-F8DT.js";import{g as ve}from"./terminal-BncJ-1sF.js";import{n as ye,r as be,t as H}from"./scissors-DpiKUioV.js";import{t as xe}from"./square-check-big-DAcFGNUN.js";import{$u as Se,Af as Ce,Ai as we,Ap as Te,Ar as Ee,Ca as De,Cp as U,Cu as Oe,Df as ke,Dr as Ae,Du as je,Ef as Me,Eu as Ne,Ff as Pe,Fr as Fe,Gr as Ie,Hp as Le,Hr as Re,Ia as W,Ir as ze,It as Be,Jd as Ve,Ji as He,Kr as Ue,Mf as We,Mp as Ge,Nf as Ke,Np as qe,Nr as Je,Of as Ye,Pa as G,Pf as Xe,Pp as Ze,Su as Qe,Tf as $e,Tp as K,Tu as et,Ui as tt,Uu as nt,Xd as rt,Xi as it,Yd as at,Yi as ot,Zi as st,_u as ct,au as lt,bu as ut,ca as dt,cm as ft,d as pt,da as mt,di as ht,ea as gt,fi as _t,gu as vt,ha as yt,ic as bt,id as xt,jf as St,jp as Ct,kf as wt,la as Tt,mi as Et,na as Dt,oa as Ot,pi as kt,qd as At,qu as jt,rm as Mt,sa as Nt,ta as Pt,tt as Ft,ua as It,vp as Lt,vr as Rt,vu as zt,wf as Bt,wp as Vt,wu as Ht,xu as Ut,yo as Wt,yp as Gt,yu as Kt}from"./src-FszuUAOe.js";import{r as qt,t as Jt}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-BPba2g2p.js";import{t as q}from"./i18n-CkHf1ol7.js";import{t as J}from"./useTranslation-BJr-n0es.js";import"./mount-OGGUkOts.js";import{Ai as Yt,B as Xt,Ci as Zt,Ei as Qt,Mi as $t,Ni as en,Oi as tn,Si as nn,Ti as rn,V as an,ji as on,ki as sn,w as cn}from"./index-PErHbELp.js";import{t as ln}from"./AdminSectionedPage-Cx1I8W-T.js";import{a as un,d as dn,f as fn,i as pn,m as mn,n as hn,o as gn,p as _n,r as vn,s as yn,t as bn,u as xn}from"./NewExportModal-kUxB58Tr.js";import{a as Sn,i as Cn,r as wn,t as Tn}from"./authed-media-BWbcdqJS.js";import{t as Y}from"./format-size-DIxKXxtj.js";import{a as En,i as Dn,n as On,o as kn,r as An,s as jn,t as Mn}from"./StorageLocationsTable-CshKJzd9.js";c();var Nn={info:0,warning:1,critical:2},Pn={"motion-without-detections":`motion`,"detections-under-floor":`detection`,"inference-too-slow":`detection`,"frames-shed":`detection`,"inference-device-unusable":`detection`};function Fn(e){return{id:`op:${e.id}`,at:e.at,source:`operation`,severity:`info`,fn:e.domain===`recording`?`recording`:`events`,deviceId:e.deviceId,title:`${e.op} · ${e.reason}`,detail:e.detail}}function In(e,t){return{id:`finding:${e.id}`,at:t,source:`finding`,severity:e.severity,fn:Pn[e.kind],deviceId:e.subject.type===`camera`?e.subject.deviceId:null,title:e.what,detail:e.action}}function Ln(e,t){return e.filter(e=>t.deviceId===null||e.deviceId===t.deviceId).filter(e=>t.fn===null||e.fn===t.fn).filter(e=>t.minSeverity===null||Nn[e.severity]>=Nn[t.minSeverity]).toSorted((e,t)=>t.at-e.at)}var Rn=``,zn=[`recording`,`events`,`detection`,`motion`],Bn=[`info`,`warning`,`critical`];function Vn({data:t,deviceId:r}){let{t:a}=J(),s=at({},{refetchOnWindowFocus:!1}),c=Qe({},{refetchOnWindowFocus:!1}),[l,u]=o(Rn),[d,f]=o(Rn),[p,m]=o(Rn),h=n(()=>{let e=[...s.data??[],...c.data??[]].map(Fn),n=t.digestAtMs??0,r=(t.findings??[]).map(e=>In(e,n));return[...e,...r]},[s.data,c.data,t.findings,t.digestAtMs]),g=n(()=>({deviceId:r??(l===Rn?null:Number(l)),fn:zn.find(e=>e===d)??null,minSeverity:Bn.find(e=>e===p)??null}),[r,l,d,p]),_=n(()=>Ln(h,g),[h,g]),v=n(()=>new Map(t.cameras.map(e=>[e.id,e.name])),[t.cameras]),y=[];s.isError&&y.push(a(`archive.activity.footageLog`,`footage`)),c.isError&&y.push(a(`archive.activity.eventLog`,`event`));let b=n(()=>[{key:`at`,header:a(`archive.activity.when`,`When`),nowrap:!0,sortValue:e=>e.at,render:e=>i(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.at===0?`—`:new Date(e.at).toLocaleString()})},{key:`severity`,header:a(`archive.activity.severity`,`Severity`),nowrap:!0,sortValue:e=>e.severity,render:e=>i(`span`,{className:Hn[e.severity],children:a(`archive.severity.${e.severity}`,e.severity)})},{key:`camera`,header:a(`archive.activity.camera`,`Camera`),sortValue:e=>e.deviceId===null?``:v.get(e.deviceId)??`#${String(e.deviceId)}`,render:e=>i(`span`,{className:`text-foreground`,children:e.deviceId===null?a(`archive.activity.cluster`,`Cluster`):v.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`what`,header:a(`archive.activity.what`,`What`),render:t=>e(`div`,{className:`flex flex-col`,children:[i(`span`,{className:`text-foreground`,children:t.title}),t.detail!==null&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:t.detail})]})}],[a,v]);return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`archive-activity`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r===void 0&&e(M,{wrapperClassName:`inline-block w-auto`,value:l,onChange:e=>u(e.target.value),"aria-label":a(`archive.activity.filterCamera`,`Camera`),children:[i(`option`,{value:Rn,children:a(`archive.activity.allCameras`,`All cameras`)}),t.cameras.map(e=>i(`option`,{value:String(e.id),children:e.name},e.id))]}),e(M,{wrapperClassName:`inline-block w-auto`,value:d,onChange:e=>f(e.target.value),"aria-label":a(`archive.activity.filterFunction`,`Function`),children:[i(`option`,{value:Rn,children:a(`archive.activity.allFunctions`,`All functions`)}),zn.map(e=>i(`option`,{value:e,children:a(`archive.function.${e}`,e)},e))]}),e(M,{wrapperClassName:`inline-block w-auto`,value:p,onChange:e=>m(e.target.value),"aria-label":a(`archive.activity.filterSeverity`,`Severity`),children:[i(`option`,{value:Rn,children:a(`archive.activity.allSeverities`,`Any severity`)}),Bn.map(e=>i(`option`,{value:e,children:a(`archive.activity.atLeast`,`At least {{severity}}`,{severity:a(`archive.severity.${e}`,e)})},e))]})]}),y.length>0&&i(G,{variant:`warning`,message:a(`archive.activity.logUnread`,`The {{names}} log did not answer. This is not "nothing happened".`,{names:y.join(` / `)})}),_.length===0&&y.length===0?i(yt,{icon:j,title:a(`archive.activity.none`,`No activity`),description:a(`archive.activity.noneHint`,`Pruning, deletion and health findings show up here.`)}):i(Ie,{columns:b,rows:_,rowKey:e=>e.id,minWidthPx:640,maxBodyHeight:Ue,pageSize:25})]})}var Hn={info:`text-foreground-subtle`,warning:`text-warning`,critical:`text-danger`},Un={recording:`recording`,motion:null,detection:`object-detection`,"event-media":`event-saving`},Wn={"motion-without-detections":`motion`,"detections-under-floor":`detection`,"inference-too-slow":`detection`,"frames-shed":`detection`,"inference-device-unusable":null},Gn={recording:`recording`,motion:null,detection:`detection`,"event-media":null},Kn=[`recording`,`motion`,`detection`,`event-media`];function qn(e,t){switch(e){case`recording`:return t.recording===null?null:t.recording.active?`ok`:`warning`;case`motion`:return t.motion===null?null:t.motion.enabled?`ok`:`off`;case`detection`:return t.detection===null?null:`ok`;case`event-media`:return`ok`}}function Jn(e){return e.some(e=>e.severity===`critical`)?`critical`:e.some(e=>e.severity===`warning`)?`warning`:`ok`}function Yn(e,t){return Kn.map(n=>{let r=t.filter(e=>Wn[e.kind]===n);if(e===void 0)return{fn:n,state:r.length>0?Jn(r):`unknown`,findings:r};let i=Un[n];if(i!==null&&e.switchedOff.includes(i))return{fn:n,state:`off`,findings:r};let a=Gn[n];return a!==null&&e.degraded.some(e=>e.stage===a)?{fn:n,state:r.length>0?Jn(r):`unknown`,findings:r}:r.length>0?{fn:n,state:Jn(r),findings:r}:n===`recording`&&e.recording?.mode===`off`?{fn:n,state:`off`,findings:r}:{fn:n,state:qn(n,e)??`unknown`,findings:r}})}var Xn=`recording`;function Zn(e,t){return(e??[]).filter(e=>e.subject.type===`camera`&&e.subject.deviceId===t)}function Qn(e){return e.filter(e=>e.severity!==`info`).length}function $n(e,t){return e===void 0?`unknown`:e.switchedOff.includes(Xn)||e.recording?.mode===`off`?`off`:e.degraded.some(e=>e.stage===`recording`||e.stage===`switches`)||e.recording===null?`unknown`:t>0||!e.recording.active?`degraded`:`recording`}function er(e){let t=new Map((e.footage??[]).map(e=>[e.deviceId,e])),n=new Map((e.events??[]).map(e=>[e.deviceId,e])),r=new Map((e.statuses??[]).map(e=>[e.deviceId,e]));return e.cameras.map(i=>{let a=Qn(Zn(e.findings,i.id)),o=r.get(i.id),s=t.get(i.id),c=n.get(i.id);return{deviceId:i.id,name:i.name,mode:o?.recording?.mode??null,state:$n(o,a),warnings:a,footageBytes:e.footage===null?null:s?.usedBytes??0,oldestMs:s?.oldestMs??null,eventRows:e.events===null?null:c?.rows??0,eventBytes:e.events===null?null:c?.bytes??0}})}function tr(e){let t=t=>e.filter(e=>e.state===t).length;return{recording:t(`recording`),degraded:t(`degraded`),off:t(`off`),unknown:t(`unknown`),warnings:e.reduce((e,t)=>e+t.warnings,0)}}var nr={ok:`success`,off:`default`,warning:`warning`,critical:`danger`,unknown:`default`};function rr(e,t){return e.statuses?.find(e=>e.deviceId===t)}function ir({data:t,deviceId:n}){let{t:r}=J(),a=Yn(rr(t,n),Zn(t.findings,n));return e(`div`,{className:`flex flex-col gap-4`,"data-testid":`archive-health`,children:[t.findings===null&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`archive.health.noDigest`,`The health digest has not run yet — findings are not available.`)}),i(`ul`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border bg-surface`,children:a.map(t=>e(`li`,{className:`flex flex-col gap-1 p-3`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:r(`archive.function.${t.fn}`,t.fn)}),i(W,{variant:nr[t.state],children:r(`archive.functionState.${t.state}`,t.state)})]}),t.findings.map(t=>e(`div`,{className:`text-[11px] text-foreground-subtle`,children:[i(`span`,{className:`text-foreground`,children:t.what}),` — `,t.action]},t.id))]},t.fn))}),e(`div`,{className:`flex flex-col gap-2`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:r(`archive.health.logs`,`Camera log`)}),i(Zt,{className:`text-xs text-primary hover:underline`,to:`/system/logs?deviceId=${String(n)}`,children:r(`archive.health.openLogs`,`Open in Logs`)})]}),i(`div`,{className:`overflow-hidden rounded-lg border border-border bg-surface`,children:i(Rt,{deviceId:n,limit:100,maxHeight:`max-h-80`,showFilters:!0})})]})]})}qt();function ar(e){let t=e.subLabel??e.label;if(t!==void 0)return t;let n=e.audioLabels?.[0]?.label;return n!==void 0&&n.length>0?n:void 0}var or=720*60*60*1e3;function sr(e){let t=[];for(let n of e)t.push(...n);return t}function cr(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function lr(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function ur(e,t){return`${String(e)}:${t}`}function dr(e,t){let n=new Map,r=new Set;for(let i of e){let e=ur(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function fr(e,t){return{since:e.fromMs??t-or,until:e.toMs??t}}var pr=typeof ct==`function`,mr=`Track deletion arrives with the next server update`;function hr(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var gr=pr?ct:hr;c();var _r=3e4,vr=[];function yr(e){let t=O(),r=e.deviceIds.length>0,i=[...e.deviceIds].sort((e,t)=>e-t),{data:a,isLoading:o}=s({queryKey:[`events-feed`,i,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:r,staleTime:_r,refetchInterval:_r,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:i,since:e.since,until:e.until,limit:200,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>e.events.map(t=>({...t,deviceId:e.deviceId})))});return{rows:n(()=>cr(sr(a??vr),`importance`),[a]),isLoading:r&&o}}c();var br=[`events-feed`],xr=2e3;function Sr(e){let n=l(),i=e?.paused===!0,s=t(n);s.current=n;let c=t(i);c.current=i;let[u,d]=o(!1),f=r(()=>{s.current.invalidateQueries({queryKey:br})},[]),p=t(void 0);p.current||=mn({delayMs:xr,invalidate:()=>{c.current?d(!0):f()}}),a(()=>()=>p.current?.cancel(),[]),a(()=>{i||!u||(d(!1),f())},[i,u,f]);let m=r(()=>{d(!1),f()},[f]);return ft(pe.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),ft(pe.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:u,refreshNow:m}}c();function Cr(e){let t=new Map;for(let n of e)t.set(n,(t.get(n)??0)+1);return[...t.entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0])).map(([e])=>e)}function wr({classes:e,hidden:t,onChange:r}){let{t:a}=J(),o=n(()=>Cr(e).map(e=>({id:e,label:e})),[e]);return o.length<2?null:i(Ee,{chips:o,off:t,onChange:r,allLabel:a(`detectionIntelligence.eventClassChips.all`,`All classes`),ariaLabel:a(`detectionIntelligence.eventClassChips.label`,`Classes`),testId:`event-class-chips`})}var Tr=[0,1,2],Er=`camstack.archive.eventRowSize`,Dr={0:`w-[72px]`,1:`w-28`,2:`w-40`};function Or(e){return e===1||e===2?e:0}c();function kr({groups:t,selected:r,onChange:a,loading:s=!1}){let{t:c}=J(),l=Ae(),[u,d]=o(!1),[f,p]=o(``),[m,h]=o(new Set),g=f.trim().toLowerCase(),_=e=>g.length===0||U(e,c).toLowerCase().includes(g),v=n(()=>t.map(e=>({macro:e.macro,subs:e.subs.filter(t=>_(t)||_(e.macro))})).filter(e=>_(e.macro)||e.subs.length>0),[t,g]),y=e=>h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),x=e=>{let t=new Set(r),n=r.has(e.macro.kind)&&e.subs.every(e=>r.has(e.kind)),i=[e.macro.kind,...e.subs.map(e=>e.kind)];if(n)for(let e of i)t.delete(e);else for(let e of i)t.add(e);a(t)},S=e=>{let t=new Set(r);t.has(e)?t.delete(e):t.add(e),a(t)},C=()=>a(new Set),w=r.size;return e(`div`,{className:`relative`,children:[e(K,{variant:`unstyled`,type:`button`,onClick:()=>d(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${w>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[i(ce,{className:`h-3.5 w-3.5`}),w>0?c(`detectionIntelligence.eventKindFilter.kinds`,`Kinds ({{value1}})`,{value1:String(w)}):c(`detectionIntelligence.eventKindFilter.kinds2`,`Kinds`),i(_e,{className:`h-3 w-3`})]}),u&&e(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[e(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[i(b,{className:`h-3.5 w-3.5 text-foreground-subtle`}),i(qe,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:c(`detectionIntelligence.eventKindFilter.searchKinds`,`Search kinds…`),className:`w-full bg-transparent py-1 text-xs outline-none`}),w>0&&i(K,{variant:`unstyled`,type:`button`,onClick:C,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:c(`detectionIntelligence.eventKindFilter.clear`,`Clear`)})]}),v.length===0&&i(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:s?c(`detectionIntelligence.eventKindFilter.loadingKinds`,`Loading kinds…`):g.length>0?c(`detectionIntelligence.eventKindFilter.noKindMatchesThatSearch`,`No kind matches that search.`):c(`detectionIntelligence.eventKindFilter.theseCamerasAdvertiseNoEvent`,`These cameras advertise no event kinds.`)}),v.map(t=>{let n=Vt(t.macro.iconId),a=m.has(t.macro.kind)||g.length>0,o=r.has(t.macro.kind);return e(`div`,{className:`mb-0.5`,children:[e(`div`,{className:`flex items-center gap-1`,children:[t.subs.length>0?i(K,{variant:`unstyled`,type:`button`,onClick:()=>y(t.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":c(`detectionIntelligence.eventKindFilter.expand`,`Expand`),children:i(a?_e:oe,{className:`h-3 w-3`})}):i(`span`,{className:`w-3`}),e(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[i(B,{checked:o,onChange:()=>x(t),className:`accent-primary`}),i(n,{className:`h-3.5 w-3.5`,style:{color:l(t.macro.kind)}}),i(`span`,{className:`font-medium`,children:U(t.macro,c)})]})]}),a&&t.subs.map(t=>{let n=Vt(t.iconId);return e(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[i(B,{checked:r.has(t.kind),onChange:()=>S(t.kind),className:`accent-primary`}),i(n,{className:`h-3.5 w-3.5`,style:{color:l(t.kind)}}),i(`span`,{children:U(t,c)})]},t.kind)})]},t.macro.kind)})]})]})}function Ar(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function jr(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var Mr=new Set([`detection`,`package`]);function Nr(e,t){return[...Ar(e,t).values()].filter(e=>e.parentKind===null&&Mr.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function Pr(e,t){let n=Ar(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,jr(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}c();var Fr=1400,Ir=`Admin-gated URL — opens only inside an authenticated session`;function Lr({label:t,value:n,title:s}){let{t:c}=J(),[l,u]=o(!1),d=le();return a(()=>{if(!l)return;let e=setTimeout(()=>u(!1),Fr);return()=>clearTimeout(e)},[l]),e(K,{variant:`unstyled`,type:`button`,onClick:r(()=>{(async()=>{try{await navigator.clipboard.writeText(n),u(!0)}catch{await d({title:c(`detectionIntelligence.copyUrlChips.copyTheMediaUrl`,`Copy the media URL`),message:c(`detectionIntelligence.copyUrlChips.clipboardAccessWasRefusedSelect`,`Clipboard access was refused. Select the URL below and copy it manually.`),label:c(`detectionIntelligence.copyUrlChips.url`,`{{label}} URL`,{label:t}),defaultValue:n,readOnly:!0,cancelLabel:c(`common.close`,`Close`)})}})()},[n,t,d,c]),title:s,"aria-label":c(`detectionIntelligence.copyUrlChips.copyUrl`,`Copy {{label}} URL`,{label:t}),className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${l?`border-success/40 bg-success/10 text-success`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[i(l?te:g,{className:`h-2.5 w-2.5 shrink-0`}),i(`span`,{className:`truncate`,children:l?c(`detectionIntelligence.copyUrlChips.copied`,`Copied`):t})]})}function Rr({localUrl:t,publicUrl:n}){let{t:r}=J();return e(`div`,{className:`flex flex-wrap gap-1`,children:[i(Lr,{label:r(`detectionIntelligence.copyUrlChips.local`,`Local`),value:t,title:r(`detectionIntelligence.copyUrlChips.copyLanUrl`,`Copy LAN URL — {{AUTH_HINT}}`,{AUTH_HINT:Ir})}),n&&i(Lr,{label:r(`detectionIntelligence.copyUrlChips.public`,`Public`),value:n,title:r(`detectionIntelligence.copyUrlChips.copyPublicUrl`,`Copy public URL — {{AUTH_HINT}}`,{AUTH_HINT:Ir})})]})}var zr={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`,confirmationCrop:`Confirmation crop (what the gate saw)`,debugCrop:`Debug crop (why this decision)`,sceneFrame:`Scene frame (clean)`,lastSceneFrame:`Last frame (clean)`};function Br(e){return e in zr}function Vr(e){return Br(e)?zr[e]:e}function Hr(e,t){return`${e}${t}`}var Ur=[`native`,`raster`,`standin`];function Wr(e){return Ur.some(t=>t===e)}function Gr(e){return e===`standin`?{label:q.t(`helpers.mediaProvenance.standin.label`),title:q.t(`helpers.mediaProvenance.standin.title`),tone:`warning`}:{label:q.t(`helpers.mediaProvenance.raster.label`),title:q.t(`helpers.mediaProvenance.raster.title`),tone:`info`}}function Kr(e){return e===`standin`?Gr(`standin`):e===`raster`?Gr(`raster`):null}var qr={"no-key-frame":`helpers.mediaProvenance.miss.noKeyFrame`,"no-best-seen-bbox":`helpers.mediaProvenance.miss.noBestSeenBbox`,"derive-returned-null":`helpers.mediaProvenance.miss.deriveReturnedNull`,"derive-threw":`helpers.mediaProvenance.miss.deriveThrew`,"derive-not-wired":`helpers.mediaProvenance.miss.deriveNotWired`,"no-media-store":`helpers.mediaProvenance.miss.noMediaStore`,"no-thumbnail":`helpers.mediaProvenance.miss.noThumbnail`,"standin-tile":`helpers.mediaProvenance.miss.standinTile`,"raster-tile":`helpers.mediaProvenance.miss.rasterTile`,"native-tile":`helpers.mediaProvenance.miss.nativeTile`};function Jr(e){if(e===void 0)return null;let t=e.trim();if(t.length===0)return null;let n=t.split(/\s+/),r=n[0]??t,i=[];for(let e of n.slice(1)){let t=e.indexOf(`=`);t===-1?i.push({key:e,value:null}):i.push({key:e.slice(0,t),value:e.slice(t+1)})}let a=qr[r];return{sentence:a===void 0?r:q.t(a),detail:i,raw:t}}c();var Yr=3e4;function Xr(e){let[t,n]=o(null),s=r(e=>{n(t=>t??e)},[]);return a(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?i(Zr,{onOrigin:s}):null}}function Zr({onOrigin:e}){let{data:t}=Wt({capName:`network-access`});return i(u,{children:(t??[]).map(t=>i(Qr,{addonId:t.addonId,onOrigin:e},t.addonId))})}function Qr({addonId:e,onOrigin:t}){let{data:n}=lt({addonId:e},{refetchInterval:Yr,retry:!1});return a(()=>{let e=n?he.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var $r=typeof je==`function`,ei=`Track flags arrive with the next server update`;function ti(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var ni=$r?je:ti;function ri(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e)||!(`favourited`in e))return null;let{trackId:t,markForTrain:n,debug:r,favourited:i}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`||typeof i!=`boolean`?null:{trackId:t,markForTrain:n,debug:r,favourited:i}}c();function ii({label:t,hint:n,checked:r,disabled:a,title:o,icon:s,onToggle:c}){return e(K,{variant:`unstyled`,type:`button`,role:`switch`,"aria-checked":r,"aria-label":t,disabled:a,title:o,onClick:c,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${r?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[i(`span`,{className:r?`text-primary`:`text-foreground-subtle`,children:s}),e(`span`,{className:`min-w-0 flex-1`,children:[i(`span`,{className:`block text-[11px] font-medium text-foreground`,children:t}),i(`span`,{className:`block text-[10px] text-foreground-subtle`,children:n})]}),i(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${r?`bg-primary`:`bg-border`}`,children:i(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${r?`translate-x-3`:``}`})})]})}function ai({deviceId:t,trackId:n,markForTrain:r,debug:a,favourited:s,onChange:c}){let{t:l}=J(),u=ni(),d=R(),[f,p]=o(null),m=f?.markForTrain??r===!0,h=f?.debug??a===!0,g=f?.favourited??s===!0,_=!$r||u.isPending,v=$r?void 0:ei,y=e=>{_||(async()=>{try{let r=ri(await u.mutateAsync({deviceId:t,trackId:n,flags:e}));if(!r)return;p(r),c?.(r)}catch(e){let t=e instanceof Error?e.message:``;await d({title:l(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack`,`Could not update this track`),message:t===``?l(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack2`,`Could not update this track. Check the server logs.`):t,variant:`danger`})}})()};return e(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[i(ii,{label:l(`detectionIntelligence.trackFlagToggles.markForTraining`,`Mark for training`),hint:l(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:m,disabled:_,...v===void 0?{}:{title:v},icon:i(I,{className:`h-4 w-4`}),onToggle:()=>y({markForTrain:!m})}),i(ii,{label:l(`detectionIntelligence.trackFlagToggles.debug`,`Debug`),hint:l(`detectionIntelligence.trackFlagToggles.flagThisTrackForDiagnostic`,`Flag this track for diagnostic attention`),checked:h,disabled:_,...v===void 0?{}:{title:v},icon:i(ue,{className:`h-4 w-4`}),onToggle:()=>y({debug:!h})}),i(ii,{label:l(`detectionIntelligence.trackFlagToggles.favourited`,`Favourited`),hint:l(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:g,disabled:_,...v===void 0?{}:{title:v},icon:i(ne,{className:`h-4 w-4`}),onToggle:()=>y({favourited:!g})})]})}function oi(e){let t=e.deviceKey===void 0?e.nodeId:`${e.nodeId} · ${e.deviceKey}`;return e.modelId===void 0?t:`${t} (${e.modelId})`}function si(e){let t=e?.openedPlacement,n=e?.closedPlacement;if(t!==void 0&&n!==void 0){let e=oi(t),r=oi(n);return e===r?[{kind:`detected`,value:e}]:[{kind:`opened`,value:e},{kind:`closed`,value:r}]}return t===void 0?n===void 0?[]:[{kind:`closed`,value:oi(n)}]:[{kind:`opened`,value:oi(t)}]}var ci=100,li={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},ui=e=>e<0?0:e>1?1:e,di=e=>Math.round(e*100)/100;function fi(e,t,n){if(e.length===0||t===null)return li;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return li;let a=ge(e.map(e=>({x:e.x/r,y:e.y/i,w:e.bbox.w/r,h:e.bbox.h/i})),n?.maxPoints===void 0?void 0:{maxPoints:n.maxPoints}).nodes.map(e=>({x:di(e.x*ci),y:di(e.y*ci)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:di(ui(e.x/r)*ci),y:di(ui(e.y/i)*ci),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=ui(t.bbox.w/r)*ui(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:di(ui(u.bbox.x/r)*ci),y:di(ui(u.bbox.y/i)*ci),w:di(ui(u.bbox.w/r)*ci),h:di(ui(u.bbox.h/i)*ci)}:null}}c();var pi=15e3,mi=E();function hi({url:e,label:t}){let{src:n,failed:r}=Sn(e);return n===null?i(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?i(v,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):i(x,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):i(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var gi=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),_i=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function vi(e){let[t,n]=o(null);return a(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function yi({overlay:t,onPickSnapshot:n}){let{t:r}=J();return!t.polyline&&!t.peakBox&&t.snapshots.length===0?null:e(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[t.peakBox&&i(`rect`,{x:t.peakBox.x,y:t.peakBox.y,width:t.peakBox.w,height:t.peakBox.h,fill:`none`,stroke:`var(--color-warning)`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),t.polyline&&i(`polyline`,{points:t.polyline,fill:`none`,stroke:`var(--color-info)`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),t.points.map((e,t)=>i(`circle`,{cx:e.x,cy:e.y,r:1,fill:`var(--color-info)`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),t.snapshots.map((e,t)=>i(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`var(--color-info)`,fillOpacity:.95,stroke:`var(--color-background)`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:n?`pointer-events-auto cursor-pointer`:void 0,onClick:n?t=>{t.stopPropagation(),n(e.mediaId)}:void 0,children:i(`title`,{children:r(`detectionIntelligence.eventDetailPanel.snapshotCheckpointClickToView`,`Snapshot checkpoint — click to view this frame`)})},`snap-${String(e.mediaId)}-${String(t)}`)),t.start&&i(`circle`,{cx:t.start.x,cy:t.start.y,r:2.4,fill:`var(--color-success)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),t.end&&i(`circle`,{cx:t.end.x,cy:t.end.y,r:2.4,fill:`var(--color-danger)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function X({label:t,value:n,mono:r,wrap:a}){return e(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[i(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),i(`span`,{className:`min-w-0 ${a?`break-words`:`truncate`} text-right text-xs font-medium text-foreground ${r?`font-mono text-[11px]`:``}`,title:n,children:n})]})}function bi({row:t,cameraName:s,deleteAvailable:c,onClose:l,onDeleted:d,onFlagsChanged:f}){let{t:p}=J(),m=O(),h=R(),g=k(),_=gr(),y=t!==null,b=t?.deviceId??0,S=t?.trackId??``,C=t?.timestamp??0,w=t?.windowMs??0,{data:T}=Kt({deviceId:b,trackId:S},{enabled:y}),{data:E}=Oe({trackId:S,deviceId:b},{enabled:y}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:A}=Ut({ownerType:`object`,eventId:D??0,deviceId:b},{enabled:y&&D!==void 0&&Number.isFinite(D)}),{data:j}=Gt({deviceId:b},{enabled:y}),M=(j??[]).find(e=>e.addonId!==void 0)?.addonId,{data:N}=Lt({deviceId:b,since:C-pi,until:C+w+pi,provider:M??``},{enabled:y&&M!==void 0}),[P,F]=o(null),[te,I]=o(!1),{publicOrigin:L,probes:ne}=Xr(y);a(()=>{F(null)},[b,S]);let ie=n(()=>{let e=E??[],t=A??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,A]),ae=P??ie,z=Sn(ae?ae.url:void 0),oe=n(()=>{let e=new Set,t=[];for(let n of[...A??[],...E??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[A,E]),se=n(()=>oe.find(e=>gi.has(e.kind))??null,[oe]),B=vi(Sn(se?se.url:void 0).src),ce=n(()=>fi(T?.positions??[],B,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,B]),le=r(e=>{let t=oe.find(t=>t.mediaId===e);t&&F(t)},[oe]);if(t===null)return null;let ue=z.src,de=ae?.kind,fe=de!==void 0&&_i.has(de)&&B!==null&&(T?.positions.length??0)>=2,pe=N&&N.length>0?N[0]:null,V=()=>{pe&&(I(!0),(async()=>{try{let e=await m.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:pe.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{h({title:p(`detectionIntelligence.eventDetailPanel.clipUnavailable`,`Clip unavailable`),message:p(`detectionIntelligence.eventDetailPanel.couldNotResolveClipPlayback`,`Could not resolve clip playback. Check the server logs.`),variant:`warning`})}finally{I(!1)}})())},me=()=>{!c||_.isPending||(async()=>{if(await g({title:p(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`),message:p(`detectionIntelligence.eventDetailPanel.deleteThisTrackAndEvery`,`Delete this track and every image and clip captured for it? This cannot be undone.`),confirmLabel:p(`common.delete`,`Delete`),variant:`danger`}))try{await _.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),d()}catch{await h({title:p(`detectionIntelligence.eventDetailPanel.deleteFailed`,`Delete failed`),message:p(`detectionIntelligence.eventDetailPanel.failedToDeleteThisTrack`,`Failed to delete this track. Check the server logs.`),variant:`danger`})}})()},he=Math.round(t.importance*100),ge=T?.importanceReason?`${String(he)}% · ${T.importanceReason}`:`${String(he)}%`,_e=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,ve=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,ye=ve===void 0?`—`:ve.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),be=T?T.totalDistance.toFixed(2):`—`,H=Jr(T?.previewMissReason),xe=fn(T?T.firstSeen:C),Se=T?fn(T.lastSeen):`—`,Ce=si(T),we={detected:p(`detectionIntelligence.eventDetailPanel.detectedOn`,`Detected on`),opened:p(`detectionIntelligence.eventDetailPanel.openedOn`,`Opened on`),closed:p(`detectionIntelligence.eventDetailPanel.closedOn`,`Closed on`)};return i(ot,{open:!0,onOpenChange:e=>!e&&l(),children:e(st,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":p(`detectionIntelligence.eventDetailPanel.eventDetail`,`Event detail`),className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[i(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,ar(t)?e(`span`,{className:`text-foreground-subtle`,children:[` · `,ar(t)]}):null]}),i(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:s})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[ue?i(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:i(pn,{src:ue,alt:p(`detectionIntelligence.eventDetailPanel.keyFrameFrom`,`Key frame from {{cameraName}}`,{cameraName:s}),fit:`natural`,className:`w-full`,overlay:fe?i(yi,{overlay:ce,onPickSnapshot:le}):void 0})}):i(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:z.failed?e(u,{children:[i(v,{className:`h-8 w-8 opacity-60`}),i(`span`,{className:`text-[11px]`,children:p(`detectionIntelligence.eventDetailPanel.keyFrameMediaUnavailable`,`Key-frame media unavailable`)})]}):i(x,{className:`h-6 w-6 animate-spin opacity-70`})}),oe.length>0&&i(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:oe.map(t=>{let n=Vr(t.kind),r=Hr(mi,t.url),a=L?Hr(L,t.url):null;return e(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[i(K,{variant:`unstyled`,type:`button`,onClick:()=>F(t),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${fn(t.timestamp)}`,children:i(hi,{url:t.url,label:n})}),e(`figcaption`,{className:`min-w-0 px-0.5`,children:[i(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),i(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:fn(t.timestamp),children:xn(t.timestamp)})]}),i(Rr,{localUrl:r,publicUrl:a})]},t.mediaId)})}),ne,pe&&e(K,{variant:`secondary`,onClick:V,disabled:te,children:[te?i(x,{className:`h-3.5 w-3.5 animate-spin`}):i(ee,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.viewClip`,`View clip`)]}),i(ai,{deviceId:t.deviceId,trackId:t.trackId,...(T?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??t.markForTrain},...(T?.debug??t.debug)===void 0?{}:{debug:T?.debug??t.debug},...(T?.favourited??t.favourited)===void 0?{}:{favourited:T?.favourited??t.favourited},onChange:f}),H!==null&&e(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[i(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p(`detectionIntelligence.eventDetailPanel.bestShot`,`Best shot`)}),i(`p`,{className:`mt-0.5 text-xs text-foreground`,children:H.sentence}),i(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:H.raw})]}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[i(X,{label:p(`detectionIntelligence.eventDetailPanel.camera`,`Camera`),value:s}),Ce.map(e=>i(X,{label:we[e.kind],value:e.value,mono:!0,wrap:!0},e.kind)),i(X,{label:p(`detectionIntelligence.eventDetailPanel.class`,`Class`),value:t.className}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.label`,`Label`),value:t.label??`—`}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.subLabel`,`Sub-label`),value:t.subLabel??`—`}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.importance`,`Importance`),value:ge}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.zonesVisited`,`Zones visited`),value:_e}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.audioHeard`,`Audio heard`),value:ye}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.totalDistance`,`Total distance`),value:be}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.firstSeen`,`First seen`),value:xe}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.lastSeen`,`Last seen`),value:Se}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.track`,`Track`),value:t.trackId,mono:!0})]})]}),i(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:i(`span`,{title:c?void 0:mr,children:e(K,{variant:`secondary`,onClick:me,disabled:!c||_.isPending,children:[_.isPending?i(x,{className:`h-3.5 w-3.5 animate-spin`}):i(re,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`)]})})})]})})}function xi(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function Si({row:t,cameraName:n,nowMs:r,onOpenDetail:a,selected:o=!1,onToggleSelect:s,score:c,provenance:l,footer:u}){let{t:d}=J(),f=Sn(t.mediaId===void 0?Cn(`track`,t.trackId):wn(t.mediaId)),p=Math.round(t.importance*100),m=c===void 0?void 0:Math.round(c*100),h=xi(t.windowMs),g=()=>a(t),_=Kr(l);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${o?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[f.src?i(`img`,{src:f.src,alt:d(`detectionIntelligence.eventCard.eventFrom`,`Event from {{cameraName}}`,{cameraName:n}),onClick:g,className:`h-full w-full cursor-zoom-in object-cover`}):i(K,{variant:`unstyled`,type:`button`,onClick:g,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:f.failed?d(`detectionIntelligence.eventCard.keyEventMediaUnavailable`,`Key-event media unavailable`):d(`detectionIntelligence.eventCard.noKeyEventMedia`,`No key-event media`),children:i(v,{className:`h-6 w-6 opacity-60`})}),s&&i(K,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),s(ur(t.deviceId,t.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":o?d(`detectionIntelligence.eventCard.deselect`,`Deselect`):d(`detectionIntelligence.eventCard.select`,`Select`),children:o?i(xe,{className:`h-4 w-4 text-primary`}):i(P,{className:`h-4 w-4`})}),m!==void 0&&e(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:d(`detectionIntelligence.eventCard.clipSemanticMatchScore`,`CLIP semantic-match score`),children:[String(m),`%`]}),p>0&&i(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(p)}),_!==null&&i(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${_.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:_.title,children:_.label}),(t.markForTrain===!0||t.retrainStatus===`trained`||t.debug===!0||t.favourited===!0)&&e(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[t.markForTrain===!0&&i(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.markedForTraining`,`Marked for training`),"aria-label":d(`detectionIntelligence.eventCard.markedForTraining`,`Marked for training`),children:i(I,{className:`h-3 w-3`})}),t.retrainStatus===`trained`&&t.markForTrain!==!0&&i(`span`,{className:`rounded bg-success/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.trainingComplete`,`Training complete`),"aria-label":d(`detectionIntelligence.eventCard.trainingComplete`,`Training complete`),"data-testid":`retrain-status-trained`,children:i(te,{className:`h-3 w-3`})}),t.debug===!0&&i(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.flaggedForDebug`,`Flagged for debug`),"aria-label":d(`detectionIntelligence.eventCard.flaggedForDebug`,`Flagged for debug`),children:i(ue,{className:`h-3 w-3`})}),t.favourited===!0&&i(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.favourited`,`Favourited`),"aria-label":d(`detectionIntelligence.eventCard.favourited`,`Favourited`),children:i(ne,{className:`h-3 w-3`})})]})]}),e(K,{variant:`unstyled`,type:`button`,onClick:g,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[e(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:t.className,children:[t.className,ar(t)?e(`span`,{className:`text-foreground-subtle`,children:[` · `,ar(t)]}):null]}),i(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:n,children:n}),e(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:dn(t.timestamp,r)}),h&&i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:h})]})]}),u!==void 0&&i(`div`,{className:`px-2 pb-1.5`,children:u})]})}function Ci({row:t,onSeek:n,onOpenDetail:r,size:a=0,onToggleSelect:o,selected:s=!1}){let{t:c}=J(),l=Sn(t.mediaId===void 0?Cn(`track`,t.trackId):wn(t.mediaId)),u=Math.round(t.importance*100),d=ar(t),f=new Date(t.timestamp).toLocaleTimeString();return e(`div`,{className:`flex w-full items-center gap-2 rounded-md border bg-surface hover:bg-surface-hover ${s?`border-primary ring-1 ring-primary`:`border-border`}`,"data-testid":`event-row`,children:[o&&i(B,{className:`ml-2 shrink-0`,checked:s,onChange:()=>o(ur(t.deviceId,t.trackId)),"aria-label":c(`detectionIntelligence.eventRow.select`,`Select {{className}} at {{time}}`,{className:t.className,time:f})}),i(K,{variant:`unstyled`,type:`button`,onClick:()=>r(t),className:`aspect-video ${Dr[a]} shrink-0 overflow-hidden rounded-l-md bg-surface-hover`,"aria-label":c(`detectionIntelligence.eventRow.openDetail`,`Open event details`),children:l.src?i(`img`,{src:l.src,alt:``,className:`h-full w-full object-cover`}):i(`span`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:i(v,{className:`h-4 w-4 opacity-60`})})}),e(K,{variant:`unstyled`,type:`button`,onClick:()=>n(t.timestamp),className:`flex min-w-0 flex-1 items-center gap-2 py-1 pr-2 text-left`,"aria-label":c(`detectionIntelligence.eventRow.seek`,`Play {{className}} at {{time}}`,{className:t.className,time:f}),children:[e(`span`,{className:`min-w-0 flex-1`,children:[e(`span`,{className:`block truncate text-[12px] font-medium text-foreground`,children:[t.className,d?e(`span`,{className:`text-foreground-subtle`,children:[` · `,d]}):null]}),i(`span`,{className:`block text-[11px] tabular-nums text-foreground-subtle`,children:f})]}),u>0&&i(`span`,{className:`shrink-0 rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-semibold tabular-nums text-foreground-muted`,children:String(u)})]}),e(`div`,{className:`flex shrink-0 items-center gap-0.5 pr-1`,children:[i(wi,{icon:T,label:c(`detectionIntelligence.eventRow.details`,`Details`),onClick:()=>r(t)}),i(wi,{icon:ae,label:c(`detectionIntelligence.eventRow.play`,`Play`),onClick:()=>n(t.timestamp)})]})]})}function wi({icon:t,label:n,onClick:r}){return e(Te,{children:[i(Ge,{children:i(Ze,{variant:`ghost`,size:`sm`,icon:t,"aria-label":n,onClick:r})}),i(Ct,{children:n})]})}var Ti=120*1e3;function Ei(e,t,n=Ti){let r=[...e].sort((e,n)=>t(n)-t(e)),i=[];for(let e of r){let r=i[i.length-1],a=t(e);r!==void 0&&r.fromMs-a<=n?(r.events.push(e),r.fromMs=a):i.push({fromMs:a,toMs:a,events:[e]})}return i}c();function Di(){let[e,n]=o(!1),i=t(null),[s,c]=o(0),l=r(e=>{i.current!==e&&(i.current=e,c(e=>e+1))},[]);return a(()=>{let e=i.current;if(!e||typeof IntersectionObserver>`u`){n(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&n(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[s]),{ref:l,scrolledPast:e}}c();var Oi=[`events-feed`],ki=60,Ai=[{value:`importance`,labelKey:`detectionIntelligence.eventsSection.sortImportance`,icon:be},{value:`time`,labelKey:`detectionIntelligence.eventsSection.sortRecent`,icon:S}];function ji({deviceId:t,onSeek:r,window:s,rowFilter:c,onListChange:d,layout:f=`cards`,toolbarTarget:m}={}){let{t:h}=J(),g=l(),_=R(),v=k(),[y,b]=o(gn),[S,C]=o(new Set),[w,T]=o(new Set),[E,ee]=o(new Set),[O,A]=Be({storageKey:Er,options:Tr,defaultSize:0}),M=Or(O),[N,P]=o(0),[F,te]=o(`time`),[I,L]=o(new Set),[ne,ae]=o(null),[z,oe]=o(()=>Date.now());a(()=>{let e=setInterval(()=>oe(Date.now()),6e4);return()=>clearInterval(e)},[]);let se=n(()=>fr({fromMs:y.fromMs,toMs:y.toMs},z),[y.fromMs,y.toMs,z]),ce=s?.since??se.since,le=s?.until??se.until,ue=Di(),{pending:de,refreshNow:fe}=Sr({paused:ne!==null||I.size>0||ue.scrolledPast}),{data:pe=[]}=bt({isCamera:!0,projection:`slim`}),V=n(()=>t===void 0?pe:pe.filter(e=>e.id===t),[pe,t]),me=n(()=>V.map(e=>e.id),[V]),{data:he,isLoading:ge}=ut({deviceIds:me},{enabled:me.length>0,staleTime:5*6e4}),_e=n(()=>Pr(he??[],S),[he,S]),ve=gr(),be=ve.isPending,{rows:H,isLoading:xe}=yr({deviceIds:me,since:ce,until:le,minImportance:N>0?N:void 0,classFilter:w.size===1?[...w][0]:void 0}),Se=n(()=>{let e=new Map;for(let t of V??[])e.set(t.id,t.name);return e},[V]),Ce=e=>Se.get(e)??h(`detectionIntelligence.cameraFallback`,{id:String(e)}),we=n(()=>yn(H).map(e=>({id:e,name:Ce(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[H,Se]),Te=n(()=>cr(lr(H,{cameras:S,classes:w,minImportance:N}).filter(e=>!E.has(e.className)&&(c===void 0||c(e))),F),[H,S,w,E,N,F,c]),Ee=n(()=>H.map(e=>e.className),[H]),De=w.size>0||E.size>0||N>0;a(()=>{d?.({rows:Te,narrowed:De})},[Te,De,d]);let U=hn(Te,ki,n(()=>JSON.stringify([[...S].sort((e,t)=>e-t),[...w].sort(),[...E].sort(),N,F,ce,le]),[S,w,E,N,F,ce,le])),Oe=()=>{g.invalidateQueries({queryKey:Oi})},ke=()=>L(new Set),Ae=Te.map(e=>ur(e.deviceId,e.trackId)),je=Ae.length>0&&Ae.every(e=>I.has(e)),Me=()=>L(je?new Set:new Set(Ae));function Ne(e){L(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function Pe(){if(I.size===0||!pr)return;let e=dr(H,I),t=[...e.values()].reduce((e,t)=>e+t.length,0);t!==0&&(async()=>{await v({title:h(`detectionIntelligence.eventsSection.deleteTitle`,{count:t}),message:h(`detectionIntelligence.eventsSection.deleteMessage`,{count:t}),confirmLabel:h(`common.delete`,`Delete`),variant:`danger`})&&Fe(e)})()}function Fe(e){let t=[...e];Promise.allSettled(t.map(([e,t])=>ve.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{Oe();let n=[],r=new Set;if(e.forEach((e,i)=>{let a=t[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add(ur(o,e));else n.push(o)}),L(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),n.length>0){let e=n.map(e=>Ce(e)).join(`, `);_({title:h(`detectionIntelligence.eventsSection.someTracksWereNotDeleted`,`Some tracks were not deleted`),message:h(`detectionIntelligence.eventsSection.failedToDeleteTracksOn`,`Failed to delete tracks on: {{names}}. They remain selected — retry, or check the server logs.`,{names:e}),variant:`danger`})}})}let Ie=n(()=>Ei(U.pageItems,e=>e.timestamp),[U.pageItems]),Le=Te.length!==H.length,Re=t=>i(Si,{row:t,cameraName:Ce(t.deviceId),nowMs:z,selected:I.has(ur(t.deviceId,t.trackId)),onToggleSelect:Ne,onOpenDetail:ae,footer:r===void 0?void 0:e(K,{variant:`ghost`,onClick:()=>r(t.timestamp),children:[i(ye,{className:`h-3.5 w-3.5`}),h(`detectionIntelligence.eventsSection.showInReview`,`Show in Review`)]})},ur(t.deviceId,t.trackId)),W=f===`rows`&&r!==void 0,ze=e=>W?i(Ci,{row:e,onSeek:r,onOpenDetail:ae,size:M,selected:I.has(ur(e.deviceId,e.trackId)),onToggleSelect:Ne},ur(e.deviceId,e.trackId)):Re(e),Ve=e=>W?i(`div`,{className:`flex flex-col gap-1`,"data-testid":`events-grid`,children:e.map(ze)}):i(Ft,{status:`ready`,testId:`events-grid`,children:e.map(ze)}),He=e(`div`,{className:m===void 0?`flex flex-wrap items-center gap-1.5`:`contents`,children:[s===void 0&&i(un,{onChange:b}),t===void 0&&i(_n,{cameras:we,selected:S,onChange:C}),i(kr,{groups:_e,selected:w,onChange:T,loading:ge}),W&&i(wr,{classes:Ee,hidden:E,onChange:ee}),e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(`span`,{children:h(`detectionIntelligence.eventsSection.minScore`,`Min score`)}),i(ie,{min:0,max:1,step:.05,value:N,onChange:e=>P(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":h(`detectionIntelligence.eventsSection.minimumImportance`,`Minimum importance`)}),i(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(N*100)})]}),i(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Ai.map(t=>{let n=t.icon;return e(`button`,{type:`button`,onClick:()=>te(t.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${F===t.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[i(n,{className:`h-3.5 w-3.5`}),` `,h(t.labelKey)]},t.value)})}),!xe&&i(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Le?h(`detectionIntelligence.eventsSection.ofEvents`,`{{value1}} of {{value2}} events`,{value1:String(Te.length),value2:String(H.length)}):h(`detectionIntelligence.eventsSection.eventCount`,{count:Te.length})})]});return e(`div`,{className:`relative space-y-3`,children:[m===void 0?He:m!==null&&Jt(He,m),I.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[i(`span`,{className:`text-xs font-medium text-foreground`,children:h(`common.selectedCount`,{count:I.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[i(`span`,{title:pr?void 0:`Track deletion arrives with the next server update`,children:e(K,{variant:`secondary`,onClick:Pe,disabled:!pr||be,children:[be?i(x,{className:`h-3.5 w-3.5 animate-spin`}):i(re,{className:`h-3.5 w-3.5`}),` `,h(`common.delete`,`Delete`)]})}),i(K,{variant:`ghost`,onClick:ke,disabled:be,children:i(p,{className:`h-3.5 w-3.5`})})]})]}),de&&i(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:i(`button`,{type:`button`,onClick:fe,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:h(`detectionIntelligence.eventsSection.newEventsRefresh`,`New events — refresh`)})}),xe?i(Ft,{status:`pending`,pendingMessage:`Loading events…`,testId:`events-grid`}):Te.length===0?i(yt,{icon:j,title:Le?h(`detectionIntelligence.eventsSection.nothingMatchesTheFilter`,`Nothing matches the filter`):h(`detectionIntelligence.eventsSection.noKeyEventsInThis`,`No key events in this window`),description:Le?h(`detectionIntelligence.eventsSection.widenTheDateRangeClear`,`Widen the date range, clear cameras or kinds, or lower the min score.`):h(`detectionIntelligence.eventsSection.capturedTracksAppearHereWhen`,`Captured tracks appear here when the pipeline scores a key event.`)}):e(u,{children:[i(`div`,{ref:ue.ref,"aria-hidden":!0,className:`h-0`}),W&&e(`div`,{className:`flex flex-wrap items-center gap-3`,children:[e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(B,{checked:je,onChange:Me,"data-testid":`event-rows-select-all`}),i(`span`,{children:h(`detectionIntelligence.eventsSection.selectAll`,`Select all ({{count}})`,{count:Te.length})})]}),e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(D,{className:`h-3.5 w-3.5`}),i(`span`,{children:h(`detectionIntelligence.eventsSection.rowSize`,`Size`)}),i(ie,{min:0,max:Tr.length-1,step:1,value:M,onChange:e=>A(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"data-testid":`event-row-size`,"aria-label":h(`detectionIntelligence.eventsSection.rowSizeLabel`,`Event row size`)})]})]}),!W&&t!==void 0&&F===`time`?Ie.map(t=>e(`div`,{className:`space-y-1.5`,children:[i(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:h(`detectionIntelligence.eventsSection.clusterHeading`,{count:t.events.length,time:new Date(t.toMs).toLocaleString()})}),Ve(t.events)]},t.toMs)):Ve(U.pageItems),i(vn,{currentPage:U.page,totalItems:U.totalItems,pageSize:U.pageSize,onPageChange:U.setPage,itemNoun:`events`})]}),ne&&i(bi,{row:ne,cameraName:Ce(ne.deviceId),deleteAvailable:pr,onClose:()=>ae(null),onDeleted:()=>{Oe(),ae(null)},onFlagsChanged:e=>{ae(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}var Mi={zone:null,identity:`any`,debug:!1};function Ni(e){return new Map(e.map(e=>[e.trackId,e]))}function Pi(e){let t=new Set;for(let n of e)for(let e of n.zoneNames??[])t.add(e);return[...t].sort((e,t)=>e.localeCompare(t))}function Fi(e,t){if(t===`any`)return!0;let n=e.classes??[];return t===`face`?e.hasFace===!0||n.includes(`face`):n.includes(`plate`)}function Ii(e,t){return n=>{if(e.debug&&n.debug!==!0)return!1;if(e.zone===null&&e.identity===`any`)return!0;let r=t.get(n.trackId);return r===void 0?!0:e.zone!==null&&!(r.zoneNames??[]).includes(e.zone)?!1:Fi(r,e.identity)}}function Li(e){return e.zone!==null||e.identity!==`any`}function Ri(e,t,n){return Li(t)?e.filter(e=>!n.has(e.trackId)).length:0}function zi(e){return e.map(e=>({atMs:e.timestamp,kind:e.className===`audio`?`audio`:`object`}))}var Bi=`/addon/training`;function Vi(){let{t}=J(),n=Qt();return e(It,{className:`flex flex-col gap-3 border-border bg-surface p-3 sm:flex-row sm:items-center sm:gap-4`,"data-testid":`events-feed-retrain-cta`,children:[e(`div`,{className:`flex min-w-0 flex-1 items-start gap-2.5`,children:[i(I,{className:`mt-0.5 h-4 w-4 shrink-0 text-primary`,"aria-hidden":!0}),e(`div`,{className:`min-w-0 space-y-0.5`,children:[i(`p`,{className:`text-xs font-medium text-foreground`,children:t(`detectionIntelligence.retrainTabCallout.trainingFromThisFeed`,`Training from this feed`)}),i(`p`,{className:`${de} leading-relaxed`,children:t(`detectionIntelligence.retrainTabCallout.markATrackWithThe`,`Mark a track with the graduation-cap control on its card. On Training you correct frames, build collections, and start cloud fine-tunes.`)})]})]}),i(K,{variant:`outline`,size:`sm`,className:`shrink-0 self-start sm:self-center`,onClick:()=>n(Bi),children:t(`detectionIntelligence.retrainTabCallout.openTraining`,`Open Training`)})]})}c();var Hi=50,Ui=350,Wi=[{value:`loose`,labelKey:`detectionIntelligence.semanticEventSearch.looseLabel`,titleKey:`detectionIntelligence.semanticEventSearch.looseTitle`},{value:`balanced`,labelKey:`detectionIntelligence.semanticEventSearch.balancedLabel`,titleKey:`detectionIntelligence.semanticEventSearch.balancedTitle`},{value:`strict`,labelKey:`detectionIntelligence.semanticEventSearch.strictLabel`,titleKey:`detectionIntelligence.semanticEventSearch.strictTitle`}];function Gi(e){let t=String(e.id);return{id:t,trackId:e.trackId??t,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:t,mediaId:e.keyFrameMediaId??e.mediaId,windowMs:void 0}}function Ki({deviceId:r}){let s=t(null);Le(s);let{t:c}=J(),[l,u]=o(``),[d,f]=o(`loose`),[m,h]=o(null),[g,_]=o(null),v=r??g,[y,S]=o(null),C=tt(l,Ui).trim(),w=C.length>0,[T,E]=o(()=>Date.now());a(()=>{let e=setInterval(()=>E(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:D=[]}=bt({isCamera:!0,projection:`slim`}),ee=n(()=>{let e=new Map;for(let t of D)e.set(t.id,t.name);return e},[D]),O=e=>ee.get(e)??c(`detectionIntelligence.cameraFallback`,{id:String(e)}),k=n(()=>D.map(e=>e.id),[D]),{data:A}=ut({deviceIds:k},{enabled:k.length>0,staleTime:5*6e4}),j=n(()=>Nr(A??[],new Set(v===null?[]:[v])),[A,v]);a(()=>{m!==null&&(j.some(e=>e.kind===m)||h(null))},[j,m]);let{data:N,isFetching:P,isError:F,error:te}=Ne({text:C,strictness:d,limit:Hi,classFilter:m??void 0,deviceId:v??void 0},{enabled:w}),I=n(()=>[...N??[]].sort((e,t)=>t.score-e.score).map(e=>({...Gi(e),score:e.score})),[N]);function L(e){h(t=>t===e?null:e)}return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(`div`,{className:`relative min-w-[16rem] flex-1`,children:[i(b,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),i(qe,{ref:s,type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:c(`detectionIntelligence.semanticEventSearch.semanticSearchDescribeWhatYou`,`Semantic search — describe what you're looking for…`),className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":c(`detectionIntelligence.semanticEventSearch.semanticEventSearch`,`Semantic event search`)}),l&&i(`button`,{type:`button`,onClick:()=>u(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":c(`detectionIntelligence.semanticEventSearch.clearSearch`,`Clear search`),children:i(p,{className:`h-3.5 w-3.5`})})]}),P&&w&&i(x,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),e(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[i(`div`,{className:`flex items-center gap-1`,children:j.map(e=>i(`button`,{type:`button`,onClick:()=>L(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${m===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:U(e)},e.kind))}),r===void 0&&e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(`span`,{children:c(`detectionIntelligence.semanticEventSearch.camera`,`Camera`)}),i(M,{value:v===null?``:String(v),onChange:e=>_(e.target.value===``?null:Number(e.target.value)),className:`h-7 text-xs`,"aria-label":c(`detectionIntelligence.semanticEventSearch.filterByCamera`,`Filter by camera`),options:[{value:``,label:c(`detectionIntelligence.semanticEventSearch.all`,`All`)},...D.map(e=>({value:String(e.id),label:e.name}))]})]}),e(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(`span`,{children:c(`detectionIntelligence.semanticEventSearch.match`,`Match`)}),i(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Wi.map(e=>i(`button`,{type:`button`,onClick:()=>f(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${d===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:c(e.titleKey),children:c(e.labelKey)},e.value))})]}),w&&!P&&!F&&i(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:c(`common.matches`,{count:I.length})})]})]}),w&&e(`div`,{className:`space-y-3`,children:[F&&e(`p`,{className:`py-4 text-xs text-danger`,children:[c(`detectionIntelligence.semanticEventSearch.searchFailed`,`Search failed:`),` `,te instanceof Error?te.message:c(`detectionIntelligence.semanticEventSearch.unknownError`,`unknown error`),`. Check that the CLIP embedding step is enabled.`]}),!F&&P&&I.length===0&&i(Ft,{status:`pending`,pendingMessage:`Searching…`,testId:`semantic-events-grid`}),!F&&!P&&I.length===0&&i(Ft,{status:`empty`,emptyMessage:c(`detectionIntelligence.semanticEventSearch.noSemanticMatchesForTry`,`No semantic matches for “{{debounced}}”. Try a looser match threshold or a different phrasing.`,{debounced:C}),testId:`semantic-events-grid`}),!F&&I.length>0&&i(Ft,{status:`ready`,testId:`semantic-events-grid`,children:I.map(e=>i(Si,{row:e,cameraName:O(e.deviceId),nowMs:T,score:e.score,onOpenDetail:S},e.id))})]}),y&&i(bi,{row:y,cameraName:O(y.deviceId),deleteAvailable:pr,onClose:()=>S(null),onDeleted:()=>S(null)})]})}c();function qi(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return q.t(`helpers.relativeTime.justNow`);if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function Ji({row:t,cameraName:n,nowMs:r}){let{t:a}=J(),o=Sn(t.keyFrameMediaId===void 0?void 0:wn(t.keyFrameMediaId));return e(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[e(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[o.src?i(`img`,{src:o.src,alt:a(`detectionIntelligence.stationarySection.parkedOn`,`Parked {{className}} on {{cameraName}}`,{className:t.className,cameraName:n}),className:`h-full w-full object-cover`}):i(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:i(N,{className:`h-6 w-6`})}),i(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:t.label??t.className})]}),e(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[i(`span`,{className:`truncate text-[11px] text-foreground`,children:n}),i(`span`,{className:`text-[10px] text-foreground-subtle`,children:a(`common.parkedSince`,{since:qi(r,t.becameStationaryAt)})})]})]})}function Yi({deviceId:t}={}){let{t:r}=J(),[a,s]=o(!1),c=Date.now(),{data:l=[]}=bt({isCamera:!0,projection:`slim`}),u=n(()=>t===void 0?l.map(e=>e.id):[t],[l,t]),d=n(()=>{let e=new Map;for(let t of l)e.set(t.id,t.name);return e},[l]),{rows:f,unreadableCount:p}=an(u);return f.length===0&&p===0?null:e(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[e(K,{variant:`unstyled`,type:`button`,onClick:()=>s(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[i(a?_e:oe,{className:`h-4 w-4 text-foreground-subtle`}),i(N,{className:`h-4 w-4 text-foreground-subtle`}),i(`span`,{className:`text-sm font-semibold text-foreground`,children:r(`detectionIntelligence.stationarySection.stationary`,`Stationary`)}),i(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:f.length}),i(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:r(`detectionIntelligence.stationarySection.parkedObjectsKeptOutOf`,`Parked objects — kept out of the event feed`)}),p>0?i(`span`,{className:`ml-2 text-[11px] text-warning`,children:r(`detectionIntelligence.stationarySection.unreadable`,{count:p})}):null]}),a&&i(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:f.map(e=>i(Ji,{row:e,cameraName:d.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:c},e.id))})]})}var Xi={status:`debug.tape.status`,promote:`debug.tape.promote`,list:`debug.tape.list`,tracks:`debug.tape.tracks`,review:`debug.tape.review`,release:`debug.tape.release`,remove:`debug.tape.delete`},Zi={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},Qi=_(`/addon/pipeline-analytics/tape-export`),$i=10*6e4;function ea(e){return`${Qi}?tapeId=${encodeURIComponent(e)}`}var ta=`The server answered in a shape this build does not understand.`;function na(e){return e instanceof Error?e.message:q.t(`helpers.eventsDebugTapes.actionFailed`)}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function ra(e,t){if(!(t in e))return;let n=e[t];return n===null?null:typeof n==`number`&&Number.isFinite(n)?n:void 0}function $(e,t){let n=e[t];return typeof n==`string`?n:null}function ia(e,t){let n=e[t];return typeof n==`boolean`?n:null}function aa(e,t){if(!Array.isArray(e))return null;let n=[];for(let r of e){let e=t(r);if(e===null)return null;n.push(e)}return n}function oa(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function sa(e){if(!Z(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=ra(e,`segmentsHeld`),a=ra(e,`bytesLastHour`),o=ra(e,`bytesHeld`);if(t===null||!oa(n)||r===null||i===void 0||a===void 0||o===void 0)return null;let s=$(e,`reason`),c=Q(e,`segmentOriginMs`),l=Q(e,`framesPerMin`),u=Q(e,`heldFromMs`),d=Q(e,`heldToMs`),f=$(e,`shelfError`);return{deviceId:t,state:n,gapsSinceArmed:r,segmentsHeld:i,bytesLastHour:a,bytesHeld:o,...s===null?{}:{reason:s},...c===null?{}:{segmentOriginMs:c},...l===null?{}:{framesPerMin:l},...u===null?{}:{heldFromMs:u},...d===null?{}:{heldToMs:d},...f===null?{}:{shelfError:f}}}function ca(e){return Z(e)?aa(e.cameras,sa):null}function la(e){if(!Z(e))return null;let t=$(e,`id`),n=Q(e,`deviceId`),r=$(e,`scenario`),i=e.lighting,a=Q(e,`fromMs`),o=Q(e,`toMs`),s=e.state,c=Q(e,`frames`),l=Q(e,`gaps`),u=Q(e,`bytes`),d=ia(e,`reviewed`),f=ia(e,`released`),p=aa(e.tracks,e=>typeof e==`string`?e:null),m=Q(e,`tracksStillStored`);return t===null||n===null||r===null||i!==`day`&&i!==`ir`||a===null||o===null||s!==`complete`&&s!==`incomplete`||c===null||l===null||u===null||d===null||f===null||p===null||m===null?null:{id:t,deviceId:n,scenario:r,note:$(e,`note`),lighting:i,fromMs:a,toMs:o,state:s,frames:c,gaps:l,bytes:u,reviewed:d,released:f,tracks:p,tracksStillStored:m}}function ua(e){return Z(e)?aa(e.tapes,la):null}function da(e){if(!Z(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=ia(e,`stillStored`);return t===null||n===null||r===null||i===null||a===null||o===null?null:{trackId:t,firstT:n,lastT:r,boundFrames:i,cls:a,stillStored:o}}function fa(e){if(!Z(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=ia(e,`reviewed`),o=aa(e.lanes,da);return t===null||n===null||r===null||i===null||a===null||o===null?null:{tapeId:t,deviceId:n,fromMs:r,toMs:i,reviewed:a,lanes:o}}function pa(e){if(!Z(e))return null;if(e.ok===!1){let t=$(e,`reason`),n=$(e,`detail`);return t===null||n===null?null:{ok:!1,reason:t,detail:n}}if(e.ok!==!0)return null;let t=$(e,`tapeId`),n=e.state,r=Q(e,`frames`),i=Q(e,`gaps`),a=Q(e,`pinnedTracks`),o=Q(e,`bytes`);return t===null||n!==`complete`&&n!==`incomplete`||r===null||i===null||a===null||o===null?null:{ok:!0,tapeId:t,state:n,frames:r,gaps:i,pinnedTracks:a,bytes:o}}function ma(e){if(!Z(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=ia(e,`pinsSettled`);return n===null||r===null?null:{status:t,unpinned:n,pinsSettled:r}}if(t===`already-released`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function ha(e){if(!Z(e))return null;let t=e.status;if(t===`deleted`||t===`pins-owed`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function ga(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return q.t(`helpers.eventsDebugTapes.alreadyReleased`);case`not-found`:return q.t(`helpers.eventsDebugTapes.notFound`);case`pins-owed`:return q.t(`helpers.eventsDebugTapes.pinsOwed`);case`unavailable`:return q.t(`helpers.eventsDebugTapes.unavailable`,{reason:e.reason})}}function _a(e){if(!Z(e))return null;let t=$(e,`leftTrackId`),n=$(e,`rightTrackId`),r=e.relation,i=e.presence;return t===null||n===null||r!==`same-subject`&&r!==`different-subjects`?null:{leftTrackId:t,rightTrackId:n,relation:r,presence:i===`continuous`?`continuous`:null}}function va(e){if(!Z(e))return null;let t=$(e,`sourceTrackId`),n=e.purity;return t===null||n!==`mixed`&&n!==`not-a-subject`?null:{sourceTrackId:t,purity:n,switchAtMs:Q(e,`switchAtMs`)}}function ya(e){if(!Z(e))return null;let t=aa(e.relations,_a),n=aa(e.purities,va),r=ia(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function ba(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return q.t(`helpers.eventsDebugTapes.truncatedMarks`,{count:t})}function xa(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function Sa(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function Ca(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function wa(e,t){let n=[];for(let r of t.relations){let t=r.leftTrackId===e?r.rightTrackId:r.rightTrackId===e?r.leftTrackId:null;if(t===null)continue;let i=r.relation===`same-subject`?`same as`:`different from`;n.push(`${i} ${t}${r.presence===`continuous`?` (continuous)`:``}`)}for(let r of t.purities)r.sourceTrackId===e&&n.push(r.purity===`not-a-subject`?`not a subject`:r.switchAtMs===null?`mixed`:`mixed at switch`);return n}function Ta(e){switch(e.state){case`off`:return q.t(`helpers.eventsDebugTapes.statusOff`);case`recording`:return q.t(`helpers.eventsDebugTapes.statusRecording`);case`refused`:return q.t(`helpers.eventsDebugTapes.statusRefused`,{reason:e.reason??q.t(`helpers.eventsDebugTapes.unknownReason`)});case`failing`:return q.t(`helpers.eventsDebugTapes.statusFailing`,{reason:e.reason??q.t(`helpers.eventsDebugTapes.unknownReason`)});case`unknown`:return q.t(`helpers.eventsDebugTapes.statusUnknown`,{reason:e.reason??q.t(`helpers.eventsDebugTapes.unknownReason`)})}}var Ea={"window-too-long":`A promoted window is at most 30 minutes.`,"window-in-future":`The window ends in the future.`,"window-not-recorded":`No segment covers that window — the camera was not recording then, or it is older than 24 h.`,"invalid-scenario":`The scenario must be a slug: lowercase letters, digits and dashes, 3–64 characters.`,"promotion-budget":`A promotion budget is full (60 tapes, 1 GiB, 3 000 pinned tracks). Release or delete a tape already committed as a case first.`,"empty-window":`No frame was recorded in that window.`,"shelf-unreadable":`The camera's recorded segments could not be listed, so the window cannot be proven whole.`,"not-post-processing-node":`This node does not post-process frames, so it records no tracking tapes.`,"artifacts-elsewhere":`The artifacts storage location is on another node; tapes are recorded only where it lives.`,"tapes-not-started":`The tape recorder has not started on this node (or failed to).`};function Da(e,t){let n=Ea[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Oa(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function ka(e){return e<1024*1024?q.t(`helpers.eventsDebugTapes.sizeKb`,{value:(e/1024).toFixed(0)}):q.t(`helpers.eventsDebugTapes.sizeMb`,{value:(e/1024/1024).toFixed(1)})}function Aa(e){return e===null?`unknown`:ka(e)}function ja(e){return e===null?`unknown`:String(e)}function Ma(e,t){let n=t.trim();return e===404?q.t(`helpers.eventsDebugTapes.exportUnknown`):e===503?n.length>0?n:q.t(`helpers.eventsDebugTapes.tapesUnavailable`):e===500?n.length>0?n:q.t(`helpers.eventsDebugTapes.exportUnreadable`):q.t(`helpers.eventsDebugTapes.downloadFailed`,{status:e})}c();function Na({cameras:t,call:n,onPromoted:r}){let{t:a}=J(),[s,c]=o(``),[l,u]=o(``),[d,f]=o(``),[p,m]=o(``),[h,g]=o(``),[_,v]=o(`auto`),[y,b]=o(!1),[S,C]=o(null),w=async()=>{let e=Number.parseInt(s===``?t[0]?.value??``:s,10),i=Oa(l),a=Oa(d);if(!Number.isFinite(e)||i===null||a===null){C(`Pick a camera and both ends of the window.`);return}b(!0),C(null);try{let t=pa(await n(Xi.promote,{deviceId:e,fromMs:i,toMs:a,scenario:p,...h.trim().length>0?{note:h.trim()}:{},..._===`day`||_===`ir`?{lighting:_}:{}}));t===null?C(ta):t.ok?(C(`Promoted ${t.tapeId}: ${String(t.frames)} frames, ${ka(t.bytes)}, ${String(t.pinnedTracks)} tracks pinned`+(t.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),r()):C(Da(t.reason,t.detail))}catch(e){C(na(e))}finally{b(!1)}};return e(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border px-3 py-2`,children:[i(`div`,{className:`w-40`,children:i(M,{value:s,options:[...t],onChange:e=>c(e.target.value),"aria-label":a(`eventsDebugTapesPromoteForm.camera`,`Camera`)})}),i(qe,{type:`datetime-local`,"aria-label":a(`eventsDebugTapesPromoteForm.from`,`From`),value:l,onChange:e=>u(e.target.value),className:`w-48`}),i(qe,{type:`datetime-local`,"aria-label":a(`eventsDebugTapesPromoteForm.to`,`To`),value:d,onChange:e=>f(e.target.value),className:`w-48`}),i(qe,{"aria-label":a(`eventsDebugTapesPromoteForm.scenario`,`Scenario`),placeholder:`101-door-groups`,value:p,onChange:e=>m(e.target.value),className:`w-44`}),i(qe,{"aria-label":a(`eventsDebugTapesPromoteForm.note`,`Note`),placeholder:a(`eventsDebugTapesPromoteForm.optionalNote`,`optional note`),value:h,onChange:e=>g(e.target.value),className:`w-52`}),i(`div`,{className:`w-28`,children:i(M,{value:_,"aria-label":a(`eventsDebugTapesPromoteForm.lighting`,`Lighting`),options:[{value:`auto`,label:a(`eventsDebugTapesPromoteForm.lightingAuto`,`Lighting: auto`)},{value:`day`,label:a(`eventsDebugTapes.dayMode`)},{value:`ir`,label:`IR`}],onChange:e=>v(e.target.value)})}),e(K,{onClick:()=>void w(),disabled:y||t.length===0,children:[y?i(x,{className:`h-3.5 w-3.5 animate-spin`}):null,` `,a(`eventsDebugTapes.promoteWindow`)]}),i(`p`,{className:`w-full text-xs text-foreground-subtle`,children:a(`eventsDebugTapesPromoteForm.aPromotedTapeMayBe`,`A promoted tape may be shared as a test case — keep the scenario slug and note free of names or other personal data.`)}),S!==null&&i(`p`,{className:`w-full text-xs text-foreground`,children:S})]})}var Pa=`pipeline-analytics`,Fa=`debug.listTracks`,Ia=`debug.analyze`,La=_(`/addon/pipeline-analytics/debug-export`);function Ra(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function za(e,t){let n=e[t];return typeof n==`string`?n:null}function Ba(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Va(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Ha(e){return e===`error`||e===`warn`||e===`info`}function Ua(e){if(!Ra(e))return null;let t=za(e,`code`),n=za(e,`detail`),r=e.severity;return t===null||n===null||!Ha(r)?null:{code:t,severity:r,detail:n}}function Wa(e){if(!Ra(e))return null;let t=za(e,`trackId`),n=Ba(e,`deviceId`),r=za(e,`className`),i=Ba(e,`firstSeen`),a=Ba(e,`lastSeen`),o=Ba(e,`durationMs`),s=Va(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=za(e,`label`),l=za(e,`subLabel`),u=za(e,`previewMissReason`),d=Va(e,`markForTrain`),f=Va(e,`favourited`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},...l===null?{}:{subLabel:l},firstSeen:i,lastSeen:a,durationMs:o,active:s,timestamp:i,windowMs:o,importance:Ba(e,`importance`)??0,bestEventId:za(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function Ga(e){let t=Wa(e);if(t===null||!Ra(e))return null;let n=Ba(e,`mediaCount`),r=Ba(e,`eventCount`),i=Ba(e,`positionCount`);if(n===null||r===null||i===null)return null;let a=e.mediaKinds,o=e.findings;if(!Array.isArray(a)||!Array.isArray(o))return null;let s=a.filter(e=>typeof e==`string`),c=[];for(let e of o){let t=Ua(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...Wr(l)?{thumbnailProvenance:l}:{}}}function Ka(e){if(!Ra(e))return null;let t=Va(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=Wa(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function qa(e){if(!Ra(e))return null;let t=e.reports,n=e.vanished;if(!Array.isArray(t)||!Array.isArray(n))return null;let r=[];for(let e of t){let t=Ga(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var Ja={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`,UNSCORED_LABEL:`unscored label`,BEST_SHOT_STANDIN:`stand-in best shot`,BEST_SHOT_RASTER:`low-res best shot`};function Ya(e){return Ja[e]??e}var Xa={error:0,warn:1,info:2};function Za(e){return e.toSorted((e,t)=>Xa[e.severity]-Xa[t.severity]||e.code.localeCompare(t.code))}function Qa(e){return e.length===0?La:`${La}?deviceIds=${e.join(`,`)}`}function $a(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}function eo(e,t){return`${String(e)}:${t}`}function to(e,t){let n=[],r=new Set;for(let i of e){let e=eo(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}c();function no({tapeId:t,call:n,onClose:r,onChanged:a}){let{t:c}=J(),l=s({queryKey:[`events-debug`,`tapes`,`tracks`,t],queryFn:async()=>fa(await n(Xi.tracks,{tapeId:t}))}),u=l.data??null,d=s({queryKey:[`events-debug`,`tapes`,`marks`,t],enabled:u!==null,queryFn:async()=>u===null?null:ya(await n(Zi.list,{deviceId:u.deviceId,since:u.fromMs-$i,until:u.toMs+$i,limit:5e3}))}),[f,p]=o([]),[m,h]=o(``),[g,_]=o(null),v=e=>p(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),y=async e=>{_(null);try{for(let[t,r]of e)await n(t,r);p([]),await d.refetch(),a()}catch(e){_(na(e))}};if(u===null)return l.isLoading?i(`p`,{className:`text-xs`,children:c(`eventsDebugTapesReview.loadingTheTape`,`Loading the tape…`)}):i(G,{message:ta});let b=u.deviceId,x=(e,t)=>y(e.map(e=>[Zi.setRelation,{deviceId:b,...e,relation:t}])),S=e=>{let t=Number.parseFloat(m),n=e===`mixed`&&Number.isFinite(t)?u.fromMs+t*1e3:void 0;return y(f.map(t=>[Zi.setPurity,{deviceId:b,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},C=d.data==null?null:ba(d.data);return e(`div`,{className:`space-y-2 rounded-md border border-primary/40 px-3 py-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[i(`span`,{className:`text-xs font-medium`,children:c(`eventsDebugTapes.reviewLanes`,{id:u.tapeId,count:u.lanes.length})}),i(K,{disabled:f.length<2,onClick:()=>void x(Sa(f),`same-subject`),children:c(`eventsDebugTapesReview.sameSubject`,`Same subject`)}),i(K,{variant:`secondary`,disabled:f.length<2,onClick:()=>void x(Ca(f),`different-subjects`),children:c(`eventsDebugTapesReview.differentSubjects`,`Different subjects`)}),i(qe,{"aria-label":c(`eventsDebugTapesReview.changedAtSFromTape`,`Changed at (s from tape start)`),placeholder:c(`eventsDebugTapesReview.changedAtS`,`changed at s`),value:m,onChange:e=>h(e.target.value),className:`w-28`}),i(K,{variant:`secondary`,disabled:f.length!==1,onClick:()=>void S(`mixed`),children:c(`eventsDebugTapesReview.mixed`,`Mixed`)}),i(K,{variant:`secondary`,disabled:f.length===0,onClick:()=>void S(`not-a-subject`),children:c(`eventsDebugTapesReview.notASubject`,`Not a subject`)}),i(K,{variant:u.reviewed?`secondary`:`primary`,onClick:()=>void y([[Xi.review,{tapeId:u.tapeId,reviewed:!u.reviewed}]]).then(()=>l.refetch()),children:u.reviewed?c(`eventsDebugTapesReview.markNotReviewed`,`Mark not reviewed`):c(`eventsDebugTapesReview.markReviewed`,`Mark reviewed`)}),i(K,{variant:`ghost`,onClick:r,children:c(`common.close`,`Close`)})]}),g!==null&&i(G,{message:g}),C!==null&&i(G,{variant:`warning`,message:C}),i(`ul`,{className:`space-y-1`,children:u.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>i(ro,{lane:e,marks:d.data===null||d.data===void 0?[]:wa(e.trackId,d.data),selected:f.includes(e.trackId),onToggle:()=>v(e.trackId)},e.trackId))})]})}function ro({lane:t,marks:n,selected:r,onToggle:a}){let{t:o}=J(),{src:s}=Sn(t.stillStored?Cn(`track`,t.trackId):void 0);return e(`li`,{className:`flex items-center gap-2 text-xs`,children:[i(B,{"aria-label":o(`eventsDebugTapesReview.select`,`select {{trackId}}`,{trackId:t.trackId}),checked:r,onChange:a}),s===null?i(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):i(`img`,{src:s,alt:t.trackId,className:`h-10 w-10 rounded object-cover`}),i(`span`,{className:`font-mono`,children:t.trackId}),i(`span`,{children:t.cls}),i(`span`,{className:`text-foreground-subtle`,children:o(`eventsDebugTapes.laneFrames`,{range:`${$a(t.firstT)} → ${$a(t.lastT)}`,count:t.boundFrames})}),!t.stillStored&&i(`span`,{className:`text-foreground-subtle`,children:o(`eventsDebugTapesReview.notStoredMarkedThroughThe`,`not stored — marked through the tape`)}),n.map(e=>i(W,{variant:`info`,children:e},e))]})}c();var io=`camstack_admin_token`;function ao(){let e=O();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:Pa,action:t,input:n})}async function oo(e,t){let n=localStorage.getItem(io),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(ea(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(Ma(i.status,e))}let a=await i.blob(),o=i.headers.get(`content-disposition`),s=(o===null?null:/filename="?([^";]+)"?/i.exec(o))?.[1]?.trim()??t,c=URL.createObjectURL(a),l=document.createElement(`a`);l.href=c,l.download=s,l.click(),setTimeout(()=>URL.revokeObjectURL(c),6e4)}function so(){let{t:e}=J(),[t,n]=o(!1);return i(we,{expanded:t,onExpandedChange:n,header:i(`span`,{className:`text-sm font-medium text-foreground`,children:e(`eventsDebugTapes.trackingTapes`,`Tracking tapes`)}),children:i(co,{})})}function co(){let{t}=J(),r=ao(),a=bt({isCamera:!0,projection:`slim`}),c=n(()=>{let e=new Map;for(let t of a.data??[])e.set(t.id,t.name);return n=>e.get(n)??t(`cameraLoad.deviceLabel`,{deviceId:n})},[a.data,t]),l=s({queryKey:[`events-debug`,`tapes`,`status`],queryFn:async()=>ca(await r(Xi.status,{}))}),u=s({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>ua(await r(Xi.list,{}))}),[d,p]=o(null),[m,h]=o(null),g=async e=>{h(null);try{await oo(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){h(na(e))}},_=async e=>{let t=ma(await r(Xi.release,{tapeId:e.id}));if(t===null)throw Error(ta);let n=ga(t);if(n!==null)throw Error(n);await u.refetch()},v=async e=>{let t=ha(await r(Xi.remove,{tapeId:e.id}));if(t===null)throw Error(ta);let n=ga(t);if(n!==null)throw Error(n);await u.refetch()};return e(`div`,{className:`space-y-3`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:i(nn,{i18nKey:`eventsDebugTapes.intro`,components:{b:i(`strong`,{}),code:i(`code`,{})}})}),m!==null&&i(G,{message:m}),l.isLoading&&i(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebugTapes.loadingCameraStatus`,`Loading camera status…`)}),l.data===null&&i(G,{message:`The server answered in a shape this build does not understand.`}),e(`table`,{className:`w-full text-xs`,children:[i(`thead`,{children:e(`tr`,{className:`text-left text-foreground-subtle`,children:[i(`th`,{children:t(`eventsDebugTapes.camera`,`Camera`)}),i(`th`,{children:t(`eventsDebugTapes.state`,`State`)}),i(`th`,{children:t(`eventsDebugTapes.framesMin`,`Frames/min`)}),i(`th`,{children:t(`eventsDebugTapes.lastHour`,`Last hour`)}),i(`th`,{children:t(`eventsDebugTapes.held`,`Held`)}),i(`th`,{children:t(`eventsDebugTapes.gaps`,`Gaps`)})]})}),i(`tbody`,{children:(l.data??[]).map(n=>e(`tr`,{children:[i(`td`,{children:c(n.deviceId)}),i(`td`,{children:i(W,{variant:n.state===`recording`?`success`:n.state===`off`?`default`:n.state===`unknown`?`warning`:`danger`,children:Ta(n)})}),i(`td`,{children:n.framesPerMin===void 0?`—`:String(Math.round(n.framesPerMin))}),i(`td`,{title:n.shelfError,children:Aa(n.bytesLastHour)}),i(`td`,{title:n.shelfError,children:t(`eventsDebugTapes.segsHeld`,{count:ja(n.segmentsHeld),size:Aa(n.bytesHeld)})}),i(`td`,{children:String(n.gapsSinceArmed)})]},n.deviceId))})]}),i(Na,{cameras:xa(l.data??[]).map(e=>({value:String(e.deviceId),label:e.segmentsUnknown?t(`eventsDebugTapes.segmentsUnknown`,`{{value1}} (segments unknown)`,{value1:c(e.deviceId)}):c(e.deviceId)})),call:r,onPromoted:()=>void u.refetch()}),u.isLoading&&i(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebugTapes.loadingPromotedTapes`,`Loading promoted tapes…`)}),u.data===null&&i(G,{message:`The server answered in a shape this build does not understand.`}),e(`table`,{className:`w-full text-xs`,children:[i(`thead`,{children:e(`tr`,{className:`text-left text-foreground-subtle`,children:[i(`th`,{children:t(`eventsDebugTapes.scenario`,`Scenario`)}),i(`th`,{children:t(`eventsDebugTapes.camera`,`Camera`)}),i(`th`,{children:t(`eventsDebugTapes.window`,`Window`)}),i(`th`,{children:t(`eventsDebugTapes.state`,`State`)}),i(`th`,{children:t(`eventsDebugTapes.tracks`,`Tracks`)}),i(`th`,{})]})}),i(`tbody`,{children:(u.data??[]).map(n=>e(`tr`,{children:[i(`td`,{children:n.scenario}),i(`td`,{children:c(n.deviceId)}),e(`td`,{children:[new Date(n.fromMs).toLocaleString(),` · `,$a(n.toMs-n.fromMs),` `,`· `,n.lighting]}),e(`td`,{children:[i(W,{variant:n.state===`complete`?`success`:`warning`,children:n.state}),` `,n.reviewed&&i(W,{variant:`info`,children:t(`eventsDebugTapes.reviewed`)}),` `,n.released&&i(W,{children:t(`eventsDebugTapes.released`)})]}),i(`td`,{children:t(`eventsDebugTapes.storedOf`,{stored:String(n.tracksStillStored),total:String(n.tracks.length)})}),e(`td`,{className:`space-x-1 text-right`,children:[i(K,{variant:`secondary`,"aria-label":t(`eventsDebugTapes.review`,`Review {{scenario}}`,{scenario:n.scenario}),onClick:()=>p(n.id),children:t(`eventsDebugTapes.review2`,`Review`)}),i(K,{variant:`ghost`,"aria-label":t(`eventsDebugTapes.download`,`Download {{scenario}}`,{scenario:n.scenario}),onClick:()=>void g(n),children:i(f,{className:`h-3.5 w-3.5`})}),i(Je,{label:t(`eventsDebugTapes.release`,`Release`),icon:fe,title:t(`eventsDebugTapes.release2`,`Release {{scenario}}?`,{scenario:n.scenario}),description:t(`eventsDebugTapes.releasingReturnsThisTapeS`,`Releasing returns this tape's pinned tracks to ordinary retention — they can be pruned from then on. The promoted bundle itself is kept until deleted.`),confirmLabel:t(`eventsDebugTapes.release`,`Release`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:n.released,action:()=>_(n)}),i(Je,{label:t(`common.delete`,`Delete`),icon:re,title:t(`eventsDebugTapes.delete`,`Delete {{scenario}}?`,{scenario:n.scenario}),description:t(`eventsDebugTapes.deletingRemovesThePromotedBundle`,`Deleting removes the promoted bundle and its index row for good. Its tracks' pins are released first — this cannot be undone.`),confirmLabel:t(`common.delete`,`Delete`),triggerVariant:`ghost`,confirmVariant:`danger`,action:()=>v(n)})]})]},n.id))})]}),d!==null&&i(no,{tapeId:d,call:r,onClose:()=>p(null),onChanged:()=>void u.refetch()})]})}c();var lo=`all`,uo=`The server answered in a shape this build does not understand.`,fo={error:`danger`,warn:`warning`,info:`info`};function po({findings:e}){let{t}=J();return e.length===0?i(W,{variant:`success`,children:t(`eventsDebug.noAnomalyFound`,`no anomaly found`)}):i(`div`,{className:`flex flex-wrap gap-1`,children:Za(e).map(e=>i(W,{variant:fo[e.severity],title:e.detail,children:Ya(e.code)},e.code))})}function mo({track:t,report:n,analyzing:r}){let{t:a}=J(),o=Jr(n?.previewMissReason??t.previewMissReason);return e(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[n===void 0?i(`span`,{className:`text-[10px] text-foreground-subtle`,children:r?a(`eventsDebug.analysing`,`analysing…`):a(`eventsDebug.notAnalysed`,`not analysed`)}):e(u,{children:[i(po,{findings:n.findings}),i(`p`,{className:`text-[10px] text-foreground-subtle`,title:n.mediaKinds.length>0?n.mediaKinds.join(`, `):a(`eventsDebug.noMediaOfAnyKind`,`no media of any kind`),children:a(`eventsDebug.reportCounts`,{media:String(n.mediaCount),events:String(n.eventCount),positions:String(n.positionCount)})})]}),o!==null&&i(`p`,{className:`text-[10px] text-foreground-subtle`,title:o.raw,children:o.sentence})]})}function ho({deviceId:t}={}){let{t:r}=J(),a=O(),[c,l]=o(lo),u=t===void 0?c:String(t),[d,m]=o(!1),[g,_]=o(null),[v,y]=o(new Set),[b,S]=o(null),[w,T]=o(null),[E,D]=o(null),[ee,k]=o([]),A=ni(),j=bt({isCamera:!0,projection:`slim`}),N=n(()=>[{value:lo,label:r(`eventsDebug.allCameras`,`All cameras`)},...(j.data??[]).map(e=>({value:String(e.id),label:e.name}))],[j.data,r]),P=n(()=>{let e=new Map;for(let t of j.data??[])e.set(t.id,t.name);return e},[j.data]),F=e=>P.get(e)??r(`eventsDebug.cameraFallback`,{deviceId:e}),I=n(()=>u===lo?[]:[Number.parseInt(u,10)],[u]),L=s({queryKey:[`events-debug`,`list`,I],queryFn:async()=>Ka(await a.trpcClient.addons.custom.mutate({addonId:Pa,action:Fa,input:I.length===0?{}:{deviceIds:I}}))}),re=n(()=>(L.data?.tracks??[]).map(e=>e.trackId),[L.data]),ie=s({queryKey:[`events-debug`,`analyze`,re],enabled:re.length>0,queryFn:async()=>qa(await a.trpcClient.addons.custom.mutate({addonId:Pa,action:Ia,input:{trackIds:re}}))}),ae=n(()=>{let e=new Map;for(let t of ie.data?.reports??[])e.set(t.trackId,t);return e},[ie.data]),R=L.data?.tracks??[],z=L.data===null||ie.data===null,oe=()=>{L.refetch(),ie.refetch()},se=e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},B=()=>{y(new Set(R.map(e=>eo(e.deviceId,e.trackId))))},ce=()=>y(new Set),le=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await A.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},de=e=>{if(!$r||w!==null)return;let t=to(R,v);t.length!==0&&(T(e),D(null),(async()=>{let n=await le(e,t);T(null);let r=new Set(n.refused);y(new Set(t.filter(e=>r.has(e.trackId)).map(e=>eo(e.deviceId,e.trackId)))),e===`analyzed`&&k(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&D(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),L.refetch()})())},fe=()=>{let e=ee;e.length===0||w!==null||(T(`analyzed`),D(null),(async()=>{for(let t of e)try{await A.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{D(`Some tracks could not be re-marked. Refresh and try again.`)}T(null),k([]),L.refetch()})())},pe=async()=>{m(!0),_(null);try{await Tn(Qa(I),`camstack-debug.zip`)}catch(e){_(e instanceof Error?e.message:`Export failed.`)}finally{m(!1)}},V=w!==null;return e(`section`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[t===void 0&&i(`div`,{className:`w-44`,children:i(M,{value:u,options:N,onChange:e=>l(e.target.value)})}),e(K,{variant:`secondary`,onClick:oe,disabled:L.isFetching,children:[L.isFetching?i(x,{className:`h-3.5 w-3.5 animate-spin`}):i(C,{className:`h-3.5 w-3.5`}),r(`common.refresh`,`Refresh`)]}),e(K,{onClick:()=>void pe(),disabled:d||R.length===0,children:[d?i(x,{className:`h-3.5 w-3.5 animate-spin`}):i(f,{className:`h-3.5 w-3.5`}),r(`eventsDebug.exportAll`,{count:String(R.length)})]}),R.length>0&&v.size<R.length&&i(K,{variant:`ghost`,onClick:B,children:r(`eventsDebug.selectAll`,`Select all`)})]}),i(`p`,{className:`text-xs text-foreground-subtle`,children:i(nn,{i18nKey:`eventsDebug.debugMarkNote`,components:{code:i(`code`,{}),strong:i(`strong`,{})}})}),i(so,{}),L.isError&&i(G,{message:r(`eventsDebug.couldNotLoadTheMarked`,`Could not load the marked tracks.`)}),z&&!L.isError&&i(G,{message:uo}),g!==null&&i(G,{message:g}),E!==null&&i(G,{message:E}),L.data?.truncated===!0&&i(G,{message:r(`eventsDebug.aCameraFilledThePer`,`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`)}),(ie.data?.vanished.length??0)>0&&i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`eventsDebug.vanished`,{count:String(ie.data?.vanished.length)})}),v.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[i(`span`,{className:`text-xs font-medium text-foreground`,children:r(`common.selectedCount`,{count:v.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[i(`span`,{title:$r?void 0:`Track flags arrive with the next server update`,children:e(K,{variant:`secondary`,onClick:()=>de(`keep`),disabled:!$r||V,children:[w===`keep`?i(x,{className:`h-3.5 w-3.5 animate-spin`}):i(ne,{className:`h-3.5 w-3.5`}),` `,r(`eventsDebug.keep`,`Keep`)]})}),i(`span`,{title:$r?void 0:`Track flags arrive with the next server update`,children:e(K,{onClick:()=>de(`analyzed`),disabled:!$r||V,children:[w===`analyzed`?i(x,{className:`h-3.5 w-3.5 animate-spin`}):i(te,{className:`h-3.5 w-3.5`}),` `,r(`eventsDebug.analyzed`,`Analyzed`)]})}),i(K,{variant:`ghost`,onClick:ce,disabled:V,children:i(p,{className:`h-3.5 w-3.5`})})]})]}),ee.length>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[i(`span`,{className:`text-xs text-foreground`,children:r(`eventsDebug.markedAnalyzed`,{count:String(ee.length)})}),e(K,{variant:`ghost`,onClick:fe,disabled:V,children:[i(h,{className:`h-3.5 w-3.5`}),` `,r(`eventsDebug.undo`)]}),i(K,{variant:`ghost`,onClick:()=>k([]),disabled:V,children:i(p,{className:`h-3.5 w-3.5`})})]}),L.isLoading?i(Ft,{status:`pending`,pendingMessage:`Loading…`,testId:`debug-tracks-grid`}):R.length===0?i(yt,{icon:ue,title:r(`eventsDebug.noTrackIsMarkedFor`,`No track is marked for debug`),description:r(`eventsDebug.markOneFromATrack`,`Mark one from a track's actions on the Feed to see it here.`)}):i(Ft,{status:`ready`,testId:`debug-tracks-grid`,children:R.map(e=>{let t=ae.get(e.trackId);return i(Si,{row:e,cameraName:F(e.deviceId),nowMs:e.lastSeen,selected:v.has(eo(e.deviceId,e.trackId)),onToggleSelect:se,onOpenDetail:S,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:i(mo,{track:e,report:t,analyzing:ie.isFetching})},eo(e.deviceId,e.trackId))})}),b&&i(bi,{row:b,cameraName:F(b.deviceId),deleteAvailable:pr,onClose:()=>S(null),onDeleted:()=>{S(null),L.refetch()},onFlagsChanged:e=>{e.debug||(S(null),L.refetch())}})]})}c();function go({deviceId:t,debug:n}){let{t:r}=J(),[a,s]=o(!1);return i(we,{expanded:a||n,onExpandedChange:s,header:e(`span`,{className:`flex items-center gap-2 text-sm font-medium text-foreground`,children:[i(b,{className:`h-3.5 w-3.5`}),r(`archive.review.tools`,`Search, parked objects and debug`)]}),children:e(`div`,{className:`flex flex-col gap-3`,"data-testid":`archive-review-tools`,children:[i(Vi,{}),i(Ki,{deviceId:t}),i(Yi,{deviceId:t}),n&&i(ho,{deviceId:t})]})})}var _o=``;function vo(e){return e===`any`||e===`face`||e===`plate`}function yo({filters:t,zones:n,onChange:r,unchecked:a=0}){let{t:o}=J();return e(`div`,{className:`contents`,"data-testid":`archive-review-filters`,children:[n.length>0&&e(M,{wrapperClassName:`inline-block w-auto`,"aria-label":o(`archive.review.zone`,`Zone`),value:t.zone??_o,onChange:e=>r({...t,zone:e.target.value===_o?null:e.target.value}),children:[i(`option`,{value:_o,children:o(`archive.review.allZones`,`All zones`)}),n.map(e=>i(`option`,{value:e,children:e},e))]}),e(M,{wrapperClassName:`inline-block w-auto`,"aria-label":o(`archive.review.identity`,`Face or plate`),value:t.identity,onChange:e=>{let n=e.target.value;vo(n)&&r({...t,identity:n})},children:[i(`option`,{value:`any`,children:o(`archive.review.identityAny`,`Any subject`)}),i(`option`,{value:`face`,children:o(`archive.review.identityFace`,`With a face`)}),i(`option`,{value:`plate`,children:o(`archive.review.identityPlate`,`With a plate`)})]}),e(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(B,{checked:t.debug,onChange:e=>r({...t,debug:e.target.checked})}),o(`archive.camera.debugFilter`,`Debug-marked tracks only`)]}),a>0&&i(`span`,{className:`text-[11px] text-warning`,"data-testid":`archive-review-unchecked`,children:o(`archive.review.unchecked`,`Events not checked by this filter: {{count}}`,{count:a})})]})}c();function bo(){let e=Date.now(),t=new Date(e);return t.setHours(0,0,0,0),{fromMs:t.getTime(),toMs:e}}var xo=[];function So({deviceId:e}){return i(De,{deviceId:e,children:i(mt,{children:i(Dt,{children:i(se,{children:i(pt,{children:i(Co,{deviceId:e},e)})})})})})}function Co({deviceId:t}){let{t:a}=J(),[s,c]=o(bo),[l,u]=o(Mi),[d,f]=o(null),[p,m]=o(void 0),[h,g]=o(null),[_,v]=o(!1),[y,b]=o(null),[x,S]=o(null),[C,w]=o(`high`),[T,E]=o(null),[D,ee]=o(null),O=Gt({deviceId:t}),k=n(()=>Nt(O.data??[]),[O.data]),A=y??dt(k,`recorder`),j=A===null||A===`recorder`,N=ze(t,j?null:A,s),P=Ht({deviceId:t,since:s.fromMs,until:s.toMs,limit:200,projection:`slim`}),F=P.data??xo,te=n(()=>Pi(F),[F]),I=n(()=>Ni(F),[F]),L=n(()=>Ii(l,I),[l,I]),ne=Li(l)||l.debug,re=n(()=>d===null?0:Ri(d.rows,l,I),[d,l,I]),ie=n(()=>d!==null&&(d.narrowed||ne)?zi(d.rows):void 0,[d,ne]),ae=n(()=>({since:s.fromMs,until:s.toMs}),[s]),R=r(e=>c(e),[]),z=r(e=>{if(E(null),j){S(null),m(t=>({atMs:e,nonce:(t?.nonce??0)+1}));return}let t=Ot(N.clips,e);t===null&&E(e),S(t)},[j,N.clips]),oe=r((e,t)=>{if(b(e),E(null),e===`recorder`){S(null),m(e=>({atMs:t.timeRange.startMs,nonce:(e?.nonce??0)+1}));return}S(t)},[]),se=O.status===`pending`?i(`span`,{className:`text-[11px] text-foreground-subtle`,role:`status`,children:a(`archive.review.sourcesLoading`,`Loading sources…`)}):O.status===`error`?i(`span`,{className:`text-[11px] text-danger`,role:`alert`,children:a(`archive.review.sourcesFailed`,`Sources could not be read — {{reason}}`,{reason:O.error?.message??a(`archive.review.noReason`,`no reason given`)})}):null,B=P.status===`error`?i(`span`,{className:`text-[11px] text-danger`,role:`alert`,"data-testid":`archive-review-tracks-failed`,children:a(`archive.review.tracksFailed`,`Track facts could not be read — {{reason}}`,{reason:P.error?.message??a(`archive.review.noReason`,`no reason given`)})}):null,ce=se??(k.length>1?i(M,{wrapperClassName:`inline-block w-auto`,"aria-label":a(`archive.review.source`,`Source`),value:A??``,onChange:e=>{b(e.target.value),S(null),E(null)},children:k.map(e=>i(`option`,{value:e.value,children:e.label},e.value))}):null);return e(`div`,{className:`grid grid-cols-1 gap-3 lg:grid-cols-[minmax(0,calc(40vh*16/9))_minmax(20rem,1fr)]`,children:[i(`div`,{className:`order-1 flex min-w-0 flex-col gap-2 lg:order-none lg:col-start-1 lg:row-start-1`,children:i(`div`,{className:`mx-auto aspect-video w-full max-w-[calc(40vh*16/9)] overflow-hidden rounded-lg border border-border bg-black`,"data-testid":`archive-review-player`,children:i(Xt,{deviceId:t})})}),e(`div`,{className:`order-3 flex min-w-0 flex-col gap-2 lg:order-none lg:col-start-2 lg:row-start-1 lg:max-h-[40vh] lg:overflow-y-auto`,"data-testid":`archive-review-events`,children:[T!==null&&i(G,{variant:`warning`,message:a(`archive.review.noClipAt`,`This source holds no clip at {{time}}. Pick another source or another moment.`,{time:new Date(T).toLocaleTimeString()})}),x!==null&&A!==null&&i(Tt,{deviceId:t,clip:x,profile:C,onProfileChange:w}),i(ji,{deviceId:t,window:ae,rowFilter:L,onListChange:f,onSeek:z,layout:`rows`,toolbarTarget:D})]}),i(`div`,{className:`order-2 flex min-w-0 flex-col gap-2 lg:order-none lg:col-span-2 lg:row-start-2`,children:i(He,{deviceId:t,seekTo:p,onExportRange:(e,t)=>{v(!1),g({fromMs:e,toMs:t})},onViewChange:R,densityPoints:ie,toolbar:e(`div`,{className:`contents`,"data-testid":`archive-review-bar`,children:[ce,_&&e(`span`,{className:`text-[11px] text-success`,role:`status`,children:[a(`archive.review.exportQueued`,`Export queued.`),` `,i(Zt,{to:en(t),className:`font-medium underline`,children:a(`archive.review.openExports`,`Open Library → Exports`)})]}),i(`span`,{ref:ee,className:`contents`}),i(yo,{filters:l,zones:te,onChange:u,unchecked:re}),B]}),lanes:i(Fe,{deviceId:t,options:k,view:s,selectedProvider:A,onPickClip:oe})})}),i(`div`,{className:`order-4 min-w-0 lg:order-none lg:col-span-2 lg:row-start-3`,children:i(go,{deviceId:t,debug:l.debug})}),h!==null&&i(bn,{onClose:()=>g(null),onCreated:()=>{g(null),v(!0)},initialDeviceId:t,initialRange:h})]})}function wo({deviceId:e}){return i(De,{deviceId:e,children:i(cn,{deviceId:e,sectionFilter:e=>e.location===`top-tab`&&e.tab===`recording`})},e)}function To(e){return e.locationIds!==void 0&&e.locationIds.length>0?e.locationIds:e.locationId===null?[]:[e.locationId]}function Eo(e,t){let n=To(e);return n.length===0?q.t(`helpers.cameraDisk.defaultRoot`):n.map(e=>t.get(e)??e).join(` + `)}function Do(e,t,n){if(e.length===0)return null;let r=e[0];if(e.length===1&&r!==void 0)return{label:Eo(r,t),exact:!0};if(n===null)return null;let i=e.find(e=>To(e).includes(n));return i===void 0?null:{label:Eo(i,t),exact:!1}}c();var Oo=[{value:`retention`,labelKey:`recordings.storageSection.pruneRetention`},{value:`quota`,labelKey:`recordings.storageSection.pruneQuota`},{value:`operator`,labelKey:`recordings.storageSection.pruneOperator`}],ko=`—`;function Ao({data:t,row:a}){let{t:s}=J(),c=k(),u=l(),[d,f]=o(`retention`),p=Bt({}).data,m=r(()=>{u.invalidateQueries({queryKey:[[`recording`]]}),u.invalidateQueries({queryKey:[[`recordingArchive`]]}),u.invalidateQueries({queryKey:[[`pipelineAnalytics`]]})},[u]),h=rt({onSuccess:m}),g=At({onSuccess:m}),_=vt({onSuccess:m}),v=n(()=>{let e=new Map((p??[]).map(e=>[e.id,e.displayName])),n=(p??[]).filter(e=>e.type===`recordings`),r=(n.find(e=>me(e)===`active`)??n[0])?.id??null;return Do(t.usage?.locations??[],e,r)},[p,t.usage?.locations]),y=r(async(e,t,n)=>c({title:e,message:t,confirmLabel:n,variant:`danger`}),[c]),b=async()=>{await y(s(`archive.space.pruneTitle`,`Apply retention to {{name}}?`,{name:a.name}),s(`archive.space.pruneMessage`,`Footage beyond the retention policy is permanently deleted.`),s(`archive.space.pruneNow`,`Prune now`))&&h.mutate({deviceId:a.deviceId,reason:d})},x=async()=>{await y(s(`archive.space.deleteFootageTitle`,`Delete all footage for {{name}}?`,{name:a.name}),s(`archive.space.deleteFootageMessage`,`Permanently deletes {{size}} of recorded footage. This cannot be undone.`,{size:a.footageBytes===null?ko:Y(a.footageBytes)}),s(`archive.space.deleteFootage`,`Delete footage`))&&g.mutate({deviceId:a.deviceId})},S=async()=>{await y(s(`archive.space.deleteEventsTitle`,`Delete all events for {{name}}?`,{name:a.name}),s(`archive.space.deleteEventsMessage`,`Permanently deletes the events and their media. This cannot be undone.`),s(`archive.space.deleteEvents`,`Delete events`))&&_.mutate({deviceId:a.deviceId})};return e(`div`,{className:`flex flex-col gap-4`,"data-testid":`archive-space`,children:[e(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[i(w,{label:s(`archive.space.footage`,`Footage`),icon:i(z,{className:`h-3.5 w-3.5`}),footer:v===null?s(`archive.space.diskUnknown`,`Disk not reported`):v.exact?v.label:s(`archive.space.diskDefault`,`{{label}} (default)`,{label:v.label}),children:a.footageBytes===null?ko:Y(a.footageBytes)}),i(w,{label:s(`archive.space.events`,`Event storage`),footer:a.eventRows===null?void 0:s(`archive.space.eventRows`,`{{count}} events`,{count:a.eventRows}),children:a.eventBytes===null?ko:Y(a.eventBytes)}),i(w,{label:s(`archive.space.oldest`,`Oldest footage`),children:a.oldestMs===null?ko:new Date(a.oldestMs).toLocaleDateString()})]}),e(`div`,{className:`flex flex-col gap-2 rounded-lg border border-danger/40 p-3`,children:[i(`h3`,{className:`text-sm font-semibold text-danger`,children:s(`archive.space.danger`,`Danger zone`)}),e(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[i(`span`,{className:`text-foreground-subtle`,children:s(`recordings.storageSection.pruneReason`,`Prune reason`)}),i(M,{wrapperClassName:`inline-block w-auto`,value:d,"aria-label":s(`recordings.storageSection.pruneReason`,`Prune reason`),onChange:e=>{let t=Oo.find(t=>t.value===e.target.value);t&&f(t.value)},children:Oo.map(e=>i(`option`,{value:e.value,children:s(e.labelKey)},e.value))})]}),e(`div`,{className:`flex flex-wrap gap-2`,children:[e(K,{variant:`secondary`,onClick:()=>void b(),disabled:h.isPending,children:[i(H,{className:`h-3.5 w-3.5`}),s(`archive.space.applyRetention`,`Apply retention now`)]}),e(K,{variant:`secondary`,onClick:()=>void x(),disabled:g.isPending,children:[i(re,{className:`h-3.5 w-3.5`}),s(`archive.space.deleteFootage`,`Delete footage`)]}),e(K,{variant:`secondary`,onClick:()=>void S(),disabled:_.isPending,children:[i(re,{className:`h-3.5 w-3.5`}),s(`archive.space.deleteEvents`,`Delete events`)]})]})]})]})}c();var jo=[`review`,`health`,`settings`];function Mo(e){return jo.some(t=>t===e)}function No({data:t}){let{t:n}=J(),[a,o]=tn(),s=a.get(sn),c=a.get(on),l=Mo(c)?c:`review`,u=s===null?t.cameras[0]?.id??null:Number(s),d=r((e,t)=>{o(n=>{let r=new URLSearchParams(n);return r.set(e,t),r},{replace:!0})},[o]);if(u===null||!Number.isFinite(u))return i(yt,{icon:L,title:n(`archive.camera.none`,`No cameras yet`),description:n(`archive.camera.noneHint`,`Cameras appear here once one is added.`)});let f=t.rows.find(e=>e.deviceId===u),p=Yn(rr(t,u),Zn(t.findings,u));return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`archive-camera-section`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(M,{wrapperClassName:`inline-block w-auto`,value:u,onChange:e=>d(sn,e.target.value),"aria-label":n(`archive.camera.picker`,`Camera`),children:t.cameras.map(e=>i(`option`,{value:e.id,children:e.name},e.id))}),p.map(t=>e(W,{variant:nr[t.state],children:[n(`archive.function.${t.fn}`,t.fn),` · `,n(`archive.functionState.${t.state}`,t.state)]},t.fn))]}),!t.isLoading&&f===void 0?i(yt,{icon:L,title:n(`archive.camera.unknown`,`Camera not found`),description:n(`archive.camera.unknownHint`,`This camera is not in the Archive. Pick one from the overview.`)}):e(ht,{appearance:`pills`,value:l,onValueChange:e=>d(on,e),className:`flex flex-col gap-3`,children:[e(kt,{"aria-label":n(`archive.camera.sections`,`Camera sections`),children:[i(Et,{value:`review`,children:n(`archive.camera.review`,`Review`)}),i(Et,{value:`health`,children:n(`archive.camera.healthSpace`,`Health & space`)}),i(Et,{value:`settings`,children:n(`archive.camera.settings`,`Settings`)})]}),i(_t,{value:`review`,children:i(So,{deviceId:u})}),i(_t,{value:`health`,children:e(`div`,{className:`flex flex-col gap-6`,children:[i(ir,{data:t,deviceId:u}),i(Vn,{data:t,deviceId:u}),f!==void 0&&i(Ao,{data:t,row:f})]})}),i(_t,{value:`settings`,children:i(wo,{deviceId:u})})]})]})}c();var Po={recording:`success`,off:`default`,degraded:`warning`,unknown:`default`},Fo=`—`;function Io({rows:t,isLoading:r}){let{t:a}=J(),o=Qt(),s=n(()=>[{key:`camera`,header:a(`archive.table.camera`,`Camera`),sortValue:e=>e.name,render:e=>i(`span`,{className:`font-medium text-foreground`,children:e.name})},{key:`mode`,header:a(`archive.table.mode`,`Recording`),sortValue:e=>e.mode??``,render:e=>i(`span`,{className:`text-foreground-subtle`,children:e.mode===null?Fo:a(`archive.mode.${e.mode}`,e.mode)})},{key:`status`,header:a(`archive.table.status`,`Status`),sortValue:e=>e.state,render:t=>e(`span`,{className:`inline-flex items-center gap-1.5`,children:[i(W,{variant:Po[t.state],children:a(`archive.state.${t.state}`,t.state)}),t.warnings>0&&i(W,{variant:`warning`,children:a(`archive.table.warnings`,`{{count}} warning`,{count:t.warnings})})]})},{key:`footage`,header:a(`archive.table.footage`,`Footage`),align:`right`,nowrap:!0,sortValue:e=>e.footageBytes,render:e=>i(`span`,{className:`tabular-nums`,children:e.footageBytes===null?Fo:Y(e.footageBytes)})},{key:`events`,header:a(`archive.table.events`,`Events`),align:`right`,nowrap:!0,sortValue:e=>e.eventRows,render:e=>i(`span`,{className:`tabular-nums`,children:e.eventRows===null||e.eventBytes===null?Fo:`${e.eventRows.toLocaleString()} · ${Y(e.eventBytes)}`})},{key:`oldest`,header:a(`archive.table.oldest`,`Oldest footage`),align:`right`,nowrap:!0,sortValue:e=>e.oldestMs,render:e=>i(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.oldestMs===null?Fo:new Date(e.oldestMs).toLocaleDateString()})}],[a]);return!r&&t.length===0?i(yt,{icon:L,title:a(`archive.table.noCameras`,`No cameras`),description:a(`archive.table.addACamera`,`Add a camera first.`)}):i(Ie,{columns:s,rows:t,rowKey:e=>e.deviceId,onRowClick:e=>o($t(e.deviceId)),minWidthPx:720,maxBodyHeight:Ue,defaultSort:{columnKey:`camera`,dir:`asc`}})}var Lo=1440*60*1e3;function Ro(e){if(e.footageBytes===null||e.oldestMs===null)return null;let t=e.nowMs-e.oldestMs;return t<Lo?null:e.footageBytes/(t/Lo)}function zo(e,t){return e===null||t===null||t<=0?null:e/t}function Bo(e){let t=null;for(let n of e)n.oldestMs!==null&&(t===null||n.oldestMs<t)&&(t=n.oldestMs);return t}c();var Vo=`—`;function Ho({data:t}){let{t:r}=J(),{usage:a,footprint:o,rows:s,totals:c}=t,l=a!==null&&a.devicesRead!==`unavailable`,u=n(()=>Ro({footageBytes:l?a.totalUsedBytes:null,oldestMs:Bo(s),nowMs:Date.now()}),[l,a,s]),d=zo(n(()=>{let e=jn(a?.locations??[]);return e===null||e.knownVolumes===0?null:e.freeBytes},[a?.locations]),u);return e(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-5`,"data-testid":`archive-key-numbers`,children:[i(w,{label:r(`archive.keyNumbers.footage`,`Footage`),icon:i(z,{className:`h-3.5 w-3.5`}),footer:l?void 0:r(`archive.keyNumbers.footageUnread`,`The recorder did not answer`),children:l?Y(a.totalUsedBytes):Vo}),i(w,{label:r(`archive.keyNumbers.eventStorage`,`Event storage`),icon:i(F,{className:`h-3.5 w-3.5`}),footer:o===null?r(`archive.keyNumbers.eventsUnread`,`The event store did not answer`):r(`archive.keyNumbers.eventRows`,`{{count}} events`,{count:o.totalRows}),children:o===null?Vo:Y(o.totalBytes)}),i(w,{label:r(`archive.keyNumbers.growth`,`Growth per day`),icon:i(A,{className:`h-3.5 w-3.5`}),footer:u===null?r(`archive.keyNumbers.growthUnknown`,`Needs a day of footage`):d===null?r(`archive.keyNumbers.daysUnknown`,`Free space unknown`):r(`archive.keyNumbers.daysLeft`,`{{days}} days of space left`,{days:Math.floor(d)}),children:u===null?Vo:Y(u)}),i(w,{label:r(`archive.keyNumbers.cameras`,`Cameras`),icon:i(L,{className:`h-3.5 w-3.5`}),footer:r(`archive.keyNumbers.cameraStates`,`{{degraded}} degraded · {{off}} off`,{degraded:c.degraded,off:c.off}),children:r(`archive.keyNumbers.recordingOf`,`{{recording}} of {{total}} recording`,{recording:c.recording,total:s.length})}),i(w,{label:r(`archive.keyNumbers.warnings`,`Open warnings`),icon:i(y,{className:`h-3.5 w-3.5`}),footer:t.findings===null?r(`archive.keyNumbers.digestPending`,`No health digest yet`):void 0,children:t.findings===null?Vo:String(c.warnings)})]})}c();var Uo={active:`success`,readonly:`default`,drain:`warning`,disabled:`danger`};function Wo(){let{t}=J(),n=On(),[r,a]=o(null);return n.locations.length===0?i(yt,{icon:z,title:t(`archive.storage.none`,`No storage locations`),description:t(`archive.storage.noneHint`,`Add a location to start storing footage and events.`)}):e(u,{children:[i(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3`,"data-testid":`archive-storage-cards`,children:n.locations.map(r=>{let o=En(r);return e(`div`,{className:`flex flex-col gap-2 rounded-lg border border-border bg-surface p-3`,children:[e(`div`,{className:`flex items-start justify-between gap-2`,children:[e(`div`,{className:`min-w-0`,children:[i(`div`,{className:`truncate text-sm font-medium text-foreground`,children:r.displayName}),e(`div`,{className:`text-[11px] text-foreground-subtle`,children:[r.type,r.nodeId===void 0?``:` · ${r.nodeId}`]})]}),i(W,{variant:Uo[o],children:Dn(o).label})]}),i(An,{location:r,ownedBytes:n.ownedBytesById.get(r.id)??null}),i(kn,{drain:n.drainOf(r)}),e(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`span`,{className:`text-[11px] text-foreground-subtle`,children:o===`active`?t(`archive.storage.writing`,`Taking new writes`):t(`archive.storage.notWriting`,`Not taking new writes`)}),i(K,{variant:`ghost`,onClick:()=>a(r),children:t(`archive.storage.manage`,`Manage`)})]})]},r.id)})}),r!==null&&i(ot,{open:!0,onOpenChange:e=>!e&&a(null),children:e(st,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(gt,{children:i(Pt,{children:r.displayName})}),i(it,{children:i(Mn,{kinds:[r.type]})})]})})]})}c();var Go=1440*60*1e3,Ko=[1,7,30,90],qo=30;function Jo(){let{t}=J(),n=k(),a=l(),[s,c]=o(qo),u=et({onSuccess:()=>{a.invalidateQueries({queryKey:[[`pipelineAnalytics`]]})}}),d=r(async()=>{await n({title:t(`recordings.eventsManagementSection.pruneTitle`,{count:s}),message:t(`recordings.eventsManagementSection.permanentlyDeletesEveryEventMotion`,`Permanently deletes every event (motion / object / audio) older than the cutoff across all cameras, and their media. This cannot be undone.`),confirmLabel:t(`recordings.eventsManagementSection.pruneEvents`,`Prune events`),variant:`danger`})&&u.mutate({olderThanMs:Date.now()-s*Go,reason:`retention`})},[n,u,s,t]);return e(`section`,{className:`flex flex-wrap items-center gap-2 text-xs`,"data-testid":`prune-events-by-age`,children:[i(`span`,{className:`text-foreground-subtle`,children:t(`recordings.eventsManagementSection.pruneEventsOlderThan`,`Prune events older than`)}),i(M,{wrapperClassName:`inline-block w-auto`,value:s,onChange:e=>c(Number(e.target.value)),"aria-label":t(`recordings.eventsManagementSection.pruneEventsOlderThan`,`Prune events older than`),children:Ko.map(e=>i(`option`,{value:e,children:t(`recordings.eventsManagementSection.ageDays`,{count:e})},e))}),e(K,{variant:`secondary`,onClick:()=>void d(),disabled:u.isPending,children:[u.isPending?i(x,{className:`h-3 w-3 animate-spin`}):i(H,{className:`h-3 w-3`}),t(`recordings.eventsManagementSection.pruneNow`,`Prune now`)]})]})}var Yo=`inline-flex w-fit 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 disabled:opacity-50`;c();var Xo=`storage-migration`,Zo=new Set([`orphans`,`debug-media`,`ghost-ledger`]);function Qo(e){return[`${e.orphansReclaimed} orphan rows (${Y(e.orphanBytesReclaimed)})`,e.includeDebugMedia?`${e.debugMediaReclaimed} debug files (${Y(e.debugMediaBytesReclaimed)})`:null,`${e.ghostsForgotten} ghost rows (${Y(e.ghostBytesForgotten)})`].filter(e=>e!==null).join(` · `)}function $o(){let{t:e}=J(),t=Mt(Xo);return t===`pending`?null:t===`unknown`?i(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:e(`recordings.cleanupSection.couldNotCheckWhetherStorage`,`Could not check whether storage cleanup is installed on this hub.`)}):t===`present`?i(es,{}):null}function es(){let{t}=J(),n=k(),[r,a]=o(!1),[s,c]=o(null),l=Ye({},{refetchInterval:2e3}),u=l.data??null,d=u!==null&&Zo.has(u.phase),f=ke(),p=Me(),m=async()=>{if(await n({title:t(`recordings.cleanupSection.runStorageCleanup`,`Run storage cleanup?`),message:r?t(`recordings.cleanupSection.reclaimsLeftoverAnalyticsRowsAnd`,`Reclaims leftover analytics rows and files, debug stills/filmstrips, and ghost footage rows on frozen locations. Safe to re-run.`):t(`recordings.cleanupSection.reclaimsLeftoverAnalyticsRowsAnd2`,`Reclaims leftover analytics rows and files, and ghost footage rows on frozen locations. Debug stills are left alone. Safe to re-run.`),confirmLabel:t(`recordings.cleanupSection.runCleanup`,`Run cleanup`),variant:`danger`})){c(null);try{await f.mutateAsync({includeDebugMedia:r}),await l.refetch()}catch(e){c(e instanceof Error?e.message:String(e))}}},h=async()=>{if(u&&await n({title:t(`recordings.cleanupSection.cancelCleanup`,`Cancel cleanup?`),message:t(`recordings.cleanupSection.stopsAfterTheCurrentStep`,`Stops after the current step. Work already done stays done.`),confirmLabel:t(`recordings.cleanupSection.cancelCleanup2`,`Cancel cleanup`),variant:`danger`}))try{await p.mutateAsync({jobId:u.jobId}),await l.refetch()}catch{}};return e(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`recordings.cleanupSection.cleanup`,`Cleanup`)}),i(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`recordings.cleanupSection.onePassOverLeftoverAnalytics`,`One pass over leftover analytics (database + files) and ghost footage rows on frozen locations. Does not time out — progress updates here until it finishes.`)}),e(`label`,{className:`mt-3 flex items-start gap-2 text-[11px] text-foreground`,children:[i(B,{checked:r,disabled:d,onChange:e=>{a(e.target.checked)},className:`mt-0.5 h-3.5 w-3.5 accent-primary`}),i(`span`,{children:t(`recordings.cleanupSection.alsoRemoveDebugMediaMotion`,`Also remove debug media (motion stills and track filmstrips)`)})]}),e(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[e(K,{variant:`unstyled`,type:`button`,disabled:d||f.isPending,onClick:()=>{m()},className:Yo,children:[(d||f.isPending)&&i(x,{className:`h-3 w-3 animate-spin`}),i(re,{className:`h-3 w-3`}),t(`recordings.cleanupSection.runCleanup`,`Run cleanup`)]}),d&&i(K,{variant:`unstyled`,type:`button`,onClick:()=>{h()},className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,children:t(`common.cancel`,`Cancel`)})]}),s&&i(`p`,{className:`mt-2 text-[11px] text-danger`,children:s}),u&&e(`div`,{className:`mt-3 space-y-1 rounded-md border border-border px-2.5 py-2`,children:[e(`p`,{className:`text-xs text-foreground`,children:[t(`recordings.cleanupSection.phase`,`Phase:`),` `,i(`span`,{className:`font-medium`,children:u.phase}),d&&i(x,{className:`ml-2 inline h-3 w-3 animate-spin text-primary`})]}),u.detail&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:u.detail}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:Qo(u)}),u.error&&i(`p`,{className:`text-[11px] text-danger`,children:u.error})]})]})}c();var ts=2e3;function ns(){let{t}=J(),n=k(),r=l(),o=xt(),s=Se(void 0,{refetchInterval:e=>e.state.data?.state===`running`?ts:!1}),c=s.data,u=c?.state===`running`,d=u||o.isPending;a(()=>{c?.state!==`done`||c.finishedAtMs===null||(r.invalidateQueries({queryKey:[[`recording`]]}),r.invalidateQueries({queryKey:[[`pipelineAnalytics`]]}))},[c?.state,c?.finishedAtMs,r]);let f=async()=>{await n({title:t(`recordings.diskReconcileSection.reconcileStorageFromDisk`,`Reconcile storage from disk?`),message:t(`recordings.diskReconcileSection.makesTheDatabaseMatchThe`,`Makes the database match the filesystem: recordings index, tracks, events and media whose files are gone. Favourited tracks without files are deleted. Snapshot-less motion/audio events are deleted. Enrolled identities stay. This cannot be undone.`),confirmLabel:t(`recordings.diskReconcileSection.reconcile`,`Reconcile`),variant:`warning`})&&(await o.mutateAsync(),await s.refetch())},p=u?c.total>0?`Reconciling ${String(c.completed)}/${String(c.total)}…`:`Reconciling…`:o.isPending?`Reconciling…`:`Reconcile from disk`;return e(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:t(`recordings.diskReconcileSection.diskReconcile`,`Disk reconcile`)}),i(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`recordings.diskReconcileSection.deletesDatabaseRowsWhoseFiles`,`Deletes database rows whose files are gone. Enrolled identities stay.`)}),e(`div`,{className:`mt-3 flex flex-col gap-2`,children:[e(K,{variant:`unstyled`,type:`button`,onClick:()=>void f(),disabled:d,className:`inline-flex w-fit 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 disabled:opacity-50`,children:[d?i(x,{className:`h-3.5 w-3.5 animate-spin`}):i(z,{className:`h-3.5 w-3.5`}),p]}),c?.state===`done`?e(`p`,{className:`text-[11px] text-foreground-subtle`,children:[t(`recordings.diskReconcileSection.lastRun`,`Last run:`),` `,t(`recordings.diskReconcileSection.summary`,{completed:String(c.completed),tracks:String(c.tracks),events:String(c.events),media:String(c.mediaDropped)}),c.failed.length>0?t(`recordings.diskReconcileSection.failed`,`, {{value1}} failed ({{value2}})`,{value1:String(c.failed.length),value2:c.failed.join(`, `)}):``,`.`]}):null,c?.state===`error`&&c.error!==null?e(`p`,{className:`text-[11px] text-destructive`,children:[t(`recordings.diskReconcileSection.reconcileFailed`,`Reconcile failed:`),` `,c.error]}):null]})]})}var rs=1e3,is=60*rs,as=60*is;function os(e){return e.toLocaleString(`en-US`)}function ss(e){if(!Number.isFinite(e)||e<0)return`—`;if(e>=as){let t=Math.floor(e/as),n=Math.round(e%as/is);return`${t.toString()}h ${n.toString()}m`}if(e>=is){let t=Math.floor(e/is),n=Math.round(e%is/rs);return`${t.toString()}m ${n.toString()}s`}return`${Math.max(0,Math.round(e/rs)).toString()}s`}function cs(e){let t=Math.max(0,e.observedAt-e.startedAt),n=e.filesTotal===null?`${os(e.filesMoved)} files`:`${os(e.filesMoved)} / ${os(e.filesTotal)} files`,r=e.filesTotal===null||e.filesTotal===0?null:Math.min(1,e.filesMoved/e.filesTotal),i=t>0&&e.filesMoved>0,a=i?`${Y(e.bytesMoved/t*rs)}/s`:null,o=e.filesTotal===null?null:e.filesTotal-e.filesMoved,s=!i||o===null||o<=0?null:`~${ss(o*t/e.filesMoved)} left`;return{counted:n,fraction:r,moved:`${Y(e.bytesMoved)} moved`,rate:a,eta:s}}function ls(e){let t=cs(e);return[t.counted,t.moved,t.rate,t.eta].filter(e=>e!==null).join(` · `)}c();var us=`storage-migration`,ds=[{id:`recordings`,labelKey:`recordings.storageMigrationSection.classRecordings`,locationType:`recordings`},{id:`recordingsLow`,labelKey:`recordings.storageMigrationSection.classRecordingsLow`,locationType:`recordingsLow`},{id:`eventMedia`,labelKey:`recordings.storageMigrationSection.classEventMedia`,locationType:`eventMedia`}],fs=new Set([`planning`,`sealing`,`pausing`,`moving`,`draining`,`verifying`,`repointing`,`refreshing`,`resuming`]);function ps(){let{t}=J(),n=Mt(us);return n===`pending`?e(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[i(x,{className:`h-4 w-4 animate-spin`}),t(`migration.storageMigrationSection.checkingWhetherStorageMigrationIs`,`Checking whether storage migration is installed…`)]}):n===`unknown`?i(yt,{icon:y,title:t(`migration.storageMigrationSection.couldnTCheckWhetherStorage`,`Couldn't check whether storage migration is installed`),description:t(`migration.storageMigrationSection.theCapabilityRegistryDidNot`,`The capability registry did not answer, so this panel has nothing to report either way — it is not a statement that the capability is missing. Reload to ask again.`)}):n===`absent`?i(yt,{icon:m,title:t(`migration.storageMigrationSection.storageMigrationNotInstalled`,`Storage migration not installed`),description:t(`migration.storageMigrationSection.theCapabilityRegistryAnsweredNo`,`The capability registry answered: no addon in this cluster provides storage-migration. Once one is deployed, this panel moves recordings, low-res recordings and event media to new storage locations in one coordinated, verified operation.`)}):i(ms,{})}function ms(){let{t}=J(),r=k(),{data:a}=Bt({}),[s,c]=o({}),[l,u]=o({}),[d,f]=o(null),[h,g]=o(null),_=n(()=>{let e=new Map;for(let t of a??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[a]),v=n(()=>{let e=new Map;for(let t of a??[]){if(!V(t))continue;let n=e.get(t.type);n?n.push(t.id):e.set(t.type,[t.id])}let t=new Map;for(let[n,r]of e)r.length===1&&t.set(n,r[0]);return t},[a]),y=Pe({},{refetchInterval:2e3}),b=y.data??null,S=b!==null&&fs.has(b.phase),C=n(()=>{let e={};for(let t of ds){let n=s[t.id];n&&(e[t.id]=n)}return Object.keys(e).length>0?e:void 0},[s]),w=n(()=>{let e={};for(let t of ds){if(!s[t.id])continue;let n=l[t.id]??v.get(t.locationType);n&&(e[t.id]=n)}return Object.keys(e).length>0?e:void 0},[s,l,v]),T=n(()=>({destinations:C??{},...w?{sources:w}:{}}),[C,w]),E=We(T,{enabled:!1,retry:!1}),D=Xe(),ee=$e(),O=async()=>{if(!C)return;g(null);let e=await E.refetch();if(e.error){g(e.error instanceof Error?e.error.message:String(e.error));return}f(e.data??null)},A=async()=>{if(C&&await r({title:t(`migration.storageMigrationSection.startStorageMigration`,`Start storage migration?`),message:t(`migration.storageMigrationSection.copiesTheSelectedClassesFrom`,`Copies the selected classes from the chosen source to the destination, verifies, then either makes the destination the default (if the source was) or disables the source. Safe to re-run if interrupted.`),confirmLabel:t(`migration.storageMigrationSection.startMigration`,`Start migration`),variant:`danger`})){g(null);try{await D.mutateAsync(T),f(null),await y.refetch()}catch(e){g(e instanceof Error?e.message:String(e))}}},j=async()=>{if(b&&await r({title:t(`migration.storageMigrationSection.cancelMigration`,`Cancel migration?`),message:t(`migration.storageMigrationSection.stopsTheInProgressMigration`,`Stops the in-progress migration. Data already moved and verified stays at the destination; anything already repointed is not reverted.`),confirmLabel:t(`migration.storageMigrationSection.cancelMigration2`,`Cancel migration`),variant:`danger`}))try{await ee.mutateAsync({jobId:b.jobId}),await y.refetch()}catch{}};return e(`div`,{className:`flex flex-col gap-6`,children:[e(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[e(`h3`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[i(m,{className:`h-3.5 w-3.5`}),t(`migration.storageMigrationSection.storageMigration`,`Storage migration`)]}),i(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`migration.storageMigrationSection.moveRecordingsLowResRecordings`,`Move recordings, low-res recordings and/or event media from one location to another: copies via the recorder / pipeline-analytics movers, verifies, then either repoints the default (when the source was the default) or disables the source (when it was not). Skip a class with an empty destination.`)}),i(`div`,{className:`mt-3 grid grid-cols-1 gap-3 sm:grid-cols-3`,children:ds.map(n=>{let r=_.get(n.locationType)??[],a=v.get(n.locationType)??``;return e(`div`,{className:`space-y-2`,children:[i(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:t(n.labelKey)}),e(`div`,{className:`space-y-1`,children:[i(`label`,{htmlFor:`migration-from-${n.id}`,className:`text-[10px] text-foreground-subtle`,children:t(`recordings.storageMigrationSection.classFrom`,{label:t(n.labelKey)})}),i(M,{id:`migration-from-${n.id}`,value:l[n.id]??a,onChange:e=>{let t=e.target.value;u(e=>({...e,[n.id]:t}))},disabled:S,className:`w-full`,children:r.map(n=>e(`option`,{value:n.id,children:[n.displayName,V(n)?``:` (${t(`recordings.storageMigrationSection.readOnly`)})`]},n.id))})]}),e(`div`,{className:`space-y-1`,children:[i(`label`,{htmlFor:`migration-dest-${n.id}`,className:`text-[10px] text-foreground-subtle`,children:t(`recordings.storageMigrationSection.classTo`,{label:t(n.labelKey)})}),e(M,{id:`migration-dest-${n.id}`,value:s[n.id]??``,onChange:e=>{let t=e.target.value;c(e=>({...e,[n.id]:t}))},disabled:S,className:`w-full`,children:[i(`option`,{value:``,children:t(`migration.storageMigrationSection.skip`,`— skip —`)}),r.map(e=>i(`option`,{value:e.id,children:e.displayName},e.id))]})]})]},n.id)})}),h&&i(`p`,{className:`mt-2 text-[11px] text-danger`,children:h}),e(`div`,{className:`mt-3 flex items-center gap-2`,children:[e(K,{variant:`unstyled`,type:`button`,onClick:()=>{O()},disabled:!C||E.isFetching||S,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[E.isFetching&&i(x,{className:`h-3 w-3 animate-spin`}),t(`migration.storageMigrationSection.plan`,`Plan`)]}),e(K,{variant:`unstyled`,type:`button`,onClick:()=>{A()},disabled:!C||D.isPending||S,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[D.isPending&&i(x,{className:`h-3 w-3 animate-spin`}),t(`migration.storageMigrationSection.startMigration`,`Start migration`)]})]}),d&&i(`div`,{className:`mt-3 divide-y divide-border rounded-md border border-border`,children:d.moves.length===0?i(`p`,{className:`px-2.5 py-1.5 text-[11px] text-foreground-subtle`,children:t(`migration.storageMigrationSection.nothingToMoveSelectedDestinations`,`Nothing to move — selected destinations match the current defaults.`)}):d.moves.map(t=>e(`div`,{className:`px-2.5 py-1.5 text-[11px] text-foreground`,children:[t.storageClass,`: `,t.fromLocationId,` → `,t.toLocationId]},`${t.storageClass}-${t.toLocationId}`))}),b&&e(`div`,{className:`mt-4 border-t border-border pt-3`,children:[e(`div`,{className:`flex items-center justify-between`,children:[i(`h4`,{className:`text-xs font-semibold text-foreground`,children:t(`migration.storageMigrationSection.migrationStatus`,`Migration status`)}),S&&e(K,{variant:`unstyled`,type:`button`,onClick:()=>{j()},className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,children:[i(p,{className:`h-3 w-3`}),t(`common.cancel`,`Cancel`)]})]}),e(`p`,{className:`mt-1 text-xs text-foreground`,children:[t(`migration.storageMigrationSection.phase`,`Phase:`),` `,i(`span`,{className:`font-medium`,children:b.phase}),S&&i(x,{className:`ml-2 inline h-3 w-3 animate-spin text-primary`})]}),b.error&&i(`p`,{className:`mt-1 text-[11px] text-danger`,children:b.error}),b.pausedParticipants.length>0&&e(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:[t(`migration.storageMigrationSection.paused`,`Paused:`),` `,b.pausedParticipants.join(`, `)]}),i(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:b.moves.map(e=>i(hs,{move:e},`${e.storageClass}-${e.fromLocationId}`))})]}),i(gs,{})]}),i(_s,{running:S}),i(ys,{})]})}function hs({move:t}){let{t:n}=J(),r=t.progress===null?null:cs(t.progress);return e(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:[e(`div`,{className:`flex items-center justify-between`,children:[e(`span`,{className:`text-foreground`,children:[t.storageClass,`: `,t.fromLocationId,` → `,t.toLocationId]}),e(`span`,{className:`text-foreground-subtle`,children:[t.state??n(`common.pending`),t.error?` (${t.error})`:``]})]}),t.progress!==null&&e(`div`,{className:`mt-1 space-y-1`,children:[r!==null&&r.fraction!==null&&i(`div`,{className:`h-1 w-full overflow-hidden rounded bg-border`,children:i(`div`,{className:`h-full bg-primary`,style:{width:`${(r.fraction*100).toFixed(1)}%`}})}),i(`p`,{className:`text-[10px] text-foreground-subtle`,children:ls(t.progress)})]})]})}function gs(){let{t}=J(),{data:n}=Ce({});return!n||n.length===0?null:e(`div`,{className:`mt-4 border-t border-border pt-3`,children:[i(`h4`,{className:`text-xs font-semibold text-foreground`,children:t(`migration.storageMigrationSection.migrationHistory`,`Migration history`)}),i(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:n.map(t=>e(`div`,{className:`px-2.5 py-1.5 text-[11px] text-foreground-subtle`,children:[i(`span`,{className:`font-medium text-foreground`,children:t.phase}),` · `,Object.entries(t.destinations).filter(e=>typeof e[1]==`string`).map(([e,t])=>`${e} → ${t}`).join(`, `),` · `,new Date(t.startedAt).toLocaleString()]},t.jobId))})]})}function _s({running:t}){let{t:n}=J(),r=k(),a=Ke({},{staleTime:1/0,refetchOnWindowFocus:!1}),s=wt(),[c,l]=o(null),u=a.data??[];if(u.length===0)return null;let d=async e=>{if(await r({title:n(`migration.storageMigrationSection.drainRemaining`,`Drain remaining {{storageClass}}?`,{storageClass:e.storageClass}),message:`Moves what is still on ${e.fromLocationId} to ${e.toLocationId}. Nothing is paused and no default is changed — this is the second half of a migration, run on its own. It is resumable: cancelling leaves everything readable from both locations.`,confirmLabel:n(`migration.storageMigrationSection.drainRemaining2`,`Drain remaining`),variant:`danger`})){l(null);try{await s.mutateAsync({classes:[e.storageClass]}),await a.refetch()}catch(e){l(e instanceof Error?e.message:String(e))}}};return e(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[e(`div`,{className:`flex items-start justify-between gap-2`,children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:n(`migration.storageMigrationSection.leftOnTheOldLocation`,`Left on the old location`)}),e(`div`,{className:`flex shrink-0 items-center gap-2`,children:[i(`span`,{className:`text-[10px] text-foreground-subtle`,children:a.dataUpdatedAt>0?n(`migration.storageMigrationSection.measured`,`Measured {{value1}}`,{value1:new Date(a.dataUpdatedAt).toLocaleTimeString()}):n(`migration.storageMigrationSection.measuredNever`,`Measured — never`)}),i(K,{variant:`unstyled`,type:`button`,onClick:()=>{a.refetch()},disabled:a.isFetching,className:`rounded border border-border px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`,children:a.isFetching?n(`migration.storageMigrationSection.counting`,`Counting…`):n(`common.refresh`,`Refresh`)})]})]}),i(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:n(`migration.storageMigrationSection.aMigrationRepointsFirstAnd`,`A migration repoints first and drains behind. If the drain was cancelled, failed, or was interrupted by a restart, the data below is still on the source — readable, but not where the defaults now point. Draining moves it; it changes no default and pauses nothing.`)}),i(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:n(`migration.storageMigrationSection.thisCountIsTakenOn`,`This count is taken on demand: measuring it walks the whole media collection, so it is not refreshed on a timer. Press Refresh after a drain finishes.`)}),c&&i(`p`,{className:`mt-2 text-[11px] text-danger`,children:c}),i(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:u.map(r=>e(`div`,{className:`flex items-center justify-between gap-2 px-2.5 py-1.5 text-[11px]`,children:[e(`span`,{className:`text-foreground`,children:[r.storageClass,`: `,r.fromLocationId,` → `,r.toLocationId,i(`span`,{className:`ml-2 text-foreground-subtle`,children:vs(r)})]}),i(K,{variant:`unstyled`,type:`button`,onClick:()=>{d(r)},disabled:t||s.isPending,className:`shrink-0 rounded border border-border px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`,children:n(`migration.storageMigrationSection.drainRemaining2`,`Drain remaining`)})]},`${r.storageClass}-${r.fromLocationId}`))})]})}function vs(e){if(e.items===null)return q.t(`recordings.storageMigrationSection.residueUnknown`);let t=e.items.toLocaleString(`en-US`);return e.bytes===null?q.t(`recordings.storageMigrationSection.residueRows`,{count:e.items,items:t}):q.t(`recordings.storageMigrationSection.residueSegments`,{count:e.items,items:t,size:Y(e.bytes)})}function ys(){let{t}=J(),{data:n}=St({},{refetchInterval:2e3}),r=(n??[]).filter(e=>e.migrationJobId===null&&e.job.state===`running`);return r.length===0?null:e(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:t(`migration.storageMigrationSection.moversRunningOutsideAMigration`,`Movers running outside a migration`)}),i(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:r.map(t=>e(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:[e(`div`,{className:`text-foreground`,children:[t.lane,`: `,t.job.fromLocationId,` → `,t.job.toLocationId]}),i(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:ls({filesMoved:t.job.filesMoved,filesTotal:t.job.filesTotal,bytesMoved:t.job.bytesMoved,startedAt:t.job.startedAt,observedAt:t.observedAt})})]},t.job.jobId))})]})}c();function bs({openOnMount:t}){let{t:n}=J(),[r,s]=o(t);return a(()=>{t&&s(!0)},[t]),i(we,{expanded:r,onExpandedChange:s,header:e(`span`,{className:`flex items-center gap-2 text-sm font-medium text-foreground`,children:[i(d,{className:`h-3.5 w-3.5`}),n(`archive.tools.title`,`Tools`),i(`span`,{className:`text-[11px] font-normal text-foreground-subtle`,children:n(`archive.tools.subtitle`,`Storage migration, prune events, cleanup, reconcile from disk`)})]}),children:e(`div`,{className:`flex flex-col gap-6`,"data-testid":`archive-tools`,children:[e(`section`,{className:`flex flex-col gap-2`,children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:n(`archive.tools.migration`,`Move storage`)}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`archive.tools.migrationHint`,`Copy footage, low-res footage or event media to a new location, verify, then repoint the default. Applies to every camera.`)}),i(ps,{})]}),e(`section`,{className:`flex flex-col gap-2`,children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:n(`archive.tools.pruneEvents`,`Prune old events`)}),i(Jo,{})]}),i($o,{}),i(ns,{})]})})}c();function xs({data:t}){let{t:n}=J(),{hash:r}=rn();return a(()=>{r.length>1&&document.getElementById(r.slice(1))?.scrollIntoView({block:`start`})},[r]),e(`div`,{className:`flex flex-col gap-4`,children:[i(Ho,{data:t}),i(Re,{headingId:`archive-storage`,title:n(`archive.section.storage`,`Storage`),icon:z,children:i(`div`,{className:`p-3`,children:i(Wo,{})})}),i(Re,{headingId:`archive-cameras`,title:n(`archive.section.cameras`,`Cameras`),icon:L,children:i(Io,{rows:t.rows,isLoading:t.isLoading})}),i(`div`,{id:`activity`,children:i(Re,{headingId:`archive-activity`,title:n(`archive.section.activity`,`Activity & health`),icon:j,children:i(`div`,{className:`p-3`,children:i(Vn,{data:t})})})}),i(`div`,{id:`tools`,children:i(bs,{openOnMount:r===`#tools`})})]})}c();function Ss(){let e=bt({isCamera:!0,projection:`slim`}),t=Ve({},{refetchOnWindowFocus:!1}),r=zt({},{refetchOnWindowFocus:!1}),i=nt({},{refetchOnWindowFocus:!1}),a=jt({history:1},{refetchOnWindowFocus:!1}),o=n(()=>(e.data??[]).map(e=>({id:e.id,name:e.name})).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data]),s=t.data??null,c=s!==null&&s.devicesRead!==`unavailable`,l=r.data??null,u=i.data??null,d=a.data?.latest??null,f=d===null?null:d.findings,p=n(()=>er({cameras:o,footage:c?s.devices:null,events:l===null?null:l.devices,statuses:u,findings:f}),[o,c,s,l,u,f]);return{cameras:o,rows:p,totals:n(()=>tr(p),[p]),usage:s,footprint:l,statuses:u,findings:f,digestAtMs:d===null?null:d.generatedAt,isLoading:e.isLoading||t.isLoading||r.isLoading}}function Cs(){let{t:e}=J(),t=Ss();return i(ln,{icon:ve,title:e(`nav.archive`,`Archive`),subtitle:e(`archive.subtitle`,`Recorded footage and captured events — what they occupy, where they are written, and how each camera is doing.`),paramName:Yt,defaultSection:`overview`,sectionsLabel:e(`archive.sections`,`Archive sections`),sections:[{id:`overview`,label:e(`archive.section.overview`,`Overview`),content:i(xs,{data:t})},{id:`cameras`,label:e(`archive.section.cameras`,`Cameras`),ownedParams:[sn,on],content:i(No,{data:t})}]})}export{Cs as ArchivePage};
|