bunqueue-dashboard 0.0.33 → 0.0.34

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 (46) hide show
  1. package/dist/.vite/manifest.json +62 -62
  2. package/dist/assets/{AddJob-ytpBLTCJ.js → AddJob-Cih9F84t.js} +1 -1
  3. package/dist/assets/{Alerts-C39RrGbQ.js → Alerts-Dp4Vclez.js} +1 -1
  4. package/dist/assets/{Benchmark-CM60tHbf.js → Benchmark-X_gdZun5.js} +1 -1
  5. package/dist/assets/{BulkAddJobs-BjL-xcQy.js → BulkAddJobs-CXTpYMZf.js} +1 -1
  6. package/dist/assets/{CopilotPanel-BGK1rw-V.js → CopilotPanel-CIXpcwkH.js} +1 -1
  7. package/dist/assets/{Cron-s1e-jgOo.js → Cron-DUHkse77.js} +1 -1
  8. package/dist/assets/{CronManager-BostU7BX.js → CronManager-BeYrLK2E.js} +1 -1
  9. package/dist/assets/{Database-ZluStWMz.js → Database-CXPb3XGr.js} +1 -1
  10. package/dist/assets/{Diagnostics-C0N5z5j-.js → Diagnostics-DDtoiDYT.js} +1 -1
  11. package/dist/assets/{Dlq-CtcLzs-b.js → Dlq-CX_uRblW.js} +1 -1
  12. package/dist/assets/{DlqControl-B_Z8KKn5.js → DlqControl-CazFmSEd.js} +1 -1
  13. package/dist/assets/{DlqPro-B68en6AG.js → DlqPro-HSffdtLJ.js} +1 -1
  14. package/dist/assets/{Flows-CD_bkCBM.js → Flows-CGmyghKF.js} +1 -1
  15. package/dist/assets/{JobInspector-DwRtyMz0.js → JobInspector-B9i1HnG5.js} +1 -1
  16. package/dist/assets/{Jobs-BUtcBKKk.js → Jobs-BZGtMnJI.js} +1 -1
  17. package/dist/assets/{JobsPro-BK_xd4ji.js → JobsPro-tmEN8f-P.js} +1 -1
  18. package/dist/assets/{Logs-CmVODYCI.js → Logs-DxUD9V2A.js} +1 -1
  19. package/dist/assets/{LogsPro-CJ-Il3LP.js → LogsPro-BTQhvPKj.js} +1 -1
  20. package/dist/assets/{McpServer-dMjyJKgT.js → McpServer-D5rwBg74.js} +1 -1
  21. package/dist/assets/{Metrics-Dsbeplz-.js → Metrics-CSPpBf1m.js} +1 -1
  22. package/dist/assets/{MetricsPro-BqxurxrJ.js → MetricsPro-DSn-3qNT.js} +1 -1
  23. package/dist/assets/{Overview-DH9C2dsf.js → Overview-StvHYRZ5.js} +1 -1
  24. package/dist/assets/{Pagination-DpxiBnt8.js → Pagination-eotgGQf9.js} +1 -1
  25. package/dist/assets/{QueueActions-D_QGBaVm.js → QueueActions-CibRLzrz.js} +1 -1
  26. package/dist/assets/{QueueControl-V0DJ6qk6.js → QueueControl-DwYNcMfI.js} +1 -1
  27. package/dist/assets/{QueueDetail-BgKAMJqf.js → QueueDetail-NMfKwj6E.js} +1 -1
  28. package/dist/assets/{QueueDetailPro-BkHYzGiq.js → QueueDetailPro-C8SBjX09.js} +1 -1
  29. package/dist/assets/{Queues-2_v7DcNi.js → Queues-BeTAi8V8.js} +1 -1
  30. package/dist/assets/{QueuesOverview-BySSkmB4.js → QueuesOverview-BfQO8NS4.js} +1 -1
  31. package/dist/assets/{S3Backup-CPADzKQE.js → S3Backup-BYkAtONl.js} +1 -1
  32. package/dist/assets/{S3BackupPro-CSrQYIDL.js → S3BackupPro-BP1Ch54R.js} +1 -1
  33. package/dist/assets/{ServerControl-C0tI1VDx.js → ServerControl-C85jYgyN.js} +1 -1
  34. package/dist/assets/{Settings-CSzoM5up.js → Settings-DjP28c_5.js} +1 -1
  35. package/dist/assets/{Usage-B4B7tmrc.js → Usage-DECeEsO2.js} +1 -1
  36. package/dist/assets/{UsagePro-CCBpgSDy.js → UsagePro-CD7dgt3d.js} +1 -1
  37. package/dist/assets/{Webhooks-aJz-GisQ.js → Webhooks-Ct-x8DD1.js} +1 -1
  38. package/dist/assets/{Workers-Bg8xKjkg.js → Workers-lP1BXHFq.js} +1 -1
  39. package/dist/assets/{WorkersPro-BOOCrXf8.js → WorkersPro-CAUqy3Cp.js} +1 -1
  40. package/dist/assets/{index-Bn2R06qm.js → index-Dr__4DsT.js} +3 -3
  41. package/dist/assets/install-DPCcfOYo.js +3 -0
  42. package/dist/assets/{useThroughputSeries-tb26_lkb.js → useThroughputSeries-Bpyg6Jaq.js} +1 -1
  43. package/dist/index.html +1 -1
  44. package/package.json +1 -1
  45. package/scripts/embedded.gen.ts +120 -120
  46. package/dist/assets/install-CUS8Kijb.js +0 -3
@@ -1 +1 @@
1
- import{r as e,t}from"./cn-CMFYpumL.js";import{g as n,t as r}from"./react-vendor-Bjui4wS4.js";import{o as i}from"./connectionStore-Cd9-3Fw0.js";import{A as a,C as o,O as s,S as c,U as ee,W as l,c as u,h as d,m as f,r as p,s as m,st as h,w as g}from"./index-Bn2R06qm.js";import{i as _,n as v,o as y,t as b}from"./form-DsUq0w8s.js";import{t as x}from"./AreaChart-REK4ZsTC.js";var S=e(n(),1),C={total:1e6,batch:5e3,producers:64,payload:65536,workers:64,workerBatch:1e3,processMs:6e4,durationS:600},w={queue:`benchmark`,mode:`count`,total:5e3,durationS:30,batch:100,producers:4,payload:128,workers:4,workerBatch:100,processMs:5,durable:!1,removeOnComplete:!0},T=`bq-dashboard-benchmark-`;function E(){if(typeof globalThis.crypto?.randomUUID!=`function`)throw Error(`A cryptographically secure browser is required to create a benchmark queue.`);return`${T}${globalThis.crypto.randomUUID()}`}function D(e){return RegExp(`^${T}[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 O={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}},k=(e,t,n)=>Number.isFinite(e)?Math.max(t,Math.min(n,Math.floor(e))):t;function te(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 A=(e,t)=>e.length?e[Math.min(e.length-1,Math.max(0,Math.ceil(t/100*e.length)-1))]:0,j=(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]}:{}})),M=e=>new Promise(t=>setTimeout(t,e)),N=async(e,t)=>{let n=performance.now()+e;for(;t()&&performance.now()<n;)await M(Math.min(100,Math.max(0,n-performance.now())))},P=e=>e instanceof Error?e.message:String(e),F=e=>e>=1e6?`${(e/1e6).toFixed(2)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:`${Math.round(e)}`,I=r();function ne({history:e,onClear:t}){if(!e.length)return null;let n=JSON.stringify(e,null,2);return(0,I.jsxs)(c,{padded:!1,className:`mt-6 overflow-hidden`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between border-b border-line px-5 py-3`,children:[(0,I.jsx)(`h3`,{className:`text-base font-semibold text-fg`,children:`Run history`}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(s,{value:n}),(0,I.jsx)(g,{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,I.jsx)(g,{size:`sm`,variant:`ghost`,onClick:t,children:`Clear`})]})]}),(0,I.jsx)(`div`,{className:`overflow-x-auto`,children:(0,I.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,I.jsx)(`th`,{className:`px-5 py-2 font-medium`,children:`Mode`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Prod`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Wkr`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Pushed`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Done`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Push/s`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Done/s`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`p95`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Dur`})]})}),(0,I.jsx)(`tbody`,{children:e.map(e=>(0,I.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,I.jsx)(`td`,{className:`px-5 py-2 capitalize text-muted`,children:e.mode}),(0,I.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-muted`,children:e.producers}),(0,I.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-muted`,children:e.workers}),(0,I.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-fg`,children:u(e.pushed)}),(0,I.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-success`,children:u(e.completed)}),(0,I.jsxs)(`td`,{className:`px-5 py-2 text-right tnum text-accent`,children:[F(e.pushPerSec),`/s`]}),(0,I.jsxs)(`td`,{className:`px-5 py-2 text-right tnum text-success`,children:[F(e.donePerSec),`/s`]}),(0,I.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-muted`,children:m(e.p95)}),(0,I.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-muted`,children:m(e.durationMs)})]},e.id))})]})})]})}var L={pushed:0,completed:0,pushFailed:0,ackFailed:0,bytes:0,elapsedMs:0,pushPerSec:0,donePerSec:0,activeWorkers:0,pushSeries:[],doneSeries:[],etaMs:null,error:null},R=()=>({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:[]}),z=0,B=[`waiting`,`prioritized`,`delayed`,`active`,`paused`,`waiting-children`,`completed`,`failed`];function V(e){return B.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 H(e,t){if(!e||typeof e!=`object`||e.ok!==!0)throw Error(`${t} returned a malformed success response.`)}function re(){let[e,t]=(0,S.useState)(`idle`),[n,r]=(0,S.useState)(L),[i,a]=(0,S.useState)(null),[o,s]=(0,S.useState)([]),[c,ee]=(0,S.useState)(null),l=(0,S.useRef)(!1),u=(0,S.useRef)(!0),d=(0,S.useRef)(0),f=(0,S.useRef)(!1),p=(0,S.useRef)(!1),m=(0,S.useRef)(null),g=(0,S.useRef)(`idle`);g.current=e;let _=(0,S.useRef)(R());return(0,S.useEffect)(()=>(u.current=!0,()=>{u.current=!1,l.current=!0,d.current++}),[]),(0,S.useEffect)(()=>{if(e!==`running`&&e!==`draining`)return;let t=setInterval(()=>{let e=_.current,t=performance.now(),n=t-e.startedAt,i=(t-e.lastAt)/1e3,a=i>0?Math.max(0,(e.pushed-e.lastPushed)/i):0,o=i>0?Math.max(0,(e.completed-e.lastDone)/i):0;e.lastAt=t,e.lastPushed=e.pushed,e.lastDone=e.completed,e.pushSeries=[...e.pushSeries,a].slice(-60),e.doneSeries=[...e.doneSeries,o].slice(-60);let s=null,c=m.current;if(c&&c.mode===`count`){let t=k(c.total,1,C.total);if(g.current===`draining`){let r=e.doneSeries.slice(-10),i=r.length?r.reduce((e,t)=>e+t,0)/r.length:0;i<=0&&n>0&&(i=e.completed/(n/1e3)),i>0&&(s=Math.max(0,t-e.completed)/i*1e3)}else a>0&&(s=Math.max(0,t-e.pushed)/a*1e3)}else c&&c.mode===`duration`&&(s=Math.max(0,k(c.durationS,1,C.durationS)*1e3-n));r({pushed:e.pushed,completed:e.completed,pushFailed:e.pushFailed,ackFailed:e.ackFailed,bytes:e.bytes,elapsedMs:n,pushPerSec:a,donePerSec:o,activeWorkers:e.activeWorkers,pushSeries:e.pushSeries,doneSeries:e.doneSeries,etaMs:s,error:e.error})},200);return()=>clearInterval(t)},[e]),{phase:e,live:n,summary:i,history:o,runCfg:c,run:async(e,n)=>{if(f.current||!u.current)return;f.current=!0;let i=++d.current,o=n??h.createServerTargetClient(h.captureServerRequestTarget()),c=()=>u.current&&d.current===i,v=()=>c()&&!l.current;l.current=!1;try{a(null);let n=e.queue.trim(),i=te(n);if(i){r({...L,error:i}),g.current=`error`,t(`error`);return}if(![`count`,`duration`].includes(e.mode)){r({...L,error:`Benchmark mode is invalid.`}),g.current=`error`,t(`error`);return}if(typeof e.durable!=`boolean`||typeof e.removeOnComplete!=`boolean`){r({...L,error:`Benchmark job options are invalid.`}),g.current=`error`,t(`error`);return}let u=k(e.total,1,C.total),d=k(e.durationS,1,C.durationS),f=d*1e3,h=k(e.batch,1,C.batch),y=k(e.producers,1,C.producers),b=k(e.payload,0,C.payload),x=k(e.workers,0,C.workers),S=k(e.workerBatch,1,C.workerBatch),w=k(e.processMs,0,C.processMs),T=Object.freeze({...e,queue:n,total:u,durationS:d,batch:h,producers:y,payload:b,workers:x,workerBatch:S,processMs:w});try{H(await o.overview(),`Dashboard preflight`)}catch(e){if(!c())return;r({...L,error:`Server unreachable — start it on the Server page first. (${P(e)})`}),t(`error`);return}if(!v())return;try{let e=await o.counts(n);if(!v())return;if(H(e,`Queue-count preflight`),!e?.counts||typeof e.counts!=`object`||Array.isArray(e.counts))throw Error(`Malformed queue-count response.`);let i=V(e.counts);if(i>0){r({...L,error:`Dedicated benchmark queue "${n}" is not empty (${i} job(s) across all states). Clean it before running so no external work can be consumed or deleted.`}),t(`error`);return}}catch(e){if(!c())return;r({...L,error:`Could not verify that dedicated queue "${n}" is empty. (${P(e)})`}),t(`error`);return}if(!v())return;p.current=!1,m.current=T,ee(T),_.current=R(),_.current.startedAt=performance.now(),_.current.lastAt=performance.now(),r({...L}),g.current=`running`,t(`running`);let E=`x`.repeat(b),D=performance.now()+f,O=`bqbench-${globalThis.crypto.randomUUID()}`,M=new Set,F=new Set,I=async()=>{for(;v();){let e;if(T.mode===`count`){if(_.current.assigned>=u)break;e=Math.min(h,u-_.current.assigned)}else{if(performance.now()>=D)break;e=h}let t=_.current.assigned;_.current.assigned+=e;let r=j(t,e,E,T.durable,T.removeOnComplete,O,Math.max(12e4,w+6e4)),i=performance.now(),a=o.addJobsBulk(n,r).then(t=>{if(!c())return;if(H(t,`Bulk enqueue`),!Array.isArray(t.ids)||t.ids.length!==e||t.ids.some(e=>typeof e!=`string`||e.length===0)||new Set(t.ids).size!==t.ids.length)throw Error(`Bulk enqueue returned invalid job IDs.`);let n=t.ids;for(let e of n)M.add(e);_.current.pushed+=n.length,_.current.bytes+=n.length*b;let r=Math.max(0,e-n.length);r>0&&(_.current.pushFailed+=r,_.current.error??=`Server created ${n.length} of ${e} jobs in a benchmark batch.`)}).catch(t=>{c()&&(_.current.pushFailed+=e,_.current.error??=P(t))});F.add(a);try{await a}finally{F.delete(a)}c()&&_.current.pushLat.push(performance.now()-i)}},ne=async()=>{for(;v()&&!(T.mode===`duration`&&performance.now()>=D||T.mode===`count`&&_.current.completed>=u);){_.current.activeWorkers++;let e=[];try{try{let t=await o.pullBatch(n,S);if(!v())break;if(t?.ok!==!0||!Array.isArray(t?.jobs)||t.jobs.length>S||t.jobs.some(e=>!e||typeof e!=`object`||typeof e.id!=`string`||e.id.length===0)||new Set(t.jobs.map(e=>e.id)).size!==t.jobs.length)throw Error(`Malformed pull-batch response.`);e=t.jobs}catch(e){if(!c())break;_.current.error??=P(e)}if(!v())break;if(e.length>0){if(e.some(e=>!M.has(e.id))&&F.size>0&&await Promise.allSettled([...F]),!v())break;let t=e.filter(e=>M.has(e.id)),n=e.filter(e=>!M.has(e.id));if(n.length>0){if(!v())break;let e=await Promise.allSettled(n.map(async e=>{H(await o.retryJob(e.id),`Restore job ${e.id}`)}));if(!c())break;let t=e.filter(e=>e.status===`rejected`);_.current.error??=t.length>0?`Detected ${n.length} foreign job(s); ${t.length} could not be returned to waiting. Benchmark stopped.`:`Detected ${n.length} foreign job(s); returned them to waiting and stopped without counting them.`,l.current=!0}if(t.length>0&&v()){if(w>0&&await N(w,v),!v())break;try{let e=await o.heartbeatBatch(t.map(e=>e.id));H(e,`Heartbeat benchmark jobs`);let n=e.data;if(!n||typeof n!=`object`||n.ok!==!0||!Number.isSafeInteger(n.count)||n.count!==t.length)throw Error(`Heartbeat confirmed ${String(n?.count)} of ${t.length} benchmark jobs; refusing a lossy batch ACK.`);if(!v()||(H(await o.ackBatch(t.map(e=>e.id)),`Acknowledge benchmark jobs`),!c()))break;_.current.completed+=t.length;for(let e of t)M.delete(e.id)}catch(e){if(!c())break;_.current.ackFailed+=t.length,_.current.error??=P(e)}}}}finally{c()&&_.current.activeWorkers--}if(!v())break;if(e.length===0){if(T.mode===`count`&&p.current){M.size>0&&(_.current.error??=`${M.size} benchmark job(s) could not be drained.`);break}await N(50,v)}}},B=Array.from({length:y},I),re=Array.from({length:x},ne),ie=Promise.all(B).then(()=>{c()&&(p.current=!0,v()&&T.mode===`count`&&x>0&&g.current===`running`&&(g.current=`draining`,t(`draining`)))});if(await Promise.all([ie,...re]),!c())return;let U=_.current,W=performance.now()-U.startedAt,G=W/1e3||1,K=[...U.pushLat].sort((e,t)=>e-t),q={pushed:U.pushed,completed:U.completed,pushFailed:U.pushFailed,ackFailed:U.ackFailed,bytes:U.bytes,durationMs:W,pushPerSec:U.pushed/G,donePerSec:U.completed/G,mbPerSec:U.bytes/G,avg:K.length?K.reduce((e,t)=>e+t,0)/K.length:0,p50:A(K,50),p95:A(K,95),p99:A(K,99),max:K.length?K[K.length-1]:0,error:U.error};a(q),r(e=>({...e,pushed:U.pushed,completed:U.completed,pushFailed:U.pushFailed,ackFailed:U.ackFailed,bytes:U.bytes,elapsedMs:W,pushPerSec:0,donePerSec:0,activeWorkers:0,etaMs:0,error:U.error})),s(e=>[{...q,id:++z,at:Date.now(),mode:T.mode,producers:y,workers:x},...e].slice(0,12)),g.current=l.current?`stopped`:U.error?`error`:`done`,t(g.current)}finally{f.current=!1}},stop:()=>{l.current=!0,(g.current===`running`||g.current===`draining`)&&(g.current=`stopping`,t(`stopping`))},reset:()=>{l.current=!0,d.current++,g.current=`idle`,a(null),r(L),t(`idle`)},clearHistory:()=>s([])}}var ie=[`count`,`duration`],U=[`waiting`,`completed`,`failed`],W=null;function G(){return W??=E(),W}var K=[`total`,`durationS`,`batch`,`producers`,`payload`,`workers`,`workerBatch`,`processMs`],q=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)}),ae=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)});function oe(){let[e]=(0,S.useState)(G),[n,r]=(0,S.useState)(()=>q({...w,queue:e})),s=re(),T=i(e=>e.baseUrl),[E,A]=(0,S.useState)(null),j=(0,S.useRef)(null),M=(0,S.useRef)(!0);(0,S.useEffect)(()=>(M.current=!0,()=>{M.current=!1,j.current=null}),[]);let{phase:N,live:P,summary:L,history:R}=s,z=N===`running`||N===`draining`||N===`stopping`,B=(e,t)=>r(n=>({...n,[e]:t})),W=e=>t=>B(e,t.target.value),oe=e=>r(t=>{let n={...t};for(let[t,r]of Object.entries(e))n[t]=K.includes(t)?String(r):r;return n}),[J,le]=(0,S.useState)(e);(0,S.useEffect)(()=>{let e=setTimeout(()=>le(n.queue.trim()||w.queue),400);return()=>clearTimeout(e)},[n.queue]);let ue=E?.target.baseUrl??T,{data:de,error:fe}=a(()=>E?E.client.counts(J):h.counts(J),[J,E],{intervalMs:1e3}),Y=de?.counts??null,[X,pe]=(0,S.useState)(!1),[Z,Q]=(0,S.useState)(null),me=async()=>{let t=n.queue.trim();if(j.current||!t)return;if(!D(t)||t!==e){Q({error:`refusing to clean a queue not owned by this dashboard session`});return}j.current=`clean`;let r=E;if(!r){let e=h.captureServerRequestTarget();r={target:e,client:h.createServerTargetClient(e)}}let i=Y&&J===t?` Currently ${u(Y.waiting??0)} waiting / ${u(Y.completed??0)} completed.`:``;if(!window.confirm(`Clean every cleanable job from the dedicated dashboard benchmark queue "${t}" on ${r.target.baseUrl}? This is queue-wide; the cryptographic queue name is owned by this browser session.${i}`)){j.current=null;return}pe(!0),Q(null);try{let e=null;for(let n of U){if(!M.current)return;try{let e=await r.client.clean(t,{state:n,limit:C.total});if(H(e,`Clean ${n} jobs`),!Number.isSafeInteger(e.count)||e.count<0)throw Error(`Clean ${n} jobs returned an invalid count.`)}catch(t){e=t.message}}if(!M.current)return;let n=await r.client.counts(t).catch(t=>(e=t.message,null));if(!M.current)return;if(n==null)Q({error:e??`server unreachable — could not verify`});else if(n.ok!==!0||!n.counts||typeof n.counts!=`object`||Array.isArray(n.counts))Q({error:`server returned a malformed queue-count response`});else{let t=n.counts,r;try{r=V(t)}catch{Q({error:`server returned malformed queue counts`});return}Q(e||r>0?{error:e??`${u(r)} job(s) still present`}:{remaining:0})}}finally{M.current&&pe(!1),j.current===`clean`&&(j.current=null)}},$=s.runCfg??ae(n),he=k($.total,1,C.total),ge=k($.workers,0,C.workers),_e=$.mode===`count`&&(z||L)?Math.min(100,P.pushed/he*100):0,ve=$.mode===`count`&&(z||L)?Math.min(100,P.completed/he*100):0,ye=$.mode===`duration`?Math.min(100,P.elapsedMs/(k($.durationS,1,C.durationS)*1e3)*100):0,be=N===`running`?$.mode===`duration`?`Running…`:`Producing…`:N===`draining`?`Draining…`:N===`stopping`?`Stopping…`:N===`error`?`Error`:L?`Result`:`Ready`,xe=(N===`running`||N===`draining`)&&P.etaMs!=null?P.etaMs>0?`ETA ${m(P.etaMs)}`:`finishing…`:N===`stopped`?`stopped early`:N===`done`?`complete`:``;return(0,I.jsxs)(`div`,{children:[(0,I.jsx)(d,{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:N===`stopping`?(0,I.jsxs)(g,{variant:`warning`,size:`sm`,disabled:!0,children:[(0,I.jsx)(ee,{className:`size-3.5`}),` Stopping…`]}):z?(0,I.jsxs)(g,{variant:`warning`,size:`sm`,onClick:s.stop,children:[(0,I.jsx)(ee,{className:`size-3.5`}),` Stop`]}):(0,I.jsxs)(g,{variant:`success`,size:`sm`,disabled:X,onClick:()=>{if(j.current)return;j.current=`run`;let e=ae(n),t=e.queue.trim(),r=h.captureServerRequestTarget(),i=h.createServerTargetClient(r);if(te(t)){s.run({...e,queue:t},i).finally(()=>{j.current===`run`&&(j.current=null)});return}let a=0;if(!E&&Y&&J===t)try{a=V(Y)}catch{}let o=a>0?` Warning: it already holds ${u(a)} 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 "${t}" on ${r.baseUrl}?${o}`)){j.current=null;return}A({target:r,client:i}),s.run(e,i).finally(()=>{j.current===`run`&&(j.current=null)})},children:[(0,I.jsx)(l,{className:`size-3.5`}),` Run benchmark`]})}),P.error&&(0,I.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:P.error}),(0,I.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wider text-faint`,children:`Presets`}),Object.keys(O).map(e=>(0,I.jsx)(`button`,{type:`button`,disabled:z,onClick:()=>oe(O[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,I.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-3`,children:[(0,I.jsxs)(c,{className:`lg:col-span-1`,children:[(0,I.jsx)(o,{title:`Configuration`}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,I.jsx)(b,{label:`Dedicated queue`,hint:`Cryptographically generated for this browser tab; production queue names cannot be entered here.`,children:(0,I.jsx)(v,{name:`benchmark-queue`,autoComplete:`off`,value:n.queue,readOnly:!0,"aria-readonly":`true`})}),(0,I.jsx)(b,{label:`Mode`,hint:n.mode===`count`?`Push a fixed number of jobs.`:`Run producers + workers for a fixed time.`,children:(0,I.jsx)(_,{options:ie,value:n.mode,onChange:e=>B(`mode`,e),disabled:z})}),n.mode===`count`?(0,I.jsx)(b,{label:`Total jobs`,hint:`max ${u(C.total)}`,children:(0,I.jsx)(v,{name:`benchmark-total`,autoComplete:`off`,type:`number`,min:1,max:C.total,value:n.total,disabled:z,onChange:W(`total`)})}):(0,I.jsx)(b,{label:`Duration (s)`,hint:`max ${C.durationS}s`,children:(0,I.jsx)(v,{name:`benchmark-duration-seconds`,autoComplete:`off`,type:`number`,min:1,max:C.durationS,value:n.durationS,disabled:z,onChange:W(`durationS`)})}),(0,I.jsx)(`div`,{className:`mt-1 text-[11px] font-semibold uppercase tracking-wider text-faint`,children:`Producers`}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,I.jsx)(b,{label:`Producers`,hint:`parallel, max ${C.producers}`,children:(0,I.jsx)(v,{name:`benchmark-producers`,autoComplete:`off`,type:`number`,min:1,max:C.producers,value:n.producers,disabled:z,onChange:W(`producers`)})}),(0,I.jsx)(b,{label:`Push batch`,hint:`jobs/req, max ${C.batch}`,children:(0,I.jsx)(v,{name:`benchmark-push-batch`,autoComplete:`off`,type:`number`,min:1,max:C.batch,value:n.batch,disabled:z,onChange:W(`batch`)})}),(0,I.jsx)(b,{label:`Payload`,hint:`bytes/job, max ${u(C.payload)}`,children:(0,I.jsx)(v,{name:`benchmark-payload-bytes`,autoComplete:`off`,type:`number`,min:0,max:C.payload,value:n.payload,disabled:z,onChange:W(`payload`)})})]}),(0,I.jsx)(`div`,{className:`mt-1 text-[11px] font-semibold uppercase tracking-wider text-faint`,children:`Workers (simulated)`}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,I.jsx)(b,{label:`Workers`,hint:`0 = produce only, max ${C.workers}`,children:(0,I.jsx)(v,{name:`benchmark-workers`,autoComplete:`off`,type:`number`,min:0,max:C.workers,value:n.workers,disabled:z,onChange:W(`workers`)})}),(0,I.jsx)(b,{label:`Pull batch`,hint:`jobs/pull, max ${C.workerBatch}`,children:(0,I.jsx)(v,{name:`benchmark-pull-batch`,autoComplete:`off`,type:`number`,min:1,max:C.workerBatch,value:n.workerBatch,disabled:z,onChange:W(`workerBatch`)})}),(0,I.jsx)(b,{label:`Process (ms)`,hint:`simulated work per pull`,children:(0,I.jsx)(v,{name:`benchmark-process-ms`,autoComplete:`off`,type:`number`,min:0,max:C.processMs,value:n.processMs,disabled:z,onChange:W(`processMs`)})})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(y,{checked:n.durable,onChange:e=>B(`durable`,e),disabled:z,label:`Durable (fsync each job)`}),(0,I.jsx)(`span`,{className:`text-sm text-muted`,children:`Durable (fsync each job)`})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(y,{checked:n.removeOnComplete,onChange:e=>B(`removeOnComplete`,e),disabled:z,label:`Remove on complete`}),(0,I.jsx)(`span`,{className:`text-sm text-muted`,children:`Remove on complete`})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,I.jsx)(g,{variant:`ghost`,size:`sm`,disabled:z||X,onClick:me,children:X?`Cleaning…`:`Clean queue`}),Z&&(`error`in Z?(0,I.jsxs)(`span`,{className:`text-xs text-danger`,children:[`Clean unverified — `,Z.error]}):(0,I.jsx)(`span`,{className:t(`text-xs`,Z.remaining>0?`text-warning`:`text-success`),children:Z.remaining>0?`Cleaned — ${u(Z.remaining)} active job(s) remain (requeued after the stall timeout)`:`Cleaned — 0 jobs remain`}))]})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-6 lg:col-span-2`,children:[(0,I.jsxs)(c,{children:[(0,I.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,I.jsx)(`h3`,{className:`text-base font-semibold text-fg`,children:be}),(0,I.jsxs)(`span`,{className:`text-right text-xs text-faint`,children:[(0,I.jsxs)(`span`,{className:`block`,children:[`Benchmark target: `,ue]}),xe&&(0,I.jsx)(`span`,{className:`block`,children:xe})]})]}),(0,I.jsx)(se,{label:$.mode===`duration`?`Elapsed`:`Produced`,pct:$.mode===`duration`?ye:_e,tone:`accent`}),ge>0&&$.mode===`count`&&(0,I.jsx)(se,{label:`Completed`,pct:ve,tone:`emerald`}),(0,I.jsxs)(`div`,{className:`mt-4 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,I.jsx)(f,{label:`Pushed`,value:u(P.pushed),tone:`accent`,compact:!0}),(0,I.jsx)(f,{label:`Completed`,value:u(P.completed),tone:`green`,compact:!0}),(0,I.jsx)(f,{label:`Push/sec`,value:F(P.pushPerSec),compact:!0}),(0,I.jsx)(f,{label:`Done/sec`,value:F(P.donePerSec),tone:`green`,compact:!0}),(0,I.jsx)(f,{label:`Elapsed`,value:m(P.elapsedMs),compact:!0}),(0,I.jsx)(f,{label:`Active workers`,value:`${P.activeWorkers}/${ge}`,tone:`blue`,compact:!0}),(0,I.jsx)(f,{label:`Data`,value:p(L?.bytes??P.bytes),compact:!0}),(0,I.jsx)(f,{label:`Errors`,value:u((L?.pushFailed??P.pushFailed)+(L?.ackFailed??P.ackFailed)),tone:P.pushFailed+P.ackFailed?`red`:`default`,compact:!0})]})]}),(0,I.jsxs)(c,{children:[(0,I.jsx)(o,{title:`Throughput`}),(0,I.jsx)(`p`,{className:`-mt-3 mb-4 text-xs text-faint`,children:`Enqueue (client → server) vs completion (workers) per second`}),(0,I.jsx)(x,{series:[{label:`Push/sec`,color:`#38bdf8`,points:P.pushSeries,area:!0},{label:`Done/sec`,color:`#34d399`,points:P.doneSeries,area:!0}]}),(0,I.jsxs)(`div`,{className:`mt-2 flex items-center gap-4 font-mono text-[11px] text-faint`,children:[(0,I.jsx)(ce,{color:`#38bdf8`,label:`Push/sec`,value:P.pushPerSec}),(0,I.jsx)(ce,{color:`#34d399`,label:`Done/sec`,value:P.donePerSec})]})]})]})]}),L&&(0,I.jsxs)(c,{className:`mt-6`,children:[(0,I.jsx)(o,{title:`Summary`}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-4 xl:grid-cols-8`,children:[(0,I.jsx)(f,{label:`Pushed`,value:u(L.pushed),tone:`accent`,compact:!0}),(0,I.jsx)(f,{label:`Completed`,value:u(L.completed),tone:`green`,compact:!0}),(0,I.jsx)(f,{label:`Duration`,value:m(L.durationMs),compact:!0}),(0,I.jsx)(f,{label:`Avg push/s`,value:F(L.pushPerSec),tone:`accent`,compact:!0}),(0,I.jsx)(f,{label:`Avg done/s`,value:F(L.donePerSec),tone:`green`,compact:!0}),(0,I.jsx)(f,{label:`Data rate`,value:`${p(L.mbPerSec)}/s`,compact:!0}),(0,I.jsx)(f,{label:`Push p95`,value:m(L.p95),compact:!0}),(0,I.jsx)(f,{label:`Push p99`,value:m(L.p99),compact:!0})]}),(0,I.jsxs)(`p`,{className:`mt-3 text-xs text-faint`,children:[`Push-batch latency avg `,m(L.avg),` · p50 `,m(L.p50),` · p95`,` `,m(L.p95),` · p99 `,m(L.p99),` · max `,m(L.max),`.`,L.error?` First error: ${L.error}`:``]})]}),(0,I.jsxs)(c,{className:`mt-6`,children:[(0,I.jsx)(o,{title:`Server queue: ${J}`,action:fe?(0,I.jsx)(`span`,{className:`text-xs font-medium text-warning`,children:`stale — server unreachable`}):void 0}),(0,I.jsxs)(`p`,{className:`-mt-3 mb-4 text-xs text-faint`,children:[`Live counts from `,ue,` (poll 1s).`,E?` Pinned to the current or last benchmark run.`:``]}),Y?(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-5`,children:[(0,I.jsx)(f,{label:`Waiting`,value:u(Y.waiting??0),tone:`amber`,compact:!0}),(0,I.jsx)(f,{label:`Active`,value:u(Y.active??0),tone:`blue`,compact:!0}),(0,I.jsx)(f,{label:`Completed`,value:u(Y.completed??0),tone:`green`,compact:!0}),(0,I.jsx)(f,{label:`Failed`,value:u(Y.failed??0),tone:Y.failed?`red`:`default`,compact:!0}),(0,I.jsx)(f,{label:`Delayed`,value:u(Y.delayed??0),compact:!0})]}):(0,I.jsx)(`p`,{className:`text-sm text-faint`,children:`No counts yet — waiting for the server to answer for this queue.`})]}),(0,I.jsx)(ne,{history:R,onClear:s.clearHistory})]})}function se({label:e,pct:n,tone:r}){return(0,I.jsxs)(`div`,{className:`mb-2`,children:[(0,I.jsxs)(`div`,{className:`mb-1 flex items-center justify-between text-[11px] text-faint`,children:[(0,I.jsx)(`span`,{children:e}),(0,I.jsxs)(`span`,{className:`tnum`,children:[n.toFixed(0),`%`]})]}),(0,I.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,I.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 ce({color:e,label:t,value:n}){return(0,I.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,I.jsx)(`span`,{className:`size-2 rounded-full`,style:{background:e}}),t,` `,(0,I.jsxs)(`span`,{className:`text-fg`,children:[F(n),`/s`]})]})}export{oe as Benchmark};
1
+ import{r as e,t}from"./cn-CMFYpumL.js";import{g as n,t as r}from"./react-vendor-Bjui4wS4.js";import{o as i}from"./connectionStore-Cd9-3Fw0.js";import{A as a,C as o,O as s,S as c,U as ee,W as l,c as u,h as d,m as f,r as p,s as m,st as h,w as g}from"./index-Dr__4DsT.js";import{i as _,n as v,o as y,t as b}from"./form-DsUq0w8s.js";import{t as x}from"./AreaChart-REK4ZsTC.js";var S=e(n(),1),C={total:1e6,batch:5e3,producers:64,payload:65536,workers:64,workerBatch:1e3,processMs:6e4,durationS:600},w={queue:`benchmark`,mode:`count`,total:5e3,durationS:30,batch:100,producers:4,payload:128,workers:4,workerBatch:100,processMs:5,durable:!1,removeOnComplete:!0},T=`bq-dashboard-benchmark-`;function E(){if(typeof globalThis.crypto?.randomUUID!=`function`)throw Error(`A cryptographically secure browser is required to create a benchmark queue.`);return`${T}${globalThis.crypto.randomUUID()}`}function D(e){return RegExp(`^${T}[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 O={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}},k=(e,t,n)=>Number.isFinite(e)?Math.max(t,Math.min(n,Math.floor(e))):t;function te(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 A=(e,t)=>e.length?e[Math.min(e.length-1,Math.max(0,Math.ceil(t/100*e.length)-1))]:0,j=(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]}:{}})),M=e=>new Promise(t=>setTimeout(t,e)),N=async(e,t)=>{let n=performance.now()+e;for(;t()&&performance.now()<n;)await M(Math.min(100,Math.max(0,n-performance.now())))},P=e=>e instanceof Error?e.message:String(e),F=e=>e>=1e6?`${(e/1e6).toFixed(2)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:`${Math.round(e)}`,I=r();function ne({history:e,onClear:t}){if(!e.length)return null;let n=JSON.stringify(e,null,2);return(0,I.jsxs)(c,{padded:!1,className:`mt-6 overflow-hidden`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between border-b border-line px-5 py-3`,children:[(0,I.jsx)(`h3`,{className:`text-base font-semibold text-fg`,children:`Run history`}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(s,{value:n}),(0,I.jsx)(g,{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,I.jsx)(g,{size:`sm`,variant:`ghost`,onClick:t,children:`Clear`})]})]}),(0,I.jsx)(`div`,{className:`overflow-x-auto`,children:(0,I.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,I.jsx)(`thead`,{children:(0,I.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,I.jsx)(`th`,{className:`px-5 py-2 font-medium`,children:`Mode`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Prod`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Wkr`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Pushed`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Done`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Push/s`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Done/s`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`p95`}),(0,I.jsx)(`th`,{className:`px-5 py-2 text-right font-medium`,children:`Dur`})]})}),(0,I.jsx)(`tbody`,{children:e.map(e=>(0,I.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,I.jsx)(`td`,{className:`px-5 py-2 capitalize text-muted`,children:e.mode}),(0,I.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-muted`,children:e.producers}),(0,I.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-muted`,children:e.workers}),(0,I.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-fg`,children:u(e.pushed)}),(0,I.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-success`,children:u(e.completed)}),(0,I.jsxs)(`td`,{className:`px-5 py-2 text-right tnum text-accent`,children:[F(e.pushPerSec),`/s`]}),(0,I.jsxs)(`td`,{className:`px-5 py-2 text-right tnum text-success`,children:[F(e.donePerSec),`/s`]}),(0,I.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-muted`,children:m(e.p95)}),(0,I.jsx)(`td`,{className:`px-5 py-2 text-right tnum text-muted`,children:m(e.durationMs)})]},e.id))})]})})]})}var L={pushed:0,completed:0,pushFailed:0,ackFailed:0,bytes:0,elapsedMs:0,pushPerSec:0,donePerSec:0,activeWorkers:0,pushSeries:[],doneSeries:[],etaMs:null,error:null},R=()=>({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:[]}),z=0,B=[`waiting`,`prioritized`,`delayed`,`active`,`paused`,`waiting-children`,`completed`,`failed`];function V(e){return B.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 H(e,t){if(!e||typeof e!=`object`||e.ok!==!0)throw Error(`${t} returned a malformed success response.`)}function re(){let[e,t]=(0,S.useState)(`idle`),[n,r]=(0,S.useState)(L),[i,a]=(0,S.useState)(null),[o,s]=(0,S.useState)([]),[c,ee]=(0,S.useState)(null),l=(0,S.useRef)(!1),u=(0,S.useRef)(!0),d=(0,S.useRef)(0),f=(0,S.useRef)(!1),p=(0,S.useRef)(!1),m=(0,S.useRef)(null),g=(0,S.useRef)(`idle`);g.current=e;let _=(0,S.useRef)(R());return(0,S.useEffect)(()=>(u.current=!0,()=>{u.current=!1,l.current=!0,d.current++}),[]),(0,S.useEffect)(()=>{if(e!==`running`&&e!==`draining`)return;let t=setInterval(()=>{let e=_.current,t=performance.now(),n=t-e.startedAt,i=(t-e.lastAt)/1e3,a=i>0?Math.max(0,(e.pushed-e.lastPushed)/i):0,o=i>0?Math.max(0,(e.completed-e.lastDone)/i):0;e.lastAt=t,e.lastPushed=e.pushed,e.lastDone=e.completed,e.pushSeries=[...e.pushSeries,a].slice(-60),e.doneSeries=[...e.doneSeries,o].slice(-60);let s=null,c=m.current;if(c&&c.mode===`count`){let t=k(c.total,1,C.total);if(g.current===`draining`){let r=e.doneSeries.slice(-10),i=r.length?r.reduce((e,t)=>e+t,0)/r.length:0;i<=0&&n>0&&(i=e.completed/(n/1e3)),i>0&&(s=Math.max(0,t-e.completed)/i*1e3)}else a>0&&(s=Math.max(0,t-e.pushed)/a*1e3)}else c&&c.mode===`duration`&&(s=Math.max(0,k(c.durationS,1,C.durationS)*1e3-n));r({pushed:e.pushed,completed:e.completed,pushFailed:e.pushFailed,ackFailed:e.ackFailed,bytes:e.bytes,elapsedMs:n,pushPerSec:a,donePerSec:o,activeWorkers:e.activeWorkers,pushSeries:e.pushSeries,doneSeries:e.doneSeries,etaMs:s,error:e.error})},200);return()=>clearInterval(t)},[e]),{phase:e,live:n,summary:i,history:o,runCfg:c,run:async(e,n)=>{if(f.current||!u.current)return;f.current=!0;let i=++d.current,o=n??h.createServerTargetClient(h.captureServerRequestTarget()),c=()=>u.current&&d.current===i,v=()=>c()&&!l.current;l.current=!1;try{a(null);let n=e.queue.trim(),i=te(n);if(i){r({...L,error:i}),g.current=`error`,t(`error`);return}if(![`count`,`duration`].includes(e.mode)){r({...L,error:`Benchmark mode is invalid.`}),g.current=`error`,t(`error`);return}if(typeof e.durable!=`boolean`||typeof e.removeOnComplete!=`boolean`){r({...L,error:`Benchmark job options are invalid.`}),g.current=`error`,t(`error`);return}let u=k(e.total,1,C.total),d=k(e.durationS,1,C.durationS),f=d*1e3,h=k(e.batch,1,C.batch),y=k(e.producers,1,C.producers),b=k(e.payload,0,C.payload),x=k(e.workers,0,C.workers),S=k(e.workerBatch,1,C.workerBatch),w=k(e.processMs,0,C.processMs),T=Object.freeze({...e,queue:n,total:u,durationS:d,batch:h,producers:y,payload:b,workers:x,workerBatch:S,processMs:w});try{H(await o.overview(),`Dashboard preflight`)}catch(e){if(!c())return;r({...L,error:`Server unreachable — start it on the Server page first. (${P(e)})`}),t(`error`);return}if(!v())return;try{let e=await o.counts(n);if(!v())return;if(H(e,`Queue-count preflight`),!e?.counts||typeof e.counts!=`object`||Array.isArray(e.counts))throw Error(`Malformed queue-count response.`);let i=V(e.counts);if(i>0){r({...L,error:`Dedicated benchmark queue "${n}" is not empty (${i} job(s) across all states). Clean it before running so no external work can be consumed or deleted.`}),t(`error`);return}}catch(e){if(!c())return;r({...L,error:`Could not verify that dedicated queue "${n}" is empty. (${P(e)})`}),t(`error`);return}if(!v())return;p.current=!1,m.current=T,ee(T),_.current=R(),_.current.startedAt=performance.now(),_.current.lastAt=performance.now(),r({...L}),g.current=`running`,t(`running`);let E=`x`.repeat(b),D=performance.now()+f,O=`bqbench-${globalThis.crypto.randomUUID()}`,M=new Set,F=new Set,I=async()=>{for(;v();){let e;if(T.mode===`count`){if(_.current.assigned>=u)break;e=Math.min(h,u-_.current.assigned)}else{if(performance.now()>=D)break;e=h}let t=_.current.assigned;_.current.assigned+=e;let r=j(t,e,E,T.durable,T.removeOnComplete,O,Math.max(12e4,w+6e4)),i=performance.now(),a=o.addJobsBulk(n,r).then(t=>{if(!c())return;if(H(t,`Bulk enqueue`),!Array.isArray(t.ids)||t.ids.length!==e||t.ids.some(e=>typeof e!=`string`||e.length===0)||new Set(t.ids).size!==t.ids.length)throw Error(`Bulk enqueue returned invalid job IDs.`);let n=t.ids;for(let e of n)M.add(e);_.current.pushed+=n.length,_.current.bytes+=n.length*b;let r=Math.max(0,e-n.length);r>0&&(_.current.pushFailed+=r,_.current.error??=`Server created ${n.length} of ${e} jobs in a benchmark batch.`)}).catch(t=>{c()&&(_.current.pushFailed+=e,_.current.error??=P(t))});F.add(a);try{await a}finally{F.delete(a)}c()&&_.current.pushLat.push(performance.now()-i)}},ne=async()=>{for(;v()&&!(T.mode===`duration`&&performance.now()>=D||T.mode===`count`&&_.current.completed>=u);){_.current.activeWorkers++;let e=[];try{try{let t=await o.pullBatch(n,S);if(!v())break;if(t?.ok!==!0||!Array.isArray(t?.jobs)||t.jobs.length>S||t.jobs.some(e=>!e||typeof e!=`object`||typeof e.id!=`string`||e.id.length===0)||new Set(t.jobs.map(e=>e.id)).size!==t.jobs.length)throw Error(`Malformed pull-batch response.`);e=t.jobs}catch(e){if(!c())break;_.current.error??=P(e)}if(!v())break;if(e.length>0){if(e.some(e=>!M.has(e.id))&&F.size>0&&await Promise.allSettled([...F]),!v())break;let t=e.filter(e=>M.has(e.id)),n=e.filter(e=>!M.has(e.id));if(n.length>0){if(!v())break;let e=await Promise.allSettled(n.map(async e=>{H(await o.retryJob(e.id),`Restore job ${e.id}`)}));if(!c())break;let t=e.filter(e=>e.status===`rejected`);_.current.error??=t.length>0?`Detected ${n.length} foreign job(s); ${t.length} could not be returned to waiting. Benchmark stopped.`:`Detected ${n.length} foreign job(s); returned them to waiting and stopped without counting them.`,l.current=!0}if(t.length>0&&v()){if(w>0&&await N(w,v),!v())break;try{let e=await o.heartbeatBatch(t.map(e=>e.id));H(e,`Heartbeat benchmark jobs`);let n=e.data;if(!n||typeof n!=`object`||n.ok!==!0||!Number.isSafeInteger(n.count)||n.count!==t.length)throw Error(`Heartbeat confirmed ${String(n?.count)} of ${t.length} benchmark jobs; refusing a lossy batch ACK.`);if(!v()||(H(await o.ackBatch(t.map(e=>e.id)),`Acknowledge benchmark jobs`),!c()))break;_.current.completed+=t.length;for(let e of t)M.delete(e.id)}catch(e){if(!c())break;_.current.ackFailed+=t.length,_.current.error??=P(e)}}}}finally{c()&&_.current.activeWorkers--}if(!v())break;if(e.length===0){if(T.mode===`count`&&p.current){M.size>0&&(_.current.error??=`${M.size} benchmark job(s) could not be drained.`);break}await N(50,v)}}},B=Array.from({length:y},I),re=Array.from({length:x},ne),ie=Promise.all(B).then(()=>{c()&&(p.current=!0,v()&&T.mode===`count`&&x>0&&g.current===`running`&&(g.current=`draining`,t(`draining`)))});if(await Promise.all([ie,...re]),!c())return;let U=_.current,W=performance.now()-U.startedAt,G=W/1e3||1,K=[...U.pushLat].sort((e,t)=>e-t),q={pushed:U.pushed,completed:U.completed,pushFailed:U.pushFailed,ackFailed:U.ackFailed,bytes:U.bytes,durationMs:W,pushPerSec:U.pushed/G,donePerSec:U.completed/G,mbPerSec:U.bytes/G,avg:K.length?K.reduce((e,t)=>e+t,0)/K.length:0,p50:A(K,50),p95:A(K,95),p99:A(K,99),max:K.length?K[K.length-1]:0,error:U.error};a(q),r(e=>({...e,pushed:U.pushed,completed:U.completed,pushFailed:U.pushFailed,ackFailed:U.ackFailed,bytes:U.bytes,elapsedMs:W,pushPerSec:0,donePerSec:0,activeWorkers:0,etaMs:0,error:U.error})),s(e=>[{...q,id:++z,at:Date.now(),mode:T.mode,producers:y,workers:x},...e].slice(0,12)),g.current=l.current?`stopped`:U.error?`error`:`done`,t(g.current)}finally{f.current=!1}},stop:()=>{l.current=!0,(g.current===`running`||g.current===`draining`)&&(g.current=`stopping`,t(`stopping`))},reset:()=>{l.current=!0,d.current++,g.current=`idle`,a(null),r(L),t(`idle`)},clearHistory:()=>s([])}}var ie=[`count`,`duration`],U=[`waiting`,`completed`,`failed`],W=null;function G(){return W??=E(),W}var K=[`total`,`durationS`,`batch`,`producers`,`payload`,`workers`,`workerBatch`,`processMs`],q=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)}),ae=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)});function oe(){let[e]=(0,S.useState)(G),[n,r]=(0,S.useState)(()=>q({...w,queue:e})),s=re(),T=i(e=>e.baseUrl),[E,A]=(0,S.useState)(null),j=(0,S.useRef)(null),M=(0,S.useRef)(!0);(0,S.useEffect)(()=>(M.current=!0,()=>{M.current=!1,j.current=null}),[]);let{phase:N,live:P,summary:L,history:R}=s,z=N===`running`||N===`draining`||N===`stopping`,B=(e,t)=>r(n=>({...n,[e]:t})),W=e=>t=>B(e,t.target.value),oe=e=>r(t=>{let n={...t};for(let[t,r]of Object.entries(e))n[t]=K.includes(t)?String(r):r;return n}),[J,le]=(0,S.useState)(e);(0,S.useEffect)(()=>{let e=setTimeout(()=>le(n.queue.trim()||w.queue),400);return()=>clearTimeout(e)},[n.queue]);let ue=E?.target.baseUrl??T,{data:de,error:fe}=a(()=>E?E.client.counts(J):h.counts(J),[J,E],{intervalMs:1e3}),Y=de?.counts??null,[X,pe]=(0,S.useState)(!1),[Z,Q]=(0,S.useState)(null),me=async()=>{let t=n.queue.trim();if(j.current||!t)return;if(!D(t)||t!==e){Q({error:`refusing to clean a queue not owned by this dashboard session`});return}j.current=`clean`;let r=E;if(!r){let e=h.captureServerRequestTarget();r={target:e,client:h.createServerTargetClient(e)}}let i=Y&&J===t?` Currently ${u(Y.waiting??0)} waiting / ${u(Y.completed??0)} completed.`:``;if(!window.confirm(`Clean every cleanable job from the dedicated dashboard benchmark queue "${t}" on ${r.target.baseUrl}? This is queue-wide; the cryptographic queue name is owned by this browser session.${i}`)){j.current=null;return}pe(!0),Q(null);try{let e=null;for(let n of U){if(!M.current)return;try{let e=await r.client.clean(t,{state:n,limit:C.total});if(H(e,`Clean ${n} jobs`),!Number.isSafeInteger(e.count)||e.count<0)throw Error(`Clean ${n} jobs returned an invalid count.`)}catch(t){e=t.message}}if(!M.current)return;let n=await r.client.counts(t).catch(t=>(e=t.message,null));if(!M.current)return;if(n==null)Q({error:e??`server unreachable — could not verify`});else if(n.ok!==!0||!n.counts||typeof n.counts!=`object`||Array.isArray(n.counts))Q({error:`server returned a malformed queue-count response`});else{let t=n.counts,r;try{r=V(t)}catch{Q({error:`server returned malformed queue counts`});return}Q(e||r>0?{error:e??`${u(r)} job(s) still present`}:{remaining:0})}}finally{M.current&&pe(!1),j.current===`clean`&&(j.current=null)}},$=s.runCfg??ae(n),he=k($.total,1,C.total),ge=k($.workers,0,C.workers),_e=$.mode===`count`&&(z||L)?Math.min(100,P.pushed/he*100):0,ve=$.mode===`count`&&(z||L)?Math.min(100,P.completed/he*100):0,ye=$.mode===`duration`?Math.min(100,P.elapsedMs/(k($.durationS,1,C.durationS)*1e3)*100):0,be=N===`running`?$.mode===`duration`?`Running…`:`Producing…`:N===`draining`?`Draining…`:N===`stopping`?`Stopping…`:N===`error`?`Error`:L?`Result`:`Ready`,xe=(N===`running`||N===`draining`)&&P.etaMs!=null?P.etaMs>0?`ETA ${m(P.etaMs)}`:`finishing…`:N===`stopped`?`stopped early`:N===`done`?`complete`:``;return(0,I.jsxs)(`div`,{children:[(0,I.jsx)(d,{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:N===`stopping`?(0,I.jsxs)(g,{variant:`warning`,size:`sm`,disabled:!0,children:[(0,I.jsx)(ee,{className:`size-3.5`}),` Stopping…`]}):z?(0,I.jsxs)(g,{variant:`warning`,size:`sm`,onClick:s.stop,children:[(0,I.jsx)(ee,{className:`size-3.5`}),` Stop`]}):(0,I.jsxs)(g,{variant:`success`,size:`sm`,disabled:X,onClick:()=>{if(j.current)return;j.current=`run`;let e=ae(n),t=e.queue.trim(),r=h.captureServerRequestTarget(),i=h.createServerTargetClient(r);if(te(t)){s.run({...e,queue:t},i).finally(()=>{j.current===`run`&&(j.current=null)});return}let a=0;if(!E&&Y&&J===t)try{a=V(Y)}catch{}let o=a>0?` Warning: it already holds ${u(a)} 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 "${t}" on ${r.baseUrl}?${o}`)){j.current=null;return}A({target:r,client:i}),s.run(e,i).finally(()=>{j.current===`run`&&(j.current=null)})},children:[(0,I.jsx)(l,{className:`size-3.5`}),` Run benchmark`]})}),P.error&&(0,I.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:P.error}),(0,I.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-wider text-faint`,children:`Presets`}),Object.keys(O).map(e=>(0,I.jsx)(`button`,{type:`button`,disabled:z,onClick:()=>oe(O[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,I.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-3`,children:[(0,I.jsxs)(c,{className:`lg:col-span-1`,children:[(0,I.jsx)(o,{title:`Configuration`}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,I.jsx)(b,{label:`Dedicated queue`,hint:`Cryptographically generated for this browser tab; production queue names cannot be entered here.`,children:(0,I.jsx)(v,{name:`benchmark-queue`,autoComplete:`off`,value:n.queue,readOnly:!0,"aria-readonly":`true`})}),(0,I.jsx)(b,{label:`Mode`,hint:n.mode===`count`?`Push a fixed number of jobs.`:`Run producers + workers for a fixed time.`,children:(0,I.jsx)(_,{options:ie,value:n.mode,onChange:e=>B(`mode`,e),disabled:z})}),n.mode===`count`?(0,I.jsx)(b,{label:`Total jobs`,hint:`max ${u(C.total)}`,children:(0,I.jsx)(v,{name:`benchmark-total`,autoComplete:`off`,type:`number`,min:1,max:C.total,value:n.total,disabled:z,onChange:W(`total`)})}):(0,I.jsx)(b,{label:`Duration (s)`,hint:`max ${C.durationS}s`,children:(0,I.jsx)(v,{name:`benchmark-duration-seconds`,autoComplete:`off`,type:`number`,min:1,max:C.durationS,value:n.durationS,disabled:z,onChange:W(`durationS`)})}),(0,I.jsx)(`div`,{className:`mt-1 text-[11px] font-semibold uppercase tracking-wider text-faint`,children:`Producers`}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,I.jsx)(b,{label:`Producers`,hint:`parallel, max ${C.producers}`,children:(0,I.jsx)(v,{name:`benchmark-producers`,autoComplete:`off`,type:`number`,min:1,max:C.producers,value:n.producers,disabled:z,onChange:W(`producers`)})}),(0,I.jsx)(b,{label:`Push batch`,hint:`jobs/req, max ${C.batch}`,children:(0,I.jsx)(v,{name:`benchmark-push-batch`,autoComplete:`off`,type:`number`,min:1,max:C.batch,value:n.batch,disabled:z,onChange:W(`batch`)})}),(0,I.jsx)(b,{label:`Payload`,hint:`bytes/job, max ${u(C.payload)}`,children:(0,I.jsx)(v,{name:`benchmark-payload-bytes`,autoComplete:`off`,type:`number`,min:0,max:C.payload,value:n.payload,disabled:z,onChange:W(`payload`)})})]}),(0,I.jsx)(`div`,{className:`mt-1 text-[11px] font-semibold uppercase tracking-wider text-faint`,children:`Workers (simulated)`}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,I.jsx)(b,{label:`Workers`,hint:`0 = produce only, max ${C.workers}`,children:(0,I.jsx)(v,{name:`benchmark-workers`,autoComplete:`off`,type:`number`,min:0,max:C.workers,value:n.workers,disabled:z,onChange:W(`workers`)})}),(0,I.jsx)(b,{label:`Pull batch`,hint:`jobs/pull, max ${C.workerBatch}`,children:(0,I.jsx)(v,{name:`benchmark-pull-batch`,autoComplete:`off`,type:`number`,min:1,max:C.workerBatch,value:n.workerBatch,disabled:z,onChange:W(`workerBatch`)})}),(0,I.jsx)(b,{label:`Process (ms)`,hint:`simulated work per pull`,children:(0,I.jsx)(v,{name:`benchmark-process-ms`,autoComplete:`off`,type:`number`,min:0,max:C.processMs,value:n.processMs,disabled:z,onChange:W(`processMs`)})})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(y,{checked:n.durable,onChange:e=>B(`durable`,e),disabled:z,label:`Durable (fsync each job)`}),(0,I.jsx)(`span`,{className:`text-sm text-muted`,children:`Durable (fsync each job)`})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(y,{checked:n.removeOnComplete,onChange:e=>B(`removeOnComplete`,e),disabled:z,label:`Remove on complete`}),(0,I.jsx)(`span`,{className:`text-sm text-muted`,children:`Remove on complete`})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,I.jsx)(g,{variant:`ghost`,size:`sm`,disabled:z||X,onClick:me,children:X?`Cleaning…`:`Clean queue`}),Z&&(`error`in Z?(0,I.jsxs)(`span`,{className:`text-xs text-danger`,children:[`Clean unverified — `,Z.error]}):(0,I.jsx)(`span`,{className:t(`text-xs`,Z.remaining>0?`text-warning`:`text-success`),children:Z.remaining>0?`Cleaned — ${u(Z.remaining)} active job(s) remain (requeued after the stall timeout)`:`Cleaned — 0 jobs remain`}))]})]})]}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-6 lg:col-span-2`,children:[(0,I.jsxs)(c,{children:[(0,I.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,I.jsx)(`h3`,{className:`text-base font-semibold text-fg`,children:be}),(0,I.jsxs)(`span`,{className:`text-right text-xs text-faint`,children:[(0,I.jsxs)(`span`,{className:`block`,children:[`Benchmark target: `,ue]}),xe&&(0,I.jsx)(`span`,{className:`block`,children:xe})]})]}),(0,I.jsx)(se,{label:$.mode===`duration`?`Elapsed`:`Produced`,pct:$.mode===`duration`?ye:_e,tone:`accent`}),ge>0&&$.mode===`count`&&(0,I.jsx)(se,{label:`Completed`,pct:ve,tone:`emerald`}),(0,I.jsxs)(`div`,{className:`mt-4 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,I.jsx)(f,{label:`Pushed`,value:u(P.pushed),tone:`accent`,compact:!0}),(0,I.jsx)(f,{label:`Completed`,value:u(P.completed),tone:`green`,compact:!0}),(0,I.jsx)(f,{label:`Push/sec`,value:F(P.pushPerSec),compact:!0}),(0,I.jsx)(f,{label:`Done/sec`,value:F(P.donePerSec),tone:`green`,compact:!0}),(0,I.jsx)(f,{label:`Elapsed`,value:m(P.elapsedMs),compact:!0}),(0,I.jsx)(f,{label:`Active workers`,value:`${P.activeWorkers}/${ge}`,tone:`blue`,compact:!0}),(0,I.jsx)(f,{label:`Data`,value:p(L?.bytes??P.bytes),compact:!0}),(0,I.jsx)(f,{label:`Errors`,value:u((L?.pushFailed??P.pushFailed)+(L?.ackFailed??P.ackFailed)),tone:P.pushFailed+P.ackFailed?`red`:`default`,compact:!0})]})]}),(0,I.jsxs)(c,{children:[(0,I.jsx)(o,{title:`Throughput`}),(0,I.jsx)(`p`,{className:`-mt-3 mb-4 text-xs text-faint`,children:`Enqueue (client → server) vs completion (workers) per second`}),(0,I.jsx)(x,{series:[{label:`Push/sec`,color:`#38bdf8`,points:P.pushSeries,area:!0},{label:`Done/sec`,color:`#34d399`,points:P.doneSeries,area:!0}]}),(0,I.jsxs)(`div`,{className:`mt-2 flex items-center gap-4 font-mono text-[11px] text-faint`,children:[(0,I.jsx)(ce,{color:`#38bdf8`,label:`Push/sec`,value:P.pushPerSec}),(0,I.jsx)(ce,{color:`#34d399`,label:`Done/sec`,value:P.donePerSec})]})]})]})]}),L&&(0,I.jsxs)(c,{className:`mt-6`,children:[(0,I.jsx)(o,{title:`Summary`}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-4 xl:grid-cols-8`,children:[(0,I.jsx)(f,{label:`Pushed`,value:u(L.pushed),tone:`accent`,compact:!0}),(0,I.jsx)(f,{label:`Completed`,value:u(L.completed),tone:`green`,compact:!0}),(0,I.jsx)(f,{label:`Duration`,value:m(L.durationMs),compact:!0}),(0,I.jsx)(f,{label:`Avg push/s`,value:F(L.pushPerSec),tone:`accent`,compact:!0}),(0,I.jsx)(f,{label:`Avg done/s`,value:F(L.donePerSec),tone:`green`,compact:!0}),(0,I.jsx)(f,{label:`Data rate`,value:`${p(L.mbPerSec)}/s`,compact:!0}),(0,I.jsx)(f,{label:`Push p95`,value:m(L.p95),compact:!0}),(0,I.jsx)(f,{label:`Push p99`,value:m(L.p99),compact:!0})]}),(0,I.jsxs)(`p`,{className:`mt-3 text-xs text-faint`,children:[`Push-batch latency avg `,m(L.avg),` · p50 `,m(L.p50),` · p95`,` `,m(L.p95),` · p99 `,m(L.p99),` · max `,m(L.max),`.`,L.error?` First error: ${L.error}`:``]})]}),(0,I.jsxs)(c,{className:`mt-6`,children:[(0,I.jsx)(o,{title:`Server queue: ${J}`,action:fe?(0,I.jsx)(`span`,{className:`text-xs font-medium text-warning`,children:`stale — server unreachable`}):void 0}),(0,I.jsxs)(`p`,{className:`-mt-3 mb-4 text-xs text-faint`,children:[`Live counts from `,ue,` (poll 1s).`,E?` Pinned to the current or last benchmark run.`:``]}),Y?(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-5`,children:[(0,I.jsx)(f,{label:`Waiting`,value:u(Y.waiting??0),tone:`amber`,compact:!0}),(0,I.jsx)(f,{label:`Active`,value:u(Y.active??0),tone:`blue`,compact:!0}),(0,I.jsx)(f,{label:`Completed`,value:u(Y.completed??0),tone:`green`,compact:!0}),(0,I.jsx)(f,{label:`Failed`,value:u(Y.failed??0),tone:Y.failed?`red`:`default`,compact:!0}),(0,I.jsx)(f,{label:`Delayed`,value:u(Y.delayed??0),compact:!0})]}):(0,I.jsx)(`p`,{className:`text-sm text-faint`,children:`No counts yet — waiting for the server to answer for this queue.`})]}),(0,I.jsx)(ne,{history:R,onClear:s.clearHistory})]})}function se({label:e,pct:n,tone:r}){return(0,I.jsxs)(`div`,{className:`mb-2`,children:[(0,I.jsxs)(`div`,{className:`mb-1 flex items-center justify-between text-[11px] text-faint`,children:[(0,I.jsx)(`span`,{children:e}),(0,I.jsxs)(`span`,{className:`tnum`,children:[n.toFixed(0),`%`]})]}),(0,I.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,I.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 ce({color:e,label:t,value:n}){return(0,I.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,I.jsx)(`span`,{className:`size-2 rounded-full`,style:{background:e}}),t,` `,(0,I.jsxs)(`span`,{className:`text-fg`,children:[F(n),`/s`]})]})}export{oe as Benchmark};
@@ -1,4 +1,4 @@
1
- import{r as e}from"./cn-CMFYpumL.js";import{g as t,t as n}from"./react-vendor-Bjui4wS4.js";import{i as r}from"./upstreamPaths-nG8N1XAz.js";import{A as i,C as a,S as o,ct as s,ft as c,h as l,st as u,w as d}from"./index-Bn2R06qm.js";import{i as f,n as p,t as m}from"./form-DsUq0w8s.js";import{r as h}from"./useServerActionGuard-CItj3hvh.js";import{MAX_JOB_DATA_BYTES as g,acceptedBulkIds as _,parseRepeat as v,queueNameError as y,utf8ByteLength as b}from"./AddJob-ytpBLTCJ.js";var x=e(t(),1),S=n(),C=1e4,w=365*24*60*60*1e3,T=1440*60*1e3,E=64*1024*1024,D=64*1024*1024,O=`[
1
+ import{r as e}from"./cn-CMFYpumL.js";import{g as t,t as n}from"./react-vendor-Bjui4wS4.js";import{i as r}from"./upstreamPaths-nG8N1XAz.js";import{A as i,C as a,S as o,ct as s,ft as c,h as l,st as u,w as d}from"./index-Dr__4DsT.js";import{i as f,n as p,t as m}from"./form-DsUq0w8s.js";import{r as h}from"./useServerActionGuard-CItj3hvh.js";import{MAX_JOB_DATA_BYTES as g,acceptedBulkIds as _,parseRepeat as v,queueNameError as y,utf8ByteLength as b}from"./AddJob-Cih9F84t.js";var x=e(t(),1),S=n(),C=1e4,w=365*24*60*60*1e3,T=1440*60*1e3,E=64*1024*1024,D=64*1024*1024,O=`[
2
2
  { "data": { "to": "a@example.com", "template": "welcome" }, "priority": 1 },
3
3
  { "data": { "to": "b@example.com", "template": "welcome" } }
4
4
  ]`,k=e=>{let t=typeof e==`string`&&e.trim()!==``?Number(e.trim()):e;return typeof t==`number`&&Number.isFinite(t)?t:void 0},A=e=>typeof e==`boolean`?e:void 0,j=e=>typeof e==`string`?e.trim()===``?void 0:e.trim():typeof e==`number`&&Number.isFinite(e)?String(e):void 0,M=e=>{if(!Array.isArray(e))return;let t=e.map(j);return t.every(e=>e!==void 0)?t:void 0},N=e=>typeof e==`object`&&e&&!Array.isArray(e)?e:void 0,P=e=>{let t=k(e);if(t!==void 0)return t;let n=N(e);if(!n||n.type!==`fixed`&&n.type!==`exponential`||Object.keys(n).some(e=>e!==`type`&&e!==`delay`))return;let r=k(n.delay);return r===void 0?void 0:{type:n.type,delay:r}},F=e=>{let t=N(e);if(!t)return;let n=v(JSON.stringify(t));return n.ok?n.repeat:void 0};function I(e){let t=N(e);if(!t)return{ok:!1,msg:`must be an object`};let n=new Set([`ttl`,`extend`,`replace`]),r=Object.keys(t).filter(e=>!n.has(e));if(r.length)return{ok:!1,msg:`has unknown option(s): ${r.join(`, `)}`};if(t.ttl!==void 0&&(!Number.isSafeInteger(t.ttl)||t.ttl<=0||t.ttl>w))return{ok:!1,msg:`ttl must be a whole number from 1 to ${w} ms`};for(let e of[`extend`,`replace`])if(t[e]!==void 0&&typeof t[e]!=`boolean`)return{ok:!1,msg:`${e} must be a boolean`};return t.extend===!0&&t.replace===!0?{ok:!1,msg:`extend and replace are mutually exclusive`}:t.extend===!0&&t.ttl===void 0?{ok:!1,msg:`extend requires ttl`}:{ok:!0,dedup:{...typeof t.ttl==`number`?{ttl:t.ttl}:{},...typeof t.extend==`boolean`?{extend:t.extend}:{},...typeof t.replace==`boolean`?{replace:t.replace}:{}}}}var L=e=>{let t=I(e);return t.ok?t.dedup:void 0};function R(e,t,n){if(n===`spec`&&e&&typeof e==`object`&&!Array.isArray(e)&&`data`in e){let n=e;return{data:n.data,priority:k(n.priority)??t.priority,delay:k(n.delay),maxAttempts:k(n.maxAttempts)??t.maxAttempts,backoff:P(n.backoff)??t.backoff,timeout:k(n.timeout)??t.timeout,jobId:j(n.jobId)??j(n.customId),removeOnComplete:A(n.removeOnComplete),removeOnFail:A(n.removeOnFail),durable:A(n.durable),lifo:A(n.lifo),ttl:k(n.ttl),uniqueKey:j(n.uniqueKey),tags:M(n.tags),groupId:j(n.groupId),dependsOn:M(n.dependsOn),stallTimeout:k(n.stallTimeout),repeat:F(n.repeat),dedup:L(n.dedup),stackTraceLimit:k(n.stackTraceLimit),timestamp:k(n.timestamp)}}return{data:e,...t}}var z=new Set([`data`,`priority`,`delay`,`maxAttempts`,`backoff`,`timeout`,`jobId`,`customId`,`removeOnComplete`,`removeOnFail`,`durable`,`lifo`,`ttl`,`uniqueKey`,`tags`,`groupId`,`dependsOn`,`stallTimeout`,`repeat`,`dedup`,`stackTraceLimit`,`timestamp`]),B=(e,t,n,r,i)=>{if(e===void 0)return null;let a=k(e);return a===void 0?`${t} must be a number`:i&&!Number.isSafeInteger(a)?`${t} must be a whole, safe integer`:a<n||a>r?`${t} must be between ${n} and ${r}`:null};function V(e){let t={priority:e.priority.trim()||void 0,maxAttempts:e.maxAttempts.trim()||void 0,backoff:e.backoff.trim()||void 0,timeout:e.timeout.trim()||void 0},n=[[`priority`,`Default priority`,-1e6,1e6,!0],[`maxAttempts`,`Default max attempts`,1,1e3,!0],[`backoff`,`Default backoff`,0,T,!0],[`timeout`,`Default timeout`,0,T,!0]],r={};for(let[e,i,a,o,s]of n){let n=B(t[e],i,a,o,s);if(n)return{ok:!1,msg:n};let c=k(t[e]);c!==void 0&&(r[e]=c)}return{ok:!0,defaults:r}}function H(e){let t=Object.keys(e).filter(e=>!z.has(e));if(t.length)return`unknown job option(s): ${t.join(`, `)}`;let n=[[`priority`,`priority`,-1e6,1e6,!0],[`delay`,`delay`,0,w,!0],[`maxAttempts`,`maxAttempts`,1,1e3,!0],[`timeout`,`timeout`,0,T,!0],[`ttl`,`ttl`,0,w,!0],[`stallTimeout`,`stallTimeout`,0,T,!0],[`stackTraceLimit`,`stackTraceLimit`,0,1e4,!0],[`timestamp`,`timestamp`,0,2**53-1,!0]];for(let[t,r,i,a,o]of n){let n=B(e[t],r,i,a,o);if(n)return n}if(e.backoff!==void 0){let t=P(e.backoff);if(t===void 0)return`backoff must be a number or {"type":"fixed|exponential","delay":number} with no extra keys`;let n=B(typeof t==`number`?t:t.delay,`backoff delay`,0,T,!0);if(n)return n}if(e.repeat!==void 0){let t=N(e.repeat);if(!t)return`repeat must be an object`;let n=v(JSON.stringify(t));if(!n.ok)return n.msg}if(e.dedup!==void 0){let t=I(e.dedup);if(!t.ok)return`dedup ${t.msg}`;if(j(e.uniqueKey)===void 0)return`dedup requires a non-empty uniqueKey`}for(let t of[`removeOnComplete`,`removeOnFail`,`durable`,`lifo`])if(e[t]!==void 0&&typeof e[t]!=`boolean`)return`${t} must be a boolean`;for(let t of[`jobId`,`customId`,`uniqueKey`]){let n=e[t];if(n===void 0)continue;let i=j(n);if(i===void 0||i.length>1024)return`${t} must be a non-empty string (or finite numeric id) of at most 1024 characters`;if((t===`jobId`||t===`customId`)&&r(i))return`${t}: ${r(i)}`}let i=j(e.jobId),a=j(e.customId);if(i!==void 0&&a!==void 0&&i!==a)return`jobId and customId disagree; provide only one spelling`;if(e.groupId!==void 0){let t=j(e.groupId);if(t===void 0||t.length>256)return`groupId must be a non-empty string of at most 256 characters`}for(let t of[`tags`,`dependsOn`]){if(e[t]===void 0)continue;let n=M(e[t]),i=t===`tags`?256:1024;if(!n||n.some(e=>e.length>i))return`${t} must be an array of non-empty strings of at most ${i} characters`;if(t===`dependsOn`){let e=n?.find(e=>r(e));if(e)return`dependsOn ID "${e}": ${r(e)}`}}return null}function U(e){let t=new Map;for(let n of e)if(n.jobId){if(t.has(n.jobId))return`duplicate jobId/customId "${n.jobId}" makes dependency resolution ambiguous`;t.set(n.jobId,n)}let n=new Set,r=new Set,i=e=>{if(n.has(e))return!0;if(r.has(e))return!1;n.add(e);for(let n of t.get(e)?.dependsOn??[])if(t.has(n)&&i(n))return!0;return n.delete(e),r.add(e),!1};for(let e of t.keys())if(i(e))return`dependency cycle detected in this batch (involving "${e}")`;return null}function W(e,t,n){if(e.length>C)return{ok:!1,msg:`Too many jobs (${e.length}). Limit is ${C}.`};let r=[],i=0;for(let a=0;a<e.length;a++){let o=e[a];if(n===`spec`&&typeof o==`object`&&o&&!Array.isArray(o)&&`data`in o){let e=H(o);if(e)return{ok:!1,msg:`Job ${a+1}: ${e}`}}let s=R(o,t,n),c;try{c=JSON.stringify(s.data)}catch{return{ok:!1,msg:`Job ${a+1}: data must be JSON serializable`}}if(c===void 0)return{ok:!1,msg:`Job ${a+1}: data must be JSON serializable`};if(c.length>10485760)return{ok:!1,msg:`Job ${a+1}: data exceeds the 10 MiB UTF-8 limit`};let l=b(c,g);if(l>10485760)return{ok:!1,msg:`Job ${a+1}: data exceeds the 10 MiB UTF-8 limit`};if(i+=l,i>67108864)return{ok:!1,msg:`Combined job data exceeds the 64 MiB import safety limit`};r.push(s)}let a=U(r);return a?{ok:!1,msg:a}:{ok:!0,bodies:r}}function G(e){return e.length>67108864||b(e,67108864)>67108864?`Import text exceeds the 64 MiB UTF-8 safety limit`:null}function K(e,t=D){return s(e,t)}function q(e,t,n){return{ok:!0,msg:`Accepted ${t} job submission${t===1?``:`s`} in ${n}; server returned ${e} distinct job ID${e===1?``:`s`} (deduplication may reuse existing jobs)`}}function J(e){let t=G(e);if(t)return{items:[],error:t};let n=e.trim();if(!n)return{items:[],error:null};try{let e=JSON.parse(n);return Array.isArray(e)?{items:e,error:null}:{items:[e],error:null}}catch{}let r=[],i=e.split(`
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-DjvZiKhB.js","assets/dist-DZL8soAh.js","assets/dist-1f1fMHVO.js","assets/dist-BlWBaCN6.js","assets/dist-DpZcbP9W.js"])))=>i.map(i=>d[i]);
2
- import{n as e,r as t,t as n}from"./cn-CMFYpumL.js";import{g as r,p as i,t as a}from"./react-vendor-Bjui4wS4.js";import{E as o,lt as s,ot as c,ut as l}from"./index-Bn2R06qm.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-DsUq0w8s.js";var Ne=t(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]));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]));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]));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]));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=e(((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=e(((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=e(((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{n as e,r as t,t as n}from"./cn-CMFYpumL.js";import{g as r,p as i,t as a}from"./react-vendor-Bjui4wS4.js";import{E as o,lt as s,ot as c,ut as l}from"./index-Dr__4DsT.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-DsUq0w8s.js";var Ne=t(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]));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]));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]));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]));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=e(((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=e(((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=e(((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 +1 @@
1
- import{r as e}from"./cn-CMFYpumL.js";import{g as t,t as n}from"./react-vendor-Bjui4wS4.js";import{A as r,L as i,T as a,Y as o,a as s,b as c,c as l,h as u,j as d,v as f,x as p,y as m}from"./index-Bn2R06qm.js";import{t as h}from"./Pagination-DpxiBnt8.js";import{r as g,t as _}from"./useServerActionGuard-CItj3hvh.js";var v=e(t(),1),y=n();function b(){let{data:e,error:t,loading:n,refetch:b}=r(()=>d.crons(),[]),x=(e?.crons??[]).slice(),[S,C]=(0,v.useState)(0),w=Math.max(1,Math.ceil(x.length/15)),T=Math.min(S,w-1),[E,D]=(0,v.useState)(null),[O,k]=(0,v.useState)(null),A=g(`classic-cron`);(0,v.useEffect)(()=>{D(null),k(null)},[A.scopeKey]);let j=async e=>{if(!window.confirm(`Delete cron "${e}"?`))return;let t=A.begin(`delete:${e}`);if(t){D(null),k(e);try{if(_(await d.deleteCron(e),`Delete cron`),!t.isCurrent())return;await b()}catch(e){t.isCurrent()&&D(`Delete failed: ${e.message}`)}finally{t.finish()&&k(null)}}};return(0,y.jsxs)(`div`,{children:[t&&e&&(0,y.jsx)(p,{message:`Cron refresh failed — showing the last successful schedule list.`,onRetry:b}),(0,y.jsx)(u,{title:`Cron Jobs`,description:e?`${x.length} scheduled`:`Schedule inventory unavailable`,live:!!e&&!t}),E&&(0,y.jsx)(`p`,{role:`alert`,className:`mb-4 text-sm text-danger`,children:E}),t&&!e?(0,y.jsx)(m,{error:t,onRetry:b}):n&&!e?(0,y.jsx)(c,{label:`Loading cron jobs…`}):x.length===0?(0,y.jsx)(f,{icon:(0,y.jsx)(i,{}),title:`No scheduled jobs`,hint:`Repeatable jobs created with upsertJobScheduler appear here.`}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,y.jsx)(`thead`,{children:(0,y.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,y.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Name`}),(0,y.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queue`}),(0,y.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Schedule`}),(0,y.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Next Run`}),(0,y.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Runs`}),(0,y.jsx)(`th`,{className:`w-12 px-5 py-3`})]})}),(0,y.jsx)(`tbody`,{children:x.slice(T*15,T*15+15).map(e=>(0,y.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,y.jsx)(`td`,{className:`px-5 py-3 font-medium text-fg`,children:e.name}),(0,y.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queue??`—`}),(0,y.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.schedule??(e.repeatEvery?`every ${e.repeatEvery}ms`:`—`)}),(0,y.jsx)(`td`,{className:`px-5 py-3 text-faint`,children:s(e.nextRun)}),(0,y.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:l(e.executions??0)}),(0,y.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,y.jsx)(a,{"aria-label":`Delete cron`,disabled:O!==null,onClick:()=>j(e.name),children:(0,y.jsx)(o,{className:`size-3.5`})})})]},e.name))})]})}),(0,y.jsx)(h,{page:T,pageSize:15,total:x.length,onPageChange:C,label:`crons`})]})]})}export{b as Cron};
1
+ import{r as e}from"./cn-CMFYpumL.js";import{g as t,t as n}from"./react-vendor-Bjui4wS4.js";import{A as r,L as i,T as a,Y as o,a as s,b as c,c as l,h as u,j as d,v as f,x as p,y as m}from"./index-Dr__4DsT.js";import{t as h}from"./Pagination-eotgGQf9.js";import{r as g,t as _}from"./useServerActionGuard-CItj3hvh.js";var v=e(t(),1),y=n();function b(){let{data:e,error:t,loading:n,refetch:b}=r(()=>d.crons(),[]),x=(e?.crons??[]).slice(),[S,C]=(0,v.useState)(0),w=Math.max(1,Math.ceil(x.length/15)),T=Math.min(S,w-1),[E,D]=(0,v.useState)(null),[O,k]=(0,v.useState)(null),A=g(`classic-cron`);(0,v.useEffect)(()=>{D(null),k(null)},[A.scopeKey]);let j=async e=>{if(!window.confirm(`Delete cron "${e}"?`))return;let t=A.begin(`delete:${e}`);if(t){D(null),k(e);try{if(_(await d.deleteCron(e),`Delete cron`),!t.isCurrent())return;await b()}catch(e){t.isCurrent()&&D(`Delete failed: ${e.message}`)}finally{t.finish()&&k(null)}}};return(0,y.jsxs)(`div`,{children:[t&&e&&(0,y.jsx)(p,{message:`Cron refresh failed — showing the last successful schedule list.`,onRetry:b}),(0,y.jsx)(u,{title:`Cron Jobs`,description:e?`${x.length} scheduled`:`Schedule inventory unavailable`,live:!!e&&!t}),E&&(0,y.jsx)(`p`,{role:`alert`,className:`mb-4 text-sm text-danger`,children:E}),t&&!e?(0,y.jsx)(m,{error:t,onRetry:b}):n&&!e?(0,y.jsx)(c,{label:`Loading cron jobs…`}):x.length===0?(0,y.jsx)(f,{icon:(0,y.jsx)(i,{}),title:`No scheduled jobs`,hint:`Repeatable jobs created with upsertJobScheduler appear here.`}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,y.jsx)(`thead`,{children:(0,y.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,y.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Name`}),(0,y.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queue`}),(0,y.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Schedule`}),(0,y.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Next Run`}),(0,y.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Runs`}),(0,y.jsx)(`th`,{className:`w-12 px-5 py-3`})]})}),(0,y.jsx)(`tbody`,{children:x.slice(T*15,T*15+15).map(e=>(0,y.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,y.jsx)(`td`,{className:`px-5 py-3 font-medium text-fg`,children:e.name}),(0,y.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queue??`—`}),(0,y.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.schedule??(e.repeatEvery?`every ${e.repeatEvery}ms`:`—`)}),(0,y.jsx)(`td`,{className:`px-5 py-3 text-faint`,children:s(e.nextRun)}),(0,y.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:l(e.executions??0)}),(0,y.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,y.jsx)(a,{"aria-label":`Delete cron`,disabled:O!==null,onClick:()=>j(e.name),children:(0,y.jsx)(o,{className:`size-3.5`})})})]},e.name))})]})}),(0,y.jsx)(h,{page:T,pageSize:15,total:x.length,onPageChange:C,label:`crons`})]})]})}export{b as Cron};
@@ -1 +1 @@
1
- import{r as e,t}from"./cn-CMFYpumL.js";import{g as n,t as r}from"./react-vendor-Bjui4wS4.js";import{t as i}from"./upstreamPaths-nG8N1XAz.js";import{A as a,C as o,L as s,S as c,T as l,Y as u,a as d,b as f,c as p,ft as m,h,st as g,v as _,w as v,x as y,y as b}from"./index-Bn2R06qm.js";import{i as x,n as S,o as C,t as w}from"./form-DsUq0w8s.js";import{t as T}from"./Pagination-DpxiBnt8.js";import{r as ee}from"./useServerActionGuard-CItj3hvh.js";import{MAX_JOB_DATA_CHARS as te,parseJobData as E,queueNameError as D}from"./AddJob-ytpBLTCJ.js";var O=e(n(),1),k=[``,`jan`,`feb`,`mar`,`apr`,`may`,`jun`,`jul`,`aug`,`sep`,`oct`,`nov`,`dec`],ne=[`sun`,`mon`,`tue`,`wed`,`thu`,`fri`,`sat`];function A(e,t,n,r){let i=e===`*`||/^\*\/\d+$/.test(e),a=new Set;for(let i of e.split(`,`)){let e=i.trim().toLowerCase();if(e===``)return null;let o=e.match(/^(.+)\/(\d+)$/),s=o?Number(o[2]):1,c=o?o[1]:e;if(s<1)return null;let l,u;if(c===`*`)l=t,u=n;else if(c.includes(`-`)){let[e,t]=c.split(`-`),n=j(e,r),i=j(t,r);if(n==null||i==null)return null;l=n,u=i}else{let e=j(c,r);if(e==null)return null;l=e,u=o?n:e}if(l<t||u>n||l>u)return null;for(let e=l;e<=u;e+=s)a.add(e)}return a.size?{values:a,star:i}:null}function j(e,t){let n=e.trim().toLowerCase();if(n===``)return null;if(t){let e=t.indexOf(n.slice(0,3));if(e!==-1)return e}return/^\d+$/.test(n)?Number(n):null}function re(e,t,n){let r=e.trim().split(/\s+/);if(r.length!==5)return{valid:!1,error:`Expected 5 fields (min hour day month weekday), got ${r.length}.`,runs:[]};let i=A(r[0],0,59),a=A(r[1],0,23),o=A(r[2],1,31),s=A(r[3],1,12,k),c=A(r[4],0,7,ne);if(!i||!a||!o||!s||!c)return{valid:!1,error:`Invalid field syntax.`,runs:[]};let l=new Set;for(let e of c.values)l.add(e===7?0:e);let u={values:l,star:c.star},d=e=>{let t=o.values.has(e.getDate()),n=u.values.has(e.getDay());return o.star||u.star?t&&n:t||n},f=[],p=new Date(n);p.setSeconds(0,0),p.setMinutes(p.getMinutes()+1);let m=n+5*366*864e5;for(let e=0;e<22e5&&f.length<t&&!(p.getTime()>m);e++){if(!s.values.has(p.getMonth()+1)){p.setMonth(p.getMonth()+1,1),p.setHours(0,0,0,0);continue}if(!d(p)){p.setDate(p.getDate()+1),p.setHours(0,0,0,0);continue}if(!a.values.has(p.getHours())){p.setHours(p.getHours()+1,0,0,0);continue}if(!i.values.has(p.getMinutes())){p.setMinutes(p.getMinutes()+1,0,0);continue}f.push(p.getTime()),p.setMinutes(p.getMinutes()+1,0,0)}return{valid:!0,runs:f}}var M=r(),N=365*24*60*60*1e3,P=1440*60*1e3;function F(e){let[t,n]=(0,O.useState)(0);return(0,O.useEffect)(()=>{t>e-1&&n(e-1)},[t,e]),[Math.min(t,e-1),n]}function ie(e){let[t,n]=(0,O.useState)(!1),r=(0,O.useRef)(null),i=()=>{r.current&&clearTimeout(r.current),r.current=null};return(0,O.useEffect)(()=>()=>{r.current&&clearTimeout(r.current)},[]),{on:t,fire:()=>{i(),n(!0),r.current=setTimeout(()=>n(!1),e)},reset:()=>{i(),n(!1)}}}function I(){let{data:e,error:t,loading:n,refetch:r}=a(()=>g.crons(),[]),i=e?.crons??[],v=(0,O.useMemo)(()=>new Set(i.map(e=>e.name)),[i]),[x,S]=F(Math.max(1,Math.ceil(i.length/15))),[C,w]=(0,O.useState)(null),[te,E]=(0,O.useState)(new Set),D=ee(`cron-manager`);(0,O.useEffect)(()=>{w(null),E(new Set)},[D.scopeKey]);let k=async e=>{if(!window.confirm(`Delete cron "${e}"? It will not be recreated automatically; creating a replacement is a separate action.`))return;let t=D.begin(`cron:${e}`);if(t){w(null),E(t=>new Set(t).add(e));try{if(L(await g.deleteCron(e)),!t.isCurrent())return;m.success(`Cron deleted`,e),r()}catch(e){if(!t.isCurrent())return;w(e.message),m.error(`Delete cron failed`,e.message)}finally{t.finish()&&E(t=>{let n=new Set(t);return n.delete(e),n})}}};return(0,M.jsxs)(`div`,{children:[t&&e&&(0,M.jsx)(y,{message:`Cron refresh failed — showing the last successful schedule list.`,onRetry:r}),(0,M.jsx)(h,{title:`Cron Manager`,description:`Submit explicitly acknowledged schedule upserts and manage repeatable jobs.`,live:!!e&&!t}),C&&(0,M.jsx)(`div`,{role:`status`,className:`mb-4 rounded-lg border border-red-500/20 bg-red-500/5 px-4 py-2 text-sm text-danger`,children:C}),(0,M.jsxs)(c,{className:`mb-6`,children:[(0,M.jsx)(o,{title:`Create schedule via upstream upsert`}),(0,M.jsx)(H,{existingNames:v,onCreate:async(e,t)=>{let n=await g.crons();if(!t())throw Error(`Cron creation target changed during preflight`);return z(n,e.name),g.createCron(e)},onAccepted:r,beginCreate:e=>D.begin(`cron:${e}`),scopeKey:D.scopeKey})]}),t&&!e?(0,M.jsx)(b,{error:t,onRetry:r}):n&&!e?(0,M.jsx)(f,{label:`Loading crons…`}):i.length===0?(0,M.jsx)(_,{icon:(0,M.jsx)(s,{}),title:`No scheduled jobs`,hint:`Submit one above.`}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,M.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,M.jsx)(`thead`,{children:(0,M.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,M.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Name`}),(0,M.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Queue`}),(0,M.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Schedule`}),(0,M.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Next Run`}),(0,M.jsx)(`th`,{scope:`col`,className:`px-5 py-3 text-right font-medium`,children:`Runs`}),(0,M.jsx)(`th`,{scope:`col`,className:`w-12 px-5 py-3`})]})}),(0,M.jsx)(`tbody`,{children:i.slice(x*15,x*15+15).map(e=>(0,M.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,M.jsx)(`td`,{className:`px-5 py-3 font-medium text-fg`,children:e.name}),(0,M.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queue}),(0,M.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.schedule??(e.repeatEvery?`every ${e.repeatEvery}ms`:`—`)}),(0,M.jsx)(`td`,{className:`px-5 py-3 text-faint`,children:d(e.nextRun)}),(0,M.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:p(e.executions)}),(0,M.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,M.jsx)(l,{"aria-label":`Delete cron ${e.name}`,disabled:te.has(e.name),onClick:()=>k(e.name),children:(0,M.jsx)(u,{className:`size-3.5`})})})]},e.name))})]})}),(0,M.jsx)(T,{page:x,pageSize:15,total:i.length,onPageChange:S,label:`crons`})]})]})}function L(e){if(typeof e!=`object`||!e||e.ok!==!0)throw Error(`Delete cron returned a malformed success response`)}function ae(e,t){let n=e?.cron;if(typeof e!=`object`||!e||e.ok!==!0||typeof n!=`object`||!n||n.name!==t.name||n.queue!==t.queue)throw Error(`Create cron returned a malformed success response`)}var R=e=>`Cron "${e}" already exists. Bunqueue v2.8.55 does not return complete cron definitions, so editing could reset hidden options. Delete it explicitly, wait for the list to refresh, then create the replacement as a separate action.`;function oe(e,t){let n=e.trim();return n&&t.has(n)?R(n):null}function z(e,t){let n=e;if(typeof n!=`object`||!n||n.ok!==!0||!Array.isArray(n.crons)||n.crons.some(e=>typeof e!=`object`||!e||typeof e.name!=`string`))throw Error(`Cannot verify that the cron name is unused; creation was not attempted`);if(n.crons.some(e=>e.name===t.trim()))throw Error(R(t.trim()))}function B(e){let t=Number(e);if(!Number.isInteger(t)||t<=0)return null;if(t<1e3)return`every ${t}ms`;for(let[e,n]of[[864e5,`d`],[36e5,`h`],[6e4,`m`],[1e3,`s`]])if(t>=e){let r=t/e;return`${Number.isInteger(r)?``:`≈ `}every ${Math.round(r*10)/10}${n}`}return null}function V(e,t,n,r){if(!e.trim())return{ok:!0};let i=Number(e);return!Number.isSafeInteger(i)||i<n||i>r?{ok:!1,msg:`${t} must be a whole number from ${n} to ${r}`}:{ok:!0,value:i}}function se(e,t=Date.now()){let n=e.name.trim(),r=e.queue.trim();if(!n)return{ok:!1,msg:`Name is required`};if(n.length>256)return{ok:!1,msg:`Name must be 256 characters or fewer`};let a=i(n,`Name`,256);if(a)return{ok:!1,msg:a};let o=D(r);if(o)return{ok:!1,msg:o};let s={};if(e.dataText.trim()){let t=E(e.dataText);if(!t.ok)return{ok:!1,msg:t.kind===`json`?`Data is not valid JSON`:t.msg};s=t.data}let c={name:n,queue:r,data:s,preventOverlap:e.preventOverlap,skipIfNoWorker:e.skipIfNoWorker,immediately:e.immediately,skipMissedOnRestart:e.skipMissedOnRestart};if(e.mode===`cron`){let t=e.schedule.trim();if(!t)return{ok:!1,msg:`Cron expression required`};c.schedule=t}else{let t=V(e.every,`Interval`,1,N);if(!t.ok||t.value===void 0)return{ok:!1,msg:t.ok?`Interval is required`:t.msg};c.repeatEvery=t.value}let l=e.timezone.trim();if(l){if(e.mode!==`cron`)return{ok:!1,msg:`Timezone applies only to cron expressions, not intervals`};try{new Intl.DateTimeFormat(`en`,{timeZone:l}).format(t)}catch{return{ok:!1,msg:`Timezone must be a valid IANA timezone`}}c.timezone=l}let u=V(e.priority,`Priority`,-1e6,1e6);if(!u.ok)return u;u.value!==void 0&&(c.priority=u.value);let d=V(e.maxLimit,`Max executions`,1,2**53-1);if(!d.ok)return d;d.value!==void 0&&(c.maxLimit=d.value);let f=e.uniqueKey.trim();if(f.length>1024)return{ok:!1,msg:`Unique key must be 1024 characters or fewer`};f&&(c.uniqueKey=f);let p=V(e.dedupTtl,`Dedup TTL`,1,N);if(!p.ok)return p;let m=p.value!==void 0||e.dedupExtend||e.dedupReplace;if(e.dedupExtend&&e.dedupReplace)return{ok:!1,msg:`Dedup extend and replace are mutually exclusive`};if(e.dedupExtend&&p.value===void 0)return{ok:!1,msg:`Dedup extend requires a TTL`};if(m&&!f&&!e.preventOverlap)return{ok:!1,msg:`Dedup options require a unique key or Prevent overlap`};m&&(c.dedup={...p.value===void 0?{}:{ttl:p.value},...e.dedupExtend?{extend:!0}:{},...e.dedupReplace?{replace:!0}:{}});let h=[{raw:e.jobMaxAttempts,label:`Spawned-job max attempts`,min:1,max:1e3,key:`maxAttempts`},{raw:e.jobBackoff,label:`Spawned-job backoff`,min:0,max:P,key:`backoff`},{raw:e.jobTimeout,label:`Spawned-job timeout`,min:0,max:P,key:`timeout`},{raw:e.jobDelay,label:`Spawned-job delay`,min:0,max:N,key:`delay`},{raw:e.jobStallTimeout,label:`Spawned-job stall timeout`,min:0,max:P,key:`stallTimeout`}],g={};for(let e of h){let t=V(e.raw,e.label,e.min,e.max);if(!t.ok)return t;t.value!==void 0&&(g[e.key]=t.value)}return e.jobRemoveOnComplete&&(g.removeOnComplete=!0),e.jobRemoveOnFail&&(g.removeOnFail=!0),Object.keys(g).length&&(c.jobOptions=g),{ok:!0,body:c}}function H({onCreate:e,onAccepted:n,beginCreate:r,scopeKey:i,existingNames:a}){let[o,s]=(0,O.useState)(``),[c,l]=(0,O.useState)(``),[u,f]=(0,O.useState)(`cron`),[p,h]=(0,O.useState)(``),[g,_]=(0,O.useState)(``),[y,b]=(0,O.useState)(`{}`),[T,ee]=(0,O.useState)(!1),[E,D]=(0,O.useState)(``),[k,ne]=(0,O.useState)(``),[A,j]=(0,O.useState)(!0),[F,I]=(0,O.useState)(!1),[L,R]=(0,O.useState)(``),[z,V]=(0,O.useState)(!1),[H,ce]=(0,O.useState)(!0),[U,le]=(0,O.useState)(``),[W,ue]=(0,O.useState)(``),[G,de]=(0,O.useState)(!1),[K,fe]=(0,O.useState)(!1),[q,pe]=(0,O.useState)(``),[J,me]=(0,O.useState)(``),[he,ge]=(0,O.useState)(``),[_e,ve]=(0,O.useState)(``),[ye,be]=(0,O.useState)(``),[xe,Se]=(0,O.useState)(!1),[Ce,we]=(0,O.useState)(!1),[Y,X]=(0,O.useState)(null),[Te,Z]=(0,O.useState)(!1),{on:Ee,fire:De,reset:Oe}=ie(3e3);(0,O.useEffect)(()=>{Z(!1),X(null),Oe()},[i]);let Q=(0,O.useMemo)(()=>u!==`cron`||!p.trim()?null:re(p.trim(),3,Date.now()),[u,p]),$=oe(o,a),ke=async()=>{X(null),Oe();let t=se({name:o,queue:c,mode:u,schedule:p,every:g,dataText:y,timezone:E,priority:k,preventOverlap:A,skipIfNoWorker:F,maxLimit:L,immediately:z,skipMissedOnRestart:H,uniqueKey:U,dedupTtl:W,dedupExtend:G,dedupReplace:K,jobMaxAttempts:q,jobBackoff:J,jobTimeout:he,jobDelay:_e,jobStallTimeout:ye,jobRemoveOnComplete:xe,jobRemoveOnFail:Ce});if(!t.ok){X(t.msg);return}let i=t.body,l=oe(i.name,a);if(l){X(l);return}if(!window.confirm(`Submit an upsert for cron "${i.name}"? Bunqueue v2.8.55 has no atomic create-only condition. The dashboard will recheck immediately before writing, but another client using the same name at the same time could still be replaced. Continue only if you authorize last-writer-wins behavior for this globally unique name.`))return;let d=r(i.name);if(d){Z(!0);try{if(ae(await e(i,d.isCurrent),i),!d.isCurrent())return;s(``),h(``),_(``),De(),m.success(`Cron upsert acknowledged`,i.name),n()}catch(e){if(!d.isCurrent())return;X(e.message)}finally{d.finish()&&Z(!1)}}};return(0,M.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),ke()},children:[(0,M.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,M.jsx)(w,{label:`Name`,children:(0,M.jsx)(S,{name:`cron-name`,autoComplete:`off`,maxLength:256,value:o,onChange:e=>s(e.target.value),placeholder:`daily-report`})}),(0,M.jsx)(w,{label:`Queue`,children:(0,M.jsx)(S,{name:`cron-queue`,autoComplete:`off`,maxLength:256,value:c,onChange:e=>l(e.target.value),placeholder:`reports`})})]}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,M.jsxs)(`fieldset`,{children:[(0,M.jsx)(`legend`,{className:`sr-only`,children:`Schedule type`}),(0,M.jsx)(x,{options:[`cron`,`every`],value:u,onChange:f})]}),u===`cron`?(0,M.jsx)(`div`,{className:`min-w-56 flex-1`,children:(0,M.jsx)(w,{label:`Cron expression`,children:(0,M.jsx)(S,{name:`cron-expression`,value:p,onChange:e=>h(e.target.value),placeholder:`0 9 * * *`})})}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`w-40`,children:(0,M.jsx)(w,{label:`Every (ms)`,children:(0,M.jsx)(S,{type:`number`,min:1,max:N,step:1,name:`cron-interval`,value:g,onChange:e=>_(e.target.value),placeholder:`30000`})})}),g.trim()!==``&&(0,M.jsx)(`span`,{className:t(`pb-2 text-xs`,B(g)?`text-muted`:`text-danger`),children:B(g)??`not a valid interval`})]})]}),u===`cron`&&p.trim()&&Q&&(0,M.jsx)(`div`,{className:`rounded-lg border border-line bg-surface-2 px-3 py-2 text-xs`,children:Q.valid?Q.runs.length?(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,M.jsxs)(`span`,{className:`text-faint`,children:[`Next runs`,E.trim()?` (local)`:``,`:`]}),Q.runs.map(e=>(0,M.jsx)(`span`,{className:`font-mono text-muted`,children:d(e)},e)),E.trim()&&(0,M.jsxs)(`span`,{className:`text-faint`,children:[`— server evaluates in `,E.trim()]})]}):(0,M.jsx)(`span`,{className:`text-warning`,children:`Valid, but no runs in the next few years.`}):(0,M.jsxs)(`span`,{className:`text-warning`,children:[`Preview unavailable: `,Q.error,` Bunqueue will validate this expression when you create the schedule.`]})}),(0,M.jsx)(w,{label:`Data (JSON)`,children:(0,M.jsx)(`textarea`,{name:`cron-data`,value:y,onChange:e=>b(e.target.value),maxLength:te,rows:3,spellCheck:!1,className:`w-full rounded-lg border border-line bg-surface-2 px-3 py-2 font-mono text-sm text-fg placeholder:text-faint transition-colors focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`})}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`button`,{type:`button`,onClick:()=>ee(e=>!e),"aria-expanded":T,"aria-controls":`cron-advanced-options`,className:`text-xs font-medium text-muted hover:text-fg`,children:T?`− Hide advanced`:`+ Advanced options`}),T&&(0,M.jsxs)(`div`,{id:`cron-advanced-options`,className:`mt-3 grid grid-cols-2 gap-3`,children:[(0,M.jsx)(w,{label:`Timezone (IANA)`,hint:`e.g. Europe/Rome. Default: server timezone.`,children:(0,M.jsx)(S,{name:`cron-timezone`,autoComplete:`off`,value:E,onChange:e=>D(e.target.value),placeholder:`Europe/Rome`})}),(0,M.jsx)(w,{label:`Priority`,children:(0,M.jsx)(S,{type:`number`,min:-1e6,max:1e6,step:1,name:`cron-priority`,value:k,onChange:e=>ne(e.target.value),placeholder:`0`})}),(0,M.jsx)(w,{label:`Max executions`,hint:`blank = unlimited`,children:(0,M.jsx)(S,{type:`number`,min:1,max:2**53-1,step:1,name:`cron-max-executions`,value:L,onChange:e=>R(e.target.value),placeholder:`∞`})}),(0,M.jsx)(w,{label:`Unique key`,hint:`optional deduplication key`,children:(0,M.jsx)(S,{name:`cron-unique-key`,autoComplete:`off`,maxLength:1024,value:U,onChange:e=>le(e.target.value),placeholder:`daily-report`})}),(0,M.jsxs)(`div`,{className:`col-span-2 flex flex-wrap gap-6`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(C,{checked:A,onChange:j,label:`prevent overlap`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`prevent overlap`})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(C,{checked:F,onChange:I,label:`skip if no worker`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`skip if no worker`})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(C,{checked:z,onChange:V,label:`run immediately`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`run immediately`})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(C,{checked:H,onChange:ce,label:`skip missed on restart`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`skip missed on restart`})]})]}),(0,M.jsxs)(`div`,{className:`col-span-2`,children:[(0,M.jsx)(`div`,{className:`mb-2 text-[11px] uppercase tracking-wider text-faint`,children:`Cron deduplication`}),(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,M.jsx)(w,{label:`Dedup TTL (ms)`,hint:`blank = no TTL`,children:(0,M.jsx)(S,{type:`number`,min:1,max:N,step:1,name:`cron-dedup-ttl`,value:W,onChange:e=>ue(e.target.value),placeholder:`60000`})}),(0,M.jsxs)(`div`,{className:`flex items-end gap-2 pb-2`,children:[(0,M.jsx)(C,{checked:G,onChange:de,label:`extend dedup TTL`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`extend TTL`})]}),(0,M.jsxs)(`div`,{className:`flex items-end gap-2 pb-2`,children:[(0,M.jsx)(C,{checked:K,onChange:fe,label:`replace duplicate`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`replace duplicate`})]})]})]}),(0,M.jsxs)(`div`,{className:`col-span-2`,children:[(0,M.jsx)(`div`,{className:`mb-2 text-[11px] uppercase tracking-wider text-faint`,children:`Spawned-job options`}),(0,M.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-5`,children:[(0,M.jsx)(w,{label:`Max attempts`,children:(0,M.jsx)(S,{type:`number`,min:1,max:1e3,step:1,name:`cron-job-max-attempts`,value:q,onChange:e=>pe(e.target.value),placeholder:`3`})}),(0,M.jsx)(w,{label:`Backoff (ms)`,children:(0,M.jsx)(S,{type:`number`,min:0,max:P,step:1,name:`cron-job-backoff`,value:J,onChange:e=>me(e.target.value),placeholder:`1000`})}),(0,M.jsx)(w,{label:`Timeout (ms)`,children:(0,M.jsx)(S,{type:`number`,min:0,max:P,step:1,name:`cron-job-timeout`,value:he,onChange:e=>ge(e.target.value),placeholder:`—`})}),(0,M.jsx)(w,{label:`Delay (ms)`,children:(0,M.jsx)(S,{type:`number`,min:0,max:N,step:1,name:`cron-job-delay`,value:_e,onChange:e=>ve(e.target.value),placeholder:`0`})}),(0,M.jsx)(w,{label:`Stall timeout (ms)`,children:(0,M.jsx)(S,{type:`number`,min:0,max:P,step:1,name:`cron-job-stall-timeout`,value:ye,onChange:e=>be(e.target.value),placeholder:`server default`})})]}),(0,M.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-6`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(C,{checked:xe,onChange:Se,label:`remove spawned jobs on complete`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`remove on complete`})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(C,{checked:Ce,onChange:we,label:`remove spawned jobs on fail`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`remove on fail`})]})]})]})]})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,M.jsx)(v,{type:`submit`,variant:`accent`,size:`sm`,disabled:Te||!!$,children:Te?`Saving…`:$?`Name already exists`:`Submit upsert`}),$&&!Y&&(0,M.jsx)(`span`,{role:`alert`,className:`max-w-2xl text-xs text-warning`,children:$}),Y&&(0,M.jsx)(`span`,{role:`alert`,className:`text-xs text-danger`,children:Y}),Ee&&(0,M.jsx)(`span`,{role:`status`,className:`text-xs text-success`,children:`Cron upsert acknowledged ✓`})]}),(0,M.jsx)(`p`,{className:`text-xs text-warning`,children:`Creation is an upstream upsert, not an atomic create-only operation. Use a globally unique name; the fail-closed preflight cannot eliminate a simultaneous write from another client.`})]})}export{I as CronManager};
1
+ import{r as e,t}from"./cn-CMFYpumL.js";import{g as n,t as r}from"./react-vendor-Bjui4wS4.js";import{t as i}from"./upstreamPaths-nG8N1XAz.js";import{A as a,C as o,L as s,S as c,T as l,Y as u,a as d,b as f,c as p,ft as m,h,st as g,v as _,w as v,x as y,y as b}from"./index-Dr__4DsT.js";import{i as x,n as S,o as C,t as w}from"./form-DsUq0w8s.js";import{t as T}from"./Pagination-eotgGQf9.js";import{r as ee}from"./useServerActionGuard-CItj3hvh.js";import{MAX_JOB_DATA_CHARS as te,parseJobData as E,queueNameError as D}from"./AddJob-Cih9F84t.js";var O=e(n(),1),k=[``,`jan`,`feb`,`mar`,`apr`,`may`,`jun`,`jul`,`aug`,`sep`,`oct`,`nov`,`dec`],ne=[`sun`,`mon`,`tue`,`wed`,`thu`,`fri`,`sat`];function A(e,t,n,r){let i=e===`*`||/^\*\/\d+$/.test(e),a=new Set;for(let i of e.split(`,`)){let e=i.trim().toLowerCase();if(e===``)return null;let o=e.match(/^(.+)\/(\d+)$/),s=o?Number(o[2]):1,c=o?o[1]:e;if(s<1)return null;let l,u;if(c===`*`)l=t,u=n;else if(c.includes(`-`)){let[e,t]=c.split(`-`),n=j(e,r),i=j(t,r);if(n==null||i==null)return null;l=n,u=i}else{let e=j(c,r);if(e==null)return null;l=e,u=o?n:e}if(l<t||u>n||l>u)return null;for(let e=l;e<=u;e+=s)a.add(e)}return a.size?{values:a,star:i}:null}function j(e,t){let n=e.trim().toLowerCase();if(n===``)return null;if(t){let e=t.indexOf(n.slice(0,3));if(e!==-1)return e}return/^\d+$/.test(n)?Number(n):null}function re(e,t,n){let r=e.trim().split(/\s+/);if(r.length!==5)return{valid:!1,error:`Expected 5 fields (min hour day month weekday), got ${r.length}.`,runs:[]};let i=A(r[0],0,59),a=A(r[1],0,23),o=A(r[2],1,31),s=A(r[3],1,12,k),c=A(r[4],0,7,ne);if(!i||!a||!o||!s||!c)return{valid:!1,error:`Invalid field syntax.`,runs:[]};let l=new Set;for(let e of c.values)l.add(e===7?0:e);let u={values:l,star:c.star},d=e=>{let t=o.values.has(e.getDate()),n=u.values.has(e.getDay());return o.star||u.star?t&&n:t||n},f=[],p=new Date(n);p.setSeconds(0,0),p.setMinutes(p.getMinutes()+1);let m=n+5*366*864e5;for(let e=0;e<22e5&&f.length<t&&!(p.getTime()>m);e++){if(!s.values.has(p.getMonth()+1)){p.setMonth(p.getMonth()+1,1),p.setHours(0,0,0,0);continue}if(!d(p)){p.setDate(p.getDate()+1),p.setHours(0,0,0,0);continue}if(!a.values.has(p.getHours())){p.setHours(p.getHours()+1,0,0,0);continue}if(!i.values.has(p.getMinutes())){p.setMinutes(p.getMinutes()+1,0,0);continue}f.push(p.getTime()),p.setMinutes(p.getMinutes()+1,0,0)}return{valid:!0,runs:f}}var M=r(),N=365*24*60*60*1e3,P=1440*60*1e3;function F(e){let[t,n]=(0,O.useState)(0);return(0,O.useEffect)(()=>{t>e-1&&n(e-1)},[t,e]),[Math.min(t,e-1),n]}function ie(e){let[t,n]=(0,O.useState)(!1),r=(0,O.useRef)(null),i=()=>{r.current&&clearTimeout(r.current),r.current=null};return(0,O.useEffect)(()=>()=>{r.current&&clearTimeout(r.current)},[]),{on:t,fire:()=>{i(),n(!0),r.current=setTimeout(()=>n(!1),e)},reset:()=>{i(),n(!1)}}}function I(){let{data:e,error:t,loading:n,refetch:r}=a(()=>g.crons(),[]),i=e?.crons??[],v=(0,O.useMemo)(()=>new Set(i.map(e=>e.name)),[i]),[x,S]=F(Math.max(1,Math.ceil(i.length/15))),[C,w]=(0,O.useState)(null),[te,E]=(0,O.useState)(new Set),D=ee(`cron-manager`);(0,O.useEffect)(()=>{w(null),E(new Set)},[D.scopeKey]);let k=async e=>{if(!window.confirm(`Delete cron "${e}"? It will not be recreated automatically; creating a replacement is a separate action.`))return;let t=D.begin(`cron:${e}`);if(t){w(null),E(t=>new Set(t).add(e));try{if(L(await g.deleteCron(e)),!t.isCurrent())return;m.success(`Cron deleted`,e),r()}catch(e){if(!t.isCurrent())return;w(e.message),m.error(`Delete cron failed`,e.message)}finally{t.finish()&&E(t=>{let n=new Set(t);return n.delete(e),n})}}};return(0,M.jsxs)(`div`,{children:[t&&e&&(0,M.jsx)(y,{message:`Cron refresh failed — showing the last successful schedule list.`,onRetry:r}),(0,M.jsx)(h,{title:`Cron Manager`,description:`Submit explicitly acknowledged schedule upserts and manage repeatable jobs.`,live:!!e&&!t}),C&&(0,M.jsx)(`div`,{role:`status`,className:`mb-4 rounded-lg border border-red-500/20 bg-red-500/5 px-4 py-2 text-sm text-danger`,children:C}),(0,M.jsxs)(c,{className:`mb-6`,children:[(0,M.jsx)(o,{title:`Create schedule via upstream upsert`}),(0,M.jsx)(H,{existingNames:v,onCreate:async(e,t)=>{let n=await g.crons();if(!t())throw Error(`Cron creation target changed during preflight`);return z(n,e.name),g.createCron(e)},onAccepted:r,beginCreate:e=>D.begin(`cron:${e}`),scopeKey:D.scopeKey})]}),t&&!e?(0,M.jsx)(b,{error:t,onRetry:r}):n&&!e?(0,M.jsx)(f,{label:`Loading crons…`}):i.length===0?(0,M.jsx)(_,{icon:(0,M.jsx)(s,{}),title:`No scheduled jobs`,hint:`Submit one above.`}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,M.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,M.jsx)(`thead`,{children:(0,M.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,M.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Name`}),(0,M.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Queue`}),(0,M.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Schedule`}),(0,M.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Next Run`}),(0,M.jsx)(`th`,{scope:`col`,className:`px-5 py-3 text-right font-medium`,children:`Runs`}),(0,M.jsx)(`th`,{scope:`col`,className:`w-12 px-5 py-3`})]})}),(0,M.jsx)(`tbody`,{children:i.slice(x*15,x*15+15).map(e=>(0,M.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,M.jsx)(`td`,{className:`px-5 py-3 font-medium text-fg`,children:e.name}),(0,M.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queue}),(0,M.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.schedule??(e.repeatEvery?`every ${e.repeatEvery}ms`:`—`)}),(0,M.jsx)(`td`,{className:`px-5 py-3 text-faint`,children:d(e.nextRun)}),(0,M.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:p(e.executions)}),(0,M.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,M.jsx)(l,{"aria-label":`Delete cron ${e.name}`,disabled:te.has(e.name),onClick:()=>k(e.name),children:(0,M.jsx)(u,{className:`size-3.5`})})})]},e.name))})]})}),(0,M.jsx)(T,{page:x,pageSize:15,total:i.length,onPageChange:S,label:`crons`})]})]})}function L(e){if(typeof e!=`object`||!e||e.ok!==!0)throw Error(`Delete cron returned a malformed success response`)}function ae(e,t){let n=e?.cron;if(typeof e!=`object`||!e||e.ok!==!0||typeof n!=`object`||!n||n.name!==t.name||n.queue!==t.queue)throw Error(`Create cron returned a malformed success response`)}var R=e=>`Cron "${e}" already exists. Bunqueue v2.8.55 does not return complete cron definitions, so editing could reset hidden options. Delete it explicitly, wait for the list to refresh, then create the replacement as a separate action.`;function oe(e,t){let n=e.trim();return n&&t.has(n)?R(n):null}function z(e,t){let n=e;if(typeof n!=`object`||!n||n.ok!==!0||!Array.isArray(n.crons)||n.crons.some(e=>typeof e!=`object`||!e||typeof e.name!=`string`))throw Error(`Cannot verify that the cron name is unused; creation was not attempted`);if(n.crons.some(e=>e.name===t.trim()))throw Error(R(t.trim()))}function B(e){let t=Number(e);if(!Number.isInteger(t)||t<=0)return null;if(t<1e3)return`every ${t}ms`;for(let[e,n]of[[864e5,`d`],[36e5,`h`],[6e4,`m`],[1e3,`s`]])if(t>=e){let r=t/e;return`${Number.isInteger(r)?``:`≈ `}every ${Math.round(r*10)/10}${n}`}return null}function V(e,t,n,r){if(!e.trim())return{ok:!0};let i=Number(e);return!Number.isSafeInteger(i)||i<n||i>r?{ok:!1,msg:`${t} must be a whole number from ${n} to ${r}`}:{ok:!0,value:i}}function se(e,t=Date.now()){let n=e.name.trim(),r=e.queue.trim();if(!n)return{ok:!1,msg:`Name is required`};if(n.length>256)return{ok:!1,msg:`Name must be 256 characters or fewer`};let a=i(n,`Name`,256);if(a)return{ok:!1,msg:a};let o=D(r);if(o)return{ok:!1,msg:o};let s={};if(e.dataText.trim()){let t=E(e.dataText);if(!t.ok)return{ok:!1,msg:t.kind===`json`?`Data is not valid JSON`:t.msg};s=t.data}let c={name:n,queue:r,data:s,preventOverlap:e.preventOverlap,skipIfNoWorker:e.skipIfNoWorker,immediately:e.immediately,skipMissedOnRestart:e.skipMissedOnRestart};if(e.mode===`cron`){let t=e.schedule.trim();if(!t)return{ok:!1,msg:`Cron expression required`};c.schedule=t}else{let t=V(e.every,`Interval`,1,N);if(!t.ok||t.value===void 0)return{ok:!1,msg:t.ok?`Interval is required`:t.msg};c.repeatEvery=t.value}let l=e.timezone.trim();if(l){if(e.mode!==`cron`)return{ok:!1,msg:`Timezone applies only to cron expressions, not intervals`};try{new Intl.DateTimeFormat(`en`,{timeZone:l}).format(t)}catch{return{ok:!1,msg:`Timezone must be a valid IANA timezone`}}c.timezone=l}let u=V(e.priority,`Priority`,-1e6,1e6);if(!u.ok)return u;u.value!==void 0&&(c.priority=u.value);let d=V(e.maxLimit,`Max executions`,1,2**53-1);if(!d.ok)return d;d.value!==void 0&&(c.maxLimit=d.value);let f=e.uniqueKey.trim();if(f.length>1024)return{ok:!1,msg:`Unique key must be 1024 characters or fewer`};f&&(c.uniqueKey=f);let p=V(e.dedupTtl,`Dedup TTL`,1,N);if(!p.ok)return p;let m=p.value!==void 0||e.dedupExtend||e.dedupReplace;if(e.dedupExtend&&e.dedupReplace)return{ok:!1,msg:`Dedup extend and replace are mutually exclusive`};if(e.dedupExtend&&p.value===void 0)return{ok:!1,msg:`Dedup extend requires a TTL`};if(m&&!f&&!e.preventOverlap)return{ok:!1,msg:`Dedup options require a unique key or Prevent overlap`};m&&(c.dedup={...p.value===void 0?{}:{ttl:p.value},...e.dedupExtend?{extend:!0}:{},...e.dedupReplace?{replace:!0}:{}});let h=[{raw:e.jobMaxAttempts,label:`Spawned-job max attempts`,min:1,max:1e3,key:`maxAttempts`},{raw:e.jobBackoff,label:`Spawned-job backoff`,min:0,max:P,key:`backoff`},{raw:e.jobTimeout,label:`Spawned-job timeout`,min:0,max:P,key:`timeout`},{raw:e.jobDelay,label:`Spawned-job delay`,min:0,max:N,key:`delay`},{raw:e.jobStallTimeout,label:`Spawned-job stall timeout`,min:0,max:P,key:`stallTimeout`}],g={};for(let e of h){let t=V(e.raw,e.label,e.min,e.max);if(!t.ok)return t;t.value!==void 0&&(g[e.key]=t.value)}return e.jobRemoveOnComplete&&(g.removeOnComplete=!0),e.jobRemoveOnFail&&(g.removeOnFail=!0),Object.keys(g).length&&(c.jobOptions=g),{ok:!0,body:c}}function H({onCreate:e,onAccepted:n,beginCreate:r,scopeKey:i,existingNames:a}){let[o,s]=(0,O.useState)(``),[c,l]=(0,O.useState)(``),[u,f]=(0,O.useState)(`cron`),[p,h]=(0,O.useState)(``),[g,_]=(0,O.useState)(``),[y,b]=(0,O.useState)(`{}`),[T,ee]=(0,O.useState)(!1),[E,D]=(0,O.useState)(``),[k,ne]=(0,O.useState)(``),[A,j]=(0,O.useState)(!0),[F,I]=(0,O.useState)(!1),[L,R]=(0,O.useState)(``),[z,V]=(0,O.useState)(!1),[H,ce]=(0,O.useState)(!0),[U,le]=(0,O.useState)(``),[W,ue]=(0,O.useState)(``),[G,de]=(0,O.useState)(!1),[K,fe]=(0,O.useState)(!1),[q,pe]=(0,O.useState)(``),[J,me]=(0,O.useState)(``),[he,ge]=(0,O.useState)(``),[_e,ve]=(0,O.useState)(``),[ye,be]=(0,O.useState)(``),[xe,Se]=(0,O.useState)(!1),[Ce,we]=(0,O.useState)(!1),[Y,X]=(0,O.useState)(null),[Te,Z]=(0,O.useState)(!1),{on:Ee,fire:De,reset:Oe}=ie(3e3);(0,O.useEffect)(()=>{Z(!1),X(null),Oe()},[i]);let Q=(0,O.useMemo)(()=>u!==`cron`||!p.trim()?null:re(p.trim(),3,Date.now()),[u,p]),$=oe(o,a),ke=async()=>{X(null),Oe();let t=se({name:o,queue:c,mode:u,schedule:p,every:g,dataText:y,timezone:E,priority:k,preventOverlap:A,skipIfNoWorker:F,maxLimit:L,immediately:z,skipMissedOnRestart:H,uniqueKey:U,dedupTtl:W,dedupExtend:G,dedupReplace:K,jobMaxAttempts:q,jobBackoff:J,jobTimeout:he,jobDelay:_e,jobStallTimeout:ye,jobRemoveOnComplete:xe,jobRemoveOnFail:Ce});if(!t.ok){X(t.msg);return}let i=t.body,l=oe(i.name,a);if(l){X(l);return}if(!window.confirm(`Submit an upsert for cron "${i.name}"? Bunqueue v2.8.55 has no atomic create-only condition. The dashboard will recheck immediately before writing, but another client using the same name at the same time could still be replaced. Continue only if you authorize last-writer-wins behavior for this globally unique name.`))return;let d=r(i.name);if(d){Z(!0);try{if(ae(await e(i,d.isCurrent),i),!d.isCurrent())return;s(``),h(``),_(``),De(),m.success(`Cron upsert acknowledged`,i.name),n()}catch(e){if(!d.isCurrent())return;X(e.message)}finally{d.finish()&&Z(!1)}}};return(0,M.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),ke()},children:[(0,M.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,M.jsx)(w,{label:`Name`,children:(0,M.jsx)(S,{name:`cron-name`,autoComplete:`off`,maxLength:256,value:o,onChange:e=>s(e.target.value),placeholder:`daily-report`})}),(0,M.jsx)(w,{label:`Queue`,children:(0,M.jsx)(S,{name:`cron-queue`,autoComplete:`off`,maxLength:256,value:c,onChange:e=>l(e.target.value),placeholder:`reports`})})]}),(0,M.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,M.jsxs)(`fieldset`,{children:[(0,M.jsx)(`legend`,{className:`sr-only`,children:`Schedule type`}),(0,M.jsx)(x,{options:[`cron`,`every`],value:u,onChange:f})]}),u===`cron`?(0,M.jsx)(`div`,{className:`min-w-56 flex-1`,children:(0,M.jsx)(w,{label:`Cron expression`,children:(0,M.jsx)(S,{name:`cron-expression`,value:p,onChange:e=>h(e.target.value),placeholder:`0 9 * * *`})})}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:`w-40`,children:(0,M.jsx)(w,{label:`Every (ms)`,children:(0,M.jsx)(S,{type:`number`,min:1,max:N,step:1,name:`cron-interval`,value:g,onChange:e=>_(e.target.value),placeholder:`30000`})})}),g.trim()!==``&&(0,M.jsx)(`span`,{className:t(`pb-2 text-xs`,B(g)?`text-muted`:`text-danger`),children:B(g)??`not a valid interval`})]})]}),u===`cron`&&p.trim()&&Q&&(0,M.jsx)(`div`,{className:`rounded-lg border border-line bg-surface-2 px-3 py-2 text-xs`,children:Q.valid?Q.runs.length?(0,M.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,M.jsxs)(`span`,{className:`text-faint`,children:[`Next runs`,E.trim()?` (local)`:``,`:`]}),Q.runs.map(e=>(0,M.jsx)(`span`,{className:`font-mono text-muted`,children:d(e)},e)),E.trim()&&(0,M.jsxs)(`span`,{className:`text-faint`,children:[`— server evaluates in `,E.trim()]})]}):(0,M.jsx)(`span`,{className:`text-warning`,children:`Valid, but no runs in the next few years.`}):(0,M.jsxs)(`span`,{className:`text-warning`,children:[`Preview unavailable: `,Q.error,` Bunqueue will validate this expression when you create the schedule.`]})}),(0,M.jsx)(w,{label:`Data (JSON)`,children:(0,M.jsx)(`textarea`,{name:`cron-data`,value:y,onChange:e=>b(e.target.value),maxLength:te,rows:3,spellCheck:!1,className:`w-full rounded-lg border border-line bg-surface-2 px-3 py-2 font-mono text-sm text-fg placeholder:text-faint transition-colors focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`})}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`button`,{type:`button`,onClick:()=>ee(e=>!e),"aria-expanded":T,"aria-controls":`cron-advanced-options`,className:`text-xs font-medium text-muted hover:text-fg`,children:T?`− Hide advanced`:`+ Advanced options`}),T&&(0,M.jsxs)(`div`,{id:`cron-advanced-options`,className:`mt-3 grid grid-cols-2 gap-3`,children:[(0,M.jsx)(w,{label:`Timezone (IANA)`,hint:`e.g. Europe/Rome. Default: server timezone.`,children:(0,M.jsx)(S,{name:`cron-timezone`,autoComplete:`off`,value:E,onChange:e=>D(e.target.value),placeholder:`Europe/Rome`})}),(0,M.jsx)(w,{label:`Priority`,children:(0,M.jsx)(S,{type:`number`,min:-1e6,max:1e6,step:1,name:`cron-priority`,value:k,onChange:e=>ne(e.target.value),placeholder:`0`})}),(0,M.jsx)(w,{label:`Max executions`,hint:`blank = unlimited`,children:(0,M.jsx)(S,{type:`number`,min:1,max:2**53-1,step:1,name:`cron-max-executions`,value:L,onChange:e=>R(e.target.value),placeholder:`∞`})}),(0,M.jsx)(w,{label:`Unique key`,hint:`optional deduplication key`,children:(0,M.jsx)(S,{name:`cron-unique-key`,autoComplete:`off`,maxLength:1024,value:U,onChange:e=>le(e.target.value),placeholder:`daily-report`})}),(0,M.jsxs)(`div`,{className:`col-span-2 flex flex-wrap gap-6`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(C,{checked:A,onChange:j,label:`prevent overlap`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`prevent overlap`})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(C,{checked:F,onChange:I,label:`skip if no worker`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`skip if no worker`})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(C,{checked:z,onChange:V,label:`run immediately`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`run immediately`})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(C,{checked:H,onChange:ce,label:`skip missed on restart`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`skip missed on restart`})]})]}),(0,M.jsxs)(`div`,{className:`col-span-2`,children:[(0,M.jsx)(`div`,{className:`mb-2 text-[11px] uppercase tracking-wider text-faint`,children:`Cron deduplication`}),(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,M.jsx)(w,{label:`Dedup TTL (ms)`,hint:`blank = no TTL`,children:(0,M.jsx)(S,{type:`number`,min:1,max:N,step:1,name:`cron-dedup-ttl`,value:W,onChange:e=>ue(e.target.value),placeholder:`60000`})}),(0,M.jsxs)(`div`,{className:`flex items-end gap-2 pb-2`,children:[(0,M.jsx)(C,{checked:G,onChange:de,label:`extend dedup TTL`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`extend TTL`})]}),(0,M.jsxs)(`div`,{className:`flex items-end gap-2 pb-2`,children:[(0,M.jsx)(C,{checked:K,onChange:fe,label:`replace duplicate`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`replace duplicate`})]})]})]}),(0,M.jsxs)(`div`,{className:`col-span-2`,children:[(0,M.jsx)(`div`,{className:`mb-2 text-[11px] uppercase tracking-wider text-faint`,children:`Spawned-job options`}),(0,M.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-5`,children:[(0,M.jsx)(w,{label:`Max attempts`,children:(0,M.jsx)(S,{type:`number`,min:1,max:1e3,step:1,name:`cron-job-max-attempts`,value:q,onChange:e=>pe(e.target.value),placeholder:`3`})}),(0,M.jsx)(w,{label:`Backoff (ms)`,children:(0,M.jsx)(S,{type:`number`,min:0,max:P,step:1,name:`cron-job-backoff`,value:J,onChange:e=>me(e.target.value),placeholder:`1000`})}),(0,M.jsx)(w,{label:`Timeout (ms)`,children:(0,M.jsx)(S,{type:`number`,min:0,max:P,step:1,name:`cron-job-timeout`,value:he,onChange:e=>ge(e.target.value),placeholder:`—`})}),(0,M.jsx)(w,{label:`Delay (ms)`,children:(0,M.jsx)(S,{type:`number`,min:0,max:N,step:1,name:`cron-job-delay`,value:_e,onChange:e=>ve(e.target.value),placeholder:`0`})}),(0,M.jsx)(w,{label:`Stall timeout (ms)`,children:(0,M.jsx)(S,{type:`number`,min:0,max:P,step:1,name:`cron-job-stall-timeout`,value:ye,onChange:e=>be(e.target.value),placeholder:`server default`})})]}),(0,M.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-6`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(C,{checked:xe,onChange:Se,label:`remove spawned jobs on complete`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`remove on complete`})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(C,{checked:Ce,onChange:we,label:`remove spawned jobs on fail`}),(0,M.jsx)(`span`,{className:`text-sm text-muted`,children:`remove on fail`})]})]})]})]})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,M.jsx)(v,{type:`submit`,variant:`accent`,size:`sm`,disabled:Te||!!$,children:Te?`Saving…`:$?`Name already exists`:`Submit upsert`}),$&&!Y&&(0,M.jsx)(`span`,{role:`alert`,className:`max-w-2xl text-xs text-warning`,children:$}),Y&&(0,M.jsx)(`span`,{role:`alert`,className:`text-xs text-danger`,children:Y}),Ee&&(0,M.jsx)(`span`,{role:`status`,className:`text-xs text-success`,children:`Cron upsert acknowledged ✓`})]}),(0,M.jsx)(`p`,{className:`text-xs text-warning`,children:`Creation is an upstream upsert, not an atomic create-only operation. Use a globally unique name; the fail-closed preflight cannot eliminate a simultaneous write from another client.`})]})}export{I as CronManager};
@@ -1,3 +1,3 @@
1
- import{r as e,t}from"./cn-CMFYpumL.js";import{g as n,h as r,t as i}from"./react-vendor-Bjui4wS4.js";import{o as a}from"./connectionStore-Cd9-3Fw0.js";import{$ as o,A as s,C as c,I as l,J as u,O as d,Q as f,S as p,b as m,c as h,ft as g,h as _,it as v,m as y,r as b,rt as x,st as S,v as C,w,x as ee,y as te}from"./index-Bn2R06qm.js";import{a as T}from"./form-DsUq0w8s.js";import{t as ne}from"./Pagination-DpxiBnt8.js";var E=e(n(),1),re=e(r(),1),D=i(),O=50,k=`bq-dash-db-history`,A=10,j=2e4,M=100;function N(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 ie(e,t){return[e.map(N).join(`,`),...t.map(e=>e.map(N).join(`,`))].join(`
1
+ import{r as e,t}from"./cn-CMFYpumL.js";import{g as n,h as r,t as i}from"./react-vendor-Bjui4wS4.js";import{o as a}from"./connectionStore-Cd9-3Fw0.js";import{$ as o,A as s,C as c,I as l,J as u,O as d,Q as f,S as p,b as m,c as h,ft as g,h as _,it as v,m as y,r as b,rt as x,st as S,v as C,w,x as ee,y as te}from"./index-Dr__4DsT.js";import{a as T}from"./form-DsUq0w8s.js";import{t as ne}from"./Pagination-eotgGQf9.js";var E=e(n(),1),re=e(r(),1),D=i(),O=50,k=`bq-dash-db-history`,A=10,j=2e4,M=100;function N(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 ie(e,t){return[e.map(N).join(`,`),...t.map(e=>e.map(N).join(`,`))].join(`
2
2
  `)}function P(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 F(e){if(!Array.isArray(e))return[];let t=[],n=new Set;for(let r of e.slice(0,M))if(!(typeof r!=`string`||r.length===0||r.length>j||n.has(r))&&(n.add(r),t.push(r),t.length===A))break;return t}function I(){try{return F(JSON.parse(localStorage.getItem(k)??`[]`))}catch{return[]}}function L(e){let t=F(e);try{localStorage.setItem(k,JSON.stringify(t))}catch{}return t}function R(e){return L([e,...I().filter(t=>t!==e)].slice(0,A))}function z(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 ae(e,t=S.captureAgentRequestTarget(),n){let r=Object.freeze({table:e.table,orderBy:e.orderBy,dir:e.dir,filter:e.filter?Object.freeze({...e.filter}):void 0});return S.getDbExportAtTarget(t,r,n)}var B=(e,t)=>t?e?.column===t.column&&e.op===t.op&&e.value===t.value:e===null;function oe(e,t){return e.table===t.table&&e.limit===t.limit&&e.offset===t.offset&&e.orderBy===(t.orderBy??null)&&e.dir===t.dir&&B(e.filter,t.filter)}var se=-(1n<<63n),ce=(1n<<63n)-1n;function V(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>=se&&t<=ce}catch{return!1}}var H=e=>e===null||typeof e==`string`||typeof e==`number`&&Number.isFinite(e);function le(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=>!H(e)))||!Array.isArray(a)||a.length!==i.length||a.some(e=>!V(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(!oe(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 ue(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 U=(e,t)=>e.length===t.length&&e.every((e,n)=>Object.is(e,t[n]));function de(e,t){let n=ue(t,e.index);return n!==null&&n.table===e.table&&n.rowid===e.rowid&&U(n.columns,e.columns)&&U(n.row,e.row)&&U(n.truncated,e.truncated)}function W({value:e,align:n}){if(e==null)return(0,D.jsx)(`span`,{className:`italic text-faint`,children:`NULL`});let r=typeof e==`string`?e:String(e);return(0,D.jsx)(`span`,{className:t(`block max-w-[24rem] truncate`,n===`right`&&`text-right tabular-nums`),title:r,children:r})}function fe({columns:e,rows:n,truncatedCells:r,colMeta:i,sort:a,onSort:o,onRowClick:s,dimmed:c}){let l=(0,E.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,D.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,D.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,D.jsx)(`thead`,{children:(0,D.jsxs)(`tr`,{className:`text-left text-[11px] uppercase tracking-wider text-faint`,children:[s&&(0,D.jsx)(`th`,{className:`sticky top-0 z-10 whitespace-nowrap border-b border-line bg-surface px-4 py-3 font-medium`,children:(0,D.jsx)(`span`,{className:`sr-only`,children:`Row actions`})}),e.map((e,n)=>{let r=i?.[e];return(0,D.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,D.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,D.jsx)(`span`,{className:`rounded bg-accent/15 px-1 py-0.5 text-[9px] font-semibold text-accent`,children:`PK`}),r?.type&&(0,D.jsx)(`span`,{className:`text-faint/70`,children:r.type.toLowerCase()}),(0,D.jsx)(`span`,{"aria-hidden":`true`,className:a?.col===e?`text-accent`:`text-faint/60`,children:a?.col===e?a.dir===`asc`?`▲`:`▼`:`↕`})]}):e},e)})]})}),(0,D.jsx)(`tbody`,{children:n.map((e,t)=>(0,D.jsxs)(`tr`,{className:`border-b border-line font-mono text-xs last:border-0 hover:bg-surface-2/40`,children:[s&&(0,D.jsx)(`td`,{className:`whitespace-nowrap px-4 py-2`,children:(0,D.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,D.jsx)(`td`,{className:`whitespace-nowrap px-4 py-2 text-muted`,children:(0,D.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,D.jsx)(W,{value:e,align:l[n]?`right`:`left`}),r?.[t]?.[n]&&(0,D.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 pe(){let e=a(K),[n,r]=(0,E.useState)(``),[i,c]=(0,E.useState)(0),[l,u]=(0,E.useState)(null),[d,f]=(0,E.useState)(`data`),[T,k]=(0,E.useState)(null),[A,j]=(0,E.useState)(null),M=o(e=>e.active),N=o(e=>e.request),F=o(e=>e.release),[I,L]=(0,E.useState)(`SELECT name FROM sqlite_master WHERE type = 'table'`),R=(0,E.useRef)(null);(0,E.useEffect)(()=>{A===null?F(`database-row`):M!==`database-row`&&j(null)},[A,M,F]),(0,E.useEffect)(()=>()=>{o.getState().release(`database-row`)},[]);let{data:z,error:B,loading:se,refetch:ce}=s(()=>S.db.tables(),[],{intervalMs:1e4}),V=(0,E.useMemo)(()=>z?.tables??[],[z]),H=B instanceof x&&B.status===404,{data:U,error:W,refetch:pe}=s(()=>H?Promise.resolve(null):S.db.info(),[H],{intervalMs:15e3}),G=n||V[0]?.name||``;(0,E.useEffect)(()=>{!n&&V[0]&&r(V[0].name)},[n,V]);let{data:q,error:ve,refetch:ye}=s(()=>G?S.db.schema(G):Promise.resolve(null),[G],{intervalMs:3e4}),be=(0,E.useMemo)(()=>{let e={};if(q?.table===G)for(let t of q.columns)e[t.name]={type:t.type,primaryKey:t.primaryKey};return e},[q,G]),xe=T?JSON.stringify([T.column,T.op,T.value]):``,{data:J,error:Se,loading:Ce,refetch:we}=s((0,E.useCallback)(async()=>{if(!G)return null;let e={table:G,limit:O,offset:i*O,orderBy:l?.col,dir:l?.dir??`asc`,filter:T??void 0};return le(await S.db.rows(G,O,e.offset,l?.col,l?.dir,T??void 0),e)},[G,i,l,T]),[G,i,l,xe],{intervalMs:6e3}),Te={table:G,limit:O,offset:i*O,orderBy:l?.col,dir:l?.dir??`asc`,filter:T??void 0},Ee=!!J&&oe(J,Te),De=Se??(J&&!Ee?Error(`Database rows identity no longer matches the selected table and page.`):null),Y=!De&&Ee?J:null,Oe=A!==null&&Y!==null&&de(A,Y),X=Oe?A:null;(0,E.useEffect)(()=>{A&&!Oe&&j(null)},[A,Oe]),(0,E.useEffect)(()=>{Y&&Y.total>0&&Y.rows.length===0&&i>0&&c(Math.max(0,Math.ceil(Y.total/O)-1))},[Y,i]);let[ke,Ae]=(0,E.useState)(!1),[je,Z]=(0,E.useState)(null),Q=(0,E.useRef)(!1),$=(0,E.useRef)(null);(0,E.useEffect)(()=>($.current?.abort(),$.current=null,Q.current=!1,Ae(!1),Z(null),()=>{$.current?.abort(),$.current=null,Q.current=!1}),[e]);let Me=()=>{c(0),u(null),k(null),j(null)},Ne=e=>{r(e),f(`data`),Me()},Pe=e=>{c(0),j(null),u(t=>t?.col===e?t.dir===`asc`?{col:e,dir:`desc`}:null:{col:e,dir:`asc`})},Fe=()=>{Y&&P(`${Y.table}-page${i+1}.csv`,`text/csv`,ie(Y.columns,Y.rows))},Ie=async()=>{if(!G||Q.current)return;Q.current=!0;let e=K(a.getState()),t={table:G,orderBy:l?.col,dir:l?.dir??`asc`,filter:T?{...T}:void 0},n=S.captureAgentRequestTarget(),r=new AbortController;$.current=r,Ae(!0),Z(null);try{let i=await ae(t,n,r.signal);if(r.signal.aborted||K(a.getState())!==e)return;P(`${t.table}.csv`,`text/csv;charset=utf-8`,i.content);let o=i.cap===`rows`?`Exported the first ${h(i.rowCount)} rows (row cap reached)`:i.cap===`bytes`?`Exported ${h(i.rowCount)} rows (${b(v)} byte cap reached)`:`Exported ${h(i.rowCount)} rows`;Z(o),g.success(`Export of ${t.table} complete`,o)}catch(n){if(r.signal.aborted||K(a.getState())!==e)return;Z(`Export failed: ${n.message}`),g.error(`Export of ${t.table} failed`,n.message)}finally{$.current===r&&($.current=null,Q.current=!1,r.signal.aborted||Ae(!1))}},Le=()=>{let e=`SELECT * FROM "${G.replaceAll(`"`,`""`)}" LIMIT 100`;L(e),requestAnimationFrame(()=>{R.current?.focus(),R.current?.scrollIntoView({behavior:`smooth`,block:`center`})})},Re=!!Y?.truncatedCells.some(e=>e.some(Boolean));return(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{"data-database-background":``,inert:X?!0:void 0,"aria-hidden":X?!0:void 0,children:[(0,D.jsx)(_,{title:`Database`,description:`SQLite inspector — schema, data and queries over a read-only connection.`,actions:(0,D.jsx)(`span`,{className:`rounded-full bg-emerald-500/10 px-2.5 py-1 text-[11px] font-medium text-success`,children:`read-only`})}),B&&!H&&(0,D.jsx)(ee,{message:`Could not read the database — ${B.message}`,onRetry:ce}),W&&!H&&(0,D.jsx)(ee,{message:`Could not read database metadata — ${W.message}`,onRetry:pe}),U&&(0,D.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-5`,children:[(0,D.jsx)(y,{label:`SQLite`,value:U.sqliteVersion,compact:!0}),(0,D.jsx)(y,{label:`On disk`,value:b(U.fileSize+U.walSize),compact:!0}),(0,D.jsx)(y,{label:`Journal`,value:U.journalMode.toUpperCase(),compact:!0}),(0,D.jsx)(y,{label:`Tables`,value:h(U.tables),compact:!0}),(0,D.jsx)(y,{label:`Indexes`,value:h(U.indexes),compact:!0})]}),H?(0,D.jsx)(C,{title:`No database yet`,hint:B.message}):se&&V.length===0?(0,D.jsx)(m,{label:`Reading database…`}):(0,D.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-4`,children:[(0,D.jsxs)(p,{padded:!1,className:`self-start overflow-hidden`,children:[(0,D.jsxs)(`div`,{className:`border-b border-line px-4 py-3 text-[11px] font-medium uppercase tracking-wider text-faint`,children:[`Tables (`,V.length,`)`]}),(0,D.jsxs)(`ul`,{className:`max-h-[28rem] overflow-y-auto`,children:[V.map(e=>(0,D.jsx)(`li`,{children:(0,D.jsxs)(`button`,{type:`button`,onClick:()=>Ne(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`,G===e.name?`bg-surface-2 text-fg`:`text-muted hover:bg-surface-2/60 hover:text-fg`),children:[(0,D.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs`,children:e.name}),(0,D.jsx)(`span`,{className:`shrink-0 text-[11px] text-faint tabular-nums`,children:h(e.rows)})]})},e.name)),V.length===0&&(0,D.jsx)(`li`,{className:`px-4 py-6 text-center text-xs text-faint`,children:`No tables.`})]})]}),(0,D.jsx)(`div`,{className:`min-w-0 lg:col-span-3`,children:V.length===0?(0,D.jsx)(C,{title:`No tables`,hint:`This database has no user tables yet.`}):(0,D.jsxs)(D.Fragment,{children:[G&&(0,D.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`mr-auto min-w-0 truncate font-mono text-sm text-fg`,title:G,children:G}),(0,D.jsx)(w,{size:`sm`,variant:`ghost`,onClick:Le,children:`Query`}),(0,D.jsx)(`div`,{className:`inline-flex items-center gap-1 rounded-lg border border-line bg-surface p-1`,children:[`data`,`schema`].map(e=>(0,D.jsx)(`button`,{type:`button`,onClick:()=>f(e),"aria-pressed":d===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`,d===e?`bg-surface-2 text-fg`:`text-muted hover:text-fg`),children:e},e))}),d===`data`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(w,{size:`sm`,disabled:!Y||Y.rows.length===0,title:Y?`Exports the ${Y.rows.length} rows on this page only`:void 0,onClick:Fe,children:[`Export page`,Y?` (${Y.rows.length})`:``]}),(0,D.jsx)(w,{size:`sm`,variant:`accent`,disabled:ke||!Y||Y.total===0,onClick:Ie,children:ke?`Exporting…`:`Export table${Y?` (${h(Y.total)})`:``}`})]})]}),d===`data`&&G&&(0,D.jsx)(me,{columns:Y?.columns??q?.columns.map(e=>e.name)??[],filter:T,onChange:e=>{k(e),c(0),j(null)}},G),je&&(0,D.jsx)(`p`,{className:`mb-3 text-xs text-muted`,children:je}),d===`schema`?ve?(0,D.jsx)(C,{title:`Could not read schema`,hint:ve.message,action:(0,D.jsx)(w,{size:`sm`,onClick:ye,children:`Retry`})}):q?.table===G?(0,D.jsx)(ge,{schema:q}):(0,D.jsx)(m,{label:`Reading schema of ${G}…`}):De?(0,D.jsx)(te,{error:De,onRetry:we}):Ce&&!Y?(0,D.jsx)(m,{label:`Reading ${G}…`}):Y?Y.total===0?(0,D.jsx)(C,{title:T?`No matching rows`:`Empty table`,hint:T?`No rows match the current filter.`:`"${Y.table}" has no rows.`}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(fe,{columns:Y.columns,rows:Y.rows,truncatedCells:Y.truncatedCells,colMeta:be,sort:l,onSort:Pe,onRowClick:e=>{let t=ue(Y,e);t&&N(`database-row`)&&j(t)},dimmed:Ce&&!Y}),Re&&(0,D.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,D.jsx)(ne,{page:i,pageSize:O,total:Y.total,onPageChange:e=>{c(e),j(null)},label:`rows`})]}):(0,D.jsx)(C,{title:`Select a table`,hint:`Pick a table on the left to browse its rows.`}),(0,D.jsx)(_e,{sql:I,setSql:L,editorRef:R})]})})]})]}),X&&M===`database-row`&&(0,re.createPortal)((0,D.jsx)(he,{table:X.table,columns:X.columns,row:X.row,rowid:X.rowid,truncated:X.truncated,onClose:()=>j(null)}),document.body)]})}function me({columns:e,filter:t,onChange:n}){let[r,i]=(0,E.useState)(t?.column??``),[a,o]=(0,E.useState)(t?.op??`contains`),[s,c]=(0,E.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,D.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,D.jsx)(`div`,{className:`w-40`,children:(0,D.jsx)(T,{value:l,"aria-label":`Filter column`,name:`database-filter-column`,autoComplete:`off`,onChange:e=>i(e.target.value),children:e.map(e=>(0,D.jsx)(`option`,{value:e,children:e},e))})}),(0,D.jsx)(`div`,{className:`w-32`,children:(0,D.jsxs)(T,{value:a,"aria-label":`Filter operator`,name:`database-filter-operator`,autoComplete:`off`,onChange:e=>o(e.target.value),children:[(0,D.jsx)(`option`,{value:`contains`,children:`contains`}),(0,D.jsx)(`option`,{value:`eq`,children:`=`}),(0,D.jsx)(`option`,{value:`ne`,children:`≠`})]})}),(0,D.jsxs)(`div`,{className:`relative min-w-40 flex-1`,children:[(0,D.jsx)(u,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-faint`}),(0,D.jsx)(`input`,{value: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,D.jsx)(w,{size:`sm`,onClick:d,disabled:!s.trim(),children:`Filter`}),t&&(0,D.jsx)(w,{size:`sm`,variant:`ghost`,onClick:()=>{c(``),n(null)},children:`Clear`}),(0,D.jsx)(`span`,{className:`text-[11px] text-faint`,children:`filters the whole table, server-side`})]})}var G=[`a[href]`,`button:not([disabled])`,`input:not([disabled])`,`select:not([disabled])`,`textarea:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`,`);function he({table:e,columns:t,row:n,rowid:r,truncated:i,onClose:a}){let[o,s]=(0,E.useState)({}),[c,u]=(0,E.useState)({}),p=(0,E.useRef)(null),m=(0,E.useRef)(null),h=(0,E.useRef)(a);h.current=a,(0,E.useEffect)(()=>{let e=document.activeElement,t=p.current,n=()=>t?Array.from(t.querySelectorAll(G)).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(),h.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 m.current?.focus(),document.activeElement!==m.current&&t?.focus(),document.addEventListener(`keydown`,i,!0),document.addEventListener(`focusin`,a),()=>{document.removeEventListener(`keydown`,i,!0),document.removeEventListener(`focusin`,a),f(`database-row`)&&e?.isConnected&&e.focus()}},[]);let g=JSON.stringify(t.filter((e,t)=>i[t]));return(0,E.useEffect)(()=>{s({}),u({});let t=JSON.parse(g);if(r==null||t.length===0)return;let n=!1;return Promise.all(t.map(async t=>{try{let i=await S.db.cell(e,r,t);if(!i||typeof i!=`object`||!Object.hasOwn(i,`value`))throw Error(`Malformed full-cell response.`);n||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,g]),(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`button`,{type:`button`,"aria-label":`Close row detail`,onClick:a,className:`fixed inset-0 z-40 bg-black/50`}),(0,D.jsxs)(`aside`,{ref:p,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,D.jsxs)(`div`,{className:`flex items-center justify-between border-b border-line px-5 py-4`,children:[(0,D.jsxs)(`h2`,{className:`font-mono text-sm text-fg`,children:[e,` · row detail`]}),(0,D.jsx)(`button`,{ref:m,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,D.jsx)(l,{className:`size-4`})})]}),(0,D.jsx)(`div`,{className:`flex-1 overscroll-contain overflow-y-auto p-5`,children:(0,D.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=z(a),l=s.includes(`
3
3
  `)||s.length>80;return(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`dt`,{className:`mb-1 flex items-center gap-1.5 text-[11px] uppercase tracking-wider text-faint`,children:[e,a!=null&&(0,D.jsx)(d,{value:String(a)}),i[t]&&!r&&(Object.hasOwn(c,e)?(0,D.jsxs)(`span`,{role:`alert`,className:`normal-case text-danger`,children:[`(full value unavailable — `,c[e],`)`]}):(0,D.jsx)(`span`,{className:`text-warning`,children:`(loading full value…)`}))]}),(0,D.jsx)(`dd`,{children:a==null?(0,D.jsx)(`span`,{className:`italic text-faint`,children:`NULL`}):l?(0,D.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,D.jsx)(`span`,{className:`break-words font-mono text-sm text-fg`,children:s})})]},e)})})})]})]})}function ge({schema:e}){return(0,D.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,D.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,D.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,D.jsx)(`thead`,{children:(0,D.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,D.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:`Column`}),(0,D.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:`Type`}),(0,D.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:`Constraints`}),(0,D.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:`Default`})]})}),(0,D.jsx)(`tbody`,{children:e.columns.map(e=>(0,D.jsxs)(`tr`,{className:`border-b border-line last:border-0`,children:[(0,D.jsx)(`td`,{className:`px-4 py-2 font-mono text-xs text-fg`,children:e.name}),(0,D.jsx)(`td`,{className:`px-4 py-2 font-mono text-xs text-muted`,children:e.type}),(0,D.jsxs)(`td`,{className:`px-4 py-2 text-xs`,children:[e.primaryKey&&(0,D.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,D.jsx)(`span`,{className:`rounded-md bg-surface-2 px-1.5 py-0.5 text-[10px] font-semibold text-muted`,children:`NOT NULL`})]}),(0,D.jsx)(`td`,{className:`px-4 py-2 font-mono text-xs text-faint`,children:e.defaultValue??`—`})]},e.name))})]})}),(0,D.jsxs)(p,{children:[(0,D.jsx)(c,{title:`Indexes (${e.indexes.length})`}),e.indexes.length===0?(0,D.jsx)(`p`,{className:`text-xs text-faint`,children:`No indexes on this table.`}):(0,D.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:e.indexes.map(e=>(0,D.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2 font-mono text-xs`,children:[(0,D.jsx)(`span`,{className:`text-fg`,children:e.name}),e.unique&&(0,D.jsx)(`span`,{className:`rounded-md bg-accent/15 px-1.5 py-0.5 text-[10px] font-semibold text-accent`,children:`UNIQUE`}),(0,D.jsxs)(`span`,{className:`text-faint`,children:[`(`,e.columns.join(`, `),`)`]})]},e.name))})]}),e.sql&&(0,D.jsxs)(p,{children:[(0,D.jsx)(c,{title:`DDL`,action:(0,D.jsx)(d,{value:e.sql})}),(0,D.jsx)(`pre`,{className:`overflow-x-auto rounded-lg bg-surface-2 p-3 font-mono text-xs text-muted`,children:e.sql})]})]})}var K=e=>JSON.stringify([e.baseUrl,e.token,e.agentToken]);function q(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 _e({sql:e,setSql:t,editorRef:n}){let r=a(K),[i,o]=(0,E.useState)(null),[s,l]=(0,E.useState)(null),[u,d]=(0,E.useState)(I),[f,m]=(0,E.useState)(null),g=(0,E.useRef)(0),_=(0,E.useRef)(null),v=(0,E.useRef)(r);v.current!==r&&(v.current=r,g.current++,_.current=null),(0,E.useEffect)(()=>(g.current++,_.current=null,o(null),l(null),m(null),()=>{g.current++,_.current=null}),[r]);let y=i===r,b=s?.target===r?s.message:null,x=f?.target===r?f:null,C=async(t=e,n=!0)=>{let i=t.trim();if(!i||_.current?.target===r)return;let s=++g.current,c=r;_.current={generation:s,target:c},o(c),l(null);try{let e=q(await S.db.query(t));if(s!==g.current||K(a.getState())!==c)return;m({...e,target:c}),n&&d(R(i))}catch(e){if(s!==g.current||K(a.getState())!==c)return;m(null),l({target:c,message:e.message})}finally{_.current?.generation===s&&(_.current=null),s===g.current&&o(null)}};return(0,D.jsxs)(p,{className:`mt-6`,children:[(0,D.jsx)(c,{title:`Query`,action:(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,D.jsx)(w,{size:`sm`,disabled:y||!e.trim(),onClick:()=>{let t=e.trim();t&&C(`EXPLAIN QUERY PLAN ${t}`,!1)},children:`Explain`}),(0,D.jsx)(w,{size:`sm`,variant:`accent`,disabled:y||!e.trim(),onClick:()=>C(),children:y?`Running…`:`Run`})]})}),(0,D.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)&&C()},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,D.jsx)(`p`,{className:`mt-1 text-[11px] text-faint`,children:`⌘/Ctrl+Enter runs. Connection is read-only.`}),u.length>0&&(0,D.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider text-faint`,children:`History`}),u.map(e=>(0,D.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,D.jsx)(`button`,{type:`button`,onClick:()=>{L([]),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,D.jsxs)(`div`,{"aria-live":`polite`,children:[b&&(0,D.jsx)(`p`,{role:`alert`,className:`mt-3 text-xs text-danger`,children:b}),x&&!b&&(0,D.jsxs)(`div`,{className:`mt-4`,children:[(0,D.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-3`,children:[(0,D.jsxs)(`p`,{className:`text-xs text-faint`,children:[x.truncated?`≥ `:``,h(x.rowCount),` row`,x.rowCount===1?``:`s`,` · `,h(x.ms),` ms`,x.truncated&&(0,D.jsxs)(`span`,{className:`text-warning`,children:[` — showing first `,x.rows.length]})]}),x.rows.length>0&&(0,D.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,D.jsx)(w,{size:`sm`,onClick:()=>P(`query-results.csv`,`text/csv`,ie(x.columns,x.rows)),children:`CSV`}),(0,D.jsx)(w,{size:`sm`,onClick:()=>P(`query-results.json`,`application/json`,JSON.stringify(x.rows.map(e=>Object.fromEntries(x.columns.map((t,n)=>[t,e[n]]))),null,2)),children:`JSON`})]})]}),x.rows.length>0?(0,D.jsx)(fe,{columns:x.columns,rows:x.rows}):(0,D.jsx)(`p`,{className:`text-xs text-faint`,children:`Query returned no rows.`})]})]})]})}export{pe as Database};
@@ -1 +1 @@
1
- import{r as e}from"./cn-CMFYpumL.js";import{g as t,t as n}from"./react-vendor-Bjui4wS4.js";import{A as r,C as i,O as a,S as o,b as s,c,d as l,ft as u,h as d,m as f,r as p,st as m,w as h,x as g}from"./index-Bn2R06qm.js";var _=e(t(),1),v=n();async function y(e){try{return{value:await e,error:null}}catch(e){return{value:null,error:e instanceof Error?e.message:String(e)}}}function b(){let{data:e,error:t,loading:n,refetch:b}=r(async()=>{let[e,t,n]=await Promise.all([y(m.health()),y(m.storage()),y(m.stats())]);return{health:e.value,storage:t.value,stats:n.value,healthError:e.error,storageError:t.error,statsError:n.error}},[]),[C,w]=(0,_.useState)(null),T=(0,_.useRef)(0),E=async()=>{let e=++T.current;w(`…`);let t=performance.now();try{await m.ping(),e===T.current&&w(`${Math.round(performance.now()-t)} ms`)}catch{e===T.current&&w(`unreachable`)}},[D,O]=(0,_.useState)(!1),[k,A]=(0,_.useState)(null),j=async()=>{O(!0),A(null);try{let e=await m.gc(),t=e.before.rss-e.after.rss,n=t>0?`Freed ${t} MB (RSS ${e.before.rss}→${e.after.rss})`:`No memory reclaimed`;A(n),u.success(`Memory compacted`,n),b()}catch(e){u.error(`GC failed`,e.message),A(e.message)}finally{O(!1)}},[M,N]=(0,_.useState)(null),[P,F]=(0,_.useState)(!1),I=async()=>{F(!0);try{N(await m.heapStats())}catch(e){u.error(`Heap stats failed`,e.message)}finally{F(!1)}};if(n&&!e&&!t)return(0,v.jsx)(s,{label:`Loading diagnostics…`});let L=e??{health:null,storage:null,stats:null,healthError:null,storageError:null,statsError:null},R=L.health,z=L.storage?.data,B=L.stats?.stats,V=R!=null,H=z!=null,U=V&&R.ok===!0,W=!!t||!!L.healthError||!!L.storageError||!!L.statsError;return(0,v.jsxs)(`div`,{children:[(0,v.jsx)(d,{title:`Diagnostics`,description:`Server health, storage, memory and connections.`,live:!!e&&!W}),t&&(0,v.jsx)(g,{message:`Diagnostics refresh failed — ${t.message}`,onRetry:b}),L.healthError&&(0,v.jsx)(g,{message:`Health unavailable — ${L.healthError}`,onRetry:b}),L.storageError&&(0,v.jsx)(g,{message:`Storage diagnostics unavailable — ${L.storageError}`,onRetry:b}),L.statsError&&(0,v.jsx)(g,{message:`Server totals unavailable — ${L.statsError}`,onRetry:b}),(0,v.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,v.jsx)(f,{label:`Status`,value:V?R.status??(R.ok?`healthy`:`degraded`):`Unavailable`,tone:U?`green`:`red`,compact:!0}),(0,v.jsx)(f,{label:`Version`,value:R?.version?`v${R.version}`:`—`,compact:!0}),(0,v.jsx)(f,{label:`Uptime`,value:l(R?.uptime),compact:!0}),(0,v.jsx)(f,{label:`Disk`,value:H?z.diskFull?`Full`:`Healthy`:`Unavailable`,tone:!H||z.diskFull?`red`:`green`,compact:!0})]}),(0,v.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,v.jsxs)(o,{children:[(0,v.jsx)(i,{title:`Connectivity`,action:(0,v.jsxs)(h,{size:`sm`,onClick:E,children:[`Ping`,C?` · ${C}`:``]})}),(0,v.jsxs)(`dl`,{className:`divide-y divide-line text-sm`,children:[(0,v.jsx)(x,{k:`WebSocket clients`,v:R?.connections?.ws==null?`—`:String(R.connections.ws)}),(0,v.jsx)(x,{k:`SSE clients`,v:R?.connections?.sse==null?`—`:String(R.connections.sse)}),(0,v.jsx)(x,{k:`Storage error`,v:L.storageError?`unavailable — ${L.storageError}`:z?.error?String(z.error):H?`none`:`—`})]})]}),(0,v.jsxs)(o,{children:[(0,v.jsx)(i,{title:`Memory`,action:(0,v.jsx)(h,{size:`sm`,disabled:D,onClick:j,children:D?`Compacting…`:`Compact (GC)`})}),(0,v.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,v.jsx)(S,{k:`Heap used`,v:R?.memory?p(R.memory.heapUsed*1024*1024):`—`}),(0,v.jsx)(S,{k:`Heap total`,v:R?.memory?p(R.memory.heapTotal*1024*1024):`—`}),(0,v.jsx)(S,{k:`RSS`,v:R?.memory?p(R.memory.rss*1024*1024):`—`})]}),k&&(0,v.jsx)(`p`,{className:`mt-3 text-xs text-muted`,children:k})]})]}),(0,v.jsxs)(o,{className:`mt-6`,children:[(0,v.jsx)(i,{title:`Heap statistics`,action:(0,v.jsx)(h,{size:`sm`,disabled:P,onClick:I,children:P?`Loading…`:M?`Refresh`:`Load`})}),M?(0,v.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,v.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,v.jsx)(S,{k:`Objects`,v:c(M.heap?.objectCount??0)}),(0,v.jsx)(S,{k:`Protected`,v:c(M.heap?.protectedCount??0)}),(0,v.jsx)(S,{k:`Global`,v:c(M.heap?.globalCount??0)})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`div`,{className:`mb-2 text-[11px] uppercase tracking-wider text-faint`,children:`Top object types`}),(0,v.jsx)(`div`,{className:`max-h-52 overflow-y-auto rounded-lg border border-line`,children:(0,v.jsx)(`table`,{className:`w-full text-xs`,children:(0,v.jsx)(`tbody`,{children:(M.topObjectTypes??[]).map(e=>(0,v.jsxs)(`tr`,{className:`border-b border-line last:border-0`,children:[(0,v.jsx)(`td`,{className:`px-3 py-1.5 font-mono text-muted`,children:e.type}),(0,v.jsx)(`td`,{className:`px-3 py-1.5 text-right tnum text-fg`,children:c(e.count)})]},e.type))})})})]})]}):(0,v.jsxs)(`p`,{className:`text-sm text-muted`,children:[`On-demand `,(0,v.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.`]})]}),(0,v.jsxs)(o,{className:`mt-6`,children:[(0,v.jsx)(i,{title:`Prometheus`}),(0,v.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,v.jsx)(`code`,{className:`font-mono text-xs`,children:`requireAuthForMetrics`}),`.`]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-line bg-surface-2 px-3 py-2`,children:[(0,v.jsx)(`code`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-fg`,children:m.prometheusUrl()}),(0,v.jsx)(a,{value:m.prometheusUrl()})]})]}),B&&(0,v.jsxs)(o,{className:`mt-6`,children:[(0,v.jsx)(i,{title:`Totals since restart`}),(0,v.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,v.jsx)(S,{k:`Pushed`,v:c(B.totalPushed)}),(0,v.jsx)(S,{k:`Pulled`,v:c(B.totalPulled)}),(0,v.jsx)(S,{k:`Completed`,v:c(B.totalCompleted)}),(0,v.jsx)(S,{k:`Failed`,v:c(B.totalFailed)})]})]})]})}function x({k:e,v:t}){return(0,v.jsxs)(`div`,{className:`flex items-center justify-between py-2.5`,children:[(0,v.jsx)(`dt`,{className:`text-muted`,children:e}),(0,v.jsx)(`dd`,{className:`font-medium text-fg`,children:t})]})}function S({k:e,v:t}){return(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-faint`,children:e}),(0,v.jsx)(`div`,{className:`mt-1 text-lg font-semibold tnum text-fg`,children:t})]})}export{b as Diagnostics};
1
+ import{r as e}from"./cn-CMFYpumL.js";import{g as t,t as n}from"./react-vendor-Bjui4wS4.js";import{A as r,C as i,O as a,S as o,b as s,c,d as l,ft as u,h as d,m as f,r as p,st as m,w as h,x as g}from"./index-Dr__4DsT.js";var _=e(t(),1),v=n();async function y(e){try{return{value:await e,error:null}}catch(e){return{value:null,error:e instanceof Error?e.message:String(e)}}}function b(){let{data:e,error:t,loading:n,refetch:b}=r(async()=>{let[e,t,n]=await Promise.all([y(m.health()),y(m.storage()),y(m.stats())]);return{health:e.value,storage:t.value,stats:n.value,healthError:e.error,storageError:t.error,statsError:n.error}},[]),[C,w]=(0,_.useState)(null),T=(0,_.useRef)(0),E=async()=>{let e=++T.current;w(`…`);let t=performance.now();try{await m.ping(),e===T.current&&w(`${Math.round(performance.now()-t)} ms`)}catch{e===T.current&&w(`unreachable`)}},[D,O]=(0,_.useState)(!1),[k,A]=(0,_.useState)(null),j=async()=>{O(!0),A(null);try{let e=await m.gc(),t=e.before.rss-e.after.rss,n=t>0?`Freed ${t} MB (RSS ${e.before.rss}→${e.after.rss})`:`No memory reclaimed`;A(n),u.success(`Memory compacted`,n),b()}catch(e){u.error(`GC failed`,e.message),A(e.message)}finally{O(!1)}},[M,N]=(0,_.useState)(null),[P,F]=(0,_.useState)(!1),I=async()=>{F(!0);try{N(await m.heapStats())}catch(e){u.error(`Heap stats failed`,e.message)}finally{F(!1)}};if(n&&!e&&!t)return(0,v.jsx)(s,{label:`Loading diagnostics…`});let L=e??{health:null,storage:null,stats:null,healthError:null,storageError:null,statsError:null},R=L.health,z=L.storage?.data,B=L.stats?.stats,V=R!=null,H=z!=null,U=V&&R.ok===!0,W=!!t||!!L.healthError||!!L.storageError||!!L.statsError;return(0,v.jsxs)(`div`,{children:[(0,v.jsx)(d,{title:`Diagnostics`,description:`Server health, storage, memory and connections.`,live:!!e&&!W}),t&&(0,v.jsx)(g,{message:`Diagnostics refresh failed — ${t.message}`,onRetry:b}),L.healthError&&(0,v.jsx)(g,{message:`Health unavailable — ${L.healthError}`,onRetry:b}),L.storageError&&(0,v.jsx)(g,{message:`Storage diagnostics unavailable — ${L.storageError}`,onRetry:b}),L.statsError&&(0,v.jsx)(g,{message:`Server totals unavailable — ${L.statsError}`,onRetry:b}),(0,v.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,v.jsx)(f,{label:`Status`,value:V?R.status??(R.ok?`healthy`:`degraded`):`Unavailable`,tone:U?`green`:`red`,compact:!0}),(0,v.jsx)(f,{label:`Version`,value:R?.version?`v${R.version}`:`—`,compact:!0}),(0,v.jsx)(f,{label:`Uptime`,value:l(R?.uptime),compact:!0}),(0,v.jsx)(f,{label:`Disk`,value:H?z.diskFull?`Full`:`Healthy`:`Unavailable`,tone:!H||z.diskFull?`red`:`green`,compact:!0})]}),(0,v.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,v.jsxs)(o,{children:[(0,v.jsx)(i,{title:`Connectivity`,action:(0,v.jsxs)(h,{size:`sm`,onClick:E,children:[`Ping`,C?` · ${C}`:``]})}),(0,v.jsxs)(`dl`,{className:`divide-y divide-line text-sm`,children:[(0,v.jsx)(x,{k:`WebSocket clients`,v:R?.connections?.ws==null?`—`:String(R.connections.ws)}),(0,v.jsx)(x,{k:`SSE clients`,v:R?.connections?.sse==null?`—`:String(R.connections.sse)}),(0,v.jsx)(x,{k:`Storage error`,v:L.storageError?`unavailable — ${L.storageError}`:z?.error?String(z.error):H?`none`:`—`})]})]}),(0,v.jsxs)(o,{children:[(0,v.jsx)(i,{title:`Memory`,action:(0,v.jsx)(h,{size:`sm`,disabled:D,onClick:j,children:D?`Compacting…`:`Compact (GC)`})}),(0,v.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,v.jsx)(S,{k:`Heap used`,v:R?.memory?p(R.memory.heapUsed*1024*1024):`—`}),(0,v.jsx)(S,{k:`Heap total`,v:R?.memory?p(R.memory.heapTotal*1024*1024):`—`}),(0,v.jsx)(S,{k:`RSS`,v:R?.memory?p(R.memory.rss*1024*1024):`—`})]}),k&&(0,v.jsx)(`p`,{className:`mt-3 text-xs text-muted`,children:k})]})]}),(0,v.jsxs)(o,{className:`mt-6`,children:[(0,v.jsx)(i,{title:`Heap statistics`,action:(0,v.jsx)(h,{size:`sm`,disabled:P,onClick:I,children:P?`Loading…`:M?`Refresh`:`Load`})}),M?(0,v.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,v.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,v.jsx)(S,{k:`Objects`,v:c(M.heap?.objectCount??0)}),(0,v.jsx)(S,{k:`Protected`,v:c(M.heap?.protectedCount??0)}),(0,v.jsx)(S,{k:`Global`,v:c(M.heap?.globalCount??0)})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`div`,{className:`mb-2 text-[11px] uppercase tracking-wider text-faint`,children:`Top object types`}),(0,v.jsx)(`div`,{className:`max-h-52 overflow-y-auto rounded-lg border border-line`,children:(0,v.jsx)(`table`,{className:`w-full text-xs`,children:(0,v.jsx)(`tbody`,{children:(M.topObjectTypes??[]).map(e=>(0,v.jsxs)(`tr`,{className:`border-b border-line last:border-0`,children:[(0,v.jsx)(`td`,{className:`px-3 py-1.5 font-mono text-muted`,children:e.type}),(0,v.jsx)(`td`,{className:`px-3 py-1.5 text-right tnum text-fg`,children:c(e.count)})]},e.type))})})})]})]}):(0,v.jsxs)(`p`,{className:`text-sm text-muted`,children:[`On-demand `,(0,v.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.`]})]}),(0,v.jsxs)(o,{className:`mt-6`,children:[(0,v.jsx)(i,{title:`Prometheus`}),(0,v.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,v.jsx)(`code`,{className:`font-mono text-xs`,children:`requireAuthForMetrics`}),`.`]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-line bg-surface-2 px-3 py-2`,children:[(0,v.jsx)(`code`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-fg`,children:m.prometheusUrl()}),(0,v.jsx)(a,{value:m.prometheusUrl()})]})]}),B&&(0,v.jsxs)(o,{className:`mt-6`,children:[(0,v.jsx)(i,{title:`Totals since restart`}),(0,v.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,v.jsx)(S,{k:`Pushed`,v:c(B.totalPushed)}),(0,v.jsx)(S,{k:`Pulled`,v:c(B.totalPulled)}),(0,v.jsx)(S,{k:`Completed`,v:c(B.totalCompleted)}),(0,v.jsx)(S,{k:`Failed`,v:c(B.totalFailed)})]})]})]})}function x({k:e,v:t}){return(0,v.jsxs)(`div`,{className:`flex items-center justify-between py-2.5`,children:[(0,v.jsx)(`dt`,{className:`text-muted`,children:e}),(0,v.jsx)(`dd`,{className:`font-medium text-fg`,children:t})]})}function S({k:e,v:t}){return(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-faint`,children:e}),(0,v.jsx)(`div`,{className:`mt-1 text-lg font-semibold tnum text-fg`,children:t})]})}export{b as Diagnostics};
@@ -1 +1 @@
1
- import{r as e}from"./cn-CMFYpumL.js";import{g as t,t as n}from"./react-vendor-Bjui4wS4.js";import{A as r,R as i,b as a,c as o,h as s,j as c,m as l,u,v as d,w as f,x as p,y as m}from"./index-Bn2R06qm.js";import{a as h}from"./form-DsUq0w8s.js";import{t as g}from"./Pagination-DpxiBnt8.js";import{r as _,t as v}from"./flowMutationSafety-DVD1IMr-.js";import{discoverAllQueues as y}from"./Jobs-BUtcBKKk.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}=r(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}=r((0,b.useCallback)(async()=>{if(!e)return{entries:[],total:0};let t=await c.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)(p,{message:`DLQ refresh failed — showing the last successful page.`,onRetry:j}),T&&(0,x.jsx)(p,{onRetry:D,message:`Could not discover queues — ${T.message}. Retry before selecting a queue.`}),(0,x.jsx)(s,{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)(f,{size:`sm`,disabled:!0,title:v,children:`Retry all`}),(0,x.jsx)(f,{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)(l,{label:`DLQ Entries`,value:e&&O?o(O.total):`—`,tone:e&&O?.total?`red`:`default`,compact:!0})})]}),k&&!O?(0,x.jsx)(m,{error:k,onRetry:j}):E&&!C&&!e&&!T?(0,x.jsx)(a,{label:`Discovering queues…`}):A&&!O&&!k?(0,x.jsx)(a,{label:`Loading DLQ…`}):T&&!e?(0,x.jsx)(d,{icon:(0,x.jsx)(i,{}),title:`Could not discover queues`,hint:`${T.message}. Retry the queue discovery request above.`}):e?M.length===0?(0,x.jsx)(d,{icon:(0,x.jsx)(i,{}),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.data?.name||`unnamed`}),(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:u(e.attempts?.at(-1)?.failedAt??e.enteredAt)})]},e.job.id||t))})]})}):(0,x.jsx)(d,{icon:(0,x.jsx)(i,{}),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{r as e}from"./cn-CMFYpumL.js";import{g as t,t as n}from"./react-vendor-Bjui4wS4.js";import{A as r,R as i,b as a,c as o,h as s,j as c,m as l,u,v as d,w as f,x as p,y as m}from"./index-Dr__4DsT.js";import{a as h}from"./form-DsUq0w8s.js";import{t as g}from"./Pagination-eotgGQf9.js";import{r as _,t as v}from"./flowMutationSafety-DVD1IMr-.js";import{discoverAllQueues as y}from"./Jobs-BZGtMnJI.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}=r(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}=r((0,b.useCallback)(async()=>{if(!e)return{entries:[],total:0};let t=await c.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)(p,{message:`DLQ refresh failed — showing the last successful page.`,onRetry:j}),T&&(0,x.jsx)(p,{onRetry:D,message:`Could not discover queues — ${T.message}. Retry before selecting a queue.`}),(0,x.jsx)(s,{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)(f,{size:`sm`,disabled:!0,title:v,children:`Retry all`}),(0,x.jsx)(f,{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)(l,{label:`DLQ Entries`,value:e&&O?o(O.total):`—`,tone:e&&O?.total?`red`:`default`,compact:!0})})]}),k&&!O?(0,x.jsx)(m,{error:k,onRetry:j}):E&&!C&&!e&&!T?(0,x.jsx)(a,{label:`Discovering queues…`}):A&&!O&&!k?(0,x.jsx)(a,{label:`Loading DLQ…`}):T&&!e?(0,x.jsx)(d,{icon:(0,x.jsx)(i,{}),title:`Could not discover queues`,hint:`${T.message}. Retry the queue discovery request above.`}):e?M.length===0?(0,x.jsx)(d,{icon:(0,x.jsx)(i,{}),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.data?.name||`unnamed`}),(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:u(e.attempts?.at(-1)?.failedAt??e.enteredAt)})]},e.job.id||t))})]})}):(0,x.jsx)(d,{icon:(0,x.jsx)(i,{}),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{r as e,t}from"./cn-CMFYpumL.js";import{g as n,r,t as i}from"./react-vendor-Bjui4wS4.js";import{A as a,B as o,F as s,J as c,K as l,O as u,R as d,T as f,a as p,b as m,c as h,ft as g,h as _,m as v,o as y,st as b,u as x,v as S,w as C,x as w,y as T,z as E}from"./index-Bn2R06qm.js";import{a as D}from"./form-DsUq0w8s.js";import{t as O}from"./Pagination-DpxiBnt8.js";import{r as k,t as A}from"./flowMutationSafety-DVD1IMr-.js";import{t as j}from"./exportFile-C7xhE8Yh.js";import{loadAllQueuePages as M}from"./QueueControl-V0DJ6qk6.js";var N=e(n(),1),P=i(),F=25,I=e=>`${e.job.id}-${e.enteredAt}`;function L(){let[e,t]=(0,N.useState)(``),[n,r]=(0,N.useState)(0),[i,o]=(0,N.useState)(`all`),[s,u]=(0,N.useState)(``),[f,p]=(0,N.useState)(new Set),{data:y,error:L,loading:z,refetch:B}=a(M,[],{intervalMs:3e4});(0,N.useEffect)(()=>{e||!y?.queues?.length||t((y.queues.find(e=>e.dlq>0)??y.queues[0]).name)},[y,e]);let{data:V,error:H,loading:U,refetch:W}=a((0,N.useCallback)(async()=>{if(!e)return{queue:e,page:n,entries:[],total:0,stats:null,statsError:null};let[t,r]=await Promise.all([b.dlq(e,F,n*F),b.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]),G=V&&V.queue===e&&V.page===n?V:null;(0,N.useEffect)(()=>{if(!G)return;let e=Math.max(0,Math.ceil((G.total??0)/F)-1);n>e&&r(e)},[G,n]),(0,N.useEffect)(()=>{p(new Set)},[e,n]);let K=G?.stats?.byReason??{},q=(0,N.useMemo)(()=>Object.keys(K).filter(e=>K[e]>0),[K]),J=(0,N.useMemo)(()=>[...q].sort((e,t)=>(K[t]??0)-(K[e]??0))[0],[q,K]),Y=G?.entries??[],X=(0,N.useMemo)(()=>{let e=Y;i!==`all`&&(e=e.filter(e=>e.reason===i));let t=s.trim().toLowerCase();return t&&(e=e.filter(e=>e.job.id.toLowerCase().includes(t))),[...e].sort((e,t)=>t.enteredAt-e.enteredAt)},[Y,i,s]),Z=i!==`all`||s.trim()!==``,Q=(G?.total??0)>F,$=e=>p(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)(_,{title:`DLQ Control`,description:`Inspect and triage one queue's dead-lettered jobs.`,live:!!e&&!!G&&!G.statsError&&!H&&!L,actions:(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(C,{size:`sm`,disabled:!e||!X.length,onClick:()=>{if(X.length===0){g.info(`Nothing to export`);return}j(`dlq-${e}`,X.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)(E,{className:`size-3.5`}),` Export`]}),(0,P.jsxs)(C,{size:`sm`,disabled:!0,title:A,children:[(0,P.jsx)(l,{className:`size-3.5`}),` Retry all`]}),(0,P.jsx)(C,{variant:`danger`,size:`sm`,disabled:!0,title:k,children:`Purge`})]})}),H&&G&&(0,P.jsx)(w,{message:`DLQ refresh failed — showing the last successful page.`,onRetry:W}),L&&(0,P.jsx)(w,{onRetry:B,message:`Could not discover queues — ${L.message}. Retry before selecting a queue.`}),G?.statsError&&(0,P.jsx)(w,{message:`DLQ statistics are unavailable — ${G.statsError}. The entry list may still be current.`,onRetry:W}),(0,P.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,P.jsx)(v,{label:`Entries`,value:e&&G?h(G.total):`—`,tone:!e||!G?`default`:G.total?`red`:`green`,hint:!e||!G?`waiting for queue data`:G.total?J?`top: ${J}`:void 0:`queue is clean`,compact:!0}),(0,P.jsx)(v,{label:`Failure types`,value:G?.stats?h(q.length):`—`,hint:`distinct reasons`,compact:!0}),(0,P.jsx)(v,{label:`Pending retry`,value:G?.stats?h(G.stats.pendingRetry??0):`—`,tone:G?.stats?.pendingRetry?`amber`:`default`,hint:`auto-retry queued`,compact:!0}),(0,P.jsx)(v,{label:`Oldest entry`,value:G?.stats?.oldestEntry?x(G.stats.oldestEntry):`—`,hint:`time in DLQ`,compact:!0})]}),(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=>{t(e.target.value),r(0),o(`all`),u(``)},children:(y?.queues??[]).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:i,"aria-label":`Filter by reason`,name:`dlq-control-reason`,autoComplete:`off`,onChange:e=>o(e.target.value),children:[(0,P.jsx)(`option`,{value:`all`,children:`All reasons`}),q.map(e=>(0,P.jsxs)(`option`,{value:e,children:[e,` (`,K[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:s,onChange:e=>u(e.target.value),placeholder:Q?`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`})]})]}),(0,P.jsx)(`p`,{className:`mb-4 text-xs text-warning`,children:A}),H&&!G?(0,P.jsx)(T,{error:H,onRetry:W}):z&&!y&&!e&&!L?(0,P.jsx)(m,{label:`Discovering queues…`}):U&&!G&&!H?(0,P.jsx)(m,{label:`Loading DLQ…`}):L&&!e?(0,P.jsx)(S,{icon:(0,P.jsx)(d,{}),title:`Could not discover queues`,hint:`${L.message}. Retry the queue discovery request above.`}):e?X.length===0?(0,P.jsx)(S,{icon:(0,P.jsx)(d,{}),title:Z?`No matches`:`Dead letter queue is empty`,hint:Z?Q?`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:`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:X.map(e=>{let t=I(e);return(0,P.jsx)(R,{entry:e,isOpen:f.has(t),onToggle:()=>$(t),attempts:e.attempts??[]},t)})})]})}):(0,P.jsx)(S,{icon:(0,P.jsx)(d,{}),title:y?.queues.length===0?`No queues available`:`Select a queue`,hint:`A queue must be selected before its dead letter entries can be inspected.`}),G&&(0,P.jsx)(O,{page:n,pageSize:F,total:G.total,onPageChange:r,label:`entries`})]})}function R({entry:e,isOpen:n,onToggle:i,attempts:a}){let c=e;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)(f,{"aria-label":n?`Collapse details`:`Expand details`,"aria-expanded":n,onClick:i,children:(0,P.jsx)(s,{className:t(`size-3.5 transition-transform`,n&&`rotate-90`)})})}),(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(c.job.id)}`,className:`max-w-[14rem] truncate font-mono text-xs text-accent hover:underline`,title:c.job.id,children:c.job.id}),(0,P.jsx)(u,{value:c.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:c.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:c.error??``,children:c.error||`—`})}),(0,P.jsx)(`td`,{className:`px-3 py-3 text-right tnum text-muted`,children:c.job.attempts??a.length}),(0,P.jsx)(`td`,{className:`px-3 py-3 text-right text-faint`,title:p(c.enteredAt),children:x(c.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(c.job.id)}`,"aria-label":`Inspect job ${c.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)(o,{className:`size-3.5`})}),(0,P.jsx)(f,{"aria-label":`Retry job unavailable`,disabled:!0,title:A,children:(0,P.jsx)(l,{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:6,className:`px-3 pb-4 pt-1`,children:[c.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:c.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 c.retryCount==`number`&&c.retryCount>0&&(0,P.jsxs)(`span`,{className:`rounded-full bg-surface px-2 py-0.5 text-[10px] normal-case text-muted`,children:[`retried `,c.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:p(e.failedAt),children:x(e.failedAt)}),e.duration!=null&&(0,P.jsx)(`span`,{className:`tnum text-muted`,children:y(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}`))})]})]})]})}export{L as DlqControl};
1
+ import{r as e,t}from"./cn-CMFYpumL.js";import{g as n,r,t as i}from"./react-vendor-Bjui4wS4.js";import{A as a,B as o,F as s,J as c,K as l,O as u,R as d,T as f,a as p,b as m,c as h,ft as g,h as _,m as v,o as y,st as b,u as x,v as S,w as C,x as w,y as T,z as E}from"./index-Dr__4DsT.js";import{a as D}from"./form-DsUq0w8s.js";import{t as O}from"./Pagination-eotgGQf9.js";import{r as k,t as A}from"./flowMutationSafety-DVD1IMr-.js";import{t as j}from"./exportFile-C7xhE8Yh.js";import{loadAllQueuePages as M}from"./QueueControl-DwYNcMfI.js";var N=e(n(),1),P=i(),F=25,I=e=>`${e.job.id}-${e.enteredAt}`;function L(){let[e,t]=(0,N.useState)(``),[n,r]=(0,N.useState)(0),[i,o]=(0,N.useState)(`all`),[s,u]=(0,N.useState)(``),[f,p]=(0,N.useState)(new Set),{data:y,error:L,loading:z,refetch:B}=a(M,[],{intervalMs:3e4});(0,N.useEffect)(()=>{e||!y?.queues?.length||t((y.queues.find(e=>e.dlq>0)??y.queues[0]).name)},[y,e]);let{data:V,error:H,loading:U,refetch:W}=a((0,N.useCallback)(async()=>{if(!e)return{queue:e,page:n,entries:[],total:0,stats:null,statsError:null};let[t,r]=await Promise.all([b.dlq(e,F,n*F),b.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]),G=V&&V.queue===e&&V.page===n?V:null;(0,N.useEffect)(()=>{if(!G)return;let e=Math.max(0,Math.ceil((G.total??0)/F)-1);n>e&&r(e)},[G,n]),(0,N.useEffect)(()=>{p(new Set)},[e,n]);let K=G?.stats?.byReason??{},q=(0,N.useMemo)(()=>Object.keys(K).filter(e=>K[e]>0),[K]),J=(0,N.useMemo)(()=>[...q].sort((e,t)=>(K[t]??0)-(K[e]??0))[0],[q,K]),Y=G?.entries??[],X=(0,N.useMemo)(()=>{let e=Y;i!==`all`&&(e=e.filter(e=>e.reason===i));let t=s.trim().toLowerCase();return t&&(e=e.filter(e=>e.job.id.toLowerCase().includes(t))),[...e].sort((e,t)=>t.enteredAt-e.enteredAt)},[Y,i,s]),Z=i!==`all`||s.trim()!==``,Q=(G?.total??0)>F,$=e=>p(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)(_,{title:`DLQ Control`,description:`Inspect and triage one queue's dead-lettered jobs.`,live:!!e&&!!G&&!G.statsError&&!H&&!L,actions:(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(C,{size:`sm`,disabled:!e||!X.length,onClick:()=>{if(X.length===0){g.info(`Nothing to export`);return}j(`dlq-${e}`,X.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)(E,{className:`size-3.5`}),` Export`]}),(0,P.jsxs)(C,{size:`sm`,disabled:!0,title:A,children:[(0,P.jsx)(l,{className:`size-3.5`}),` Retry all`]}),(0,P.jsx)(C,{variant:`danger`,size:`sm`,disabled:!0,title:k,children:`Purge`})]})}),H&&G&&(0,P.jsx)(w,{message:`DLQ refresh failed — showing the last successful page.`,onRetry:W}),L&&(0,P.jsx)(w,{onRetry:B,message:`Could not discover queues — ${L.message}. Retry before selecting a queue.`}),G?.statsError&&(0,P.jsx)(w,{message:`DLQ statistics are unavailable — ${G.statsError}. The entry list may still be current.`,onRetry:W}),(0,P.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,P.jsx)(v,{label:`Entries`,value:e&&G?h(G.total):`—`,tone:!e||!G?`default`:G.total?`red`:`green`,hint:!e||!G?`waiting for queue data`:G.total?J?`top: ${J}`:void 0:`queue is clean`,compact:!0}),(0,P.jsx)(v,{label:`Failure types`,value:G?.stats?h(q.length):`—`,hint:`distinct reasons`,compact:!0}),(0,P.jsx)(v,{label:`Pending retry`,value:G?.stats?h(G.stats.pendingRetry??0):`—`,tone:G?.stats?.pendingRetry?`amber`:`default`,hint:`auto-retry queued`,compact:!0}),(0,P.jsx)(v,{label:`Oldest entry`,value:G?.stats?.oldestEntry?x(G.stats.oldestEntry):`—`,hint:`time in DLQ`,compact:!0})]}),(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=>{t(e.target.value),r(0),o(`all`),u(``)},children:(y?.queues??[]).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:i,"aria-label":`Filter by reason`,name:`dlq-control-reason`,autoComplete:`off`,onChange:e=>o(e.target.value),children:[(0,P.jsx)(`option`,{value:`all`,children:`All reasons`}),q.map(e=>(0,P.jsxs)(`option`,{value:e,children:[e,` (`,K[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:s,onChange:e=>u(e.target.value),placeholder:Q?`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`})]})]}),(0,P.jsx)(`p`,{className:`mb-4 text-xs text-warning`,children:A}),H&&!G?(0,P.jsx)(T,{error:H,onRetry:W}):z&&!y&&!e&&!L?(0,P.jsx)(m,{label:`Discovering queues…`}):U&&!G&&!H?(0,P.jsx)(m,{label:`Loading DLQ…`}):L&&!e?(0,P.jsx)(S,{icon:(0,P.jsx)(d,{}),title:`Could not discover queues`,hint:`${L.message}. Retry the queue discovery request above.`}):e?X.length===0?(0,P.jsx)(S,{icon:(0,P.jsx)(d,{}),title:Z?`No matches`:`Dead letter queue is empty`,hint:Z?Q?`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:`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:X.map(e=>{let t=I(e);return(0,P.jsx)(R,{entry:e,isOpen:f.has(t),onToggle:()=>$(t),attempts:e.attempts??[]},t)})})]})}):(0,P.jsx)(S,{icon:(0,P.jsx)(d,{}),title:y?.queues.length===0?`No queues available`:`Select a queue`,hint:`A queue must be selected before its dead letter entries can be inspected.`}),G&&(0,P.jsx)(O,{page:n,pageSize:F,total:G.total,onPageChange:r,label:`entries`})]})}function R({entry:e,isOpen:n,onToggle:i,attempts:a}){let c=e;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)(f,{"aria-label":n?`Collapse details`:`Expand details`,"aria-expanded":n,onClick:i,children:(0,P.jsx)(s,{className:t(`size-3.5 transition-transform`,n&&`rotate-90`)})})}),(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(c.job.id)}`,className:`max-w-[14rem] truncate font-mono text-xs text-accent hover:underline`,title:c.job.id,children:c.job.id}),(0,P.jsx)(u,{value:c.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:c.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:c.error??``,children:c.error||`—`})}),(0,P.jsx)(`td`,{className:`px-3 py-3 text-right tnum text-muted`,children:c.job.attempts??a.length}),(0,P.jsx)(`td`,{className:`px-3 py-3 text-right text-faint`,title:p(c.enteredAt),children:x(c.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(c.job.id)}`,"aria-label":`Inspect job ${c.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)(o,{className:`size-3.5`})}),(0,P.jsx)(f,{"aria-label":`Retry job unavailable`,disabled:!0,title:A,children:(0,P.jsx)(l,{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:6,className:`px-3 pb-4 pt-1`,children:[c.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:c.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 c.retryCount==`number`&&c.retryCount>0&&(0,P.jsxs)(`span`,{className:`rounded-full bg-surface px-2 py-0.5 text-[10px] normal-case text-muted`,children:[`retried `,c.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:p(e.failedAt),children:x(e.failedAt)}),e.duration!=null&&(0,P.jsx)(`span`,{className:`tnum text-muted`,children:y(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}`))})]})]})]})}export{L as DlqControl};
@@ -1 +1 @@
1
- import{r as e,t}from"./cn-CMFYpumL.js";import{f as n,g as r,r as i,t as a}from"./react-vendor-Bjui4wS4.js";import{A as o,K as s,R as c,S as l,T as u,b as d,c as f,ft as ee,h as te,st as p,u as m,v as h,w as g,x as _,y as v,z as y}from"./index-Bn2R06qm.js";import{a as b}from"./form-DsUq0w8s.js";import{t as ne}from"./Pagination-DpxiBnt8.js";import{r as re,t as x}from"./flowMutationSafety-DVD1IMr-.js";import{t as ie}from"./exportFile-C7xhE8Yh.js";import{loadAllQueuePages as ae}from"./QueueControl-V0DJ6qk6.js";var S=e(r(),1),C=a(),w=25;function T(){let[e,r]=n(),[a,T]=(0,S.useState)(``),[E,D]=(0,S.useState)(`all`),[O,k]=(0,S.useState)(`newest`),[A,oe]=(0,S.useState)(``),[j,M]=(0,S.useState)(0),[N,se]=(0,S.useState)(new Set),{data:P,error:F,loading:ce,refetch:le}=o(ae,[],{intervalMs:1e4}),I=P?.queues??[],L=P?I.reduce((e,t)=>e+t.dlq,0):null,{data:R,error:z,loading:B,refetch:V}=o((0,S.useCallback)(async()=>{if(!a)return{queue:a,page:j,entries:[],entriesTotal:0,stats:null,statsError:null};let[e,t]=await Promise.all([p.dlq(a,w,j*w),p.dlqStats(a).then(e=>({stats:e.stats,error:null})).catch(e=>({stats:null,error:e.message||`Unknown error`}))]);return{queue:a,page:j,entries:e.entries??[],entriesTotal:e.total??0,stats:t.stats,statsError:t.error}},[a,j]),[a,j]),H=R&&R.queue===a&&R.page===j?R:null;(0,S.useEffect)(()=>{if(!H)return;let e=H.entriesTotal??0;j>0&&j*w>=e&&M(Math.max(0,Math.ceil(e/w)-1))},[H,j]);let U=()=>{let e=(H?.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){ee.info(`Nothing to export on this page`);return}ie(`dlq-${a}`,e,[`jobId`,`reason`,`error`,`enteredAt`,`attempts`])},W=e=>{J.current=!0,T(e),M(0),D(`all`),r(e?{queue:e}:{},{replace:!0})},G=H?.stats?.byReason??{},K=Object.keys(G).filter(e=>G[e]>0),ue=[...K].sort((e,t)=>(G[t]??0)-(G[e]??0))[0],q=(0,S.useMemo)(()=>I.filter(e=>e.dlq>0).sort((e,t)=>t.dlq-e.dlq),[I]),J=(0,S.useRef)(!1),Y=e.get(`queue`);(0,S.useEffect)(()=>{if(!(J.current||a)){if(Y){if(I.some(e=>e.name===Y)){J.current=!0,T(Y),M(0),D(`all`);return}if(I.length===0)return}q.length!==0&&(J.current=!0,T(q[0].name),M(0),D(`all`))}},[a,I,q,Y]);let X=(0,S.useMemo)(()=>{let e=H?.entries??[];E!==`all`&&(e=e.filter(e=>e.reason===E));let t=A.trim().toLowerCase();return t&&(e=e.filter(e=>e.job.id.toLowerCase().includes(t))),[...e].sort((e,t)=>O===`newest`?t.enteredAt-e.enteredAt:e.enteredAt-t.enteredAt)},[H,E,A,O]),Z=L===0&&!F,Q=E!==`all`||A.trim()!==``,$=(H?.entriesTotal??0)>w;return(0,C.jsxs)(`div`,{children:[(0,C.jsx)(te,{title:`Dead Letter Queue`,description:`Jobs that failed after exhausting all retries. Inspect and export entries without mutating flow topology.`,live:!!a&&!!H&&!H.statsError&&!z&&!F}),z&&H&&(0,C.jsx)(_,{message:`DLQ refresh failed — showing the last successful page.`,onRetry:V}),F&&(0,C.jsx)(_,{onRetry:le,message:`Could not discover queue DLQ totals — ${F.message}. Health status is unavailable.`}),H?.statsError&&(0,C.jsx)(_,{message:`DLQ statistics are unavailable — ${H.statsError}. The entry list may still be current.`,onRetry:V}),(0,C.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,C.jsxs)(l,{children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,C.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Total in DLQ`}),(0,C.jsx)(`span`,{className:t(`rounded-full px-2 py-0.5 text-[11px] font-medium`,F?`bg-amber-500/10 text-warning`:L==null?`bg-surface-2 text-muted`:Z?`bg-emerald-500/10 text-success`:`bg-red-500/10 text-danger`),children:F?`Unavailable`:L==null?`Loading`:Z?`Healthy`:`Attention`})]}),(0,C.jsx)(`div`,{className:t(`mt-2 text-3xl font-bold tnum`,L==null||F?`text-muted`:Z?`text-success`:`text-danger`),children:L==null?`—`:f(L)})]}),(0,C.jsxs)(l,{children:[(0,C.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Top Reason`}),(0,C.jsx)(`div`,{className:`mt-2 text-lg font-semibold text-fg`,children:F||H?.statsError?`Unavailable`:a?ue??`No failures`:`Select a queue`})]}),(0,C.jsxs)(l,{children:[(0,C.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Pending Retry`}),(0,C.jsx)(`div`,{className:`mt-2 text-3xl font-bold tnum text-fg`,children:H?.stats?f(H.stats.pendingRetry??0):`—`}),(0,C.jsx)(`div`,{className:`mt-1 text-xs text-faint`,children:a?`in this queue`:`awaiting retry`})]}),(0,C.jsxs)(l,{children:[(0,C.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Failure Types`}),(0,C.jsx)(`div`,{className:`mt-2 text-3xl font-bold tnum text-fg`,children:H?.stats?f(K.length):`—`}),(0,C.jsx)(`div`,{className:`mt-1 text-xs text-faint`,children:`distinct reasons`})]})]}),q.length>0&&(0,C.jsxs)(l,{className:`mb-6`,children:[(0,C.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,C.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`DLQ by queue`}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsxs)(g,{size:`sm`,disabled:!0,title:`DLQ retry is unavailable in Bunqueue v2.8.55: its GET and retry POST have no atomic job-generation, state, or flow-topology precondition.`,children:[(0,C.jsx)(s,{className:`size-3.5`}),` Retry all (`,q.length,` queues)`]}),(0,C.jsxs)(g,{variant:`danger`,size:`sm`,disabled:!0,title:`Unavailable in Bunqueue v2.8.55: the server cannot inspect reverse flow dependencies or delete/discard topology atomically.`,children:[`Purge all (`,q.length,` queues)`]})]})]}),(0,C.jsx)(`div`,{className:`grid grid-cols-2 gap-3 md:grid-cols-4 xl:grid-cols-5`,children:q.map(e=>(0,C.jsxs)(`button`,{type:`button`,onClick:()=>W(e.name),className:t(`rounded-lg border p-3 text-left transition-colors`,a===e.name?`border-accent/50 bg-surface-2`:`border-line hover:border-line-strong`),children:[(0,C.jsx)(`div`,{className:`truncate font-mono text-xs text-muted`,children:e.name}),(0,C.jsx)(`div`,{className:`mt-1 text-xl font-bold tnum text-danger`,children:e.dlq})]},e.name))})]}),(0,C.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-3`,children:[(0,C.jsx)(`div`,{className:`w-48`,children:(0,C.jsxs)(b,{value:a,"aria-label":`Queue`,name:`dlq-queue`,autoComplete:`off`,onChange:e=>W(e.target.value),children:[(0,C.jsx)(`option`,{value:``,children:`Select a queue…`}),I.map(e=>(0,C.jsxs)(`option`,{value:e.name,children:[e.name,e.dlq?` (${e.dlq})`:``]},e.name))]})}),(0,C.jsx)(`div`,{className:`w-40`,children:(0,C.jsxs)(b,{value:E,onChange:e=>D(e.target.value),"aria-label":`Filter by reason`,name:`dlq-reason-filter`,autoComplete:`off`,children:[(0,C.jsx)(`option`,{value:`all`,children:`All Reasons`}),K.map(e=>(0,C.jsx)(`option`,{value:e,children:e},e))]})}),(0,C.jsx)(`div`,{className:`w-36`,children:(0,C.jsxs)(b,{value:O,onChange:e=>k(e.target.value),"aria-label":$?`Sort this page`:`Sort`,name:`dlq-sort`,autoComplete:`off`,children:[(0,C.jsxs)(`option`,{value:`newest`,children:[`Newest First`,$?` (this page)`:``]}),(0,C.jsxs)(`option`,{value:`oldest`,children:[`Oldest First`,$?` (this page)`:``]})]})}),(0,C.jsx)(`input`,{value:A,onChange:e=>oe(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,C.jsxs)(g,{size:`sm`,disabled:!0,title:x,children:[(0,C.jsx)(s,{className:`size-3.5`}),` Retry All`]}),(0,C.jsx)(g,{variant:`danger`,size:`sm`,disabled:!0,title:re,children:`Purge All`}),(0,C.jsx)(u,{"aria-label":`Export this page to CSV`,title:`Export this page to CSV`,disabled:!a,onClick:U,children:(0,C.jsx)(y,{className:`size-3.5`})})]}),(0,C.jsx)(`p`,{className:`mb-4 text-xs text-warning`,children:x}),z&&!H?(0,C.jsx)(v,{error:z,onRetry:V}):ce&&!P&&!a&&!F?(0,C.jsx)(d,{label:`Discovering queues…`}):B&&!H&&!z?(0,C.jsx)(d,{label:`Loading DLQ…`}):F&&!a?(0,C.jsx)(h,{icon:(0,C.jsx)(c,{}),title:`Could not discover queues`,hint:`${F.message}. Retry the queue discovery request above.`}):a?X.length===0?(0,C.jsx)(h,{icon:(0,C.jsx)(c,{}),title:Q?`No matches on this page`:`No dead letter entries`,hint:Q?`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,C.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,C.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,C.jsx)(`thead`,{children:(0,C.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,C.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Job ID`}),(0,C.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Reason`}),(0,C.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Error`}),(0,C.jsx)(`th`,{scope:`col`,className:`px-5 py-3 text-right font-medium`,children:`Entered`}),(0,C.jsx)(`th`,{scope:`col`,className:`w-16 px-5 py-3`})]})}),(0,C.jsx)(`tbody`,{children:X.map(e=>(0,C.jsxs)(`tr`,{className:`border-b border-line last:border-0 align-top hover:bg-surface-2/40`,children:[(0,C.jsx)(`td`,{className:`px-5 py-3`,children:(0,C.jsx)(i,{to:`/job?id=${encodeURIComponent(e.job.id)}`,className:`font-mono text-xs text-accent hover:underline`,children:e.job.id})}),(0,C.jsx)(`td`,{className:`px-5 py-3`,children:(0,C.jsx)(`span`,{className:`rounded-md bg-red-500/10 px-2 py-0.5 text-xs text-danger`,children:e.reason})}),(0,C.jsx)(`td`,{className:`max-w-md px-5 py-3 text-xs text-danger/80`,children:e.error?(0,C.jsx)(`button`,{type:`button`,title:e.error,"aria-expanded":N.has(`${e.job.id}-${e.enteredAt}`),onClick:()=>se(t=>{let n=new Set(t),r=`${e.job.id}-${e.enteredAt}`;return n.has(r)?n.delete(r):n.add(r),n}),className:t(`block w-full break-words text-left`,!N.has(`${e.job.id}-${e.enteredAt}`)&&`line-clamp-2`),children:e.error}):`—`}),(0,C.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:m(e.enteredAt)}),(0,C.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,C.jsx)(u,{"aria-label":`Retry unavailable`,disabled:!0,title:x,children:(0,C.jsx)(s,{className:`size-3.5`})})})]},`${e.job.id}-${e.enteredAt}`))})]})}):(0,C.jsx)(h,{icon:(0,C.jsx)(c,{}),title:`Select a queue`,hint:`Choose a queue from the dropdown to view its dead letter queue entries.`}),a&&H&&(0,C.jsx)(ne,{page:j,pageSize:w,total:H.entriesTotal,onPageChange:M,label:`entries`})]})}export{T as DlqPro};
1
+ import{r as e,t}from"./cn-CMFYpumL.js";import{f as n,g as r,r as i,t as a}from"./react-vendor-Bjui4wS4.js";import{A as o,K as s,R as c,S as l,T as u,b as d,c as f,ft as ee,h as te,st as p,u as m,v as h,w as g,x as _,y as v,z as y}from"./index-Dr__4DsT.js";import{a as b}from"./form-DsUq0w8s.js";import{t as ne}from"./Pagination-eotgGQf9.js";import{r as re,t as x}from"./flowMutationSafety-DVD1IMr-.js";import{t as ie}from"./exportFile-C7xhE8Yh.js";import{loadAllQueuePages as ae}from"./QueueControl-DwYNcMfI.js";var S=e(r(),1),C=a(),w=25;function T(){let[e,r]=n(),[a,T]=(0,S.useState)(``),[E,D]=(0,S.useState)(`all`),[O,k]=(0,S.useState)(`newest`),[A,oe]=(0,S.useState)(``),[j,M]=(0,S.useState)(0),[N,se]=(0,S.useState)(new Set),{data:P,error:F,loading:ce,refetch:le}=o(ae,[],{intervalMs:1e4}),I=P?.queues??[],L=P?I.reduce((e,t)=>e+t.dlq,0):null,{data:R,error:z,loading:B,refetch:V}=o((0,S.useCallback)(async()=>{if(!a)return{queue:a,page:j,entries:[],entriesTotal:0,stats:null,statsError:null};let[e,t]=await Promise.all([p.dlq(a,w,j*w),p.dlqStats(a).then(e=>({stats:e.stats,error:null})).catch(e=>({stats:null,error:e.message||`Unknown error`}))]);return{queue:a,page:j,entries:e.entries??[],entriesTotal:e.total??0,stats:t.stats,statsError:t.error}},[a,j]),[a,j]),H=R&&R.queue===a&&R.page===j?R:null;(0,S.useEffect)(()=>{if(!H)return;let e=H.entriesTotal??0;j>0&&j*w>=e&&M(Math.max(0,Math.ceil(e/w)-1))},[H,j]);let U=()=>{let e=(H?.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){ee.info(`Nothing to export on this page`);return}ie(`dlq-${a}`,e,[`jobId`,`reason`,`error`,`enteredAt`,`attempts`])},W=e=>{J.current=!0,T(e),M(0),D(`all`),r(e?{queue:e}:{},{replace:!0})},G=H?.stats?.byReason??{},K=Object.keys(G).filter(e=>G[e]>0),ue=[...K].sort((e,t)=>(G[t]??0)-(G[e]??0))[0],q=(0,S.useMemo)(()=>I.filter(e=>e.dlq>0).sort((e,t)=>t.dlq-e.dlq),[I]),J=(0,S.useRef)(!1),Y=e.get(`queue`);(0,S.useEffect)(()=>{if(!(J.current||a)){if(Y){if(I.some(e=>e.name===Y)){J.current=!0,T(Y),M(0),D(`all`);return}if(I.length===0)return}q.length!==0&&(J.current=!0,T(q[0].name),M(0),D(`all`))}},[a,I,q,Y]);let X=(0,S.useMemo)(()=>{let e=H?.entries??[];E!==`all`&&(e=e.filter(e=>e.reason===E));let t=A.trim().toLowerCase();return t&&(e=e.filter(e=>e.job.id.toLowerCase().includes(t))),[...e].sort((e,t)=>O===`newest`?t.enteredAt-e.enteredAt:e.enteredAt-t.enteredAt)},[H,E,A,O]),Z=L===0&&!F,Q=E!==`all`||A.trim()!==``,$=(H?.entriesTotal??0)>w;return(0,C.jsxs)(`div`,{children:[(0,C.jsx)(te,{title:`Dead Letter Queue`,description:`Jobs that failed after exhausting all retries. Inspect and export entries without mutating flow topology.`,live:!!a&&!!H&&!H.statsError&&!z&&!F}),z&&H&&(0,C.jsx)(_,{message:`DLQ refresh failed — showing the last successful page.`,onRetry:V}),F&&(0,C.jsx)(_,{onRetry:le,message:`Could not discover queue DLQ totals — ${F.message}. Health status is unavailable.`}),H?.statsError&&(0,C.jsx)(_,{message:`DLQ statistics are unavailable — ${H.statsError}. The entry list may still be current.`,onRetry:V}),(0,C.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,C.jsxs)(l,{children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,C.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Total in DLQ`}),(0,C.jsx)(`span`,{className:t(`rounded-full px-2 py-0.5 text-[11px] font-medium`,F?`bg-amber-500/10 text-warning`:L==null?`bg-surface-2 text-muted`:Z?`bg-emerald-500/10 text-success`:`bg-red-500/10 text-danger`),children:F?`Unavailable`:L==null?`Loading`:Z?`Healthy`:`Attention`})]}),(0,C.jsx)(`div`,{className:t(`mt-2 text-3xl font-bold tnum`,L==null||F?`text-muted`:Z?`text-success`:`text-danger`),children:L==null?`—`:f(L)})]}),(0,C.jsxs)(l,{children:[(0,C.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Top Reason`}),(0,C.jsx)(`div`,{className:`mt-2 text-lg font-semibold text-fg`,children:F||H?.statsError?`Unavailable`:a?ue??`No failures`:`Select a queue`})]}),(0,C.jsxs)(l,{children:[(0,C.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Pending Retry`}),(0,C.jsx)(`div`,{className:`mt-2 text-3xl font-bold tnum text-fg`,children:H?.stats?f(H.stats.pendingRetry??0):`—`}),(0,C.jsx)(`div`,{className:`mt-1 text-xs text-faint`,children:a?`in this queue`:`awaiting retry`})]}),(0,C.jsxs)(l,{children:[(0,C.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Failure Types`}),(0,C.jsx)(`div`,{className:`mt-2 text-3xl font-bold tnum text-fg`,children:H?.stats?f(K.length):`—`}),(0,C.jsx)(`div`,{className:`mt-1 text-xs text-faint`,children:`distinct reasons`})]})]}),q.length>0&&(0,C.jsxs)(l,{className:`mb-6`,children:[(0,C.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,C.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:`DLQ by queue`}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsxs)(g,{size:`sm`,disabled:!0,title:`DLQ retry is unavailable in Bunqueue v2.8.55: its GET and retry POST have no atomic job-generation, state, or flow-topology precondition.`,children:[(0,C.jsx)(s,{className:`size-3.5`}),` Retry all (`,q.length,` queues)`]}),(0,C.jsxs)(g,{variant:`danger`,size:`sm`,disabled:!0,title:`Unavailable in Bunqueue v2.8.55: the server cannot inspect reverse flow dependencies or delete/discard topology atomically.`,children:[`Purge all (`,q.length,` queues)`]})]})]}),(0,C.jsx)(`div`,{className:`grid grid-cols-2 gap-3 md:grid-cols-4 xl:grid-cols-5`,children:q.map(e=>(0,C.jsxs)(`button`,{type:`button`,onClick:()=>W(e.name),className:t(`rounded-lg border p-3 text-left transition-colors`,a===e.name?`border-accent/50 bg-surface-2`:`border-line hover:border-line-strong`),children:[(0,C.jsx)(`div`,{className:`truncate font-mono text-xs text-muted`,children:e.name}),(0,C.jsx)(`div`,{className:`mt-1 text-xl font-bold tnum text-danger`,children:e.dlq})]},e.name))})]}),(0,C.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-3`,children:[(0,C.jsx)(`div`,{className:`w-48`,children:(0,C.jsxs)(b,{value:a,"aria-label":`Queue`,name:`dlq-queue`,autoComplete:`off`,onChange:e=>W(e.target.value),children:[(0,C.jsx)(`option`,{value:``,children:`Select a queue…`}),I.map(e=>(0,C.jsxs)(`option`,{value:e.name,children:[e.name,e.dlq?` (${e.dlq})`:``]},e.name))]})}),(0,C.jsx)(`div`,{className:`w-40`,children:(0,C.jsxs)(b,{value:E,onChange:e=>D(e.target.value),"aria-label":`Filter by reason`,name:`dlq-reason-filter`,autoComplete:`off`,children:[(0,C.jsx)(`option`,{value:`all`,children:`All Reasons`}),K.map(e=>(0,C.jsx)(`option`,{value:e,children:e},e))]})}),(0,C.jsx)(`div`,{className:`w-36`,children:(0,C.jsxs)(b,{value:O,onChange:e=>k(e.target.value),"aria-label":$?`Sort this page`:`Sort`,name:`dlq-sort`,autoComplete:`off`,children:[(0,C.jsxs)(`option`,{value:`newest`,children:[`Newest First`,$?` (this page)`:``]}),(0,C.jsxs)(`option`,{value:`oldest`,children:[`Oldest First`,$?` (this page)`:``]})]})}),(0,C.jsx)(`input`,{value:A,onChange:e=>oe(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,C.jsxs)(g,{size:`sm`,disabled:!0,title:x,children:[(0,C.jsx)(s,{className:`size-3.5`}),` Retry All`]}),(0,C.jsx)(g,{variant:`danger`,size:`sm`,disabled:!0,title:re,children:`Purge All`}),(0,C.jsx)(u,{"aria-label":`Export this page to CSV`,title:`Export this page to CSV`,disabled:!a,onClick:U,children:(0,C.jsx)(y,{className:`size-3.5`})})]}),(0,C.jsx)(`p`,{className:`mb-4 text-xs text-warning`,children:x}),z&&!H?(0,C.jsx)(v,{error:z,onRetry:V}):ce&&!P&&!a&&!F?(0,C.jsx)(d,{label:`Discovering queues…`}):B&&!H&&!z?(0,C.jsx)(d,{label:`Loading DLQ…`}):F&&!a?(0,C.jsx)(h,{icon:(0,C.jsx)(c,{}),title:`Could not discover queues`,hint:`${F.message}. Retry the queue discovery request above.`}):a?X.length===0?(0,C.jsx)(h,{icon:(0,C.jsx)(c,{}),title:Q?`No matches on this page`:`No dead letter entries`,hint:Q?`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,C.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,C.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,C.jsx)(`thead`,{children:(0,C.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,C.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Job ID`}),(0,C.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Reason`}),(0,C.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Error`}),(0,C.jsx)(`th`,{scope:`col`,className:`px-5 py-3 text-right font-medium`,children:`Entered`}),(0,C.jsx)(`th`,{scope:`col`,className:`w-16 px-5 py-3`})]})}),(0,C.jsx)(`tbody`,{children:X.map(e=>(0,C.jsxs)(`tr`,{className:`border-b border-line last:border-0 align-top hover:bg-surface-2/40`,children:[(0,C.jsx)(`td`,{className:`px-5 py-3`,children:(0,C.jsx)(i,{to:`/job?id=${encodeURIComponent(e.job.id)}`,className:`font-mono text-xs text-accent hover:underline`,children:e.job.id})}),(0,C.jsx)(`td`,{className:`px-5 py-3`,children:(0,C.jsx)(`span`,{className:`rounded-md bg-red-500/10 px-2 py-0.5 text-xs text-danger`,children:e.reason})}),(0,C.jsx)(`td`,{className:`max-w-md px-5 py-3 text-xs text-danger/80`,children:e.error?(0,C.jsx)(`button`,{type:`button`,title:e.error,"aria-expanded":N.has(`${e.job.id}-${e.enteredAt}`),onClick:()=>se(t=>{let n=new Set(t),r=`${e.job.id}-${e.enteredAt}`;return n.has(r)?n.delete(r):n.add(r),n}),className:t(`block w-full break-words text-left`,!N.has(`${e.job.id}-${e.enteredAt}`)&&`line-clamp-2`),children:e.error}):`—`}),(0,C.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:m(e.enteredAt)}),(0,C.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,C.jsx)(u,{"aria-label":`Retry unavailable`,disabled:!0,title:x,children:(0,C.jsx)(s,{className:`size-3.5`})})})]},`${e.job.id}-${e.enteredAt}`))})]})}):(0,C.jsx)(h,{icon:(0,C.jsx)(c,{}),title:`Select a queue`,hint:`Choose a queue from the dropdown to view its dead letter queue entries.`}),a&&H&&(0,C.jsx)(ne,{page:j,pageSize:w,total:H.entriesTotal,onPageChange:M,label:`entries`})]})}export{T as DlqPro};