@camstack/addon-admin-ui 1.2.476 → 1.2.478
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonAssetIcon-NsStjqDv.js → AddonAssetIcon-B_-30Ezl.js} +1 -1
- package/dist/assets/Addons-DAuTfOiO.js +5 -0
- package/dist/assets/{AdminPage-BBb_f0ke.js → AdminPage-3JxWocN3.js} +1 -1
- package/dist/assets/{AdminSectionedPage-B77fFYLu.js → AdminSectionedPage-BByl6Zss.js} +1 -1
- package/dist/assets/AiProfiles-Cvu3UHy2.js +3 -0
- package/dist/assets/{BrokerForm-Dql4j_7g.js → BrokerForm-D6ln7R0A.js} +1 -1
- package/dist/assets/{Build-0VXUZTUO.js → Build-C0J5ce6Z.js} +4 -4
- package/dist/assets/{Calendars-DDdCqGq7.js → Calendars-G5xKjOn2.js} +1 -1
- package/dist/assets/{Cluster-B8y8FoQV.js → Cluster-w5Kcsast.js} +1 -1
- package/dist/assets/{CompositionBlockEditor-RHV08gl_.js → CompositionBlockEditor-BsmLsHO7.js} +1 -1
- package/dist/assets/{CompositionEditorPage-zqBIwPtu.js → CompositionEditorPage-AIRu6m_i.js} +1 -1
- package/dist/assets/Data-r1IoElgA.js +2 -0
- package/dist/assets/{DeviceDetail-BhhXtfQ_.js → DeviceDetail-Dz6PV7rK.js} +2 -2
- package/dist/assets/{DeviceDoActionFields-CM877gWa.js → DeviceDoActionFields-gklZW8H7.js} +1 -1
- package/dist/assets/{Devices-D_p1jnJs.js → Devices-z5XqFK0f.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-n_ZfqSgX.js → EmbedPlayerPage-Ccf5hGui.js} +1 -1
- package/dist/assets/{HelperWizard-WGprHYSO.js → HelperWizard-B5Evcb8G.js} +2 -2
- package/dist/assets/History-DLllXIdk.js +1 -0
- package/dist/assets/Identity-gwaZ5bXU.js +1 -0
- package/dist/assets/IntegrationDetail-P1tm0l2J.js +1 -0
- package/dist/assets/IntegrationHub-Dv8jClEP.js +1 -0
- package/dist/assets/Integrations-B9RbWg-F.js +1 -0
- package/dist/assets/Integrations-BLXg84-0.js +1 -0
- package/dist/assets/{Library-B6p5cMT3.js → Library-BXbZKXfl.js} +1 -1
- package/dist/assets/Locations-CjHnNjAh.js +3 -0
- package/dist/assets/{Logs-DbUcQh4T.js → Logs-D7ADXC_5.js} +1 -1
- package/dist/assets/{MyAccess-BjgGZZmK.js → MyAccess-id2Dmf9N.js} +1 -1
- package/dist/assets/{Network-DJAN2ffw.js → Network-BS9VI_eu.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-P5f0HKwt.js → NodeAddonsSettingsPanel-GEn1r68w.js} +1 -1
- package/dist/assets/Notifications-CIXn3wxj.js +1 -0
- package/dist/assets/Pipeline-B6AdA9Ua.js +1 -0
- package/dist/assets/Recordings-2Ej5v6LZ.js +1 -0
- package/dist/assets/{ScanNetworkModal-D0nIF1xL.js → ScanNetworkModal-CJoDRy24.js} +1 -1
- package/dist/assets/SessionsList-CMV9rDkY.js +2 -0
- package/dist/assets/{Showroom-OGwDnxr_.js → Showroom-eCnhoQBD.js} +1 -1
- package/dist/assets/{System-CkfHfeMd.js → System-AxGI_wdI.js} +1 -1
- package/dist/assets/{Terminal-puPiVrKC.js → Terminal-Br0QNfMN.js} +3 -3
- package/dist/assets/{Viewer-QizHE8-x.js → Viewer-DwNVIy-u.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BIhn7NhC.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-QiJARN9B.js} +1 -1
- package/dist/assets/{addon-icons-context-DxUCqyaH.js → addon-icons-context-lrP_33gc.js} +1 -1
- package/dist/assets/{assignment-candidates-D58mtpje.js → assignment-candidates-BMhC6h3l.js} +1 -1
- package/dist/assets/{authed-media-B_8ON2MT.js → authed-media-CnaIhiH3.js} +1 -1
- package/dist/assets/{board-model-4EY3kgfH.js → board-model--9Jw6SCm.js} +1 -1
- package/dist/assets/{device-integration-icon-C28x8nbP.js → device-integration-icon-DEZs4Umq.js} +1 -1
- package/dist/assets/device-picker-model-CUPf26ML.js +1 -0
- package/dist/assets/{format-Bq6kzos8.js → format-fYneBFV6.js} +1 -1
- package/dist/assets/{hostInit-EKt3RqKv.js → hostInit-DB6u6qxU.js} +1 -1
- package/dist/assets/i18n-D0o08mg-.js +1 -0
- package/dist/assets/icons-apbWMCU4.js +1 -0
- package/dist/assets/{index-CU-5JpMo.css → index-D4id__eL.css} +1 -1
- package/dist/assets/index-XXQ5yMw_.js +4 -0
- package/dist/assets/{linked-devices-model-Cgse8lhb.js → linked-devices-model-DMEJU3bE.js} +1 -1
- package/dist/assets/{location-owned-usage-uS8d4cQL.js → location-owned-usage-8xhfNE7j.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-99fca1f4.js → mf-entry-bootstrap-0-dcdd32c2.js} +2 -2
- package/dist/assets/mount-CUPf26ML.js +1 -0
- package/dist/assets/remoteEntry-CVuKB7K_.js +1 -0
- package/dist/assets/src-DntJrWmU.js +67 -0
- package/dist/assets/{step-inspector-model-C-7jLQzL.js → step-inspector-model-CI19RBoT.js} +1 -1
- package/dist/assets/table-2-CTZnEliG.js +1 -0
- package/dist/assets/{use-scenes-feed-wrd7r_Sr.js → use-scenes-feed-D80maECB.js} +1 -1
- package/dist/assets/{use-stationary-objects-U-Gv-CIi.js → use-stationary-objects-DBEa50KS.js} +1 -1
- package/dist/assets/useEventInvalidation-CUPf26ML.js +1 -0
- package/dist/assets/{useNodeUrlSelection-DZ8j6nae.js → useNodeUrlSelection-DWbo46bM.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BaETqb6x.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CglCXJMd.js} +2 -2
- package/dist/index.html +7 -7
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/Addons-CC-7wyzX.js +0 -5
- package/dist/assets/AiProfiles-DQ7eLKoM.js +0 -3
- package/dist/assets/Data-C8MsiGcu.js +0 -2
- package/dist/assets/History-DP_G-ECr.js +0 -1
- package/dist/assets/Identity-D_ESOlFi.js +0 -1
- package/dist/assets/IntegrationDetail-DAaPI_ET.js +0 -1
- package/dist/assets/IntegrationHub-Ch94ozNN.js +0 -1
- package/dist/assets/Integrations-BBm9vAbT.js +0 -1
- package/dist/assets/Integrations-CcDZmbwS.js +0 -1
- package/dist/assets/Locations-C_Mo8QAj.js +0 -3
- package/dist/assets/Notifications-BahnGVKD.js +0 -1
- package/dist/assets/Pipeline-gniN2j7S.js +0 -1
- package/dist/assets/Recordings-BK-wAC4w.js +0 -1
- package/dist/assets/SessionsList-eAK6hNQb.js +0 -2
- package/dist/assets/device-picker-model-BkHlLdb8.js +0 -1
- package/dist/assets/i18n-l_m6iBJW.js +0 -1
- package/dist/assets/icons-BivKI4y9.js +0 -1
- package/dist/assets/index-BFjKpxae.js +0 -4
- package/dist/assets/mount-BkHlLdb8.js +0 -1
- package/dist/assets/remoteEntry-awBSqPjf.js +0 -1
- package/dist/assets/src-ByunGuTZ.js +0 -67
- package/dist/assets/useEventInvalidation-BkHlLdb8.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{It as d,Nt as f,Ot as p,Q as m,Rn as h,Si as g,Tn as _,Wr as v,ai as y,bn as b,dt as x,fn as S,or as C,pi as ee,pn as w,tn as T,un as E,vi as te,xi as D}from"./player-overlays-Dbv95cvz.js";import{Na as ne}from"./client-DvJxGh2F.js";import{i as O,l as re}from"./video-D7jv0spx.js";import{Ai as k,Bn as A,Ci as ie,Di as ae,Ei as oe,Fi as j,Gr as M,Hn as N,Hr as P,Ii as F,Mi as se,Ot as I,Pi as L,Qr as ce,Qs as R,Qu as le,Ti as z,Ur as ue,Vn as B,_i as de,_r as fe,bi as pe,en as V,fi as me,fr as H,gd as he,gi as ge,gr as _e,hi as U,ji as W,ki as ve,mi as ye,mr as be,pd as G,pr as xe,qu as Se,tn as Ce,vi as K,vr as q,wi as we,xi as Te,yi as Ee,yt as De,zn as J}from"./src-ByunGuTZ.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import"./mount-BkHlLdb8.js";import{fr as X,lr as Z,mr as Oe}from"./index-BFjKpxae.js";import{t as ke}from"./AdminPage-BBb_f0ke.js";import{t as Ae}from"./NodeAddonsSettingsPanel-P5f0HKwt.js";import{n as Q,t as je}from"./useNodeUrlSelection-DZ8j6nae.js";function Me(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 Ne={queued:{icon:y,bg:`bg-muted text-foreground-subtle`,labelKey:`addons.addonRowBadge.queued`},updating:{icon:C,bg:`bg-primary/10 text-primary`,labelKey:`addons.addonRowBadge.updating`,spin:!0},"done-pending-restart":{icon:b,bg:`bg-amber-500/10 text-amber-700`,labelKey:`addons.addonRowBadge.pendingRestart`},done:{icon:g,bg:`bg-success/10 text-success`,labelKey:`addons.addonRowBadge.done`},failed:{icon:O,bg:`bg-danger/10 text-danger`,labelKey:`addons.addonRowBadge.failed`}};function Pe({item:e}){let{t:n}=Y(),r=Ne[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 Fe=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),Ie=new Set([`done`,`failed`,`skipped`]);function Le(e){return!Ie.has(e.phase)&&!Fe.has(e.jobState)}function Re(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=Fe.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 ze(){let{data:e}=we({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=he(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 Re([...n.values()],Date.now())},[e,t])}var Be={queued:{icon:y,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.queued`},fetching:{icon:C,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.fetching`,spin:!0},staged:{icon:C,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.staged`,spin:!0},validating:{icon:C,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.validating`,spin:!0},applying:{icon:C,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.applying`,spin:!0},restarting:{icon:C,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,labelKey:`addons.jobProgress.restarting`,spin:!0},applied:{icon:C,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.finalizing`,spin:!0},done:{icon:g,cls:`bg-success/10 text-success`,labelKey:`addons.jobProgress.updated`},failed:{icon:O,cls:`bg-danger/10 text-danger`,labelKey:`addons.jobProgress.failed`},skipped:{icon:T,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.skipped`}};function Ve({progress:e}){let{t:n}=Y(),r=Be[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 He(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 Ue(e){let t=e.version===null?``:` ${e.version}`,n=e.isOnline?``:` (offline: removed when it reconnects)`;return`- ${e.nodeName}${t}${n}`}function We(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(Ue)];return n.length>0&&r.push(`Could not ask: ${n.join(`, `)} — not included.`),r.push(`This cannot be undone.`),r.join(`
|
|
2
|
-
`)}function Ge(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 Ke={uninstalled:`uninstalled`,"not-installed":`was not installed`,refused:`REFUSED`,failed:`FAILED`,"pending-reconnect":`offline — removed when it reconnects`};function qe(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)}: ${Ke[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 Je={},Ye=3e4,Xe=`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 Ze({packageName:e,displayName:n,selectedNode:r,hideNodeAction:i,disabled:o}){let{t:s}=Y(),c=l(),u=ue(),f=P(),p=ie(Je,{staleTime:Ye}),m=p.data?.installations??[],h=(p.data?.unreachable??[]).map(e=>e.nodeId),g=He(m,e),_=e=>g.find(t=>t.nodeId===e)?.nodeName??(e===r.id?r.name:e),v=j({onSettled:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addonPages`]]}),c.invalidateQueries({queryKey:[[`capabilities`]]}),c.invalidateQueries({queryKey:[[`nodes`]]})}}),y=async e=>{await f({title:e.success?s(`addons.addonUninstallControls.uninstalled`,`{{displayName}} uninstalled`,{displayName:n}):s(`addons.addonUninstallControls.notEveryNodeWasCleaned`,`{{displayName}}: not every node was cleaned`,{displayName:n}),message:qe(e,_),variant:e.success?`default`:`danger`})},b=async t=>{try{await y(await v.mutateAsync({packageName:e,...t}))}catch(e){await f({title:s(`addons.addonUninstallControls.uninstallFailed`,`Uninstall {{displayName}} failed`,{displayName:n}),message:e instanceof Error?e.message:String(e),variant:`danger`})}},x=async()=>{let e=g.filter(e=>e.nodeId!==r.id);await u({title:s(`addons.addonUninstallControls.uninstallFrom`,`Uninstall {{displayName}} from {{name}}?`,{displayName:n,name:r.name}),message:Ge(n,r.name,e),confirmLabel:s(`addons.addonUninstallControls.uninstall`,`Uninstall`),variant:`danger`})&&await b(r.isHub?{}:{nodeId:r.id})},S=async()=>{let t=(await p.refetch()).data;if(t===void 0){await f({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=He(t.installations,e);await u({title:s(`addons.addonUninstallControls.uninstallEverywhere`,`Uninstall {{displayName}} everywhere?`,{displayName:n}),message:We(n,r,t.unreachable.map(e=>e.nodeId)),confirmLabel:s(`addons.addonUninstallControls.uninstallFromNodeS`,`Uninstall from {{length}} node(s)`,{length:r.length}),variant:`danger`})&&await b({everywhere:!0})},C=v.isPending||o===!0;return t(`div`,{className:`flex items-center gap-1.5`,children:[i!==!0&&t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),x()},disabled:C,className:Xe,title:s(`addons.addonUninstallControls.uninstallFrom2`,`Uninstall from {{name}}`,{name:r.name}),children:[a(d,{className:`h-3 w-3`}),v.isPending?s(`addons.addonUninstallControls.removing`,`Removing...`):s(`addons.addonUninstallControls.uninstall`,`Uninstall`)]}),(g.length>1||i===!0||h.length>0)&&t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S()},disabled:C,className:Xe,title:s(`addons.addonUninstallControls.uninstallFromEveryNodeThat`,`Uninstall from every node that has it`),children:[a(re,{className:`h-3 w-3`}),g.length>0?s(`addons.uninstallControls.everywhereCount`,{count:g.length}):s(`addons.uninstallControls.everywhere`)]})]})}function Qe(e){return typeof e.deprecated==`string`&&e.deprecated.length>0}function $e(e,t){return t?e:e.filter(e=>e.distTags.includes(`latest`)||!Qe(e))}function et(e){return e.length-$e(e,!1).length}c();function tt({packageName:e,currentVersion:n,installSource:r,onInstall:i,onClose:o,onSelect:c,selectedVersion:l}){let{t:d}=Y(),f=r===`upload`||r===`local`,[m,h]=s(!1),{data:_,isLoading:y,isError:b}=Ee({name:e}),S=_?$e(_,m):[],ee=_?et(_):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:d(`addons.versionPicker.versions`,`Versions`)}),a(`button`,{type:`button`,onClick:o,className:`text-foreground-subtle hover:text-foreground`,children:a(x,{className:`h-3 w-3`})})]}),f&&t(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[a(p,{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:d(`addons.versionPicker.inPlace`,{kind:r===`upload`?d(`addons.versionPicker.uploadedCopy`,`Uploaded copy`):d(`addons.versionPicker.localCopy`,`Local copy`)})}),` `,a(Z,{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(C,{className:`h-3.5 w-3.5 animate-spin`}),d(`addons.versionPicker.loadingVersions`,`Loading versions...`)]}),b&&a(`div`,{className:`px-3 py-4 text-center text-[10px] text-danger`,children:d(`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),f=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:d(`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)),Qe(e)&&a(`span`,{className:`text-[9px] text-red-400 line-through`,children:d(`common.deprecated`)}),a(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return c?t(`button`,{type:`button`,"aria-label":d(`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:[f,o?a(g,{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:[f,a(`button`,{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?d(`addons.versionPicker.reInstallFromNpm`,`Re-install {{version}} from npm`,{version:e.version}):d(`addons.versionPicker.install`,`Install {{version}}`,{version:e.version}),children:a(v,{className:`h-3 w-3`})})]},e.version)})}),!y&&!b&&_&&_.length===0&&a(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:d(`addons.versionPicker.noVersionsFound`,`No versions found`)}),ee>0&&a(M,{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:()=>h(e=>!e),children:m?d(`addons.versionPicker.hideOlder`,`Hide older versions`):d(`addons.versionPicker.showOlder`,`Show older versions ({{count}})`,{count:ee})})]})}c();var nt=`device-export`;function rt(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===nt)}function it(e){return e!==`local`&&e!==`upload`}function at({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?m(`/api/addon-assets/${r}/${i}`):null,g=!!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:g?a(`img`,{src:f,alt:r,className:`h-4 w-4`,onError:()=>l(!0)}):a(e?h:_,{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`}),it(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(p,{className:`h-2.5 w-2.5 text-white`})})]})}function ot({version:e,availableUpdate:n,selectedVersion:r,isUpdating:i,installSource:o,disabled:s,onUpdate:c,onOpenPicker:l,children:u}){let{t:d}=Y();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(C,{className:`h-3 w-3 animate-spin`}),d(`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(`button`,{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:d(`addons.addonCard.updateTo`,`Update to {{target}}`,{target:i}),children:[a(v,{className:`h-3 w-3`}),d(`addons.addonCard.update`,`Update`)]}),t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:s,"aria-label":d(`addons.addonCard.selectVersionToInstall`,`Select version to install`),title:d(`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(D,{className:`h-3 w-3`})]}),u]})}return t(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[t(`button`,{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:d(`addons.addonCard.versionTapToViewAll`,`Version {{version}} — tap to view all versions`,{version:e}),children:[e,a(D,{className:`h-3 w-3 opacity-50`})]}),u]})}function st({addonId:e}){let t=l(),{data:n=`inherit`}=U({addonId:e}),r=W({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(`button`,{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 ct={id:`hub`,name:`Hub`,isHub:!0};function lt({addon:e,clusterStatus:n,hideVersion:r,availableUpdate:i,onUpdate:c,isUpdating:d,jobProgress:f,bundle:p,bulkItem:m,disabledByBulk:g,isSystem:_,selectedNode:v}){let{t:y}=Y(),[S,C]=s(!1),[ee,T]=s(!1),[ne,re]=s(null);o(()=>{re(null)},[i]);let k=ne??i,[A,ie]=s(!1),[oe,j]=s(!1),[N,P]=s(`logs`),F=l(),se=X(),{manifest:L}=e,ce=!p&&!L.protected&&L.removable!==!1,R=!!p,le=p?.displayName??L.name,z=p?.packageName??L.packageName,ue=p?.version??L.packageVersion??L.version,B=p?.installSource??e.installSource,de=p?p.bundle?.description??p.addons[0]?.manifest.description:L.description,me=ae({onSuccess:()=>{F.invalidateQueries({queryKey:[[`addons`]]})}}),he=pe({onSuccess:()=>{F.invalidateQueries({queryKey:[[`addons`]]}),F.invalidateQueries({queryKey:[[`addonPages`]]}),F.invalidateQueries({queryKey:[[`capabilities`]]}),F.invalidateQueries({queryKey:[[`integrations`]]})}}),ge=ve({onSuccess:()=>{F.invalidateQueries({queryKey:[[`addons`]]}),F.invalidateQueries({queryKey:[[`alerts`]]})}}),U=e.health,W=U?.phase===`failed`&&!U.inGracePeriod,ye=W&&U?.nextRetryAt&&!U.retrying,G=Me(e.process);return t(`div`,{className:`rounded-md border bg-surface overflow-hidden ${W?`border-red-500/50`:`border-border`}`,children:[W&&U&&t(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[a(O,{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:y(`addons.addonCard.failedToLoad`,{attempt:U.retryCount})}),a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:U.lastError?.message??y(`addons.addonCard.unknownError`,`Unknown error`)}),ye&&U.nextRetryAt&&a(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:y(`addons.addonCard.autoRetryAt`,{time:new Date(U.nextRetryAt).toLocaleTimeString()})})]}),t(`button`,{type:`button`,disabled:ge.isPending||U.retrying,onClick:e=>{e.stopPropagation(),ge.mutate({packageName:z})},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:y(`addons.addonCard.resetRetryCounterAndForce`,`Reset retry counter and force immediate reload`),children:[a(b,{className:`h-3 w-3 ${ge.isPending||U.retrying?`animate-spin`:``}`}),y(`addons.addonCard.retryNow`,`Retry now`)]})]}),G!==null&&t(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[a(O,{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:y(`addons.addonCard.processProblem.${G.kind}`)}),G.reason!==void 0&&a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:G.reason})]})]}),t(`div`,{className:`flex items-start gap-2.5 px-3 py-2`,children:[a(at,{isBundle:R||!!L.components&&L.components.length>1,installSource:B,addonId:R?p.addons[0]?.manifest.id:L.id,iconPath:R?p.bundle?.icon??p.addons[0]?.manifest.icon:L.icon,color:R?p.addons[0]?.manifest.color:L.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:le}),!r&&a(ot,{version:ue,availableUpdate:i,...k===void 0?{}:{selectedVersion:k},isUpdating:d,installSource:B,disabled:g,...c&&k!==void 0?{onUpdate:()=>c(k)}:{},onOpenPicker:()=>T(e=>!e),children:ee&&a(tt,{packageName:z,currentVersion:ue,...B?{installSource:B}:{},...i!==void 0&&k!==void 0?{selectedVersion:k,onSelect:e=>{re(e),T(!1)}}:{},onInstall:e=>{T(!1),he.mutate({packageName:z,version:e})},onClose:()=>T(!1)})})]}),t(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[z!==le&&a(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:z}),R&&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(h,{className:`h-3 w-3`}),p.addons.length]}),_&&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:y(`addons.addonCard.systemPackageUpdatingRestartsThe`,`System package — updating restarts the hub`),children:[a(b,{className:`h-3 w-3`}),y(`addons.addonCard.system`,`System`)]}),m!=null&&a(Pe,{item:m}),f!=null&&a(Ve,{progress:f})]}),de&&a(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:de}),!R&&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`?y(`addons.addonCard.forked`):y(`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`:G===null?`bg-gray-500/15 text-gray-400`:`bg-red-500/15 text-red-400`}`,children:e.process.state})]})]})]}),!R&&t(`div`,{className:`flex items-center gap-1 px-3 py-1 border-t border-border/50 bg-surface-hover/20`,children:[t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),me.mutate({addonId:L.id})},disabled:me.isPending||g,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(b,{className:`h-3 w-3 ${me.isPending?`animate-spin`:``}`}),y(`addons.addonCard.restart`,`Restart`)]}),t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ie(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${A?`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(w,{className:`h-3 w-3`}),y(`addons.addonCard.logs`,`Logs`)]}),!R&&t(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),j(!0)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${oe?`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(E,{className:`h-3 w-3`}),y(`addons.addonCard.settings`,`Settings`)]}),a(`div`,{className:`flex-1`}),ce&&a(Ze,{packageName:L.packageName,displayName:L.name,selectedNode:v??ct,disabled:g})]}),n&&n.nodes.length>1&&!R&&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:y(`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:y(`addons.addonCard.outdated`)}),e.status===`offline`&&a(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:y(`common.offline`)}),e.synced&&e.status!==`offline`&&a(`span`,{className:`text-[9px] text-success`,children:y(`common.synced`)})]},e.nodeId))})]}),A&&!R&&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(`button`,{type:`button`,onClick:()=>P(`logs`),className:`px-2 py-0.5 transition-colors ${N===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:y(`addons.addonCard.logs`,`Logs`)}),a(`button`,{type:`button`,onClick:()=>P(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${N===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:y(`addons.addonCard.events`,`Events`)})]}),a(`div`,{className:`flex-1`}),a(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ie(!1)},className:`text-foreground-subtle hover:text-foreground`,children:a(x,{className:`h-3.5 w-3.5`})})]}),N===`logs`&&a(Ce,{addonId:L.id,maxHeight:`max-h-64`,showFilters:!1}),N===`events`&&a(V,{addonId:L.id,category:`addon.*`,maxHeight:`max-h-64`})]}),R&&t(u,{children:[a(`button`,{type:`button`,onClick:()=>C(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(S?te:D,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),S&&a(`div`,{className:`border-t border-border px-2.5 py-1.5 space-y-1.5`,children:p.addons.map(e=>a(lt,{addon:e,hideVersion:!0},e.manifest.id))})]}),oe&&!R&&a(H,{open:!0,onOpenChange:e=>!e&&j(!1),children:t(be,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(fe,{children:t(q,{className:`flex items-center gap-2`,children:[a(E,{className:`h-4 w-4 text-primary`}),y(`addons.addonCard.settingsTitle`,{name:le})]})}),t(xe,{className:`space-y-4`,children:[a(`div`,{className:`text-[10px] text-foreground-subtle mb-2`,children:y(`addons.addonCard.clusterWideSettingsOneValue`,`Cluster-wide settings — one value for every node. Per-node settings live under Cluster → the node → Settings.`)}),a(Ae,{nodeId:null,addonIds:[L.id],level:`global`,fieldScope:`cluster`,emptyMessage:y(`addons.addonCard.thisAddonExposesNoCluster`,`This addon exposes no cluster-wide settings. Anything it can configure is per-node — open it from Cluster → the node → Settings.`)}),rt(L)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:y(`addons.addonCard.deviceExport`,`Device export`)}),a(I,{addonId:L.id,onOpenDevice:e=>se(`/devices/${e}`)})]}),it(B)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:y(`addons.addonCard.autoUpdate`,`Auto-Update`)}),a(st,{addonId:L.id})]}),L.components&&L.components.length>0&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:y(`addons.addonCard.components`,{count:L.components.length})}),a(`div`,{className:`flex flex-wrap gap-1`,children:L.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(_e,{children:a(M,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>j(!1),children:y(`common.close`,`Close`)})})]})})]})}c();var ut=`.tgz,.tar.gz,.zip`;function dt({onUploadSuccess:e}){let{t:r}=Y(),[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(m(`/api/addons/upload`),{method:`POST`,headers:{Authorization:`Bearer ${r}`},body:n})).json()).success&&e()}finally{c(!1)}},[e]);return t(u,{children:[a(`input`,{ref:l,type:`file`,accept:ut,onChange:i(e=>{let t=e.target.files?.[0];t&&d(t),e.target.value=``},[d]),className:`hidden`}),t(`button`,{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(C,{className:`w-3.5 h-3.5 animate-spin`}):a(p,{className:`w-3.5 h-3.5`}),o?r(`addons.addonUploadZone.uploading`,`Uploading...`):r(`addons.addonUploadZone.upload`,`Upload`)]})]})}var ft=/```[^\n]*\n([\s\S]*?)```/g;function pt(e){let t=[],n=0;for(let r of e.matchAll(ft)){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 mt(e){let t=e.trim();return t.startsWith(`https://`)||t.startsWith(`http://`)?t:null}function ht(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?mt(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 gt(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:ht(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:ht(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=ht(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 _t({markdown:e}){return a(`div`,{className:`text-xs text-foreground leading-relaxed`,children:pt(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:gt(e.body,`b${t}`)},`text-${t}`))})}c();function vt(e){return e.replace(/^@camstack\/(addon-)?/,``)}function yt(e,t,n){let r=$e(e,n);return r.some(e=>e.version===t)?r:[{version:t,distTags:[],deprecated:void 0},...r]}function bt({pending:e,failed:n,body:r,missing:i}){let{t:o}=Y();return e?t(`div`,{className:`flex items-center gap-2 py-6 text-xs text-foreground-subtle`,children:[a(C,{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(_t,{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 xt({target:e,installing:n,installError:r,onClose:i,onInstall:o}){let{t:c}=Y(),[l,u]=s(e.version),[d,f]=s(!1),p=Ee({name:e.name}),m=K({name:e.name,version:l}),h=p.data??[],g=et(h),_=yt(h,l,d),v=m.data;return a(H,{open:!0,onOpenChange:e=>!e&&i(),children:t(be,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(fe,{children:a(q,{children:c(`addons.installDialog.title`,`Install {{name}}`,{name:vt(e.name)})})}),t(xe,{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(Se,{"aria-label":c(`addons.installDialog.version`,`Version`),value:l,options:_.map(e=>({value:e.version,label:Qe(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(M,{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(J,{defaultValue:`readme`,children:[t(B,{children:[a(N,{value:`readme`,children:c(`addons.installDialog.readme`,`README`)}),a(N,{value:`changelog`,children:c(`addons.installDialog.changelog`,`CHANGELOG`)})]}),a(A,{value:`readme`,children:a(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border bg-background p-3`,children:a(bt,{pending:m.isPending,failed:m.isError,body:v?.readme,missing:c(`addons.installDialog.missingReadme`,`This package has no README.`)})})}),a(A,{value:`changelog`,children:a(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border bg-background p-3`,children:a(bt,{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(_e,{children:[a(M,{type:`button`,variant:`outline`,size:`sm`,onClick:i,children:c(`common.cancel`,`Cancel`)}),a(M,{type:`button`,size:`sm`,disabled:n||l.length===0,onClick:()=>o(e.name,l),children:n?a(C,{className:`h-3.5 w-3.5 animate-spin`}):c(`addons.installDialog.install`,`Install`)})]})]})})}var St=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/ui-library`,`@camstack/addon-agent-ui`]);function Ct(e,t){let n=new Map;for(let r of e){if(r.isHub||r.onHub||St.has(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 wt({selectedNode:e}){let{t:n}=Y(),{data:r}=ie(Je,{staleTime:Ye});if(r===void 0)return null;let i=Ct(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(f,{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(Ze,{packageName:n.packageName,displayName:n.packageName,selectedNode:e,hideNodeAction:e.isHub})]},n.packageName))]})}function Tt({addon:e,installing:n,onInstall:r}){let{t:i}=Y();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(g,{className:`h-3 w-3`}),children:e.installedVersion??i(`system.capabilityCatalog.installed`,`Installed`)}):t(M,{size:`sm`,onClick:()=>r(e),disabled:n,className:`shrink-0`,children:[n?a(C,{className:`h-3 w-3 animate-spin`}):a(v,{className:`h-3 w-3`}),i(`system.capabilityCatalog.install`,`Install`)]})]})}function Et({capability:e,installing:n,onInstall:r}){let{t:i}=Y(),{data:o,isPending:s,isError:c}=k({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(C,{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(Tt,{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 Dt(e){return e===`npm`||e===`dev`?e:null}var Ot=`rounded-full border border-primary bg-primary/10 px-2 py-0.5 text-[10px] text-foreground`,kt=`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-muted hover:bg-surface-hover`,At=[{seconds:900,label:`15m`},{seconds:3600,label:`1h`},{seconds:21600,label:`6h`},{seconds:43200,label:`12h`},{seconds:86400,label:`24h`}],jt=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function Mt(e){return e!==void 0&&jt.has(e)}var Nt={id:`hub`,name:`Hub`,isHub:!0,isOnline:!0};function Pt(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function Ft(e){return e===`local`?`dev`:`npm`}function It(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 Lt(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 Rt({addons:c,clusterStatus:u,selectedNode:d,onRefresh:f,listPhase:p}){let{t:m}=Y(),h=l(),[g,_]=s(``),y=e(g),[x,w]=s(!1),T=n(null);o(()=>{if(!x)return;let e=e=>{T.current&&!T.current.contains(e.target)&&w(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[x]);let{data:E}=z({nodeId:d.id}),te=r(()=>{let e=new Map;for(let t of E??[])e.set(t.name,t.latestVersion);return e},[E]),D=r(()=>(E??[]).filter(e=>!e.isSystem).length,[E]),[ne,O]=s(()=>new Set),[re,A]=s(()=>new Map),ie=i(e=>{O(t=>new Set(t).add(e))},[]),ae=i(e=>{O(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),oe=i((e,t)=>{A(n=>new Map(n).set(e,t))},[]),j=i(e=>{A(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),M=F({onMutate:e=>{ie(e.name),j(e.name)},onSuccess:(e,t)=>{ae(t.name);let n=e;if(n&&n.success===!1){oe(t.name,n.error??`Update failed (no error message returned by server)`);return}h.invalidateQueries({queryKey:[[`addons`]]}),h.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{ae(t.name),oe(t.name,e instanceof Error?e.message:String(e))}}),N=ze(),P=n(new Set);o(()=>{let e=new Set;for(let[t,n]of N)Le(n)&&e.add(t);let t=[...P.current].some(t=>!e.has(t));P.current=e,t&&(h.invalidateQueries({queryKey:[[`addons`]]}),h.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[N,h]);let{data:I}=ge(void 0),ce=me({onSuccess:()=>{h.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),R=se({onSuccess:()=>{h.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:B,isFetching:fe}=k({query:y||void 0},{enabled:x}),V=L(),{data:H}=de(void 0),he=H?.requestedAt,[_e,U]=s(null),[W,ve]=s(!1);o(()=>{if(H?.kind===`framework-bulk-update`&&H.requestedAt!==_e){U(H.requestedAt),ve(!0);let e=window.setTimeout(()=>ve(!1),6e3);return()=>window.clearTimeout(e)}},[he,_e,H]),ue();let ye=i(async()=>{let e=(E??[]).filter(e=>!e.isSystem);if(e.length!==0){if(!d.isHub){for(let t of e)await M.mutateAsync({name:t.name,version:t.latestVersion,nodeId:d.id});return}await V.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[d.id]})}},[E,d.id,d.isHub,V,M]),[be,G]=s(null),[xe,Se]=s(null),Ce=e=>{Se(null),G(e)},K=pe({onSuccess:()=>{G(null),Se(null),h.invalidateQueries({queryKey:[[`addons`]]}),h.invalidateQueries({queryKey:[[`addonPages`]]}),h.invalidateQueries({queryKey:[[`capabilities`]]}),h.invalidateQueries({queryKey:[[`integrations`]]})},onError:e=>{Se(e instanceof Error?e.message:`Install failed`)}}),[q,we]=s(`type`),[Te,Ee]=s(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),De=e=>{Ee(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[J,X]=Oe(),Z=J.get(`capability`),ke=J.get(`updatable`)===`1`,Ae=J.get(`error`)===`1`,Q=Dt(J.get(`source`)),je=i(e=>{let t=new URLSearchParams(J);e?t.set(`updatable`,`1`):t.delete(`updatable`),X(t,{replace:!0})},[J,X]),Ne=i(e=>{let t=new URLSearchParams(J);e?t.set(`error`,`1`):t.delete(`error`),X(t,{replace:!0})},[J,X]),Pe=i(e=>{let t=new URLSearchParams(J);e===null?t.delete(`source`):t.set(`source`,e),X(t,{replace:!0})},[J,X]),Fe=r(()=>c.filter(e=>Me(e.process)!==null).length,[c]),Ie=r(()=>{let e=c.filter(e=>!Mt(e.manifest.packageName));return d.isHub||(e=e.filter(e=>Pt(e.placement,d.isHub))),Z&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===Z))),ke&&(e=e.filter(e=>{let t=e.manifest.packageName;return t!==void 0&&te.has(t)})),Q!==null&&(e=e.filter(e=>Ft(e.installSource)===Q)),Ae&&(e=e.filter(e=>Me(e.process)!==null)),e},[c,d.isHub,Z,ke,Q,Ae,te]),Re=()=>{let e=new URLSearchParams(J);e.delete(`capability`),X(e,{replace:!0})},Be=Te===`flat`?Ie:Lt(Ie),Ve=r(()=>{let e=[...Be];switch(q){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},[Be,q]);return t(`div`,{className:`space-y-3`,children:[[...re.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:m(`systemPage.addons.updateFailed`,{name:e})}),a(`div`,{className:`text-foreground-subtle font-mono`,children:n})]}),a(`button`,{type:`button`,onClick:()=>j(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:m(`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:m(`admin.system.addons.sort`,`Sort:`)}),t(`select`,{value:q,onChange:e=>we(e.target.value),className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary/50`,children:[a(`option`,{value:`type`,children:m(`admin.system.addons.bundlesFirst`,`Bundles first`)}),a(`option`,{value:`name`,children:m(`admin.system.addons.name`,`Name`)}),a(`option`,{value:`source`,children:m(`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:m(`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(`button`,{type:`button`,onClick:()=>De(e),className:`px-2 py-1 transition-colors capitalize ${Te===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?m(`admin.system.addons.groupMultiAddonPackagesInto`,`Group multi-addon packages into a bundle card`):m(`admin.system.addons.showEveryAddonAsIts`,`Show every addon as its own card`),children:e},e))})]}),d.isHub&&t(`div`,{className:`flex items-center gap-1.5`,children:[a(b,{className:`h-3 w-3 text-foreground-subtle`}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:m(`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(`button`,{type:`button`,onClick:()=>ce.mutate({channel:e}),disabled:ce.isPending,className:`px-2 py-1 transition-colors capitalize ${I?.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))})]}),d.isHub&&t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:m(`admin.system.addons.checkEvery`,`Check every:`)}),a(`select`,{className:`rounded-md border border-border bg-transparent px-1.5 py-1 text-[10px] font-medium text-foreground-subtle`,value:I?.updateCheckIntervalSeconds??21600,disabled:R.isPending||I===void 0,onChange:e=>{I!==void 0&&R.mutate({channel:I.channel,updateCheckIntervalSeconds:Number(e.target.value)})},children:At.map(e=>a(`option`,{value:e.seconds,children:e.label},e.seconds))})]}),D>0&&t(`button`,{type:`button`,onClick:()=>void ye(),disabled:V.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:[V.isPending?a(C,{className:`w-3 h-3 animate-spin`}):a(v,{className:`w-3 h-3`}),V.isPending?m(`admin.system.addons.updating`,`Updating…`):m(`admin.system.addons.updateAll`,`Update All ({{nonSystemUpdateCount}})`,{nonSystemUpdateCount:D})]})]}),t(`div`,{className:`flex flex-wrap items-center gap-1.5`,role:`group`,"aria-label":m(`admin.system.addons.filterInstalledAddons`,`Filter installed addons`),children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:m(`admin.system.addons.filter`,`Filter:`)}),[{id:`updatable`,label:m(`admin.system.addons.updatable`,`Updatable`),pressed:ke,toggle:()=>je(!ke)},{id:`error`,label:m(`admin.system.addons.inError`,`In error ({{count}})`,{count:Fe}),pressed:Ae,toggle:()=>Ne(!Ae)},{id:`npm`,label:`npm`,pressed:Q===`npm`,toggle:()=>Pe(Q===`npm`?null:`npm`)},{id:`dev`,label:m(`admin.system.addons.dev`,`Dev`),pressed:Q===`dev`,toggle:()=>Pe(Q===`dev`?null:`dev`)}].map(e=>a(`button`,{type:`button`,"aria-pressed":e.pressed,onClick:e.toggle,className:e.pressed?Ot:kt,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:T,children:[a(le,{type:`text`,value:g,onChange:e=>{_(e.target.value),w(!0)},onFocus:()=>w(!0),placeholder:m(`admin.system.addons.searchAddonsOnNpm`,`Search addons on npm...`),"aria-label":m(`admin.system.addons.searchAddonsOnNpm2`,`Search addons on npm`),disabled:V.isPending,leftSlot:a(S,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),rightSlot:fe?a(C,{className:`h-3 w-3 animate-spin`}):void 0}),x&&B&&B.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:[B.length>0&&a(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:m(`systemPage.addons.npmResults`,{count:B.length})}),B&&B.length>0&&a(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:B.map(e=>a(Tt,{addon:e,installing:K.isPending,onInstall:e=>Ce({name:e.name,version:e.version,description:e.description})},e.name))})]})]}),a(dt,{onUploadSuccess:()=>{h.invalidateQueries({queryKey:[[`addons`]]}),f()}})]}),Z&&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:m(`admin.system.addons.filteringByCapability`,`Filtering by capability:`)}),a(`span`,{className:`font-mono text-primary font-semibold`,children:Z}),a(`button`,{type:`button`,onClick:Re,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:m(`admin.system.addons.clear`,`Clear`)})]}),Z&&a(Et,{capability:Z,installing:K.isPending,onInstall:e=>Ce({name:e.name,version:e.version,description:e.description})}),Z&&Ie.length>0&&a(`h2`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:m(`admin.system.addons.installed`,`Installed`)}),W&&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 backdrop-blur-sm max-w-sm pointer-events-auto`,children:[a(ee,{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:m(`admin.system.addons.bulkUpdateCompleted`,`Bulk update completed`)}),a(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:m(`admin.system.addons.systemPackagesUpdatedHubRestarted`,`System packages updated — hub restarted successfully.`)})]})]}),p===`pending`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[a(C,{className:`h-3 w-3 animate-spin`}),m(`admin.system.addons.loadingInstalled`,`Loading installed addons…`)]}),p===`error`&&a(`div`,{className:`text-xs text-danger`,children:m(`admin.system.addons.failedToLoadAddons`,`Failed to load addons`)}),p===`ready`&&Ie.length===0&&a(`div`,{className:`text-xs text-foreground-subtle`,children:c.length===0?m(`admin.system.addons.noAddonsInstalled`,`No addons installed`):Z?m(`admin.system.addons.noInstalledAddonDeclaresThe`,`No installed addon declares the "{{capabilityFilter}}" capability. Any addon you can install appears under "Available to install" above.`,{capabilityFilter:Z}):m(`admin.system.addons.noAddonsCompatibleWithPlacement`,`No addons compatible with {{name}} (placement filter active)`,{name:d.name})}),a(`div`,{className:`space-y-1.5`,children:p===`ready`&&Ve.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,n=te.get(t),r=$(e)?e.representative:e,i=n?e=>M.mutate({name:t,version:e,nodeId:d.id}):void 0,o=N.get(t)??null,s=o!==null&&Le(o);return a(lt,{addon:r,clusterStatus:u?.[r.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:n,isUpdating:ne.has(t)||s,jobProgress:o,onUpdate:i,disabledByBulk:V.isPending,selectedNode:d},$(e)?t:e.manifest.id)})}),be!==null&&a(xt,{target:be,installing:K.isPending,installError:xe,onClose:()=>G(null),onInstall:(e,t)=>K.mutate({packageName:e,version:t})})]})}function zt(){let{t:e}=Y(),r=l(),{data:i}=R(void 0),{nodes:s}=G(),{selection:c,selectNode:u,requestedNodeId:d}=je(s.length>0?s:[Nt]),f=c.node??Nt,p=f.id,m=s.length>0?c.staleNodeId:null,{data:h,isLoading:g,isError:_}=Te({nodeId:p}),v=ye(),y=oe(),x=v.isPending||y.isPending,S=async()=>{await v.mutateAsync({nodeId:p}),await y.mutateAsync(),r.invalidateQueries({queryKey:[[`addons`]]})},C=n(v);C.current=v;let ee=n(d??`hub`);o(()=>{C.current.mutate({nodeId:ee.current})},[]);let w=(h??[]).map(It).filter(e=>e!==null);return t(ke,{children:[t(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[a(De,{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:w.length})}),t(`button`,{type:`button`,onClick:()=>void S(),disabled:x,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(b,{className:`w-3 h-3 ${x?`animate-spin`:``}`}),e(`admin.system.addons.checkForUpdates`,`Check for updates`)]})]})]}),a(Q,{staleNodeId:m,shownNodeName:f.name}),a(wt,{selectedNode:f}),a(Rt,{addons:w,clusterStatus:i,selectedNode:f,onRefresh:()=>void S(),listPhase:g?`pending`:_?`error`:`ready`})]})}export{zt 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,t 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{$r as d,D as f,Di as p,Fn as m,G as h,It as g,L as _,Mi as v,On as y,Or as b,Q as x,Wr as S,Xi as C,Xr as w,Yt as T,Zt as E,bn as D,dn as ee,dt as O,fn as k,ji as A,kn as j,or as M,ot as N}from"./player-overlays-Dbv95cvz.js";import{Aa as te,Ar as P,jr as F}from"./client-DvJxGh2F.js";import{n as I,t as L}from"./send-402PlgqT.js";import{t as ne}from"./message-square-plus-C4N5hy0x.js";import{$n as R,$u as re,Cn as z,Dr as B,Er as V,Gn as ie,Gr as H,Or as U,Qr as W,Qu as G,St as K,Un as q,Ur as ae,do as J,ht as oe,kr as Y,pt as se,qu as ce,rt as le,sr as ue,wn as de,xn as X,xt as fe}from"./src-ByunGuTZ.js";import{t as Z}from"./i18n-l_m6iBJW.js";import{t as Q}from"./useTranslation-BJr-n0es.js";import"./mount-BkHlLdb8.js";import{mr as pe,x as me}from"./index-BFjKpxae.js";import{t as he}from"./AdminSectionedPage-B77fFYLu.js";import{t as ge}from"./AdminPage-BBb_f0ke.js";c();var _e=`__redacted__`,ve=[`llm`,`listProfiles`],ye=[`llm`,`listProfileKinds`],be=[`llm`,`getDefaults`],xe=[`llm`,`listRuntimeNodes`],Se=[`llm`,`listModelCatalog`],Ce=[`llm`,`getUsage`],we=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],Te=new Map([[`cloud`,d],[`plug`,y],[`cpu`,w],[`server`,ee],[`sparkles`,E]]);function Ee(e){return Te.get(e)??v}function De(e){return typeof e==`string`&&e.length>0?e:void 0}function Oe(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);return Number.isFinite(t)?t:void 0}}function ke(e){return e===!0}function Ae(e){let t=new Map;for(let n of e){let e=t.get(n.addonId)??[];e.push(n),t.set(n.addonId,e)}return[...t.entries()].map(([e,t])=>({addonId:e,kinds:t}))}var je={deviceNotEligible:{key:`ai.appleNotEligible`,tone:`default`},appleIntelligenceNotEnabled:{key:`ai.appleIntelligenceOff`,tone:`warning`},modelNotReady:{key:`ai.appleModelNotReady`,tone:`warning`},osTooOld:{key:`ai.appleOsTooOld`,tone:`default`},helperMissing:{key:`ai.appleHelperMissing`,tone:`danger`},helperCrashed:{key:`ai.appleHelperCrashed`,tone:`danger`}};function Me(e){let t=t=>({nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleUnknown`,labelDefault:Z.t(`ai.appleUnknown`),detail:t,tone:`default`});if(!e.reachable)return t(e.error??null);let n=e.apple;if(n===void 0)return t(null);switch(n.state){case`available`:return{nodeId:e.nodeId,selectable:!0,labelKey:`ai.appleAvailable`,labelDefault:Z.t(`ai.appleAvailable`),detail:Z.t(n.imageInput?`helpers.aiPage.appleDetailImages`:`helpers.aiPage.appleDetailText`,{version:n.osVersion}),tone:`success`};case`unavailable`:{let t=je[n.reason];return{nodeId:e.nodeId,selectable:!1,labelKey:t.key,labelDefault:Z.t(t.key),detail:n.detail,tone:t.tone}}case`unsupported-platform`:return{nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleNotMac`,labelDefault:Z.t(`ai.appleNotMac`),detail:n.platform,tone:`default`};case`unknown`:return t(n.error)}}var Ne={ready:`success`,downloading:`info`,starting:`info`,stopped:`danger`,crashed:`danger`,failed:`danger`};function Pe(e){return e.reachable?e.status===void 0?`success`:Ne[e.status.state]:`danger`}function Fe(e){if(!e.reachable)return[];let t=[],n=e.apple;if(n?.state===`available`)t.push({id:`apple`,labelKey:`ai.featureApple`,tone:`success`,detail:Me(e).detail}),n.imageInput&&t.push({id:`apple-images`,labelKey:`ai.featureAppleImages`,tone:`success`,detail:null});else if(n?.state===`unavailable`){let n=Me(e);t.push({id:`apple`,labelKey:`ai.featureApple`,tone:n.tone,detail:n.labelDefault})}let r=e.status?.vramBytes;return r!==void 0&&r>0&&t.push({id:`gpu`,labelKey:`ai.featureGpu`,tone:`info`,detail:null}),t}function Ie(){return{temperature:[{type:`slider`,key:`temperature`,label:Z.t(`helpers.aiProfileForm.temperature`),min:0,max:2,step:.1,showValue:!0,showStepper:!0,nullable:!0,nullLabel:`Provider default`,description:Z.t(`helpers.aiProfileForm.temperatureHint`)}],topP:[{type:`slider`,key:`topP`,label:Z.t(`helpers.aiProfileForm.topP`),min:0,max:1,step:.05,showValue:!0,showStepper:!0,nullable:!0,nullLabel:`Provider default`}],topK:[{type:`number`,key:`topK`,label:Z.t(`helpers.aiProfileForm.topK`),min:1}],maxTokens:[{type:`number`,key:`maxTokens`,label:Z.t(`helpers.aiProfileForm.maxTokens`),min:1}],contextLength:[{type:`number`,key:`contextLength`,label:Z.t(`helpers.aiProfileForm.contextLength`),min:512,unit:`tokens`,description:Z.t(`helpers.aiProfileForm.contextLengthHint`)}],systemPrompt:[{type:`textarea`,key:`systemPrompt`,label:Z.t(`helpers.aiProfileForm.systemPrompt`),rows:4,maxLength:4e3,span:2,description:Z.t(`helpers.aiProfileForm.systemPromptHint`)}],timeoutMs:[{type:`number`,key:`timeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutTotal`),min:1e3,default:F.totalMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutTotalHint`)}],connectTimeoutMs:[{type:`number`,key:`connectTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutConnect`),min:500,default:F.connectMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutConnectHint`)}],firstTokenTimeoutMs:[{type:`number`,key:`firstTokenTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutFirstToken`),min:1e3,default:F.firstTokenMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutFirstTokenHint`)}],idleTimeoutMs:[{type:`number`,key:`idleTimeoutMs`,label:Z.t(`helpers.aiProfileForm.timeoutIdle`),min:1e3,default:F.idleMs,unit:`ms`,description:Z.t(`helpers.aiProfileForm.timeoutIdleHint`)}],retry:[{type:`boolean`,key:`retryEnabled`,label:Z.t(`helpers.aiProfileForm.retry`),description:Z.t(`helpers.aiProfileForm.retryHint`)},{type:`number`,key:`retryMaxAttempts`,label:Z.t(`helpers.aiProfileForm.retryMaxAttempts`),min:1,max:5,default:1,showWhen:{field:`retryEnabled`,equals:!0}}],toolsEnabled:[{type:`boolean`,key:`toolsEnabled`,label:Z.t(`helpers.aiProfileForm.toolsEnabled`),description:Z.t(`helpers.aiProfileForm.toolsEnabledHint`)}]}}var Le=[`temperature`,`topP`,`topK`,`maxTokens`,`contextLength`,`systemPrompt`],Re=[`timeoutMs`,`connectTimeoutMs`,`firstTokenTimeoutMs`,`idleTimeoutMs`,`retry`,`toolsEnabled`];function ze(e,t){let n=Ie();return t.filter(t=>e.includes(t)).flatMap(e=>n[e])}function Be(e){let t=ze(e,Le);return t.length===0?null:{sections:[{id:`generation`,title:Z.t(`helpers.aiProfileForm.generation`),fields:t}]}}function Ve(e){let t=ze(e,Re);return t.length===0?null:{sections:[{id:`bounds`,title:Z.t(`helpers.aiProfileForm.bounds`),fields:t}]}}function He(e){return e===null?{}:{temperature:e.temperature,topP:e.topP,topK:e.topK,maxTokens:e.maxTokens,contextLength:e.contextLength,systemPrompt:e.systemPrompt,timeoutMs:e.timeoutMs,connectTimeoutMs:e.connectTimeoutMs,firstTokenTimeoutMs:e.firstTokenTimeoutMs,idleTimeoutMs:e.idleTimeoutMs,retryEnabled:e.retry.enabled,retryMaxAttempts:e.retry.maxAttempts,toolsEnabled:e.toolsEnabled}}function Ue(e,t){return{...e.features,...t?.features}}function We(e,t){return t===null?e.modelCatalog===`static`?e.staticModels??[]:[]:t}function Ge(e,t,n){let r=e.profileFields,i=n.common,a=(e,t,n)=>r.includes(e)?Oe(i[e])??t:n??t,o=e=>r.includes(e)?Oe(i[e]):t?.[e],s=o(`temperature`),c=o(`topP`),l=o(`topK`),u=o(`maxTokens`),d=o(`contextLength`),f=r.includes(`systemPrompt`)?De(i.systemPrompt):t?.systemPrompt;return{id:t?.id??crypto.randomUUID(),name:n.name,kind:e.kind,addonId:e.addonId.length>0?e.addonId:`ai`,enabled:t?.enabled??!0,model:n.model,supportsVision:n.supportsVision,timeoutMs:a(`timeoutMs`,F.totalMs,t?.timeoutMs),connectTimeoutMs:a(`connectTimeoutMs`,F.connectMs,t?.connectTimeoutMs),firstTokenTimeoutMs:a(`firstTokenTimeoutMs`,F.firstTokenMs,t?.firstTokenTimeoutMs),idleTimeoutMs:a(`idleTimeoutMs`,F.idleMs,t?.idleTimeoutMs),retry:r.includes(`retry`)?{enabled:ke(i.retryEnabled),maxAttempts:Oe(i.retryMaxAttempts)??1}:t?.retry??{enabled:!1,maxAttempts:1},toolsEnabled:r.includes(`toolsEnabled`)?ke(i.toolsEnabled):t?.toolsEnabled??!1,...s===void 0?{}:{temperature:s},...c===void 0?{}:{topP:c},...l===void 0?{}:{topK:l},...u===void 0?{}:{maxTokens:u},...d===void 0?{}:{contextLength:d},...f===void 0?{}:{systemPrompt:f},providerConfig:n.providerConfig}}var Ke=2e3;function $(e){return Z.t(`system.aiModelPicker.sizeGb`,{value:(e/1e9).toFixed(2)})}function qe(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Je({nodeId:t,value:r,onChange:a}){let{t:c}=Q(),u=N(),[d,f]=o(``),[p,m]=o(null),[h,g]=o(!1),_=s({queryKey:Se,queryFn:()=>u.trpcClient.llm.listModelCatalog.query({})}),v=s({queryKey:[`llm`,`listNodeModels`,t],queryFn:()=>u.trpcClient.llm.listNodeModels.query({nodeId:t})}),y=l({mutationFn:e=>u.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{m(e),g(!1),e.ok&&a({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),b=l({mutationFn:e=>u.trpcClient.llm.installModel.mutate({nodeId:t,model:e}),onSuccess:()=>{g(!0),v.refetch()}}),x=s({queryKey:xe,enabled:b.isPending,refetchInterval:b.isPending?Ke:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(e=>e.nodeId===t)?.status?.download,C=n(()=>{let e=(_.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${$(e.sizeBytes)}`})),n=(v.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:$(e.sizeBytes),node:t})})),r=p?.ok===!0?[{value:`custom`,label:`${p.label} · ${$(p.totalBytes)}`}]:[];return[{value:``,label:c(`ai.selectModel`,`Select a model…`)},...e,...n,...r]},[_.data,v.data,p,t,c]),w=e=>{if(e===``){a(null);return}if(e===`custom`){if(p?.ok!==!0)return;a({model:p.model,modelId:p.label,supportsVision:p.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),n=_.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=v.data?.find(e=>e.file===t);n?.path!==void 0&&a({model:{kind:`path`,path:n.path},modelId:t,supportsVision:!1})},T=e=>{d.trim()!==``&&y.mutate({ref:d.trim(),...e===void 0?{}:{maxBytes:e}})};return e(`div`,{className:`space-y-3`,children:[i(K,{label:c(`ai.model`,`Model`),required:!0,children:i(ce,{id:`ai-model`,"aria-label":c(`ai.model`,`Model`),value:qe(r),options:C,onChange:e=>w(e.target.value)})}),i(K,{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(G,{"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(),T())}}),e(H,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||y.isPending,onClick:()=>T(),children:[y.isPending?i(M,{className:`h-3.5 w-3.5 animate-spin`}):i(k,{className:`h-3.5 w-3.5`}),c(`ai.hfCheck`,`Check`)]})]})}),y.isError&&i(V,{message:y.error instanceof Error?y.error.message:c(`common.error`,`Error`)}),p?.ok===!1&&i(V,{message:p.message,action:e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(p.candidates??[]).map(e=>i(H,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{let t=`${d.trim().split(`:`)[0]??``}:${e}`;f(t),y.mutate({ref:t})},children:e},e)),p.requiredBytes!==void 0&&i(H,{size:`sm`,variant:`secondary`,type:`button`,onClick:()=>T(p.requiredBytes),children:c(`ai.hfOverride`,`Install anyway ({{size}})`,{size:$(p.requiredBytes)})})]})}),p?.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:p.label}),i(W,{variant:p.purpose===`vision`?`info`:`default`,children:p.purpose}),i(W,{variant:`default`,children:$(p.totalBytes)})]}),p.extraFilenames.length>0&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:c(`ai.hfExtras`,`Also downloads: {{files}}`,{files:p.extraFilenames.join(`, `)})}),e(`div`,{className:`flex items-center gap-2`,children:[e(H,{size:`sm`,type:`button`,disabled:b.isPending||h,onClick:()=>b.mutate(p.model),children:[b.isPending?i(M,{className:`h-3.5 w-3.5 animate-spin`}):i(S,{className:`h-3.5 w-3.5`}),h?c(`ai.hfInstalled`,`Downloaded`):c(`ai.hfInstall`,`Download to {{node}}`,{node:t})]}),x!==void 0&&i(`span`,{className:`text-[10px] text-foreground-subtle`,children:x.phase===`verifying`?c(`ai.hfVerifying`,`verifying {{file}}…`,{file:x.file}):c(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:x.file,index:x.fileIndex,count:x.fileCount,done:$(x.downloadedBytes),total:x.totalBytes===void 0?``:` / ${$(x.totalBytes)}`})})]}),b.isError&&i(V,{message:b.error instanceof Error?b.error.message:c(`common.error`,`Error`)})]})]})}function Ye({value:t,onChange:n}){let{t:r}=Q(),a=N(),o=s({queryKey:xe,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(M,{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(`button`,{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(W,{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 Xe(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Ze({providerConfig:e,onProviderConfigChange:t}){return i(Ye,{value:Xe(e,`nodeId`),onChange:n=>t({...e,nodeId:n})})}function Qe({providerConfig:e,onProviderConfigChange:t,model:n,onModelChange:r}){let a=P.safeParse(e.model),o=a.success?{model:a.data,modelId:n.id,supportsVision:n.supportsVision}:null;return i(Je,{nodeId:Xe(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 $e=new Map([[`ai/apple-node`,Ze],[`ai/managed-model`,Qe]]);function et(e){return $e.get(e)??null}c();function tt({kind:e,className:t}){return i(Ee(e.icon),{className:t,"aria-hidden":!0})}function nt({kinds:e,onPick:t,onCancel:r}){let{t:a}=Q(),o=n(()=>Ae(e),[e]),s=n(()=>new Map(e.map(e=>[`${e.addonId}:${e.kind}`,e])),[e]);return i(oe,{open:!0,onClose:r,title:a(`ai.chooseKind`,`Choose a profile type`),width:`lg`,testId:`ai-kind-picker`,children:i(fe,{emptyMessage:a(`ai.noKinds`,`No AI provider is installed.`),onPick:e=>{let n=s.get(e);n!==void 0&&t(n)},groups:o.map(e=>({id:e.addonId,label:e.addonId,tiles:e.kinds.map(t=>({key:`${e.addonId}:${t.kind}`,label:t.label,testId:`ai-kind-${t.kind}`,icon:i(tt,{kind:t,className:`h-5 w-5 text-foreground-subtle`})}))}))})})}function rt(e){return(e?.sections??[]).flatMap(e=>e.fields)}function it(...e){let t={};for(let n of e)for(let e of rt(n))`default`in e&&e.default!==void 0&&(t[e.key]=e.default);return t}function at(e){return e==null?!1:typeof e==`string`?e.trim().length>0:!0}function ot(e,t){return rt(e).filter(e=>`required`in e&&e.required===!0&&!at(t[e.key])).map(e=>`label`in e&&typeof e.label==`string`?e.label:e.key)}var st={auth:{key:`ai.listAuth`,fallback:`Credentials refused`},network:{key:`ai.listNetwork`,fallback:`Endpoint unreachable`},unsupported:{key:`ai.listUnsupported`,fallback:`No model list`},invalid:{key:`ai.listInvalid`,fallback:`Connection incomplete`}};function ct(e,t){if(t!==null)return{id:t.model,supportsVision:t.supportsVision};let n=e.modelCatalog===`static`&&e.staticModels?.length===1?e.staticModels?.[0]:void 0;return{id:n?.id??``,supportsVision:Ue(e,n).vision}}function lt({kind:t,existing:r,onSave:a,onCancel:s,onChangeKind:c,saving:d,error:p}){let{t:m}=Q(),h=N(),[g,v]=o(r?.name??t.label),[y,b]=o(()=>r===null?it(t.connectionSchema,t.advancedSchema):{...r.providerConfig}),[x,S]=o(()=>He(r)),[w,T]=o(()=>ct(t,r)),[E,ee]=o(!1),O=t.providerWidgets??[],k=O.filter(e=>e.placement===`connection`),A=O.find(e=>e.placement===`model`)??null,j=n(()=>[...te(t.connectionSchema)].some(e=>r?.providerConfig[e]===_e),[r,t.connectionSchema]),P=l({mutationFn:()=>h.trpcClient.llm.listModels.mutate({addonId:t.addonId,kind:t.kind,connection:y,...r===null?{}:{profileId:r.id}}),onSuccess:e=>{e.ok&&T(n=>{let r=e.models.find(e=>e.id===n.id);return r===void 0?n:{id:n.id,supportsVision:Ue(t,r).vision}})}}),F=We(t,P.data?.ok===!0?P.data.models:null),I=F.find(e=>e.id===w.id),L=Ue(t,I),ne=Be(t.profileFields),re=Ve(t.profileFields),z=ot(t.connectionSchema,y),B=O.some(e=>(e.requires??[]).some(e=>!at(y[e]))),ie=t.modelCatalog===`fetch`&&A===null,U=rt(t.connectionSchema).length>0||k.length>0,ae=e=>{T({id:e,supportsVision:Ue(t,F.find(t=>t.id===e)).vision})},J=d||g.trim()===``||w.id.trim()===``||z.length>0||B,Y=()=>{a(Ge(t,r,{name:g.trim(),model:w.id.trim(),supportsVision:t.visionEditable?w.supportsVision:!1,common:x,providerConfig:y}))},se=r===null?m(`ai.newProfile`,`New {{kind}} profile`,{kind:t.label}):m(`ai.editProfile`,`Edit {{name}}`,{name:r.name}),le=e=>{let n=et(e);return n===null?i(V,{variant:`warning`,message:m(`ai.unknownWidget`,`This provider needs an editor part this build does not have ({{id}}).`,{id:e})}):i(n,{descriptor:t,providerConfig:y,onProviderConfigChange:b,model:w,onModelChange:T},e)};return i(oe,{open:!0,onClose:s,title:se,error:p,width:`lg`,testId:`ai-profile-editor`,footer:e(u,{children:[z.length>0&&i(W,{variant:`warning`,children:m(`ai.missingRequired`,`required: {{fields}}`,{fields:z.join(`, `)})}),z.length===0&&B&&i(W,{variant:`warning`,children:m(`ai.completeProvider`,`complete the provider settings`)}),z.length===0&&!B&&w.id.trim()===``&&i(W,{variant:`warning`,children:m(`ai.pickModelFirst`,`pick a model`)}),e(H,{size:`sm`,type:`button`,disabled:J,onClick:Y,children:[d&&i(M,{className:`h-3.5 w-3.5 animate-spin`}),r===null?m(`ai.createProfile`,`Create profile`):m(`ai.saveChanges`,`Save changes`)]})]}),children:e(`div`,{className:_,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`ai-editor-provider`,children:[i(tt,{kind:t,className:`h-4 w-4 text-foreground-subtle`}),i(`span`,{className:`text-xs font-medium text-foreground`,children:t.label}),i(W,{variant:`neutral`,children:t.addonId}),c!==void 0&&e(H,{size:`sm`,variant:`ghost`,type:`button`,onClick:c,children:[i(C,{className:`h-3.5 w-3.5`}),m(`ai.changeKind`,`Change type`)]})]}),i(K,{label:m(`ai.name`,`Name`),required:!0,children:i(G,{id:`ai-profile-name`,"aria-label":m(`ai.name`,`Name`),value:g,onChange:e=>v(e.target.value),placeholder:t.label})}),U&&i(X,{headingId:`ai-editor-connection`,title:m(`ai.sectionConnection`,`Connection`),actions:ie?e(H,{size:`sm`,variant:`secondary`,type:`button`,disabled:P.isPending,onClick:()=>P.mutate(),"data-testid":`ai-verify-models`,children:[P.isPending?i(M,{className:`h-3.5 w-3.5 animate-spin`}):i(D,{className:`h-3.5 w-3.5`}),m(`ai.verifyModels`,`Verify & load models`)]}):void 0,children:e(`div`,{className:`p-2 sm:p-3 lg:p-4 space-y-3`,children:[rt(t.connectionSchema).length>0&&i(ue,{bare:!0,schema:t.connectionSchema,values:y,onChange:b}),k.map(e=>le(e.id)),j&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:m(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)}),P.data?.ok===!0&&i(W,{variant:`success`,"data-testid":`ai-models-found`,children:m(`ai.modelsFound`,`{{count}} models found`,{count:P.data.models.length})}),P.data?.ok===!1&&i(V,{title:m(st[P.data.code]?.key??`ai.listNetwork`,st[P.data.code]?.fallback??`Endpoint unreachable`),message:P.data.message}),P.isError&&i(V,{message:P.error instanceof Error?P.error.message:m(`common.error`,`Error`)})]})}),i(X,{headingId:`ai-editor-model`,title:m(`ai.sectionModel`,`Model`),children:e(`div`,{className:`${f} space-y-3`,children:[A===null?e(u,{children:[F.length>0&&i(ce,{id:`ai-model-pick`,"aria-label":m(`ai.selectModel`,`Select a model…`),value:I===void 0?``:I.id,options:[{value:``,label:m(`ai.selectModel`,`Select a model…`)},...F.map(e=>({value:e.id,label:e.label??e.id}))],onChange:e=>{e.target.value!==``&&ae(e.target.value)}}),i(K,{label:m(`ai.customModel`,`Model id`),description:m(`ai.customModelHint`,`Pick one from the list, or type any model id the provider accepts.`),required:!0,children:i(G,{id:`ai-model-id`,"aria-label":m(`ai.customModel`,`Model id`),value:w.id,onChange:e=>T({...w,id:e.target.value}),placeholder:F[0]?.id??`model-id`})})]}):le(A.id),e(`div`,{className:`flex flex-wrap items-center gap-1.5`,"data-testid":`ai-model-features`,children:[(w.supportsVision||!t.visionEditable&&L.vision)&&i(W,{variant:`info`,children:m(`ai.featureVision`,`vision`)}),L.tools&&i(W,{variant:`neutral`,children:m(`ai.featureTools`,`tools`)}),L.streaming&&i(W,{variant:`neutral`,children:m(`ai.featureStreaming`,`streaming`)})]}),t.visionEditable&&i(K,{orientation:`horizontal`,label:m(`ai.supportsVision`,`Supports vision`),description:m(`ai.supportsVisionHint`,`A vision call against a text-only profile is refused, never downgraded.`),children:i(q,{checked:w.supportsVision,onCheckedChange:e=>T({...w,supportsVision:e}),"aria-label":m(`ai.supportsVision`,`Supports vision`)})})]})}),ne!==null&&i(X,{headingId:`ai-editor-generation`,title:m(`ai.sectionGeneration`,`Generation`),children:i(`div`,{className:`p-2 sm:p-3 lg:p-4`,children:i(ue,{bare:!0,schema:ne,values:x,onChange:S})})}),(re!==null||t.advancedSchema!==void 0)&&i(R,{expanded:E,onExpandedChange:ee,header:i(`span`,{className:`text-[11px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:m(`ai.sectionAdvanced`,`Advanced`)}),children:e(`div`,{className:`p-2 sm:p-3 lg:p-4 space-y-3`,children:[re!==null&&i(ue,{bare:!0,schema:re,values:x,onChange:S}),t.advancedSchema!==void 0&&i(ue,{bare:!0,schema:t.advancedSchema,values:y,onChange:b})]})})]})})}c();function ut(t){return[{key:`name`,header:t.t(`ai.colProfile`,`Profile`),render:n=>{let r=t.kindByName.get(n.kind);return e(`span`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface`,title:r?.label??n.kind,children:r===void 0?i(`span`,{className:`text-xs text-foreground-subtle`,children:`?`}):i(tt,{kind:r,className:`h-4 w-4 text-foreground-subtle`})}),e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block truncate font-medium text-foreground`,children:n.name}),t.testResult?.id===n.id&&i(`span`,{className:`block truncate ${t.testResult.ok?`text-success`:`text-danger`}`,children:t.testResult.text})]})]})}},{key:`kind`,header:t.t(`ai.colKind`,`Kind`),nowrap:!0,render:e=>i(`span`,{className:`text-foreground-muted`,children:t.kindByName.get(e.kind)?.label??e.kind})},{key:`model`,header:t.t(`ai.colModel`,`Model`),render:e=>i(`span`,{className:`text-foreground`,children:e.model})},{key:`vision`,header:t.t(`ai.colVision`,`Vision`),align:`center`,nowrap:!0,render:e=>e.supportsVision?i(W,{variant:`info`,style:`outline`,children:t.t(`ai.vision`,`vision`)}):i(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`node`,header:t.t(`ai.colNode`,`Node`),nowrap:!0,render:e=>typeof e.providerConfig.nodeId==`string`?i(W,{variant:`default`,children:e.providerConfig.nodeId}):i(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`enabled`,header:t.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:e=>i(q,{checked:e.enabled,onCheckedChange:()=>t.onToggle(e),"aria-label":Z.t(`system.aiProfilesTab.toggle`,`toggle {{name}}`,{name:e.name})})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:n=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[i(H,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onTest(n),"aria-label":t.t(`ai.test`,`Test`),title:t.t(`ai.test`,`Test`),children:t.testingId===n.id?i(M,{className:`h-3.5 w-3.5 animate-spin`}):i(L,{className:`h-3.5 w-3.5`})}),i(H,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t.kindByName.has(n.kind),onClick:()=>t.onEdit(n),"aria-label":t.t(`common.edit`,`Edit`),title:t.t(`common.edit`,`Edit`),children:i(m,{className:`h-3.5 w-3.5`})}),i(H,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>t.onDelete(n),"aria-label":t.t(`common.delete`,`Delete`),title:t.t(`common.delete`,`Delete`),children:i(g,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function dt(){let{t}=Q(),c=N(),{state:u,openEdit:d,close:p}=se(),m=ae(),[h,g]=o(null),[v,y]=o(null),[b,x]=o(null),S=s({queryKey:ve,queryFn:()=>c.trpcClient.llm.listProfiles.query({})}),C=s({queryKey:ye,queryFn:async()=>(await c.trpcClient.llm.listProfileKinds.query({})).map(({connectionSchema:e,advancedSchema:t,...n})=>({...n,connectionSchema:e,...t===void 0?{}:{advancedSchema:t}}))}),w=()=>{S.refetch()},T=r(()=>{g(null),x(null),p()},[p]);a(()=>{u.mode===`closed`&&g(null)},[u.mode]);let D=l({mutationFn:e=>c.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{T(),w()},onError:e=>x(e instanceof Error?e.message:t(`ai.saveFailed`,`Save failed`))}),ee=l({mutationFn:e=>c.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:w}),O=l({mutationFn:e=>c.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>y({id:t.id,ok:e.ok,text:e.ok?Z.t(`system.aiProfilesTab.testOk`,{text:e.text,tokens:e.usage.outputTokens,ms:e.latencyMs}):`${e.code}: ${e.message}`})}),k=S.data??[],A=n(()=>C.data??[],[C.data]),j=n(()=>{let e=new Map;for(let t of A)e.set(t.kind,t);return e},[A]),M=u.mode===`edit`?k.find(e=>e.id===u.id)??null:null,te=M===null?null:j.get(M.kind)??null,P=u.mode===`new`&&h===null,F=u.mode===`new`?h:te,I=u.mode===`edit`?M:null,L=F!==null&&(u.mode===`new`||I!==null),ne=async e=>{await m({title:t(`ai.deleteProfileTitle`,`Delete profile?`),message:t(`ai.deleteProfileMessage`,`Delete "{{name}}". Features that name it will no longer get an answer from it.`,{name:e.name}),confirmLabel:t(`common.delete`,`Delete`),variant:`danger`})&&ee.mutate(e)};return e(`div`,{className:_,children:[i(ft,{profiles:k}),i(X,{headingId:`ai-profiles-list`,title:t(`ai.profilesList`,`Profiles`),children:S.isPending?e(`div`,{className:`${f} space-y-2`,"data-testid":`ai-profiles-loading`,children:[i(Y,{className:`h-8 w-full`}),i(Y,{className:`h-8 w-full`}),i(Y,{className:`h-8 w-full`})]}):S.isError?i(`div`,{className:f,children:i(V,{title:t(`ai.loadFailed`,`Failed to load profiles`),message:S.error instanceof Error?S.error.message:t(`common.error`,`Error`),onRetry:()=>void S.refetch()})}):k.length===0?i(B,{icon:E,title:t(`ai.noProfilesTitle`,`No AI profiles yet`),description:t(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}):i(z,{columns:ut({kindByName:j,testResult:v,testingId:O.isPending?O.variables?.id??null:null,t,onToggle:e=>D.mutate({...e,enabled:!e.enabled}),onTest:e=>O.mutate(e),onEdit:e=>{j.has(e.kind)&&(x(null),g(null),d(e.id))},onDelete:e=>void ne(e)}),rows:k,rowKey:e=>e.id,minWidthPx:760,bordered:!1,maxBodyHeight:de})}),P&&i(nt,{kinds:A,onCancel:T,onPick:e=>{x(null),g(e)}}),L&&F!==null&&i(lt,{kind:F,existing:I,saving:D.isPending,error:b,onSave:e=>D.mutate(e),onCancel:T,...u.mode===`new`?{onChangeKind:()=>{x(null),g(null)}}:{}})]})}function ft({profiles:t}){let{t:n}=Q(),r=N(),a=s({queryKey:be,queryFn:()=>r.trpcClient.llm.getDefaults.query({})}),o=l({mutationFn:e=>r.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??``,u=e=>e===`vision`?n(`ai.defaultVision`,`Default vision profile`):n(`ai.defaultText`,`Default text profile`);return i(X,{headingId:`ai-profiles-defaults`,title:n(`ai.defaultsTitle`,`Defaults`),children:i(`div`,{className:`${f} grid gap-4 sm:grid-cols-2`,children:we.map(({purpose:r,visionOnly:a})=>{let s=a?t.filter(e=>e.supportsVision):t,l=c(r),d=t.find(e=>e.id===l);return e(`div`,{children:[i(ie,{className:`mb-1 block`,htmlFor:`llm-default-${r}`,children:u(r)}),i(ce,{id:`llm-default-${r}`,"aria-label":u(r),value:l,onChange:e=>o.mutate({purpose:r,profileId:e.target.value===``?null:e.target.value}),options:[{value:``,label:n(`ai.none`,`None`)},...l!==``&&!s.some(e=>e.id===l)?[{value:l,label:d?.name??l}]:[],...s.map(e=>({value:e.id,label:`${e.name} · ${e.model}`}))]}),l!==``&&d===void 0&&i(`p`,{className:`mt-1 text-xs text-danger`,children:n(`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:n(`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)})]},r)})})})}c();var pt=5e3;function mt(e){return Z.t(`system.aiRuntimes.sizeGb`,{value:(e/1e9).toFixed(1)})}function ht(){let{t}=Q(),r=N(),a=s({queryKey:xe,refetchInterval:pt,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(W,{variant:Pe(n),children:n.reachable?n.status?.state??t(`ai.ready`,`ready`):t(`ai.unreachable`,`unreachable`)}),n.status?.downloadProgress!==void 0&&i(W,{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?`—`:mt(e.disk.modelsBytes)})},{key:`features`,header:t(`ai.colFeatures`,`Features`),render:n=>{let r=Fe(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(W,{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(X,{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(Y,{className:`h-8 w-full`}),i(Y,{className:`h-8 w-full`})]}):a.isError?i(`div`,{className:f,children:i(V,{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(B,{icon:ee,title:t(`ai.noRuntimesTitle`,`No runtime nodes`),description:t(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):i(z,{columns:o,rows:c,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,maxBodyHeight:de})})}var gt=x(`/addon/ai/test-chat`),_t=x(`/addon/ai/test-chat/chats`),vt=6e5;function yt(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),vt)}function bt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function xt(e){if(!bt(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 St=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function Ct(e){let t;try{t=JSON.parse(e)}catch{return null}if(!bt(t))return null;switch(t.kind){case`status`:{let e=St.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:xt(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:Z.t(`helpers.aiTestChat.providerError`)};default:return null}}async function*wt(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=Ct(e);t!==null&&(yield t)}a=r.indexOf(`
|
|
3
|
-
`)}}let e=r.trim();if(e.length>0){let t=Ct(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function Tt(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function Et(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function Dt(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 Ot(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 kt(e,t){switch(e){case`resolving-image`:return Z.t(`helpers.aiTestChat.phaseImage`);case`connecting`:return Z.t(`helpers.aiTestChat.phaseConnecting`);case`first-token-wait`:return t>0?Z.t(`helpers.aiTestChat.phaseWaitUpTo`,{seconds:Math.round(t/1e3)}):Z.t(`helpers.aiTestChat.phaseWait`);case`streaming`:return Z.t(`helpers.aiTestChat.phaseAnswering`)}}c();var At=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],jt=360*60*1e3,Mt=40,Nt=160,Pt={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function Ft(){let{t:c}=Q(),l=N(),[u,d]=o(``),[m,h]=o(``),[v,y]=o(``),[b,x]=o([]),[S,C]=o(null),[w,E]=o(`none`),[D,ee]=o(`throwaway`),[k,j]=o(null),[M,te]=o([]),[P,F]=o(null),[I,R]=o(null),z=t(null);a(()=>()=>z.current?.abort(),[]);let B=r(async()=>{let e=await fetch(_t,{credentials:`same-origin`});e.ok&&te((await e.json()).chats??[])},[]);a(()=>{D===`persistent`&&B()},[D,B]);let U=s({queryKey:ve,queryFn:()=>l.trpcClient.llm.listProfiles.query({})}),W=n(()=>(U.data??[]).filter(e=>e.enabled),[U.data]),K=W.find(e=>e.id===u)??null,q=I!==null,ae=r(async(e,t)=>{let n=new AbortController;z.current=n,F(null);let r=yt(K??{});R({...Pt,firstTokenTimeoutMs:r??0});let i=``,a=null,o,s=null,l=null,d;try{let c=await fetch(gt,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:n.signal,body:JSON.stringify({profileId:u,messages:e,...m.trim()===``?{}:{system:m.trim()},...t===void 0?{}:{attachment:t},...r===void 0?{}:{firstTokenTimeoutMs:r},...D===`persistent`?{persist:!0,...k===null?{}:{conversationId:k}}:{}})});if(!c.ok||c.body===null){let e=await c.text().catch(()=>``);throw Error(e.length>0?e:`HTTP ${String(c.status)}`)}for await(let e of wt(c.body))switch(e.kind){case`status`:R(t=>({...t??Pt,phase:e.phase}));break;case`meta`:a=e.mediaSent,o=e.model,R(t=>({...t??Pt,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:i+=e.text,R(e=>({...e??Pt,text:i}));break;case`done`:l={outputTokens:e.outputTokens,latencyMs:e.latencyMs},d=e.conversationId;break;case`error`:s=`${e.code}: ${e.message}`;break}}catch(e){n.signal.aborted||F(e instanceof Error?e.message:c(`common.error`,`Error`))}finally{z.current=null,R(null)}d!==void 0&&(j(d),B());let f=n.signal.aborted&&i.length>0;s===null&&i.length===0&&!f||x(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:s??i,...s===null?{}:{failed:!0},...a===null?{}:{attachment:a},...o!==void 0&&s===null?{model:o}:{},...l===null?{}:l}])},[D,k,K,u,B,m,c]),J=r(()=>{let e=v.trim();if(e===``||u===``||q)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...S===null?{}:{attachmentLabel:S.label,attachmentKind:S.ref.kind}},n=[...b,t];x(n),y(``);let r=S?.ref;C(null),E(`none`),ae(D===`persistent`&&k!==null?[{role:`user`,content:e}]:Tt(n),r)},[D,k,v,S,u,ae,q,b]),oe=()=>z.current?.abort(),Y=()=>{z.current?.abort(),x([]),C(null),y(``),F(null),R(null),j(null)},se=async e=>{z.current?.abort();let t=await fetch(`${_t}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();j(e),x(Dt(n)),R(null),F(null)};return e(`div`,{className:_,children:[i(X,{headingId:`ai-test-setup`,title:c(`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(ie,{className:`mb-1 block`,htmlFor:`ai-test-profile`,children:c(`ai.profile`,`Profile`)}),i(ce,{id:`ai-test-profile`,value:u,onChange:e=>d(e.target.value),options:[{value:``,label:c(`ai.selectProfile`,`Select a profile…`)},...W.map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.supportsVision?` · vision`:``}`}))]}),W.length===0&&!U.isLoading&&i(`p`,{className:`mt-1 text-xs text-foreground-subtle`,children:c(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),e(`div`,{children:[i(ie,{className:`mb-1 block`,htmlFor:`ai-test-system`,children:c(`ai.systemPrompt`,`System prompt (optional)`)}),i(G,{id:`ai-test-system`,value:m,onChange:e=>h(e.target.value),placeholder:c(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),i(le,{label:c(`ai.chatMode`,`Conversation mode`),value:D,options:[{value:`throwaway`,label:c(`ai.throwawayMode`,`Throwaway`)},{value:`persistent`,label:c(`ai.saveConversation`,`Save conversation`)}],onChange:e=>{ee(e),e===`throwaway`&&j(null)}}),D===`persistent`&&e(`div`,{className:`space-y-2`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:c(`ai.testSubtitlePersistent`,`Conversations are saved for you and can be reopened. Throwaway mode is still available.`)}),e(H,{size:`sm`,variant:`secondary`,type:`button`,onClick:Y,children:[i(ne,{className:`h-3.5 w-3.5`}),c(`ai.newChat`,`New chat`)]}),M.length>0&&i(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:M.map(e=>i(`button`,{type:`button`,onClick:()=>void se(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-xs hover:bg-surface-hover ${e.id===k?`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:c(`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.`)}),K!==null&&!K.supportsVision&&i(`p`,{className:`text-xs text-warning`,children:c(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]})}),P!==null&&i(V,{title:c(`ai.chatFailed`,`The test call failed`),message:P}),e(X,{headingId:`ai-test-conversation`,title:c(`ai.testConversation`,`Conversation`),actions:e(H,{size:`sm`,variant:`ghost`,type:`button`,disabled:b.length===0&&S===null,onClick:Y,children:[i(g,{className:`h-3.5 w-3.5`}),c(`ai.clearChat`,`Clear`)]}),children:[i(It,{turns:b,live:I}),e(`div`,{className:`${f} space-y-2 border-t border-border`,children:[S!==null&&e(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-background px-2.5 py-1.5`,children:[S.ref.kind===`snapshot`?i(p,{className:`h-3.5 w-3.5 text-foreground-subtle`}):i(A,{className:`h-3.5 w-3.5 text-foreground-subtle`}),i(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:S.label}),i(re,{size:`sm`,variant:`ghost`,type:`button`,icon:O,"aria-label":c(`ai.removeAttachment`,`Remove attachment`),onClick:()=>C(null)})]}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(H,{size:`sm`,variant:w===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>E(w===`snapshot`?`none`:`snapshot`),children:[i(p,{className:`h-3.5 w-3.5`}),c(`ai.attachSnapshot`,`Camera snapshot`)]}),e(H,{size:`sm`,variant:w===`track`?`primary`:`outline`,type:`button`,onClick:()=>E(w===`track`?`none`:`track`),children:[i(A,{className:`h-3.5 w-3.5`}),c(`ai.attachTrack`,`Recent track`)]})]}),w===`snapshot`&&i(zt,{onPick:e=>{C({ref:{kind:`snapshot`,deviceId:e.id},label:c(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:e.name})}),E(`none`)}}),w===`track`&&i(Vt,{onPick:(e,t)=>{C({ref:{kind:`track`,trackId:e.trackId,deviceId:e.deviceId},label:c(`ai.trackOf`,`{{class}} on {{name}}`,{class:e.label??e.className,name:t})}),E(`none`)}}),e(`div`,{className:`flex items-center gap-2`,children:[i(G,{value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),J())},placeholder:c(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":c(`ai.message`,`Message`)}),q?e(H,{size:`sm`,variant:`secondary`,type:`button`,onClick:oe,children:[i(T,{className:`h-3.5 w-3.5`}),c(`ai.stop`,`Stop`)]}):e(H,{size:`sm`,type:`button`,disabled:v.trim()===``||u===``,onClick:J,children:[i(L,{className:`h-3.5 w-3.5`}),c(`ai.send`,`Send`)]})]})]})]})]})}function It({turns:t,live:n}){let{t:r}=Q();return t.length===0&&n===null?i(B,{icon:I,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(Lt,{turn:e},e.id)),n!==null&&e(`div`,{className:`space-y-1`,children:[n.mediaSent!==null&&i(Rt,{attachment:n.mediaSent}),n.text.length>0&&i(Lt,{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(M,{className:`h-3.5 w-3.5 animate-spin`}),kt(n.phase,n.firstTokenTimeoutMs)]})]})]})}function Lt({turn:t,streaming:n=!1}){let{t:r}=Q(),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(Rt,{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(A,{className:`h-3 w-3`}):i(p,{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(p,{className:`h-3 w-3`}):i(A,{className:`h-3 w-3`}),Ot(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 Rt({attachment:e}){let{t}=Q(),n=Et(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 zt({onPick:e}){let{t}=Q(),n=J({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?i(M,{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(Bt,{device:t,onPick:e},t.id))})}function Bt({device:t,onPick:n}){let{t:r}=Q(),{src:a}=h(t.id,{width:Nt});return e(`button`,{type:`button`,onClick:()=>n(t),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:a!==null&&i(`img`,{src:a,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(W,{variant:`warning`,children:r(`common.off`)}),i(`span`,{className:`truncate text-[10px] text-foreground`,children:t.name})]})]})}function Vt({onPick:t}){let{t:r}=Q(),a=N(),o=J({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:[...At,c.length],enabled:c.length>0,queryFn:()=>a.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...c],since:Date.now()-jt,limit:Mt,projection:`slim`})});if(o.isLoading||u.isLoading)return i(M,{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(A,{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 Ht=1440*60*1e3,Ut=[1,7,30,90];function Wt(){let{t}=Q(),r=N(),[a,c]=o(7),l=n(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(a-1)*Ht},[a]),u=s({queryKey:ve,queryFn:()=>r.trpcClient.llm.listProfiles.query({})}),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(ce,{"aria-label":t(`ai.window`,`Window`),value:String(a),options:Ut.map(e=>({value:String(e),label:t(`ai.lastDays`,`Last {{days}} days`,{days:e})})),onChange:e=>c(Number(e.target.value))})});return i(X,{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(Y,{className:`h-8 w-full`}),i(Y,{className:`h-8 w-full`}),i(Y,{className:`h-8 w-full`})]}):d.isError?i(`div`,{className:f,children:i(V,{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(B,{icon:b,title:t(`ai.noUsage`,`No AI calls in this window.`)}):i(z,{columns:m,rows:h,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,maxBodyHeight:de})})}var Gt=`llm`,Kt=[`profiles`,`runtimes`,`usage`,`test`],qt=[`new`,`edit`];function Jt(e){return Kt.some(t=>t===e)}function Yt(){let{t}=Q(),n=U(Gt),[r]=pe(),{openNew:a}=se(),o=me(`/system/ai`,{t,isAdmin:!0})??{icon:E,title:t(`system.ai`,`AI`)};if(n!==`present`)return i(ge,{icon:o.icon,title:o.title,children:i(Xt,{presence:n})});let s=r.get(`tab`),c=Jt(s)?s:`profiles`,l={profiles:t(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),runtimes:t(`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:t(`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:t(`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.`)},u=c===`profiles`?e(H,{size:`sm`,type:`button`,"data-testid":`ai-add-profile`,onClick:a,children:[i(j,{className:`h-3.5 w-3.5`}),t(`ai.addProfile`,`Add profile`)]}):void 0;return i(he,{icon:o.icon,title:o.title,subtitle:l[c],actions:u,defaultSection:`profiles`,sectionsLabel:`${o.title} sections`,sections:[{id:`profiles`,label:t(`ai.tabProfiles`,`Profiles`),content:i(dt,{}),ownedParams:qt},{id:`runtimes`,label:t(`ai.tabRuntimes`,`Runtimes`),content:i(ht,{})},{id:`usage`,label:t(`ai.tabUsage`,`Usage`),content:i(Wt,{})},{id:`test`,label:t(`ai.tabTest`,`Test`),content:i(Ft,{})}]})}function Xt({presence:t}){let{t:n}=Q();return t===`pending`?e(`div`,{className:`space-y-3`,"data-testid":`ai-presence-pending`,children:[i(Y,{className:`h-8 w-64`}),i(Y,{className:`h-40 w-full`})]}):t===`unknown`?i(V,{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(B,{icon:E,title:n(`ai.absentTitle`,`AI is not installed`),description:n(`ai.absentDescription`,`Install the AI addon from System → Addons to add model profiles.`)})}export{Yt as AiProfilesPage,Yt as default};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{C as e,K as t,R as n,S as r,V as i,Y as a,et as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{An as l,D as u,Fn as d,Gi as f,It as p,Jr as m,Nt as h,Q as g,Wr as _,Xi as v,Yi as y,Zr as b,ai as x,fn as S,ir as C,kn as w,or as T,pi as E,rr as D,si as O,vn as k,xi as A,yi as j}from"./player-overlays-Dbv95cvz.js";import{n as M,t as N}from"./cloud-upload-M9JxZe_d.js";import{t as P}from"./circle-slash-CaxGVwz5.js";import{t as F}from"./hard-drive-download-iRJR_Xj9.js";import{$i as I,$u as L,Cn as R,Dr as z,Er as B,Gi as ee,Gl as te,Gr as V,Hn as ne,Ji as re,Ki as ie,Kl as ae,Ml as oe,Oi as se,Qi as ce,Qu as le,St as H,Ul as ue,Ur as U,Vn as de,Wi as fe,Wl as pe,Wn as me,Xa as he,Xi as ge,Yi as _e,Zi as ve,_r as ye,aa as be,au as xe,ea as Se,fr as Ce,gr as we,ht as Te,ia as Ee,lt as De,mr as Oe,mt as ke,na as Ae,pr as je,pt as Me,qi as Ne,qu as Pe,ra as Fe,ta as Ie,vr as Le,wn as Re,zn as ze}from"./src-ByunGuTZ.js";import{t as W}from"./i18n-l_m6iBJW.js";import{t as G}from"./useTranslation-BJr-n0es.js";import"./mount-BkHlLdb8.js";import{dr as Be,lr as Ve,mr as He,x as Ue}from"./index-BFjKpxae.js";import{t as We}from"./AdminSectionedPage-B77fFYLu.js";import{t as Ge}from"./AdminPage-BBb_f0ke.js";import{n as Ke}from"./authed-media-B_8ON2MT.js";import{t as K}from"./format-size-DIxKXxtj.js";import{a as qe,c as Je,l as Ye,n as Xe,o as Ze,s as Qe,t as $e,u as et}from"./location-owned-usage-uS8d4cQL.js";o();function tt(){let{t:n}=G(),a=s(),o=U(),{data:c,isLoading:l,isError:u}=ae({}),d=te(),f=t(()=>d.data??[],[d.data]),{data:p}=oe({},{refetchOnWindowFocus:!1}),m=t(()=>$e(c??[],p?.locations),[c,p?.locations]),{data:h}=pe({},{refetchOnWindowFocus:!1}),g=t(()=>qe(h),[h]),{state:_,openNew:v,openEdit:y,close:b}=Me(),[x,S]=ke(`type`),C=()=>{S(null),b()},w=e=>{S(e),v()},T=e=>{S(null),y(e.id)},E=c??[],D=_.mode===`edit`?E.find(e=>e.id===_.id)??null:null;i(()=>{_.mode===`new`&&(x===null||x===``)&&(S(null),b())},[_.mode,x,b,S]),i(()=>{_.mode===`edit`&&!l&&D===null&&(S(null),b())},[_.mode,l,D,b,S]),i(()=>{_.mode===`closed`&&x!==null&&S(null)},[_.mode,x,S]);let O=ue({onSuccess:()=>{a.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),k=xe({onSuccess:()=>{a.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),A=async(e,t)=>{Ye(t)&&!await o({title:n(`system.storage.disable`,`Disable "{{displayName}}"?`,{displayName:e.displayName}),message:n(`system.storage.nothingIsDeletedSetThe`,`{{consequence}} Nothing is deleted — set the location back to Read-only or Active to bring its footage back.`,{consequence:Je(t).consequence}),confirmLabel:n(`common.disable`,`Disable`),variant:`danger`})||k.mutate(Qe(e,{mode:t}))},j=async e=>{if(await o({title:n(`system.storage.deleteLocation`,`Delete location "{{displayName}}"?`,{displayName:e.displayName}),message:n(`system.storage.thisRemovesTheLocationRecord`,`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`),confirmLabel:n(`common.delete`,`Delete`),variant:`danger`}))try{await O.mutateAsync({id:e.id}),_.mode===`edit`&&_.id===e.id&&C()}catch(t){await o({title:n(`system.storage.deleteAnyway`,`Delete anyway?`),message:n(`system.storage.forcingNote`,{error:t instanceof Error?t.message:String(t)}),confirmLabel:n(`system.storage.forceDelete`,`Force delete`),variant:`danger`})&&O.mutate({id:e.id,force:!0},{onSuccess:()=>{_.mode===`edit`&&_.id===e.id&&C()}})}},M=t(()=>{let e=new Map;for(let t of c??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[c]),N=l||d.isLoading,P=u||d.isError,F=_.mode===`new`&&x!==null&&x!==``,I=_.mode===`edit`&&D!==null;return e(Ge,{embedded:!0,children:[N&&r(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:n(`system.storage.loadingLocations`,`Loading locations…`)}),P&&r(`div`,{className:`text-xs text-danger`,children:n(`system.storage.failedToLoadStorageLocations`,`Failed to load storage locations.`)}),!N&&!P&&e(`div`,{className:`space-y-3`,children:[f.length===0&&r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:n(`system.storage.noStorageLocationsDeclaredBy`,`No storage locations declared by any installed addon.`)}),f.map(e=>r(Xe,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:M.get(e.id)??[],onAdd:w,onEdit:T,onDelete:e=>{j(e)},ownedBytesById:m,drainById:g,onSetMode:(e,t)=>{A(e,t)}},e.id))]}),F&&x!==null&&r(et,{initialType:x,onClose:C,onCreated:()=>{a.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}}),I&&D!==null&&r(Ze,{location:D,onClose:C,onSaved:()=>{a.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}})]})}var q={settings:{labelKey:`helpers.backupDatabases.settings.label`,descriptionKey:`helpers.backupDatabases.settings.description`,shortKey:`helpers.backupDatabases.settings.short`},events:{labelKey:`helpers.backupDatabases.events.label`,descriptionKey:`helpers.backupDatabases.events.description`,shortKey:`helpers.backupDatabases.events.short`},history:{labelKey:`helpers.backupDatabases.history.label`,descriptionKey:`helpers.backupDatabases.history.description`,shortKey:`helpers.backupDatabases.history.short`}},nt=Object.keys(q),J=[`settings`];function rt(){return W.t(`helpers.backupDatabases.notCreated`)}function it(e){return W.t(q[e].labelKey)}function at(e){return W.t(q[e].shortKey)}function ot(e){return W.t(q[e].descriptionKey)}function Y(e){let t=new Set(e);return nt.filter(e=>t.has(e))}function X(e){return e!==void 0&&e.length>0?Y(e):J}function st(e){return Y(e)}function ct(e,t){return t===void 0||!t.answered?`unknown`:t.databases.includes(e)?`present`:`absent`}function lt(e,t,n){return ct(e,t)===`absent`&&!n.has(e)}function ut(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function dt(e){return!e.includes(`settings`)}function ft(e){return{databases:[...st(e)]}}function pt(e,t){return e!==void 0&&e.length>0?Y(e):t!==void 0&&t.length>0?Y(t.map(e=>e.databaseId??`settings`)):J}function Z({databases:e}){return r(`span`,{className:`text-xs font-medium uppercase tracking-wide text-foreground-muted`,"data-testid":`backup-database-badges`,children:e.map(e=>at(e)).join(` · `)})}o();var mt=[[`backup`,`listDestinations`]],ht=[`backup`,`listArchives`];function gt({destinationId:i,restoreSupported:o,onOpenRestoreWizard:c}){let{t:l}=G(),u=s(),d=U(),{data:f,isLoading:m,isError:h}=ge({destinationId:i}),g=f??[],v=ee({onSuccess:()=>{u.invalidateQueries({queryKey:[[...ht]]}),u.invalidateQueries({queryKey:mt})}}),y=n(async e=>{await d({title:l(`backup.archiveList.deleteThisArchive`,`Delete this archive?`),message:l(`backup.archiveList.permanentlyDeletesAndFrees`,`Permanently deletes "{{value1}}" and frees {{value2}}.`,{value1:e.label??e.id,value2:K(e.sizeBytes)}),confirmLabel:l(`common.delete`,`Delete`),variant:`danger`})&&v.mutate({destinationId:i,backupId:e.id})},[d,i,v,l]),[b,x]=a(null),S=n(async e=>{x(e.id);try{let t=await Ke(_t(i,e.id)),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.label??e.id}.tar.gz${e.encryption===void 0?``:`.csbk`}`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}finally{x(null)}},[i]),C=t(()=>[...g].toSorted((e,t)=>t.createdAt-e.createdAt),[g]);return m?r(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:l(`backup.archiveList.loadingArchives`,`Loading archives…`)}):h?r(`div`,{className:`text-xs text-danger py-2`,children:l(`backup.archiveList.failedToReadManifestFor`,`Failed to read manifest for this destination`)}):C.length===0?r(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)}):r(R,{columns:[{key:`when`,header:l(`backup.archiveList.when`,`When`),sortValue:e=>e.createdAt,render:e=>r(`span`,{className:`tabular-nums`,children:vt(e.createdAt)})},{key:`label`,header:l(`backup.archiveList.label`,`Label`),sortValue:e=>e.label??null,render:t=>e(`span`,{className:`inline-flex items-center gap-1`,children:[t.encryption!==void 0&&r(D,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.archiveList.encryptedRestoreNeedsBackupKey`,`encrypted — restore needs backup key {{keyId}}`,{keyId:t.encryption.keyId})}),t.label??r(`span`,{className:`text-foreground-subtle italic`,children:`—`})]})},{key:`databases`,header:l(`backup.archiveList.databases`,`Databases`),nowrap:!1,notSortableReason:`Database badges`,render:e=>r(Z,{databases:X(e.databases)})},{key:`includes`,header:l(`backup.archiveList.files`,`Files`),nowrap:!1,notSortableReason:`Location list`,render:e=>e.locations.length>0?r(`span`,{className:`text-foreground-subtle`,children:e.locations.join(`, `)}):r(`span`,{className:`text-foreground-subtle italic`,children:l(`common.none`)})},{key:`size`,header:l(`backup.archiveList.size`,`Size`),align:`right`,sortValue:e=>e.sizeBytes,render:e=>r(`span`,{className:`tabular-nums`,children:K(e.sizeBytes)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Actions`,render:t=>e(`span`,{className:`flex items-center justify-end gap-1`,children:[e(V,{variant:`ghost`,size:`sm`,onClick:()=>{S(t)},disabled:b===t.id,title:l(`backup.archiveList.downloadArchive`,`Download archive`),children:[b===t.id?r(T,{className:`h-3 w-3 animate-spin`}):r(_,{className:`h-3 w-3`}),l(`backup.archiveList.download`,`Download`)]}),o&&c&&e(V,{variant:`ghost`,size:`sm`,onClick:()=>c({destinationId:i,archiveId:t.id}),title:l(`backup.archiveList.restoreFromThisArchive`,`Restore from this archive`),children:[r(k,{className:`h-3 w-3`}),l(`backup.archiveList.restore`,`Restore`)]}),r(L,{variant:`ghost`,size:`sm`,icon:p,"aria-label":l(`backup.archiveList.delete`,`Delete {{value1}}`,{value1:t.label??t.id}),disabled:v.isPending,onClick:()=>{y(t)}})]})}],rows:C,rowKey:e=>e.id,minWidthPx:760,emptyMessage:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)})}function _t(e,t){return g(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function vt(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}o();var yt=[[`backup`,`listSchedules`]];function bt({onEdit:i,onOpenRestoreWizard:o}){let{t:s}=G(),{data:c,isLoading:l,isError:u,error:d,refetch:f}=Se(),p=c??[],m=ce().data??[],h=t(()=>{let e=new Map;for(let t of m)e.set(t.id,t);return e},[m]),[g,_]=a(null),v=n(e=>{_(t=>t===e?null:e)},[]),y=t(()=>xt({destById:h,expandedId:g,onToggleExpand:v,onEdit:i}),[h,g,v,i]);return l?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle animate-pulse`,children:[r(T,{className:`h-3.5 w-3.5 animate-spin`}),s(`backup.backupEntriesTable.loadingBackupEntries`,`Loading backup entries…`)]}):u?r(B,{title:s(`backup.backupEntriesTable.failedToLoadBackupEntries`,`Failed to load backup entries`),message:d instanceof Error?d.message:s(`backup.backupEntriesTable.unknownError`,`Unknown error`),onRetry:()=>void f()}):p.length===0?r(z,{icon:M,title:s(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),description:s(`backup.backupEntriesTable.createOneToScheduleBackups`,`Create one to schedule backups across one or more storage locations.`)}):r(R,{columns:y,rows:p,rowKey:e=>e.id,minWidthPx:980,maxBodyHeight:Re,emptyMessage:s(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),onRowClick:e=>i(e),isExpanded:e=>e.id===g,renderExpanded:e=>r(Ot,{row:e,destById:h,...o?{onOpenRestoreWizard:o}:{}})})}function xt(t){return[{key:`expand`,header:``,width:`w-8`,nowrap:!0,notSortableReason:`Expand control`,render:e=>{let n=t.expandedId===e.id;return r(L,{variant:`ghost`,size:`sm`,icon:n?A:j,"aria-label":n?W.t(`backup.backupEntriesTable.hideArchives`,`Hide archives`):W.t(`backup.backupEntriesTable.showArchives`,`Show archives`),"aria-expanded":n,onClick:n=>{n.stopPropagation(),t.onToggleExpand(e.id)}})}},{key:`entry`,header:W.t(`backup.backupEntriesTable.entry`,`Entry`),sortValue:e=>e.label,render:t=>e(`span`,{className:`flex min-w-0 flex-col`,children:[r(`span`,{className:`truncate font-medium text-foreground`,children:t.label||W.t(`backup.backupEntriesTable.unnamed`,`(unnamed)`)}),t.lastRunAt!==void 0&&r(`span`,{className:`text-[10px] text-foreground-subtle`,children:W.t(`backup.backupEntriesTable.lastRun`,{when:new Date(t.lastRunAt).toLocaleString()})})]})},{key:`enabled`,header:W.t(`backup.backupEntriesTable.enabled`,`Enabled`),width:`w-20`,nowrap:!0,sortValue:e=>+!!e.enabled,render:e=>r(`span`,{onClick:e=>e.stopPropagation(),children:r(Tt,{row:e})})},{key:`databases`,header:W.t(`backup.backupEntriesTable.backsUp`,`Backs up`),nowrap:!1,notSortableReason:`Database badges`,render:e=>r(Z,{databases:X(e.databases)})},{key:`locations`,header:W.t(`backup.backupEntriesTable.locations`,`Locations`),nowrap:!1,notSortableReason:`Location chips`,render:e=>r(St,{row:e,destById:t.destById})},{key:`retention`,header:W.t(`backup.backupEntriesTable.retention`,`Retention`),width:`w-24`,nowrap:!0,sortValue:e=>e.retentionCount,render:e=>r(`span`,{onClick:e=>e.stopPropagation(),children:r(Et,{row:e})})},{key:`schedule`,header:W.t(`backup.backupEntriesTable.schedule`,`Schedule`),width:`w-48`,nowrap:!0,sortValue:e=>e.cron,render:e=>r(Ct,{row:e})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:e=>r(`span`,{onClick:e=>e.stopPropagation(),children:r(Dt,{row:e,onEdit:()=>t.onEdit(e)})})}]}function St({row:e,destById:t}){let{t:n}=G();return e.locationIds.length===0?r(`span`,{className:`text-[11px] italic text-danger`,children:n(`backup.backupEntriesTable.noLocations`,`No locations`)}):r(`span`,{className:`flex flex-wrap gap-1`,children:e.locationIds.map(e=>r(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:t.get(e)?.displayName??e},e))})}function Ct({row:t}){let{t:n}=G(),i=t.cron.trim().length>0;return e(`span`,{className:`flex flex-col items-start gap-0.5`,children:[e(`span`,{className:`inline-flex items-center gap-1`,children:[r(M,{className:`h-3 w-3 text-foreground-subtle`}),r(`span`,{className:`font-mono text-[11px] text-foreground`,children:i?t.cron:n(`backup.backupEntriesTable.manual`,`Manual`)})]}),i&&t.nextRunAt!==void 0&&r(`span`,{className:`text-[10px] text-foreground-subtle`,children:W.t(`common.nextRun`,{when:new Date(t.nextRunAt).toLocaleString()})})]})}function wt(e){return t(()=>({id:e.id,label:e.label,cron:e.cron,locationIds:[...e.locationIds],retentionCount:e.retentionCount,...e.dataSources?{dataSources:[...e.dataSources]}:{},...e.databases?{databases:[...e.databases]}:{}}),[e])}function Tt({row:e}){let{t}=G(),n=s(),i=be({onSuccess:()=>{n.invalidateQueries({queryKey:yt})}}),a=wt(e);return r(`label`,{className:`inline-flex cursor-pointer items-center`,children:r(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:i.isPending,onChange:e=>i.mutate({...a,enabled:e.target.checked}),"aria-label":t(`backup.backupEntriesTable.enable`,`Enable {{value1}}`,{value1:e.label||e.id})})})}function Et({row:e}){let{t}=G(),n=s(),o=be({onSuccess:()=>{n.invalidateQueries({queryKey:yt})}}),c=wt(e),[l,u]=a(String(e.retentionCount));return i(()=>{u(String(e.retentionCount))},[e.retentionCount]),r(le,{type:`number`,min:1,max:1e3,value:l,disabled:o.isPending,onChange:e=>u(e.target.value),onBlur:()=>{let t=Number.parseInt(l,10);if(Number.isNaN(t)||t<1){u(String(e.retentionCount));return}t!==e.retentionCount&&o.mutate({...c,enabled:e.enabled,retentionCount:t})},onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&u(String(e.retentionCount))},className:`w-16`,"aria-label":t(`backup.backupEntriesTable.retentionFor`,`Retention for {{value1}}`,{value1:e.label||e.id})})}function Dt({row:t,onEdit:n}){let{t:i}=G(),a=s(),o=U(),c=ie({onSuccess:()=>{a.invalidateQueries({queryKey:yt})}}),u=Ee({onMutate:()=>{a.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{a.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),a.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),a.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),f=()=>{t.locationIds.length!==0&&u.mutate({destinations:[...t.locationIds],...t.dataSources&&t.dataSources.length>0?{locations:[...t.dataSources]}:{},label:t.label,retentionCount:t.retentionCount,databases:[...X(t.databases)]})},m=async()=>{await o({title:i(`backup.backupEntriesTable.deleteBackupEntry`,`Delete backup entry?`),message:i(`backup.backupEntriesTable.willStopRunningExistingArchives`,`"{{value1}}" will stop running. Existing archives are kept.`,{value1:t.label||t.id}),confirmLabel:i(`common.delete`,`Delete`),variant:`warning`})&&c.mutate({id:t.id})};return e(`span`,{className:`flex items-center justify-end gap-1.5`,children:[e(V,{size:`sm`,type:`button`,onClick:f,disabled:u.isPending||t.locationIds.length===0,title:i(`backup.backupEntriesTable.runThisEntryNow`,`Run this entry now`),children:[u.isPending?r(T,{className:`h-3 w-3 animate-spin`}):r(l,{className:`h-3 w-3`}),i(`backup.backupEntriesTable.runNow`,`Run now`)]}),r(L,{variant:`ghost`,size:`sm`,icon:d,"aria-label":i(`backup.backupEntriesTable.edit`,`Edit {{value1}}`,{value1:t.label||t.id}),onClick:n}),r(L,{variant:`ghost`,size:`sm`,icon:p,"aria-label":i(`backup.backupEntriesTable.delete`,`Delete {{value1}}`,{value1:t.label||t.id}),disabled:c.isPending,onClick:()=>{m()}})]})}function Ot({row:t,destById:n,onOpenRestoreWizard:i}){let{t:a}=G();return e(`div`,{className:`space-y-4 rounded-lg border border-border bg-background/30 px-4 py-3`,children:[r(`p`,{className:`text-[11px] font-medium text-foreground-subtle`,children:a(`backup.backupEntriesTable.archivesFor`,{name:t.label||t.id})}),t.locationIds.length===0&&r(`p`,{className:`text-xs italic text-foreground-subtle`,children:a(`backup.backupEntriesTable.thisEntryHasNoLocations`,`This entry has no locations selected.`)}),t.locationIds.map(t=>e(`div`,{className:`space-y-1.5`,children:[r(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:n.get(t)?.displayName??t}),r(gt,{destinationId:t,restoreSupported:n.get(t)?.restoreSupported??!0,...i?{onOpenRestoreWizard:i}:{}})]},t))]})}function kt({selected:t,onChange:n,disabled:i=!1,testId:a=`backup-databases`}){let{t:o}=G(),s=ve().data,c=t.size>0&&dt(Y(t)),l=t.size===0?`Pick at least one.`:c?`Snapshots only: configuration and files are not part of this backup.`:null;return r(H,{label:o(`backup.backupDatabasePicker.whatToBackUp`,`What to back up`),required:!0,...l===null?{}:{description:l},children:r(`div`,{className:`divide-y divide-border rounded border border-border bg-background`,"data-testid":a,children:nt.map(o=>{let c=ct(o,s),l=i||lt(o,s,t);return e(`label`,{className:`flex items-start gap-2 px-3 py-2 text-xs ${l?`opacity-60`:`cursor-pointer hover:bg-primary/5`}`,children:[r(me,{checked:t.has(o),disabled:l,onChange:()=>n(ut(t,o)),"data-testid":`${a}-${o}`}),e(`span`,{className:`min-w-0 flex-1`,children:[r(`span`,{className:`flex flex-wrap items-center gap-1.5 text-foreground`,children:it(o)}),r(`span`,{className:`block text-[11px] text-foreground-subtle`,children:c===`absent`?rt():ot(o)})]})]},o)})})})}o();function At({onClose:t}){let{t:n}=G(),i=s(),[o,c]=a(new Set(J)),u=Ee({onMutate:()=>{i.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{i.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),i.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),i.invalidateQueries({queryKey:[[`backup`,`listRuns`]]}),t()}});return r(Ce,{open:!0,onOpenChange:e=>!e&&t(),children:e(Oe,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[e(ye,{children:[r(Le,{children:n(`backup.backupNowDialog.backUpNow`,`Back up now`)}),r(`p`,{className:`text-xs text-foreground-subtle`,children:n(`backup.backupNowDialog.runsOnceAndWritesThe`,`Runs once and writes the archive to every enabled backup location.`)})]}),r(je,{children:e(`div`,{className:`p-4`,children:[r(kt,{selected:o,onChange:c,disabled:u.isPending,testId:`backup-now-databases`}),u.error&&r(`p`,{role:`alert`,className:`pt-2 text-xs text-danger`,children:u.error.message})]})}),e(we,{children:[r(V,{variant:`outline`,size:`sm`,onClick:t,children:n(`common.cancel`,`Cancel`)}),e(V,{size:`sm`,onClick:()=>{o.size!==0&&u.mutate(ft(o))},disabled:o.size===0||u.isPending,"data-testid":`backup-now-run`,children:[u.isPending?r(T,{className:`h-3.5 w-3.5 animate-spin`}):r(l,{className:`h-3.5 w-3.5`}),n(`backup.backupNowDialog.backUpNow`,`Back up now`)]})]})]})})}o();function jt(e){return e===null?`—`:new Date(e).toLocaleString()}function Mt(e){let t=new Blob([`${e.secretKey}\n`],{type:`text/plain`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`camstack-backup-key-${e.keyId}.txt`,r.click(),URL.revokeObjectURL(n)}function Nt({revealed:t,onDone:n}){let{t:i}=G(),[o,s]=a(!1),[c,l]=a(!1);return r(Ce,{open:!0,onOpenChange:e=>!e&&o&&n(),children:e(Oe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`border-danger/40`,"aria-labelledby":`backup-key-title`,children:[r(ye,{children:r(Le,{id:`backup-key-title`,children:i(`backup.encryptionCard.yourKey`,{keyId:t.keyId})})}),e(je,{className:`space-y-3`,children:[e(`p`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 p-2 text-xs text-foreground`,children:[r(h,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),r(`span`,{children:i(`backup.backupEncryptionCard.thisKeyIsShownOnly`,`This key is shown only once. CamStack does not keep it — not the hub, not its database, not its backups. Without it, an encrypted backup cannot be restored by anyone, including you. Store it in a password manager or print it, away from this server.`)})]}),r(`div`,{className:`break-all rounded-md border border-border bg-background p-2 font-mono text-xs text-foreground select-all`,children:t.secretKey}),e(`div`,{className:`flex flex-wrap gap-2`,children:[e(V,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard?.writeText(t.secretKey).then(()=>l(!0))},children:[r(b,{className:`mr-1 h-3.5 w-3.5`}),c?i(`backup.backupEncryptionCard.copied`,`Copied`):i(`common.copy`,`Copy`)]}),e(V,{size:`sm`,variant:`outline`,onClick:()=>Mt(t),children:[r(_,{className:`mr-1 h-3.5 w-3.5`}),i(`backup.backupEncryptionCard.downloadAsFile`,`Download as file`)]})]}),e(`label`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[r(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`accent-primary`}),i(`backup.backupEncryptionCard.iHaveStoredThisKey`,`I have stored this key somewhere safe, off this server.`)]})]}),r(we,{children:r(V,{size:`sm`,disabled:!o,onClick:n,children:i(`backup.backupEncryptionCard.iHaveStoredIt`,`I have stored it`)})})]})})}function Pt(){let{t}=G(),n=re(),i=Fe(),o=Ne(),s=U(),[l,u]=a(null),[d,f]=a(null),p=n.data?.enabled??!1,m=n.data?.active??null,h=(n.data?.keys??[]).filter(e=>e.retiredAt!==null),g=async()=>{if(await s({title:p?t(`backup.backupEncryptionCard.replaceTheBackupKey`,`Replace the backup key`):t(`backup.backupEncryptionCard.encryptBackups`,`Encrypt backups`),message:p?t(`backup.backupEncryptionCard.aNewKeyIsGenerated`,`A new key is generated and shown once; new backups are encrypted to it. Older backups keep needing the key they were made with — keep that one too.`):t(`backup.backupEncryptionCard.aBackupKeyIsGenerated`,`A backup key is generated and shown once. Every new backup is encrypted to it, and restoring one will ask for it. Existing backups stay as they are.`),confirmLabel:p?t(`backup.backupEncryptionCard.generateANewKey`,`Generate a new key`):t(`backup.backupEncryptionCard.generateTheKey`,`Generate the key`),variant:`warning`})){f(null);try{let e=await i.mutateAsync({});u({keyId:e.keyId,secretKey:e.secretKey})}catch(e){f(e instanceof Error?e.message:String(e))}}},_=async()=>{if(await s({title:t(`backup.backupEncryptionCard.turnBackupEncryptionOff`,`Turn backup encryption off`),message:t(`backup.backupEncryptionCard.newBackupsWillBeWritten`,`New backups will be written unencrypted. Existing encrypted backups still need their key to be restored.`),confirmLabel:t(`backup.backupEncryptionCard.turnOff`,`Turn off`),variant:`danger`})){f(null);try{await o.mutateAsync({}),n.refetch()}catch(e){f(e instanceof Error?e.message:String(e))}}};return e(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-4`,children:[e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[p?r(D,{className:`h-4 w-4 text-success`}):r(C,{className:`h-4 w-4 text-foreground-subtle`}),r(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`backup.backupEncryptionCard.encryption`,`Encryption`)}),r(`span`,{className:`text-xs text-foreground-subtle`,children:p&&m!==null?t(`backup.backupEncryptionCard.onKeySince`,`On — key {{keyId}}, since {{value2}}`,{keyId:m.keyId,value2:jt(m.createdAt)}):t(`backup.backupEncryptionCard.offBackupsAreNotEncrypted`,`Off — backups are not encrypted`)})]}),r(`div`,{className:`flex gap-2`,children:p?e(c,{children:[r(V,{size:`sm`,variant:`outline`,disabled:i.isPending,onClick:()=>void g(),children:t(`backup.backupEncryptionCard.replaceKey`,`Replace key`)}),r(V,{size:`sm`,variant:`outline`,disabled:o.isPending,onClick:()=>void _(),children:t(`backup.backupEncryptionCard.turnOff`,`Turn off`)})]}):r(V,{size:`sm`,disabled:i.isPending,onClick:()=>void g(),children:t(`backup.backupEncryptionCard.enableEncryption`,`Enable encryption`)})})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:t(`backup.backupEncryptionCard.archivesAreEncryptedOnThis`,`Archives are encrypted on this server before they reach any destination. The server keeps only a public key, so it can encrypt scheduled backups but cannot decrypt them — only your backup key can. Covers the database snapshot, config.yaml, addon data (HomeKit pairing, Matter fabric, Tailscale state) and TLS.`)}),h.length>0&&e(`div`,{className:`text-xs`,children:[r(`p`,{className:`text-foreground-subtle`,children:t(`backup.backupEncryptionCard.olderKeysBackupsMadeWith`,`Older keys (backups made with them still need them):`)}),r(`ul`,{className:`font-mono text-foreground`,children:h.map(t=>e(`li`,{children:[t.keyId,` · `,jt(t.createdAt),` → `,jt(t.retiredAt)]},t.keyId))})]}),d!==null&&r(`p`,{className:`text-xs text-danger`,children:d}),l!==null&&r(Nt,{revealed:l,onDone:()=>{u(null),n.refetch()}})]})}o();var Ft=[{id:`manual`,labelKey:`backup.cronEditor.presetManual`,cron:``},{id:`hourly`,labelKey:`backup.cronEditor.presetHourly`,cron:`0 * * * *`,descriptionKey:`backup.cronEditor.presetHourlyDesc`},{id:`every-3h`,labelKey:`backup.cronEditor.preset3h`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,labelKey:`backup.cronEditor.preset6h`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,labelKey:`backup.cronEditor.presetDaily`,cron:`0 3 * * *`,descriptionKey:`backup.cronEditor.presetDailyDesc`},{id:`weekly-sun`,labelKey:`backup.cronEditor.presetWeekly`,cron:`0 3 * * 0`,descriptionKey:`backup.cronEditor.presetWeeklyDesc`}];function It(e){let t=e.trim();for(let e of Ft)if(e.cron===t)return e.id;return`custom`}function Lt({value:t,onChange:n,previewCount:o=5,disabled:s=!1}){let{t:c}=G(),l=It(t),[u,d]=a(l===`custom`);i(()=>{l!==`custom`&&d(!1)},[l]);let f=Bt(t,250),p=Ie({cron:f,count:o},{enabled:f.trim().length>0}),m=p.data??null,h=e=>{d(!1),n(e.cron)},g=u||l===`custom`;return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`space-y-1`,children:[r(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:c(`backup.cronEditor.schedulePreset`,`Schedule preset`)}),e(`div`,{className:`flex flex-wrap gap-1.5`,children:[Ft.map(e=>r(`button`,{type:`button`,onClick:()=>h(e),disabled:s,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!u&&l===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.descriptionKey===void 0?e.description??c(e.labelKey):c(e.descriptionKey),children:c(e.labelKey)},e.id)),r(`button`,{type:`button`,onClick:()=>{d(!0),t.trim().length===0&&n(`0 3 * * *`)},disabled:s,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(g?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:c(`backup.cronEditor.custom`,`Custom…`)})]})]}),g&&e(`div`,{className:`space-y-1`,children:[r(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:c(`backup.cronEditor.cronExpression5FieldPosix`,`Cron expression (5-field POSIX)`)}),r(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),disabled:s,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),e(`p`,{className:`text-[10px] text-foreground-subtle`,children:[c(`backup.cronEditor.format`,`Format:`),` `,r(Ve,{i18nKey:`backup.cronEditor.formatLine`,components:{code:r(`span`,{className:`font-mono`})}})]})]}),r(Rt,{cron:f,preview:m,loading:p.isFetching})]})}function Rt({cron:t,preview:n,loading:i}){let{t:a}=G();return i&&n===null?e(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[r(T,{className:`h-3 w-3 animate-spin`}),a(`backup.cronEditor.validating`,`Validating…`)]}):n===null?null:n.ok?n.nextRuns.length===0?r(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:a(`backup.cronEditor.noFutureRunsMatchThis`,`No future runs match this expression.`)}):e(`div`,{className:`space-y-1`,children:[r(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:a(`backup.cronEditor.nextRuns`,`Next runs`)}),r(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:n.nextRuns.map((t,n)=>e(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[r(`span`,{className:`text-foreground tabular-nums`,children:new Date(t).toLocaleString()}),r(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:zt(t)})]},`${t}-${n}`))})]}):r(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:n.error??a(`backup.cronEditor.invalidCronExpression`,`Invalid cron expression`)})}function zt(e){let t=e-Date.now();if(t<=0)return W.t(`helpers.relativeTime.now`);let n=Math.floor(t/1e3);if(n<60)return W.t(`helpers.relativeTime.inSeconds`,{count:n});let r=Math.floor(n/60);if(r<60)return W.t(`helpers.relativeTime.inMinutes`,{count:r});let i=Math.floor(r/60);if(i<24)return W.t(`helpers.relativeTime.inHours`,{count:i});let a=Math.floor(i/24);return W.t(`helpers.relativeTime.inDays`,{count:a})}function Bt(e,n){let[r,o]=a(e),s=t(()=>e,[e]);return i(()=>{let e=setTimeout(()=>o(s),n);return()=>clearTimeout(e)},[s,n]),r}o();var Vt=[[`backup`,`listSchedules`]];function Ht({entry:n,onClose:i,onSaved:o}){let{t:c}=G(),l=s(),u=ce(),d=u.data??[],[f,p]=a(n?.label??``),[m,h]=a(n?.cron??`0 3 * * *`),[g,_]=a(n?.enabled??!0),[v,y]=a(String(n?.retentionCount??7)),[b,x]=a(new Set(n?.locationIds??[])),[S,C]=a(new Set(n===null?J:X(n.databases))),w=be({onSuccess:()=>{l.invalidateQueries({queryKey:Vt}),o()}}),E=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},D=Number.parseInt(v,10),O=t(()=>f.trim().length>0&&b.size>0&&S.size>0&&!Number.isNaN(D)&&D>=1&&D<=1e3,[f,b,S,D]),k=()=>{O&&w.mutate({...n?{id:n.id}:{},label:f.trim(),cron:m.trim(),enabled:g,locationIds:Array.from(b),retentionCount:D,databases:[...st(S)]})},A=w.error instanceof Error?w.error.message:null;return r(Te,{open:!0,onClose:i,title:n?c(`backup.backupEntryModal.editBackupEntry`,`Edit backup entry`):c(`backup.backupEntryModal.newBackupEntry`,`New backup entry`),icon:M,error:A,width:`lg`,testId:`backup-entry-form`,footer:e(V,{size:`sm`,type:`button`,onClick:k,disabled:!O||w.isPending,children:[w.isPending?r(T,{className:`h-3.5 w-3.5 animate-spin`}):null,n?c(`common.save`,`Save`):c(`backup.backupEntryModal.createEntry`,`Create entry`)]}),children:e(`div`,{className:`space-y-4`,children:[r(H,{label:c(`backup.backupEntryModal.name`,`Name`),required:!0,children:r(le,{value:f,onChange:e=>p(e.target.value),placeholder:c(`backup.backupEntryModal.nightlyOffsite`,`Nightly offsite`),autoFocus:!0,"data-testid":`backup-entry-name`})}),e(H,{label:c(`backup.backupEntryModal.locationsSelected`,`Locations ({{value1}} selected)`,{value1:String(b.size)}),required:!0,children:[u.isLoading&&e(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[r(T,{className:`h-3.5 w-3.5 animate-spin`}),c(`backup.backupEntryModal.loadingLocations`,`Loading locations…`)]}),!u.isLoading&&d.length===0&&r(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:c(`backup.backupEntryModal.noBackupsStorageLocationsConfigured`,"No `backups` storage locations configured. Add one in Settings → Storage first.")}),d.length>0&&r(`div`,{className:`max-h-52 divide-y divide-border overflow-y-auto rounded border border-border bg-background`,children:d.map(t=>e(`label`,{className:`flex cursor-pointer items-center justify-between px-3 py-2 text-xs hover:bg-primary/5`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(`input`,{type:`checkbox`,checked:b.has(t.id),onChange:()=>E(t.id),className:`accent-primary`}),r(`span`,{className:`text-foreground`,children:t.displayName})]}),e(`div`,{className:`flex items-center gap-1.5`,children:[r(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-foreground-subtle`,children:t.kind}),r(`span`,{className:`font-mono text-[10px] text-foreground-subtle`,children:t.id})]})]},t.id))})]}),r(kt,{selected:S,onChange:C,disabled:w.isPending,testId:`backup-entry-databases`}),e(`div`,{className:`grid grid-cols-2 gap-3`,children:[r(H,{label:c(`backup.backupEntryModal.retentionArchivesKept`,`Retention (archives kept)`),required:!0,children:r(le,{type:`number`,min:1,max:1e3,value:v,onChange:e=>y(e.target.value),"data-testid":`backup-entry-retention`})}),r(H,{label:c(`backup.backupEntryModal.enabled`,`Enabled`),description:c(`backup.backupEntryModal.runOnScheduleWhenChecked`,`Run on schedule when checked.`),children:e(`label`,{className:`inline-flex cursor-pointer items-center gap-2 py-1.5 text-xs text-foreground`,children:[r(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`accent-primary`,"data-testid":`backup-entry-enabled`}),r(`span`,{children:c(`backup.backupEntryModal.runOnSchedule`,`Run on schedule`)})]})})]}),r(H,{label:c(`backup.backupEntryModal.schedule`,`Schedule`),children:r(Lt,{value:m,onChange:h,disabled:w.isPending})})]})})}o();var Ut=2e3,Wt=5e3;function Q(e){return e.state===`queued`||e.state===`running`}function Gt(e){if(e.state===`queued`)return{title:W.t(`backup.backupRunsPanel.cancelQueuedBackupRun`,`Cancel queued backup run?`),message:W.t(`backup.backupRunsPanel.thisRunHasNotStarted`,`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`),confirmLabel:W.t(`backup.backupRunsPanel.cancelRun`,`Cancel run`),variant:`warning`};let t=e.completedDestinationIds.length,n=t>0?`${t===1?`The 1 destination`:`The ${t} destinations`} that already completed KEEP${t===1?`S`:``} the archive.`:`No destination has completed yet, so nothing will be kept.`;return{title:W.t(`backup.backupRunsPanel.stopThisBackupRun`,`Stop this backup run?`),message:W.t(`backup.backupRunsPanel.theHalfWrittenStagingArchive`,`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. {{keptSentence}}`,{keptSentence:n}),confirmLabel:W.t(`backup.backupRunsPanel.stopRun`,`Stop run`),variant:`danger`}}function Kt(){let e=U(),[t,i]=a(null),o=I(void 0,{refetchInterval:e=>(e.state.data??[]).some(Q)?Ut:Wt}),s=fe({onSettled:()=>{i(null),o.refetch()}}),c=n(async t=>{await e(Gt(t))&&(i(t.id),s.mutate({runId:t.id}))},[e,s]);return r(qt,{queryState:o.isError?`error`:o.data===void 0?`pending`:`ready`,runs:o.data??[],cancelingId:t,onCancelRequest:e=>{c(e)},now:Date.now()})}function qt({queryState:t,runs:n,cancelingId:i,onCancelRequest:a,now:o}){let{t:s}=G(),c=t===`ready`&&n.some(Q),l=n.filter(e=>e.state===`running`),u=n.filter(e=>e.state===`queued`),d=n.filter(e=>!Q(e)),f=[...l,...u,...d];return e(`section`,{className:`rounded-lg border border-border bg-surface`,children:[e(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[r(`h2`,{className:`text-xs font-semibold text-foreground`,children:s(`backup.backupRunsPanel.runs`,`Runs`)}),c&&e(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-primary`,title:s(`backup.backupRunsPanel.aBackupRunIsIn`,`A backup run is in progress`),children:[r(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),s(`backup.runsPanel.live`)]}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:s(`backup.backupRunsPanel.oneRunExecutesAtA`,`One run executes at a time — queued runs wait in line.`)})]}),t===`pending`&&r(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle animate-pulse`,children:s(`backup.backupRunsPanel.checkingForBackupRuns`,`Checking for backup runs…`)}),t===`error`&&r(`div`,{className:`px-3 py-2.5 text-xs text-danger`,children:s(`backup.backupRunsPanel.couldNotReadBackupRuns`,`Could not read backup runs — the orchestrator did not answer.`)}),t===`ready`&&n.length===0&&r(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle italic`,children:s(`backup.backupRunsPanel.noBackupRunsYetRuns`,`No backup runs yet. Runs appear here the moment one starts — manual or scheduled.`)}),t===`ready`&&n.length>0&&r(`div`,{className:`overflow-x-auto`,children:e(`table`,{className:`w-full text-xs min-w-[720px]`,children:[r(`thead`,{children:e(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[r(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:s(`backup.backupRunsPanel.run`,`Run`)}),r(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:s(`backup.backupRunsPanel.state`,`State`)}),r(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:s(`backup.backupRunsPanel.progress`,`Progress`)}),r(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:s(`backup.backupRunsPanel.destinations`,`Destinations`)}),r(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:s(`backup.backupRunsPanel.timing`,`Timing`)}),r(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:s(`backup.backupRunsPanel.actions`,`Actions`)})]})}),r(`tbody`,{children:f.map(e=>r(Jt,{run:e,canceling:i===e.id,onCancelRequest:a,now:o},e.id))})]})})]})}function Jt({run:t,canceling:n,onCancelRequest:i,now:a}){let{t:o}=G(),s=Q(t);return e(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[r(`td`,{className:`px-3 py-2`,children:r(`div`,{className:`text-foreground`,title:t.id,children:t.label??r(`span`,{className:`text-foreground-subtle italic`,children:o(`backup.runsPanel.manual`)})})}),e(`td`,{className:`px-3 py-2`,children:[r(Yt,{run:t}),t.state===`failed`&&t.error!==void 0&&r(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:t.error,children:t.error})]}),r(`td`,{className:`px-3 py-2`,children:r(Xt,{run:t})}),r(`td`,{className:`px-3 py-2`,children:r(Zt,{run:t})}),r(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:r(Qt,{run:t,now:a})}),r(`td`,{className:`px-3 py-2`,children:r(`div`,{className:`flex justify-end`,children:s&&e(`button`,{onClick:()=>i(t),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:t.state===`queued`?o(`backup.backupRunsPanel.removeThisRunFromThe`,`Remove this run from the queue before it starts`):o(`backup.backupRunsPanel.stopThisRunTheHalf`,`Stop this run — the half-written archive is discarded`),children:[n?r(T,{className:`h-3 w-3 animate-spin`}):r(f,{className:`h-3 w-3`}),t.state===`queued`?o(`common.cancel`,`Cancel`):o(`backup.backupRunsPanel.stop`,`Stop`)]})})})]})}function Yt({run:t}){let{t:n}=G();switch(t.state){case`queued`:return e(`span`,{className:`inline-flex items-center gap-1 rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[r(x,{className:`h-3 w-3`}),n(`backup.backupRunsPanel.queued`,`Queued`)]});case`running`:return e(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:[r(T,{className:`h-3 w-3 animate-spin`}),t.phase===`uploading`?n(`backup.backupRunsPanel.uploading`,`Uploading`):n(`backup.backupRunsPanel.buildingArchive`,`Building archive`)]});case`succeeded`:return e(`span`,{className:`inline-flex items-center gap-1 rounded bg-success/10 px-1.5 py-0.5 text-[10px] font-medium text-success`,children:[r(E,{className:`h-3 w-3`}),n(`backup.backupRunsPanel.succeeded`,`Succeeded`)]});case`failed`:return e(`span`,{className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 text-[10px] font-medium text-danger`,children:[r(O,{className:`h-3 w-3`}),n(`backup.backupRunsPanel.failed`,`Failed`)]});case`cancelled`:return e(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:text-amber-300`,title:n(`backup.backupRunsPanel.stoppedBeforeCompletingEveryDestination`,`Stopped before completing every destination — not a success`),children:[r(P,{className:`h-3 w-3`}),n(`backup.backupRunsPanel.stopped`,`Stopped`)]})}}function Xt({run:t}){let{t:n}=G();if(t.state===`queued`)return r(`span`,{className:`text-foreground-subtle`,children:t.queuePosition===void 0?r(`span`,{className:`italic`,children:n(`backup.backupRunsPanel.waitingItsTurn`,`waiting its turn`)}):e(`span`,{className:`inline-flex items-center gap-1`,children:[r(`span`,{className:t.queuePosition===1?`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`:`rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium`,children:$t(t.queuePosition)}),n(`backup.backupRunsPanel.inLine`,`in line`)]})});if(t.state===`running`&&t.phase===`building`)return e(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[r(F,{className:`h-3 w-3 text-primary`}),r(`span`,{className:`tabular-nums font-medium animate-pulse`,children:K(t.stagedBytes)}),r(`span`,{className:`text-foreground-subtle`,children:n(`backup.backupRunsPanel.stagedSoFar`,`staged so far`)})]});if(t.state===`running`){let i=t.archiveSizeBytes;return e(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[r(N,{className:`h-3 w-3 text-primary`}),e(`span`,{className:`tabular-nums font-medium`,children:[K(t.uploadedBytes),i===void 0?``:` / ${K(i)}`]}),r(`span`,{className:`text-foreground-subtle`,children:n(`backup.backupRunsPanel.toCurrentDestination`,`to current destination`)})]})}let i=t.archiveSizeBytes??(t.stagedBytes>0?t.stagedBytes:void 0);return i===void 0?r(`span`,{className:`text-foreground-subtle italic`,children:`—`}):r(`span`,{className:`tabular-nums text-foreground`,children:n(`backup.runsPanel.archiveSize`,{size:K(i)})})}function Zt({run:t}){let{t:n}=G(),i=t.destinationIds.length,a=t.completedDestinationIds.length,o=t.failedDestinationIds.length;return i===0?r(`span`,{className:`text-foreground-subtle italic`,children:n(`backup.backupRunsPanel.notResolvedYet`,`not resolved yet`)}):e(`div`,{className:`flex flex-col gap-0.5`,children:[r(`span`,{className:`text-foreground-subtle`,title:t.destinationIds.join(`, `),children:n(`backup.runsPanel.targets`,{count:i})}),e(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[a>0&&r(`span`,{className:`text-success`,title:n(`backup.backupRunsPanel.keptTheirArchive`,`Kept their archive: {{value1}}`,{value1:t.completedDestinationIds.join(`, `)}),children:n(`backup.runsPanel.completed`,{count:a})}),o>0&&r(`span`,{className:`text-danger`,title:n(`backup.backupRunsPanel.failed2`,`Failed: {{value1}}`,{value1:t.failedDestinationIds.join(`, `)}),children:n(`backup.runsPanel.failedCount`,{count:o})})]})]})}function Qt({run:t,now:n}){let{t:i}=G();return t.state===`queued`?r(`span`,{children:i(`backup.runsPanel.queuedAgo`,{elapsed:en(n-t.requestedAt)})}):t.startedAt===void 0?r(`span`,{children:`—`}):t.finishedAt===void 0?r(`span`,{children:i(`backup.runsPanel.runningFor`,{elapsed:en(n-t.startedAt)})}):e(`div`,{className:`flex flex-col gap-0.5`,children:[r(`span`,{children:tn(t.finishedAt)}),r(`span`,{className:`text-[10px]`,children:i(`backup.runsPanel.took`,{elapsed:en(t.finishedAt-t.startedAt)})})]})}function $t(e){if(e<=1)return`next`;let t=e%100;if(t>=11&&t<=13)return`${e}th`;switch(e%10){case 1:return`${e}st`;case 2:return`${e}nd`;case 3:return`${e}rd`;default:return`${e}th`}}function en(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${String(t%60).padStart(2,`0`)}s`:`${Math.floor(n/60)}h ${String(n%60).padStart(2,`0`)}m`}function tn(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}o();var nn=[[`backup`,`list`]];function rn({initialDestinationId:n,initialArchiveId:o,onClose:c,onScheduled:l}){let{t:u}=G(),d=s(),[f,p]=a(n&&o?2:1),[m,h]=a(n),[g,_]=a(o),[b,x]=a(new Set),[S,C]=a(``),{data:w}=ce(),E=w??[],{data:D,isLoading:O}=ge({destinationId:m??``},{enabled:!!m}),A=D??[];i(()=>{if(m!==void 0)return;let e=E.filter(e=>e.restoreSupported);e.length===1&&h(e[0].id)},[m,E]);let{data:j}=_e({destinationId:m??``,backupId:g??``},{enabled:!!m&&!!g}),M=t(()=>j?.locations??[],[j]);i(()=>{M.length!==0&&x(e=>e.size===0?new Set(M):e)},[M]);let N=Ae({onSuccess:()=>{d.invalidateQueries({queryKey:nn}),l(),c()}}),P=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},F=A.find(e=>e.id===g),I=F?.encryption!==void 0,L=pt(F?.databases,j?.sqliteSnapshots),R=dt(L),z=!!m&&!!g,B=R||b.size>0,ee=z&&B&&!N.isPending&&(!I||S.trim().length>0),te=()=>{!m||!g||N.mutate({destinationId:m,backupId:g,...R?{}:{locations:[...b]},...I?{backupSecretKey:S.trim()}:{}})};return r(Ce,{open:!0,onOpenChange:e=>!e&&c(),children:e(Oe,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[e(ye,{children:[r(Le,{children:u(`backup.restoreWizard.restoreBackup`,`Restore Backup`)}),r(`p`,{className:`text-xs text-foreground-subtle`,children:u(`backup.restoreWizard.stepOf`,{step:f,name:f===1?u(`backup.restoreWizard.pickSource`,`pick source`):f===2?u(`backup.restoreWizard.pickLocations`,`pick locations`):u(`backup.restoreWizard.confirmStep`)})})]}),e(je,{children:[f===1&&r(an,{destinations:E,destinationId:m,onPickDestination:e=>{h(e),_(void 0),x(new Set)},archives:A,archivesLoading:O,archiveId:g,onPickArchive:_}),f===2&&r(on,{locations:M,picked:b,onToggle:P,databases:L,snapshotsOnly:R}),f===3&&r(sn,{destinationName:E.find(e=>e.id===m)?.displayName??m??``,archive:F,picked:[...b],databases:L,snapshotsOnly:R}),f===3&&F?.encryption!==void 0&&r(cn,{keyId:F.encryption.keyId,value:S,onChange:C}),f===3&&N.error&&r(`p`,{role:`alert`,className:`px-4 pb-2 text-xs text-danger`,children:N.error.message})]}),e(we,{className:`justify-between`,children:[r(`div`,{children:f>1&&e(V,{variant:`outline`,size:`sm`,onClick:()=>p(e=>e===3?2:1),children:[r(v,{className:`h-3 w-3`}),u(`common.back`,`Back`)]})}),e(`div`,{className:`flex items-center gap-2`,children:[r(V,{variant:`outline`,size:`sm`,onClick:c,children:u(`common.cancel`,`Cancel`)}),f<3?e(V,{size:`sm`,disabled:f===1&&!z||f===2&&!B,onClick:()=>p(e=>e===1?2:3),children:[u(`common.next`,`Next`),r(y,{className:`h-3 w-3`})]}):e(V,{size:`sm`,onClick:te,disabled:!ee,children:[N.isPending?r(T,{className:`h-3.5 w-3.5 animate-spin`}):r(k,{className:`h-3.5 w-3.5`}),u(`backup.restoreWizard.scheduleRestore`,`Schedule Restore`)]})]})]})]})})}function an({destinations:t,destinationId:n,onPickDestination:i,archives:a,archivesLoading:o,archiveId:s,onPickArchive:c}){let{t:l}=G(),u=t.filter(e=>e.restoreSupported);return e(`div`,{className:`p-4 space-y-3`,children:[e(`div`,{className:`space-y-1.5`,children:[r(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.destination`,`Destination`)}),r(Pe,{value:n??``,onChange:e=>i(e.target.value),options:[{value:``,label:l(`backup.restoreWizard.selectDestination`,`Select destination…`)},...u.map(e=>({value:e.id,label:`${e.displayName} (${e.kind})`}))]})]}),e(`div`,{className:`space-y-1.5`,children:[r(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.archive`,`Archive`)}),!n&&r(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.pickADestinationFirst`,`Pick a destination first.`)}),n&&o&&r(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:l(`backup.restoreWizard.readingArchives`,`Reading archives…`)}),n&&!o&&a.length===0&&r(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.noArchivesAvailableAtThis`,`No archives available at this destination.`)}),n&&a.length>0&&r(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:a.map(t=>{let n=s===t.id;return e(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${n?`bg-primary/10`:`hover:bg-primary/5`}`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(`input`,{type:`radio`,name:`archive`,checked:n,onChange:()=>c(t.id),className:`accent-primary`}),e(`div`,{children:[e(`div`,{className:`flex items-center gap-1 font-medium text-foreground`,children:[t.encryption!==void 0&&r(D,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.restoreWizard.encryptedKey`,`encrypted (key {{keyId}})`,{keyId:t.encryption.keyId})}),t.label??t.id]}),r(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(t.createdAt).toLocaleString()}),r(`div`,{className:`pt-1`,children:r(Z,{databases:pt(t.databases,void 0)})})]})]}),r(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:K(t.sizeBytes)})]},t.id)})})]})]})}function on({locations:t,picked:n,onToggle:i,databases:a,snapshotsOnly:o}){let{t:s}=G();return o?e(`div`,{className:`space-y-3 p-4`,children:[e(`div`,{className:`space-y-1.5`,children:[r(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),r(Z,{databases:a})]}),r(`div`,{className:`rounded border border-info/30 bg-info/10 px-3 py-2 text-[11px] text-info`,children:s(`backup.restoreWizard.snapshotsOnlyRestoringThisArchive`,`Snapshots only: restoring this archive replaces just these databases. It does NOT touch configuration, addons, addon data or certificates.`)})]}):t.length===0?r(`div`,{className:`p-4`,children:r(`div`,{className:`text-xs text-foreground-subtle`,children:s(`backup.restoreWizard.loadingArchiveManifestIfThis`,`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`)})}):e(`div`,{className:`p-4 space-y-3`,children:[e(`div`,{className:`space-y-1.5`,children:[r(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),r(Z,{databases:a})]}),r(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:s(`backup.restoreWizard.selectedEntriesWillOverwriteLive`,`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`)}),e(`div`,{className:`space-y-1.5`,children:[r(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:s(`common.apply`,`Apply`)}),r(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:t.map(t=>e(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[r(`input`,{type:`checkbox`,checked:n.has(t),onChange:()=>i(t),className:`accent-primary`}),r(`span`,{className:`font-mono text-foreground`,children:t}),r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:un(t)})]},t))})]})]})}function sn({destinationName:t,archive:n,picked:i,databases:a,snapshotsOnly:o}){let{t:s}=G();return e(`div`,{className:`p-4 space-y-3 text-xs`,children:[r(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-warning`,children:s(`backup.restoreWizard.restoreIsAppliedAtNext`,`Restore is applied at next server boot. Active connections will drop when you restart.`)}),e(`dl`,{className:`space-y-1.5`,children:[r($,{term:`Destination`,value:t}),r($,{term:`Archive`,value:n?.label??n?.id??`—`}),n&&r($,{term:`Created`,value:`${new Date(n.createdAt).toLocaleString()} · ${K(n.sizeBytes)}`}),e(`div`,{className:`flex justify-between gap-3`,children:[r(`dt`,{className:`text-foreground-subtle`,children:s(`backup.restoreWizard.databases`,`Databases`)}),r(`dd`,{className:`text-right`,children:r(Z,{databases:a})})]}),r($,{term:`Locations`,value:o?`none (configuration is not touched)`:i.length>0?i.join(`, `):`— (full archive)`})]})]})}function cn({keyId:t,value:n,onChange:i}){let{t:a}=G();return e(`div`,{className:`space-y-1.5 px-4 pb-3`,children:[r(`label`,{htmlFor:`restore-backup-key`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:a(`backup.restoreWizard.backupKey`,`Backup key`)}),r(`input`,{id:`restore-backup-key`,type:`password`,autoComplete:`off`,spellCheck:!1,value:n,onChange:e=>i(e.target.value),placeholder:a(`backup.restoreWizard.camstackBackupSecretV1`,`camstack-backup-secret-v1:…`),className:`w-full rounded border border-border bg-background px-2 py-1.5 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(Ve,{i18nKey:`backup.restoreWizard.encryptedTo`,values:{keyId:t},components:{mono:r(`span`,{className:`font-mono`})}})})]})}function $({term:t,value:n}){return e(`div`,{className:`flex justify-between gap-3`,children:[r(`dt`,{className:`text-foreground-subtle`,children:t}),r(`dd`,{className:`text-foreground font-mono text-right truncate`,children:n})]})}var ln={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function un(e){return ln[e]??``}o();function dn(){let{t}=G(),n=U(),o=se(),{state:s,openNew:c,openEdit:u,close:d}=Me({editKey:`edit`,newKey:`new`}),f=Se(),p=f.data??[],[m,h]=a(null),[g,_]=a(!1),[v,y]=a(!1),[b,x]=a(!1),S=s.mode===`edit`?p.find(e=>e.id===s.id)??null:null;i(()=>{s.mode===`edit`&&!f.isLoading&&S===null&&d()},[s.mode,f.isLoading,S,d]);let C=s.mode===`new`||s.mode===`edit`&&S!==null,E=async()=>{await n({title:t(`system.backup.restartServerNow`,`Restart server now?`),message:t(`system.backup.activeConnectionsWillDropAnd`,`Active connections will drop and the apply-backup hook will run before boot.`),confirmLabel:t(`system.backup.restart`,`Restart`),variant:`warning`})&&o.mutate({confirm:!0})};return e(Ge,{embedded:!0,children:[e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,"data-testid":`backup-actions`,children:[e(V,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>x(!0),"data-testid":`backup-now`,children:[r(l,{className:`h-3.5 w-3.5`}),t(`system.backup.backUpNow`,`Back up now`)]}),e(V,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[r(k,{className:`h-3.5 w-3.5`}),t(`system.backup.restore`,`Restore…`)]}),e(V,{size:`sm`,type:`button`,onClick:c,"data-testid":`backup-new-entry`,children:[r(w,{className:`h-3.5 w-3.5`}),t(`system.backup.newEntry`,`New entry`)]})]}),v&&r(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2.5 text-xs text-warning`,children:e(`div`,{className:`flex items-center justify-between gap-3`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(k,{className:`h-3.5 w-3.5`}),r(`span`,{children:t(`system.backup.restoreScheduledRestartTheServer`,`Restore scheduled. Restart the server to apply.`)})]}),e(V,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{E()},disabled:o.isPending,children:[o.isPending?r(T,{className:`h-3.5 w-3.5 animate-spin`}):r(k,{className:`h-3.5 w-3.5`}),t(`system.backup.restartNow`,`Restart Now`)]})]})}),r(Pt,{}),r(Kt,{}),r(bt,{onEdit:e=>u(e.id),onOpenRestoreWizard:e=>h(e)}),C&&r(Ht,{entry:S,onClose:d,onSaved:d}),b&&r(At,{onClose:()=>x(!1)}),(m||g)&&r(rn,{...m?{initialDestinationId:m.destinationId,initialArchiveId:m.archiveId}:{},onClose:()=>{h(null),_(!1)},onScheduled:()=>y(!0)})]})}o();function fn(e){return Object.entries(e).map(([e,t])=>`${e} ${t}`).join(` · `)}function pn(e){return e.reduce((e,t)=>e+Object.values(t.stores).reduce((e,t)=>e+t,0),0)}function mn(){let{t}=G(),n=U(),i=he(),[o,s]=a(null),[l,u]=a(null),d=async e=>{u(null);try{s(await i.mutateAsync({confirm:e}))}catch(e){u(e instanceof Error?e.message:String(e))}},f=async()=>{o===null||o.status!==`dry-run`||await n({title:t(`systemPage.deletedDevices.confirmTitle`,`Delete the data of deleted devices?`),message:o.devices.map(e=>`#${e.deviceId}: ${fn(e.stores)}`).join(`
|
|
2
|
-
`),confirmLabel:t(`systemPage.deletedDevices.confirmLabel`,`Delete`),variant:`danger`})&&await d(!0)},m=[{key:`device`,header:t(`systemPage.deletedDevices.device`,`Device`),render:e=>`#${e.deviceId}`},{key:`stores`,header:t(`systemPage.deletedDevices.stores`,`Data held`),nowrap:!1,render:e=>fn(e.stores)}];return e(`div`,{className:`space-y-4`,"data-testid":`deleted-devices-data`,children:[r(`p`,{className:`text-sm text-foreground-muted`,children:t(`systemPage.deletedDevices.intro`,`Data that still belongs to devices that were deleted before deletions were recorded: footage, events, history and per-addon settings. Scanning deletes nothing; deleting asks first and shows what goes.`)}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(V,{variant:`outline`,onClick:()=>void d(!1),disabled:i.isPending,"data-testid":`deleted-devices-scan`,children:[i.isPending?r(T,{className:`mr-2 h-4 w-4 animate-spin`}):r(S,{className:`mr-2 h-4 w-4`}),t(`systemPage.deletedDevices.scan`,`Scan`)]}),o?.status===`dry-run`&&o.devices.length>0?e(V,{variant:`danger`,onClick:()=>void f(),disabled:i.isPending,"data-testid":`deleted-devices-delete`,children:[r(p,{className:`mr-2 h-4 w-4`}),t(`systemPage.deletedDevices.delete`,`Delete the data of {{count}} devices…`,{count:o.devices.length})]}):null]}),l===null?null:r(`p`,{className:`text-sm text-danger`,children:l}),o?.status===`skipped`?r(`p`,{className:`text-sm text-warning`,"data-testid":`deleted-devices-skipped`,children:t(`systemPage.deletedDevices.skipped`,`Nothing was listed or deleted: the device list could not be trusted ({{reason}}). Try again.`,{reason:o.reason??``})}):null,o!==null&&o.status!==`skipped`?e(c,{children:[r(`p`,{className:`text-sm`,"data-testid":`deleted-devices-summary`,children:o.status===`cleaned`?t(`systemPage.deletedDevices.cleaned`,`Deleted {{rows}} items of {{count}} devices.`,{rows:pn(o.devices),count:o.devices.length}):t(`systemPage.deletedDevices.found`,`{{count}} deleted devices still hold {{rows}} items.`,{rows:pn(o.devices),count:o.devices.length})}),r(R,{columns:m,rows:o.devices,rowKey:e=>e.deviceId,emptyMessage:t(`systemPage.deletedDevices.none`,`No data belongs to a deleted device.`)}),o.unreachable.length>0?r(`p`,{className:`text-xs text-foreground-muted`,children:t(`systemPage.deletedDevices.unreachable`,`Not asked (unreachable): {{names}}`,{names:o.unreachable.join(`, `)})}):null]}):null]})}var hn=`view`,gn=`kinds`,_n=`deleted-devices`;function vn(){let{t}=G(),[n,i]=He(),a=n.get(`view`)===`deleted-devices`?_n:gn;return e(`div`,{className:u,children:[e(`div`,{className:`mb-3 space-y-2`,children:[r(ze,{appearance:`pills`,value:a,onValueChange:e=>{i(t=>{let n=new URLSearchParams(t);return e===`kinds`?n.delete(hn):n.set(hn,e),n},{replace:!0})},children:e(de,{className:`flex flex-wrap gap-1`,children:[r(ne,{value:gn,children:t(`systemPage.data.viewKinds`,`Record kinds`)}),r(ne,{value:_n,children:t(`systemPage.data.viewDeletedDevices`,`Deleted devices`)})]})}),a===`kinds`?r(`p`,{className:`text-xs text-foreground-muted`,children:t(`systemPage.data.recordsUnifiedIntro`,`Every declared record kind on this hub. Entry kinds can be added, edited and deleted; the rest are read-only. Secret fields are redacted.`)}):null]}),r(a===`kinds`?De:mn,{})]})}var yn={entries:null,"deleted-devices":`deleted-devices`};function bn(){let{t:e}=G(),t=Ue(`/system/data`,{t:e,isAdmin:!0})??{icon:m,title:e(`system.data`,`Data`)},[n]=He(),i=yn[n.get(`tab`)??``];if(i!==void 0){let e=new URLSearchParams(n);return e.set(`tab`,`records`),i!==null&&e.set(`view`,i),r(Be,{replace:!0,to:{search:e.toString()}})}return r(We,{icon:t.icon,title:t.title,defaultSection:`storage`,sectionsLabel:`${t.title} sections`,sections:[{id:`storage`,label:e(`systemPage.data.storage`,`Storage`),content:r(tt,{})},{id:`records`,label:e(`systemPage.data.records`,`Records`),content:r(vn,{}),ownedParams:[`view`,`recordsOwner`,`recordsKind`,`entryNew`,`entryEdit`]},{id:`backup`,label:e(`systemPage.data.backup`,`Backup`),content:r(dn,{})}]})}export{bn as DataPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,K as t,S as n,Y as r,et as i,i as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ci as s,It as c,bn as l,dt as u,hn as d,or as f,ot as p,sa as m,yr as h}from"./player-overlays-Dbv95cvz.js";import{Li as g,cr as _}from"./client-DvJxGh2F.js";import{A as v,Ba as y,C as b,Cn as x,D as S,Dr as C,E as w,Er as T,Gr as E,Kl as D,M as O,N as k,O as A,Or as ee,P as j,Qr as M,S as te,Ur as N,Wr as ne,_ as re,_r as ie,b as P,d as ae,do as F,f as oe,fr as se,gr as ce,h as le,j as ue,k as de,kr as I,m as fe,mn as pe,mr as me,pd as he,pn as ge,pr as _e,u as ve,v as ye,vr as be,w as xe,wn as L,wr as Se,x as R,xn as z,za as Ce}from"./src-ByunGuTZ.js";import{t as B}from"./useTranslation-BJr-n0es.js";import{mr as we}from"./index-BFjKpxae.js";import{t as Te}from"./AdminPage-BBb_f0ke.js";i();function V(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function Ee(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:R(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:V(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:R(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:V(t,n)})}return r}function De(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}var Oe=[`energy`,`temperatures`,`nodes`,`storage`],ke=new Set([`cap:temperature-sensor.celsius`,`cap:climate-control.currentTemp`]),H=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],Ae=`addon:storage-orchestrator/location-used-percent`;function je(e,t){let n=(e,n)=>{let r=t.filter(e);return P((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&ke.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&H.includes(e.info.key)&&e.info.scope===``,(e,t)=>H.indexOf(e.info.key)-H.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===Ae)}}function Me(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of P(e)){let e=n.get(R(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function U(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var W=`history-page`;function G(e){return`${e.subjectName} · ${e.metric}`}function Ne({part:r,window:i}){let{t:a}=B(),o=m(),c=t(()=>[...r.lines,...r.states,...r.energy],[r]),l=fe(t(()=>c.map(e=>U(e.ref)),[c]),i,!1),u=e=>l.status===`ok`?l.data.current.get(oe(U(e.ref))):void 0,d=e=>{let t=u(e);return t?.ok?t.result:void 0};if(c.length===0)return n(C,{icon:s,title:a(`history.page.emptyTitle`,`Pick series to compare`),description:a(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(l.status===`error`)return n(T,{title:a(`history.page.readFailed`,`History could not be read`),message:l.error});let f=l.status===`pending`,p=c.map(e=>({c:e,e:u(e)})).filter(e=>e.e?.ok===!1),h=r.lines.map((e,t)=>{let n=d(e),r=S(e.info,n,i.from);return{id:e.id,label:G(e),unit:e.info.unit,colorIndex:t,points:r.points,gapMs:r.gapMs,interpolation:r.held&&n?.resolution===`raw`?`step`:`linear`}}),g=r.states.map((e,t)=>{let n=A(e.info,d(e),i.from,i.to),r=xe(e.info.key,o);return{id:e.id,label:G(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?r.on:r.off:void 0}}),_=r.energy.map(e=>({c:e,...w(d(e))})),v=_[0]?.bucketMs??36e5,y=[...new Set(_.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:_.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return e(`div`,{className:`space-y-5 min-w-0`,children:[p.length>0&&n(T,{title:a(`history.page.someFailed`,`Some series could not be read`),message:p.map(e=>`${G(e.c)}: ${e.e.error}`).join(` · `)}),h.length>0&&n(j,{title:a(`history.page.lines`,`Measurements`),series:h,range:i,height:260,syncKey:W,pending:f}),_.length>0&&n(Se,{title:a(`history.page.energy`,`Energy`),layers:_.map((e,t)=>({id:e.c.id,label:e.c.subjectName,colorIndex:t})),buckets:y,bucketMs:v,range:i,unit:`kWh`,showTotal:!0,height:160,syncKey:W,pending:f}),g.length>0&&n(k,{title:g.length===1?g[0]?.label??``:a(`history.page.states`,`States`),rows:g,range:i,syncKey:W,pending:f})]})}function Pe(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function Fe(e,t){let n=[];for(let r of Pe(e,50))try{let{results:e}=await t(r),i=new Map(e.map(e=>[e.seriesId,e]));for(let e of r)n.push(i.get(e)??{seriesId:e,ok:!1,reason:`not-found`})}catch(e){let t=e instanceof Error?e.message:String(e);for(let e of r)n.push({seriesId:e,ok:!1,reason:`request-failed`,message:t})}return n}function K(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function Ie(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+K(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function Le(e,t){let n=new Map(e.map(e=>[e.seriesId,e]));return t.flatMap(e=>{let t=n.get(e.seriesId);return t===void 0?[]:[{series:t,outcome:e}]})}var q=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function J(e,t,n){let r=t.get(e.deviceId);return r===void 0?e.reason===`device-gone`?n(`history.orphans.deviceRemoved`,`#{{id}} (removed)`,{id:e.deviceId}):n(`history.orphans.deviceId`,`#{{id}}`,{id:e.deviceId}):r}function Y(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function X(t,r,i){return{key:`series`,header:i(`history.orphans.colSeries`,`Series`),render:a=>{let o=t(a);return e(`div`,{className:`min-w-0 max-w-[16rem]`,children:[n(`div`,{className:`truncate text-foreground`,title:o.key,children:Y(o)}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:J(o,r,i)})]})},sortValue:e=>`${J(t(e),r,i)} ${Y(t(e))}`}}var Re=[`raw`,`5m`,`1h`,`1d`];function ze(e,t){return e===`raw`?t(`history.orphans.colRaw`,`Raw points`):e===`5m`?t(`history.orphans.col5m`,`5 min`):e===`1h`?t(`history.orphans.col1h`,`1 h`):t(`history.orphans.col1d`,`1 day`)}function Be(t,r){return[X(e=>e,t,r),{key:`reason`,header:r(`history.orphans.colReason`,`Reason`),render:t=>e(`div`,{className:`flex flex-col items-start gap-0.5`,children:[n(M,{variant:t.reason===`device-gone`?`warning`:`neutral`,className:`text-[10px]`,children:t.reason===`device-gone`?r(`history.orphans.deviceGone`,`Device removed`):r(`history.orphans.undeclared`,`No longer declared`)}),t.missingSince!==null&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`history.orphans.since`,`since {{date}}`,{date:q(t.missingSince)})})]}),sortValue:e=>e.reason},{key:`span`,header:r(`history.orphans.colSpan`,`Recorded`),render:t=>e(`span`,{className:`tabular-nums text-foreground-muted`,children:[q(t.firstTs),` → `,q(t.lastTs)]}),sortValue:e=>e.lastTs},...Re.map(e=>({key:`rows-${e}`,header:ze(e,r),align:`right`,render:t=>n(`span`,{className:`tabular-nums text-foreground-muted`,children:t.rows[e].toLocaleString()}),sortValue:t=>t.rows[e]}))]}function Ve(e,t){if(e.ok)return n(M,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:K(e.deleted),points:K(e.deleted).toLocaleString(),defaultValue_one:`Deleted · {{points}} point`,defaultValue_other:`Deleted · {{points}} points`})});let r=e.reason===`request-failed`?t(`history.orphans.requestFailed`,`Not sent: {{message}}`,{message:e.message}):e.reason===`not-orphan`?t(`history.orphans.refusedNotOrphan`,`Kept: no longer orphan`):e.reason===`not-found`?t(`history.orphans.refusedNotFound`,`Already gone`):t(`history.orphans.refusedFailed`,`The hub could not delete it`);return n(M,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:r})}function He(e,t){return[X(e=>e.series,e,t),{key:`result`,header:t(`history.orphans.colResult`,`Result`),render:e=>Ve(e.outcome,t),sortValue:e=>+!e.outcome.ok}]}i();function Ue({open:i,onClose:a,list:o,deviceNames:s,onDelete:u,onRefresh:d,refreshing:p}){let{t:m}=B(),h=N(),[g,_]=r(new Set),[v,y]=r(!1),[b,S]=r([]),C=t(()=>Be(s,m),[s,m]),w=t(()=>He(s,m),[s,m]),T=t(()=>new Set(o.series.map(e=>String(e.seriesId))),[o.series]),D=[...g].filter(e=>T.has(e)).map(Number),O=Ie(b.map(e=>e.outcome)),k=async()=>{if(await h({title:m(`history.orphans.confirmTitle`,{count:D.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:m(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:m(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){y(!0);try{let e=await Fe(D,u);S(Le(o.series,e)),_(new Set)}finally{y(!1),d()}}};return n(se,{open:i,onOpenChange:e=>!e&&a(),children:e(me,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[n(ie,{children:n(be,{children:m(`history.orphans.title`,`Series no longer linked to a device`)})}),e(_e,{className:`space-y-3`,children:[n(`p`,{className:`text-xs text-foreground-muted`,children:m(`history.orphans.intro`,`Nothing records into these series any more: their device was removed, or no capability declares them now. Select the ones to delete.`)}),o.truncated&&e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`orphan-truncated`,children:[n(`p`,{className:`text-xs text-warning`,children:m(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),e(E,{size:`sm`,variant:`outline`,onClick:d,disabled:p,children:[n(l,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.loadAgain`,`Load again`)]})]}),b.length>0&&e(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[n(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:m(`history.orphans.summary`,{count:O.deleted,refused:O.refused,points:O.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),n(x,{columns:w,rows:b,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),n(x,{columns:C,rows:o.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:L,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:m(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:g,onChange:_,rowLabel:e=>`${Y(e)} — ${J(e,s,m)}`,pageLabel:m(`history.orphans.selectAll`,`Select every listed series`)}})]}),e(ce,{children:[n(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:m(`history.orphans.selected`,{count:D.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),n(E,{variant:`ghost`,size:`sm`,onClick:a,children:m(`history.orphans.close`,`Close`)}),e(E,{variant:`danger`,size:`sm`,disabled:D.length===0||v,onClick:()=>void k(),children:[v?n(f,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(c,{className:`h-3 w-3`,"aria-hidden":!0}),m(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}i();var Z=5*6e4;function We({enabled:i}){let{t:a}=B(),[s,c]=r(!1),l=y({},{enabled:i,staleTime:Z}),u=F({projection:`slim`},{enabled:i}),d=Ce(),f=t(()=>new Map((u.data??[]).map(e=>[e.id,e.name])),[u.data]),p=e=>d.mutateAsync({seriesIds:[...e]});if(!i||l.status===`pending`)return null;if(l.status===`error`)return n(T,{variant:`warning`,title:a(`history.orphans.checkFailedTitle`,`Could not check for unlinked series`),message:l.error.message,onRetry:()=>void l.refetch()});let m=l.data;if(m.series.length===0&&!s)return null;let h=m.series.length;return e(o,{children:[h>0&&n(T,{variant:`warning`,message:m.truncated?a(`history.orphans.noticeMore`,{count:h,defaultValue_one:`More than {{count}} series are no longer linked to a device.`,defaultValue_other:`More than {{count}} series are no longer linked to a device.`}):a(`history.orphans.notice`,{count:h,defaultValue_one:`{{count}} series is no longer linked to a device.`,defaultValue_other:`{{count}} series are no longer linked to a device.`}),action:n(E,{size:`sm`,variant:`outline`,onClick:()=>c(!0),children:a(`history.orphans.review`,`Review`)})}),n(Ue,{open:s,onClose:()=>c(!1),list:m,deviceNames:f,onDelete:p,onRefresh:()=>void l.refetch(),refreshing:l.isFetching})]})}i();var Q=`device`,Ge=`node`;function Ke({catalog:r,selected:i,onChange:a,loading:o}){let{t:s}=B(),c=ge(r,{searchText:e=>[De(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?Q:Ge},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),l=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:t=>e(`div`,{className:`min-w-0`,children:[n(`div`,{className:`truncate text-foreground`,children:t.metric}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.location===``?t.subjectName:`${t.subjectName} · ${t.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>n(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s]),u=i.size>=24;return e(`div`,{className:`space-y-2 min-w-0`,children:[n(pe,{state:c.state,facets:[],groups:[{...c.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===Q?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...c.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...c.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:c.setSearch,onToggleFacet:c.toggleFacet,onToggleGroupFacet:c.toggleGroupFacet,onClear:c.clear}),n(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:i.size,max:24})}),n(x,{columns:l,rows:c.rows,rowKey:e=>e.id,maxBodyHeight:L,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):c.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:i,onChange:e=>{let t=[...e].filter(e=>i.has(e)),n=[...e].filter(e=>!i.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>i.has(e.id)||!u,rowLabel:e=>`${e.subjectName} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}i();var qe=new Set([g.Hub,g.Container]),$=5*6e4;function Je(){let{t:r}=B(),i=ee(`device-history`),[a,o]=we(),c=t(()=>P(a.getAll(`s`).flatMap(e=>{let t=re(e);return t===null?[]:[t]})),[a]),l=a.get(`window`),f=ue(l)?l:`7d`,p=de(a.get(`range`)),m=(e,t,n)=>{let r=new URLSearchParams;for(let t of P(e))r.append(`s`,ye(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),o(r,{replace:!0})},g=Ye(i===`present`),_=O(f,Date.now(),p),y=O(f,ae(Date.now(),_.to-_.from),p),x=t(()=>Me(c,g.candidates),[c,g.candidates]),S=t(()=>new Set(c.map(R)),[c]),w=ve(),D=ne(),k=N(),A=async()=>{let e=await D({title:r(`history.page.saveTitle`,`Save as panel`),label:r(`history.page.saveName`,`Panel name`),confirmLabel:r(`history.page.save`,`Save`)});e===null||e.trim()===``||await w.update(t=>te(t,{id:`panel-${Date.now().toString(36)}`,name:e.trim().slice(0,80),window:f,selection:[...c]}))},j=async(e,t)=>{await k({title:r(`history.page.deleteTitle`,`Delete panel`),message:r(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:t}),confirmLabel:r(`history.page.delete`,`Delete`),variant:`danger`})&&await w.update(t=>b(t,e))},M=e=>e===`energy`?r(`history.panels.energy`,`Total energy`):e===`temperatures`?r(`history.panels.temperatures`,`Temperatures by room`):e===`nodes`?r(`history.panels.nodes`,`Cluster nodes`):r(`history.panels.storage`,`Storage locations`);return n(Te,{icon:s,title:r(`history.page.title`,`History`),subtitle:r(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:i===`present`?e(E,{size:`sm`,variant:`outline`,onClick:()=>void A(),disabled:c.length===0||!w.writable,children:[n(d,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:i===`pending`?n(I,{className:`h-64 w-full`}):i===`unknown`?n(T,{title:r(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:r(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):i===`absent`?n(C,{icon:h,title:r(`history.page.absentTitle`,`Device history is not running on this hub`),description:r(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):e(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(We,{enabled:i===`present`}),e(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":r(`history.page.panels`,`Panels`),children:[Oe.map(e=>n(E,{size:`sm`,variant:`outline`,disabled:g.status!==`ok`,onClick:()=>m(je(e,g.candidates),f),children:M(e)},e)),w.value.panels.map(t=>e(`span`,{className:`inline-flex items-center`,children:[n(E,{size:`sm`,variant:`secondary`,onClick:()=>m(t.selection,t.window,null),children:t.name}),n(E,{size:`sm`,variant:`ghost`,"aria-label":r(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void j(t.id,t.name),disabled:!w.writable,children:n(u,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),e(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[n(`div`,{className:`min-w-0 xl:col-span-2`,children:n(z,{headingId:`history-picker`,title:r(`history.picker.title`,`Series`),children:n(`div`,{className:`p-2 sm:p-3`,children:g.status===`error`?n(T,{message:g.error}):n(Ke,{catalog:g.candidates,loading:g.status===`pending`,selected:S,onChange:e=>{let t=c.filter(t=>e.has(R(t))),n=g.candidates.filter(t=>e.has(t.id)&&!S.has(t.id)).map(e=>e.ref);m([...t,...n],f)}})})})}),n(`div`,{className:`min-w-0 xl:col-span-3`,children:n(z,{headingId:`history-overlay`,title:r(`history.page.overlay`,`Overlay`),actions:c.length>0?n(E,{size:`sm`,variant:`ghost`,onClick:()=>m([],f),children:r(`history.page.clear`,`Clear`)}):void 0,children:e(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[n(le,{value:f,onChange:e=>m(c,e),custom:p,onCustomChange:e=>m(c,`custom`,v(e))}),g.status===`pending`&&c.length>0?n(I,{className:`h-64 w-full`}):n(Ne,{part:x,window:y}),x.missing.length>0&&g.status===`ok`&&n(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`history.page.missing`,{count:x.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]})]})})}function Ye(e){let{t:n}=B(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=p().trpcClient,o=F({projection:`slim`},{enabled:e}),{nodes:s}=he(),c=t(()=>(o.data??[]).filter(e=>!qe.has(String(e.type))),[o.data]),l=a({queries:c.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>i.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),u=a({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>i.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),d=D({},{enabled:e,staleTime:$}),f=t(()=>new Map((d?.data??[]).map(e=>[e.id,e.displayName])),[d?.data]),m=l.map(e=>e.data),h=u.map(e=>e.data),g=t(()=>Ee(c.flatMap((e,t)=>{let n=m[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=h[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return f.get(e.scope)??e.scope;let{zoneId:t,className:n}=_(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,f,[...l,...u].map(e=>e.dataUpdatedAt).join(`,`),r]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||l.some(e=>e.isPending)||u.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:g}}export{Je as HistoryPage};
|