@camstack/addon-admin-ui 1.2.35 → 1.2.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/dist/assets/{AddLocationWizard-BpkZ7g8M.js → AddLocationWizard-ruAb2ySj.js} +1 -1
  2. package/dist/assets/AddonCollectionPage-y9PlVqw3.js +1 -0
  3. package/dist/assets/Addons-cAsBu2OQ.js +1 -0
  4. package/dist/assets/{AdminTabs-BzqgdZo8.js → AdminTabs-BVHcviOJ.js} +1 -1
  5. package/dist/assets/{AiProfiles-Du2Gut1p.js → AiProfiles-B6EskvNu.js} +1 -1
  6. package/dist/assets/{BrokerForm-en5xEKn5.js → BrokerForm-DIw2g_KM.js} +1 -1
  7. package/dist/assets/Build-sVmfeGFf.js +29 -0
  8. package/dist/assets/Capabilities-CTlKJVid.js +1 -0
  9. package/dist/assets/{CapabilityBadges-2-jFnJcJ.js → CapabilityBadges-B_ZC7k04.js} +1 -1
  10. package/dist/assets/Cluster-DkXZdWpm.js +1 -0
  11. package/dist/assets/{ClusterRecordingTab-BdEH4zMe.js → ClusterRecordingTab-U0cdF9UF.js} +1 -1
  12. package/dist/assets/{Dashboard-Bi7LNLdP.js → Dashboard-BCNcg--7.js} +1 -1
  13. package/dist/assets/Data-ZtVnR1Fe.js +1 -0
  14. package/dist/assets/DetectionIntelligence-BlZl9E8S.js +1 -0
  15. package/dist/assets/{DeviceAggregateSection-D8oQ4avR.js → DeviceAggregateSection-UxtJHE5B.js} +1 -1
  16. package/dist/assets/DeviceDetail-BbYvgUSY.js +2 -0
  17. package/dist/assets/{Devices-BmmGXj4K.js → Devices-DzLVWcFg.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-CRkfP_Ng.js → EmbedPlayerPage-C5yT7D0W.js} +1 -1
  19. package/dist/assets/Events-BGJ5su4V.js +1 -0
  20. package/dist/assets/FormBuilder-C0N6NRfe.js +1 -0
  21. package/dist/assets/Identity-FI4f8ox5.js +1 -0
  22. package/dist/assets/IntegrationDetail-DxAOxN6t.js +1 -0
  23. package/dist/assets/Integrations-D5S4Yf1A.js +1 -0
  24. package/dist/assets/{Integrations-CsuR-wnp.js → Integrations-w3RuUxDV.js} +1 -1
  25. package/dist/assets/{Logs-D-v1pY1C.js → Logs-BfDIf7QZ.js} +1 -1
  26. package/dist/assets/{MotionZonesSettings-DSAuUczY.js → MotionZonesSettings-CHyWV5lm.js} +1 -1
  27. package/dist/assets/{MyAccess-CSduDxGh.js → MyAccess-76Y7QhMu.js} +1 -1
  28. package/dist/assets/Network-BAUdETHi.js +1 -0
  29. package/dist/assets/{NodeAddonsSettingsPanel-0BTA46bg.js → NodeAddonsSettingsPanel-CeWEr-Zg.js} +1 -1
  30. package/dist/assets/NodeInferenceDevices-CUinkSSN.js +1 -0
  31. package/dist/assets/Notifications-CK3PuxFQ.js +1 -0
  32. package/dist/assets/Pipeline-CTSS1aGu.js +1 -0
  33. package/dist/assets/Plates-Cns09Gg2.js +1 -0
  34. package/dist/assets/{PrivacyMaskSettings-CfGREDOs.js → PrivacyMaskSettings-C4ycA7Un.js} +1 -1
  35. package/dist/assets/{ProviderIcon-mSy1d917.js → ProviderIcon-DyK-gNEs.js} +1 -1
  36. package/dist/assets/Recordings-UAlZznSu.js +1 -0
  37. package/dist/assets/{ScanNetworkModal-DsEiGH4q.js → ScanNetworkModal-h3WtjMhA.js} +1 -1
  38. package/dist/assets/{Settings-_QzMAEQz.js → Settings-oupU5GDf.js} +1 -1
  39. package/dist/assets/{Showroom-BrqmuRQr.js → Showroom-HqqCUr23.js} +1 -1
  40. package/dist/assets/{Terminal-D6ADzUw6.js → Terminal-7B0qx8ho.js} +2 -2
  41. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D6JCOoeB.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BnceOEA8.js} +1 -1
  42. package/dist/assets/authed-media-B8T1dsFh.js +1 -0
  43. package/dist/assets/{rotate-ccw-RsWJHCWz.js → boxes-BS6UzXs9.js} +1 -1
  44. package/dist/assets/{build-cluster-graph-DK8tHUpQ.js → build-cluster-graph-CO-MCBmD.js} +2 -2
  45. package/dist/assets/circle-check-big-DKZCFZff.js +1 -0
  46. package/dist/assets/clock-DqPUDB1Y.js +1 -0
  47. package/dist/assets/{copy-CiHOHvWK.js → copy-bKWchDUS.js} +1 -1
  48. package/dist/assets/debounced-invalidate-CoCA-chF.js +1 -0
  49. package/dist/assets/dist-B66gZe27.js +7 -0
  50. package/dist/assets/{dist-CD_UFqu_.js → dist-CXHmz2j1.js} +1 -1
  51. package/dist/assets/{download-BbJFh_GP.js → download-C3-lXLSJ.js} +1 -1
  52. package/dist/assets/{face-bbox-DFwfVPg5.js → face-bbox-Cb2eJK0t.js} +1 -1
  53. package/dist/assets/{hostInit-Gt7MZSrm.js → hostInit-DtkE57IB.js} +1 -1
  54. package/dist/assets/index-Bke_0boK.js +4 -0
  55. package/dist/assets/index-mdJi1UIz.css +2 -0
  56. package/dist/assets/{key-round-wDYpv-03.js → key-round-CSNhr2jN.js} +1 -1
  57. package/dist/assets/{mf-entry-bootstrap-0-eafb02b4.js → mf-entry-bootstrap-0-e0821d3f.js} +2 -2
  58. package/dist/assets/{pencil-CGcp1H_S.js → pencil-Dbscj0iB.js} +1 -1
  59. package/dist/assets/{player-overlays-DnLMvF2y.js → player-overlays-CCOENCr_.js} +1 -1
  60. package/dist/assets/plus-kjGKne3v.js +1 -0
  61. package/dist/assets/{radio-DejuKcx3.js → radio-BCrXf-T5.js} +1 -1
  62. package/dist/assets/{refresh-cw-CW_Ljqdp.js → refresh-cw-B50UNH29.js} +1 -1
  63. package/dist/assets/remoteEntry-DSjWOwlm.js +1 -0
  64. package/dist/assets/rotate-ccw-CnFi79eH.js +1 -0
  65. package/dist/assets/rotate-cw-BMi2-EKp.js +1 -0
  66. package/dist/assets/search-Cqbwip0Z.js +1 -0
  67. package/dist/assets/{send-CJWIa1yB.js → send-vIA2Sg01.js} +1 -1
  68. package/dist/assets/{server-DLCgy7fU.js → server-CVgGKwKo.js} +1 -1
  69. package/dist/assets/square-NIJNDIvZ.js +1 -0
  70. package/dist/assets/{square-check-big-C1eD-s2U.js → square-check-big-DTiBKI6p.js} +1 -1
  71. package/dist/assets/src-C3IwZqep.js +7 -0
  72. package/dist/assets/src-DiF3p-RR.js +67 -0
  73. package/dist/assets/{undo-2-B2bADvVZ.js → undo-2-buMXiXDJ.js} +1 -1
  74. package/dist/assets/{upload-DeJAhsSx.js → upload-YICZuTHD.js} +1 -1
  75. package/dist/assets/{useEventInvalidation-BuTU98fj.js → useEventInvalidation-CGT7WKQk.js} +1 -1
  76. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CwEvP83T.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CbdC118i.js} +2 -2
  77. package/dist/assets/{wifi-BuwizIJA.js → wifi-B6uMvniy.js} +1 -1
  78. package/dist/assets/{zap-CWuo4dzD.js → zap-O3h5iXhW.js} +1 -1
  79. package/dist/index.html +6 -6
  80. package/dist/server/addon.js +1361 -1283
  81. package/package.json +1 -1
  82. package/dist/assets/AddonCollectionPage-CqEMePgW.js +0 -1
  83. package/dist/assets/Addons-cCLSqWfM.js +0 -1
  84. package/dist/assets/Automation-CryfmheY.js +0 -29
  85. package/dist/assets/Capabilities-DOVICQ71.js +0 -1
  86. package/dist/assets/Cluster-DSXKolnm.js +0 -1
  87. package/dist/assets/Data-CTCmNwJC.js +0 -1
  88. package/dist/assets/DetectionIntelligence-3cLwl4I3.js +0 -1
  89. package/dist/assets/DeviceDetail-BcRXDqYg.js +0 -2
  90. package/dist/assets/Events-CRvWzt-T.js +0 -1
  91. package/dist/assets/FormBuilder-D36jBkTY.js +0 -1
  92. package/dist/assets/Identity-D6X1Vx5c.js +0 -1
  93. package/dist/assets/IntegrationDetail-Kd39JHzv.js +0 -1
  94. package/dist/assets/Integrations-BUaA-BHV.js +0 -1
  95. package/dist/assets/Network-D2GsfRiT.js +0 -1
  96. package/dist/assets/NodeInferenceDevices-FEzIpBGg.js +0 -1
  97. package/dist/assets/Notifications-C2xW5T2d.js +0 -1
  98. package/dist/assets/Pipeline-BAy-OSuJ.js +0 -1
  99. package/dist/assets/Plates-B-enbHRO.js +0 -1
  100. package/dist/assets/Recordings-CVuEjle9.js +0 -1
  101. package/dist/assets/Retrain-B38fDPkv.js +0 -1
  102. package/dist/assets/authed-media-XfBD4Ma-.js +0 -1
  103. package/dist/assets/circle-check-big-CmRUug-s.js +0 -1
  104. package/dist/assets/clock-CbQ_m2UA.js +0 -1
  105. package/dist/assets/debounced-invalidate-CS1Zql4g.js +0 -1
  106. package/dist/assets/dist-DyDQKWiO.js +0 -7
  107. package/dist/assets/image-off-CePvOw2Z.js +0 -1
  108. package/dist/assets/index-D4VDD87s.css +0 -2
  109. package/dist/assets/index-DzefosH4.js +0 -4
  110. package/dist/assets/plus-CWclgqCc.js +0 -1
  111. package/dist/assets/remoteEntry-DNdwEnrY.js +0 -1
  112. package/dist/assets/rotate-cw-Bj3NywrT.js +0 -1
  113. package/dist/assets/search-kZ6MJ1BT.js +0 -1
  114. package/dist/assets/square-I9BIO4a-.js +0 -1
  115. package/dist/assets/src-C2KiI31z.js +0 -67
  116. package/dist/assets/src-DREH726E.js +0 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-admin-ui",
3
- "version": "1.2.35",
3
+ "version": "1.2.37",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Admin UI — Vite frontend build and server-side addon",
@@ -1 +0,0 @@
1
- import{At as e,Ho as t,Tt as n,Wo as r,d as i,g as a,m as o,oo as s,so as c}from"./src-C2KiI31z.js";import{Q as l,S as u,o as d,q as f,x as p,z as m}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as h}from"./plus-CWclgqCc.js";import{t as g}from"./refresh-cw-CW_Ljqdp.js";import{t as _}from"./square-I9BIO4a-.js";import{C as v,K as y,R as b,U as x,h as S,q as C}from"./index-DzefosH4.js";import{t as w}from"./AdminPage-Dq33XE9j.js";import{t as T}from"./NodeAddonsSettingsPanel-0BTA46bg.js";var E=y(`play`,[[`polygon`,{points:`6 3 20 12 6 21 6 3`,key:`1oa8hb`}]]);l();function D({addonId:e,fallback:t,tileClassName:n,iconPath:r=`assets/icon.svg`}){let[i,a]=f(!1),o=`/api/addon-assets/${e}/${r}`;return p(`div`,{className:`h-10 w-10 rounded-lg flex items-center justify-center shrink-0 ${n}`,children:i?p(t,{className:`h-5 w-5`}):p(`img`,{src:o,alt:e,className:`h-7 w-7 rounded-md bg-white p-1 ring-1 ring-black/5`,onError:()=>a(!0)})})}l();function O({addonId:e,defaultActivity:t,showActivity:n=!0,maxHeight:r=`max-h-64`,defaultTab:i,capability:s}){let[c,l]=f(t??(i===`events`?`events`:`logs`));return u(`div`,{className:`flex flex-col gap-4`,children:[p(T,{nodeId:`hub`,addonIds:[e],level:`global`,capability:s}),n&&u(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[u(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border bg-surface-hover/20`,children:[p(`span`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Activity`}),u(`div`,{className:`flex items-center gap-1`,children:[p(k,{kind:`logs`,active:c===`logs`,onClick:()=>l(`logs`)}),p(k,{kind:`events`,active:c===`events`,onClick:()=>l(`events`)})]})]}),c===`logs`?p(a,{addonId:e,maxHeight:r,showFilters:!1}):p(o,{addonId:e,category:`addon.*`,maxHeight:r})]})]})}function k({kind:e,active:t,onClick:n}){return u(`button`,{onClick:n,className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${t?`bg-primary/10 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[p(e===`logs`?S:x,{className:`h-3 w-3`}),e===`logs`?`Logs`:`Events`]})}l();function A(e){let{title:n,subtitle:i,pageIcon:a,itemIcon:o,capability:l,installButtonLabel:d=`Add addon`,items:g,isLoading:_,emptyTitle:v=`No addons installed for this capability`,emptyDescription:y,itemIconColor:x,renderStatusBadges:S,renderPrimaryAction:T,itemError:E,renderExpandedPanel:k,workspaceMaxHeight:A=`max-h-72`,trailing:P,showChrome:F=!1}=e,I=g.length>1,[L,R]=f(()=>g[0]?.addonId??null);m(()=>{L&&(g.some(e=>e.addonId===L)||R(g[0]?.addonId??null))},[g,L]);let z=e=>R(t=>t===e?null:e),B=`/system/addons?capability=${encodeURIComponent(l)}`;return p(w,{icon:F?a:void 0,title:F?n:void 0,subtitle:F?i:void 0,actions:F?p(C,{to:B,children:u(r,{variant:`primary`,size:`sm`,children:[p(h,{className:`h-3.5 w-3.5 mr-1`}),d]})}):void 0,children:_?p(t,{children:p(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):g.length===0?p(t,{children:p(c,{title:v,description:y??`Install an addon that declares the "${l}" capability to get started.`,action:F?p(C,{to:B,children:u(r,{variant:`primary`,size:`sm`,children:[p(h,{className:`h-3.5 w-3.5 mr-1`}),d]})}):void 0})}):u(`div`,{className:`flex flex-col gap-4`,children:[g.map(e=>{let n=!I||L===e.addonId,r=x?.(e)??(e.isActive?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`),i=E?.(e)??null;return u(t,{children:[u(`div`,{className:`flex flex-col gap-3 p-4 sm:flex-row sm:items-center ${n?`border-b border-border`:``}`,children:[u(`div`,{className:`flex items-center gap-3 flex-1 min-w-0`,children:[I&&p(`button`,{type:`button`,onClick:()=>z(e.addonId),"aria-label":n?`Collapse`:`Expand`,className:`shrink-0 p-1 rounded hover:bg-foreground-subtle/10 transition-colors`,children:p(b,{className:`h-4 w-4 text-foreground-subtle transition-transform ${n?`rotate-180`:``}`})}),u(`button`,{type:`button`,onClick:()=>I&&z(e.addonId),className:`flex items-center gap-4 flex-1 min-w-0 text-left ${I?`hover:opacity-80 transition-opacity`:``}`,disabled:!I,children:[p(D,{addonId:e.addonId,fallback:o,tileClassName:r}),u(`div`,{className:`flex-1 min-w-0`,children:[u(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[p(`span`,{className:`font-semibold text-foreground`,children:e.displayName}),p(j,{isActive:e.isActive}),S?.(e)]}),p(`div`,{className:`text-xs text-foreground-subtle mt-1 font-mono break-all`,children:e.addonId})]})]})]}),u(`div`,{className:`flex items-center gap-1 shrink-0 flex-wrap justify-end`,children:[T?.(e),p(M,{capName:e.capName??l,addonId:e.addonId,isActive:e.isActive}),p(N,{addonId:e.addonId,displayName:e.displayName})]})]}),n&&u(`div`,{className:`p-4 flex flex-col gap-3`,children:[i!==null&&p(s,{message:i}),k?.(e),p(O,{addonId:e.addonId,maxHeight:A,capability:e.capName??l})]})]},e.addonId)}),P]})})}function j({isActive:e}){return p(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${e?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:e?`Enabled`:`Disabled`})}function M({capName:t,addonId:n,isActive:i}){let a=d(),o=e({onSuccess:()=>{a.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}}),s=o.isPending;return u(r,{size:`sm`,variant:i?`secondary`:`primary`,disabled:s,onClick:()=>o.mutate({capName:t,addonId:n,enabled:!i}),children:[s?p(v,{className:`h-3 w-3 animate-spin`}):p(i?_:E,{className:`h-3 w-3`}),i?`Disable`:`Enable`]})}function N({addonId:e,displayName:t}){let r=d(),a=n({onSuccess:()=>{r.invalidateQueries({queryKey:[[`addons`,`listCapabilityProviders`]]})}});return p(i,{label:`Restart`,icon:g,size:`sm`,title:`Restart "${t}"?`,description:`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:a.isPending,action:()=>a.mutateAsync({addonId:e})})}export{E as n,A as t};
@@ -1 +0,0 @@
1
- import{Ct as e,Dt as t,Mt as n,Nt as r,Ot as i,Rr as a,St as o,Tt as s,Wr as c,_t as l,ao as ee,bt as u,co as d,do as f,g as p,gt as m,ht as h,jt as g,kt as _,m as v,mt as te,pt as ne,v as re,vt as ie,wt as y,yt as ae}from"./src-C2KiI31z.js";import{I as b,K as x,Q as S,R as oe,S as C,W as w,b as T,o as E,q as D,x as O,z as k}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{Q as A}from"./src-DREH726E.js";import{p as se}from"./player-overlays-DnLMvF2y.js";import{t as j}from"./clock-CbQ_m2UA.js";import{t as M}from"./download-BbJFh_GP.js";import{t as ce}from"./plus-CWclgqCc.js";import{t as N}from"./refresh-cw-CW_Ljqdp.js";import{t as le}from"./search-kZ6MJ1BT.js";import{t as P}from"./upload-DeJAhsSx.js";import{C as F,J as ue,K as I,P as de,R as fe,X as L,_ as R,c as z,h as pe,i as B,m as V,z as H}from"./index-DzefosH4.js";import{t as U}from"./AdminPage-Dq33XE9j.js";import{t as me}from"./NodeAddonsSettingsPanel-0BTA46bg.js";var he=I(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),W=I(`octagon-alert`,[[`path`,{d:`M12 16h.01`,key:`1drbdi`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z`,key:`1fd625`}]]),ge=I(`package`,[[`path`,{d:`M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z`,key:`1a0edw`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}]]),G=I(`skip-forward`,[[`polygon`,{points:`5 4 15 12 5 20 5 4`,key:`16p6eg`}],[`line`,{x1:`19`,x2:`19`,y1:`5`,y2:`19`,key:`futhcm`}]]);S();var K=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),q=new Set([`done`,`failed`,`skipped`]);function J(e){return!q.has(e.phase)&&!K.has(e.jobState)}function _e(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=K.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 ve(){let{data:e}=o({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=f(A.AddonsJobProgress,e=>e.job.jobId);return w(()=>{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 _e([...n.values()],Date.now())},[e,t])}var Y={queued:{icon:j,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:F,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:F,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:F,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:F,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:F,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:F,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:H,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:W,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:G,cls:`bg-muted text-foreground-subtle`,label:`skipped`}};function ye({progress:e}){let t=Y[e.phase],n=t.icon,r=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return C(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${t.cls}`,title:r,children:[O(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label,C(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function be({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:i,onSelect:a,selectedVersion:o}){let s=n===`upload`||n===`local`,{data:c,isLoading:l}=ie({name:e});return C(`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:[C(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[O(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),O(`button`,{type:`button`,onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:O(B,{className:`h-3 w-3`})})]}),s&&C(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[O(P,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),C(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[C(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,O(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),l&&C(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[O(F,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),c&&O(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:c.map(e=>{let n=e.version===t,i=a!==void 0&&e.version===o,c=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),l=C(T,{children:[O(`span`,{className:`font-mono flex-1 text-left ${n?`text-primary font-semibold`:c?`text-amber-400`:`text-foreground`}`,children:e.version}),n&&O(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:`current`}),e.distTags.map(e=>O(`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)),e.deprecated&&O(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),O(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return a?C(`button`,{type:`button`,"aria-label":`Select ${e.version}`,onClick:()=>a(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${i?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[l,i?O(H,{className:`h-3 w-3 text-primary shrink-0`}):O(`span`,{className:`w-3 shrink-0`})]},e.version):C(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[l,n&&!s?O(H,{className:`h-3 w-3 text-primary shrink-0`}):O(`button`,{type:`button`,onClick:()=>r(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:n?`Re-install ${e.version} from npm`:`Install ${e.version}`,children:O(M,{className:`h-3 w-3`})})]},e.version)})}),c&&c.length===0&&O(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var xe={queued:{icon:j,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:F,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:N,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:H,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:W,bg:`bg-danger/10 text-danger`,label:`failed`}};function Se({item:e}){let t=xe[e.status],n=t.icon;return C(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[O(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}S();var X=`device-export`;function Ce(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===X)}function we({isBundle:e,installSource:t,addonId:n,iconPath:r,color:i}){let[a,o]=D(!1),s=i?{backgroundColor:`${i.startsWith(`#`)?i:`#${i}`}26`}:void 0,c=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,l=n&&r?`/api/addon-assets/${n}/${r}`:null,ee=!!l&&!a;return C(`div`,{className:`relative flex-shrink-0`,children:[O(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${s?``:c}`,style:s,children:ee?O(`img`,{src:l,alt:n,className:`h-5 w-5`,onError:()=>o(!0)}):O(e?ge:R,{className:`h-4 w-4`})}),t===`local`&&O(`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`}),t===`npm`&&O(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:O(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:O(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&O(`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:O(P,{className:`h-2.5 w-2.5 text-white`})})]})}function Te({version:e,availableUpdate:t,selectedVersion:n,isUpdating:r,installSource:i,disabled:a,onUpdate:o,onOpenPicker:s,children:c}){if(r)return C(`span`,{className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[O(F,{className:`h-3 w-3 animate-spin`}),`Updating…`]});if(t){let r=n??t;return C(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[o&&C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:a,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 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:`Update to ${r}`,children:[O(M,{className:`h-3 w-3`}),`Update`]}),C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:a,"aria-label":`Select version to install`,title:`Installed ${e} — update available. Selected ${r}; tap to choose another version.`,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 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:[O(`span`,{className:`font-normal opacity-70`,children:e}),O(`span`,{className:`font-normal opacity-70`,children:`→`}),r,O(fe,{className:`h-3 w-3`})]}),c]})}return C(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:a,className:[`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,i===`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:`Version ${e} — tap to view all versions`,children:[e,O(fe,{className:`h-3 w-3 opacity-50`})]}),c]})}function Ee({addonId:e}){let t=E(),{data:n=`inherit`}=h({addonId:e}),r=_({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return O(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>O(`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))})}function De({addon:e,agents:r=[],clusterStatus:i,hideVersion:a,availableUpdate:o,onUpdate:c,isUpdating:l,jobProgress:u,bundle:d,bulkItem:f,disabledByBulk:m,isSystem:h}){let[g,_]=D(!1),[te,ne]=D(!1),[ie,y]=D(!1),[b,x]=D(null);k(()=>{x(null)},[o]);let S=b??o,[oe,w]=D(!1),[A,j]=D(!1),[M,le]=D(`logs`),P=E(),F=se(),I=ue(),de=ee(),{manifest:L}=e,R=e.installedOn??[],H=!d&&!L.protected&&L.removable!==!1,U=!!d,G=d?.displayName??L.name,K=d?.packageName??L.packageName,q=d?.version??L.packageVersion??L.version,J=d?.installSource??e.installSource,_e=d?d.bundle?.description??d.addons[0]?.manifest.description:L.description,ve=n({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`addonPages`]]}),P.invalidateQueries({queryKey:[[`capabilities`]]})}}),Y=s({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]})}}),xe=ae({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`addonPages`]]}),P.invalidateQueries({queryKey:[[`capabilities`]]}),P.invalidateQueries({queryKey:[[`integrations`]]})}}),X=t({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`alerts`]]})}}),Z=e.health,Q=Z?.phase===`failed`&&!Z.inGracePeriod,Oe=Q&&Z?.nextRetryAt&&!Z.retrying;return C(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${Q?`border-red-500/50`:`border-border`}`,children:[Q&&Z&&C(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[O(W,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),C(`div`,{className:`flex-1 min-w-0`,children:[C(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,Z.retryCount,`)`]}),O(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:Z.lastError?.message??`Unknown error`}),Oe&&Z.nextRetryAt&&C(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(Z.nextRetryAt).toLocaleTimeString()]})]}),C(`button`,{type:`button`,disabled:X.isPending||Z.retrying,onClick:e=>{e.stopPropagation(),X.mutate({packageName:K})},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:`Reset retry counter and force immediate reload`,children:[O(N,{className:`h-3 w-3 ${X.isPending||Z.retrying?`animate-spin`:``}`}),`Retry now`]})]}),C(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[O(we,{isBundle:U||!!L.components&&L.components.length>1,installSource:J,addonId:U?d.addons[0]?.manifest.id:L.id,iconPath:U?d.bundle?.icon??d.addons[0]?.manifest.icon:L.icon,color:U?d.addons[0]?.manifest.color:L.color}),C(`div`,{className:`flex-1 min-w-0`,children:[C(`div`,{className:`flex items-start justify-between gap-2`,children:[O(`span`,{className:`text-sm font-semibold text-foreground truncate min-w-0`,children:G}),!a&&O(Te,{version:q,availableUpdate:o,...S===void 0?{}:{selectedVersion:S},isUpdating:l,installSource:J,disabled:m,...c&&S!==void 0?{onUpdate:()=>c(S)}:{},onOpenPicker:()=>y(e=>!e),children:ie&&O(be,{packageName:K,currentVersion:q,...J?{installSource:J}:{},...o!==void 0&&S!==void 0?{selectedVersion:S,onSelect:e=>{x(e),y(!1)}}:{},onInstall:e=>{y(!1),xe.mutate({packageName:K,version:e})},onClose:()=>y(!1)})})]}),C(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[K!==G&&O(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:K}),U&&C(`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:[O(ge,{className:`h-3 w-3`}),d.addons.length]}),h&&C(`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:`System package — updating restarts the hub`,children:[O(N,{className:`h-3 w-3`}),`System`]}),f!=null&&O(Se,{item:f}),u!=null&&O(ye,{progress:u})]}),_e&&O(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:_e}),!U&&e.process&&C(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[O(`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`?`forked`:`in-process`}),e.process.pid!=null&&C(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),O(`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`:e.process.state===`crashed`||e.process.state===`failed`?`bg-red-500/15 text-red-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.state})]})]})]}),!U&&C(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),Y.mutate({addonId:L.id})},disabled:Y.isPending||m,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 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:[O(N,{className:`h-3 w-3 ${Y.isPending?`animate-spin`:``}`}),`Restart`]}),C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),w(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 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:[O(pe,{className:`h-3 w-3`}),`Logs`]}),!U&&C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),j(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 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:[O(V,{className:`h-3 w-3`}),`Settings`]}),O(`div`,{className:`flex-1`}),H&&C(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await de({title:`Uninstall ${L.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&ve.mutate({packageName:L.packageName})},disabled:ve.isPending||m,className:`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`,children:[O(z,{className:`h-3 w-3`}),ve.isPending?`Removing...`:`Uninstall`]})]}),i&&i.nodes.length>1&&!U&&C(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),O(`div`,{className:`space-y-1`,children:i.nodes.map(e=>C(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[O(`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`}`}),O(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),O(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&O(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:`outdated`}),e.status===`offline`&&O(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&O(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),oe&&!U&&C(`div`,{className:`border-t border-border`,children:[C(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[C(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[O(`button`,{type:`button`,onClick:()=>le(`logs`),className:`px-2 py-0.5 transition-colors ${M===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),O(`button`,{type:`button`,onClick:()=>le(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${M===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),O(`div`,{className:`flex-1`}),O(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),w(!1)},className:`text-foreground-subtle hover:text-foreground`,children:O(B,{className:`h-3.5 w-3.5`})})]}),M===`logs`&&O(p,{addonId:L.id,maxHeight:`max-h-64`,showFilters:!1}),M===`events`&&O(v,{addonId:L.id,category:`addon.*`,maxHeight:`max-h-64`})]}),U&&C(T,{children:[O(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:O(g?he:fe,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),g&&O(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:d.addons.map(e=>O(De,{addon:e,agents:r,hideVersion:!0},e.manifest.id))})]}),A&&!U&&O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>j(!1),children:C(`div`,{className:`w-full max-w-lg max-h-[80vh] rounded-xl border border-border bg-surface shadow-2xl flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[C(`div`,{className:`flex items-center gap-2`,children:[O(V,{className:`h-4 w-4 text-primary`}),C(`h2`,{className:`text-sm font-semibold text-foreground`,children:[G,` Settings`]})]}),O(`button`,{onClick:()=>j(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:O(B,{className:`h-4 w-4`})})]}),C(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[O(me,{nodeId:`hub`,addonIds:[L.id],level:`global`}),Ce(L)&&C(`div`,{children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),O(re,{addonId:L.id,trpc:F.trpcClient,onOpenDevice:e=>I(`/devices/${e}`)})]}),J===`npm`&&C(`div`,{children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),O(Ee,{addonId:L.id})]}),L.components&&L.components.length>0&&C(`div`,{children:[C(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,L.components.length,`)`]}),O(`div`,{className:`flex flex-wrap gap-1`,children:L.components.map(e=>O(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),r.length>=2&&C(`div`,{children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),C(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[R.length===0&&O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),R.map(e=>O(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),C(`div`,{className:`relative`,children:[C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ne(e=>!e)},className:`inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:border-primary transition-colors`,title:`Install on more agents`,children:[O(ce,{className:`h-3 w-3`}),`Add agent`]}),te&&C(`div`,{className:`absolute left-0 top-full mt-1 z-10 min-w-[160px] rounded-md border border-border bg-surface shadow-lg overflow-hidden`,children:[r.filter(e=>!e.isHub&&!R.includes(e.name)).map(e=>O(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ne(!1)},className:`w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors`,children:e.name},e.id)),r.filter(e=>!e.isHub&&!R.includes(e.name)).length===0&&O(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),O(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:O(`button`,{type:`button`,onClick:()=>j(!1),className:`rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:`Close`})})]})})]})}S();var Z=`.tgz,.tar.gz,.zip`;function Q({onUploadSuccess:e}){let[t,n]=D(!1),r=x(null),i=b(async t=>{n(!0);let r=new FormData;r.append(`file`,t);let i=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(`/api/addons/upload`,{method:`POST`,headers:{Authorization:`Bearer ${i}`},body:r})).json()).success&&e()}finally{n(!1)}},[e]);return C(T,{children:[O(`input`,{ref:r,type:`file`,accept:Z,onChange:b(e=>{let t=e.target.files?.[0];t&&i(t),e.target.value=``},[i]),className:`hidden`}),C(`button`,{type:`button`,onClick:()=>r.current?.click(),disabled:t,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:[t?O(F,{className:`w-3.5 h-3.5 animate-spin`}):O(P,{className:`w-3.5 h-3.5`}),t?`Uploading...`:`Upload`]})]})}S();var Oe=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function ke(e){return e!==void 0&&Oe.has(e)}function Ae(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function je(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`}: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 Me(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 Ne({addons:t,clusterStatus:n,selectedNode:a,onRefresh:o,isRefreshing:s}){let c=E(),[u,d]=D(``),f=oe(u),[p,h]=D(!1),_=x(null);k(()=>{if(!p)return;let e=e=>{_.current&&!_.current.contains(e.target)&&h(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[p]);let{data:v}=e({nodeId:a.id}),te=w(()=>{let e=new Map;for(let t of v??[])e.set(t.name,t.latestVersion);return e},[v]),re=w(()=>(v??[]).filter(e=>!e.isSystem).length,[v]),[ie,y]=D(()=>new Set),[S,T]=D(()=>new Map),A=b(e=>{y(t=>new Set(t).add(e))},[]),se=b(e=>{y(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),j=b((e,t)=>{T(n=>new Map(n).set(e,t))},[]),ce=b(e=>{T(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),P=r({onMutate:e=>{A(e.name),ce(e.name)},onSuccess:(e,t)=>{se(t.name);let n=e;if(n&&n.success===!1){j(t.name,n.error??`Update failed (no error message returned by server)`);return}c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{se(t.name),j(t.name,e instanceof Error?e.message:String(e))}}),ue=ve(),I=x(new Set);k(()=>{let e=new Set;for(let[t,n]of ue)J(n)&&e.add(t);let t=[...I.current].some(t=>!e.has(t));I.current=e,t&&(c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[ue,c]);let{data:fe}=m(void 0),R=ne({onSuccess:()=>{c.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:z,isFetching:pe}=i({query:f||void 0},{enabled:p}),B=g(),{data:V}=l(void 0),U=V?.requestedAt,[me,he]=D(null),[W,ge]=D(!1);k(()=>{if(V?.kind===`framework-bulk-update`&&V.requestedAt!==me){he(V.requestedAt),ge(!0);let e=window.setTimeout(()=>ge(!1),6e3);return()=>window.clearTimeout(e)}},[U,me,V]),ee();let G=b(async()=>{let e=(v??[]).filter(e=>!e.isSystem);e.length!==0&&await B.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[a.id]})},[v,a.id,B]),K=ae({onSuccess:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addonPages`]]}),c.invalidateQueries({queryKey:[[`capabilities`]]}),c.invalidateQueries({queryKey:[[`integrations`]]})}}),[q,_e]=D(`type`),[Y,ye]=D(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),be=e=>{ye(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[xe,Se]=L(),X=xe.get(`capability`),Ce=w(()=>{let e=t.filter(e=>!ke(e.manifest.packageName));return a.isHub||(e=e.filter(e=>Ae(e.placement,a.isHub))),X&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===X))),e},[t,a.isHub,X]),we=()=>{let e=new URLSearchParams(xe);e.delete(`capability`),Se(e,{replace:!0})},Te=Y===`flat`?Ce:Me(Ce),Ee=w(()=>{let e=[...Te];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},[Te,q]);return C(`div`,{className:`space-y-4`,children:[[...S.entries()].map(([e,t])=>O(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:C(`div`,{className:`flex items-start justify-between gap-3`,children:[C(`div`,{className:`space-y-0.5`,children:[C(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,e]}),O(`div`,{className:`text-foreground-subtle font-mono`,children:t})]}),O(`button`,{type:`button`,onClick:()=>ce(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})},e)),C(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[C(`div`,{className:`flex items-center gap-1.5`,children:[O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),C(`select`,{value:q,onChange:e=>_e(e.target.value),className:`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground focus:outline-none focus:border-primary/50`,children:[O(`option`,{value:`type`,children:`Bundles first`}),O(`option`,{value:`name`,children:`Name`}),O(`option`,{value:`source`,children:`Install source`})]})]}),C(`div`,{className:`flex items-center gap-1.5`,children:[O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),O(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>O(`button`,{type:`button`,onClick:()=>be(e),className:`px-2.5 py-1.5 transition-colors capitalize ${Y===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?`Group multi-addon packages into a bundle card`:`Show every addon as its own card`,children:e},e))})]}),a.isHub&&C(`div`,{className:`flex items-center gap-1.5`,children:[O(N,{className:`h-3 w-3 text-foreground-subtle`}),O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),O(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>O(`button`,{type:`button`,onClick:()=>R.mutate({channel:e}),disabled:R.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${fe?.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))})]}),re>0&&C(`button`,{type:`button`,onClick:()=>void G(),disabled:B.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium`,children:[B.isPending?O(F,{className:`w-3 h-3 animate-spin`}):O(M,{className:`w-3 h-3`}),B.isPending?`Updating…`:`Update All (${re})`]}),C(`button`,{type:`button`,onClick:o,disabled:s||B.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[O(N,{className:`w-3 h-3 ${s?`animate-spin`:``}`}),`Refresh`]})]}),C(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[C(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:_,children:[O(le,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),O(`input`,{type:`text`,value:u,onChange:e=>{d(e.target.value),h(!0)},onFocus:()=>h(!0),placeholder:`Search addons on npm...`,disabled:B.isPending,className:`w-full rounded-lg border border-border bg-background pl-9 pr-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-50 disabled:cursor-not-allowed`}),pe&&O(F,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),p&&z&&z.length>0&&C(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,children:[z.length>0&&C(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,z.length,`)`]}),z&&z.length>0&&O(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:z.map(e=>C(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[O(`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()}),C(`div`,{className:`flex-1 min-w-0`,children:[C(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[O(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),C(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),O(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&O(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?C(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md border border-emerald-500/30 bg-emerald-500/10 text-emerald-400 shrink-0`,children:[O(H,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):C(`button`,{type:`button`,onClick:()=>K.mutate({packageName:e.name}),disabled:K.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[K.isPending?O(F,{className:`h-3 w-3 animate-spin`}):O(M,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),O(Q,{onUploadSuccess:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),o()}})]}),X&&C(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[O(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),O(`span`,{className:`font-mono text-primary font-semibold`,children:X}),O(`button`,{type:`button`,onClick:we,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),W&&C(`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:[O(de,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),C(`div`,{children:[O(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),O(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),Ce.length===0&&O(`div`,{className:`text-xs text-foreground-subtle`,children:t.length===0?`No addons installed`:X?`No installed addons declare the "${X}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${a.name} (placement filter active)`}),O(`div`,{className:`space-y-2`,children:Ee.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,r=te.get(t),i=$(e)?e.representative:e,o=r?e=>P.mutate({name:t,version:e,nodeId:a.id}):void 0,s=ue.get(t)??null,c=s!==null&&J(s);return O(De,{addon:i,clusterStatus:n?.[i.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:r,isUpdating:ie.has(t)||c,jobProgress:s,onUpdate:o,disabledByBulk:B.isPending},$(e)?t:e.manifest.id)})})]})}function Pe(){let e=E(),{data:t,isLoading:n,isError:r}=u(),{data:i}=a(void 0),{data:o}=c(void 0,{refetchInterval:1e4}),s=w(()=>{let e=new Map;e.set(`hub`,{id:`hub`,name:`Hub`,isHub:!0});for(let t of o??[]){let n=String(t.id??``);n&&e.set(n,{id:n,name:String(t.name??n),isHub:!!t.isHub})}return[...e.values()]},[o]),[l,ee]=D(`hub`),f=s.find(e=>e.id===l)??s[0],p=te(),m=y(),h=p.isPending||m.isPending,g=async()=>{await p.mutateAsync({nodeId:l}),await m.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},_=x(p);_.current=p,k(()=>{_.current.mutate({nodeId:`hub`})},[]);let v=(t??[]).map(je).filter(e=>e!==null);return C(U,{children:[C(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(d,{selectedNodeId:l,onSelect:ee}),C(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!n&&!r&&C(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[v.length,` installed`]}),C(`button`,{type:`button`,onClick:()=>void g(),disabled:h,className:`inline-flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:`Re-fetch addons + check npm for new versions`,children:[O(N,{className:`w-3 h-3 ${h?`animate-spin`:``}`}),`Check for updates`]})]})]}),!f.isHub&&C(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[`Showing only addons compatible with`,` `,O(`span`,{className:`font-medium text-foreground`,children:f.name}),` — agents only run`,` `,O(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,O(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),n&&O(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),r&&O(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!n&&!r&&O(Ne,{addons:v,clusterStatus:i,selectedNode:f,onRefresh:()=>void g(),isRefreshing:h})]})}export{Pe as AddonsPage};
@@ -1,29 +0,0 @@
1
- import{Co as e,Eo as t,Ho as n,Qo as r,To as i,Uo as a,Vo as o,Wo as s,co as c,oo as l,wo as u}from"./src-C2KiI31z.js";import{I as d,K as f,M as p,Q as m,S as h,T as g,W as _,a as v,q as y,t as b,x,z as S}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as C}from"./player-overlays-DnLMvF2y.js";import{t as w}from"./pencil-CGcp1H_S.js";import{t as T}from"./plus-CWclgqCc.js";import{C as E,X as D,a as O,c as k,s as A}from"./index-DzefosH4.js";import{t as j}from"./AdminPage-Dq33XE9j.js";function M({onOpenScripts:e}){return x(n,{children:h(`div`,{className:`max-w-2xl space-y-3 p-6`,children:[h(`div`,{className:`flex items-center gap-2`,children:[x(O,{className:`h-5 w-5 text-foreground-subtle`}),x(`h3`,{className:`font-medium`,children:`Automations are not built yet`})]}),h(`p`,{className:`text-sm text-foreground-subtle`,children:[`A CamStack automation will be a `,x(`strong`,{children:`trigger`}),`, a set of`,` `,x(`strong`,{children:`conditions`}),`, and `,x(`strong`,{children:`actions`}),` — authored here, with its own trigger vocabulary. It is deliberately not the notification rule engine: the two share words and nothing else, and folding one into the other was ruled out.`]}),h(`p`,{className:`text-sm text-foreground-subtle`,children:[`Nothing is hidden behind this tab — there is no engine to configure, so there is no screen to show. Until there is, a `,x(`strong`,{children:`script`}),` does the same job in code: it runs in its own supervised process with the full addon context, so it can watch the event bus and drive devices.`]}),x(s,{variant:`outline`,onClick:e,children:`Write a script instead`})]})})}m();function N(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function P(e){if(Array.isArray(e))return e}function F(e,t,n){return(t=ae(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ee(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function te(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
2
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function I(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function L(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?I(Object(n),!0).forEach(function(t){F(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):I(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function R(e,t){if(e==null)return{};var n,r,i=ne(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function ne(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function re(e,t){return P(e)||ee(e,t)||oe(e,t)||te()}function ie(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function ae(e){var t=ie(e,`string`);return typeof t==`symbol`?t:t+``}function oe(e,t){if(e){if(typeof e==`string`)return N(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?N(e,t):void 0}}function se(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ce(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function le(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ce(Object(n),!0).forEach(function(t){se(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ce(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ue(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function z(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function B(e){return{}.toString.call(e).includes(`Object`)}function de(e){return!Object.keys(e).length}function V(e){return typeof e==`function`}function fe(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function pe(e,t){return B(t)||H(`changeType`),Object.keys(t).some(function(t){return!fe(e,t)})&&H(`changeField`),t}function me(e){V(e)||H(`selectorType`)}function he(e){V(e)||B(e)||H(`handlerType`),B(e)&&Object.values(e).some(function(e){return!V(e)})&&H(`handlersType`)}function ge(e){e||H(`initialIsRequired`),B(e)||H(`initialType`),de(e)&&H(`initialContent`)}function _e(e,t){throw Error(e[t]||e.default)}var H=z(_e)({initialIsRequired:`initial state is required`,initialType:`initial state should be an object`,initialContent:`initial state shouldn't be an empty object`,handlerType:`handler should be an object or a function`,handlersType:`all handlers should be a functions`,selectorType:`selector should be a function`,changeType:`provided value of changes should be an object`,changeField:`it seams you want to change a field in the state which is not specified in the "initial" state`,default:"an unknown error accured in `state-local` package"}),U={changes:pe,selector:me,handler:he,initial:ge};function ve(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};U.initial(e),U.handler(t);var n={current:e},r=z(xe)(n,t),i=z(be)(n),a=z(U.changes)(e),o=z(ye)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return U.selector(e),e(n.current)}function c(e){ue(r,i,a,o)(e)}return[s,c]}function ye(e,t){return V(t)?t(e.current):t}function be(e,t){return e.current=le(le({},e.current),t),t}function xe(e,t,n){return V(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Se={create:ve},Ce={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function we(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function Te(e){return{}.toString.call(e).includes(`Object`)}function Ee(e){return e||Ae(`configIsRequired`),Te(e)||Ae(`configType`),e.urls?(De(),{paths:{vs:e.urls.monacoBase}}):e}function De(){console.warn(ke.deprecation)}function Oe(e,t){throw Error(e[t]||e.default)}var ke={configIsRequired:`the configuration object is required`,configType:`the configuration object should be an object`,default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
3
- You are using deprecated way of configuration.
4
-
5
- Instead of using
6
- monaco.config({ urls: { monacoBase: '...' } })
7
- use
8
- monaco.config({ paths: { vs: '...' } })
9
-
10
- For more please check the link https://github.com/suren-atoyan/monaco-loader#config
11
- `},Ae=we(Oe)(ke),je={config:Ee},Me=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function Ne(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],Ne(e[n],t[n]))}),L(L({},e),t)}var Pe={type:`cancelation`,msg:`operation is manually canceled`};function W(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(Pe):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var Fe=[`monaco`],Ie=re(Se.create({config:Ce,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),G=Ie[0],K=Ie[1];function Le(e){var t=je.config(e),n=t.monaco,r=R(t,Fe);K(function(e){return{config:Ne(e.config,r),monaco:n}})}function Re(){var e=G(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(K({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),W(q);if(window.monaco&&window.monaco.editor)return Ue(window.monaco),e.resolve(window.monaco),W(q);Me(ze,Ve)(He)}return W(q)}function ze(e){return document.body.appendChild(e)}function Be(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function Ve(e){var t=G(function(e){return{config:e.config,reject:e.reject}}),n=Be(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function He(){var e=G(function(e){return{config:e.config,resolve:e.resolve,reject:e.reject}}),t=window.require;t.config(e.config),t([`vs/editor/editor.main`],function(t){var n=t.m||t;Ue(n),e.resolve(n)},function(t){e.reject(t)})}function Ue(e){G().monaco||K({monaco:e})}function We(){return G(function(e){return e.monaco})}var q=new Promise(function(e,t){return K({resolve:e,reject:t})}),Ge={config:Le,init:Re,__getMonacoInstance:We},Ke={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},qe={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function Je({children:e}){return g.createElement(`div`,{style:qe.container},e)}var Ye=Je;function Xe({width:e,height:t,isEditorReady:n,loading:r,_ref:i,className:a,wrapperProps:o}){return g.createElement(`section`,{style:{...Ke.wrapper,width:e,height:t},...o},!n&&g.createElement(Ye,null,r),g.createElement(`div`,{ref:i,style:{...Ke.fullWidth,...!n&&Ke.hide},className:a}))}var Ze=p(Xe);function Qe(e){S(e,[])}var $e=Qe;function et(e,t,n=!0){let r=f(!0);S(r.current||!n?()=>{r.current=!1}:e,t)}var J=et;function Y(){}function X(e,t,n,r){return tt(e,r)||nt(e,t,n,r)}function tt(e,t){return e.editor.getModel(rt(e,t))}function nt(e,t,n,r){return e.editor.createModel(t,n,r?rt(e,r):void 0)}function rt(e,t){return e.Uri.parse(t)}function it({original:e,modified:t,language:n,originalLanguage:r,modifiedLanguage:i,originalModelPath:a,modifiedModelPath:o,keepCurrentOriginalModel:s=!1,keepCurrentModifiedModel:c=!1,theme:l=`light`,loading:u=`Loading...`,options:p={},height:m=`100%`,width:h=`100%`,className:_,wrapperProps:v={},beforeMount:b=Y,onMount:x=Y}){let[C,w]=y(!1),[T,E]=y(!0),D=f(null),O=f(null),k=f(null),A=f(x),j=f(b),M=f(!1);$e(()=>{let e=Ge.init();return e.then(e=>(O.current=e)&&E(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>D.current?F():e.cancel()}),J(()=>{if(D.current&&O.current){let t=D.current.getOriginalEditor(),i=X(O.current,e||``,r||n||`text`,a||``);i!==t.getModel()&&t.setModel(i)}},[a],C),J(()=>{if(D.current&&O.current){let e=D.current.getModifiedEditor(),r=X(O.current,t||``,i||n||`text`,o||``);r!==e.getModel()&&e.setModel(r)}},[o],C),J(()=>{let e=D.current.getModifiedEditor();e.getOption(O.current.editor.EditorOption.readOnly)?e.setValue(t||``):t!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:t||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[t],C),J(()=>{D.current?.getModel()?.original.setValue(e||``)},[e],C),J(()=>{let{original:e,modified:t}=D.current.getModel();O.current.editor.setModelLanguage(e,r||n||`text`),O.current.editor.setModelLanguage(t,i||n||`text`)},[n,r,i],C),J(()=>{O.current?.editor.setTheme(l)},[l],C),J(()=>{D.current?.updateOptions(p)},[p],C);let N=d(()=>{if(!O.current)return;j.current(O.current);let s=X(O.current,e||``,r||n||`text`,a||``),c=X(O.current,t||``,i||n||`text`,o||``);D.current?.setModel({original:s,modified:c})},[n,t,i,e,r,a,o]),P=d(()=>{!M.current&&k.current&&(D.current=O.current.editor.createDiffEditor(k.current,{automaticLayout:!0,...p}),N(),O.current?.editor.setTheme(l),w(!0),M.current=!0)},[p,l,N]);S(()=>{C&&A.current(D.current,O.current)},[C]),S(()=>{!T&&!C&&P()},[T,C,P]);function F(){let e=D.current?.getModel();s||e?.original?.dispose(),c||e?.modified?.dispose(),D.current?.dispose()}return g.createElement(Ze,{width:h,height:m,isEditorReady:C,loading:u,_ref:k,className:_,wrapperProps:v})}p(it);function at(e){let t=f();return S(()=>{t.current=e},[e]),t.current}var ot=at,Z=new Map;function st({defaultValue:e,defaultLanguage:t,defaultPath:n,value:r,language:i,path:a,theme:o=`light`,line:s,loading:c=`Loading...`,options:l={},overrideServices:u={},saveViewState:p=!0,keepCurrentModel:m=!1,width:h=`100%`,height:_=`100%`,className:v,wrapperProps:b={},beforeMount:x=Y,onMount:C=Y,onChange:w,onValidate:T=Y}){let[E,D]=y(!1),[O,k]=y(!0),A=f(null),j=f(null),M=f(null),N=f(C),P=f(x),F=f(),ee=f(r),te=ot(a),I=f(!1),L=f(!1);$e(()=>{let e=Ge.init();return e.then(e=>(A.current=e)&&k(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>j.current?ne():e.cancel()}),J(()=>{let o=X(A.current,e||r||``,t||i||``,a||n||``);o!==j.current?.getModel()&&(p&&Z.set(te,j.current?.saveViewState()),j.current?.setModel(o),p&&j.current?.restoreViewState(Z.get(a)))},[a],E),J(()=>{j.current?.updateOptions(l)},[l],E),J(()=>{!j.current||r===void 0||(j.current.getOption(A.current.editor.EditorOption.readOnly)?j.current.setValue(r):r!==j.current.getValue()&&(L.current=!0,j.current.executeEdits(``,[{range:j.current.getModel().getFullModelRange(),text:r,forceMoveMarkers:!0}]),j.current.pushUndoStop(),L.current=!1))},[r],E),J(()=>{let e=j.current?.getModel();e&&i&&A.current?.editor.setModelLanguage(e,i)},[i],E),J(()=>{s!==void 0&&j.current?.revealLine(s)},[s],E),J(()=>{A.current?.editor.setTheme(o)},[o],E);let R=d(()=>{if(!(!M.current||!A.current)&&!I.current){P.current(A.current);let c=a||n,d=X(A.current,r||e||``,t||i||``,c||``);j.current=A.current?.editor.create(M.current,{model:d,automaticLayout:!0,...l},u),p&&j.current.restoreViewState(Z.get(c)),A.current.editor.setTheme(o),s!==void 0&&j.current.revealLine(s),D(!0),I.current=!0}},[e,t,n,r,i,a,l,u,p,o,s]);S(()=>{E&&N.current(j.current,A.current)},[E]),S(()=>{!O&&!E&&R()},[O,E,R]),ee.current=r,S(()=>{E&&w&&(F.current?.dispose(),F.current=j.current?.onDidChangeModelContent(e=>{L.current||w(j.current.getValue(),e)}))},[E,w]),S(()=>{if(E){let e=A.current.editor.onDidChangeMarkers(e=>{let t=j.current.getModel()?.uri;if(t&&e.find(e=>e.path===t.path)){let e=A.current.editor.getModelMarkers({resource:t});T?.(e)}});return()=>{e?.dispose()}}return()=>{}},[E,T]);function ne(){F.current?.dispose(),m?p&&Z.set(a,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return g.createElement(Ze,{width:h,height:_,isEditorReady:E,loading:c,_ref:M,className:v,wrapperProps:b})}var ct=p(st);m();var lt={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function ut(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...lt}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function dt({value:e,onChange:t,extraLibs:n=[],onDiagnostics:r,readOnly:i=!1,heightPx:a=420,dark:o=!0}){let s=f(null),c=d((e,t)=>{if(s.current=t,ut(t,n),r===void 0)return;let i=e.getModel();if(i===null)return;let a=()=>{r(t.editor.getModelMarkers({resource:i.uri}).map(e=>({line:e.startLineNumber,column:e.startColumn,message:e.message,severity:e.severity})))};t.editor.onDidChangeMarkers(a),a()},[n,r]);return x(ct,{height:a,defaultLanguage:`typescript`,path:`file:///block.ts`,theme:o?`vs-dark`:`vs`,value:e,onChange:e=>t(e??``),onMount:c,options:{readOnly:i,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,renderWhitespace:`selection`}})}function ft(e){return e.some(e=>e.severity>=8)}var pt=`import type { AddonContext } from '@camstack/types'
12
-
13
- /**
14
- * A core block. Runs in its own process, with the same \`ctx\` an addon gets.
15
- * Return a function to release whatever you took (timers, sockets, listeners) —
16
- * it is awaited on shutdown.
17
- */
18
- export default function block(ctx: AddonContext) {
19
- ctx.logger.info('hello from a core block')
20
-
21
- const timer = setInterval(() => {
22
- ctx.logger.info('tick')
23
- }, 60_000)
24
-
25
- return () => {
26
- clearInterval(timer)
27
- }
28
- }
29
- `;m();var mt=`hub`;function ht({existing:e,typeDefs:t,typeDefsLoading:i,saving:l,saveError:u,onSave:d,onCancel:f}){let{resolvedMode:p}=r(),[m,g]=y(e?.name??``),[v,b]=y(e?.code??pt),[S,C]=y(e?.placement??mt),[w,T]=y(e?.integrationId??``),[D,O]=y([]),k=_(()=>D.filter(e=>e.severity>=8),[D]),j=ft(D),M=m.trim()===``;return x(n,{children:h(`div`,{className:`space-y-4 p-4`,children:[x(`h3`,{className:`font-medium`,children:e===null?`New script`:`Edit ${e.name}`}),h(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[h(`label`,{className:`block text-sm`,children:[x(`span`,{className:`text-foreground-subtle`,children:`Name`}),x(o,{className:`mt-1`,value:m,onChange:e=>g(e.target.value),placeholder:`What this script does`})]}),h(`label`,{className:`block text-sm`,children:[x(`span`,{className:`text-foreground-subtle`,children:`Integration (optional)`}),x(o,{className:`mt-1`,value:w,onChange:e=>T(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),h(`div`,{children:[x(c,{selectedNodeId:S,onSelect:C,label:`Runs on`,alwaysShow:!0}),S!==mt&&h(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[x(A,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),h(`span`,{children:[`Block execution is hub-only today. Saved with this placement the block will be stored and compiled, but it will report `,x(`strong`,{children:`Failed`}),` instead of running.`]})]})]}),x(`div`,{className:`rounded border border-border`,children:i?x(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading the node's type definitions…`}):x(dt,{value:v,onChange:b,extraLibs:t?.libs??[],onDiagnostics:O,dark:p===`dark`,heightPx:420})}),t!==void 0&&t.libs.length===0&&x(`p`,{className:`text-xs text-warning`,children:`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`}),k.length>0&&h(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[h(`p`,{className:`font-medium text-danger`,children:[k.length,` error`,k.length===1?``:`s`,` — the block cannot be saved.`]}),k.slice(0,5).map(e=>h(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),k.length>5&&h(`p`,{className:`text-foreground-subtle`,children:[`…and `,k.length-5,` more.`]})]}),u!==null&&x(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:u}),h(`div`,{className:`flex items-center gap-2`,children:[h(s,{onClick:()=>{d({name:m.trim(),code:v,enabled:e?.enabled??!0,placement:S,...w.trim()===``?{}:{integrationId:w.trim()}})},disabled:l||j||M,children:[l&&x(E,{className:`h-4 w-4 animate-spin`}),` Save`]}),x(s,{variant:`ghost`,onClick:f,disabled:l,children:`Cancel`}),M&&x(a,{variant:`warning`,children:`Name required`})]})]})})}function Q(e){if(!e.enabled)return{tone:`idle`,label:`Disabled`,detail:`Not started — the block is turned off.`};switch(e.status){case`running`:return{tone:`ok`,label:`Running`,detail:`One process, supervised.`};case`starting`:return{tone:`pending`,label:`Starting`,detail:e.lastError??`Waiting for the process to report ready.`};case`failed`:return{tone:`error`,label:`Failed`,detail:e.lastError??`Failed with no reason recorded — check the node logs.`};default:return{tone:`error`,label:`Not running`,detail:e.lastError??`Enabled but no process is running. The supervisor reconciles every 15s; if this persists, the node may not be running a block supervisor.`}}}function gt(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function _t(e){let t=e=>{let t=Q(e).tone;return t===`error`?0:t===`pending`?1:t===`ok`?2:3};return[...e].sort((e,n)=>t(e)-t(n)||e.name.localeCompare(n.name))}function vt(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>Q(e).tone===`error`).length,n=e.filter(e=>Q(e).tone===`ok`).length,r=[`${String(e.length)} block${e.length===1?``:`s`}`];return n>0&&r.push(`${String(n)} running`),t>0&&r.push(`${String(t)} NOT running`),r.join(` · `)}m();var yt=[`coreBlocks`,`list`],bt=[`coreBlocks`,`getTypeDefs`],xt=5e3;function $(e){return e instanceof Error?e.message:String(e)}function St(){let e=C(),[t,r]=y({mode:`closed`}),[i,a]=y(null),o=v({queryKey:yt,refetchInterval:xt,queryFn:async()=>(await e.trpcClient.coreBlocks.list.query({})).blocks}),c=v({queryKey:bt,enabled:t.mode===`edit`,staleTime:1/0,gcTime:1/0,queryFn:()=>e.trpcClient.coreBlocks.getTypeDefs.query({})}),u=()=>{o.refetch()},d=b({mutationFn:t=>e.trpcClient.coreBlocks.create.mutate({block:t}),onSuccess:()=>{r({mode:`closed`}),u()}}),f=b({mutationFn:t=>e.trpcClient.coreBlocks.update.mutate(t),onSuccess:()=>{r({mode:`closed`}),u()}}),p=b({mutationFn:t=>e.trpcClient.coreBlocks.delete.mutate({blockId:t}),onSuccess:()=>{a(null),u()}}),m=b({mutationFn:t=>e.trpcClient.coreBlocks.setEnabled.mutate(t),onSuccess:u}),g=_t(o.data??[]),_=o.data!==void 0&&g.length===0,S=d.isPending||f.isPending,w=d.error===null?f.error===null?null:$(f.error):$(d.error);return h(`div`,{className:`space-y-3`,children:[h(`div`,{className:`flex items-center justify-between gap-3`,children:[x(`p`,{className:`text-xs text-foreground-subtle`,children:o.data===void 0?``:vt(g)}),h(s,{onClick:()=>r({mode:`edit`,block:null}),children:[x(T,{className:`h-4 w-4`}),` New script`]})]}),o.error!=null&&x(l,{title:`Could not read the scripts`,message:$(o.error),onRetry:u}),t.mode===`edit`&&x(ht,{existing:t.block,typeDefs:c.data,typeDefsLoading:c.isLoading,saving:S,saveError:w,onSave:e=>{let n=t.block;n===null?d.mutate(e):f.mutate({blockId:n.id,block:e})},onCancel:()=>{d.reset(),f.reset(),r({mode:`closed`})}}),_&&x(n,{children:h(`div`,{className:`space-y-1 p-4`,children:[x(`p`,{className:`text-sm text-foreground`,children:`No scripts yet.`}),x(`p`,{className:`text-xs text-foreground-subtle`,children:`A script is TypeScript the hub runs in its own process, with the same context an addon gets — devices, storage, the event bus. It is supervised: one that throws or hangs is marked failed and shown here, not left silently absent.`})]})}),g.length>0&&x(n,{children:x(`ul`,{className:`divide-y divide-border`,children:g.map(e=>x(Ct,{block:e,busy:m.isPending||p.isPending,confirming:i===e.id,onToggle:t=>m.mutate({blockId:e.id,enabled:t}),onEdit:()=>r({mode:`edit`,block:e}),onAskDelete:()=>a(e.id),onCancelDelete:()=>a(null),onConfirmDelete:()=>p.mutate(e.id)},e.id))})}),p.error!=null&&x(l,{message:$(p.error)}),m.error!=null&&x(l,{message:$(m.error)})]})}function Ct({block:e,busy:t,confirming:n,onToggle:r,onEdit:i,onAskDelete:o,onCancelDelete:c,onConfirmDelete:l}){let u=Q(e);return h(`li`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:gap-3`,children:[h(`div`,{className:`min-w-0 flex-1`,children:[h(`div`,{className:`flex flex-wrap items-center gap-2`,children:[x(`span`,{className:`truncate font-medium`,children:e.name}),x(a,{variant:gt(u.tone),children:u.label}),x(a,{variant:`info`,children:e.placement})]}),x(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:u.detail})]}),n?h(`div`,{className:`flex items-center gap-2`,children:[x(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this script?`}),x(s,{variant:`danger`,onClick:l,disabled:t,children:`Delete`}),x(s,{variant:`ghost`,onClick:c,children:`Cancel`})]}):h(`div`,{className:`flex items-center gap-2`,children:[x(s,{variant:`ghost`,onClick:()=>r(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),x(s,{variant:`ghost`,onClick:i,title:`Edit`,children:x(w,{className:`h-4 w-4`})}),x(s,{variant:`ghost`,onClick:o,title:`Delete`,children:x(k,{className:`h-4 w-4`})})]})]})}var wt=[`automations`,`scripts`];function Tt(e){return e!==null&&wt.some(t=>t===e)}function Et(){let[n,r]=D(),a=n.get(`tab`),o=Tt(a)?a:`automations`,s=e=>{r(t=>{let n=new URLSearchParams(t);return n.set(`tab`,e),n},{replace:!0})};return x(j,{icon:O,title:`Automation`,subtitle:`Automations and scripts — what this installation does on its own.`,children:h(e,{value:o,onValueChange:s,children:[h(i,{children:[x(t,{value:`automations`,children:`Automations`}),x(t,{value:`scripts`,children:`Scripts`})]}),x(u,{value:`automations`,children:x(M,{onOpenScripts:()=>s(`scripts`)})}),x(u,{value:`scripts`,children:x(St,{})})]})})}export{Et as AutomationPage};
@@ -1 +0,0 @@
1
- import{oo as e}from"./src-C2KiI31z.js";import{Q as t,S as n,W as r,a as i,q as a,t as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as c}from"./player-overlays-DnLMvF2y.js";import{t as l}from"./circle-check-big-CmRUug-s.js";import{C as u,F as d,f}from"./index-DzefosH4.js";import{t as p}from"./AdminPage-Dq33XE9j.js";t();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:t}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,o=e.providers.find(e=>e.active),c=t?.pendingCapability===e.name;return n(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[n(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&s(u,{className:`h-3 w-3 animate-spin text-primary`})]}),s(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?s(_,{entry:e,actions:t,activeProvider:o,isPending:c}):s(v,{entry:e,actions:t,isPending:c})]})}function _({entry:e,actions:t,activeProvider:r,isPending:i}){if(!t)return s(`div`,{children:r?n(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[s(l,{className:`h-3 w-3 text-green-400 shrink-0`}),s(`span`,{className:`font-medium`,children:r.addonName}),s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return n(`div`,{className:`space-y-2`,children:[s(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return n(`button`,{type:`button`,disabled:i||a,onClick:()=>t.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[s(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),s(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&s(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let o=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=n=>{n===a?t.onClearNodeSingleton(e.name,r.nodeId):t.onSelectNodeSingleton(e.name,r.nodeId,n)},u=i;return n(`div`,{className:`space-y-0.5`,children:[n(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&s(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let t=o===e.value;return n(`button`,{type:`button`,disabled:u||t,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${t?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[s(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${t?`border-green-400 bg-green-400`:`border-border`}`}),s(`span`,{className:`font-medium truncate`,children:e.label}),t&&e.value!==a&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:t,isPending:r}){if(e.providers.length===0)return s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!t)return s(`div`,{className:`space-y-1`,children:e.providers.map(e=>n(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[s(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(n,r)=>{let a=r?[...new Set([...i,n])]:i.filter(e=>e!==n);t.onToggleCollection(e.name,a)};return s(`div`,{className:`space-y-1`,children:e.providers.map(e=>n(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[n(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[s(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),s(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?s(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):s(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>s(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let t=c(),[u,m]=a(null),[h,g]=a(null),_=i({queryKey:b,queryFn:()=>t.trpcClient.capabilities.listCapabilities.query()}),v=r(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=r(()=>v.filter(e=>e.mode===`singleton`),[v]),w=r(()=>v.filter(e=>e.mode===`collection`),[v]),T=o({mutationFn:e=>t.trpcClient.capabilities.setActiveSingleton.mutate({capability:e.capName,addonId:e.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=o({mutationFn:e=>t.trpcClient.capabilities.setActiveSingleton.mutate({capability:e.capName,addonId:e.addonId,nodeId:e.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=o({mutationFn:e=>t.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:e.capName,nodeId:e.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=o({mutationFn:e=>t.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:e.capName,enabledAddonIds:[...e.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:u};return n(p,{icon:f,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&n(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?s(l,{className:`h-3.5 w-3.5 shrink-0`}):s(d,{className:`h-3.5 w-3.5 shrink-0`}),s(`span`,{children:h.message})]}),_.isLoading&&s(`div`,{className:`flex items-center justify-center py-16`,children:s(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&s(e,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&s(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&n(`div`,{className:`space-y-6`,children:[S.length>0&&n(`section`,{className:`space-y-2`,children:[s(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),s(y,{capabilities:S,actions:k})]}),w.length>0&&n(`section`,{className:`space-y-2`,children:[s(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),s(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
@@ -1 +0,0 @@
1
- import{Ao as e,Br as t,Ca as n,Gr as r,Hr as i,Mo as a,Mr as o,Nr as s,Sa as c,Ta as l,Ur as u,Vr as d,Wr as f,ao as p,fo as m,g as h,jo as g,ki as _,ko as v,m as y,qi as b,uo as x,wa as S,zr as C}from"./src-C2KiI31z.js";import{I as w,K as T,Q as E,S as D,W as O,o as k,q as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as N}from"./player-overlays-DnLMvF2y.js";import{t as P}from"./pencil-CGcp1H_S.js";import{t as F}from"./radio-DejuKcx3.js";import{t as I}from"./refresh-cw-CW_Ljqdp.js";import{t as L}from"./rotate-cw-Bj3NywrT.js";import{t as ee}from"./server-DLCgy7fU.js";import{t as te}from"./upload-DeJAhsSx.js";import{C as R,H as z,I as ne,K as B,N as re,R as ie,c as V,h as ae,i as H,s as U,t as W,z as G}from"./index-DzefosH4.js";import{n as K,t as q}from"./build-cluster-graph-DK8tHUpQ.js";import{t as J}from"./format-size-CO9d3C3-.js";import{t as oe}from"./NodeAddonsSettingsPanel-0BTA46bg.js";var Y=B(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),se=B(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),ce=B(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),le=B(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),X=B(`skull`,[[`path`,{d:`m12.5 17-.5-1-.5 1h1z`,key:`3me087`}],[`path`,{d:`M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z`,key:`1o5pge`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}]]),ue=B(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]);E();function de(e){let t=new FormData;return t.append(`file`,e.file,e.file.name),t.append(`nodeId`,e.nodeId),e.addonId&&t.append(`addonId`,e.addonId),new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/addons/upload`),e.token&&i.setRequestHeader(`Authorization`,`Bearer ${e.token}`),i.upload.addEventListener(`progress`,t=>{t.lengthComputable&&e.onProgress(Math.round(t.loaded/t.total*100))}),i.addEventListener(`load`,()=>{let e;try{e=JSON.parse(i.responseText)}catch{r(Error(`HTTP ${i.status}`));return}i.status>=200&&i.status<300?n(e):r(Error(e.error??`HTTP ${i.status}`))}),i.addEventListener(`error`,()=>r(Error(`Network error during upload`))),i.addEventListener(`abort`,()=>r(Error(`Upload aborted`))),i.send(t)})}function fe({nodeId:e,addons:t,isHub:n}){let i=k(),a=p(),[o,s]=A(null),[c,l]=A(null),[u,f]=A(!1),[m,h]=A(null),[g,_]=A(0),v=T(null),y=d(),b=r(),x=C({nodeId:e}),S=x.data??[],w=new Map(t.map(e=>[e.id,e.capabilities])),E=S.length>0?S.map(e=>({id:e.id,status:e.status,capabilities:w.get(e.id)??[],version:e.version,packageName:e.packageName})):t.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),O=()=>{i.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),x.refetch()},M=async t=>{s(t);try{await y.mutateAsync({nodeId:e,addonId:t}),O()}catch(e){console.error(`Failed to restart addon:`,e)}finally{s(null)}},N=async t=>{if(await a({title:`Uninstall addon`,message:`Remove "${t}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){l(t);try{await b.mutateAsync({nodeId:e,addonId:t}),O()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{l(null)}}},P=D(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(`input`,{ref:v,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,h(null),f(!0),_(0);try{await de({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:_}),O()}catch(e){h(e instanceof Error?e.message:String(e))}finally{f(!1),_(0)}}}}),D(`button`,{onClick:()=>v.current?.click(),disabled:u,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[u?j(R,{className:`h-3 w-3 animate-spin`}):j(te,{className:`h-3 w-3`}),u?`Uploading… ${g}%`:`Upload addon (.tgz)`]}),u&&j(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:j(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${g}%`}})}),m&&j(`span`,{className:`text-[10px] text-destructive`,children:m})]});return E.length===0?D(`div`,{children:[P,j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:x.isLoading?`Loading addons…`:`No addons on this node`})]}):D(`div`,{children:[P,j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`px-3 py-2 font-medium`,children:`Addon`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Version`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Capabilities`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Status`}),j(`th`,{className:`px-3 py-2 font-medium w-16`})]})}),j(`tbody`,{children:E.map(e=>D(`tr`,{className:`border-t border-border/50`,children:[D(`td`,{className:`px-3 py-2 font-medium`,children:[j(`div`,{children:e.id}),e.packageName&&j(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),j(`td`,{className:`px-3 py-2 text-muted-foreground`,children:e.version??`—`}),j(`td`,{className:`px-3 py-2`,children:j(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):j(`span`,{className:`text-muted-foreground`,children:`—`})})}),j(`td`,{className:`px-3 py-2`,children:j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e.status===`running`?`bg-success/10 text-success`:e.status===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e.status})}),j(`td`,{className:`px-3 py-2`,children:D(`div`,{className:`flex items-center gap-1 justify-end`,children:[j(`button`,{onClick:()=>M(e.id),disabled:o===e.id||c===e.id,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.id}`,children:j(L,{className:`h-3 w-3 ${o===e.id?`animate-spin`:``}`})}),j(`button`,{onClick:()=>N(e.id),disabled:o===e.id||c===e.id,className:`p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50`,title:`Uninstall ${e.id}`,children:c===e.id?j(R,{className:`h-3 w-3 animate-spin`}):j(V,{className:`h-3 w-3`})})]})})]},e.id))})]})})]})}E();function pe(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function me({state:e}){return j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var he=[`trace`,`debug`,`info`,`warn`,`error`];function ge({proc:t,nodeId:n,defaultExpanded:r,activePanel:o,onTogglePanel:s}){let c=t.services??[],l=c.length===1,[f,p]=A(l||r),[m,_]=A(null),[b,x]=A(`info`),S=t.name.includes(`(core)`),C=d(),w=i(),T=u(),E=async e=>{_(e);try{await C.mutateAsync({nodeId:n,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{_(null)}},O=async()=>{_(t.name);try{await w.mutateAsync({nodeId:n,processName:t.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{_(null)}},k=async e=>{let r=`${n}/${t.name}`;try{await T.mutateAsync({nodeId:r,level:e}),x(e)}catch(e){console.error(`Failed to set log level:`,e)}};return D(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[D(`div`,{role:l?void 0:`button`,tabIndex:l?void 0:0,onClick:l?void 0:()=>p(!f),onKeyDown:l?void 0:e=>{(e.key===`Enter`||e.key===` `)&&p(!f)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${l?``:`hover:bg-muted/40 cursor-pointer`}`,children:[l?j(`span`,{className:`h-3 w-3 shrink-0`}):j(f?ie:ne,{className:`h-3 w-3 text-muted-foreground shrink-0`}),S?j(ee,{className:`h-3.5 w-3.5 text-primary shrink-0`}):j(z,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),j(`span`,{className:`text-xs font-semibold flex-1`,children:t.name}),D(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,t.pid]}),j(me,{state:t.state}),D(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[t.cpuPercent,`% CPU`]}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:J(t.memoryRss)}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:pe(t.uptimeSeconds)}),!S&&D(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[D(v,{children:[j(a,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:b}),j(e,{align:`end`,className:`min-w-[70px] py-0.5`,children:he.map(e=>j(g,{onClick:()=>k(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===b?`text-primary font-semibold`:``}`,children:e},e))})]}),j(`button`,{onClick:O,disabled:m===t.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:j(L,{className:`h-3 w-3 ${m===t.name?`animate-spin`:``}`})})]})]}),f&&c.length>0&&j(`div`,{className:`divide-y divide-border/30`,children:c.map(e=>D(`div`,{children:[D(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[j(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),j(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&D(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&D(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),D(`div`,{className:`flex items-center gap-1 shrink-0`,children:[j(`button`,{onClick:()=>s(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${o?.addonId===e.addonId&&o.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:j(ae,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>s(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${o?.addonId===e.addonId&&o.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:j(F,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>E(e.addonId),disabled:m===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:j(L,{className:`h-3 w-3 ${m===e.addonId?`animate-spin`:``}`})})]})]}),o?.addonId===e.addonId&&o.type===`logs`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(h,{addonId:e.addonId,agentId:n,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>s(e.addonId,`logs`)})}),o?.addonId===e.addonId&&o.type===`events`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(y,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>s(e.addonId,`events`)})})]},e.addonId))}),f&&c.length===0&&j(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function _e({nodeId:e,processes:t}){let[n,r]=A(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):j(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>j(ge,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}E();function ve(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function ye(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function be({nodeId:e}){let t=k(),n=p(),[r,i]=A(`all`),a=x(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:c}=s({nodeId:e}),l=a?.processes??c,u=O(()=>l?[...l]:[],[l]),d=O(()=>r===`ghost`?u.filter(e=>e.classification===`ghost`):u,[u,r]),f=O(()=>{let e=u.filter(e=>e.classification===`ghost`),t=new Map;for(let n of e)t.has(n.ppid)||t.set(n.ppid,[]),t.get(n.ppid).push(n);return[...t.entries()].filter(([,e])=>e.length>1).map(([e,t])=>({ppid:e,children:t})).toSorted((e,t)=>t.children.length-e.children.length)},[u]),m=o({onSettled:()=>{t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),h=O(()=>{let e=new Map;for(let t of u)e.set(t.pid,t.classification);return e},[u]),g=async(t,r)=>{if(t.classification===`root`||t.classification===`system`)return;let i=t.classification===`ghost`?`ghost`:t.addonId??`process`,a=r?`SIGKILL`:`SIGTERM`;await n({title:`Send ${a}?`,message:`Target pid ${t.pid} (${i}) on node ${e}.`,confirmLabel:`Send ${a}`,variant:`danger`})&&m.mutate({nodeId:e,pid:t.pid,force:r})},_=async(t,n)=>{try{await m.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},v=async r=>{let i=h.get(r.ppid);if(i===`root`||i===`system`){await n({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${r.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${r.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:`OK`,cancelLabel:`Close`,variant:`warning`});return}await n({title:`Kill ghost parent + ${r.children.length} child(ren)?`,message:`SIGKILL parent pid ${r.ppid} and SIGTERM ${r.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([_(r.ppid,!0),...r.children.map(e=>_(e.pid,!1))]),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},y=async()=>{let r=u.filter(e=>e.classification===`ghost`);r.length!==0&&await n({title:`Kill all ${r.length} ghost process(es)?`,message:`SIGKILL ${r.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(r.map(e=>_(e.pid,!0))),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},b=u.filter(e=>e.classification===`ghost`).length,S=u.filter(e=>e.classification===`managed`).length,C=u.filter(e=>e.classification===`root`).length,w=u.filter(e=>e.classification===`system`).length;return D(`div`,{className:`space-y-4`,children:[D(`div`,{className:`flex items-start justify-between gap-4`,children:[D(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`ps`," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),D(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[j(I,{className:`h-3 w-3`}),` Refresh`]})]}),D(`div`,{className:`grid grid-cols-4 gap-3`,children:[D(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:C})]}),D(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:S})]}),D(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:w})]}),D(`div`,{className:`rounded-lg border p-3 ${b>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[D(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[b>0&&j(X,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),j(`div`,{className:`text-xl font-semibold ${b>0?`text-destructive`:`text-foreground`}`,children:b})]})]}),f.length>0&&D(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[D(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[j(U,{className:`h-3 w-3`}),` Recurring ghost parents (`,f.length,`)`]}),j(`div`,{className:`space-y-1.5`,children:f.map(e=>D(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[D(`div`,{className:`flex items-center gap-2`,children:[D(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),D(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),D(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{v(e)},className:`inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30`,children:[j(X,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),D(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[D(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),D(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${r===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>i(`all`),children:[`All (`,u.length,`)`]}),D(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${r===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>i(`ghost`),children:[`Ghost only (`,b,`)`]})]}),b>0&&D(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{y()},className:`inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30`,children:[j(X,{className:`h-3 w-3`}),` Kill all `,b,` ghost(s)`]})]}),j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[j(`th`,{className:`text-left px-3 py-2`,children:`Class`}),j(`th`,{className:`text-right px-3 py-2`,children:`PID`}),j(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),j(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),j(`th`,{className:`text-left px-3 py-2`,children:`Command`}),j(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),j(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),j(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),j(`th`,{className:`w-44`})]})}),D(`tbody`,{children:[d.length===0&&j(`tr`,{children:j(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:r===`ghost`?`No ghost processes detected.`:`Scanning…`})}),d.map(e=>D(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[j(`td`,{className:`px-3 py-2`,children:j(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`ghost`?`bg-destructive/20 text-destructive`:e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})}),j(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),D(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),j(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),j(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:ye(e.command)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:J(e.memoryRssBytes)}),j(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:ve(e.uptimeSec)}),j(`td`,{className:`px-3 py-2 text-right`,children:D(`div`,{className:`inline-flex gap-1`,children:[D(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{g(e,!1)},title:`SIGTERM`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30`,children:[j(V,{className:`h-3 w-3`}),` Term`]}),D(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{g(e,!0)},title:`SIGKILL`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30`,children:[j(X,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),m.isError&&D(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,m.error instanceof Error?m.error.message:`unknown`]})]})}function xe({nodeId:e,addonIds:t}){return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):j(`div`,{className:`w-full py-2`,children:j(oe,{nodeId:e,addonIds:t,level:`global`,selfTabbed:!0})})}E();function Se({nodeId:e,addons:t}){let n=k(),{data:r,isLoading:i}=_({nodeId:e}),a=O(()=>{let e=new Map;for(let n of t)for(let t of n.capabilities){let r=e.get(t)??[];r.push(n.id),e.set(t,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[t]),o=b({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return a.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`px-3 py-2 font-medium w-1/2`,children:`Capability`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Bound provider`})]})}),j(`tbody`,{children:a.map(({capName:t,providers:n})=>{let a=r?.[t]??n[0]??``,s=n.length===1;return D(`tr`,{className:`border-t border-border/50`,children:[j(`td`,{className:`px-3 py-2 font-medium`,children:t}),j(`td`,{className:`px-3 py-2`,children:j(`select`,{value:a,onChange:n=>o.mutate({nodeId:e,capName:t,addonId:n.target.value}),disabled:s||o.isPending||i,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:s?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:n.map(e=>j(`option`,{value:e,children:e},e))})})]},t)})})]})})}E();function Z(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function Ce(e){let[n,r]=A(!1),[i,a]=A(e.name),o=k(),s=t({onSuccess:()=>{o.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),c=(e.localIps??[]).filter(e=>!e.includes(`:`)),l=(e.localIps??[]).filter(e=>e.includes(`:`)),u=async()=>{if(!i.trim()||i===e.name){r(!1);return}try{await s.mutateAsync({nodeId:e.nodeId,name:i.trim()}),r(!1)}catch(e){console.error(`Rename failed:`,e)}},d=[[`Node ID`,j(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,n?D(`div`,{className:`flex items-center gap-1.5`,children:[j(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&u(),e.key===`Escape`&&r(!1)},disabled:s.isPending,autoFocus:!0}),j(`button`,{onClick:()=>void u(),disabled:s.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:j(G,{className:`h-3.5 w-3.5`})}),j(`button`,{onClick:()=>r(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:j(H,{className:`h-3.5 w-3.5`})})]}):D(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&j(`button`,{onClick:()=>{a(e.name),r(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:j(P,{className:`h-3 w-3`})})]})],[`Hostname`,j(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Root Package`,e.rootPackage?D(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,D(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,D(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,j(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,j(`span`,{className:`text-xs`,children:Z(e.uptime)})],[`Engines`,e.engines.length>0?j(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return c.length>0&&d.push([`IPv4`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>j(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),l.length>0&&d.push([`IPv6`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map((e,t)=>j(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),j(`div`,{className:`py-2`,children:j(`table`,{className:`w-full text-sm`,children:j(`tbody`,{children:d.map(([e,t],n)=>D(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[j(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),j(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}E();var we=[[`serverManagement`,`getServerPackageStatus`]];function Q({label:e,tone:t}){return j(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${{neutral:`bg-surface-muted text-foreground-subtle`,ok:`bg-emerald-500/15 text-emerald-500`,info:`bg-sky-500/15 text-sky-500`,warn:`bg-amber-500/15 text-amber-500`,error:`bg-red-500/15 text-red-500`}[t]}`,children:e})}function $({label:e,value:t}){return D(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:e}),j(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function Te({node:e}){let{t}=W(),r=k(),i=p(),[a,o]=A(!1),s=e.isHub?void 0:{nodeId:e.id},u=S(s,{refetchInterval:1e4,enabled:e.isOnline,retry:1}),d=u.data??null,f=w(()=>{r.invalidateQueries({queryKey:we})},[r]),m=n({onSettled:f}),h=c({onSettled:f}),g=l({onSettled:f}),_=w(async()=>{d?.latestVersion!=null&&await i({title:t(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:t(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:d.packageName,version:d.latestVersion,node:e.name}),confirmLabel:t(`serverManagement.confirmUpdateAction`,`Update & restart`)})&&(await h.mutateAsync({version:d.latestVersion,...s})).restarting&&o(!0)},[h,i,e.name,s,d,t]),v=w(async()=>{await i({title:t(`serverManagement.confirmRestartTitle`,`Restart node`),message:t(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:e.name}),confirmLabel:t(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})&&(await g.mutateAsync(s)).restarting&&o(!0)},[i,e.name,g,s,t]),y=()=>{switch(d?.bootMode){case`data-root`:return{label:t(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:t(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:t(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},b=()=>{if(d==null)return null;switch(d.updateState){case`checking`:return{label:t(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:t(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:t(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return d.updateAvailable?{label:t(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:t(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},x=d?.bootMode===`workspace`,C=e.isOnline&&d!=null&&!x&&d.updateAvailable&&d.updateState===`idle`&&!h.isPending,T=e.isOnline&&d!=null&&d.updateState===`idle`&&!g.isPending,E=e.isOnline?b():null;return D(`div`,{className:`space-y-4 py-2`,children:[D(`div`,{className:`flex items-center justify-between gap-3`,children:[D(`div`,{className:`flex items-center gap-2 min-w-0`,children:[j(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:d?.packageName??e.rootPackage?.name??`@camstack/server`}),e.isOnline&&d!=null&&j(Q,{...y()})]}),E!=null&&j(Q,{...E})]}),!e.isOnline&&j($,{label:t(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage?.version??null}),e.isOnline&&u.isLoading&&D(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[j(R,{className:`h-4 w-4 animate-spin`}),t(`common.loading`,`Loading…`)]}),e.isOnline&&u.isError&&D(`div`,{className:`space-y-1.5`,children:[j(`p`,{className:`text-sm text-red-500`,children:t(`serverManagement.loadError`,`Could not load the node root-package status.`)}),e.rootPackage!=null&&j($,{label:t(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage.version})]}),e.isOnline&&d!=null&&D(`div`,{className:`space-y-1.5`,children:[j($,{label:t(`serverManagement.runningVersion`,`Running version`),value:d.runningVersion}),j($,{label:t(`serverManagement.latestVersion`,`Latest on registry`),value:d.latestVersion}),j($,{label:t(`serverManagement.imageSeedVersion`,`Image seed (baked)`),value:d.seedVersion}),j($,{label:t(`serverManagement.nodeRuntimeVersion`,`Node.js runtime`),value:d.nodeRuntimeVersion}),d.pendingVersion!=null&&j($,{label:t(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:d.pendingVersion})]}),e.isOnline&&(d?.imageContract?.state===`behind-series`||d?.imageContract?.state===`behind-patch`)&&D(`div`,{className:`rounded-md border px-3 py-2 text-xs leading-relaxed ${d.imageContract.state===`behind-series`?`border-red-500/40 bg-red-500/10 text-red-500`:`border-amber-500/40 bg-amber-500/10 text-amber-500`}`,children:[j(`p`,{className:`mb-0.5 font-semibold`,children:t(`serverManagement.imageContractDiverged`,`Container image diverges from the deployment contract`)}),j(`p`,{children:d.imageContract.message})]}),e.isOnline&&x&&j(`p`,{className:`text-xs text-foreground-subtle`,children:t(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),a&&D(`div`,{className:`flex items-center gap-2 text-sm text-amber-500`,children:[j(R,{className:`h-4 w-4 animate-spin`}),t(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),e.isOnline&&D(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:m.isPending||d?.updateState===`staging`,onClick:()=>m.mutate(s),children:[m.isPending?j(R,{className:`h-3.5 w-3.5 animate-spin`}):j(I,{className:`h-3.5 w-3.5`}),t(`serverManagement.checkForUpdate`,`Check for update`)]}),C&&D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void _(),children:[h.isPending?j(R,{className:`h-3.5 w-3.5 animate-spin`}):j(Y,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateTo`,`Update to {{version}}`,{version:d?.latestVersion??``})]}),D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!T,onClick:()=>void v(),children:[g.isPending?j(R,{className:`h-3.5 w-3.5 animate-spin`}):j(L,{className:`h-3.5 w-3.5`}),t(`serverManagement.restart`,`Restart`)]})]}),e.isOnline&&d?.lastCheckedAtMs!=null&&D(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[j(ce,{className:`h-3 w-3`}),t(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(d.lastCheckedAtMs).toLocaleString()})]})]})}E();function Ee({node:e}){let t=N(),[n,r]=A(`info`),[i,a]=A(!1),o=e.processes??[],s=e.addons.map(e=>e.id),c=async()=>{if(!i){a(!0);try{await Promise.allSettled([t.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:e.id}),t.trpcClient.clusterNodes.forgetNode.mutate({nodeId:e.id})])}finally{a(!1)}}};return e.isOnline?D(`div`,{className:`border border-border rounded-xl`,children:[D(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border rounded-t-xl`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),D(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),D(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[D(`span`,{className:`flex items-center gap-1`,children:[j(re,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),D(`span`,{className:`flex items-center gap-1`,children:[j(le,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),j(`div`,{className:`sticky top-0 z-20 flex border-b border-border px-4 bg-background overflow-x-auto`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(t=>j(`button`,{onClick:()=>r(t),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${n===t?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:t===`info`?`General`:t===`addons`?`Addons (${e.addons.length})`:t===`forks`?`Forks (${o.length})`:t===`processes`?`Processes`:t===`settings`?`Settings`:`Capabilities`},t))}),D(`div`,{className:`px-4 py-2`,children:[n===`info`&&D(`div`,{className:`space-y-3`,children:[j(Ce,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps,rootPackage:e.rootPackage}),j(`div`,{className:`border-t border-border pt-1`,children:j(Te,{node:{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}})})]}),n===`addons`&&j(fe,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),n===`forks`&&j(_e,{nodeId:e.id,processes:o}),n===`processes`&&j(be,{nodeId:e.id}),n===`settings`&&j(xe,{nodeId:e.id,addonIds:s}),n===`capabilities`&&j(Se,{nodeId:e.id,addons:e.addons})]})]}):D(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[D(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),D(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),e.rootPackage&&D(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}),j(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),D(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[D(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSeen?`Last seen ${new Date(e.lastSeen).toLocaleString()} — `:``,e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned; will resume when node reconnects`]}),D(`button`,{type:`button`,onClick:()=>void c(),disabled:i,title:`Forget this node — removes its saved history and pipeline assignments`,className:`flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-border text-muted-foreground hover:text-destructive hover:border-destructive/50 disabled:opacity-50 transition-colors`,children:[j(V,{className:`h-3 w-3`}),i?`Forgetting…`:`Forget node`]})]})]})}E();function De({nodes:e,focusNodeId:t,focusNonce:n}){let r=[...e].toSorted((e,t)=>e.isHub?-1:t.isHub?1:e.isOnline&&!t.isOnline?-1:!e.isOnline&&t.isOnline?1:e.name.localeCompare(t.name)),i=T(null);return M(()=>{if(!t)return;let e=i.current?.querySelector(`#node-card-${CSS.escape(t)}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[t,n]),j(`div`,{ref:i,className:`flex flex-col gap-4`,children:r.map(e=>j(`div`,{id:`node-card-${e.id}`,children:j(Ee,{node:e})},e.id))})}E();function Oe(e){let[t,n]=A(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return M(()=>{let t=window.matchMedia(e),r=e=>n(e.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function ke(){let{data:e,isLoading:t}=f(void 0,{staleTime:1/0}),[n,r]=A(null);return m(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&r(t)}),{nodes:O(()=>n??e??[],[n,e]),isLoading:t&&!n}}function Ae(){let{t:e}=W(),t=p(),[n,r]=A(`table`),[i,a]=A(void 0),[o,s]=A(0),l=Oe(`(max-width: 767px)`),u=l&&n===`graph`?`table`:n,{nodes:d,isLoading:f}=ke(),m=O(()=>q(d),[d]),h=O(()=>d.filter(e=>e.isOnline),[d]),g=h.length,_=d.filter(e=>!e.isOnline).length,v=c(),[y,b]=A(!1),x=w(async()=>{let n=[...h].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1);if(await t({title:e(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:e(`serverManagement.confirmUpdateAllBody`,`Update and restart every online node, agents first, hub last. Up-to-date nodes are skipped; this page reconnects when the hub comes back.`),confirmLabel:e(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){b(!0);try{for(let e of n)try{await v.mutateAsync(e.isHub?{}:{nodeId:e.id})}catch{}}finally{b(!1)}}},[v,t,h,e]),S=w(e=>{r(`table`),a(e),s(e=>e+1)},[]),C=(e,t,i)=>D(`button`,{onClick:()=>r(e),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${n===e?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[j(i,{className:`h-3.5 w-3.5`}),t]});return D(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[D(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[D(`div`,{className:`flex items-center gap-2`,children:[g>0&&D(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[g,` online`]}),_>0&&D(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[_,` offline`]})]}),D(`div`,{className:`flex items-center gap-2`,children:[g>1&&D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,disabled:y,title:e(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void x(),children:[y?j(R,{className:`h-3.5 w-3.5 animate-spin`}):j(Y,{className:`h-3.5 w-3.5`}),e(`serverManagement.updateAll`,`Update all nodes`)]}),D(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[C(`table`,`Table`,ue),!l&&C(`graph`,`Graph`,se)]})]})]}),f?j(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):u===`graph`?j(K,{graph:m,onOpenNodeDetail:S}):j(`div`,{className:`flex-1 overflow-auto`,children:j(De,{nodes:d,focusNodeId:i,focusNonce:o})})]})}export{Ae as ClusterPage};
@@ -1 +0,0 @@
1
- import{Aa as e,Da as t,Ea as n,Et as r,Gt as i,Ht as a,Jt as o,Kt as s,Oa as c,Ut as l,Vt as u,Wt as d,Xt as f,Yt as p,ao as m,bt as h,qt as g,xt as _}from"./src-C2KiI31z.js";import{I as v,Q as y,S as b,W as x,a as S,b as C,o as w,q as T,x as E,z as D}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as O}from"./player-overlays-DnLMvF2y.js";import{a as k,i as A,n as j,r as M,t as N}from"./AddLocationWizard-BpkZ7g8M.js";import{t as P}from"./download-BbJFh_GP.js";import{t as F}from"./pencil-CGcp1H_S.js";import{n as ee,t as te}from"./AddonCollectionPage-CqEMePgW.js";import{t as ne}from"./plus-CWclgqCc.js";import{t as I}from"./rotate-cw-Bj3NywrT.js";import{C as L,I as re,K as R,R as z,W as ie,c as B,h as V,i as H}from"./index-DzefosH4.js";import{t as U}from"./AdminPage-Dq33XE9j.js";import{n as ae}from"./authed-media-XfBD4Ma-.js";import{t as W}from"./format-size-CO9d3C3-.js";import{t as G}from"./AdminTabs-BzqgdZo8.js";import{t as K}from"./addon-display-names-DvSEQty-.js";var q=R(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),J=R(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),oe=R(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),se=R(`file-text`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]);y();var ce=new Set([`recordings`,`recordingsLow`]);function le(e){let t=e.filesTotal===null?``:`/${e.filesTotal}`,n=Math.round(e.bytesMoved/(1024*1024)),r=`${e.entities.join(`+`)}: ${e.filesMoved}${t} files, ${n} MB — ${e.state}`;return e.error?`${r} (${e.error})`:r}function ue({location:e,onClose:t}){let n=O().trpcClient,[r,i]=T(``),[a,o]=T(!0),[s,c]=T(!0),[l,u]=T(null),[d,f]=T(!1),p=S({queryKey:[`storage`,`listLocations`,`relocate`],queryFn:()=>n.storage.listLocations.query({})}),m=x(()=>(p.data??[]).filter(t=>t.id!==e.id&&ce.has(t.type)&&t.config.readOnly!==!0&&t.config.basePath!==e.config.basePath),[p.data,e]),h=S({queryKey:[`relocate`,`jobs`],queryFn:async()=>{let[e,t]=await Promise.all([n.recording.getRelocateStatus.query({}).catch(()=>[]),n.pipelineAnalytics.getMediaRelocateStatus.query({}).catch(()=>[])]);return[...e,...t].sort((e,t)=>t.startedAt-e.startedAt)},refetchInterval:2e3}),g=h.data??[],_=g.some(e=>e.state===`running`);D(()=>{r===``&&m.length>0&&i(m[0].id)},[m,r]);let v=async()=>{if(r!==``){u(null),f(!0);try{a&&await n.recording.relocateFootage.mutate({fromLocationId:e.id,toLocationId:r}),s&&await n.pipelineAnalytics.relocateMedia.mutate({toLocationId:r}),await h.refetch()}catch(e){u(e instanceof Error?e.message:String(e))}finally{f(!1)}}},y=async e=>{try{e.entities.includes(`media`)?await n.pipelineAnalytics.cancelMediaRelocate.mutate({jobId:e.jobId}):await n.recording.cancelRelocate.mutate({jobId:e.jobId}),await h.refetch()}catch{}};return E(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:b(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[b(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[b(`div`,{className:`space-y-0.5`,children:[b(`h2`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[E(k,{className:`h-3.5 w-3.5`}),`Relocate from `,e.displayName]}),E(`p`,{className:`text-xs text-foreground-subtle`,children:`Throttled background move; safe to re-run — it resumes where it stopped. Mark this location read-only first so nothing new lands here.`})]}),E(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:E(H,{className:`h-4 w-4`})})]}),b(`div`,{className:`p-4 space-y-3`,children:[b(`div`,{className:`space-y-1`,children:[E(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Target location`}),m.length===0?E(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No writable recordings location on a different root to move to.`}):E(`select`,{value:r,onChange:e=>i(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:m.map(e=>b(`option`,{value:e.id,children:[e.displayName,` (`,String(e.config.basePath??e.id),`)`]},e.id))})]}),b(`div`,{className:`space-y-1`,children:[b(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[E(`input`,{type:`checkbox`,checked:a,onChange:e=>o(e.target.checked),className:`accent-primary`}),`Footage (segments + strips)`]}),b(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[E(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),className:`accent-primary`}),`Event media (crops, thumbnails, snapshots)`]})]}),l&&E(`p`,{className:`text-[11px] text-danger`,children:l}),g.length>0&&E(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:g.slice(0,4).map(e=>b(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[E(`span`,{className:`flex-1 truncate text-[11px] text-foreground`,children:le(e)}),e.state===`running`&&E(`button`,{onClick:()=>void y(e),className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground`,children:`Cancel`})]},e.jobId))})]}),b(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[E(`button`,{onClick:t,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Close`}),E(`button`,{onClick:()=>void v(),disabled:r===``||d||_||!a&&!s,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:_?`Running…`:`Start relocation`})]})]})})}y();function de(){let r=w(),i=m(),{data:a,isLoading:o,isError:s}=c({}),l=t(),u=x(()=>l.data??[],[l.data]),[d,f]=T(null),[p,h]=T(null),[g,_]=T(null),v=n({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),y=e({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),S=e=>{e.isDefault||y.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},C=async e=>{if(e.isDefault){await i({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another location as default first, then delete this one.`,confirmLabel:`OK`,variant:`warning`});return}await i({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`})&&v.mutate({id:e.id})},D=x(()=>{let e=new Map;for(let t of a??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[a]),O=o||l.isLoading,k=s||l.isError;return b(U,{children:[O&&E(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),k&&E(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!O&&!k&&b(`div`,{className:`space-y-3`,children:[u.length===0&&E(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),u.map(e=>E(M,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:D.get(e.id)??[],onAdd:e=>f(e),onEdit:e=>h(e),onDelete:e=>{C(e)},onSetDefault:e=>S(e),...e.id===`recordings`||e.id===`recordingsLow`?{onRelocate:e=>_(e)}:{}},e.id))]}),d!==null&&E(N,{initialType:d,onClose:()=>f(null),onCreated:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),f(null)}}),p!==null&&E(j,{location:p,onClose:()=>h(null),onSaved:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),h(null)}}),g&&E(ue,{location:g,onClose:()=>_(null)})]})}y();var fe=[[`backup`,`listDestinations`]],pe=[`backup`,`listArchives`];function me({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){let r=w(),i=m(),{data:a,isLoading:o,isError:s}=d({destinationId:e}),c=a??[],l=u({onSuccess:()=>{r.invalidateQueries({queryKey:[[...pe]]}),r.invalidateQueries({queryKey:fe})}}),f=v(async t=>{await i({title:`Delete this archive?`,message:`Permanently deletes "${t.label??t.id}" and frees ${W(t.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&l.mutate({destinationId:e,backupId:t.id})},[i,e,l]),[p,h]=T(null),g=v(async t=>{h(t.id);try{let n=await ae(he(e,t.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t.label??t.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{h(null)}},[e]),_=x(()=>[...c].toSorted((e,t)=>t.createdAt-e.createdAt),[c]);return o?E(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):s?E(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):_.length===0?E(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):E(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:b(`table`,{className:`w-full text-xs min-w-[640px]`,children:[E(`thead`,{children:b(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[E(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),E(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),E(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),E(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),E(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),E(`tbody`,{children:_.map(r=>b(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[E(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:ge(r.createdAt)}),E(`td`,{className:`px-3 py-1.5 text-foreground`,children:r.label??E(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),E(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:r.locations.join(`, `)}),E(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:W(r.sizeBytes)}),E(`td`,{className:`px-3 py-1.5`,children:b(`div`,{className:`flex items-center justify-end gap-1`,children:[b(`button`,{onClick:()=>{g(r)},disabled:p===r.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[p===r.id?E(L,{className:`h-3 w-3 animate-spin`}):E(P,{className:`h-3 w-3`}),`Download`]}),t&&n&&b(`button`,{onClick:()=>n({destinationId:e,archiveId:r.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[E(I,{className:`h-3 w-3`}),`Restore`]}),E(`button`,{onClick:()=>{f(r)},disabled:l.isPending,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:`Delete archive`,children:l.isPending?E(L,{className:`h-3 w-3 animate-spin`}):E(B,{className:`h-3 w-3`})})]})})]},r.id))})]})})}function he(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function ge(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}y();var Y=[[`backup`,`listSchedules`]];function _e({onEdit:e,onOpenRestoreWizard:t}){let{data:n,isLoading:r,isError:a}=s(),o=n??[],c=i().data??[],l=x(()=>{let e=new Map;for(let t of c)e.set(t.id,t);return e},[c]),[u,d]=T(null),f=e=>{d(t=>t===e?null:e)};return r?E(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading backup entries…`}):a?E(`div`,{className:`text-xs text-danger`,children:`Failed to load backup entries`}):o.length===0?E(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:E(`p`,{className:`text-xs text-foreground-subtle`,children:`No backup entries yet. Create one to schedule backups across one or more storage locations.`})}):E(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:b(`table`,{className:`w-full text-xs min-w-[820px]`,children:[E(`thead`,{children:b(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[E(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),E(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Entry`}),E(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),E(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Locations`}),E(`th`,{className:`text-left px-3 py-2 font-medium w-24`,children:`Retention`}),E(`th`,{className:`text-left px-3 py-2 font-medium w-48`,children:`Schedule`}),E(`th`,{className:`text-right px-3 py-2 font-medium w-52`,children:`Actions`})]})}),E(`tbody`,{children:o.map(n=>E(ve,{row:n,destById:l,isOpen:u===n.id,onToggle:()=>f(n.id),onEdit:()=>e(n),...t?{onOpenRestoreWizard:t}:{}},n.id))})]})})}function ve({row:e,destById:t,isOpen:n,onToggle:r,onEdit:i,onOpenRestoreWizard:o}){let s=w(),c=m(),l=f({onSuccess:()=>{s.invalidateQueries({queryKey:Y})}}),u=a({onSuccess:()=>{s.invalidateQueries({queryKey:Y})}}),d=p({onSuccess:()=>{s.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),s.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}}),[h,g]=T(String(e.retentionCount));D(()=>{g(String(e.retentionCount))},[e.retentionCount]);let _=x(()=>({id:e.id,label:e.label,cron:e.cron,locationIds:[...e.locationIds],retentionCount:e.retentionCount,...e.dataSources?{dataSources:[...e.dataSources]}:{}}),[e]),y=v(e=>{l.mutate({..._,enabled:e})},[l,_]),S=v(()=>{let t=Number.parseInt(h,10);if(Number.isNaN(t)||t<1){g(String(e.retentionCount));return}t!==e.retentionCount&&l.mutate({..._,enabled:e.enabled,retentionCount:t})},[l,_,h,e.retentionCount,e.enabled]),O=v(()=>{e.locationIds.length!==0&&d.mutate({destinations:[...e.locationIds],...e.dataSources&&e.dataSources.length>0?{locations:[...e.dataSources]}:{},label:e.label,retentionCount:e.retentionCount})},[d,e]),k=v(async()=>{await c({title:`Delete backup entry?`,message:`"${e.label||e.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&u.mutate({id:e.id})},[c,u,e.id,e.label]),A=e.cron.trim().length>0,j=l.isPending||u.isPending;return b(C,{children:[b(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[E(`td`,{className:`px-2 py-2`,children:E(`button`,{onClick:r,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:n?`Hide archives`:`Show archives`,children:E(n?z:re,{className:`h-3.5 w-3.5`})})}),E(`td`,{className:`px-3 py-2`,children:b(`button`,{onClick:i,className:`text-left hover:underline focus:outline-none`,children:[E(`div`,{className:`text-foreground font-medium`,children:e.label||`(unnamed)`}),e.lastRunAt!==void 0&&b(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`last run `,new Date(e.lastRunAt).toLocaleString()]})]})}),E(`td`,{className:`px-3 py-2`,children:E(`label`,{className:`inline-flex items-center cursor-pointer`,children:E(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:j,onChange:e=>y(e.target.checked)})})}),E(`td`,{className:`px-3 py-2`,children:b(`div`,{className:`flex flex-wrap gap-1`,children:[e.locationIds.length===0&&E(`span`,{className:`text-[11px] text-danger italic`,children:`No locations`}),e.locationIds.map(e=>E(`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))]})}),E(`td`,{className:`px-3 py-2`,children:E(`input`,{type:`number`,min:1,max:1e3,value:h,disabled:j,onChange:e=>g(e.target.value),onBlur:S,onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&g(String(e.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),E(`td`,{className:`px-3 py-2`,children:b(`button`,{onClick:i,className:`group flex flex-col items-start gap-0.5 text-left`,title:`Edit schedule`,children:[b(`span`,{className:`inline-flex items-center gap-1`,children:[E(oe,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),E(`span`,{className:`font-mono text-[11px] text-foreground`,children:A?e.cron:`Manual`})]}),A&&e.nextRunAt!==void 0&&b(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(e.nextRunAt).toLocaleString()]})]})}),E(`td`,{className:`px-3 py-2`,children:b(`div`,{className:`flex items-center justify-end gap-1.5`,children:[b(`button`,{onClick:O,disabled:d.isPending||e.locationIds.length===0,className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,title:`Run this entry now`,children:[d.isPending?E(L,{className:`h-3 w-3 animate-spin`}):E(ee,{className:`h-3 w-3`}),`Run now`]}),E(`button`,{onClick:i,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-foreground hover:bg-primary/5`,title:`Edit entry`,children:E(F,{className:`h-3 w-3`})}),E(`button`,{onClick:()=>{k()},disabled:j,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-danger hover:border-danger/40 disabled:opacity-50`,title:`Delete entry`,children:E(B,{className:`h-3 w-3`})})]})})]}),n&&E(`tr`,{className:`border-t border-border bg-background/30`,children:b(`td`,{colSpan:7,className:`px-4 py-3 space-y-4`,children:[e.locationIds.length===0&&E(`p`,{className:`text-xs text-foreground-subtle italic`,children:`This entry has no locations selected.`}),e.locationIds.map(e=>b(`div`,{className:`space-y-1.5`,children:[E(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:t.get(e)?.displayName??e}),E(me,{destinationId:e,restoreSupported:t.get(e)?.restoreSupported??!0,...o?{onOpenRestoreWizard:o}:{}})]},e))]})})]})}y();var X=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function ye(e){let t=e.trim();for(let e of X)if(e.cron===t)return e.id;return`custom`}function be({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){let i=ye(e),[a,o]=T(i===`custom`);D(()=>{i!==`custom`&&o(!1)},[i]);let s=Ce(e,250),c=g({cron:s,count:n},{enabled:s.trim().length>0}),l=c.data??null,u=e=>{o(!1),t(e.cron)},d=a||i===`custom`;return b(`div`,{className:`space-y-3`,children:[b(`div`,{className:`space-y-1`,children:[E(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),b(`div`,{className:`flex flex-wrap gap-1.5`,children:[X.map(e=>E(`button`,{type:`button`,onClick:()=>u(e),disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!a&&i===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.description??e.label,children:e.label},e.id)),E(`button`,{type:`button`,onClick:()=>{o(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(d?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),d&&b(`div`,{className:`space-y-1`,children:[E(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),E(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:r,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`}),b(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,E(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),E(xe,{cron:s,preview:l,loading:c.isFetching})]})}function xe({cron:e,preview:t,loading:n}){return n&&t===null?b(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[E(L,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?E(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):b(`div`,{className:`space-y-1`,children:[E(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),E(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>b(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[E(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),E(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:Se(e)})]},`${e}-${t}`))})]}):E(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function Se(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function Ce(e,t){let[n,r]=T(e),i=x(()=>e,[e]);return D(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}y();var we=[[`backup`,`listSchedules`]];function Te({entry:e,onClose:t,onSaved:n}){let r=w(),a=i(),o=a.data??[],[s,c]=T(e?.label??``),[l,u]=T(e?.cron??`0 3 * * *`),[d,p]=T(e?.enabled??!0),[m,h]=T(String(e?.retentionCount??7)),[g,_]=T(new Set(e?.locationIds??[])),v=f({onSuccess:()=>{r.invalidateQueries({queryKey:we}),n()}}),y=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},S=Number.parseInt(m,10),C=x(()=>s.trim().length>0&&g.size>0&&!Number.isNaN(S)&&S>=1&&S<=1e3,[s,g,S]),D=()=>{C&&v.mutate({...e?{id:e.id}:{},label:s.trim(),cron:l.trim(),enabled:d,locationIds:Array.from(g),retentionCount:S})},O=v.error instanceof Error?v.error.message:null;return E(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:b(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[b(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3 sticky top-0 bg-surface`,children:[E(`h2`,{className:`text-sm font-semibold text-foreground`,children:e?`Edit backup entry`:`New backup entry`}),E(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:E(H,{className:`h-4 w-4`})})]}),b(`div`,{className:`p-4 space-y-4`,children:[b(`div`,{className:`space-y-1`,children:[E(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Name`}),E(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`Nightly offsite`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),b(`div`,{className:`space-y-1.5`,children:[b(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:[`Locations (`,g.size,` selected)`]}),a.isLoading&&b(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[E(L,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!a.isLoading&&o.length===0&&E(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),o.length>0&&E(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-52 overflow-y-auto`,children:o.map(e=>b(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[b(`div`,{className:`flex items-center gap-2`,children:[E(`input`,{type:`checkbox`,checked:g.has(e.id),onChange:()=>y(e.id),className:`accent-primary`}),E(`span`,{className:`text-foreground`,children:e.displayName})]}),b(`div`,{className:`flex items-center gap-1.5`,children:[E(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-surface border border-border rounded px-1.5 py-0.5`,children:e.kind}),E(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]},e.id))})]}),b(`div`,{className:`grid grid-cols-2 gap-3`,children:[b(`div`,{className:`space-y-1`,children:[E(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Retention (archives kept)`}),E(`input`,{type:`number`,min:1,max:1e3,value:m,onChange:e=>h(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),b(`div`,{className:`space-y-1`,children:[E(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Enabled`}),b(`label`,{className:`inline-flex items-center gap-2 py-1.5 cursor-pointer`,children:[E(`input`,{type:`checkbox`,checked:d,onChange:e=>p(e.target.checked),className:`accent-primary`}),E(`span`,{className:`text-xs text-foreground-subtle`,children:`Run on schedule`})]})]})]}),b(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[E(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Schedule`}),E(be,{value:l,onChange:u,disabled:v.isPending})]}),O&&E(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:O})]}),b(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3 sticky bottom-0 bg-surface`,children:[E(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),b(`button`,{onClick:D,disabled:!C||v.isPending,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[v.isPending&&E(L,{className:`h-3.5 w-3.5 animate-spin`}),e?`Save`:`Create entry`]})]})]})})}y();var Ee=[[`backup`,`list`]];function De({initialDestinationId:e,initialArchiveId:t,onClose:n,onScheduled:r}){let a=w(),[s,c]=T(e&&t?2:1),[u,f]=T(e),[p,m]=T(t),[h,g]=T(new Set),{data:_}=i(),v=_??[],{data:y,isLoading:S}=d({destinationId:u??``},{enabled:!!u}),C=y??[];D(()=>{if(u!==void 0)return;let e=v.filter(e=>e.restoreSupported);e.length===1&&f(e[0].id)},[u,v]);let{data:O}=l({destinationId:u??``,backupId:p??``},{enabled:!!u&&!!p}),k=x(()=>O?.locations??[],[O]);D(()=>{k.length!==0&&g(e=>e.size===0?new Set(k):e)},[k]);let A=o({onSuccess:()=>{a.invalidateQueries({queryKey:Ee}),r(),n()}}),j=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},M=!!u&&!!p,N=h.size>0,P=M&&N&&!A.isPending,F=()=>{!u||!p||A.mutate({destinationId:u,backupId:p,locations:[...h]})};return E(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:b(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[b(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[b(`div`,{className:`space-y-0.5`,children:[E(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),b(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,s,` of 3 —`,` `,s===1?`pick source`:s===2?`pick locations`:`confirm`]})]}),E(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:E(H,{className:`h-4 w-4`})})]}),s===1&&E(Oe,{destinations:v,destinationId:u,onPickDestination:e=>{f(e),m(void 0),g(new Set)},archives:C,archivesLoading:S,archiveId:p,onPickArchive:m}),s===2&&E(ke,{locations:k,picked:h,onToggle:j}),s===3&&E(Z,{destinationName:v.find(e=>e.id===u)?.displayName??u??``,archive:C.find(e=>e.id===p),picked:[...h]}),b(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[E(`div`,{children:s>1&&b(`button`,{onClick:()=>c(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[E(ie,{className:`h-3 w-3`}),`Back`]})}),b(`div`,{className:`flex items-center gap-2`,children:[E(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),s<3?b(`button`,{disabled:s===1&&!M||s===2&&!N,onClick:()=>c(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,E(J,{className:`h-3 w-3`})]}):b(`button`,{onClick:F,disabled:!P,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[A.isPending?E(L,{className:`h-3.5 w-3.5 animate-spin`}):E(I,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Oe({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:a,onPickArchive:o}){let s=e.filter(e=>e.restoreSupported);return b(`div`,{className:`p-4 space-y-3`,children:[b(`div`,{className:`space-y-1.5`,children:[E(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),b(`select`,{value:t??``,onChange:e=>n(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[E(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>b(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),b(`div`,{className:`space-y-1.5`,children:[E(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&E(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&E(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&E(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&E(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=a===e.id;return b(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[b(`div`,{className:`flex items-center gap-2`,children:[E(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),b(`div`,{children:[E(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),E(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),E(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:W(e.sizeBytes)})]},e.id)})})]})]})}function ke({locations:e,picked:t,onToggle:n}){return e.length===0?E(`div`,{className:`p-4`,children:E(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):b(`div`,{className:`p-4 space-y-3`,children:[E(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),b(`div`,{className:`space-y-1.5`,children:[E(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),E(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>b(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[E(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),E(`span`,{className:`font-mono text-foreground`,children:e}),E(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:je(e)})]},e))})]})]})}function Z({destinationName:e,archive:t,picked:n}){return b(`div`,{className:`p-4 space-y-3 text-xs`,children:[E(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),b(`dl`,{className:`space-y-1.5`,children:[E(Q,{term:`Destination`,value:e}),E(Q,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&E(Q,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${W(t.sizeBytes)}`}),E(Q,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function Q({term:e,value:t}){return b(`div`,{className:`flex justify-between gap-3`,children:[E(`dt`,{className:`text-foreground-subtle`,children:e}),E(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Ae={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function je(e){return Ae[e]??``}y();function Me(){let e=m(),t=r(),[n,i]=T(null),[a,o]=T(!1),[s,c]=T(!1),[l,u]=T(void 0),d=async()=>{await e({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&t.mutate({confirm:!0})};return b(U,{children:[b(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[b(`button`,{onClick:()=>o(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[E(I,{className:`h-3.5 w-3.5`}),`Restore…`]}),b(`button`,{onClick:()=>u(null),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[E(ne,{className:`h-3.5 w-3.5`}),`New entry`]})]}),s&&E(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:b(`div`,{className:`flex items-center justify-between gap-3`,children:[b(`div`,{className:`flex items-center gap-2`,children:[E(I,{className:`h-3.5 w-3.5`}),E(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),b(`button`,{onClick:()=>{d()},disabled:t.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[t.isPending?E(L,{className:`h-3.5 w-3.5 animate-spin`}):E(I,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),E(_e,{onEdit:e=>u(e),onOpenRestoreWizard:e=>i(e)}),l!==void 0&&E(Te,{entry:l,onClose:()=>u(void 0),onSaved:()=>u(void 0)}),(n||a)&&E(De,{...n?{initialDestinationId:n.destinationId,initialArchiveId:n.archiveId}:{},onClose:()=>{i(null),o(!1)},onScheduled:()=>c(!0)})]})}y();var $=5e3,Ne={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function Pe(){let e=_({capName:`log-destination`},{refetchInterval:$}),t=h(void 0,{refetchInterval:$}),n=x(()=>K(t.data??[]),[t.data]),r=x(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]);return E(te,{title:`Logging`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another. Each destination's own configuration is docked under it.`,pageIcon:V,itemIcon:se,capability:`log-destination`,installButtonLabel:`Add destination`,items:x(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive,caption:r.get(e.addonId)??Ne[e.addonId]??``})),[e.data,n,r]),isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`,renderStatusBadges:e=>e.caption.length>0?E(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.caption}):null})}function Fe(){return E(`div`,{className:`flex flex-col p-4`,children:E(G,{tabs:[{id:`storage`,label:`Storage`,icon:A,content:E(de,{})},{id:`backup`,label:`Backup`,icon:q,content:E(Me,{})},{id:`logging`,label:`Logging`,icon:V,content:E(Pe,{})}]})})}export{Fe as DataPage};
@@ -1 +0,0 @@
1
- import{$n as e,Fo as t,Io as n,Jn as r,Lo as i,Mn as a,No as o,Po as s,Qn as c,Ro as l,Uo as u,Vo as d,Wo as f,Xn as p,Yn as m,Zn as h,ao as g,ar as _,er as v,fo as y,ir as b,nr as x,or as S,rr as C,tr as w}from"./src-C2KiI31z.js";import{K as T,Q as E,S as D,W as O,b as k,o as A,q as j,x as M,z as N}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{Q as P}from"./src-DREH726E.js";import{a as F,i as I,n as L,r as ee,t as R}from"./face-bbox-DFwfVPg5.js";import{t as z}from"./image-off-CePvOw2Z.js";import{t as B}from"./pencil-CGcp1H_S.js";import{t as V}from"./plus-CWclgqCc.js";import{t as H}from"./refresh-cw-CW_Ljqdp.js";import{t as te}from"./square-check-big-C1eD-s2U.js";import{t as U}from"./square-I9BIO4a-.js";import{t as W}from"./undo-2-B2bADvVZ.js";import{C as G,I as K,K as q,R as ne,c as J,g as Y,i as X,u as re,z as Z}from"./index-DzefosH4.js";import{t as ie}from"./AdminPage-Dq33XE9j.js";import{a as ae,c as oe,f as se,i as ce,l as le,n as ue,o as de,p as Q,r as fe,s as pe,t as $,u as me}from"./debounced-invalidate-CS1Zql4g.js";import{n as he,t as ge}from"./authed-media-XfBD4Ma-.js";var _e=q(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]);E();var ve=[[`faceGallery`]];function ye({identityId:e}){let t=A(),{data:n,isLoading:r}=v({identityId:e}),i=x();function a(n){i.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:ve})}})}return r?D(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[M(G,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?M(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):M(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:n.map(e=>D(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?M(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):M(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:M(_e,{className:`h-6 w-6`})}),M(`button`,{type:`button`,onClick:()=>a(e),disabled:i.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:M(X,{className:`h-4 w-4 text-white`})})]},e.id))})}function be({identity:e,expanded:r,onToggle:a}){let c=A(),[p,m]=j(``),[g,_]=j(!1),[v,y]=j(!1),b=C(),x=h();function S(){m(e.name),_(!0)}function w(){_(!1),m(``)}function T(){let t=p.trim();if(!t||t===e.name){w();return}b.mutate({id:e.id,name:t},{onSettled:()=>{c.invalidateQueries({queryKey:ve}),w()}})}function E(){x.mutate({id:e.id},{onSettled:()=>{c.invalidateQueries({queryKey:ve}),y(!1)}})}return D(`div`,{className:`rounded-md border border-border bg-surface`,children:[D(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[M(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?M(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):M(`div`,{className:`flex h-full w-full items-center justify-center`,children:M(_e,{className:`h-4 w-4 text-foreground-subtle`})})}),M(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:g?D(k,{children:[M(d,{value:p,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&w()},className:`h-6 text-xs`,autoFocus:!0}),M(`button`,{type:`button`,onClick:T,disabled:b.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:M(Z,{className:`h-3.5 w-3.5`})}),M(`button`,{type:`button`,onClick:w,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:M(X,{className:`h-3.5 w-3.5`})})]}):M(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),M(u,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!g&&D(`div`,{className:`flex items-center gap-1`,children:[M(`button`,{type:`button`,onClick:S,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:M(B,{className:`h-3.5 w-3.5`})}),M(`button`,{type:`button`,onClick:()=>y(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:M(J,{className:`h-3.5 w-3.5`})})]}),M(`button`,{type:`button`,onClick:a,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":r?`Collapse`:`Expand`,children:M(r?ne:K,{className:`h-3.5 w-3.5`})})]}),r&&M(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:M(ye,{identityId:e.id})}),M(o,{open:v,onOpenChange:e=>!e&&y(!1),children:D(s,{children:[D(i,{children:[M(l,{children:`Delete person`}),D(t,{children:[`Delete `,M(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),D(n,{children:[M(f,{variant:`secondary`,onClick:()=>y(!1),children:`Cancel`}),D(f,{variant:`danger`,onClick:E,disabled:x.isPending,children:[x.isPending?M(G,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function xe(){let e=A(),[t,n]=j(``),r=m();function i(){let i=t.trim();i&&r.mutate({name:i},{onSettled:()=>{e.invalidateQueries({queryKey:ve}),n(``)}})}return D(`div`,{className:`flex items-center gap-2 pt-2`,children:[M(d,{placeholder:`New person name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i()},className:`h-7 text-xs flex-1`}),D(f,{variant:`primary`,size:`sm`,onClick:i,disabled:r.isPending||!t.trim(),children:[r.isPending?M(G,{className:`h-3.5 w-3.5 animate-spin`}):M(V,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Se(){let{data:t,isLoading:n}=e(),[r,i]=j(null);function a(e){i(t=>t===e?null:e)}return n?D(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[M(G,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):D(`div`,{className:`space-y-2`,children:[(!t||t.length===0)&&M(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),t?.map(e=>M(be,{identity:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),M(xe,{})]})}function Ce(e){return e.base64===void 0||e.base64.length===0}function we(e){return e.filter(Ce).map(e=>e.faceId)}function Te(e){let t=0;for(let n of e)Ce(n)&&(t+=1);return t}E();function Ee(e){let[t,n]=j(null),[r,i]=j(null),[a,o]=j(!1);return N(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await he(`${ge}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),N(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function De(e){let t=e.filter(e=>e.base64.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function Oe({label:e,value:t}){return D(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[M(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),M(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function ke({box:e}){return M(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:M(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function Ae({face:e,cameraName:t,onClose:n,onAssign:r,onUnassign:i,onDelete:a,actionsPending:l}){let{data:u,isFetching:d}=c({faceId:e?.faceId??``},{enabled:e!==null}),[p,m]=j(`frame`),{frameSrc:h,naturalWidth:g,naturalHeight:_,failed:v}=Ee(e?.keyFrameMediaKey),y=O(()=>{let t=De(u??[]);return t?`data:image/jpeg;base64,${t.base64}`:e?.base64?`data:image/jpeg;base64,${e.base64}`:null},[u,e]),b=O(()=>!e?.faceBbox||g===null||_===null?null:R(e.faceBbox,g,_),[e?.faceBbox,g,_]);if(e===null)return null;let x=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!v,S=x&&p===`frame`,C=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return M(o,{open:!0,onOpenChange:e=>!e&&n(),children:D(s,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Face detail`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[D(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[D(`div`,{className:`min-w-0`,children:[M(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),M(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),M(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:M(X,{className:`h-4 w-4`})})]}),D(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[x&&D(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[D(`button`,{type:`button`,onClick:()=>m(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${p===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(I,{className:`h-3.5 w-3.5`}),` Full frame`]}),D(`button`,{type:`button`,onClick:()=>m(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${p===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(F,{className:`h-3.5 w-3.5`}),` Crop`]})]}),S&&h?M(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:M(ce,{src:h,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:b?M(ke,{box:b}):void 0})}):y?D(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[M(ce,{src:y,alt:`Detected face`,className:`h-full w-full`}),d&&M(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:M(G,{className:`h-3.5 w-3.5 animate-spin`})})]}):D(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[M(z,{className:`h-8 w-8 text-warning/70`}),M(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),M(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`})]}),D(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[M(Oe,{label:`Camera`,value:t}),M(Oe,{label:`Captured`,value:Q(e.timestamp)}),M(Oe,{label:`Track`,value:e.trackId}),M(Oe,{label:`Identity`,value:C})]})]}),D(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?D(f,{variant:`secondary`,onClick:()=>i(e.faceId),disabled:l,children:[M(L,{className:`h-3.5 w-3.5`}),` Detach`]}):D(f,{variant:`primary`,onClick:()=>r(e.faceId),disabled:l,children:[M(ee,{className:`h-3.5 w-3.5`}),` Assign`]}),D(f,{variant:`secondary`,onClick:()=>a(e.faceId),disabled:l,children:[M(J,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}E();var je=[[`faceGallery`]];function Me({faceIds:e,identities:a,onDone:c}){let u=A(),p=r(),h=m(),[g,_]=j(``),[v,y]=j(!1),[b,x]=j(null),S=e!==null&&e.length>0,C=e?.length??0;function w(){y(!1),_(``),x(null)}function T(){w(),c()}function E(t){!e||e.length===0||p.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{u.invalidateQueries({queryKey:je}),T()}})}function O(){!e||!g.trim()||h.mutate({name:g.trim()},{onSuccess:e=>{e?.id&&E(e.id)},onError:()=>{u.invalidateQueries({queryKey:je}),T()}})}let k=p.isPending||h.isPending;return M(o,{open:S,onOpenChange:e=>!e&&T(),children:D(s,{children:[D(i,{children:[M(l,{children:C>1?`Assign ${String(C)} faces to person`:`Assign face to person`}),M(t,{children:`Select an existing person or create a new one.`})]}),M(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:a.map(e=>D(`button`,{type:`button`,onClick:()=>x(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${b===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[M(`span`,{className:`font-medium`,children:e.name}),D(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),v?M(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:M(d,{placeholder:`New person name…`,value:g,onChange:e=>_(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()},autoFocus:!0,className:`flex-1`})}):M(`button`,{type:`button`,onClick:()=>{x(null),y(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New person…`}),D(n,{children:[M(f,{variant:`secondary`,onClick:T,disabled:k,children:`Cancel`}),v?D(f,{variant:`primary`,onClick:O,disabled:k||!g.trim(),children:[k&&M(G,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):D(f,{variant:`primary`,onClick:()=>b&&E(b),disabled:k||!b,children:[k&&M(G,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,C>1?` ${String(C)}`:``]})]})]})})}function Ne(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Pe(e,t){return e.faceIds.filter(e=>!t.has(e))}function Fe(e,t){return e.faceIds.filter(e=>t(e))}E();var Ie=[[`faceGallery`]],Le=20,Re=.3,ze=.9,Be=.05,Ve=.5,He=2,Ue=10,We=2;function Ge({cluster:e,face:t,active:n,onSelect:r}){return D(`button`,{type:`button`,onClick:r,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${n?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[M(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:t?.base64?M(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:``,className:`h-24 w-24 object-cover`}):M(z,{className:`h-24 w-24 p-6 text-foreground-subtle`})}),D(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]})]})}function Ke({face:e,cameraName:t,nowMs:n,excluded:r,onToggleExclude:i,onDelete:a,deletePending:o}){return D(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${r?`border-border opacity-40 grayscale`:`border-border`}`,children:[D(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?M(ce,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face from ${t}`,className:`h-full w-full`}):D(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[M(z,{className:`h-7 w-7 text-warning/70`}),M(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),M(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?`Include face`:`Exclude face`,title:r?`Include`:`Exclude`,children:M(r?W:X,{className:`h-3.5 w-3.5`})})]}),D(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[M(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),M(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:se(e.timestamp,n)})]}),M(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:M(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},disabled:o,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:o?M(G,{className:`h-4 w-4 animate-spin`}):M(J,{className:`h-4 w-4`})})})]})}function qe({open:e,onClose:t,byId:n,cameraName:r,nowMs:i,identities:a,selectMany:c}){let l=A(),u=g(),d=p(),[m,h]=j(Ve),[_,v]=j(We),[y,x]=j(null),[S,C]=j({}),[w,T]=j(null),{data:E,isFetching:P,refetch:F}=b({threshold:m,minClusterSize:_,limit:Le},{enabled:e}),I=E??[];N(()=>{C({})},[m,_]),N(()=>{if(I.length===0){x(null);return}I.some(e=>e.representativeFaceId===y)||x(I[0]?.representativeFaceId??null)},[I]);let L=O(()=>I.find(e=>e.representativeFaceId===y)??null,[I,y]),R=L?S[L.representativeFaceId]??new Set:new Set,z=O(()=>L?Fe(L,e=>n.has(e)):[],[L,n]),B=L?L.faceIds.length-z.length:0,V=L?Pe({...L,faceIds:z},R):[];function te(e){if(!L)return;let t=L.representativeFaceId;C(n=>({...n,[t]:Ne(n[t]??new Set,e)}))}function U(){l.invalidateQueries({queryKey:Ie})}async function W(e){await u({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&d.mutate({faceId:e},{onSettled:U})}function K(){T(null),t()}function q(){V.length!==0&&(c(V),K())}return D(o,{open:e,onOpenChange:e=>!e&&K(),children:[D(s,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":`Look-alike groups`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[D(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3`,children:[D(`div`,{className:`flex items-center justify-between gap-2`,children:[D(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[M(re,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),M(`button`,{type:`button`,onClick:K,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:M(X,{className:`h-4 w-4`})})]}),D(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[D(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,M(`input`,{type:`range`,min:Re,max:ze,step:Be,value:m,onChange:e=>h(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),M(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:m.toFixed(2)})]}),D(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,M(`input`,{type:`number`,min:He,max:Ue,step:1,value:_,onChange:e=>v(Math.min(Ue,Math.max(He,Number(e.target.value)||He))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),D(f,{variant:`secondary`,onClick:()=>{C({}),F()},disabled:P,children:[P?M(G,{className:`h-3.5 w-3.5 animate-spin`}):M(H,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),M(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:P&&I.length===0?D(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[M(G,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):I.length===0?M(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):D(k,{children:[M(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:I.map(e=>M(Ge,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===y,onSelect:()=>x(e.representativeFaceId)},e.representativeFaceId))}),M(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:I.map(e=>M(Ge,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===y,onSelect:()=>x(e.representativeFaceId)},e.representativeFaceId))}),M(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:L&&D(k,{children:[B>0&&D(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[B,` not loaded — excluded from actions`]}),M(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:z.map(e=>{let t=n.get(e);return t?M(Ke,{face:t,cameraName:r(t.deviceId),nowMs:i,excluded:R.has(e),onToggleExclude:()=>te(e),onDelete:()=>void W(e),deletePending:d.isPending&&d.variables?.faceId===e},e):null})})]})})]})}),D(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[M(f,{variant:`secondary`,onClick:q,disabled:V.length===0,children:`Select in gallery`}),D(f,{variant:`primary`,onClick:()=>T(V),disabled:V.length===0,children:[M(ee,{className:`h-3.5 w-3.5`}),` Adopt (`,V.length,`)`]})]})]}),M(Me,{faceIds:w,identities:a,onDone:()=>T(null)})]})}E();var Je=[[`faceGallery`]],Ye=500,Xe=120;function Ze({face:e,cameraName:t,nowMs:n,selected:r,onToggleSelect:i,onAssign:a,onOpenDetail:o}){let s=A(),c=_(),l=p(),u=()=>{s.invalidateQueries({queryKey:Je})},d=()=>o(e.faceId);return D(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${r?`border-primary ring-1 ring-primary`:`border-border`}`,children:[D(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?M(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face from ${t}`,onClick:d,className:`h-full w-full cursor-zoom-in object-cover`}):D(`button`,{type:`button`,onClick:d,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`,children:[M(z,{className:`h-7 w-7 text-warning/70`}),M(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?`Deselect`:`Select`,children:r?M(te,{className:`h-4 w-4 text-primary`}):M(U,{className:`h-4 w-4`})})]}),D(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[M(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),M(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:se(e.timestamp,n)}),e.identityName&&M(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),D(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),c.mutate({faceId:e.faceId},{onSettled:u})},disabled:c.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach face`,title:`Detach`,children:c.isPending?M(G,{className:`h-4 w-4 animate-spin`}):M(L,{className:`h-4 w-4`})}):M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(e.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign face to person`,title:`Assign to person`,children:M(ee,{className:`h-4 w-4`})}),M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),l.mutate({faceId:e.faceId},{onSettled:u})},disabled:l.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:l.isPending?M(G,{className:`h-4 w-4 animate-spin`}):M(J,{className:`h-4 w-4`})})]})]})}var Qe=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function $e(){let t=A(),[n,i]=j(`all`),[o,s]=j(pe),[c,l]=j(new Set),[u,d]=j(new Set),[m,h]=j(null),[g,v]=j(!1),[y,b]=j(null),{data:x,isLoading:C}=w({limit:Ye,filter:n},{refetchInterval:3e4}),{data:T=[]}=e(),{data:E}=a({}),N=r(),P=_(),F=S(),I=p(),R=Date.now(),B=x??[],V=O(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),H=e=>V.get(e)??`Camera #${String(e)}`,te=O(()=>oe(B).map(e=>({id:e,name:H(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[B,V]),U=O(()=>le(me(B,o),c),[B,o,c]),W=ue(U,Xe,O(()=>JSON.stringify([n,o.fromMs,o.toMs,[...c].sort((e,t)=>e-t)]),[n,o.fromMs,o.toMs,c])),K=O(()=>new Map(B.map(e=>[e.faceId,e])),[B]),q=O(()=>Te(U),[U]),ne=y===null?null:K.get(y)??null,Y=()=>{t.invalidateQueries({queryKey:Je})},Z=()=>d(new Set);function ie(e){d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function se(e){d(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ce(){se(we(U))}let Q=[...u],$=N.isPending||F.isPending||I.isPending,he=P.isPending||I.isPending;function ge(){Q.length!==0&&F.mutate({faceIds:Q},{onSettled:()=>{Y(),Z()}})}function _e(){Q.length!==0&&Promise.allSettled(Q.map(e=>I.mutateAsync({faceId:e}))).then(()=>{Y(),Z()})}function ve(e){b(null),h([e])}function ye(e){P.mutate({faceId:e},{onSettled:Y}),b(null)}function be(e){I.mutate({faceId:e},{onSettled:Y}),b(null)}let xe=U.length!==B.length;return D(`div`,{className:`relative space-y-3`,children:[D(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[M(`div`,{className:`flex items-center gap-1`,children:Qe.map(e=>M(`button`,{type:`button`,onClick:()=>i(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${n===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),M(ae,{onChange:s}),M(de,{cameras:te,selected:c,onChange:l}),D(`button`,{type:`button`,onClick:()=>v(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${g?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(re,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!C&&q>0&&D(`button`,{type:`button`,onClick:ce,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:`Select every visible face whose crop image is missing so you can delete the orphans in one pass`,children:[M(z,{className:`h-3.5 w-3.5`}),` Select `,q,` crop-less`]}),!C&&M(`span`,{className:`text-[10px] text-foreground-subtle ${q>0?`ml-2`:`ml-auto`}`,children:xe?`${String(U.length)} of ${String(B.length)} faces`:`${String(U.length)} face${U.length===1?``:`s`}`})]}),u.size>0&&D(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[D(`span`,{className:`text-xs font-medium text-foreground`,children:[u.size,` selected`]}),D(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[D(f,{variant:`primary`,onClick:()=>h(Q),disabled:$,children:[M(ee,{className:`h-3.5 w-3.5`}),` Assign`]}),D(f,{variant:`secondary`,onClick:ge,disabled:$,children:[F.isPending?M(G,{className:`h-3.5 w-3.5 animate-spin`}):M(L,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),D(f,{variant:`secondary`,onClick:_e,disabled:$,children:[M(J,{className:`h-3.5 w-3.5`}),` Delete`]}),M(f,{variant:`ghost`,onClick:Z,disabled:$,children:M(X,{className:`h-3.5 w-3.5`})})]})]}),C&&D(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[M(G,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!C&&U.length===0&&M(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:B.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!C&&U.length>0&&D(k,{children:[M(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:W.pageItems.map(e=>M(Ze,{face:e,cameraName:H(e.deviceId),nowMs:R,selected:u.has(e.faceId),onToggleSelect:ie,onAssign:e=>h([e]),onOpenDetail:b},e.faceId))}),M(fe,{currentPage:W.page,totalItems:W.totalItems,pageSize:W.pageSize,onPageChange:W.setPage,itemNoun:`faces`})]}),M(Ae,{face:ne,cameraName:ne?H(ne.deviceId):``,onClose:()=>b(null),onAssign:ve,onUnassign:ye,onDelete:be,actionsPending:he}),M(Me,{faceIds:m,identities:T,onDone:()=>{h(null),Z()}}),M(qe,{open:g,onClose:()=>v(!1),byId:K,cameraName:H,nowMs:R,identities:T,selectMany:se})]})}E();var et=[[`faceGallery`]],tt=2e3;function nt(){let e=A(),t=T(e);t.current=e;let n=T(void 0);n.current||=$({delayMs:tt,invalidate:()=>{t.current.invalidateQueries({queryKey:et})}}),N(()=>()=>n.current?.cancel(),[]),y(P.PipelineAnalyticsFaceGalleryChanged,()=>{n.current?.trigger()})}function rt(){return nt(),M(ie,{icon:Y,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:D(`section`,{className:`space-y-3`,children:[D(`div`,{children:[M(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),M(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled identities used for face recognition. Expand a row to view or remove training samples.`}),M(Se,{})]}),D(`div`,{className:`pt-4 border-t border-border`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),M(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`}),M($e,{})]})]})})}export{rt as DetectionIntelligencePage};