bunqueue-dashboard 0.0.36 → 0.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +20 -7
  2. package/agent/backup/resultValidation.ts +1 -1
  3. package/agent/backup/routes.ts +4 -3
  4. package/agent/flow/routes.ts +7 -6
  5. package/agent/index.ts +17 -4
  6. package/agent/managedTarget.ts +41 -2
  7. package/agent/manager/config.ts +1 -1
  8. package/agent/queue/routes.ts +21 -14
  9. package/agent/server/controlRoutes.ts +39 -7
  10. package/agent/server/controlTarget.ts +116 -0
  11. package/agent/server/errors.ts +1 -0
  12. package/agent/server/handler.ts +10 -1
  13. package/agent/server/router.ts +19 -8
  14. package/agent/server/types.ts +7 -0
  15. package/agent/server.ts +10 -0
  16. package/agent/workflow/runtimeRoutes.ts +5 -4
  17. package/agent/workflows.ts +1 -1
  18. package/dist/.vite/manifest.json +207 -207
  19. package/dist/assets/{AddJob-UUa2fSXE.js → AddJob-CWkkVHmf.js} +1 -1
  20. package/dist/assets/{Alerts-7oGYfQMb.js → Alerts-Gh1pVbqj.js} +1 -1
  21. package/dist/assets/{Benchmark-C2NFp_kj.js → Benchmark-Dir2A1CQ.js} +1 -1
  22. package/dist/assets/{BulkAddJobs-CL4yBae-.js → BulkAddJobs-Di_IgRSH.js} +1 -1
  23. package/dist/assets/{CopilotPanel-BQ2Cgo9p.js → CopilotPanel-Db5nYpo1.js} +1 -1
  24. package/dist/assets/{Cron-DfWBhoBf.js → Cron-BRgWcBGk.js} +1 -1
  25. package/dist/assets/{CronManager-DAK7RSOX.js → CronManager-CbM0x_s0.js} +1 -1
  26. package/dist/assets/{Database-DqL7giEj.js → Database-BeoEreW0.js} +1 -1
  27. package/dist/assets/{Diagnostics-D98YwN-6.js → Diagnostics-Cw9iJ84f.js} +1 -1
  28. package/dist/assets/{Dlq-BHmA5PTI.js → Dlq-DfCg04Jd.js} +1 -1
  29. package/dist/assets/{DlqControl-DihxvP-i.js → DlqControl-BRCkUXvb.js} +1 -1
  30. package/dist/assets/{DlqPro-ncgnDtpE.js → DlqPro-BHJwBYsN.js} +1 -1
  31. package/dist/assets/{Flows-B5N5Cil0.js → Flows-BAzbFP_W.js} +2 -2
  32. package/dist/assets/{JobInspector-B40nFiGh.js → JobInspector-qvW_APO6.js} +2 -2
  33. package/dist/assets/{Jobs-Bla3IEef.js → Jobs-URpnFjC6.js} +1 -1
  34. package/dist/assets/{JobsPro-CnczVx7x.js → JobsPro-pQ_RFSU3.js} +1 -1
  35. package/dist/assets/{Logs-T91Q3cH0.js → Logs-C5jX2OPE.js} +1 -1
  36. package/dist/assets/{LogsPro-CMn6-Wwv.js → LogsPro-Cq_npmmS.js} +1 -1
  37. package/dist/assets/{McpServer-BQBabwW-.js → McpServer-DtCTmQBu.js} +2 -2
  38. package/dist/assets/{Metrics-DxT_RI2B.js → Metrics-BdxitePr.js} +1 -1
  39. package/dist/assets/{MetricsPro-Cjen-nAP.js → MetricsPro-orHfW0mg.js} +1 -1
  40. package/dist/assets/{Overview-XN2ej8ph.js → Overview-DaNns1aj.js} +1 -1
  41. package/dist/assets/{QueueActions-C-Aferd6.js → QueueActions-jiTzndPH.js} +1 -1
  42. package/dist/assets/{QueueControl-B8Q9NX6t.js → QueueControl-l5bSdMgb.js} +1 -1
  43. package/dist/assets/{QueueDetail-BMhG0jUB.js → QueueDetail-URK2pjtH.js} +1 -1
  44. package/dist/assets/{QueueDetailPro-BKTTyLR4.js → QueueDetailPro-C9M5CV4K.js} +1 -1
  45. package/dist/assets/{Queues-COqPMoY9.js → Queues-DeLXlww2.js} +1 -1
  46. package/dist/assets/{QueuesOverview-pWdrPy8Z.js → QueuesOverview-DoQ-MUfT.js} +1 -1
  47. package/dist/assets/{S3Backup-BmsZ8xtq.js → S3Backup-D2agV9_z.js} +1 -1
  48. package/dist/assets/{S3BackupPro-AtlsPUJL.js → S3BackupPro--WSZWTQn.js} +3 -3
  49. package/dist/assets/{ServerControl-D3XwHr72.js → ServerControl-QVd6m_iR.js} +3 -3
  50. package/dist/assets/{Settings-BofKZoHn.js → Settings-CiJRj_SM.js} +1 -1
  51. package/dist/assets/{Usage-DAR9E22v.js → Usage-DbHJgA4t.js} +1 -1
  52. package/dist/assets/{UsagePro-Bc30N2Lo.js → UsagePro-LoPo3k1L.js} +1 -1
  53. package/dist/assets/{Webhooks-Bg2k1PU4.js → Webhooks-CuzIJHwk.js} +1 -1
  54. package/dist/assets/{Workers-BqUZMJVQ.js → Workers-BpUgpwUH.js} +1 -1
  55. package/dist/assets/{WorkersPro-C9aSadUh.js → WorkersPro-BYY0P1Pt.js} +1 -1
  56. package/dist/assets/{Workflows-BEFMfHmo.js → Workflows-ByJw4FFH.js} +1 -1
  57. package/dist/assets/{api-CQ5Z7xR7.js → api-V_sVpHDo.js} +1 -1
  58. package/dist/assets/{bq-BeBxa743.js → bq-DYmbVkgR.js} +1 -1
  59. package/dist/assets/{connectionStore-DbBYqHEY.js → connectionStore-CKFQrxDo.js} +1 -1
  60. package/dist/assets/{controlConnectionEpoch-CFSO6237.js → controlConnectionEpoch-JM4omZ6j.js} +1 -1
  61. package/dist/assets/{flowMutationSafety-CoOp94wS.js → flowMutationSafety-DObp9nJo.js} +1 -1
  62. package/dist/assets/index-D64v2vNO.js +8 -0
  63. package/dist/assets/{install-Cd9Is10G.js → install-jXi1SOYY.js} +1 -1
  64. package/dist/assets/{responses-kPO4rSu5.js → responses-CBLyy1Ob.js} +1 -1
  65. package/dist/assets/{toastStore-CS_9Xndn.js → toastStore-B7n0zS0y.js} +1 -1
  66. package/dist/assets/{upstreamPaths-D_LPsv7b.js → upstreamPaths-CDVsu6IM.js} +1 -1
  67. package/dist/assets/{usePolledData-DzlUpBOO.js → usePolledData-c53tx1jw.js} +1 -1
  68. package/dist/assets/{useServerActionGuard-BlH-Kso1.js → useServerActionGuard-OTv6_fU0.js} +1 -1
  69. package/dist/assets/{useThroughputSeries-C2pa1Wd_.js → useThroughputSeries-DWHQl7cM.js} +1 -1
  70. package/dist/index.html +7 -7
  71. package/package.json +5 -3
  72. package/scripts/embedded.gen.ts +160 -160
  73. package/scripts/serve.ts +38 -7
  74. package/scripts/serveHandler.ts +27 -7
  75. package/scripts/servePolicy.ts +54 -0
  76. package/dist/assets/index-Cui9IwWy.js +0 -8
@@ -1 +1 @@
1
- import{i as e,t}from"./cn-zFEt5SO8.js";import{g as n,r,t as i}from"./react-vendor-CyjgmGTq.js";import{t as a}from"./bq-BeBxa743.js";import{t as o}from"./toastStore-CS_9Xndn.js";import{S as s,T as c,b as l,n as u,x as d}from"./icons-CIvFfU2b.js";import{n as f}from"./usePolledData-DzlUpBOO.js";import{n as p,t as m}from"./Button-BPqpRZJD.js";import{i as h,n as g,r as _}from"./feedback-BnGE2oW2.js";import{t as v}from"./PageHeader-BXlZSBcc.js";import{s as y}from"./format-Cg7VCIZW.js";import{n as b}from"./index-Cui9IwWy.js";import{t as x}from"./Pagination-Q-vf4hsX.js";import{r as S,t as C}from"./useServerActionGuard-BlH-Kso1.js";import{t as w}from"./promisePool-BVfQ9n9Q.js";var T=e(n(),1),E=i(),D=[[`waiting`,`Waiting`],[`prioritized`,`Prioritized`],[`active`,`Active`],[`completed`,`Completed`],[`failed`,`Failed`],[`delayed`,`Delayed`]];function O({rows:e,hasData:n,error:i,search:a,sortCol:o,sortDir:c,bulkBusy:f,busy:m,onSort:h,onToggle:g}){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":o===e?c===`desc`?`descending`:`ascending`:void 0,className:`px-5 py-3 text-right font-medium`,children:(0,E.jsxs)(`button`,{type:`button`,onClick:()=>h(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,o===e&&(0,E.jsx)(`span`,{"aria-hidden":`true`,children:c===`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:!n&&i?(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 — `,i.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 n=f||m.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)(r,{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)(s,{className:`size-4 text-faint`}),e.name]})}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-warning`,children:y(e.counts.waiting)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-orange-400`,children:y(e.counts.prioritized)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-blue-400`,children:y(e.counts.active)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-success`,children:y(e.counts.completed)}),(0,E.jsx)(`td`,{className:t(`px-5 py-3 text-right tnum`,e.counts.failed?`text-danger`:`text-muted`),children:y(e.counts.failed)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:y(e.counts.delayed)}),(0,E.jsx)(`td`,{className:`px-5 py-3`,children:(0,E.jsxs)(`span`,{className:t(`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)(p,{"aria-label":e.paused?`Resume queue`:`Pause queue`,disabled:n,onClick:t=>{t.stopPropagation(),g(e)},children:e.paused?(0,E.jsx)(d,{className:`size-3.5 text-success`}):(0,E.jsx)(l,{className:`size-3.5 text-warning`})}),(0,E.jsx)(u,{className:`size-4 text-faint opacity-0 transition-opacity group-hover:opacity-100`})]})})]},e.name)})})]})})}var k=6,A=15;function j(){let[e,n]=(0,T.useState)(``),[r,i]=(0,T.useState)(0),[s,u]=(0,T.useState)(new Set),[p,D]=(0,T.useState)(!1),[j,M]=(0,T.useState)(null),[N,P]=(0,T.useState)(null),[F,I]=(0,T.useState)(`desc`),L=S(`queues-overview`);(0,T.useEffect)(()=>{u(new Set),D(!1),M(null)},[L.scopeKey]);let{data:R,error:z,loading:B,refetch:V}=f(()=>a.queuesSummary(),[]),H=R??[],U=e=>{N===e?F===`desc`?I(`asc`):P(null):(P(e),I(`desc`)),i(0)},W=(0,T.useMemo)(()=>{let t=e.trim().toLowerCase(),n=[...t?H.filter(e=>e.name.toLowerCase().includes(t)):H].sort((e,t)=>e.name.localeCompare(t.name));if(N){let e=F===`desc`?-1:1;n.sort((t,n)=>e*(t.counts[N]-n.counts[N]))}return n},[H,e,N,F]),G=(0,T.useMemo)(()=>H.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}),[H]),K=Math.max(1,Math.ceil(W.length/A)),q=Math.min(r,K-1),J=W.slice(q*A,q*A+A),Y=async e=>{let t=L.begin(`queue:${e.name}`);if(t){u(t=>new Set(t).add(e.name)),M(null);try{if(C(await(e.paused?a.resume(e.name):a.pause(e.name)),e.paused?`Resume queue`:`Pause queue`),!t.isCurrent())return;M({ok:!0,text:`${e.name} ${e.paused?`resumed`:`paused`} ✓`}),V()}catch(n){if(!t.isCurrent())return;M({ok:!1,text:n.message}),o.error(`Failed to ${e.paused?`resume`:`pause`} ${e.name}`,n.message)}finally{t.finish()&&u(t=>{let n=new Set(t);return n.delete(e.name),n})}}},X=async e=>{let t=H.filter(t=>e===`pause`?!t.paused:t.paused);if(t.length===0){o.info(`No queues to ${e}`);return}if(!window.confirm(`${e===`pause`?`Pause`:`Resume`} ${t.length} queue(s)?`))return;let n=L.begin([`bulk`,...H.map(e=>`queue:${e.name}`)]);if(n){D(!0),M(null);try{let r=await w(t,k,async t=>{if(!n.isCurrent())throw Error(`Queue action target changed`);C(e===`pause`?await a.pause(t.name):await a.resume(t.name),`${e===`pause`?`Pause`:`Resume`} ${t.name}`)});if(!n.isCurrent())return;let i=r.filter(e=>e.status===`rejected`).length,s=`${e===`pause`?`Paused`:`Resumed`} ${t.length-i}/${t.length} queues${i?`, ${i} failed`:``}`;M({ok:i===0,text:s}),i===0?o.success(s):o.error(s),V()}finally{n.finish()&&D(!1)}}};return B&&!R&&!z?(0,E.jsx)(_,{label:`Loading queues…`}):z&&!R?(0,E.jsxs)(`div`,{children:[(0,E.jsx)(v,{title:`Queues`,description:`Queue inventory unavailable`}),(0,E.jsx)(g,{error:z,onRetry:V})]}):(0,E.jsxs)(`div`,{children:[(0,E.jsx)(v,{title:`Queues`,description:R?`${H.length} queues`:`Queue inventory unavailable`,live:!!R&&!z,actions:H.length>0?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(m,{variant:`warning`,size:`sm`,disabled:p||s.size>0||G.paused>=H.length,onClick:()=>X(`pause`),children:[(0,E.jsx)(l,{className:`size-3.5`}),` Pause all`]}),(0,E.jsxs)(m,{variant:`success`,size:`sm`,disabled:p||s.size>0||G.paused===0,onClick:()=>X(`resume`),children:[(0,E.jsx)(d,{className:`size-3.5`}),` Resume all`]})]}):void 0}),z&&(0,E.jsx)(h,{message:`Queue refresh failed — showing the last successful inventory.`,onRetry:V}),(0,E.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-5`,children:[(0,E.jsx)(b,{label:`Waiting`,value:y(G.waiting),tone:`amber`,compact:!0}),(0,E.jsx)(b,{label:`Prioritized`,value:y(G.prioritized),tone:`amber`,compact:!0}),(0,E.jsx)(b,{label:`Active`,value:y(G.active),tone:`blue`,compact:!0}),(0,E.jsx)(b,{label:`Failed`,value:y(G.failed),tone:G.failed?`red`:`default`,compact:!0}),(0,E.jsx)(b,{label:`Paused`,value:y(G.paused),tone:G.paused?`amber`:`default`,compact:!0})]}),(0,E.jsxs)(`div`,{className:`relative mb-4 max-w-sm`,children:[(0,E.jsx)(c,{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=>{n(e.target.value),i(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`})]}),j&&(0,E.jsx)(`div`,{role:`status`,className:t(`mb-3 text-sm`,j.ok?`text-success`:`text-danger`),children:j.text}),(0,E.jsx)(O,{rows:J,hasData:!!R,error:z,search:e,sortCol:N,sortDir:F,bulkBusy:p,busy:s,onSort:U,onToggle:e=>void Y(e)}),(0,E.jsx)(x,{page:q,pageSize:A,total:W.length,onPageChange:i,label:`queues`})]})}export{j as QueuesOverview};
1
+ import{i as e,t}from"./cn-zFEt5SO8.js";import{g as n,r,t as i}from"./react-vendor-CyjgmGTq.js";import{t as a}from"./bq-DYmbVkgR.js";import{t as o}from"./toastStore-B7n0zS0y.js";import{S as s,T as c,b as l,n as u,x as d}from"./icons-CIvFfU2b.js";import{n as f}from"./usePolledData-c53tx1jw.js";import{n as p,t as m}from"./Button-BPqpRZJD.js";import{i as h,n as g,r as _}from"./feedback-BnGE2oW2.js";import{t as v}from"./PageHeader-BXlZSBcc.js";import{s as y}from"./format-Cg7VCIZW.js";import{n as b}from"./index-D64v2vNO.js";import{t as x}from"./Pagination-Q-vf4hsX.js";import{r as S,t as C}from"./useServerActionGuard-OTv6_fU0.js";import{t as w}from"./promisePool-BVfQ9n9Q.js";var T=e(n(),1),E=i(),D=[[`waiting`,`Waiting`],[`prioritized`,`Prioritized`],[`active`,`Active`],[`completed`,`Completed`],[`failed`,`Failed`],[`delayed`,`Delayed`]];function O({rows:e,hasData:n,error:i,search:a,sortCol:o,sortDir:c,bulkBusy:f,busy:m,onSort:h,onToggle:g}){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":o===e?c===`desc`?`descending`:`ascending`:void 0,className:`px-5 py-3 text-right font-medium`,children:(0,E.jsxs)(`button`,{type:`button`,onClick:()=>h(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,o===e&&(0,E.jsx)(`span`,{"aria-hidden":`true`,children:c===`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:!n&&i?(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 — `,i.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 n=f||m.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)(r,{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)(s,{className:`size-4 text-faint`}),e.name]})}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-warning`,children:y(e.counts.waiting)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-orange-400`,children:y(e.counts.prioritized)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-blue-400`,children:y(e.counts.active)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-success`,children:y(e.counts.completed)}),(0,E.jsx)(`td`,{className:t(`px-5 py-3 text-right tnum`,e.counts.failed?`text-danger`:`text-muted`),children:y(e.counts.failed)}),(0,E.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:y(e.counts.delayed)}),(0,E.jsx)(`td`,{className:`px-5 py-3`,children:(0,E.jsxs)(`span`,{className:t(`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)(p,{"aria-label":e.paused?`Resume queue`:`Pause queue`,disabled:n,onClick:t=>{t.stopPropagation(),g(e)},children:e.paused?(0,E.jsx)(d,{className:`size-3.5 text-success`}):(0,E.jsx)(l,{className:`size-3.5 text-warning`})}),(0,E.jsx)(u,{className:`size-4 text-faint opacity-0 transition-opacity group-hover:opacity-100`})]})})]},e.name)})})]})})}var k=6,A=15;function j(){let[e,n]=(0,T.useState)(``),[r,i]=(0,T.useState)(0),[s,u]=(0,T.useState)(new Set),[p,D]=(0,T.useState)(!1),[j,M]=(0,T.useState)(null),[N,P]=(0,T.useState)(null),[F,I]=(0,T.useState)(`desc`),L=S(`queues-overview`);(0,T.useEffect)(()=>{u(new Set),D(!1),M(null)},[L.scopeKey]);let{data:R,error:z,loading:B,refetch:V}=f(()=>a.queuesSummary(),[]),H=R??[],U=e=>{N===e?F===`desc`?I(`asc`):P(null):(P(e),I(`desc`)),i(0)},W=(0,T.useMemo)(()=>{let t=e.trim().toLowerCase(),n=[...t?H.filter(e=>e.name.toLowerCase().includes(t)):H].sort((e,t)=>e.name.localeCompare(t.name));if(N){let e=F===`desc`?-1:1;n.sort((t,n)=>e*(t.counts[N]-n.counts[N]))}return n},[H,e,N,F]),G=(0,T.useMemo)(()=>H.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}),[H]),K=Math.max(1,Math.ceil(W.length/A)),q=Math.min(r,K-1),J=W.slice(q*A,q*A+A),Y=async e=>{let t=L.begin(`queue:${e.name}`);if(t){u(t=>new Set(t).add(e.name)),M(null);try{if(C(await(e.paused?a.resume(e.name):a.pause(e.name)),e.paused?`Resume queue`:`Pause queue`),!t.isCurrent())return;M({ok:!0,text:`${e.name} ${e.paused?`resumed`:`paused`} ✓`}),V()}catch(n){if(!t.isCurrent())return;M({ok:!1,text:n.message}),o.error(`Failed to ${e.paused?`resume`:`pause`} ${e.name}`,n.message)}finally{t.finish()&&u(t=>{let n=new Set(t);return n.delete(e.name),n})}}},X=async e=>{let t=H.filter(t=>e===`pause`?!t.paused:t.paused);if(t.length===0){o.info(`No queues to ${e}`);return}if(!window.confirm(`${e===`pause`?`Pause`:`Resume`} ${t.length} queue(s)?`))return;let n=L.begin([`bulk`,...H.map(e=>`queue:${e.name}`)]);if(n){D(!0),M(null);try{let r=await w(t,k,async t=>{if(!n.isCurrent())throw Error(`Queue action target changed`);C(e===`pause`?await a.pause(t.name):await a.resume(t.name),`${e===`pause`?`Pause`:`Resume`} ${t.name}`)});if(!n.isCurrent())return;let i=r.filter(e=>e.status===`rejected`).length,s=`${e===`pause`?`Paused`:`Resumed`} ${t.length-i}/${t.length} queues${i?`, ${i} failed`:``}`;M({ok:i===0,text:s}),i===0?o.success(s):o.error(s),V()}finally{n.finish()&&D(!1)}}};return B&&!R&&!z?(0,E.jsx)(_,{label:`Loading queues…`}):z&&!R?(0,E.jsxs)(`div`,{children:[(0,E.jsx)(v,{title:`Queues`,description:`Queue inventory unavailable`}),(0,E.jsx)(g,{error:z,onRetry:V})]}):(0,E.jsxs)(`div`,{children:[(0,E.jsx)(v,{title:`Queues`,description:R?`${H.length} queues`:`Queue inventory unavailable`,live:!!R&&!z,actions:H.length>0?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(m,{variant:`warning`,size:`sm`,disabled:p||s.size>0||G.paused>=H.length,onClick:()=>X(`pause`),children:[(0,E.jsx)(l,{className:`size-3.5`}),` Pause all`]}),(0,E.jsxs)(m,{variant:`success`,size:`sm`,disabled:p||s.size>0||G.paused===0,onClick:()=>X(`resume`),children:[(0,E.jsx)(d,{className:`size-3.5`}),` Resume all`]})]}):void 0}),z&&(0,E.jsx)(h,{message:`Queue refresh failed — showing the last successful inventory.`,onRetry:V}),(0,E.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-5`,children:[(0,E.jsx)(b,{label:`Waiting`,value:y(G.waiting),tone:`amber`,compact:!0}),(0,E.jsx)(b,{label:`Prioritized`,value:y(G.prioritized),tone:`amber`,compact:!0}),(0,E.jsx)(b,{label:`Active`,value:y(G.active),tone:`blue`,compact:!0}),(0,E.jsx)(b,{label:`Failed`,value:y(G.failed),tone:G.failed?`red`:`default`,compact:!0}),(0,E.jsx)(b,{label:`Paused`,value:y(G.paused),tone:G.paused?`amber`:`default`,compact:!0})]}),(0,E.jsxs)(`div`,{className:`relative mb-4 max-w-sm`,children:[(0,E.jsx)(c,{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=>{n(e.target.value),i(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`})]}),j&&(0,E.jsx)(`div`,{role:`status`,className:t(`mb-3 text-sm`,j.ok?`text-success`:`text-danger`),children:j.text}),(0,E.jsx)(O,{rows:J,hasData:!!R,error:z,search:e,sortCol:N,sortDir:F,bulkBusy:p,busy:s,onSort:U,onToggle:e=>void Y(e)}),(0,E.jsx)(x,{page:q,pageSize:A,total:W.length,onPageChange:i,label:`queues`})]})}export{j as QueuesOverview};
@@ -1 +1 @@
1
- import{t as e}from"./react-vendor-CyjgmGTq.js";import{t}from"./api-CQ5Z7xR7.js";import{n}from"./usePolledData-DzlUpBOO.js";import{n as r,t as i}from"./Card-C7NMhqUt.js";import{i as a,n as o,r as s}from"./feedback-BnGE2oW2.js";import{t as c}from"./PageHeader-BXlZSBcc.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)(a,{message:`Storage refresh failed — showing the last successful status.`,onRetry:p}),(0,l.jsx)(c,{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)(i,{children:[(0,l.jsx)(r,{title:`Storage status`}),d&&!e?(0,l.jsx)(o,{error:d,onRetry:p}):f&&!e?(0,l.jsx)(s,{}):(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)(i,{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-CyjgmGTq.js";import{t}from"./api-V_sVpHDo.js";import{n}from"./usePolledData-c53tx1jw.js";import{n as r,t as i}from"./Card-C7NMhqUt.js";import{i as a,n as o,r as s}from"./feedback-BnGE2oW2.js";import{t as c}from"./PageHeader-BXlZSBcc.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)(a,{message:`Storage refresh failed — showing the last successful status.`,onRetry:p}),(0,l.jsx)(c,{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)(i,{children:[(0,l.jsx)(r,{title:`Storage status`}),d&&!e?(0,l.jsx)(o,{error:d,onRetry:p}):f&&!e?(0,l.jsx)(s,{}):(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)(i,{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{i as e}from"./cn-zFEt5SO8.js";import{g as t,t as n}from"./react-vendor-CyjgmGTq.js";import{c as r,i,l as a,o,u as s}from"./connectionStore-DbBYqHEY.js";import{o as c,t as l}from"./bq-BeBxa743.js";import{w as u}from"./icons-CIvFfU2b.js";import{n as d}from"./usePolledData-DzlUpBOO.js";import{t as f}from"./Button-BPqpRZJD.js";import{t as p}from"./Card-C7NMhqUt.js";import{t as m}from"./PageHeader-BXlZSBcc.js";import{a as h}from"./index-Cui9IwWy.js";import{a as g,n as _,r as v,t as y}from"./form-tC20r4Ma.js";var b=e(t(),1),ee=`bq-dash-s3`,x=2,S=[`disabled`,`6h`,`12h`,`24h`],C={endpoint:``,region:`us-east-1`,bucket:``,schedule:`disabled`,pathPrefix:``,virtualHostedStyle:`auto`,retention:7};function w(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function T(e,t,n){return typeof e==`string`&&e.length<=n?e:t}function E(e){return S.includes(e)?e:`disabled`}function D(e){return e===`virtual-hosted`||e===`path-style`?e:`auto`}function O(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=1&&e<=1e6?e:C.retention}function k(e){let t=w(e)?e:{};return{endpoint:T(t.endpoint,C.endpoint,2048),region:T(t.region,C.region,128),bucket:T(t.bucket,C.bucket,255),schedule:E(t.schedule),pathPrefix:T(t.pathPrefix,C.pathPrefix,1024),virtualHostedStyle:D(t.virtualHostedStyle),retention:O(t.retention)}}function A(e){return k(e)}function j(){try{return globalThis.localStorage??null}catch{return null}}function M(e){try{let t=JSON.parse(e),n=w(t)?t:{},r=k(`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:x})}}catch{return null}}var te={getItem(e){let t=j();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=M(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{j()?.setItem(e,t)}catch{}},removeItem(e){try{j()?.removeItem(e)}catch{}}},ne=s()(a(e=>({...C,accessKeyId:``,secretAccessKey:``,sessionToken:``,set:t=>e(e=>{let n={...e,...t};return{...k(n),accessKeyId:T(n.accessKeyId,``,512),secretAccessKey:T(n.secretAccessKey,``,2048),sessionToken:T(n.sessionToken,``,4096)}})}),{name:ee,version:x,storage:r(()=>te),partialize:A,migrate:k,merge:(e,t)=>({...t,...k(e),accessKeyId:``,secretAccessKey:``,sessionToken:``})})),N=new Set([`enabled`,`bucket`,`endpoint`,`interval`,`retention`]),P=new Set([`key`,`size`,`date`]);function F(e){let t=L(e,N,`Backup status`);return typeof t.enabled!=`boolean`&&B(`Backup status`),{enabled:t.enabled,bucket:R(t.bucket,`Backup status bucket`,1024),endpoint:R(t.endpoint,`Backup status endpoint`,4096),interval:R(t.interval,`Backup status interval`,128),retention:R(t.retention,`Backup status retention`,128)}}function I(e){(!Array.isArray(e)||e.length>2e4)&&B(`Backup list`);let t=new Set,n=0;return e.map((e,r)=>{let i=L(e,P,`Backup list item ${r}`),a=R(i.key,`Backup list item ${r} key`,2048),o=R(i.size,`Backup list item ${r} size`,128),s=R(i.date,`Backup list item ${r} date`,128);return n+=a.length+o.length+s.length,(n>2*1024*1024||t.has(a)||!z(s))&&B(`Backup list item ${r}`),t.add(a),{key:a,size:o,date:s}})}function L(e,t,n){(!e||typeof e!=`object`||Array.isArray(e))&&B(n);let r=e;return Object.keys(r).some(e=>!t.has(e))&&B(n),r}function R(e,t,n){return(typeof e!=`string`||e.length<1||e.length>n)&&B(t),e}function z(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 B(e){throw Error(`${e} returned an invalid Bunqueue 2.8.57 contract`)}function V(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 H=e=>`${e}?target=${encodeURIComponent(i())}`,U=e=>({method:`POST`,headers:e===void 0?void 0:{"Content-Type":`application/json`},body:e===void 0?void 0:JSON.stringify(e)}),W=async(e,t)=>(await c(H(e),t)).result,G={status:()=>W(`/backup/status`),list:()=>W(`/backup/list`),backupNow:()=>W(`/backup/now`,U()),restore:(e,t)=>W(`/backup/restore`,U({key:e,database:t})),configure:e=>W(`/backup/configure`,U({environment:e})),restoreContext:async()=>{let e=await c(`/control/status`);return{serverStatus:e.status,database:e.db??null}}},K=n();function q({environmentText:e,repository:t=G}){let n=d(()=>X(t),[t],{intervalMs:15e3}),[r,i]=(0,b.useState)(``),[a,o]=(0,b.useState)(``),[s,c]=(0,b.useState)(``),l=(0,b.useRef)(!1),u=async(e,t)=>{if(!l.current){l.current=!0,i(e),o(``),c(``);try{let r=(await t())?.message;c(r??`${e} completed.`),await n.refetch()}catch(e){o(e instanceof Error?e.message:String(e))}finally{l.current=!1,i(``)}}},f=()=>{e&&window.confirm(`Apply this S3 configuration to the managed server? A restart is required.`)&&u(`Configuration`,()=>t.configure(V(e)))},p=()=>{window.confirm(`Create a transactionally consistent S3 backup now?`)&&u(`Backup`,()=>t.backupNow())},m=e=>{let r=n.data?.context?.database;!r||n.data?.context?.serverStatus!==`stopped`||window.prompt(`Type RESTORE to replace ${r.path} with ${e}`)===`RESTORE`&&u(`Restore`,()=>t.restore(e,r))},h=n.data;return(0,K.jsxs)(`section`,{className:`mt-6 overflow-hidden rounded-lg border border-line bg-surface`,children:[(0,K.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-3 border-b border-line px-4 py-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:`Live backup operations`}),(0,K.jsx)(`p`,{className:`mt-1 text-xs text-faint`,children:`Official Bunqueue 2.8.57 backup CLI, executed by the local control agent.`})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,disabled:!e||!!r,onClick:f,className:`rounded-md border border-line px-3 py-2 text-xs text-muted disabled:opacity-40`,children:`Apply configuration`}),(0,K.jsx)(`button`,{type:`button`,disabled:!!r,onClick:p,className:`rounded-md bg-accent px-3 py-2 text-xs font-medium text-accent-fg disabled:opacity-40`,children:r===`Backup`?`Backing up…`:`Backup now`}),(0,K.jsx)(`button`,{type:`button`,disabled:n.loading,onClick:()=>void n.refetch(),className:`rounded-md border border-line px-3 py-2 text-xs text-muted disabled:opacity-40`,children:`Refresh`})]})]}),h?.status&&(0,K.jsx)(J,{status:h.status,context:h.context}),a||h?.errors.length?(0,K.jsx)(`div`,{role:`alert`,className:`border-b border-line px-4 py-3 text-xs text-danger`,children:a||h?.errors.join(` · `)}):null,s&&(0,K.jsx)(`div`,{role:`status`,className:`border-b border-line px-4 py-3 text-xs text-success`,children:s}),(0,K.jsx)(Y,{rows:h?.backups??[],canRestore:h?.context?.serverStatus===`stopped`&&!!h.context.database,busy:!!r,onRestore:m})]})}function J({status:e,context:t}){return(0,K.jsx)(`dl`,{className:`grid border-b border-line sm:grid-cols-2 xl:grid-cols-5`,children:[[`Scheduler`,e.enabled?`Enabled after restart`:`Disabled`],[`Bucket`,e.bucket||`—`],[`Endpoint`,e.endpoint],[`Retention`,e.retention],[`Server`,t?.serverStatus??`Unknown`]].map(([e,t])=>(0,K.jsxs)(`div`,{className:`border-b border-line px-4 py-3 last:border-b-0 xl:border-r xl:border-b-0`,children:[(0,K.jsx)(`dt`,{className:`text-[10px] uppercase tracking-wider text-faint`,children:e}),(0,K.jsx)(`dd`,{className:`mt-1 truncate text-xs text-fg`,title:t,children:t})]},e))})}function Y({rows:e,canRestore:t,busy:n,onRestore:r}){return e.length?(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full min-w-[680px] text-left text-xs`,children:[(0,K.jsx)(`thead`,{className:`border-b border-line text-[10px] uppercase tracking-wider text-faint`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Object key`}),(0,K.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Size`}),(0,K.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Created`}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-right font-medium`,children:`Restore`})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-line`,children:e.map(e=>(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`td`,{className:`max-w-md truncate px-4 py-3 font-mono text-fg`,title:e.key,children:e.key}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-muted`,children:e.size}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-muted`,children:e.date}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-right`,children:(0,K.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,K.jsx)(`p`,{className:`px-4 py-8 text-center text-sm text-muted`,children:`No backup objects returned.`})}async function X(e){let[t,n,r]=await Promise.allSettled([e.status().then(e=>F(e.data)),e.list().then(e=>I(e.data)),e.restoreContext()]),i=[t,n,r].filter(e=>e.status===`rejected`).map(e=>e.reason instanceof Error?e.reason.message:String(e.reason));return{status:t.status===`fulfilled`?t.value:void 0,backups:n.status===`fulfilled`?n.value:[],context:r.status===`fulfilled`?r.value:void 0,errors:i}}function re(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.baseUrl,e.token]),Q={"6h":360*60*1e3,"12h":720*60*1e3,"24h":1440*60*1e3};function $(e,t){return`${e}=${typeof t==`string`?JSON.stringify(t):String(t)}`}function ie(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:$(`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=[$(`S3_BACKUP_ENABLED`,!0),$(`S3_ACCESS_KEY_ID`,a),$(`S3_SECRET_ACCESS_KEY`,o),$(`S3_BUCKET`,i),$(`S3_REGION`,r),$(`S3_BACKUP_RETENTION`,e.retention)];return s&&l.push($(`S3_SESSION_TOKEN`,s)),e.virtualHostedStyle!==`auto`&&l.push($(`S3_VIRTUAL_HOSTED_STYLE`,e.virtualHostedStyle===`virtual-hosted`)),n&&l.push($(`S3_ENDPOINT`,n)),c&&l.push($(`S3_BACKUP_PREFIX`,c)),l.push($(`S3_BACKUP_INTERVAL`,Q[e.schedule])),{ok:!0,value:l.join(`
3
- `)}}function ae({environment:e}){return(0,K.jsxs)(p,{children:[(0,K.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-base font-semibold text-fg`,children:`Server environment`}),(0,K.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,K.jsx)(h,{value:e.value})]}),e.ok?(0,K.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,K.jsx)(`ul`,{className:`space-y-1 text-sm text-danger`,"aria-label":`Configuration errors`,children:e.errors.map(e=>(0,K.jsxs)(`li`,{children:[`• `,e]},e))})]})}function oe(){let e=ne(),t=o(Z),[n,r]=(0,b.useState)(null),[i,a]=(0,b.useState)(null),s=(0,b.useRef)(0),c=ie(e),d=n?.target===t?n:null,h=i===t;return(0,b.useEffect)(()=>(s.current++,r(null),a(null),()=>{s.current++}),[t]),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(m,{title:`S3 Backup Setup`,description:`Configure and operate Bunqueue 2.8.57 S3 backups.`}),(0,K.jsxs)(`div`,{className:`mb-6 flex items-center justify-between rounded-xl border border-line bg-surface px-5 py-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`span`,{className:`flex size-10 items-center justify-center rounded-lg bg-surface-2 text-faint`,children:(0,K.jsx)(u,{className:`size-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`font-semibold text-fg`,children:c.ok?`Configuration draft complete`:`Configuration draft incomplete`}),(0,K.jsx)(`div`,{className:`text-xs text-faint`,children:c.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,K.jsx)(`span`,{className:c.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:c.ok?`Ready`:`Configure`})]}),(0,K.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,K.jsxs)(p,{className:`mb-6`,children:[(0,K.jsx)(`h2`,{className:`mb-1 text-base font-semibold text-fg`,children:`Connection Settings`}),(0,K.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,K.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 md:grid-cols-2`,children:[(0,K.jsx)(y,{label:`Endpoint`,children:(0,K.jsx)(_,{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,K.jsx)(y,{label:`Region`,children:(0,K.jsx)(_,{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,K.jsx)(`div`,{className:`md:col-span-2`,children:(0,K.jsx)(y,{label:`Bucket name`,children:(0,K.jsx)(_,{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,K.jsx)(y,{label:`Access key ID`,children:(0,K.jsx)(_,{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,K.jsx)(y,{label:`Secret access key`,children:(0,K.jsx)(_,{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,K.jsx)(`div`,{className:`md:col-span-2`,children:(0,K.jsx)(y,{label:`Session token (optional, for temporary STS credentials)`,children:(0,K.jsx)(_,{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,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(v,{htmlFor:`s3-backup-schedule`,children:`Backup interval`}),(0,K.jsxs)(g,{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,K.jsx)(`option`,{value:`disabled`,children:`Disabled`}),(0,K.jsx)(`option`,{value:`6h`,children:`Every 6 hours`}),(0,K.jsx)(`option`,{value:`12h`,children:`Every 12 hours`}),(0,K.jsx)(`option`,{value:`24h`,children:`Every 24 hours`})]})]}),(0,K.jsx)(y,{label:`Path prefix (optional)`,children:(0,K.jsx)(_,{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,K.jsxs)(`div`,{children:[(0,K.jsx)(v,{htmlFor:`s3-addressing-style`,children:`Addressing style`}),(0,K.jsxs)(g,{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,K.jsx)(`option`,{value:`auto`,children:`Provider default`}),(0,K.jsx)(`option`,{value:`virtual-hosted`,children:`Virtual-hosted style`}),(0,K.jsx)(`option`,{value:`path-style`,children:`Path style`})]})]}),(0,K.jsx)(y,{label:`Backups to retain`,children:(0,K.jsx)(_,{name:`s3-retention`,type:`number`,min:1,max:1e6,step:1,value:e.retention,onChange:t=>e.set({retention:Number(t.target.value)}),inputMode:`numeric`})})]}),(0,K.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(f,{onClick:async()=>{let e=t,n=++s.current;r(null),a(e);try{let t=await l.storage();if(n!==s.current||Z(o.getState())!==e)return;let i=re(t);r({target:e,ok:!i.diskFull,msg:i.diskFull?`Server disk is full`:`Server disk healthy — this does not validate the S3 credentials`})}catch(t){if(n!==s.current||Z(o.getState())!==e)return;r({target:e,ok:!1,msg:t.message})}finally{n===s.current&&a(null)}},children:h?`Checking server storage…`:`Check server storage`}),(0,K.jsx)(`span`,{className:`text-xs text-faint`,children:`This checks SQLite disk health only, not S3 connectivity.`}),d&&(0,K.jsx)(`span`,{role:`status`,className:d.ok?`text-xs text-success`:`text-xs text-danger`,children:d.msg})]})]}),(0,K.jsx)(ae,{environment:c}),(0,K.jsx)(q,{environmentText:c.ok?c.value:void 0})]})}export{oe as S3BackupPro};
1
+ import{i as e}from"./cn-zFEt5SO8.js";import{g as t,t as n}from"./react-vendor-CyjgmGTq.js";import{d as r,f as i,i as a,o,u as s}from"./connectionStore-CKFQrxDo.js";import{o as c,t as l}from"./bq-DYmbVkgR.js";import{w as u}from"./icons-CIvFfU2b.js";import{n as d}from"./usePolledData-c53tx1jw.js";import{t as f}from"./Button-BPqpRZJD.js";import{t as p}from"./Card-C7NMhqUt.js";import{t as m}from"./PageHeader-BXlZSBcc.js";import{a as h}from"./index-D64v2vNO.js";import{a as g,n as _,r as v,t as y}from"./form-tC20r4Ma.js";var b=e(t(),1),ee=`bq-dash-s3`,x=2,S=[`disabled`,`6h`,`12h`,`24h`],C={endpoint:``,region:`us-east-1`,bucket:``,schedule:`disabled`,pathPrefix:``,virtualHostedStyle:`auto`,retention:7};function w(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function T(e,t,n){return typeof e==`string`&&e.length<=n?e:t}function E(e){return S.includes(e)?e:`disabled`}function D(e){return e===`virtual-hosted`||e===`path-style`?e:`auto`}function O(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=1&&e<=1e6?e:C.retention}function k(e){let t=w(e)?e:{};return{endpoint:T(t.endpoint,C.endpoint,2048),region:T(t.region,C.region,128),bucket:T(t.bucket,C.bucket,255),schedule:E(t.schedule),pathPrefix:T(t.pathPrefix,C.pathPrefix,1024),virtualHostedStyle:D(t.virtualHostedStyle),retention:O(t.retention)}}function A(e){return k(e)}function j(){try{return globalThis.localStorage??null}catch{return null}}function M(e){try{let t=JSON.parse(e),n=w(t)?t:{},r=k(`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:x})}}catch{return null}}var te={getItem(e){let t=j();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=M(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{j()?.setItem(e,t)}catch{}},removeItem(e){try{j()?.removeItem(e)}catch{}}},ne=i()(r(e=>({...C,accessKeyId:``,secretAccessKey:``,sessionToken:``,set:t=>e(e=>{let n={...e,...t};return{...k(n),accessKeyId:T(n.accessKeyId,``,512),secretAccessKey:T(n.secretAccessKey,``,2048),sessionToken:T(n.sessionToken,``,4096)}})}),{name:ee,version:x,storage:s(()=>te),partialize:A,migrate:k,merge:(e,t)=>({...t,...k(e),accessKeyId:``,secretAccessKey:``,sessionToken:``})})),N=new Set([`enabled`,`bucket`,`endpoint`,`interval`,`retention`]),P=new Set([`key`,`size`,`date`]);function F(e){let t=L(e,N,`Backup status`);return typeof t.enabled!=`boolean`&&B(`Backup status`),{enabled:t.enabled,bucket:R(t.bucket,`Backup status bucket`,1024),endpoint:R(t.endpoint,`Backup status endpoint`,4096),interval:R(t.interval,`Backup status interval`,128),retention:R(t.retention,`Backup status retention`,128)}}function I(e){(!Array.isArray(e)||e.length>2e4)&&B(`Backup list`);let t=new Set,n=0;return e.map((e,r)=>{let i=L(e,P,`Backup list item ${r}`),a=R(i.key,`Backup list item ${r} key`,2048),o=R(i.size,`Backup list item ${r} size`,128),s=R(i.date,`Backup list item ${r} date`,128);return n+=a.length+o.length+s.length,(n>2*1024*1024||t.has(a)||!z(s))&&B(`Backup list item ${r}`),t.add(a),{key:a,size:o,date:s}})}function L(e,t,n){(!e||typeof e!=`object`||Array.isArray(e))&&B(n);let r=e;return Object.keys(r).some(e=>!t.has(e))&&B(n),r}function R(e,t,n){return(typeof e!=`string`||e.length<1||e.length>n)&&B(t),e}function z(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 B(e){throw Error(`${e} returned an invalid Bunqueue 2.8.59 contract`)}function V(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 H=e=>`${e}?target=${encodeURIComponent(a())}`,U=e=>({method:`POST`,headers:e===void 0?void 0:{"Content-Type":`application/json`},body:e===void 0?void 0:JSON.stringify(e)}),W=async(e,t)=>(await c(H(e),t)).result,G={status:()=>W(`/backup/status`),list:()=>W(`/backup/list`),backupNow:()=>W(`/backup/now`,U()),restore:(e,t)=>W(`/backup/restore`,U({key:e,database:t})),configure:e=>W(`/backup/configure`,U({environment:e})),restoreContext:async()=>{let e=await c(`/control/status`);return{serverStatus:e.status,database:e.db??null}}},K=n();function q({environmentText:e,repository:t=G}){let n=d(()=>X(t),[t],{intervalMs:15e3}),[r,i]=(0,b.useState)(``),[a,o]=(0,b.useState)(``),[s,c]=(0,b.useState)(``),l=(0,b.useRef)(!1),u=async(e,t)=>{if(!l.current){l.current=!0,i(e),o(``),c(``);try{let r=(await t())?.message;c(r??`${e} completed.`),await n.refetch()}catch(e){o(e instanceof Error?e.message:String(e))}finally{l.current=!1,i(``)}}},f=()=>{e&&window.confirm(`Apply this S3 configuration to the managed server? A restart is required.`)&&u(`Configuration`,()=>t.configure(V(e)))},p=()=>{window.confirm(`Create a transactionally consistent S3 backup now?`)&&u(`Backup`,()=>t.backupNow())},m=e=>{let r=n.data?.context?.database;!r||n.data?.context?.serverStatus!==`stopped`||window.prompt(`Type RESTORE to replace ${r.path} with ${e}`)===`RESTORE`&&u(`Restore`,()=>t.restore(e,r))},h=n.data;return(0,K.jsxs)(`section`,{className:`mt-6 overflow-hidden rounded-lg border border-line bg-surface`,children:[(0,K.jsxs)(`header`,{className:`flex flex-wrap items-start justify-between gap-3 border-b border-line px-4 py-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:`Live backup operations`}),(0,K.jsx)(`p`,{className:`mt-1 text-xs text-faint`,children:`Official Bunqueue 2.8.59 backup CLI, executed by the local control agent.`})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,disabled:!e||!!r,onClick:f,className:`rounded-md border border-line px-3 py-2 text-xs text-muted disabled:opacity-40`,children:`Apply configuration`}),(0,K.jsx)(`button`,{type:`button`,disabled:!!r,onClick:p,className:`rounded-md bg-accent px-3 py-2 text-xs font-medium text-accent-fg disabled:opacity-40`,children:r===`Backup`?`Backing up…`:`Backup now`}),(0,K.jsx)(`button`,{type:`button`,disabled:n.loading,onClick:()=>void n.refetch(),className:`rounded-md border border-line px-3 py-2 text-xs text-muted disabled:opacity-40`,children:`Refresh`})]})]}),h?.status&&(0,K.jsx)(J,{status:h.status,context:h.context}),a||h?.errors.length?(0,K.jsx)(`div`,{role:`alert`,className:`border-b border-line px-4 py-3 text-xs text-danger`,children:a||h?.errors.join(` · `)}):null,s&&(0,K.jsx)(`div`,{role:`status`,className:`border-b border-line px-4 py-3 text-xs text-success`,children:s}),(0,K.jsx)(Y,{rows:h?.backups??[],canRestore:h?.context?.serverStatus===`stopped`&&!!h.context.database,busy:!!r,onRestore:m})]})}function J({status:e,context:t}){return(0,K.jsx)(`dl`,{className:`grid border-b border-line sm:grid-cols-2 xl:grid-cols-5`,children:[[`Scheduler`,e.enabled?`Enabled after restart`:`Disabled`],[`Bucket`,e.bucket||`—`],[`Endpoint`,e.endpoint],[`Retention`,e.retention],[`Server`,t?.serverStatus??`Unknown`]].map(([e,t])=>(0,K.jsxs)(`div`,{className:`border-b border-line px-4 py-3 last:border-b-0 xl:border-r xl:border-b-0`,children:[(0,K.jsx)(`dt`,{className:`text-[10px] uppercase tracking-wider text-faint`,children:e}),(0,K.jsx)(`dd`,{className:`mt-1 truncate text-xs text-fg`,title:t,children:t})]},e))})}function Y({rows:e,canRestore:t,busy:n,onRestore:r}){return e.length?(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full min-w-[680px] text-left text-xs`,children:[(0,K.jsx)(`thead`,{className:`border-b border-line text-[10px] uppercase tracking-wider text-faint`,children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Object key`}),(0,K.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Size`}),(0,K.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Created`}),(0,K.jsx)(`th`,{className:`px-4 py-2 text-right font-medium`,children:`Restore`})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-line`,children:e.map(e=>(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`td`,{className:`max-w-md truncate px-4 py-3 font-mono text-fg`,title:e.key,children:e.key}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-muted`,children:e.size}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-muted`,children:e.date}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-right`,children:(0,K.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,K.jsx)(`p`,{className:`px-4 py-8 text-center text-sm text-muted`,children:`No backup objects returned.`})}async function X(e){let[t,n,r]=await Promise.allSettled([e.status().then(e=>F(e.data)),e.list().then(e=>I(e.data)),e.restoreContext()]),i=[t,n,r].filter(e=>e.status===`rejected`).map(e=>e.reason instanceof Error?e.reason.message:String(e.reason));return{status:t.status===`fulfilled`?t.value:void 0,backups:n.status===`fulfilled`?n.value:[],context:r.status===`fulfilled`?r.value:void 0,errors:i}}function re(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.baseUrl,e.token]),Q={"6h":360*60*1e3,"12h":720*60*1e3,"24h":1440*60*1e3};function $(e,t){return`${e}=${typeof t==`string`?JSON.stringify(t):String(t)}`}function ie(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:$(`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=[$(`S3_BACKUP_ENABLED`,!0),$(`S3_ACCESS_KEY_ID`,a),$(`S3_SECRET_ACCESS_KEY`,o),$(`S3_BUCKET`,i),$(`S3_REGION`,r),$(`S3_BACKUP_RETENTION`,e.retention)];return s&&l.push($(`S3_SESSION_TOKEN`,s)),e.virtualHostedStyle!==`auto`&&l.push($(`S3_VIRTUAL_HOSTED_STYLE`,e.virtualHostedStyle===`virtual-hosted`)),n&&l.push($(`S3_ENDPOINT`,n)),c&&l.push($(`S3_BACKUP_PREFIX`,c)),l.push($(`S3_BACKUP_INTERVAL`,Q[e.schedule])),{ok:!0,value:l.join(`
3
+ `)}}function ae({environment:e}){return(0,K.jsxs)(p,{children:[(0,K.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-base font-semibold text-fg`,children:`Server environment`}),(0,K.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,K.jsx)(h,{value:e.value})]}),e.ok?(0,K.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,K.jsx)(`ul`,{className:`space-y-1 text-sm text-danger`,"aria-label":`Configuration errors`,children:e.errors.map(e=>(0,K.jsxs)(`li`,{children:[`• `,e]},e))})]})}function oe(){let e=ne(),t=o(Z),[n,r]=(0,b.useState)(null),[i,a]=(0,b.useState)(null),s=(0,b.useRef)(0),c=ie(e),d=n?.target===t?n:null,h=i===t;return(0,b.useEffect)(()=>(s.current++,r(null),a(null),()=>{s.current++}),[t]),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(m,{title:`S3 Backup Setup`,description:`Configure and operate Bunqueue 2.8.59 S3 backups.`}),(0,K.jsxs)(`div`,{className:`mb-6 flex items-center justify-between rounded-xl border border-line bg-surface px-5 py-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`span`,{className:`flex size-10 items-center justify-center rounded-lg bg-surface-2 text-faint`,children:(0,K.jsx)(u,{className:`size-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`font-semibold text-fg`,children:c.ok?`Configuration draft complete`:`Configuration draft incomplete`}),(0,K.jsx)(`div`,{className:`text-xs text-faint`,children:c.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,K.jsx)(`span`,{className:c.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:c.ok?`Ready`:`Configure`})]}),(0,K.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,K.jsxs)(p,{className:`mb-6`,children:[(0,K.jsx)(`h2`,{className:`mb-1 text-base font-semibold text-fg`,children:`Connection Settings`}),(0,K.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,K.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 md:grid-cols-2`,children:[(0,K.jsx)(y,{label:`Endpoint`,children:(0,K.jsx)(_,{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,K.jsx)(y,{label:`Region`,children:(0,K.jsx)(_,{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,K.jsx)(`div`,{className:`md:col-span-2`,children:(0,K.jsx)(y,{label:`Bucket name`,children:(0,K.jsx)(_,{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,K.jsx)(y,{label:`Access key ID`,children:(0,K.jsx)(_,{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,K.jsx)(y,{label:`Secret access key`,children:(0,K.jsx)(_,{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,K.jsx)(`div`,{className:`md:col-span-2`,children:(0,K.jsx)(y,{label:`Session token (optional, for temporary STS credentials)`,children:(0,K.jsx)(_,{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,K.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,K.jsxs)(`div`,{children:[(0,K.jsx)(v,{htmlFor:`s3-backup-schedule`,children:`Backup interval`}),(0,K.jsxs)(g,{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,K.jsx)(`option`,{value:`disabled`,children:`Disabled`}),(0,K.jsx)(`option`,{value:`6h`,children:`Every 6 hours`}),(0,K.jsx)(`option`,{value:`12h`,children:`Every 12 hours`}),(0,K.jsx)(`option`,{value:`24h`,children:`Every 24 hours`})]})]}),(0,K.jsx)(y,{label:`Path prefix (optional)`,children:(0,K.jsx)(_,{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,K.jsxs)(`div`,{children:[(0,K.jsx)(v,{htmlFor:`s3-addressing-style`,children:`Addressing style`}),(0,K.jsxs)(g,{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,K.jsx)(`option`,{value:`auto`,children:`Provider default`}),(0,K.jsx)(`option`,{value:`virtual-hosted`,children:`Virtual-hosted style`}),(0,K.jsx)(`option`,{value:`path-style`,children:`Path style`})]})]}),(0,K.jsx)(y,{label:`Backups to retain`,children:(0,K.jsx)(_,{name:`s3-retention`,type:`number`,min:1,max:1e6,step:1,value:e.retention,onChange:t=>e.set({retention:Number(t.target.value)}),inputMode:`numeric`})})]}),(0,K.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(f,{onClick:async()=>{let e=t,n=++s.current;r(null),a(e);try{let t=await l.storage();if(n!==s.current||Z(o.getState())!==e)return;let i=re(t);r({target:e,ok:!i.diskFull,msg:i.diskFull?`Server disk is full`:`Server disk healthy — this does not validate the S3 credentials`})}catch(t){if(n!==s.current||Z(o.getState())!==e)return;r({target:e,ok:!1,msg:t.message})}finally{n===s.current&&a(null)}},children:h?`Checking server storage…`:`Check server storage`}),(0,K.jsx)(`span`,{className:`text-xs text-faint`,children:`This checks SQLite disk health only, not S3 connectivity.`}),d&&(0,K.jsx)(`span`,{role:`status`,className:d.ok?`text-xs text-success`:`text-xs text-danger`,children:d.msg})]})]}),(0,K.jsx)(ae,{environment:c}),(0,K.jsx)(q,{environmentText:c.ok?c.value:void 0})]})}export{oe as S3BackupPro};
@@ -1,3 +1,3 @@
1
- import{i as e,t}from"./cn-zFEt5SO8.js";import{g as n,t as r}from"./react-vendor-CyjgmGTq.js";import{t as i}from"./bq-BeBxa743.js";import{C as a,T as o,b as s,x as c}from"./icons-CIvFfU2b.js";import{n as l}from"./usePolledData-DzlUpBOO.js";import{t as u}from"./Button-BPqpRZJD.js";import{n as d,t as f}from"./Card-C7NMhqUt.js";import{i as p,n as m,r as h}from"./feedback-BnGE2oW2.js";import{t as g}from"./PageHeader-BXlZSBcc.js";import{f as _,i as v,l as y,n as b,u as x}from"./format-Cg7VCIZW.js";import{a as S}from"./index-Cui9IwWy.js";import{i as C,n as w,t as T}from"./form-tC20r4Ma.js";var E=e(n(),1),D=r();function O({children:e}){return(0,D.jsx)(`code`,{className:`rounded bg-surface-2 px-1.5 py-0.5 text-xs text-fg`,children:e})}function k({agentBase:e}){return(0,D.jsx)(f,{children:(0,D.jsxs)(`details`,{className:`group`,children:[(0,D.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-2`,children:[(0,D.jsx)(`span`,{className:`text-base font-semibold text-fg`,children:`How server control works`}),(0,D.jsx)(`span`,{className:`text-xs text-muted transition-transform group-open:rotate-90`,children:`▶`})]}),(0,D.jsxs)(`div`,{className:`mt-4 space-y-4 text-sm leading-relaxed text-muted`,children:[(0,D.jsxs)(`p`,{children:[`A browser can't start or stop an OS process, so the dashboard talks to a small local`,` `,(0,D.jsx)(`span`,{className:`font-medium text-fg`,children:`control agent`}),` (`,(0,D.jsx)(O,{children:e}),`) that supervises the bunqueue server process — start, stop and restart — and streams its logs back here.`]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`Launch & environment`}),(0,D.jsxs)(`p`,{children:[`The agent runs your `,(0,D.jsx)(`span`,{className:`text-fg`,children:`Command`}),` and injects`,` `,(0,D.jsx)(O,{children:`HTTP_PORT`}),`, `,(0,D.jsx)(O,{children:`TCP_PORT`}),` and `,(0,D.jsx)(O,{children:`BUNQUEUE_DATA_PATH`}),` — plus any `,(0,D.jsx)(`span`,{className:`text-fg`,children:`Environment variables`}),` you add — into its environment. The default `,(0,D.jsx)(O,{children:`bunx bunqueue@2.8.57 start`}),` resolves the verified release; pointing the command at a local entry (e.g.`,` `,(0,D.jsx)(O,{children:`bun run /path/to/bunqueue/src/main.ts`}),`) works without one.`]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`When changes apply`}),(0,D.jsxs)(`p`,{children:[`Config is editable any time, but `,(0,D.jsx)(`span`,{className:`text-fg`,children:`Command`}),`, ports and data path only take effect on the `,(0,D.jsx)(`span`,{className:`text-fg`,children:`next start/restart`}),` `,`— the running process keeps the config it launched with until then.`]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`Data path`}),(0,D.jsxs)(`p`,{children:[`Relative paths resolve against the `,(0,D.jsx)(`span`,{className:`text-fg`,children:`agent's`}),` working directory. SQLite creates the database `,(0,D.jsx)(`span`,{className:`text-fg`,children:`file`}),` but not its parent `,(0,D.jsx)(`span`,{className:`text-fg`,children:`folder`}),` — if start fails with`,` `,(0,D.jsx)(O,{children:`SQLITE_CANTOPEN`}),`, create the directory first or use a path whose folder already exists.`]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`Security`}),(0,D.jsxs)(`p`,{children:[`The direct agent listener binds `,(0,D.jsx)(O,{children:`127.0.0.1`}),`, locks CORS to an allowlist (never `,(0,D.jsx)(O,{children:`*`}),`), and rejects a disallowed `,(0,D.jsx)(O,{children:`Origin`}),` or`,` `,(0,D.jsx)(O,{children:`Host`}),` with `,(0,D.jsx)(O,{children:`403`}),`. The all-in-one server's `,(0,D.jsx)(O,{children:`/agent`}),` `,`bridge treats LAN and reverse-proxy access as remote: `,(0,D.jsx)(O,{children:`AGENT_TOKEN`}),` is then mandatory for status, logs, database reads and changes alike. Without it, the bridge stays disabled.`]}),(0,D.jsxs)(`p`,{children:[`If you started the agent with `,(0,D.jsx)(O,{children:`AGENT_TOKEN`}),`, enter that token under`,` `,(0,D.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,D.jsx)(O,{children:`VITE_*`}),` value.`]})]})]})]})})}var A=0,j=e=>Object.entries(e).map(([e,t])=>({id:A++,key:e,value:t})),M=e=>{let t={};for(let n of e){let e=n.key.trim();e&&(t[e]=n.value)}return t};function N(e){let t=e.map(e=>e.trim());return[...new Set(t.filter((e,t,n)=>e&&n.indexOf(e)!==t))]}var P=[`AUTH_TOKENS`,`LOG_LEVEL`,`S3_BACKUP_ENABLED`,`S3_BUCKET`,`METRICS_ENABLED`];function F({value:e,onChange:t,disabled:n}){let[r,i]=(0,E.useState)(()=>j(e)),a=e=>{i(e),t(M(e))},o=(e,t)=>a(r.map(n=>n.id===e?{...n,...t}:n)),s=(e=``)=>a([...r,{id:A++,key:e,value:``}]),c=e=>a(r.filter(t=>t.id!==e)),l=new Set(r.map(e=>e.key.trim()).filter(Boolean)),d=N(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,D.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.length===0&&(0,D.jsxs)(`p`,{className:`text-xs leading-relaxed text-faint`,children:[`No custom variables. The agent already injects`,` `,(0,D.jsx)(`code`,{className:`rounded bg-surface-2 px-1 py-0.5`,children:`HTTP_PORT`}),`,`,` `,(0,D.jsx)(`code`,{className:`rounded bg-surface-2 px-1 py-0.5`,children:`TCP_PORT`}),` and`,` `,(0,D.jsx)(`code`,{className:`rounded bg-surface-2 px-1 py-0.5`,children:`BUNQUEUE_DATA_PATH`}),`.`]}),r.map(e=>(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`div`,{className:`w-2/5 shrink-0`,children:(0,D.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,D.jsx)(`span`,{className:`text-faint`,children:`=`}),(0,D.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,D.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,D.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.key||`variable`}`,disabled:n,onClick:()=>c(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,D.jsxs)(`p`,{className:`text-xs text-warning`,children:[`Duplicate key`,d.length>1?`s`:``,` — the last value wins: `,d.join(`, `)]}),f.length>0&&(0,D.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,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[(0,D.jsx)(u,{size:`sm`,variant:`ghost`,disabled:n,onClick:()=>s(),children:`+ Add variable`}),P.filter(e=>!l.has(e)).map(e=>(0,D.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 I({status:e,onSaved:t,running:n,transitioning:r}){let[o,s]=(0,E.useState)(null),[c,l]=(0,E.useState)(!1),[p,m]=(0,E.useState)(!1),[h,g]=(0,E.useState)(null);(0,E.useEffect)(()=>{e?.config&&!o&&s(e.config)},[e,o]);let _=o??e?.config??null;if(!_)return(0,D.jsx)(f,{children:`Loading…`});let v=e=>s({..._,...e}),y=e?.runningConfig??null,b=(e={})=>JSON.stringify(Object.keys(e).sort().map(t=>[t,e[t]])),x=[];y!=null&&(y.command!==_.command&&x.push(`command`),y.httpPort!==_.httpPort&&x.push(`HTTP port`),y.tcpPort!==_.tcpPort&&x.push(`TCP port`),y.dataPath!==_.dataPath&&x.push(`data path`),b(y.extraEnv)!==b(_.extraEnv)&&x.push(`environment variables`));let S=n&&x.length>0,C=r||p,O=()=>{l(!0),setTimeout(()=>l(!1),2e3)},k=()=>{let e=e=>Number.isInteger(e)&&e>=1&&e<=65535;return e(_.httpPort)?e(_.tcpPort)?_.httpPort===_.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`},A=async()=>{let e=k();if(e)return g(e);g(null);try{await i.control.setConfig(_),O(),t()}catch(e){g(e.message)}};return(0,D.jsxs)(f,{children:[(0,D.jsx)(d,{title:`Configuration`}),(0,D.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,D.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),A()},children:[(0,D.jsx)(T,{label:`Command`,hint:`The exact command the agent runs to launch bunqueue. It receives HTTP_PORT, TCP_PORT and BUNQUEUE_DATA_PATH in its environment. The default resolves Bunqueue 2.8.57 with bunx; offline installs can point at a local entry.`,children:(0,D.jsx)(w,{name:`server-command`,autoComplete:`off`,spellCheck:!1,value:_.command,disabled:C,onChange:e=>v({command:e.target.value}),placeholder:`bunx bunqueue@2.8.57 start`})}),(0,D.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,D.jsx)(T,{label:`HTTP port`,hint:`Dashboard API + SSE.`,children:(0,D.jsx)(w,{name:`server-http-port`,autoComplete:`off`,type:`number`,min:1,max:65535,value:_.httpPort,disabled:C,onChange:e=>v({httpPort:Number(e.target.value)})})}),(0,D.jsx)(T,{label:`TCP port`,hint:`Binary protocol. Must differ from HTTP.`,children:(0,D.jsx)(w,{name:`server-tcp-port`,autoComplete:`off`,type:`number`,min:1,max:65535,value:_.tcpPort,disabled:C,onChange:e=>v({tcpPort:Number(e.target.value)})})})]}),(0,D.jsx)(T,{label:`Data path`,hint:`SQLite database file, relative to the agent's working directory. The parent folder must already exist — SQLite creates the file, not the directory.`,children:(0,D.jsx)(w,{name:`server-data-path`,autoComplete:`off`,spellCheck:!1,value:_.dataPath,disabled:C,onChange:e=>v({dataPath:e.target.value})})}),(0,D.jsx)(T,{label:`Environment variables`,hint:`Injected into the server process on start, on top of the ports + data path. Applies on the next restart.`,children:(0,D.jsx)(F,{value:_.extraEnv??{},onChange:e=>v({extraEnv:e}),disabled:C})}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,D.jsx)(u,{type:`submit`,variant:`accent`,size:`sm`,disabled:C,children:`Save config`}),n&&(0,D.jsxs)(u,{variant:`warning`,size:`sm`,disabled:C,onClick:async()=>{let e=k();if(e)return g(e);let n=x.length>0?` Changed: ${x.join(`, `)}.`:``;if(window.confirm(`Save configuration and restart the server to apply it?${n}`)){g(null),m(!0);try{await i.control.setConfig(_),await i.control.restart(),O(),t()}catch(e){g(e.message)}finally{m(!1)}}},children:[(0,D.jsx)(a,{className:`size-3.5`}),` Save & restart`]}),S&&!c&&(0,D.jsx)(`span`,{className:`text-xs text-warning`,children:`Restart to apply changes`}),c&&(0,D.jsx)(`span`,{className:`text-xs text-success`,children:`Saved`}),h&&(0,D.jsx)(`span`,{className:`text-xs text-danger`,children:h})]})]})]})}var L=[`all`,`stdout`,`stderr`,`sys`],R=e=>`${new Date(e).toLocaleTimeString([],{hour12:!1})}.${String(e%1e3).padStart(3,`0`)}`,z=e=>e===`stderr`?`text-danger/90`:e===`sys`?`text-accent/80`:`text-muted`;function B(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 V(){let{data:e,error:n,loading:r,refetch:i}=U(),a=(0,E.useMemo)(()=>e?.lines??[],[e]),[s,c]=(0,E.useState)(`all`),[l,u]=(0,E.useState)(``),[d,g]=(0,E.useState)(!0),[v,y]=(0,E.useState)(!1),b=(0,E.useRef)(null),x=(0,E.useMemo)(()=>{let e=l.trim().toLowerCase();return a.map(e=>e.line.includes(`\x1B`)?{...e,line:_(e.line)}:e).filter(t=>(s===`all`||t.stream===s)&&(!e||t.line.toLowerCase().includes(e)))},[a,s,l]);(0,E.useEffect)(()=>{if(!d)return;let e=b.current;e&&(e.scrollTop=e.scrollHeight)},[x.length,d]);let w=(0,E.useMemo)(()=>x.map(e=>v?`${R(e.ts)} [${e.stream}] ${e.line}`:e.line).join(`
2
- `),[x,v]);return(0,D.jsxs)(f,{padded:!1,className:`overflow-hidden`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-line px-4 py-3`,children:[(0,D.jsx)(`h3`,{className:`mr-1 text-base font-semibold text-fg`,children:`Process logs`}),(0,D.jsx)(C,{options:L,value:s,onChange:c}),(0,D.jsxs)(`div`,{className:`relative min-w-40 flex-1`,children:[(0,D.jsx)(o,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-faint`}),(0,D.jsx)(`input`,{value:l,onChange:e=>u(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,D.jsx)(H,{on:d,onClick:()=>g(e=>!e),label:`Follow`}),(0,D.jsx)(H,{on:v,onClick:()=>y(e=>!e),label:`Times`}),(0,D.jsx)(S,{value:w}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>{B(w)},disabled:x.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`})]}),n&&e&&(0,D.jsx)(`div`,{className:`border-b border-line px-4 pt-3 font-sans`,children:(0,D.jsx)(p,{message:`Process-log refresh failed — showing the last received lines. ${n.message}`,onRetry:i})}),(0,D.jsx)(`div`,{ref:b,className:`max-h-80 min-h-40 overflow-y-auto p-4 font-mono text-xs leading-relaxed`,children:r&&!e&&!n?(0,D.jsx)(`div`,{className:`font-sans`,children:(0,D.jsx)(h,{label:`Loading process logs…`})}):n&&!e?(0,D.jsx)(`div`,{className:`font-sans`,children:(0,D.jsx)(m,{error:n,onRetry:i})}):x.length===0?(0,D.jsx)(`p`,{className:`text-faint`,children:a.length===0?`No output yet.`:`No lines match the current filter.`}):x.map(e=>(0,D.jsxs)(`div`,{className:t(`whitespace-pre-wrap`,z(e.stream)),children:[v&&(0,D.jsx)(`span`,{className:`mr-2 text-faint`,children:R(e.ts)}),e.line]},e.seq))}),(0,D.jsxs)(`div`,{className:`flex items-center justify-between border-t border-line px-4 py-2 text-[11px] text-faint`,children:[(0,D.jsx)(`span`,{children:n&&!e?`logs unavailable`:x.length===a.length?`${a.length} lines`:`${x.length} of ${a.length} lines`}),(0,D.jsx)(`span`,{children:n?`refresh failed`:d?`following tail`:`paused`})]})]})}function H({on:e,onClick:n,label:r}){return(0,D.jsx)(`button`,{type:`button`,onClick:n,"aria-pressed":e,className:t(`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:r})}function U(){return l(()=>i.control.logs(),[])}var W={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 G({startedAt:e}){let[,t]=(0,E.useState)(0);return(0,E.useEffect)(()=>{let e=setInterval(()=>t(e=>e+1),1e3);return()=>clearInterval(e)},[]),(0,D.jsx)(D.Fragment,{children:x((Date.now()-e)/1e3)})}function K({label:e,children:t,title:n}){return(0,D.jsxs)(`div`,{className:`min-w-0`,title:n,children:[(0,D.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-faint`,children:e}),(0,D.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-sm text-fg`,children:t})]})}function q({status:e,agentBase:n,transitioning:r,stale:i=!1,vitals:o=null,busy:l,onStart:d,onStop:f,onRestart:p}){let m=e?.status??`stopped`,h=m===`running`,g=W[m]??W.stopped,_=!!e?.healthy&&!i,y=!h&&e?.exitCode!=null&&e.exitCode!==0,b=e?.runningConfig??e?.config??null,x=`http://localhost:${b?.httpPort??6790}`;return(0,D.jsxs)(`section`,{className:`mb-6 overflow-hidden rounded-xl border border-line bg-surface`,children:[(0,D.jsx)(`div`,{className:t(`h-0.5 bg-gradient-to-r to-transparent`,h&&_?`from-emerald-400/80 via-emerald-400/25`:h||r?`from-amber-400/80 via-amber-400/25`:`from-red-400/70 via-red-400/20`)}),(0,D.jsxs)(`div`,{className:`flex flex-col gap-5 p-5 lg:flex-row lg:items-center lg:justify-between`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,D.jsxs)(`span`,{className:`relative flex size-3.5 shrink-0`,children:[h&&_&&(0,D.jsx)(`span`,{className:`absolute inline-flex size-full rounded-full bg-emerald-400 opacity-50 motion-safe:animate-ping`}),(0,D.jsx)(`span`,{className:t(`relative inline-flex size-3.5 rounded-full`,g.dot)})]}),(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3 gap-y-1`,children:[(0,D.jsx)(`span`,{className:t(`text-2xl font-bold tracking-tight`,g.tone),children:r&&l?`${l}…`:g.label}),e?.version&&(0,D.jsxs)(`span`,{className:`font-mono text-xs text-muted`,children:[`bunqueue v`,e.version]}),y&&(0,D.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,D.jsx)(`div`,{className:`mt-1 font-mono text-xs text-muted`,children:i?(0,D.jsxs)(`span`,{className:`text-warning`,children:[`last known: pid `,e?.pid??`—`,` — agent unreachable, state may have changed`]}):h?(0,D.jsxs)(D.Fragment,{children:[_?`healthy`:`waiting for health…`,` · pid `,e?.pid??`—`,` · up`,` `,e?.startedAt?(0,D.jsx)(G,{startedAt:e.startedAt}):`—`]}):`process not running — start it below or point the dashboard at an external server`})]})]}),(0,D.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,D.jsxs)(u,{variant:`success`,disabled:h||r||i,onClick:d,children:[(0,D.jsx)(c,{className:`size-4`}),` Start`]}),(0,D.jsxs)(u,{variant:`warning`,disabled:!h||r||i,onClick:f,children:[(0,D.jsx)(s,{className:`size-4`}),` Stop`]}),(0,D.jsxs)(u,{disabled:r||i,onClick:p,children:[(0,D.jsx)(a,{className:`size-4`}),` Restart`]})]})]}),(0,D.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,D.jsx)(K,{label:`Memory`,children:o?.memory?.rss==null?(0,D.jsx)(`span`,{className:`text-faint`,children:`—`}):(0,D.jsxs)(`span`,{title:`heap ${o.memory.heapUsed??`?`} / ${o.memory.heapTotal??`?`} MB`,children:[o.memory.rss,` MB rss`]})}),(0,D.jsx)(K,{label:`Connections`,children:o?.connections?`${o.connections.tcp??0} tcp · ${o.connections.ws??0} ws · ${o.connections.sse??0} sse`:(0,D.jsx)(`span`,{className:`text-faint`,children:`—`})}),(0,D.jsx)(K,{label:`API endpoint`,title:x,children:h?(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(`a`,{href:`${x}/health`,target:`_blank`,rel:`noreferrer`,className:`truncate text-accent hover:underline`,children:x}),(0,D.jsx)(S,{value:x})]}):(0,D.jsx)(`span`,{className:`text-faint`,children:x})}),(0,D.jsx)(K,{label:`Ports`,children:b?`${b.httpPort} http · ${b.tcpPort} tcp`:`—`}),(0,D.jsx)(K,{label:`Started`,children:h&&e?.startedAt?v(e.startedAt):`—`}),(0,D.jsx)(K,{label:`Control agent`,title:n,children:n.replace(/^https?:\/\//,``)}),(0,D.jsx)(K,{label:`Launch command`,title:b?.command,children:b?.command??`—`})]})]})}var J=[{key:`size`,label:`Database`,color:`bg-accent`},{key:`walSize`,label:`WAL`,color:`bg-amber-400`},{key:`shmSize`,label:`SHM`,color:`bg-zinc-500`}];function Y({db:e}){let n=e.totalSize||0;return(0,D.jsxs)(f,{children:[(0,D.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2`,children:[(0,D.jsx)(`h3`,{className:`text-base font-semibold text-fg`,children:`Storage`}),(0,D.jsx)(`span`,{className:`font-mono text-xs text-muted`,children:e.exists?`${b(n)} on disk`:`not created yet`})]}),(0,D.jsxs)(`p`,{className:`mb-4 flex items-center gap-1.5 truncate font-mono text-xs text-faint`,title:e.path,children:[(0,D.jsx)(`span`,{className:`truncate`,children:e.path}),(0,D.jsx)(S,{value:e.path})]}),e.exists&&n>0?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`flex h-2.5 overflow-hidden rounded-full bg-surface-2`,children:J.map(r=>{let i=e[r.key];return i?(0,D.jsx)(`div`,{className:t(`h-full`,r.color),style:{width:`${i/n*100}%`},title:`${r.label}: ${b(i)}`},r.key):null})}),(0,D.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-5 gap-y-1.5 font-mono text-[11px] text-faint`,children:[J.map(n=>(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:t(`size-2 rounded-full`,n.color)}),n.label,` `,(0,D.jsx)(`span`,{className:`text-fg`,children:b(e[n.key])})]},n.key)),e.mtimeMs?(0,D.jsxs)(`span`,{className:`ml-auto`,children:[`written `,y(e.mtimeMs)]}):null]})]}):(0,D.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 X(){let{data:e,error:t,refetch:n}=l(()=>i.control.status(),[]),[r,a]=(0,E.useState)(null),[o,s]=(0,E.useState)(null),c=e?.status===`running`,{data:u}=l(()=>c?i.health():Promise.resolve(null),[c]),m=c?u??null:null,h=m?.connections?` This drops ${m.connections.tcp??0} TCP / ${m.connections.ws??0} WS connections; in-flight jobs are interrupted.`:` In-flight jobs are interrupted.`,_=async(e,t,r)=>{if(!(r&&!window.confirm(r))){a(e),s(null);try{await t(),await n()}catch(e){s(e.message)}finally{a(null)}}};if(t&&!e)return(0,D.jsxs)(`div`,{children:[(0,D.jsx)(g,{title:`Server`,description:`Start, stop and restart the bunqueue server.`}),(0,D.jsx)(p,{message:`Control agent unreachable — server lifecycle controls are unavailable.`,onRetry:n}),(0,D.jsxs)(f,{children:[(0,D.jsx)(d,{title:`Control agent not running`}),(0,D.jsxs)(`p`,{className:`text-sm text-muted`,children:[`The local control agent is unreachable at`,` `,(0,D.jsx)(`code`,{className:`rounded bg-surface-2 px-1.5 py-0.5 text-xs`,children:i.agentBase}),`. It manages the bunqueue server process (start / stop / restart). Start it with:`]}),(0,D.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
- `,`bun run agent`,` `,`# agent only, if the dashboard is already running`]}),(0,D.jsx)(`p`,{className:`mt-3 text-xs text-faint`,children:`This page reconnects automatically once the agent is up — no reload needed.`})]})]});let v=e?.status??`stopped`,y=v===`running`,b=v===`starting`||v===`stopping`||r!=null,x=t!=null&&e!=null;return(0,D.jsxs)(`div`,{children:[(0,D.jsx)(g,{title:`Server`,description:`Supervise the bunqueue server process — lifecycle, configuration, storage and logs.`}),o&&(0,D.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:o}),x&&(0,D.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,D.jsx)(q,{status:e,agentBase:i.agentBase,stale:x,vitals:m,transitioning:b,busy:r,onStart:()=>_(`starting`,()=>i.control.start()),onStop:()=>_(`stopping`,()=>i.control.stop(),`Stop the bunqueue server?${h}`),onRestart:()=>_(`restarting`,()=>i.control.restart(),`Restart the bunqueue server?${h}`)}),(0,D.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,D.jsx)(I,{status:e,onSaved:n,running:y,transitioning:b}),(0,D.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[e?.db&&(0,D.jsx)(Y,{db:e.db}),(0,D.jsx)(V,{})]})]}),(0,D.jsx)(`div`,{className:`mt-6`,children:(0,D.jsx)(k,{agentBase:i.agentBase})})]})}export{X as ServerControl};
1
+ import{i as e,t}from"./cn-zFEt5SO8.js";import{g as n,t as r}from"./react-vendor-CyjgmGTq.js";import{t as i}from"./bq-DYmbVkgR.js";import{C as a,T as o,b as s,x as c}from"./icons-CIvFfU2b.js";import{n as l}from"./usePolledData-c53tx1jw.js";import{t as u}from"./Button-BPqpRZJD.js";import{n as d,t as f}from"./Card-C7NMhqUt.js";import{i as p,n as m,r as h}from"./feedback-BnGE2oW2.js";import{t as g}from"./PageHeader-BXlZSBcc.js";import{f as _,i as v,l as y,n as b,u as x}from"./format-Cg7VCIZW.js";import{a as S}from"./index-D64v2vNO.js";import{i as C,n as w,t as T}from"./form-tC20r4Ma.js";var E=e(n(),1),D=r();function O({children:e}){return(0,D.jsx)(`code`,{className:`rounded bg-surface-2 px-1.5 py-0.5 text-xs text-fg`,children:e})}function k({agentBase:e}){return(0,D.jsx)(f,{children:(0,D.jsxs)(`details`,{className:`group`,children:[(0,D.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-2`,children:[(0,D.jsx)(`span`,{className:`text-base font-semibold text-fg`,children:`How server control works`}),(0,D.jsx)(`span`,{className:`text-xs text-muted transition-transform group-open:rotate-90`,children:`▶`})]}),(0,D.jsxs)(`div`,{className:`mt-4 space-y-4 text-sm leading-relaxed text-muted`,children:[(0,D.jsxs)(`p`,{children:[`A browser can't start or stop an OS process, so the dashboard talks to a small local`,` `,(0,D.jsx)(`span`,{className:`font-medium text-fg`,children:`control agent`}),` (`,(0,D.jsx)(O,{children:e}),`) that supervises the bunqueue server process — start, stop and restart — and streams its logs back here.`]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`Launch & environment`}),(0,D.jsxs)(`p`,{children:[`The agent runs your `,(0,D.jsx)(`span`,{className:`text-fg`,children:`Command`}),` and injects`,` `,(0,D.jsx)(O,{children:`HTTP_PORT`}),`, `,(0,D.jsx)(O,{children:`TCP_PORT`}),` and `,(0,D.jsx)(O,{children:`BUNQUEUE_DATA_PATH`}),` — plus any `,(0,D.jsx)(`span`,{className:`text-fg`,children:`Environment variables`}),` you add — into its environment. The default `,(0,D.jsx)(O,{children:`bunx bunqueue@2.8.59 start`}),` resolves the verified release; pointing the command at a local entry (e.g.`,` `,(0,D.jsx)(O,{children:`bun run /path/to/bunqueue/src/main.ts`}),`) works without one.`]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`When changes apply`}),(0,D.jsxs)(`p`,{children:[`Config is editable any time, but `,(0,D.jsx)(`span`,{className:`text-fg`,children:`Command`}),`, ports and data path only take effect on the `,(0,D.jsx)(`span`,{className:`text-fg`,children:`next start/restart`}),` `,`— the running process keeps the config it launched with until then.`]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`Data path`}),(0,D.jsxs)(`p`,{children:[`Relative paths resolve against the `,(0,D.jsx)(`span`,{className:`text-fg`,children:`agent's`}),` working directory. SQLite creates the database `,(0,D.jsx)(`span`,{className:`text-fg`,children:`file`}),` but not its parent `,(0,D.jsx)(`span`,{className:`text-fg`,children:`folder`}),` — if start fails with`,` `,(0,D.jsx)(O,{children:`SQLITE_CANTOPEN`}),`, create the directory first or use a path whose folder already exists.`]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`mb-1 font-medium text-fg`,children:`Security`}),(0,D.jsxs)(`p`,{children:[`The direct agent listener binds `,(0,D.jsx)(O,{children:`127.0.0.1`}),`, locks CORS to an allowlist (never `,(0,D.jsx)(O,{children:`*`}),`), and rejects a disallowed `,(0,D.jsx)(O,{children:`Origin`}),` or`,` `,(0,D.jsx)(O,{children:`Host`}),` with `,(0,D.jsx)(O,{children:`403`}),`. The all-in-one server's `,(0,D.jsx)(O,{children:`/agent`}),` `,`bridge treats LAN and reverse-proxy access as remote: `,(0,D.jsx)(O,{children:`AGENT_TOKEN`}),` is then mandatory for status, logs, database reads and changes alike. Without it, the bridge stays disabled.`]}),(0,D.jsxs)(`p`,{children:[`If you started the agent with `,(0,D.jsx)(O,{children:`AGENT_TOKEN`}),`, enter that token under`,` `,(0,D.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,D.jsx)(O,{children:`VITE_*`}),` value.`]})]})]})]})})}var A=0,j=e=>Object.entries(e).map(([e,t])=>({id:A++,key:e,value:t})),M=e=>{let t={};for(let n of e){let e=n.key.trim();e&&(t[e]=n.value)}return t};function N(e){let t=e.map(e=>e.trim());return[...new Set(t.filter((e,t,n)=>e&&n.indexOf(e)!==t))]}var P=[`AUTH_TOKENS`,`LOG_LEVEL`,`S3_BACKUP_ENABLED`,`S3_BUCKET`,`METRICS_ENABLED`];function F({value:e,onChange:t,disabled:n}){let[r,i]=(0,E.useState)(()=>j(e)),a=e=>{i(e),t(M(e))},o=(e,t)=>a(r.map(n=>n.id===e?{...n,...t}:n)),s=(e=``)=>a([...r,{id:A++,key:e,value:``}]),c=e=>a(r.filter(t=>t.id!==e)),l=new Set(r.map(e=>e.key.trim()).filter(Boolean)),d=N(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,D.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.length===0&&(0,D.jsxs)(`p`,{className:`text-xs leading-relaxed text-faint`,children:[`No custom variables. The agent already injects`,` `,(0,D.jsx)(`code`,{className:`rounded bg-surface-2 px-1 py-0.5`,children:`HTTP_PORT`}),`,`,` `,(0,D.jsx)(`code`,{className:`rounded bg-surface-2 px-1 py-0.5`,children:`TCP_PORT`}),` and`,` `,(0,D.jsx)(`code`,{className:`rounded bg-surface-2 px-1 py-0.5`,children:`BUNQUEUE_DATA_PATH`}),`.`]}),r.map(e=>(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`div`,{className:`w-2/5 shrink-0`,children:(0,D.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,D.jsx)(`span`,{className:`text-faint`,children:`=`}),(0,D.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,D.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,D.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.key||`variable`}`,disabled:n,onClick:()=>c(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,D.jsxs)(`p`,{className:`text-xs text-warning`,children:[`Duplicate key`,d.length>1?`s`:``,` — the last value wins: `,d.join(`, `)]}),f.length>0&&(0,D.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,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[(0,D.jsx)(u,{size:`sm`,variant:`ghost`,disabled:n,onClick:()=>s(),children:`+ Add variable`}),P.filter(e=>!l.has(e)).map(e=>(0,D.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 I({status:e,onSaved:t,running:n,transitioning:r}){let[o,s]=(0,E.useState)(null),[c,l]=(0,E.useState)(!1),[p,m]=(0,E.useState)(!1),[h,g]=(0,E.useState)(null);(0,E.useEffect)(()=>{e?.config&&!o&&s(e.config)},[e,o]);let _=o??e?.config??null;if(!_)return(0,D.jsx)(f,{children:`Loading…`});let v=e=>s({..._,...e}),y=e?.runningConfig??null,b=(e={})=>JSON.stringify(Object.keys(e).sort().map(t=>[t,e[t]])),x=[];y!=null&&(y.command!==_.command&&x.push(`command`),y.httpPort!==_.httpPort&&x.push(`HTTP port`),y.tcpPort!==_.tcpPort&&x.push(`TCP port`),y.dataPath!==_.dataPath&&x.push(`data path`),b(y.extraEnv)!==b(_.extraEnv)&&x.push(`environment variables`));let S=n&&x.length>0,C=r||p,O=()=>{l(!0),setTimeout(()=>l(!1),2e3)},k=()=>{let e=e=>Number.isInteger(e)&&e>=1&&e<=65535;return e(_.httpPort)?e(_.tcpPort)?_.httpPort===_.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`},A=async()=>{let e=k();if(e)return g(e);g(null);try{await i.control.setConfig(_),O(),t()}catch(e){g(e.message)}};return(0,D.jsxs)(f,{children:[(0,D.jsx)(d,{title:`Configuration`}),(0,D.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,D.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),A()},children:[(0,D.jsx)(T,{label:`Command`,hint:`The exact command the agent runs to launch bunqueue. It receives HTTP_PORT, TCP_PORT and BUNQUEUE_DATA_PATH in its environment. The default resolves Bunqueue 2.8.59 with bunx; offline installs can point at a local entry.`,children:(0,D.jsx)(w,{name:`server-command`,autoComplete:`off`,spellCheck:!1,value:_.command,disabled:C,onChange:e=>v({command:e.target.value}),placeholder:`bunx bunqueue@2.8.59 start`})}),(0,D.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,D.jsx)(T,{label:`HTTP port`,hint:`Dashboard API + SSE.`,children:(0,D.jsx)(w,{name:`server-http-port`,autoComplete:`off`,type:`number`,min:1,max:65535,value:_.httpPort,disabled:C,onChange:e=>v({httpPort:Number(e.target.value)})})}),(0,D.jsx)(T,{label:`TCP port`,hint:`Binary protocol. Must differ from HTTP.`,children:(0,D.jsx)(w,{name:`server-tcp-port`,autoComplete:`off`,type:`number`,min:1,max:65535,value:_.tcpPort,disabled:C,onChange:e=>v({tcpPort:Number(e.target.value)})})})]}),(0,D.jsx)(T,{label:`Data path`,hint:`SQLite database file, relative to the agent's working directory. The parent folder must already exist — SQLite creates the file, not the directory.`,children:(0,D.jsx)(w,{name:`server-data-path`,autoComplete:`off`,spellCheck:!1,value:_.dataPath,disabled:C,onChange:e=>v({dataPath:e.target.value})})}),(0,D.jsx)(T,{label:`Environment variables`,hint:`Injected into the server process on start, on top of the ports + data path. Applies on the next restart.`,children:(0,D.jsx)(F,{value:_.extraEnv??{},onChange:e=>v({extraEnv:e}),disabled:C})}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,D.jsx)(u,{type:`submit`,variant:`accent`,size:`sm`,disabled:C,children:`Save config`}),n&&(0,D.jsxs)(u,{variant:`warning`,size:`sm`,disabled:C,onClick:async()=>{let e=k();if(e)return g(e);let n=x.length>0?` Changed: ${x.join(`, `)}.`:``;if(window.confirm(`Save configuration and restart the server to apply it?${n}`)){g(null),m(!0);try{await i.control.setConfig(_),await i.control.restart(),O(),t()}catch(e){g(e.message)}finally{m(!1)}}},children:[(0,D.jsx)(a,{className:`size-3.5`}),` Save & restart`]}),S&&!c&&(0,D.jsx)(`span`,{className:`text-xs text-warning`,children:`Restart to apply changes`}),c&&(0,D.jsx)(`span`,{className:`text-xs text-success`,children:`Saved`}),h&&(0,D.jsx)(`span`,{className:`text-xs text-danger`,children:h})]})]})]})}var L=[`all`,`stdout`,`stderr`,`sys`],R=e=>`${new Date(e).toLocaleTimeString([],{hour12:!1})}.${String(e%1e3).padStart(3,`0`)}`,z=e=>e===`stderr`?`text-danger/90`:e===`sys`?`text-accent/80`:`text-muted`;function B(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 V(){let{data:e,error:n,loading:r,refetch:i}=U(),a=(0,E.useMemo)(()=>e?.lines??[],[e]),[s,c]=(0,E.useState)(`all`),[l,u]=(0,E.useState)(``),[d,g]=(0,E.useState)(!0),[v,y]=(0,E.useState)(!1),b=(0,E.useRef)(null),x=(0,E.useMemo)(()=>{let e=l.trim().toLowerCase();return a.map(e=>e.line.includes(`\x1B`)?{...e,line:_(e.line)}:e).filter(t=>(s===`all`||t.stream===s)&&(!e||t.line.toLowerCase().includes(e)))},[a,s,l]);(0,E.useEffect)(()=>{if(!d)return;let e=b.current;e&&(e.scrollTop=e.scrollHeight)},[x.length,d]);let w=(0,E.useMemo)(()=>x.map(e=>v?`${R(e.ts)} [${e.stream}] ${e.line}`:e.line).join(`
2
+ `),[x,v]);return(0,D.jsxs)(f,{padded:!1,className:`overflow-hidden`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-line px-4 py-3`,children:[(0,D.jsx)(`h3`,{className:`mr-1 text-base font-semibold text-fg`,children:`Process logs`}),(0,D.jsx)(C,{options:L,value:s,onChange:c}),(0,D.jsxs)(`div`,{className:`relative min-w-40 flex-1`,children:[(0,D.jsx)(o,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-faint`}),(0,D.jsx)(`input`,{value:l,onChange:e=>u(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,D.jsx)(H,{on:d,onClick:()=>g(e=>!e),label:`Follow`}),(0,D.jsx)(H,{on:v,onClick:()=>y(e=>!e),label:`Times`}),(0,D.jsx)(S,{value:w}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>{B(w)},disabled:x.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`})]}),n&&e&&(0,D.jsx)(`div`,{className:`border-b border-line px-4 pt-3 font-sans`,children:(0,D.jsx)(p,{message:`Process-log refresh failed — showing the last received lines. ${n.message}`,onRetry:i})}),(0,D.jsx)(`div`,{ref:b,className:`max-h-80 min-h-40 overflow-y-auto p-4 font-mono text-xs leading-relaxed`,children:r&&!e&&!n?(0,D.jsx)(`div`,{className:`font-sans`,children:(0,D.jsx)(h,{label:`Loading process logs…`})}):n&&!e?(0,D.jsx)(`div`,{className:`font-sans`,children:(0,D.jsx)(m,{error:n,onRetry:i})}):x.length===0?(0,D.jsx)(`p`,{className:`text-faint`,children:a.length===0?`No output yet.`:`No lines match the current filter.`}):x.map(e=>(0,D.jsxs)(`div`,{className:t(`whitespace-pre-wrap`,z(e.stream)),children:[v&&(0,D.jsx)(`span`,{className:`mr-2 text-faint`,children:R(e.ts)}),e.line]},e.seq))}),(0,D.jsxs)(`div`,{className:`flex items-center justify-between border-t border-line px-4 py-2 text-[11px] text-faint`,children:[(0,D.jsx)(`span`,{children:n&&!e?`logs unavailable`:x.length===a.length?`${a.length} lines`:`${x.length} of ${a.length} lines`}),(0,D.jsx)(`span`,{children:n?`refresh failed`:d?`following tail`:`paused`})]})]})}function H({on:e,onClick:n,label:r}){return(0,D.jsx)(`button`,{type:`button`,onClick:n,"aria-pressed":e,className:t(`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:r})}function U(){return l(()=>i.control.logs(),[])}var W={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 G({startedAt:e}){let[,t]=(0,E.useState)(0);return(0,E.useEffect)(()=>{let e=setInterval(()=>t(e=>e+1),1e3);return()=>clearInterval(e)},[]),(0,D.jsx)(D.Fragment,{children:x((Date.now()-e)/1e3)})}function K({label:e,children:t,title:n}){return(0,D.jsxs)(`div`,{className:`min-w-0`,title:n,children:[(0,D.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-faint`,children:e}),(0,D.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-sm text-fg`,children:t})]})}function q({status:e,agentBase:n,transitioning:r,stale:i=!1,vitals:o=null,busy:l,onStart:d,onStop:f,onRestart:p}){let m=e?.status??`stopped`,h=e?.managementMode===`external`,g=h?e?.reachable===!0:m===`running`,_=h?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`}:W[m]??W.stopped,y=!!e?.healthy&&!i,b=!h&&!g&&e?.exitCode!=null&&e.exitCode!==0,x=e?.runningConfig??e?.config??null,C=x?.httpPort??6790,w=h?e?.externalUrl??`—`:`http://localhost:${C}`,T=w===`—`?`—`:`${w}/health`;return(0,D.jsxs)(`section`,{className:`mb-6 overflow-hidden rounded-xl border border-line bg-surface`,children:[(0,D.jsx)(`div`,{className:t(`h-0.5 bg-gradient-to-r to-transparent`,g&&y?`from-emerald-400/80 via-emerald-400/25`:g||r?`from-amber-400/80 via-amber-400/25`:`from-red-400/70 via-red-400/20`)}),(0,D.jsxs)(`div`,{className:`flex flex-col gap-5 p-5 lg:flex-row lg:items-center lg:justify-between`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,D.jsxs)(`span`,{className:`relative flex size-3.5 shrink-0`,children:[g&&y&&(0,D.jsx)(`span`,{className:`absolute inline-flex size-full rounded-full bg-emerald-400 opacity-50 motion-safe:animate-ping`}),(0,D.jsx)(`span`,{className:t(`relative inline-flex size-3.5 rounded-full`,_.dot)})]}),(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3 gap-y-1`,children:[(0,D.jsx)(`span`,{className:t(`text-2xl font-bold tracking-tight`,_.tone),children:r&&l?`${l}…`:_.label}),e?.version&&(0,D.jsxs)(`span`,{className:`font-mono text-xs text-muted`,children:[`bunqueue v`,e.version]}),b&&(0,D.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,D.jsx)(`div`,{className:`mt-1 font-mono text-xs text-muted`,children:i?(0,D.jsxs)(`span`,{className:`text-warning`,children:[`last known: pid `,e?.pid??`—`,` — agent unreachable, state may have changed`]}):h?(0,D.jsx)(`span`,{title:e?.healthError,children:e?.reachable?y?`healthy via ${T}`:`reachable but unhealthy via ${T}`:`unreachable via ${T}`}):g?(0,D.jsxs)(D.Fragment,{children:[y?`healthy`:`waiting for health…`,` · pid `,e?.pid??`—`,` · up`,` `,e?.startedAt?(0,D.jsx)(G,{startedAt:e.startedAt}):`—`]}):`process not running — start it below or point the dashboard at an external server`})]})]}),!h&&(0,D.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,D.jsxs)(u,{variant:`success`,disabled:g||r||i,onClick:d,children:[(0,D.jsx)(c,{className:`size-4`}),` Start`]}),(0,D.jsxs)(u,{variant:`warning`,disabled:!g||r||i,onClick:f,children:[(0,D.jsx)(s,{className:`size-4`}),` Stop`]}),(0,D.jsxs)(u,{disabled:r||i,onClick:p,children:[(0,D.jsx)(a,{className:`size-4`}),` Restart`]})]})]}),(0,D.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,D.jsx)(K,{label:`Memory`,children:o?.memory?.rss==null?(0,D.jsx)(`span`,{className:`text-faint`,children:`—`}):(0,D.jsxs)(`span`,{title:`heap ${o.memory.heapUsed??`?`} / ${o.memory.heapTotal??`?`} MB`,children:[o.memory.rss,` MB rss`]})}),(0,D.jsx)(K,{label:`Connections`,children:o?.connections?`${o.connections.tcp??0} tcp · ${o.connections.ws??0} ws · ${o.connections.sse??0} sse`:(0,D.jsx)(`span`,{className:`text-faint`,children:`—`})}),(0,D.jsx)(K,{label:h?`Health target`:`API endpoint`,title:T,children:w===`—`?(0,D.jsx)(`span`,{className:`text-faint`,children:w}):(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(`a`,{href:T,target:`_blank`,rel:`noreferrer`,className:`truncate text-accent hover:underline`,children:w}),(0,D.jsx)(S,{value:w})]})}),(0,D.jsx)(K,{label:h?`Lifecycle`:`Ports`,children:h?`external`:x?`${x.httpPort} http · ${x.tcpPort} tcp`:`—`}),(0,D.jsx)(K,{label:h?`Health HTTP`:`Started`,children:h?e?.healthStatus??`—`:g&&e?.startedAt?v(e.startedAt):`—`}),(0,D.jsx)(K,{label:`Control agent`,title:n,children:n.replace(/^https?:\/\//,``)}),(0,D.jsx)(K,{label:h?`Supervisor`:`Launch command`,title:x?.command,children:h?`managed elsewhere`:x?.command??`—`})]})]})}var J=[{key:`size`,label:`Database`,color:`bg-accent`},{key:`walSize`,label:`WAL`,color:`bg-amber-400`},{key:`shmSize`,label:`SHM`,color:`bg-zinc-500`}];function Y({db:e}){let n=e.totalSize||0;return(0,D.jsxs)(f,{children:[(0,D.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between gap-2`,children:[(0,D.jsx)(`h3`,{className:`text-base font-semibold text-fg`,children:`Storage`}),(0,D.jsx)(`span`,{className:`font-mono text-xs text-muted`,children:e.exists?`${b(n)} on disk`:`not created yet`})]}),(0,D.jsxs)(`p`,{className:`mb-4 flex items-center gap-1.5 truncate font-mono text-xs text-faint`,title:e.path,children:[(0,D.jsx)(`span`,{className:`truncate`,children:e.path}),(0,D.jsx)(S,{value:e.path})]}),e.exists&&n>0?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`flex h-2.5 overflow-hidden rounded-full bg-surface-2`,children:J.map(r=>{let i=e[r.key];return i?(0,D.jsx)(`div`,{className:t(`h-full`,r.color),style:{width:`${i/n*100}%`},title:`${r.label}: ${b(i)}`},r.key):null})}),(0,D.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-5 gap-y-1.5 font-mono text-[11px] text-faint`,children:[J.map(n=>(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:t(`size-2 rounded-full`,n.color)}),n.label,` `,(0,D.jsx)(`span`,{className:`text-fg`,children:b(e[n.key])})]},n.key)),e.mtimeMs?(0,D.jsxs)(`span`,{className:`ml-auto`,children:[`written `,y(e.mtimeMs)]}):null]})]}):(0,D.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 X(){let{data:e,error:t,refetch:n}=l(()=>i.control.status(),[]),[r,a]=(0,E.useState)(null),[o,s]=(0,E.useState)(null),c=e?.managementMode===`external`,u=c?e?.reachable===!0:e?.status===`running`,{data:m}=l(()=>u?i.health():Promise.resolve(null),[u]),h=u?m??null:null,_=h?.connections?` This drops ${h.connections.tcp??0} TCP / ${h.connections.ws??0} WS connections; in-flight jobs are interrupted.`:` In-flight jobs are interrupted.`,v=async(e,t,r)=>{if(!(r&&!window.confirm(r))){a(e),s(null);try{await t(),await n()}catch(e){s(e.message)}finally{a(null)}}};if(t&&!e)return(0,D.jsxs)(`div`,{children:[(0,D.jsx)(g,{title:`Server`,description:`Start, stop and restart the bunqueue server.`}),(0,D.jsx)(p,{message:`Control agent unreachable — server lifecycle controls are unavailable.`,onRetry:n}),(0,D.jsxs)(f,{children:[(0,D.jsx)(d,{title:`Control agent not running`}),(0,D.jsxs)(`p`,{className:`text-sm text-muted`,children:[`The local control agent is unreachable at`,` `,(0,D.jsx)(`code`,{className:`rounded bg-surface-2 px-1.5 py-0.5 text-xs`,children:i.agentBase}),`. It manages the bunqueue server process (start / stop / restart). Start it with:`]}),(0,D.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
+ `,`bun run agent`,` `,`# agent only, if the dashboard is already running`]}),(0,D.jsx)(`p`,{className:`mt-3 text-xs text-faint`,children:`This page reconnects automatically once the agent is up — no reload needed.`})]})]});let y=e?.status??`stopped`,b=y===`running`,x=y===`starting`||y===`stopping`||r!=null,S=t!=null&&e!=null;return(0,D.jsxs)(`div`,{children:[(0,D.jsx)(g,{title:`Server`,description:c?`Observe the Bunqueue server managed by an external supervisor.`:`Supervise the bunqueue server process — lifecycle, configuration, storage and logs.`}),o&&(0,D.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:o}),S&&(0,D.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,D.jsx)(q,{status:e,agentBase:i.agentBase,stale:S,vitals:h,transitioning:x,busy:r,onStart:()=>v(`starting`,()=>i.control.start()),onStop:()=>v(`stopping`,()=>i.control.stop(),`Stop the bunqueue server?${_}`),onRestart:()=>v(`restarting`,()=>i.control.restart(),`Restart the bunqueue server?${_}`)}),c?(0,D.jsxs)(f,{children:[(0,D.jsx)(d,{title:`Managed externally`}),(0,D.jsxs)(`p`,{className:`text-sm text-muted`,children:[`This dashboard is attached to`,` `,(0,D.jsx)(`code`,{className:`rounded bg-surface-2 px-1.5 py-0.5 text-xs`,children:e?.externalUrl??`BUNQUEUE_URL`}),`. Start, stop, restart and launch configuration are intentionally unavailable while`,` `,(0,D.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,D.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,D.jsx)(I,{status:e,onSaved:n,running:b,transitioning:x}),(0,D.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[e?.db&&(0,D.jsx)(Y,{db:e.db}),(0,D.jsx)(V,{})]})]}),(0,D.jsx)(`div`,{className:`mt-6`,children:(0,D.jsx)(k,{agentBase:i.agentBase})})]})}export{X as ServerControl};
@@ -1 +1 @@
1
- import{i as e}from"./cn-zFEt5SO8.js";import{g as t,t as n}from"./react-vendor-CyjgmGTq.js";import{a as r,o as i,t as a}from"./connectionStore-DbBYqHEY.js";import{f as o}from"./icons-CIvFfU2b.js";import{n as s,t as c}from"./Button-BPqpRZJD.js";import{n as l,t as u}from"./Card-C7NMhqUt.js";import{t as d}from"./PageHeader-BXlZSBcc.js";import{o as f}from"./index-Cui9IwWy.js";import{a as p,n as m,t as h}from"./form-tC20r4Ma.js";var g=e(t(),1),_=n(),v=[[`1000`,`1 second`],[`2000`,`2 seconds`],[`3000`,`3 seconds`],[`5000`,`5 seconds`],[`10000`,`10 seconds`]];function y(){let{refreshMs:e,setRefreshMs:t}=i(),{theme:n,setTheme:r}=f();return(0,_.jsxs)(u,{children:[(0,_.jsx)(l,{title:`Appearance & refresh`}),(0,_.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,_.jsx)(h,{label:`Theme`,children:(0,_.jsxs)(p,{name:`theme`,autoComplete:`off`,value:n,onChange:e=>r(e.target.value),children:[(0,_.jsx)(`option`,{value:`dark`,children:`Dark`}),(0,_.jsx)(`option`,{value:`light`,children:`Light`})]})}),(0,_.jsx)(h,{label:`Refresh interval`,children:(0,_.jsx)(p,{name:`refresh-interval`,autoComplete:`off`,value:String(e),onChange:e=>t(Number(e.target.value)),children:v.map(([e,t])=>(0,_.jsx)(`option`,{value:e,children:t},e))})})]})]})}var 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});if(!n.ok&&n.status!==503)throw Error(`HTTP ${n.status}`);let r=await n.json();if(typeof r!=`object`||!r||Array.isArray(r))throw Error(`Malformed health response`);let i=r;if(typeof i.ok!=`boolean`||i.status!==`healthy`&&i.status!==`degraded`||!Number.isSafeInteger(i.uptime)||i.uptime<0||typeof i.version!=`string`||!x.test(i.version)||i.ok!==(i.status===`healthy`))throw Error(`Malformed health response`);return{response:n,health:i}})();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?.()}}function C(){let{baseUrl:e,token:t,agentToken:n,saveConnection:f}=i(),[p,v]=(0,g.useState)(!1),[b,x]=(0,g.useState)(null),[C,w]=(0,g.useState)(e),[T,E]=(0,g.useState)(t),[D,O]=(0,g.useState)(n),[k,A]=(0,g.useState)(!1),[j,M]=(0,g.useState)(!1),[N,P]=(0,g.useState)(null),[F,I]=(0,g.useState)(null),L=(0,g.useRef)(!0),R=(0,g.useRef)(0),z=(0,g.useRef)(null),B=(0,g.useRef)(null),V=(0,g.useCallback)(()=>{B.current!==null&&(clearTimeout(B.current),B.current=null),L.current&&I(null)},[]),H=(0,g.useCallback)(()=>{R.current+=1,z.current?.abort(new DOMException(`Connection test superseded`,`AbortError`)),z.current=null,L.current&&(v(!1),x(null))},[]);return(0,g.useEffect)(()=>(L.current=!0,()=>{L.current=!1,R.current+=1,z.current?.abort(new DOMException(`Settings unmounted`,`AbortError`)),z.current=null,B.current!==null&&(clearTimeout(B.current),B.current=null)}),[]),(0,g.useEffect)(()=>{w(e),E(t),O(n),H()},[n,e,H,t]),(0,_.jsxs)(`div`,{children:[(0,_.jsx)(d,{title:`Settings`,description:`Connection and appearance.`}),(0,_.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,_.jsxs)(u,{children:[(0,_.jsx)(l,{title:`Connection`}),(0,_.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,_.jsx)(h,{label:`Server URL`,children:(0,_.jsx)(m,{name:`server-url`,value:C,onChange:e=>{H(),V(),w(e.target.value),P(null)},placeholder:`/api or https://queue.example.com`,autoComplete:`off`,inputMode:`url`,"aria-invalid":N?!0:void 0,"aria-describedby":N?`server-url-error`:`server-url-help`})}),N&&(0,_.jsx)(`p`,{id:`server-url-error`,className:`-mt-2 text-xs text-danger`,children:N}),(0,_.jsxs)(`p`,{id:`server-url-help`,className:`-mt-2 text-xs text-faint`,children:[`Use `,(0,_.jsx)(`code`,{className:`font-mono`,children:`/api`}),` in dev (proxied to localhost:6790), or the server origin in production.`]}),(0,_.jsx)(h,{label:`Bearer token (optional)`,hint:`Kept in memory only — re-enter after reload. Never bake secrets into VITE_* variables.`,htmlFor:`bearer-token`,children:(0,_.jsxs)(`div`,{className:`relative`,children:[(0,_.jsx)(m,{id:`bearer-token`,name:`bearer-token`,type:k?`text`:`password`,value:T,onChange:e=>{H(),V(),E(e.target.value)},placeholder:`only if AUTH_TOKENS is set`,className:`pr-10`,autoComplete:`off`,spellCheck:!1}),(0,_.jsx)(s,{"aria-label":k?`Hide token`:`Show token`,className:`absolute right-0.5 top-1/2 -translate-y-1/2`,onClick:()=>A(e=>!e),children:(0,_.jsx)(o,{className:`size-4`})})]})}),(0,_.jsx)(h,{label:`Agent token (optional)`,hint:`Only if the control agent runs with AGENT_TOKEN. Kept in memory; re-enter after reload.`,htmlFor:`agent-token`,children:(0,_.jsxs)(`div`,{className:`relative`,children:[(0,_.jsx)(m,{id:`agent-token`,name:`agent-token`,type:j?`text`:`password`,value:D,onChange:e=>{H(),V(),O(e.target.value)},placeholder:`only if AGENT_TOKEN is set`,className:`pr-10`,autoComplete:`off`,spellCheck:!1}),(0,_.jsx)(s,{"aria-label":j?`Hide agent token`:`Show agent token`,className:`absolute right-0.5 top-1/2 -translate-y-1/2`,onClick:()=>M(e=>!e),children:(0,_.jsx)(o,{className:`size-4`})})]})}),(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,_.jsx)(c,{variant:`accent`,onClick:()=>{H();let e=r(C);if(!e){P(a);return}P(null),w(e);let t=f({baseUrl:e,token:T,agentToken:D});V(),I({persisted:t.persisted,message:t.persisted?`Saved ✓`:`Saved for this session only — browser storage unavailable${t.error?`: ${t.error}`:`.`}`}),B.current=setTimeout(()=>{B.current=null,L.current&&I(null)},4e3)},children:`Save`}),(0,_.jsx)(c,{onClick:async()=>{H();let e=r(C);if(!e){P(a),x({ok:!1,msg:a});return}P(null);let t=R.current,n=new AbortController,o=i.getState(),s=()=>{let e=i.getState();return L.current&&t===R.current&&!n.signal.aborted&&e.baseUrl===o.baseUrl&&e.token===o.token&&e.agentToken===o.agentToken};z.current=n,v(!0),x(null);let c=performance.now();try{let{response:t,health:r}=await S(`${e}/health`,{headers:T.trim()?{Authorization:`Bearer ${T.trim()}`}:void 0,signal:n.signal});if(!s())return;let i=Math.round(performance.now()-c),a=t.status===503||r.status===`degraded`;x({ok:!a,msg:`${a?`Server reachable`:`Connected`} in ${i}ms · bunqueue v${r.version}${a?` · degraded`:``}`})}catch(e){if(!s())return;x({ok:!1,msg:e.message})}finally{L.current&&t===R.current&&(z.current=null,v(!1))}},children:p?`Restart test`:`Test connection`}),F&&(0,_.jsx)(`span`,{role:`status`,className:F.persisted?`text-sm text-success`:`text-sm text-warning`,children:F.message}),b&&(0,_.jsx)(`span`,{role:`status`,className:b.ok?`text-sm text-success`:`text-sm text-danger`,children:b.msg})]}),(0,_.jsx)(`p`,{className:`-mt-1 text-xs text-faint`,children:`Test checks the values above as typed. Saving repoints every page at the new server immediately.`})]})]}),(0,_.jsx)(y,{})]})]})}export{C as Settings};
1
+ import{i as e}from"./cn-zFEt5SO8.js";import{g as t,t as n}from"./react-vendor-CyjgmGTq.js";import{a as r,o as i,t as a}from"./connectionStore-CKFQrxDo.js";import{f as o}from"./icons-CIvFfU2b.js";import{n as s,t as c}from"./Button-BPqpRZJD.js";import{n as l,t as u}from"./Card-C7NMhqUt.js";import{t as d}from"./PageHeader-BXlZSBcc.js";import{o as f}from"./index-D64v2vNO.js";import{a as p,n as m,t as h}from"./form-tC20r4Ma.js";var g=e(t(),1),_=n(),v=[[`1000`,`1 second`],[`2000`,`2 seconds`],[`3000`,`3 seconds`],[`5000`,`5 seconds`],[`10000`,`10 seconds`]];function y(){let{refreshMs:e,setRefreshMs:t}=i(),{theme:n,setTheme:r}=f();return(0,_.jsxs)(u,{children:[(0,_.jsx)(l,{title:`Appearance & refresh`}),(0,_.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,_.jsx)(h,{label:`Theme`,children:(0,_.jsxs)(p,{name:`theme`,autoComplete:`off`,value:n,onChange:e=>r(e.target.value),children:[(0,_.jsx)(`option`,{value:`dark`,children:`Dark`}),(0,_.jsx)(`option`,{value:`light`,children:`Light`})]})}),(0,_.jsx)(h,{label:`Refresh interval`,children:(0,_.jsx)(p,{name:`refresh-interval`,autoComplete:`off`,value:String(e),onChange:e=>t(Number(e.target.value)),children:v.map(([e,t])=>(0,_.jsx)(`option`,{value:e,children:t},e))})})]})]})}var 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});if(!n.ok&&n.status!==503)throw Error(`HTTP ${n.status}`);let r=await n.json();if(typeof r!=`object`||!r||Array.isArray(r))throw Error(`Malformed health response`);let i=r;if(typeof i.ok!=`boolean`||i.status!==`healthy`&&i.status!==`degraded`||!Number.isSafeInteger(i.uptime)||i.uptime<0||typeof i.version!=`string`||!x.test(i.version)||i.ok!==(i.status===`healthy`))throw Error(`Malformed health response`);return{response:n,health:i}})();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?.()}}function C(){let{baseUrl:e,token:t,agentToken:n,saveConnection:f}=i(),[p,v]=(0,g.useState)(!1),[b,x]=(0,g.useState)(null),[C,w]=(0,g.useState)(e),[T,E]=(0,g.useState)(t),[D,O]=(0,g.useState)(n),[k,A]=(0,g.useState)(!1),[j,M]=(0,g.useState)(!1),[N,P]=(0,g.useState)(null),[F,I]=(0,g.useState)(null),L=(0,g.useRef)(!0),R=(0,g.useRef)(0),z=(0,g.useRef)(null),B=(0,g.useRef)(null),V=(0,g.useCallback)(()=>{B.current!==null&&(clearTimeout(B.current),B.current=null),L.current&&I(null)},[]),H=(0,g.useCallback)(()=>{R.current+=1,z.current?.abort(new DOMException(`Connection test superseded`,`AbortError`)),z.current=null,L.current&&(v(!1),x(null))},[]);return(0,g.useEffect)(()=>(L.current=!0,()=>{L.current=!1,R.current+=1,z.current?.abort(new DOMException(`Settings unmounted`,`AbortError`)),z.current=null,B.current!==null&&(clearTimeout(B.current),B.current=null)}),[]),(0,g.useEffect)(()=>{w(e),E(t),O(n),H()},[n,e,H,t]),(0,_.jsxs)(`div`,{children:[(0,_.jsx)(d,{title:`Settings`,description:`Connection and appearance.`}),(0,_.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,_.jsxs)(u,{children:[(0,_.jsx)(l,{title:`Connection`}),(0,_.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,_.jsx)(h,{label:`Server URL`,children:(0,_.jsx)(m,{name:`server-url`,value:C,onChange:e=>{H(),V(),w(e.target.value),P(null)},placeholder:`/api or https://queue.example.com`,autoComplete:`off`,inputMode:`url`,"aria-invalid":N?!0:void 0,"aria-describedby":N?`server-url-error`:`server-url-help`})}),N&&(0,_.jsx)(`p`,{id:`server-url-error`,className:`-mt-2 text-xs text-danger`,children:N}),(0,_.jsxs)(`p`,{id:`server-url-help`,className:`-mt-2 text-xs text-faint`,children:[`Use `,(0,_.jsx)(`code`,{className:`font-mono`,children:`/api`}),` in dev (proxied to localhost:6790), or the server origin in production.`]}),(0,_.jsx)(h,{label:`Bearer token (optional)`,hint:`Kept in memory only — re-enter after reload. Never bake secrets into VITE_* variables.`,htmlFor:`bearer-token`,children:(0,_.jsxs)(`div`,{className:`relative`,children:[(0,_.jsx)(m,{id:`bearer-token`,name:`bearer-token`,type:k?`text`:`password`,value:T,onChange:e=>{H(),V(),E(e.target.value)},placeholder:`only if AUTH_TOKENS is set`,className:`pr-10`,autoComplete:`off`,spellCheck:!1}),(0,_.jsx)(s,{"aria-label":k?`Hide token`:`Show token`,className:`absolute right-0.5 top-1/2 -translate-y-1/2`,onClick:()=>A(e=>!e),children:(0,_.jsx)(o,{className:`size-4`})})]})}),(0,_.jsx)(h,{label:`Agent token (optional)`,hint:`Only if the control agent runs with AGENT_TOKEN. Kept in memory; re-enter after reload.`,htmlFor:`agent-token`,children:(0,_.jsxs)(`div`,{className:`relative`,children:[(0,_.jsx)(m,{id:`agent-token`,name:`agent-token`,type:j?`text`:`password`,value:D,onChange:e=>{H(),V(),O(e.target.value)},placeholder:`only if AGENT_TOKEN is set`,className:`pr-10`,autoComplete:`off`,spellCheck:!1}),(0,_.jsx)(s,{"aria-label":j?`Hide agent token`:`Show agent token`,className:`absolute right-0.5 top-1/2 -translate-y-1/2`,onClick:()=>M(e=>!e),children:(0,_.jsx)(o,{className:`size-4`})})]})}),(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,_.jsx)(c,{variant:`accent`,onClick:()=>{H();let e=r(C);if(!e){P(a);return}P(null),w(e);let t=f({baseUrl:e,token:T,agentToken:D});V(),I({persisted:t.persisted,message:t.persisted?`Saved ✓`:`Saved for this session only — browser storage unavailable${t.error?`: ${t.error}`:`.`}`}),B.current=setTimeout(()=>{B.current=null,L.current&&I(null)},4e3)},children:`Save`}),(0,_.jsx)(c,{onClick:async()=>{H();let e=r(C);if(!e){P(a),x({ok:!1,msg:a});return}P(null);let t=R.current,n=new AbortController,o=i.getState(),s=()=>{let e=i.getState();return L.current&&t===R.current&&!n.signal.aborted&&e.baseUrl===o.baseUrl&&e.token===o.token&&e.agentToken===o.agentToken};z.current=n,v(!0),x(null);let c=performance.now();try{let{response:t,health:r}=await S(`${e}/health`,{headers:T.trim()?{Authorization:`Bearer ${T.trim()}`}:void 0,signal:n.signal});if(!s())return;let i=Math.round(performance.now()-c),a=t.status===503||r.status===`degraded`;x({ok:!a,msg:`${a?`Server reachable`:`Connected`} in ${i}ms · bunqueue v${r.version}${a?` · degraded`:``}`})}catch(e){if(!s())return;x({ok:!1,msg:e.message})}finally{L.current&&t===R.current&&(z.current=null,v(!1))}},children:p?`Restart test`:`Test connection`}),F&&(0,_.jsx)(`span`,{role:`status`,className:F.persisted?`text-sm text-success`:`text-sm text-warning`,children:F.message}),b&&(0,_.jsx)(`span`,{role:`status`,className:b.ok?`text-sm text-success`:`text-sm text-danger`,children:b.msg})]}),(0,_.jsx)(`p`,{className:`-mt-1 text-xs text-faint`,children:`Test checks the values above as typed. Saving repoints every page at the new server immediately.`})]})]}),(0,_.jsx)(y,{})]})]})}export{C as Settings};
@@ -1 +1 @@
1
- import{t as e}from"./react-vendor-CyjgmGTq.js";import{t}from"./api-CQ5Z7xR7.js";import{n}from"./usePolledData-DzlUpBOO.js";import{n as r,t as i}from"./Card-C7NMhqUt.js";import{i as a,n as o,r as s}from"./feedback-BnGE2oW2.js";import{t as c}from"./PageHeader-BXlZSBcc.js";import{l,n as u,s as d,u as f}from"./format-Cg7VCIZW.js";import{n as p}from"./index-Cui9IwWy.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)(s,{label:`Loading usage…`});if(g&&!e)return(0,m.jsxs)(`div`,{children:[(0,m.jsx)(c,{title:`Usage`,description:`Cumulative resource usage is unavailable.`}),(0,m.jsx)(o,{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)(c,{title:`Usage`,description:`Cumulative resource usage on the connected server.`,live:!!e&&!g&&T}),g&&(0,m.jsx)(a,{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)(p,{label:`Jobs Pushed`,value:d(b.totalPushed)}),(0,m.jsx)(p,{label:`Jobs Completed`,value:d(b.totalCompleted),tone:`green`}),(0,m.jsx)(p,{label:`Jobs Failed`,value:d(b.totalFailed),tone:b.totalFailed?`red`:`default`}),(0,m.jsx)(p,{label:`Jobs Pulled`,value:d(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)(i,{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:f(b.uptime/1e3)}),(0,m.jsx)(_,{label:`Heap used`,value:u(x.heapUsed*1024*1024)}),(0,m.jsx)(_,{label:`RSS`,value:u(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)(i,{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?l(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-CyjgmGTq.js";import{t}from"./api-V_sVpHDo.js";import{n}from"./usePolledData-c53tx1jw.js";import{n as r,t as i}from"./Card-C7NMhqUt.js";import{i as a,n as o,r as s}from"./feedback-BnGE2oW2.js";import{t as c}from"./PageHeader-BXlZSBcc.js";import{l,n as u,s as d,u as f}from"./format-Cg7VCIZW.js";import{n as p}from"./index-D64v2vNO.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)(s,{label:`Loading usage…`});if(g&&!e)return(0,m.jsxs)(`div`,{children:[(0,m.jsx)(c,{title:`Usage`,description:`Cumulative resource usage is unavailable.`}),(0,m.jsx)(o,{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)(c,{title:`Usage`,description:`Cumulative resource usage on the connected server.`,live:!!e&&!g&&T}),g&&(0,m.jsx)(a,{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)(p,{label:`Jobs Pushed`,value:d(b.totalPushed)}),(0,m.jsx)(p,{label:`Jobs Completed`,value:d(b.totalCompleted),tone:`green`}),(0,m.jsx)(p,{label:`Jobs Failed`,value:d(b.totalFailed),tone:b.totalFailed?`red`:`default`}),(0,m.jsx)(p,{label:`Jobs Pulled`,value:d(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)(i,{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:f(b.uptime/1e3)}),(0,m.jsx)(_,{label:`Heap used`,value:u(x.heapUsed*1024*1024)}),(0,m.jsx)(_,{label:`RSS`,value:u(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)(i,{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?l(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-CyjgmGTq.js";import{t}from"./bq-BeBxa743.js";import{n}from"./usePolledData-DzlUpBOO.js";import{n as r,t as i}from"./Card-C7NMhqUt.js";import{i as a,n as o,r as s}from"./feedback-BnGE2oW2.js";import{t as c}from"./PageHeader-BXlZSBcc.js";import{c as l,l as u,n as d,s as f,t as p,u as m}from"./format-Cg7VCIZW.js";import{n as h}from"./index-Cui9IwWy.js";var g=e(),_={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 v(){let{data:e,error:v,loading:b,refetch:x}=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`);let i=r.reduce((e,t)=>e+(t.counts?.failed??0),0);return{overview:e,storage:n.data,failedTotal:i}},[]);if(b&&!e&&!v)return(0,g.jsx)(s,{label:`Loading usage…`});if(v&&!e)return(0,g.jsxs)(`div`,{children:[(0,g.jsx)(c,{title:`Usage`,description:`Cumulative resource usage is unavailable.`}),(0,g.jsx)(o,{error:v,onRetry:x})]});let S=e??_,{stats:C,memory:w,crons:T}=S.overview,{storage:E,failedTotal:D}=S,O=p(C.completed,D),k=C.uptime?m(C.uptime/1e3):`—`;return(0,g.jsxs)(`div`,{children:[(0,g.jsx)(c,{title:`Usage`,description:`Cumulative resource usage on the connected server.`,live:!!e&&!v}),v&&(0,g.jsx)(a,{message:`Usage refresh failed — showing the last successful snapshot.`,onRetry:x}),(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-6`,children:[(0,g.jsx)(h,{label:`Completed`,value:f(C.completed),tone:`green`}),(0,g.jsx)(h,{label:`Failed`,value:f(D),tone:D?`red`:`default`}),(0,g.jsx)(h,{label:`Waiting`,value:f(C.waiting),tone:`amber`}),(0,g.jsx)(h,{label:`Active`,value:f(C.active),tone:`blue`}),(0,g.jsx)(h,{label:`Error Rate`,value:O==null?`—`:l(O),tone:O==null?`default`:O>.05?`red`:`green`}),(0,g.jsx)(h,{label:`Uptime`,value:k})]}),(0,g.jsxs)(`div`,{className:`mt-6 grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,g.jsxs)(i,{children:[(0,g.jsx)(r,{title:`Runtime`}),(0,g.jsxs)(`dl`,{className:`divide-y divide-line text-sm`,children:[(0,g.jsx)(y,{label:`Jobs pushed (since restart)`,value:f(C.totalPushed)}),(0,g.jsx)(y,{label:`Jobs pulled (since restart)`,value:f(C.totalPulled)}),(0,g.jsx)(y,{label:`Heap used`,value:d(w.heapUsed*1024*1024)}),(0,g.jsx)(y,{label:`RSS`,value:d(w.rss*1024*1024)}),(0,g.jsx)(y,{label:`Cron jobs`,value:String(T.total)})]})]}),(0,g.jsxs)(i,{children:[(0,g.jsx)(r,{title:`Storage`}),E.diskFull?(0,g.jsxs)(`div`,{className:`rounded-lg border border-red-500/25 bg-red-500/[0.06] px-4 py-3`,children:[(0,g.jsx)(`div`,{className:`font-semibold text-danger`,children:`Disk full — writes suspended`}),E.error&&(0,g.jsx)(`div`,{className:`mt-1 text-xs text-muted`,children:E.error}),E.since!=null&&(0,g.jsxs)(`div`,{className:`mt-1 text-xs text-faint`,children:[`since `,u(E.since)]})]}):(0,g.jsxs)(`div`,{className:`rounded-lg border border-emerald-500/25 bg-emerald-500/[0.06] px-4 py-3`,children:[(0,g.jsx)(`div`,{className:`font-semibold text-success`,children:`Healthy`}),(0,g.jsx)(`div`,{className:`mt-1 text-xs text-faint`,children:`Disk writes are being accepted.`})]})]})]})]})}function y({label:e,value:t}){return(0,g.jsxs)(`div`,{className:`flex items-center justify-between py-2.5`,children:[(0,g.jsx)(`dt`,{className:`text-muted`,children:e}),(0,g.jsx)(`dd`,{className:`font-medium text-fg`,children:t})]})}export{v as UsagePro};
1
+ import{t as e}from"./react-vendor-CyjgmGTq.js";import{t}from"./bq-DYmbVkgR.js";import{n}from"./usePolledData-c53tx1jw.js";import{n as r,t as i}from"./Card-C7NMhqUt.js";import{i as a,n as o,r as s}from"./feedback-BnGE2oW2.js";import{t as c}from"./PageHeader-BXlZSBcc.js";import{c as l,l as u,n as d,s as f,t as p,u as m}from"./format-Cg7VCIZW.js";import{n as h}from"./index-D64v2vNO.js";var g=e(),_={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 v(){let{data:e,error:v,loading:b,refetch:x}=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`);let i=r.reduce((e,t)=>e+(t.counts?.failed??0),0);return{overview:e,storage:n.data,failedTotal:i}},[]);if(b&&!e&&!v)return(0,g.jsx)(s,{label:`Loading usage…`});if(v&&!e)return(0,g.jsxs)(`div`,{children:[(0,g.jsx)(c,{title:`Usage`,description:`Cumulative resource usage is unavailable.`}),(0,g.jsx)(o,{error:v,onRetry:x})]});let S=e??_,{stats:C,memory:w,crons:T}=S.overview,{storage:E,failedTotal:D}=S,O=p(C.completed,D),k=C.uptime?m(C.uptime/1e3):`—`;return(0,g.jsxs)(`div`,{children:[(0,g.jsx)(c,{title:`Usage`,description:`Cumulative resource usage on the connected server.`,live:!!e&&!v}),v&&(0,g.jsx)(a,{message:`Usage refresh failed — showing the last successful snapshot.`,onRetry:x}),(0,g.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-6`,children:[(0,g.jsx)(h,{label:`Completed`,value:f(C.completed),tone:`green`}),(0,g.jsx)(h,{label:`Failed`,value:f(D),tone:D?`red`:`default`}),(0,g.jsx)(h,{label:`Waiting`,value:f(C.waiting),tone:`amber`}),(0,g.jsx)(h,{label:`Active`,value:f(C.active),tone:`blue`}),(0,g.jsx)(h,{label:`Error Rate`,value:O==null?`—`:l(O),tone:O==null?`default`:O>.05?`red`:`green`}),(0,g.jsx)(h,{label:`Uptime`,value:k})]}),(0,g.jsxs)(`div`,{className:`mt-6 grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,g.jsxs)(i,{children:[(0,g.jsx)(r,{title:`Runtime`}),(0,g.jsxs)(`dl`,{className:`divide-y divide-line text-sm`,children:[(0,g.jsx)(y,{label:`Jobs pushed (since restart)`,value:f(C.totalPushed)}),(0,g.jsx)(y,{label:`Jobs pulled (since restart)`,value:f(C.totalPulled)}),(0,g.jsx)(y,{label:`Heap used`,value:d(w.heapUsed*1024*1024)}),(0,g.jsx)(y,{label:`RSS`,value:d(w.rss*1024*1024)}),(0,g.jsx)(y,{label:`Cron jobs`,value:String(T.total)})]})]}),(0,g.jsxs)(i,{children:[(0,g.jsx)(r,{title:`Storage`}),E.diskFull?(0,g.jsxs)(`div`,{className:`rounded-lg border border-red-500/25 bg-red-500/[0.06] px-4 py-3`,children:[(0,g.jsx)(`div`,{className:`font-semibold text-danger`,children:`Disk full — writes suspended`}),E.error&&(0,g.jsx)(`div`,{className:`mt-1 text-xs text-muted`,children:E.error}),E.since!=null&&(0,g.jsxs)(`div`,{className:`mt-1 text-xs text-faint`,children:[`since `,u(E.since)]})]}):(0,g.jsxs)(`div`,{className:`rounded-lg border border-emerald-500/25 bg-emerald-500/[0.06] px-4 py-3`,children:[(0,g.jsx)(`div`,{className:`font-semibold text-success`,children:`Healthy`}),(0,g.jsx)(`div`,{className:`mt-1 text-xs text-faint`,children:`Disk writes are being accepted.`})]})]})]})]})}function y({label:e,value:t}){return(0,g.jsxs)(`div`,{className:`flex items-center justify-between py-2.5`,children:[(0,g.jsx)(`dt`,{className:`text-muted`,children:e}),(0,g.jsx)(`dd`,{className:`font-medium text-fg`,children:t})]})}export{v as UsagePro};
@@ -1 +1 @@
1
- import{i as e}from"./cn-zFEt5SO8.js";import{g as t,t as n}from"./react-vendor-CyjgmGTq.js";import{t as r}from"./bq-BeBxa743.js";import{t as i}from"./toastStore-CS_9Xndn.js";import{O as a,m as o}from"./icons-CIvFfU2b.js";import{n as s}from"./usePolledData-DzlUpBOO.js";import{n as c,t as l}from"./Button-BPqpRZJD.js";import{n as u,t as d}from"./Card-C7NMhqUt.js";import{i as f,n as p,r as m,t as h}from"./feedback-BnGE2oW2.js";import{t as g}from"./PageHeader-BXlZSBcc.js";import{l as _,s as v}from"./format-Cg7VCIZW.js";import{n as y,o as b,t as x}from"./form-tC20r4Ma.js";import{t as S}from"./Pagination-Q-vf4hsX.js";import{r as C,t as w}from"./useServerActionGuard-BlH-Kso1.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,a]=(0,E.useState)(``),[o,s]=(0,E.useState)(``),[c,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,o,c);if(!r.ok)return m(r.msg);let s=n();if(s){g(!0);try{if(w(await e(r.body),`Add webhook`),!s.isCurrent())return;a(``),u(``),t()}catch(e){s.isCurrent()&&m(e.message)}finally{s.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=>a(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:o,onChange:e=>s(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:c,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)(l,{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:l}=s(()=>r.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{if(w(await r.removeWebhook(e),`Remove webhook`),!t.isCurrent())return;l()}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`),a=R.current.get(e);if(a){a.desired=t,a.intent=n,L(r=>({...r,[e]:{value:t,intent:n}}));return}let o=F.begin(`webhook:${e}`);if(!o)return;let s={desired:t,intent:n,lease:o};R.current.set(e,s),L(r=>({...r,[e]:{value:t,intent:n}})),(async()=>{for(;o.isCurrent()&&R.current.get(e)===s;){let t=s.desired,n=null;try{w(await r.setWebhookEnabled(e,t),`Toggle webhook`)}catch(e){n=e instanceof Error?e:Error(String(e))}if(!o.isCurrent()||R.current.get(e)!==s)return;if(s.desired!==t)continue;if(await l(),!o.isCurrent()||R.current.get(e)!==s)return;if(s.desired!==t)continue;R.current.delete(e);let a=s.intent;L(t=>{if(t[e]?.intent!==a)return t;let{[e]:n,...r}=t;return r}),n&&i.error(`Webhook toggle failed`,n.message),o.finish();return}})()};return(0,A.jsxs)(`div`,{children:[(0,A.jsx)(g,{title:`Webhooks`,description:`HTTP callbacks fired on job events.`,live:!!e&&!t}),t&&e&&(0,A.jsx)(f,{message:`Webhook refresh failed — showing the last successful registry.`,onRetry:l}),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)(d,{className:`mb-6`,children:[(0,A.jsx)(u,{title:`Add webhook`}),(0,A.jsx)(j,{onAdd:e=>r.addWebhook(e),onAccepted:()=>void l(),beginAdd:()=>F.begin([`registry-write`,`add`]),scopeKey:F.scopeKey})]}),t&&!e?(0,A.jsx)(p,{error:t,onRetry:l}):n&&!e?(0,A.jsx)(m,{label:`Loading webhooks…`}):y.length===0?(0,A.jsx)(h,{icon:(0,A.jsx)(o,{}),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:v(e.successCount)}),` / `,(0,A.jsx)(`span`,{className:e.failureCount?`text-danger`:``,children:v(e.failureCount)})]}),(0,A.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:_(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)(c,{"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)(a,{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{i as e}from"./cn-zFEt5SO8.js";import{g as t,t as n}from"./react-vendor-CyjgmGTq.js";import{t as r}from"./bq-DYmbVkgR.js";import{t as i}from"./toastStore-B7n0zS0y.js";import{O as a,m as o}from"./icons-CIvFfU2b.js";import{n as s}from"./usePolledData-c53tx1jw.js";import{n as c,t as l}from"./Button-BPqpRZJD.js";import{n as u,t as d}from"./Card-C7NMhqUt.js";import{i as f,n as p,r as m,t as h}from"./feedback-BnGE2oW2.js";import{t as g}from"./PageHeader-BXlZSBcc.js";import{l as _,s as v}from"./format-Cg7VCIZW.js";import{n as y,o as b,t as x}from"./form-tC20r4Ma.js";import{t as S}from"./Pagination-Q-vf4hsX.js";import{r as C,t as w}from"./useServerActionGuard-OTv6_fU0.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,a]=(0,E.useState)(``),[o,s]=(0,E.useState)(``),[c,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,o,c);if(!r.ok)return m(r.msg);let s=n();if(s){g(!0);try{if(w(await e(r.body),`Add webhook`),!s.isCurrent())return;a(``),u(``),t()}catch(e){s.isCurrent()&&m(e.message)}finally{s.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=>a(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:o,onChange:e=>s(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:c,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)(l,{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:l}=s(()=>r.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{if(w(await r.removeWebhook(e),`Remove webhook`),!t.isCurrent())return;l()}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`),a=R.current.get(e);if(a){a.desired=t,a.intent=n,L(r=>({...r,[e]:{value:t,intent:n}}));return}let o=F.begin(`webhook:${e}`);if(!o)return;let s={desired:t,intent:n,lease:o};R.current.set(e,s),L(r=>({...r,[e]:{value:t,intent:n}})),(async()=>{for(;o.isCurrent()&&R.current.get(e)===s;){let t=s.desired,n=null;try{w(await r.setWebhookEnabled(e,t),`Toggle webhook`)}catch(e){n=e instanceof Error?e:Error(String(e))}if(!o.isCurrent()||R.current.get(e)!==s)return;if(s.desired!==t)continue;if(await l(),!o.isCurrent()||R.current.get(e)!==s)return;if(s.desired!==t)continue;R.current.delete(e);let a=s.intent;L(t=>{if(t[e]?.intent!==a)return t;let{[e]:n,...r}=t;return r}),n&&i.error(`Webhook toggle failed`,n.message),o.finish();return}})()};return(0,A.jsxs)(`div`,{children:[(0,A.jsx)(g,{title:`Webhooks`,description:`HTTP callbacks fired on job events.`,live:!!e&&!t}),t&&e&&(0,A.jsx)(f,{message:`Webhook refresh failed — showing the last successful registry.`,onRetry:l}),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)(d,{className:`mb-6`,children:[(0,A.jsx)(u,{title:`Add webhook`}),(0,A.jsx)(j,{onAdd:e=>r.addWebhook(e),onAccepted:()=>void l(),beginAdd:()=>F.begin([`registry-write`,`add`]),scopeKey:F.scopeKey})]}),t&&!e?(0,A.jsx)(p,{error:t,onRetry:l}):n&&!e?(0,A.jsx)(m,{label:`Loading webhooks…`}):y.length===0?(0,A.jsx)(h,{icon:(0,A.jsx)(o,{}),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:v(e.successCount)}),` / `,(0,A.jsx)(`span`,{className:e.failureCount?`text-danger`:``,children:v(e.failureCount)})]}),(0,A.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:_(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)(c,{"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)(a,{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{i as e}from"./cn-zFEt5SO8.js";import{g as t,t as n}from"./react-vendor-CyjgmGTq.js";import{A as r}from"./icons-CIvFfU2b.js";import{t as i}from"./api-CQ5Z7xR7.js";import{n as a}from"./usePolledData-DzlUpBOO.js";import{i as o,n as s,r as c,t as l}from"./feedback-BnGE2oW2.js";import{t as u}from"./PageHeader-BXlZSBcc.js";import{l as d,s as f}from"./format-Cg7VCIZW.js";import{n as p}from"./index-Cui9IwWy.js";import{t as m}from"./Pagination-Q-vf4hsX.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)(c,{label:`Loading workers…`});if(t&&!e)return(0,g.jsxs)(`div`,{children:[(0,g.jsx)(u,{title:`Workers`,description:`Worker inventory is unavailable.`}),(0,g.jsx)(s,{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)(o,{message:`Worker refresh failed — showing the last successful inventory.`,onRetry:y}),(0,g.jsx)(u,{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)(p,{label:`Total`,value:f(S.total),compact:!0}),(0,g.jsx)(p,{label:`Active`,value:f(S.active),tone:`green`,compact:!0})]}),S.list.length===0?(0,g.jsx)(l,{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:f(e.activeJobs)}),(0,g.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:f(e.processedJobs)}),(0,g.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:f(e.failedJobs)}),(0,g.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:d(e.lastSeen)})]},e.id))})]})}),S.truncated&&(0,g.jsxs)(`p`,{className:`mt-3 text-xs text-amber-400`,children:[`Showing first `,f(S.list.length),` of `,f(S.total),` `,`workers.`]}),(0,g.jsx)(m,{page:w,pageSize:_,total:S.list.length,onPageChange:x,label:`workers`})]})}export{y as Workers};
1
+ import{i as e}from"./cn-zFEt5SO8.js";import{g as t,t as n}from"./react-vendor-CyjgmGTq.js";import{A as r}from"./icons-CIvFfU2b.js";import{t as i}from"./api-V_sVpHDo.js";import{n as a}from"./usePolledData-c53tx1jw.js";import{i as o,n as s,r as c,t as l}from"./feedback-BnGE2oW2.js";import{t as u}from"./PageHeader-BXlZSBcc.js";import{l as d,s as f}from"./format-Cg7VCIZW.js";import{n as p}from"./index-D64v2vNO.js";import{t as m}from"./Pagination-Q-vf4hsX.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)(c,{label:`Loading workers…`});if(t&&!e)return(0,g.jsxs)(`div`,{children:[(0,g.jsx)(u,{title:`Workers`,description:`Worker inventory is unavailable.`}),(0,g.jsx)(s,{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)(o,{message:`Worker refresh failed — showing the last successful inventory.`,onRetry:y}),(0,g.jsx)(u,{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)(p,{label:`Total`,value:f(S.total),compact:!0}),(0,g.jsx)(p,{label:`Active`,value:f(S.active),tone:`green`,compact:!0})]}),S.list.length===0?(0,g.jsx)(l,{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:f(e.activeJobs)}),(0,g.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:f(e.processedJobs)}),(0,g.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:f(e.failedJobs)}),(0,g.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:d(e.lastSeen)})]},e.id))})]})}),S.truncated&&(0,g.jsxs)(`p`,{className:`mt-3 text-xs text-amber-400`,children:[`Showing first `,f(S.list.length),` of `,f(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{i as e,t}from"./cn-zFEt5SO8.js";import{g as n,t as r}from"./react-vendor-CyjgmGTq.js";import{t as i}from"./bq-BeBxa743.js";import{A as a,O as o}from"./icons-CIvFfU2b.js";import{n as s}from"./usePolledData-DzlUpBOO.js";import{n as c}from"./Button-BPqpRZJD.js";import{i as l,n as u,r as d,t as f}from"./feedback-BnGE2oW2.js";import{t as p}from"./PageHeader-BXlZSBcc.js";import{l as m,s as h}from"./format-Cg7VCIZW.js";import{n as g}from"./index-Cui9IwWy.js";import{r as _,t as v}from"./useServerActionGuard-BlH-Kso1.js";var y=e(n(),1),b=r(),x=100,S=`No heartbeat recently — derived from lastSeen`;function C(){let{data:e,error:n,loading:r,refetch:C}=s(async()=>(await i.workers()).data,[]),[T,E]=(0,y.useState)(new Set),[D,O]=(0,y.useState)(null),[k,A]=(0,y.useState)(null),j=_(`workers-pro`);if((0,y.useEffect)(()=>{E(new Set),O(null)},[j.scopeKey]),r&&!e&&!n)return(0,b.jsx)(d,{label:`Loading workers…`});if(n&&!e)return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(p,{title:`Workers`,description:`Worker inventory is unavailable.`}),(0,b.jsx)(u,{error:n,onRetry:C})]});let M=e?.workers??[],N=e?.quarantinedWorkers??[],P=(k?[...M].sort((e,t)=>{let n=k.key===`failed`?e.failedJobs??0:e.lastSeen??0,r=k.key===`failed`?t.failedJobs??0:t.lastSeen??0;return k.dir===`asc`?n-r:r-n}):M).slice(0,x),F=e=>A(t=>t?.key===e?{key:e,dir:t.dir===`desc`?`asc`:`desc`}:{key:e,dir:`desc`}),I=M.filter(e=>e.status===`active`).length,L=M.length-I,R=M.reduce((e,t)=>e+(t.activeJobs??0),0),z=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.8.57 workers do not automatically re-register after their heartbeat record is removed.`))return;let t=j.begin(`worker:${e}`);if(t){E(t=>new Set(t).add(e)),O(null);try{if(v(await i.unregisterWorker(e),`Remove stale worker registry record`),!t.isCurrent())return;O({ok:!0,text:`Removed stale registry record for ${e} ✓`}),C()}catch(e){if(!t.isCurrent())return;O({ok:!1,text:`Removal failed: ${e.message}`})}finally{t.finish()&&E(t=>{let n=new Set(t);return n.delete(e),n})}}};return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(p,{title:`Workers`,description:`Registered workers and their throughput.`,live:!!e&&!n}),n&&(0,b.jsx)(l,{message:`Worker refresh failed — showing the last successful inventory.`,onRetry:C}),(0,b.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-5`,children:[(0,b.jsx)(g,{label:`Total`,value:h(M.length+N.length),compact:!0}),(0,b.jsx)(g,{label:`Active`,value:h(I),tone:`green`,compact:!0}),(0,b.jsx)(`div`,{title:S,children:(0,b.jsx)(g,{label:`Stale`,value:h(L),tone:L?`amber`:`default`,compact:!0})}),(0,b.jsx)(g,{label:`Active Jobs`,value:h(R),tone:`blue`,compact:!0}),(0,b.jsx)(g,{label:`Quarantined`,value:h(N.length),tone:N.length?`red`:`default`,compact:!0})]}),N.length>0&&(0,b.jsxs)(`div`,{role:`alert`,className:`mb-4 rounded-lg border border-danger/30 bg-danger/5 p-4`,children:[(0,b.jsxs)(`p`,{className:`text-sm font-medium text-danger`,children:[N.length,` worker registration(s) contain values accepted by Bunqueue 2.8.57 but unsafe to render. Healthy workers remain available below.`]}),(0,b.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,b.jsx)(`ul`,{className:`mt-2 space-y-1 text-xs text-muted`,children:N.slice(0,20).map(e=>(0,b.jsxs)(`li`,{className:`truncate font-mono`,children:[`#`,e.index+1,` `,e.id??`(unaddressable id)`,` — `,e.reason]},`${e.index}:${e.id??`unknown`}`))})]}),D&&(0,b.jsx)(`div`,{className:t(`mb-3 text-sm`,D.ok?`text-success`:`text-danger`),children:D.text}),M.length===0?(0,b.jsx)(f,{icon:(0,b.jsx)(a,{}),title:N.length?`No renderable workers`:`No workers registered`,hint:N.length?`Malformed registrations are isolated above instead of taking down the inventory.`:`Workers appear here once they connect and register with the server.`}):(0,b.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,b.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,b.jsx)(`thead`,{children:(0,b.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,b.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Worker`}),(0,b.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queues`}),(0,b.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Status`}),(0,b.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Active`}),(0,b.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Processed`}),(0,b.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:(0,b.jsx)(w,{label:`Failed`,active:k?.key===`failed`?k.dir:null,onClick:()=>F(`failed`)})}),(0,b.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:(0,b.jsx)(w,{label:`Last Seen`,active:k?.key===`lastSeen`?k.dir:null,onClick:()=>F(`lastSeen`)})}),(0,b.jsx)(`th`,{className:`w-16 px-5 py-3 text-right font-medium`,children:`Actions`})]})}),(0,b.jsx)(`tbody`,{children:P.map(e=>(0,b.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,b.jsxs)(`td`,{className:`px-5 py-3`,children:[(0,b.jsx)(`div`,{className:`font-medium text-fg`,children:e.name||`worker`}),(0,b.jsx)(`div`,{className:`font-mono text-[11px] text-faint`,children:e.id})]}),(0,b.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queues.join(`, `)||`—`}),(0,b.jsx)(`td`,{className:`px-5 py-3`,children:(0,b.jsx)(`span`,{title:e.status===`active`?void 0:S,className:t(`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,b.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-blue-400`,children:h(e.activeJobs)}),(0,b.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:h(e.processedJobs)}),(0,b.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:h(e.failedJobs)}),(0,b.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:m(e.lastSeen)}),(0,b.jsx)(`td`,{className:`px-5 py-3`,children:(0,b.jsx)(`div`,{className:`flex justify-end`,children:e.status===`stale`&&e.activeJobs===0?(0,b.jsx)(c,{"aria-label":`Remove stale registry record for worker ${e.id}`,title:`Registry cleanup only — does not stop the worker process`,disabled:T.has(e.id),onClick:()=>z(e.id),children:(0,b.jsx)(o,{className:`size-3.5`})}):(0,b.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))})]})}),M.length>x&&(0,b.jsxs)(`p`,{className:`mt-3 text-xs text-warning`,children:[`Showing first `,h(x),` of `,h(M.length),` workers.`]})]})}function w({label:e,active:n,onClick:r}){return(0,b.jsxs)(`button`,{type:`button`,onClick:r,title:`Sort by ${e}`,className:t(`inline-flex items-center gap-1 uppercase tracking-wider transition-colors hover:text-fg`,n?`text-fg`:`text-faint`),children:[e,(0,b.jsx)(`span`,{"aria-hidden":`true`,children:n===`desc`?`↓`:n===`asc`?`↑`:``})]})}export{C as WorkersPro};
1
+ import{i as e,t}from"./cn-zFEt5SO8.js";import{g as n,t as r}from"./react-vendor-CyjgmGTq.js";import{t as i}from"./bq-DYmbVkgR.js";import{A as a,O as o}from"./icons-CIvFfU2b.js";import{n as s}from"./usePolledData-c53tx1jw.js";import{n as c}from"./Button-BPqpRZJD.js";import{i as l,n as u,r as d,t as f}from"./feedback-BnGE2oW2.js";import{t as p}from"./PageHeader-BXlZSBcc.js";import{l as m,s as h}from"./format-Cg7VCIZW.js";import{n as g}from"./index-D64v2vNO.js";import{r as _,t as v}from"./useServerActionGuard-OTv6_fU0.js";var y=e(n(),1),b=r(),x=100,S=`No heartbeat recently — derived from lastSeen`;function C(){let{data:e,error:n,loading:r,refetch:C}=s(async()=>(await i.workers()).data,[]),[T,E]=(0,y.useState)(new Set),[D,O]=(0,y.useState)(null),[k,A]=(0,y.useState)(null),j=_(`workers-pro`);if((0,y.useEffect)(()=>{E(new Set),O(null)},[j.scopeKey]),r&&!e&&!n)return(0,b.jsx)(d,{label:`Loading workers…`});if(n&&!e)return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(p,{title:`Workers`,description:`Worker inventory is unavailable.`}),(0,b.jsx)(u,{error:n,onRetry:C})]});let M=e?.workers??[],N=e?.quarantinedWorkers??[],P=(k?[...M].sort((e,t)=>{let n=k.key===`failed`?e.failedJobs??0:e.lastSeen??0,r=k.key===`failed`?t.failedJobs??0:t.lastSeen??0;return k.dir===`asc`?n-r:r-n}):M).slice(0,x),F=e=>A(t=>t?.key===e?{key:e,dir:t.dir===`desc`?`asc`:`desc`}:{key:e,dir:`desc`}),I=M.filter(e=>e.status===`active`).length,L=M.length-I,R=M.reduce((e,t)=>e+(t.activeJobs??0),0),z=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.8.59 workers do not automatically re-register after their heartbeat record is removed.`))return;let t=j.begin(`worker:${e}`);if(t){E(t=>new Set(t).add(e)),O(null);try{if(v(await i.unregisterWorker(e),`Remove stale worker registry record`),!t.isCurrent())return;O({ok:!0,text:`Removed stale registry record for ${e} ✓`}),C()}catch(e){if(!t.isCurrent())return;O({ok:!1,text:`Removal failed: ${e.message}`})}finally{t.finish()&&E(t=>{let n=new Set(t);return n.delete(e),n})}}};return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(p,{title:`Workers`,description:`Registered workers and their throughput.`,live:!!e&&!n}),n&&(0,b.jsx)(l,{message:`Worker refresh failed — showing the last successful inventory.`,onRetry:C}),(0,b.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-5`,children:[(0,b.jsx)(g,{label:`Total`,value:h(M.length+N.length),compact:!0}),(0,b.jsx)(g,{label:`Active`,value:h(I),tone:`green`,compact:!0}),(0,b.jsx)(`div`,{title:S,children:(0,b.jsx)(g,{label:`Stale`,value:h(L),tone:L?`amber`:`default`,compact:!0})}),(0,b.jsx)(g,{label:`Active Jobs`,value:h(R),tone:`blue`,compact:!0}),(0,b.jsx)(g,{label:`Quarantined`,value:h(N.length),tone:N.length?`red`:`default`,compact:!0})]}),N.length>0&&(0,b.jsxs)(`div`,{role:`alert`,className:`mb-4 rounded-lg border border-danger/30 bg-danger/5 p-4`,children:[(0,b.jsxs)(`p`,{className:`text-sm font-medium text-danger`,children:[N.length,` worker registration(s) contain values accepted by Bunqueue 2.8.59 but unsafe to render. Healthy workers remain available below.`]}),(0,b.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,b.jsx)(`ul`,{className:`mt-2 space-y-1 text-xs text-muted`,children:N.slice(0,20).map(e=>(0,b.jsxs)(`li`,{className:`truncate font-mono`,children:[`#`,e.index+1,` `,e.id??`(unaddressable id)`,` — `,e.reason]},`${e.index}:${e.id??`unknown`}`))})]}),D&&(0,b.jsx)(`div`,{className:t(`mb-3 text-sm`,D.ok?`text-success`:`text-danger`),children:D.text}),M.length===0?(0,b.jsx)(f,{icon:(0,b.jsx)(a,{}),title:N.length?`No renderable workers`:`No workers registered`,hint:N.length?`Malformed registrations are isolated above instead of taking down the inventory.`:`Workers appear here once they connect and register with the server.`}):(0,b.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,b.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,b.jsx)(`thead`,{children:(0,b.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,b.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Worker`}),(0,b.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queues`}),(0,b.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Status`}),(0,b.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Active`}),(0,b.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Processed`}),(0,b.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:(0,b.jsx)(w,{label:`Failed`,active:k?.key===`failed`?k.dir:null,onClick:()=>F(`failed`)})}),(0,b.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:(0,b.jsx)(w,{label:`Last Seen`,active:k?.key===`lastSeen`?k.dir:null,onClick:()=>F(`lastSeen`)})}),(0,b.jsx)(`th`,{className:`w-16 px-5 py-3 text-right font-medium`,children:`Actions`})]})}),(0,b.jsx)(`tbody`,{children:P.map(e=>(0,b.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,b.jsxs)(`td`,{className:`px-5 py-3`,children:[(0,b.jsx)(`div`,{className:`font-medium text-fg`,children:e.name||`worker`}),(0,b.jsx)(`div`,{className:`font-mono text-[11px] text-faint`,children:e.id})]}),(0,b.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queues.join(`, `)||`—`}),(0,b.jsx)(`td`,{className:`px-5 py-3`,children:(0,b.jsx)(`span`,{title:e.status===`active`?void 0:S,className:t(`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,b.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-blue-400`,children:h(e.activeJobs)}),(0,b.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:h(e.processedJobs)}),(0,b.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:h(e.failedJobs)}),(0,b.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:m(e.lastSeen)}),(0,b.jsx)(`td`,{className:`px-5 py-3`,children:(0,b.jsx)(`div`,{className:`flex justify-end`,children:e.status===`stale`&&e.activeJobs===0?(0,b.jsx)(c,{"aria-label":`Remove stale registry record for worker ${e.id}`,title:`Registry cleanup only — does not stop the worker process`,disabled:T.has(e.id),onClick:()=>z(e.id),children:(0,b.jsx)(o,{className:`size-3.5`})}):(0,b.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))})]})}),M.length>x&&(0,b.jsxs)(`p`,{className:`mt-3 text-xs text-warning`,children:[`Showing first `,h(x),` of `,h(M.length),` workers.`]})]})}function w({label:e,active:n,onClick:r}){return(0,b.jsxs)(`button`,{type:`button`,onClick:r,title:`Sort by ${e}`,className:t(`inline-flex items-center gap-1 uppercase tracking-wider transition-colors hover:text-fg`,n?`text-fg`:`text-faint`),children:[e,(0,b.jsx)(`span`,{"aria-hidden":`true`,children:n===`desc`?`↓`:n===`asc`?`↑`:``})]})}export{C as WorkersPro};