bunqueue-dashboard 1.0.4 → 1.1.0

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 (68) hide show
  1. package/README.md +173 -360
  2. package/agent/queue/validation.ts +6 -3
  3. package/dist/.vite/manifest.json +177 -82
  4. package/dist/assets/AddJob-jmrtBSrz.js +3 -0
  5. package/dist/assets/{Alerts-Lyzbq0qw.js → Alerts-DrwYvhbk.js} +1 -1
  6. package/dist/assets/{Benchmark-B4NfYkAi.js → Benchmark-7ULYlqmK.js} +1 -1
  7. package/dist/assets/{BulkAddJobs-BAN5wT8A.js → BulkAddJobs-C2sxF-St.js} +3 -3
  8. package/dist/assets/{Cron-Bz46oVXB.js → Cron-BY9EGj2n.js} +1 -1
  9. package/dist/assets/{CronManager-Cl5RW2cB.js → CronManager-CZvC_uox.js} +1 -1
  10. package/dist/assets/Database-B1Dx5OV2.js +3 -0
  11. package/dist/assets/{Diagnostics-DuzTPfyb.js → Diagnostics-D1LEl6O4.js} +1 -1
  12. package/dist/assets/{Dlq-D8s-NhV2.js → Dlq-CPxeigKg.js} +1 -1
  13. package/dist/assets/{DlqControl-DDxRMM8i.js → DlqControl-Dhcz7LY7.js} +1 -1
  14. package/dist/assets/DlqPro-CW80tQdN.js +1 -0
  15. package/dist/assets/FailureDiagnostics-DkLd6szC.js +1 -0
  16. package/dist/assets/{Fleet-BAziMWfo.js → Fleet-CsscadVQ.js} +1 -1
  17. package/dist/assets/Flows-Bzq3onQ3.js +2 -0
  18. package/dist/assets/GlobalSearch-CeCvA6Tm.js +1 -0
  19. package/dist/assets/{JobInspector-BXuXxDwR.js → JobInspector-nTUU1VOU.js} +2 -2
  20. package/dist/assets/{Jobs-pQBmffni.js → Jobs-OwKndzhg.js} +1 -1
  21. package/dist/assets/{JobsPro-k20Pas24.js → JobsPro-CSHP2AYC.js} +1 -1
  22. package/dist/assets/{Logs-DA4JFvpM.js → Logs-CiYuY8ix.js} +1 -1
  23. package/dist/assets/{LogsPro-hna5L6sP.js → LogsPro-BA-wZ8Dr.js} +1 -1
  24. package/dist/assets/{McpServer-Cqem-L3z.js → McpServer-BvOGxNnE.js} +1 -1
  25. package/dist/assets/MetricHistory-Dmu-XqaO.js +1 -0
  26. package/dist/assets/{Metrics-CJ9dW0me.js → Metrics-BF38GgYm.js} +1 -1
  27. package/dist/assets/{MetricsPro-BslYrx1A.js → MetricsPro-DHPmT4Md.js} +1 -1
  28. package/dist/assets/MonitoringSetup-60_ib3rf.js +3 -0
  29. package/dist/assets/{Overview-Cmg_2NAt.js → Overview-DBLxV_vL.js} +1 -1
  30. package/dist/assets/{Pagination-WVfHLHDS.js → Pagination-CmVnmrFt.js} +1 -1
  31. package/dist/assets/{QueueActions-BQf1-g5m.js → QueueActions-uNol2MD7.js} +1 -1
  32. package/dist/assets/QueueControl-DbQwvvtX.js +1 -0
  33. package/dist/assets/{QueueDetail-DfRY4jS4.js → QueueDetail-CA33Kebs.js} +1 -1
  34. package/dist/assets/{QueueDetailPro-CpSMSo8A.js → QueueDetailPro-AUf6FktH.js} +1 -1
  35. package/dist/assets/{Queues-C5lElTjp.js → Queues-C_KeSyQs.js} +1 -1
  36. package/dist/assets/{QueuesOverview-DRohFtuC.js → QueuesOverview-DQ6ta4wA.js} +1 -1
  37. package/dist/assets/{S3Backup-DUHmp2Xw.js → S3Backup-BgPBXJVZ.js} +1 -1
  38. package/dist/assets/{S3BackupPro-Cr2ZJZkw.js → S3BackupPro-BUzcmhnj.js} +3 -3
  39. package/dist/assets/{ServerControl-m58ooJT2.js → ServerControl-WUZjdjPX.js} +1 -1
  40. package/dist/assets/{Settings-DXsjoOqD.js → Settings-Dwh79r-B.js} +1 -1
  41. package/dist/assets/{Usage-CY2uEJEu.js → Usage-DeWofLpa.js} +1 -1
  42. package/dist/assets/{UsagePro-DtlB1dJc.js → UsagePro-BQJWWwW3.js} +1 -1
  43. package/dist/assets/{Webhooks-B_GwTCBW.js → Webhooks-DS3xmbEi.js} +1 -1
  44. package/dist/assets/{Workers-Bu8aJlZf.js → Workers-DyAVvmbR.js} +1 -1
  45. package/dist/assets/{WorkersPro-C6gNYGfo.js → WorkersPro-BJgab7of.js} +1 -1
  46. package/dist/assets/Workflows-BLXlNIxO.js +1 -0
  47. package/dist/assets/bqQueueOperationsRepository-BXoBdFQc.js +1 -0
  48. package/dist/assets/exportFile-B6puuPQx.js +2 -0
  49. package/dist/assets/index-D7iDxOBp.css +1 -0
  50. package/dist/assets/index-DwsYIYdu.js +8 -0
  51. package/dist/assets/{install-hFu5e6YM.js → install-DVeS3d31.js} +2 -2
  52. package/dist/assets/{package-Bb3FkjoS.js → package-D11d0FBn.js} +1 -1
  53. package/dist/assets/targetClient-DvzvwnGp.js +1 -0
  54. package/dist/assets/useDiscovery-BbWXsy6R.js +1 -0
  55. package/dist/assets/{useThroughputSeries-BN5QmKPt.js → useThroughputSeries-DQo7JaT-.js} +1 -1
  56. package/dist/favicon.svg +11 -22
  57. package/dist/index.html +3 -2
  58. package/package.json +1 -1
  59. package/scripts/embedded.gen.ts +146 -132
  60. package/dist/assets/AddJob-Dgjlhzn2.js +0 -3
  61. package/dist/assets/Database-CeUKS6Nf.js +0 -3
  62. package/dist/assets/DlqPro-xj-MM6u8.js +0 -1
  63. package/dist/assets/Flows-BFUMTSWv.js +0 -2
  64. package/dist/assets/QueueControl-BiMM0jLp.js +0 -1
  65. package/dist/assets/Workflows-ClF4YzhW.js +0 -1
  66. package/dist/assets/exportFile-C7xhE8Yh.js +0 -2
  67. package/dist/assets/index-DR8flo6r.css +0 -1
  68. package/dist/assets/index-X_fHGbXZ.js +0 -8
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,r as n,t as r}from"./react-vendor-08inPAVO.js";import{S as i,T as a,n as o}from"./icons-BIT5aq1c.js";import{r as s}from"./StatusBadge-D-mexaga.js";import{t as c}from"./api-CCgfskjt.js";import{O as l,b as u,g as d,h as f,l as p,y as m}from"./index-X_fHGbXZ.js";import{t as h}from"./Pagination-WVfHLHDS.js";var g=e(t(),1),_=r(),v=20,y={ok:!1,queues:[],total:0,limit:v,offset:0,timestamp:0};function b(){let[e,t]=(0,g.useState)(``),[r,b]=(0,g.useState)(0),{data:x,error:S,loading:C,refetch:w}=l(()=>c.queues(v,r*v),[r]),{data:T}=l(()=>c.overview(),[]),E=x??y,D=(0,g.useMemo)(()=>{let t=E.queues,n=e.trim().toLowerCase();return n?t.filter(e=>e.name.toLowerCase().includes(n)):t},[E,e]);if(C&&!x&&!S)return(0,_.jsx)(m,{label:`Loading queues…`});let O=T?.stats;return(0,_.jsxs)(`div`,{children:[S&&(0,_.jsx)(u,{onRetry:w}),(0,_.jsx)(d,{title:`Queues`,description:x?`${E.total} queues`:`Queue inventory unavailable`,live:!!x&&!S}),(0,_.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,_.jsx)(f,{label:`Waiting`,value:O?p(O.waiting):`—`,tone:`amber`,compact:!0}),(0,_.jsx)(f,{label:`Active`,value:O?p(O.active):`—`,tone:`blue`,compact:!0}),(0,_.jsx)(f,{label:`Delayed`,value:O?p(O.delayed):`—`,tone:`default`,compact:!0}),(0,_.jsx)(f,{label:`DLQ`,value:O?p(O.dlq):`—`,tone:O?.dlq?`red`:`default`,compact:!0})]}),(0,_.jsxs)(`div`,{className:`relative mb-4 max-w-sm`,children:[(0,_.jsx)(a,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-faint`}),(0,_.jsx)(`input`,{"aria-label":`Filter queues`,name:`classic-queue-filter`,autoComplete:`off`,value:e,onChange:e=>t(e.target.value),placeholder:`Search queues…`,className:`h-9 w-full rounded-lg border border-line bg-surface pl-9 pr-3 text-sm text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`})]}),(0,_.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,_.jsxs)(`table`,{className:`w-full min-w-[52rem] text-sm`,children:[(0,_.jsx)(`thead`,{children:(0,_.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,_.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queue`}),(0,_.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Waiting`}),(0,_.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Active`}),(0,_.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Delayed`}),(0,_.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`DLQ`}),(0,_.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Status`}),(0,_.jsx)(`th`,{className:`w-10 px-5 py-3`})]})}),(0,_.jsx)(`tbody`,{children:!x&&S?(0,_.jsx)(`tr`,{children:(0,_.jsxs)(`td`,{colSpan:7,className:`px-5 py-12 text-center text-sm text-warning`,children:[`Could not load queues — `,S.message,`. Retry above.`]})}):D.length===0?(0,_.jsx)(`tr`,{children:(0,_.jsx)(`td`,{colSpan:7,className:`px-5 py-12 text-center text-sm text-faint`,children:e?`No queues match on this page.`:`No queues yet.`})}):D.map(e=>(0,_.jsxs)(`tr`,{className:`group border-b border-line last:border-0 transition-colors hover:bg-surface-2/50`,children:[(0,_.jsx)(`td`,{className:`px-5 py-3`,children:(0,_.jsxs)(n,{to:`/queues-classic/${encodeURIComponent(e.name)}`,className:`flex items-center gap-2 rounded font-medium text-fg hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,children:[(0,_.jsx)(i,{className:`size-4 text-faint`}),e.name]})}),(0,_.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:p(e.waiting)}),(0,_.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-blue-400`,children:p(e.active)}),(0,_.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:p(e.delayed)}),(0,_.jsx)(`td`,{className:s(`px-5 py-3 text-right tnum`,e.dlq?`text-red-400`:`text-muted`),children:p(e.dlq)}),(0,_.jsx)(`td`,{className:`px-5 py-3`,children:(0,_.jsxs)(`span`,{className:s(`inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-xs font-medium`,e.paused?`bg-orange-500/10 text-orange-400`:`bg-emerald-500/10 text-emerald-400`),children:[(0,_.jsx)(`span`,{className:`size-1.5 rounded-full bg-current`}),e.paused?`Paused`:`Active`]})}),(0,_.jsx)(`td`,{className:`px-5 py-3 text-faint`,children:(0,_.jsx)(o,{className:`size-4 opacity-0 transition-opacity group-hover:opacity-100`})})]},e.name))})]})}),x&&(0,_.jsx)(h,{page:r,pageSize:v,total:E.total,onPageChange:b,label:`queues`})]})}export{b as Queues};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,r as n,t as r}from"./react-vendor-08inPAVO.js";import{S as i,T as a,n as o}from"./icons-BIT5aq1c.js";import{r as s}from"./StatusBadge-D-mexaga.js";import{t as c}from"./api-CCgfskjt.js";import{O as l,b as u,g as d,h as f,l as p,y as m}from"./index-DwsYIYdu.js";import{t as h}from"./Pagination-CmVnmrFt.js";var g=e(t(),1),_=r(),v=20,y={ok:!1,queues:[],total:0,limit:v,offset:0,timestamp:0};function b(){let[e,t]=(0,g.useState)(``),[r,b]=(0,g.useState)(0),{data:x,error:S,loading:C,refetch:w}=l(()=>c.queues(v,r*v),[r]),{data:T}=l(()=>c.overview(),[]),E=x??y,D=(0,g.useMemo)(()=>{let t=E.queues,n=e.trim().toLowerCase();return n?t.filter(e=>e.name.toLowerCase().includes(n)):t},[E,e]);if(C&&!x&&!S)return(0,_.jsx)(m,{label:`Loading queues…`});let O=T?.stats;return(0,_.jsxs)(`div`,{children:[S&&(0,_.jsx)(u,{onRetry:w}),(0,_.jsx)(d,{title:`Queues`,description:x?`${E.total} queues`:`Queue inventory unavailable`,live:!!x&&!S}),(0,_.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,_.jsx)(f,{label:`Waiting`,value:O?p(O.waiting):`—`,tone:`amber`,compact:!0}),(0,_.jsx)(f,{label:`Active`,value:O?p(O.active):`—`,tone:`blue`,compact:!0}),(0,_.jsx)(f,{label:`Delayed`,value:O?p(O.delayed):`—`,tone:`default`,compact:!0}),(0,_.jsx)(f,{label:`DLQ`,value:O?p(O.dlq):`—`,tone:O?.dlq?`red`:`default`,compact:!0})]}),(0,_.jsxs)(`div`,{className:`relative mb-4 max-w-sm`,children:[(0,_.jsx)(a,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-faint`}),(0,_.jsx)(`input`,{"aria-label":`Filter queues`,name:`classic-queue-filter`,autoComplete:`off`,value:e,onChange:e=>t(e.target.value),placeholder:`Search queues…`,className:`h-9 w-full rounded-lg border border-line bg-surface pl-9 pr-3 text-sm text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`})]}),(0,_.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,_.jsxs)(`table`,{className:`w-full min-w-[52rem] text-sm`,children:[(0,_.jsx)(`thead`,{children:(0,_.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,_.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queue`}),(0,_.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Waiting`}),(0,_.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Active`}),(0,_.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Delayed`}),(0,_.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`DLQ`}),(0,_.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Status`}),(0,_.jsx)(`th`,{className:`w-10 px-5 py-3`})]})}),(0,_.jsx)(`tbody`,{children:!x&&S?(0,_.jsx)(`tr`,{children:(0,_.jsxs)(`td`,{colSpan:7,className:`px-5 py-12 text-center text-sm text-warning`,children:[`Could not load queues — `,S.message,`. Retry above.`]})}):D.length===0?(0,_.jsx)(`tr`,{children:(0,_.jsx)(`td`,{colSpan:7,className:`px-5 py-12 text-center text-sm text-faint`,children:e?`No queues match on this page.`:`No queues yet.`})}):D.map(e=>(0,_.jsxs)(`tr`,{className:`group border-b border-line last:border-0 transition-colors hover:bg-surface-2/50`,children:[(0,_.jsx)(`td`,{className:`px-5 py-3`,children:(0,_.jsxs)(n,{to:`/queues-classic/${encodeURIComponent(e.name)}`,className:`flex items-center gap-2 rounded font-medium text-fg hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,children:[(0,_.jsx)(i,{className:`size-4 text-faint`}),e.name]})}),(0,_.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:p(e.waiting)}),(0,_.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-blue-400`,children:p(e.active)}),(0,_.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:p(e.delayed)}),(0,_.jsx)(`td`,{className:s(`px-5 py-3 text-right tnum`,e.dlq?`text-red-400`:`text-muted`),children:p(e.dlq)}),(0,_.jsx)(`td`,{className:`px-5 py-3`,children:(0,_.jsxs)(`span`,{className:s(`inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-xs font-medium`,e.paused?`bg-orange-500/10 text-orange-400`:`bg-emerald-500/10 text-emerald-400`),children:[(0,_.jsx)(`span`,{className:`size-1.5 rounded-full bg-current`}),e.paused?`Paused`:`Active`]})}),(0,_.jsx)(`td`,{className:`px-5 py-3 text-faint`,children:(0,_.jsx)(o,{className:`size-4 opacity-0 transition-opacity group-hover:opacity-100`})})]},e.name))})]})}),x&&(0,_.jsx)(h,{page:r,pageSize:v,total:E.total,onPageChange:b,label:`queues`})]})}export{b as Queues};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,r as n,t as r}from"./react-vendor-08inPAVO.js";import{S as i,T as a,b as o,n as s,x as c}from"./icons-BIT5aq1c.js";import{r as l}from"./StatusBadge-D-mexaga.js";import{C as u,F as d,I as f,O as p,b as m,g as h,h as g,l as _,v,w as y,y as b}from"./index-X_fHGbXZ.js";import{t as x}from"./Pagination-WVfHLHDS.js";import{r as S,t as C}from"./useServerActionGuard-uiZWD3dS.js";import{t as w}from"./promisePool-BVfQ9n9Q.js";var T=e(t(),1),E=r(),D=[[`waiting`,`Waiting`],[`prioritized`,`Prioritized`],[`active`,`Active`],[`completed`,`Completed`],[`failed`,`Failed`],[`delayed`,`Delayed`]];function O({rows:e,hasData:t,error:r,search:a,sortCol:u,sortDir:d,bulkBusy:f,busy:p,onSort:m,onToggle:h}){return(0,E.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,E.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,E.jsx)(`thead`,{children:(0,E.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,E.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queue`}),D.map(([e,t])=>(0,E.jsx)(`th`,{"aria-sort":u===e?d===`desc`?`descending`:`ascending`:void 0,className:`px-5 py-3 text-right font-medium`,children:(0,E.jsxs)(`button`,{type:`button`,onClick:()=>m(e),className:`inline-flex items-center gap-1 rounded uppercase tracking-wider hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,children:[t,u===e&&(0,E.jsx)(`span`,{"aria-hidden":`true`,children:d===`desc`?`↓`:`↑`})]})},e)),(0,E.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Status`}),(0,E.jsx)(`th`,{className:`w-24 px-5 py-3 text-right font-medium`,children:`Actions`})]})}),(0,E.jsx)(`tbody`,{children:!t&&r?(0,E.jsx)(`tr`,{children:(0,E.jsxs)(`td`,{colSpan:9,className:`px-5 py-12 text-center text-sm text-warning`,children:[`Could not load queues — `,r.message,`. Retry above.`]})}):e.length===0?(0,E.jsx)(`tr`,{children:(0,E.jsx)(`td`,{colSpan:9,className:`px-5 py-12 text-center text-sm text-faint`,children:a?`No queues match your search.`:`No queues yet.`})}):e.map(e=>{let t=f||p.has(e.name);return(0,E.jsxs)(`tr`,{className:`group border-b border-line last:border-0 transition-colors hover:bg-surface-2/50`,children:[(0,E.jsx)(`td`,{className:`px-5 py-3`,children:(0,E.jsxs)(n,{to:`/queues/${encodeURIComponent(e.name)}`,className:`flex items-center gap-2 rounded font-medium text-fg hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,children:[(0,E.jsx)(i,{className:`size-4 text-faint`}),e.name]})}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-warning`,children:_(e.counts.waiting)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-orange-400`,children:_(e.counts.prioritized)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-blue-400`,children:_(e.counts.active)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-success`,children:_(e.counts.completed)}),(0,E.jsx)(`td`,{className:l(`px-5 py-3 text-right tnum`,e.counts.failed?`text-danger`:`text-muted`),children:_(e.counts.failed)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:_(e.counts.delayed)}),(0,E.jsx)(`td`,{className:`px-5 py-3`,children:(0,E.jsxs)(`span`,{className:l(`inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-xs font-medium`,e.paused?`bg-orange-500/10 text-orange-400`:`bg-emerald-500/10 text-success`),children:[(0,E.jsx)(`span`,{className:`size-1.5 rounded-full bg-current`}),e.paused?`Paused`:`Active`]})}),(0,E.jsx)(`td`,{className:`px-5 py-3`,children:(0,E.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,E.jsx)(y,{"aria-label":e.paused?`Resume queue`:`Pause queue`,disabled:t,onClick:t=>{t.stopPropagation(),h(e)},children:e.paused?(0,E.jsx)(c,{className:`size-3.5 text-success`}):(0,E.jsx)(o,{className:`size-3.5 text-warning`})}),(0,E.jsx)(s,{className:`size-4 text-faint opacity-0 transition-opacity group-hover:opacity-100`})]})})]},e.name)})})]})})}var k=6,A=15,j=[];function M(){let[e,t]=(0,T.useState)(``),[n,r]=(0,T.useState)(0),[i,s]=(0,T.useState)(new Set),[y,D]=(0,T.useState)(!1),[M,N]=(0,T.useState)(null),[P,F]=(0,T.useState)(null),[I,L]=(0,T.useState)(`desc`),R=S(`queues-overview`);(0,T.useEffect)(()=>{s(new Set),D(!1),N(null)},[R.scopeKey]);let{data:z,error:B,loading:V,refetch:H}=p(()=>f.queuesSummary(),[]),U=z??j,W=e=>{P===e?I===`desc`?L(`asc`):F(null):(F(e),L(`desc`)),r(0)},G=(0,T.useMemo)(()=>{let t=e.trim().toLowerCase(),n=[...t?U.filter(e=>e.name.toLowerCase().includes(t)):U].sort((e,t)=>e.name.localeCompare(t.name));if(P){let e=I===`desc`?-1:1;n.sort((t,n)=>e*(t.counts[P]-n.counts[P]))}return n},[U,e,P,I]),K=(0,T.useMemo)(()=>U.reduce((e,t)=>(e.waiting+=t.counts.waiting,e.prioritized+=t.counts.prioritized,e.active+=t.counts.active,e.failed+=t.counts.failed,e.paused+=+!!t.paused,e),{waiting:0,prioritized:0,active:0,failed:0,paused:0}),[U]),q=Math.max(1,Math.ceil(G.length/A)),J=Math.min(n,q-1),Y=G.slice(J*A,J*A+A),X=async e=>{let t=R.begin(`queue:${e.name}`);if(t){s(t=>new Set(t).add(e.name)),N(null);try{let n=await(e.paused?f.resume(e.name):f.pause(e.name));if(C(n,e.paused?`Resume queue`:`Pause queue`),!t.isCurrent())return;N({ok:!0,text:`${e.name} ${e.paused?`resumed`:`paused`} ✓`}),H()}catch(n){if(!t.isCurrent())return;N({ok:!1,text:n.message}),d.error(`Failed to ${e.paused?`resume`:`pause`} ${e.name}`,n.message)}finally{t.finish()&&s(t=>{let n=new Set(t);return n.delete(e.name),n})}}},Z=async e=>{let t=U.filter(t=>e===`pause`?!t.paused:t.paused);if(t.length===0){d.info(`No queues to ${e}`);return}if(!window.confirm(`${e===`pause`?`Pause`:`Resume`} ${t.length} queue(s)?`))return;let n=R.begin([`bulk`,...U.map(e=>`queue:${e.name}`)]);if(n){D(!0),N(null);try{let r=await w(t,k,async t=>{if(!n.isCurrent())throw Error(`Queue action target changed`);let r=e===`pause`?await f.pause(t.name):await f.resume(t.name);C(r,`${e===`pause`?`Pause`:`Resume`} ${t.name}`)});if(!n.isCurrent())return;let i=r.filter(e=>e.status===`rejected`).length,a=`${e===`pause`?`Paused`:`Resumed`} ${t.length-i}/${t.length} queues${i?`, ${i} failed`:``}`;N({ok:i===0,text:a}),i===0?d.success(a):d.error(a),H()}finally{n.finish()&&D(!1)}}};return V&&!z&&!B?(0,E.jsx)(b,{label:`Loading queues…`}):B&&!z?(0,E.jsxs)(`div`,{children:[(0,E.jsx)(h,{title:`Queues`,description:`Queue inventory unavailable`}),(0,E.jsx)(v,{error:B,onRetry:H})]}):(0,E.jsxs)(`div`,{children:[(0,E.jsx)(h,{title:`Queues`,description:z?`${U.length} queues`:`Queue inventory unavailable`,live:!!z&&!B,actions:U.length>0?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(u,{variant:`warning`,size:`sm`,disabled:y||i.size>0||K.paused>=U.length,onClick:()=>Z(`pause`),children:[(0,E.jsx)(o,{className:`size-3.5`}),` Pause all`]}),(0,E.jsxs)(u,{variant:`success`,size:`sm`,disabled:y||i.size>0||K.paused===0,onClick:()=>Z(`resume`),children:[(0,E.jsx)(c,{className:`size-3.5`}),` Resume all`]})]}):void 0}),B&&(0,E.jsx)(m,{message:`Queue refresh failed — showing the last successful inventory.`,onRetry:H}),(0,E.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-5`,children:[(0,E.jsx)(g,{label:`Waiting`,value:_(K.waiting),tone:`amber`,compact:!0}),(0,E.jsx)(g,{label:`Prioritized`,value:_(K.prioritized),tone:`amber`,compact:!0}),(0,E.jsx)(g,{label:`Active`,value:_(K.active),tone:`blue`,compact:!0}),(0,E.jsx)(g,{label:`Failed`,value:_(K.failed),tone:K.failed?`red`:`default`,compact:!0}),(0,E.jsx)(g,{label:`Paused`,value:_(K.paused),tone:K.paused?`amber`:`default`,compact:!0})]}),(0,E.jsxs)(`div`,{className:`relative mb-4 max-w-sm`,children:[(0,E.jsx)(a,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-faint`}),(0,E.jsx)(`input`,{value:e,onChange:e=>{t(e.target.value),r(0)},placeholder:`Search queues…`,"aria-label":`Filter queues`,name:`queue-filter`,autoComplete:`off`,className:`h-9 w-full rounded-lg border border-line bg-surface pl-9 pr-3 text-sm text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`})]}),M&&(0,E.jsx)(`div`,{role:`status`,className:l(`mb-3 text-sm`,M.ok?`text-success`:`text-danger`),children:M.text}),(0,E.jsx)(O,{rows:Y,hasData:!!z,error:B,search:e,sortCol:P,sortDir:I,bulkBusy:y,busy:i,onSort:W,onToggle:e=>void X(e)}),(0,E.jsx)(x,{page:J,pageSize:A,total:G.length,onPageChange:r,label:`queues`})]})}export{M as QueuesOverview};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,r as n,t as r}from"./react-vendor-08inPAVO.js";import{S as i,T as a,b as o,n as s,x as c}from"./icons-BIT5aq1c.js";import{r as l}from"./StatusBadge-D-mexaga.js";import{C as u,F as d,I as f,O as p,b as m,g as h,h as g,l as _,v,w as y,y as b}from"./index-DwsYIYdu.js";import{t as x}from"./Pagination-CmVnmrFt.js";import{r as S,t as C}from"./useServerActionGuard-uiZWD3dS.js";import{t as w}from"./promisePool-BVfQ9n9Q.js";var T=e(t(),1),E=r(),D=[[`waiting`,`Waiting`],[`prioritized`,`Prioritized`],[`active`,`Active`],[`completed`,`Completed`],[`failed`,`Failed`],[`delayed`,`Delayed`]];function O({rows:e,hasData:t,error:r,search:a,sortCol:u,sortDir:d,bulkBusy:f,busy:p,onSort:m,onToggle:h}){return(0,E.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,E.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,E.jsx)(`thead`,{children:(0,E.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,E.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queue`}),D.map(([e,t])=>(0,E.jsx)(`th`,{"aria-sort":u===e?d===`desc`?`descending`:`ascending`:void 0,className:`px-5 py-3 text-right font-medium`,children:(0,E.jsxs)(`button`,{type:`button`,onClick:()=>m(e),className:`inline-flex items-center gap-1 rounded uppercase tracking-wider hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,children:[t,u===e&&(0,E.jsx)(`span`,{"aria-hidden":`true`,children:d===`desc`?`↓`:`↑`})]})},e)),(0,E.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Status`}),(0,E.jsx)(`th`,{className:`w-24 px-5 py-3 text-right font-medium`,children:`Actions`})]})}),(0,E.jsx)(`tbody`,{children:!t&&r?(0,E.jsx)(`tr`,{children:(0,E.jsxs)(`td`,{colSpan:9,className:`px-5 py-12 text-center text-sm text-warning`,children:[`Could not load queues — `,r.message,`. Retry above.`]})}):e.length===0?(0,E.jsx)(`tr`,{children:(0,E.jsx)(`td`,{colSpan:9,className:`px-5 py-12 text-center text-sm text-faint`,children:a?`No queues match your search.`:`No queues yet.`})}):e.map(e=>{let t=f||p.has(e.name);return(0,E.jsxs)(`tr`,{className:`group border-b border-line last:border-0 transition-colors hover:bg-surface-2/50`,children:[(0,E.jsx)(`td`,{className:`px-5 py-3`,children:(0,E.jsxs)(n,{to:`/queues/${encodeURIComponent(e.name)}`,className:`flex items-center gap-2 rounded font-medium text-fg hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,children:[(0,E.jsx)(i,{className:`size-4 text-faint`}),e.name]})}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-warning`,children:_(e.counts.waiting)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-orange-400`,children:_(e.counts.prioritized)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-blue-400`,children:_(e.counts.active)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-success`,children:_(e.counts.completed)}),(0,E.jsx)(`td`,{className:l(`px-5 py-3 text-right tnum`,e.counts.failed?`text-danger`:`text-muted`),children:_(e.counts.failed)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:_(e.counts.delayed)}),(0,E.jsx)(`td`,{className:`px-5 py-3`,children:(0,E.jsxs)(`span`,{className:l(`inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-xs font-medium`,e.paused?`bg-orange-500/10 text-orange-400`:`bg-emerald-500/10 text-success`),children:[(0,E.jsx)(`span`,{className:`size-1.5 rounded-full bg-current`}),e.paused?`Paused`:`Active`]})}),(0,E.jsx)(`td`,{className:`px-5 py-3`,children:(0,E.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,E.jsx)(y,{"aria-label":e.paused?`Resume queue`:`Pause queue`,disabled:t,onClick:t=>{t.stopPropagation(),h(e)},children:e.paused?(0,E.jsx)(c,{className:`size-3.5 text-success`}):(0,E.jsx)(o,{className:`size-3.5 text-warning`})}),(0,E.jsx)(s,{className:`size-4 text-faint opacity-0 transition-opacity group-hover:opacity-100`})]})})]},e.name)})})]})})}var k=6,A=15,j=[];function M(){let[e,t]=(0,T.useState)(``),[n,r]=(0,T.useState)(0),[i,s]=(0,T.useState)(new Set),[y,D]=(0,T.useState)(!1),[M,N]=(0,T.useState)(null),[P,F]=(0,T.useState)(null),[I,L]=(0,T.useState)(`desc`),R=S(`queues-overview`);(0,T.useEffect)(()=>{s(new Set),D(!1),N(null)},[R.scopeKey]);let{data:z,error:B,loading:V,refetch:H}=p(()=>f.queuesSummary(),[]),U=z??j,W=e=>{P===e?I===`desc`?L(`asc`):F(null):(F(e),L(`desc`)),r(0)},G=(0,T.useMemo)(()=>{let t=e.trim().toLowerCase(),n=[...t?U.filter(e=>e.name.toLowerCase().includes(t)):U].sort((e,t)=>e.name.localeCompare(t.name));if(P){let e=I===`desc`?-1:1;n.sort((t,n)=>e*(t.counts[P]-n.counts[P]))}return n},[U,e,P,I]),K=(0,T.useMemo)(()=>U.reduce((e,t)=>(e.waiting+=t.counts.waiting,e.prioritized+=t.counts.prioritized,e.active+=t.counts.active,e.failed+=t.counts.failed,e.paused+=+!!t.paused,e),{waiting:0,prioritized:0,active:0,failed:0,paused:0}),[U]),q=Math.max(1,Math.ceil(G.length/A)),J=Math.min(n,q-1),Y=G.slice(J*A,J*A+A),X=async e=>{let t=R.begin(`queue:${e.name}`);if(t){s(t=>new Set(t).add(e.name)),N(null);try{let n=await(e.paused?f.resume(e.name):f.pause(e.name));if(C(n,e.paused?`Resume queue`:`Pause queue`),!t.isCurrent())return;N({ok:!0,text:`${e.name} ${e.paused?`resumed`:`paused`} ✓`}),H()}catch(n){if(!t.isCurrent())return;N({ok:!1,text:n.message}),d.error(`Failed to ${e.paused?`resume`:`pause`} ${e.name}`,n.message)}finally{t.finish()&&s(t=>{let n=new Set(t);return n.delete(e.name),n})}}},Z=async e=>{let t=U.filter(t=>e===`pause`?!t.paused:t.paused);if(t.length===0){d.info(`No queues to ${e}`);return}if(!window.confirm(`${e===`pause`?`Pause`:`Resume`} ${t.length} queue(s)?`))return;let n=R.begin([`bulk`,...U.map(e=>`queue:${e.name}`)]);if(n){D(!0),N(null);try{let r=await w(t,k,async t=>{if(!n.isCurrent())throw Error(`Queue action target changed`);let r=e===`pause`?await f.pause(t.name):await f.resume(t.name);C(r,`${e===`pause`?`Pause`:`Resume`} ${t.name}`)});if(!n.isCurrent())return;let i=r.filter(e=>e.status===`rejected`).length,a=`${e===`pause`?`Paused`:`Resumed`} ${t.length-i}/${t.length} queues${i?`, ${i} failed`:``}`;N({ok:i===0,text:a}),i===0?d.success(a):d.error(a),H()}finally{n.finish()&&D(!1)}}};return V&&!z&&!B?(0,E.jsx)(b,{label:`Loading queues…`}):B&&!z?(0,E.jsxs)(`div`,{children:[(0,E.jsx)(h,{title:`Queues`,description:`Queue inventory unavailable`}),(0,E.jsx)(v,{error:B,onRetry:H})]}):(0,E.jsxs)(`div`,{children:[(0,E.jsx)(h,{title:`Queues`,description:z?`${U.length} queues`:`Queue inventory unavailable`,live:!!z&&!B,actions:U.length>0?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(u,{variant:`warning`,size:`sm`,disabled:y||i.size>0||K.paused>=U.length,onClick:()=>Z(`pause`),children:[(0,E.jsx)(o,{className:`size-3.5`}),` Pause all`]}),(0,E.jsxs)(u,{variant:`success`,size:`sm`,disabled:y||i.size>0||K.paused===0,onClick:()=>Z(`resume`),children:[(0,E.jsx)(c,{className:`size-3.5`}),` Resume all`]})]}):void 0}),B&&(0,E.jsx)(m,{message:`Queue refresh failed — showing the last successful inventory.`,onRetry:H}),(0,E.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-5`,children:[(0,E.jsx)(g,{label:`Waiting`,value:_(K.waiting),tone:`amber`,compact:!0}),(0,E.jsx)(g,{label:`Prioritized`,value:_(K.prioritized),tone:`amber`,compact:!0}),(0,E.jsx)(g,{label:`Active`,value:_(K.active),tone:`blue`,compact:!0}),(0,E.jsx)(g,{label:`Failed`,value:_(K.failed),tone:K.failed?`red`:`default`,compact:!0}),(0,E.jsx)(g,{label:`Paused`,value:_(K.paused),tone:K.paused?`amber`:`default`,compact:!0})]}),(0,E.jsxs)(`div`,{className:`relative mb-4 max-w-sm`,children:[(0,E.jsx)(a,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-faint`}),(0,E.jsx)(`input`,{value:e,onChange:e=>{t(e.target.value),r(0)},placeholder:`Search queues…`,"aria-label":`Filter queues`,name:`queue-filter`,autoComplete:`off`,className:`h-9 w-full rounded-lg border border-line bg-surface pl-9 pr-3 text-sm text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`})]}),M&&(0,E.jsx)(`div`,{role:`status`,className:l(`mb-3 text-sm`,M.ok?`text-success`:`text-danger`),children:M.text}),(0,E.jsx)(O,{rows:Y,hasData:!!z,error:B,search:e,sortCol:P,sortDir:I,bulkBusy:y,busy:i,onSort:W,onToggle:e=>void X(e)}),(0,E.jsx)(x,{page:J,pageSize:A,total:G.length,onPageChange:r,label:`queues`})]})}export{M as QueuesOverview};
@@ -1 +1 @@
1
- import{t as e}from"./react-vendor-08inPAVO.js";import{t}from"./api-CCgfskjt.js";import{O as n,S as r,b as i,g as a,v as o,x as s,y as c}from"./index-X_fHGbXZ.js";var l=e(),u=[[`S3_BACKUP_ENABLED`,`Set to 1 to enable periodic backups`],[`S3_BUCKET`,`Target bucket name`],[`S3_REGION`,`Bucket region (default us-east-1)`],[`S3_ENDPOINT`,`Custom endpoint (for S3-compatible stores)`],[`S3_ACCESS_KEY_ID`,`Access key`],[`S3_SECRET_ACCESS_KEY`,`Secret key`],[`S3_BACKUP_INTERVAL`,`Interval in ms (default 21600000 = 6h)`],[`S3_BACKUP_RETENTION`,`Backups to keep (default 7)`]];function d(){let{data:e,error:d,loading:f,refetch:p}=n(async()=>{let e=await t.storage();if(!e?.data||typeof e.data.diskFull!=`boolean`)throw Error(`Storage status response is missing disk health data`);return e},[]);return(0,l.jsxs)(`div`,{children:[d&&e&&(0,l.jsx)(i,{message:`Storage refresh failed — showing the last successful status.`,onRetry:p}),(0,l.jsx)(a,{title:`S3 Backup`,description:`SQLite snapshot backups to object storage.`,live:!!e?.data&&!d}),(0,l.jsx)(`div`,{className:`mb-6 rounded-lg border border-line bg-surface/60 px-4 py-3 text-sm text-muted`,children:`S3 backup runs on the server and is configured via environment variables — it cannot be toggled from the dashboard. The status below reflects the connected server's storage.`}),(0,l.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,l.jsxs)(s,{children:[(0,l.jsx)(r,{title:`Storage status`}),d&&!e?(0,l.jsx)(o,{error:d,onRetry:p}):f&&!e?(0,l.jsx)(c,{}):(0,l.jsxs)(`dl`,{className:`divide-y divide-line text-sm`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between py-2.5`,children:[(0,l.jsx)(`dt`,{className:`text-muted`,children:`Disk`}),(0,l.jsx)(`dd`,{className:e?.data?e.data.diskFull?`font-medium text-red-400`:`font-medium text-emerald-400`:`font-medium text-muted`,children:e?.data?e.data.diskFull?`Full`:`Healthy`:`Unavailable`})]}),(0,l.jsxs)(`div`,{className:`flex items-center justify-between py-2.5`,children:[(0,l.jsx)(`dt`,{className:`text-muted`,children:`Error`}),(0,l.jsx)(`dd`,{className:`font-mono text-xs text-fg`,children:e?.data?.error?String(e.data.error):`—`})]})]})]}),(0,l.jsxs)(s,{children:[(0,l.jsx)(r,{title:`Configuration (server env)`}),(0,l.jsx)(`dl`,{className:`divide-y divide-line text-sm`,children:u.map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-2.5`,children:[(0,l.jsx)(`dt`,{className:`font-mono text-xs text-accent/90`,children:e}),(0,l.jsx)(`dd`,{className:`text-right text-xs text-faint`,children:t})]},e))})]})]})]})}export{d as S3Backup};
1
+ import{t as e}from"./react-vendor-08inPAVO.js";import{t}from"./api-CCgfskjt.js";import{O as n,S as r,b as i,g as a,v as o,x as s,y as c}from"./index-DwsYIYdu.js";var l=e(),u=[[`S3_BACKUP_ENABLED`,`Set to 1 to enable periodic backups`],[`S3_BUCKET`,`Target bucket name`],[`S3_REGION`,`Bucket region (default us-east-1)`],[`S3_ENDPOINT`,`Custom endpoint (for S3-compatible stores)`],[`S3_ACCESS_KEY_ID`,`Access key`],[`S3_SECRET_ACCESS_KEY`,`Secret key`],[`S3_BACKUP_INTERVAL`,`Interval in ms (default 21600000 = 6h)`],[`S3_BACKUP_RETENTION`,`Backups to keep (default 7)`]];function d(){let{data:e,error:d,loading:f,refetch:p}=n(async()=>{let e=await t.storage();if(!e?.data||typeof e.data.diskFull!=`boolean`)throw Error(`Storage status response is missing disk health data`);return e},[]);return(0,l.jsxs)(`div`,{children:[d&&e&&(0,l.jsx)(i,{message:`Storage refresh failed — showing the last successful status.`,onRetry:p}),(0,l.jsx)(a,{title:`S3 Backup`,description:`SQLite snapshot backups to object storage.`,live:!!e?.data&&!d}),(0,l.jsx)(`div`,{className:`mb-6 rounded-lg border border-line bg-surface/60 px-4 py-3 text-sm text-muted`,children:`S3 backup runs on the server and is configured via environment variables — it cannot be toggled from the dashboard. The status below reflects the connected server's storage.`}),(0,l.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,l.jsxs)(s,{children:[(0,l.jsx)(r,{title:`Storage status`}),d&&!e?(0,l.jsx)(o,{error:d,onRetry:p}):f&&!e?(0,l.jsx)(c,{}):(0,l.jsxs)(`dl`,{className:`divide-y divide-line text-sm`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between py-2.5`,children:[(0,l.jsx)(`dt`,{className:`text-muted`,children:`Disk`}),(0,l.jsx)(`dd`,{className:e?.data?e.data.diskFull?`font-medium text-red-400`:`font-medium text-emerald-400`:`font-medium text-muted`,children:e?.data?e.data.diskFull?`Full`:`Healthy`:`Unavailable`})]}),(0,l.jsxs)(`div`,{className:`flex items-center justify-between py-2.5`,children:[(0,l.jsx)(`dt`,{className:`text-muted`,children:`Error`}),(0,l.jsx)(`dd`,{className:`font-mono text-xs text-fg`,children:e?.data?.error?String(e.data.error):`—`})]})]})]}),(0,l.jsxs)(s,{children:[(0,l.jsx)(r,{title:`Configuration (server env)`}),(0,l.jsx)(`dl`,{className:`divide-y divide-line text-sm`,children:u.map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-center justify-between gap-4 py-2.5`,children:[(0,l.jsx)(`dt`,{className:`font-mono text-xs text-accent/90`,children:e}),(0,l.jsx)(`dd`,{className:`text-right text-xs text-faint`,children:t})]},e))})]})]})]})}export{d as S3Backup};
@@ -1,3 +1,3 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,t as n}from"./react-vendor-08inPAVO.js";import{a as r,f as i,m as a,o,p as s}from"./connectionStore-B946Fhuv.js";import{w as c}from"./icons-BIT5aq1c.js";import{C as l,E as u,H as d,I as f,O as p,U as m,V as h,W as g,g as _,x as v}from"./index-X_fHGbXZ.js";import{a as y,n as b,r as x,t as S}from"./form-DBkslwzu.js";var C=e(t(),1),ee=`bq-dash-s3`,w=2,T=[`disabled`,`6h`,`12h`,`24h`],E={endpoint:``,region:`us-east-1`,bucket:``,schedule:`disabled`,pathPrefix:``,virtualHostedStyle:`auto`,retention:7};function D(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function O(e,t,n){return typeof e==`string`&&e.length<=n?e:t}function k(e){return T.includes(e)?e:`disabled`}function A(e){return e===`virtual-hosted`||e===`path-style`?e:`auto`}function j(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=1&&e<=1e6}function te(e){return j(e)?e:E.retention}function M(e){let t=D(e)?e:{};return{endpoint:O(t.endpoint,E.endpoint,2048),region:O(t.region,E.region,128),bucket:O(t.bucket,E.bucket,255),schedule:k(t.schedule),pathPrefix:O(t.pathPrefix,E.pathPrefix,1024),virtualHostedStyle:A(t.virtualHostedStyle),retention:te(t.retention)}}function ne(e){return M(e)}function N(){try{return globalThis.localStorage??null}catch{return null}}function P(e){try{let t=JSON.parse(e),n=D(t)?t:{},r=M(`state`in n?n.state:n),i=typeof n.version==`number`?n.version:void 0;return{hydration:JSON.stringify({state:r,...i===void 0?{}:{version:i}}),canonical:JSON.stringify({state:r,version:w})}}catch{return null}}var F={getItem(e){let t=N();if(!t)return null;let n;try{n=t.getItem(e)}catch{return null}if(n===null||e!==`bq-dash-s3`)return n;let r=P(n);if(!r){try{t.removeItem(e)}catch{}return null}if(n!==r.canonical)try{t.setItem(e,r.canonical)}catch{try{t.removeItem(e)}catch{}}return r.hydration},setItem(e,t){try{N()?.setItem(e,t)}catch{}},removeItem(e){try{N()?.removeItem(e)}catch{}}},I=a()(s(e=>({...E,accessKeyId:``,secretAccessKey:``,sessionToken:``,set:t=>e(e=>{let n={...e,...t};return{...M(n),accessKeyId:O(n.accessKeyId,``,512),secretAccessKey:O(n.secretAccessKey,``,2048),sessionToken:O(n.sessionToken,``,4096)}})}),{name:ee,version:w,storage:i(()=>F),partialize:ne,migrate:M,merge:(e,t)=>({...t,...M(e),accessKeyId:``,secretAccessKey:``,sessionToken:``})}));function L(){let e=Promise.resolve();return{async run(t,n){let r=e,i;e=new Promise(e=>{i=e}),await r;try{return n?.throwIfAborted(),await t()}finally{i()}}}}var R=new Set([`enabled`,`bucket`,`endpoint`,`interval`,`retention`]),re=new Set([`key`,`size`,`date`]);function ie(e){let t=z(e,R,`Backup status`);return typeof t.enabled!=`boolean`&&H(`Backup status`),{enabled:t.enabled,bucket:B(t.bucket,`Backup status bucket`,1024),endpoint:B(t.endpoint,`Backup status endpoint`,4096),interval:B(t.interval,`Backup status interval`,128),retention:B(t.retention,`Backup status retention`,128)}}function ae(e){(!Array.isArray(e)||e.length>2e4)&&H(`Backup list`);let t=new Set,n=0;return e.map((e,r)=>{let i=z(e,re,`Backup list item ${r}`),a=B(i.key,`Backup list item ${r} key`,2048),o=B(i.size,`Backup list item ${r} size`,128),s=B(i.date,`Backup list item ${r} date`,128);return n+=a.length+o.length+s.length,(n>2097152||t.has(a)||!V(s))&&H(`Backup list item ${r}`),t.add(a),{key:a,size:o,date:s}})}function z(e,t,n){(!e||typeof e!=`object`||Array.isArray(e))&&H(n);let r=e;return Object.keys(r).some(e=>!t.has(e))&&H(n),r}function B(e,t,n){return(typeof e!=`string`||e.length<1||e.length>n)&&H(t),e}function V(e){let t=Date.parse(e);return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(e)&&Number.isFinite(t)&&new Date(t).toISOString()===e}function H(e){throw Error(`${e} returned an invalid Bunqueue 2.9.3 contract`)}function U(e){return e.capture?.()??e}async function W(e,t,n){let r=await t.run(async()=>{let t=G(()=>e.restoreContext()),n=await G(()=>e.status().then(e=>ie(e.data)));return{context:t,list:await G(()=>e.list().then(e=>ae(e.data))),status:n}},n),{list:i,status:a}=r,o=await r.context,s=Array.from(new Set([a,i,o].filter(e=>e.status===`rejected`).map(e=>e.reason instanceof Error?e.reason.message:String(e.reason))));return{status:a.status===`fulfilled`?a.value:void 0,backups:i.status===`fulfilled`?i.value:[],context:o.status===`fulfilled`?o.value:void 0,errors:s}}async function G(e){try{return{status:`fulfilled`,value:await e()}}catch(e){return{status:`rejected`,reason:e}}}function K(e){let t={};for(let n of e.split(`
2
- `)){let e=n.indexOf(`=`);if(e<1)throw Error(`Generated backup environment is malformed`);let r=n.slice(0,e),i=n.slice(e+1);if(!/^S3_[A-Z0-9_]+$/.test(r))throw Error(`Unexpected backup key: ${r}`);let a;try{a=JSON.parse(i)}catch{if(i===`true`||i===`false`||/^\d+$/.test(i))a=i;else throw Error(`Generated backup value for ${r} is malformed`)}t[r]=String(a)}return t}var q=e=>({method:`POST`,headers:e===void 0?void 0:{"Content-Type":`application/json`},body:e===void 0?void 0:JSON.stringify(e)});function J(e,t){let n=async(n,r)=>(await t(`${n}?target=${encodeURIComponent(e())}`,r)).result;return{status:()=>n(`/backup/status`),list:()=>n(`/backup/list`),backupNow:()=>n(`/backup/now`,q()),restore:(e,t)=>n(`/backup/restore`,q({key:e,database:t})),configure:e=>n(`/backup/configure`,q({environment:e})),restoreContext:async()=>{let e=await t(`/control/status`);return{serverStatus:e.status,database:e.db??null}}}}function oe(){let e=r(),t=g(),n={...h(t)};return J(()=>e,(e,r)=>m(t.baseUrl,e,n,r,!0,`agent`))}var se={...J(r,d),capture:oe},Y=n();function ce({environmentText:e,pollIntervalMs:t=15e3,repository:n=se}){let r=o(e=>JSON.stringify([e.activeProfileId,e.baseUrl,e.agentBaseUrl,e.token,e.agentToken])),i=(0,C.useRef)(!0),a=(0,C.useRef)(null);a.current&&a.current.connectionIdentity===r&&a.current.repository===n||(a.current={connectionIdentity:r,repository:n});let[s]=(0,C.useState)(L),c=p(e=>W(U(n),s,e),[n,s],{intervalMs:t}),[l,u]=(0,C.useState)(``),[d,f]=(0,C.useState)(``),[m,h]=(0,C.useState)(``),g=(0,C.useRef)(!1);(0,C.useEffect)(()=>(i.current=!0,()=>{i.current=!1}),[]),(0,C.useEffect)(()=>{g.current=!1,u(``),f(``),h(``)},[r,n]);let _=async(e,t)=>{if(g.current)return;let r=a.current;g.current=!0,u(e),f(``),h(``);try{let o=U(n),l=await s.run(async()=>{if(!X(r,a,i))throw Error(`Backup operation scope changed before admission.`);return t(o)});if(!X(r,a,i))return;let u=l?.message;h(u??`${e} completed.`),await c.refetch()}catch(e){X(r,a,i)&&f(e instanceof Error?e.message:String(e))}finally{X(r,a,i)&&(g.current=!1,u(``))}},v=()=>{e&&window.confirm(`Apply this S3 configuration to the managed server? A restart is required.`)&&_(`Configuration`,t=>t.configure(K(e)))},y=()=>{window.confirm(`Create a transactionally consistent S3 backup now?`)&&_(`Backup`,e=>e.backupNow())},b=e=>{let t=c.data?.context?.database;t&&c.data?.context?.serverStatus===`stopped`&&window.prompt(`Type RESTORE to replace ${t.path} with ${e}`)===`RESTORE`&&_(`Restore`,n=>n.restore(e,t))},x=c.data;return(0,Y.jsxs)(`section`,{className:`mt-6 overflow-hidden rounded-lg border border-line bg-surface`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-3 border-b border-line px-4 py-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:`Live backup operations`}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-faint`,children:`Official Bunqueue 2.9.3 backup CLI, executed by the local control agent.`})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(`button`,{type:`button`,disabled:!e||!!l,onClick:v,className:`rounded-md border border-line px-3 py-2 text-xs text-muted disabled:opacity-40`,children:`Apply configuration`}),(0,Y.jsx)(`button`,{type:`button`,disabled:!!l,onClick:y,className:`rounded-md bg-accent px-3 py-2 text-xs font-medium text-accent-fg disabled:opacity-40`,children:l===`Backup`?`Backing up…`:`Backup now`}),(0,Y.jsx)(`button`,{type:`button`,disabled:!!l||c.loading,onClick:()=>void c.refetch(),className:`rounded-md border border-line px-3 py-2 text-xs text-muted disabled:opacity-40`,children:`Refresh`})]})]}),x?.status&&(0,Y.jsx)(le,{status:x.status,context:x.context}),d||x?.errors.length?(0,Y.jsx)(`div`,{role:`alert`,className:`border-b border-line px-4 py-3 text-xs text-danger`,children:d||x?.errors.join(` · `)}):null,m&&(0,Y.jsx)(`div`,{role:`status`,className:`border-b border-line px-4 py-3 text-xs text-success`,children:m}),(0,Y.jsx)(ue,{rows:x?.backups??[],canRestore:x?.context?.serverStatus===`stopped`&&!!x.context.database,busy:!!l,onRestore:b})]})}function le({status:e,context:t}){let n=[[`Scheduler`,e.enabled?`Enabled after restart`:`Disabled`],[`Bucket`,e.bucket||`—`],[`Endpoint`,e.endpoint],[`Retention`,e.retention],[`Server`,t?.serverStatus??`Unknown`]];return(0,Y.jsx)(`dl`,{className:`grid border-b border-line sm:grid-cols-2 xl:grid-cols-5`,children:n.map(([e,t])=>(0,Y.jsxs)(`div`,{className:`border-b border-line px-4 py-3 last:border-b-0 xl:border-r xl:border-b-0`,children:[(0,Y.jsx)(`dt`,{className:`text-[10px] uppercase tracking-wider text-faint`,children:e}),(0,Y.jsx)(`dd`,{className:`mt-1 truncate text-xs text-fg`,title:t,children:t})]},e))})}function ue({rows:e,canRestore:t,busy:n,onRestore:r}){return e.length?(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full min-w-[680px] text-left text-xs`,children:[(0,Y.jsx)(`thead`,{className:`border-b border-line text-[10px] uppercase tracking-wider text-faint`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Object key`}),(0,Y.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Size`}),(0,Y.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Created`}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-right font-medium`,children:`Restore`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-line`,children:e.map(e=>(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`td`,{className:`max-w-md truncate px-4 py-3 font-mono text-fg`,title:e.key,children:e.key}),(0,Y.jsx)(`td`,{className:`px-4 py-3 text-muted`,children:e.size}),(0,Y.jsx)(`td`,{className:`px-4 py-3 text-muted`,children:e.date}),(0,Y.jsx)(`td`,{className:`px-4 py-3 text-right`,children:(0,Y.jsx)(`button`,{type:`button`,disabled:!t||n,title:t?`Restore this backup`:`Stop the managed server before restore`,onClick:()=>r(e.key),className:`rounded-md border border-danger/40 px-2.5 py-1.5 text-danger disabled:opacity-35`,children:`Restore`})})]},e.key))})]})}):(0,Y.jsx)(`p`,{className:`px-4 py-8 text-center text-sm text-muted`,children:`No backup objects returned.`})}function X(e,t,n){return n.current&&e!==null&&t.current===e}function de(e){if(typeof e!=`object`||!e||Array.isArray(e)||typeof e.ok!=`boolean`)throw Error(`Malformed storage status response.`);let t=e.data;if(typeof t!=`object`||!t||Array.isArray(t)||typeof t.diskFull!=`boolean`)throw Error(`Storage status response is missing disk health data.`);return{diskFull:t.diskFull}}var Z=e=>JSON.stringify([e.activeProfileId,e.baseUrl,e.agentBaseUrl,e.token,e.agentToken]),fe={"6h":216e5,"12h":432e5,"24h":864e5};function Q(e,t){return`${e}=${typeof t==`string`?JSON.stringify(t):String(t)}`}function pe(e){let t=[],n=e.endpoint.trim(),r=e.region.trim(),i=e.bucket.trim(),a=e.accessKeyId.trim(),o=e.secretAccessKey.trim(),s=e.sessionToken.trim(),c=e.pathPrefix.trim();if(e.schedule===`disabled`)return{ok:!0,value:Q(`S3_BACKUP_ENABLED`,!1)};if((!r||r.length>128)&&t.push(`Region is required (maximum 128 characters).`),(!i||i.length>255)&&t.push(`Bucket is required (maximum 255 characters).`),(!a||a.length>512)&&t.push(`Access key ID is required (maximum 512 characters).`),(!o||o.length>2048)&&t.push(`Secret access key is required (maximum 2048 characters).`),s.length>4096&&t.push(`Session token is too long.`),(!Number.isSafeInteger(e.retention)||e.retention<1||e.retention>1e6)&&t.push(`Retention must be a whole number from 1 to 1000000.`),c.length>1024&&t.push(`Path prefix is too long.`),n)try{let e=new URL(n);(e.protocol!==`http:`&&e.protocol!==`https:`||e.username||e.password||n.length>2048)&&t.push(`Endpoint must be an http(s) URL without embedded credentials.`)}catch{t.push(`Endpoint must be a valid http(s) URL.`)}if(t.length)return{ok:!1,errors:t};let l=[Q(`S3_BACKUP_ENABLED`,!0),Q(`S3_ACCESS_KEY_ID`,a),Q(`S3_SECRET_ACCESS_KEY`,o),Q(`S3_BUCKET`,i),Q(`S3_REGION`,r),Q(`S3_BACKUP_RETENTION`,e.retention)];return s&&l.push(Q(`S3_SESSION_TOKEN`,s)),e.virtualHostedStyle!==`auto`&&l.push(Q(`S3_VIRTUAL_HOSTED_STYLE`,e.virtualHostedStyle===`virtual-hosted`)),n&&l.push(Q(`S3_ENDPOINT`,n)),c&&l.push(Q(`S3_BACKUP_PREFIX`,c)),l.push(Q(`S3_BACKUP_INTERVAL`,fe[e.schedule])),{ok:!0,value:l.join(`
3
- `)}}function $(e){let t=e.trim();return t?Number(t):NaN}function me(e,t){let[n,r]=(0,C.useState)(()=>({text:String(e),base:e})),i=n.base===e?n.text:String(e);return{text:i,value:$(i),change(n){let i=$(n),a=j(i);a&&t(i),r({text:n,base:a?i:e})}}}function he({environment:e}){return(0,Y.jsxs)(v,{children:[(0,Y.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-base font-semibold text-fg`,children:`Server environment`}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-faint`,children:`Credentials stay in memory and are copied or applied only when you request it.`})]}),e.ok&&(0,Y.jsx)(u,{value:e.value})]}),e.ok?(0,Y.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap break-all rounded-lg bg-surface-2 p-4 font-mono text-xs text-muted`,children:e.value.replace(/^S3_ACCESS_KEY_ID=.*$/m,`S3_ACCESS_KEY_ID="••••••••"`).replace(/^S3_SECRET_ACCESS_KEY=.*$/m,`S3_SECRET_ACCESS_KEY="••••••••"`).replace(/^S3_SESSION_TOKEN=.*$/m,`S3_SESSION_TOKEN="••••••••"`)}):(0,Y.jsx)(`ul`,{className:`space-y-1 text-sm text-danger`,"aria-label":`Configuration errors`,children:e.errors.map(e=>(0,Y.jsxs)(`li`,{children:[`• `,e]},e))})]})}function ge(){let e=I(),t=me(e.retention,t=>e.set({retention:t})),n=o(Z),[r,i]=(0,C.useState)(null),[a,s]=(0,C.useState)(null),u=(0,C.useRef)(0),d=pe({...e,retention:t.value}),p=r?.target===n?r:null,m=a===n;return(0,C.useEffect)(()=>(u.current++,i(null),s(null),()=>{u.current++}),[n]),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(_,{title:`S3 Backup Setup`,description:`Configure and operate Bunqueue 2.9.3 S3 backups.`}),(0,Y.jsxs)(`div`,{className:`mb-6 flex items-center justify-between rounded-xl border border-line bg-surface px-5 py-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`flex size-10 items-center justify-center rounded-lg bg-surface-2 text-faint`,children:(0,Y.jsx)(c,{className:`size-5`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-semibold text-fg`,children:d.ok?`Configuration draft complete`:`Configuration draft incomplete`}),(0,Y.jsx)(`div`,{className:`text-xs text-faint`,children:d.ok?e.schedule===`disabled`?`Safe disable settings ready to apply`:`Target: ${e.bucket.trim()} · ready to apply`:`Complete the required fields to generate server settings`})]})]}),(0,Y.jsx)(`span`,{className:d.ok?`rounded-full bg-emerald-500/10 px-3 py-1 text-xs font-medium text-success`:`rounded-full bg-amber-500/10 px-3 py-1 text-xs font-medium text-warning`,children:d.ok?`Ready`:`Configure`})]}),(0,Y.jsx)(`div`,{className:`mb-6 rounded-lg border border-line bg-surface/60 px-4 py-2.5 text-xs text-faint`,children:`Apply the generated settings through the local control agent below, then restart Bunqueue. Status, object listing, manual backups, and guarded restores use the official Bunqueue CLI. Non-secret draft fields are stored locally; credentials remain in memory.`}),(0,Y.jsxs)(v,{className:`mb-6`,children:[(0,Y.jsx)(`h2`,{className:`mb-1 text-base font-semibold text-fg`,children:`Connection Settings`}),(0,Y.jsx)(`p`,{className:`mb-4 text-xs text-faint`,children:`Works with AWS S3, Cloudflare R2, MinIO, DigitalOcean Spaces, and any S3-compatible provider.`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 md:grid-cols-2`,children:[(0,Y.jsx)(S,{label:`Endpoint`,children:(0,Y.jsx)(b,{name:`s3-endpoint`,value:e.endpoint,onChange:t=>e.set({endpoint:t.target.value}),placeholder:`https://s3.amazonaws.com`,maxLength:2048,autoComplete:`off`,inputMode:`url`})}),(0,Y.jsx)(S,{label:`Region`,children:(0,Y.jsx)(b,{name:`s3-region`,value:e.region,onChange:t=>e.set({region:t.target.value}),placeholder:`us-east-1`,maxLength:128,autoComplete:`off`,spellCheck:!1})}),(0,Y.jsx)(`div`,{className:`md:col-span-2`,children:(0,Y.jsx)(S,{label:`Bucket name`,children:(0,Y.jsx)(b,{name:`s3-bucket`,value:e.bucket,onChange:t=>e.set({bucket:t.target.value}),placeholder:`my-bunqueue-backups`,maxLength:255,autoComplete:`off`,spellCheck:!1})})}),(0,Y.jsx)(S,{label:`Access key ID`,children:(0,Y.jsx)(b,{name:`s3-access-key-id`,value:e.accessKeyId,onChange:t=>e.set({accessKeyId:t.target.value}),placeholder:`AKIA…`,maxLength:512,autoComplete:`off`,spellCheck:!1})}),(0,Y.jsx)(S,{label:`Secret access key`,children:(0,Y.jsx)(b,{name:`s3-secret-access-key`,type:`password`,value:e.secretAccessKey,onChange:t=>e.set({secretAccessKey:t.target.value}),placeholder:`••••••••••••••••`,maxLength:2048,autoComplete:`off`,spellCheck:!1})}),(0,Y.jsx)(`div`,{className:`md:col-span-2`,children:(0,Y.jsx)(S,{label:`Session token (optional, for temporary STS credentials)`,children:(0,Y.jsx)(b,{name:`s3-session-token`,type:`password`,value:e.sessionToken,onChange:t=>e.set({sessionToken:t.target.value}),placeholder:`Temporary AWS session token`,maxLength:4096,autoComplete:`off`,spellCheck:!1})})}),(0,Y.jsx)(`p`,{className:`-mt-2 text-xs text-faint md:col-span-2`,children:`Keys are kept in memory only and cleared on reload.`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(x,{htmlFor:`s3-backup-schedule`,children:`Backup interval`}),(0,Y.jsxs)(y,{id:`s3-backup-schedule`,name:`s3-backup-schedule`,value:e.schedule,onChange:t=>e.set({schedule:t.target.value}),className:`mt-1.5`,title:`Written to S3_BACKUP_ENABLED and S3_BACKUP_INTERVAL in the generated config`,autoComplete:`off`,children:[(0,Y.jsx)(`option`,{value:`disabled`,children:`Disabled`}),(0,Y.jsx)(`option`,{value:`6h`,children:`Every 6 hours`}),(0,Y.jsx)(`option`,{value:`12h`,children:`Every 12 hours`}),(0,Y.jsx)(`option`,{value:`24h`,children:`Every 24 hours`})]})]}),(0,Y.jsx)(S,{label:`Path prefix (optional)`,children:(0,Y.jsx)(b,{name:`s3-path-prefix`,value:e.pathPrefix,onChange:t=>e.set({pathPrefix:t.target.value}),placeholder:`backups/production/`,maxLength:1024,autoComplete:`off`,spellCheck:!1})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(x,{htmlFor:`s3-addressing-style`,children:`Addressing style`}),(0,Y.jsxs)(y,{id:`s3-addressing-style`,name:`s3-addressing-style`,value:e.virtualHostedStyle,onChange:t=>e.set({virtualHostedStyle:t.target.value}),className:`mt-1.5`,children:[(0,Y.jsx)(`option`,{value:`auto`,children:`Provider default`}),(0,Y.jsx)(`option`,{value:`virtual-hosted`,children:`Virtual-hosted style`}),(0,Y.jsx)(`option`,{value:`path-style`,children:`Path style`})]})]}),(0,Y.jsx)(S,{label:`Backups to retain`,children:(0,Y.jsx)(b,{name:`s3-retention`,type:`number`,min:1,max:1e6,step:1,value:t.text,onChange:e=>t.change(e.target.value),inputMode:`numeric`})})]}),(0,Y.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(l,{onClick:async()=>{let e=n,t=++u.current;i(null),s(e);try{let n=await f.storage();if(t!==u.current||Z(o.getState())!==e)return;let r=de(n);i({target:e,ok:!r.diskFull,msg:r.diskFull?`Server disk is full`:`Server disk healthy — this does not validate the S3 credentials`})}catch(n){if(t!==u.current||Z(o.getState())!==e)return;i({target:e,ok:!1,msg:n.message})}finally{t===u.current&&s(null)}},children:m?`Checking server storage…`:`Check server storage`}),(0,Y.jsx)(`span`,{className:`text-xs text-faint`,children:`This checks SQLite disk health only, not S3 connectivity.`}),p&&(0,Y.jsx)(`span`,{role:`status`,className:p.ok?`text-xs text-success`:`text-xs text-danger`,children:p.msg})]})]}),(0,Y.jsx)(he,{environment:d}),(0,Y.jsx)(ce,{environmentText:d.ok?d.value:void 0})]})}export{ge as S3BackupPro};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,t as n}from"./react-vendor-08inPAVO.js";import{a as r,f as i,m as a,o,p as s}from"./connectionStore-B946Fhuv.js";import{_ as c,f as l,g as u,p as d}from"./targetClient-DvzvwnGp.js";import{w as f}from"./icons-BIT5aq1c.js";import{C as p,E as m,I as h,O as g,g as _,x as v}from"./index-DwsYIYdu.js";import{a as y,n as b,r as x,t as S}from"./form-DBkslwzu.js";var C=e(t(),1),w=`bq-dash-s3`,T=2,ee=[`disabled`,`6h`,`12h`,`24h`],E={endpoint:``,region:`us-east-1`,bucket:``,schedule:`disabled`,pathPrefix:``,virtualHostedStyle:`auto`,retention:7};function D(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function O(e,t,n){return typeof e==`string`&&e.length<=n?e:t}function k(e){return ee.includes(e)?e:`disabled`}function A(e){return e===`virtual-hosted`||e===`path-style`?e:`auto`}function j(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=1&&e<=1e6}function te(e){return j(e)?e:E.retention}function M(e){let t=D(e)?e:{};return{endpoint:O(t.endpoint,E.endpoint,2048),region:O(t.region,E.region,128),bucket:O(t.bucket,E.bucket,255),schedule:k(t.schedule),pathPrefix:O(t.pathPrefix,E.pathPrefix,1024),virtualHostedStyle:A(t.virtualHostedStyle),retention:te(t.retention)}}function ne(e){return M(e)}function N(){try{return globalThis.localStorage??null}catch{return null}}function P(e){try{let t=JSON.parse(e),n=D(t)?t:{},r=M(`state`in n?n.state:n),i=typeof n.version==`number`?n.version:void 0;return{hydration:JSON.stringify({state:r,...i===void 0?{}:{version:i}}),canonical:JSON.stringify({state:r,version:T})}}catch{return null}}var F={getItem(e){let t=N();if(!t)return null;let n;try{n=t.getItem(e)}catch{return null}if(n===null||e!==`bq-dash-s3`)return n;let r=P(n);if(!r){try{t.removeItem(e)}catch{}return null}if(n!==r.canonical)try{t.setItem(e,r.canonical)}catch{try{t.removeItem(e)}catch{}}return r.hydration},setItem(e,t){try{N()?.setItem(e,t)}catch{}},removeItem(e){try{N()?.removeItem(e)}catch{}}},I=a()(s(e=>({...E,accessKeyId:``,secretAccessKey:``,sessionToken:``,set:t=>e(e=>{let n={...e,...t};return{...M(n),accessKeyId:O(n.accessKeyId,``,512),secretAccessKey:O(n.secretAccessKey,``,2048),sessionToken:O(n.sessionToken,``,4096)}})}),{name:w,version:T,storage:i(()=>F),partialize:ne,migrate:M,merge:(e,t)=>({...t,...M(e),accessKeyId:``,secretAccessKey:``,sessionToken:``})}));function L(){let e=Promise.resolve();return{async run(t,n){let r=e,i;e=new Promise(e=>{i=e}),await r;try{return n?.throwIfAborted(),await t()}finally{i()}}}}var re=new Set([`enabled`,`bucket`,`endpoint`,`interval`,`retention`]),ie=new Set([`key`,`size`,`date`]);function ae(e){let t=z(e,re,`Backup status`);return typeof t.enabled!=`boolean`&&H(`Backup status`),{enabled:t.enabled,bucket:B(t.bucket,`Backup status bucket`,1024),endpoint:B(t.endpoint,`Backup status endpoint`,4096),interval:B(t.interval,`Backup status interval`,128),retention:B(t.retention,`Backup status retention`,128)}}function R(e){(!Array.isArray(e)||e.length>2e4)&&H(`Backup list`);let t=new Set,n=0;return e.map((e,r)=>{let i=z(e,ie,`Backup list item ${r}`),a=B(i.key,`Backup list item ${r} key`,2048),o=B(i.size,`Backup list item ${r} size`,128),s=B(i.date,`Backup list item ${r} date`,128);return n+=a.length+o.length+s.length,(n>2097152||t.has(a)||!V(s))&&H(`Backup list item ${r}`),t.add(a),{key:a,size:o,date:s}})}function z(e,t,n){(!e||typeof e!=`object`||Array.isArray(e))&&H(n);let r=e;return Object.keys(r).some(e=>!t.has(e))&&H(n),r}function B(e,t,n){return(typeof e!=`string`||e.length<1||e.length>n)&&H(t),e}function V(e){let t=Date.parse(e);return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(e)&&Number.isFinite(t)&&new Date(t).toISOString()===e}function H(e){throw Error(`${e} returned an invalid Bunqueue 2.9.3 contract`)}function U(e){return e.capture?.()??e}async function W(e,t,n){let r=await t.run(async()=>{let t=G(()=>e.restoreContext()),n=await G(()=>e.status().then(e=>ae(e.data)));return{context:t,list:await G(()=>e.list().then(e=>R(e.data))),status:n}},n),{list:i,status:a}=r,o=await r.context,s=Array.from(new Set([a,i,o].filter(e=>e.status===`rejected`).map(e=>e.reason instanceof Error?e.reason.message:String(e.reason))));return{status:a.status===`fulfilled`?a.value:void 0,backups:i.status===`fulfilled`?i.value:[],context:o.status===`fulfilled`?o.value:void 0,errors:s}}async function G(e){try{return{status:`fulfilled`,value:await e()}}catch(e){return{status:`rejected`,reason:e}}}function K(e){let t={};for(let n of e.split(`
2
+ `)){let e=n.indexOf(`=`);if(e<1)throw Error(`Generated backup environment is malformed`);let r=n.slice(0,e),i=n.slice(e+1);if(!/^S3_[A-Z0-9_]+$/.test(r))throw Error(`Unexpected backup key: ${r}`);let a;try{a=JSON.parse(i)}catch{if(i===`true`||i===`false`||/^\d+$/.test(i))a=i;else throw Error(`Generated backup value for ${r} is malformed`)}t[r]=String(a)}return t}var q=e=>({method:`POST`,headers:e===void 0?void 0:{"Content-Type":`application/json`},body:e===void 0?void 0:JSON.stringify(e)});function J(e,t){let n=async(n,r)=>(await t(`${n}?target=${encodeURIComponent(e())}`,r)).result;return{status:()=>n(`/backup/status`),list:()=>n(`/backup/list`),backupNow:()=>n(`/backup/now`,q()),restore:(e,t)=>n(`/backup/restore`,q({key:e,database:t})),configure:e=>n(`/backup/configure`,q({environment:e})),restoreContext:async()=>{let e=await t(`/control/status`);return{serverStatus:e.status,database:e.db??null}}}}function oe(){let e=r(),t=c(),n={...l(t)};return J(()=>e,(e,r)=>u(t.baseUrl,e,n,r,!0,`agent`))}var se={...J(r,d),capture:oe},Y=n();function ce({environmentText:e,pollIntervalMs:t=15e3,repository:n=se}){let r=o(e=>JSON.stringify([e.activeProfileId,e.baseUrl,e.agentBaseUrl,e.token,e.agentToken])),i=(0,C.useRef)(!0),a=(0,C.useRef)(null);a.current&&a.current.connectionIdentity===r&&a.current.repository===n||(a.current={connectionIdentity:r,repository:n});let[s]=(0,C.useState)(L),c=g(e=>W(U(n),s,e),[n,s],{intervalMs:t}),[l,u]=(0,C.useState)(``),[d,f]=(0,C.useState)(``),[p,m]=(0,C.useState)(``),h=(0,C.useRef)(!1);(0,C.useEffect)(()=>(i.current=!0,()=>{i.current=!1}),[]),(0,C.useEffect)(()=>{h.current=!1,u(``),f(``),m(``)},[r,n]);let _=async(e,t)=>{if(h.current)return;let r=a.current;h.current=!0,u(e),f(``),m(``);try{let o=U(n),l=await s.run(async()=>{if(!X(r,a,i))throw Error(`Backup operation scope changed before admission.`);return t(o)});if(!X(r,a,i))return;let u=l?.message;m(u??`${e} completed.`),await c.refetch()}catch(e){X(r,a,i)&&f(e instanceof Error?e.message:String(e))}finally{X(r,a,i)&&(h.current=!1,u(``))}},v=()=>{e&&window.confirm(`Apply this S3 configuration to the managed server? A restart is required.`)&&_(`Configuration`,t=>t.configure(K(e)))},y=()=>{window.confirm(`Create a transactionally consistent S3 backup now?`)&&_(`Backup`,e=>e.backupNow())},b=e=>{let t=c.data?.context?.database;t&&c.data?.context?.serverStatus===`stopped`&&window.prompt(`Type RESTORE to replace ${t.path} with ${e}`)===`RESTORE`&&_(`Restore`,n=>n.restore(e,t))},x=c.data;return(0,Y.jsxs)(`section`,{className:`mt-6 overflow-hidden rounded-lg border border-line bg-surface`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-3 border-b border-line px-4 py-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:`Live backup operations`}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-faint`,children:`Official Bunqueue 2.9.3 backup CLI, executed by the local control agent.`})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(`button`,{type:`button`,disabled:!e||!!l,onClick:v,className:`rounded-md border border-line px-3 py-2 text-xs text-muted disabled:opacity-40`,children:`Apply configuration`}),(0,Y.jsx)(`button`,{type:`button`,disabled:!!l,onClick:y,className:`rounded-md bg-accent px-3 py-2 text-xs font-medium text-accent-fg disabled:opacity-40`,children:l===`Backup`?`Backing up…`:`Backup now`}),(0,Y.jsx)(`button`,{type:`button`,disabled:!!l||c.loading,onClick:()=>void c.refetch(),className:`rounded-md border border-line px-3 py-2 text-xs text-muted disabled:opacity-40`,children:`Refresh`})]})]}),x?.status&&(0,Y.jsx)(le,{status:x.status,context:x.context}),d||x?.errors.length?(0,Y.jsx)(`div`,{role:`alert`,className:`border-b border-line px-4 py-3 text-xs text-danger`,children:d||x?.errors.join(` · `)}):null,p&&(0,Y.jsx)(`div`,{role:`status`,className:`border-b border-line px-4 py-3 text-xs text-success`,children:p}),(0,Y.jsx)(ue,{rows:x?.backups??[],canRestore:x?.context?.serverStatus===`stopped`&&!!x.context.database,busy:!!l,onRestore:b})]})}function le({status:e,context:t}){let n=[[`Scheduler`,e.enabled?`Enabled after restart`:`Disabled`],[`Bucket`,e.bucket||`—`],[`Endpoint`,e.endpoint],[`Retention`,e.retention],[`Server`,t?.serverStatus??`Unknown`]];return(0,Y.jsx)(`dl`,{className:`grid border-b border-line sm:grid-cols-2 xl:grid-cols-5`,children:n.map(([e,t])=>(0,Y.jsxs)(`div`,{className:`border-b border-line px-4 py-3 last:border-b-0 xl:border-r xl:border-b-0`,children:[(0,Y.jsx)(`dt`,{className:`text-[10px] uppercase tracking-wider text-faint`,children:e}),(0,Y.jsx)(`dd`,{className:`mt-1 truncate text-xs text-fg`,title:t,children:t})]},e))})}function ue({rows:e,canRestore:t,busy:n,onRestore:r}){return e.length?(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full min-w-[680px] text-left text-xs`,children:[(0,Y.jsx)(`thead`,{className:`border-b border-line text-[10px] uppercase tracking-wider text-faint`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Object key`}),(0,Y.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Size`}),(0,Y.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Created`}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-right font-medium`,children:`Restore`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-line`,children:e.map(e=>(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`td`,{className:`max-w-md truncate px-4 py-3 font-mono text-fg`,title:e.key,children:e.key}),(0,Y.jsx)(`td`,{className:`px-4 py-3 text-muted`,children:e.size}),(0,Y.jsx)(`td`,{className:`px-4 py-3 text-muted`,children:e.date}),(0,Y.jsx)(`td`,{className:`px-4 py-3 text-right`,children:(0,Y.jsx)(`button`,{type:`button`,disabled:!t||n,title:t?`Restore this backup`:`Stop the managed server before restore`,onClick:()=>r(e.key),className:`rounded-md border border-danger/40 px-2.5 py-1.5 text-danger disabled:opacity-35`,children:`Restore`})})]},e.key))})]})}):(0,Y.jsx)(`p`,{className:`px-4 py-8 text-center text-sm text-muted`,children:`No backup objects returned.`})}function X(e,t,n){return n.current&&e!==null&&t.current===e}function de(e){if(typeof e!=`object`||!e||Array.isArray(e)||typeof e.ok!=`boolean`)throw Error(`Malformed storage status response.`);let t=e.data;if(typeof t!=`object`||!t||Array.isArray(t)||typeof t.diskFull!=`boolean`)throw Error(`Storage status response is missing disk health data.`);return{diskFull:t.diskFull}}var Z=e=>JSON.stringify([e.activeProfileId,e.baseUrl,e.agentBaseUrl,e.token,e.agentToken]),fe={"6h":216e5,"12h":432e5,"24h":864e5};function Q(e,t){return`${e}=${typeof t==`string`?JSON.stringify(t):String(t)}`}function pe(e){let t=[],n=e.endpoint.trim(),r=e.region.trim(),i=e.bucket.trim(),a=e.accessKeyId.trim(),o=e.secretAccessKey.trim(),s=e.sessionToken.trim(),c=e.pathPrefix.trim();if(e.schedule===`disabled`)return{ok:!0,value:Q(`S3_BACKUP_ENABLED`,!1)};if((!r||r.length>128)&&t.push(`Region is required (maximum 128 characters).`),(!i||i.length>255)&&t.push(`Bucket is required (maximum 255 characters).`),(!a||a.length>512)&&t.push(`Access key ID is required (maximum 512 characters).`),(!o||o.length>2048)&&t.push(`Secret access key is required (maximum 2048 characters).`),s.length>4096&&t.push(`Session token is too long.`),(!Number.isSafeInteger(e.retention)||e.retention<1||e.retention>1e6)&&t.push(`Retention must be a whole number from 1 to 1000000.`),c.length>1024&&t.push(`Path prefix is too long.`),n)try{let e=new URL(n);(e.protocol!==`http:`&&e.protocol!==`https:`||e.username||e.password||n.length>2048)&&t.push(`Endpoint must be an http(s) URL without embedded credentials.`)}catch{t.push(`Endpoint must be a valid http(s) URL.`)}if(t.length)return{ok:!1,errors:t};let l=[Q(`S3_BACKUP_ENABLED`,!0),Q(`S3_ACCESS_KEY_ID`,a),Q(`S3_SECRET_ACCESS_KEY`,o),Q(`S3_BUCKET`,i),Q(`S3_REGION`,r),Q(`S3_BACKUP_RETENTION`,e.retention)];return s&&l.push(Q(`S3_SESSION_TOKEN`,s)),e.virtualHostedStyle!==`auto`&&l.push(Q(`S3_VIRTUAL_HOSTED_STYLE`,e.virtualHostedStyle===`virtual-hosted`)),n&&l.push(Q(`S3_ENDPOINT`,n)),c&&l.push(Q(`S3_BACKUP_PREFIX`,c)),l.push(Q(`S3_BACKUP_INTERVAL`,fe[e.schedule])),{ok:!0,value:l.join(`
3
+ `)}}function $(e){let t=e.trim();return t?Number(t):NaN}function me(e,t){let[n,r]=(0,C.useState)(()=>({text:String(e),base:e})),i=n.base===e?n.text:String(e);return{text:i,value:$(i),change(n){let i=$(n),a=j(i);a&&t(i),r({text:n,base:a?i:e})}}}function he({environment:e}){return(0,Y.jsxs)(v,{children:[(0,Y.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-base font-semibold text-fg`,children:`Server environment`}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-faint`,children:`Credentials stay in memory and are copied or applied only when you request it.`})]}),e.ok&&(0,Y.jsx)(m,{value:e.value})]}),e.ok?(0,Y.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap break-all rounded-lg bg-surface-2 p-4 font-mono text-xs text-muted`,children:e.value.replace(/^S3_ACCESS_KEY_ID=.*$/m,`S3_ACCESS_KEY_ID="••••••••"`).replace(/^S3_SECRET_ACCESS_KEY=.*$/m,`S3_SECRET_ACCESS_KEY="••••••••"`).replace(/^S3_SESSION_TOKEN=.*$/m,`S3_SESSION_TOKEN="••••••••"`)}):(0,Y.jsx)(`ul`,{className:`space-y-1 text-sm text-danger`,"aria-label":`Configuration errors`,children:e.errors.map(e=>(0,Y.jsxs)(`li`,{children:[`• `,e]},e))})]})}function ge(){let e=I(),t=me(e.retention,t=>e.set({retention:t})),n=o(Z),[r,i]=(0,C.useState)(null),[a,s]=(0,C.useState)(null),c=(0,C.useRef)(0),l=pe({...e,retention:t.value}),u=r?.target===n?r:null,d=a===n;return(0,C.useEffect)(()=>(c.current++,i(null),s(null),()=>{c.current++}),[n]),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(_,{title:`S3 Backup Setup`,description:`Configure and operate Bunqueue 2.9.3 S3 backups.`}),(0,Y.jsxs)(`div`,{className:`mb-6 flex items-center justify-between rounded-xl border border-line bg-surface px-5 py-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`span`,{className:`flex size-10 items-center justify-center rounded-lg bg-surface-2 text-faint`,children:(0,Y.jsx)(f,{className:`size-5`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-semibold text-fg`,children:l.ok?`Configuration draft complete`:`Configuration draft incomplete`}),(0,Y.jsx)(`div`,{className:`text-xs text-faint`,children:l.ok?e.schedule===`disabled`?`Safe disable settings ready to apply`:`Target: ${e.bucket.trim()} · ready to apply`:`Complete the required fields to generate server settings`})]})]}),(0,Y.jsx)(`span`,{className:l.ok?`rounded-full bg-emerald-500/10 px-3 py-1 text-xs font-medium text-success`:`rounded-full bg-amber-500/10 px-3 py-1 text-xs font-medium text-warning`,children:l.ok?`Ready`:`Configure`})]}),(0,Y.jsx)(`div`,{className:`mb-6 rounded-lg border border-line bg-surface/60 px-4 py-2.5 text-xs text-faint`,children:`Apply the generated settings through the local control agent below, then restart Bunqueue. Status, object listing, manual backups, and guarded restores use the official Bunqueue CLI. Non-secret draft fields are stored locally; credentials remain in memory.`}),(0,Y.jsxs)(v,{className:`mb-6`,children:[(0,Y.jsx)(`h2`,{className:`mb-1 text-base font-semibold text-fg`,children:`Connection Settings`}),(0,Y.jsx)(`p`,{className:`mb-4 text-xs text-faint`,children:`Works with AWS S3, Cloudflare R2, MinIO, DigitalOcean Spaces, and any S3-compatible provider.`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 md:grid-cols-2`,children:[(0,Y.jsx)(S,{label:`Endpoint`,children:(0,Y.jsx)(b,{name:`s3-endpoint`,value:e.endpoint,onChange:t=>e.set({endpoint:t.target.value}),placeholder:`https://s3.amazonaws.com`,maxLength:2048,autoComplete:`off`,inputMode:`url`})}),(0,Y.jsx)(S,{label:`Region`,children:(0,Y.jsx)(b,{name:`s3-region`,value:e.region,onChange:t=>e.set({region:t.target.value}),placeholder:`us-east-1`,maxLength:128,autoComplete:`off`,spellCheck:!1})}),(0,Y.jsx)(`div`,{className:`md:col-span-2`,children:(0,Y.jsx)(S,{label:`Bucket name`,children:(0,Y.jsx)(b,{name:`s3-bucket`,value:e.bucket,onChange:t=>e.set({bucket:t.target.value}),placeholder:`my-bunqueue-backups`,maxLength:255,autoComplete:`off`,spellCheck:!1})})}),(0,Y.jsx)(S,{label:`Access key ID`,children:(0,Y.jsx)(b,{name:`s3-access-key-id`,value:e.accessKeyId,onChange:t=>e.set({accessKeyId:t.target.value}),placeholder:`AKIA…`,maxLength:512,autoComplete:`off`,spellCheck:!1})}),(0,Y.jsx)(S,{label:`Secret access key`,children:(0,Y.jsx)(b,{name:`s3-secret-access-key`,type:`password`,value:e.secretAccessKey,onChange:t=>e.set({secretAccessKey:t.target.value}),placeholder:`••••••••••••••••`,maxLength:2048,autoComplete:`off`,spellCheck:!1})}),(0,Y.jsx)(`div`,{className:`md:col-span-2`,children:(0,Y.jsx)(S,{label:`Session token (optional, for temporary STS credentials)`,children:(0,Y.jsx)(b,{name:`s3-session-token`,type:`password`,value:e.sessionToken,onChange:t=>e.set({sessionToken:t.target.value}),placeholder:`Temporary AWS session token`,maxLength:4096,autoComplete:`off`,spellCheck:!1})})}),(0,Y.jsx)(`p`,{className:`-mt-2 text-xs text-faint md:col-span-2`,children:`Keys are kept in memory only and cleared on reload.`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(x,{htmlFor:`s3-backup-schedule`,children:`Backup interval`}),(0,Y.jsxs)(y,{id:`s3-backup-schedule`,name:`s3-backup-schedule`,value:e.schedule,onChange:t=>e.set({schedule:t.target.value}),className:`mt-1.5`,title:`Written to S3_BACKUP_ENABLED and S3_BACKUP_INTERVAL in the generated config`,autoComplete:`off`,children:[(0,Y.jsx)(`option`,{value:`disabled`,children:`Disabled`}),(0,Y.jsx)(`option`,{value:`6h`,children:`Every 6 hours`}),(0,Y.jsx)(`option`,{value:`12h`,children:`Every 12 hours`}),(0,Y.jsx)(`option`,{value:`24h`,children:`Every 24 hours`})]})]}),(0,Y.jsx)(S,{label:`Path prefix (optional)`,children:(0,Y.jsx)(b,{name:`s3-path-prefix`,value:e.pathPrefix,onChange:t=>e.set({pathPrefix:t.target.value}),placeholder:`backups/production/`,maxLength:1024,autoComplete:`off`,spellCheck:!1})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(x,{htmlFor:`s3-addressing-style`,children:`Addressing style`}),(0,Y.jsxs)(y,{id:`s3-addressing-style`,name:`s3-addressing-style`,value:e.virtualHostedStyle,onChange:t=>e.set({virtualHostedStyle:t.target.value}),className:`mt-1.5`,children:[(0,Y.jsx)(`option`,{value:`auto`,children:`Provider default`}),(0,Y.jsx)(`option`,{value:`virtual-hosted`,children:`Virtual-hosted style`}),(0,Y.jsx)(`option`,{value:`path-style`,children:`Path style`})]})]}),(0,Y.jsx)(S,{label:`Backups to retain`,children:(0,Y.jsx)(b,{name:`s3-retention`,type:`number`,min:1,max:1e6,step:1,value:t.text,onChange:e=>t.change(e.target.value),inputMode:`numeric`})})]}),(0,Y.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(p,{onClick:async()=>{let e=n,t=++c.current;i(null),s(e);try{let n=await h.storage();if(t!==c.current||Z(o.getState())!==e)return;let r=de(n);i({target:e,ok:!r.diskFull,msg:r.diskFull?`Server disk is full`:`Server disk healthy — this does not validate the S3 credentials`})}catch(n){if(t!==c.current||Z(o.getState())!==e)return;i({target:e,ok:!1,msg:n.message})}finally{t===c.current&&s(null)}},children:d?`Checking server storage…`:`Check server storage`}),(0,Y.jsx)(`span`,{className:`text-xs text-faint`,children:`This checks SQLite disk health only, not S3 connectivity.`}),u&&(0,Y.jsx)(`span`,{role:`status`,className:u.ok?`text-xs text-success`:`text-xs text-danger`,children:u.msg})]})]}),(0,Y.jsx)(he,{environment:l}),(0,Y.jsx)(ce,{environmentText:l.ok?l.value:void 0})]})}export{ge as S3BackupPro};
@@ -1,3 +1,3 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,t as n}from"./react-vendor-08inPAVO.js";import{C as r,T as i,b as a,x as o}from"./icons-BIT5aq1c.js";import{r as s}from"./StatusBadge-D-mexaga.js";import{C as c,E as l,I as u,O as d,S as f,b as p,d as m,f as h,g,i as _,m as v,o as y,v as b,x,y as S}from"./index-X_fHGbXZ.js";import{i as C,n as w,t as T}from"./form-DBkslwzu.js";import{t as E}from"./package-Bb3FkjoS.js";import{t as D}from"./useControlActionGuard-Bx5MkufG.js";var O=e(t(),1),k=n();function A({children:e}){return(0,k.jsx)(`code`,{className:`rounded bg-surface-2 px-1.5 py-0.5 text-xs text-fg`,children:e})}function j({agentBase:e}){return(0,k.jsx)(x,{children:(0,k.jsxs)(`details`,{className:`group`,children:[(0,k.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-2`,children:[(0,k.jsx)(`span`,{className:`text-base font-semibold text-fg`,children:`How server control works`}),(0,k.jsx)(`span`,{className:`text-xs text-muted transition-transform group-open:rotate-90`,children:`▶`})]}),(0,k.jsxs)(`div`,{className:`mt-4 space-y-4 text-sm leading-relaxed text-muted`,children:[(0,k.jsxs)(`p`,{children:[`A browser can't start or stop an OS process, so the dashboard talks to a small local`,` `,(0,k.jsx)(`span`,{className:`font-medium text-fg`,children:`control agent`}),` (`,(0,k.jsx)(A,{children:e}),`) that supervises the bunqueue server process — start, stop and restart — and streams its logs back here.`]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`Launch & environment`}),(0,k.jsxs)(`p`,{children:[`The agent runs your `,(0,k.jsx)(`span`,{className:`text-fg`,children:`Command`}),` and injects`,` `,(0,k.jsx)(A,{children:`HTTP_PORT`}),` and `,(0,k.jsx)(A,{children:`TCP_PORT`}),`, plus `,(0,k.jsx)(A,{children:`BUNQUEUE_DATA_PATH`}),` `,`only for SQLite. Memory and PostgreSQL modes remove every SQLite path alias before launch. Any `,(0,k.jsx)(`span`,{className:`text-fg`,children:`Environment variables`}),` you add are included too. The default`,` `,(0,k.jsx)(A,{children:`bunx bunqueue@${E.dependencies.bunqueue} start`}),` resolves the verified release; pointing the command at a local entry (e.g.`,` `,(0,k.jsx)(A,{children:`bun run /path/to/bunqueue/src/main.ts`}),`) works without one.`]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`When changes apply`}),(0,k.jsxs)(`p`,{children:[`Config is editable any time, but `,(0,k.jsx)(`span`,{className:`text-fg`,children:`Command`}),`, ports and data path only take effect on the `,(0,k.jsx)(`span`,{className:`text-fg`,children:`next start/restart`}),` `,`— the running process keeps the config it launched with until then.`]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`Data path`}),(0,k.jsxs)(`p`,{children:[`Relative paths resolve against the `,(0,k.jsx)(`span`,{className:`text-fg`,children:`agent's`}),` working directory. SQLite creates the database `,(0,k.jsx)(`span`,{className:`text-fg`,children:`file`}),` but not its parent `,(0,k.jsx)(`span`,{className:`text-fg`,children:`folder`}),` — if start fails with`,` `,(0,k.jsx)(A,{children:`SQLITE_CANTOPEN`}),`, create the directory first or use a path whose folder already exists.`]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`Security`}),(0,k.jsxs)(`p`,{children:[`The direct agent listener binds `,(0,k.jsx)(A,{children:`127.0.0.1`}),`, locks CORS to an allowlist (never `,(0,k.jsx)(A,{children:`*`}),`), and rejects a disallowed `,(0,k.jsx)(A,{children:`Origin`}),` or`,` `,(0,k.jsx)(A,{children:`Host`}),` with `,(0,k.jsx)(A,{children:`403`}),`. The all-in-one server's `,(0,k.jsx)(A,{children:`/agent`}),` `,`bridge treats LAN and reverse-proxy access as remote: `,(0,k.jsx)(A,{children:`AGENT_TOKEN`}),` is then mandatory for status, logs, database reads and changes alike. Without it, the bridge stays disabled.`]}),(0,k.jsxs)(`p`,{children:[`If you started the agent with `,(0,k.jsx)(A,{children:`AGENT_TOKEN`}),`, enter that token under`,` `,(0,k.jsx)(`span`,{className:`text-fg`,children:`Settings → Agent token`}),` (or when the lock screen prompts). It stays in memory for this browser session; never bake it into a public`,` `,(0,k.jsx)(A,{children:`VITE_*`}),` value.`]})]})]})]})})}function M(e,t,n,r){return{baseline:z(e),id:r,revision:t,scope:n,value:z(e)}}function N(e,t,n,r,i){return{accepted:z(e),acceptedRevision:t,before:n?z(n):null,beforeRevision:r,ignoreThroughRequestId:i}}function P(e,t,n,r){return R(t,e.accepted)?!1:r!==void 0&&e.ignoreThroughRequestId!==void 0?r<=e.ignoreThroughRequestId:n===void 0?e.before!==null&&R(t,e.before):n===e.beforeRevision||n===e.acceptedRevision}function ee(e){if(!V(e))return H();let{command:t,httpPort:n,tcpPort:r,dataPath:i,extraEnv:a}=e;if(typeof t!=`string`||t.trim()===``||!B(n)||!B(r)||n===r||typeof i!=`string`||!V(a)||Object.values(a).some(e=>typeof e!=`string`))return H();let o=F(e.configRevision);return e.configRevision!==void 0&&o===void 0?H():{config:{command:t,httpPort:n,tcpPort:r,dataPath:i,extraEnv:Object.fromEntries(Object.entries(a))},revision:o}}function F(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0?e:void 0}function I(e){return B(e.httpPort)?B(e.tcpPort)?e.httpPort===e.tcpPort?`HTTP and TCP ports must differ`:null:`TCP port must be an integer between 1 and 65535`:`HTTP port must be an integer between 1 and 65535`}function L(e,t){if(!e)return[];let n=[];return e.command!==t.command&&n.push(`command`),e.httpPort!==t.httpPort&&n.push(`HTTP port`),e.tcpPort!==t.tcpPort&&n.push(`TCP port`),e.dataPath!==t.dataPath&&n.push(`data path`),U(e.extraEnv)!==U(t.extraEnv)&&n.push(`environment variables`),n}function R(e,t){return JSON.stringify(W(e))===JSON.stringify(W(t))}function z(e){return{...e,extraEnv:{...e.extraEnv}}}function B(e){return typeof e==`number`&&Number.isInteger(e)&&e>=1&&e<=65535}function V(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function H(){throw Error(`Configuration save returned a malformed response`)}function U(e){return JSON.stringify(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)))}function W(e){return{...e,extraEnv:Object.fromEntries(Object.entries(e.extraEnv).sort(([e],[t])=>e.localeCompare(t)))}}var G=0,K=e=>Object.entries(e).map(([e,t])=>({id:G++,key:e,value:t})),q=e=>{let t={};for(let n of e){let e=n.key.trim();e&&(t[e]=n.value)}return t};function J(e){let t=e.map(e=>e.trim());return[...new Set(t.filter((e,t,n)=>e&&n.indexOf(e)!==t))]}var te=[`AUTH_TOKENS`,`LOG_LEVEL`,`BUNQUEUE_STORAGE_DRIVER`,`BUNQUEUE_POSTGRES_URL`,`BUNQUEUE_POSTGRES_NAMESPACE`,`BUNQUEUE_POSTGRES_POOL_SIZE`,`BUNQUEUE_MAX_COMPLETED_JOBS`,`BUNQUEUE_COMPLETED_RETENTION_MS`,`S3_BACKUP_ENABLED`,`S3_BUCKET`,`METRICS_ENABLED`];function ne({value:e,onChange:t,disabled:n}){let[r,i]=(0,O.useState)(()=>K(e)),a=e=>{i(e),t(q(e))},o=(e,t)=>a(r.map(n=>n.id===e?{...n,...t}:n)),s=(e=``)=>a([...r,{id:G++,key:e,value:``}]),l=e=>a(r.filter(t=>t.id!==e)),u=new Set(r.map(e=>e.key.trim()).filter(Boolean)),d=J(r.map(e=>e.key)),f=[...new Set(r.map(e=>e.key.trim()).filter(e=>e&&(/[\s=]/.test(e)||/[a-z]/.test(e))))];return(0,k.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.length===0&&(0,k.jsxs)(`p`,{className:`text-xs leading-relaxed text-faint`,children:[`No custom variables. The agent already injects`,` `,(0,k.jsx)(`code`,{className:`rounded bg-surface-2 px-1 py-0.5`,children:`HTTP_PORT`}),`,`,` `,(0,k.jsx)(`code`,{className:`rounded bg-surface-2 px-1 py-0.5`,children:`TCP_PORT`}),`, plus the SQLite data path unless PostgreSQL mode is selected.`]}),r.map(e=>(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`div`,{className:`w-2/5 shrink-0`,children:(0,k.jsx)(w,{id:`env-key-${e.id}`,name:`env-key-${e.id}`,"aria-label":`Variable name${e.key?` ${e.key}`:``}`,className:`font-mono`,placeholder:`KEY`,value:e.key,disabled:n,autoComplete:`off`,spellCheck:!1,onChange:t=>o(e.id,{key:t.target.value})})}),(0,k.jsx)(`span`,{className:`text-faint`,children:`=`}),(0,k.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,k.jsx)(w,{id:`env-value-${e.id}`,name:`env-value-${e.id}`,"aria-label":`Value for ${e.key||`variable`}`,className:`font-mono`,placeholder:`value`,value:e.value,disabled:n,autoComplete:`off`,spellCheck:!1,onChange:t=>o(e.id,{value:t.target.value})})}),(0,k.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.key||`variable`}`,disabled:n,onClick:()=>l(e.id),className:`shrink-0 rounded-md px-2 py-1 text-xs text-faint transition-colors hover:text-danger disabled:opacity-40`,children:`✕`})]},e.id)),d.length>0&&(0,k.jsxs)(`p`,{className:`text-xs text-warning`,children:[`Duplicate key`,d.length>1?`s`:``,` — the last value wins: `,d.join(`, `)]}),f.length>0&&(0,k.jsxs)(`p`,{className:`text-xs text-faint`,children:[`Unusual key`,f.length>1?`s`:``,` — env names are usually UPPER_SNAKE_CASE with no spaces or "=": `,f.join(`, `),`. Saved as-is.`]}),(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[(0,k.jsx)(c,{size:`sm`,variant:`ghost`,disabled:n,onClick:()=>s(),children:`+ Add variable`}),te.filter(e=>!u.has(e)).map(e=>(0,k.jsxs)(`button`,{type:`button`,disabled:n,onClick:()=>s(e),className:`rounded-md border border-line bg-surface-2 px-2 py-1 font-mono text-[11px] text-muted transition-colors hover:border-line-strong hover:text-fg disabled:opacity-40`,children:[`+ `,e]},e))]})]})}function re({status:e,onSaved:t,running:n,statusRequestId:i,getStatusRequestSequence:a,transitioning:o}){let s=D(`server-config`),l=(0,O.useRef)(0),d=(0,O.useRef)(null),p=(0,O.useRef)(null),[m,h]=(0,O.useState)(null),[g,_]=(0,O.useState)(!1),[v,y]=(0,O.useState)(!1),[b,S]=(0,O.useState)(null),[C,A]=(0,O.useState)(!1),[j,z]=(0,O.useState)(null);(0,O.useEffect)(()=>{d.current&&clearTimeout(d.current),d.current=null,p.current=null,h(null),_(!1),y(!1),S(null),A(!1),z(null)},[s.scopeKey]),(0,O.useEffect)(()=>{if(!e?.config||g)return;let t=p.current;t&&P(t,e.config,F(e.configRevision),i)||(p.current=null,h(M(e.config,F(e.configRevision),s.scopeKey,++l.current)),A(!1))},[s.scopeKey,g,e?.config,e?.configRevision,i]),(0,O.useEffect)(()=>()=>{d.current&&clearTimeout(d.current)},[]);let B=m?.scope===s.scopeKey?m:null,V=B?.value??e?.config??null;if(!V)return(0,k.jsx)(x,{children:`Loading…`});let H=t=>{let n=B??M(V,F(e?.configRevision),s.scopeKey,++l.current);h({...n,value:{...n.value,...t}}),_(!0),y(!1),A(!1)},U=L(e?.runningConfig??null,V),W=n&&U.length>0,G=o||b!==null,K=()=>{d.current&&clearTimeout(d.current),y(!0),d.current=setTimeout(()=>{d.current=null,y(!1)},2e3)},q=async n=>{let r=s.begin([`config`,`lifecycle`]);if(!r)return;let i=I(V);if(i)return r.finish(),z(i);let o=B?.baseline??e?.config,c=B?.revision??F(e?.configRevision);if(c===void 0&&o&&e?.config&&!R(o,e.config))return r.finish(),A(!0),z(`Configuration changed elsewhere; reload the latest values before saving.`);z(null),A(!1),S(n?`restart`:`save`);try{let i=await u.control.setConfig(V,c);if(!r.isCurrent())return;let{config:o,revision:d}=ee(i);if(p.current=N(o,d,e?.config??null,F(e?.configRevision),a?.()),h(M(o,d,s.scopeKey,++l.current)),_(!1),n&&await u.control.restart(),!r.isCurrent())return;K(),await t()}catch(e){if(!r.isCurrent())return;let t=e.message;t.startsWith(`Configuration changed since revision`)&&A(!0),z(t)}finally{r.finish()&&S(null)}},J=()=>q(!1);return(0,k.jsxs)(x,{children:[(0,k.jsx)(f,{title:`Configuration`}),(0,k.jsx)(`p`,{className:`mb-3 text-xs text-muted`,children:n?`Ports and data path apply on the next restart — edit freely, then restart.`:`Edit and save; the config is used the next time the server starts.`}),(0,k.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),J()},children:[(0,k.jsx)(T,{label:`Command`,hint:`The exact command the agent runs to launch bunqueue. It receives HTTP_PORT and TCP_PORT; BUNQUEUE_DATA_PATH is injected only for SQLite and removed in non-SQLite modes. The default resolves Bunqueue ${E.dependencies.bunqueue} with bunx; offline installs can point at a local entry.`,children:(0,k.jsx)(w,{name:`server-command`,autoComplete:`off`,spellCheck:!1,value:V.command,disabled:G,onChange:e=>H({command:e.target.value}),placeholder:`bunx bunqueue@${E.dependencies.bunqueue} start`})}),(0,k.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,k.jsx)(T,{label:`HTTP port`,hint:`Dashboard API + SSE.`,children:(0,k.jsx)(w,{name:`server-http-port`,autoComplete:`off`,type:`number`,min:1,max:65535,value:V.httpPort,disabled:G,onChange:e=>H({httpPort:Number(e.target.value)})})}),(0,k.jsx)(T,{label:`TCP port`,hint:`Binary protocol. Must differ from HTTP.`,children:(0,k.jsx)(w,{name:`server-tcp-port`,autoComplete:`off`,type:`number`,min:1,max:65535,value:V.tcpPort,disabled:G,onChange:e=>H({tcpPort:Number(e.target.value)})})})]}),(0,k.jsx)(T,{label:`Data path`,hint:`Durable SQLite path for the managed broker and Workflow Engine, relative to the agent's working directory. In PostgreSQL mode the agent keeps it for Workflow state but does not pass it to the broker.`,children:(0,k.jsx)(w,{name:`server-data-path`,autoComplete:`off`,spellCheck:!1,value:V.dataPath,disabled:G,onChange:e=>H({dataPath:e.target.value})})}),(0,k.jsx)(T,{label:`Environment variables`,hint:`Injected on start. Includes Bunqueue 2.9.3 completed-history controls: BUNQUEUE_MAX_COMPLETED_JOBS bounds hot memory, while BUNQUEUE_COMPLETED_RETENTION_MS opts into durable age-based expiry. Memory and PostgreSQL modes remove inherited SQLite path aliases. Applies on the next restart.`,children:(0,k.jsx)(ne,{value:V.extraEnv??{},onChange:e=>H({extraEnv:e}),disabled:G},B?.id??`initial`)}),(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,k.jsx)(c,{type:`submit`,variant:`accent`,size:`sm`,disabled:G,children:`Save config`}),n&&(0,k.jsxs)(c,{variant:`warning`,size:`sm`,disabled:G,onClick:()=>{let e=U.length>0?` Changed: ${U.join(`, `)}.`:``;if(window.confirm(`Save configuration and restart the server to apply it?${e}`))return q(!0)},children:[(0,k.jsx)(r,{className:`size-3.5`}),` Save & restart`]}),W&&!v&&(0,k.jsx)(`span`,{className:`text-xs text-warning`,children:`Restart to apply changes`}),v&&(0,k.jsx)(`span`,{className:`text-xs text-success`,children:`Saved`}),C&&(0,k.jsx)(c,{type:`button`,variant:`ghost`,size:`sm`,disabled:G,onClick:()=>{e?.config&&(p.current=null,h(M(e.config,F(e.configRevision),s.scopeKey,++l.current)),_(!1),A(!1),z(null))},children:`Reload latest`}),j&&(0,k.jsx)(`span`,{className:`text-xs text-danger`,children:j})]})]})]})}var ie=[`all`,`stdout`,`stderr`,`sys`],Y=e=>`${new Date(e).toLocaleTimeString([],{hour12:!1})}.${String(e%1e3).padStart(3,`0`)}`,ae=e=>e===`stderr`?`text-danger/90`:e===`sys`?`text-accent/80`:`text-muted`;function oe(e,t=Date.now()){let n=new Blob([e],{type:`text/plain`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`bunqueue-logs-${t}.log`;try{document.body.appendChild(i),i.click()}finally{i.remove(),setTimeout(()=>URL.revokeObjectURL(r),0)}}function se(){let{data:e,error:t,loading:n,refetch:r}=ce(),a=(0,O.useMemo)(()=>e?.lines??[],[e]),[o,c]=(0,O.useState)(`all`),[u,d]=(0,O.useState)(``),[f,m]=(0,O.useState)(!0),[h,g]=(0,O.useState)(!1),_=(0,O.useRef)(null),y=(0,O.useMemo)(()=>{let e=u.trim().toLowerCase();return a.map(e=>e.line.includes(`\x1B`)?{...e,line:v(e.line)}:e).filter(t=>(o===`all`||t.stream===o)&&(!e||t.line.toLowerCase().includes(e)))},[a,o,u]);(0,O.useEffect)(()=>{if(!f)return;let e=_.current;e&&(e.scrollTop=e.scrollHeight)},[y.length,f]);let w=(0,O.useMemo)(()=>y.map(e=>h?`${Y(e.ts)} [${e.stream}] ${e.line}`:e.line).join(`
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,t as n}from"./react-vendor-08inPAVO.js";import{C as r,T as i,b as a,x as o}from"./icons-BIT5aq1c.js";import{r as s}from"./StatusBadge-D-mexaga.js";import{C as c,E as l,I as u,O as d,S as f,b as p,d as m,f as h,g,i as _,m as v,o as y,v as b,x,y as S}from"./index-DwsYIYdu.js";import{i as C,n as w,t as T}from"./form-DBkslwzu.js";import{t as E}from"./package-D11d0FBn.js";import{t as D}from"./useControlActionGuard-Bx5MkufG.js";var O=e(t(),1),k=n();function A({children:e}){return(0,k.jsx)(`code`,{className:`rounded bg-surface-2 px-1.5 py-0.5 text-xs text-fg`,children:e})}function j({agentBase:e}){return(0,k.jsx)(x,{children:(0,k.jsxs)(`details`,{className:`group`,children:[(0,k.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-2`,children:[(0,k.jsx)(`span`,{className:`text-base font-semibold text-fg`,children:`How server control works`}),(0,k.jsx)(`span`,{className:`text-xs text-muted transition-transform group-open:rotate-90`,children:`▶`})]}),(0,k.jsxs)(`div`,{className:`mt-4 space-y-4 text-sm leading-relaxed text-muted`,children:[(0,k.jsxs)(`p`,{children:[`A browser can't start or stop an OS process, so the dashboard talks to a small local`,` `,(0,k.jsx)(`span`,{className:`font-medium text-fg`,children:`control agent`}),` (`,(0,k.jsx)(A,{children:e}),`) that supervises the bunqueue server process — start, stop and restart — and streams its logs back here.`]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`Launch & environment`}),(0,k.jsxs)(`p`,{children:[`The agent runs your `,(0,k.jsx)(`span`,{className:`text-fg`,children:`Command`}),` and injects`,` `,(0,k.jsx)(A,{children:`HTTP_PORT`}),` and `,(0,k.jsx)(A,{children:`TCP_PORT`}),`, plus `,(0,k.jsx)(A,{children:`BUNQUEUE_DATA_PATH`}),` `,`only for SQLite. Memory and PostgreSQL modes remove every SQLite path alias before launch. Any `,(0,k.jsx)(`span`,{className:`text-fg`,children:`Environment variables`}),` you add are included too. The default`,` `,(0,k.jsx)(A,{children:`bunx bunqueue@${E.dependencies.bunqueue} start`}),` resolves the verified release; pointing the command at a local entry (e.g.`,` `,(0,k.jsx)(A,{children:`bun run /path/to/bunqueue/src/main.ts`}),`) works without one.`]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`When changes apply`}),(0,k.jsxs)(`p`,{children:[`Config is editable any time, but `,(0,k.jsx)(`span`,{className:`text-fg`,children:`Command`}),`, ports and data path only take effect on the `,(0,k.jsx)(`span`,{className:`text-fg`,children:`next start/restart`}),` `,`— the running process keeps the config it launched with until then.`]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`Data path`}),(0,k.jsxs)(`p`,{children:[`Relative paths resolve against the `,(0,k.jsx)(`span`,{className:`text-fg`,children:`agent's`}),` working directory. SQLite creates the database `,(0,k.jsx)(`span`,{className:`text-fg`,children:`file`}),` but not its parent `,(0,k.jsx)(`span`,{className:`text-fg`,children:`folder`}),` — if start fails with`,` `,(0,k.jsx)(A,{children:`SQLITE_CANTOPEN`}),`, create the directory first or use a path whose folder already exists.`]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`Security`}),(0,k.jsxs)(`p`,{children:[`The direct agent listener binds `,(0,k.jsx)(A,{children:`127.0.0.1`}),`, locks CORS to an allowlist (never `,(0,k.jsx)(A,{children:`*`}),`), and rejects a disallowed `,(0,k.jsx)(A,{children:`Origin`}),` or`,` `,(0,k.jsx)(A,{children:`Host`}),` with `,(0,k.jsx)(A,{children:`403`}),`. The all-in-one server's `,(0,k.jsx)(A,{children:`/agent`}),` `,`bridge treats LAN and reverse-proxy access as remote: `,(0,k.jsx)(A,{children:`AGENT_TOKEN`}),` is then mandatory for status, logs, database reads and changes alike. Without it, the bridge stays disabled.`]}),(0,k.jsxs)(`p`,{children:[`If you started the agent with `,(0,k.jsx)(A,{children:`AGENT_TOKEN`}),`, enter that token under`,` `,(0,k.jsx)(`span`,{className:`text-fg`,children:`Settings → Agent token`}),` (or when the lock screen prompts). It stays in memory for this browser session; never bake it into a public`,` `,(0,k.jsx)(A,{children:`VITE_*`}),` value.`]})]})]})]})})}function M(e,t,n,r){return{baseline:z(e),id:r,revision:t,scope:n,value:z(e)}}function N(e,t,n,r,i){return{accepted:z(e),acceptedRevision:t,before:n?z(n):null,beforeRevision:r,ignoreThroughRequestId:i}}function P(e,t,n,r){return R(t,e.accepted)?!1:r!==void 0&&e.ignoreThroughRequestId!==void 0?r<=e.ignoreThroughRequestId:n===void 0?e.before!==null&&R(t,e.before):n===e.beforeRevision||n===e.acceptedRevision}function ee(e){if(!V(e))return H();let{command:t,httpPort:n,tcpPort:r,dataPath:i,extraEnv:a}=e;if(typeof t!=`string`||t.trim()===``||!B(n)||!B(r)||n===r||typeof i!=`string`||!V(a)||Object.values(a).some(e=>typeof e!=`string`))return H();let o=F(e.configRevision);return e.configRevision!==void 0&&o===void 0?H():{config:{command:t,httpPort:n,tcpPort:r,dataPath:i,extraEnv:Object.fromEntries(Object.entries(a))},revision:o}}function F(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0?e:void 0}function I(e){return B(e.httpPort)?B(e.tcpPort)?e.httpPort===e.tcpPort?`HTTP and TCP ports must differ`:null:`TCP port must be an integer between 1 and 65535`:`HTTP port must be an integer between 1 and 65535`}function L(e,t){if(!e)return[];let n=[];return e.command!==t.command&&n.push(`command`),e.httpPort!==t.httpPort&&n.push(`HTTP port`),e.tcpPort!==t.tcpPort&&n.push(`TCP port`),e.dataPath!==t.dataPath&&n.push(`data path`),U(e.extraEnv)!==U(t.extraEnv)&&n.push(`environment variables`),n}function R(e,t){return JSON.stringify(W(e))===JSON.stringify(W(t))}function z(e){return{...e,extraEnv:{...e.extraEnv}}}function B(e){return typeof e==`number`&&Number.isInteger(e)&&e>=1&&e<=65535}function V(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function H(){throw Error(`Configuration save returned a malformed response`)}function U(e){return JSON.stringify(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)))}function W(e){return{...e,extraEnv:Object.fromEntries(Object.entries(e.extraEnv).sort(([e],[t])=>e.localeCompare(t)))}}var G=0,K=e=>Object.entries(e).map(([e,t])=>({id:G++,key:e,value:t})),q=e=>{let t={};for(let n of e){let e=n.key.trim();e&&(t[e]=n.value)}return t};function J(e){let t=e.map(e=>e.trim());return[...new Set(t.filter((e,t,n)=>e&&n.indexOf(e)!==t))]}var te=[`AUTH_TOKENS`,`LOG_LEVEL`,`BUNQUEUE_STORAGE_DRIVER`,`BUNQUEUE_POSTGRES_URL`,`BUNQUEUE_POSTGRES_NAMESPACE`,`BUNQUEUE_POSTGRES_POOL_SIZE`,`BUNQUEUE_MAX_COMPLETED_JOBS`,`BUNQUEUE_COMPLETED_RETENTION_MS`,`S3_BACKUP_ENABLED`,`S3_BUCKET`,`METRICS_ENABLED`];function ne({value:e,onChange:t,disabled:n}){let[r,i]=(0,O.useState)(()=>K(e)),a=e=>{i(e),t(q(e))},o=(e,t)=>a(r.map(n=>n.id===e?{...n,...t}:n)),s=(e=``)=>a([...r,{id:G++,key:e,value:``}]),l=e=>a(r.filter(t=>t.id!==e)),u=new Set(r.map(e=>e.key.trim()).filter(Boolean)),d=J(r.map(e=>e.key)),f=[...new Set(r.map(e=>e.key.trim()).filter(e=>e&&(/[\s=]/.test(e)||/[a-z]/.test(e))))];return(0,k.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.length===0&&(0,k.jsxs)(`p`,{className:`text-xs leading-relaxed text-faint`,children:[`No custom variables. The agent already injects`,` `,(0,k.jsx)(`code`,{className:`rounded bg-surface-2 px-1 py-0.5`,children:`HTTP_PORT`}),`,`,` `,(0,k.jsx)(`code`,{className:`rounded bg-surface-2 px-1 py-0.5`,children:`TCP_PORT`}),`, plus the SQLite data path unless PostgreSQL mode is selected.`]}),r.map(e=>(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`div`,{className:`w-2/5 shrink-0`,children:(0,k.jsx)(w,{id:`env-key-${e.id}`,name:`env-key-${e.id}`,"aria-label":`Variable name${e.key?` ${e.key}`:``}`,className:`font-mono`,placeholder:`KEY`,value:e.key,disabled:n,autoComplete:`off`,spellCheck:!1,onChange:t=>o(e.id,{key:t.target.value})})}),(0,k.jsx)(`span`,{className:`text-faint`,children:`=`}),(0,k.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,k.jsx)(w,{id:`env-value-${e.id}`,name:`env-value-${e.id}`,"aria-label":`Value for ${e.key||`variable`}`,className:`font-mono`,placeholder:`value`,value:e.value,disabled:n,autoComplete:`off`,spellCheck:!1,onChange:t=>o(e.id,{value:t.target.value})})}),(0,k.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.key||`variable`}`,disabled:n,onClick:()=>l(e.id),className:`shrink-0 rounded-md px-2 py-1 text-xs text-faint transition-colors hover:text-danger disabled:opacity-40`,children:`✕`})]},e.id)),d.length>0&&(0,k.jsxs)(`p`,{className:`text-xs text-warning`,children:[`Duplicate key`,d.length>1?`s`:``,` — the last value wins: `,d.join(`, `)]}),f.length>0&&(0,k.jsxs)(`p`,{className:`text-xs text-faint`,children:[`Unusual key`,f.length>1?`s`:``,` — env names are usually UPPER_SNAKE_CASE with no spaces or "=": `,f.join(`, `),`. Saved as-is.`]}),(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[(0,k.jsx)(c,{size:`sm`,variant:`ghost`,disabled:n,onClick:()=>s(),children:`+ Add variable`}),te.filter(e=>!u.has(e)).map(e=>(0,k.jsxs)(`button`,{type:`button`,disabled:n,onClick:()=>s(e),className:`rounded-md border border-line bg-surface-2 px-2 py-1 font-mono text-[11px] text-muted transition-colors hover:border-line-strong hover:text-fg disabled:opacity-40`,children:[`+ `,e]},e))]})]})}function re({status:e,onSaved:t,running:n,statusRequestId:i,getStatusRequestSequence:a,transitioning:o}){let s=D(`server-config`),l=(0,O.useRef)(0),d=(0,O.useRef)(null),p=(0,O.useRef)(null),[m,h]=(0,O.useState)(null),[g,_]=(0,O.useState)(!1),[v,y]=(0,O.useState)(!1),[b,S]=(0,O.useState)(null),[C,A]=(0,O.useState)(!1),[j,z]=(0,O.useState)(null);(0,O.useEffect)(()=>{d.current&&clearTimeout(d.current),d.current=null,p.current=null,h(null),_(!1),y(!1),S(null),A(!1),z(null)},[s.scopeKey]),(0,O.useEffect)(()=>{if(!e?.config||g)return;let t=p.current;t&&P(t,e.config,F(e.configRevision),i)||(p.current=null,h(M(e.config,F(e.configRevision),s.scopeKey,++l.current)),A(!1))},[s.scopeKey,g,e?.config,e?.configRevision,i]),(0,O.useEffect)(()=>()=>{d.current&&clearTimeout(d.current)},[]);let B=m?.scope===s.scopeKey?m:null,V=B?.value??e?.config??null;if(!V)return(0,k.jsx)(x,{children:`Loading…`});let H=t=>{let n=B??M(V,F(e?.configRevision),s.scopeKey,++l.current);h({...n,value:{...n.value,...t}}),_(!0),y(!1),A(!1)},U=L(e?.runningConfig??null,V),W=n&&U.length>0,G=o||b!==null,K=()=>{d.current&&clearTimeout(d.current),y(!0),d.current=setTimeout(()=>{d.current=null,y(!1)},2e3)},q=async n=>{let r=s.begin([`config`,`lifecycle`]);if(!r)return;let i=I(V);if(i)return r.finish(),z(i);let o=B?.baseline??e?.config,c=B?.revision??F(e?.configRevision);if(c===void 0&&o&&e?.config&&!R(o,e.config))return r.finish(),A(!0),z(`Configuration changed elsewhere; reload the latest values before saving.`);z(null),A(!1),S(n?`restart`:`save`);try{let i=await u.control.setConfig(V,c);if(!r.isCurrent())return;let{config:o,revision:d}=ee(i);if(p.current=N(o,d,e?.config??null,F(e?.configRevision),a?.()),h(M(o,d,s.scopeKey,++l.current)),_(!1),n&&await u.control.restart(),!r.isCurrent())return;K(),await t()}catch(e){if(!r.isCurrent())return;let t=e.message;t.startsWith(`Configuration changed since revision`)&&A(!0),z(t)}finally{r.finish()&&S(null)}},J=()=>q(!1);return(0,k.jsxs)(x,{children:[(0,k.jsx)(f,{title:`Configuration`}),(0,k.jsx)(`p`,{className:`mb-3 text-xs text-muted`,children:n?`Ports and data path apply on the next restart — edit freely, then restart.`:`Edit and save; the config is used the next time the server starts.`}),(0,k.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),J()},children:[(0,k.jsx)(T,{label:`Command`,hint:`The exact command the agent runs to launch bunqueue. It receives HTTP_PORT and TCP_PORT; BUNQUEUE_DATA_PATH is injected only for SQLite and removed in non-SQLite modes. The default resolves Bunqueue ${E.dependencies.bunqueue} with bunx; offline installs can point at a local entry.`,children:(0,k.jsx)(w,{name:`server-command`,autoComplete:`off`,spellCheck:!1,value:V.command,disabled:G,onChange:e=>H({command:e.target.value}),placeholder:`bunx bunqueue@${E.dependencies.bunqueue} start`})}),(0,k.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,k.jsx)(T,{label:`HTTP port`,hint:`Dashboard API + SSE.`,children:(0,k.jsx)(w,{name:`server-http-port`,autoComplete:`off`,type:`number`,min:1,max:65535,value:V.httpPort,disabled:G,onChange:e=>H({httpPort:Number(e.target.value)})})}),(0,k.jsx)(T,{label:`TCP port`,hint:`Binary protocol. Must differ from HTTP.`,children:(0,k.jsx)(w,{name:`server-tcp-port`,autoComplete:`off`,type:`number`,min:1,max:65535,value:V.tcpPort,disabled:G,onChange:e=>H({tcpPort:Number(e.target.value)})})})]}),(0,k.jsx)(T,{label:`Data path`,hint:`Durable SQLite path for the managed broker and Workflow Engine, relative to the agent's working directory. In PostgreSQL mode the agent keeps it for Workflow state but does not pass it to the broker.`,children:(0,k.jsx)(w,{name:`server-data-path`,autoComplete:`off`,spellCheck:!1,value:V.dataPath,disabled:G,onChange:e=>H({dataPath:e.target.value})})}),(0,k.jsx)(T,{label:`Environment variables`,hint:`Injected on start. Includes Bunqueue 2.9.3 completed-history controls: BUNQUEUE_MAX_COMPLETED_JOBS bounds hot memory, while BUNQUEUE_COMPLETED_RETENTION_MS opts into durable age-based expiry. Memory and PostgreSQL modes remove inherited SQLite path aliases. Applies on the next restart.`,children:(0,k.jsx)(ne,{value:V.extraEnv??{},onChange:e=>H({extraEnv:e}),disabled:G},B?.id??`initial`)}),(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,k.jsx)(c,{type:`submit`,variant:`accent`,size:`sm`,disabled:G,children:`Save config`}),n&&(0,k.jsxs)(c,{variant:`warning`,size:`sm`,disabled:G,onClick:()=>{let e=U.length>0?` Changed: ${U.join(`, `)}.`:``;if(window.confirm(`Save configuration and restart the server to apply it?${e}`))return q(!0)},children:[(0,k.jsx)(r,{className:`size-3.5`}),` Save & restart`]}),W&&!v&&(0,k.jsx)(`span`,{className:`text-xs text-warning`,children:`Restart to apply changes`}),v&&(0,k.jsx)(`span`,{className:`text-xs text-success`,children:`Saved`}),C&&(0,k.jsx)(c,{type:`button`,variant:`ghost`,size:`sm`,disabled:G,onClick:()=>{e?.config&&(p.current=null,h(M(e.config,F(e.configRevision),s.scopeKey,++l.current)),_(!1),A(!1),z(null))},children:`Reload latest`}),j&&(0,k.jsx)(`span`,{className:`text-xs text-danger`,children:j})]})]})]})}var ie=[`all`,`stdout`,`stderr`,`sys`],Y=e=>`${new Date(e).toLocaleTimeString([],{hour12:!1})}.${String(e%1e3).padStart(3,`0`)}`,ae=e=>e===`stderr`?`text-danger/90`:e===`sys`?`text-accent/80`:`text-muted`;function oe(e,t=Date.now()){let n=new Blob([e],{type:`text/plain`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`bunqueue-logs-${t}.log`;try{document.body.appendChild(i),i.click()}finally{i.remove(),setTimeout(()=>URL.revokeObjectURL(r),0)}}function se(){let{data:e,error:t,loading:n,refetch:r}=ce(),a=(0,O.useMemo)(()=>e?.lines??[],[e]),[o,c]=(0,O.useState)(`all`),[u,d]=(0,O.useState)(``),[f,m]=(0,O.useState)(!0),[h,g]=(0,O.useState)(!1),_=(0,O.useRef)(null),y=(0,O.useMemo)(()=>{let e=u.trim().toLowerCase();return a.map(e=>e.line.includes(`\x1B`)?{...e,line:v(e.line)}:e).filter(t=>(o===`all`||t.stream===o)&&(!e||t.line.toLowerCase().includes(e)))},[a,o,u]);(0,O.useEffect)(()=>{if(!f)return;let e=_.current;e&&(e.scrollTop=e.scrollHeight)},[y.length,f]);let w=(0,O.useMemo)(()=>y.map(e=>h?`${Y(e.ts)} [${e.stream}] ${e.line}`:e.line).join(`
2
2
  `),[y,h]);return(0,k.jsxs)(x,{padded:!1,className:`overflow-hidden`,children:[(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-line px-4 py-3`,children:[(0,k.jsx)(`h3`,{className:`mr-1 text-base font-semibold text-fg`,children:`Process logs`}),(0,k.jsx)(C,{options:ie,value:o,onChange:c}),(0,k.jsxs)(`div`,{className:`relative min-w-40 flex-1`,children:[(0,k.jsx)(i,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-faint`}),(0,k.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),"aria-label":`Filter log lines`,name:`process-log-filter`,autoComplete:`off`,placeholder:`Filter…`,className:`h-8 w-full rounded-lg border border-line bg-surface-2 pl-8 pr-2 text-xs text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`})]}),(0,k.jsx)(X,{on:f,onClick:()=>m(e=>!e),label:`Follow`}),(0,k.jsx)(X,{on:h,onClick:()=>g(e=>!e),label:`Times`}),(0,k.jsx)(l,{value:w}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>{oe(w)},disabled:y.length===0,className:`rounded-md border border-line bg-surface-2 px-2 py-1 text-xs text-muted transition-colors hover:text-fg disabled:opacity-40`,children:`Download`})]}),t&&e&&(0,k.jsx)(`div`,{className:`border-b border-line px-4 pt-3 font-sans`,children:(0,k.jsx)(p,{message:`Process-log refresh failed — showing the last received lines. ${t.message}`,onRetry:r})}),(0,k.jsx)(`div`,{ref:_,className:`max-h-80 min-h-40 overflow-y-auto p-4 font-mono text-xs leading-relaxed`,children:n&&!e&&!t?(0,k.jsx)(`div`,{className:`font-sans`,children:(0,k.jsx)(S,{label:`Loading process logs…`})}):t&&!e?(0,k.jsx)(`div`,{className:`font-sans`,children:(0,k.jsx)(b,{error:t,onRetry:r})}):y.length===0?(0,k.jsx)(`p`,{className:`text-faint`,children:a.length===0?`No output yet.`:`No lines match the current filter.`}):y.map(e=>(0,k.jsxs)(`div`,{className:s(`whitespace-pre-wrap`,ae(e.stream)),children:[h&&(0,k.jsx)(`span`,{className:`mr-2 text-faint`,children:Y(e.ts)}),e.line]},e.seq))}),(0,k.jsxs)(`div`,{className:`flex items-center justify-between border-t border-line px-4 py-2 text-[11px] text-faint`,children:[(0,k.jsx)(`span`,{children:t&&!e?`logs unavailable`:y.length===a.length?`${a.length} lines`:`${y.length} of ${a.length} lines`}),(0,k.jsx)(`span`,{children:t?`refresh failed`:f?`following tail`:`paused`})]})]})}function X({on:e,onClick:t,label:n}){return(0,k.jsx)(`button`,{type:`button`,onClick:t,"aria-pressed":e,className:s(`rounded-md border px-2 py-1 text-xs transition-colors`,e?`border-accent/40 bg-accent/10 text-accent`:`border-line bg-surface-2 text-muted hover:text-fg`),children:n})}function ce(){return d(()=>u.control.logs(),[])}var Z={running:{label:`Running`,tone:`text-success`,dot:`bg-emerald-400`},starting:{label:`Starting`,tone:`text-warning`,dot:`bg-amber-400`},stopping:{label:`Stopping`,tone:`text-warning`,dot:`bg-amber-400`},stopped:{label:`Stopped`,tone:`text-danger`,dot:`bg-red-400`}};function le({startedAt:e}){let[,t]=(0,O.useState)(0);return(0,O.useEffect)(()=>{let e=setInterval(()=>t(e=>e+1),1e3);return()=>clearInterval(e)},[]),(0,k.jsx)(k.Fragment,{children:h((Date.now()-e)/1e3)})}function Q({label:e,children:t,title:n}){return(0,k.jsxs)(`div`,{className:`min-w-0`,title:n,children:[(0,k.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-faint`,children:e}),(0,k.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-sm text-fg`,children:t})]})}function ue({status:e,agentBase:t,transitioning:n,stale:i=!1,vitals:u=null,busy:d,onStart:f,onStop:p,onRestart:m}){let h=e?.status??`stopped`,g=e?.managementMode===`external`,_=g?e?.reachable===!0:h===`running`,v=g?e?.healthy?{label:`External`,tone:`text-success`,dot:`bg-emerald-400`}:e?.reachable?{label:`External`,tone:`text-warning`,dot:`bg-amber-400`}:{label:`External`,tone:`text-danger`,dot:`bg-red-400`}:Z[h]??Z.stopped,b=!!e?.healthy&&!i,x=!g&&!_&&e?.exitCode!=null&&e.exitCode!==0,S=e?.runningConfig??e?.config??null,C=S?.httpPort??6790,w=g?e?.externalUrl??`—`:`http://localhost:${C}`,T=w===`—`?`—`:`${w}/health`;return(0,k.jsxs)(`section`,{className:`mb-6 overflow-hidden rounded-xl border border-line bg-surface`,children:[(0,k.jsx)(`div`,{className:s(`h-0.5 bg-gradient-to-r to-transparent`,_&&b?`from-emerald-400/80 via-emerald-400/25`:_||n?`from-amber-400/80 via-amber-400/25`:`from-red-400/70 via-red-400/20`)}),(0,k.jsxs)(`div`,{className:`flex flex-col gap-5 p-5 lg:flex-row lg:items-center lg:justify-between`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,k.jsxs)(`span`,{className:`relative flex size-3.5 shrink-0`,children:[_&&b&&(0,k.jsx)(`span`,{className:`absolute inline-flex size-full rounded-full bg-emerald-400 opacity-50 motion-safe:animate-ping`}),(0,k.jsx)(`span`,{className:s(`relative inline-flex size-3.5 rounded-full`,v.dot)})]}),(0,k.jsxs)(`div`,{className:`min-w-0`,children:[(0,k.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3 gap-y-1`,children:[(0,k.jsx)(`span`,{className:s(`text-2xl font-bold tracking-tight`,v.tone),children:n&&d?`${d}…`:v.label}),e?.version&&(0,k.jsxs)(`span`,{className:`font-mono text-xs text-muted`,children:[`bunqueue v`,e.version]}),x&&(0,k.jsxs)(`span`,{className:`rounded-full bg-red-500/15 px-2 py-0.5 font-mono text-[11px] font-medium text-danger`,children:[`crashed · exit `,e?.exitCode]})]}),(0,k.jsx)(`div`,{className:`mt-1 font-mono text-xs text-muted`,children:i?(0,k.jsxs)(`span`,{className:`text-warning`,children:[`last known: pid `,e?.pid??`—`,` — agent unreachable, state may have changed`]}):g?(0,k.jsx)(`span`,{title:e?.healthError,children:e?.reachable?b?`healthy via ${T}`:`reachable but unhealthy via ${T}`:`unreachable via ${T}`}):_?(0,k.jsxs)(k.Fragment,{children:[b?`healthy`:`waiting for health…`,` · pid `,e?.pid??`—`,` · up`,` `,e?.startedAt?(0,k.jsx)(le,{startedAt:e.startedAt}):`—`]}):`process not running — start it below or point the dashboard at an external server`})]})]}),!g&&(0,k.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,k.jsxs)(c,{variant:`success`,disabled:_||n||i,onClick:f,children:[(0,k.jsx)(o,{className:`size-4`}),` Start`]}),(0,k.jsxs)(c,{variant:`warning`,disabled:!_||n||i,onClick:p,children:[(0,k.jsx)(a,{className:`size-4`}),` Stop`]}),(0,k.jsxs)(c,{disabled:n||i,onClick:m,children:[(0,k.jsx)(r,{className:`size-4`}),` Restart`]})]})]}),(0,k.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 border-t border-line bg-surface-2/30 px-5 py-4 md:grid-cols-3 xl:grid-cols-7`,children:[(0,k.jsx)(Q,{label:`Memory`,children:u?.memory?.rss==null?(0,k.jsx)(`span`,{className:`text-faint`,children:`—`}):(0,k.jsxs)(`span`,{title:`heap ${u.memory.heapUsed??`?`} / ${u.memory.heapTotal??`?`} MB`,children:[u.memory.rss,` MB rss`]})}),(0,k.jsx)(Q,{label:`Connections`,children:u?.connections?`${u.connections.tcp??0} tcp · ${u.connections.ws??0} ws · ${u.connections.sse??0} sse`:(0,k.jsx)(`span`,{className:`text-faint`,children:`—`})}),(0,k.jsx)(Q,{label:g?`Health target`:`API endpoint`,title:T,children:w===`—`?(0,k.jsx)(`span`,{className:`text-faint`,children:w}):(0,k.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,k.jsx)(`a`,{href:T,target:`_blank`,rel:`noreferrer`,className:`truncate text-accent hover:underline`,children:w}),(0,k.jsx)(l,{value:w})]})}),(0,k.jsx)(Q,{label:g?`Lifecycle`:`Ports`,children:g?`external`:S?`${S.httpPort} http · ${S.tcpPort} tcp`:`—`}),(0,k.jsx)(Q,{label:g?`Health HTTP`:`Started`,children:g?e?.healthStatus??`—`:_&&e?.startedAt?y(e.startedAt):`—`}),(0,k.jsx)(Q,{label:`Control agent`,title:t,children:t.replace(/^https?:\/\//,``)}),(0,k.jsx)(Q,{label:g?`Supervisor`:`Storage`,title:e?.storageMode===`postgres`?`PostgreSQL ${e.postgresTarget??`configured`} · namespace ${e.postgresNamespace??`default`}`:e?.storageMode,children:g?`managed elsewhere`:e?.storageMode===`postgres`?`postgres · ${e.postgresNamespace??`default`}`:e?.storageMode??`—`})]})]})}var $=[{key:`size`,label:`Database`,color:`bg-accent`},{key:`walSize`,label:`WAL`,color:`bg-amber-400`},{key:`shmSize`,label:`SHM`,color:`bg-zinc-500`}];function de({db:e}){let t=e.totalSize||0;return(0,k.jsxs)(x,{children:[(0,k.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2`,children:[(0,k.jsx)(`h3`,{className:`text-base font-semibold text-fg`,children:`Storage`}),(0,k.jsx)(`span`,{className:`font-mono text-xs text-muted`,children:e.exists?`${_(t)} on disk`:`not created yet`})]}),(0,k.jsxs)(`p`,{className:`mb-4 flex items-center gap-1.5 truncate font-mono text-xs text-faint`,title:e.path,children:[(0,k.jsx)(`span`,{className:`truncate`,children:e.path}),(0,k.jsx)(l,{value:e.path})]}),e.exists&&t>0?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`flex h-2.5 overflow-hidden rounded-full bg-surface-2`,children:$.map(n=>{let r=e[n.key];return r?(0,k.jsx)(`div`,{className:s(`h-full`,n.color),style:{width:`${r/t*100}%`},title:`${n.label}: ${_(r)}`},n.key):null})}),(0,k.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-5 gap-y-1.5 font-mono text-[11px] text-faint`,children:[$.map(t=>(0,k.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,k.jsx)(`span`,{className:s(`size-2 rounded-full`,t.color)}),t.label,` `,(0,k.jsx)(`span`,{className:`text-fg`,children:_(e[t.key])})]},t.key)),e.mtimeMs?(0,k.jsxs)(`span`,{className:`ml-auto`,children:[`written `,m(e.mtimeMs)]}):null]})]}):(0,k.jsx)(`p`,{className:`rounded-lg border border-dashed border-line px-4 py-6 text-center text-sm text-faint`,children:`The database appears here after the first start — SQLite creates the file at the configured data path.`})]})}function fe(){let e=(0,O.useRef)(0),t=(0,O.useRef)(new WeakMap),{data:n,error:r,refetch:i}=d(async()=>{let n=++e.current,r=await u.control.status();return t.current.set(r,n),r},[]),a=D(`server-lifecycle`),[o,s]=(0,O.useState)(null),[c,l]=(0,O.useState)(null);(0,O.useEffect)(()=>{s(null),l(null)},[a.scopeKey]);let m=n?.managementMode===`external`,h=m?n?.reachable===!0:n?.status===`running`,{data:_}=d(()=>h?u.health():Promise.resolve(null),[h]),v=h?_??null:null,y=v?.connections?` This drops ${v.connections.tcp??0} TCP / ${v.connections.ws??0} WS connections; in-flight jobs are interrupted.`:` In-flight jobs are interrupted.`,b=async(e,t,n)=>{let r=a.begin(`lifecycle`);if(r){if(n&&!window.confirm(n))r.finish();else if(!r.isCurrent())r.finish();else{s(e),l(null);try{if(await t(),!r.isCurrent())return;await i()}catch(e){if(!r.isCurrent())return;l(e.message)}finally{r.finish()&&s(null)}}}};if(r&&!n)return(0,k.jsxs)(`div`,{children:[(0,k.jsx)(g,{title:`Server`,description:`Start, stop and restart the bunqueue server.`}),(0,k.jsx)(p,{message:`Control agent unreachable — server lifecycle controls are unavailable.`,onRetry:i}),(0,k.jsxs)(x,{children:[(0,k.jsx)(f,{title:`Control agent not running`}),(0,k.jsxs)(`p`,{className:`text-sm text-muted`,children:[`The local control agent is unreachable at`,` `,(0,k.jsx)(`code`,{className:`rounded bg-surface-2 px-1.5 py-0.5 text-xs`,children:u.agentBase}),`. It manages the bunqueue server process (start / stop / restart). Start it with:`]}),(0,k.jsxs)(`pre`,{className:`mt-3 overflow-x-auto rounded-lg border border-line bg-surface-2 px-3 py-2 text-xs`,children:[`bun start`,` `,`# agent + dashboard together (recommended)`,`
3
3
  `,`bun run agent`,` `,`# agent only, if the dashboard is already running`]}),(0,k.jsx)(`p`,{className:`mt-3 text-xs text-faint`,children:`This page reconnects automatically once the agent is up — no reload needed.`})]})]});let S=n?.status??`stopped`,C=S===`running`,w=S===`starting`||S===`stopping`||o!=null,T=r!=null&&n!=null;return(0,k.jsxs)(`div`,{children:[(0,k.jsx)(g,{title:`Server`,description:m?`Observe the Bunqueue server managed by an external supervisor.`:`Supervise the bunqueue server process — lifecycle, configuration, storage and logs.`}),c&&(0,k.jsx)(`div`,{role:`status`,className:`mb-4 rounded-lg border border-red-500/20 bg-red-500/5 px-4 py-2 text-sm text-danger`,children:c}),T&&(0,k.jsx)(`div`,{className:`mb-4 rounded-lg border border-amber-500/20 bg-amber-500/5 px-4 py-2 text-sm text-warning`,children:`Control agent unreachable — showing last known state. Lifecycle actions are disabled until it responds again.`}),(0,k.jsx)(ue,{status:n,agentBase:u.agentBase,stale:T,vitals:v,transitioning:w,busy:o,onStart:()=>b(`starting`,()=>u.control.start()),onStop:()=>b(`stopping`,()=>u.control.stop(),`Stop the bunqueue server?${y}`),onRestart:()=>b(`restarting`,()=>u.control.restart(),`Restart the bunqueue server?${y}`)}),m?(0,k.jsxs)(x,{children:[(0,k.jsx)(f,{title:`Managed externally`}),(0,k.jsxs)(`p`,{className:`text-sm text-muted`,children:[`This dashboard is attached to`,` `,(0,k.jsx)(`code`,{className:`rounded bg-surface-2 px-1.5 py-0.5 text-xs`,children:n?.externalUrl??`BUNQUEUE_URL`}),`. Start, stop, restart and launch configuration are intentionally unavailable while`,` `,(0,k.jsx)(`code`,{className:`rounded bg-surface-2 px-1.5 py-0.5 text-xs`,children:`BUNQUEUE_MANAGED=0`}),`. Use systemd, Docker, Kubernetes or the broker's external supervisor instead.`]})]}):(0,k.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,k.jsx)(re,{status:n,onSaved:i,running:C,statusRequestId:n?t.current.get(n):void 0,getStatusRequestSequence:()=>e.current,transitioning:w}),(0,k.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[n?.db&&(0,k.jsx)(de,{db:n.db}),(0,k.jsx)(se,{})]})]}),(0,k.jsx)(`div`,{className:`mt-6`,children:(0,k.jsx)(j,{agentBase:u.agentBase})})]})}export{fe as ServerControl};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,t as n}from"./react-vendor-08inPAVO.js";import{c as r,o as i,s as a}from"./connectionStore-B946Fhuv.js";import{f as o}from"./icons-BIT5aq1c.js";import{C as s,S as c,g as l,k as u,w as d,x as f}from"./index-X_fHGbXZ.js";import{a as p,n as m,t as h}from"./form-DBkslwzu.js";var g=n(),_=[[`1000`,`1 second`],[`2000`,`2 seconds`],[`3000`,`3 seconds`],[`5000`,`5 seconds`],[`10000`,`10 seconds`]];function v(){let{refreshMs:e,setRefreshMs:t}=i(),{theme:n,setTheme:r}=u();return(0,g.jsxs)(f,{children:[(0,g.jsx)(c,{title:`Appearance & refresh`}),(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,g.jsx)(h,{label:`Theme`,children:(0,g.jsxs)(p,{name:`theme`,autoComplete:`off`,value:n,onChange:e=>r(e.target.value),children:[(0,g.jsx)(`option`,{value:`dark`,children:`Dark`}),(0,g.jsx)(`option`,{value:`light`,children:`Light`})]})}),(0,g.jsx)(h,{label:`Refresh interval`,children:(0,g.jsx)(p,{name:`refresh-interval`,autoComplete:`off`,value:String(e),onChange:e=>t(Number(e.target.value)),children:_.map(([e,t])=>(0,g.jsx)(`option`,{value:e,children:t},e))})})]})]})}var y=e(t(),1),b=1e4,x=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u;async function S(e,t={},n=b){let r=new AbortController,i=t.signal,a=i?AbortSignal.any([i,r.signal]):r.signal,o=Error(`Connection test timed out after ${Math.ceil(n/1e3)} seconds.`),s,c,l=new Promise((e,t)=>{s=setTimeout(()=>{r.abort(o),t(o)},n)}),u=i?new Promise((e,t)=>{let n=()=>{t(i.reason??new DOMException(`Connection test aborted`,`AbortError`))};i.aborted?n():(i.addEventListener(`abort`,n,{once:!0}),c=()=>i.removeEventListener(`abort`,n))}):null;try{let n=(async()=>{let n=await fetch(e,{...t,signal:a});return{response:n,value:await n.json()}})();return await Promise.race(u?[n,l,u]:[n,l])}catch(e){throw r.signal.aborted&&r.signal.reason===o?o:e}finally{s!==void 0&&clearTimeout(s),c?.()}}async function C(e,t={},n=b){let{response:r,value:i}=await S(e,t,n);if(!r.ok&&r.status!==503)throw Error(`HTTP ${r.status}`);if(typeof i!=`object`||!i||Array.isArray(i))throw Error(`Malformed health response`);let a=i;if(typeof a.ok!=`boolean`||a.status!==`healthy`&&a.status!==`degraded`||!Number.isSafeInteger(a.uptime)||a.uptime<0||typeof a.version!=`string`||!x.test(a.version)||a.ok!==(a.status===`healthy`))throw Error(`Malformed health response`);return{response:r,health:a}}function w(){let e=i(),[t,n]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null),[x,w]=(0,y.useState)(null),[T,E]=(0,y.useState)(null),D=(0,y.useRef)(!0),O=(0,y.useRef)(0),k=(0,y.useRef)(null),A=(0,y.useRef)(null),j=(0,y.useCallback)(()=>{A.current!==null&&clearTimeout(A.current),A.current=null,D.current&&E(null)},[]),M=(0,y.useCallback)(()=>{O.current+=1,k.current?.abort(new DOMException(`Connection test superseded`,`AbortError`)),k.current=null,D.current&&(h(null),_(null))},[]),N=(0,y.useCallback)(()=>{M(),j()},[j,M]);(0,y.useEffect)(()=>(D.current=!0,()=>{D.current=!1,O.current+=1,k.current?.abort(new DOMException(`Settings unmounted`,`AbortError`)),A.current!==null&&clearTimeout(A.current)}),[]),(0,y.useEffect)(()=>{let t=e.profiles.find(t=>t.id===e.activeProfileId);n(t?.name??`Bunqueue`),s(e.baseUrl),l(e.agentBaseUrl),d(e.token),p(e.agentToken),b(null),w(null),M()},[e.activeProfileId,e.agentBaseUrl,e.baseUrl,e.profiles,e.token,e.agentToken,M]);let P=()=>{let e=i.getState();return JSON.stringify([e.activeProfileId,e.baseUrl,e.agentBaseUrl,e.token,e.agentToken])},F=async e=>{M();let t=r(e===`server`?o:c);if(!t){e===`server`?b(a):w(a),_({ok:!1,msg:a});return}e===`server`?b(null):w(null);let n=O.current,i=new AbortController,s=P(),l=()=>D.current&&n===O.current&&!i.signal.aborted&&P()===s;k.current=i,h(e),_(null);let d=performance.now();try{if(e===`server`){let{response:e,health:n}=await C(`${t}/health`,{headers:u.trim()?{Authorization:`Bearer ${u.trim()}`}:void 0,signal:i.signal});if(!l())return;let r=e.status===503||n.status===`degraded`;_({ok:!r,msg:`${r?`Server reachable`:`Connected`} in ${Math.round(performance.now()-d)}ms · bunqueue v${n.version}${r?` · degraded`:``}`})}else{let{response:e,value:n}=await S(`${t}/control/status`,{headers:f.trim()?{Authorization:`Bearer ${f.trim()}`}:void 0,signal:i.signal});if(!e.ok)throw Error(`HTTP ${e.status}`);if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`Malformed control agent response`);let r=n;if(![`running`,`stopped`,`starting`,`stopping`].includes(String(r.status)))throw Error(`Malformed control agent response`);if(!l())return;_({ok:!0,msg:`Agent connected in ${Math.round(performance.now()-d)}ms · server ${r.status}${r.storageMode?` · ${r.storageMode}`:``}`})}}catch(e){l()&&_({ok:!1,msg:e.message})}finally{D.current&&n===O.current&&(k.current=null,h(null))}},I=()=>{M();let n=r(o),i=r(c);if(b(n?null:a),w(i?null:a),!n||!i)return;let s=e.saveConnection({name:t,baseUrl:n,agentBaseUrl:i,token:u,agentToken:f});j(),E({ok:s.persisted,msg:s.persisted?`Saved ✓`:`Saved for this session only — browser storage unavailable${s.error?`: ${s.error}`:`.`}`}),A.current=setTimeout(()=>D.current&&E(null),4e3)},L=()=>{N(),e.addProfile({name:`Bunqueue ${e.profiles.length+1}`,baseUrl:`http://localhost:6790`,agentBaseUrl:`http://localhost:6800`,token:``,agentToken:``})},R=()=>{let t=e.profiles.find(t=>t.id===e.activeProfileId);t&&window.confirm(`Remove connection profile "${t.name}"?`)&&e.removeProfile(t.id)};return{...e,name:t,setName:n,url:o,setUrl:s,agentUrl:c,setAgentUrl:l,tok:u,setTok:d,agentTok:f,setAgentTok:p,testing:m,result:g,urlError:v,agentUrlError:x,saveNotice:T,edit:N,save:I,add:L,remove:R,testServer:()=>F(`server`),testAgent:()=>F(`agent`)}}function T({id:e,label:t,hint:n,value:r,placeholder:i,onChange:a}){let[s,c]=(0,y.useState)(!1);return(0,g.jsx)(h,{label:t,hint:n,htmlFor:e,children:(0,g.jsxs)(`div`,{className:`relative`,children:[(0,g.jsx)(m,{id:e,name:e,type:s?`text`:`password`,value:r,onChange:e=>a(e.target.value),placeholder:i,className:`pr-10`,autoComplete:`off`,spellCheck:!1}),(0,g.jsx)(d,{"aria-label":s?`Hide ${t.toLowerCase()}`:`Show ${t.toLowerCase()}`,className:`absolute right-0.5 top-1/2 -translate-y-1/2`,onClick:()=>c(e=>!e),children:(0,g.jsx)(o,{className:`size-4`})})]})})}function E(){let e=w(),t=t=>n=>{e.edit(),t(n)};return(0,g.jsxs)(f,{children:[(0,g.jsx)(c,{title:`Bunqueue fleet connections`}),(0,g.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,g.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-[1fr_auto_auto]`,children:[(0,g.jsx)(h,{label:`Active node`,children:(0,g.jsx)(p,{"aria-label":`Active Bunqueue node`,value:e.activeProfileId,onChange:t=>e.activateProfile(t.target.value),children:e.profiles.map(e=>(0,g.jsx)(`option`,{value:e.id,children:e.name},e.id))})}),(0,g.jsx)(s,{className:`self-end`,onClick:e.add,children:`Add node`}),(0,g.jsx)(s,{className:`self-end`,variant:`danger`,disabled:e.profiles.length===1,onClick:e.remove,children:`Remove`})]}),(0,g.jsx)(h,{label:`Node name`,children:(0,g.jsx)(m,{name:`profile-name`,value:e.name,onChange:n=>t(e.setName)(n.target.value),maxLength:64,autoComplete:`off`,placeholder:`broker-eu-1`})}),(0,g.jsx)(h,{label:`Server URL`,children:(0,g.jsx)(m,{name:`server-url`,value:e.url,onChange:n=>{t(e.setUrl)(n.target.value)},placeholder:`/api or https://queue.example.com`,autoComplete:`off`,inputMode:`url`,"aria-invalid":e.urlError?!0:void 0,"aria-describedby":e.urlError?`server-url-error`:`server-url-help`})}),e.urlError?(0,g.jsx)(`p`,{id:`server-url-error`,className:`-mt-2 text-xs text-danger`,children:e.urlError}):(0,g.jsx)(`p`,{id:`server-url-help`,className:`-mt-2 text-xs text-faint`,children:`Bunqueue HTTP API for this broker. All queue pages use the selected node.`}),(0,g.jsx)(h,{label:`Control agent URL`,children:(0,g.jsx)(m,{name:`agent-url`,value:e.agentUrl,onChange:n=>t(e.setAgentUrl)(n.target.value),placeholder:`/agent or https://broker.example.com/agent`,autoComplete:`off`,inputMode:`url`,"aria-invalid":e.agentUrlError?!0:void 0,"aria-describedby":e.agentUrlError?`agent-url-error`:`agent-url-help`})}),e.agentUrlError?(0,g.jsx)(`p`,{id:`agent-url-error`,className:`-mt-2 text-xs text-danger`,children:e.agentUrlError}):(0,g.jsx)(`p`,{id:`agent-url-help`,className:`-mt-2 text-xs text-faint`,children:`One paired agent per broker enables lifecycle, configuration, Flow, Workflow and advanced queue controls.`}),(0,g.jsx)(T,{id:`bearer-token`,label:`Bearer token (optional)`,hint:`Server credential, kept in memory only and isolated to this node.`,value:e.tok,onChange:t(e.setTok),placeholder:`only if AUTH_TOKENS is set`}),(0,g.jsx)(T,{id:`agent-token`,label:`Agent token (optional)`,hint:`AGENT_TOKEN for this node, kept in memory only.`,value:e.agentTok,onChange:t(e.setAgentTok),placeholder:`only if AGENT_TOKEN is set`}),(0,g.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,g.jsx)(s,{variant:`accent`,onClick:e.save,children:`Save`}),(0,g.jsx)(s,{onClick:e.testServer,children:e.testing===`server`?`Restart test`:`Test connection`}),(0,g.jsx)(s,{onClick:e.testAgent,children:e.testing===`agent`?`Restart agent test`:`Test agent`}),e.saveNotice&&(0,g.jsx)(`span`,{role:`status`,className:e.saveNotice.ok?`text-sm text-success`:`text-sm text-warning`,children:e.saveNotice.msg}),e.result&&(0,g.jsx)(`span`,{role:`status`,className:e.result.ok?`text-sm text-success`:`text-sm text-danger`,children:e.result.msg})]}),(0,g.jsx)(`p`,{className:`-mt-1 text-xs text-faint`,children:`Switching the active node retargets every Dashboard feature atomically. Profile metadata persists; both credentials are erased on reload.`})]})]})}function D(){return(0,g.jsxs)(`div`,{children:[(0,g.jsx)(l,{title:`Settings`,description:`Bunqueue fleet connections, credentials and appearance.`}),(0,g.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,g.jsx)(E,{}),(0,g.jsx)(v,{})]})]})}export{D as Settings};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,t as n}from"./react-vendor-08inPAVO.js";import{c as r,o as i,s as a}from"./connectionStore-B946Fhuv.js";import{f as o}from"./icons-BIT5aq1c.js";import{C as s,S as c,g as l,k as u,w as d,x as f}from"./index-DwsYIYdu.js";import{a as p,n as m,t as h}from"./form-DBkslwzu.js";var g=n(),_=[[`1000`,`1 second`],[`2000`,`2 seconds`],[`3000`,`3 seconds`],[`5000`,`5 seconds`],[`10000`,`10 seconds`]];function v(){let{refreshMs:e,setRefreshMs:t}=i(),{theme:n,setTheme:r}=u();return(0,g.jsxs)(f,{children:[(0,g.jsx)(c,{title:`Appearance & refresh`}),(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,g.jsx)(h,{label:`Theme`,children:(0,g.jsxs)(p,{name:`theme`,autoComplete:`off`,value:n,onChange:e=>r(e.target.value),children:[(0,g.jsx)(`option`,{value:`dark`,children:`Dark`}),(0,g.jsx)(`option`,{value:`light`,children:`Light`})]})}),(0,g.jsx)(h,{label:`Refresh interval`,children:(0,g.jsx)(p,{name:`refresh-interval`,autoComplete:`off`,value:String(e),onChange:e=>t(Number(e.target.value)),children:_.map(([e,t])=>(0,g.jsx)(`option`,{value:e,children:t},e))})})]})]})}var y=e(t(),1),b=1e4,x=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u;async function S(e,t={},n=b){let r=new AbortController,i=t.signal,a=i?AbortSignal.any([i,r.signal]):r.signal,o=Error(`Connection test timed out after ${Math.ceil(n/1e3)} seconds.`),s,c,l=new Promise((e,t)=>{s=setTimeout(()=>{r.abort(o),t(o)},n)}),u=i?new Promise((e,t)=>{let n=()=>{t(i.reason??new DOMException(`Connection test aborted`,`AbortError`))};i.aborted?n():(i.addEventListener(`abort`,n,{once:!0}),c=()=>i.removeEventListener(`abort`,n))}):null;try{let n=(async()=>{let n=await fetch(e,{...t,signal:a});return{response:n,value:await n.json()}})();return await Promise.race(u?[n,l,u]:[n,l])}catch(e){throw r.signal.aborted&&r.signal.reason===o?o:e}finally{s!==void 0&&clearTimeout(s),c?.()}}async function C(e,t={},n=b){let{response:r,value:i}=await S(e,t,n);if(!r.ok&&r.status!==503)throw Error(`HTTP ${r.status}`);if(typeof i!=`object`||!i||Array.isArray(i))throw Error(`Malformed health response`);let a=i;if(typeof a.ok!=`boolean`||a.status!==`healthy`&&a.status!==`degraded`||!Number.isSafeInteger(a.uptime)||a.uptime<0||typeof a.version!=`string`||!x.test(a.version)||a.ok!==(a.status===`healthy`))throw Error(`Malformed health response`);return{response:r,health:a}}function w(){let e=i(),[t,n]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null),[x,w]=(0,y.useState)(null),[T,E]=(0,y.useState)(null),D=(0,y.useRef)(!0),O=(0,y.useRef)(0),k=(0,y.useRef)(null),A=(0,y.useRef)(null),j=(0,y.useCallback)(()=>{A.current!==null&&clearTimeout(A.current),A.current=null,D.current&&E(null)},[]),M=(0,y.useCallback)(()=>{O.current+=1,k.current?.abort(new DOMException(`Connection test superseded`,`AbortError`)),k.current=null,D.current&&(h(null),_(null))},[]),N=(0,y.useCallback)(()=>{M(),j()},[j,M]);(0,y.useEffect)(()=>(D.current=!0,()=>{D.current=!1,O.current+=1,k.current?.abort(new DOMException(`Settings unmounted`,`AbortError`)),A.current!==null&&clearTimeout(A.current)}),[]),(0,y.useEffect)(()=>{let t=e.profiles.find(t=>t.id===e.activeProfileId);n(t?.name??`Bunqueue`),s(e.baseUrl),l(e.agentBaseUrl),d(e.token),p(e.agentToken),b(null),w(null),M()},[e.activeProfileId,e.agentBaseUrl,e.baseUrl,e.profiles,e.token,e.agentToken,M]);let P=()=>{let e=i.getState();return JSON.stringify([e.activeProfileId,e.baseUrl,e.agentBaseUrl,e.token,e.agentToken])},F=async e=>{M();let t=r(e===`server`?o:c);if(!t){e===`server`?b(a):w(a),_({ok:!1,msg:a});return}e===`server`?b(null):w(null);let n=O.current,i=new AbortController,s=P(),l=()=>D.current&&n===O.current&&!i.signal.aborted&&P()===s;k.current=i,h(e),_(null);let d=performance.now();try{if(e===`server`){let{response:e,health:n}=await C(`${t}/health`,{headers:u.trim()?{Authorization:`Bearer ${u.trim()}`}:void 0,signal:i.signal});if(!l())return;let r=e.status===503||n.status===`degraded`;_({ok:!r,msg:`${r?`Server reachable`:`Connected`} in ${Math.round(performance.now()-d)}ms · bunqueue v${n.version}${r?` · degraded`:``}`})}else{let{response:e,value:n}=await S(`${t}/control/status`,{headers:f.trim()?{Authorization:`Bearer ${f.trim()}`}:void 0,signal:i.signal});if(!e.ok)throw Error(`HTTP ${e.status}`);if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`Malformed control agent response`);let r=n;if(![`running`,`stopped`,`starting`,`stopping`].includes(String(r.status)))throw Error(`Malformed control agent response`);if(!l())return;_({ok:!0,msg:`Agent connected in ${Math.round(performance.now()-d)}ms · server ${r.status}${r.storageMode?` · ${r.storageMode}`:``}`})}}catch(e){l()&&_({ok:!1,msg:e.message})}finally{D.current&&n===O.current&&(k.current=null,h(null))}},I=()=>{M();let n=r(o),i=r(c);if(b(n?null:a),w(i?null:a),!n||!i)return;let s=e.saveConnection({name:t,baseUrl:n,agentBaseUrl:i,token:u,agentToken:f});j(),E({ok:s.persisted,msg:s.persisted?`Saved ✓`:`Saved for this session only — browser storage unavailable${s.error?`: ${s.error}`:`.`}`}),A.current=setTimeout(()=>D.current&&E(null),4e3)},L=()=>{N(),e.addProfile({name:`Bunqueue ${e.profiles.length+1}`,baseUrl:`http://localhost:6790`,agentBaseUrl:`http://localhost:6800`,token:``,agentToken:``})},R=()=>{let t=e.profiles.find(t=>t.id===e.activeProfileId);t&&window.confirm(`Remove connection profile "${t.name}"?`)&&e.removeProfile(t.id)};return{...e,name:t,setName:n,url:o,setUrl:s,agentUrl:c,setAgentUrl:l,tok:u,setTok:d,agentTok:f,setAgentTok:p,testing:m,result:g,urlError:v,agentUrlError:x,saveNotice:T,edit:N,save:I,add:L,remove:R,testServer:()=>F(`server`),testAgent:()=>F(`agent`)}}function T({id:e,label:t,hint:n,value:r,placeholder:i,onChange:a}){let[s,c]=(0,y.useState)(!1);return(0,g.jsx)(h,{label:t,hint:n,htmlFor:e,children:(0,g.jsxs)(`div`,{className:`relative`,children:[(0,g.jsx)(m,{id:e,name:e,type:s?`text`:`password`,value:r,onChange:e=>a(e.target.value),placeholder:i,className:`pr-10`,autoComplete:`off`,spellCheck:!1}),(0,g.jsx)(d,{"aria-label":s?`Hide ${t.toLowerCase()}`:`Show ${t.toLowerCase()}`,className:`absolute right-0.5 top-1/2 -translate-y-1/2`,onClick:()=>c(e=>!e),children:(0,g.jsx)(o,{className:`size-4`})})]})})}function E(){let e=w(),t=t=>n=>{e.edit(),t(n)};return(0,g.jsxs)(f,{children:[(0,g.jsx)(c,{title:`Bunqueue fleet connections`}),(0,g.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,g.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-[1fr_auto_auto]`,children:[(0,g.jsx)(h,{label:`Active node`,children:(0,g.jsx)(p,{"aria-label":`Active Bunqueue node`,value:e.activeProfileId,onChange:t=>e.activateProfile(t.target.value),children:e.profiles.map(e=>(0,g.jsx)(`option`,{value:e.id,children:e.name},e.id))})}),(0,g.jsx)(s,{className:`self-end`,onClick:e.add,children:`Add node`}),(0,g.jsx)(s,{className:`self-end`,variant:`danger`,disabled:e.profiles.length===1,onClick:e.remove,children:`Remove`})]}),(0,g.jsx)(h,{label:`Node name`,children:(0,g.jsx)(m,{name:`profile-name`,value:e.name,onChange:n=>t(e.setName)(n.target.value),maxLength:64,autoComplete:`off`,placeholder:`broker-eu-1`})}),(0,g.jsx)(h,{label:`Server URL`,children:(0,g.jsx)(m,{name:`server-url`,value:e.url,onChange:n=>{t(e.setUrl)(n.target.value)},placeholder:`/api or https://queue.example.com`,autoComplete:`off`,inputMode:`url`,"aria-invalid":e.urlError?!0:void 0,"aria-describedby":e.urlError?`server-url-error`:`server-url-help`})}),e.urlError?(0,g.jsx)(`p`,{id:`server-url-error`,className:`-mt-2 text-xs text-danger`,children:e.urlError}):(0,g.jsx)(`p`,{id:`server-url-help`,className:`-mt-2 text-xs text-faint`,children:`Bunqueue HTTP API for this broker. All queue pages use the selected node.`}),(0,g.jsx)(h,{label:`Control agent URL`,children:(0,g.jsx)(m,{name:`agent-url`,value:e.agentUrl,onChange:n=>t(e.setAgentUrl)(n.target.value),placeholder:`/agent or https://broker.example.com/agent`,autoComplete:`off`,inputMode:`url`,"aria-invalid":e.agentUrlError?!0:void 0,"aria-describedby":e.agentUrlError?`agent-url-error`:`agent-url-help`})}),e.agentUrlError?(0,g.jsx)(`p`,{id:`agent-url-error`,className:`-mt-2 text-xs text-danger`,children:e.agentUrlError}):(0,g.jsx)(`p`,{id:`agent-url-help`,className:`-mt-2 text-xs text-faint`,children:`One paired agent per broker enables lifecycle, configuration, Flow, Workflow and advanced queue controls.`}),(0,g.jsx)(T,{id:`bearer-token`,label:`Bearer token (optional)`,hint:`Server credential, kept in memory only and isolated to this node.`,value:e.tok,onChange:t(e.setTok),placeholder:`only if AUTH_TOKENS is set`}),(0,g.jsx)(T,{id:`agent-token`,label:`Agent token (optional)`,hint:`AGENT_TOKEN for this node, kept in memory only.`,value:e.agentTok,onChange:t(e.setAgentTok),placeholder:`only if AGENT_TOKEN is set`}),(0,g.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,g.jsx)(s,{variant:`accent`,onClick:e.save,children:`Save`}),(0,g.jsx)(s,{onClick:e.testServer,children:e.testing===`server`?`Restart test`:`Test connection`}),(0,g.jsx)(s,{onClick:e.testAgent,children:e.testing===`agent`?`Restart agent test`:`Test agent`}),e.saveNotice&&(0,g.jsx)(`span`,{role:`status`,className:e.saveNotice.ok?`text-sm text-success`:`text-sm text-warning`,children:e.saveNotice.msg}),e.result&&(0,g.jsx)(`span`,{role:`status`,className:e.result.ok?`text-sm text-success`:`text-sm text-danger`,children:e.result.msg})]}),(0,g.jsx)(`p`,{className:`-mt-1 text-xs text-faint`,children:`Switching the active node retargets every Dashboard feature atomically. Profile metadata persists; both credentials are erased on reload.`})]})]})}function D(){return(0,g.jsxs)(`div`,{children:[(0,g.jsx)(l,{title:`Settings`,description:`Bunqueue fleet connections, credentials and appearance.`}),(0,g.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,g.jsx)(E,{}),(0,g.jsx)(v,{})]})]})}export{D as Settings};
@@ -1 +1 @@
1
- import{t as e}from"./react-vendor-08inPAVO.js";import{t}from"./api-CCgfskjt.js";import{O as n,S as r,b as i,d as a,f as o,g as s,h as c,i as l,l as u,v as d,x as f,y as p}from"./index-X_fHGbXZ.js";var m=e(),h={stats:{waiting:0,active:0,delayed:0,completed:0,dlq:0,totalPushed:0,totalPulled:0,totalCompleted:0,totalFailed:0,uptime:0},memory:{heapUsed:0,heapTotal:0,rss:0},workers:{total:0,active:0},crons:{total:0},storage:{}};function g(){let{data:e,error:g,loading:v,refetch:y}=n(()=>t.overview(),[]);if(v&&!e&&!g)return(0,m.jsx)(p,{label:`Loading usage…`});if(g&&!e)return(0,m.jsxs)(`div`,{children:[(0,m.jsx)(s,{title:`Usage`,description:`Cumulative resource usage is unavailable.`}),(0,m.jsx)(d,{error:g,onRetry:y})]});let{stats:b,memory:x,workers:S,crons:C,storage:w}=e??h,T=typeof w.diskFull==`boolean`;return(0,m.jsxs)(`div`,{children:[(0,m.jsx)(s,{title:`Usage`,description:`Cumulative resource usage on the connected server.`,live:!!e&&!g&&T}),g&&(0,m.jsx)(i,{message:`Usage refresh failed — showing the last successful snapshot.`,onRetry:y}),(0,m.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,m.jsx)(c,{label:`Jobs Pushed`,value:u(b.totalPushed)}),(0,m.jsx)(c,{label:`Jobs Completed`,value:u(b.totalCompleted),tone:`green`}),(0,m.jsx)(c,{label:`Jobs Failed`,value:u(b.totalFailed),tone:b.totalFailed?`red`:`default`}),(0,m.jsx)(c,{label:`Jobs Pulled`,value:u(b.totalPulled),tone:`blue`})]}),(0,m.jsxs)(`div`,{className:`mt-6 grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,m.jsxs)(f,{children:[(0,m.jsx)(r,{title:`Runtime`}),(0,m.jsxs)(`dl`,{className:`divide-y divide-line text-sm`,children:[(0,m.jsx)(_,{label:`Uptime`,value:o(b.uptime/1e3)}),(0,m.jsx)(_,{label:`Heap used`,value:l(x.heapUsed*1024*1024)}),(0,m.jsx)(_,{label:`RSS`,value:l(x.rss*1024*1024)}),(0,m.jsx)(_,{label:`Workers`,value:`${S.active} active / ${S.total}`}),(0,m.jsx)(_,{label:`Cron jobs`,value:String(C.total)})]})]}),(0,m.jsxs)(f,{children:[(0,m.jsx)(r,{title:`Storage`}),(0,m.jsxs)(`dl`,{className:`divide-y divide-line text-sm`,children:[(0,m.jsx)(_,{label:`Status`,value:T?w.diskFull?`Disk full`:`Healthy`:`Unavailable`}),(0,m.jsx)(_,{label:`Disk full since`,value:w.diskFull?a(w.since):`—`}),w.error?(0,m.jsx)(_,{label:`Error`,value:String(w.error)}):null]})]})]})]})}function _({label:e,value:t,mono:n}){return(0,m.jsxs)(`div`,{className:`flex items-center justify-between py-2.5`,children:[(0,m.jsx)(`dt`,{className:`text-muted`,children:e}),(0,m.jsx)(`dd`,{className:n?`font-mono text-xs text-fg`:`font-medium text-fg`,children:t})]})}export{g as Usage};
1
+ import{t as e}from"./react-vendor-08inPAVO.js";import{t}from"./api-CCgfskjt.js";import{O as n,S as r,b as i,d as a,f as o,g as s,h as c,i as l,l as u,v as d,x as f,y as p}from"./index-DwsYIYdu.js";var m=e(),h={stats:{waiting:0,active:0,delayed:0,completed:0,dlq:0,totalPushed:0,totalPulled:0,totalCompleted:0,totalFailed:0,uptime:0},memory:{heapUsed:0,heapTotal:0,rss:0},workers:{total:0,active:0},crons:{total:0},storage:{}};function g(){let{data:e,error:g,loading:v,refetch:y}=n(()=>t.overview(),[]);if(v&&!e&&!g)return(0,m.jsx)(p,{label:`Loading usage…`});if(g&&!e)return(0,m.jsxs)(`div`,{children:[(0,m.jsx)(s,{title:`Usage`,description:`Cumulative resource usage is unavailable.`}),(0,m.jsx)(d,{error:g,onRetry:y})]});let{stats:b,memory:x,workers:S,crons:C,storage:w}=e??h,T=typeof w.diskFull==`boolean`;return(0,m.jsxs)(`div`,{children:[(0,m.jsx)(s,{title:`Usage`,description:`Cumulative resource usage on the connected server.`,live:!!e&&!g&&T}),g&&(0,m.jsx)(i,{message:`Usage refresh failed — showing the last successful snapshot.`,onRetry:y}),(0,m.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,m.jsx)(c,{label:`Jobs Pushed`,value:u(b.totalPushed)}),(0,m.jsx)(c,{label:`Jobs Completed`,value:u(b.totalCompleted),tone:`green`}),(0,m.jsx)(c,{label:`Jobs Failed`,value:u(b.totalFailed),tone:b.totalFailed?`red`:`default`}),(0,m.jsx)(c,{label:`Jobs Pulled`,value:u(b.totalPulled),tone:`blue`})]}),(0,m.jsxs)(`div`,{className:`mt-6 grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,m.jsxs)(f,{children:[(0,m.jsx)(r,{title:`Runtime`}),(0,m.jsxs)(`dl`,{className:`divide-y divide-line text-sm`,children:[(0,m.jsx)(_,{label:`Uptime`,value:o(b.uptime/1e3)}),(0,m.jsx)(_,{label:`Heap used`,value:l(x.heapUsed*1024*1024)}),(0,m.jsx)(_,{label:`RSS`,value:l(x.rss*1024*1024)}),(0,m.jsx)(_,{label:`Workers`,value:`${S.active} active / ${S.total}`}),(0,m.jsx)(_,{label:`Cron jobs`,value:String(C.total)})]})]}),(0,m.jsxs)(f,{children:[(0,m.jsx)(r,{title:`Storage`}),(0,m.jsxs)(`dl`,{className:`divide-y divide-line text-sm`,children:[(0,m.jsx)(_,{label:`Status`,value:T?w.diskFull?`Disk full`:`Healthy`:`Unavailable`}),(0,m.jsx)(_,{label:`Disk full since`,value:w.diskFull?a(w.since):`—`}),w.error?(0,m.jsx)(_,{label:`Error`,value:String(w.error)}):null]})]})]})]})}function _({label:e,value:t,mono:n}){return(0,m.jsxs)(`div`,{className:`flex items-center justify-between py-2.5`,children:[(0,m.jsx)(`dt`,{className:`text-muted`,children:e}),(0,m.jsx)(`dd`,{className:n?`font-mono text-xs text-fg`:`font-medium text-fg`,children:t})]})}export{g as Usage};
@@ -1 +1 @@
1
- import{t as e}from"./react-vendor-08inPAVO.js";import{I as t,O as n,S as r,b as i,d as a,f as o,g as s,h as c,i as l,l as u,n as d,r as f,u as p,v as m,x as h,y as g}from"./index-X_fHGbXZ.js";var _=e(),v={overview:{stats:{waiting:0,active:0,delayed:0,completed:0,dlq:0,totalPushed:0,totalPulled:0,totalCompleted:0,totalFailed:0,uptime:0},memory:{heapUsed:0,heapTotal:0,rss:0},crons:{total:0}},storage:{},failedTotal:0};function y(){let{data:e,error:y,loading:x,refetch:S}=n(async()=>{let[e,n,r]=await Promise.all([t.overview(),t.storage(),t.queuesSummary()]);if(!n?.data||typeof n.data.diskFull!=`boolean`)throw Error(`Storage status response is missing disk health data`);if(d(e),!Number.isFinite(e.memory.heapUsed))throw Error(`Malformed /dashboard response: memory.heapUsed is missing or non-numeric.`);let i=r.reduce((e,t)=>e+(t.counts?.failed??0),0);return{overview:e,storage:n.data,failedTotal:i}},[]);if(x&&!e&&!y)return(0,_.jsx)(g,{label:`Loading usage…`});if(y&&!e)return(0,_.jsxs)(`div`,{children:[(0,_.jsx)(s,{title:`Usage`,description:`Cumulative resource usage is unavailable.`}),(0,_.jsx)(m,{error:y,onRetry:S})]});let C=e??v,{stats:w,memory:T,crons:E}=C.overview,{storage:D,failedTotal:O}=C,k=f(w.completed,O),A=w.uptime?o(w.uptime/1e3):`—`;return(0,_.jsxs)(`div`,{children:[(0,_.jsx)(s,{title:`Usage`,description:`Cumulative resource usage on the connected server.`,live:!!e&&!y}),y&&(0,_.jsx)(i,{message:`Usage refresh failed — showing the last successful snapshot.`,onRetry:S}),(0,_.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-6`,children:[(0,_.jsx)(c,{label:`Completed`,value:u(w.completed),tone:`green`}),(0,_.jsx)(c,{label:`Failed`,value:u(O),tone:O?`red`:`default`}),(0,_.jsx)(c,{label:`Waiting`,value:u(w.waiting),tone:`amber`}),(0,_.jsx)(c,{label:`Active`,value:u(w.active),tone:`blue`}),(0,_.jsx)(c,{label:`Error Rate`,value:k==null?`—`:p(k),tone:k==null?`default`:k>.05?`red`:`green`}),(0,_.jsx)(c,{label:`Uptime`,value:A})]}),(0,_.jsxs)(`div`,{className:`mt-6 grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,_.jsxs)(h,{children:[(0,_.jsx)(r,{title:`Runtime`}),(0,_.jsxs)(`dl`,{className:`divide-y divide-line text-sm`,children:[(0,_.jsx)(b,{label:`Jobs pushed (since restart)`,value:u(w.totalPushed)}),(0,_.jsx)(b,{label:`Jobs pulled (since restart)`,value:u(w.totalPulled)}),(0,_.jsx)(b,{label:`Heap used`,value:l(T.heapUsed*1024*1024)}),(0,_.jsx)(b,{label:`RSS`,value:l(T.rss*1024*1024)}),(0,_.jsx)(b,{label:`Cron jobs`,value:String(E.total)})]})]}),(0,_.jsxs)(h,{children:[(0,_.jsx)(r,{title:`Storage`}),D.diskFull?(0,_.jsxs)(`div`,{className:`rounded-lg border border-red-500/25 bg-red-500/[0.06] px-4 py-3`,children:[(0,_.jsx)(`div`,{className:`font-semibold text-danger`,children:`Disk full — writes suspended`}),D.error&&(0,_.jsx)(`div`,{className:`mt-1 text-xs text-muted`,children:D.error}),D.since!=null&&(0,_.jsxs)(`div`,{className:`mt-1 text-xs text-faint`,children:[`since `,a(D.since)]})]}):(0,_.jsxs)(`div`,{className:`rounded-lg border border-emerald-500/25 bg-emerald-500/[0.06] px-4 py-3`,children:[(0,_.jsx)(`div`,{className:`font-semibold text-success`,children:`Healthy`}),(0,_.jsx)(`div`,{className:`mt-1 text-xs text-faint`,children:`Disk writes are being accepted.`})]})]})]})]})}function b({label:e,value:t}){return(0,_.jsxs)(`div`,{className:`flex items-center justify-between py-2.5`,children:[(0,_.jsx)(`dt`,{className:`text-muted`,children:e}),(0,_.jsx)(`dd`,{className:`font-medium text-fg`,children:t})]})}export{y as UsagePro};
1
+ import{t as e}from"./react-vendor-08inPAVO.js";import{I as t,O as n,S as r,b as i,d as a,f as o,g as s,h as c,i as l,l as u,n as d,r as f,u as p,v as m,x as h,y as g}from"./index-DwsYIYdu.js";var _=e(),v={overview:{stats:{waiting:0,active:0,delayed:0,completed:0,dlq:0,totalPushed:0,totalPulled:0,totalCompleted:0,totalFailed:0,uptime:0},memory:{heapUsed:0,heapTotal:0,rss:0},crons:{total:0}},storage:{},failedTotal:0};function y(){let{data:e,error:y,loading:x,refetch:S}=n(async()=>{let[e,n,r]=await Promise.all([t.overview(),t.storage(),t.queuesSummary()]);if(!n?.data||typeof n.data.diskFull!=`boolean`)throw Error(`Storage status response is missing disk health data`);if(d(e),!Number.isFinite(e.memory.heapUsed))throw Error(`Malformed /dashboard response: memory.heapUsed is missing or non-numeric.`);let i=r.reduce((e,t)=>e+(t.counts?.failed??0),0);return{overview:e,storage:n.data,failedTotal:i}},[]);if(x&&!e&&!y)return(0,_.jsx)(g,{label:`Loading usage…`});if(y&&!e)return(0,_.jsxs)(`div`,{children:[(0,_.jsx)(s,{title:`Usage`,description:`Cumulative resource usage is unavailable.`}),(0,_.jsx)(m,{error:y,onRetry:S})]});let C=e??v,{stats:w,memory:T,crons:E}=C.overview,{storage:D,failedTotal:O}=C,k=f(w.completed,O),A=w.uptime?o(w.uptime/1e3):`—`;return(0,_.jsxs)(`div`,{children:[(0,_.jsx)(s,{title:`Usage`,description:`Cumulative resource usage on the connected server.`,live:!!e&&!y}),y&&(0,_.jsx)(i,{message:`Usage refresh failed — showing the last successful snapshot.`,onRetry:S}),(0,_.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-6`,children:[(0,_.jsx)(c,{label:`Completed`,value:u(w.completed),tone:`green`}),(0,_.jsx)(c,{label:`Failed`,value:u(O),tone:O?`red`:`default`}),(0,_.jsx)(c,{label:`Waiting`,value:u(w.waiting),tone:`amber`}),(0,_.jsx)(c,{label:`Active`,value:u(w.active),tone:`blue`}),(0,_.jsx)(c,{label:`Error Rate`,value:k==null?`—`:p(k),tone:k==null?`default`:k>.05?`red`:`green`}),(0,_.jsx)(c,{label:`Uptime`,value:A})]}),(0,_.jsxs)(`div`,{className:`mt-6 grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,_.jsxs)(h,{children:[(0,_.jsx)(r,{title:`Runtime`}),(0,_.jsxs)(`dl`,{className:`divide-y divide-line text-sm`,children:[(0,_.jsx)(b,{label:`Jobs pushed (since restart)`,value:u(w.totalPushed)}),(0,_.jsx)(b,{label:`Jobs pulled (since restart)`,value:u(w.totalPulled)}),(0,_.jsx)(b,{label:`Heap used`,value:l(T.heapUsed*1024*1024)}),(0,_.jsx)(b,{label:`RSS`,value:l(T.rss*1024*1024)}),(0,_.jsx)(b,{label:`Cron jobs`,value:String(E.total)})]})]}),(0,_.jsxs)(h,{children:[(0,_.jsx)(r,{title:`Storage`}),D.diskFull?(0,_.jsxs)(`div`,{className:`rounded-lg border border-red-500/25 bg-red-500/[0.06] px-4 py-3`,children:[(0,_.jsx)(`div`,{className:`font-semibold text-danger`,children:`Disk full — writes suspended`}),D.error&&(0,_.jsx)(`div`,{className:`mt-1 text-xs text-muted`,children:D.error}),D.since!=null&&(0,_.jsxs)(`div`,{className:`mt-1 text-xs text-faint`,children:[`since `,a(D.since)]})]}):(0,_.jsxs)(`div`,{className:`rounded-lg border border-emerald-500/25 bg-emerald-500/[0.06] px-4 py-3`,children:[(0,_.jsx)(`div`,{className:`font-semibold text-success`,children:`Healthy`}),(0,_.jsx)(`div`,{className:`mt-1 text-xs text-faint`,children:`Disk writes are being accepted.`})]})]})]})]})}function b({label:e,value:t}){return(0,_.jsxs)(`div`,{className:`flex items-center justify-between py-2.5`,children:[(0,_.jsx)(`dt`,{className:`text-muted`,children:e}),(0,_.jsx)(`dd`,{className:`font-medium text-fg`,children:t})]})}export{y as UsagePro};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,t as n}from"./react-vendor-08inPAVO.js";import{O as r,m as i}from"./icons-BIT5aq1c.js";import{C as a,F as o,I as s,O as c,S as l,_ as u,b as d,d as f,g as p,l as m,v as h,w as g,x as _,y as v}from"./index-X_fHGbXZ.js";import{n as y,o as b,t as x}from"./form-DBkslwzu.js";import{t as S}from"./Pagination-WVfHLHDS.js";import{r as C,t as w}from"./useServerActionGuard-uiZWD3dS.js";var T=[`job.pushed`,`job.started`,`job.completed`,`job.failed`,`job.progress`],E=e(t(),1);function D(e){try{let t=new URL(e);return e.length<=2048&&/^https?:$/.test(t.protocol)&&t.username===``&&t.password===``}catch{return!1}}function O(e){try{let t=new URL(e);return!t.username&&!t.password?e:(t.username=`redacted`,t.password=`redacted`,t.toString())}catch{return e}}function k(e,t,n,r){let i=e.trim();if(!i||t.length===0)return{ok:!1,msg:`URL and at least one event are required`};if(!D(i))return{ok:!1,msg:`URL must be a valid http:// or https:// address without embedded credentials`};let a=n.trim();return a&&(a.length>256||!/^[a-zA-Z0-9_\-.:]+$/.test(a))?{ok:!1,msg:`Queue must be at most 256 characters using letters, numbers, _, -, . or :`}:{ok:!0,body:{url:i,events:t,queue:a||void 0,secret:r.trim()||void 0}}}var A=n();function j({onAdd:e,onAccepted:t,beginAdd:n,scopeKey:r}){let[i,o]=(0,E.useState)(``),[s,c]=(0,E.useState)(``),[l,u]=(0,E.useState)(``),[d,f]=(0,E.useState)([`job.completed`,`job.failed`]),[p,m]=(0,E.useState)(null),[h,g]=(0,E.useState)(!1);(0,E.useEffect)(()=>{g(!1),m(null)},[r]);let _=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),v=async()=>{if(h)return;m(null);let r=k(i,d,s,l);if(!r.ok)return m(r.msg);let a=n();if(a){g(!0);try{let n=await e(r.body);if(w(n,`Add webhook`),!a.isCurrent())return;o(``),u(``),t()}catch(e){a.isCurrent()&&m(e.message)}finally{a.finish()&&g(!1)}}};return(0,A.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),v()},children:[(0,A.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 md:grid-cols-3`,children:[(0,A.jsx)(`div`,{className:`md:col-span-1`,children:(0,A.jsx)(x,{label:`URL`,children:(0,A.jsx)(y,{value:i,onInput:e=>o(e.currentTarget.value),name:`webhook-url`,type:`url`,maxLength:2048,autoComplete:`url`,placeholder:`https://example.com/hook`})})}),(0,A.jsx)(x,{label:`Queue (optional)`,children:(0,A.jsx)(y,{value:s,onChange:e=>c(e.target.value),name:`webhook-queue`,maxLength:256,autoComplete:`off`,placeholder:`all queues`})}),(0,A.jsx)(x,{label:`Secret (optional)`,children:(0,A.jsx)(y,{type:`password`,autoComplete:`new-password`,name:`webhook-secret`,maxLength:65536,value:l,onChange:e=>u(e.target.value),placeholder:`HMAC signing secret`})})]}),(0,A.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:T.map(e=>(0,A.jsx)(`button`,{type:`button`,"aria-pressed":d.includes(e),onClick:()=>_(e),className:d.includes(e)?`rounded-full bg-accent/15 px-3 py-1 text-xs font-medium text-accent`:`rounded-full border border-line px-3 py-1 text-xs font-medium text-muted hover:text-fg`,children:e},e))}),(0,A.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,A.jsx)(a,{type:`submit`,variant:`accent`,size:`sm`,disabled:h,children:h?`Adding…`:`Add webhook`}),p&&(0,A.jsx)(`span`,{className:`text-xs text-danger`,children:p})]})]})}function M(e){let[t,n]=(0,E.useState)(0);return(0,E.useEffect)(()=>{t>e-1&&n(e-1)},[t,e]),[Math.min(t,e-1),n]}function N(){let{data:e,error:t,loading:n,refetch:a}=c(()=>s.webhooks(),[]),y=e?.data?.webhooks??[],[x,T]=M(Math.max(1,Math.ceil(y.length/15))),[D,k]=(0,E.useState)(null),[N,P]=(0,E.useState)(new Set),F=C(`webhooks`),[I,L]=(0,E.useState)({}),R=(0,E.useRef)(new Map);(0,E.useEffect)(()=>{k(null),P(new Set),L({}),R.current.clear()},[F.scopeKey]);let z=async e=>{let t=F.begin([`registry-write`,`webhook:${e}`]);if(t){k(null),P(t=>new Set(t).add(e));try{let n=await s.removeWebhook(e);if(w(n,`Remove webhook`),!t.isCurrent())return;a()}catch(e){if(!t.isCurrent())return;k(e.message)}finally{t.finish()&&P(t=>{let n=new Set(t);return n.delete(e),n})}}},B=(e,t)=>{let n=Symbol(`webhook-toggle`),r=R.current.get(e);if(r){r.desired=t,r.intent=n,L(r=>({...r,[e]:{value:t,intent:n}}));return}let i=F.begin(`webhook:${e}`);if(!i)return;let c={desired:t,intent:n,lease:i};R.current.set(e,c),L(r=>({...r,[e]:{value:t,intent:n}})),(async()=>{try{for(;i.isCurrent()&&R.current.get(e)===c;){let t=c.desired,n=null;try{let n=await s.setWebhookEnabled(e,t);w(n,`Toggle webhook`)}catch(e){n=e instanceof Error?e:Error(String(e))}if(!i.isCurrent()||R.current.get(e)!==c)return;if(c.desired!==t)continue;if(await a(),!i.isCurrent()||R.current.get(e)!==c)return;if(c.desired!==t)continue;R.current.delete(e);let r=c.intent;L(t=>{if(t[e]?.intent!==r)return t;let{[e]:n,...i}=t;return i}),n&&o.error(`Webhook toggle failed`,n.message);return}}finally{i.finish()}})()};return(0,A.jsxs)(`div`,{children:[(0,A.jsx)(p,{title:`Webhooks`,description:`HTTP callbacks fired on job events.`,live:!!e&&!t}),t&&e&&(0,A.jsx)(d,{message:`Webhook refresh failed — showing the last successful registry.`,onRetry:a}),D&&(0,A.jsx)(`div`,{role:`status`,className:`mb-4 rounded-lg border border-red-500/20 bg-red-500/5 px-4 py-2 text-sm text-danger`,children:D}),(0,A.jsxs)(_,{className:`mb-6`,children:[(0,A.jsx)(l,{title:`Add webhook`}),(0,A.jsx)(j,{onAdd:e=>s.addWebhook(e),onAccepted:()=>void a(),beginAdd:()=>F.begin([`registry-write`,`add`]),scopeKey:F.scopeKey})]}),t&&!e?(0,A.jsx)(h,{error:t,onRetry:a}):n&&!e?(0,A.jsx)(v,{label:`Loading webhooks…`}):y.length===0?(0,A.jsx)(u,{icon:(0,A.jsx)(i,{}),title:`No webhooks`,hint:`Add one above to receive job-event callbacks.`}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,A.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,A.jsx)(`thead`,{children:(0,A.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,A.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`URL`}),(0,A.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Events`}),(0,A.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queue`}),(0,A.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Success / Fail`}),(0,A.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Last`}),(0,A.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Enabled`}),(0,A.jsx)(`th`,{className:`w-12 px-5 py-3`})]})}),(0,A.jsx)(`tbody`,{children:y.slice(x*15,x*15+15).map(e=>(0,A.jsxs)(`tr`,{className:`border-b border-line last:border-0 align-top hover:bg-surface-2/40`,children:[(0,A.jsx)(`td`,{className:`max-w-xs truncate px-5 py-3 font-mono text-xs text-fg`,children:O(e.url)}),(0,A.jsx)(`td`,{className:`px-5 py-3 text-xs text-muted`,children:e.events.join(`, `)}),(0,A.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queue??`all`}),(0,A.jsxs)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:[(0,A.jsx)(`span`,{className:`text-success`,children:m(e.successCount)}),` / `,(0,A.jsx)(`span`,{className:e.failureCount?`text-danger`:``,children:m(e.failureCount)})]}),(0,A.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:f(e.lastTriggered)}),(0,A.jsx)(`td`,{className:`px-5 py-3`,children:(0,A.jsx)(b,{checked:I[e.id]?.value??e.enabled,label:`${I[e.id]?.value??e.enabled?`Disable`:`Enable`} webhook`,onChange:t=>B(e.id,t)})}),(0,A.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,A.jsx)(g,{"aria-label":`Remove webhook`,disabled:N.has(e.id),onClick:()=>window.confirm(`Remove webhook for ${O(e.url)}?`)&&z(e.id),children:(0,A.jsx)(r,{className:`size-3.5`})})})]},e.id))})]})}),(0,A.jsx)(S,{page:x,pageSize:15,total:y.length,onPageChange:T,label:`webhooks`})]})]})}export{N as Webhooks};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,t as n}from"./react-vendor-08inPAVO.js";import{O as r,m as i}from"./icons-BIT5aq1c.js";import{C as a,F as o,I as s,O as c,S as l,_ as u,b as d,d as f,g as p,l as m,v as h,w as g,x as _,y as v}from"./index-DwsYIYdu.js";import{n as y,o as b,t as x}from"./form-DBkslwzu.js";import{t as S}from"./Pagination-CmVnmrFt.js";import{r as C,t as w}from"./useServerActionGuard-uiZWD3dS.js";var T=[`job.pushed`,`job.started`,`job.completed`,`job.failed`,`job.progress`],E=e(t(),1);function D(e){try{let t=new URL(e);return e.length<=2048&&/^https?:$/.test(t.protocol)&&t.username===``&&t.password===``}catch{return!1}}function O(e){try{let t=new URL(e);return!t.username&&!t.password?e:(t.username=`redacted`,t.password=`redacted`,t.toString())}catch{return e}}function k(e,t,n,r){let i=e.trim();if(!i||t.length===0)return{ok:!1,msg:`URL and at least one event are required`};if(!D(i))return{ok:!1,msg:`URL must be a valid http:// or https:// address without embedded credentials`};let a=n.trim();return a&&(a.length>256||!/^[a-zA-Z0-9_\-.:]+$/.test(a))?{ok:!1,msg:`Queue must be at most 256 characters using letters, numbers, _, -, . or :`}:{ok:!0,body:{url:i,events:t,queue:a||void 0,secret:r.trim()||void 0}}}var A=n();function j({onAdd:e,onAccepted:t,beginAdd:n,scopeKey:r}){let[i,o]=(0,E.useState)(``),[s,c]=(0,E.useState)(``),[l,u]=(0,E.useState)(``),[d,f]=(0,E.useState)([`job.completed`,`job.failed`]),[p,m]=(0,E.useState)(null),[h,g]=(0,E.useState)(!1);(0,E.useEffect)(()=>{g(!1),m(null)},[r]);let _=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),v=async()=>{if(h)return;m(null);let r=k(i,d,s,l);if(!r.ok)return m(r.msg);let a=n();if(a){g(!0);try{let n=await e(r.body);if(w(n,`Add webhook`),!a.isCurrent())return;o(``),u(``),t()}catch(e){a.isCurrent()&&m(e.message)}finally{a.finish()&&g(!1)}}};return(0,A.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),v()},children:[(0,A.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 md:grid-cols-3`,children:[(0,A.jsx)(`div`,{className:`md:col-span-1`,children:(0,A.jsx)(x,{label:`URL`,children:(0,A.jsx)(y,{value:i,onInput:e=>o(e.currentTarget.value),name:`webhook-url`,type:`url`,maxLength:2048,autoComplete:`url`,placeholder:`https://example.com/hook`})})}),(0,A.jsx)(x,{label:`Queue (optional)`,children:(0,A.jsx)(y,{value:s,onChange:e=>c(e.target.value),name:`webhook-queue`,maxLength:256,autoComplete:`off`,placeholder:`all queues`})}),(0,A.jsx)(x,{label:`Secret (optional)`,children:(0,A.jsx)(y,{type:`password`,autoComplete:`new-password`,name:`webhook-secret`,maxLength:65536,value:l,onChange:e=>u(e.target.value),placeholder:`HMAC signing secret`})})]}),(0,A.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:T.map(e=>(0,A.jsx)(`button`,{type:`button`,"aria-pressed":d.includes(e),onClick:()=>_(e),className:d.includes(e)?`rounded-full bg-accent/15 px-3 py-1 text-xs font-medium text-accent`:`rounded-full border border-line px-3 py-1 text-xs font-medium text-muted hover:text-fg`,children:e},e))}),(0,A.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,A.jsx)(a,{type:`submit`,variant:`accent`,size:`sm`,disabled:h,children:h?`Adding…`:`Add webhook`}),p&&(0,A.jsx)(`span`,{className:`text-xs text-danger`,children:p})]})]})}function M(e){let[t,n]=(0,E.useState)(0);return(0,E.useEffect)(()=>{t>e-1&&n(e-1)},[t,e]),[Math.min(t,e-1),n]}function N(){let{data:e,error:t,loading:n,refetch:a}=c(()=>s.webhooks(),[]),y=e?.data?.webhooks??[],[x,T]=M(Math.max(1,Math.ceil(y.length/15))),[D,k]=(0,E.useState)(null),[N,P]=(0,E.useState)(new Set),F=C(`webhooks`),[I,L]=(0,E.useState)({}),R=(0,E.useRef)(new Map);(0,E.useEffect)(()=>{k(null),P(new Set),L({}),R.current.clear()},[F.scopeKey]);let z=async e=>{let t=F.begin([`registry-write`,`webhook:${e}`]);if(t){k(null),P(t=>new Set(t).add(e));try{let n=await s.removeWebhook(e);if(w(n,`Remove webhook`),!t.isCurrent())return;a()}catch(e){if(!t.isCurrent())return;k(e.message)}finally{t.finish()&&P(t=>{let n=new Set(t);return n.delete(e),n})}}},B=(e,t)=>{let n=Symbol(`webhook-toggle`),r=R.current.get(e);if(r){r.desired=t,r.intent=n,L(r=>({...r,[e]:{value:t,intent:n}}));return}let i=F.begin(`webhook:${e}`);if(!i)return;let c={desired:t,intent:n,lease:i};R.current.set(e,c),L(r=>({...r,[e]:{value:t,intent:n}})),(async()=>{try{for(;i.isCurrent()&&R.current.get(e)===c;){let t=c.desired,n=null;try{let n=await s.setWebhookEnabled(e,t);w(n,`Toggle webhook`)}catch(e){n=e instanceof Error?e:Error(String(e))}if(!i.isCurrent()||R.current.get(e)!==c)return;if(c.desired!==t)continue;if(await a(),!i.isCurrent()||R.current.get(e)!==c)return;if(c.desired!==t)continue;R.current.delete(e);let r=c.intent;L(t=>{if(t[e]?.intent!==r)return t;let{[e]:n,...i}=t;return i}),n&&o.error(`Webhook toggle failed`,n.message);return}}finally{i.finish()}})()};return(0,A.jsxs)(`div`,{children:[(0,A.jsx)(p,{title:`Webhooks`,description:`HTTP callbacks fired on job events.`,live:!!e&&!t}),t&&e&&(0,A.jsx)(d,{message:`Webhook refresh failed — showing the last successful registry.`,onRetry:a}),D&&(0,A.jsx)(`div`,{role:`status`,className:`mb-4 rounded-lg border border-red-500/20 bg-red-500/5 px-4 py-2 text-sm text-danger`,children:D}),(0,A.jsxs)(_,{className:`mb-6`,children:[(0,A.jsx)(l,{title:`Add webhook`}),(0,A.jsx)(j,{onAdd:e=>s.addWebhook(e),onAccepted:()=>void a(),beginAdd:()=>F.begin([`registry-write`,`add`]),scopeKey:F.scopeKey})]}),t&&!e?(0,A.jsx)(h,{error:t,onRetry:a}):n&&!e?(0,A.jsx)(v,{label:`Loading webhooks…`}):y.length===0?(0,A.jsx)(u,{icon:(0,A.jsx)(i,{}),title:`No webhooks`,hint:`Add one above to receive job-event callbacks.`}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,A.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,A.jsx)(`thead`,{children:(0,A.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,A.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`URL`}),(0,A.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Events`}),(0,A.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queue`}),(0,A.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Success / Fail`}),(0,A.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Last`}),(0,A.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Enabled`}),(0,A.jsx)(`th`,{className:`w-12 px-5 py-3`})]})}),(0,A.jsx)(`tbody`,{children:y.slice(x*15,x*15+15).map(e=>(0,A.jsxs)(`tr`,{className:`border-b border-line last:border-0 align-top hover:bg-surface-2/40`,children:[(0,A.jsx)(`td`,{className:`max-w-xs truncate px-5 py-3 font-mono text-xs text-fg`,children:O(e.url)}),(0,A.jsx)(`td`,{className:`px-5 py-3 text-xs text-muted`,children:e.events.join(`, `)}),(0,A.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queue??`all`}),(0,A.jsxs)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:[(0,A.jsx)(`span`,{className:`text-success`,children:m(e.successCount)}),` / `,(0,A.jsx)(`span`,{className:e.failureCount?`text-danger`:``,children:m(e.failureCount)})]}),(0,A.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:f(e.lastTriggered)}),(0,A.jsx)(`td`,{className:`px-5 py-3`,children:(0,A.jsx)(b,{checked:I[e.id]?.value??e.enabled,label:`${I[e.id]?.value??e.enabled?`Disable`:`Enable`} webhook`,onChange:t=>B(e.id,t)})}),(0,A.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,A.jsx)(g,{"aria-label":`Remove webhook`,disabled:N.has(e.id),onClick:()=>window.confirm(`Remove webhook for ${O(e.url)}?`)&&z(e.id),children:(0,A.jsx)(r,{className:`size-3.5`})})})]},e.id))})]})}),(0,A.jsx)(S,{page:x,pageSize:15,total:y.length,onPageChange:T,label:`webhooks`})]})]})}export{N as Webhooks};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,t as n}from"./react-vendor-08inPAVO.js";import{A as r}from"./icons-BIT5aq1c.js";import{t as i}from"./api-CCgfskjt.js";import{O as a,_ as o,b as s,d as c,g as l,h as u,l as d,v as f,y as p}from"./index-X_fHGbXZ.js";import{t as m}from"./Pagination-WVfHLHDS.js";var h=e(t(),1),g=n(),_=20,v={workers:{total:0,active:0,list:[],truncated:!1}};function y(){let{data:e,error:t,loading:n,refetch:y}=a(()=>i.overview(),[]),[b,x]=(0,h.useState)(0);if(n&&!e&&!t)return(0,g.jsx)(p,{label:`Loading workers…`});if(t&&!e)return(0,g.jsxs)(`div`,{children:[(0,g.jsx)(l,{title:`Workers`,description:`Worker inventory is unavailable.`}),(0,g.jsx)(f,{error:t,onRetry:y})]});let{workers:S}=e??v,C=Math.max(1,Math.ceil(S.list.length/_)),w=Math.min(b,C-1),T=S.list.slice(w*_,w*_+_);return(0,g.jsxs)(`div`,{children:[t&&(0,g.jsx)(s,{message:`Worker refresh failed — showing the last successful inventory.`,onRetry:y}),(0,g.jsx)(l,{title:`Workers`,description:`Registered workers and their throughput.`,live:!!e&&!t}),(0,g.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,g.jsx)(u,{label:`Total`,value:d(S.total),compact:!0}),(0,g.jsx)(u,{label:`Active`,value:d(S.active),tone:`green`,compact:!0})]}),S.list.length===0?(0,g.jsx)(o,{icon:(0,g.jsx)(r,{}),title:`No workers registered`,hint:`Workers appear here once they connect and register with the server.`}):(0,g.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,g.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,g.jsx)(`thead`,{children:(0,g.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,g.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Worker`}),(0,g.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queues`}),(0,g.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Active`}),(0,g.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Processed`}),(0,g.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Failed`}),(0,g.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Last Seen`})]})}),(0,g.jsx)(`tbody`,{children:T.map(e=>(0,g.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,g.jsxs)(`td`,{className:`px-5 py-3`,children:[(0,g.jsx)(`div`,{className:`font-medium text-fg`,children:e.name||`worker`}),(0,g.jsx)(`div`,{className:`font-mono text-[11px] text-faint`,children:e.id})]}),(0,g.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queues.join(`, `)||`—`}),(0,g.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-blue-400`,children:d(e.activeJobs)}),(0,g.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:d(e.processedJobs)}),(0,g.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:d(e.failedJobs)}),(0,g.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:c(e.lastSeen)})]},e.id))})]})}),S.truncated&&(0,g.jsxs)(`p`,{className:`mt-3 text-xs text-amber-400`,children:[`Showing first `,d(S.list.length),` of `,d(S.total),` `,`workers.`]}),(0,g.jsx)(m,{page:w,pageSize:_,total:S.list.length,onPageChange:x,label:`workers`})]})}export{y as Workers};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,t as n}from"./react-vendor-08inPAVO.js";import{A as r}from"./icons-BIT5aq1c.js";import{t as i}from"./api-CCgfskjt.js";import{O as a,_ as o,b as s,d as c,g as l,h as u,l as d,v as f,y as p}from"./index-DwsYIYdu.js";import{t as m}from"./Pagination-CmVnmrFt.js";var h=e(t(),1),g=n(),_=20,v={workers:{total:0,active:0,list:[],truncated:!1}};function y(){let{data:e,error:t,loading:n,refetch:y}=a(()=>i.overview(),[]),[b,x]=(0,h.useState)(0);if(n&&!e&&!t)return(0,g.jsx)(p,{label:`Loading workers…`});if(t&&!e)return(0,g.jsxs)(`div`,{children:[(0,g.jsx)(l,{title:`Workers`,description:`Worker inventory is unavailable.`}),(0,g.jsx)(f,{error:t,onRetry:y})]});let{workers:S}=e??v,C=Math.max(1,Math.ceil(S.list.length/_)),w=Math.min(b,C-1),T=S.list.slice(w*_,w*_+_);return(0,g.jsxs)(`div`,{children:[t&&(0,g.jsx)(s,{message:`Worker refresh failed — showing the last successful inventory.`,onRetry:y}),(0,g.jsx)(l,{title:`Workers`,description:`Registered workers and their throughput.`,live:!!e&&!t}),(0,g.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,g.jsx)(u,{label:`Total`,value:d(S.total),compact:!0}),(0,g.jsx)(u,{label:`Active`,value:d(S.active),tone:`green`,compact:!0})]}),S.list.length===0?(0,g.jsx)(o,{icon:(0,g.jsx)(r,{}),title:`No workers registered`,hint:`Workers appear here once they connect and register with the server.`}):(0,g.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,g.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,g.jsx)(`thead`,{children:(0,g.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,g.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Worker`}),(0,g.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queues`}),(0,g.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Active`}),(0,g.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Processed`}),(0,g.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Failed`}),(0,g.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Last Seen`})]})}),(0,g.jsx)(`tbody`,{children:T.map(e=>(0,g.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,g.jsxs)(`td`,{className:`px-5 py-3`,children:[(0,g.jsx)(`div`,{className:`font-medium text-fg`,children:e.name||`worker`}),(0,g.jsx)(`div`,{className:`font-mono text-[11px] text-faint`,children:e.id})]}),(0,g.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queues.join(`, `)||`—`}),(0,g.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-blue-400`,children:d(e.activeJobs)}),(0,g.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:d(e.processedJobs)}),(0,g.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:d(e.failedJobs)}),(0,g.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:c(e.lastSeen)})]},e.id))})]})}),S.truncated&&(0,g.jsxs)(`p`,{className:`mt-3 text-xs text-amber-400`,children:[`Showing first `,d(S.list.length),` of `,d(S.total),` `,`workers.`]}),(0,g.jsx)(m,{page:w,pageSize:_,total:S.list.length,onPageChange:x,label:`workers`})]})}export{y as Workers};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,t as n}from"./react-vendor-08inPAVO.js";import{A as r,O as i}from"./icons-BIT5aq1c.js";import{r as a}from"./StatusBadge-D-mexaga.js";import{I as o,O as s,_ as c,b as l,d as u,g as d,h as f,l as p,v as m,w as h,y as g}from"./index-X_fHGbXZ.js";import{t as _}from"./Pagination-WVfHLHDS.js";import{r as v,t as y}from"./useServerActionGuard-uiZWD3dS.js";var b=e(t(),1),x=n(),S=`No heartbeat recently — derived from lastSeen`;function C({rows:e,sort:t,busyIds:n,onSort:r,onRemove:o}){return(0,x.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,x.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,x.jsx)(`thead`,{children:(0,x.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,x.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Worker`}),(0,x.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queues`}),(0,x.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Status`}),(0,x.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Active`}),(0,x.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Processed`}),(0,x.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:(0,x.jsx)(w,{label:`Failed`,active:t?.key===`failed`?t.dir:null,onClick:()=>r(`failed`)})}),(0,x.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:(0,x.jsx)(w,{label:`Last Seen`,active:t?.key===`lastSeen`?t.dir:null,onClick:()=>r(`lastSeen`)})}),(0,x.jsx)(`th`,{className:`w-16 px-5 py-3 text-right font-medium`,children:`Actions`})]})}),(0,x.jsx)(`tbody`,{children:e.map(e=>(0,x.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,x.jsxs)(`td`,{className:`px-5 py-3`,children:[(0,x.jsx)(`div`,{className:`font-medium text-fg`,children:e.name||`worker`}),(0,x.jsx)(`div`,{className:`font-mono text-[11px] text-faint`,children:e.id})]}),(0,x.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queues.join(`, `)||`—`}),(0,x.jsx)(`td`,{className:`px-5 py-3`,children:(0,x.jsx)(`span`,{title:e.status===`active`?void 0:S,className:a(`rounded-full px-2 py-0.5 text-[11px] font-medium`,e.status===`active`?`bg-emerald-500/10 text-success`:`bg-amber-500/10 text-warning`),children:e.status})}),(0,x.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-blue-400`,children:p(e.activeJobs)}),(0,x.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:p(e.processedJobs)}),(0,x.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:p(e.failedJobs)}),(0,x.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:u(e.lastSeen)}),(0,x.jsx)(`td`,{className:`px-5 py-3`,children:(0,x.jsx)(`div`,{className:`flex justify-end`,children:e.status===`stale`&&e.activeJobs===0?(0,x.jsx)(h,{"aria-label":`Remove stale registry record for worker ${e.id}`,title:`Registry cleanup only — does not stop the worker process`,disabled:n.has(e.id),onClick:()=>o(e.id),children:(0,x.jsx)(i,{className:`size-3.5`})}):(0,x.jsx)(`span`,{className:`text-xs text-faint`,title:e.status===`stale`?`Registry cleanup is blocked while active jobs are reported`:`Only stale, idle registry records can be removed`,children:`—`})})})]},e.id))})]})})}function w({label:e,active:t,onClick:n}){return(0,x.jsxs)(`button`,{type:`button`,onClick:n,title:`Sort by ${e}`,className:a(`inline-flex items-center gap-1 uppercase tracking-wider transition-colors hover:text-fg`,t?`text-fg`:`text-faint`),children:[e,(0,x.jsx)(`span`,{"aria-hidden":`true`,children:t===`desc`?`↓`:t===`asc`?`↑`:``})]})}var T=100;function E(){let{data:e,error:t,loading:n,refetch:i}=s(async()=>(await o.workers()).data,[]),[u,h]=(0,b.useState)(new Set),[w,E]=(0,b.useState)(null),[D,O]=(0,b.useState)(null),[k,A]=(0,b.useState)(``),[j,M]=(0,b.useState)(0),N=v(`workers-pro`);if((0,b.useEffect)(()=>{h(new Set),E(null),M(0),A(``)},[N.scopeKey]),n&&!e&&!t)return(0,x.jsx)(g,{label:`Loading workers…`});if(t&&!e)return(0,x.jsxs)(`div`,{children:[(0,x.jsx)(d,{title:`Workers`,description:`Worker inventory is unavailable.`}),(0,x.jsx)(m,{error:t,onRetry:i})]});let P=e?.workers??[],F=e?.quarantinedWorkers??[],I=D?[...P].sort((e,t)=>{let n=D.key===`failed`?e.failedJobs??0:e.lastSeen??0,r=D.key===`failed`?t.failedJobs??0:t.lastSeen??0;return D.dir===`asc`?n-r:r-n}):P,L=k.trim().toLowerCase(),R=L?I.filter(e=>[e.name,e.id,e.hostname,e.status,...e.queues].some(e=>e.toLowerCase().includes(L))):I,z=Math.min(j,Math.max(0,Math.ceil(R.length/T)-1)),B=R.slice(z*T,(z+1)*T),V=e=>{M(0),O(t=>t?.key===e?{key:e,dir:t.dir===`desc`?`asc`:`desc`}:{key:e,dir:`desc`})},H=P.filter(e=>e.status===`active`).length,U=P.length-H,W=P.reduce((e,t)=>e+(t.activeJobs??0),0),G=async e=>{if(!window.confirm(`Remove the stale registry record for worker "${e}"? This does not stop the worker process. Continue only after confirming that process is stopped; Bunqueue v2.9.3 workers do not automatically re-register after their heartbeat record is removed.`))return;let t=N.begin(`worker:${e}`);if(t){h(t=>new Set(t).add(e)),E(null);try{let n=await o.unregisterWorker(e);if(y(n,`Remove stale worker registry record`),!t.isCurrent())return;E({ok:!0,text:`Removed stale registry record for ${e} ✓`}),i()}catch(e){if(!t.isCurrent())return;E({ok:!1,text:`Removal failed: ${e.message}`})}finally{t.finish()&&h(t=>{let n=new Set(t);return n.delete(e),n})}}};return(0,x.jsxs)(`div`,{children:[(0,x.jsx)(d,{title:`Workers`,description:`Registered workers and their throughput.`,live:!!e&&!t}),t&&(0,x.jsx)(l,{message:`Worker refresh failed — showing the last successful inventory.`,onRetry:i}),(0,x.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-5`,children:[(0,x.jsx)(f,{label:`Total`,value:p(P.length+F.length),compact:!0}),(0,x.jsx)(f,{label:`Active`,value:p(H),tone:`green`,compact:!0}),(0,x.jsx)(`div`,{title:S,children:(0,x.jsx)(f,{label:`Stale`,value:p(U),tone:U?`amber`:`default`,compact:!0})}),(0,x.jsx)(f,{label:`Active Jobs`,value:p(W),tone:`blue`,compact:!0}),(0,x.jsx)(f,{label:`Quarantined`,value:p(F.length),tone:F.length?`red`:`default`,compact:!0})]}),F.length>0&&(0,x.jsxs)(`div`,{role:`alert`,className:`mb-4 rounded-lg border border-danger/30 bg-danger/5 p-4`,children:[(0,x.jsxs)(`p`,{className:`text-sm font-medium text-danger`,children:[F.length,` worker registration(s) contain values accepted by Bunqueue 2.9.3 but unsafe to render. Healthy workers remain available below.`]}),(0,x.jsx)(`p`,{className:`mt-1 text-xs text-muted`,children:`Their status and active-job count are unknown, so this dashboard will not offer the registry-only removal action for them.`}),(0,x.jsx)(`ul`,{className:`mt-2 space-y-1 text-xs text-muted`,children:F.slice(0,20).map(e=>(0,x.jsxs)(`li`,{className:`truncate font-mono`,children:[`#`,e.index+1,` `,e.id??`(unaddressable id)`,` — `,e.reason]},`${e.index}:${e.id??`unknown`}`))})]}),w&&(0,x.jsx)(`div`,{className:a(`mb-3 text-sm`,w.ok?`text-success`:`text-danger`),children:w.text}),P.length>0&&(0,x.jsx)(`div`,{className:`mb-4`,children:(0,x.jsx)(`input`,{"aria-label":`Search workers`,name:`workers-search`,value:k,onInput:e=>{A(e.currentTarget.value),M(0)},placeholder:`Search workers, queues or hosts…`,className:`h-9 w-full max-w-sm rounded-lg border border-line bg-surface px-3 text-sm text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`})}),P.length===0?(0,x.jsx)(c,{icon:(0,x.jsx)(r,{}),title:F.length?`No renderable workers`:`No workers registered`,hint:F.length?`Malformed registrations are isolated above instead of taking down the inventory.`:`Workers appear here once they connect and register with the server.`}):R.length===0?(0,x.jsx)(c,{icon:(0,x.jsx)(r,{}),title:`No workers match your search`,hint:`Try a different name, ID, queue, host, or status.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(C,{rows:B,sort:D,busyIds:u,onSort:V,onRemove:e=>void G(e)}),(0,x.jsx)(_,{page:j,pageSize:T,total:R.length,onPageChange:M,label:`workers`})]})]})}export{E as WorkersPro};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{h as t,t as n}from"./react-vendor-08inPAVO.js";import{A as r,O as i}from"./icons-BIT5aq1c.js";import{r as a}from"./StatusBadge-D-mexaga.js";import{I as o,O as s,_ as c,b as l,d as u,g as d,h as f,l as p,v as m,w as h,y as g}from"./index-DwsYIYdu.js";import{t as _}from"./Pagination-CmVnmrFt.js";import{r as v,t as y}from"./useServerActionGuard-uiZWD3dS.js";var b=e(t(),1),x=n(),S=`No heartbeat recently — derived from lastSeen`;function C({rows:e,sort:t,busyIds:n,onSort:r,onRemove:o}){return(0,x.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,x.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,x.jsx)(`thead`,{children:(0,x.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,x.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Worker`}),(0,x.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queues`}),(0,x.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Status`}),(0,x.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Active`}),(0,x.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Processed`}),(0,x.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:(0,x.jsx)(w,{label:`Failed`,active:t?.key===`failed`?t.dir:null,onClick:()=>r(`failed`)})}),(0,x.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:(0,x.jsx)(w,{label:`Last Seen`,active:t?.key===`lastSeen`?t.dir:null,onClick:()=>r(`lastSeen`)})}),(0,x.jsx)(`th`,{className:`w-16 px-5 py-3 text-right font-medium`,children:`Actions`})]})}),(0,x.jsx)(`tbody`,{children:e.map(e=>(0,x.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,x.jsxs)(`td`,{className:`px-5 py-3`,children:[(0,x.jsx)(`div`,{className:`font-medium text-fg`,children:e.name||`worker`}),(0,x.jsx)(`div`,{className:`font-mono text-[11px] text-faint`,children:e.id})]}),(0,x.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queues.join(`, `)||`—`}),(0,x.jsx)(`td`,{className:`px-5 py-3`,children:(0,x.jsx)(`span`,{title:e.status===`active`?void 0:S,className:a(`rounded-full px-2 py-0.5 text-[11px] font-medium`,e.status===`active`?`bg-emerald-500/10 text-success`:`bg-amber-500/10 text-warning`),children:e.status})}),(0,x.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-blue-400`,children:p(e.activeJobs)}),(0,x.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:p(e.processedJobs)}),(0,x.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:p(e.failedJobs)}),(0,x.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:u(e.lastSeen)}),(0,x.jsx)(`td`,{className:`px-5 py-3`,children:(0,x.jsx)(`div`,{className:`flex justify-end`,children:e.status===`stale`&&e.activeJobs===0?(0,x.jsx)(h,{"aria-label":`Remove stale registry record for worker ${e.id}`,title:`Registry cleanup only — does not stop the worker process`,disabled:n.has(e.id),onClick:()=>o(e.id),children:(0,x.jsx)(i,{className:`size-3.5`})}):(0,x.jsx)(`span`,{className:`text-xs text-faint`,title:e.status===`stale`?`Registry cleanup is blocked while active jobs are reported`:`Only stale, idle registry records can be removed`,children:`—`})})})]},e.id))})]})})}function w({label:e,active:t,onClick:n}){return(0,x.jsxs)(`button`,{type:`button`,onClick:n,title:`Sort by ${e}`,className:a(`inline-flex items-center gap-1 uppercase tracking-wider transition-colors hover:text-fg`,t?`text-fg`:`text-faint`),children:[e,(0,x.jsx)(`span`,{"aria-hidden":`true`,children:t===`desc`?`↓`:t===`asc`?`↑`:``})]})}var T=100;function E(){let{data:e,error:t,loading:n,refetch:i}=s(async()=>(await o.workers()).data,[]),[u,h]=(0,b.useState)(new Set),[w,E]=(0,b.useState)(null),[D,O]=(0,b.useState)(null),[k,A]=(0,b.useState)(``),[j,M]=(0,b.useState)(0),N=v(`workers-pro`);if((0,b.useEffect)(()=>{h(new Set),E(null),M(0),A(``)},[N.scopeKey]),n&&!e&&!t)return(0,x.jsx)(g,{label:`Loading workers…`});if(t&&!e)return(0,x.jsxs)(`div`,{children:[(0,x.jsx)(d,{title:`Workers`,description:`Worker inventory is unavailable.`}),(0,x.jsx)(m,{error:t,onRetry:i})]});let P=e?.workers??[],F=e?.quarantinedWorkers??[],I=D?[...P].sort((e,t)=>{let n=D.key===`failed`?e.failedJobs??0:e.lastSeen??0,r=D.key===`failed`?t.failedJobs??0:t.lastSeen??0;return D.dir===`asc`?n-r:r-n}):P,L=k.trim().toLowerCase(),R=L?I.filter(e=>[e.name,e.id,e.hostname,e.status,...e.queues].some(e=>e.toLowerCase().includes(L))):I,z=Math.min(j,Math.max(0,Math.ceil(R.length/T)-1)),B=R.slice(z*T,(z+1)*T),V=e=>{M(0),O(t=>t?.key===e?{key:e,dir:t.dir===`desc`?`asc`:`desc`}:{key:e,dir:`desc`})},H=P.filter(e=>e.status===`active`).length,U=P.length-H,W=P.reduce((e,t)=>e+(t.activeJobs??0),0),G=async e=>{if(!window.confirm(`Remove the stale registry record for worker "${e}"? This does not stop the worker process. Continue only after confirming that process is stopped; Bunqueue v2.9.3 workers do not automatically re-register after their heartbeat record is removed.`))return;let t=N.begin(`worker:${e}`);if(t){h(t=>new Set(t).add(e)),E(null);try{let n=await o.unregisterWorker(e);if(y(n,`Remove stale worker registry record`),!t.isCurrent())return;E({ok:!0,text:`Removed stale registry record for ${e} ✓`}),i()}catch(e){if(!t.isCurrent())return;E({ok:!1,text:`Removal failed: ${e.message}`})}finally{t.finish()&&h(t=>{let n=new Set(t);return n.delete(e),n})}}};return(0,x.jsxs)(`div`,{children:[(0,x.jsx)(d,{title:`Workers`,description:`Registered workers and their throughput.`,live:!!e&&!t}),t&&(0,x.jsx)(l,{message:`Worker refresh failed — showing the last successful inventory.`,onRetry:i}),(0,x.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-5`,children:[(0,x.jsx)(f,{label:`Total`,value:p(P.length+F.length),compact:!0}),(0,x.jsx)(f,{label:`Active`,value:p(H),tone:`green`,compact:!0}),(0,x.jsx)(`div`,{title:S,children:(0,x.jsx)(f,{label:`Stale`,value:p(U),tone:U?`amber`:`default`,compact:!0})}),(0,x.jsx)(f,{label:`Active Jobs`,value:p(W),tone:`blue`,compact:!0}),(0,x.jsx)(f,{label:`Quarantined`,value:p(F.length),tone:F.length?`red`:`default`,compact:!0})]}),F.length>0&&(0,x.jsxs)(`div`,{role:`alert`,className:`mb-4 rounded-lg border border-danger/30 bg-danger/5 p-4`,children:[(0,x.jsxs)(`p`,{className:`text-sm font-medium text-danger`,children:[F.length,` worker registration(s) contain values accepted by Bunqueue 2.9.3 but unsafe to render. Healthy workers remain available below.`]}),(0,x.jsx)(`p`,{className:`mt-1 text-xs text-muted`,children:`Their status and active-job count are unknown, so this dashboard will not offer the registry-only removal action for them.`}),(0,x.jsx)(`ul`,{className:`mt-2 space-y-1 text-xs text-muted`,children:F.slice(0,20).map(e=>(0,x.jsxs)(`li`,{className:`truncate font-mono`,children:[`#`,e.index+1,` `,e.id??`(unaddressable id)`,` — `,e.reason]},`${e.index}:${e.id??`unknown`}`))})]}),w&&(0,x.jsx)(`div`,{className:a(`mb-3 text-sm`,w.ok?`text-success`:`text-danger`),children:w.text}),P.length>0&&(0,x.jsx)(`div`,{className:`mb-4`,children:(0,x.jsx)(`input`,{"aria-label":`Search workers`,name:`workers-search`,value:k,onInput:e=>{A(e.currentTarget.value),M(0)},placeholder:`Search workers, queues or hosts…`,className:`h-9 w-full max-w-sm rounded-lg border border-line bg-surface px-3 text-sm text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`})}),P.length===0?(0,x.jsx)(c,{icon:(0,x.jsx)(r,{}),title:F.length?`No renderable workers`:`No workers registered`,hint:F.length?`Malformed registrations are isolated above instead of taking down the inventory.`:`Workers appear here once they connect and register with the server.`}):R.length===0?(0,x.jsx)(c,{icon:(0,x.jsx)(r,{}),title:`No workers match your search`,hint:`Try a different name, ID, queue, host, or status.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(C,{rows:B,sort:D,busyIds:u,onSort:V,onRemove:e=>void G(e)}),(0,x.jsx)(_,{page:j,pageSize:T,total:R.length,onPageChange:M,label:`workers`})]})]})}export{E as WorkersPro};