bunqueue-dashboard 1.0.3 → 1.0.5

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 (118) hide show
  1. package/README.md +162 -356
  2. package/dist/.vite/manifest.json +335 -608
  3. package/dist/assets/AddJob-g7DKWNZ0.js +3 -0
  4. package/dist/assets/Alerts-WcpDWdDf.js +1 -0
  5. package/dist/assets/{AreaChart-BMYp7z5y.js → AreaChart-CSP0-00u.js} +1 -1
  6. package/dist/assets/Benchmark-i6UOuIR-.js +1 -0
  7. package/dist/assets/{BulkAddJobs-0cdWqkEF.js → BulkAddJobs-56_SkYFd.js} +3 -3
  8. package/dist/assets/Cron-BnqxADsg.js +1 -0
  9. package/dist/assets/CronManager-4pAw6m87.js +1 -0
  10. package/dist/assets/Database-BDyQ8N-r.js +3 -0
  11. package/dist/assets/Diagnostics-DJNus54z.js +1 -0
  12. package/dist/assets/Dlq-BaHXmn0r.js +1 -0
  13. package/dist/assets/DlqControl-Bc48Yxxi.js +1 -0
  14. package/dist/assets/DlqPro-BaL9PRlj.js +1 -0
  15. package/dist/assets/Fleet-NYO3foQN.js +1 -0
  16. package/dist/assets/Flows-RPGep40V.js +2 -0
  17. package/dist/assets/JobInspector-DEboXZKA.js +2 -0
  18. package/dist/assets/Jobs-DRJLVzTB.js +1 -0
  19. package/dist/assets/JobsPro-BtoJgs_P.js +1 -0
  20. package/dist/assets/Logs-wZd30gMQ.js +1 -0
  21. package/dist/assets/LogsPro-Bed1atn5.js +1 -0
  22. package/dist/assets/{McpServer-ffXr4nFW.js → McpServer-CGe9T6dL.js} +2 -2
  23. package/dist/assets/Metrics-vii1CWGY.js +1 -0
  24. package/dist/assets/MetricsPro-Cbx-5-HO.js +1 -0
  25. package/dist/assets/Overview-2qju4F93.js +1 -0
  26. package/dist/assets/Pagination-ByDp7kNr.js +1 -0
  27. package/dist/assets/{QueueActions-BgdW95rN.js → QueueActions-BhjKtapT.js} +1 -1
  28. package/dist/assets/QueueControl-QMlFMQA6.js +1 -0
  29. package/dist/assets/QueueDetail-B-mcgloD.js +1 -0
  30. package/dist/assets/QueueDetailPro-BKFwiQUg.js +1 -0
  31. package/dist/assets/Queues-DCCwG__I.js +1 -0
  32. package/dist/assets/QueuesOverview-BMIfVWtk.js +1 -0
  33. package/dist/assets/S3Backup-DpLn5T8m.js +1 -0
  34. package/dist/assets/S3BackupPro-BUHJBozP.js +3 -0
  35. package/dist/assets/ServerControl-F5hvQwk3.js +3 -0
  36. package/dist/assets/Settings-UBD8Zrj0.js +1 -0
  37. package/dist/assets/{StatusBadge-cYUkK-4P.js → StatusBadge-D-mexaga.js} +1 -1
  38. package/dist/assets/Usage-D2D1i5nA.js +1 -0
  39. package/dist/assets/UsagePro-B8UDx-CC.js +1 -0
  40. package/dist/assets/Webhooks-TnNw3Mml.js +1 -0
  41. package/dist/assets/Workers-BAz4V_bk.js +1 -0
  42. package/dist/assets/WorkersPro-Cbh-P8vR.js +1 -0
  43. package/dist/assets/Workflows-CBMzJbn0.js +1 -0
  44. package/dist/assets/{api-Bbo86MB6.js → api-CCgfskjt.js} +1 -1
  45. package/dist/assets/{classicJobsData-BimIyQky.js → classicJobsData-wdIr-E4y.js} +1 -1
  46. package/dist/assets/connectionStore-B946Fhuv.js +1 -0
  47. package/dist/assets/controlConnectionEpoch-x9VjrWgN.js +1 -0
  48. package/dist/assets/{form-Dy-an7ew.js → form-DBkslwzu.js} +1 -1
  49. package/dist/assets/{icons-C1HVBnFn.js → icons-BIT5aq1c.js} +1 -1
  50. package/dist/assets/index-DR8flo6r.css +1 -0
  51. package/dist/assets/index-DcVSLtH4.js +8 -0
  52. package/dist/assets/install-Ch82YzWH.js +3 -0
  53. package/dist/assets/package-V6gqAKfV.js +1 -0
  54. package/dist/assets/react-vendor-08inPAVO.js +11 -0
  55. package/dist/assets/responses-YgpvqWEr.js +1 -0
  56. package/dist/assets/rolldown-runtime-XKyaHtl9.js +1 -0
  57. package/dist/assets/{useControlActionGuard-DImMgJtj.js → useControlActionGuard-Bx5MkufG.js} +1 -1
  58. package/dist/assets/{useServerActionGuard-Cr4KUOeZ.js → useServerActionGuard-uiZWD3dS.js} +1 -1
  59. package/dist/assets/useThroughputSeries-BZ9Bb2PU.js +1 -0
  60. package/dist/favicon.svg +11 -22
  61. package/dist/index.html +8 -16
  62. package/package.json +29 -36
  63. package/scripts/embedded.gen.ts +130 -146
  64. package/dist/assets/AddJob-jq-VZ_YE.js +0 -3
  65. package/dist/assets/Alerts-Bi8zLKXV.js +0 -1
  66. package/dist/assets/Benchmark-CWYdqm55.js +0 -1
  67. package/dist/assets/Button-BCjgbAhY.js +0 -1
  68. package/dist/assets/Card-DptfvL2O.js +0 -1
  69. package/dist/assets/Cron-dPGwJXqY.js +0 -1
  70. package/dist/assets/CronManager-C0-Y2QDg.js +0 -1
  71. package/dist/assets/Database-CseJOrvD.js +0 -3
  72. package/dist/assets/Diagnostics-cZTy4Y2t.js +0 -1
  73. package/dist/assets/Dlq-W2xOJiZM.js +0 -1
  74. package/dist/assets/DlqControl-CIV5278D.js +0 -1
  75. package/dist/assets/DlqPro-BuRxGtGt.js +0 -1
  76. package/dist/assets/Fleet-0zKJSjCw.js +0 -1
  77. package/dist/assets/Flows-CEfm102Y.js +0 -2
  78. package/dist/assets/JobInspector-BlMj5-Vr.js +0 -2
  79. package/dist/assets/Jobs-D_TId_Oa.js +0 -1
  80. package/dist/assets/JobsPro-A06ZG5Xi.js +0 -1
  81. package/dist/assets/Logs-hbh7XhQU.js +0 -1
  82. package/dist/assets/LogsPro-BgEIjgfj.js +0 -1
  83. package/dist/assets/Metrics-CIKZGgf0.js +0 -1
  84. package/dist/assets/MetricsPro-CK3WfLCl.js +0 -1
  85. package/dist/assets/Overview-BBgwyUn4.js +0 -1
  86. package/dist/assets/PageHeader-DD4vnVog.js +0 -1
  87. package/dist/assets/Pagination-Cj7GzYNX.js +0 -1
  88. package/dist/assets/QueueControl-g-9kwrpt.js +0 -1
  89. package/dist/assets/QueueDetail-Cv3MLDoE.js +0 -1
  90. package/dist/assets/QueueDetailPro-AhdOAzEF.js +0 -1
  91. package/dist/assets/Queues-Bbvh_OCE.js +0 -1
  92. package/dist/assets/QueuesOverview-sPQILfMU.js +0 -1
  93. package/dist/assets/S3Backup-Cg6sc2JG.js +0 -1
  94. package/dist/assets/S3BackupPro-BWV_R_Vj.js +0 -3
  95. package/dist/assets/ServerControl-Dr2gXbaU.js +0 -3
  96. package/dist/assets/Settings-BsDDlu-h.js +0 -1
  97. package/dist/assets/Usage-Cxx6pZfb.js +0 -1
  98. package/dist/assets/UsagePro-CkC8WYcS.js +0 -1
  99. package/dist/assets/Webhooks-BKWnALGC.js +0 -1
  100. package/dist/assets/Workers-SJ9MApx3.js +0 -1
  101. package/dist/assets/WorkersPro-BDgHBTpY.js +0 -1
  102. package/dist/assets/Workflows-Cp6jqKeM.js +0 -1
  103. package/dist/assets/bq-CSX8DSME.js +0 -1
  104. package/dist/assets/connectionStore-DdLzJyut.js +0 -1
  105. package/dist/assets/controlConnectionEpoch-D4HtriLM.js +0 -1
  106. package/dist/assets/feedback-Dxfj-Fy1.js +0 -1
  107. package/dist/assets/format-Cg7VCIZW.js +0 -1
  108. package/dist/assets/index-CxzFSZj3.js +0 -8
  109. package/dist/assets/index-DZXf58c2.css +0 -1
  110. package/dist/assets/install-DUkXE5kb.js +0 -3
  111. package/dist/assets/package-C7CtgBEy.js +0 -1
  112. package/dist/assets/react-vendor-DfC0iyIS.js +0 -11
  113. package/dist/assets/responses-BkR2JTH9.js +0 -1
  114. package/dist/assets/rolldown-runtime-QTnfLwEv.js +0 -1
  115. package/dist/assets/toastStore-DnqA_aL-.js +0 -1
  116. package/dist/assets/usePolledData-Dp_ynL9f.js +0 -1
  117. package/dist/assets/useThroughputSeries-CrTeR9s3.js +0 -1
  118. package/patches/ai@7.0.14.patch +0 -25
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{g as t,t as n}from"./react-vendor-DfC0iyIS.js";import{o as r}from"./connectionStore-DdLzJyut.js";import{t as i}from"./bq-CSX8DSME.js";import{b as a,x as o}from"./icons-C1HVBnFn.js";import{r as s}from"./StatusBadge-cYUkK-4P.js";import{n as c}from"./usePolledData-Dp_ynL9f.js";import{t as l}from"./Button-BCjgbAhY.js";import{n as u,t as d}from"./Card-DptfvL2O.js";import{t as f}from"./PageHeader-DD4vnVog.js";import{n as p,o as m,s as h}from"./format-Cg7VCIZW.js";import{a as g,r as _}from"./index-CxzFSZj3.js";import{i as v,n as y,o as b,t as x}from"./form-Dy-an7ew.js";import{t as S}from"./AreaChart-BMYp7z5y.js";var C=e(t(),1),w={total:1e6,batch:5e3,producers:64,payload:65536,workers:64,workerBatch:1e3,processMs:6e4,durationS:600},T={queue:`benchmark`,mode:`count`,total:5e3,durationS:30,batch:100,producers:4,payload:128,workers:4,workerBatch:100,processMs:5,durable:!1,removeOnComplete:!0},E=`bq-dashboard-benchmark-`;function D(){if(typeof globalThis.crypto?.randomUUID!=`function`)throw Error(`A cryptographically secure browser is required to create a benchmark queue.`);return`${E}${globalThis.crypto.randomUUID()}`}function O(e){return RegExp(`^${E}[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`,`i`).test(e)}var k={Smoke:{mode:`count`,total:200,batch:50,producers:2,workers:1,workerBatch:50,processMs:0},Standard:{mode:`count`,total:5e3,batch:100,producers:4,workers:4,workerBatch:100,processMs:5},Stress:{mode:`count`,total:5e4,batch:500,producers:16,workers:16,workerBatch:200,processMs:0},Soak:{mode:`duration`,durationS:30,batch:100,producers:4,workers:8,workerBatch:100,processMs:10}},A=(e,t,n)=>Number.isFinite(e)?Math.max(t,Math.min(n,Math.floor(e))):t;function j(e){return e?e.length>256?`Queue name is too long (maximum 256 characters).`:/^[a-zA-Z0-9_\-.:]+$/.test(e)?null:`Queue name contains unsupported characters.`:`Queue name is required.`}var M=(e,t)=>e.length?e[Math.min(e.length-1,Math.max(0,Math.ceil(t/100*e.length)-1))]:0,N=(e,t,n,r,i,a,o)=>Array.from({length:t},(t,s)=>({data:{i:e+s,blob:n},durable:r,removeOnComplete:i,...o===void 0?{}:{stallTimeout:o},...a?{jobId:`${a}-${e+s}`,tags:[`bunqueue-dashboard-benchmark`,a]}:{}})),P=e=>new Promise(t=>setTimeout(t,e)),F=async(e,t)=>{let n=performance.now()+e;for(;t()&&performance.now()<n;)await P(Math.min(100,Math.max(0,n-performance.now())))},I=e=>e instanceof Error?e.message:String(e),L=e=>e>=1e6?`${(e/1e6).toFixed(2)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:`${Math.round(e)}`,R=[`count`,`duration`],z=[`waiting`,`completed`,`failed`],B=null;function ee(){return B??=D(),B}var te=[`total`,`durationS`,`batch`,`producers`,`payload`,`workers`,`workerBatch`,`processMs`],ne=e=>({...e,total:String(e.total),durationS:String(e.durationS),batch:String(e.batch),producers:String(e.producers),payload:String(e.payload),workers:String(e.workers),workerBatch:String(e.workerBatch),processMs:String(e.processMs)}),V=e=>({...e,total:Number(e.total),durationS:Number(e.durationS),batch:Number(e.batch),producers:Number(e.producers),payload:Number(e.payload),workers:Number(e.workers),workerBatch:Number(e.workerBatch),processMs:Number(e.processMs)}),H=n();function re({draft:e,active:t,cleaning:n,cleanResult:r,setField:i,numberInput:a,onClean:o}){return(0,H.jsxs)(d,{className:`lg:col-span-1`,children:[(0,H.jsx)(u,{title:`Configuration`}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,H.jsx)(x,{label:`Dedicated queue`,hint:`Cryptographically generated for this browser tab; production queue names cannot be entered here.`,children:(0,H.jsx)(y,{name:`benchmark-queue`,autoComplete:`off`,value:e.queue,readOnly:!0,"aria-readonly":`true`})}),(0,H.jsx)(x,{label:`Mode`,hint:e.mode===`count`?`Push a fixed number of jobs.`:`Run producers + workers for a fixed time.`,children:(0,H.jsx)(v,{options:R,value:e.mode,onChange:e=>i(`mode`,e),disabled:t})}),e.mode===`count`?(0,H.jsx)(x,{label:`Total jobs`,hint:`max ${h(w.total)}`,children:(0,H.jsx)(y,{name:`benchmark-total`,autoComplete:`off`,type:`number`,min:1,max:w.total,value:e.total,disabled:t,onChange:a(`total`)})}):(0,H.jsx)(x,{label:`Duration (s)`,hint:`max ${w.durationS}s`,children:(0,H.jsx)(y,{name:`benchmark-duration-seconds`,autoComplete:`off`,type:`number`,min:1,max:w.durationS,value:e.durationS,disabled:t,onChange:a(`durationS`)})}),(0,H.jsx)(`div`,{className:`mt-1 text-[11px] font-semibold uppercase tracking-wider text-faint`,children:`Producers`}),(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,H.jsx)(x,{label:`Producers`,hint:`parallel, max ${w.producers}`,children:(0,H.jsx)(y,{name:`benchmark-producers`,autoComplete:`off`,type:`number`,min:1,max:w.producers,value:e.producers,disabled:t,onChange:a(`producers`)})}),(0,H.jsx)(x,{label:`Push batch`,hint:`jobs/req, max ${w.batch}`,children:(0,H.jsx)(y,{name:`benchmark-push-batch`,autoComplete:`off`,type:`number`,min:1,max:w.batch,value:e.batch,disabled:t,onChange:a(`batch`)})}),(0,H.jsx)(x,{label:`Payload`,hint:`bytes/job, max ${h(w.payload)}`,children:(0,H.jsx)(y,{name:`benchmark-payload-bytes`,autoComplete:`off`,type:`number`,min:0,max:w.payload,value:e.payload,disabled:t,onChange:a(`payload`)})})]}),(0,H.jsx)(`div`,{className:`mt-1 text-[11px] font-semibold uppercase tracking-wider text-faint`,children:`Workers (simulated)`}),(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,H.jsx)(x,{label:`Workers`,hint:`0 = produce only, max ${w.workers}`,children:(0,H.jsx)(y,{name:`benchmark-workers`,autoComplete:`off`,type:`number`,min:0,max:w.workers,value:e.workers,disabled:t,onChange:a(`workers`)})}),(0,H.jsx)(x,{label:`Pull batch`,hint:`jobs/pull, max ${w.workerBatch}`,children:(0,H.jsx)(y,{name:`benchmark-pull-batch`,autoComplete:`off`,type:`number`,min:1,max:w.workerBatch,value:e.workerBatch,disabled:t,onChange:a(`workerBatch`)})}),(0,H.jsx)(x,{label:`Process (ms)`,hint:`simulated work per pull`,children:(0,H.jsx)(y,{name:`benchmark-process-ms`,autoComplete:`off`,type:`number`,min:0,max:w.processMs,value:e.processMs,disabled:t,onChange:a(`processMs`)})})]}),(0,H.jsx)(U,{label:`Durable (fsync each job)`,checked:e.durable,active:t,onChange:e=>i(`durable`,e)}),(0,H.jsx)(U,{label:`Remove on complete`,checked:e.removeOnComplete,active:t,onChange:e=>i(`removeOnComplete`,e)}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,H.jsx)(l,{variant:`ghost`,size:`sm`,disabled:t||n,onClick:o,children:n?`Cleaning…`:`Clean queue`}),r&&(`error`in r?(0,H.jsxs)(`span`,{className:`text-xs text-danger`,children:[`Clean unverified — `,r.error]}):(0,H.jsx)(`span`,{className:s(`text-xs`,r.remaining>0?`text-warning`:`text-success`),children:r.remaining>0?`Cleaned — ${h(r.remaining)} active job(s) remain (requeued after the stall timeout)`:`Cleaned — 0 jobs remain`}))]})]})]})}function U({label:e,checked:t,active:n,onChange:r}){return(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(b,{checked:t,onChange:r,disabled:n,label:e}),(0,H.jsx)(`span`,{className:`text-sm text-muted`,children:e})]})}function ie({heading:e,pollBaseUrl:t,etaText:n,shown:r,shownWorkers:i,producePct:a,drainPct:o,durationPct:s,live:c,summary:l}){return(0,H.jsxs)(`div`,{className:`flex flex-col gap-6 lg:col-span-2`,children:[(0,H.jsxs)(d,{children:[(0,H.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,H.jsx)(`h3`,{className:`text-base font-semibold text-fg`,children:e}),(0,H.jsxs)(`span`,{className:`text-right text-xs text-faint`,children:[(0,H.jsxs)(`span`,{className:`block`,children:[`Benchmark target: `,t]}),n&&(0,H.jsx)(`span`,{className:`block`,children:n})]})]}),(0,H.jsx)(W,{label:r.mode===`duration`?`Elapsed`:`Produced`,pct:r.mode===`duration`?s:a,tone:`accent`}),i>0&&r.mode===`count`&&(0,H.jsx)(W,{label:`Completed`,pct:o,tone:`emerald`}),(0,H.jsxs)(`div`,{className:`mt-4 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,H.jsx)(_,{label:`Pushed`,value:h(c.pushed),tone:`accent`,compact:!0}),(0,H.jsx)(_,{label:`Completed`,value:h(c.completed),tone:`green`,compact:!0}),(0,H.jsx)(_,{label:`Push/sec`,value:L(c.pushPerSec),compact:!0}),(0,H.jsx)(_,{label:`Done/sec`,value:L(c.donePerSec),tone:`green`,compact:!0}),(0,H.jsx)(_,{label:`Elapsed`,value:m(c.elapsedMs),compact:!0}),(0,H.jsx)(_,{label:`Active workers`,value:`${c.activeWorkers}/${i}`,tone:`blue`,compact:!0}),(0,H.jsx)(_,{label:`Data`,value:p(l?.bytes??c.bytes),compact:!0}),(0,H.jsx)(_,{label:`Errors`,value:h((l?.pushFailed??c.pushFailed)+(l?.ackFailed??c.ackFailed)),tone:c.pushFailed+c.ackFailed?`red`:`default`,compact:!0})]})]}),(0,H.jsxs)(d,{children:[(0,H.jsx)(u,{title:`Throughput`}),(0,H.jsx)(`p`,{className:`-mt-3 mb-4 text-xs text-faint`,children:`Enqueue (client → server) vs completion (workers) per second`}),(0,H.jsx)(S,{series:[{label:`Push/sec`,color:`#38bdf8`,points:c.pushSeries,area:!0},{label:`Done/sec`,color:`#34d399`,points:c.doneSeries,area:!0}]}),(0,H.jsxs)(`div`,{className:`mt-2 flex items-center gap-4 font-mono text-[11px] text-faint`,children:[(0,H.jsx)(G,{color:`#38bdf8`,label:`Push/sec`,value:c.pushPerSec}),(0,H.jsx)(G,{color:`#34d399`,label:`Done/sec`,value:c.donePerSec})]})]})]})}function ae({summary:e}){return e?(0,H.jsxs)(d,{className:`mt-6`,children:[(0,H.jsx)(u,{title:`Summary`}),(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-4 xl:grid-cols-8`,children:[(0,H.jsx)(_,{label:`Pushed`,value:h(e.pushed),tone:`accent`,compact:!0}),(0,H.jsx)(_,{label:`Completed`,value:h(e.completed),tone:`green`,compact:!0}),(0,H.jsx)(_,{label:`Duration`,value:m(e.durationMs),compact:!0}),(0,H.jsx)(_,{label:`Avg push/s`,value:L(e.pushPerSec),tone:`accent`,compact:!0}),(0,H.jsx)(_,{label:`Avg done/s`,value:L(e.donePerSec),tone:`green`,compact:!0}),(0,H.jsx)(_,{label:`Data rate`,value:`${p(e.mbPerSec)}/s`,compact:!0}),(0,H.jsx)(_,{label:`Push p95`,value:m(e.p95),compact:!0}),(0,H.jsx)(_,{label:`Push p99`,value:m(e.p99),compact:!0})]}),(0,H.jsxs)(`p`,{className:`mt-3 text-xs text-faint`,children:[`Push-batch latency avg `,m(e.avg),` · p50 `,m(e.p50),` · p95`,` `,m(e.p95),` · p99 `,m(e.p99),` · max `,m(e.max),`.`,e.error?` First error: ${e.error}`:``]})]}):null}function oe({pollQueue:e,pollBaseUrl:t,pinned:n,counts:r,error:i}){return(0,H.jsxs)(d,{className:`mt-6`,children:[(0,H.jsx)(u,{title:`Server queue: ${e}`,action:i?(0,H.jsx)(`span`,{className:`text-xs font-medium text-warning`,children:`stale — server unreachable`}):void 0}),(0,H.jsxs)(`p`,{className:`-mt-3 mb-4 text-xs text-faint`,children:[`Live counts from `,t,` (poll 1s).`,n?` Pinned to the current or last benchmark run.`:``]}),r?(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-5`,children:[(0,H.jsx)(_,{label:`Waiting`,value:h(r.waiting??0),tone:`amber`,compact:!0}),(0,H.jsx)(_,{label:`Active`,value:h(r.active??0),tone:`blue`,compact:!0}),(0,H.jsx)(_,{label:`Completed`,value:h(r.completed??0),tone:`green`,compact:!0}),(0,H.jsx)(_,{label:`Failed`,value:h(r.failed??0),tone:r.failed?`red`:`default`,compact:!0}),(0,H.jsx)(_,{label:`Delayed`,value:h(r.delayed??0),compact:!0})]}):(0,H.jsx)(`p`,{className:`text-sm text-faint`,children:`No counts yet — waiting for the server to answer for this queue.`})]})}function W({label:e,pct:t,tone:n}){return(0,H.jsxs)(`div`,{className:`mb-2`,children:[(0,H.jsxs)(`div`,{className:`mb-1 flex items-center justify-between text-[11px] text-faint`,children:[(0,H.jsx)(`span`,{children:e}),(0,H.jsxs)(`span`,{className:`tnum`,children:[t.toFixed(0),`%`]})]}),(0,H.jsx)(`div`,{className:`h-1.5 overflow-hidden rounded-full bg-surface-2`,role:`progressbar`,"aria-label":e,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(t),children:(0,H.jsx)(`div`,{className:s(`h-full rounded-full transition-[width] motion-reduce:transition-none`,n===`accent`?`bg-accent`:`bg-emerald-500`),style:{width:`${t}%`}})})]})}function G({color:e,label:t,value:n}){return(0,H.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,H.jsx)(`span`,{className:`size-2 rounded-full`,style:{background:e}}),t,` `,(0,H.jsxs)(`span`,{className:`text-fg`,children:[L(n),`/s`]})]})}function se({history:e,onClear:t}){if(!e.length)return null;let n=JSON.stringify(e,null,2);return(0,H.jsxs)(d,{padded:!1,className:`mt-6 overflow-hidden`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between border-b border-line px-5 py-3`,children:[(0,H.jsx)(`h3`,{className:`text-base font-semibold text-fg`,children:`Run history`}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(g,{value:n}),(0,H.jsx)(l,{size:`sm`,variant:`ghost`,onClick:()=>{let e=new Blob([n],{type:`application/json`}),t=URL.createObjectURL(e),r=document.createElement(`a`);r.href=t,r.download=`benchmark-history-${Date.now()}.json`,r.click(),URL.revokeObjectURL(t)},children:`Export JSON`}),(0,H.jsx)(l,{size:`sm`,variant:`ghost`,onClick:t,children:`Clear`})]})]}),(0,H.jsx)(`div`,{className:`overflow-x-auto`,children:(0,H.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,H.jsx)(`thead`,{children:(0,H.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,H.jsx)(`th`,{className:`px-5 py-2 font-medium`,children:`Mode`}),(0,H.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Prod`}),(0,H.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Wkr`}),(0,H.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Pushed`}),(0,H.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Done`}),(0,H.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Push/s`}),(0,H.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Done/s`}),(0,H.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`p95`}),(0,H.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Dur`})]})}),(0,H.jsx)(`tbody`,{children:e.map(e=>(0,H.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,H.jsx)(`td`,{className:`px-5 py-2 capitalize text-muted`,children:e.mode}),(0,H.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-muted`,children:e.producers}),(0,H.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-muted`,children:e.workers}),(0,H.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-fg`,children:h(e.pushed)}),(0,H.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-success`,children:h(e.completed)}),(0,H.jsxs)(`td`,{className:`px-5 py-2 text-right tnum text-accent`,children:[L(e.pushPerSec),`/s`]}),(0,H.jsxs)(`td`,{className:`px-5 py-2 text-right tnum text-success`,children:[L(e.donePerSec),`/s`]}),(0,H.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-muted`,children:m(e.p95)}),(0,H.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-muted`,children:m(e.durationMs)})]},e.id))})]})})]})}function ce(e=8){if(!Number.isSafeInteger(e)||e<1)throw RangeError(`Benchmark compensation concurrency must be a positive whole number`);let t=0,n=[],r=()=>{--t,n.shift()?.()};return Object.freeze({run(i){return new Promise((a,o)=>{let s=()=>{t+=1,Promise.resolve().then(i).then(a,o).finally(r)};t<e?s():n.push(s)})}})}var le=[`waiting`,`prioritized`,`delayed`,`active`,`paused`,`waiting-children`,`completed`,`failed`];function K(e){return le.reduce((t,n)=>{let r=e[n];if(!Number.isSafeInteger(r)||r<0)throw Error(`Malformed queue count for "${n}".`);return t+r},0)}function q(e,t){if(!e||typeof e!=`object`||e.ok!==!0)throw Error(`${t} returned a malformed success response.`)}var J={pushed:0,completed:0,pushFailed:0,ackFailed:0,bytes:0,elapsedMs:0,pushPerSec:0,donePerSec:0,activeWorkers:0,pushSeries:[],doneSeries:[],etaMs:null,error:null},Y=()=>({pushed:0,completed:0,pushFailed:0,ackFailed:0,bytes:0,assigned:0,startedAt:0,pushLat:[],activeWorkers:0,error:null,lastAt:0,lastPushed:0,lastDone:0,pushSeries:[],doneSeries:[]});function ue(e,t,n,r){let i=r-e.startedAt,a=(r-e.lastAt)/1e3,o=a>0?Math.max(0,(e.pushed-e.lastPushed)/a):0,s=a>0?Math.max(0,(e.completed-e.lastDone)/a):0;e.lastAt=r,e.lastPushed=e.pushed,e.lastDone=e.completed,e.pushSeries=[...e.pushSeries,o].slice(-60),e.doneSeries=[...e.doneSeries,s].slice(-60);let c=null;if(t?.mode===`count`){let r=A(t.total,1,w.total);if(n===`draining`){let t=e.doneSeries.slice(-10),n=t.length?t.reduce((e,t)=>e+t,0)/t.length:0;n<=0&&i>0&&(n=e.completed/(i/1e3)),n>0&&(c=Math.max(0,r-e.completed)/n*1e3)}else o>0&&(c=Math.max(0,r-e.pushed)/o*1e3)}else t?.mode===`duration`&&(c=Math.max(0,A(t.durationS,1,w.durationS)*1e3-i));return{pushed:e.pushed,completed:e.completed,pushFailed:e.pushFailed,ackFailed:e.ackFailed,bytes:e.bytes,elapsedMs:i,pushPerSec:o,donePerSec:s,activeWorkers:e.activeWorkers,pushSeries:e.pushSeries,doneSeries:e.doneSeries,etaMs:c,error:e.error}}function de(e,t){let n=t/1e3||1,r=[...e.pushLat].sort((e,t)=>e-t);return{pushed:e.pushed,completed:e.completed,pushFailed:e.pushFailed,ackFailed:e.ackFailed,bytes:e.bytes,durationMs:t,pushPerSec:e.pushed/n,donePerSec:e.completed/n,mbPerSec:e.bytes/n,avg:r.length?r.reduce((e,t)=>e+t,0)/r.length:0,p50:M(r,50),p95:M(r,95),p99:M(r,99),max:r.length?r[r.length-1]:0,error:e.error}}function fe(e){let t=e.queue.trim(),n=j(t);return n?{ok:!1,error:n}:[`count`,`duration`].includes(e.mode)?typeof e.durable!=`boolean`||typeof e.removeOnComplete!=`boolean`?{ok:!1,error:`Benchmark job options are invalid.`}:{ok:!0,config:Object.freeze({...e,queue:t,total:A(e.total,1,w.total),durationS:A(e.durationS,1,w.durationS),batch:A(e.batch,1,w.batch),producers:A(e.producers,1,w.producers),payload:A(e.payload,0,w.payload),workers:A(e.workers,0,w.workers),workerBatch:A(e.workerBatch,1,w.workerBatch),processMs:A(e.processMs,0,w.processMs)})}:{ok:!1,error:`Benchmark mode is invalid.`}}async function pe(e,t,n){try{q(await e.overview(),`Dashboard preflight`)}catch(e){return{ok:!1,live:{...J,error:`Server unreachable — start it on the Server page first. (${I(e)})`}}}if(!n())return{ok:!0};try{let r=await e.counts(t);if(!n())return{ok:!0};if(q(r,`Queue-count preflight`),!r.counts||typeof r.counts!=`object`||Array.isArray(r.counts))throw Error(`Malformed queue-count response.`);let i=K(r.counts);if(i>0)return{ok:!1,live:{...J,error:`Dedicated benchmark queue "${t}" is not empty (${i} job(s) across all states). Clean it before running so no external work can be consumed or deleted.`}}}catch(e){return{ok:!1,live:{...J,error:`Could not verify that dedicated queue "${t}" is empty. (${I(e)})`}}}return{ok:!0}}var X=new WeakMap;function me(e){let t=X.get(e);return t||(t={next:0,inFlight:new Set},X.set(e,t)),t}function he(e){return async()=>{let{stats:t}=e;for(;e.shouldContinue();){let n;if(e.runConfig.mode===`count`){if(t.assigned>=e.total)break;n=Math.min(e.batch,e.total-t.assigned)}else{if(performance.now()>=e.deadline)break;n=e.batch}let r=t.assigned;t.assigned+=n;let i=N(r,n,e.blob,e.runConfig.durable,e.runConfig.removeOnComplete,e.runId,Math.max(12e4,e.processMs+6e4)),a=performance.now(),o=e.client.addJobsBulk(e.queue,i).then(r=>{if(!e.isCurrent())return;if(q(r,`Bulk enqueue`),!Array.isArray(r.ids)||r.ids.length!==n||r.ids.some(e=>typeof e!=`string`||e.length===0)||new Set(r.ids).size!==r.ids.length)throw Error(`Bulk enqueue returned invalid job IDs.`);let i=r.ids;for(let t of i)e.ownJobIds.add(t);t.pushed+=i.length,t.bytes+=i.length*e.payload;let a=Math.max(0,n-i.length);a>0&&(t.pushFailed+=a,t.error??=`Server created ${i.length} of ${n} jobs in a benchmark batch.`)}).catch(r=>{e.isCurrent()&&(t.pushFailed+=n,t.error??=I(r))});e.pendingPushes.add(o);try{await o}finally{e.pendingPushes.delete(o)}e.isCurrent()&&t.pushLat.push(performance.now()-a)}}}function ge(e){return async()=>{let{stats:t}=e,n=me(e);for(;e.shouldContinue()&&!(e.runConfig.mode===`duration`&&performance.now()>=e.deadline||e.runConfig.mode===`count`&&t.completed>=e.total);){t.activeWorkers++;let r=++n.next;n.inFlight.add(r);let i=[];try{if(i=await _e(e),!e.shouldContinue()){await Z(e,i);break}i.length>0&&await ve(e,i)}finally{n.inFlight.delete(r),e.isCurrent()&&t.activeWorkers--}if(!e.shouldContinue())break;if(i.length===0){if(e.runConfig.mode===`count`&&e.producersDone()){let r=n.next;for(;e.ownJobIds.size>0&&e.shouldContinue()&&[...n.inFlight].some(e=>e<=r);)await F(50,e.shouldContinue);if(!e.shouldContinue())break;e.ownJobIds.size>0&&(t.error??=`${e.ownJobIds.size} benchmark job(s) could not be drained.`);break}await F(50,e.shouldContinue)}}}}async function _e(e){try{let t=await e.client.pullBatch(e.queue,e.workerBatch,`dashboard-benchmark:${e.runId}`);if(t?.ok!==!0||!Array.isArray(t.jobs)||t.jobs.length>e.workerBatch||t.jobs.some(e=>!e||typeof e!=`object`||typeof e.id!=`string`||e.id.length===0)||!Array.isArray(t.tokens)||t.tokens.length!==t.jobs.length||t.tokens.some(e=>typeof e!=`string`||e.length===0)||new Set(t.jobs.map(e=>e.id)).size!==t.jobs.length)throw Error(`Malformed pull-batch response.`);let n=t.jobs.map((e,n)=>({id:e.id,token:t.tokens?.[n]}));return e.shouldContinue()?n:(await Z(e,n),[])}catch(t){return e.isCurrent()&&(e.stats.error??=I(t)),[]}}async function ve(e,t){if(t.some(t=>!e.ownJobIds.has(t.id))&&e.pendingPushes.size>0&&await Promise.allSettled([...e.pendingPushes]),!e.shouldContinue())return Z(e,t);let n=t.filter(t=>e.ownJobIds.has(t.id)),r=t.filter(t=>!e.ownJobIds.has(t.id));if(r.length>0){await ye(e,t,r.length);return}if(n.length===0)return;if(!e.shouldContinue()||(e.processMs>0&&await F(e.processMs,e.shouldContinue),!e.shouldContinue()))return Z(e,n);let i=!1;try{let t=n.map(e=>e.id),r=n.map(e=>e.token),a=await e.client.heartbeatBatch(t,r);q(a,`Heartbeat benchmark jobs`);let o=a.data;if(!o||typeof o!=`object`||o.ok!==!0||!Number.isSafeInteger(o.count)||o.count!==n.length)throw Error(`Heartbeat confirmed ${String(o?.count)} of ${n.length} benchmark jobs; refusing a lossy batch ACK.`);if(!e.shouldContinue())return Z(e,n);if(i=!0,q(await e.client.ackBatch(t,r),`Acknowledge benchmark jobs`),!e.isCurrent())return;e.stats.completed+=n.length;for(let t of n)e.ownJobIds.delete(t.id)}catch(t){e.isCurrent()&&(e.stats.ackFailed+=n.length,e.stats.error??=I(t)),i||await Z(e,n)}}async function ye(e,t,n){let r=await Q(e,t);e.isCurrent()&&(e.stats.error??=r>0?`Detected ${n} foreign job(s); ${r} pulled job(s) could not be returned to waiting. Benchmark stopped.`:`Detected ${n} foreign job(s); returned the complete pulled batch to waiting and stopped without counting it.`),e.stop()}async function Z(e,t){if(t.length===0)return;let n=await Q(e,t);n>0&&e.isCurrent()&&(e.stats.error??=`${n} interrupted benchmark job(s) could not be returned to waiting.`)}async function Q(e,t){return(await Promise.allSettled(t.map(t=>e.compensationQueue.run(async()=>{q(await e.client.retryJob(t.id,t.token),`Restore job ${t.id}`),e.ownJobIds.delete(t.id)})))).filter(e=>e.status===`rejected`).length}var be=0;async function xe(e,t,n){if(e.runningRef.current||!e.mountedRef.current)return;e.runningRef.current=!0;let r=++e.runGenerationRef.current,a=n??i.createServerTargetClient(i.captureServerRequestTarget()),o=()=>e.mountedRef.current&&e.runGenerationRef.current===r,s=()=>o()&&!e.stopRef.current;e.stopRef.current=!1;try{e.setSummary(null);let n=fe(t);if(!n.ok){e.setLive({...J,error:n.error}),$(e,`error`);return}let r=n.config,i=await pe(a,r.queue,s);if(!o())return;if(!i.ok){e.setLive(i.live),$(e,`error`);return}if(!s())return;e.producersDoneRef.current=!1,e.configRef.current=r,e.setRunConfig(r);let c=Y();c.startedAt=performance.now(),c.lastAt=performance.now(),e.statsRef.current=c,e.setLive({...J}),$(e,`running`);let l={batch:r.batch,blob:`x`.repeat(r.payload),client:a,compensationQueue:ce(),deadline:performance.now()+r.durationS*1e3,isCurrent:o,ownJobIds:new Set,payload:r.payload,pendingPushes:new Set,processMs:r.processMs,producersDone:()=>e.producersDoneRef.current,queue:r.queue,runConfig:r,runId:`bqbench-${globalThis.crypto.randomUUID()}`,shouldContinue:s,stats:c,stop:()=>{e.stopRef.current=!0},total:r.total,workerBatch:r.workerBatch},u=he(l),d=ge(l),f=Array.from({length:r.producers},u),p=Array.from({length:r.workers},d),m=Promise.all(f).then(()=>{o()&&(e.producersDoneRef.current=!0,s()&&r.mode===`count`&&r.workers>0&&e.phaseRef.current===`running`&&$(e,`draining`))});if(await Promise.all([m,...p]),!o())return;Se(e,r,c)}finally{e.runningRef.current=!1}}function Se(e,t,n){let r=performance.now()-n.startedAt,i=de(n,r);e.setSummary(i),e.setLive(e=>({...e,pushed:n.pushed,completed:n.completed,pushFailed:n.pushFailed,ackFailed:n.ackFailed,bytes:n.bytes,elapsedMs:r,pushPerSec:0,donePerSec:0,activeWorkers:0,etaMs:0,error:n.error})),e.setHistory(e=>[{...i,id:++be,at:Date.now(),mode:t.mode,producers:t.producers,workers:t.workers},...e].slice(0,12)),$(e,e.stopRef.current?`stopped`:n.error?`error`:`done`)}function $(e,t){e.phaseRef.current=t,e.setPhase(t)}function Ce(){let[e,t]=(0,C.useState)(`idle`),[n,r]=(0,C.useState)(J),[i,a]=(0,C.useState)(null),[o,s]=(0,C.useState)([]),[c,l]=(0,C.useState)(null),u=(0,C.useRef)(!1),d=(0,C.useRef)(!0),f=(0,C.useRef)(0),p=(0,C.useRef)(!1),m=(0,C.useRef)(!1),h=(0,C.useRef)(null),g=(0,C.useRef)(`idle`),_=(0,C.useRef)(Y());return g.current=e,(0,C.useEffect)(()=>{let e=d,t=u,n=f;return d.current=!0,()=>{e.current=!1,t.current=!0,n.current++}},[]),(0,C.useEffect)(()=>{if(e!==`running`&&e!==`draining`)return;let t=setInterval(()=>{r(ue(_.current,h.current,g.current,performance.now()))},200);return()=>clearInterval(t)},[e]),{phase:e,live:n,summary:i,history:o,runCfg:c,run:(e,n)=>xe({configRef:h,mountedRef:d,phaseRef:g,producersDoneRef:m,runningRef:p,runGenerationRef:f,setHistory:s,setLive:r,setPhase:t,setRunConfig:l,setSummary:a,statsRef:_,stopRef:u},e,n),stop:()=>{u.current=!0,(g.current===`running`||g.current===`draining`)&&(g.current=`stopping`,t(`stopping`))},reset:()=>{u.current=!0,f.current++,g.current=`idle`,a(null),r(J),t(`idle`)},clearHistory:()=>s([])}}function we({benchmark:e,counts:t,dedicatedQueue:n,draft:r,pollQueue:i,runTarget:a,setRunTarget:o}){let s=(0,C.useRef)(null),c=(0,C.useRef)(!0),[l,u]=(0,C.useState)(!1),[d,f]=(0,C.useState)(null);(0,C.useEffect)(()=>(c.current=!0,()=>{c.current=!1,s.current=null}),[]);let p=async()=>{let e=r.queue.trim();if(s.current||!e)return;if(!O(e)||e!==n){f({error:`refusing to clean a queue not owned by this dashboard session`});return}s.current=`clean`;let o=a??Te(),l=t&&i===e?` Currently ${h(t.waiting??0)} waiting / ${h(t.completed??0)} completed.`:``;if(!window.confirm(`Clean every cleanable job from the dedicated dashboard benchmark queue "${e}" on ${o.target.baseUrl}? This is queue-wide; the cryptographic queue name is owned by this browser session.${l}`)){s.current=null;return}u(!0),f(null);try{let t=null;for(let n of z){if(!c.current)return;try{let t=await o.client.clean(e,{state:n,limit:w.total});if(q(t,`Clean ${n} jobs`),!Number.isSafeInteger(t.count)||t.count<0)throw Error(`Clean ${n} jobs returned an invalid count.`)}catch(e){t=e.message}}if(!c.current)return;let n=await o.client.counts(e).catch(e=>(t=e.message,null));if(!c.current)return;if(!n)f({error:t??`server unreachable — could not verify`});else if(n.ok!==!0||!n.counts||typeof n.counts!=`object`||Array.isArray(n.counts))f({error:`server returned a malformed queue-count response`});else try{let e=K(n.counts);f(t||e>0?{error:t??`${h(e)} job(s) still present`}:{remaining:0})}catch{f({error:`server returned malformed queue counts`})}}finally{c.current&&u(!1),s.current===`clean`&&(s.current=null)}},m=()=>{if(s.current)return;s.current=`run`;let n=V(r),c=n.queue.trim(),l=Te();if(j(c)){e.run({...n,queue:c},l.client).finally(g);return}let u=0;if(!a&&t&&i===c)try{u=K(t)}catch{}let d=u>0?` Warning: it already holds ${h(u)} job(s) across all states; the safety preflight will refuse the run until the dedicated queue is empty.`:``;if(!window.confirm(`Enqueue real jobs into "${c}" on ${l.target.baseUrl}?${d}`)){s.current=null;return}o(l),e.run(n,l.client).finally(g)},g=()=>{s.current===`run`&&(s.current=null)};return{cleaning:l,cleanResult:d,cleanup:p,start:m}}function Te(){let e=i.captureServerRequestTarget();return{target:e,client:i.createServerTargetClient(e)}}function Ee(){let[e]=(0,C.useState)(ee),[t,n]=(0,C.useState)(()=>ne({...T,queue:e})),s=Ce(),u=r(e=>e.baseUrl),[d,p]=(0,C.useState)(null),m=(e,t)=>n(n=>({...n,[e]:t})),h=e=>t=>m(e,t.target.value),g=e=>n(t=>{let n={...t};for(let[t,r]of Object.entries(e))n[t]=te.includes(t)?String(r):r;return n}),[_,v]=(0,C.useState)(e);(0,C.useEffect)(()=>{let e=setTimeout(()=>v(t.queue.trim()||T.queue),400);return()=>clearTimeout(e)},[t.queue]);let y=d?.target.baseUrl??u,{data:b,error:x}=c(()=>d?d.client.counts(_):i.counts(_),[_,d],{intervalMs:1e3}),S=b?.counts??null,E=we({benchmark:s,counts:S,dedicatedQueue:e,draft:t,pollQueue:_,runTarget:d,setRunTarget:p}),{phase:D,live:O,summary:j,history:M}=s,N=D===`running`||D===`draining`||D===`stopping`,P=s.runCfg??V(t),F=A(P.total,1,w.total),I=A(P.workers,0,w.workers),L=P.mode===`count`&&(N||j)?Math.min(100,O.pushed/F*100):0,R=P.mode===`count`&&(N||j)?Math.min(100,O.completed/F*100):0,z=P.mode===`duration`?Math.min(100,O.elapsedMs/(A(P.durationS,1,w.durationS)*1e3)*100):0,B=De(D,P.mode,!!j),U=Oe(D,O.etaMs);return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(f,{title:`Benchmark`,description:`Drive real load against the server — producers bulk-enqueue jobs while simulated workers pull, process and ack them. Throughput is measured client-side; the queue genuinely fills and drains.`,actions:D===`stopping`?(0,H.jsxs)(l,{variant:`warning`,size:`sm`,disabled:!0,children:[(0,H.jsx)(a,{className:`size-3.5`}),` Stopping…`]}):N?(0,H.jsxs)(l,{variant:`warning`,size:`sm`,onClick:s.stop,children:[(0,H.jsx)(a,{className:`size-3.5`}),` Stop`]}):(0,H.jsxs)(l,{variant:`success`,size:`sm`,disabled:E.cleaning,onClick:E.start,children:[(0,H.jsx)(o,{className:`size-3.5`}),` Run benchmark`]})}),O.error&&(0,H.jsx)(`div`,{className:`mb-4 rounded-lg border border-red-500/20 bg-red-500/5 px-4 py-2 text-sm text-danger`,children:O.error}),(0,H.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wider text-faint`,children:`Presets`}),Object.keys(k).map(e=>(0,H.jsx)(`button`,{type:`button`,disabled:N,onClick:()=>g(k[e]),className:`rounded-md border border-line bg-surface-2 px-2.5 py-1 text-xs text-muted transition-colors hover:border-line-strong hover:text-fg disabled:opacity-40`,children:e},e))]}),(0,H.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-3`,children:[(0,H.jsx)(re,{draft:t,active:N,cleaning:E.cleaning,cleanResult:E.cleanResult,setField:m,numberInput:h,onClean:()=>void E.cleanup()}),(0,H.jsx)(ie,{heading:B,pollBaseUrl:y,etaText:U,shown:P,shownWorkers:I,producePct:L,drainPct:R,durationPct:z,live:O,summary:j})]}),(0,H.jsx)(ae,{summary:j}),(0,H.jsx)(oe,{pollQueue:_,pollBaseUrl:y,pinned:!!d,counts:S,error:x}),(0,H.jsx)(se,{history:M,onClear:s.clearHistory})]})}function De(e,t,n){return e===`running`?t===`duration`?`Running…`:`Producing…`:e===`draining`?`Draining…`:e===`stopping`?`Stopping…`:e===`error`?`Error`:n?`Result`:`Ready`}function Oe(e,t){return(e===`running`||e===`draining`)&&t!=null?t>0?`ETA ${m(t)}`:`finishing…`:e===`stopped`?`stopped early`:e===`done`?`complete`:``}export{Ee as Benchmark};
@@ -1 +0,0 @@
1
- import{t as e}from"./react-vendor-DfC0iyIS.js";import{r as t}from"./StatusBadge-cYUkK-4P.js";var n=e(),r={default:`border border-line bg-surface-2 text-fg hover:bg-surface-2/70 hover:border-line-strong`,ghost:`text-muted hover:text-fg hover:bg-surface-2`,accent:`bg-accent text-accent-fg hover:opacity-90 border border-transparent`,danger:`border border-red-500/30 text-danger hover:bg-red-500/10 hover:border-red-500/50`,warning:`border border-amber-500/30 text-warning hover:bg-amber-500/10 hover:border-amber-500/50`,success:`bg-emerald-500 text-white hover:bg-emerald-500/90 border border-transparent`},i={sm:`h-8 px-3 text-xs gap-1.5`,md:`h-9 px-4 text-sm gap-2`};function a({children:e,variant:a=`default`,size:o=`md`,className:s,...c}){return(0,n.jsx)(`button`,{type:`button`,className:t(`inline-flex items-center justify-center rounded-lg font-medium transition-colors`,`focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent`,`disabled:cursor-not-allowed disabled:opacity-50`,r[a],i[o],s),...c,children:e})}function o({children:e,className:i,variant:a=`ghost`,...o}){return(0,n.jsx)(`button`,{type:`button`,className:t(`inline-flex size-8 items-center justify-center rounded-lg transition-colors`,`focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent`,`disabled:cursor-not-allowed disabled:opacity-50`,r[a],i),...o,children:e})}export{o as n,a as t};
@@ -1 +0,0 @@
1
- import{t as e}from"./react-vendor-DfC0iyIS.js";import{r as t}from"./StatusBadge-cYUkK-4P.js";var n=e();function r({children:e,className:r,padded:i=!0}){return(0,n.jsx)(`div`,{className:t(`rounded-xl border border-line bg-surface`,i&&`p-5`,r),children:e})}function i({title:e,action:t,icon:r,headingLevel:i=2}){return(0,n.jsxs)(`div`,{className:`mb-4 flex items-center justify-between gap-3`,children:[(0,n.jsxs)(`h${i}`,{className:`flex items-center gap-2 text-base font-semibold text-fg`,children:[r,e]}),t]})}export{i as n,r as t};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{g as t,t as n}from"./react-vendor-DfC0iyIS.js";import{O as r,c as i}from"./icons-C1HVBnFn.js";import{t as a}from"./api-Bbo86MB6.js";import{n as o}from"./usePolledData-Dp_ynL9f.js";import{n as s}from"./Button-BCjgbAhY.js";import{i as c,n as l,r as u,t as d}from"./feedback-Dxfj-Fy1.js";import{t as f}from"./PageHeader-DD4vnVog.js";import{i as p,s as m}from"./format-Cg7VCIZW.js";import{t as h}from"./Pagination-Cj7GzYNX.js";import{r as g,t as _}from"./useServerActionGuard-Cr4KUOeZ.js";var v=e(t(),1),y=n();function b(){let{data:e,error:t,loading:n,refetch:b}=o(()=>a.crons(),[]),x=(e?.crons??[]).slice(),[S,C]=(0,v.useState)(0),w=Math.max(1,Math.ceil(x.length/15)),T=Math.min(S,w-1),[E,D]=(0,v.useState)(null),[O,k]=(0,v.useState)(null),A=g(`classic-cron`);(0,v.useEffect)(()=>{D(null),k(null)},[A.scopeKey]);let j=async e=>{if(!window.confirm(`Delete cron "${e}"?`))return;let t=A.begin(`delete:${e}`);if(t){D(null),k(e);try{if(_(await a.deleteCron(e),`Delete cron`),!t.isCurrent())return;await b()}catch(e){t.isCurrent()&&D(`Delete failed: ${e.message}`)}finally{t.finish()&&k(null)}}};return(0,y.jsxs)(`div`,{children:[t&&e&&(0,y.jsx)(c,{message:`Cron refresh failed — showing the last successful schedule list.`,onRetry:b}),(0,y.jsx)(f,{title:`Cron Jobs`,description:e?`${x.length} scheduled`:`Schedule inventory unavailable`,live:!!e&&!t}),E&&(0,y.jsx)(`p`,{role:`alert`,className:`mb-4 text-sm text-danger`,children:E}),t&&!e?(0,y.jsx)(l,{error:t,onRetry:b}):n&&!e?(0,y.jsx)(u,{label:`Loading cron jobs…`}):x.length===0?(0,y.jsx)(d,{icon:(0,y.jsx)(i,{}),title:`No scheduled jobs`,hint:`Repeatable jobs created with upsertJobScheduler appear here.`}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,y.jsx)(`thead`,{children:(0,y.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,y.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Name`}),(0,y.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queue`}),(0,y.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Schedule`}),(0,y.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Next Run`}),(0,y.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Runs`}),(0,y.jsx)(`th`,{className:`w-12 px-5 py-3`})]})}),(0,y.jsx)(`tbody`,{children:x.slice(T*15,T*15+15).map(e=>(0,y.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,y.jsx)(`td`,{className:`px-5 py-3 font-medium text-fg`,children:e.name}),(0,y.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queue??`—`}),(0,y.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.schedule??(e.repeatEvery?`every ${e.repeatEvery}ms`:`—`)}),(0,y.jsx)(`td`,{className:`px-5 py-3 text-faint`,children:p(e.nextRun)}),(0,y.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:m(e.executions??0)}),(0,y.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,y.jsx)(s,{"aria-label":`Delete cron`,disabled:O!==null,onClick:()=>j(e.name),children:(0,y.jsx)(r,{className:`size-3.5`})})})]},e.name))})]})}),(0,y.jsx)(h,{page:T,pageSize:15,total:x.length,onPageChange:C,label:`crons`})]})]})}export{b as Cron};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{g as t,t as n}from"./react-vendor-DfC0iyIS.js";import{t as r}from"./upstreamPaths-DQeKSxGc.js";import{t as i}from"./bq-CSX8DSME.js";import{t as a}from"./toastStore-DnqA_aL-.js";import{O as o,c as s}from"./icons-C1HVBnFn.js";import{r as c}from"./StatusBadge-cYUkK-4P.js";import{n as l}from"./usePolledData-Dp_ynL9f.js";import{n as u,t as d}from"./Button-BCjgbAhY.js";import{n as f,t as p}from"./Card-DptfvL2O.js";import{i as m,n as h,r as g,t as _}from"./feedback-Dxfj-Fy1.js";import{t as v}from"./PageHeader-DD4vnVog.js";import{i as y,s as b}from"./format-Cg7VCIZW.js";import{i as x,n as S,o as C,t as w}from"./form-Dy-an7ew.js";import{t as ee}from"./Pagination-Cj7GzYNX.js";import{r as te}from"./useServerActionGuard-Cr4KUOeZ.js";import{d as ne,h as re,m as T}from"./responses-BkR2JTH9.js";import"./AddJob-jq-VZ_YE.js";var E=e(t(),1),D=6e4;function O(e){return{year:e.getFullYear(),month:e.getMonth()+1,day:e.getDate(),weekday:e.getDay(),hour:e.getHours(),minute:e.getMinutes()}}function k(e){e.minute>59&&(e.minute-=60,e.hour+=1),e.hour>23&&(e.hour-=24,e.day+=1);let t=new Date(Date.UTC(e.year,e.month-1,e.day,12));e.year=t.getUTCFullYear(),e.month=t.getUTCMonth()+1,e.day=t.getUTCDate(),e.weekday=t.getUTCDay()}function A(e,t,n){let r=e.dayOfMonth.values.has(t),i=e.dayOfWeek.values.has(n);return e.dayOfMonth.literalWildcard||e.dayOfWeek.literalWildcard?r&&i:r||i}function j(e,t){let n=new Date(t);return e.minute.values.has(n.getMinutes())&&e.hour.values.has(n.getHours())&&e.month.values.has(n.getMonth()+1)&&A(e,n.getDate(),n.getDay())}function M(e,t){return e.values.size===t}function N(e,t,n,r){let i=new Date(t.year,t.month-1,t.day,t.hour,t.minute,0,0).getTime();if(M(e.minute,60)||M(e.hour,24)){let a=Date.UTC(r.year,r.month-1,r.day,r.hour,r.minute),o=Date.UTC(t.year,t.month-1,t.day,t.hour,t.minute);if(i<=n||i-n>o-a){let t=(Math.floor(n/D)+1)*D,r=n+121*D;for(i>n&&(r=Math.min(r,i));t<r;){if(j(e,t))return t;t+=D}}}return i>n?i:null}function P(e,t){if(!Number.isFinite(t))return null;let n=O(new Date(t)),r={...n,minute:n.minute+1},i=n.year+8;for(let a=0;a<1e5&&r.year<=i;a++){if(k(r),!e.month.values.has(r.month)){r.month+=1,r.day=1,r.hour=0,r.minute=0;continue}if(!A(e,r.day,r.weekday)){r.day+=1,r.hour=0,r.minute=0;continue}if(!e.hour.values.has(r.hour)){r.hour+=1,r.minute=0;continue}if(!e.minute.values.has(r.minute)){r.minute+=1;continue}let i=N(e,r,t,n);if(i!==null)return i;r.minute+=1}return null}function F(e,t,n){let r=P(e,Math.floor(n/D)*D-1);for(;r!==null;){for(let e of t){let t=r+e*1e3;if(t>n)return t}let i=P(e,r);if(i===null||i<=r)return null;r=i}return null}var I={jan:1,january:1,feb:2,february:2,mar:3,march:3,apr:4,april:4,may:5,jun:6,june:6,jul:7,july:7,aug:8,august:8,sep:9,september:9,oct:10,october:10,nov:11,november:11,dec:12,december:12},L={sun:0,sunday:0,mon:1,monday:1,tue:2,tuesday:2,wed:3,wednesday:3,thu:4,thursday:4,fri:5,friday:5,sat:6,saturday:6},ie={"@yearly":`0 0 1 1 *`,"@annually":`0 0 1 1 *`,"@monthly":`0 0 1 * *`,"@weekly":`0 0 * * 0`,"@daily":`0 0 * * *`,"@midnight":`0 0 * * *`,"@hourly":`0 * * * *`};function R(e,t,n,r){let i=e===`*`,a=new Set;for(let i of e.split(`,`)){let e=i.trim().toLowerCase();if(e===``)return null;let o=e.match(/^(.+)\/(\+?\d+)$/),s=o?Number(o[2]):1,c=o?o[1]:e;if(!Number.isSafeInteger(s)||s<1||s>127)return null;let l,u;if(c===`*`)l=t,u=n;else if(c.includes(`-`)){let e=c.split(`-`);if(e.length!==2)return null;let[t,n]=e,i=z(t,r),a=z(n,r);if(i==null||a==null)return null;l=i,u=a}else{let e=z(c,r);if(e==null)return null;l=e,u=o?n:e}if(l<t||u>n||l>u)return null;for(let e=l;e<=u;e+=s)a.add(e)}return a.size?{values:a,star:i}:null}function z(e,t){let n=e.trim().toLowerCase();if(n===``)return null;if(t){let e=t[n];if(e!==void 0)return e}if(!/^\+?\d+$/.test(n))return null;let r=Number(n);return Number.isSafeInteger(r)?r:null}function B(e,t,n){let r=e.trim(),i=(ie[r.toLowerCase()]??r).split(/\s+/);if(i.length!==5&&i.length!==6)return{valid:!1,error:`Expected 5 fields (min hour day month weekday) or 6 with leading seconds, got ${i.length}.`,runs:[]};let a=i.length===6,o=+!!a,s=a?H(i[0]):V(0),c=R(i[o],0,59),l=R(i[o+1],0,23),u=R(i[o+2],1,31),d=R(i[o+3],1,12,I),f=R(i[o+4],0,7,L);if(!s||!c||!l||!u||!d||!f)return{valid:!1,error:`Invalid field syntax.`,runs:[]};let p=new Set;for(let e of f.values)p.add(e===7?0:e);let m={values:p,star:f.star},h={minute:{values:c.values,literalWildcard:c.star},hour:{values:l.values,literalWildcard:l.star},dayOfMonth:{values:u.values,literalWildcard:u.star},month:{values:d.values,literalWildcard:d.star},dayOfWeek:{values:m.values,literalWildcard:m.star}},g=[],_=Number.isSafeInteger(t)?Math.max(0,Math.min(t,100)):0,v=[...s.values].sort((e,t)=>e-t),y=n;for(;g.length<_;){let e=a?F(h,v,y):P(h,y);if(e===null||e<=y)break;g.push(e),y=e}return{valid:!0,runs:g}}function V(e){return{values:new Set([e]),star:!1}}function H(e){let t=new Set;for(let n of e.split(`,`)){if(!n)return null;let e=n.split(`/`);if(e.length>2||!e[0]||e[1]===``)return null;let r=e[0],i=e.length===2;if(i&&!/^\d+$/.test(e[1]))return null;let a=i?Number(e[1]):1;if(a<1||a>60)return null;let o,s;if(r===`*`)o=0,s=59;else if(r.includes(`-`)){let e=r.split(`-`);if(e.length!==2||!e[0]||!e[1]||!/^\d+$/.test(e[0])||!/^\d+$/.test(e[1]))return null;o=Number(e[0]),s=Number(e[1])}else{if(i||!/^\d+$/.test(r))return null;o=Number(r),s=o}if(o<0||s>59||o>s)return null;for(let e=o;e<=s;e+=a)t.add(e)}return t.size?{values:t,star:e===`*`||/^\*\/\d+$/.test(e)}:null}var U=365*24*60*60*1e3,W=1440*60*1e3;function G(e){if(typeof e!=`object`||!e||e.ok!==!0)throw Error(`Delete cron returned a malformed success response`)}function K(e,t){let n=e?.cron;if(typeof e!=`object`||!e||e.ok!==!0||typeof n!=`object`||!n||n.name!==t.name||n.queue!==t.queue)throw Error(`Create cron returned a malformed success response`)}var q=e=>`Cron "${e}" already exists. Bunqueue v2.9.3 does not return complete cron definitions, so editing could reset hidden options. Delete it explicitly, wait for the list to refresh, then create the replacement as a separate action.`;function J(e,t){let n=e.trim();return n&&t.has(n)?q(n):null}function ae(e,t){let n=e;if(typeof n!=`object`||!n||n.ok!==!0||!Array.isArray(n.crons)||n.crons.some(e=>typeof e!=`object`||!e||typeof e.name!=`string`))throw Error(`Cannot verify that the cron name is unused; creation was not attempted`);if(n.crons.some(e=>e.name===t.trim()))throw Error(q(t.trim()))}function oe(e){let t=Number(e);if(!Number.isInteger(t)||t<=0)return null;if(t<1e3)return`every ${t}ms`;for(let[e,n]of[[864e5,`d`],[36e5,`h`],[6e4,`m`],[1e3,`s`]])if(t>=e){let r=t/e;return`${Number.isInteger(r)?``:`≈ `}every ${Math.round(r*10)/10}${n}`}return null}function Y(e,t,n,r){if(!e.trim())return{ok:!0};let i=Number(e);return!Number.isSafeInteger(i)||i<n||i>r?{ok:!1,msg:`${t} must be a whole number from ${n} to ${r}`}:{ok:!0,value:i}}function se(e,t=Date.now()){let n=e.name.trim(),i=e.queue.trim();if(!n)return{ok:!1,msg:`Name is required`};if(n.length>256)return{ok:!1,msg:`Name must be 256 characters or fewer`};let a=r(n,`Name`,256);if(a)return{ok:!1,msg:a};let o=ne(i);if(o)return{ok:!1,msg:o};let s=e.jobName?.trim()||`default`;if(s.length>256)return{ok:!1,msg:`Spawned job name must be 256 characters or fewer`};let c={};if(e.dataText.trim()){let t=re(e.dataText);if(!t.ok)return{ok:!1,msg:t.kind===`json`?`Data is not valid JSON`:t.msg};c=t.data}let l={name:n,jobName:s,queue:i,data:c,preventOverlap:e.preventOverlap,skipIfNoWorker:e.skipIfNoWorker,immediately:e.immediately,skipMissedOnRestart:e.skipMissedOnRestart};if(e.mode===`cron`){let n=e.schedule.trim();if(!n)return{ok:!1,msg:`Cron expression required`};let r=B(n,1,t);if(!r.valid)return{ok:!1,msg:`Cron expression is not supported by Bunqueue 2.9: ${r.error??`invalid syntax`}`};l.schedule=n}else{let t=Y(e.every,`Interval`,1,U);if(!t.ok||t.value===void 0)return{ok:!1,msg:t.ok?`Interval is required`:t.msg};l.repeatEvery=t.value}let u=e.timezone.trim();if(u){if(e.mode!==`cron`)return{ok:!1,msg:`Timezone applies only to cron expressions, not intervals`};try{new Intl.DateTimeFormat(`en`,{timeZone:u}).format(t)}catch{return{ok:!1,msg:`Timezone must be a valid IANA timezone`}}l.timezone=u}let d=Y(e.priority,`Priority`,-1e6,1e6);if(!d.ok)return d;d.value!==void 0&&(l.priority=d.value);let f=Y(e.maxLimit,`Max executions`,1,2**53-1);if(!f.ok)return f;f.value!==void 0&&(l.maxLimit=f.value);let p=e.uniqueKey.trim();if(p.length>1024)return{ok:!1,msg:`Unique key must be 1024 characters or fewer`};p&&(l.uniqueKey=p);let m=Y(e.dedupTtl,`Dedup TTL`,1,U);if(!m.ok)return m;let h=m.value!==void 0||e.dedupExtend||e.dedupReplace;if(e.dedupExtend&&e.dedupReplace)return{ok:!1,msg:`Dedup extend and replace are mutually exclusive`};if(e.dedupExtend&&m.value===void 0)return{ok:!1,msg:`Dedup extend requires a TTL`};if(h&&!p&&!e.preventOverlap)return{ok:!1,msg:`Dedup options require a unique key or Prevent overlap`};h&&(l.dedup={...m.value===void 0?{}:{ttl:m.value},...e.dedupExtend?{extend:!0}:{},...e.dedupReplace?{replace:!0}:{}});let g=[{raw:e.jobMaxAttempts,label:`Spawned-job max attempts`,min:1,max:1e3,key:`maxAttempts`},{raw:e.jobBackoff,label:`Spawned-job backoff`,min:0,max:W,key:`backoff`},{raw:e.jobTimeout,label:`Spawned-job timeout`,min:0,max:W,key:`timeout`},{raw:e.jobDelay,label:`Spawned-job delay`,min:0,max:U,key:`delay`},{raw:e.jobStallTimeout,label:`Spawned-job stall timeout`,min:0,max:W,key:`stallTimeout`}],_={};for(let e of g){let t=Y(e.raw,e.label,e.min,e.max);if(!t.ok)return t;t.value!==void 0&&(_[e.key]=t.value)}return e.jobRemoveOnComplete&&(_.removeOnComplete=!0),e.jobRemoveOnFail&&(_.removeOnFail=!0),Object.keys(_).length&&(l.jobOptions=_),{ok:!0,body:l}}var X=n();function ce({values:e,setValue:t}){return(0,X.jsxs)(`div`,{id:`cron-advanced-options`,className:`mt-3 grid grid-cols-2 gap-3`,children:[(0,X.jsx)(w,{label:`Timezone (IANA)`,hint:`e.g. Europe/Rome. Default: server timezone.`,children:(0,X.jsx)(S,{name:`cron-timezone`,autoComplete:`off`,value:e.timezone,onChange:e=>t(`timezone`,e.target.value),placeholder:`Europe/Rome`})}),(0,X.jsx)(w,{label:`Priority`,children:(0,X.jsx)(S,{type:`number`,min:-1e6,max:1e6,step:1,name:`cron-priority`,value:e.priority,onChange:e=>t(`priority`,e.target.value),placeholder:`0`})}),(0,X.jsx)(w,{label:`Max executions`,hint:`blank = unlimited`,children:(0,X.jsx)(S,{type:`number`,min:1,max:2**53-1,step:1,name:`cron-max-executions`,value:e.maxLimit,onChange:e=>t(`maxLimit`,e.target.value),placeholder:`∞`})}),(0,X.jsx)(w,{label:`Unique key`,hint:`optional deduplication key`,children:(0,X.jsx)(S,{name:`cron-unique-key`,autoComplete:`off`,maxLength:1024,value:e.uniqueKey,onChange:e=>t(`uniqueKey`,e.target.value),placeholder:`daily-report`})}),(0,X.jsxs)(`div`,{className:`col-span-2 flex flex-wrap gap-6`,children:[(0,X.jsx)(Q,{label:`prevent overlap`,checked:e.preventOverlap,onChange:e=>t(`preventOverlap`,e)}),(0,X.jsx)(Q,{label:`skip if no worker`,checked:e.skipIfNoWorker,onChange:e=>t(`skipIfNoWorker`,e)}),(0,X.jsx)(Q,{label:`run immediately`,checked:e.immediately,onChange:e=>t(`immediately`,e)}),(0,X.jsx)(Q,{label:`skip missed on restart`,checked:e.skipMissedOnRestart,onChange:e=>t(`skipMissedOnRestart`,e)})]}),(0,X.jsxs)(`div`,{className:`col-span-2`,children:[(0,X.jsx)(`div`,{className:`mb-2 text-[11px] uppercase tracking-wider text-faint`,children:`Cron deduplication`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,X.jsx)(w,{label:`Dedup TTL (ms)`,hint:`blank = no TTL`,children:(0,X.jsx)(S,{type:`number`,min:1,max:U,step:1,name:`cron-dedup-ttl`,value:e.dedupTtl,onChange:e=>t(`dedupTtl`,e.target.value),placeholder:`60000`})}),(0,X.jsx)(Q,{className:`items-end pb-2`,label:`extend TTL`,controlLabel:`extend dedup TTL`,checked:e.dedupExtend,onChange:e=>t(`dedupExtend`,e)}),(0,X.jsx)(Q,{className:`items-end pb-2`,label:`replace duplicate`,checked:e.dedupReplace,onChange:e=>t(`dedupReplace`,e)})]})]}),(0,X.jsxs)(`div`,{className:`col-span-2`,children:[(0,X.jsx)(`div`,{className:`mb-2 text-[11px] uppercase tracking-wider text-faint`,children:`Spawned-job options`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-5`,children:[(0,X.jsx)(Z,{label:`Max attempts`,name:`cron-job-max-attempts`,value:e.jobMaxAttempts,min:1,max:1e3,placeholder:`3`,onChange:e=>t(`jobMaxAttempts`,e)}),(0,X.jsx)(Z,{label:`Backoff (ms)`,name:`cron-job-backoff`,value:e.jobBackoff,min:0,max:W,placeholder:`1000`,onChange:e=>t(`jobBackoff`,e)}),(0,X.jsx)(Z,{label:`Timeout (ms)`,name:`cron-job-timeout`,value:e.jobTimeout,min:0,max:W,placeholder:`—`,onChange:e=>t(`jobTimeout`,e)}),(0,X.jsx)(Z,{label:`Delay (ms)`,name:`cron-job-delay`,value:e.jobDelay,min:0,max:U,placeholder:`0`,onChange:e=>t(`jobDelay`,e)}),(0,X.jsx)(Z,{label:`Stall timeout (ms)`,name:`cron-job-stall-timeout`,value:e.jobStallTimeout,min:0,max:W,placeholder:`server default`,onChange:e=>t(`jobStallTimeout`,e)})]}),(0,X.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-6`,children:[(0,X.jsx)(Q,{label:`remove on complete`,controlLabel:`remove spawned jobs on complete`,checked:e.jobRemoveOnComplete,onChange:e=>t(`jobRemoveOnComplete`,e)}),(0,X.jsx)(Q,{label:`remove on fail`,controlLabel:`remove spawned jobs on fail`,checked:e.jobRemoveOnFail,onChange:e=>t(`jobRemoveOnFail`,e)})]})]})]})}function Z({label:e,name:t,value:n,min:r,max:i,placeholder:a,onChange:o}){return(0,X.jsx)(w,{label:e,children:(0,X.jsx)(S,{type:`number`,min:r,max:i,step:1,name:t,value:n,onChange:e=>o(e.target.value),placeholder:a})})}function Q({label:e,controlLabel:t=e,checked:n,onChange:r,className:i=`items-center`}){return(0,X.jsxs)(`div`,{className:`flex gap-2 ${i}`,children:[(0,X.jsx)(C,{checked:n,onChange:r,label:t}),(0,X.jsx)(`span`,{className:`text-sm text-muted`,children:e})]})}function le({values:e,setValue:t}){let n=e.mode===`cron`&&e.schedule.trim()?B(e.schedule.trim(),3,Date.now()):null,r=oe(e.every);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,X.jsx)(w,{label:`Name`,children:(0,X.jsx)(S,{name:`cron-name`,autoComplete:`off`,maxLength:256,value:e.name,onChange:e=>t(`name`,e.target.value),placeholder:`daily-report`})}),(0,X.jsx)(w,{label:`Queue`,children:(0,X.jsx)(S,{name:`cron-queue`,autoComplete:`off`,maxLength:256,value:e.queue,onChange:e=>t(`queue`,e.target.value),placeholder:`reports`})}),(0,X.jsx)(w,{label:`Spawned job name`,hint:`First-class worker routing name; separate from schedule data.`,children:(0,X.jsx)(S,{name:`cron-job-name`,autoComplete:`off`,maxLength:256,value:e.jobName,onChange:e=>t(`jobName`,e.target.value),placeholder:`default`})})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,X.jsxs)(`fieldset`,{children:[(0,X.jsx)(`legend`,{className:`sr-only`,children:`Schedule type`}),(0,X.jsx)(x,{options:[`cron`,`every`],value:e.mode,onChange:e=>t(`mode`,e)})]}),e.mode===`cron`?(0,X.jsx)(`div`,{className:`min-w-56 flex-1`,children:(0,X.jsx)(w,{label:`Cron expression`,hint:`Standard 5-field syntax, 6 fields with leading seconds, or an official @hourly/@daily-style shortcut. Croner extensions L/W/#/? are rejected by Bunqueue 2.9.`,children:(0,X.jsx)(S,{name:`cron-expression`,value:e.schedule,onChange:e=>t(`schedule`,e.target.value),placeholder:`0 9 * * *`})})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`w-40`,children:(0,X.jsx)(w,{label:`Every (ms)`,children:(0,X.jsx)(S,{type:`number`,min:1,max:U,step:1,name:`cron-interval`,value:e.every,onChange:e=>t(`every`,e.target.value),placeholder:`30000`})})}),e.every.trim()!==``&&(0,X.jsx)(`span`,{className:c(`pb-2 text-xs`,r?`text-muted`:`text-danger`),children:r??`not a valid interval`})]})]}),e.mode===`cron`&&e.schedule.trim()&&n&&(0,X.jsx)(`div`,{className:`rounded-lg border border-line bg-surface-2 px-3 py-2 text-xs`,children:n.valid?n.runs.length?(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,X.jsx)(`span`,{className:`text-faint`,children:`Next runs (browser-local time):`}),n.runs.map(e=>(0,X.jsx)(`span`,{className:`font-mono text-muted`,children:y(e)},e)),(0,X.jsx)(`span`,{className:`text-faint`,children:e.timezone.trim()?`— server evaluates in ${e.timezone.trim()}`:`— no timezone set: the server evaluates in its own timezone, which may differ`})]}):(0,X.jsx)(`span`,{className:`text-warning`,children:`Valid, but no runs in the next few years.`}):(0,X.jsxs)(`span`,{className:`text-warning`,children:[`Unsupported expression: `,n.error,` Fix it before creating the schedule.`]})}),(0,X.jsx)(w,{label:`Data (JSON)`,children:(0,X.jsx)(`textarea`,{name:`cron-data`,value:e.dataText,onChange:e=>t(`dataText`,e.target.value),maxLength:T,rows:3,spellCheck:!1,className:`w-full rounded-lg border border-line bg-surface-2 px-3 py-2 font-mono text-sm text-fg placeholder:text-faint transition-colors focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`})})]})}function $(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 ue(e){let[t,n]=(0,E.useState)(!1),r=(0,E.useRef)(null),i=()=>{r.current&&clearTimeout(r.current),r.current=null};return(0,E.useEffect)(()=>()=>{r.current&&clearTimeout(r.current)},[]),{on:t,fire:()=>{i(),n(!0),r.current=setTimeout(()=>n(!1),e)},reset:()=>{i(),n(!1)}}}var de={name:``,jobName:`default`,queue:``,mode:`cron`,schedule:``,every:``,dataText:`{}`,timezone:``,priority:``,preventOverlap:!0,skipIfNoWorker:!1,maxLimit:``,immediately:!1,skipMissedOnRestart:!0,uniqueKey:``,dedupTtl:``,dedupExtend:!1,dedupReplace:!1,jobMaxAttempts:``,jobBackoff:``,jobTimeout:``,jobDelay:``,jobStallTimeout:``,jobRemoveOnComplete:!1,jobRemoveOnFail:!1};function fe({onCreate:e,onAccepted:t,beginCreate:n,scopeKey:r,existingNames:i}){let[o,s]=(0,E.useState)(de),[c,l]=(0,E.useState)(!1),[u,f]=(0,E.useState)(null),[p,m]=(0,E.useState)(!1),{on:h,fire:g,reset:_}=ue(3e3),v=(e,t)=>s(n=>({...n,[e]:t}));(0,E.useEffect)(()=>{m(!1),f(null),_()},[r]);let y=J(o.name,i),b=async()=>{f(null),_();let r=se(o);if(!r.ok){f(r.msg);return}let c=J(r.body.name,i);if(c){f(c);return}if(!window.confirm(`Submit an upsert for cron "${r.body.name}"? Bunqueue v2.9.3 has no atomic create-only condition. The dashboard will recheck immediately before writing, but another client using the same name at the same time could still be replaced. Continue only if you authorize last-writer-wins behavior for this globally unique name.`))return;let l=n(r.body.name);if(l){m(!0);try{if(K(await e(r.body,l.isCurrent),r.body),!l.isCurrent())return;s(e=>({...e,name:``,schedule:``,every:``})),g(),a.success(`Cron upsert acknowledged`,r.body.name),t()}catch(e){l.isCurrent()&&f(e.message)}finally{l.finish()&&m(!1)}}};return(0,X.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),b()},children:[(0,X.jsx)(le,{values:o,setValue:v}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),"aria-expanded":c,"aria-controls":`cron-advanced-options`,className:`text-xs font-medium text-muted hover:text-fg`,children:c?`− Hide advanced`:`+ Advanced options`}),c&&(0,X.jsx)(ce,{values:o,setValue:v})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(d,{type:`submit`,variant:`accent`,size:`sm`,disabled:p||!!y,children:p?`Saving…`:y?`Name already exists`:`Submit upsert`}),y&&!u&&(0,X.jsx)(`span`,{role:`alert`,className:`max-w-2xl text-xs text-warning`,children:y}),u&&(0,X.jsx)(`span`,{role:`alert`,className:`text-xs text-danger`,children:u}),h&&(0,X.jsx)(`span`,{role:`status`,className:`text-xs text-success`,children:`Cron upsert acknowledged ✓`})]}),(0,X.jsx)(`p`,{className:`text-xs text-warning`,children:`Creation is an upstream upsert, not an atomic create-only operation. Use a globally unique name; the fail-closed preflight cannot eliminate a simultaneous write from another client.`})]})}function pe({crons:e,page:t,removing:n,onPageChange:r,onRemove:i}){let a=e.slice(t*15,t*15+15);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,X.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,X.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Name`}),(0,X.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Queue`}),(0,X.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Job name`}),(0,X.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Schedule`}),(0,X.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Next Run`}),(0,X.jsx)(`th`,{scope:`col`,className:`px-5 py-3 text-right font-medium`,children:`Runs`}),(0,X.jsx)(`th`,{scope:`col`,className:`w-12 px-5 py-3`})]})}),(0,X.jsx)(`tbody`,{children:a.map(e=>(0,X.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,X.jsx)(`td`,{className:`px-5 py-3 font-medium text-fg`,children:e.name}),(0,X.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queue}),(0,X.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.jobName??`default`}),(0,X.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.schedule??(e.repeatEvery?`every ${e.repeatEvery}ms`:`—`)}),(0,X.jsx)(`td`,{className:`px-5 py-3 text-faint`,children:y(e.nextRun)}),(0,X.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:b(e.executions)}),(0,X.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,X.jsx)(u,{"aria-label":`Delete cron ${e.name}`,disabled:n.has(e.name),onClick:()=>i(e.name),children:(0,X.jsx)(o,{className:`size-3.5`})})})]},e.name))})]})}),(0,X.jsx)(ee,{page:t,pageSize:15,total:e.length,onPageChange:r,label:`crons`})]})}var me=[];function he(){let{data:e,error:t,loading:n,refetch:r}=l(()=>i.crons(),[]),o=e?.crons??me,c=(0,E.useMemo)(()=>new Set(o.map(e=>e.name)),[o]),[u,d]=$(Math.max(1,Math.ceil(o.length/15))),[y,b]=(0,E.useState)(null),[x,S]=(0,E.useState)(new Set),C=te(`cron-manager`);(0,E.useEffect)(()=>{b(null),S(new Set)},[C.scopeKey]);let w=async e=>{if(!window.confirm(`Delete cron "${e}"? It will not be recreated automatically; creating a replacement is a separate action.`))return;let t=C.begin(`cron:${e}`);if(t){b(null),S(t=>new Set(t).add(e));try{if(G(await i.deleteCron(e)),!t.isCurrent())return;a.success(`Cron deleted`,e),r()}catch(e){if(!t.isCurrent())return;b(e.message),a.error(`Delete cron failed`,e.message)}finally{t.finish()&&S(t=>{let n=new Set(t);return n.delete(e),n})}}};return(0,X.jsxs)(`div`,{children:[t&&e&&(0,X.jsx)(m,{message:`Cron refresh failed — showing the last successful schedule list.`,onRetry:r}),(0,X.jsx)(v,{title:`Cron Manager`,description:`Submit explicitly acknowledged schedule upserts and manage repeatable jobs.`,live:!!e&&!t}),y&&(0,X.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:y}),(0,X.jsxs)(p,{className:`mb-6`,children:[(0,X.jsx)(f,{title:`Create schedule via upstream upsert`}),(0,X.jsx)(fe,{existingNames:c,onCreate:async(e,t)=>{let n=await i.crons();if(!t())throw Error(`Cron creation target changed during preflight`);return ae(n,e.name),i.createCron(e)},onAccepted:r,beginCreate:e=>C.begin(`cron:${e}`),scopeKey:C.scopeKey})]}),t&&!e?(0,X.jsx)(h,{error:t,onRetry:r}):n&&!e?(0,X.jsx)(g,{label:`Loading crons…`}):o.length===0?(0,X.jsx)(_,{icon:(0,X.jsx)(s,{}),title:`No scheduled jobs`,hint:`Submit one above.`}):(0,X.jsx)(pe,{crons:o,page:u,removing:x,onPageChange:d,onRemove:e=>void w(e)})]})}export{he as CronManager};
@@ -1,3 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{g as t,h as n,t as r}from"./react-vendor-DfC0iyIS.js";import{o as i}from"./connectionStore-DdLzJyut.js";import{a,i as o,t as s}from"./bq-CSX8DSME.js";import{t as c}from"./toastStore-DnqA_aL-.js";import{T as l,o as u}from"./icons-C1HVBnFn.js";import{r as d}from"./StatusBadge-cYUkK-4P.js";import{n as f}from"./usePolledData-Dp_ynL9f.js";import{t as p}from"./Button-BCjgbAhY.js";import{n as m,t as h}from"./Card-DptfvL2O.js";import{i as g,n as _,r as v,t as y}from"./feedback-Dxfj-Fy1.js";import{t as b}from"./PageHeader-DD4vnVog.js";import{n as x,s as S}from"./format-Cg7VCIZW.js";import{a as C,c as w,r as T,s as E}from"./index-CxzFSZj3.js";import{a as D}from"./form-Dy-an7ew.js";import{t as ee}from"./Pagination-Cj7GzYNX.js";var O=e(n(),1),k=e(t(),1),A=r();function j({columns:e,filter:t,onChange:n}){let[r,i]=(0,k.useState)(t?.column??``),[a,o]=(0,k.useState)(t?.op??`contains`),[s,c]=(0,k.useState)(t?.value??``),u=r||e[0]||``,d=()=>n(s.trim()?{column:u,op:a,value:s.trim()}:null);return e.length===0?null:(0,A.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,A.jsx)(`div`,{className:`w-40`,children:(0,A.jsx)(D,{value:u,"aria-label":`Filter column`,name:`database-filter-column`,autoComplete:`off`,onChange:e=>i(e.target.value),children:e.map(e=>(0,A.jsx)(`option`,{value:e,children:e},e))})}),(0,A.jsx)(`div`,{className:`w-32`,children:(0,A.jsxs)(D,{value:a,"aria-label":`Filter operator`,name:`database-filter-operator`,autoComplete:`off`,onChange:e=>o(e.target.value),children:[(0,A.jsx)(`option`,{value:`contains`,children:`contains`}),(0,A.jsx)(`option`,{value:`eq`,children:`=`}),(0,A.jsx)(`option`,{value:`ne`,children:`≠`})]})}),(0,A.jsxs)(`div`,{className:`relative min-w-40 flex-1`,children:[(0,A.jsx)(l,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-faint`}),(0,A.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>e.key===`Enter`&&d(),"aria-label":`Filter value`,name:`database-filter-value`,autoComplete:`off`,placeholder:`value — Enter to filter`,className:`h-9 w-full rounded-lg border border-line bg-surface pl-8 pr-3 text-sm text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`})]}),(0,A.jsx)(p,{size:`sm`,onClick:d,disabled:!s.trim(),children:`Filter`}),t&&(0,A.jsx)(p,{size:`sm`,variant:`ghost`,onClick:()=>{c(``),n(null)},children:`Clear`}),(0,A.jsx)(`span`,{className:`text-[11px] text-faint`,children:`filters the whole table, server-side`})]})}var M=`bq-dash-db-history`,N=10,P=2e4,F=100;function I(e){let t=e==null?``:String(e),n=typeof e==`string`&&/^[=+\-@\t\r]/.test(e)?`'${e}`:t;return/[",\r\n]/.test(n)?`"${n.replaceAll(`"`,`""`)}"`:n}function L(e,t){return[e.map(I).join(`,`),...t.map(e=>e.map(I).join(`,`))].join(`
2
- `)}function R(e,t,n){let r=URL.createObjectURL(new Blob([n],{type:t})),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),0)}function z(e){if(!Array.isArray(e))return[];let t=[],n=new Set;for(let r of e.slice(0,F))if(!(typeof r!=`string`||r.length===0||r.length>P||n.has(r))&&(n.add(r),t.push(r),t.length===N))break;return t}function B(){try{return z(JSON.parse(localStorage.getItem(M)??`[]`))}catch{return[]}}function V(e){let t=z(e);try{localStorage.setItem(M,JSON.stringify(t))}catch{}return t}function H(e){return V([e,...B().filter(t=>t!==e)].slice(0,N))}function U(e){if(e==null)return`NULL`;let t=typeof e==`string`?e:String(e),n=t.trimStart();if(n.startsWith(`{`)||n.startsWith(`[`))try{return JSON.stringify(JSON.parse(t),null,2)}catch{return t}return t}async function W(e,t=s.captureAgentRequestTarget(),n){let r=Object.freeze({table:e.table,orderBy:e.orderBy,dir:e.dir,filter:e.filter?Object.freeze({...e.filter}):void 0});return s.getDbExportAtTarget(t,r,n)}var G=e=>JSON.stringify([e.activeProfileId,e.baseUrl,e.agentBaseUrl,e.token,e.agentToken]);function te({value:e,align:t}){if(e==null)return(0,A.jsx)(`span`,{className:`italic text-faint`,children:`NULL`});let n=typeof e==`string`?e:String(e);return(0,A.jsx)(`span`,{className:d(`block max-w-[24rem] truncate`,t===`right`&&`text-right tabular-nums`),title:n,children:n})}function ne({columns:e,rows:t,truncatedCells:n,colMeta:r,sort:i,onSort:a,onRowClick:o,dimmed:s}){let c=(0,k.useMemo)(()=>e.map((e,n)=>{let i=r?.[e]?.type?.toUpperCase()??``;if(/INT|REAL|NUM|DEC|DOUB|FLOA/.test(i))return!0;let a=!1;for(let e of t){let t=e[n];if(t!=null&&(a=!0,typeof t!=`number`))return!1}return a}),[e,t,r]);return(0,A.jsx)(`div`,{className:d(`max-h-[70vh] overflow-auto rounded-xl border border-line bg-surface transition-opacity`,s&&`pointer-events-none opacity-50`),children:(0,A.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,A.jsx)(`thead`,{children:(0,A.jsxs)(`tr`,{className:`text-left text-[11px] uppercase tracking-wider text-faint`,children:[o&&(0,A.jsx)(`th`,{className:`sticky top-0 z-10 whitespace-nowrap border-b border-line bg-surface px-4 py-3 font-medium`,children:(0,A.jsx)(`span`,{className:`sr-only`,children:`Row actions`})}),e.map((e,t)=>{let n=r?.[e];return(0,A.jsx)(`th`,{className:d(`sticky top-0 z-10 whitespace-nowrap border-b border-line bg-surface px-4 py-3 font-medium`,c[t]&&`text-right`),"aria-sort":i?.col===e?i.dir===`asc`?`ascending`:`descending`:a?`none`:void 0,children:a?(0,A.jsxs)(`button`,{type:`button`,onClick:()=>a(e),"aria-label":`Sort by ${e}`,className:`inline-flex items-center gap-1 uppercase tracking-wider hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,children:[e,n?.primaryKey&&(0,A.jsx)(`span`,{className:`rounded bg-accent/15 px-1 py-0.5 text-[9px] font-semibold text-accent`,children:`PK`}),n?.type&&(0,A.jsx)(`span`,{className:`text-faint/70`,children:n.type.toLowerCase()}),(0,A.jsx)(`span`,{"aria-hidden":`true`,className:i?.col===e?`text-accent`:`text-faint/60`,children:i?.col===e?i.dir===`asc`?`▲`:`▼`:`↕`})]}):e},e)})]})}),(0,A.jsx)(`tbody`,{children:t.map((e,t)=>(0,A.jsxs)(`tr`,{className:`border-b border-line font-mono text-xs last:border-0 hover:bg-surface-2/40`,children:[o&&(0,A.jsx)(`td`,{className:`whitespace-nowrap px-4 py-2`,children:(0,A.jsx)(`button`,{type:`button`,"aria-label":`View row ${t+1} details`,onClick:()=>o(t),className:`rounded-md border border-line px-2 py-1 font-sans text-[11px] font-medium text-muted transition-colors hover:border-line-strong hover:text-fg focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-accent`,children:`View`})}),e.map((e,r)=>(0,A.jsx)(`td`,{className:`whitespace-nowrap px-4 py-2 text-muted`,children:(0,A.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,A.jsx)(te,{value:e,align:c[r]?`right`:`left`}),n?.[t]?.[r]&&(0,A.jsx)(`span`,{title:`Value truncated — use the row's View action to read it in full`,className:`shrink-0 rounded bg-warning/15 px-1 text-[9px] font-semibold text-warning`,children:`…`})]})},r))]},t))})]})})}function K(e){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Malformed database query response.`);let t=e;if(t.ok!==!0||!Array.isArray(t.columns)||t.columns.some(e=>typeof e!=`string`)||!Array.isArray(t.rows)||t.rows.length>500||t.rows.some(e=>!Array.isArray(e)||e.length!==t.columns.length)||!Number.isSafeInteger(t.rowCount)||t.rowCount!==t.rows.length||typeof t.truncated!=`boolean`||typeof t.ms!=`number`||!Number.isFinite(t.ms)||t.ms<0)throw Error(`Malformed database query response.`);return{columns:[...t.columns],rows:t.rows.map(e=>[...e]),rowCount:t.rowCount,truncated:t.truncated,ms:t.ms}}function re({sql:e,setSql:t,editorRef:n}){let r=i(G),[a,o]=(0,k.useState)(null),[c,l]=(0,k.useState)(null),[u,d]=(0,k.useState)(B),[f,g]=(0,k.useState)(null),_=(0,k.useRef)(0),v=(0,k.useRef)(null),y=(0,k.useRef)(r);y.current!==r&&(y.current=r,_.current++,v.current=null),(0,k.useEffect)(()=>(_.current++,v.current=null,o(null),l(null),g(null),()=>{_.current++,v.current=null}),[r]);let b=a===r,x=c?.target===r?c.message:null,C=f?.target===r?f:null,w=async(t=e,n=!0)=>{let a=t.trim();if(!a||v.current?.target===r)return;let c=++_.current,u=r;v.current={generation:c,target:u},o(u),l(null);try{let e=K(await s.db.query(t));if(c!==_.current||G(i.getState())!==u)return;g({...e,target:u}),n&&d(H(a))}catch(e){if(c!==_.current||G(i.getState())!==u)return;g(null),l({target:u,message:e.message})}finally{v.current?.generation===c&&(v.current=null),c===_.current&&o(null)}};return(0,A.jsxs)(h,{className:`mt-6`,children:[(0,A.jsx)(m,{title:`Query`,action:(0,A.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,A.jsx)(p,{size:`sm`,disabled:b||!e.trim(),onClick:()=>{let t=e.trim();t&&w(`EXPLAIN QUERY PLAN ${t}`,!1)},children:`Explain`}),(0,A.jsx)(p,{size:`sm`,variant:`accent`,disabled:b||!e.trim(),onClick:()=>w(),children:b?`Running…`:`Run`})]})}),(0,A.jsx)(`textarea`,{name:`database-sql-query`,autoComplete:`off`,ref:n,value:e,onChange:e=>t(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&w()},rows:3,spellCheck:!1,"aria-label":`SQL query`,placeholder:`SELECT … — read-only: writes are rejected by the engine`,className:`w-full resize-y rounded-lg border border-line bg-surface-2 p-3 font-mono text-xs text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`}),(0,A.jsx)(`p`,{className:`mt-1 text-[11px] text-faint`,children:`⌘/Ctrl+Enter runs. Connection is read-only.`}),u.length>0&&(0,A.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:[(0,A.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider text-faint`,children:`History`}),u.map(e=>(0,A.jsx)(`button`,{type:`button`,onClick:()=>t(e),title:e,className:`max-w-56 truncate 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 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,children:e},e)),(0,A.jsx)(`button`,{type:`button`,onClick:()=>{V([]),d([])},className:`rounded-md px-2 py-1 text-[11px] text-faint transition-colors hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,children:`Clear`})]}),(0,A.jsxs)(`div`,{"aria-live":`polite`,children:[x&&(0,A.jsx)(`p`,{role:`alert`,className:`mt-3 text-xs text-danger`,children:x}),C&&!x&&(0,A.jsxs)(`div`,{className:`mt-4`,children:[(0,A.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-3`,children:[(0,A.jsxs)(`p`,{className:`text-xs text-faint`,children:[C.truncated?`≥ `:``,S(C.rowCount),` row`,C.rowCount===1?``:`s`,` · `,S(C.ms),` ms`,C.truncated&&(0,A.jsxs)(`span`,{className:`text-warning`,children:[` — showing first `,C.rows.length]})]}),C.rows.length>0&&(0,A.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,A.jsx)(p,{size:`sm`,onClick:()=>R(`query-results.csv`,`text/csv`,L(C.columns,C.rows)),children:`CSV`}),(0,A.jsx)(p,{size:`sm`,onClick:()=>R(`query-results.json`,`application/json`,JSON.stringify(C.rows.map(e=>Object.fromEntries(C.columns.map((t,n)=>[t,e[n]]))),null,2)),children:`JSON`})]})]}),C.rows.length>0?(0,A.jsx)(ne,{columns:C.columns,rows:C.rows}):(0,A.jsx)(`p`,{className:`text-xs text-faint`,children:`Query returned no rows.`})]})]})]})}var q=(e,t)=>t?e?.column===t.column&&e.op===t.op&&e.value===t.value:e===null;function J(e,t){return e.table===t.table&&e.limit===t.limit&&e.offset===t.offset&&e.orderBy===(t.orderBy??null)&&e.dir===t.dir&&q(e.filter,t.filter)}var Y=-(1n<<63n),X=(1n<<63n)-1n;function Z(e){if(e===null)return!0;if(typeof e==`number`)return Number.isSafeInteger(e);if(typeof e!=`string`||!/^-?(?:0|[1-9]\d*)$/.test(e)||e.length>20)return!1;try{let t=BigInt(e);return t>=Y&&t<=X}catch{return!1}}var ie=e=>e===null||typeof e==`string`||typeof e==`number`&&Number.isFinite(e);function ae(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Malformed database rows response.`);let n=e,r=n.columns,i=n.rows,a=n.rowids,o=n.truncatedCells,s=n.filter,c=s===null||typeof s==`object`&&!!s&&!Array.isArray(s)&&typeof s.column==`string`&&(s.op===`contains`||s.op===`eq`||s.op===`ne`)&&typeof s.value==`string`;if(n.ok!==!0||typeof n.table!=`string`||!Array.isArray(r)||r.length===0||r.length>2e3||r.some(e=>typeof e!=`string`||!e)||new Set(r).size!==r.length||!Array.isArray(i)||i.length>t.limit||i.some(e=>!Array.isArray(e)||e.length!==r.length||e.some(e=>!ie(e)))||!Array.isArray(a)||a.length!==i.length||a.some(e=>!Z(e))||!Array.isArray(o)||o.length!==i.length||o.some(e=>!Array.isArray(e)||e.length!==r.length||e.some(e=>typeof e!=`boolean`))||!Number.isSafeInteger(n.total)||n.total<0||!Number.isSafeInteger(n.limit)||!Number.isSafeInteger(n.offset)||n.offset<0||n.orderBy!==null&&typeof n.orderBy!=`string`||n.dir!==`asc`&&n.dir!==`desc`||!c)throw Error(`Malformed database rows response.`);let l={ok:!0,table:n.table,columns:[...r],rows:i.map(e=>[...e]),rowids:[...a],truncatedCells:o.map(e=>[...e]),total:n.total,limit:n.limit,offset:n.offset,orderBy:n.orderBy,dir:n.dir,filter:s===null?null:{...s}};if(!J(l,t))throw Error(`Database rows identity mismatch: requested table "${t.table}" at offset ${t.offset}.`);let u=Math.min(l.limit,Math.max(0,l.total-l.offset));if(l.rows.length!==u)throw Error(`Malformed database rows response: row count does not match pagination metadata.`);return l}function Q(e,t){let n=e.rows[t],r=e.truncatedCells[t],i=e.rowids[t];return!n||!r||i===void 0||t<0?null:{index:t,table:e.table,columns:[...e.columns],row:[...n],rowid:i,truncated:[...r]}}var oe=(e,t)=>e.length===t.length&&e.every((e,n)=>Object.is(e,t[n]));function se(e,t){let n=Q(t,e.index);return n!==null&&n.table===e.table&&n.rowid===e.rowid&&oe(n.columns,e.columns)&&oe(n.row,e.row)&&oe(n.truncated,e.truncated)}function ce({schema:e}){return(0,A.jsxs)(`div`,{className:`flex flex-col gap-6`,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-4 py-3 font-medium`,children:`Column`}),(0,A.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:`Type`}),(0,A.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:`Constraints`}),(0,A.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:`Default`})]})}),(0,A.jsx)(`tbody`,{children:e.columns.map(e=>(0,A.jsxs)(`tr`,{className:`border-b border-line last:border-0`,children:[(0,A.jsx)(`td`,{className:`px-4 py-2 font-mono text-xs text-fg`,children:e.name}),(0,A.jsx)(`td`,{className:`px-4 py-2 font-mono text-xs text-muted`,children:e.type}),(0,A.jsxs)(`td`,{className:`px-4 py-2 text-xs`,children:[e.primaryKey&&(0,A.jsx)(`span`,{className:`mr-1 rounded-md bg-accent/15 px-1.5 py-0.5 text-[10px] font-semibold text-accent`,children:`PK`}),e.notNull&&(0,A.jsx)(`span`,{className:`rounded-md bg-surface-2 px-1.5 py-0.5 text-[10px] font-semibold text-muted`,children:`NOT NULL`})]}),(0,A.jsx)(`td`,{className:`px-4 py-2 font-mono text-xs text-faint`,children:e.defaultValue??`—`})]},e.name))})]})}),(0,A.jsxs)(h,{children:[(0,A.jsx)(m,{title:`Indexes (${e.indexes.length})`}),e.indexes.length===0?(0,A.jsx)(`p`,{className:`text-xs text-faint`,children:`No indexes on this table.`}):(0,A.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:e.indexes.map(e=>(0,A.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2 font-mono text-xs`,children:[(0,A.jsx)(`span`,{className:`text-fg`,children:e.name}),e.unique&&(0,A.jsx)(`span`,{className:`rounded-md bg-accent/15 px-1.5 py-0.5 text-[10px] font-semibold text-accent`,children:`UNIQUE`}),(0,A.jsxs)(`span`,{className:`text-faint`,children:[`(`,e.columns.join(`, `),`)`]})]},e.name))})]}),e.sql&&(0,A.jsxs)(h,{children:[(0,A.jsx)(m,{title:`DDL`,action:(0,A.jsx)(C,{value:e.sql})}),(0,A.jsx)(`pre`,{className:`overflow-x-auto rounded-lg bg-surface-2 p-3 font-mono text-xs text-muted`,children:e.sql})]})]})}function le({db:e}){let{anyTruncated:t,colMeta:n,cycleSort:r,data:i,dbMissing:a,detail:o,editorRef:s,exportBusy:c,exportPage:l,exportTable:u,filter:f,info:m,infoError:C,msg:w,page:E,pageSize:D,queryThisTable:O,refetchInfo:k,refetchRows:M,refetchSchema:N,refetchTables:P,requestModal:F,rowsLoading:I,schema:L,schemaError:R,selectTable:z,selected:B,setDetailSelection:V,setFilter:H,setPage:U,setSql:W,setTab:G,sort:te,sql:K,tab:q,tables:J,tablesError:Y,tablesLoading:X,visibleRowsError:Z}=e;return(0,A.jsxs)(`div`,{"data-database-background":``,inert:o?!0:void 0,"aria-hidden":o?!0:void 0,children:[(0,A.jsx)(b,{title:`Database`,description:`SQLite inspector — schema, data and queries over a read-only connection.`,actions:(0,A.jsx)(`span`,{className:`rounded-full bg-emerald-500/10 px-2.5 py-1 text-[11px] font-medium text-success`,children:`read-only`})}),Y&&!a&&(0,A.jsx)(g,{message:`Could not read the database — ${Y.message}`,onRetry:P}),C&&!a&&(0,A.jsx)(g,{message:`Could not read database metadata — ${C.message}`,onRetry:k}),m&&(0,A.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-5`,children:[(0,A.jsx)(T,{label:`SQLite`,value:m.sqliteVersion,compact:!0}),(0,A.jsx)(T,{label:`On disk`,value:x(m.fileSize+m.walSize),compact:!0}),(0,A.jsx)(T,{label:`Journal`,value:m.journalMode.toUpperCase(),compact:!0}),(0,A.jsx)(T,{label:`Tables`,value:S(m.tables),compact:!0}),(0,A.jsx)(T,{label:`Indexes`,value:S(m.indexes),compact:!0})]}),a?(0,A.jsx)(y,{title:`No database yet`,hint:Y.message}):X&&J.length===0?(0,A.jsx)(v,{label:`Reading database…`}):(0,A.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-4`,children:[(0,A.jsxs)(h,{padded:!1,className:`self-start overflow-hidden`,children:[(0,A.jsxs)(`div`,{className:`border-b border-line px-4 py-3 text-[11px] font-medium uppercase tracking-wider text-faint`,children:[`Tables (`,J.length,`)`]}),(0,A.jsxs)(`ul`,{className:`max-h-[28rem] overflow-y-auto`,children:[J.map(e=>(0,A.jsx)(`li`,{children:(0,A.jsxs)(`button`,{type:`button`,onClick:()=>z(e.name),className:d(`flex w-full items-center justify-between gap-2 px-4 py-2 text-left text-sm transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,B===e.name?`bg-surface-2 text-fg`:`text-muted hover:bg-surface-2/60 hover:text-fg`),children:[(0,A.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs`,children:e.name}),(0,A.jsx)(`span`,{className:`shrink-0 text-[11px] text-faint tabular-nums`,children:S(e.rows)})]})},e.name)),J.length===0&&(0,A.jsx)(`li`,{className:`px-4 py-6 text-center text-xs text-faint`,children:`No tables.`})]})]}),(0,A.jsx)(`div`,{className:`min-w-0 lg:col-span-3`,children:J.length===0?(0,A.jsx)(y,{title:`No tables`,hint:`This database has no user tables yet.`}):(0,A.jsxs)(A.Fragment,{children:[B&&(0,A.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:[(0,A.jsx)(`span`,{className:`mr-auto min-w-0 truncate font-mono text-sm text-fg`,title:B,children:B}),(0,A.jsx)(p,{size:`sm`,variant:`ghost`,onClick:O,children:`Query`}),(0,A.jsx)(`div`,{className:`inline-flex items-center gap-1 rounded-lg border border-line bg-surface p-1`,children:[`data`,`schema`].map(e=>(0,A.jsx)(`button`,{type:`button`,onClick:()=>G(e),"aria-pressed":q===e,className:d(`rounded-md px-3 py-1 text-xs font-medium capitalize transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,q===e?`bg-surface-2 text-fg`:`text-muted hover:text-fg`),children:e},e))}),q===`data`&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(p,{size:`sm`,disabled:!i||i.rows.length===0,title:i?`Exports the ${i.rows.length} rows on this page only`:void 0,onClick:l,children:[`Export page`,i?` (${i.rows.length})`:``]}),(0,A.jsx)(p,{size:`sm`,variant:`accent`,disabled:c||!i||i.total===0,onClick:u,children:c?`Exporting…`:`Export table${i?` (${S(i.total)})`:``}`})]})]}),q===`data`&&B&&(0,A.jsx)(j,{columns:i?.columns??L?.columns.map(e=>e.name)??[],filter:f,onChange:e=>{H(e),U(0),V(null)}},B),w&&(0,A.jsx)(`p`,{className:`mb-3 text-xs text-muted`,children:w}),q===`schema`?R?(0,A.jsx)(y,{title:`Could not read schema`,hint:R.message,action:(0,A.jsx)(p,{size:`sm`,onClick:N,children:`Retry`})}):L?.table===B?(0,A.jsx)(ce,{schema:L}):(0,A.jsx)(v,{label:`Reading schema of ${B}…`}):Z?(0,A.jsx)(_,{error:Z,onRetry:M}):I&&!i?(0,A.jsx)(v,{label:`Reading ${B}…`}):i?i.total===0?(0,A.jsx)(y,{title:f?`No matching rows`:`Empty table`,hint:f?`No rows match the current filter.`:`"${i.table}" has no rows.`}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(ne,{columns:i.columns,rows:i.rows,truncatedCells:i.truncatedCells,colMeta:n,sort:te,onSort:r,onRowClick:e=>{let t=Q(i,e);t&&F(`database-row`)&&V(t)},dimmed:I&&!i}),t&&(0,A.jsx)(`p`,{className:`mt-2 text-[11px] text-faint`,children:`Cells over 2000 chars and BLOBs are abbreviated in the grid and CSV — use the row's View action to read the full value.`}),(0,A.jsx)(ee,{page:E,pageSize:D,total:i.total,onPageChange:e=>{U(e),V(null)},label:`rows`})]}):(0,A.jsx)(y,{title:`Select a table`,hint:`Pick a table on the left to browse its rows.`}),(0,A.jsx)(re,{sql:K,setSql:W,editorRef:s})]})})]})]})}var ue=[`a[href]`,`button:not([disabled])`,`input:not([disabled])`,`select:not([disabled])`,`textarea:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`,`);function de({table:e,columns:t,row:n,rowid:r,truncated:i,onClose:a}){let[o,c]=(0,k.useState)({}),[l,d]=(0,k.useState)({}),f=(0,k.useRef)(null),p=(0,k.useRef)(null),m=(0,k.useRef)(a);m.current=a,(0,k.useEffect)(()=>{let e=document.activeElement,t=f.current,n=()=>t?Array.from(t.querySelectorAll(ue)).filter(e=>e.getAttribute(`aria-hidden`)!==`true`):[],r=(e=!1)=>{let r=n();(e?r.at(-1):r[0])?.focus(),r.length===0&&t?.focus()},i=e=>{if(e.key===`Escape`){e.preventDefault(),m.current();return}if(e.key!==`Tab`)return;let r=n();if(r.length===0){e.preventDefault(),t?.focus();return}let i=document.activeElement,a=r[0],o=r[r.length-1];e.shiftKey&&(i===a||!i||!t?.contains(i))?(e.preventDefault(),o.focus()):!e.shiftKey&&(i===o||!i||!t?.contains(i))&&(e.preventDefault(),a.focus())},a=e=>{t&&!t.contains(e.target)&&r()};return p.current?.focus(),document.activeElement!==p.current&&t?.focus(),document.addEventListener(`keydown`,i,!0),document.addEventListener(`focusin`,a),()=>{document.removeEventListener(`keydown`,i,!0),document.removeEventListener(`focusin`,a),E(`database-row`)&&e?.isConnected&&e.focus()}},[]);let h=JSON.stringify(t.filter((e,t)=>i[t]));return(0,k.useEffect)(()=>{c({}),d({});let t=JSON.parse(h);if(r==null||t.length===0)return;let n=!1;return Promise.all(t.map(async t=>{try{let i=await s.db.cell(e,r,t);if(!i||typeof i!=`object`||!Object.hasOwn(i,`value`))throw Error(`Malformed full-cell response.`);n||c(e=>({...e,[t]:i.value}))}catch(e){if(!n){let n=e instanceof Error?e.message:String(e);d(e=>({...e,[t]:n.slice(0,300)}))}}})),()=>{n=!0}},[e,r,h]),(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`button`,{type:`button`,"aria-label":`Close row detail`,onClick:a,className:`fixed inset-0 z-40 bg-black/50`}),(0,A.jsxs)(`aside`,{ref:f,role:`dialog`,"aria-modal":`true`,"aria-label":`${e} row ${r??`detail`}`,tabIndex:-1,className:`fixed inset-y-0 right-0 z-50 flex w-full max-w-xl flex-col border-l border-line bg-surface shadow-xl focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-accent`,children:[(0,A.jsxs)(`div`,{className:`flex items-center justify-between border-b border-line px-5 py-4`,children:[(0,A.jsxs)(`h2`,{className:`font-mono text-sm text-fg`,children:[e,` · row detail`]}),(0,A.jsx)(`button`,{ref:p,type:`button`,"aria-label":`Close`,onClick:a,className:`flex size-8 items-center justify-center rounded-lg text-muted hover:bg-surface-2 hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,children:(0,A.jsx)(u,{className:`size-4`})})]}),(0,A.jsx)(`div`,{className:`flex-1 overscroll-contain overflow-y-auto p-5`,children:(0,A.jsx)(`dl`,{className:`flex flex-col gap-4`,children:t.map((e,t)=>{let a=Object.hasOwn(o,e),s=a?o[e]:n[t],c=U(s),u=c.includes(`
3
- `)||c.length>80;return(0,A.jsxs)(`div`,{children:[(0,A.jsxs)(`dt`,{className:`mb-1 flex items-center gap-1.5 text-[11px] uppercase tracking-wider text-faint`,children:[e,s!=null&&(0,A.jsx)(C,{value:String(s)}),i[t]&&!a&&(r==null?(0,A.jsx)(`span`,{className:`normal-case text-warning`,children:`(truncated — full value unavailable: this table has no rowid to fetch it by)`}):Object.hasOwn(l,e)?(0,A.jsxs)(`span`,{role:`alert`,className:`normal-case text-danger`,children:[`(full value unavailable — `,l[e],`)`]}):(0,A.jsx)(`span`,{className:`text-warning`,children:`(loading full value…)`}))]}),(0,A.jsx)(`dd`,{children:s==null?(0,A.jsx)(`span`,{className:`italic text-faint`,children:`NULL`}):u?(0,A.jsx)(`pre`,{className:`max-h-80 overflow-auto whitespace-pre-wrap break-words rounded-lg bg-surface-2 p-3 font-mono text-xs text-muted`,children:c}):(0,A.jsx)(`span`,{className:`break-words font-mono text-sm text-fg`,children:c})})]},e)})})})]})]})}function fe({data:e,filter:t,page:n,selected:r,sort:a}){let l=i(G),[u,d]=(0,k.useState)(!1),[f,p]=(0,k.useState)(null),m=(0,k.useRef)(!1),h=(0,k.useRef)(null);return(0,k.useEffect)(()=>(h.current?.abort(),h.current=null,m.current=!1,d(!1),p(null),()=>{h.current?.abort(),h.current=null,m.current=!1}),[l]),{exportBusy:u,exportPage:()=>{e&&R(`${e.table}-page${n+1}.csv`,`text/csv`,L(e.columns,e.rows))},exportTable:async()=>{if(!r||m.current)return;m.current=!0;let e=G(i.getState()),n={table:r,orderBy:a?.col,dir:a?.dir??`asc`,filter:t?{...t}:void 0},l=s.captureAgentRequestTarget(),u=new AbortController;h.current=u,d(!0),p(null);try{let t=await W(n,l,u.signal);if(u.signal.aborted||G(i.getState())!==e)return;R(`${n.table}.csv`,`text/csv;charset=utf-8`,t.content);let r=t.cap===`rows`?`Exported the first ${S(t.rowCount)} rows (row cap reached)`:t.cap===`bytes`?`Exported ${S(t.rowCount)} rows (${x(o)} byte cap reached)`:`Exported ${S(t.rowCount)} rows`;p(r),c.success(`Export of ${n.table} complete`,r)}catch(t){if(u.signal.aborted||G(i.getState())!==e)return;p(`Export failed: ${t.message}`),c.error(`Export of ${n.table} failed`,t.message)}finally{h.current===u&&(h.current=null,m.current=!1,u.signal.aborted||d(!1))}},msg:f}}var $=50;function pe(){let[e,t]=(0,k.useState)(``),[n,r]=(0,k.useState)(0),[i,o]=(0,k.useState)(null),[c,l]=(0,k.useState)(`data`),[u,d]=(0,k.useState)(null),[p,m]=(0,k.useState)(null),h=w(e=>e.active),g=w(e=>e.request),_=w(e=>e.release),[v,y]=(0,k.useState)(`SELECT name FROM sqlite_master WHERE type = 'table'`),b=(0,k.useRef)(null);(0,k.useEffect)(()=>{p===null?_(`database-row`):h!==`database-row`&&m(null)},[p,h,_]),(0,k.useEffect)(()=>()=>{w.getState().release(`database-row`)},[]);let{data:x,error:S,loading:C,refetch:T}=f(()=>s.db.tables(),[],{intervalMs:1e4}),E=(0,k.useMemo)(()=>x?.tables??[],[x]),D=S instanceof a&&S.status===404,{data:ee,error:O,refetch:A}=f(()=>D?Promise.resolve(null):s.db.info(),[D],{intervalMs:15e3}),j=e||E[0]?.name||``;(0,k.useEffect)(()=>{!e&&E[0]&&t(E[0].name)},[e,E]);let{data:M,error:N,refetch:P}=f(()=>j?s.db.schema(j):Promise.resolve(null),[j],{intervalMs:3e4}),F=(0,k.useMemo)(()=>{let e={};if(M?.table===j)for(let t of M.columns)e[t.name]={type:t.type,primaryKey:t.primaryKey};return e},[M,j]),I=u?JSON.stringify([u.column,u.op,u.value]):``,{data:L,error:R,loading:z,refetch:B}=f((0,k.useCallback)(async()=>{if(!j)return null;let e={table:j,limit:$,offset:n*$,orderBy:i?.col,dir:i?.dir??`asc`,filter:u??void 0};return ae(await s.db.rows(j,$,e.offset,i?.col,i?.dir,u??void 0),e)},[j,n,i,u]),[j,n,i,I],{intervalMs:6e3}),V={table:j,limit:$,offset:n*$,orderBy:i?.col,dir:i?.dir??`asc`,filter:u??void 0},H=!!L&&J(L,V),U=R??(L&&!H?Error(`Database rows identity no longer matches the selected table and page.`):null),W=!U&&H?L:null,G=p!==null&&W!==null&&se(p,W),te=G?p:null;(0,k.useEffect)(()=>{p&&!G&&m(null)},[p,G]),(0,k.useEffect)(()=>{W&&W.total>0&&W.rows.length===0&&n>0&&r(Math.max(0,Math.ceil(W.total/$)-1))},[W,n]);let ne=()=>{r(0),o(null),d(null),m(null)},K=e=>{t(e),l(`data`),ne()},re=e=>{r(0),m(null),o(t=>t?.col===e?t.dir===`asc`?{col:e,dir:`desc`}:null:{col:e,dir:`asc`})},q=()=>{let e=`SELECT * FROM "${j.replaceAll(`"`,`""`)}" LIMIT 100`;y(e),requestAnimationFrame(()=>{b.current?.focus(),b.current?.scrollIntoView({behavior:`smooth`,block:`center`})})},Y=!!W?.truncatedCells.some(e=>e.some(Boolean)),{exportBusy:X,exportPage:Z,exportTable:ie,msg:Q}=fe({data:W,filter:u,page:n,selected:j,sort:i});return{activeModal:h,anyTruncated:Y,colMeta:F,cycleSort:re,data:W,dbMissing:D,detail:te,editorRef:b,exportBusy:X,exportPage:Z,exportTable:ie,filter:u,info:ee,infoError:O,msg:Q,page:n,pageSize:$,queryThisTable:q,refetchInfo:A,refetchRows:B,refetchSchema:P,refetchTables:T,requestModal:g,rowsLoading:z,schema:M,schemaError:N,selectTable:K,selected:j,setDetailSelection:m,setFilter:d,setPage:r,setSql:y,setTab:l,sort:i,sql:v,tab:c,tables:E,tablesError:S,tablesLoading:C,visibleRowsError:U}}function me(){let e=pe(),{activeModal:t,detail:n,setDetailSelection:r}=e;return(0,A.jsxs)(`div`,{children:[(0,A.jsx)(le,{db:e}),n&&t===`database-row`&&(0,O.createPortal)((0,A.jsx)(de,{table:n.table,columns:n.columns,row:n.row,rowid:n.rowid,truncated:n.truncated,onClose:()=>r(null)}),document.body)]})}export{me as Database};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{g as t,t as n}from"./react-vendor-DfC0iyIS.js";import{t as r}from"./bq-CSX8DSME.js";import{t as i}from"./toastStore-DnqA_aL-.js";import{n as a}from"./StatusBadge-cYUkK-4P.js";import{t as o}from"./api-Bbo86MB6.js";import{n as s}from"./usePolledData-Dp_ynL9f.js";import{t as c}from"./Button-BCjgbAhY.js";import{n as l,t as u}from"./Card-DptfvL2O.js";import{i as d,r as f}from"./feedback-Dxfj-Fy1.js";import{t as p}from"./PageHeader-DD4vnVog.js";import{n as m,s as h,u as g}from"./format-Cg7VCIZW.js";import{a as _,r as v}from"./index-CxzFSZj3.js";import{t as y}from"./useControlActionGuard-DImMgJtj.js";var b=n();function x(e,t){return t?{label:`Unavailable`,tone:`red`,detail:t}:e===null?{label:`Unknown`,tone:`zinc`,detail:`No response yet`}:e.trim()===`OK`?{label:`Live`,tone:`green`,detail:`HTTP 200 · OK`}:{label:`Unexpected`,tone:`amber`,detail:`HTTP 200 · ${e.trim().slice(0,80)||`empty body`}`}}function S(e,t){return t?{label:`Unavailable`,tone:`red`,detail:t}:e?e.ok===!0&&e.ready===!0?{label:`Ready`,tone:`green`,detail:`Persistence accepts traffic`}:e.ok===!1&&e.ready===!1?{label:`Not ready`,tone:`red`,detail:e.storage.error??`Persistence is degraded`}:{label:`Unexpected`,tone:`amber`,detail:`Incoherent readiness payload`}:{label:`Unknown`,tone:`zinc`,detail:`No response yet`}}function C({path:e,state:t}){return(0,b.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 border-b border-line py-2.5 last:border-0`,children:[(0,b.jsx)(`code`,{className:`w-20 shrink-0 font-mono text-xs text-fg`,children:e}),(0,b.jsx)(a,{label:t.label,tone:t.tone}),(0,b.jsx)(`span`,{className:`min-w-0 flex-1 text-right text-xs text-faint`,children:t.detail})]})}function w({snapshot:e}){let t=e.metrics?.metrics;return(0,b.jsxs)(`div`,{className:`mt-6 grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,b.jsxs)(u,{children:[(0,b.jsx)(l,{title:`Orchestrator probes`}),(0,b.jsx)(`p`,{className:`mb-2 text-xs text-muted`,children:`Native Bunqueue liveness and persistence-readiness endpoints.`}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(C,{path:`/healthz`,state:x(e.healthz,e.healthzError)}),(0,b.jsx)(C,{path:`/live`,state:x(e.live,e.liveError)}),(0,b.jsx)(C,{path:`/ready`,state:S(e.ready,e.readyError)})]})]}),(0,b.jsxs)(u,{children:[(0,b.jsx)(l,{title:`JSON metrics`}),e.metricsError?(0,b.jsxs)(`p`,{className:`text-sm text-danger`,children:[`Unavailable — `,e.metricsError]}):t?(0,b.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,b.jsx)(O,{k:`Pushed`,v:h(t.totalPushed)}),(0,b.jsx)(O,{k:`Pulled`,v:h(t.totalPulled)}),(0,b.jsx)(O,{k:`Completed`,v:h(t.totalCompleted)}),(0,b.jsx)(O,{k:`Failed`,v:h(t.totalFailed)})]}):(0,b.jsx)(`p`,{className:`text-sm text-muted`,children:`No metrics response yet.`}),(0,b.jsx)(`p`,{className:`mt-3 font-mono text-xs text-faint`,children:`GET /metrics · application/json`})]})]})}function T({heap:e,busy:t,onLoad:n}){return(0,b.jsxs)(u,{className:`mt-6`,children:[(0,b.jsx)(l,{title:`Heap statistics`,action:(0,b.jsx)(c,{size:`sm`,disabled:t,onClick:n,children:t?`Loading…`:e?`Refresh`:`Load`})}),e?(0,b.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,b.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,b.jsx)(O,{k:`Objects`,v:h(e.heap?.objectCount??0)}),(0,b.jsx)(O,{k:`Protected`,v:h(e.heap?.protectedCount??0)}),(0,b.jsx)(O,{k:`Global`,v:h(e.heap?.globalCount??0)})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`div`,{className:`mb-2 text-[11px] uppercase tracking-wider text-faint`,children:`Top object types`}),(0,b.jsx)(`div`,{className:`max-h-52 overflow-y-auto rounded-lg border border-line`,children:(0,b.jsx)(`table`,{className:`w-full text-xs`,children:(0,b.jsx)(`tbody`,{children:(e.topObjectTypes??[]).map(e=>(0,b.jsxs)(`tr`,{className:`border-b border-line last:border-0`,children:[(0,b.jsx)(`td`,{className:`px-3 py-1.5 font-mono text-muted`,children:e.type}),(0,b.jsx)(`td`,{className:`px-3 py-1.5 text-right tnum text-fg`,children:h(e.count)})]},e.type))})})})]})]}):(0,b.jsxs)(`p`,{className:`text-sm text-muted`,children:[`On-demand `,(0,b.jsx)(`code`,{className:`font-mono text-xs`,children:`bun:jsc`}),` heap breakdown (forces a GC first). Use it to spot which internal object type is growing when chasing a leak.`]})]})}function E(){let e=r.prometheusUrl();return(0,b.jsxs)(u,{className:`mt-6`,children:[(0,b.jsx)(l,{title:`Prometheus`}),(0,b.jsxs)(`p`,{className:`mb-3 text-sm text-muted`,children:[`Scrape endpoint (text exposition) for Grafana / Alertmanager. Auth is required only if the server sets `,(0,b.jsx)(`code`,{className:`font-mono text-xs`,children:`requireAuthForMetrics`}),`.`]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-line bg-surface-2 px-3 py-2`,children:[(0,b.jsx)(`code`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-fg`,children:e}),(0,b.jsx)(_,{value:e})]})]})}function D({stats:e}){return e?(0,b.jsxs)(u,{className:`mt-6`,children:[(0,b.jsx)(l,{title:`Totals since restart`}),(0,b.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,b.jsx)(O,{k:`Pushed`,v:h(e.totalPushed)}),(0,b.jsx)(O,{k:`Pulled`,v:h(e.totalPulled)}),(0,b.jsx)(O,{k:`Completed`,v:h(e.totalCompleted)}),(0,b.jsx)(O,{k:`Failed`,v:h(e.totalFailed)})]})]}):null}function O({k:e,v:t}){return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-faint`,children:e}),(0,b.jsx)(`div`,{className:`mt-1 text-lg font-semibold tnum text-fg`,children:t})]})}var k=e(t(),1);function A(e){let t=y(`diagnostics`),[n,a]=(0,k.useState)(null),o=n?.scope===t.scopeKey?n.value:null,s=(0,k.useRef)(0),c=async()=>{let e=++s.current,n=t.begin(`ping:${e}`);if(!n)return;a({scope:t.scopeKey,value:`…`});let i=performance.now();try{await r.ping(),n.isCurrent()&&s.current===e&&a({scope:t.scopeKey,value:`${Math.round(performance.now()-i)} ms`})}catch{n.isCurrent()&&s.current===e&&a({scope:t.scopeKey,value:`unreachable`})}finally{n.finish()}},[l,u]=(0,k.useState)(null),d=l?.scope===t.scopeKey&&l.busy,f=l?.scope===t.scopeKey?l.message:null,p=async()=>{let n=t.begin(`gc`);if(n){u({busy:!0,message:null,scope:t.scopeKey});try{let a=await r.gc();if(!n.isCurrent())return;let o=a.before.rss-a.after.rss,s=o>0?`Freed ${o} MB (RSS ${a.before.rss}→${a.after.rss})`:`No memory reclaimed`;u({busy:!0,message:s,scope:t.scopeKey}),i.success(`Memory compacted`,s),e()}catch(e){if(!n.isCurrent())return;let r=e.message;i.error(`GC failed`,r),u({busy:!0,message:r,scope:t.scopeKey})}finally{n.finish()&&u(e=>e?.scope===t.scopeKey?{...e,busy:!1}:e)}}},[m,h]=(0,k.useState)(null);return{doGc:p,doPing:c,gcBusy:d,gcMsg:f,heap:m?.scope===t.scopeKey?m.value:null,heapBusy:m?.scope===t.scopeKey&&m.busy,loadHeap:async()=>{let e=t.begin(`heap`);if(e){h({busy:!0,scope:t.scopeKey,value:null});try{let n=await r.heapStats();e.isCurrent()&&h({busy:!0,scope:t.scopeKey,value:n})}catch(t){e.isCurrent()&&i.error(`Heap stats failed`,t.message)}finally{e.finish()&&h(e=>e?.scope===t.scopeKey?{...e,busy:!1}:e)}}},ping:o}}async function j(e){try{return{value:await e,error:null}}catch(e){return{value:null,error:e instanceof Error?e.message:String(e)}}}function M(){let{data:e,error:t,loading:n,refetch:i}=s(async()=>{let[e,t,n,i,a,s,c]=await Promise.all([j(r.health()),j(r.storage()),j(r.stats()),j(o.healthz()),j(o.live()),j(o.ready()),j(o.metrics())]);return{health:e.value,storage:t.value,stats:n.value,healthError:e.error,storageError:t.error,statsError:n.error,healthz:i.value,live:a.value,ready:s.value,metrics:c.value,healthzError:i.error,liveError:a.error,readyError:s.error,metricsError:c.error}},[]),{doGc:a,doPing:h,gcBusy:_,gcMsg:y,heap:x,heapBusy:S,loadHeap:C,ping:k}=A(i);if(n&&!e&&!t)return(0,b.jsx)(f,{label:`Loading diagnostics…`});let M=e??{health:null,storage:null,stats:null,healthError:null,storageError:null,statsError:null,healthz:null,live:null,ready:null,metrics:null,healthzError:null,liveError:null,readyError:null,metricsError:null},P=M.health,F=M.storage?.data,I=M.stats?.stats,L=P!=null,R=F!=null,z=L&&P.ok===!0,B=!!t||!!M.healthError||!!M.storageError||!!M.statsError||!!M.healthzError||!!M.liveError||!!M.readyError||!!M.metricsError;return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(p,{title:`Diagnostics`,description:`Server health, storage, memory and connections.`,live:!!e&&!B}),t&&(0,b.jsx)(d,{message:`Diagnostics refresh failed — ${t.message}`,onRetry:i}),M.healthError&&(0,b.jsx)(d,{message:`Health unavailable — ${M.healthError}`,onRetry:i}),M.storageError&&(0,b.jsx)(d,{message:`Storage diagnostics unavailable — ${M.storageError}`,onRetry:i}),M.statsError&&(0,b.jsx)(d,{message:`Server totals unavailable — ${M.statsError}`,onRetry:i}),(0,b.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,b.jsx)(v,{label:`Status`,value:L?P.status??(P.ok?`healthy`:`degraded`):`Unavailable`,tone:z?`green`:`red`,compact:!0}),(0,b.jsx)(v,{label:`Version`,value:P?.version?`v${P.version}`:`—`,compact:!0}),(0,b.jsx)(v,{label:`Uptime`,value:g(P?.uptime),compact:!0}),(0,b.jsx)(v,{label:`Disk`,value:R?F.diskFull?`Full`:`Healthy`:`Unavailable`,tone:!R||F.diskFull?`red`:`green`,compact:!0})]}),(0,b.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,b.jsxs)(u,{children:[(0,b.jsx)(l,{title:`Connectivity`,action:(0,b.jsxs)(c,{size:`sm`,onClick:h,children:[`Ping`,k?` · ${k}`:``]})}),(0,b.jsxs)(`dl`,{className:`divide-y divide-line text-sm`,children:[(0,b.jsx)(N,{k:`WebSocket clients`,v:P?.connections?.ws==null?`—`:String(P.connections.ws)}),(0,b.jsx)(N,{k:`SSE clients`,v:P?.connections?.sse==null?`—`:String(P.connections.sse)}),(0,b.jsx)(N,{k:`Storage error`,v:M.storageError?`unavailable — ${M.storageError}`:F?.error?String(F.error):R?`none`:`—`})]})]}),(0,b.jsxs)(u,{children:[(0,b.jsx)(l,{title:`Memory`,action:(0,b.jsx)(c,{size:`sm`,disabled:_,onClick:a,children:_?`Compacting…`:`Compact (GC)`})}),(0,b.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,b.jsx)(O,{k:`Heap used`,v:P?.memory?m(P.memory.heapUsed*1024*1024):`—`}),(0,b.jsx)(O,{k:`Heap total`,v:P?.memory?m(P.memory.heapTotal*1024*1024):`—`}),(0,b.jsx)(O,{k:`RSS`,v:P?.memory?m(P.memory.rss*1024*1024):`—`})]}),y&&(0,b.jsx)(`p`,{className:`mt-3 text-xs text-muted`,children:y})]})]}),(0,b.jsx)(w,{snapshot:M}),(0,b.jsx)(T,{heap:x,busy:S,onLoad:C}),(0,b.jsx)(E,{}),(0,b.jsx)(D,{stats:I})]})}function N({k:e,v:t}){return(0,b.jsxs)(`div`,{className:`flex items-center justify-between py-2.5`,children:[(0,b.jsx)(`dt`,{className:`text-muted`,children:e}),(0,b.jsx)(`dd`,{className:`font-medium text-fg`,children:t})]})}export{M as Diagnostics};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{g as t,t as n}from"./react-vendor-DfC0iyIS.js";import{u as r}from"./icons-C1HVBnFn.js";import{t as i}from"./api-Bbo86MB6.js";import{n as a}from"./usePolledData-Dp_ynL9f.js";import{t as o}from"./Button-BCjgbAhY.js";import{i as s,n as c,r as l,t as u}from"./feedback-Dxfj-Fy1.js";import{t as d}from"./PageHeader-DD4vnVog.js";import{l as f,s as p}from"./format-Cg7VCIZW.js";import{r as m}from"./index-CxzFSZj3.js";import{a as h}from"./form-Dy-an7ew.js";import{t as g}from"./Pagination-Cj7GzYNX.js";import{r as _,t as v}from"./flowMutationSafety-YKTHxqKv.js";import{i as y,r as b}from"./classicJobsData-BimIyQky.js";import"./Jobs-D_TId_Oa.js";var x=e(t(),1),S=n(),C=25;function w(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}async function T(){let e=await b();if(!Number.isFinite(e.timestamp)||e.queues.some(e=>!w(e.waiting)||!w(e.delayed)||!w(e.active)||!w(e.dlq)||typeof e.paused!=`boolean`))throw Error(`Queue discovery returned malformed queue summaries`);return e}function E(){let[e,t]=(0,x.useState)(``),[n,b]=(0,x.useState)(0),{data:w,error:E,loading:D,refetch:O}=a(T,[],{intervalMs:3e4});(0,x.useEffect)(()=>{if(e||!w?.queues?.length)return;let n=w.queues.find(e=>e.dlq>0)??w.queues[0];t(n.name)},[w,e]);let{data:k,error:A,loading:j,refetch:M}=a((0,x.useCallback)(async()=>{if(!e)return{entries:[],total:0};let t=await i.dlq(e,C,n*C);return{entries:t.entries??[],total:t.total??t.entries?.length??0}},[e,n]),[e,n]),N=k?.entries??[];return(0,S.jsxs)(`div`,{children:[A&&k&&(0,S.jsx)(s,{message:`DLQ refresh failed — showing the last successful page.`,onRetry:M}),E&&(0,S.jsx)(s,{onRetry:O,message:`Could not discover queues — ${E.message}. Retry before selecting a queue.`}),(0,S.jsx)(d,{title:`Dead Letter Queue`,description:`Jobs that exhausted their retries.`,live:!!e&&!!k&&!A&&!E,actions:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(o,{size:`sm`,disabled:!0,title:v,children:`Retry all`}),(0,S.jsx)(o,{variant:`danger`,size:`sm`,disabled:!0,title:_,children:`Purge`})]})}),(0,S.jsxs)(`div`,{className:`mb-6 flex flex-wrap items-center gap-3`,children:[(0,S.jsx)(`div`,{className:`w-56`,children:(0,S.jsx)(h,{value:e,"aria-label":`Queue`,name:`classic-dlq-queue`,autoComplete:`off`,onChange:e=>{t(e.target.value),b(0)},children:(w?.queues??[]).map(e=>(0,S.jsxs)(`option`,{value:e.name,children:[e.name,` `,e.dlq?`(${e.dlq})`:``]},e.name))})}),(0,S.jsx)(`div`,{className:`w-40`,children:(0,S.jsx)(m,{label:`DLQ Entries`,value:e&&k?p(k.total):`—`,tone:e&&k?.total?`red`:`default`,compact:!0})})]}),A&&!k?(0,S.jsx)(c,{error:A,onRetry:M}):D&&!w&&!e&&!E?(0,S.jsx)(l,{label:`Discovering queues…`}):j&&!k&&!A?(0,S.jsx)(l,{label:`Loading DLQ…`}):E&&!e?(0,S.jsx)(u,{icon:(0,S.jsx)(r,{}),title:`Could not discover queues`,hint:`${E.message}. Retry the queue discovery request above.`}):e?N.length===0?(0,S.jsx)(u,{icon:(0,S.jsx)(r,{}),title:`Dead letter queue is empty`,hint:`Jobs land here after exhausting their retry attempts.`}):(0,S.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,S.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,S.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Job ID`}),(0,S.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Name`}),(0,S.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Reason`}),(0,S.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Attempts`}),(0,S.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Failed`})]})}),(0,S.jsx)(`tbody`,{children:N.map((e,t)=>(0,S.jsxs)(`tr`,{className:`border-b border-line last:border-0 align-top hover:bg-surface-2/40`,children:[(0,S.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.job.id}),(0,S.jsx)(`td`,{className:`px-5 py-3 text-fg`,children:e.job.name??y(e.job.data)??`default`}),(0,S.jsx)(`td`,{className:`max-w-md px-5 py-3 text-xs text-red-400/90`,children:String(e.reason||e.error||`—`)}),(0,S.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:e.attempts?.length??e.job.attempts??`—`}),(0,S.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:f(e.attempts?.at(-1)?.failedAt??e.enteredAt)})]},e.job.id||t))})]})}):(0,S.jsx)(u,{icon:(0,S.jsx)(r,{}),title:w?.queues.length===0?`No queues available`:`Select a queue`,hint:`A queue must be selected before its dead letter entries can be inspected.`}),k&&(0,S.jsx)(g,{page:n,pageSize:C,total:k.total,onPageChange:b,label:`entries`})]})}export{E as Dlq};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{g as t,r as n,t as r}from"./react-vendor-DfC0iyIS.js";import{t as i}from"./bq-CSX8DSME.js";import{t as a}from"./toastStore-DnqA_aL-.js";import{C as o,T as s,a as c,d as l,f as u,u as d}from"./icons-C1HVBnFn.js";import{r as f}from"./StatusBadge-cYUkK-4P.js";import{n as p}from"./usePolledData-Dp_ynL9f.js";import{n as m,t as h}from"./Button-BCjgbAhY.js";import{i as g,n as _,r as v,t as y}from"./feedback-Dxfj-Fy1.js";import{t as b}from"./PageHeader-DD4vnVog.js";import{a as x,i as S,l as C,s as w}from"./format-Cg7VCIZW.js";import{a as T,r as E}from"./index-CxzFSZj3.js";import{a as D}from"./form-Dy-an7ew.js";import{t as O}from"./Pagination-Cj7GzYNX.js";import{r as k,t as A}from"./flowMutationSafety-YKTHxqKv.js";import{t as j}from"./exportFile-C7xhE8Yh.js";import{t as M}from"./QueueControl-g-9kwrpt.js";var N=e(t(),1),P=r();function F({queue:e,data:t,reasons:n,topReason:r}){return(0,P.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,P.jsx)(E,{label:`Entries`,value:e&&t?w(t.total):`—`,tone:!e||!t?`default`:t.total?`red`:`green`,hint:!e||!t?`waiting for queue data`:t.total?r?`top: ${r}`:void 0:`queue is clean`,compact:!0}),(0,P.jsx)(E,{label:`Failure types`,value:t?.stats?w(n.length):`—`,hint:`distinct reasons`,compact:!0}),(0,P.jsx)(E,{label:`Pending retry`,value:t?.stats?w(t.stats.pendingRetry??0):`—`,tone:t?.stats?.pendingRetry?`amber`:`default`,hint:`auto-retry queued`,compact:!0}),(0,P.jsx)(E,{label:`Oldest entry`,value:t?.stats?.oldestEntry?C(t.stats.oldestEntry):`—`,hint:`time in DLQ`,compact:!0})]})}function I({queue:e,queues:t,reason:n,reasons:r,byReason:i,search:a,pageScoped:o,onQueue:c,onReason:l,onSearch:u}){return(0,P.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-3`,children:[(0,P.jsx)(`div`,{className:`w-56`,children:(0,P.jsx)(D,{value:e,"aria-label":`Queue`,name:`dlq-control-queue`,autoComplete:`off`,onChange:e=>c(e.target.value),children:t.map(e=>(0,P.jsxs)(`option`,{value:e.name,children:[e.name,` `,e.dlq?`(${e.dlq})`:``]},e.name))})}),(0,P.jsx)(`div`,{className:`w-44`,children:(0,P.jsxs)(D,{value:n,"aria-label":`Filter by reason`,name:`dlq-control-reason`,autoComplete:`off`,onChange:e=>l(e.target.value),children:[(0,P.jsx)(`option`,{value:`all`,children:`All reasons`}),r.map(e=>(0,P.jsxs)(`option`,{value:e,children:[e,` (`,i[e],`)`]},e))]})}),(0,P.jsxs)(`div`,{className:`relative min-w-40 flex-1`,children:[(0,P.jsx)(s,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-faint`}),(0,P.jsx)(`input`,{value:a,onChange:e=>u(e.target.value),placeholder:o?`Filter this page by job ID…`:`Filter by job ID…`,"aria-label":`Filter by job ID`,name:`dlq-control-job-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`})]})]})}function L({entry:e,isOpen:t,onToggle:r,attempts:i}){return(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`tr`,{className:`border-b border-line align-top last:border-0 hover:bg-surface-2/40`,children:[(0,P.jsx)(`td`,{className:`py-3 pl-4`,children:(0,P.jsx)(m,{"aria-label":t?`Collapse details`:`Expand details`,"aria-expanded":t,onClick:r,children:(0,P.jsx)(c,{className:f(`size-3.5 transition-transform`,t&&`rotate-90`)})})}),(0,P.jsx)(`td`,{className:`px-3 py-3 font-mono text-xs text-muted`,children:e.job.name??`default`}),(0,P.jsx)(`td`,{className:`px-3 py-3`,children:(0,P.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,P.jsx)(n,{to:`/job?id=${encodeURIComponent(e.job.id)}`,className:`max-w-[14rem] truncate font-mono text-xs text-accent hover:underline`,title:e.job.id,children:e.job.id}),(0,P.jsx)(T,{value:e.job.id})]})}),(0,P.jsx)(`td`,{className:`px-3 py-3`,children:(0,P.jsx)(`span`,{className:`inline-block rounded-md bg-red-500/10 px-2 py-0.5 text-xs text-danger`,children:e.reason})}),(0,P.jsx)(`td`,{className:`px-3 py-3`,children:(0,P.jsx)(`span`,{className:`block max-w-md truncate text-xs text-danger/80`,title:e.error??``,children:e.error||`—`})}),(0,P.jsx)(`td`,{className:`px-3 py-3 text-right tnum text-muted`,children:e.job.attempts??i.length}),(0,P.jsx)(`td`,{className:`px-3 py-3 text-right text-faint`,title:S(e.enteredAt),children:C(e.enteredAt)}),(0,P.jsx)(`td`,{className:`px-4 py-3`,children:(0,P.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,P.jsx)(n,{to:`/job?id=${encodeURIComponent(e.job.id)}`,"aria-label":`Inspect job ${e.job.id}`,className:`inline-flex size-8 items-center justify-center rounded-lg text-muted transition-colors hover:bg-surface-2 hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,children:(0,P.jsx)(u,{className:`size-3.5`})}),(0,P.jsx)(m,{"aria-label":`Retry job unavailable`,disabled:!0,title:A,children:(0,P.jsx)(o,{className:`size-3.5`})})]})})]}),t&&(0,P.jsxs)(`tr`,{className:`border-b border-line bg-surface-2/30 last:border-0`,children:[(0,P.jsx)(`td`,{}),(0,P.jsxs)(`td`,{colSpan:7,className:`px-3 pb-4 pt-1`,children:[e.error&&(0,P.jsxs)(`div`,{className:`mb-3`,children:[(0,P.jsx)(`div`,{className:`mb-1 text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Error`}),(0,P.jsx)(`pre`,{className:`max-h-40 overflow-auto whitespace-pre-wrap rounded-lg bg-surface p-3 font-mono text-xs text-danger/90`,children:e.error})]}),(0,P.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 text-[11px] font-medium uppercase tracking-wider text-faint`,children:[`Failure history`,typeof e.retryCount==`number`&&e.retryCount>0&&(0,P.jsxs)(`span`,{className:`rounded-full bg-surface px-2 py-0.5 text-[10px] normal-case text-muted`,children:[`retried `,e.retryCount,`×`]})]}),i.length===0?(0,P.jsx)(`p`,{className:`text-xs text-faint`,children:`No per-attempt history recorded.`}):(0,P.jsx)(`ol`,{className:`space-y-1.5`,children:i.map(e=>(0,P.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-3 gap-y-0.5 rounded-lg border border-line bg-surface px-3 py-2 text-xs`,children:[(0,P.jsxs)(`span`,{className:`font-medium text-fg`,children:[`Attempt `,e.attempt]}),(0,P.jsx)(`span`,{className:`text-faint`,title:S(e.failedAt),children:C(e.failedAt)}),e.duration!=null&&(0,P.jsx)(`span`,{className:`tnum text-muted`,children:x(e.duration)}),e.reason&&(0,P.jsx)(`span`,{className:`rounded bg-red-500/10 px-1.5 text-danger`,children:e.reason}),e.error&&(0,P.jsx)(`span`,{className:`w-full truncate text-danger/70`,children:e.error})]},`${e.attempt}-${e.failedAt}`))})]})]})]})}var R=25,z={},B=[],V=e=>`${e.job.id}-${e.enteredAt}`;function H(){let[e,t]=(0,N.useState)(``),[n,r]=(0,N.useState)(0),[s,c]=(0,N.useState)(`all`),[u,f]=(0,N.useState)(``),[m,x]=(0,N.useState)(new Set),{data:S,error:C,loading:w,refetch:T}=p(M,[],{intervalMs:3e4});(0,N.useEffect)(()=>{if(e&&S&&!S.queues.some(t=>t.name===e)){t(``),r(0),c(`all`),f(``);return}e||!S?.queues?.length||t((S.queues.find(e=>e.dlq>0)??S.queues[0]).name)},[S,e]);let{data:E,error:D,loading:H,refetch:U}=p((0,N.useCallback)(async()=>{if(!e)return{queue:e,page:n,entries:[],total:0,stats:null,statsError:null};let[t,r]=await Promise.all([i.dlq(e,R,n*R),i.dlqStats(e).then(e=>({stats:e.stats,error:null})).catch(e=>({stats:null,error:e.message||`Unknown error`}))]);return{queue:e,page:n,entries:t.entries??[],total:t.total??0,stats:r.stats,statsError:r.error}},[e,n]),[e,n]),W=E?.queue===e&&E.page===n?E:null;(0,N.useEffect)(()=>{if(!W)return;let e=Math.max(0,Math.ceil((W.total??0)/R)-1);n>e&&r(e)},[W,n]),(0,N.useEffect)(()=>{x(new Set)},[e,n]);let G=W?.stats?.byReason??z,K=(0,N.useMemo)(()=>Object.keys(G).filter(e=>G[e]>0),[G]),q=(0,N.useMemo)(()=>[...K].sort((e,t)=>(G[t]??0)-(G[e]??0))[0],[K,G]);(0,N.useEffect)(()=>{s!==`all`&&W&&!K.includes(s)&&c(`all`)},[W,s,K]);let J=W?.entries??B,Y=(0,N.useMemo)(()=>{let e=J;s!==`all`&&(e=e.filter(e=>e.reason===s));let t=u.trim().toLowerCase();return t&&(e=e.filter(e=>e.job.id.toLowerCase().includes(t))),[...e].sort((e,t)=>t.enteredAt-e.enteredAt)},[J,s,u]),X=s!==`all`||u.trim()!==``,Z=(W?.total??0)>R,Q=e=>x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,P.jsxs)(`div`,{children:[(0,P.jsx)(b,{title:`DLQ Control`,description:`Inspect and triage one queue's dead-lettered jobs.`,live:!!e&&!!W&&!W.statsError&&!D&&!C,actions:(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(h,{size:`sm`,disabled:!e||!Y.length,onClick:()=>{if(Y.length===0){a.info(`Nothing to export`);return}j(`dlq-${e}`,Y.map(e=>({jobId:e.job.id,reason:e.reason,error:e.error??``,attempts:e.job.attempts??e.attempts?.length??``,enteredAt:new Date(e.enteredAt).toISOString()})),[`jobId`,`reason`,`error`,`attempts`,`enteredAt`])},children:[(0,P.jsx)(l,{className:`size-3.5`}),` Export`]}),(0,P.jsxs)(h,{size:`sm`,disabled:!0,title:A,children:[(0,P.jsx)(o,{className:`size-3.5`}),` Retry all`]}),(0,P.jsx)(h,{variant:`danger`,size:`sm`,disabled:!0,title:k,children:`Purge`})]})}),D&&W&&(0,P.jsx)(g,{message:`DLQ refresh failed — showing the last successful page.`,onRetry:U}),C&&(0,P.jsx)(g,{onRetry:T,message:`Could not discover queues — ${C.message}. Retry before selecting a queue.`}),W?.statsError&&(0,P.jsx)(g,{message:`DLQ statistics are unavailable — ${W.statsError}. The entry list may still be current.`,onRetry:U}),(0,P.jsx)(F,{queue:e,data:W,reasons:K,topReason:q}),(0,P.jsx)(I,{queue:e,queues:S?.queues??[],reason:s,reasons:K,byReason:G,search:u,pageScoped:Z,onQueue:e=>{t(e),r(0),c(`all`),f(``)},onReason:c,onSearch:f}),(0,P.jsx)(`p`,{className:`mb-4 text-xs text-warning`,children:A}),D&&!W?(0,P.jsx)(_,{error:D,onRetry:U}):w&&!S&&!e&&!C?(0,P.jsx)(v,{label:`Discovering queues…`}):H&&!W&&!D?(0,P.jsx)(v,{label:`Loading DLQ…`}):C&&!e?(0,P.jsx)(y,{icon:(0,P.jsx)(d,{}),title:`Could not discover queues`,hint:`${C.message}. Retry the queue discovery request above.`}):e?Y.length===0?(0,P.jsx)(y,{icon:(0,P.jsx)(d,{}),title:X?`No matches`:`Dead letter queue is empty`,hint:X?Z?`No entries on this page match your filter — filters are page-scoped. Try another page or clear them.`:`No entries match your filter. Clear it to see all entries.`:`Failed jobs that exhaust their retries land here.`}):(0,P.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,P.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,P.jsx)(`thead`,{children:(0,P.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,P.jsx)(`th`,{className:`w-8 py-3 pl-4`}),(0,P.jsx)(`th`,{className:`px-3 py-3 font-medium`,children:`Name`}),(0,P.jsx)(`th`,{className:`px-3 py-3 font-medium`,children:`Job ID`}),(0,P.jsx)(`th`,{className:`px-3 py-3 font-medium`,children:`Reason`}),(0,P.jsx)(`th`,{className:`px-3 py-3 font-medium`,children:`Error`}),(0,P.jsx)(`th`,{className:`px-3 py-3 text-right font-medium`,children:`Attempts`}),(0,P.jsx)(`th`,{className:`px-3 py-3 text-right font-medium`,children:`Entered`}),(0,P.jsx)(`th`,{className:`w-20 px-4 py-3`})]})}),(0,P.jsx)(`tbody`,{children:Y.map(e=>{let t=V(e);return(0,P.jsx)(L,{entry:e,isOpen:m.has(t),onToggle:()=>Q(t),attempts:e.attempts??[]},t)})})]})}):(0,P.jsx)(y,{icon:(0,P.jsx)(d,{}),title:S?.queues.length===0?`No queues available`:`Select a queue`,hint:`A queue must be selected before its dead letter entries can be inspected.`}),W&&(0,P.jsx)(O,{page:n,pageSize:R,total:W.total,onPageChange:r,label:`entries`})]})}export{H as DlqControl};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{f as t,g as n,r,t as i}from"./react-vendor-DfC0iyIS.js";import{t as a}from"./bq-CSX8DSME.js";import{t as o}from"./toastStore-DnqA_aL-.js";import{C as s,d as c,u as l}from"./icons-C1HVBnFn.js";import{r as u}from"./StatusBadge-cYUkK-4P.js";import{n as d}from"./usePolledData-Dp_ynL9f.js";import{n as f,t as p}from"./Button-BCjgbAhY.js";import{t as m}from"./Card-DptfvL2O.js";import{i as h,n as ee,r as g,t as _}from"./feedback-Dxfj-Fy1.js";import{t as v}from"./PageHeader-DD4vnVog.js";import{l as y,s as b}from"./format-Cg7VCIZW.js";import{a as x}from"./form-Dy-an7ew.js";import{t as S}from"./Pagination-Cj7GzYNX.js";import{r as C,t as w}from"./flowMutationSafety-YKTHxqKv.js";import{t as te}from"./exportFile-C7xhE8Yh.js";import{t as T}from"./QueueControl-g-9kwrpt.js";var E=e(n(),1),D=i();function O({total:e,discoveryError:t,healthy:n,statsError:r,queue:i,topReason:a,pendingRetry:o,reasonCount:s}){return(0,D.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,D.jsxs)(m,{children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Total in DLQ`}),(0,D.jsx)(`span`,{className:u(`rounded-full px-2 py-0.5 text-[11px] font-medium`,t?`bg-amber-500/10 text-warning`:e==null?`bg-surface-2 text-muted`:n?`bg-emerald-500/10 text-success`:`bg-red-500/10 text-danger`),children:t?`Unavailable`:e==null?`Loading`:n?`Healthy`:`Attention`})]}),(0,D.jsx)(`div`,{className:u(`mt-2 text-3xl font-bold tnum`,e==null||t?`text-muted`:n?`text-success`:`text-danger`),children:e==null?`—`:b(e)})]}),(0,D.jsxs)(m,{children:[(0,D.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Top Reason`}),(0,D.jsx)(`div`,{className:`mt-2 text-lg font-semibold text-fg`,children:t||r?`Unavailable`:i?a??`No failures`:`Select a queue`})]}),(0,D.jsxs)(m,{children:[(0,D.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Pending Retry`}),(0,D.jsx)(`div`,{className:`mt-2 text-3xl font-bold tnum text-fg`,children:o==null?`—`:b(o)}),(0,D.jsx)(`div`,{className:`mt-1 text-xs text-faint`,children:i?`in this queue`:`awaiting retry`})]}),(0,D.jsxs)(m,{children:[(0,D.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Failure Types`}),(0,D.jsx)(`div`,{className:`mt-2 text-3xl font-bold tnum text-fg`,children:s==null?`—`:b(s)}),(0,D.jsx)(`div`,{className:`mt-1 text-xs text-faint`,children:`distinct reasons`})]})]})}function k({queues:e,queue:t,onSelect:n}){return e.length===0?null:(0,D.jsxs)(m,{className:`mb-6`,children:[(0,D.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,D.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`DLQ by queue`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsxs)(p,{size:`sm`,disabled:!0,title:w,children:[(0,D.jsx)(s,{className:`size-3.5`}),` Retry all (`,e.length,` queues)`]}),(0,D.jsxs)(p,{variant:`danger`,size:`sm`,disabled:!0,title:C,children:[`Purge all (`,e.length,` queues)`]})]})]}),(0,D.jsx)(`div`,{className:`grid grid-cols-2 gap-3 md:grid-cols-4 xl:grid-cols-5`,children:e.map(e=>(0,D.jsxs)(`button`,{type:`button`,onClick:()=>n(e.name),className:u(`rounded-lg border p-3 text-left transition-colors`,t===e.name?`border-accent/50 bg-surface-2`:`border-line hover:border-line-strong`),children:[(0,D.jsx)(`div`,{className:`truncate font-mono text-xs text-muted`,children:e.name}),(0,D.jsx)(`div`,{className:`mt-1 text-xl font-bold tnum text-danger`,children:e.dlq})]},e.name))})]})}function A({queue:e,queues:t,reason:n,reasons:r,sort:i,search:a,pageScoped:o,onQueue:l,onReason:u,onSort:d,onSearch:f,onExport:m}){return(0,D.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-3`,children:[(0,D.jsx)(`div`,{className:`w-48`,children:(0,D.jsxs)(x,{value:e,"aria-label":`Queue`,name:`dlq-queue`,autoComplete:`off`,onChange:e=>l(e.target.value),children:[(0,D.jsx)(`option`,{value:``,children:`Select a queue…`}),t.map(e=>(0,D.jsxs)(`option`,{value:e.name,children:[e.name,e.dlq?` (${e.dlq})`:``]},e.name))]})}),(0,D.jsx)(`div`,{className:`w-40`,children:(0,D.jsxs)(x,{value:n,onChange:e=>u(e.target.value),"aria-label":`Filter by reason`,name:`dlq-reason-filter`,autoComplete:`off`,children:[(0,D.jsx)(`option`,{value:`all`,children:`All Reasons`}),r.map(e=>(0,D.jsx)(`option`,{value:e,children:e},e))]})}),(0,D.jsx)(`div`,{className:`w-36`,children:(0,D.jsxs)(x,{value:i,onChange:e=>d(e.target.value),"aria-label":o?`Sort this page`:`Sort`,name:`dlq-sort`,autoComplete:`off`,children:[(0,D.jsxs)(`option`,{value:`newest`,children:[`Newest First`,o?` (this page)`:``]}),(0,D.jsxs)(`option`,{value:`oldest`,children:[`Oldest First`,o?` (this page)`:``]})]})}),(0,D.jsx)(`input`,{value:a,onChange:e=>f(e.target.value),placeholder:`Filter this page by job ID…`,"aria-label":`Filter this page by job ID`,name:`dlq-job-filter`,autoComplete:`off`,className:`h-9 min-w-40 flex-1 rounded-lg border border-line bg-surface px-3 text-sm text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`}),(0,D.jsxs)(p,{size:`sm`,disabled:!0,title:w,children:[(0,D.jsx)(s,{className:`size-3.5`}),` Retry All`]}),(0,D.jsx)(p,{variant:`danger`,size:`sm`,disabled:!0,title:C,children:`Purge All`}),(0,D.jsxs)(p,{size:`sm`,title:`Exports the visible rows in their displayed order; other pages are not included.`,disabled:!e,onClick:m,children:[(0,D.jsx)(c,{className:`size-3.5`}),` Export page CSV`]})]})}function j({entries:e,expanded:t,onToggle:n}){return(0,D.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,D.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,D.jsx)(`thead`,{children:(0,D.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,D.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Job ID`}),(0,D.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Name`}),(0,D.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Reason`}),(0,D.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Error`}),(0,D.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Entered`}),(0,D.jsx)(`th`,{className:`w-16 px-5 py-3`})]})}),(0,D.jsx)(`tbody`,{children:e.map(e=>{let i=`${e.job.id}-${e.enteredAt}`;return(0,D.jsxs)(`tr`,{className:`border-b border-line last:border-0 align-top hover:bg-surface-2/40`,children:[(0,D.jsx)(`td`,{className:`px-5 py-3`,children:(0,D.jsx)(r,{to:`/job?id=${encodeURIComponent(e.job.id)}`,className:`font-mono text-xs text-accent hover:underline`,children:e.job.id})}),(0,D.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.job.name??`default`}),(0,D.jsx)(`td`,{className:`px-5 py-3`,children:(0,D.jsx)(`span`,{className:`rounded-md bg-red-500/10 px-2 py-0.5 text-xs text-danger`,children:e.reason})}),(0,D.jsx)(`td`,{className:`max-w-md px-5 py-3 text-xs text-danger/80`,children:e.error?(0,D.jsx)(`button`,{type:`button`,title:e.error,"aria-expanded":t.has(i),onClick:()=>n(i),className:u(`block w-full break-words text-left`,!t.has(i)&&`line-clamp-2`),children:e.error}):`—`}),(0,D.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:y(e.enteredAt)}),(0,D.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,D.jsx)(f,{"aria-label":`Retry unavailable`,disabled:!0,title:w,children:(0,D.jsx)(s,{className:`size-3.5`})})})]},i)})})]})})}var M=25,N=[];function P(){let[e,n]=t(),[r,i]=(0,E.useState)(``),[s,c]=(0,E.useState)(`all`),[u,f]=(0,E.useState)(`newest`),[p,m]=(0,E.useState)(``),[y,b]=(0,E.useState)(0),[x,C]=(0,E.useState)(new Set),{data:P,error:F,loading:ne,refetch:I}=d(T,[],{intervalMs:1e4}),L=P?.queues??N,R=P?L.reduce((e,t)=>e+t.dlq,0):null,{data:z,error:B,loading:V,refetch:H}=d((0,E.useCallback)(async()=>{if(!r)return{queue:r,page:y,entries:[],entriesTotal:0,stats:null,statsError:null};let[e,t]=await Promise.all([a.dlq(r,M,y*M),a.dlqStats(r).then(e=>({stats:e.stats,error:null})).catch(e=>({stats:null,error:e.message||`Unknown error`}))]);return{queue:r,page:y,entries:e.entries??[],entriesTotal:e.total??0,stats:t.stats,statsError:t.error}},[r,y]),[r,y]),U=z?.queue===r&&z.page===y?z:null;(0,E.useEffect)(()=>{if(!U)return;let e=U.entriesTotal??0;y>0&&y*M>=e&&b(Math.max(0,Math.ceil(e/M)-1))},[U,y]);let W=()=>{let e=Q.map(e=>({jobId:e.job.id,reason:e.reason,error:e.error??``,enteredAt:new Date(e.enteredAt).toISOString(),attempts:e.attempts?.length??0}));if(e.length===0){o.info(`Nothing to export on this page`);return}te(`dlq-${r}-page-${y+1}`,e,[`jobId`,`reason`,`error`,`enteredAt`,`attempts`])},G=e=>{X.current=!0,i(e),b(0),c(`all`),n(e?{queue:e}:{},{replace:!0})};(0,E.useEffect)(()=>{s===`all`||!U||(U.stats?.byReason?.[s]??0)>0||c(`all`)},[U,s]);let K=U?.stats?.byReason??{},q=Object.keys(K).filter(e=>K[e]>0),J=[...q].sort((e,t)=>(K[t]??0)-(K[e]??0))[0],Y=(0,E.useMemo)(()=>L.filter(e=>e.dlq>0).sort((e,t)=>t.dlq-e.dlq),[L]),X=(0,E.useRef)(!1),Z=e.get(`queue`);(0,E.useEffect)(()=>{if(!(X.current||r)){if(Z){if(L.some(e=>e.name===Z)){X.current=!0,i(Z),b(0),c(`all`);return}if(L.length===0)return}Y.length!==0&&(X.current=!0,i(Y[0].name),b(0),c(`all`))}},[r,L,Y,Z]);let Q=(0,E.useMemo)(()=>{let e=U?.entries??[];s!==`all`&&(e=e.filter(e=>e.reason===s));let t=p.trim().toLowerCase();return t&&(e=e.filter(e=>e.job.id.toLowerCase().includes(t))),[...e].sort((e,t)=>u===`newest`?t.enteredAt-e.enteredAt:e.enteredAt-t.enteredAt)},[U,s,p,u]),re=R===0&&!F,$=s!==`all`||p.trim()!==``,ie=(U?.entriesTotal??0)>M;return(0,D.jsxs)(`div`,{children:[(0,D.jsx)(v,{title:`Dead Letter Queue`,description:`Jobs that failed after exhausting all retries. Inspect and export entries without mutating flow topology.`,live:!!r&&!!U&&!U.statsError&&!B&&!F}),B&&U&&(0,D.jsx)(h,{message:`DLQ refresh failed — showing the last successful page.`,onRetry:H}),F&&(0,D.jsx)(h,{onRetry:I,message:`Could not discover queue DLQ totals — ${F.message}. Health status is unavailable.`}),U?.statsError&&(0,D.jsx)(h,{message:`DLQ statistics are unavailable — ${U.statsError}. The entry list may still be current.`,onRetry:H}),(0,D.jsx)(O,{total:R,discoveryError:!!F,healthy:re,statsError:!!U?.statsError,queue:r,topReason:J,pendingRetry:U?.stats?.pendingRetry,reasonCount:U?.stats?q.length:void 0}),(0,D.jsx)(k,{queues:Y,queue:r,onSelect:G}),(0,D.jsx)(A,{queue:r,queues:L,reason:s,reasons:q,sort:u,search:p,pageScoped:ie,onQueue:G,onReason:c,onSort:f,onSearch:m,onExport:W}),(0,D.jsx)(`p`,{className:`mb-4 text-xs text-warning`,children:w}),B&&!U?(0,D.jsx)(ee,{error:B,onRetry:H}):ne&&!P&&!r&&!F?(0,D.jsx)(g,{label:`Discovering queues…`}):V&&!U&&!B?(0,D.jsx)(g,{label:`Loading DLQ…`}):F&&!r?(0,D.jsx)(_,{icon:(0,D.jsx)(l,{}),title:`Could not discover queues`,hint:`${F.message}. Retry the queue discovery request above.`}):r?Q.length===0?(0,D.jsx)(_,{icon:(0,D.jsx)(l,{}),title:$?`No matches on this page`:`No dead letter entries`,hint:$?`No entries on this page match your filter — the filter is page-scoped. Use the pager below to check other pages.`:`This queue has no dead letter entries.`}):(0,D.jsx)(j,{entries:Q,expanded:x,onToggle:e=>C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}):(0,D.jsx)(_,{icon:(0,D.jsx)(l,{}),title:`Select a queue`,hint:`Choose a queue from the dropdown to view its dead letter queue entries.`}),r&&U&&(0,D.jsx)(S,{page:y,pageSize:M,total:U.entriesTotal,onPageChange:b,label:`entries`})]})}export{P as DlqPro};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{g as t,t as n}from"./react-vendor-DfC0iyIS.js";import{o as r,t as i}from"./connectionStore-DdLzJyut.js";import{n as a}from"./usePolledData-Dp_ynL9f.js";import{t as o}from"./Button-BCjgbAhY.js";import{n as s,t as c}from"./Card-DptfvL2O.js";import{t as l}from"./PageHeader-DD4vnVog.js";import{n as u}from"./controlConnectionEpoch-D4HtriLM.js";var d=e(t(),1),f=7500;function p(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Malformed ${t} response`);return e}async function m(e){try{let t=p(await e.json(),`error`);if(typeof t.error==`string`&&t.error)return Error(t.error)}catch{}return Error(`HTTP ${e.status}`)}async function h(e,t,n,r,i,a=[]){let o=AbortSignal.timeout(f),s=r?AbortSignal.any([r,o]):o,c=new Headers(i?.headers);n&&c.set(`Authorization`,`Bearer ${n}`);let l=await fetch(`${e}${t}`,{...i,headers:c,signal:s});if(!l.ok&&!a.includes(l.status))throw await m(l);return{response:l,body:p(await l.json(),t)}}async function g(e,t){try{let{response:n,body:r}=await h(e.baseUrl,`/health`,e.token,t,void 0,[503]);if(typeof r.ok!=`boolean`)throw Error(`Malformed Bunqueue health response`);return{reachable:!0,healthy:r.ok,statusCode:n.status,version:typeof r.version==`string`?r.version:void 0}}catch(e){return{reachable:!1,healthy:!1,error:e.message}}}function _(e){return[`running`,`stopped`,`starting`,`stopping`].includes(String(e.status))&&e.config!==null&&typeof e.config==`object`&&!Array.isArray(e.config)}async function v(e,t){try{let{response:n,body:r}=await h(e.agentBaseUrl,`/control/status`,e.agentToken,t);if(!_(r))throw Error(`Malformed control agent response`);return{reachable:!0,healthy:r.healthy===!0,statusCode:n.status,version:typeof r.version==`string`?r.version:void 0,status:r}}catch(e){return{reachable:!1,healthy:!1,error:e.message}}}async function y(e,t){let n=i(e);if(!n)throw Error(`Unknown Bunqueue connection profile: ${e}`);let[r,a]=await Promise.all([g(n,t),v(n,t)]);return{target:n,server:r,agent:a}}function b(e,t){return Promise.all(e.map(e=>y(e,t)))}async function x(e,t,n){let r=i(e);if(!r)throw Error(`Unknown Bunqueue connection profile: ${e}`);let{body:a}=await h(r.agentBaseUrl,`/control/${t}`,r.agentToken,n,{method:`POST`});if(!_(a))throw Error(`Malformed control agent response`);return a}function S(e){let t=e.agent.status;return t?.storageMode!==`postgres`||!t.postgresTarget?null:`${t.postgresTarget}\u0000${t.postgresNamespace??`default`}`}var C=n();function w({ok:e,reachable:t}){return(0,C.jsx)(`span`,{className:`inline-block size-2 rounded-full ${t?e?`bg-emerald-400`:`bg-amber-400`:`bg-red-400`}`})}function T({snapshot:e,active:t,busy:n,actionError:r,onActivate:i,onAction:a}){let{target:l,server:u,agent:d}=e,f=d.status,p=f?.managementMode===`external`,m=p?f?.reachable===!0:f?.status===`running`,h=n!==void 0||f?.status===`starting`||f?.status===`stopping`,g=f?.storageMode===`postgres`?`PostgreSQL · ${f.postgresNamespace??`default`}`:f?.storageMode??`unknown`;return(0,C.jsxs)(c,{className:t?`border-accent/60`:void 0,children:[(0,C.jsx)(s,{title:l.name,action:t?(0,C.jsx)(`span`,{className:`rounded-full bg-accent/15 px-2 py-1 text-[10px] font-semibold uppercase text-accent`,children:`active`}):(0,C.jsx)(o,{size:`sm`,onClick:i,children:`Use node`})}),(0,C.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-3 gap-y-2 text-xs`,children:[(0,C.jsx)(`dt`,{className:`text-faint`,children:`Server`}),(0,C.jsxs)(`dd`,{className:`flex min-w-0 items-center gap-2 text-muted`,children:[(0,C.jsx)(w,{ok:u.healthy,reachable:u.reachable}),(0,C.jsx)(`span`,{className:`truncate`,title:l.baseUrl,children:u.reachable?`${u.healthy?`healthy`:`degraded`}${u.version?` · v${u.version}`:``}`:`offline · ${u.error??`unreachable`}`})]}),(0,C.jsx)(`dt`,{className:`text-faint`,children:`Agent`}),(0,C.jsxs)(`dd`,{className:`flex min-w-0 items-center gap-2 text-muted`,children:[(0,C.jsx)(w,{ok:d.healthy,reachable:d.reachable}),(0,C.jsx)(`span`,{className:`truncate`,title:l.agentBaseUrl,children:d.reachable?`${f?.status??`connected`}${p?` · external`:``}`:`offline · ${d.error??`unreachable`}`})]}),(0,C.jsx)(`dt`,{className:`text-faint`,children:`Storage`}),(0,C.jsx)(`dd`,{className:`truncate font-mono text-muted`,title:f?.postgresTarget,children:g}),f?.storageMode===`postgres`&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`dt`,{className:`text-faint`,children:`Cluster`}),(0,C.jsx)(`dd`,{className:`truncate font-mono text-muted`,children:f.postgresTarget??`configured PostgreSQL`})]})]}),r&&(0,C.jsx)(`p`,{role:`status`,className:`mt-3 text-xs text-danger`,children:r}),!p&&(0,C.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-2 border-t border-line pt-4`,children:[(0,C.jsx)(o,{size:`sm`,variant:`success`,disabled:!d.reachable||m||h,onClick:()=>a(`start`),children:`Start`}),(0,C.jsx)(o,{size:`sm`,variant:`warning`,disabled:!d.reachable||!m||h,onClick:()=>a(`stop`),children:`Stop`}),(0,C.jsx)(o,{size:`sm`,disabled:!d.reachable||h,onClick:()=>a(`restart`),children:n===`restart`?`Restarting…`:`Restart`})]})]})}function E(e){let t=new Map;for(let n of e){let e=S(n);e&&t.set(e,[...t.get(e)??[],n])}return[...t.entries()].map(([e,t])=>{let n=t[0]?.agent.status;return{key:e,target:n?.postgresTarget??`configured PostgreSQL`,namespace:n?.postgresNamespace??`default`,members:t}})}function D(){let e=r(e=>e.profiles),t=r(e=>e.activeProfileId),n=r(e=>e.activateProfile),i=u(),f=e.map(e=>e.id),p=`${i}:${JSON.stringify(e)}`,{data:m,error:h,loading:g,refetch:_}=a(e=>b(f,e),[p],{intervalMs:1e4}),[v,y]=(0,d.useState)({}),[S,w]=(0,d.useState)({}),D=(0,d.useRef)(0),O=(0,d.useMemo)(()=>E(m??[]),[m]);(0,d.useEffect)(()=>{D.current+=1,y({}),w({})},[p]);let k=async(e,t)=>{let n=e.target.id;if(v[n]||t!==`start`&&!window.confirm(`${t===`stop`?`Stop`:`Restart`} ${e.target.name}? In-flight jobs on this broker may be interrupted.`))return;let r=D.current;y(e=>({...e,[n]:t})),w(e=>({...e,[n]:``}));try{await x(n,t),r===D.current&&await _()}catch(e){r===D.current&&w(t=>({...t,[n]:e.message}))}finally{r===D.current&&y(e=>{let t={...e};return delete t[n],t})}};return(0,C.jsxs)(`div`,{children:[(0,C.jsx)(l,{title:`Fleet`,description:`Operate every Bunqueue broker and verify shared PostgreSQL topology.`,actions:(0,C.jsx)(o,{onClick:()=>void _(),children:`Refresh all`})}),(0,C.jsxs)(`div`,{className:`mb-6 grid grid-cols-1 gap-4 md:grid-cols-3`,children:[(0,C.jsxs)(c,{children:[(0,C.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-faint`,children:`Configured nodes`}),(0,C.jsx)(`div`,{className:`mt-1 text-2xl font-bold text-fg`,children:e.length})]}),(0,C.jsxs)(c,{children:[(0,C.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-faint`,children:`Healthy APIs`}),(0,C.jsxs)(`div`,{className:`mt-1 text-2xl font-bold text-fg`,children:[(m??[]).filter(e=>e.server.healthy).length,`/`,e.length]})]}),(0,C.jsxs)(c,{children:[(0,C.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-faint`,children:`PostgreSQL clusters`}),(0,C.jsx)(`div`,{className:`mt-1 text-2xl font-bold text-fg`,children:O.length})]})]}),h&&(0,C.jsxs)(`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:[`Fleet refresh failed: `,h.message]}),O.length>0&&(0,C.jsxs)(c,{className:`mb-6`,children:[(0,C.jsx)(s,{title:`Shared PostgreSQL topology`}),(0,C.jsx)(`div`,{className:`flex flex-col gap-3`,children:O.map(e=>(0,C.jsxs)(`div`,{className:`rounded-lg border border-line bg-surface-2/40 px-4 py-3`,children:[(0,C.jsx)(`div`,{className:`font-mono text-sm text-fg`,children:e.target}),(0,C.jsxs)(`div`,{className:`mt-1 text-xs text-muted`,children:[`namespace `,(0,C.jsx)(`span`,{className:`font-mono text-fg`,children:e.namespace}),` ·`,` `,e.members.length,` broker`,e.members.length===1?``:`s`,`:`,` `,e.members.map(e=>e.target.name).join(`, `)]})]},e.key))})]}),g&&!m?(0,C.jsx)(c,{children:`Checking every Bunqueue node…`}):(0,C.jsx)(`div`,{className:`grid grid-cols-1 gap-4 xl:grid-cols-2`,children:(m??[]).map(e=>(0,C.jsx)(T,{snapshot:e,active:e.target.id===t,busy:v[e.target.id],actionError:S[e.target.id],onActivate:()=>n(e.target.id),onAction:t=>void k(e,t)},e.target.id))}),(0,C.jsx)(`p`,{className:`mt-5 text-xs leading-relaxed text-faint`,children:`PostgreSQL-backed queues, jobs, flows, crons, workers, limits, durable metrics and events are visible through every healthy broker in the same target and namespace. Lifecycle, process logs/configuration and in-memory webhooks are node-local; Workflow Engine storage uses each profile's agent data path.`})]})}export{D as Fleet};
@@ -1,2 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{f as t,g as n,r,t as i}from"./react-vendor-DfC0iyIS.js";import{a,o}from"./connectionStore-DdLzJyut.js";import{i as s}from"./upstreamPaths-DQeKSxGc.js";import{a as c,d as l,s as u,u as d}from"./bq-CSX8DSME.js";import{r as f}from"./StatusBadge-cYUkK-4P.js";import{t as p}from"./Card-DptfvL2O.js";import{i as m,n as h,r as g}from"./feedback-Dxfj-Fy1.js";import{t as _}from"./PageHeader-DD4vnVog.js";import{i as v}from"./index-CxzFSZj3.js";import{n as y,t as b}from"./controlConnectionEpoch-D4HtriLM.js";import{t as x}from"./useControlActionGuard-DImMgJtj.js";import{n as S,r as C}from"./flowOperationPolicy-B2Etcb3f.js";var w={nodeWidth:168,nodeHeight:60},ee=`flow-order-9a3f`,T={completed:`border-success/50 bg-success/10 text-success`,failed:`border-danger/50 bg-danger/10 text-danger`,active:`border-blue-400/60 bg-blue-400/10 text-blue-400`,delayed:`border-accent/50 bg-accent/10 text-accent`,waiting:`border-warning/50 bg-warning/10 text-warning`,prioritized:`border-warning/50 bg-warning/10 text-warning`,"waiting-children":`border-cyan-400/60 bg-cyan-400/10 text-cyan-400`},E=e=>e&&T[e]||`border-line bg-surface-2 text-muted`,D=e=>e.length>12?`${e.slice(0,6)}…${e.slice(-4)}`:e,O=class extends Error{constructor(e,t){super(e,t),this.name=`FlowSnapshotError`}};function k(e,t,n){if(!Array.isArray(e)||e.some(e=>typeof e!=`string`||s(e)!==null))throw new O(`Job ${n} returned an invalid ${t} list`);return e}function A(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw new O(`GET /jobs/${t} returned an invalid response`);let n=e;if(n.ok!==!0)throw new O(`GET /jobs/${t} returned an invalid success envelope`);let r=n.job;if(typeof r!=`object`||!r||Array.isArray(r))throw new O(`GET /jobs/${t} returned no job snapshot`);let i=r;if(i.id!==t)throw new O(`GET /jobs/${t} returned the wrong job id (${String(i.id)})`);if(typeof i.queue!=`string`||i.queue.length===0)throw new O(`Job ${t} returned an invalid queue`);if(typeof i.state!=`string`||i.state.length===0)throw new O(`Job ${t} returned an invalid state`);if(!Object.hasOwn(i,`parentId`)||i.parentId!==null&&(typeof i.parentId!=`string`||s(i.parentId)!==null))throw new O(`Job ${t} returned an invalid parentId`);return{...r,parentId:i.parentId,childrenIds:k(i.childrenIds,`childrenIds`,t),dependsOn:k(i.dependsOn,`dependsOn`,t)}}async function j(e,t,n){n?.throwIfAborted();let r=await l(e,t,n);return n?.throwIfAborted(),A(r,t)}function M(e){let t=s(e);return t?`Job ID: ${t}`:null}async function te(e,t={}){let n=M(e);if(n)throw new O(n);let r=t.target??d(),{signal:i}=t,a=e,o=new Set([e]),s=[];for(let e=0;;e++){i?.throwIfAborted();let t;try{t=await j(r,a,i)}catch(t){if(i?.throwIfAborted(),e===0)throw t;if(t instanceof c&&t.status===404){let e=s.at(-1);if(!e)throw t;return{id:e.id,job:e,hops:Math.max(0,s.length-1),path:s,missingParent:a}}throw new O(`Could not resolve the flow root because parent ${a} could not be loaded: ${t instanceof Error?t.message:String(t)}`,{cause:t})}s.push(t);let n=t.parentId;if(!n)return{id:a,job:t,hops:e,path:s};if(o.has(n))throw new O(`Flow parent cycle detected at job ${n}`);if(e>=100)throw new O(`Flow parent chain exceeds the Bunqueue 2.9.3 limit of 100 levels`);o.add(n),a=n}}function N(e,t){let n=new Set(e),r=new Map(e.map(e=>[e,[]]));for(let e of t)n.has(e.from)&&n.has(e.to)&&r.get(e.from)?.push(e.to);let i=new Map,a=[],o=e=>{i.set(e,1),a.push(e);for(let t of r.get(e)??[]){if(i.get(t)===1){let e=a.lastIndexOf(t);return[...a.slice(Math.max(0,e)),t]}if(i.get(t)!==2){let e=o(t);if(e)return e}}return a.pop(),i.set(e,2),null};for(let t of e)if(!i.has(t)){let e=o(t);if(e)return e}return null}var ne=[`failParentOnFailure`,`removeDependencyOnFailure`,`continueParentOnFailure`,`ignoreDependencyOnFailure`];function P(e){return ne.filter(t=>e[t]===!0)}function F(e,t){if(e?.parentId!==t)return null;let n=P(e);return n.length===1?n[0]===`continueParentOnFailure`?{scope:`parent`,policy:`continueParentOnFailure`}:n[0]===`removeDependencyOnFailure`?{scope:`child`,policy:`removeDependencyOnFailure`}:n[0]===`ignoreDependencyOnFailure`?{scope:`child`,policy:`ignoreDependencyOnFailure`}:null:null}async function re(e,t,n={}){let r=M(e);if(r)throw new O(r);let i=n.target??d(),{signal:a}=n,o=new Map,s=[],c=[],l=new Set,u=new Set,f=new Map,p=new Set,m=new Set,h=new Set(n.limitations??[]),g=[{id:e,depth:0}],_=new Set([e]),v=new Map;t&&v.set(e,A({ok:!0,job:t},e));let y=[...n.seedPath??[]].reverse(),b=!1;if(y.length>0&&y[0]?.id!==e)throw new O(`Resolved seed path does not start at the requested flow root`);for(let[e,t]of y.entries()){let n=A({ok:!0,job:t},t.id);if(v.set(n.id,n),e!==0){if(e>100||_.size>=500){b=!0;continue}_.has(n.id)||(_.add(n.id),g.push({id:n.id,depth:e}))}}let x=new Set,S=b;for(;g.length;){a?.throwIfAborted();let{id:t,depth:n}=g.shift();if(x.has(t))continue;x.add(t);let r=null;try{r=v.get(t)??await j(i,t,a)}catch(n){if(a?.throwIfAborted(),t===e)throw n;f.set(t,n instanceof Error?n.message:String(n))}if(o.set(t,r??{id:t,state:`unknown`}),!r)continue;if(n>=100){(r.childrenIds?.length??0)+(r.dependsOn?.length??0)>0&&(S=!0);continue}let d=e=>_.has(e)?!0:_.size>=500?(S=!0,!1):(_.add(e),g.push({id:e,depth:n+1}),!0),m=(e,t,n,r)=>{if(!d(r))return;let i=`${e}->${t}:${n}`;l.has(i)||(l.add(i),s.push({from:e,to:t,kind:n}))},h=r.childrenIds??[],y=r.dependsOn??[],b=new Set(h),C=new Set(y);b.size!==h.length&&p.add(`Job ${t} lists a child more than once`),C.size!==y.length&&p.add(`Job ${t} lists a dependency more than once`);for(let e of h)m(t,e,`child`,e);for(let e of y)if(d(e)){let n=`${e}->${t}`;u.has(n)||(u.add(n),c.push({from:e,to:t,kind:`depends`})),b.has(e)||m(e,t,`depends`,e)}}for(let[e,t]of o)!f.has(e)&&P(t).length>1&&p.add(`Job ${e} enables mutually exclusive failure policies`);for(let e of s){if(e.kind!==`child`||f.has(e.to))continue;let t=o.get(e.to);t&&t.parentId!==e.from&&p.add(`Child ${e.to} points to parent ${String(t.parentId??`none`)}, not ${e.from}`)}for(let[e,t]of o){if(f.has(e))continue;let n=t.childrenIds??[];if(n.some(e=>!o.has(e)||f.has(e)))continue;let r=n.map(t=>({childId:t,release:F(o.get(t),e)})).find(({release:e})=>e?.scope===`parent`);for(let i of n){if(t.dependsOn?.includes(i))continue;if(r?.release?.scope===`parent`){m.add(`Parent ${e} is missing dependency ${i}; ${r.release.policy} on child ${r.childId} may have released all parent dependencies, but the HTTP snapshot cannot prove whether the policy fired`);continue}let n=F(o.get(i),e);if(n?.scope===`child`){m.add(`Parent ${e} is missing dependency ${i}; ${n.policy} may have released it, but the HTTP snapshot cannot prove whether the policy fired`);continue}p.add(`Parent ${e} lists child ${i} without the matching dependency`)}}for(let[e,t]of o){if(f.has(e)||!t.parentId)continue;let n=o.get(t.parentId);!n||f.has(t.parentId)||n.childrenIds?.includes(e)||p.add(`Parent ${t.parentId} does not list child ${e}`)}let C=N([...o.keys()],c);return{jobs:o,edges:s,truncated:S,failed:f.size,failures:f,issues:[...p],policyNotes:[...m],cycle:C,limitations:[...h]}}var ie=`bq-dash-recent-flows`,ae=8;function oe(e){return`${ie}:${encodeURIComponent(e.trim()||`/api`)}`}function se(e,t){if(!t)return[];try{let t=JSON.parse(localStorage.getItem(oe(e))??`[]`);return Array.isArray(t)?t.filter(e=>typeof e?.root==`string`&&e.root.length>0&&e.root.length<=1024&&Number.isSafeInteger(e?.nodes)&&e.nodes>1&&e.nodes<=500&&Number.isFinite(e?.at)&&e.at>=0).slice(0,ae):[]}catch{return[]}}function ce(e,t,n,r){let i=[n,...t.filter(e=>e.root!==n.root)].slice(0,ae);if(!r)return i;try{localStorage.setItem(oe(e),JSON.stringify(i))}catch{}return i}var I=e(n(),1),le=new Set([`explore`,`create`,`operations`]);function ue(e,t=``){let n=e.get(`root`),r=R(n)?n:t,i=e.get(`mode`),a=le.has(i)?i:`explore`,o=e.get(`node`);return{root:r,mode:a,node:r&&R(o)?o:null}}function L(e){let t=new URLSearchParams;return e.root&&t.set(`root`,e.root),e.mode!==`explore`&&t.set(`mode`,e.mode),e.root&&e.node&&t.set(`node`,e.node),t}function de(e,t,n=``){return L({...ue(e,n),...t})}function R(e){return!!(e&&M(e)===null)}function fe(){let[e,n]=t(),r=v()?ee:``,i=e.toString(),s=(0,I.useMemo)(()=>ue(new URLSearchParams(i),r),[r,i]),c=s.root,l=o(e=>e.baseUrl),u=o(e=>e.token),f=a(),[p,m]=(0,I.useState)(c),[h,g]=(0,I.useState)(null),[_,y]=(0,I.useState)(!!c),[b,x]=(0,I.useState)(null),[S,C]=(0,I.useState)(()=>se(f,u.length===0)),w=(0,I.useRef)(0),T=(0,I.useRef)(null),E=(0,I.useRef)(!1),D=(0,I.useRef)(z()),k=h?.seed===c?h.graph:null,A=k?s.node&&k.jobs.has(s.node)?s.node:h?.defaultSelected??null:null,j=(0,I.useCallback)((e,t=!1)=>{n(t=>de(t,e,r),{replace:t})},[r,n]),N=(0,I.useCallback)(async e=>{let t=o.getState();if(t.baseUrl!==l||t.token!==u)return;T.current?.abort(),T.current=null;let n=++w.current,r=e.trim();if(g(null),x(null),!r)return y(!1);let i=M(r);if(i)return x(new O(i)),y(!1);let a=d(),s=z(),c=new AbortController;T.current=c;let f=()=>E.current&&n===w.current&&!c.signal.aborted&&s===z();y(!0);try{let e={target:a,signal:c.signal},t=await te(r,e),n=t.missingParent?[`Ancestor ${t.missingParent} is no longer available. The graph starts at the oldest surviving node.`]:[],i=await re(t.id,t.job,{...e,seedPath:t.path,limitations:n});if(!f())return;g({seed:r,graph:i,defaultSelected:t.id}),i.jobs.size>1&&C(e=>ce(a.baseUrl,e,{root:t.id,nodes:i.jobs.size,at:Date.now()},o.getState().token.length===0))}catch(e){f()&&x(e instanceof Error?e:Error(`Failed to load flow`))}finally{T.current===c&&(T.current=null),f()&&y(!1)}},[l,u]);return(0,I.useEffect)(()=>{E.current=!0,D.current=z();let e=o.subscribe(()=>{let e=z();e!==D.current&&(D.current=e,w.current+=1,T.current?.abort(),T.current=null,E.current&&(g(null),x(null),y(!1)))});return()=>{E.current=!1,e(),w.current+=1,T.current?.abort()}},[]),(0,I.useEffect)(()=>C(u?[]:se(f,!0)),[f,u]),(0,I.useEffect)(()=>{let e={...s};k&&(!e.node||!k.jobs.has(e.node))&&(e.node=h?.defaultSelected??null);let t=L(e).toString();t!==i&&n(t,{replace:!0})},[k,i,n,h?.defaultSelected,s]),(0,I.useEffect)(()=>{m(c),N(c)},[c,N]),{input:p,setInput:m,rootParam:c,mode:s.mode,setMode:e=>j({mode:e}),graph:k,selected:A,setSelected:e=>{k?.jobs.has(e)&&j({node:e})},loading:_,error:b,recent:S,load:N,submit:e=>{e.preventDefault();let t=p.trim();if(t){if(M(t))return void N(t);t===c?N(t):j({root:t,mode:`explore`,node:null})}},openRecent:e=>{if(m(e),M(e))return void N(e);let t=e===c;j({root:e,mode:`explore`,node:null}),t&&N(e)}}}function z(){let{token:e}=o.getState();return JSON.stringify([a(),e])}function pe(e){return e instanceof c&&e.status===0||[`TypeError`,`AbortError`,`TimeoutError`].includes(e.name)}var B=e=>({method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),me=new Set([`removeChildDependency`,`removeUnprocessedChildren`,`removeDeduplicationKey`,`retry`,`promote`,`remove`]),he=e=>e+5e3,V={create:(e,t)=>u(`/flows/create?target=${encodeURIComponent(a())}`,B({operation:e,...t})),getFlow:e=>{let t=new URLSearchParams({id:e.id,queueName:e.queueName,target:a()});return e.depth!==void 0&&t.set(`depth`,String(e.depth)),e.maxChildren!==void 0&&t.set(`maxChildren`,String(e.maxChildren)),u(`/flows/tree?${t}`)},inspect:(e,t)=>u(`/flows/jobs/${encodeURIComponent(e.id)}/${t}?${new URLSearchParams({queueName:e.queueName,target:a()})}`),getParentResult:e=>u(`/flows/results?target=${encodeURIComponent(a())}`,B({operation:`getParentResult`,parentId:e})),getParentResults:e=>u(`/flows/results?target=${encodeURIComponent(a())}`,B({operation:`getParentResults`,parentIds:e})),waitUntilFinished:(e,t)=>u(`/flows/jobs/${encodeURIComponent(e.id)}/waitUntilFinished?${new URLSearchParams({queueName:e.queueName,target:a(),ttl:String(t)})}`,void 0,he(t)),mutate:(e,t,n)=>(S(t),u(`/flows/jobs/${encodeURIComponent(e.id)}/${t}?${new URLSearchParams({queueName:e.queueName,target:a()})}`,me.has(t)?{method:`POST`}:B(n??{})))},H=i();function U({value:e}){return(0,H.jsx)(`pre`,{className:`max-h-80 overflow-auto whitespace-pre-wrap break-words rounded-md border border-line bg-bg p-3 font-mono text-xs text-muted`,children:JSON.stringify(e,null,2)})}function W(...e){return JSON.stringify(e)}function G(e,t=`shared`){let n=y(),r=`flow-exclusive:${t}`,i=x(r),a=(0,I.useMemo)(()=>({key:e,connectionEpoch:n}),[n,e]),o=(0,I.useRef)(a),s=(0,I.useRef)(void 0),c=(0,I.useRef)(void 0),l=(0,I.useRef)(void 0),u=(0,I.useRef)(0),d=(0,I.useRef)(!0),[f,p]=(0,I.useState)(),[m,h]=(0,I.useState)(),[g,_]=(0,I.useState)();return(0,I.useLayoutEffect)(()=>{o.current.connectionEpoch!==a.connectionEpoch&&(c.current=void 0),o.current=a,s.current=void 0,l.current=void 0},[a]),(0,I.useEffect)(()=>(d.current=!0,()=>{d.current=!1,s.current=void 0,c.current=void 0,l.current=void 0}),[]),{busy:f?.exclusive&&f.identity.connectionEpoch===a.connectionEpoch||f?.identity===a?f.label:``,error:g?.identity===a?g.message:``,result:m?.identity===a?m.value:void 0,reject:e=>{c.current||b()!==a.connectionEpoch||(l.current=void 0,s.current=void 0,p(void 0),h(void 0),_({identity:a,message:e}))},run:async(e,t,n={})=>{let f=n.exclusive===!0;if(c.current||s.current?.identity===a||b()!==a.connectionEpoch)return;let m=i.begin(r);if(!m)return;f||m.finish();let g={id:++u.current,identity:a};f?c.current=g:s.current=g,l.current=g,p({...g,exclusive:f,label:e}),h(void 0),_(void 0);try{let e=await t();d.current&&o.current===a&&b()===a.connectionEpoch&&l.current===g&&h({identity:a,value:e})}catch(e){d.current&&o.current===a&&b()===a.connectionEpoch&&l.current===g&&_({identity:a,message:ge(e)})}finally{f&&m.finish(),c.current===g&&(c.current=void 0),s.current===g&&(s.current=void 0),d.current&&p(e=>e?.id===g.id?void 0:e)}}}}function ge(e){return e instanceof Error?e.message:String(e)}var K={add:{flow:{name:`aggregate`,queueName:`reports`,data:{},children:[{name:`fetch`,queueName:`io`,data:{source:`orders`}}]},options:{queuesOptions:{io:{attempts:3,backoff:1e3}}}},addBulk:{flows:[{name:`report-a`,queueName:`reports`,data:{region:`eu`}},{name:`report-b`,queueName:`reports`,data:{region:`us`}}]},addChain:{steps:[{name:`extract`,queueName:`pipeline`,data:{}},{name:`transform`,queueName:`pipeline`,data:{}},{name:`load`,queueName:`pipeline`,data:{}}]},addBulkThen:{parallel:[{name:`part-a`,queueName:`parallel`,data:{}},{name:`part-b`,queueName:`parallel`,data:{}}],final:{name:`merge`,queueName:`final`,data:{}}},addTree:{root:{name:`root`,queueName:`tree`,data:{},children:[{name:`child`,queueName:`tree`,data:{}}]}}};function _e({repository:e=V,onOpen:t}){let[n,r]=(0,I.useState)(`add`),[i,a]=(0,I.useState)(()=>JSON.stringify(K.add,null,2)),o=G(W(n,i),`creator`),s=!!o.busy,c=e=>{r(e),a(JSON.stringify(K[e],null,2))},l=async t=>{t.preventDefault();let r;try{r=JSON.parse(i)}catch{return o.reject(`The definition must be valid JSON.`)}if(!r||typeof r!=`object`||Array.isArray(r))return o.reject(`The definition must be a JSON object.`);let a=n;await o.run(a,()=>e.create(a,r),{exclusive:!0})},u=ve(o.result);return(0,H.jsxs)(`div`,{className:`grid gap-5 xl:grid-cols-[minmax(0,1fr)_minmax(300px,0.7fr)]`,children:[(0,H.jsxs)(`form`,{onSubmit:l,className:`rounded-lg border border-line bg-surface p-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3`,children:[(0,H.jsxs)(`label`,{className:`text-xs text-faint`,children:[`FlowProducer method`,(0,H.jsx)(`select`,{"aria-label":`FlowProducer method`,value:n,onChange:e=>c(e.target.value),className:`mt-1 block h-9 rounded-lg border border-line bg-surface-2 px-3 text-sm text-fg`,children:Object.keys(K).map(e=>(0,H.jsx)(`option`,{children:e},e))})]}),(0,H.jsx)(`button`,{type:`submit`,disabled:s,className:`rounded-lg bg-accent px-4 py-2 text-sm font-medium text-accent-fg disabled:opacity-50`,children:s?`Creating…`:`Run ${n}`})]}),(0,H.jsxs)(`label`,{className:`mt-4 block text-xs text-faint`,children:[`Definition`,(0,H.jsx)(`textarea`,{"aria-label":`Flow definition JSON`,spellCheck:!1,value:i,onChange:e=>a(e.target.value),className:`mt-1 min-h-80 w-full resize-y rounded-lg border border-line bg-bg p-3 font-mono text-xs text-fg outline-none focus:ring-2 focus:ring-accent/50`})]})]}),(0,H.jsxs)(`section`,{className:`rounded-lg border border-line bg-surface p-4`,children:[(0,H.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:`Atomic commit result`}),(0,H.jsx)(`p`,{className:`mt-1 mb-4 text-xs text-faint`,children:`Validation is performed by Bunqueue before the graph is committed.`}),o.error&&(0,H.jsx)(`p`,{role:`alert`,className:`mb-3 text-sm text-danger`,children:o.error}),o.result===void 0?(0,H.jsx)(`p`,{className:`text-sm text-muted`,children:`No flow created in this session.`}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(U,{value:o.result}),u&&(0,H.jsx)(`button`,{type:`button`,onClick:()=>t(u),className:`mt-3 rounded-lg border border-line px-3 py-2 text-xs text-fg`,children:`Open created flow`})]})]})]})}function ve(e){let t=e,n=t?.result?.root?.id??t?.result?.roots?.[0]?.id??t?.result?.finalId??t?.result?.jobIds?.at(-1);return typeof n==`string`?n:null}function ye({recent:e,onOpen:t}){return(0,H.jsx)(p,{children:(0,H.jsxs)(`div`,{className:`py-16 text-center`,children:[(0,H.jsx)(`p`,{className:`text-sm text-muted`,children:`No flow loaded.`}),(0,H.jsx)(`p`,{className:`mt-1 text-xs text-faint`,children:`Enter a job ID, or choose “View flow” from Job Inspector.`}),e.length>0&&(0,H.jsxs)(`div`,{className:`mt-6`,children:[(0,H.jsx)(`p`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Recently viewed`}),(0,H.jsx)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:e.map(e=>(0,H.jsxs)(`button`,{type:`button`,title:e.root,onClick:()=>t(e.root),className:`min-h-10 rounded-lg border border-line bg-surface-2 px-3 py-1.5 font-mono text-xs text-muted hover:text-fg`,children:[(0,H.jsx)(`span`,{translate:`no`,children:D(e.root)}),(0,H.jsxs)(`span`,{className:`ml-2 text-faint`,children:[e.nodes,` nodes`]})]},e.root))})]})]})})}function q({target:e,onChange:t}){return(0,H.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,H.jsxs)(`label`,{className:`text-xs text-faint`,children:[`Job ID`,(0,H.jsx)(`input`,{"aria-label":`Flow job ID`,value:e.id,onChange:n=>t({...e,id:n.target.value}),className:`mt-1 h-9 w-full rounded-lg border border-line bg-surface-2 px-3 font-mono text-sm text-fg`})]}),(0,H.jsxs)(`label`,{className:`text-xs text-faint`,children:[`Queue name`,(0,H.jsx)(`input`,{"aria-label":`Flow queue name`,value:e.queueName,onChange:n=>t({...e,queueName:n.target.value}),className:`mt-1 h-9 w-full rounded-lg border border-line bg-surface-2 px-3 text-sm text-fg`})]})]})}var be=[`getChildrenValues`,`getDependencies`,`getDependenciesCount`,`getFailedChildrenValues`,`getIgnoredChildrenFailures`],xe=[{id:`removeChildDependency`,label:`Release dependency`,dangerous:!0},{id:`removeUnprocessedChildren`,label:`Remove unprocessed children`,dangerous:!0},{id:`retry`,label:`Retry job`},{id:`promote`,label:`Promote delayed job`},{id:`remove`,label:`Remove job`,dangerous:!0}];function Se({repository:e=V,initialTarget:t={id:``,queueName:``},target:n,onTargetChange:r,showTarget:i=!0}){let[a,o]=(0,I.useState)(t),s=n??a,c=r??o,l=G(W(s.id,s.queueName),`dependency-console`),u=l.busy,d=!!(s.id.trim()&&s.queueName.trim()),f=t=>{let n=Ce(s);l.run(t,()=>e.inspect(n,t))},p=t=>{let n=C(t);if(n)return l.reject(n);let r=Ce(s);window.confirm(`${t} on ${r.id} in ${r.queueName}? This changes durable queue state and has no compare-and-swap precondition.`)&&l.run(t,()=>e.mutate(r,t),{exclusive:!0})};return(0,H.jsxs)(`div`,{className:`grid gap-5 xl:grid-cols-[minmax(360px,0.8fr)_minmax(0,1.2fr)]`,children:[(0,H.jsxs)(`section`,{className:`rounded-lg border border-line bg-surface p-4`,children:[(0,H.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:`Dependency control`}),(0,H.jsx)(`p`,{className:`mt-1 text-xs text-faint`,children:`Run the official Flow Job dependency methods against the managed server TCP endpoint.`}),i&&(0,H.jsx)(`div`,{className:`mt-4`,children:(0,H.jsx)(q,{target:s,onChange:c})}),(0,H.jsx)(`p`,{className:`mt-3 text-xs text-muted`,children:`Payload replacement, retry and removal are unavailable because they can damage flow dependencies or restart active work.`}),(0,H.jsx)(`h3`,{className:`mt-5 mb-2 text-[10px] font-semibold uppercase tracking-wider text-faint`,children:`Inspect`}),(0,H.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:be.map(e=>(0,H.jsx)(`button`,{type:`button`,disabled:!d||!!u,onClick:()=>f(e),className:`rounded-md border border-line px-2.5 py-1.5 font-mono text-[11px] text-muted disabled:opacity-40`,children:e},e))}),(0,H.jsx)(`h3`,{className:`mt-5 mb-2 text-[10px] font-semibold uppercase tracking-wider text-faint`,children:`Mutate`}),(0,H.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:xe.map(e=>(0,H.jsx)(`button`,{type:`button`,disabled:!d||!!u||!!C(e.id),title:C(e.id)??void 0,onClick:()=>p(e.id),className:e.dangerous?`rounded-md border border-danger/40 px-2.5 py-1.5 text-xs text-danger disabled:opacity-40`:`rounded-md border border-line px-2.5 py-1.5 text-xs text-muted disabled:opacity-40`,children:e.label},e.id))})]}),(0,H.jsxs)(`section`,{className:`rounded-lg border border-line bg-surface p-4`,children:[(0,H.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:`Operation result`}),(0,H.jsx)(`p`,{className:`mt-1 mb-4 text-xs text-faint`,children:u?`Running ${u}…`:`The last authoritative broker response appears here.`}),l.error&&(0,H.jsx)(`p`,{role:`alert`,className:`mb-3 text-sm text-danger`,children:l.error}),l.result===void 0?(0,H.jsx)(`p`,{className:`text-sm text-muted`,children:`Choose an inspection or mutation.`}):(0,H.jsx)(U,{value:l.result})]})]})}var Ce=e=>({id:e.id.trim(),queueName:e.queueName.trim()});function we({repository:e=V,initialIds:t=``}){let[n,r]=(0,I.useState)(t),i=G(W(n)),a=i.busy,o=Te(n),s=async t=>{if(o.length===0)return;let n=[...o];await i.run(t,async()=>t===`one`?await e.getParentResult(n[0]):await e.getParentResults(n))};return(0,H.jsxs)(`section`,{className:`grid gap-5 rounded-lg border border-line bg-surface p-4 xl:grid-cols-[minmax(320px,0.8fr)_minmax(0,1.2fr)]`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:`Parent results`}),(0,H.jsx)(`p`,{className:`mt-1 text-xs text-faint`,children:`Resolve completed parent values through the official FlowProducer result API.`}),(0,H.jsxs)(`label`,{className:`mt-4 block text-xs text-faint`,children:[`Parent IDs, one per line`,(0,H.jsx)(`textarea`,{"aria-label":`Flow parent IDs`,value:n,onChange:e=>r(e.target.value),placeholder:`parent-job-id
2
- another-parent-id`,className:`mt-1 min-h-28 w-full resize-y rounded-lg border border-line bg-surface-2 p-3 font-mono text-xs text-fg`})]}),(0,H.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,H.jsx)(`button`,{type:`button`,disabled:o.length===0||!!a,onClick:()=>void s(`one`),className:`rounded-md border border-line px-3 py-1.5 font-mono text-xs text-muted disabled:opacity-40`,children:`getParentResult`}),(0,H.jsxs)(`button`,{type:`button`,disabled:o.length===0||!!a,onClick:()=>void s(`many`),className:`rounded-md border border-line px-3 py-1.5 font-mono text-xs text-muted disabled:opacity-40`,children:[`getParentResults (`,o.length,`)`]})]})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:`Resolved values`}),(0,H.jsx)(`p`,{className:`mt-1 mb-4 text-xs text-faint`,children:a?`Reading durable results…`:`Falsy values and input ordering are preserved.`}),i.error&&(0,H.jsx)(`p`,{role:`alert`,className:`mb-3 text-sm text-danger`,children:i.error}),i.result===void 0?(0,H.jsx)(`p`,{className:`text-sm text-muted`,children:`No parent result requested.`}):(0,H.jsx)(U,{value:i.result})]})]})}function Te(e){return e.split(/[,\n]/).map(e=>e.trim()).filter(Boolean).slice(0,1e3)}function Ee({repository:e=V,target:t,onTargetChange:n}){let[r,i]=(0,I.useState)(`10`),[a,o]=(0,I.useState)(`100`),s=G(W(t.id,t.queueName,r,a)),c=!!s.busy,l=!!(t.id.trim()&&t.queueName.trim())&&je(r)&&je(a),u=async()=>{if(!l)return;let n={target:{id:t.id.trim(),queueName:t.queueName.trim()},depth:Number(r),maxChildren:Number(a)};await s.run(`getFlow`,async()=>{let t=await e.getFlow({...n.target,depth:n.depth,maxChildren:n.maxChildren});return{...n,value:t}})};return(0,H.jsxs)(`section`,{className:`rounded-lg border border-line bg-surface p-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:`FlowProducer.getFlow`}),(0,H.jsx)(`p`,{className:`mt-1 text-xs text-faint`,children:`Read the broker-native tree with explicit traversal limits. Results are bound to the target and limits that produced them.`})]}),(0,H.jsx)(`button`,{type:`button`,disabled:!l||c,onClick:()=>void u(),className:`rounded-md bg-accent px-3 py-2 text-xs font-medium text-accent-fg disabled:opacity-40`,children:c?`Loading tree...`:`Load getFlow tree`})]}),(0,H.jsx)(`div`,{className:`mt-4`,children:(0,H.jsx)(q,{target:t,onChange:n})}),(0,H.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2`,children:[(0,H.jsx)(De,{label:`Depth`,value:r,onChange:i}),(0,H.jsx)(De,{label:`Children per level`,value:a,onChange:o})]}),(0,H.jsx)(`p`,{className:`mt-2 text-[11px] text-faint`,children:`Both limits accept integers from 0 to 500.`}),s.error&&(0,H.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-danger`,children:s.error}),s.result&&(0,H.jsx)(Oe,{loaded:s.result})]})}function De({label:e,value:t,onChange:n}){return(0,H.jsxs)(`label`,{className:`text-xs text-faint`,children:[e,(0,H.jsx)(`input`,{"aria-label":`getFlow ${e}`,type:`number`,min:`0`,max:`500`,step:`1`,value:t,onChange:e=>n(e.target.value),className:`mt-1 h-9 w-full rounded-lg border border-line bg-surface-2 px-3 text-sm text-fg`})]})}function Oe({loaded:e}){let t=ke(e.value),n=t?Ae(t):[];return(0,H.jsxs)(`div`,{className:`mt-4 border-t border-line pt-4`,"aria-live":`polite`,children:[(0,H.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2 text-xs`,children:[(0,H.jsxs)(`span`,{className:`font-mono text-fg`,children:[e.target.queueName,`/`,e.target.id]}),(0,H.jsxs)(`span`,{className:`text-faint`,children:[`depth `,e.depth,`, max children `,e.maxChildren]})]}),t===null?(0,H.jsx)(`p`,{className:`rounded-md border border-line bg-bg p-3 text-sm text-muted`,children:`Bunqueue returned no flow for this target.`}):n.length>0?(0,H.jsx)(`ul`,{"aria-label":`getFlow tree result`,className:`max-h-72 overflow-auto rounded-md border border-line bg-bg`,children:n.map(e=>(0,H.jsxs)(`li`,{className:`flex min-w-max items-center gap-2 border-b border-line/60 px-3 py-2 last:border-b-0`,style:{paddingLeft:`${12+Math.min(e.level,20)*18}px`},children:[(0,H.jsx)(`span`,{className:`rounded border px-1.5 py-0.5 text-[10px] ${E(e.state)}`,children:e.state}),(0,H.jsx)(`span`,{className:`font-mono text-xs text-fg`,children:e.id}),(0,H.jsx)(`span`,{className:`text-xs text-muted`,children:e.name}),(0,H.jsx)(`span`,{className:`text-[11px] text-faint`,children:e.queueName})]},e.id))}):(0,H.jsx)(`p`,{role:`alert`,className:`rounded-md border border-warning/40 p-3 text-sm text-warning`,children:`The agent returned an unrecognized getFlow payload. Inspect the raw JSON below.`}),(0,H.jsxs)(`details`,{className:`mt-3`,open:!0,children:[(0,H.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium text-muted`,children:`Raw getFlow JSON`}),(0,H.jsx)(`div`,{className:`mt-2`,children:(0,H.jsx)(U,{value:e.value})})]})]})}function ke(e){let t=J(e),n=J(t?.result)??t;if(!(!n||!Object.hasOwn(n,`flow`)))return n.flow===null?null:J(n.flow)}function Ae(e){let t=[],n=[{node:e,level:0}],r=new WeakSet;for(;n.length>0&&t.length<1e3;){let e=n.shift();if(!e||r.has(e.node))continue;r.add(e.node),t.push({id:Y(e.node.id,`(missing id)`),name:Y(e.node.name,`(unnamed)`),queueName:Y(e.node.queueName,`(missing queue)`),state:Y(e.node.state,`unknown`),level:e.level});let i=Array.isArray(e.node.children)?e.node.children:[];n.unshift(...i.map(J).filter(e=>e!==void 0).map(t=>({node:t,level:e.level+1})))}return t}var je=e=>/^\d+$/.test(e)&&Number(e)<=500,J=e=>typeof e==`object`&&e&&!Array.isArray(e)?e:void 0,Y=(e,t)=>typeof e==`string`&&e.length>0?e:t,Me=[`getState`,`isWaiting`,`isActive`,`isDelayed`,`isCompleted`,`isFailed`,`isWaitingChildren`,`toJSON`,`asJSON`],X={updateData:{data:{}},updateProgress:{progress:50,message:`Halfway`},log:{message:`Operator note`},changeDelay:{delay:1e3},changePriority:{priority:1,lifo:!1},clearLogs:{keepLogs:0},removeDeduplicationKey:{}},Ne={progress:{stage:`hydrate`,completed:4,total:10}};function Pe({repository:e=V,initialTarget:t={id:``,queueName:``}}){let[n,r]=(0,I.useState)(t),[i,a]=(0,I.useState)(`updateProgress`),[o,s]=(0,I.useState)(JSON.stringify(X.updateProgress,null,2)),[c,l]=(0,I.useState)(`30000`),u=G(W(n.id,n.queueName,i,o,c),`job-toolkit`),d=u.busy,f=!!(n.id.trim()&&n.queueName.trim()),p=e=>{a(e),s(JSON.stringify(X[e],null,2))};return(0,H.jsxs)(`div`,{className:`space-y-5`,children:[(0,H.jsx)(Ee,{repository:e,target:n,onTargetChange:r}),(0,H.jsxs)(`section`,{className:`rounded-lg border border-line bg-surface p-4`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:`Flow Job methods`}),(0,H.jsx)(`p`,{className:`mt-1 text-xs text-faint`,children:`State predicates, serialization, bounded waiting, and durable mutations from Bunqueue 2.9.4.`})]}),d&&(0,H.jsxs)(`span`,{className:`font-mono text-xs text-accent`,children:[d,`…`]})]}),(0,H.jsx)(`div`,{className:`mt-4`,children:(0,H.jsx)(q,{target:n,onChange:r})}),(0,H.jsx)(`p`,{className:`mt-3 text-xs text-muted`,children:`Payload replacement, retry and removal are unavailable because they can damage flow dependencies or restart active work.`}),(0,H.jsx)(`h3`,{className:`mt-5 mb-2 text-[10px] font-semibold uppercase tracking-wider text-faint`,children:`Inspect state and wire JSON`}),(0,H.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Me.map(t=>(0,H.jsx)(`button`,{type:`button`,disabled:!f||!!d,onClick:()=>{let r=Z(n);u.run(t,()=>e.inspect(r,t))},className:`rounded-md border border-line px-2.5 py-1.5 font-mono text-[11px] text-muted disabled:opacity-40`,children:t},t))}),(0,H.jsxs)(`div`,{className:`mt-5 grid gap-4 xl:grid-cols-[minmax(0,1fr)_minmax(300px,0.7fr)]`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,H.jsxs)(`label`,{className:`text-xs text-faint`,children:[`Mutation`,(0,H.jsx)(`select`,{"aria-label":`Flow Job mutation`,value:i,onChange:e=>p(e.target.value),className:`mt-1 block h-9 rounded-lg border border-line bg-surface-2 px-3 font-mono text-xs text-fg`,children:Object.keys(X).map(e=>(0,H.jsx)(`option`,{disabled:!!C(e),children:e},e))})]}),(0,H.jsx)(`button`,{type:`button`,disabled:!f||!!d||!!C(i),title:C(i)??void 0,onClick:()=>{let t=C(i);if(t)return u.reject(t);let r;try{r=JSON.parse(o)}catch{return u.reject(`Mutation payload must be valid JSON.`)}if(!r||typeof r!=`object`||Array.isArray(r))return u.reject(`Mutation payload must be a JSON object.`);let a=Z(n),s=i;window.confirm(`${s} on ${a.id}? This writes durable job state without a compare-and-swap precondition.`)&&u.run(s,()=>e.mutate(a,s,r),{exclusive:!0})},className:`h-9 rounded-md border border-warning/40 px-3 text-xs text-warning disabled:opacity-40`,children:`Apply mutation`}),i===`updateProgress`&&(0,H.jsxs)(`div`,{className:`flex gap-2`,children:[(0,H.jsx)(`button`,{type:`button`,onClick:()=>s(JSON.stringify(X.updateProgress,null,2)),className:`h-9 rounded-md border border-line px-3 text-xs text-muted`,children:`Numeric progress`}),(0,H.jsx)(`button`,{type:`button`,onClick:()=>s(JSON.stringify(Ne,null,2)),className:`h-9 rounded-md border border-line px-3 text-xs text-muted`,children:`Object progress`})]})]}),(0,H.jsx)(`textarea`,{"aria-label":`Flow Job mutation JSON`,value:o,onChange:e=>s(e.target.value),className:`mt-3 min-h-32 w-full resize-y rounded-lg border border-line bg-bg p-3 font-mono text-xs text-fg`})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`label`,{className:`text-xs text-faint`,children:[`waitUntilFinished TTL (ms)`,(0,H.jsx)(`input`,{"aria-label":`Flow wait TTL`,type:`number`,min:`1`,max:`60000`,value:c,onChange:e=>l(e.target.value),className:`mt-1 block h-9 w-full rounded-lg border border-line bg-surface-2 px-3 text-sm text-fg`})]}),(0,H.jsx)(`button`,{type:`button`,disabled:!f||!!d||!Fe(c),onClick:()=>{let t=Z(n),r=Number(c);u.run(`waitUntilFinished`,()=>e.waitUntilFinished(t,r))},className:`mt-3 rounded-md border border-line px-3 py-2 font-mono text-xs text-muted disabled:opacity-40`,children:`waitUntilFinished`}),(0,H.jsx)(`p`,{className:`mt-3 text-[11px] leading-5 text-faint`,children:`Lease-only methods are not forged here: extendLock and worker state transitions require the active worker token; discard is process-local and non-awaitable.`})]})]}),u.error&&(0,H.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-danger`,children:u.error}),u.result!==void 0&&(0,H.jsx)(`div`,{className:`mt-4`,children:(0,H.jsx)(U,{value:u.result})})]}),(0,H.jsx)(Se,{repository:e,target:n,onTargetChange:r,showTarget:!1}),(0,H.jsx)(we,{repository:e})]})}var Z=e=>({id:e.id.trim(),queueName:e.queueName.trim()}),Fe=e=>Number.isSafeInteger(Number(e))&&Number(e)>=1&&Number(e)<=6e4;function Ie({input:e,loading:t,onInput:n,onSubmit:r}){return(0,H.jsxs)(p,{className:`mb-6`,children:[(0,H.jsxs)(`form`,{onSubmit:r,className:`flex flex-wrap items-center gap-3`,children:[(0,H.jsx)(`input`,{name:`flow-job-id`,autoComplete:`off`,spellCheck:!1,maxLength:1024,value:e,onChange:e=>n(e.target.value),placeholder:`Flow job ID`,"aria-label":`Root job ID`,"aria-describedby":`flow-input-help`,className:`min-w-0 flex-1 rounded-lg border border-line bg-surface-2 px-3 py-2 font-mono text-sm text-fg outline-none placeholder:text-faint focus-visible:ring-2 focus-visible:ring-accent/50`}),(0,H.jsx)(`button`,{type:`submit`,disabled:t||!e.trim(),className:`rounded-lg bg-accent px-4 py-2 text-sm font-medium text-accent-fg disabled:opacity-50`,children:t?`Loading…`:`Load Flow`})]}),(0,H.jsxs)(`p`,{id:`flow-input-help`,className:`mt-2 text-xs text-faint`,children:[`Start from any surviving structural node. Bunqueue 2.9.3 flow topology is resolved from durable parent, children, and dependency contracts. Up to `,500,` nodes are rendered.`]})]})}var Le={nodeWidth:168,nodeHeight:60,colGap:72,rowGap:20,padding:24};function Re(e,t){let n=new Map,r=new Map;for(let t of e)n.set(t,0),r.set(t,[]);for(let e of t)!n.has(e.from)||!n.has(e.to)||e.from===e.to||r.get(e.from)?.push(e.to);let i=ze(e,r),a=new Map;for(let t of e)a.set(t,0);for(let e of i.values())for(let t of e)a.set(t,(a.get(t)??0)+1);let o=[...n.keys()].filter(e=>(a.get(e)??0)===0);for(let e=0;e<o.length;e++){let t=o[e];for(let e of i.get(t)??[]){n.set(e,Math.max(n.get(e)??0,(n.get(t)??0)+1));let r=(a.get(e)??0)-1;a.set(e,r),r===0&&o.push(e)}}return n}function ze(e,t){let n=new Map;for(let t of e)n.set(t,[]);let r=new Set,i=new Set;for(let a of e){if(i.has(a))continue;i.add(a),r.add(a);let e=[{id:a,next:0}];for(;e.length;){let a=e[e.length-1],o=t.get(a.id)??[];if(a.next>=o.length){r.delete(a.id),e.pop();continue}let s=o[a.next++];r.has(s)||(n.get(a.id)?.push(s),!i.has(s)&&(i.add(s),r.add(s),e.push({id:s,next:0})))}}return n}function Be(e,t,n={}){let r={...Le,...n},i=Re(e,t),a=new Map,o=0;for(let t of e){let e=i.get(t)??0;o=Math.max(o,e);let n=a.get(e);n?n.push(t):a.set(e,[t])}let s=0;for(let e of a.values())s=Math.max(s,e.length);let c=s*r.nodeHeight+Math.max(0,s-1)*r.rowGap,l=[];for(let e=0;e<=o;e++){let t=a.get(e)??[],n=t.length*r.nodeHeight+Math.max(0,t.length-1)*r.rowGap,i=r.padding+(c-n)/2;t.forEach((t,n)=>{l.push({id:t,layer:e,x:r.padding+e*(r.nodeWidth+r.colGap),y:i+n*(r.nodeHeight+r.rowGap)})})}return{nodes:l,width:r.padding*2+(o+1)*r.nodeWidth+o*r.colGap,height:r.padding*2+c}}function Ve({graph:e,layout:t,selected:n,onSelect:r}){let i=new Map(t.nodes.map(e=>[e.id,e]));return(0,H.jsxs)(p,{padded:!1,className:`max-h-[70vh] overflow-auto overscroll-contain p-4`,children:[(0,H.jsx)(`h2`,{className:`sr-only`,children:`Flow Graph`}),(0,H.jsx)(`ul`,{className:`sr-only`,"aria-label":`Flow relationships`,children:e.edges.map(e=>(0,H.jsx)(`li`,{children:e.kind===`child`?`${e.from} has child ${e.to}`:`${e.to} depends on ${e.from}`},`accessible-${e.from}-${e.to}-${e.kind}`))}),(0,H.jsxs)(`div`,{className:`relative`,style:{width:t.width,height:t.height},children:[(0,H.jsxs)(`svg`,{"aria-hidden":`true`,className:`absolute inset-0 text-line`,width:t.width,height:t.height,children:[(0,H.jsxs)(`defs`,{children:[(0,H.jsx)(`marker`,{id:`flow-arrow-child`,markerWidth:`6`,markerHeight:`6`,refX:`5`,refY:`3`,orient:`auto`,children:(0,H.jsx)(`path`,{d:`M0,0 L6,3 L0,6 Z`,fill:`currentColor`})}),(0,H.jsx)(`marker`,{id:`flow-arrow-dependency`,markerWidth:`6`,markerHeight:`6`,refX:`5`,refY:`3`,orient:`auto`,children:(0,H.jsx)(`path`,{d:`M0,0 L6,3 L0,6 Z`,fill:`currentColor`})})]}),e.edges.map(e=>{let t=i.get(e.from),n=i.get(e.to);return!t||!n?null:(0,H.jsx)(`path`,{d:Ue(t,n),fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeDasharray:e.kind===`depends`?`4 4`:void 0,markerEnd:`url(#flow-arrow-${e.kind===`depends`?`dependency`:`child`})`,opacity:.5},`${e.from}-${e.to}-${e.kind}`)})]}),t.nodes.map(t=>{let i=e.jobs.get(t.id),a=e.failures.has(t.id)?`unavailable`:i?.state??`unknown`;return(0,H.jsxs)(`button`,{type:`button`,"data-flow-node":t.id,onClick:()=>r(t.id),"aria-pressed":n===t.id,"aria-label":`${t.id}, queue ${i?.queue??`unknown`}, state ${a}`,title:t.id,style:{left:t.x,top:t.y,width:168,height:60},className:f(`absolute flex flex-col justify-center gap-0.5 rounded-lg border px-3 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70`,E(i?.state),n===t.id&&`ring-2 ring-accent`),children:[(0,H.jsx)(`span`,{translate:`no`,className:`truncate font-mono text-xs text-fg`,children:D(t.id)}),(0,H.jsxs)(`span`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[(0,H.jsx)(`span`,{className:`truncate`,children:i?.queue??`—`}),(0,H.jsx)(`span`,{className:`font-medium`,children:a})]})]},t.id)})]})]})}function He(e,t,n,r){let i=(e+n)/2;return`M${e},${t} C${i},${t} ${i},${r} ${n},${r}`}function Ue(e,t){return e.x<=t.x?He(e.x+168,e.y+60/2,t.x,t.y+60/2):He(e.x,e.y+60/2,t.x+168,t.y+60/2)}function We({graph:e,selected:t}){let n=t?e.jobs.get(t):void 0,r=t?e.failures.get(t):void 0;return(0,H.jsx)(`aside`,{"aria-label":`Selected job details`,"aria-live":`polite`,children:(0,H.jsxs)(p,{children:[n?(0,H.jsx)(Ge,{job:n,failure:r}):(0,H.jsx)(`p`,{className:`text-sm text-muted`,children:`Select a node to inspect it.`}),(0,H.jsx)(Ke,{graph:e})]})})}function Ge({job:e,failure:t}){return(0,H.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`div`,{className:`text-xs text-faint`,children:`Job`}),(0,H.jsx)(`div`,{translate:`no`,className:`break-all font-mono text-xs text-fg`,children:e.id})]}),t&&(0,H.jsxs)(`p`,{role:`alert`,className:`break-words text-xs text-warning`,children:[`Snapshot unavailable: `,t]}),(0,H.jsx)($,{label:`Queue`,value:e.queue??`—`}),(0,H.jsx)($,{label:`State`,value:t?`unavailable`:e.state??`unknown`}),(0,H.jsx)($,{label:`Priority`,value:e.priority===void 0?`—`:String(e.priority)}),(0,H.jsx)($,{label:`Parent`,value:e.parentId??`—`}),(0,H.jsx)($,{label:`Children`,value:t?`—`:String(e.childrenIds?.length??0)}),(0,H.jsx)($,{label:`Depends on`,value:t?`—`:String(e.dependsOn?.length??0)}),(0,H.jsx)(r,{to:`/job?id=${encodeURIComponent(e.id)}`,className:`inline-block rounded-lg border border-line px-3 py-1.5 text-xs text-muted hover:bg-surface-2 hover:text-fg`,children:`Open in Job Inspector`})]})}function Ke({graph:e}){return(0,H.jsxs)(`div`,{className:`mt-4 border-t border-line pt-3 text-xs text-faint`,"aria-live":`polite`,children:[e.truncated&&(0,H.jsxs)(`div`,{className:`mb-1 text-warning`,children:[`Graph truncated at `,500,` nodes / depth `,100,`.`]}),(0,H.jsx)(Q,{label:`known snapshot limitation`,pluralLabel:`known snapshot limitations`,values:e.limitations,tone:`text-warning`}),(0,H.jsx)(Q,{label:`unavailable node`,pluralLabel:`unavailable nodes`,values:[...e.failures].map(([e,t])=>`${e}: ${t}`),tone:`text-warning`}),e.cycle&&(0,H.jsxs)(`div`,{className:`mb-1 break-words text-danger`,children:[`Dependency cycle: `,(0,H.jsx)(`span`,{className:`font-mono`,children:e.cycle.join(` → `)})]}),(0,H.jsx)(Q,{label:`snapshot inconsistency`,pluralLabel:`snapshot inconsistencies`,values:e.issues,tone:`text-warning`}),e.policyNotes.length>0&&(0,H.jsx)(`p`,{className:`mb-1 text-muted`,children:`Failure-policy notes are informational; the HTTP snapshot cannot prove that a policy fired.`}),(0,H.jsx)(Q,{label:`failure-policy ambiguity`,pluralLabel:`failure-policy ambiguities`,values:e.policyNotes,tone:`text-muted`}),(0,H.jsxs)(`div`,{className:`mb-1`,children:[e.jobs.size,` nodes · `,e.edges.length,` edges`]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,H.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(`span`,{className:`inline-block h-px w-4 bg-current`}),` child`]}),(0,H.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,H.jsx)(`span`,{className:`inline-block h-px w-4 border-t border-dashed border-current`}),` depends`]})]})]})}function Q({label:e,pluralLabel:t,values:n,tone:r}){return n.length?(0,H.jsxs)(`details`,{className:`mb-1 ${r}`,children:[(0,H.jsxs)(`summary`,{className:`cursor-pointer`,children:[n.length,` `,n.length===1?e:t]}),(0,H.jsx)(`ul`,{className:`mt-1 space-y-1 pl-3`,children:n.map(e=>(0,H.jsx)(`li`,{className:`break-words`,children:e},e))})]}):null}function $({label:e,value:t}){return(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-2`,children:[(0,H.jsx)(`span`,{className:`shrink-0 text-xs text-faint`,children:e}),(0,H.jsx)(`span`,{className:`min-w-0 break-all text-right text-fg`,children:t})]})}function qe({graph:e,selected:t,onSelect:n}){return(0,H.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_280px]`,children:[(0,H.jsx)(Ve,{graph:e,layout:(0,I.useMemo)(()=>Be([...e.jobs.keys()],e.edges,w),[e]),selected:t,onSelect:n}),(0,H.jsx)(We,{graph:e,selected:t})]})}function Je(){let e=fe();return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(_,{title:`Job Flows`,description:`Inspect Bunqueue 2.9.3 parent, child, and dependency topology as an operational DAG.`,actions:e.graph&&(0,H.jsx)(`button`,{type:`button`,disabled:e.loading,onClick:()=>void e.load(e.rootParam),className:`rounded-lg border border-line px-3 py-1.5 text-sm text-muted hover:bg-surface-2 hover:text-fg disabled:opacity-50`,children:`Refresh`})}),(0,H.jsx)(`nav`,{"aria-label":`Job Flow tools`,className:`mb-5 flex border-b border-line`,children:[`explore`,`create`,`operations`].map(t=>(0,H.jsx)(`button`,{type:`button`,"aria-pressed":e.mode===t,onClick:()=>e.setMode(t),className:e.mode===t?`border-b-2 border-accent px-4 py-2 text-sm capitalize text-fg`:`border-b-2 border-transparent px-4 py-2 text-sm capitalize text-faint hover:text-fg`,children:t===`operations`?`Job methods`:t},t))}),e.mode===`create`&&(0,H.jsx)(_e,{onOpen:e.openRecent}),e.mode===`operations`&&(0,H.jsx)(Pe,{initialTarget:v()?{id:`flow-order-9a3f`,queueName:`orders`}:void 0}),e.mode===`explore`&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(Ie,{input:e.input,loading:e.loading,onInput:e.setInput,onSubmit:e.submit}),(0,H.jsxs)(`div`,{"aria-live":`polite`,children:[e.error&&(pe(e.error)?(0,H.jsx)(m,{message:`Could not load the flow — ${e.error.message}`,onRetry:()=>void e.load(e.rootParam)}):(0,H.jsx)(h,{error:e.error,onRetry:()=>void e.load(e.rootParam)})),e.loading&&(0,H.jsx)(g,{label:`Loading flow…`})]}),!e.loading&&!e.graph&&!e.error&&(0,H.jsx)(ye,{recent:e.recent,onOpen:e.openRecent}),e.graph&&(0,H.jsx)(qe,{graph:e.graph,selected:e.selected,onSelect:e.setSelected})]})]})}export{Je as Flows};
@@ -1,2 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{f as t,g as n,l as r,r as i,t as a}from"./react-vendor-DfC0iyIS.js";import{a as o,o as s}from"./connectionStore-DdLzJyut.js";import{a as c,n as l}from"./upstreamPaths-DQeKSxGc.js";import{a as u,n as d,t as f}from"./bq-CSX8DSME.js";import{T as p,d as m}from"./icons-C1HVBnFn.js";import{t as h}from"./StatusBadge-cYUkK-4P.js";import{n as g,t as _}from"./Button-BCjgbAhY.js";import{n as v,t as y}from"./Card-DptfvL2O.js";import{r as b,t as x}from"./feedback-Dxfj-Fy1.js";import{t as S}from"./PageHeader-DD4vnVog.js";import{a as C,i as w}from"./format-Cg7VCIZW.js";import{a as T}from"./index-CxzFSZj3.js";import{a as E,n as D,o as O}from"./form-Dy-an7ew.js";import{r as k}from"./flowMutationSafety-YKTHxqKv.js";import{n as A}from"./exportFile-C7xhE8Yh.js";import{t as j}from"./flowOperationPolicy-B2Etcb3f.js";var M=1e4,ee=100,te=256*1024;function N(e){throw new u(`Invalid job response: ${e}`,200)}function P(e,t,{nullable:n=!1,nonEmpty:r=!1}={},i=`job`){if(!Object.hasOwn(e,t)||e[t]===void 0)return;let a=e[t];n&&a===null||(typeof a!=`string`||r&&!a.trim())&&N(`${i}.${t} must be ${n?`a string or null`:`a string`}${r?` (non-empty)`:``}`)}function F(e,t,{nullable:n=!1,integer:r=!1,min:i,max:a}={},o=`job`){if(!Object.hasOwn(e,t)||e[t]===void 0)return;let s=e[t];n&&s===null||(typeof s!=`number`||!Number.isFinite(s)||r&&!Number.isSafeInteger(s)||i!==void 0&&s<i||a!==void 0&&s>a)&&N(`${o}.${t} must be a valid${r?` safe integer`:` finite number`}`)}function I(e,t){Object.hasOwn(e,t)&&e[t]!==void 0&&typeof e[t]!=`boolean`&&N(`job.${t} must be a boolean`)}function L(e,t,{nullable:n=!1,nonEmpty:r=!1}={}){if(!Object.hasOwn(e,t)||e[t]===void 0)return;let i=e[t];n&&i===null||(!Array.isArray(i)||i.some(e=>typeof e!=`string`||r&&!e.trim()))&&N(`job.${t} must be ${n?`a string array or null`:`a string array`}`)}function ne(e,t){let n=0,r=0;for(;n<e.length&&r<t;){let t=e.codePointAt(n);n+=t!==void 0&&t>65535?2:1,r+=1}return{text:e.slice(0,n),count:r}}function re(e){let t=[],n=0,r=!1,i=Math.min(e.length,ee);for(let a=0;a<i;a++){let i=+(t.length>0),o=te-n-i;if(o<=0){r=!0;break}let s=e[a]??``,c=ne(s,o);if(t.push(c.text),n+=i+c.count,c.text.length!==s.length){r=!0;break}}return t.length<e.length&&(r=!0),{text:t.join(`
2
- `),displayedLines:t.length,totalLines:e.length,truncated:r}}function ie(e,t){if(t&&(typeof e.state!=`string`||!e.state.trim())&&N(`canonical job.state must be a non-empty string`),P(e,`state`,{nonEmpty:!0}),P(e,`name`,{nonEmpty:!0}),P(e,`failedReason`),t&&(typeof e.queue!=`string`||!e.queue.trim())&&N(`canonical job.queue must be a non-empty string`),P(e,`queue`,{nonEmpty:!0}),P(e,`customId`,{nullable:!0}),P(e,`parentId`,{nullable:!0,nonEmpty:!0}),P(e,`groupId`,{nullable:!0}),P(e,`progressMessage`,{nullable:!0}),L(e,`childrenIds`,{nonEmpty:!0}),L(e,`dependsOn`,{nonEmpty:!0}),L(e,`tags`),L(e,`stacktrace`,{nullable:!0}),Array.isArray(e.stacktrace)&&e.stacktrace.length>M&&N(`job.stacktrace exceeds Bunqueue's ${M}-entry limit`),F(e,`priority`,{integer:!0}),F(e,`createdAt`),F(e,`runAt`),F(e,`startedAt`,{nullable:!0}),F(e,`completedAt`,{nullable:!0}),F(e,`attempts`,{integer:!0,min:0}),F(e,`maxAttempts`,{integer:!0,min:0}),F(e,`backoff`,{integer:!0,min:0}),F(e,`timeout`,{nullable:!0,integer:!0,min:0}),F(e,`ttl`,{nullable:!0,integer:!0,min:0}),F(e,`progress`,{min:0,max:100}),F(e,`lastHeartbeat`),F(e,`stallCount`,{integer:!0,min:0}),I(e,`removeOnComplete`),I(e,`removeOnFail`),Object.hasOwn(e,`backoffConfig`)&&e.backoffConfig!==void 0){let t=e.backoffConfig;if(t!==null){(!t||typeof t!=`object`||Array.isArray(t))&&N(`job.backoffConfig must be an object or null`);let e=t;e.type!==`fixed`&&e.type!==`exponential`&&N(`job.backoffConfig.type must be fixed or exponential`),F(e,`delay`,{integer:!0,min:0},`job.backoffConfig`),(!Object.hasOwn(e,`delay`)||e.delay===void 0)&&N(`job.backoffConfig.delay is required`),F(e,`maxDelay`,{integer:!0,min:0},`job.backoffConfig`)}}if(Object.hasOwn(e,`timeline`)&&e.timeline!==void 0){Array.isArray(e.timeline)||N(`job.timeline must be an array`),e.timeline.length>20&&N(`job.timeline exceeds 20 entries`);for(let[t,n]of e.timeline.entries()){(!n||typeof n!=`object`||Array.isArray(n))&&N(`job.timeline[${t}] must be an object`);let e=n;(typeof e.state!=`string`||!e.state.trim())&&N(`job.timeline[${t}].state must be a non-empty string`),(typeof e.timestamp!=`number`||!Number.isFinite(e.timestamp))&&N(`job.timeline[${t}].timestamp must be a finite number`);let r=`job.timeline[${t}]`;P(e,`worker`,{},r),P(e,`error`,{},r),F(e,`attempt`,{integer:!0,min:0},r)}}}function R(e,{canonical:t,expectedId:n}){if(!e||typeof e!=`object`||Array.isArray(e))return N(`expected an object envelope`);let r=e;if(r.ok!==!0||!Object.hasOwn(r,`job`))return N(`expected { ok: true, job }`);if(r.job===null)return null;if(!r.job||typeof r.job!=`object`||Array.isArray(r.job))return N(`job must be an object or null`);let i=r.job;return typeof i.id!=`string`||!i.id.trim()?N(`job.id must be a non-empty string`):n!==void 0&&i.id!==n?N(`expected job.id ${JSON.stringify(n)}`):(ie(i,t),i)}function ae(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw new u(`Invalid job result response: expected an object envelope`,200);let n=e;if(n.ok!==!0||n.id!==t)throw new u(`Invalid job result response: expected { ok: true, id, result? }`,200);return{result:n.result}}var z=3e4;function B(){let{token:e}=s.getState();return{baseUrl:o(),authorization:e?`Bearer ${e}`:void 0}}function V(e,t){return e?.baseUrl===t.baseUrl&&e.authorization===t.authorization}function H(e,t,n){return t.aborted&&!n?.aborted?new u(`Request timed out`,0):e}async function U(e,t,n,r=z){let i=AbortSignal.timeout(r),a=n?AbortSignal.any([n,i]):i,o=new Headers;e.authorization&&o.set(`Authorization`,e.authorization);let s;try{a.throwIfAborted(),s=await fetch(`${e.baseUrl}${t}`,{headers:o,signal:a}),a.throwIfAborted()}catch(e){throw H(e,i,n)}if(s.status===204)return;let c;try{c=await s.text(),a.throwIfAborted()}catch(e){throw H(e,i,n)}let l,d=!1;if(c)try{l=JSON.parse(c)}catch{d=!0}if(!s.ok){let t=!d&&l&&typeof l==`object`?l.error:void 0,n=typeof t==`string`?t:`HTTP ${s.status}`;throw s.status===401&&typeof window<`u`&&window.dispatchEvent(new window.CustomEvent(`auth:required`,{detail:{scope:`server`,auth:e.authorization,target:e.baseUrl}})),new u(n,s.status)}if(c){if(d)throw new u(`Invalid JSON response (HTTP ${s.status})`,s.status);if(l&&typeof l==`object`&&l.ok===!1){let e=l.error;throw new u(typeof e==`string`?e:`Operation failed`,s.status)}return l}}async function oe(e,t,n={}){let r=n.target??B(),i=n.timeoutMs??z,a=R(await U(r,t===`custom`?`/jobs/custom/${l(e,`Custom job ID`)}`:`/jobs/${c(e)}`,n.signal,i),{canonical:t===`id`,expectedId:t===`id`?e:void 0});if(!a||t===`id`)return a;if(a.customId!==e)throw new u(`Invalid job response: expected job.customId ${JSON.stringify(e)}`,200);return R(await U(r,`/jobs/${c(a.id)}`,n.signal,i),{canonical:!0,expectedId:a.id})}function se(e,t){return async(n,r=e.lookupBy,i=!1,a=void 0,o=!1)=>{let s=n.trim();if(!s||a===void 0&&e.actionBusy.current&&!o)return;e.internalEmptyUrlPending.current=!1,e.preservedEmptyLocationKey.current=null,a===void 0&&(e.actionGen.current+=1),e.job!==null&&(r===`id`?e.job.id!==s:e.job.customId!==s)&&(e.jobTarget.current=null,e.setJob(null),e.setResult({fetched:!1,value:void 0}),e.setResultError(null)),e.lookupAbort.current?.abort();let l=new AbortController;e.lookupAbort.current=l,e.lookupIdentity.current={key:s,mode:r};let d=++e.lookupGen.current,f=B();e.setLoading(!0),e.setNotFound(!1),i||e.setMsg(null);try{let n=await oe(s,r,{signal:l.signal,target:f});if(!n){if(d!==e.lookupGen.current)return;e.internalEmptyUrlPending.current=!0,e.preservedEmptyLocationKey.current=null,e.setJob(null),e.setResult({fetched:!1,value:void 0}),e.setResultError(null),e.setNotFound(!0),t({},{replace:!0});return}let i=null,a=null;if(d!==e.lookupGen.current||l.signal.aborted||!V(f,B()))return;if(n.state===`completed`)if(Object.hasOwn(n,`returnvalue`))i={result:n.returnvalue};else try{i=ae(await U(f,`/jobs/${c(n.id)}/result`,l.signal),n.id)}catch(e){if(l.signal.aborted)throw e;a=e.message}if(d!==e.lookupGen.current||l.signal.aborted||!V(f,B()))return;e.jobTarget.current=f,e.setJob(n),r===`custom`?(e.setLookupBy(`id`),e.setIdInput(n.id)):e.setIdInput(s),t({id:n.id},{replace:!0}),e.setResult(i?{fetched:!0,value:i.result}:{fetched:!1,value:void 0}),e.setResultError(a)}catch(n){if(d!==e.lookupGen.current||l.signal.aborted)return;n instanceof u&&(n.status===404||/not found/i.test(n.message))?(e.internalEmptyUrlPending.current=!0,e.preservedEmptyLocationKey.current=null,e.setJob(null),e.setResult({fetched:!1,value:void 0}),e.setResultError(null),e.setNotFound(!0),t({},{replace:!0})):i?e.setMsg(e=>e?{ok:e.ok,text:`${e.text} — couldn't reload: ${n.message}`}:{ok:!1,text:n.message}):e.setMsg({ok:!1,text:n.message})}finally{d===e.lookupGen.current&&(e.lookupAbort.current===l&&(e.lookupAbort.current=null,e.lookupIdentity.current=null),e.setLoading(!1))}}}var W=e(n(),1),G=a(),K=365*24*60*60*1e3;function q(e,t){if(!e.trim())return{ok:!1,msg:`A value is required`};let n=Number(e);return Number.isFinite(n)?t===`progress`?n>=0&&n<=100?{ok:!0,value:n}:{ok:!1,msg:`Progress must be between 0 and 100`}:Number.isSafeInteger(n)?t===`priority`?n>=-1e6&&n<=1e6?{ok:!0,value:n}:{ok:!1,msg:`Priority must be between -1000000 and 1000000`}:n>=0&&n<=K?{ok:!0,value:n}:{ok:!1,msg:`Delay must be between 0 and ${K} ms`}:{ok:!1,msg:`Value must be a whole, safe integer`}:{ok:!1,msg:`Value must be a finite number`}}function ce({job:e,busy:t,act:n}){let r=j(e.state),i=r.promote||r.setPriority||r.setDelay||e.state===`active`;return(0,G.jsxs)(y,{children:[(0,G.jsx)(v,{title:`Actions`}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.promote&&(0,G.jsx)(_,{size:`sm`,disabled:t,onClick:()=>n(`Promote`,()=>f.promoteJob(e.id)),children:`Promote (run now)`}),e.state===`failed`&&(0,G.jsx)(`p`,{role:`note`,className:`rounded-lg border border-warning/30 bg-warning/5 p-2 text-xs text-warning`,children:`DLQ retry is unavailable in Bunqueue v2.9.3: its GET and retry POST have no atomic job-generation, state, or flow-topology precondition.`}),e.state===`completed`&&(0,G.jsx)(`p`,{role:`note`,className:`rounded-lg border border-warning/30 bg-warning/5 p-2 text-xs text-warning`,children:`Completed-job requeue is unavailable in Bunqueue v2.9.3 because retry-completed re-inserts a child without rebuilding its flow dependency registration.`}),e.state===`active`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{role:`note`,className:`rounded-lg border border-warning/30 bg-warning/5 p-2 text-xs text-warning`,children:`Active-job state changes are unavailable: Bunqueue cannot stop the worker that is already processing this job, so retrying, delaying, discarding or failing it here could run side effects twice.`}),(0,G.jsx)(J,{label:`Set progress (0–100)`,cta:`Progress`,kind:`progress`,disabled:t,onSubmit:t=>n(`Progress`,()=>f.setJobProgress(e.id,t))})]}),r.setPriority&&(0,G.jsx)(le,{disabled:t,onSubmit:(t,r)=>n(`Priority`,()=>f.changePriority(e.id,t,r))}),r.setDelay&&(0,G.jsx)(J,{label:`Set delay (ms)`,cta:`Delay`,kind:`delay`,disabled:t,onSubmit:t=>n(`Delay`,()=>f.changeDelay(e.id,t))}),(0,G.jsxs)(`p`,{role:`note`,className:`text-xs text-faint`,children:[`Cancel/delete/discard: `,k]}),!i&&(0,G.jsxs)(`p`,{className:`text-xs text-faint`,children:[`No actions available for a job in state "`,e.state??`unknown`,`".`]})]})]})}function J({label:e,cta:t,kind:n,disabled:r,onSubmit:i}){let[a,o]=(0,W.useState)(``),s=q(a,n);return(0,G.jsxs)(`form`,{className:`flex gap-2`,onSubmit:e=>{e.preventDefault(),!r&&s.ok&&i(s.value)},children:[(0,G.jsx)(D,{type:`number`,min:0,max:n===`progress`?100:K,step:n===`progress`?`any`:1,name:n===`progress`?`job-progress`:`job-delay`,value:a,onChange:e=>o(e.target.value),placeholder:e,"aria-label":e,className:`h-8 text-xs`}),(0,G.jsx)(_,{type:`submit`,size:`sm`,disabled:r||!s.ok,children:t}),!s.ok&&a.trim()&&(0,G.jsx)(`span`,{role:`alert`,className:`self-center text-[11px] text-danger`,children:s.msg})]})}function le({disabled:e,onSubmit:t}){let[n,r]=(0,W.useState)(``),[i,a]=(0,W.useState)(!1),o=q(n,`priority`);return(0,G.jsxs)(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:n=>{n.preventDefault(),!e&&o.ok&&t(o.value,i)},children:[(0,G.jsx)(D,{type:`number`,min:-1e6,max:1e6,step:1,name:`job-priority`,value:n,onChange:e=>r(e.target.value),placeholder:`Set priority`,"aria-label":`Set priority`,className:`h-8 min-w-28 flex-1 text-xs`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(O,{checked:i,onChange:a,label:`Place first among equal priorities`}),(0,G.jsx)(`span`,{className:`text-xs text-muted`,children:`LIFO`})]}),(0,G.jsx)(_,{type:`submit`,size:`sm`,disabled:e||!o.ok,children:`Set`}),!o.ok&&n.trim()&&(0,G.jsx)(`span`,{role:`alert`,className:`w-full text-[11px] text-danger`,children:o.msg})]})}var Y=36e5,X=10,Z=e=>Math.max(e,1);function ue(e){return Math.max(0,(e.maxAttempts??0)-Z(e.attempts??0))}function de(e){let t=e.maxAttempts??0,n=e.attempts??0,r=e.backoffConfig,i=r?.maxDelay??Y,a=r?.delay??e.backoff??1e3,o=[];for(let e=Z(n);e<t&&o.length<X;e++){let t=r?.type===`fixed`?a:a*2**e;o.push({attempt:e+1,delayMs:Math.min(t,i)})}return o}function fe({job:e}){let t=e.maxAttempts??0,n=e.attempts??0;if(t<=1)return(0,G.jsxs)(y,{children:[(0,G.jsx)(v,{title:`Backoff`}),(0,G.jsxs)(`p`,{className:`text-xs text-faint`,children:[`No retries configured (max attempts = `,t||1,`).`]})]});if(n>=t)return(0,G.jsxs)(y,{children:[(0,G.jsx)(v,{title:`Backoff schedule`}),(0,G.jsx)(`p`,{className:`text-xs text-faint`,children:`Max attempts reached — no further retries will be scheduled.`})]});let r=e.backoffConfig,i=r?r.type:`exponential (default)`,a=ue(e),o=de(e);return(0,G.jsxs)(y,{children:[(0,G.jsx)(v,{title:`Backoff schedule`,action:(0,G.jsxs)(`span`,{className:`text-xs capitalize text-faint`,children:[i,r?.maxDelay?` · cap ${C(r.maxDelay)}`:``]})}),(0,G.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:o.map(e=>(0,G.jsxs)(`li`,{className:`flex items-center justify-between text-sm`,children:[(0,G.jsxs)(`span`,{className:`text-muted`,children:[`Attempt `,e.attempt,` / `,t]}),(0,G.jsxs)(`span`,{className:`font-mono text-xs text-fg`,children:[`~`,C(e.delayMs)]})]},e.attempt))}),a>X&&(0,G.jsxs)(`p`,{className:`mt-2 text-[11px] text-faint`,children:[`Showing next `,X,` of `,a,` remaining attempts.`]}),(0,G.jsxs)(`p`,{className:`mt-2 text-[11px] text-faint`,children:[`Approximate — the server applies ±`,r?.type===`fixed`?`20`:`50`,`% jitter at retry time, capped at `,C(r?.maxDelay??Y),`.`]})]})}function pe({jobId:e}){let[t,n]=(0,W.useState)(!1),[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(void 0),[l,u]=(0,W.useState)(null),d=async()=>{o(!0),u(null);try{let t=await f.jobChildren(e);c(t.data?.values),i(!0)}catch(e){u(e.message)}finally{o(!1)}},p=()=>{let e=!t;n(e),e&&!r&&!a&&d()},m=s&&typeof s==`object`?Array.isArray(s)?s.length:Object.keys(s).length:0;return(0,G.jsxs)(y,{children:[(0,G.jsx)(v,{title:`Child values`,action:(0,G.jsx)(_,{size:`sm`,variant:`ghost`,onClick:p,children:t?`Hide`:`Show`})}),t?a?(0,G.jsx)(`p`,{className:`text-xs text-faint`,children:`Loading child values…`}):l?(0,G.jsx)(`p`,{className:`text-xs text-danger`,children:l}):m===0?(0,G.jsx)(`p`,{className:`text-xs text-faint`,children:`No child values available.`}):(0,G.jsx)(`pre`,{className:`max-h-64 overflow-auto rounded-lg bg-surface-2 p-3 font-mono text-xs text-muted`,children:JSON.stringify(s,null,2)}):(0,G.jsx)(`p`,{className:`text-xs text-faint`,children:`Resolved return values from this flow job's children.`})]})}function me({data:e,busy:t,editable:n,readOnlyReason:r,onSave:i}){let[a,o]=(0,W.useState)(()=>JSON.stringify(e??null,null,2)),[s,c]=(0,W.useState)(null),l=(0,W.useRef)(a);return(0,W.useEffect)(()=>{let t=JSON.stringify(e??null,null,2);t!==l.current&&(l.current=t,o(t),c(null))},[e]),(0,G.jsxs)(y,{children:[(0,G.jsx)(v,{title:`Data`,action:n?(0,G.jsx)(_,{size:`sm`,disabled:t,onClick:()=>{let e;try{e=JSON.parse(a)}catch(e){c(`Invalid JSON: ${e.message}`);return}c(null),i(e)},children:`Save data`}):void 0}),(0,G.jsx)(`textarea`,{"aria-label":`Job data JSON`,name:`job-data-json`,value:a,onChange:e=>o(e.target.value),readOnly:!n,spellCheck:!1,rows:8,className:`w-full resize-y rounded-lg border border-line bg-surface-2 p-3 font-mono text-xs text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`}),!n&&(0,G.jsx)(`p`,{className:`mt-2 text-xs text-faint`,children:r??`Data is read-only after a job starts processing or leaves the runnable queue.`}),s&&(0,G.jsx)(`p`,{role:`alert`,className:`mt-2 text-xs text-danger`,children:s})]})}function he(e){return e===`waiting`||e===`prioritized`||e===`delayed`}var ge=[`__parentId`,`__parentQueue`,`__childrenIds`,`__flowParentId`,`__flowParentIds`];function _e(e,t){if(!he(e))return`Data is read-only after a job starts processing or leaves the runnable queue.`;let n=t.data,r=typeof n==`object`&&!!n&&!Array.isArray(n)&&ge.some(e=>Object.hasOwn(n,e));return t.parentId||(t.childrenIds?.length??0)>0||r?`Data is read-only for Flow jobs because Bunqueue v2.9.3 replaces the full payload and would remove structural metadata.`:null}var ve=3e4;function Q(){let{token:e}=s.getState();return{baseUrl:o(),authorization:e?`Bearer ${e}`:void 0}}function ye(e,t){return e.baseUrl===t.baseUrl&&e.authorization===t.authorization}function be(e,t,n){return t.aborted&&!n.aborted?new u(`Request timed out`,0):e}async function xe(e,t,n,r){let i=AbortSignal.timeout(ve),a=AbortSignal.any([r,i]),o=new Headers(n.headers);e.authorization&&o.set(`Authorization`,e.authorization),n.body!=null&&!o.has(`Content-Type`)&&o.set(`Content-Type`,`application/json`);let s;try{a.throwIfAborted(),s=await fetch(`${e.baseUrl}${t}`,{...n,headers:o,signal:a}),a.throwIfAborted()}catch(e){throw be(e,i,r)}if(s.status===204)return;let c;try{c=await s.text(),a.throwIfAborted()}catch(e){throw be(e,i,r)}let l,d=!1;if(c)try{l=JSON.parse(c)}catch{d=!0}if(!s.ok){let t=!d&&l&&typeof l==`object`?l.error:void 0;throw s.status===401&&typeof window<`u`&&window.dispatchEvent(new window.CustomEvent(`auth:required`,{detail:{scope:`server`,auth:e.authorization,target:e.baseUrl}})),new u(typeof t==`string`?t:`HTTP ${s.status}`,s.status)}if(c){if(d)throw new u(`Invalid JSON response (HTTP ${s.status})`,s.status);if(l&&typeof l==`object`&&l.ok===!1){let e=l.error;throw new u(typeof e==`string`?e:`Operation failed`,s.status)}return l}}function Se(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new u(`Invalid logs response: expected an object envelope`,200);let t=e;if(t.ok!==!0||!t.data||typeof t.data!=`object`)throw new u(`Invalid logs response: expected { ok: true, data }`,200);let n=t.data;if(!Array.isArray(n.logs)||typeof n.count!=`number`||!Number.isSafeInteger(n.count)||n.count<0)throw new u(`Invalid logs response: expected logs[] and a non-negative count`,200);return{logs:n.logs,count:n.count}}function Ce(e){let{logs:t,count:n,loading:r,busy:i,error:a,message:o,level:s,draftRevision:c}=e;return(0,G.jsxs)(y,{children:[(0,G.jsx)(v,{title:`Logs`,action:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`font-mono text-xs text-faint`,children:n}),(0,G.jsx)(_,{size:`sm`,variant:`ghost`,disabled:r||i,onClick:e.load,children:`Refresh`}),(0,G.jsx)(_,{size:`sm`,variant:`danger`,disabled:i||t.length===0,onClick:e.clear,children:`Clear logs`})]})}),a&&(0,G.jsx)(`p`,{className:`mb-2 text-xs text-danger`,children:a}),t.length===0?(0,G.jsx)(`p`,{className:`text-xs text-faint`,children:`No log lines recorded for this job.`}):(0,G.jsx)(`ol`,{className:`flex max-h-64 flex-col gap-1 overflow-auto rounded-lg bg-surface-2 p-3`,children:t.map((e,t)=>(0,G.jsx)(`li`,{className:`whitespace-pre-wrap break-words font-mono text-xs text-muted`,children:typeof e==`string`?e:JSON.stringify(e)},t))}),(0,G.jsxs)(`form`,{className:`mt-3 flex gap-2`,onSubmit:t=>{t.preventDefault();let n=t.currentTarget.elements.namedItem(`job-log-message`),r=t.currentTarget.elements.namedItem(`job-log-level`);e.add(n?.value??o,r?.value??s)},children:[(0,G.jsx)(D,{"aria-label":`Log message`,name:`job-log-message`,autoComplete:`off`,value:o,onInput:t=>{c.current+=1,e.setMessage(t.currentTarget.value)},placeholder:`Add a log line…`,className:`h-8 flex-1 text-xs`}),(0,G.jsxs)(E,{"aria-label":`Log level`,name:`job-log-level`,value:s,onChange:t=>{c.current+=1,e.setLevel(t.target.value)},className:`h-8 w-24 text-xs`,children:[(0,G.jsx)(`option`,{value:`info`,children:`info`}),(0,G.jsx)(`option`,{value:`warn`,children:`warn`}),(0,G.jsx)(`option`,{value:`error`,children:`error`})]}),(0,G.jsx)(_,{type:`submit`,size:`sm`,disabled:i||o.trim()===``,children:`Add`})]})]})}function we({jobId:e}){let t=s(e=>e.baseUrl),n=s(e=>e.token),[r,i]=(0,W.useState)([]),[a,l]=(0,W.useState)(0),[d,f]=(0,W.useState)(!1),[p,m]=(0,W.useState)(null),[h,g]=(0,W.useState)(``),[_,v]=(0,W.useState)(`info`),[y,b]=(0,W.useState)(!1),x=(0,W.useRef)(!1),S=(0,W.useRef)(null),C=(0,W.useRef)(0),w=(0,W.useRef)(null),T=(0,W.useRef)(0),E=(0,W.useRef)(null),D=(0,W.useRef)(!1),O=(0,W.useRef)(0);(0,W.useEffect)(()=>{x.current=!0,S.current=e;let t=()=>{C.current+=1,w.current?.abort(),w.current=null,T.current+=1,E.current?.abort(),E.current=null,D.current=!1,O.current+=1,i([]),l(0),f(!1),m(null),g(``),b(!1)},n=s.subscribe((e,n)=>{e.baseUrl===n.baseUrl&&e.token===n.token||t()});return t(),()=>{x.current=!1,S.current=null,n(),C.current+=1,w.current?.abort(),w.current=null,T.current+=1,E.current?.abort(),E.current=null,D.current=!1}},[e]);let k=(0,W.useCallback)(async r=>{w.current?.abort();let a=new AbortController;w.current=a;let u=++C.current,d=s.getState(),p=r?.target??(d.baseUrl===t&&d.token===n?{baseUrl:o(),authorization:n?`Bearer ${n}`:void 0}:Q()),h=()=>x.current&&S.current===e&&u===C.current&&!a.signal.aborted&&ye(p,Q());f(!0),m(null);try{let t=Se(await xe(p,`/jobs/${c(e)}/logs`,{},a.signal));return h()?(i(t.logs),l(t.count),!0):!1}catch(e){if(!h())return!1;let t=e instanceof Error?e.message:String(e);return m(r?.acceptedLabel?`${r.acceptedLabel} succeeded, but couldn't reload logs: ${t}`:t),!1}finally{u===C.current&&(w.current===a&&(w.current=null),x.current&&f(!1))}},[e,t,n]);(0,W.useEffect)(()=>{k()},[k]);let A=async(t,n,r)=>{if(D.current)return;D.current=!0;let i=new AbortController;E.current=i;let a=++T.current,o=Q();C.current+=1,w.current?.abort(),w.current=null,f(!1),b(!0),m(null);let s=()=>x.current&&S.current===e&&a===T.current&&!i.signal.aborted&&ye(o,Q());try{let a=await xe(o,`/jobs/${c(e)}/logs`,t,i.signal);if(!a||typeof a!=`object`||Array.isArray(a)||a.ok!==!0)throw new u(`Invalid log mutation response: expected { ok: true }`,200);if(!s())return;r(),await k({acceptedLabel:n,target:o})}catch(e){s()&&m(e instanceof Error?e.message:String(e))}finally{a===T.current&&(D.current=!1,E.current===i&&(E.current=null),x.current&&b(!1))}},j=async(e=h,t=_)=>{if(D.current)return;let n=e.trim();if(!n)return;let r=t===`warn`||t===`error`?t:`info`,i=O.current;g(e),v(r),await A({method:`POST`,body:JSON.stringify({message:n,level:r})},`Log addition`,()=>{O.current===i&&g(``)})},M=async()=>{D.current||window.confirm(`Clear all logs for this job?`)&&await A({method:`DELETE`},`Log clearing`,()=>{i([]),l(0)})};return(0,G.jsx)(Ce,{logs:r,count:a,loading:d,busy:y,error:p,message:h,level:_,draftRevision:O,setMessage:g,setLevel:v,load:()=>void k(),clear:()=>void M(),add:(e,t)=>void j(e,t)})}function Te({timeline:e}){let t=e??[];return(0,G.jsxs)(y,{children:[(0,G.jsx)(v,{title:`Timeline`}),t.length===0?(0,G.jsx)(`p`,{className:`text-xs text-faint`,children:`No state transitions recorded yet.`}):(0,G.jsx)(`ol`,{className:`flex flex-col gap-0`,children:t.map((e,t)=>(0,G.jsxs)(`li`,{className:`border-b border-line/60 py-2 last:border-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(h,{status:e.state}),e.attempt!=null&&(0,G.jsxs)(`span`,{className:`font-mono text-[11px] text-faint`,children:[`attempt `,e.attempt]})]}),(0,G.jsx)(`span`,{className:`font-mono text-xs text-muted`,children:w(e.timestamp)})]}),(e.worker||e.error)&&(0,G.jsxs)(`div`,{className:`mt-1 pl-0.5`,children:[e.worker&&(0,G.jsx)(`div`,{className:`font-mono text-[11px] text-faint`,children:e.worker}),e.error&&(0,G.jsx)(`div`,{className:`mt-0.5 text-xs text-danger/90`,children:e.error})]})]},t))})]})}function Ee(e){let t=e.timeline??[];for(let e=t.length-1;e>=0;e--){let n=t[e];if(n.state===`failed`&&n.error)return{message:n.error,attempt:n.attempt,timestamp:n.timestamp}}return e.failedReason?{message:e.failedReason}:null}function De({job:e,result:t,resultError:n,loading:r,notFound:i,busy:a,lookup:o,act:s}){if(r&&!e)return(0,G.jsx)(b,{label:`Loading job…`});if(i)return(0,G.jsx)(x,{title:`Job not found`,hint:`Check the ID, or the job may have been removed.`});if(!e)return(0,G.jsx)(x,{title:`No job loaded`,hint:`Enter a job ID above to inspect it.`});let c=e.state,l=Ee(e),u=e.stacktrace?.length?re(e.stacktrace):null,d=(e.childrenIds?.length??0)>0,p=_e(c,e),m=c===`failed`,h=l||u?(0,G.jsxs)(y,{children:[(0,G.jsx)(v,{title:`Error`}),l&&(0,G.jsxs)(`div`,{className:`mb-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-danger`,children:l.message}),(0,G.jsxs)(`p`,{className:`mt-1 text-[11px] text-faint`,children:[l.attempt==null?``:`Attempt ${l.attempt} · `,w(l.timestamp)]})]}),u&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`pre`,{className:`max-h-80 overflow-auto whitespace-pre-wrap rounded-lg bg-surface-2 p-3 font-mono text-xs text-danger/90`,children:u.text}),u.truncated&&(0,G.jsxs)(`p`,{className:`mt-2 text-xs text-faint`,children:[`Stack preview truncated (`,u.displayedLines,` of `,u.totalLines,` `,`lines, 262,144 characters maximum). Download JSON for the complete stored stack.`]})]})]}):null;return(0,G.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-3`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-6 lg:col-span-2`,children:[(0,G.jsx)(Oe,{job:e}),m&&h,(0,G.jsx)(me,{data:e.data,busy:a,editable:p===null,readOnlyReason:p??void 0,onSave:t=>s(`Data`,()=>f.updateJobData(e.id,t))},`data-${e.id}`),c===`completed`&&(0,G.jsx)(ke,{jobId:e.id,result:t,resultError:n,loading:r,onRetry:()=>o(e.id,`id`)}),!m&&h,(0,G.jsx)(we,{jobId:e.id},`logs-${e.id}`),d&&(0,G.jsx)(pe,{jobId:e.id},`children-${e.id}`),(0,G.jsx)(Te,{timeline:e.timeline}),(0,G.jsx)(fe,{job:e})]}),(0,G.jsx)(`div`,{className:`order-first lg:order-none`,children:(0,G.jsx)(ce,{job:e,busy:a,act:s})})]})}function Oe({job:e}){return(0,G.jsxs)(y,{children:[(0,G.jsxs)(`div`,{className:`mb-4 flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`div`,{className:`truncate font-mono text-sm text-fg`,children:e.id}),(0,G.jsx)(T,{value:e.id})]}),(0,G.jsx)(`div`,{className:`mt-1 font-mono text-xs text-faint`,children:e.queue})]}),(0,G.jsx)(h,{status:e.state??`unknown`})]}),(0,G.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm sm:grid-cols-3`,children:[(0,G.jsx)($,{label:`Priority`,value:String(e.priority??0)}),(0,G.jsx)($,{label:`Name`,value:e.name??`default`}),(0,G.jsx)($,{label:`Attempts`,value:`${e.attempts??0} / ${e.maxAttempts??`?`}`}),(0,G.jsx)($,{label:`Progress`,value:`${e.progress??0}%`}),(0,G.jsx)($,{label:`Created`,value:w(e.createdAt)}),(0,G.jsx)($,{label:`Started`,value:w(e.startedAt??void 0)}),(0,G.jsx)($,{label:`Completed`,value:w(e.completedAt??void 0)}),(0,G.jsx)($,{label:`Duration`,value:C(e.startedAt&&e.completedAt?e.completedAt-e.startedAt:void 0)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-[11px] uppercase tracking-wider text-faint`,children:`Custom ID`}),(0,G.jsxs)(`dd`,{className:`flex items-center gap-1 text-fg`,children:[(0,G.jsx)(`span`,{className:`truncate font-mono`,children:e.customId??`—`}),e.customId&&(0,G.jsx)(T,{value:e.customId})]})]})]})]})}function ke({jobId:e,result:t,resultError:n,loading:r,onRetry:i}){let a=t.fetched&&t.value!==void 0&&t.value!==null;return(0,G.jsxs)(y,{children:[(0,G.jsx)(v,{title:`Result`,action:a?(0,G.jsx)(je,{value:t.value,filename:`job-${e}-result`}):void 0}),a?(0,G.jsx)(Ae,{value:t.value}):n?(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,G.jsxs)(`p`,{className:`text-xs text-danger`,children:[`Couldn't load result — `,n]}),(0,G.jsx)(_,{size:`sm`,disabled:r,onClick:i,children:`Retry`})]}):(0,G.jsx)(`p`,{className:`text-xs text-faint`,children:`No result stored for this job.`})]})}function $({label:e,value:t}){return(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-[11px] uppercase tracking-wider text-faint`,children:e}),(0,G.jsx)(`dd`,{className:`text-fg`,children:t})]})}function Ae({value:e}){return(0,G.jsx)(`pre`,{className:`max-h-64 overflow-auto rounded-lg bg-surface-2 p-3 font-mono text-xs text-muted`,children:JSON.stringify(e??null,null,2)})}function je({value:e,filename:t}){return(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(T,{value:JSON.stringify(e??null,null,2)}),(0,G.jsx)(g,{"aria-label":`Download JSON`,title:`Download JSON`,onClick:()=>A(t,e??null),children:(0,G.jsx)(m,{className:`size-3.5`})})]})}function Me(e){if(typeof e!=`object`||!e||Array.isArray(e))return e;let t={...e};for(let e of d)delete t[e];return t}function Ne(e){let t={};return typeof e.priority==`number`&&(t.priority=e.priority),typeof e.maxAttempts==`number`&&(t.maxAttempts=e.maxAttempts),typeof e.backoff==`number`&&(t.backoff=e.backoff),e.backoffConfig&&typeof e.backoffConfig.delay==`number`&&(t.backoffConfig={type:e.backoffConfig.type,delay:e.backoffConfig.delay},typeof t.backoff!=`number`&&(t.backoff=e.backoffConfig.delay)),typeof e.timeout==`number`&&(t.timeout=e.timeout),typeof e.removeOnComplete==`boolean`&&(t.removeOnComplete=e.removeOnComplete),typeof e.removeOnFail==`boolean`&&(t.removeOnFail=e.removeOnFail),typeof e.ttl==`number`&&(t.ttl=e.ttl),Array.isArray(e.tags)&&e.tags.length&&(t.tags=[...e.tags]),typeof e.groupId==`string`&&e.groupId&&(t.groupId=e.groupId),{clone:{queue:e.queue??``,name:e.name,dataText:JSON.stringify(Me(e.data??{}),null,2),options:t}}}function Pe({job:e,result:t,idInput:n,lookupBy:r,loading:a,busy:o,onInputChange:s,onModeChange:c,onSubmit:l}){let u=!!(e&&((e.childrenIds?.length??0)>0||e.parentId));return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(S,{title:`Job Inspector`,description:`Look up any job by ID and drive its full lifecycle.`,actions:e?(0,G.jsxs)(G.Fragment,{children:[u&&(0,G.jsx)(i,{to:`/flows?root=${encodeURIComponent(e.id)}`,className:`rounded-lg border border-line px-3 py-1.5 text-sm text-muted hover:bg-surface-2 hover:text-fg`,children:`View flow`}),(0,G.jsx)(i,{to:`/add-job`,state:Ne(e),title:`Enqueue a new job pre-filled from this one`,className:`rounded-lg border border-line px-3 py-1.5 text-sm text-muted hover:bg-surface-2 hover:text-fg`,children:`Clone`}),(0,G.jsxs)(_,{size:`sm`,onClick:()=>A(`job-${e.id}`,t.fetched?{...e,result:t.value}:e),children:[(0,G.jsx)(m,{className:`size-3.5`}),` Download JSON`]})]}):void 0}),(0,G.jsxs)(`div`,{className:`mb-6 flex flex-wrap items-center gap-2`,children:[(0,G.jsxs)(E,{name:`job-lookup-mode`,autoComplete:`off`,value:r,"aria-label":`Lookup mode`,onChange:e=>c(e.target.value),className:`w-40`,children:[(0,G.jsx)(`option`,{value:`id`,children:`By job ID`}),(0,G.jsx)(`option`,{value:`custom`,children:`By custom ID`})]}),(0,G.jsxs)(`div`,{className:`relative min-w-56 flex-1`,children:[(0,G.jsx)(p,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-faint`}),(0,G.jsx)(`input`,{value:n,"aria-label":r===`custom`?`Custom job ID`:`Job ID`,name:`job-lookup-id`,autoComplete:`off`,spellCheck:!1,maxLength:1024,onInput:e=>s(e.currentTarget.value),onKeyDown:e=>e.key===`Enter`&&l(n),placeholder:r===`custom`?`custom / idempotency id — Enter to look up`:`job id (UUID) — Enter to look up`,className:`h-9 w-full rounded-lg border border-line bg-surface pl-9 pr-3 font-mono text-sm text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`})]}),(0,G.jsx)(_,{variant:`accent`,disabled:a||o,onClick:()=>l(n),children:`Look up`})]})]})}function Fe({state:e,lookup:t,setParams:n,locationKey:r,idParam:i,customParam:a,jobBelongsToCurrentTarget:o,connectionBaseUrl:s,connectionToken:c}){(0,W.useEffect)(()=>{if(e.internalEmptyUrlPending.current){!i&&!a&&(e.internalEmptyUrlPending.current=!1,e.preservedEmptyLocationKey.current=r);return}if(!(!i&&!a&&e.preservedEmptyLocationKey.current===r))if(e.preservedEmptyLocationKey.current=null,a)if(e.job?.customId===a&&o)e.setLookupBy(`id`),e.setIdInput(e.job.id),n({id:e.job.id},{replace:!0});else{e.setLookupBy(`custom`),e.setIdInput(a);let n=e.lookupIdentity.current;(n?.mode!==`custom`||n.key!==a)&&t(a,`custom`,!1,void 0,!0)}else if(i&&(i!==e.job?.id||!o)){e.setLookupBy(`id`),e.setIdInput(i);let n=e.lookupIdentity.current;(n?.mode!==`id`||n.key!==i)&&t(i,`id`,!1,void 0,!0)}else!i&&!a&&(e.lookupGen.current+=1,e.lookupAbort.current?.abort(),e.lookupAbort.current=null,e.lookupIdentity.current=null,e.actionGen.current+=1,e.jobTarget.current=null,e.setJob(null),e.setResult({fetched:!1,value:void 0}),e.setResultError(null),e.setNotFound(!1),e.setMsg(null),e.setLoading(!1),e.setLookupBy(`id`),e.setIdInput(``))},[i,a,e.job?.id,e.job?.customId,o,r,s,c])}var Ie={fetched:!1,value:void 0};function Le(e,t){let[n,r]=(0,W.useState)(e??t??``),[i,a]=(0,W.useState)(e?`custom`:`id`),[o,c]=(0,W.useState)(null),[l,u]=(0,W.useState)(Ie),[d,f]=(0,W.useState)(null),[p,m]=(0,W.useState)(!1),[h,g]=(0,W.useState)(!1),[_,v]=(0,W.useState)(null),[y,b]=(0,W.useState)(!1),x=(0,W.useRef)(0),S=(0,W.useRef)(null),C=(0,W.useRef)(null),w=(0,W.useRef)(null),T=(0,W.useRef)(!1),E=(0,W.useRef)(null),D=(0,W.useRef)(!1),O=(0,W.useRef)(0),k=(0,W.useRef)(!1),A=(0,W.useRef)(null);return(0,W.useEffect)(()=>{D.current=!0;let e=s.subscribe((e,t)=>{e.baseUrl===t.baseUrl&&e.token===t.token||(x.current+=1,S.current?.abort(),S.current=null,C.current=null,O.current+=1,A.current=null,k.current=!1,w.current=null,T.current=!1,E.current=null,c(null),u(Ie),f(null),g(!1),v(null),m(!1),b(!1))});return()=>{D.current=!1,e(),x.current+=1,S.current?.abort(),S.current=null,C.current=null,O.current+=1,A.current=null,k.current=!1}},[]),{idInput:n,setIdInput:r,lookupBy:i,setLookupBy:a,job:o,setJob:c,result:l,setResult:u,resultError:d,setResultError:f,loading:p,setLoading:m,notFound:h,setNotFound:g,msg:_,setMsg:v,busy:y,setBusy:b,lookupGen:x,lookupAbort:S,lookupIdentity:C,jobTarget:w,internalEmptyUrlPending:T,preservedEmptyLocationKey:E,mounted:D,actionGen:O,actionBusy:k,actionLockOwner:A}}function Re(){let e=r(),[n,i]=t(),a=s(e=>e.baseUrl),c=s(e=>e.token),l=Le(n.get(`custom`),n.get(`id`)),d=se(l,i),f=n.get(`id`),p=n.get(`custom`),m={baseUrl:o(),authorization:c?`Bearer ${c}`:void 0},h=V(l.jobTarget.current,m);return Fe({state:l,lookup:d,setParams:i,locationKey:e.key,idParam:f,customParam:p,jobBelongsToCurrentTarget:h,connectionBaseUrl:a,connectionToken:c}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(Pe,{job:l.job,result:l.result,idInput:l.idInput,lookupBy:l.lookupBy,loading:l.loading,busy:l.busy,onInputChange:l.setIdInput,onModeChange:l.setLookupBy,onSubmit:(e,t=l.lookupBy)=>{let n=e.trim();if(!(!n||l.actionBusy.current)){if(t===`id`?f===n&&p===null:p===n&&f===null){d(n,t);return}i(t===`custom`?{custom:n}:{id:n})}}}),l.msg&&(0,G.jsx)(`div`,{role:`status`,className:l.msg.ok?`mb-4 text-sm text-success`:`mb-4 text-sm text-danger`,children:l.msg.text}),(0,G.jsx)(De,{job:l.job,result:l.result,resultError:l.resultError,loading:l.loading,notFound:l.notFound,busy:l.busy,lookup:d,act:async(e,t,n)=>{if(!l.job||l.actionBusy.current||l.lookupAbort.current)return;let r=B();if(!V(l.jobTarget.current,r)||n&&!window.confirm(n))return;let a=++l.actionGen.current,o=l.job.id;l.actionLockOwner.current=a,l.actionBusy.current=!0,l.setBusy(!0),l.setMsg(null);let s=()=>l.mounted.current&&a===l.actionGen.current&&V(r,B())&&V(l.jobTarget.current,r);try{let n=await t();if(!n||typeof n!=`object`||Array.isArray(n)||n.ok!==!0)throw new u(`Invalid job mutation response: expected { ok: true }`,200);if(!s())return;l.setMsg({ok:!0,text:`${e} ✓`}),e===`Cancel`?(l.internalEmptyUrlPending.current=!0,l.preservedEmptyLocationKey.current=null,l.lookupGen.current+=1,l.jobTarget.current=null,l.setJob(null),l.setResult({fetched:!1,value:void 0}),l.setResultError(null),i({},{replace:!0})):await d(o,`id`,!0,a)}catch(e){s()&&l.setMsg({ok:!1,text:e.message})}finally{l.actionLockOwner.current===a&&(l.actionLockOwner.current=null,l.actionBusy.current=!1,l.mounted.current&&l.setBusy(!1))}}})]})}export{Re as JobInspector};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{f as t,g as n,r,t as i}from"./react-vendor-DfC0iyIS.js";import{t as a}from"./bq-CSX8DSME.js";import{T as o}from"./icons-C1HVBnFn.js";import{t as s}from"./StatusBadge-cYUkK-4P.js";import{t as c}from"./api-Bbo86MB6.js";import{n as l}from"./usePolledData-Dp_ynL9f.js";import{i as u,r as d}from"./feedback-Dxfj-Fy1.js";import{t as f}from"./PageHeader-DD4vnVog.js";import{a as p,c as m,d as h,l as g,s as _,t as v}from"./format-Cg7VCIZW.js";import{r as y}from"./index-CxzFSZj3.js";import{a as b,i as x}from"./form-Dy-an7ew.js";import{r as S}from"./flowMutationSafety-YKTHxqKv.js";import{t as C}from"./promisePool-BVfQ9n9Q.js";import{i as w,n as T,r as E,t as D}from"./classicJobsData-BimIyQky.js";var O=e(n(),1),k=i();function A({rows:e,emptyMessage:t}){return(0,k.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,k.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,k.jsx)(`thead`,{children:(0,k.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,k.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Job ID`}),(0,k.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Name`}),(0,k.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queue`}),(0,k.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Status`}),(0,k.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Priority`}),(0,k.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Created`}),(0,k.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Duration`}),(0,k.jsx)(`th`,{className:`w-12 px-5 py-3`})]})}),(0,k.jsx)(`tbody`,{children:e.length===0?(0,k.jsx)(`tr`,{children:(0,k.jsx)(`td`,{colSpan:8,className:`px-5 py-12 text-center text-sm text-faint`,children:t})}):e.map(e=>(0,k.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,k.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs`,children:(0,k.jsx)(r,{to:`/job?id=${encodeURIComponent(e.id)}`,className:`text-accent/90 hover:text-accent hover:underline`,title:`Inspect job ${e.id}`,children:e.id})}),(0,k.jsx)(`td`,{className:`px-5 py-3 text-fg`,children:e.name??w(e.data)??`default`}),(0,k.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queue}),(0,k.jsx)(`td`,{className:`px-5 py-3`,children:(0,k.jsx)(s,{status:String(e.state??e.status??`waiting`)})}),(0,k.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:e.priority??0}),(0,k.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:g(e.createdAt)}),(0,k.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:p(h(e.startedAt??void 0,e.completedAt??void 0))}),(0,k.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,k.jsx)(`span`,{className:`text-xs text-faint`,title:S,children:`Delete unavailable`})})]},`${e.queue}:${e.id}`))})]})})}var j=8;function M(){let[e]=t(),[n,r]=(0,O.useState)(e.get(`queue`)??`__all__`),[i,s]=(0,O.useState)(`all`),[p,h]=(0,O.useState)(``),{data:g,error:S,refetch:M}=l(E,[],{intervalMs:3e4}),{data:N,error:P,refetch:F}=l(()=>c.overview(),[]),I=(0,O.useMemo)(()=>(g?.queues??[]).map(e=>e.name),[g]),L=`${n}\u0000${i}\u0000${JSON.stringify(I)}`,{data:R,error:z,loading:B,refetch:V}=l((0,O.useCallback)(async e=>{if(n===`__all__`&&!g)return null;let t=n===`__all__`?I:[n];if(n===`__all__`&&t.length>100)return{scopeKey:L,jobs:[],failures:[],queueCount:t.length,blockedReason:`All-queue job browsing is limited to 100 queues; ${_(t.length)} were discovered. Select one queue to avoid an unsafe request fan-out.`};let r=i===`all`?void 0:[i],o=a.createServerTargetClient(a.captureServerRequestTarget(),e),s=await C(t,j,async t=>(e.throwIfAborted(),(await o.jobsList(t,r,40)).jobs.map(e=>({...e,stacktrace:e.stacktrace??void 0,queue:e.queue??t}))),e);e.throwIfAborted();let c=[],l=[];return s.forEach((e,n)=>{e.status===`fulfilled`?c.push(...e.value):l.push({queue:t[n],message:e.reason instanceof Error?e.reason.message:String(e.reason)})}),{scopeKey:L,jobs:c.sort((e,t)=>(t.createdAt??0)-(e.createdAt??0)),failures:l,queueCount:t.length,blockedReason:null}},[n,i,g,I,L]),[L],{intervalMs:15e3}),H=R?.scopeKey===L?R:null,U=H?.blockedReason?null:H?.jobs??null,{rows:W,matchingCount:G}=(0,O.useMemo)(()=>{let e=U??[],t=p.trim().toLowerCase(),n=t?e.filter(e=>typeof e.id==`string`&&e.id.toLowerCase().includes(t)||typeof e.name==`string`&&e.name.toLowerCase().includes(t)||(w(e.data)?.toLowerCase().includes(t)??!1)):e;return{rows:n.slice(0,100),matchingCount:n.length}},[U,p]),K=N?.stats,q=K?v(K.totalCompleted,K.totalFailed):null,J=e=>K?_(e):`—`,Y=!!H&&H.queueCount>0&&H.failures.length===H.queueCount,X=n===`__all__`&&!g&&!S||B&&!H&&!z,Z=`No jobs found.`;return H?.blockedReason?Z=H.blockedReason:n===`__all__`&&S&&!g?Z=`Queue discovery unavailable — ${S.message}`:z&&!H?Z=`Could not load jobs — ${z.message}`:Y?Z=`Could not load jobs from any of the ${H.queueCount} queues.`:p.trim()&&H?.failures.length?Z=`No matching jobs in the queue results that could be loaded.`:p.trim()&&(Z=`No jobs match this search.`),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(f,{title:`Jobs Explorer`,description:`Browse, inspect, and manage individual jobs.`,live:!!H&&!S&&!P&&!z&&!H.blockedReason&&H.failures.length===0}),S&&(0,k.jsx)(u,{message:`Queue discovery unavailable — ${S.message}`,onRetry:M}),P&&(0,k.jsx)(u,{message:`Job totals unavailable — ${P.message}`,onRetry:F}),z&&(0,k.jsx)(u,{message:`Could not load jobs — ${z.message}`,onRetry:V}),H?.blockedReason&&(0,k.jsx)(u,{message:H.blockedReason}),!!H?.failures.length&&(0,k.jsx)(u,{message:`Could not load jobs from ${H.failures.length} of ${H.queueCount} queues: ${H.failures.slice(0,3).map(e=>`${e.queue} (${e.message})`).join(`, `)}${H.failures.length>3?`, …`:``}`,onRetry:V}),(0,k.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-6`,children:[(0,k.jsx)(y,{label:`Total`,value:K?_(K.totalCompleted+K.totalFailed+K.waiting+K.active):`—`,compact:!0}),(0,k.jsx)(y,{label:`Waiting`,value:J(K?.waiting),tone:`amber`,compact:!0}),(0,k.jsx)(y,{label:`Active`,value:J(K?.active),tone:`blue`,compact:!0}),(0,k.jsx)(y,{label:`Completed`,value:J(K?.totalCompleted),tone:`green`,compact:!0}),(0,k.jsx)(y,{label:`Failed`,value:J(K?.totalFailed),tone:K?.totalFailed?`red`:`default`,compact:!0}),(0,k.jsx)(y,{label:`Error Rate`,value:q==null?`—`:m(q),tone:q==null?`default`:q>.05?`red`:`green`,compact:!0})]}),(0,k.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-3`,children:[(0,k.jsx)(`div`,{className:`w-48`,children:(0,k.jsxs)(b,{value:n,"aria-label":`Queue`,name:`jobs-queue`,autoComplete:`off`,onChange:e=>r(e.target.value),children:[(0,k.jsx)(`option`,{value:D,children:`All Queues`}),(g?.queues??[]).map(e=>(0,k.jsx)(`option`,{value:e.name,children:e.name},e.name))]})}),(0,k.jsx)(x,{options:T,value:i,onChange:s}),(0,k.jsxs)(`div`,{className:`relative ml-auto min-w-56 flex-1 md:max-w-xs`,children:[(0,k.jsx)(o,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-faint`}),(0,k.jsx)(`input`,{value:p,onChange:e=>h(e.target.value),"aria-label":`Search jobs`,name:`jobs-search`,autoComplete:`off`,placeholder:`Search by ID or name…`,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`})]})]}),H&&!H.blockedReason&&(0,k.jsxs)(`p`,{role:`status`,className:`mb-3 text-xs text-faint`,children:[n===`__all__`?`Queried all ${_(H.queueCount)} discovered queues`:`Queried ${n}`,` `,`· up to `,40,` recent jobs per queue`,G>100?` · showing the newest 100 of ${_(G)} matches`:``]}),X?(0,k.jsx)(d,{label:`Loading jobs…`}):(0,k.jsx)(A,{rows:W,emptyMessage:Z})]})}export{M as Jobs};