bunqueue-dashboard 0.0.42 → 0.0.43

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 (49) hide show
  1. package/README.md +5 -4
  2. package/agent/flow/routes.ts +2 -0
  3. package/agent/flow/service.ts +7 -2
  4. package/agent/managedConnection.ts +35 -0
  5. package/agent/manager/config.ts +1 -1
  6. package/agent/queue/runtime.ts +2 -2
  7. package/agent/workflow/runtime.ts +2 -6
  8. package/agent/workflow/runtimeConfig.ts +2 -2
  9. package/dist/.vite/manifest.json +40 -39
  10. package/dist/assets/{Alerts-BvWBv-z7.js → Alerts-C961Al5D.js} +1 -1
  11. package/dist/assets/{Benchmark-BywalSmU.js → Benchmark-DQNZV7dM.js} +1 -1
  12. package/dist/assets/{CopilotPanel-CH2jbbYA.js → CopilotPanel-Dlm8XwBj.js} +1 -1
  13. package/dist/assets/{Database-BzEkXws0.js → Database-DGM2BIHy.js} +1 -1
  14. package/dist/assets/{Diagnostics-CPqhV3er.js → Diagnostics-_Sh3UyaT.js} +1 -1
  15. package/dist/assets/{Dlq-CbLN0zQ5.js → Dlq-mtInIoTh.js} +1 -1
  16. package/dist/assets/{DlqControl-C5Bgzmk0.js → DlqControl-Lq9ISb9b.js} +1 -1
  17. package/dist/assets/{DlqPro-Cgaxtuwh.js → DlqPro-0_75vrd1.js} +1 -1
  18. package/dist/assets/Flows-CE7KzaFN.js +2 -0
  19. package/dist/assets/{JobInspector-DsOt4mLJ.js → JobInspector-DyWZk1eW.js} +1 -1
  20. package/dist/assets/{Jobs-BTMpbAHD.js → Jobs-ELSH1Wbd.js} +1 -1
  21. package/dist/assets/JobsPro-BlWwDeFN.js +1 -0
  22. package/dist/assets/{Logs-uuzU5ohI.js → Logs-DMukqmHy.js} +1 -1
  23. package/dist/assets/{LogsPro-DHWbhWyq.js → LogsPro-BfYbmZHi.js} +1 -1
  24. package/dist/assets/{McpServer-BqmbhrKh.js → McpServer-DNrOEp9j.js} +1 -1
  25. package/dist/assets/{Metrics-DKyBZoFa.js → Metrics-Cm5ZvfTo.js} +1 -1
  26. package/dist/assets/{MetricsPro-BR2ULqIc.js → MetricsPro-C9g1sp-u.js} +1 -1
  27. package/dist/assets/{Overview-ClsyxH2e.js → Overview-CKAA3h9f.js} +1 -1
  28. package/dist/assets/{QueueControl-BW0XXd0B.js → QueueControl-Bvm8GUQa.js} +1 -1
  29. package/dist/assets/{QueueDetail-C1dXXN70.js → QueueDetail-BRDATlp0.js} +1 -1
  30. package/dist/assets/{QueueDetailPro-DDGxs2J2.js → QueueDetailPro-Dkz4-1wn.js} +1 -1
  31. package/dist/assets/{Queues-DkPuIy1C.js → Queues-BV99vr68.js} +1 -1
  32. package/dist/assets/{QueuesOverview-COo-V8D_.js → QueuesOverview-CT6JBaim.js} +1 -1
  33. package/dist/assets/{S3BackupPro-DxNVFvY1.js → S3BackupPro-CjR0y18n.js} +1 -1
  34. package/dist/assets/{ServerControl-B0Po974t.js → ServerControl-BH6Doax0.js} +1 -1
  35. package/dist/assets/{Settings-z9k4EVa_.js → Settings-CL7odwoU.js} +1 -1
  36. package/dist/assets/{Usage-cdWDQUaq.js → Usage-BWZkz7Se.js} +1 -1
  37. package/dist/assets/{UsagePro-DLuwnM8n.js → UsagePro-CoBbI-Cl.js} +1 -1
  38. package/dist/assets/{Workers-CVo9rJ_V.js → Workers-CBEDvXm_.js} +1 -1
  39. package/dist/assets/{WorkersPro-BYaredE9.js → WorkersPro-Dk4NfplT.js} +1 -1
  40. package/dist/assets/flowOperationPolicy-B2Etcb3f.js +1 -0
  41. package/dist/assets/{index-mID5W7vq.js → index-BFW2_47n.js} +3 -3
  42. package/dist/assets/{install-D4uRZ7XA.js → install-oydLpc1T.js} +1 -1
  43. package/dist/index.html +1 -1
  44. package/package.json +8 -5
  45. package/scripts/embedded.gen.ts +164 -164
  46. package/shared/flowOperationPolicy.ts +66 -0
  47. package/dist/assets/Flows-BtUGOaif.js +0 -2
  48. package/dist/assets/JobsPro-BfXTm9gH.js +0 -1
  49. package/dist/assets/jobActions-LQD4KfCc.js +0 -1
@@ -1 +1 @@
1
- import{i as e,t}from"./cn-zFEt5SO8.js";import{g as n,t as r}from"./react-vendor-CvwrP0tU.js";import{o as i}from"./connectionStore-BJLihGaC.js";import{t as a}from"./bq-F5BbTG1T.js";import{b as o,x as s}from"./icons-BVzwsfbG.js";import{n as c}from"./usePolledData-0CVelkl2.js";import{t as l}from"./Button-Ch1W94fJ.js";import{n as u,t as d}from"./Card-CWxrC8OY.js";import{t as f}from"./PageHeader-CvIyaFOO.js";import{n as p,o as m,s as h}from"./format-Cg7VCIZW.js";import{a as g,n as _}from"./index-mID5W7vq.js";import{i as v,n as y,o as b,t as x}from"./form-C4oby9pI.js";import{t as S}from"./AreaChart-DEAalJ6P.js";var C=e(n(),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=r();function re({draft:e,active:n,cleaning:r,cleanResult:i,setField:a,numberInput:o,onClean:s}){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=>a(`mode`,e),disabled:n})}),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:n,onChange:o(`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:n,onChange:o(`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:n,onChange:o(`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:n,onChange:o(`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:n,onChange:o(`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:n,onChange:o(`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:n,onChange:o(`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:n,onChange:o(`processMs`)})})]}),(0,H.jsx)(U,{label:`Durable (fsync each job)`,checked:e.durable,active:n,onChange:e=>a(`durable`,e)}),(0,H.jsx)(U,{label:`Remove on complete`,checked:e.removeOnComplete,active:n,onChange:e=>a(`removeOnComplete`,e)}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,H.jsx)(l,{variant:`ghost`,size:`sm`,disabled:n||r,onClick:s,children:r?`Cleaning…`:`Clean queue`}),i&&(`error`in i?(0,H.jsxs)(`span`,{className:`text-xs text-danger`,children:[`Clean unverified — `,i.error]}):(0,H.jsx)(`span`,{className:t(`text-xs`,i.remaining>0?`text-warning`:`text-success`),children:i.remaining>0?`Cleaned — ${h(i.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:n,tone:r}){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:[n.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(n),children:(0,H.jsx)(`div`,{className:t(`h-full rounded-full transition-[width] motion-reduce:transition-none`,r===`accent`?`bg-accent`:`bg-emerald-500`),style:{width:`${n}%`}})})]})}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}}function me(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 he(e){return async()=>{let{stats:t}=e;for(;e.shouldContinue()&&!(e.runConfig.mode===`duration`&&performance.now()>=e.deadline||e.runConfig.mode===`count`&&t.completed>=e.total);){t.activeWorkers++;let n=[];try{if(n=await ge(e),!e.shouldContinue()){await X(e,n);break}n.length>0&&await _e(e,n)}finally{e.isCurrent()&&t.activeWorkers--}if(!e.shouldContinue())break;if(n.length===0){if(e.runConfig.mode===`count`&&e.producersDone()){e.ownJobIds.size>0&&(t.error??=`${e.ownJobIds.size} benchmark job(s) could not be drained.`);break}await F(50,e.shouldContinue)}}}}async function ge(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 X(e,n),[])}catch(t){return e.isCurrent()&&(e.stats.error??=I(t)),[]}}async function _e(e,t){if(t.some(t=>!e.ownJobIds.has(t.id))&&e.pendingPushes.size>0&&await Promise.allSettled([...e.pendingPushes]),!e.shouldContinue())return X(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 ve(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 X(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 X(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 X(e,n)}}async function ve(e,t,n){let r=await Z(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 X(e,t){if(t.length===0)return;let n=await Z(e,t);n>0&&e.isCurrent()&&(e.stats.error??=`${n} interrupted benchmark job(s) could not be returned to waiting.`)}async function Z(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 ye=0;async function be(e,t,n){if(e.runningRef.current||!e.mountedRef.current)return;e.runningRef.current=!0;let r=++e.runGenerationRef.current,i=n??a.createServerTargetClient(a.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}),Q(e,`error`);return}let r=n.config,a=await pe(i,r.queue,s);if(!o())return;if(!a.ok){e.setLive(a.live),Q(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}),Q(e,`running`);let l={batch:r.batch,blob:`x`.repeat(r.payload),client:i,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=me(l),d=he(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`&&Q(e,`draining`))});if(await Promise.all([m,...p]),!o())return;xe(e,r,c)}finally{e.runningRef.current=!1}}function xe(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:++ye,at:Date.now(),mode:t.mode,producers:t.producers,workers:t.workers},...e].slice(0,12)),Q(e,e.stopRef.current?`stopped`:n.error?`error`:`done`)}function Q(e,t){e.phaseRef.current=t,e.setPhase(t)}function Se(){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)=>be({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 Ce({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??$(),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=$();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 $(){let e=a.captureServerRequestTarget();return{target:e,client:a.createServerTargetClient(e)}}function we(){let[e]=(0,C.useState)(ee),[t,n]=(0,C.useState)(()=>ne({...T,queue:e})),r=Se(),u=i(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(_):a.counts(_),[_,d],{intervalMs:1e3}),S=b?.counts??null,E=Ce({benchmark:r,counts:S,dedicatedQueue:e,draft:t,pollQueue:_,runTarget:d,setRunTarget:p}),{phase:D,live:O,summary:j,history:M}=r,N=D===`running`||D===`draining`||D===`stopping`,P=r.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=Te(D,P.mode,!!j),U=Ee(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)(o,{className:`size-3.5`}),` Stopping…`]}):N?(0,H.jsxs)(l,{variant:`warning`,size:`sm`,onClick:r.stop,children:[(0,H.jsx)(o,{className:`size-3.5`}),` Stop`]}):(0,H.jsxs)(l,{variant:`success`,size:`sm`,disabled:E.cleaning,onClick:E.start,children:[(0,H.jsx)(s,{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:r.clearHistory})]})}function Te(e,t,n){return e===`running`?t===`duration`?`Running…`:`Producing…`:e===`draining`?`Draining…`:e===`stopping`?`Stopping…`:e===`error`?`Error`:n?`Result`:`Ready`}function Ee(e,t){return(e===`running`||e===`draining`)&&t!=null?t>0?`ETA ${m(t)}`:`finishing…`:e===`stopped`?`stopped early`:e===`done`?`complete`:``}export{we as Benchmark};
1
+ import{i as e,t}from"./cn-zFEt5SO8.js";import{g as n,t as r}from"./react-vendor-CvwrP0tU.js";import{o as i}from"./connectionStore-BJLihGaC.js";import{t as a}from"./bq-F5BbTG1T.js";import{b as o,x as s}from"./icons-BVzwsfbG.js";import{n as c}from"./usePolledData-0CVelkl2.js";import{t as l}from"./Button-Ch1W94fJ.js";import{n as u,t as d}from"./Card-CWxrC8OY.js";import{t as f}from"./PageHeader-CvIyaFOO.js";import{n as p,o as m,s as h}from"./format-Cg7VCIZW.js";import{a as g,n as _}from"./index-BFW2_47n.js";import{i as v,n as y,o as b,t as x}from"./form-C4oby9pI.js";import{t as S}from"./AreaChart-DEAalJ6P.js";var C=e(n(),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=r();function re({draft:e,active:n,cleaning:r,cleanResult:i,setField:a,numberInput:o,onClean:s}){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=>a(`mode`,e),disabled:n})}),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:n,onChange:o(`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:n,onChange:o(`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:n,onChange:o(`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:n,onChange:o(`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:n,onChange:o(`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:n,onChange:o(`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:n,onChange:o(`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:n,onChange:o(`processMs`)})})]}),(0,H.jsx)(U,{label:`Durable (fsync each job)`,checked:e.durable,active:n,onChange:e=>a(`durable`,e)}),(0,H.jsx)(U,{label:`Remove on complete`,checked:e.removeOnComplete,active:n,onChange:e=>a(`removeOnComplete`,e)}),(0,H.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,H.jsx)(l,{variant:`ghost`,size:`sm`,disabled:n||r,onClick:s,children:r?`Cleaning…`:`Clean queue`}),i&&(`error`in i?(0,H.jsxs)(`span`,{className:`text-xs text-danger`,children:[`Clean unverified — `,i.error]}):(0,H.jsx)(`span`,{className:t(`text-xs`,i.remaining>0?`text-warning`:`text-success`),children:i.remaining>0?`Cleaned — ${h(i.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:n,tone:r}){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:[n.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(n),children:(0,H.jsx)(`div`,{className:t(`h-full rounded-full transition-[width] motion-reduce:transition-none`,r===`accent`?`bg-accent`:`bg-emerald-500`),style:{width:`${n}%`}})})]})}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}}function me(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 he(e){return async()=>{let{stats:t}=e;for(;e.shouldContinue()&&!(e.runConfig.mode===`duration`&&performance.now()>=e.deadline||e.runConfig.mode===`count`&&t.completed>=e.total);){t.activeWorkers++;let n=[];try{if(n=await ge(e),!e.shouldContinue()){await X(e,n);break}n.length>0&&await _e(e,n)}finally{e.isCurrent()&&t.activeWorkers--}if(!e.shouldContinue())break;if(n.length===0){if(e.runConfig.mode===`count`&&e.producersDone()){e.ownJobIds.size>0&&(t.error??=`${e.ownJobIds.size} benchmark job(s) could not be drained.`);break}await F(50,e.shouldContinue)}}}}async function ge(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 X(e,n),[])}catch(t){return e.isCurrent()&&(e.stats.error??=I(t)),[]}}async function _e(e,t){if(t.some(t=>!e.ownJobIds.has(t.id))&&e.pendingPushes.size>0&&await Promise.allSettled([...e.pendingPushes]),!e.shouldContinue())return X(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 ve(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 X(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 X(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 X(e,n)}}async function ve(e,t,n){let r=await Z(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 X(e,t){if(t.length===0)return;let n=await Z(e,t);n>0&&e.isCurrent()&&(e.stats.error??=`${n} interrupted benchmark job(s) could not be returned to waiting.`)}async function Z(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 ye=0;async function be(e,t,n){if(e.runningRef.current||!e.mountedRef.current)return;e.runningRef.current=!0;let r=++e.runGenerationRef.current,i=n??a.createServerTargetClient(a.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}),Q(e,`error`);return}let r=n.config,a=await pe(i,r.queue,s);if(!o())return;if(!a.ok){e.setLive(a.live),Q(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}),Q(e,`running`);let l={batch:r.batch,blob:`x`.repeat(r.payload),client:i,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=me(l),d=he(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`&&Q(e,`draining`))});if(await Promise.all([m,...p]),!o())return;xe(e,r,c)}finally{e.runningRef.current=!1}}function xe(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:++ye,at:Date.now(),mode:t.mode,producers:t.producers,workers:t.workers},...e].slice(0,12)),Q(e,e.stopRef.current?`stopped`:n.error?`error`:`done`)}function Q(e,t){e.phaseRef.current=t,e.setPhase(t)}function Se(){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)=>be({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 Ce({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??$(),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=$();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 $(){let e=a.captureServerRequestTarget();return{target:e,client:a.createServerTargetClient(e)}}function we(){let[e]=(0,C.useState)(ee),[t,n]=(0,C.useState)(()=>ne({...T,queue:e})),r=Se(),u=i(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(_):a.counts(_),[_,d],{intervalMs:1e3}),S=b?.counts??null,E=Ce({benchmark:r,counts:S,dedicatedQueue:e,draft:t,pollQueue:_,runTarget:d,setRunTarget:p}),{phase:D,live:O,summary:j,history:M}=r,N=D===`running`||D===`draining`||D===`stopping`,P=r.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=Te(D,P.mode,!!j),U=Ee(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)(o,{className:`size-3.5`}),` Stopping…`]}):N?(0,H.jsxs)(l,{variant:`warning`,size:`sm`,onClick:r.stop,children:[(0,H.jsx)(o,{className:`size-3.5`}),` Stop`]}):(0,H.jsxs)(l,{variant:`success`,size:`sm`,disabled:E.cleaning,onClick:E.start,children:[(0,H.jsx)(s,{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:r.clearHistory})]})}function Te(e,t,n){return e===`running`?t===`duration`?`Running…`:`Producing…`:e===`draining`?`Draining…`:e===`stopping`?`Stopping…`:e===`error`?`Error`:n?`Result`:`Ready`}function Ee(e,t){return(e===`running`||e===`draining`)&&t!=null?t>0?`ETA ${m(t)}`:`finishing…`:e===`stopped`?`stopped early`:e===`done`?`complete`:``}export{we as Benchmark};
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./dist-DjvZiKhB.js","./dist-DZL8soAh.js","./dist-1f1fMHVO.js","./dist-BlWBaCN6.js","./dist-DpZcbP9W.js"])))=>i.map(i=>d[i]);
2
- import{i as e,n as t,t as n}from"./cn-zFEt5SO8.js";import{g as r,p as i,t as a}from"./react-vendor-CvwrP0tU.js";import{c as o,d as s,n as c}from"./bq-F5BbTG1T.js";import{r as l}from"./index-mID5W7vq.js";import{$ as u,A as d,At as f,B as p,Bt as m,Ct as h,D as g,Dt as _,E as ee,Et as v,F as y,Ft as b,G as te,H as ne,Jt as re,Kt as ie,L as ae,Lt as x,Mt as S,Nt as C,O as w,Ot as T,P as oe,Pt as E,R as se,Rt as D,St as O,Tt as ce,U as k,Ut as le,Vt as A,X as ue,_ as j,_t as de,a as fe,at as pe,bt as me,c as M,ct as N,dt as P,et as he,ft as F,g as I,gt as L,h as ge,ht as R,j as _e,jt as z,l as ve,lt as ye,mt as B,n as be,nt as V,o as xe,ot as Se,p as Ce,pt as we,qt as Te,r as Ee,s as De,st as H,t as Oe,v as U,w as ke,wt as W,x as G,xt as K,yt as q}from"./dist-DZL8soAh.js";import{a as Ae,n as je,t as Me}from"./form-C4oby9pI.js";var Ne=e(r(),1),Pe=[{id:`anthropic`,label:`Claude — Anthropic`,kind:`anthropic`,models:[`claude-opus-4-8`,`claude-sonnet-5`,`claude-haiku-4-5-20251001`],keyUrl:`https://console.anthropic.com/settings/keys`,browserDirect:!0},{id:`openai`,label:`ChatGPT — OpenAI`,kind:`openai`,models:[`gpt-5.1`,`gpt-5`,`gpt-4.1`,`o4-mini`],keyUrl:`https://platform.openai.com/api-keys`,browserDirect:!1,note:`OpenAI blocks direct browser calls (CORS). Use OpenRouter for GPT models, or run behind a proxy.`},{id:`google`,label:`Gemini — Google`,kind:`google`,models:[`gemini-2.5-pro`,`gemini-2.5-flash`,`gemini-2.0-flash`],keyUrl:`https://aistudio.google.com/app/apikey`,browserDirect:!0},{id:`zai`,label:`GLM — Z.ai`,kind:`compatible`,baseURL:`https://api.z.ai/api/paas/v4`,models:[`glm-4.6`,`glm-4.5`,`glm-4.5-air`],keyUrl:`https://z.ai/manage-apikey/apikey-list`,browserDirect:!0},{id:`openrouter`,label:`OpenRouter — any model`,kind:`compatible`,baseURL:`https://openrouter.ai/api/v1`,models:[`anthropic/claude-opus-4.8`,`openai/gpt-5.1`,`google/gemini-2.5-pro`,`z-ai/glm-4.6`,`meta-llama/llama-3.3-70b-instruct`],keyUrl:`https://openrouter.ai/keys`,browserDirect:!0},{id:`custom`,label:`Custom — OpenAI-compatible`,kind:`compatible`,baseURL:``,models:[],keyUrl:``,browserDirect:!0,note:`Any OpenAI-compatible endpoint (Groq, Together, Mistral, a local Ollama / LM Studio, …). Set the base URL and model.`}],Fe=e=>Pe.find(t=>t.id===e);function Ie(e){return[...e].some(e=>{let t=e.charCodeAt(0);return e===`\\`||/\s/u.test(e)||t<32||t===127})}function Le(e){if(typeof e!=`string`)return null;let t=e.trim();if(!t||!/^https?:\/\//iu.test(t)||t.includes(`?`)||t.includes(`#`)||Ie(t))return null;try{let e=new URL(t);if(e.protocol!==`http:`&&e.protocol!==`https:`||!e.hostname||e.username||e.password)return null;let n=e.pathname.replace(/\/+$/,``);return`${e.origin}${n}`}catch{return null}}function Re(e,t){if(t.id===`custom`){let t=Le(e.baseURL);if(!t)throw Error(`Custom provider base URL must be a non-empty http(s) endpoint without credentials, query, or fragment.`);return t}let n=Le(t.baseURL);if(!n)throw Error(`Copilot provider "${t.id}" has no valid fixed endpoint.`);return n}async function ze(e){let t=Fe(e.provider),n=e.apiKey.trim();switch(t?.kind){case`anthropic`:{let{createAnthropic:t}=await i(async()=>{let{createAnthropic:e}=await import(`./dist-DjvZiKhB.js`);return{createAnthropic:e}},__vite__mapDeps([0,1]),import.meta.url);return t({apiKey:n,headers:{"anthropic-dangerous-direct-browser-access":`true`}})(e.model)}case`openai`:{let{createOpenAI:t}=await i(async()=>{let{createOpenAI:e}=await import(`./dist-1f1fMHVO.js`);return{createOpenAI:e}},__vite__mapDeps([2,1]),import.meta.url);return t({apiKey:n})(e.model)}case`google`:{let{createGoogleGenerativeAI:t}=await i(async()=>{let{createGoogleGenerativeAI:e}=await import(`./dist-BlWBaCN6.js`);return{createGoogleGenerativeAI:e}},__vite__mapDeps([3,1]),import.meta.url);return t({apiKey:n})(e.model)}case`compatible`:{let{createOpenAICompatible:r}=await i(async()=>{let{createOpenAICompatible:e}=await import(`./dist-DpZcbP9W.js`);return{createOpenAICompatible:e}},__vite__mapDeps([4,1]),import.meta.url);return r({name:e.provider||`custom`,baseURL:Re(e,t),apiKey:n})(e.model)}default:throw Error(`Unknown Copilot provider "${e.provider}". Pick a provider in the Copilot settings.`)}}var Be=t(((e,t)=>{var n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,o=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},s=(e,t,o,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let c of i(t))!a.call(e,c)&&c!==o&&n(e,c,{get:()=>t[c],enumerable:!(s=r(t,c))||s.enumerable});return e},c=e=>s(n({},`__esModule`,{value:!0}),e),l={};o(l,{SYMBOL_FOR_REQ_CONTEXT:()=>u,getContext:()=>d}),t.exports=c(l);var u=Symbol.for(`@vercel/request-context`);function d(){return globalThis[u]?.get?.()??{}}0&&(t.exports={SYMBOL_FOR_REQ_CONTEXT:u,getContext:d})})),Ve=t(((e,t)=>{var n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,o=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},s=(e,t,o,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let c of i(t))!a.call(e,c)&&c!==o&&n(e,c,{get:()=>t[c],enumerable:!(s=r(t,c))||s.enumerable});return e},c=e=>s(n({},`__esModule`,{value:!0}),e),l={};o(l,{AccessTokenMissingError:()=>u,RefreshAccessTokenFailedError:()=>d}),t.exports=c(l);var u=class extends Error{constructor(){super(`No authentication found. Please log in with the Vercel CLI (vercel login).`),this.name=`AccessTokenMissingError`}},d=class extends Error{constructor(e){super(`Failed to refresh authentication token.`,{cause:e}),this.name=`RefreshAccessTokenFailedError`}};0&&(t.exports={AccessTokenMissingError:u,RefreshAccessTokenFailedError:d})})),He=t(((e,t)=>{var n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,o=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},s=(e,t,o,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let c of i(t))!a.call(e,c)&&c!==o&&n(e,c,{get:()=>t[c],enumerable:!(s=r(t,c))||s.enumerable});return e},c=e=>s(n({},`__esModule`,{value:!0}),e),l={};o(l,{AccessTokenMissingError:()=>d.AccessTokenMissingError,RefreshAccessTokenFailedError:()=>d.RefreshAccessTokenFailedError,getContext:()=>u.getContext,getVercelOidcToken:()=>f,getVercelOidcTokenSync:()=>p,getVercelToken:()=>m}),t.exports=c(l);var u=Be(),d=Ve();async function f(){return``}function p(){return``}async function m(){throw Error(`getVercelToken is not supported in browser environments`)}0&&(t.exports={AccessTokenMissingError,RefreshAccessTokenFailedError,getContext,getVercelOidcToken:f,getVercelOidcTokenSync:p,getVercelToken:m})}))(),Ue=`ai-gateway-realtime.v1`,We=`ai-gateway-auth.`,Ge=`ai-gateway-team.`;function Ke(e,t){let n=[Ue,`${We}${e}`];return t?.teamIdOrSlug&&n.push(`${Ge}${qe(t.teamIdOrSlug)}`),n}function qe(e){let t=new TextEncoder().encode(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/u,``)}var Je=Symbol.for(`vercel.ai.gateway.error`),Ye,Xe,J=class e extends (Xe=Error,Ye=Je,Xe){constructor({message:e,statusCode:t=500,cause:n,generationId:r,isRetryable:i=t!=null&&(t===408||t===409||t===429||t>=500)}){super(r?`${e} [${r}]`:e),this[Ye]=!0,this.statusCode=t,this.cause=n,this.generationId=r,this.isRetryable=i}static isInstance(t){return e.hasMarker(t)}static hasMarker(e){return typeof e==`object`&&!!e&&Je in e&&e[Je]===!0}},Ze=`GatewayAuthenticationError`,Qe=`vercel.ai.gateway.error.${Ze}`,$e=Symbol.for(Qe),et,tt,nt=class e extends (tt=J,et=$e,tt){constructor({message:e=`Authentication failed`,statusCode:t=401,cause:n,generationId:r}={}){super({message:e,statusCode:t,cause:n,generationId:r}),this[et]=!0,this.name=Ze,this.type=`authentication_error`}static isInstance(e){return J.hasMarker(e)&&$e in e}static createContextualError({apiKeyProvided:t,oidcTokenProvided:n,statusCode:r=401,cause:i,generationId:a}){let o;return o=t?`AI Gateway authentication failed: Invalid API key or token.
2
+ import{i as e,n as t,t as n}from"./cn-zFEt5SO8.js";import{g as r,p as i,t as a}from"./react-vendor-CvwrP0tU.js";import{c as o,d as s,n as c}from"./bq-F5BbTG1T.js";import{r as l}from"./index-BFW2_47n.js";import{$ as u,A as d,At as f,B as p,Bt as m,Ct as h,D as g,Dt as _,E as ee,Et as v,F as y,Ft as b,G as te,H as ne,Jt as re,Kt as ie,L as ae,Lt as x,Mt as S,Nt as C,O as w,Ot as T,P as oe,Pt as E,R as se,Rt as D,St as O,Tt as ce,U as k,Ut as le,Vt as A,X as ue,_ as j,_t as de,a as fe,at as pe,bt as me,c as M,ct as N,dt as P,et as he,ft as F,g as I,gt as L,h as ge,ht as R,j as _e,jt as z,l as ve,lt as ye,mt as B,n as be,nt as V,o as xe,ot as Se,p as Ce,pt as we,qt as Te,r as Ee,s as De,st as H,t as Oe,v as U,w as ke,wt as W,x as G,xt as K,yt as q}from"./dist-DZL8soAh.js";import{a as Ae,n as je,t as Me}from"./form-C4oby9pI.js";var Ne=e(r(),1),Pe=[{id:`anthropic`,label:`Claude — Anthropic`,kind:`anthropic`,models:[`claude-opus-4-8`,`claude-sonnet-5`,`claude-haiku-4-5-20251001`],keyUrl:`https://console.anthropic.com/settings/keys`,browserDirect:!0},{id:`openai`,label:`ChatGPT — OpenAI`,kind:`openai`,models:[`gpt-5.1`,`gpt-5`,`gpt-4.1`,`o4-mini`],keyUrl:`https://platform.openai.com/api-keys`,browserDirect:!1,note:`OpenAI blocks direct browser calls (CORS). Use OpenRouter for GPT models, or run behind a proxy.`},{id:`google`,label:`Gemini — Google`,kind:`google`,models:[`gemini-2.5-pro`,`gemini-2.5-flash`,`gemini-2.0-flash`],keyUrl:`https://aistudio.google.com/app/apikey`,browserDirect:!0},{id:`zai`,label:`GLM — Z.ai`,kind:`compatible`,baseURL:`https://api.z.ai/api/paas/v4`,models:[`glm-4.6`,`glm-4.5`,`glm-4.5-air`],keyUrl:`https://z.ai/manage-apikey/apikey-list`,browserDirect:!0},{id:`openrouter`,label:`OpenRouter — any model`,kind:`compatible`,baseURL:`https://openrouter.ai/api/v1`,models:[`anthropic/claude-opus-4.8`,`openai/gpt-5.1`,`google/gemini-2.5-pro`,`z-ai/glm-4.6`,`meta-llama/llama-3.3-70b-instruct`],keyUrl:`https://openrouter.ai/keys`,browserDirect:!0},{id:`custom`,label:`Custom — OpenAI-compatible`,kind:`compatible`,baseURL:``,models:[],keyUrl:``,browserDirect:!0,note:`Any OpenAI-compatible endpoint (Groq, Together, Mistral, a local Ollama / LM Studio, …). Set the base URL and model.`}],Fe=e=>Pe.find(t=>t.id===e);function Ie(e){return[...e].some(e=>{let t=e.charCodeAt(0);return e===`\\`||/\s/u.test(e)||t<32||t===127})}function Le(e){if(typeof e!=`string`)return null;let t=e.trim();if(!t||!/^https?:\/\//iu.test(t)||t.includes(`?`)||t.includes(`#`)||Ie(t))return null;try{let e=new URL(t);if(e.protocol!==`http:`&&e.protocol!==`https:`||!e.hostname||e.username||e.password)return null;let n=e.pathname.replace(/\/+$/,``);return`${e.origin}${n}`}catch{return null}}function Re(e,t){if(t.id===`custom`){let t=Le(e.baseURL);if(!t)throw Error(`Custom provider base URL must be a non-empty http(s) endpoint without credentials, query, or fragment.`);return t}let n=Le(t.baseURL);if(!n)throw Error(`Copilot provider "${t.id}" has no valid fixed endpoint.`);return n}async function ze(e){let t=Fe(e.provider),n=e.apiKey.trim();switch(t?.kind){case`anthropic`:{let{createAnthropic:t}=await i(async()=>{let{createAnthropic:e}=await import(`./dist-DjvZiKhB.js`);return{createAnthropic:e}},__vite__mapDeps([0,1]),import.meta.url);return t({apiKey:n,headers:{"anthropic-dangerous-direct-browser-access":`true`}})(e.model)}case`openai`:{let{createOpenAI:t}=await i(async()=>{let{createOpenAI:e}=await import(`./dist-1f1fMHVO.js`);return{createOpenAI:e}},__vite__mapDeps([2,1]),import.meta.url);return t({apiKey:n})(e.model)}case`google`:{let{createGoogleGenerativeAI:t}=await i(async()=>{let{createGoogleGenerativeAI:e}=await import(`./dist-BlWBaCN6.js`);return{createGoogleGenerativeAI:e}},__vite__mapDeps([3,1]),import.meta.url);return t({apiKey:n})(e.model)}case`compatible`:{let{createOpenAICompatible:r}=await i(async()=>{let{createOpenAICompatible:e}=await import(`./dist-DpZcbP9W.js`);return{createOpenAICompatible:e}},__vite__mapDeps([4,1]),import.meta.url);return r({name:e.provider||`custom`,baseURL:Re(e,t),apiKey:n})(e.model)}default:throw Error(`Unknown Copilot provider "${e.provider}". Pick a provider in the Copilot settings.`)}}var Be=t(((e,t)=>{var n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,o=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},s=(e,t,o,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let c of i(t))!a.call(e,c)&&c!==o&&n(e,c,{get:()=>t[c],enumerable:!(s=r(t,c))||s.enumerable});return e},c=e=>s(n({},`__esModule`,{value:!0}),e),l={};o(l,{SYMBOL_FOR_REQ_CONTEXT:()=>u,getContext:()=>d}),t.exports=c(l);var u=Symbol.for(`@vercel/request-context`);function d(){return globalThis[u]?.get?.()??{}}0&&(t.exports={SYMBOL_FOR_REQ_CONTEXT:u,getContext:d})})),Ve=t(((e,t)=>{var n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,o=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},s=(e,t,o,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let c of i(t))!a.call(e,c)&&c!==o&&n(e,c,{get:()=>t[c],enumerable:!(s=r(t,c))||s.enumerable});return e},c=e=>s(n({},`__esModule`,{value:!0}),e),l={};o(l,{AccessTokenMissingError:()=>u,RefreshAccessTokenFailedError:()=>d}),t.exports=c(l);var u=class extends Error{constructor(){super(`No authentication found. Please log in with the Vercel CLI (vercel login).`),this.name=`AccessTokenMissingError`}},d=class extends Error{constructor(e){super(`Failed to refresh authentication token.`,{cause:e}),this.name=`RefreshAccessTokenFailedError`}};0&&(t.exports={AccessTokenMissingError:u,RefreshAccessTokenFailedError:d})})),He=t(((e,t)=>{var n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,o=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},s=(e,t,o,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let c of i(t))!a.call(e,c)&&c!==o&&n(e,c,{get:()=>t[c],enumerable:!(s=r(t,c))||s.enumerable});return e},c=e=>s(n({},`__esModule`,{value:!0}),e),l={};o(l,{AccessTokenMissingError:()=>d.AccessTokenMissingError,RefreshAccessTokenFailedError:()=>d.RefreshAccessTokenFailedError,getContext:()=>u.getContext,getVercelOidcToken:()=>f,getVercelOidcTokenSync:()=>p,getVercelToken:()=>m}),t.exports=c(l);var u=Be(),d=Ve();async function f(){return``}function p(){return``}async function m(){throw Error(`getVercelToken is not supported in browser environments`)}0&&(t.exports={AccessTokenMissingError,RefreshAccessTokenFailedError,getContext,getVercelOidcToken:f,getVercelOidcTokenSync:p,getVercelToken:m})}))(),Ue=`ai-gateway-realtime.v1`,We=`ai-gateway-auth.`,Ge=`ai-gateway-team.`;function Ke(e,t){let n=[Ue,`${We}${e}`];return t?.teamIdOrSlug&&n.push(`${Ge}${qe(t.teamIdOrSlug)}`),n}function qe(e){let t=new TextEncoder().encode(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/u,``)}var Je=Symbol.for(`vercel.ai.gateway.error`),Ye,Xe,J=class e extends (Xe=Error,Ye=Je,Xe){constructor({message:e,statusCode:t=500,cause:n,generationId:r,isRetryable:i=t!=null&&(t===408||t===409||t===429||t>=500)}){super(r?`${e} [${r}]`:e),this[Ye]=!0,this.statusCode=t,this.cause=n,this.generationId=r,this.isRetryable=i}static isInstance(t){return e.hasMarker(t)}static hasMarker(e){return typeof e==`object`&&!!e&&Je in e&&e[Je]===!0}},Ze=`GatewayAuthenticationError`,Qe=`vercel.ai.gateway.error.${Ze}`,$e=Symbol.for(Qe),et,tt,nt=class e extends (tt=J,et=$e,tt){constructor({message:e=`Authentication failed`,statusCode:t=401,cause:n,generationId:r}={}){super({message:e,statusCode:t,cause:n,generationId:r}),this[et]=!0,this.name=Ze,this.type=`authentication_error`}static isInstance(e){return J.hasMarker(e)&&$e in e}static createContextualError({apiKeyProvided:t,oidcTokenProvided:n,statusCode:r=401,cause:i,generationId:a}){let o;return o=t?`AI Gateway authentication failed: Invalid API key or token.
3
3
 
4
4
  Create a new API key: https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys
5
5
 
@@ -1,3 +1,3 @@
1
- import{i as e,t}from"./cn-zFEt5SO8.js";import{g as n,h as r,t as i}from"./react-vendor-CvwrP0tU.js";import{o as a}from"./connectionStore-BJLihGaC.js";import{a as o,i as s,t as c}from"./bq-F5BbTG1T.js";import{t as l}from"./toastStore-IZn6OPLZ.js";import{T as u,o as d}from"./icons-BVzwsfbG.js";import{n as f}from"./usePolledData-0CVelkl2.js";import{t as p}from"./Button-Ch1W94fJ.js";import{n as m,t as h}from"./Card-CWxrC8OY.js";import{i as g,n as _,r as v,t as y}from"./feedback-QDN1AsYt.js";import{t as b}from"./PageHeader-CvIyaFOO.js";import{n as x,s as S}from"./format-Cg7VCIZW.js";import{a as C,c as w,n as T,s as E}from"./index-mID5W7vq.js";import{a as D}from"./form-C4oby9pI.js";import{t as ee}from"./Pagination-x-Cwgrul.js";var O=e(r(),1),k=e(n(),1),A=i();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??``),l=r||e[0]||``,d=()=>n(s.trim()?{column:l,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:l,"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)(u,{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(`
1
+ import{i as e,t}from"./cn-zFEt5SO8.js";import{g as n,h as r,t as i}from"./react-vendor-CvwrP0tU.js";import{o as a}from"./connectionStore-BJLihGaC.js";import{a as o,i as s,t as c}from"./bq-F5BbTG1T.js";import{t as l}from"./toastStore-IZn6OPLZ.js";import{T as u,o as d}from"./icons-BVzwsfbG.js";import{n as f}from"./usePolledData-0CVelkl2.js";import{t as p}from"./Button-Ch1W94fJ.js";import{n as m,t as h}from"./Card-CWxrC8OY.js";import{i as g,n as _,r as v,t as y}from"./feedback-QDN1AsYt.js";import{t as b}from"./PageHeader-CvIyaFOO.js";import{n as x,s as S}from"./format-Cg7VCIZW.js";import{a as C,c as w,n as T,s as E}from"./index-BFW2_47n.js";import{a as D}from"./form-C4oby9pI.js";import{t as ee}from"./Pagination-x-Cwgrul.js";var O=e(r(),1),k=e(n(),1),A=i();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??``),l=r||e[0]||``,d=()=>n(s.trim()?{column:l,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:l,"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)(u,{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
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=c.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 c.getDbExportAtTarget(t,r,n)}var G=e=>JSON.stringify([e.activeProfileId,e.baseUrl,e.agentBaseUrl,e.token,e.agentToken]);function te({value:e,align:n}){if(e==null)return(0,A.jsx)(`span`,{className:`italic text-faint`,children:`NULL`});let r=typeof e==`string`?e:String(e);return(0,A.jsx)(`span`,{className:t(`block max-w-[24rem] truncate`,n===`right`&&`text-right tabular-nums`),title:r,children:r})}function ne({columns:e,rows:n,truncatedCells:r,colMeta:i,sort:a,onSort:o,onRowClick:s,dimmed:c}){let l=(0,k.useMemo)(()=>e.map((e,t)=>{let r=i?.[e]?.type?.toUpperCase()??``;if(/INT|REAL|NUM|DEC|DOUB|FLOA/.test(r))return!0;let a=!1;for(let e of n){let n=e[t];if(n!=null&&(a=!0,typeof n!=`number`))return!1}return a}),[e,n,i]);return(0,A.jsx)(`div`,{className:t(`max-h-[70vh] overflow-auto rounded-xl border border-line bg-surface transition-opacity`,c&&`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:[s&&(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,n)=>{let r=i?.[e];return(0,A.jsx)(`th`,{className:t(`sticky top-0 z-10 whitespace-nowrap border-b border-line bg-surface px-4 py-3 font-medium`,l[n]&&`text-right`),"aria-sort":a?.col===e?a.dir===`asc`?`ascending`:`descending`:o?`none`:void 0,children:o?(0,A.jsxs)(`button`,{type:`button`,onClick:()=>o(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,r?.primaryKey&&(0,A.jsx)(`span`,{className:`rounded bg-accent/15 px-1 py-0.5 text-[9px] font-semibold text-accent`,children:`PK`}),r?.type&&(0,A.jsx)(`span`,{className:`text-faint/70`,children:r.type.toLowerCase()}),(0,A.jsx)(`span`,{"aria-hidden":`true`,className:a?.col===e?`text-accent`:`text-faint/60`,children:a?.col===e?a.dir===`asc`?`▲`:`▼`:`↕`})]}):e},e)})]})}),(0,A.jsx)(`tbody`,{children:n.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:[s&&(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:()=>s(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,n)=>(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:l[n]?`right`:`left`}),r?.[t]?.[n]&&(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:`…`})]})},n))]},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=a(G),[i,o]=(0,k.useState)(null),[s,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=i===r,x=s?.target===r?s.message:null,C=f?.target===r?f:null,w=async(t=e,n=!0)=>{let i=t.trim();if(!i||v.current?.target===r)return;let s=++_.current,u=r;v.current={generation:s,target:u},o(u),l(null);try{let e=K(await c.db.query(t));if(s!==_.current||G(a.getState())!==u)return;g({...e,target:u}),n&&d(H(i))}catch(e){if(s!==_.current||G(a.getState())!==u)return;g(null),l({target:u,message:e.message})}finally{v.current?.generation===s&&(v.current=null),s===_.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:n,colMeta:r,cycleSort:i,data:a,dbMissing:o,detail:s,editorRef:c,exportBusy:l,exportPage:u,exportTable:d,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:s?!0:void 0,"aria-hidden":s?!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&&!o&&(0,A.jsx)(g,{message:`Could not read the database — ${Y.message}`,onRetry:P}),C&&!o&&(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})]}),o?(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:t(`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:t(`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:!a||a.rows.length===0,title:a?`Exports the ${a.rows.length} rows on this page only`:void 0,onClick:u,children:[`Export page`,a?` (${a.rows.length})`:``]}),(0,A.jsx)(p,{size:`sm`,variant:`accent`,disabled:l||!a||a.total===0,onClick:d,children:l?`Exporting…`:`Export table${a?` (${S(a.total)})`:``}`})]})]}),q===`data`&&B&&(0,A.jsx)(j,{columns:a?.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&&!a?(0,A.jsx)(v,{label:`Reading ${B}…`}):a?a.total===0?(0,A.jsx)(y,{title:f?`No matching rows`:`Empty table`,hint:f?`No rows match the current filter.`:`"${a.table}" has no rows.`}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(ne,{columns:a.columns,rows:a.rows,truncatedCells:a.truncatedCells,colMeta:r,sort:te,onSort:i,onRowClick:e=>{let t=Q(a,e);t&&F(`database-row`)&&V(t)},dimmed:I&&!a}),n&&(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:a.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:c})]})})]})]})}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,s]=(0,k.useState)({}),[l,u]=(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)(()=>{s({}),u({});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 c.db.cell(e,r,t);if(!i||typeof i!=`object`||!Object.hasOwn(i,`value`))throw Error(`Malformed full-cell response.`);n||s(e=>({...e,[t]:i.value}))}catch(e){if(!n){let n=e instanceof Error?e.message:String(e);u(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)(d,{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 r=Object.hasOwn(o,e),a=r?o[e]:n[t],s=U(a),c=s.includes(`
3
3
  `)||s.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,a!=null&&(0,A.jsx)(C,{value:String(a)}),i[t]&&!r&&(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:a==null?(0,A.jsx)(`span`,{className:`italic text-faint`,children:`NULL`}):c?(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:s}):(0,A.jsx)(`span`,{className:`break-words font-mono text-sm text-fg`,children:s})})]},e)})})})]})]})}function fe({data:e,filter:t,page:n,selected:r,sort:i}){let o=a(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}),[o]),{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(a.getState()),n={table:r,orderBy:i?.col,dir:i?.dir??`asc`,filter:t?{...t}:void 0},o=c.captureAgentRequestTarget(),u=new AbortController;h.current=u,d(!0),p(null);try{let t=await W(n,o,u.signal);if(u.signal.aborted||G(a.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(s)} byte cap reached)`:`Exported ${S(t.rowCount)} rows`;p(r),l.success(`Export of ${n.table} complete`,r)}catch(t){if(u.signal.aborted||G(a.getState())!==e)return;p(`Export failed: ${t.message}`),l.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,a]=(0,k.useState)(null),[s,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(()=>c.db.tables(),[],{intervalMs:1e4}),E=(0,k.useMemo)(()=>x?.tables??[],[x]),D=S instanceof o&&S.status===404,{data:ee,error:O,refetch:A}=f(()=>D?Promise.resolve(null):c.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?c.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 c.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),a(null),d(null),m(null)},K=e=>{t(e),l(`data`),ne()},re=e=>{r(0),m(null),a(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:s,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 +1 @@
1
- import{i as e}from"./cn-zFEt5SO8.js";import{g as t,t as n}from"./react-vendor-CvwrP0tU.js";import{t as r}from"./bq-F5BbTG1T.js";import{t as i}from"./toastStore-IZn6OPLZ.js";import{t as a}from"./api-BgWE-705.js";import{n as o}from"./usePolledData-0CVelkl2.js";import{t as s}from"./Button-Ch1W94fJ.js";import{n as c,t as l}from"./Card-CWxrC8OY.js";import{i as u,r as d}from"./feedback-QDN1AsYt.js";import{n as f}from"./StatusBadge-BoOVTnKu.js";import{t as p}from"./PageHeader-CvIyaFOO.js";import{n as m,s as h,u as g}from"./format-Cg7VCIZW.js";import{a as _,n as v}from"./index-mID5W7vq.js";import{t as y}from"./useControlActionGuard-B-bzKZKI.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)(f,{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)(l,{children:[(0,b.jsx)(c,{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)(l,{children:[(0,b.jsx)(c,{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)(l,{className:`mt-6`,children:[(0,b.jsx)(c,{title:`Heap statistics`,action:(0,b.jsx)(s,{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)(l,{className:`mt-6`,children:[(0,b.jsx)(c,{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)(l,{className:`mt-6`,children:[(0,b.jsx)(c,{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}=o(async()=>{let[e,t,n,i,o,s,c]=await Promise.all([j(r.health()),j(r.storage()),j(r.stats()),j(a.healthz()),j(a.live()),j(a.ready()),j(a.metrics())]);return{health:e.value,storage:t.value,stats:n.value,healthError:e.error,storageError:t.error,statsError:n.error,healthz:i.value,live:o.value,ready:s.value,metrics:c.value,healthzError:i.error,liveError:o.error,readyError:s.error,metricsError:c.error}},[]),{doGc:f,doPing:h,gcBusy:_,gcMsg:y,heap:x,heapBusy:S,loadHeap:C,ping:k}=A(i);if(n&&!e&&!t)return(0,b.jsx)(d,{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)(u,{message:`Diagnostics refresh failed — ${t.message}`,onRetry:i}),M.healthError&&(0,b.jsx)(u,{message:`Health unavailable — ${M.healthError}`,onRetry:i}),M.storageError&&(0,b.jsx)(u,{message:`Storage diagnostics unavailable — ${M.storageError}`,onRetry:i}),M.statsError&&(0,b.jsx)(u,{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)(l,{children:[(0,b.jsx)(c,{title:`Connectivity`,action:(0,b.jsxs)(s,{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)(l,{children:[(0,b.jsx)(c,{title:`Memory`,action:(0,b.jsx)(s,{size:`sm`,disabled:_,onClick:f,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
+ import{i as e}from"./cn-zFEt5SO8.js";import{g as t,t as n}from"./react-vendor-CvwrP0tU.js";import{t as r}from"./bq-F5BbTG1T.js";import{t as i}from"./toastStore-IZn6OPLZ.js";import{t as a}from"./api-BgWE-705.js";import{n as o}from"./usePolledData-0CVelkl2.js";import{t as s}from"./Button-Ch1W94fJ.js";import{n as c,t as l}from"./Card-CWxrC8OY.js";import{i as u,r as d}from"./feedback-QDN1AsYt.js";import{n as f}from"./StatusBadge-BoOVTnKu.js";import{t as p}from"./PageHeader-CvIyaFOO.js";import{n as m,s as h,u as g}from"./format-Cg7VCIZW.js";import{a as _,n as v}from"./index-BFW2_47n.js";import{t as y}from"./useControlActionGuard-B-bzKZKI.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)(f,{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)(l,{children:[(0,b.jsx)(c,{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)(l,{children:[(0,b.jsx)(c,{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)(l,{className:`mt-6`,children:[(0,b.jsx)(c,{title:`Heap statistics`,action:(0,b.jsx)(s,{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)(l,{className:`mt-6`,children:[(0,b.jsx)(c,{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)(l,{className:`mt-6`,children:[(0,b.jsx)(c,{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}=o(async()=>{let[e,t,n,i,o,s,c]=await Promise.all([j(r.health()),j(r.storage()),j(r.stats()),j(a.healthz()),j(a.live()),j(a.ready()),j(a.metrics())]);return{health:e.value,storage:t.value,stats:n.value,healthError:e.error,storageError:t.error,statsError:n.error,healthz:i.value,live:o.value,ready:s.value,metrics:c.value,healthzError:i.error,liveError:o.error,readyError:s.error,metricsError:c.error}},[]),{doGc:f,doPing:h,gcBusy:_,gcMsg:y,heap:x,heapBusy:S,loadHeap:C,ping:k}=A(i);if(n&&!e&&!t)return(0,b.jsx)(d,{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)(u,{message:`Diagnostics refresh failed — ${t.message}`,onRetry:i}),M.healthError&&(0,b.jsx)(u,{message:`Health unavailable — ${M.healthError}`,onRetry:i}),M.storageError&&(0,b.jsx)(u,{message:`Storage diagnostics unavailable — ${M.storageError}`,onRetry:i}),M.statsError&&(0,b.jsx)(u,{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)(l,{children:[(0,b.jsx)(c,{title:`Connectivity`,action:(0,b.jsxs)(s,{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)(l,{children:[(0,b.jsx)(c,{title:`Memory`,action:(0,b.jsx)(s,{size:`sm`,disabled:_,onClick:f,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 +1 @@
1
- import{i as e}from"./cn-zFEt5SO8.js";import{g as t,t as n}from"./react-vendor-CvwrP0tU.js";import{u as r}from"./icons-BVzwsfbG.js";import{t as i}from"./api-BgWE-705.js";import{n as a}from"./usePolledData-0CVelkl2.js";import{t as o}from"./Button-Ch1W94fJ.js";import{i as s,n as c,r as l,t as u}from"./feedback-QDN1AsYt.js";import{t as d}from"./PageHeader-CvIyaFOO.js";import{l as f,s as p}from"./format-Cg7VCIZW.js";import{n as m}from"./index-mID5W7vq.js";import{a as h}from"./form-C4oby9pI.js";import{t as g}from"./Pagination-x-Cwgrul.js";import{r as _,t as v}from"./flowMutationSafety-YKTHxqKv.js";import{t as y}from"./Jobs-BTMpbAHD.js";var b=e(t(),1),x=n(),S=25;function C(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}async function w(){let e=await y();if(!Number.isFinite(e.timestamp)||e.queues.some(e=>!C(e.waiting)||!C(e.delayed)||!C(e.active)||!C(e.dlq)||typeof e.paused!=`boolean`))throw Error(`Queue discovery returned malformed queue summaries`);return e}function T(){let[e,t]=(0,b.useState)(``),[n,y]=(0,b.useState)(0),{data:C,error:T,loading:E,refetch:D}=a(w,[],{intervalMs:3e4});(0,b.useEffect)(()=>{if(e||!C?.queues?.length)return;let n=C.queues.find(e=>e.dlq>0)??C.queues[0];t(n.name)},[C,e]);let{data:O,error:k,loading:A,refetch:j}=a((0,b.useCallback)(async()=>{if(!e)return{entries:[],total:0};let t=await i.dlq(e,S,n*S);return{entries:t.entries??[],total:t.total??t.entries?.length??0}},[e,n]),[e,n]),M=O?.entries??[];return(0,x.jsxs)(`div`,{children:[k&&O&&(0,x.jsx)(s,{message:`DLQ refresh failed — showing the last successful page.`,onRetry:j}),T&&(0,x.jsx)(s,{onRetry:D,message:`Could not discover queues — ${T.message}. Retry before selecting a queue.`}),(0,x.jsx)(d,{title:`Dead Letter Queue`,description:`Jobs that exhausted their retries.`,live:!!e&&!!O&&!k&&!T,actions:(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(o,{size:`sm`,disabled:!0,title:v,children:`Retry all`}),(0,x.jsx)(o,{variant:`danger`,size:`sm`,disabled:!0,title:_,children:`Purge`})]})}),(0,x.jsxs)(`div`,{className:`mb-6 flex flex-wrap items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-56`,children:(0,x.jsx)(h,{value:e,"aria-label":`Queue`,name:`classic-dlq-queue`,autoComplete:`off`,onChange:e=>{t(e.target.value),y(0)},children:(C?.queues??[]).map(e=>(0,x.jsxs)(`option`,{value:e.name,children:[e.name,` `,e.dlq?`(${e.dlq})`:``]},e.name))})}),(0,x.jsx)(`div`,{className:`w-40`,children:(0,x.jsx)(m,{label:`DLQ Entries`,value:e&&O?p(O.total):`—`,tone:e&&O?.total?`red`:`default`,compact:!0})})]}),k&&!O?(0,x.jsx)(c,{error:k,onRetry:j}):E&&!C&&!e&&!T?(0,x.jsx)(l,{label:`Discovering queues…`}):A&&!O&&!k?(0,x.jsx)(l,{label:`Loading DLQ…`}):T&&!e?(0,x.jsx)(u,{icon:(0,x.jsx)(r,{}),title:`Could not discover queues`,hint:`${T.message}. Retry the queue discovery request above.`}):e?M.length===0?(0,x.jsx)(u,{icon:(0,x.jsx)(r,{}),title:`Dead letter queue is empty`,hint:`Jobs land here after exhausting their retry attempts.`}):(0,x.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,x.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,x.jsx)(`thead`,{children:(0,x.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,x.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Job ID`}),(0,x.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Name`}),(0,x.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Reason`}),(0,x.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Attempts`}),(0,x.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Failed`})]})}),(0,x.jsx)(`tbody`,{children:M.map((e,t)=>(0,x.jsxs)(`tr`,{className:`border-b border-line last:border-0 align-top hover:bg-surface-2/40`,children:[(0,x.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.job.id}),(0,x.jsx)(`td`,{className:`px-5 py-3 text-fg`,children:e.job.name??e.job.data?.name??`default`}),(0,x.jsx)(`td`,{className:`max-w-md px-5 py-3 text-xs text-red-400/90`,children:String(e.reason||e.error||`—`)}),(0,x.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:e.attempts?.length??e.job.attempts??`—`}),(0,x.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,x.jsx)(u,{icon:(0,x.jsx)(r,{}),title:C?.queues.length===0?`No queues available`:`Select a queue`,hint:`A queue must be selected before its dead letter entries can be inspected.`}),O&&(0,x.jsx)(g,{page:n,pageSize:S,total:O.total,onPageChange:y,label:`entries`})]})}export{T as Dlq};
1
+ import{i as e}from"./cn-zFEt5SO8.js";import{g as t,t as n}from"./react-vendor-CvwrP0tU.js";import{u as r}from"./icons-BVzwsfbG.js";import{t as i}from"./api-BgWE-705.js";import{n as a}from"./usePolledData-0CVelkl2.js";import{t as o}from"./Button-Ch1W94fJ.js";import{i as s,n as c,r as l,t as u}from"./feedback-QDN1AsYt.js";import{t as d}from"./PageHeader-CvIyaFOO.js";import{l as f,s as p}from"./format-Cg7VCIZW.js";import{n as m}from"./index-BFW2_47n.js";import{a as h}from"./form-C4oby9pI.js";import{t as g}from"./Pagination-x-Cwgrul.js";import{r as _,t as v}from"./flowMutationSafety-YKTHxqKv.js";import{t as y}from"./Jobs-ELSH1Wbd.js";var b=e(t(),1),x=n(),S=25;function C(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}async function w(){let e=await y();if(!Number.isFinite(e.timestamp)||e.queues.some(e=>!C(e.waiting)||!C(e.delayed)||!C(e.active)||!C(e.dlq)||typeof e.paused!=`boolean`))throw Error(`Queue discovery returned malformed queue summaries`);return e}function T(){let[e,t]=(0,b.useState)(``),[n,y]=(0,b.useState)(0),{data:C,error:T,loading:E,refetch:D}=a(w,[],{intervalMs:3e4});(0,b.useEffect)(()=>{if(e||!C?.queues?.length)return;let n=C.queues.find(e=>e.dlq>0)??C.queues[0];t(n.name)},[C,e]);let{data:O,error:k,loading:A,refetch:j}=a((0,b.useCallback)(async()=>{if(!e)return{entries:[],total:0};let t=await i.dlq(e,S,n*S);return{entries:t.entries??[],total:t.total??t.entries?.length??0}},[e,n]),[e,n]),M=O?.entries??[];return(0,x.jsxs)(`div`,{children:[k&&O&&(0,x.jsx)(s,{message:`DLQ refresh failed — showing the last successful page.`,onRetry:j}),T&&(0,x.jsx)(s,{onRetry:D,message:`Could not discover queues — ${T.message}. Retry before selecting a queue.`}),(0,x.jsx)(d,{title:`Dead Letter Queue`,description:`Jobs that exhausted their retries.`,live:!!e&&!!O&&!k&&!T,actions:(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(o,{size:`sm`,disabled:!0,title:v,children:`Retry all`}),(0,x.jsx)(o,{variant:`danger`,size:`sm`,disabled:!0,title:_,children:`Purge`})]})}),(0,x.jsxs)(`div`,{className:`mb-6 flex flex-wrap items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-56`,children:(0,x.jsx)(h,{value:e,"aria-label":`Queue`,name:`classic-dlq-queue`,autoComplete:`off`,onChange:e=>{t(e.target.value),y(0)},children:(C?.queues??[]).map(e=>(0,x.jsxs)(`option`,{value:e.name,children:[e.name,` `,e.dlq?`(${e.dlq})`:``]},e.name))})}),(0,x.jsx)(`div`,{className:`w-40`,children:(0,x.jsx)(m,{label:`DLQ Entries`,value:e&&O?p(O.total):`—`,tone:e&&O?.total?`red`:`default`,compact:!0})})]}),k&&!O?(0,x.jsx)(c,{error:k,onRetry:j}):E&&!C&&!e&&!T?(0,x.jsx)(l,{label:`Discovering queues…`}):A&&!O&&!k?(0,x.jsx)(l,{label:`Loading DLQ…`}):T&&!e?(0,x.jsx)(u,{icon:(0,x.jsx)(r,{}),title:`Could not discover queues`,hint:`${T.message}. Retry the queue discovery request above.`}):e?M.length===0?(0,x.jsx)(u,{icon:(0,x.jsx)(r,{}),title:`Dead letter queue is empty`,hint:`Jobs land here after exhausting their retry attempts.`}):(0,x.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,x.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,x.jsx)(`thead`,{children:(0,x.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,x.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Job ID`}),(0,x.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Name`}),(0,x.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Reason`}),(0,x.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Attempts`}),(0,x.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Failed`})]})}),(0,x.jsx)(`tbody`,{children:M.map((e,t)=>(0,x.jsxs)(`tr`,{className:`border-b border-line last:border-0 align-top hover:bg-surface-2/40`,children:[(0,x.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.job.id}),(0,x.jsx)(`td`,{className:`px-5 py-3 text-fg`,children:e.job.name??e.job.data?.name??`default`}),(0,x.jsx)(`td`,{className:`max-w-md px-5 py-3 text-xs text-red-400/90`,children:String(e.reason||e.error||`—`)}),(0,x.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:e.attempts?.length??e.job.attempts??`—`}),(0,x.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,x.jsx)(u,{icon:(0,x.jsx)(r,{}),title:C?.queues.length===0?`No queues available`:`Select a queue`,hint:`A queue must be selected before its dead letter entries can be inspected.`}),O&&(0,x.jsx)(g,{page:n,pageSize:S,total:O.total,onPageChange:y,label:`entries`})]})}export{T as Dlq};
@@ -1 +1 @@
1
- import{i as e,t}from"./cn-zFEt5SO8.js";import{g as n,r,t as i}from"./react-vendor-CvwrP0tU.js";import{t as a}from"./bq-F5BbTG1T.js";import{t as o}from"./toastStore-IZn6OPLZ.js";import{C as s,T as c,a as l,d as u,f as d,u as f}from"./icons-BVzwsfbG.js";import{n as p}from"./usePolledData-0CVelkl2.js";import{n as m,t as h}from"./Button-Ch1W94fJ.js";import{i as g,n as _,r as v,t as y}from"./feedback-QDN1AsYt.js";import{t as b}from"./PageHeader-CvIyaFOO.js";import{a as x,i as S,l as C,s as w}from"./format-Cg7VCIZW.js";import{a as T,n as E}from"./index-mID5W7vq.js";import{a as D}from"./form-C4oby9pI.js";import{t as O}from"./Pagination-x-Cwgrul.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-BW0XXd0B.js";var N=e(n(),1),P=i();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:s,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=>s(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)(c,{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:n,onToggle:i,attempts:a}){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":n?`Collapse details`:`Expand details`,"aria-expanded":n,onClick:i,children:(0,P.jsx)(l,{className:t(`size-3.5 transition-transform`,n&&`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)(r,{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??a.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)(r,{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)(d,{className:`size-3.5`})}),(0,P.jsx)(m,{"aria-label":`Retry job unavailable`,disabled:!0,title:A,children:(0,P.jsx)(s,{className:`size-3.5`})})]})})]}),n&&(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,`×`]})]}),a.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:a.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),[i,c]=(0,N.useState)(`all`),[l,d]=(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)(()=>{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([a.dlq(e,R,n*R),a.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]),J=W?.entries??B,Y=(0,N.useMemo)(()=>{let e=J;i!==`all`&&(e=e.filter(e=>e.reason===i));let t=l.trim().toLowerCase();return t&&(e=e.filter(e=>e.job.id.toLowerCase().includes(t))),[...e].sort((e,t)=>t.enteredAt-e.enteredAt)},[J,i,l]),X=i!==`all`||l.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){o.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)(u,{className:`size-3.5`}),` Export`]}),(0,P.jsxs)(h,{size:`sm`,disabled:!0,title:A,children:[(0,P.jsx)(s,{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:i,reasons:K,byReason:G,search:l,pageScoped:Z,onQueue:e=>{t(e),r(0),c(`all`),d(``)},onReason:c,onSearch:d}),(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)(f,{}),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)(f,{}),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)(f,{}),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
+ import{i as e,t}from"./cn-zFEt5SO8.js";import{g as n,r,t as i}from"./react-vendor-CvwrP0tU.js";import{t as a}from"./bq-F5BbTG1T.js";import{t as o}from"./toastStore-IZn6OPLZ.js";import{C as s,T as c,a as l,d as u,f as d,u as f}from"./icons-BVzwsfbG.js";import{n as p}from"./usePolledData-0CVelkl2.js";import{n as m,t as h}from"./Button-Ch1W94fJ.js";import{i as g,n as _,r as v,t as y}from"./feedback-QDN1AsYt.js";import{t as b}from"./PageHeader-CvIyaFOO.js";import{a as x,i as S,l as C,s as w}from"./format-Cg7VCIZW.js";import{a as T,n as E}from"./index-BFW2_47n.js";import{a as D}from"./form-C4oby9pI.js";import{t as O}from"./Pagination-x-Cwgrul.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-Bvm8GUQa.js";var N=e(n(),1),P=i();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:s,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=>s(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)(c,{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:n,onToggle:i,attempts:a}){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":n?`Collapse details`:`Expand details`,"aria-expanded":n,onClick:i,children:(0,P.jsx)(l,{className:t(`size-3.5 transition-transform`,n&&`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)(r,{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??a.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)(r,{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)(d,{className:`size-3.5`})}),(0,P.jsx)(m,{"aria-label":`Retry job unavailable`,disabled:!0,title:A,children:(0,P.jsx)(s,{className:`size-3.5`})})]})})]}),n&&(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,`×`]})]}),a.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:a.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),[i,c]=(0,N.useState)(`all`),[l,d]=(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)(()=>{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([a.dlq(e,R,n*R),a.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]),J=W?.entries??B,Y=(0,N.useMemo)(()=>{let e=J;i!==`all`&&(e=e.filter(e=>e.reason===i));let t=l.trim().toLowerCase();return t&&(e=e.filter(e=>e.job.id.toLowerCase().includes(t))),[...e].sort((e,t)=>t.enteredAt-e.enteredAt)},[J,i,l]),X=i!==`all`||l.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){o.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)(u,{className:`size-3.5`}),` Export`]}),(0,P.jsxs)(h,{size:`sm`,disabled:!0,title:A,children:[(0,P.jsx)(s,{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:i,reasons:K,byReason:G,search:l,pageScoped:Z,onQueue:e=>{t(e),r(0),c(`all`),d(``)},onReason:c,onSearch:d}),(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)(f,{}),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)(f,{}),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)(f,{}),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 +1 @@
1
- import{i as e,t}from"./cn-zFEt5SO8.js";import{f as n,g as r,r as i,t as a}from"./react-vendor-CvwrP0tU.js";import{t as o}from"./bq-F5BbTG1T.js";import{t as s}from"./toastStore-IZn6OPLZ.js";import{C as c,d as l,u}from"./icons-BVzwsfbG.js";import{n as d}from"./usePolledData-0CVelkl2.js";import{n as f,t as p}from"./Button-Ch1W94fJ.js";import{t as m}from"./Card-CWxrC8OY.js";import{i as h,n as g,r as _,t as v}from"./feedback-QDN1AsYt.js";import{t as ee}from"./PageHeader-CvIyaFOO.js";import{l as y,s as b}from"./format-Cg7VCIZW.js";import{a as x}from"./form-C4oby9pI.js";import{t as S}from"./Pagination-x-Cwgrul.js";import{r as C,t as w}from"./flowMutationSafety-YKTHxqKv.js";import{t as T}from"./exportFile-C7xhE8Yh.js";import{t as E}from"./QueueControl-BW0XXd0B.js";var D=e(r(),1),O=a();function te({total:e,discoveryError:n,healthy:r,statsError:i,queue:a,topReason:o,pendingRetry:s,reasonCount:c}){return(0,O.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,O.jsxs)(m,{children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,O.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Total in DLQ`}),(0,O.jsx)(`span`,{className:t(`rounded-full px-2 py-0.5 text-[11px] font-medium`,n?`bg-amber-500/10 text-warning`:e==null?`bg-surface-2 text-muted`:r?`bg-emerald-500/10 text-success`:`bg-red-500/10 text-danger`),children:n?`Unavailable`:e==null?`Loading`:r?`Healthy`:`Attention`})]}),(0,O.jsx)(`div`,{className:t(`mt-2 text-3xl font-bold tnum`,e==null||n?`text-muted`:r?`text-success`:`text-danger`),children:e==null?`—`:b(e)})]}),(0,O.jsxs)(m,{children:[(0,O.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Top Reason`}),(0,O.jsx)(`div`,{className:`mt-2 text-lg font-semibold text-fg`,children:n||i?`Unavailable`:a?o??`No failures`:`Select a queue`})]}),(0,O.jsxs)(m,{children:[(0,O.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Pending Retry`}),(0,O.jsx)(`div`,{className:`mt-2 text-3xl font-bold tnum text-fg`,children:s==null?`—`:b(s)}),(0,O.jsx)(`div`,{className:`mt-1 text-xs text-faint`,children:a?`in this queue`:`awaiting retry`})]}),(0,O.jsxs)(m,{children:[(0,O.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Failure Types`}),(0,O.jsx)(`div`,{className:`mt-2 text-3xl font-bold tnum text-fg`,children:c==null?`—`:b(c)}),(0,O.jsx)(`div`,{className:`mt-1 text-xs text-faint`,children:`distinct reasons`})]})]})}function k({queues:e,queue:n,onSelect:r}){return e.length===0?null:(0,O.jsxs)(m,{className:`mb-6`,children:[(0,O.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,O.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`DLQ by queue`}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsxs)(p,{size:`sm`,disabled:!0,title:w,children:[(0,O.jsx)(c,{className:`size-3.5`}),` Retry all (`,e.length,` queues)`]}),(0,O.jsxs)(p,{variant:`danger`,size:`sm`,disabled:!0,title:C,children:[`Purge all (`,e.length,` queues)`]})]})]}),(0,O.jsx)(`div`,{className:`grid grid-cols-2 gap-3 md:grid-cols-4 xl:grid-cols-5`,children:e.map(e=>(0,O.jsxs)(`button`,{type:`button`,onClick:()=>r(e.name),className:t(`rounded-lg border p-3 text-left transition-colors`,n===e.name?`border-accent/50 bg-surface-2`:`border-line hover:border-line-strong`),children:[(0,O.jsx)(`div`,{className:`truncate font-mono text-xs text-muted`,children:e.name}),(0,O.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:s,onReason:u,onSort:d,onSearch:m,onExport:h}){return(0,O.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-3`,children:[(0,O.jsx)(`div`,{className:`w-48`,children:(0,O.jsxs)(x,{value:e,"aria-label":`Queue`,name:`dlq-queue`,autoComplete:`off`,onChange:e=>s(e.target.value),children:[(0,O.jsx)(`option`,{value:``,children:`Select a queue…`}),t.map(e=>(0,O.jsxs)(`option`,{value:e.name,children:[e.name,e.dlq?` (${e.dlq})`:``]},e.name))]})}),(0,O.jsx)(`div`,{className:`w-40`,children:(0,O.jsxs)(x,{value:n,onChange:e=>u(e.target.value),"aria-label":`Filter by reason`,name:`dlq-reason-filter`,autoComplete:`off`,children:[(0,O.jsx)(`option`,{value:`all`,children:`All Reasons`}),r.map(e=>(0,O.jsx)(`option`,{value:e,children:e},e))]})}),(0,O.jsx)(`div`,{className:`w-36`,children:(0,O.jsxs)(x,{value:i,onChange:e=>d(e.target.value),"aria-label":o?`Sort this page`:`Sort`,name:`dlq-sort`,autoComplete:`off`,children:[(0,O.jsxs)(`option`,{value:`newest`,children:[`Newest First`,o?` (this page)`:``]}),(0,O.jsxs)(`option`,{value:`oldest`,children:[`Oldest First`,o?` (this page)`:``]})]})}),(0,O.jsx)(`input`,{value:a,onChange:e=>m(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,O.jsxs)(p,{size:`sm`,disabled:!0,title:w,children:[(0,O.jsx)(c,{className:`size-3.5`}),` Retry All`]}),(0,O.jsx)(p,{variant:`danger`,size:`sm`,disabled:!0,title:C,children:`Purge All`}),(0,O.jsx)(f,{"aria-label":`Export this page to CSV`,title:`Export this page to CSV`,disabled:!e,onClick:h,children:(0,O.jsx)(l,{className:`size-3.5`})})]})}function j({entries:e,expanded:n,onToggle:r}){return(0,O.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,O.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,O.jsx)(`thead`,{children:(0,O.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,O.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Job ID`}),(0,O.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Name`}),(0,O.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Reason`}),(0,O.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Error`}),(0,O.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Entered`}),(0,O.jsx)(`th`,{className:`w-16 px-5 py-3`})]})}),(0,O.jsx)(`tbody`,{children:e.map(e=>{let a=`${e.job.id}-${e.enteredAt}`;return(0,O.jsxs)(`tr`,{className:`border-b border-line last:border-0 align-top hover:bg-surface-2/40`,children:[(0,O.jsx)(`td`,{className:`px-5 py-3`,children:(0,O.jsx)(i,{to:`/job?id=${encodeURIComponent(e.job.id)}`,className:`font-mono text-xs text-accent hover:underline`,children:e.job.id})}),(0,O.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.job.name??`default`}),(0,O.jsx)(`td`,{className:`px-5 py-3`,children:(0,O.jsx)(`span`,{className:`rounded-md bg-red-500/10 px-2 py-0.5 text-xs text-danger`,children:e.reason})}),(0,O.jsx)(`td`,{className:`max-w-md px-5 py-3 text-xs text-danger/80`,children:e.error?(0,O.jsx)(`button`,{type:`button`,title:e.error,"aria-expanded":n.has(a),onClick:()=>r(a),className:t(`block w-full break-words text-left`,!n.has(a)&&`line-clamp-2`),children:e.error}):`—`}),(0,O.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:y(e.enteredAt)}),(0,O.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,O.jsx)(f,{"aria-label":`Retry unavailable`,disabled:!0,title:w,children:(0,O.jsx)(c,{className:`size-3.5`})})})]},a)})})]})})}var M=25,N=[];function P(){let[e,t]=n(),[r,i]=(0,D.useState)(``),[a,c]=(0,D.useState)(`all`),[l,f]=(0,D.useState)(`newest`),[p,m]=(0,D.useState)(``),[y,b]=(0,D.useState)(0),[x,C]=(0,D.useState)(new Set),{data:P,error:F,loading:I,refetch:L}=d(E,[],{intervalMs:1e4}),R=P?.queues??N,z=P?R.reduce((e,t)=>e+t.dlq,0):null,{data:B,error:V,loading:H,refetch:U}=d((0,D.useCallback)(async()=>{if(!r)return{queue:r,page:y,entries:[],entriesTotal:0,stats:null,statsError:null};let[e,t]=await Promise.all([o.dlq(r,M,y*M),o.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]),W=B?.queue===r&&B.page===y?B:null;(0,D.useEffect)(()=>{if(!W)return;let e=W.entriesTotal??0;y>0&&y*M>=e&&b(Math.max(0,Math.ceil(e/M)-1))},[W,y]);let G=()=>{let e=(W?.entries??[]).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){s.info(`Nothing to export on this page`);return}T(`dlq-${r}`,e,[`jobId`,`reason`,`error`,`enteredAt`,`attempts`])},K=e=>{X.current=!0,i(e),b(0),c(`all`),t(e?{queue:e}:{},{replace:!0})},q=W?.stats?.byReason??{},J=Object.keys(q).filter(e=>q[e]>0),ne=[...J].sort((e,t)=>(q[t]??0)-(q[e]??0))[0],Y=(0,D.useMemo)(()=>R.filter(e=>e.dlq>0).sort((e,t)=>t.dlq-e.dlq),[R]),X=(0,D.useRef)(!1),Z=e.get(`queue`);(0,D.useEffect)(()=>{if(!(X.current||r)){if(Z){if(R.some(e=>e.name===Z)){X.current=!0,i(Z),b(0),c(`all`);return}if(R.length===0)return}Y.length!==0&&(X.current=!0,i(Y[0].name),b(0),c(`all`))}},[r,R,Y,Z]);let Q=(0,D.useMemo)(()=>{let e=W?.entries??[];a!==`all`&&(e=e.filter(e=>e.reason===a));let t=p.trim().toLowerCase();return t&&(e=e.filter(e=>e.job.id.toLowerCase().includes(t))),[...e].sort((e,t)=>l===`newest`?t.enteredAt-e.enteredAt:e.enteredAt-t.enteredAt)},[W,a,p,l]),re=z===0&&!F,$=a!==`all`||p.trim()!==``,ie=(W?.entriesTotal??0)>M;return(0,O.jsxs)(`div`,{children:[(0,O.jsx)(ee,{title:`Dead Letter Queue`,description:`Jobs that failed after exhausting all retries. Inspect and export entries without mutating flow topology.`,live:!!r&&!!W&&!W.statsError&&!V&&!F}),V&&W&&(0,O.jsx)(h,{message:`DLQ refresh failed — showing the last successful page.`,onRetry:U}),F&&(0,O.jsx)(h,{onRetry:L,message:`Could not discover queue DLQ totals — ${F.message}. Health status is unavailable.`}),W?.statsError&&(0,O.jsx)(h,{message:`DLQ statistics are unavailable — ${W.statsError}. The entry list may still be current.`,onRetry:U}),(0,O.jsx)(te,{total:z,discoveryError:!!F,healthy:re,statsError:!!W?.statsError,queue:r,topReason:ne,pendingRetry:W?.stats?.pendingRetry,reasonCount:W?.stats?J.length:void 0}),(0,O.jsx)(k,{queues:Y,queue:r,onSelect:K}),(0,O.jsx)(A,{queue:r,queues:R,reason:a,reasons:J,sort:l,search:p,pageScoped:ie,onQueue:K,onReason:c,onSort:f,onSearch:m,onExport:G}),(0,O.jsx)(`p`,{className:`mb-4 text-xs text-warning`,children:w}),V&&!W?(0,O.jsx)(g,{error:V,onRetry:U}):I&&!P&&!r&&!F?(0,O.jsx)(_,{label:`Discovering queues…`}):H&&!W&&!V?(0,O.jsx)(_,{label:`Loading DLQ…`}):F&&!r?(0,O.jsx)(v,{icon:(0,O.jsx)(u,{}),title:`Could not discover queues`,hint:`${F.message}. Retry the queue discovery request above.`}):r?Q.length===0?(0,O.jsx)(v,{icon:(0,O.jsx)(u,{}),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,O.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,O.jsx)(v,{icon:(0,O.jsx)(u,{}),title:`Select a queue`,hint:`Choose a queue from the dropdown to view its dead letter queue entries.`}),r&&W&&(0,O.jsx)(S,{page:y,pageSize:M,total:W.entriesTotal,onPageChange:b,label:`entries`})]})}export{P as DlqPro};
1
+ import{i as e,t}from"./cn-zFEt5SO8.js";import{f as n,g as r,r as i,t as a}from"./react-vendor-CvwrP0tU.js";import{t as o}from"./bq-F5BbTG1T.js";import{t as s}from"./toastStore-IZn6OPLZ.js";import{C as c,d as l,u}from"./icons-BVzwsfbG.js";import{n as d}from"./usePolledData-0CVelkl2.js";import{n as f,t as p}from"./Button-Ch1W94fJ.js";import{t as m}from"./Card-CWxrC8OY.js";import{i as h,n as g,r as _,t as v}from"./feedback-QDN1AsYt.js";import{t as ee}from"./PageHeader-CvIyaFOO.js";import{l as y,s as b}from"./format-Cg7VCIZW.js";import{a as x}from"./form-C4oby9pI.js";import{t as S}from"./Pagination-x-Cwgrul.js";import{r as C,t as w}from"./flowMutationSafety-YKTHxqKv.js";import{t as T}from"./exportFile-C7xhE8Yh.js";import{t as E}from"./QueueControl-Bvm8GUQa.js";var D=e(r(),1),O=a();function te({total:e,discoveryError:n,healthy:r,statsError:i,queue:a,topReason:o,pendingRetry:s,reasonCount:c}){return(0,O.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,O.jsxs)(m,{children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,O.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Total in DLQ`}),(0,O.jsx)(`span`,{className:t(`rounded-full px-2 py-0.5 text-[11px] font-medium`,n?`bg-amber-500/10 text-warning`:e==null?`bg-surface-2 text-muted`:r?`bg-emerald-500/10 text-success`:`bg-red-500/10 text-danger`),children:n?`Unavailable`:e==null?`Loading`:r?`Healthy`:`Attention`})]}),(0,O.jsx)(`div`,{className:t(`mt-2 text-3xl font-bold tnum`,e==null||n?`text-muted`:r?`text-success`:`text-danger`),children:e==null?`—`:b(e)})]}),(0,O.jsxs)(m,{children:[(0,O.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Top Reason`}),(0,O.jsx)(`div`,{className:`mt-2 text-lg font-semibold text-fg`,children:n||i?`Unavailable`:a?o??`No failures`:`Select a queue`})]}),(0,O.jsxs)(m,{children:[(0,O.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Pending Retry`}),(0,O.jsx)(`div`,{className:`mt-2 text-3xl font-bold tnum text-fg`,children:s==null?`—`:b(s)}),(0,O.jsx)(`div`,{className:`mt-1 text-xs text-faint`,children:a?`in this queue`:`awaiting retry`})]}),(0,O.jsxs)(m,{children:[(0,O.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Failure Types`}),(0,O.jsx)(`div`,{className:`mt-2 text-3xl font-bold tnum text-fg`,children:c==null?`—`:b(c)}),(0,O.jsx)(`div`,{className:`mt-1 text-xs text-faint`,children:`distinct reasons`})]})]})}function k({queues:e,queue:n,onSelect:r}){return e.length===0?null:(0,O.jsxs)(m,{className:`mb-6`,children:[(0,O.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,O.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`DLQ by queue`}),(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsxs)(p,{size:`sm`,disabled:!0,title:w,children:[(0,O.jsx)(c,{className:`size-3.5`}),` Retry all (`,e.length,` queues)`]}),(0,O.jsxs)(p,{variant:`danger`,size:`sm`,disabled:!0,title:C,children:[`Purge all (`,e.length,` queues)`]})]})]}),(0,O.jsx)(`div`,{className:`grid grid-cols-2 gap-3 md:grid-cols-4 xl:grid-cols-5`,children:e.map(e=>(0,O.jsxs)(`button`,{type:`button`,onClick:()=>r(e.name),className:t(`rounded-lg border p-3 text-left transition-colors`,n===e.name?`border-accent/50 bg-surface-2`:`border-line hover:border-line-strong`),children:[(0,O.jsx)(`div`,{className:`truncate font-mono text-xs text-muted`,children:e.name}),(0,O.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:s,onReason:u,onSort:d,onSearch:m,onExport:h}){return(0,O.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-3`,children:[(0,O.jsx)(`div`,{className:`w-48`,children:(0,O.jsxs)(x,{value:e,"aria-label":`Queue`,name:`dlq-queue`,autoComplete:`off`,onChange:e=>s(e.target.value),children:[(0,O.jsx)(`option`,{value:``,children:`Select a queue…`}),t.map(e=>(0,O.jsxs)(`option`,{value:e.name,children:[e.name,e.dlq?` (${e.dlq})`:``]},e.name))]})}),(0,O.jsx)(`div`,{className:`w-40`,children:(0,O.jsxs)(x,{value:n,onChange:e=>u(e.target.value),"aria-label":`Filter by reason`,name:`dlq-reason-filter`,autoComplete:`off`,children:[(0,O.jsx)(`option`,{value:`all`,children:`All Reasons`}),r.map(e=>(0,O.jsx)(`option`,{value:e,children:e},e))]})}),(0,O.jsx)(`div`,{className:`w-36`,children:(0,O.jsxs)(x,{value:i,onChange:e=>d(e.target.value),"aria-label":o?`Sort this page`:`Sort`,name:`dlq-sort`,autoComplete:`off`,children:[(0,O.jsxs)(`option`,{value:`newest`,children:[`Newest First`,o?` (this page)`:``]}),(0,O.jsxs)(`option`,{value:`oldest`,children:[`Oldest First`,o?` (this page)`:``]})]})}),(0,O.jsx)(`input`,{value:a,onChange:e=>m(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,O.jsxs)(p,{size:`sm`,disabled:!0,title:w,children:[(0,O.jsx)(c,{className:`size-3.5`}),` Retry All`]}),(0,O.jsx)(p,{variant:`danger`,size:`sm`,disabled:!0,title:C,children:`Purge All`}),(0,O.jsx)(f,{"aria-label":`Export this page to CSV`,title:`Export this page to CSV`,disabled:!e,onClick:h,children:(0,O.jsx)(l,{className:`size-3.5`})})]})}function j({entries:e,expanded:n,onToggle:r}){return(0,O.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,O.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,O.jsx)(`thead`,{children:(0,O.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,O.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Job ID`}),(0,O.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Name`}),(0,O.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Reason`}),(0,O.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Error`}),(0,O.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Entered`}),(0,O.jsx)(`th`,{className:`w-16 px-5 py-3`})]})}),(0,O.jsx)(`tbody`,{children:e.map(e=>{let a=`${e.job.id}-${e.enteredAt}`;return(0,O.jsxs)(`tr`,{className:`border-b border-line last:border-0 align-top hover:bg-surface-2/40`,children:[(0,O.jsx)(`td`,{className:`px-5 py-3`,children:(0,O.jsx)(i,{to:`/job?id=${encodeURIComponent(e.job.id)}`,className:`font-mono text-xs text-accent hover:underline`,children:e.job.id})}),(0,O.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.job.name??`default`}),(0,O.jsx)(`td`,{className:`px-5 py-3`,children:(0,O.jsx)(`span`,{className:`rounded-md bg-red-500/10 px-2 py-0.5 text-xs text-danger`,children:e.reason})}),(0,O.jsx)(`td`,{className:`max-w-md px-5 py-3 text-xs text-danger/80`,children:e.error?(0,O.jsx)(`button`,{type:`button`,title:e.error,"aria-expanded":n.has(a),onClick:()=>r(a),className:t(`block w-full break-words text-left`,!n.has(a)&&`line-clamp-2`),children:e.error}):`—`}),(0,O.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:y(e.enteredAt)}),(0,O.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,O.jsx)(f,{"aria-label":`Retry unavailable`,disabled:!0,title:w,children:(0,O.jsx)(c,{className:`size-3.5`})})})]},a)})})]})})}var M=25,N=[];function P(){let[e,t]=n(),[r,i]=(0,D.useState)(``),[a,c]=(0,D.useState)(`all`),[l,f]=(0,D.useState)(`newest`),[p,m]=(0,D.useState)(``),[y,b]=(0,D.useState)(0),[x,C]=(0,D.useState)(new Set),{data:P,error:F,loading:I,refetch:L}=d(E,[],{intervalMs:1e4}),R=P?.queues??N,z=P?R.reduce((e,t)=>e+t.dlq,0):null,{data:B,error:V,loading:H,refetch:U}=d((0,D.useCallback)(async()=>{if(!r)return{queue:r,page:y,entries:[],entriesTotal:0,stats:null,statsError:null};let[e,t]=await Promise.all([o.dlq(r,M,y*M),o.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]),W=B?.queue===r&&B.page===y?B:null;(0,D.useEffect)(()=>{if(!W)return;let e=W.entriesTotal??0;y>0&&y*M>=e&&b(Math.max(0,Math.ceil(e/M)-1))},[W,y]);let G=()=>{let e=(W?.entries??[]).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){s.info(`Nothing to export on this page`);return}T(`dlq-${r}`,e,[`jobId`,`reason`,`error`,`enteredAt`,`attempts`])},K=e=>{X.current=!0,i(e),b(0),c(`all`),t(e?{queue:e}:{},{replace:!0})},q=W?.stats?.byReason??{},J=Object.keys(q).filter(e=>q[e]>0),ne=[...J].sort((e,t)=>(q[t]??0)-(q[e]??0))[0],Y=(0,D.useMemo)(()=>R.filter(e=>e.dlq>0).sort((e,t)=>t.dlq-e.dlq),[R]),X=(0,D.useRef)(!1),Z=e.get(`queue`);(0,D.useEffect)(()=>{if(!(X.current||r)){if(Z){if(R.some(e=>e.name===Z)){X.current=!0,i(Z),b(0),c(`all`);return}if(R.length===0)return}Y.length!==0&&(X.current=!0,i(Y[0].name),b(0),c(`all`))}},[r,R,Y,Z]);let Q=(0,D.useMemo)(()=>{let e=W?.entries??[];a!==`all`&&(e=e.filter(e=>e.reason===a));let t=p.trim().toLowerCase();return t&&(e=e.filter(e=>e.job.id.toLowerCase().includes(t))),[...e].sort((e,t)=>l===`newest`?t.enteredAt-e.enteredAt:e.enteredAt-t.enteredAt)},[W,a,p,l]),re=z===0&&!F,$=a!==`all`||p.trim()!==``,ie=(W?.entriesTotal??0)>M;return(0,O.jsxs)(`div`,{children:[(0,O.jsx)(ee,{title:`Dead Letter Queue`,description:`Jobs that failed after exhausting all retries. Inspect and export entries without mutating flow topology.`,live:!!r&&!!W&&!W.statsError&&!V&&!F}),V&&W&&(0,O.jsx)(h,{message:`DLQ refresh failed — showing the last successful page.`,onRetry:U}),F&&(0,O.jsx)(h,{onRetry:L,message:`Could not discover queue DLQ totals — ${F.message}. Health status is unavailable.`}),W?.statsError&&(0,O.jsx)(h,{message:`DLQ statistics are unavailable — ${W.statsError}. The entry list may still be current.`,onRetry:U}),(0,O.jsx)(te,{total:z,discoveryError:!!F,healthy:re,statsError:!!W?.statsError,queue:r,topReason:ne,pendingRetry:W?.stats?.pendingRetry,reasonCount:W?.stats?J.length:void 0}),(0,O.jsx)(k,{queues:Y,queue:r,onSelect:K}),(0,O.jsx)(A,{queue:r,queues:R,reason:a,reasons:J,sort:l,search:p,pageScoped:ie,onQueue:K,onReason:c,onSort:f,onSearch:m,onExport:G}),(0,O.jsx)(`p`,{className:`mb-4 text-xs text-warning`,children:w}),V&&!W?(0,O.jsx)(g,{error:V,onRetry:U}):I&&!P&&!r&&!F?(0,O.jsx)(_,{label:`Discovering queues…`}):H&&!W&&!V?(0,O.jsx)(_,{label:`Loading DLQ…`}):F&&!r?(0,O.jsx)(v,{icon:(0,O.jsx)(u,{}),title:`Could not discover queues`,hint:`${F.message}. Retry the queue discovery request above.`}):r?Q.length===0?(0,O.jsx)(v,{icon:(0,O.jsx)(u,{}),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,O.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,O.jsx)(v,{icon:(0,O.jsx)(u,{}),title:`Select a queue`,hint:`Choose a queue from the dropdown to view its dead letter queue entries.`}),r&&W&&(0,O.jsx)(S,{page:y,pageSize:M,total:W.entriesTotal,onPageChange:b,label:`entries`})]})}export{P as DlqPro};
@@ -0,0 +1,2 @@
1
+ import{i as e,t}from"./cn-zFEt5SO8.js";import{f as n,g as r,r as i,t as a}from"./react-vendor-CvwrP0tU.js";import{a as o,o as s}from"./connectionStore-BJLihGaC.js";import{i as c}from"./upstreamPaths-DQeKSxGc.js";import{a as l,d as u,f as d,s as f}from"./bq-F5BbTG1T.js";import{t as p}from"./Card-CWxrC8OY.js";import{i as m,n as h,r as g}from"./feedback-QDN1AsYt.js";import{t as _}from"./PageHeader-CvIyaFOO.js";import{i as v}from"./index-BFW2_47n.js";import{n as y,t as b}from"./controlConnectionEpoch-CZsS0wAb.js";import{t as x}from"./useControlActionGuard-B-bzKZKI.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`||c(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`||c(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 d(e,t,n);return n?.throwIfAborted(),A(r,t)}function M(e){let t=c(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??u(),{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 l&&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??u(),{signal:a}=n,o=new Map,s=[],c=[],l=new Set,d=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 u=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(!u(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(u(e)){let n=`${e}->${t}`;d.has(n)||(d.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(r(),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,t]=n(),r=v()?ee:``,i=e.toString(),a=(0,I.useMemo)(()=>ue(new URLSearchParams(i),r),[r,i]),c=a.root,l=s(e=>e.baseUrl),d=s(e=>e.token),f=o(),[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,d.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?a.node&&k.jobs.has(a.node)?a.node:h?.defaultSelected??null:null,j=(0,I.useCallback)((e,n=!1)=>{t(t=>de(t,e,r),{replace:n})},[r,t]),N=(0,I.useCallback)(async e=>{let t=s.getState();if(t.baseUrl!==l||t.token!==d)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=u(),o=z(),c=new AbortController;T.current=c;let f=()=>E.current&&n===w.current&&!c.signal.aborted&&o===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()},s.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,d]);return(0,I.useEffect)(()=>{E.current=!0,D.current=z();let e=s.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(d?[]:se(f,!0)),[f,d]),(0,I.useEffect)(()=>{let e={...a};k&&(!e.node||!k.jobs.has(e.node))&&(e.node=h?.defaultSelected??null);let n=L(e).toString();n!==i&&t(n,{replace:!0})},[k,i,t,h?.defaultSelected,a]),(0,I.useEffect)(()=>{m(c),N(c)},[c,N]),{input:p,setInput:m,rootParam:c,mode:a.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}=s.getState();return JSON.stringify([o(),e])}function pe(e){return e instanceof l&&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)=>f(`/flows/create?target=${encodeURIComponent(o())}`,B({operation:e,...t})),getFlow:e=>{let t=new URLSearchParams({id:e.id,queueName:e.queueName,target:o()});return e.depth!==void 0&&t.set(`depth`,String(e.depth)),e.maxChildren!==void 0&&t.set(`maxChildren`,String(e.maxChildren)),f(`/flows/tree?${t}`)},inspect:(e,t)=>f(`/flows/jobs/${encodeURIComponent(e.id)}/${t}?${new URLSearchParams({queueName:e.queueName,target:o()})}`),getParentResult:e=>f(`/flows/results?target=${encodeURIComponent(o())}`,B({operation:`getParentResult`,parentId:e})),getParentResults:e=>f(`/flows/results?target=${encodeURIComponent(o())}`,B({operation:`getParentResults`,parentIds:e})),waitUntilFinished:(e,t)=>f(`/flows/jobs/${encodeURIComponent(e.id)}/waitUntilFinished?${new URLSearchParams({queueName:e.queueName,target:o(),ttl:String(t)})}`,void 0,he(t)),mutate:(e,t,n)=>(S(t),f(`/flows/jobs/${encodeURIComponent(e.id)}/${t}?${new URLSearchParams({queueName:e.queueName,target:o()})}`,me.has(t)?{method:`POST`}:B(n??{})))},H=a();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,i=new Map;for(let t of e)n.set(t,0),r.set(t,0),i.set(t,[]);for(let e of t)!n.has(e.from)||!n.has(e.to)||e.from===e.to||(i.get(e.from)?.push(e.to),r.set(e.to,(r.get(e.to)??0)+1));let a=e.filter(e=>(r.get(e)??0)===0),o=new Set;for(;o.size<n.size;){for(;a.length;){let e=a.shift();if(!o.has(e)){o.add(e);for(let t of i.get(e)??[]){if(o.has(t))continue;n.set(t,Math.max(n.get(t)??0,(n.get(e)??0)+1));let i=(r.get(t)??0)-1;r.set(t,i),i===0&&a.push(t)}}}let t=e.find(e=>!o.has(e));if(t===void 0)break;a.push(t)}return n}function ze(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 Be({graph:e,layout:n,selected:r,onSelect:i}){let a=new Map(n.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:n.width,height:n.height},children:[(0,H.jsxs)(`svg`,{"aria-hidden":`true`,className:`absolute inset-0 text-line`,width:n.width,height:n.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=a.get(e.from),n=a.get(e.to);return!t||!n?null:(0,H.jsx)(`path`,{d:He(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}`)})]}),n.nodes.map(n=>{let a=e.jobs.get(n.id),o=e.failures.has(n.id)?`unavailable`:a?.state??`unknown`;return(0,H.jsxs)(`button`,{type:`button`,"data-flow-node":n.id,onClick:()=>i(n.id),"aria-pressed":r===n.id,"aria-label":`${n.id}, queue ${a?.queue??`unknown`}, state ${o}`,title:n.id,style:{left:n.x,top:n.y,width:168,height:60},className:t(`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(a?.state),r===n.id&&`ring-2 ring-accent`),children:[(0,H.jsx)(`span`,{translate:`no`,className:`truncate font-mono text-xs text-fg`,children:D(n.id)}),(0,H.jsxs)(`span`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[(0,H.jsx)(`span`,{className:`truncate`,children:a?.queue??`—`}),(0,H.jsx)(`span`,{className:`font-medium`,children:o})]})]},n.id)})]})]})}function Ve(e,t,n,r){let i=(e+n)/2;return`M${e},${t} C${i},${t} ${i},${r} ${n},${r}`}function He(e,t){return e.x<=t.x?Ve(e.x+168,e.y+60/2,t.x,t.y+60/2):Ve(e.x,e.y+60/2,t.x+168,t.y+60/2)}function Ue({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)(We,{job:n,failure:r}):(0,H.jsx)(`p`,{className:`text-sm text-muted`,children:`Select a node to inspect it.`}),(0,H.jsx)(Ge,{graph:e})]})})}function We({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)(i,{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 Ge({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 Ke({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)(Be,{graph:e,layout:(0,I.useMemo)(()=>ze([...e.jobs.keys()],e.edges,w),[e]),selected:t,onSelect:n}),(0,H.jsx)(Ue,{graph:e,selected:t})]})}function qe(){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)(Ke,{graph:e.graph,selected:e.selected,onSelect:e.setSelected})]})]})}export{qe as Flows};