bunqueue-dashboard 0.0.31 → 0.0.33

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 (107) hide show
  1. package/README.md +44 -15
  2. package/agent/db.ts +682 -68
  3. package/agent/dbQueryWorker.ts +41 -10
  4. package/agent/index.ts +4 -1
  5. package/agent/manager.ts +267 -41
  6. package/agent/server.ts +131 -36
  7. package/dist/.vite/manifest.json +215 -159
  8. package/dist/assets/AddJob-ytpBLTCJ.js +3 -0
  9. package/dist/assets/Alerts-C39RrGbQ.js +1 -0
  10. package/dist/assets/{AreaChart-2gM0YoZT.js → AreaChart-REK4ZsTC.js} +1 -1
  11. package/dist/assets/Benchmark-CM60tHbf.js +1 -0
  12. package/dist/assets/BulkAddJobs-BjL-xcQy.js +5 -0
  13. package/dist/assets/CopilotPanel-BGK1rw-V.js +44 -0
  14. package/dist/assets/Cron-s1e-jgOo.js +1 -0
  15. package/dist/assets/CronManager-BostU7BX.js +1 -0
  16. package/dist/assets/Database-ZluStWMz.js +3 -0
  17. package/dist/assets/Diagnostics-C0N5z5j-.js +1 -0
  18. package/dist/assets/Dlq-CtcLzs-b.js +1 -0
  19. package/dist/assets/DlqControl-B_Z8KKn5.js +1 -0
  20. package/dist/assets/DlqPro-B68en6AG.js +1 -0
  21. package/dist/assets/Flows-CD_bkCBM.js +1 -0
  22. package/dist/assets/JobInspector-DwRtyMz0.js +2 -0
  23. package/dist/assets/Jobs-BUtcBKKk.js +1 -0
  24. package/dist/assets/JobsPro-BK_xd4ji.js +1 -0
  25. package/dist/assets/Logs-CmVODYCI.js +1 -0
  26. package/dist/assets/LogsPro-CJ-Il3LP.js +1 -0
  27. package/dist/assets/McpServer-dMjyJKgT.js +22 -0
  28. package/dist/assets/Metrics-Dsbeplz-.js +1 -0
  29. package/dist/assets/MetricsPro-BqxurxrJ.js +1 -0
  30. package/dist/assets/Overview-DH9C2dsf.js +1 -0
  31. package/dist/assets/{Pagination-D4ki-pGz.js → Pagination-DpxiBnt8.js} +1 -1
  32. package/dist/assets/QueueActions-D_QGBaVm.js +1 -0
  33. package/dist/assets/QueueControl-V0DJ6qk6.js +1 -0
  34. package/dist/assets/QueueDetail-BgKAMJqf.js +1 -0
  35. package/dist/assets/QueueDetailPro-BkHYzGiq.js +1 -0
  36. package/dist/assets/Queues-2_v7DcNi.js +1 -0
  37. package/dist/assets/QueuesOverview-BySSkmB4.js +1 -0
  38. package/dist/assets/S3Backup-CPADzKQE.js +1 -0
  39. package/dist/assets/S3BackupPro-CSrQYIDL.js +2 -0
  40. package/dist/assets/ServerControl-C0tI1VDx.js +3 -0
  41. package/dist/assets/Settings-CSzoM5up.js +1 -0
  42. package/dist/assets/Usage-B4B7tmrc.js +1 -0
  43. package/dist/assets/UsagePro-CCBpgSDy.js +1 -0
  44. package/dist/assets/Webhooks-aJz-GisQ.js +1 -0
  45. package/dist/assets/Workers-Bg8xKjkg.js +1 -0
  46. package/dist/assets/WorkersPro-BOOCrXf8.js +1 -0
  47. package/dist/assets/connectionStore-Cd9-3Fw0.js +1 -0
  48. package/dist/assets/{exportFile-tdUeW5m5.js → exportFile-C7xhE8Yh.js} +1 -1
  49. package/dist/assets/flowMutationSafety-DVD1IMr-.js +1 -0
  50. package/dist/assets/form-DsUq0w8s.js +1 -0
  51. package/dist/assets/index-BWoUj86M.css +1 -0
  52. package/dist/assets/index-Bn2R06qm.js +8 -0
  53. package/dist/assets/{install-DhTYJCUC.js → install-CUS8Kijb.js} +2 -2
  54. package/dist/assets/jobActions-LQD4KfCc.js +1 -0
  55. package/dist/assets/promisePool-BVfQ9n9Q.js +1 -0
  56. package/dist/assets/{react-vendor-BcouBxpZ.js → react-vendor-Bjui4wS4.js} +1 -1
  57. package/dist/assets/upstreamPaths-nG8N1XAz.js +1 -0
  58. package/dist/assets/useServerActionGuard-CItj3hvh.js +1 -0
  59. package/dist/assets/useThroughputSeries-tb26_lkb.js +1 -0
  60. package/dist/index.html +5 -4
  61. package/package.json +11 -3
  62. package/scripts/embedded.gen.ts +132 -126
  63. package/scripts/serve.ts +501 -108
  64. package/dist/assets/AddJob-CAhdg38n.js +0 -3
  65. package/dist/assets/Alerts-70bxf-PT.js +0 -1
  66. package/dist/assets/Benchmark-CFZ3WCvj.js +0 -1
  67. package/dist/assets/BulkAddJobs-BzgzpGg_.js +0 -5
  68. package/dist/assets/CopilotPanel-DZUGIf1q.js +0 -44
  69. package/dist/assets/Cron-ltjSoTjj.js +0 -1
  70. package/dist/assets/CronManager-BcFALDeT.js +0 -1
  71. package/dist/assets/Database-CV2yt5O2.js +0 -3
  72. package/dist/assets/Diagnostics-D-EK4GEi.js +0 -1
  73. package/dist/assets/Dlq-fZAKwQoC.js +0 -1
  74. package/dist/assets/DlqControl-eTrrQCrn.js +0 -1
  75. package/dist/assets/DlqPro-CF79339e.js +0 -1
  76. package/dist/assets/Flows-Ba8G7mcC.js +0 -1
  77. package/dist/assets/JobInspector--d_8ca9p.js +0 -2
  78. package/dist/assets/Jobs-DEqAc1A5.js +0 -1
  79. package/dist/assets/JobsPro-BcaokZIf.js +0 -1
  80. package/dist/assets/Logs-DBTukPIX.js +0 -1
  81. package/dist/assets/LogsPro-Wl_e6hZM.js +0 -1
  82. package/dist/assets/McpServer-CnWJsKw7.js +0 -22
  83. package/dist/assets/Metrics-DzeIhNL-.js +0 -1
  84. package/dist/assets/MetricsPro-O9eVJSH0.js +0 -1
  85. package/dist/assets/Overview-Bnu7rWqt.js +0 -1
  86. package/dist/assets/QueueActions-DHoSkWRz.js +0 -1
  87. package/dist/assets/QueueControl-DKqEXnkM.js +0 -1
  88. package/dist/assets/QueueDetail-DLRow04B.js +0 -1
  89. package/dist/assets/QueueDetailPro-BYmOVd4T.js +0 -1
  90. package/dist/assets/Queues-CoyjRFN7.js +0 -1
  91. package/dist/assets/QueuesOverview-BeWdJpKi.js +0 -1
  92. package/dist/assets/S3Backup-BaLFgl9d.js +0 -1
  93. package/dist/assets/S3BackupPro-DJB4oWgz.js +0 -1
  94. package/dist/assets/ServerControl-_0lVB33E.js +0 -3
  95. package/dist/assets/Settings-zKFJTtnq.js +0 -1
  96. package/dist/assets/Usage-CKGkvl0j.js +0 -1
  97. package/dist/assets/UsagePro-B-TJ6fp4.js +0 -1
  98. package/dist/assets/Webhooks-C3zmvY-_.js +0 -1
  99. package/dist/assets/Workers-jKhhXl3W.js +0 -1
  100. package/dist/assets/WorkersPro-mvY5VX8I.js +0 -1
  101. package/dist/assets/connectionStore-Ci04lJmR.js +0 -1
  102. package/dist/assets/form-DGinTEEb.js +0 -1
  103. package/dist/assets/index-BOcegTHa.js +0 -8
  104. package/dist/assets/index-DWV3tgrk.css +0 -1
  105. package/dist/assets/jobActions-CuOdMglt.js +0 -1
  106. package/dist/assets/promisePool-Daxkc1OB.js +0 -1
  107. package/dist/assets/useThroughputSeries-Chp5OLx3.js +0 -1
@@ -0,0 +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(`
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
+ `)||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};
@@ -0,0 +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};
@@ -0,0 +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};
@@ -0,0 +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};
@@ -0,0 +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};
@@ -0,0 +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{i as o,o as s}from"./connectionStore-Cd9-3Fw0.js";import{i as c}from"./upstreamPaths-nG8N1XAz.js";import{D as l,S as u,b as d,dt as f,h as p,lt as m,rt as h,x as g,y as _}from"./index-Bn2R06qm.js";var v=e(r(),1),y={nodeWidth:168,nodeHeight:60,colGap:72,rowGap:20,padding:24};function b(e,t){let n=new Map,r=new Map,i=new Map;for(let t of e)n.set(t,0),r.set(t,0),i.set(t,[]);for(let e of t)!n.has(e.from)||!n.has(e.to)||e.from===e.to||(i.get(e.from)?.push(e.to),r.set(e.to,(r.get(e.to)??0)+1));let a=e.filter(e=>(r.get(e)??0)===0),o=new Set;for(;o.size<n.size;){for(;a.length;){let e=a.shift();if(!o.has(e)){o.add(e);for(let t of i.get(e)??[]){if(o.has(t))continue;n.set(t,Math.max(n.get(t)??0,(n.get(e)??0)+1));let i=(r.get(t)??0)-1;r.set(t,i),i===0&&a.push(t)}}}let t=e.find(e=>!o.has(e));if(t===void 0)break;a.push(t)}return n}function x(e,t,n={}){let r={...y,...n},i=b(e,t),a=new Map,o=0;for(let t of e){let e=i.get(t)??0;o=Math.max(o,e);let n=a.get(e);n?n.push(t):a.set(e,[t])}let s=0;for(let e of a.values())s=Math.max(s,e.length);let c=s*r.nodeHeight+Math.max(0,s-1)*r.rowGap,l=[];for(let e=0;e<=o;e++){let t=a.get(e)??[],n=t.length*r.nodeHeight+Math.max(0,t.length-1)*r.rowGap,i=r.padding+(c-n)/2;t.forEach((t,n)=>{l.push({id:t,layer:e,x:r.padding+e*(r.nodeWidth+r.colGap),y:i+n*(r.nodeHeight+r.rowGap)})})}return{nodes:l,width:r.padding*2+(o+1)*r.nodeWidth+o*r.colGap,height:r.padding*2+c}}var S=a(),C=168,w=60,ee={nodeWidth:C,nodeHeight:w},T=500,E=100,D=100,O=`flow-order-9a3f`,k={completed:`border-success/50 bg-success/10 text-success`,failed:`border-danger/50 bg-danger/10 text-danger`,active:`border-blue-400/60 bg-blue-400/10 text-blue-400`,delayed:`border-accent/50 bg-accent/10 text-accent`,waiting:`border-warning/50 bg-warning/10 text-warning`,prioritized:`border-warning/50 bg-warning/10 text-warning`,"waiting-children":`border-cyan-400/60 bg-cyan-400/10 text-cyan-400`},te=e=>e&&k[e]||`border-line bg-surface-2 text-muted`,A=e=>e.length>12?`${e.slice(0,6)}…${e.slice(-4)}`:e,j=`bq-dash-recent-flows`,M=8;function N(e){return`${j}:${encodeURIComponent(e.trim()||`/api`)}`}function P(e,t){if(!t)return[];try{let t=JSON.parse(localStorage.getItem(N(e))??`[]`);return Array.isArray(t)?t.filter(e=>typeof e?.root==`string`&&e.root.length>0&&e.root.length<=1024&&Number.isSafeInteger(e?.nodes)&&e.nodes>1&&e.nodes<=T&&Number.isFinite(e?.at)&&e.at>=0).slice(0,M):[]}catch{return[]}}function ne(e,t,n,r){let i=[n,...t.filter(e=>e.root!==n.root)].slice(0,M);if(!r)return i;try{localStorage.setItem(N(e),JSON.stringify(i))}catch{}return i}var F=class extends Error{constructor(e,t){super(e,t),this.name=`FlowSnapshotError`}};function I(e,t,n){if(!Array.isArray(e)||e.some(e=>typeof e!=`string`||c(e)!==null))throw new F(`Job ${n} returned an invalid ${t} list`);return e}function L(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw new F(`GET /jobs/${t} returned an invalid response`);let n=e;if(n.ok!==!0)throw new F(`GET /jobs/${t} returned an invalid success envelope`);let r=n.job;if(typeof r!=`object`||!r||Array.isArray(r))throw new F(`GET /jobs/${t} returned no job snapshot`);let i=r;if(i.id!==t)throw new F(`GET /jobs/${t} returned the wrong job id (${String(i.id)})`);if(typeof i.queue!=`string`||i.queue.length===0)throw new F(`Job ${t} returned an invalid queue`);if(typeof i.state!=`string`||i.state.length===0)throw new F(`Job ${t} returned an invalid state`);if(!Object.hasOwn(i,`parentId`)||i.parentId!==null&&(typeof i.parentId!=`string`||c(i.parentId)!==null))throw new F(`Job ${t} returned an invalid parentId`);return{...r,parentId:i.parentId,childrenIds:I(i.childrenIds,`childrenIds`,t),dependsOn:I(i.dependsOn,`dependsOn`,t)}}async function R(e,t,n){n?.throwIfAborted();let r=await f(e,t,n);return n?.throwIfAborted(),L(r,t)}function z(e){let t=c(e);return t?`Job ID: ${t}`:null}async function re(e,t={}){let n=z(e);if(n)throw new F(n);let r=t.target??m(),{signal:i}=t,a=e,o=new Set([e]),s=[];for(let e=0;;e++){i?.throwIfAborted();let t;try{t=await R(r,a,i)}catch(t){if(i?.throwIfAborted(),e===0)throw t;if(t instanceof h&&t.status===404){let e=s.at(-1);if(!e)throw t;return{id:e.id,job:e,hops:Math.max(0,s.length-1),path:s,missingParent:a}}throw new F(`Could not resolve the flow root because parent ${a} could not be loaded: ${t instanceof Error?t.message:String(t)}`,{cause:t})}s.push(t);let n=t.parentId;if(!n)return{id:a,job:t,hops:e,path:s};if(o.has(n))throw new F(`Flow parent cycle detected at job ${n}`);if(e>=D)throw new F(`Flow parent chain exceeds the v2.8.55 limit of ${D} levels`);o.add(n),a=n}}function B(e,t){let n=new Set(e),r=new Map(e.map(e=>[e,[]]));for(let e of t)n.has(e.from)&&n.has(e.to)&&r.get(e.from)?.push(e.to);let i=new Map,a=[],o=e=>{i.set(e,1),a.push(e);for(let t of r.get(e)??[]){if(i.get(t)===1){let e=a.lastIndexOf(t);return[...a.slice(Math.max(0,e)),t]}if(i.get(t)!==2){let e=o(t);if(e)return e}}return a.pop(),i.set(e,2),null};for(let t of e)if(!i.has(t)){let e=o(t);if(e)return e}return null}var V=[`failParentOnFailure`,`removeDependencyOnFailure`,`continueParentOnFailure`,`ignoreDependencyOnFailure`];function H(e){return V.filter(t=>e[t]===!0)}function U(e,t){if(e?.parentId!==t)return null;let n=H(e);return n.length===1?n[0]===`continueParentOnFailure`?{scope:`parent`,policy:`continueParentOnFailure`}:n[0]===`removeDependencyOnFailure`?{scope:`child`,policy:`removeDependencyOnFailure`}:n[0]===`ignoreDependencyOnFailure`?{scope:`child`,policy:`ignoreDependencyOnFailure`}:null:null}async function ie(e,t,n={}){let r=z(e);if(r)throw new F(r);let i=n.target??m(),{signal:a}=n,o=new Map,s=[],c=[],l=new Set,u=new Set,d=new Map,f=new Set,p=new Set,h=new Set(n.limitations??[]),g=[{id:e,depth:0}],_=new Set([e]),v=new Map;t&&v.set(e,L({ok:!0,job:t},e));let y=[...n.seedPath??[]].reverse(),b=!1;if(y.length>0&&y[0]?.id!==e)throw new F(`Resolved seed path does not start at the requested flow root`);for(let[e,t]of y.entries()){let n=L({ok:!0,job:t},t.id);if(v.set(n.id,n),e!==0){if(e>E||_.size>=T){b=!0;continue}_.has(n.id)||(_.add(n.id),g.push({id:n.id,depth:e}))}}let x=new Set,S=b;for(;g.length;){a?.throwIfAborted();let{id:t,depth:n}=g.shift();if(x.has(t))continue;x.add(t);let r=null;try{r=v.get(t)??await R(i,t,a)}catch(n){if(a?.throwIfAborted(),t===e)throw n;d.set(t,n instanceof Error?n.message:String(n))}if(o.set(t,r??{id:t,state:`unknown`}),!r)continue;if(n>=E){(r.childrenIds?.length??0)+(r.dependsOn?.length??0)>0&&(S=!0);continue}let p=e=>_.has(e)?!0:_.size>=T?(S=!0,!1):(_.add(e),g.push({id:e,depth:n+1}),!0),m=(e,t,n,r)=>{if(!p(r))return;let i=`${e}->${t}:${n}`;l.has(i)||(l.add(i),s.push({from:e,to:t,kind:n}))},h=r.childrenIds??[],y=r.dependsOn??[],b=new Set(h),C=new Set(y);b.size!==h.length&&f.add(`Job ${t} lists a child more than once`),C.size!==y.length&&f.add(`Job ${t} lists a dependency more than once`);for(let e of h)m(t,e,`child`,e);for(let e of y)if(p(e)){let n=`${e}->${t}`;u.has(n)||(u.add(n),c.push({from:e,to:t,kind:`depends`})),b.has(e)||m(e,t,`depends`,e)}}for(let[e,t]of o)!d.has(e)&&H(t).length>1&&f.add(`Job ${e} enables mutually exclusive failure policies`);for(let e of s){if(e.kind!==`child`||d.has(e.to))continue;let t=o.get(e.to);t&&t.parentId!==e.from&&f.add(`Child ${e.to} points to parent ${String(t.parentId??`none`)}, not ${e.from}`)}for(let[e,t]of o){if(d.has(e))continue;let n=t.childrenIds??[];if(n.some(e=>!o.has(e)||d.has(e)))continue;let r=n.map(t=>({childId:t,release:U(o.get(t),e)})).find(({release:e})=>e?.scope===`parent`);for(let i of n){if(t.dependsOn?.includes(i))continue;if(r?.release?.scope===`parent`){p.add(`Parent ${e} is missing dependency ${i}; ${r.release.policy} on child ${r.childId} may have released all parent dependencies, but the HTTP snapshot cannot prove whether the policy fired`);continue}let n=U(o.get(i),e);if(n?.scope===`child`){p.add(`Parent ${e} is missing dependency ${i}; ${n.policy} may have released it, but the HTTP snapshot cannot prove whether the policy fired`);continue}f.add(`Parent ${e} lists child ${i} without the matching dependency`)}}for(let[e,t]of o){if(d.has(e)||!t.parentId)continue;let n=o.get(t.parentId);!n||d.has(t.parentId)||n.childrenIds?.includes(e)||f.add(`Parent ${t.parentId} does not list child ${e}`)}let C=B([...o.keys()],c);return{jobs:o,edges:s,truncated:S,failed:d.size,failures:d,issues:[...f],policyNotes:[...p],cycle:C,limitations:[...h]}}function W(e,t,n,r){let i=(e+n)/2;return`M${e},${t} C${i},${t} ${i},${r} ${n},${r}`}function ae(e,t){return e.x<=t.x?W(e.x+C,e.y+w/2,t.x,t.y+w/2):W(e.x,e.y+w/2,t.x+C,t.y+w/2)}function oe(e){return e instanceof h&&e.status===0||e.name===`TypeError`||e.name===`AbortError`||e.name===`TimeoutError`}function G(){let{token:e}=s.getState();return JSON.stringify([o(),e])}function K(){let[e,r]=n(),a=e.get(`root`)??(l()?O:``),c=s(e=>e.baseUrl),f=s(e=>e.token),h=o(),y=f.length===0,[b,D]=(0,v.useState)(a),[k,j]=(0,v.useState)(null),[M,N]=(0,v.useState)(null),[I,L]=(0,v.useState)(!1),[R,B]=(0,v.useState)(null),[V,H]=(0,v.useState)(()=>P(h,y)),U=(0,v.useRef)(0),W=(0,v.useRef)(null),K=(0,v.useRef)(!1),J=(0,v.useRef)(G()),Y=(0,v.useCallback)(async e=>{let t=s.getState();if(t.baseUrl!==c||t.token!==f)return;W.current?.abort(),W.current=null;let n=++U.current,r=e.trim();if(j(null),N(null),B(null),!r){L(!1);return}let i=z(r);if(i){B(new F(i)),L(!1);return}let a=m(),o=G(),l=s.getState().token.length===0,u=new AbortController;W.current=u;let d=()=>K.current&&n===U.current&&!u.signal.aborted&&o===G();L(!0);try{let e={target:a,signal:u.signal},t=await re(r,e),n=t.missingParent?[`Ancestor ${t.missingParent} is no longer available. Bunqueue may legitimately remove a completed flow root, so this graph starts at the oldest surviving node.`]:[],i=await ie(t.id,t.job,{...e,seedPath:t.path,limitations:n});if(!d())return;j(i),N(t.id),i.jobs.size>1&&H(e=>ne(a.baseUrl,e,{root:t.id,nodes:i.jobs.size,at:Date.now()},l))}catch(e){if(!d())return;B(e instanceof Error?e:Error(`Failed to load flow`))}finally{W.current===u&&(W.current=null),d()&&L(!1)}},[c,f]);(0,v.useEffect)(()=>{K.current=!0,J.current=G();let e=s.subscribe(()=>{let e=G();e!==J.current&&(J.current=e,U.current+=1,W.current?.abort(),W.current=null,K.current&&(j(null),N(null),B(null),L(!1)))});return()=>{K.current=!1,e(),U.current+=1,W.current?.abort(),W.current=null}},[]),(0,v.useEffect)(()=>{H(f?[]:P(h,!0))},[h,f]),(0,v.useEffect)(()=>{D(a),Y(a)},[a,Y]);let se=e=>{e.preventDefault();let t=b.trim();t&&(t===a?Y(t):r({root:t},{replace:!0}))},X=(0,v.useMemo)(()=>k?x([...k.jobs.keys()],k.edges,ee):null,[k]),Z=(0,v.useMemo)(()=>new Map(X?.nodes.map(e=>[e.id,e])??[]),[X]),Q=M?k?.jobs.get(M):void 0,$=M?k?.failures.get(M):void 0;return(0,S.jsxs)(`div`,{children:[(0,S.jsx)(p,{title:`Flows`,description:`Visualize a job flow: parent, children, and dependency edges as an interactive graph.`,actions:k&&(0,S.jsx)(`button`,{type:`button`,disabled:I,onClick:()=>void Y(a),className:`rounded-lg border border-line px-3 py-1.5 text-sm text-muted hover:bg-surface-2 hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 disabled:opacity-50`,children:`Refresh`})}),(0,S.jsxs)(u,{className:`mb-6`,children:[(0,S.jsxs)(`form`,{onSubmit:se,className:`flex flex-wrap items-center gap-3`,children:[(0,S.jsx)(`input`,{name:`flow-job-id`,autoComplete:`off`,spellCheck:!1,maxLength:1024,value:b,onChange:e=>D(e.target.value),placeholder:`Flow job ID`,"aria-label":`Root job ID`,"aria-describedby":`flow-input-help`,className:`min-w-0 flex-1 rounded-lg border border-line bg-surface-2 px-3 py-2 font-mono text-sm text-fg outline-none placeholder:text-faint focus-visible:ring-2 focus-visible:ring-accent/50`}),(0,S.jsx)(`button`,{type:`submit`,disabled:I||!b.trim(),className:`rounded-lg bg-accent px-4 py-2 text-sm font-medium text-accent-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 disabled:opacity-50`,children:I?`Loading…`:`Load Flow`})]}),(0,S.jsxs)(`p`,{id:`flow-input-help`,className:`mt-2 text-xs text-faint`,children:[`Structural parent/child flows can start from any surviving node. Dependency-only chains can only be followed upstream with the v2.8.55 HTTP API, so use the most downstream job to see the full chain. Up to `,T,` nodes are rendered.`]})]}),(0,S.jsxs)(`div`,{"aria-live":`polite`,children:[R&&(oe(R)?(0,S.jsx)(g,{message:`Could not load the flow — ${R.message}`,onRetry:()=>void Y(a)}):(0,S.jsx)(_,{error:R,onRetry:()=>void Y(a)})),I&&(0,S.jsx)(d,{label:`Loading flow…`})]}),!I&&!k&&!R&&(0,S.jsx)(u,{children:(0,S.jsxs)(`div`,{className:`py-16 text-center`,children:[(0,S.jsx)(`p`,{className:`text-sm text-muted`,children:`No flow loaded.`}),(0,S.jsx)(`p`,{className:`mt-1 text-xs text-faint`,children:`Enter a job ID above, or open a job that is part of a flow and choose “View flow”.`}),V.length>0&&(0,S.jsxs)(`div`,{className:`mt-6`,children:[(0,S.jsx)(`p`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Recently viewed`}),(0,S.jsx)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:V.map(e=>(0,S.jsxs)(`button`,{type:`button`,title:e.root,onClick:()=>{D(e.root),r({root:e.root},{replace:!0})},className:`min-h-10 rounded-lg border border-line bg-surface-2 px-3 py-1.5 font-mono text-xs 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:[(0,S.jsx)(`span`,{translate:`no`,children:A(e.root)}),(0,S.jsxs)(`span`,{className:`ml-2 text-faint`,children:[e.nodes,` nodes`]})]},e.root))})]})]})}),k&&X&&(0,S.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[1fr_260px]`,children:[(0,S.jsxs)(u,{padded:!1,className:`max-h-[70vh] overflow-auto overscroll-contain p-4`,children:[(0,S.jsx)(`h2`,{className:`sr-only`,children:`Flow Graph`}),(0,S.jsx)(`ul`,{className:`sr-only`,"aria-label":`Flow relationships`,children:k.edges.map(e=>(0,S.jsx)(`li`,{children:e.kind===`child`?`${e.from} has child ${e.to}`:`${e.to} depends on ${e.from}`},`accessible-${e.from}-${e.to}-${e.kind}`))}),(0,S.jsxs)(`div`,{className:`relative`,style:{width:X.width,height:X.height},children:[(0,S.jsxs)(`svg`,{"aria-hidden":`true`,className:`absolute inset-0 text-line`,width:X.width,height:X.height,children:[(0,S.jsxs)(`defs`,{children:[(0,S.jsx)(`marker`,{id:`flow-arrow-child`,markerWidth:`6`,markerHeight:`6`,refX:`5`,refY:`3`,orient:`auto`,children:(0,S.jsx)(`path`,{d:`M0,0 L6,3 L0,6 Z`,fill:`currentColor`})}),(0,S.jsx)(`marker`,{id:`flow-arrow-dependency`,markerWidth:`6`,markerHeight:`6`,refX:`5`,refY:`3`,orient:`auto`,children:(0,S.jsx)(`path`,{d:`M0,0 L6,3 L0,6 Z`,fill:`currentColor`})})]}),k.edges.map(e=>{let t=Z.get(e.from),n=Z.get(e.to);return!t||!n?null:(0,S.jsx)(`path`,{d:ae(t,n),fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeDasharray:e.kind===`depends`?`4 4`:void 0,markerEnd:`url(#flow-arrow-${e.kind===`depends`?`dependency`:`child`})`,opacity:.5},`${e.from}-${e.to}-${e.kind}`)})]}),X.nodes.map(e=>{let n=k.jobs.get(e.id),r=k.failures.has(e.id)?`unavailable`:n?.state??`unknown`;return(0,S.jsxs)(`button`,{type:`button`,"data-flow-node":e.id,onClick:()=>N(e.id),"aria-pressed":M===e.id,"aria-label":`${e.id}, queue ${n?.queue??`unknown`}, state ${r}`,title:e.id,style:{left:e.x,top:e.y,width:C,height:w},className:t(`absolute flex flex-col justify-center gap-0.5 rounded-lg border px-3 text-left transition-shadow focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70`,te(n?.state),M===e.id&&`ring-2 ring-accent`),children:[(0,S.jsx)(`span`,{translate:`no`,className:`truncate font-mono text-xs text-fg`,children:A(e.id)}),(0,S.jsxs)(`span`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[(0,S.jsx)(`span`,{className:`truncate`,children:n?.queue??`—`}),(0,S.jsx)(`span`,{className:`font-medium`,children:r})]})]},e.id)})]})]}),(0,S.jsx)(`aside`,{"aria-label":`Selected job details`,"aria-live":`polite`,children:(0,S.jsxs)(u,{children:[Q?(0,S.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`text-xs text-faint`,children:`Job`}),(0,S.jsx)(`div`,{translate:`no`,className:`break-all font-mono text-xs text-fg`,children:Q.id})]}),$&&(0,S.jsxs)(`p`,{role:`alert`,className:`break-words text-xs text-warning`,children:[`Snapshot unavailable: `,$]}),(0,S.jsx)(q,{label:`Queue`,value:Q.queue??`—`}),(0,S.jsx)(q,{label:`State`,value:$?`unavailable`:Q.state??`unknown`}),(0,S.jsx)(q,{label:`Priority`,value:Q.priority===void 0?`—`:String(Q.priority)}),(0,S.jsx)(q,{label:`Parent`,value:Q.parentId??`—`}),(0,S.jsx)(q,{label:`Children`,value:$?`—`:String(Q.childrenIds?.length??0)}),(0,S.jsx)(q,{label:`Depends On`,value:$?`—`:String(Q.dependsOn?.length??0)}),(0,S.jsx)(i,{to:`/job?id=${encodeURIComponent(Q.id)}`,className:`inline-block rounded-lg border border-line px-3 py-1.5 text-xs text-muted hover:bg-surface-2 hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,children:`Open in Job Inspector`})]}):(0,S.jsx)(`p`,{className:`text-sm text-muted`,children:`Select a node to inspect it.`}),(0,S.jsxs)(`div`,{className:`mt-4 border-t border-line pt-3 text-xs text-faint`,"aria-live":`polite`,children:[k.truncated&&(0,S.jsxs)(`div`,{className:`mb-1 text-warning`,children:[`Graph truncated at `,T,` nodes / depth `,E,` — not the whole flow.`]}),k.limitations.length>0&&(0,S.jsxs)(`details`,{className:`mb-1 text-warning`,children:[(0,S.jsxs)(`summary`,{className:`cursor-pointer`,children:[k.limitations.length,` known snapshot limitation`,k.limitations.length===1?``:`s`]}),(0,S.jsx)(`ul`,{className:`mt-1 space-y-1 pl-3`,children:k.limitations.map(e=>(0,S.jsx)(`li`,{className:`break-words`,children:e},e))})]}),k.failed>0&&(0,S.jsxs)(`details`,{className:`mb-1 text-warning`,children:[(0,S.jsxs)(`summary`,{className:`cursor-pointer`,children:[k.failed,` node`,k.failed===1?``:`s`,` couldn't be loaded — this is not the whole flow`]}),(0,S.jsx)(`ul`,{className:`mt-1 space-y-1 pl-3`,children:[...k.failures].map(([e,t])=>(0,S.jsxs)(`li`,{className:`break-words`,children:[(0,S.jsx)(`span`,{translate:`no`,className:`font-mono`,children:e}),`: `,t]},e))})]}),k.cycle&&(0,S.jsxs)(`div`,{className:`mb-1 break-words text-danger`,children:[`Dependency cycle detected:`,` `,(0,S.jsx)(`span`,{translate:`no`,className:`font-mono`,children:k.cycle.join(` → `)}),`. This is not a valid atomic v2.8.55 flow.`]}),k.issues.length>0&&(0,S.jsxs)(`details`,{className:`mb-1 text-warning`,children:[(0,S.jsxs)(`summary`,{className:`cursor-pointer`,children:[k.issues.length,` `,k.issues.length===1?`possible snapshot inconsistency`:`possible snapshot inconsistencies`,` `,`detected (the flow may have changed during these requests)`]}),(0,S.jsx)(`ul`,{className:`mt-1 space-y-1 pl-3`,children:k.issues.map(e=>(0,S.jsx)(`li`,{className:`break-words`,children:e},e))})]}),k.policyNotes.length>0&&(0,S.jsxs)(`details`,{className:`mb-1 text-muted`,children:[(0,S.jsxs)(`summary`,{className:`cursor-pointer`,children:[k.policyNotes.length,` failure-policy`,` `,k.policyNotes.length===1?`ambiguity`:`ambiguities`]}),(0,S.jsx)(`p`,{className:`mt-1`,children:`These are informational: the HTTP snapshot cannot prove whether a configured policy fired.`}),(0,S.jsx)(`ul`,{className:`mt-1 space-y-1 pl-3`,children:k.policyNotes.map(e=>(0,S.jsx)(`li`,{className:`break-words`,children:e},e))})]}),(0,S.jsxs)(`div`,{className:`mb-1`,children:[k.jobs.size,` node`,k.jobs.size===1?``:`s`,` · `,k.edges.length,` `,`edge`,k.edges.length===1?``:`s`]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,S.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,S.jsx)(`span`,{className:`inline-block h-px w-4 bg-current`}),` child`]}),(0,S.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,S.jsx)(`span`,{className:`inline-block h-px w-4 border-t border-dashed border-current`}),` `,`depends`]})]})]})]})})]})]})}function q({label:e,value:t}){return(0,S.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-2`,children:[(0,S.jsx)(`span`,{className:`shrink-0 text-xs text-faint`,children:e}),(0,S.jsx)(`span`,{className:`min-w-0 break-all text-right text-fg`,children:t})]})}export{K as Flows};
@@ -0,0 +1,2 @@
1
+ import{r as e}from"./cn-CMFYpumL.js";import{f as t,g as n,l as r,r as i,t as a}from"./react-vendor-Bjui4wS4.js";import{i as o,o as s}from"./connectionStore-Cd9-3Fw0.js";import{a as c,n as l}from"./upstreamPaths-nG8N1XAz.js";import{C as u,J as d,O as f,S as p,T as m,a as h,b as ee,g,h as te,o as _,rt as v,st as y,v as ne,w as b,z as x}from"./index-Bn2R06qm.js";import{a as re,n as ie,o as S}from"./form-DsUq0w8s.js";import{r as C}from"./flowMutationSafety-DVD1IMr-.js";import{n as w}from"./exportFile-C7xhE8Yh.js";import{t as T}from"./jobActions-LQD4KfCc.js";var E=e(n(),1);function D(e){let t={};return typeof e.priority==`number`&&(t.priority=e.priority),typeof e.maxAttempts==`number`&&(t.maxAttempts=e.maxAttempts),typeof e.backoff==`number`&&(t.backoff=e.backoff),e.backoffConfig&&typeof e.backoffConfig.delay==`number`&&(t.backoffConfig={type:e.backoffConfig.type,delay:e.backoffConfig.delay},typeof t.backoff!=`number`&&(t.backoff=e.backoffConfig.delay)),typeof e.timeout==`number`&&(t.timeout=e.timeout),typeof e.removeOnComplete==`boolean`&&(t.removeOnComplete=e.removeOnComplete),typeof e.removeOnFail==`boolean`&&(t.removeOnFail=e.removeOnFail),typeof e.ttl==`number`&&(t.ttl=e.ttl),Array.isArray(e.tags)&&e.tags.length&&(t.tags=[...e.tags]),typeof e.groupId==`string`&&e.groupId&&(t.groupId=e.groupId),{clone:{queue:e.queue??``,dataText:JSON.stringify(e.data??{},null,2),options:t}}}var O=a(),k=365*24*60*60*1e3;function A(e,t){if(!e.trim())return{ok:!1,msg:`A value is required`};let n=Number(e);return Number.isFinite(n)?t===`progress`?n>=0&&n<=100?{ok:!0,value:n}:{ok:!1,msg:`Progress must be between 0 and 100`}:Number.isSafeInteger(n)?t===`priority`?n>=-1e6&&n<=1e6?{ok:!0,value:n}:{ok:!1,msg:`Priority must be between -1000000 and 1000000`}:n>=0&&n<=k?{ok:!0,value:n}:{ok:!1,msg:`Delay must be between 0 and ${k} ms`}:{ok:!1,msg:`Value must be a whole, safe integer`}:{ok:!1,msg:`Value must be a finite number`}}function ae({job:e,busy:t,act:n}){let r=T(e.state),i=r.promote||r.setPriority||r.setDelay||e.state===`active`;return(0,O.jsxs)(p,{children:[(0,O.jsx)(u,{title:`Actions`}),(0,O.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.promote&&(0,O.jsx)(b,{size:`sm`,disabled:t,onClick:()=>n(`Promote`,()=>y.promoteJob(e.id)),children:`Promote (run now)`}),e.state===`failed`&&(0,O.jsx)(`p`,{role:`note`,className:`rounded-lg border border-warning/30 bg-warning/5 p-2 text-xs text-warning`,children:`DLQ retry is unavailable in Bunqueue v2.8.55: its GET and retry POST have no atomic job-generation, state, or flow-topology precondition.`}),e.state===`completed`&&(0,O.jsx)(`p`,{role:`note`,className:`rounded-lg border border-warning/30 bg-warning/5 p-2 text-xs text-warning`,children:`Completed-job requeue is unavailable in Bunqueue v2.8.55 because retry-completed re-inserts a child without rebuilding its flow dependency registration.`}),e.state===`active`&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`p`,{role:`note`,className:`rounded-lg border border-warning/30 bg-warning/5 p-2 text-xs text-warning`,children:`Active-job state changes are unavailable: Bunqueue cannot stop the worker that is already processing this job, so retrying, delaying, discarding or failing it here could run side effects twice.`}),(0,O.jsx)(j,{label:`Set progress (0–100)`,cta:`Progress`,kind:`progress`,disabled:t,onSubmit:t=>n(`Progress`,()=>y.setJobProgress(e.id,t))})]}),r.setPriority&&(0,O.jsx)(M,{disabled:t,onSubmit:(t,r)=>n(`Priority`,()=>y.changePriority(e.id,t,r))}),r.setDelay&&(0,O.jsx)(j,{label:`Set delay (ms)`,cta:`Delay`,kind:`delay`,disabled:t,onSubmit:t=>n(`Delay`,()=>y.changeDelay(e.id,t))}),(0,O.jsxs)(`p`,{role:`note`,className:`text-xs text-faint`,children:[`Cancel/delete/discard: `,C]}),!i&&(0,O.jsxs)(`p`,{className:`text-xs text-faint`,children:[`No actions available for a job in state "`,e.state??`unknown`,`".`]})]})]})}function j({label:e,cta:t,kind:n,disabled:r,onSubmit:i}){let[a,o]=(0,E.useState)(``),s=A(a,n);return(0,O.jsxs)(`form`,{className:`flex gap-2`,onSubmit:e=>{e.preventDefault(),!r&&s.ok&&i(s.value)},children:[(0,O.jsx)(ie,{type:`number`,min:0,max:n===`progress`?100:k,step:n===`progress`?`any`:1,name:n===`progress`?`job-progress`:`job-delay`,value:a,onChange:e=>o(e.target.value),placeholder:e,"aria-label":e,className:`h-8 text-xs`}),(0,O.jsx)(b,{type:`submit`,size:`sm`,disabled:r||!s.ok,children:t}),!s.ok&&a.trim()&&(0,O.jsx)(`span`,{role:`alert`,className:`self-center text-[11px] text-danger`,children:s.msg})]})}function M({disabled:e,onSubmit:t}){let[n,r]=(0,E.useState)(``),[i,a]=(0,E.useState)(!1),o=A(n,`priority`);return(0,O.jsxs)(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:n=>{n.preventDefault(),!e&&o.ok&&t(o.value,i)},children:[(0,O.jsx)(ie,{type:`number`,min:-1e6,max:1e6,step:1,name:`job-priority`,value:n,onChange:e=>r(e.target.value),placeholder:`Set priority`,"aria-label":`Set priority`,className:`h-8 min-w-28 flex-1 text-xs`}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,O.jsx)(S,{checked:i,onChange:a,label:`Place first among equal priorities`}),(0,O.jsx)(`span`,{className:`text-xs text-muted`,children:`LIFO`})]}),(0,O.jsx)(b,{type:`submit`,size:`sm`,disabled:e||!o.ok,children:`Set`}),!o.ok&&n.trim()&&(0,O.jsx)(`span`,{role:`alert`,className:`w-full text-[11px] text-danger`,children:o.msg})]})}var N=36e5,oe=10,P=e=>Math.max(e,1);function se(e){return Math.max(0,(e.maxAttempts??0)-P(e.attempts??0))}function ce(e){let t=e.maxAttempts??0,n=e.attempts??0,r=e.backoffConfig,i=r?.maxDelay??N,a=r?.delay??e.backoff??1e3,o=[];for(let e=P(n);e<t&&o.length<oe;e++){let t=r?.type===`fixed`?a:a*2**e;o.push({attempt:e+1,delayMs:Math.min(t,i)})}return o}function le({job:e}){let t=e.maxAttempts??0,n=e.attempts??0;if(t<=1)return(0,O.jsxs)(p,{children:[(0,O.jsx)(u,{title:`Backoff`}),(0,O.jsxs)(`p`,{className:`text-xs text-faint`,children:[`No retries configured (max attempts = `,t||1,`).`]})]});if(n>=t)return(0,O.jsxs)(p,{children:[(0,O.jsx)(u,{title:`Backoff schedule`}),(0,O.jsx)(`p`,{className:`text-xs text-faint`,children:`Max attempts reached — no further retries will be scheduled.`})]});let r=e.backoffConfig,i=r?r.type:`exponential (default)`,a=se(e),o=ce(e);return(0,O.jsxs)(p,{children:[(0,O.jsx)(u,{title:`Backoff schedule`,action:(0,O.jsxs)(`span`,{className:`text-xs capitalize text-faint`,children:[i,r?.maxDelay?` · cap ${_(r.maxDelay)}`:``]})}),(0,O.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:o.map(e=>(0,O.jsxs)(`li`,{className:`flex items-center justify-between text-sm`,children:[(0,O.jsxs)(`span`,{className:`text-muted`,children:[`Attempt `,e.attempt,` / `,t]}),(0,O.jsxs)(`span`,{className:`font-mono text-xs text-fg`,children:[`~`,_(e.delayMs)]})]},e.attempt))}),a>oe&&(0,O.jsxs)(`p`,{className:`mt-2 text-[11px] text-faint`,children:[`Showing next `,oe,` of `,a,` remaining attempts.`]}),(0,O.jsxs)(`p`,{className:`mt-2 text-[11px] text-faint`,children:[`Approximate — the server applies ±`,r?.type===`fixed`?`20`:`50`,`% jitter at retry time, capped at `,_(r?.maxDelay??N),`.`]})]})}function ue({jobId:e}){let[t,n]=(0,E.useState)(!1),[r,i]=(0,E.useState)(!1),[a,o]=(0,E.useState)(!1),[s,c]=(0,E.useState)(void 0),[l,d]=(0,E.useState)(null),f=async()=>{o(!0),d(null);try{let t=await y.jobChildren(e);c(t.data?.values),i(!0)}catch(e){d(e.message)}finally{o(!1)}},m=()=>{let e=!t;n(e),e&&!r&&!a&&f()},h=s&&typeof s==`object`?Array.isArray(s)?s.length:Object.keys(s).length:0;return(0,O.jsxs)(p,{children:[(0,O.jsx)(u,{title:`Child values`,action:(0,O.jsx)(b,{size:`sm`,variant:`ghost`,onClick:m,children:t?`Hide`:`Show`})}),t?a?(0,O.jsx)(`p`,{className:`text-xs text-faint`,children:`Loading child values…`}):l?(0,O.jsx)(`p`,{className:`text-xs text-danger`,children:l}):h===0?(0,O.jsx)(`p`,{className:`text-xs text-faint`,children:`No child values available.`}):(0,O.jsx)(`pre`,{className:`max-h-64 overflow-auto rounded-lg bg-surface-2 p-3 font-mono text-xs text-muted`,children:JSON.stringify(s,null,2)}):(0,O.jsx)(`p`,{className:`text-xs text-faint`,children:`Resolved return values from this flow job's children.`})]})}function de({data:e,busy:t,editable:n,readOnlyReason:r,onSave:i}){let[a,o]=(0,E.useState)(()=>JSON.stringify(e??null,null,2)),[s,c]=(0,E.useState)(null),l=(0,E.useRef)(a);return(0,E.useEffect)(()=>{let t=JSON.stringify(e??null,null,2);t!==l.current&&(l.current=t,o(t),c(null))},[e]),(0,O.jsxs)(p,{children:[(0,O.jsx)(u,{title:`Data`,action:n?(0,O.jsx)(b,{size:`sm`,disabled:t,onClick:()=>{let e;try{e=JSON.parse(a)}catch(e){c(`Invalid JSON: ${e.message}`);return}c(null),i(e)},children:`Save data`}):void 0}),(0,O.jsx)(`textarea`,{"aria-label":`Job data JSON`,name:`job-data-json`,value:a,onChange:e=>o(e.target.value),readOnly:!n,spellCheck:!1,rows:8,className:`w-full resize-y rounded-lg border border-line bg-surface-2 p-3 font-mono text-xs text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`}),!n&&(0,O.jsx)(`p`,{className:`mt-2 text-xs text-faint`,children:r??`Data is read-only after a job starts processing or leaves the runnable queue.`}),s&&(0,O.jsx)(`p`,{role:`alert`,className:`mt-2 text-xs text-danger`,children:s})]})}function fe(e){return e===`waiting`||e===`prioritized`||e===`delayed`}var F=[`__parentId`,`__parentQueue`,`__childrenIds`,`__flowParentId`,`__flowParentIds`];function pe(e,t){if(!fe(e))return`Data is read-only after a job starts processing or leaves the runnable queue.`;let n=t.data,r=typeof n==`object`&&!!n&&!Array.isArray(n)&&F.some(e=>Object.hasOwn(n,e));return t.parentId||(t.childrenIds?.length??0)>0||r?`Data is read-only for Flow jobs because Bunqueue v2.8.55 replaces the full payload and would remove structural metadata.`:null}var me=3e4;function I(){let{token:e}=s.getState();return{baseUrl:o(),authorization:e?`Bearer ${e}`:void 0}}function he(e,t){return e.baseUrl===t.baseUrl&&e.authorization===t.authorization}function ge(e,t,n){return t.aborted&&!n.aborted?new v(`Request timed out`,0):e}async function L(e,t,n,r){let i=AbortSignal.timeout(me),a=AbortSignal.any([r,i]),o=new Headers(n.headers);e.authorization&&o.set(`Authorization`,e.authorization),n.body!=null&&!o.has(`Content-Type`)&&o.set(`Content-Type`,`application/json`);let s;try{a.throwIfAborted(),s=await fetch(`${e.baseUrl}${t}`,{...n,headers:o,signal:a}),a.throwIfAborted()}catch(e){throw ge(e,i,r)}if(s.status===204)return;let c;try{c=await s.text(),a.throwIfAborted()}catch(e){throw ge(e,i,r)}let l,u=!1;if(c)try{l=JSON.parse(c)}catch{u=!0}if(!s.ok){let t=!u&&l&&typeof l==`object`?l.error:void 0;throw s.status===401&&typeof window<`u`&&window.dispatchEvent(new window.CustomEvent(`auth:required`,{detail:{scope:`server`,auth:e.authorization,target:e.baseUrl}})),new v(typeof t==`string`?t:`HTTP ${s.status}`,s.status)}if(c){if(u)throw new v(`Invalid JSON response (HTTP ${s.status})`,s.status);if(l&&typeof l==`object`&&l.ok===!1){let e=l.error;throw new v(typeof e==`string`?e:`Operation failed`,s.status)}return l}}function R(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new v(`Invalid logs response: expected an object envelope`,200);let t=e;if(t.ok!==!0||!t.data||typeof t.data!=`object`)throw new v(`Invalid logs response: expected { ok: true, data }`,200);let n=t.data;if(!Array.isArray(n.logs)||typeof n.count!=`number`||!Number.isSafeInteger(n.count)||n.count<0)throw new v(`Invalid logs response: expected logs[] and a non-negative count`,200);return{logs:n.logs,count:n.count}}function _e({jobId:e}){let t=s(e=>e.baseUrl),n=s(e=>e.token),[r,i]=(0,E.useState)([]),[a,l]=(0,E.useState)(0),[d,f]=(0,E.useState)(!1),[m,h]=(0,E.useState)(null),[ee,g]=(0,E.useState)(``),[te,_]=(0,E.useState)(`info`),[y,ne]=(0,E.useState)(!1),x=(0,E.useRef)(!1),S=(0,E.useRef)(null),C=(0,E.useRef)(0),w=(0,E.useRef)(null),T=(0,E.useRef)(0),D=(0,E.useRef)(null),k=(0,E.useRef)(!1),A=(0,E.useRef)(0);(0,E.useEffect)(()=>{x.current=!0,S.current=e;let t=()=>{C.current+=1,w.current?.abort(),w.current=null,T.current+=1,D.current?.abort(),D.current=null,k.current=!1,A.current+=1,i([]),l(0),f(!1),h(null),g(``),ne(!1)},n=s.subscribe((e,n)=>{e.baseUrl===n.baseUrl&&e.token===n.token||t()});return t(),()=>{x.current=!1,S.current=null,n(),C.current+=1,w.current?.abort(),w.current=null,T.current+=1,D.current?.abort(),D.current=null,k.current=!1}},[e]);let ae=(0,E.useCallback)(async r=>{w.current?.abort();let a=new AbortController;w.current=a;let u=++C.current,d=s.getState(),p=r?.target??(d.baseUrl===t&&d.token===n?{baseUrl:o(),authorization:n?`Bearer ${n}`:void 0}:I()),m=()=>x.current&&S.current===e&&u===C.current&&!a.signal.aborted&&he(p,I());f(!0),h(null);try{let t=R(await L(p,`/jobs/${c(e)}/logs`,{},a.signal));return m()?(i(t.logs),l(t.count),!0):!1}catch(e){if(!m())return!1;let t=e instanceof Error?e.message:String(e);return h(r?.acceptedLabel?`${r.acceptedLabel} succeeded, but couldn't reload logs: ${t}`:t),!1}finally{u===C.current&&(w.current===a&&(w.current=null),x.current&&f(!1))}},[e,t,n]);(0,E.useEffect)(()=>{ae()},[ae]);let j=async(t,n,r)=>{if(k.current)return;k.current=!0;let i=new AbortController;D.current=i;let a=++T.current,o=I();C.current+=1,w.current?.abort(),w.current=null,f(!1),ne(!0),h(null);let s=()=>x.current&&S.current===e&&a===T.current&&!i.signal.aborted&&he(o,I());try{let a=await L(o,`/jobs/${c(e)}/logs`,t,i.signal);if(!a||typeof a!=`object`||Array.isArray(a)||a.ok!==!0)throw new v(`Invalid log mutation response: expected { ok: true }`,200);if(!s())return;r(),await ae({acceptedLabel:n,target:o})}catch(e){s()&&h(e instanceof Error?e.message:String(e))}finally{a===T.current&&(k.current=!1,D.current===i&&(D.current=null),x.current&&ne(!1))}},M=async(e=ee,t=te)=>{if(k.current)return;let n=e.trim();if(!n)return;let r=t===`warn`||t===`error`?t:`info`,i=A.current;g(e),_(r),await j({method:`POST`,body:JSON.stringify({message:n,level:r})},`Log addition`,()=>{A.current===i&&g(``)})};return(0,O.jsxs)(p,{children:[(0,O.jsx)(u,{title:`Logs`,action:(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`span`,{className:`font-mono text-xs text-faint`,children:a}),(0,O.jsx)(b,{size:`sm`,variant:`ghost`,disabled:d||y,onClick:()=>void ae(),children:`Refresh`}),(0,O.jsx)(b,{size:`sm`,variant:`danger`,disabled:y||r.length===0,onClick:async()=>{k.current||window.confirm(`Clear all logs for this job?`)&&await j({method:`DELETE`},`Log clearing`,()=>{i([]),l(0)})},children:`Clear logs`})]})}),m&&(0,O.jsx)(`p`,{className:`mb-2 text-xs text-danger`,children:m}),r.length===0?(0,O.jsx)(`p`,{className:`text-xs text-faint`,children:`No log lines recorded for this job.`}):(0,O.jsx)(`ol`,{className:`flex max-h-64 flex-col gap-1 overflow-auto rounded-lg bg-surface-2 p-3`,children:r.map((e,t)=>(0,O.jsx)(`li`,{className:`whitespace-pre-wrap break-words font-mono text-xs text-muted`,children:typeof e==`string`?e:JSON.stringify(e)},t))}),(0,O.jsxs)(`form`,{className:`mt-3 flex gap-2`,onSubmit:e=>{e.preventDefault();let t=e.currentTarget.elements.namedItem(`job-log-message`),n=e.currentTarget.elements.namedItem(`job-log-level`);M(t?.value??ee,n?.value??te)},children:[(0,O.jsx)(ie,{"aria-label":`Log message`,name:`job-log-message`,autoComplete:`off`,value:ee,onInput:e=>{A.current+=1,g(e.currentTarget.value)},placeholder:`Add a log line…`,className:`h-8 flex-1 text-xs`}),(0,O.jsxs)(re,{"aria-label":`Log level`,name:`job-log-level`,value:te,onChange:e=>{A.current+=1,_(e.target.value)},className:`h-8 w-24 text-xs`,children:[(0,O.jsx)(`option`,{value:`info`,children:`info`}),(0,O.jsx)(`option`,{value:`warn`,children:`warn`}),(0,O.jsx)(`option`,{value:`error`,children:`error`})]}),(0,O.jsx)(b,{type:`submit`,size:`sm`,disabled:y||ee.trim()===``,children:`Add`})]})]})}function ve({timeline:e}){let t=e??[];return(0,O.jsxs)(p,{children:[(0,O.jsx)(u,{title:`Timeline`}),t.length===0?(0,O.jsx)(`p`,{className:`text-xs text-faint`,children:`No state transitions recorded yet.`}):(0,O.jsx)(`ol`,{className:`flex flex-col gap-0`,children:t.map((e,t)=>(0,O.jsxs)(`li`,{className:`border-b border-line/60 py-2 last:border-0`,children:[(0,O.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(g,{status:e.state}),e.attempt!=null&&(0,O.jsxs)(`span`,{className:`font-mono text-[11px] text-faint`,children:[`attempt `,e.attempt]})]}),(0,O.jsx)(`span`,{className:`font-mono text-xs text-muted`,children:h(e.timestamp)})]}),(e.worker||e.error)&&(0,O.jsxs)(`div`,{className:`mt-1 pl-0.5`,children:[e.worker&&(0,O.jsx)(`div`,{className:`font-mono text-[11px] text-faint`,children:e.worker}),e.error&&(0,O.jsx)(`div`,{className:`mt-0.5 text-xs text-danger/90`,children:e.error})]})]},t))})]})}var z=3e4;function B(){let{token:e}=s.getState();return{baseUrl:o(),authorization:e?`Bearer ${e}`:void 0}}function V(e,t){return e?.baseUrl===t.baseUrl&&e.authorization===t.authorization}function H(e,t,n){return t.aborted&&!n?.aborted?new v(`Request timed out`,0):e}async function ye(e,t,n,r=z){let i=AbortSignal.timeout(r),a=n?AbortSignal.any([n,i]):i,o=new Headers;e.authorization&&o.set(`Authorization`,e.authorization);let s;try{a.throwIfAborted(),s=await fetch(`${e.baseUrl}${t}`,{headers:o,signal:a}),a.throwIfAborted()}catch(e){throw H(e,i,n)}if(s.status===204)return;let c;try{c=await s.text(),a.throwIfAborted()}catch(e){throw H(e,i,n)}let l,u=!1;if(c)try{l=JSON.parse(c)}catch{u=!0}if(!s.ok){let t=!u&&l&&typeof l==`object`?l.error:void 0,n=typeof t==`string`?t:`HTTP ${s.status}`;throw s.status===401&&typeof window<`u`&&window.dispatchEvent(new window.CustomEvent(`auth:required`,{detail:{scope:`server`,auth:e.authorization,target:e.baseUrl}})),new v(n,s.status)}if(c){if(u)throw new v(`Invalid JSON response (HTTP ${s.status})`,s.status);if(l&&typeof l==`object`&&l.ok===!1){let e=l.error;throw new v(typeof e==`string`?e:`Operation failed`,s.status)}return l}}function U(e){throw new v(`Invalid job response: ${e}`,200)}function W(e,t,{nullable:n=!1,nonEmpty:r=!1}={},i=`job`){if(!Object.hasOwn(e,t)||e[t]===void 0)return;let a=e[t];n&&a===null||(typeof a!=`string`||r&&!a.trim())&&U(`${i}.${t} must be ${n?`a string or null`:`a string`}${r?` (non-empty)`:``}`)}function G(e,t,{nullable:n=!1,integer:r=!1,min:i,max:a}={},o=`job`){if(!Object.hasOwn(e,t)||e[t]===void 0)return;let s=e[t];n&&s===null||(typeof s!=`number`||!Number.isFinite(s)||r&&!Number.isSafeInteger(s)||i!==void 0&&s<i||a!==void 0&&s>a)&&U(`${o}.${t} must be a valid${r?` safe integer`:` finite number`}`)}function K(e,t){Object.hasOwn(e,t)&&e[t]!==void 0&&typeof e[t]!=`boolean`&&U(`job.${t} must be a boolean`)}function q(e,t,{nullable:n=!1,nonEmpty:r=!1}={}){if(!Object.hasOwn(e,t)||e[t]===void 0)return;let i=e[t];n&&i===null||(!Array.isArray(i)||i.some(e=>typeof e!=`string`||r&&!e.trim()))&&U(`job.${t} must be ${n?`a string array or null`:`a string array`}`)}var J=1e4,Y=100,X=256*1024;function Z(e,t){let n=0,r=0;for(;n<e.length&&r<t;){let t=e.codePointAt(n);n+=t!==void 0&&t>65535?2:1,r+=1}return{text:e.slice(0,n),count:r}}function be(e){let t=[],n=0,r=!1,i=Math.min(e.length,Y);for(let a=0;a<i;a++){let i=+(t.length>0),o=X-n-i;if(o<=0){r=!0;break}let s=e[a]??``,c=Z(s,o);if(t.push(c.text),n+=i+c.count,c.text.length!==s.length){r=!0;break}}return t.length<e.length&&(r=!0),{text:t.join(`
2
+ `),displayedLines:t.length,totalLines:e.length,truncated:r}}function xe(e,t){if(t&&(typeof e.state!=`string`||!e.state.trim())&&U(`canonical job.state must be a non-empty string`),W(e,`state`,{nonEmpty:!0}),t&&(typeof e.queue!=`string`||!e.queue.trim())&&U(`canonical job.queue must be a non-empty string`),W(e,`queue`,{nonEmpty:!0}),W(e,`customId`,{nullable:!0}),W(e,`parentId`,{nullable:!0,nonEmpty:!0}),W(e,`groupId`,{nullable:!0}),W(e,`progressMessage`,{nullable:!0}),q(e,`childrenIds`,{nonEmpty:!0}),q(e,`dependsOn`,{nonEmpty:!0}),q(e,`tags`),q(e,`stacktrace`,{nullable:!0}),Array.isArray(e.stacktrace)&&e.stacktrace.length>J&&U(`job.stacktrace exceeds Bunqueue's ${J}-entry limit`),G(e,`priority`,{integer:!0}),G(e,`createdAt`),G(e,`runAt`),G(e,`startedAt`,{nullable:!0}),G(e,`completedAt`,{nullable:!0}),G(e,`attempts`,{integer:!0,min:0}),G(e,`maxAttempts`,{integer:!0,min:0}),G(e,`backoff`,{integer:!0,min:0}),G(e,`timeout`,{nullable:!0,integer:!0,min:0}),G(e,`ttl`,{nullable:!0,integer:!0,min:0}),G(e,`progress`,{min:0,max:100}),G(e,`lastHeartbeat`),G(e,`stallCount`,{integer:!0,min:0}),K(e,`removeOnComplete`),K(e,`removeOnFail`),Object.hasOwn(e,`backoffConfig`)&&e.backoffConfig!==void 0){let t=e.backoffConfig;if(t!==null){(!t||typeof t!=`object`||Array.isArray(t))&&U(`job.backoffConfig must be an object or null`);let e=t;e.type!==`fixed`&&e.type!==`exponential`&&U(`job.backoffConfig.type must be fixed or exponential`),G(e,`delay`,{integer:!0,min:0},`job.backoffConfig`),(!Object.hasOwn(e,`delay`)||e.delay===void 0)&&U(`job.backoffConfig.delay is required`),G(e,`maxDelay`,{integer:!0,min:0},`job.backoffConfig`)}}if(Object.hasOwn(e,`timeline`)&&e.timeline!==void 0){Array.isArray(e.timeline)||U(`job.timeline must be an array`),e.timeline.length>20&&U(`job.timeline exceeds 20 entries`);for(let[t,n]of e.timeline.entries()){(!n||typeof n!=`object`||Array.isArray(n))&&U(`job.timeline[${t}] must be an object`);let e=n;(typeof e.state!=`string`||!e.state.trim())&&U(`job.timeline[${t}].state must be a non-empty string`),(typeof e.timestamp!=`number`||!Number.isFinite(e.timestamp))&&U(`job.timeline[${t}].timestamp must be a finite number`);let r=`job.timeline[${t}]`;W(e,`worker`,{},r),W(e,`error`,{},r),G(e,`attempt`,{integer:!0,min:0},r)}}}function Se(e,{canonical:t,expectedId:n}){if(!e||typeof e!=`object`||Array.isArray(e))return U(`expected an object envelope`);let r=e;if(r.ok!==!0||!Object.hasOwn(r,`job`))return U(`expected { ok: true, job }`);if(r.job===null)return null;if(!r.job||typeof r.job!=`object`||Array.isArray(r.job))return U(`job must be an object or null`);let i=r.job;return typeof i.id!=`string`||!i.id.trim()?U(`job.id must be a non-empty string`):n!==void 0&&i.id!==n?U(`expected job.id ${JSON.stringify(n)}`):(xe(i,t),i)}function Ce(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw new v(`Invalid job result response: expected an object envelope`,200);let n=e;if(n.ok!==!0||n.id!==t)throw new v(`Invalid job result response: expected { ok: true, id, result? }`,200);return{result:n.result}}async function we(e,t,n={}){let r=n.target??B(),i=n.timeoutMs??z,a=Se(await ye(r,t===`custom`?`/jobs/custom/${l(e,`Custom job ID`)}`:`/jobs/${c(e)}`,n.signal,i),{canonical:t===`id`,expectedId:t===`id`?e:void 0});return!a||t===`id`?a:a.customId===e?Se(await ye(r,`/jobs/${c(a.id)}`,n.signal,i),{canonical:!0,expectedId:a.id}):U(`expected job.customId ${JSON.stringify(e)}`)}function Te(e){let t=e.timeline??[];for(let e=t.length-1;e>=0;e--){let n=t[e];if(n.state===`failed`&&n.error)return{message:n.error,attempt:n.attempt,timestamp:n.timestamp}}return null}function Ee(){let e=r(),[n,a]=t(),l=s(e=>e.baseUrl),m=s(e=>e.token),ie=n.get(`custom`),[S,C]=(0,E.useState)(ie??n.get(`id`)??``),[T,k]=(0,E.useState)(ie?`custom`:`id`),[A,j]=(0,E.useState)(null),[M,N]=(0,E.useState)({fetched:!1,value:void 0}),[oe,P]=(0,E.useState)(null),[se,ce]=(0,E.useState)(!1),[fe,F]=(0,E.useState)(!1),[me,I]=(0,E.useState)(null),[he,ge]=(0,E.useState)(!1),L=(0,E.useRef)(0),R=(0,E.useRef)(null),z=(0,E.useRef)(null),H=(0,E.useRef)(null),U=(0,E.useRef)(!1),W=(0,E.useRef)(null),G=(0,E.useRef)(!1),K=(0,E.useRef)(0),q=(0,E.useRef)(!1),J=(0,E.useRef)(null);(0,E.useEffect)(()=>{G.current=!0;let e=s.subscribe((e,t)=>{e.baseUrl===t.baseUrl&&e.token===t.token||(L.current+=1,R.current?.abort(),R.current=null,z.current=null,K.current+=1,J.current=null,q.current=!1,H.current=null,U.current=!1,W.current=null,j(null),N({fetched:!1,value:void 0}),P(null),F(!1),I(null),ce(!1),ge(!1))});return()=>{G.current=!1,e(),L.current+=1,R.current?.abort(),R.current=null,z.current=null,K.current+=1,J.current=null,q.current=!1}},[]);let Y=async(e,t=T,n=!1,r,i=!1)=>{let o=e.trim();if(!o||r===void 0&&q.current&&!i)return;U.current=!1,W.current=null,r===void 0&&(K.current+=1),A!==null&&(t===`id`?A.id!==o:A.customId!==o)&&(H.current=null,j(null),N({fetched:!1,value:void 0}),P(null)),R.current?.abort();let s=new AbortController;R.current=s,z.current={key:o,mode:t};let l=++L.current,u=B();ce(!0),F(!1),n||I(null);try{let e=await we(o,t,{signal:s.signal,target:u});if(!e){if(l!==L.current)return;U.current=!0,W.current=null,j(null),N({fetched:!1,value:void 0}),P(null),F(!0),a({},{replace:!0});return}let n=null,r=null;if(l!==L.current||s.signal.aborted||!V(u,B()))return;if(e.state===`completed`)try{n=Ce(await ye(u,`/jobs/${c(e.id)}/result`,s.signal),e.id)}catch(e){if(s.signal.aborted)throw e;r=e.message}if(l!==L.current||s.signal.aborted||!V(u,B()))return;H.current=u,j(e),t===`custom`?(k(`id`),C(e.id)):C(o),a({id:e.id},{replace:!0}),N(n?{fetched:!0,value:n.result}:{fetched:!1,value:void 0}),P(r)}catch(e){if(l!==L.current||s.signal.aborted)return;e instanceof v&&(e.status===404||/not found/i.test(e.message))?(U.current=!0,W.current=null,j(null),N({fetched:!1,value:void 0}),P(null),F(!0),a({},{replace:!0})):I(n?t=>t?{ok:t.ok,text:`${t.text} — couldn't reload: ${e.message}`}:{ok:!1,text:e.message}:{ok:!1,text:e.message})}finally{l===L.current&&(R.current===s&&(R.current=null,z.current=null),ce(!1))}},X=n.get(`id`),Z=n.get(`custom`),xe={baseUrl:o(),authorization:m?`Bearer ${m}`:void 0},Se=V(H.current,xe);(0,E.useEffect)(()=>{if(U.current){!X&&!Z&&(U.current=!1,W.current=e.key);return}if(!(!X&&!Z&&W.current===e.key))if(W.current=null,Z)if(A?.customId===Z&&Se)k(`id`),C(A.id),a({id:A.id},{replace:!0});else{k(`custom`),C(Z);let e=z.current;(e?.mode!==`custom`||e.key!==Z)&&Y(Z,`custom`,!1,void 0,!0)}else if(X&&(X!==A?.id||!Se)){k(`id`),C(X);let e=z.current;(e?.mode!==`id`||e.key!==X)&&Y(X,`id`,!1,void 0,!0)}else!X&&!Z&&(L.current+=1,R.current?.abort(),R.current=null,z.current=null,K.current+=1,H.current=null,j(null),N({fetched:!1,value:void 0}),P(null),F(!1),I(null),ce(!1),k(`id`),C(``))},[X,Z,A?.id,A?.customId,Se,e.key,l,m]);let Ee=(e,t=T)=>{let n=e.trim();if(!(!n||q.current)){if(t===`id`?X===n&&Z===null:Z===n&&X===null){Y(n,t);return}a(t===`custom`?{custom:n}:{id:n})}},ke=async(e,t,n)=>{if(!A||q.current||R.current)return;let r=B();if(!V(H.current,r)||n&&!window.confirm(n))return;let i=++K.current,o=A.id;J.current=i,q.current=!0,ge(!0),I(null);let s=()=>G.current&&i===K.current&&V(r,B())&&V(H.current,r);try{let n=await t();if(!n||typeof n!=`object`||Array.isArray(n)||n.ok!==!0)throw new v(`Invalid job mutation response: expected { ok: true }`,200);if(!s())return;I({ok:!0,text:`${e} ✓`}),e===`Cancel`?(U.current=!0,W.current=null,L.current+=1,H.current=null,j(null),N({fetched:!1,value:void 0}),P(null),a({},{replace:!0})):await Y(o,`id`,!0,i)}catch(e){s()&&I({ok:!1,text:e.message})}finally{J.current===i&&(J.current=null,q.current=!1,G.current&&ge(!1))}},Ae=A?.state,$=A?Te(A):null,je=A?.stacktrace?.length?be(A.stacktrace):null,Me=je!==null,Ne=(A?.childrenIds?.length??0)>0,Pe=A?pe(Ae,A):null,Fe=Ae===`failed`,Ie=A&&($||Me)?(0,O.jsxs)(p,{children:[(0,O.jsx)(u,{title:`Error`}),$&&(0,O.jsxs)(`div`,{className:`mb-3`,children:[(0,O.jsx)(`p`,{className:`text-sm text-danger`,children:$.message}),(0,O.jsxs)(`p`,{className:`mt-1 text-[11px] text-faint`,children:[$.attempt==null?``:`Attempt ${$.attempt} · `,h($.timestamp)]})]}),je&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`pre`,{className:`max-h-80 overflow-auto whitespace-pre-wrap rounded-lg bg-surface-2 p-3 font-mono text-xs text-danger/90`,children:je.text}),je.truncated&&(0,O.jsxs)(`p`,{className:`mt-2 text-xs text-faint`,children:[`Stack preview truncated (`,je.displayedLines,` of `,je.totalLines,` `,`lines, 262,144 characters maximum). Download JSON for the complete stored stack.`]})]})]}):null;return(0,O.jsxs)(`div`,{children:[(0,O.jsx)(te,{title:`Job Inspector`,description:`Look up any job by ID and drive its full lifecycle.`,actions:A?(0,O.jsxs)(O.Fragment,{children:[(Ne||A.parentId)&&(0,O.jsx)(i,{to:`/flows?root=${encodeURIComponent(A.id)}`,className:`rounded-lg border border-line px-3 py-1.5 text-sm text-muted hover:bg-surface-2 hover:text-fg`,children:`View flow`}),(0,O.jsx)(i,{to:`/add-job`,state:D(A),title:`Enqueue a new job pre-filled from this one`,className:`rounded-lg border border-line px-3 py-1.5 text-sm text-muted hover:bg-surface-2 hover:text-fg`,children:`Clone`}),(0,O.jsxs)(b,{size:`sm`,onClick:()=>w(`job-${A.id}`,M.fetched?{...A,result:M.value}:A),children:[(0,O.jsx)(x,{className:`size-3.5`}),` Download JSON`]})]}):void 0}),(0,O.jsxs)(`div`,{className:`mb-6 flex flex-wrap items-center gap-2`,children:[(0,O.jsxs)(re,{name:`job-lookup-mode`,autoComplete:`off`,value:T,"aria-label":`Lookup mode`,onChange:e=>k(e.target.value),className:`w-40`,children:[(0,O.jsx)(`option`,{value:`id`,children:`By job ID`}),(0,O.jsx)(`option`,{value:`custom`,children:`By custom ID`})]}),(0,O.jsxs)(`div`,{className:`relative min-w-56 flex-1`,children:[(0,O.jsx)(d,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-faint`}),(0,O.jsx)(`input`,{value:S,"aria-label":T===`custom`?`Custom job ID`:`Job ID`,name:`job-lookup-id`,autoComplete:`off`,spellCheck:!1,maxLength:1024,onInput:e=>C(e.currentTarget.value),onKeyDown:e=>e.key===`Enter`&&Ee(S),placeholder:T===`custom`?`custom / idempotency id — Enter to look up`:`job id (UUID) — Enter to look up`,className:`h-9 w-full rounded-lg border border-line bg-surface pl-9 pr-3 font-mono text-sm text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`})]}),(0,O.jsx)(b,{variant:`accent`,disabled:se||he,onClick:()=>Ee(S),children:`Look up`})]}),me&&(0,O.jsx)(`div`,{role:`status`,className:me.ok?`mb-4 text-sm text-success`:`mb-4 text-sm text-danger`,children:me.text}),se&&!A?(0,O.jsx)(ee,{label:`Loading job…`}):fe?(0,O.jsx)(ne,{title:`Job not found`,hint:`Check the ID, or the job may have been removed.`}):A?(0,O.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-3`,children:[(0,O.jsxs)(`div`,{className:`flex flex-col gap-6 lg:col-span-2`,children:[(0,O.jsxs)(p,{children:[(0,O.jsxs)(`div`,{className:`mb-4 flex items-center justify-between gap-3`,children:[(0,O.jsxs)(`div`,{className:`min-w-0`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,O.jsx)(`div`,{className:`truncate font-mono text-sm text-fg`,children:A.id}),(0,O.jsx)(f,{value:A.id})]}),(0,O.jsx)(`div`,{className:`mt-1 font-mono text-xs text-faint`,children:A.queue})]}),(0,O.jsx)(g,{status:Ae??`unknown`})]}),(0,O.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm sm:grid-cols-3`,children:[(0,O.jsx)(Q,{k:`Priority`,v:String(A.priority??0)}),(0,O.jsx)(Q,{k:`Attempts`,v:`${A.attempts??0} / ${A.maxAttempts??`?`}`}),(0,O.jsx)(Q,{k:`Progress`,v:`${A.progress??0}%`}),(0,O.jsx)(Q,{k:`Created`,v:h(A.createdAt)}),(0,O.jsx)(Q,{k:`Started`,v:h(A.startedAt??void 0)}),(0,O.jsx)(Q,{k:`Completed`,v:h(A.completedAt??void 0)}),(0,O.jsx)(Q,{k:`Duration`,v:_(A.startedAt&&A.completedAt?A.completedAt-A.startedAt:void 0)}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[11px] uppercase tracking-wider text-faint`,children:`Custom ID`}),(0,O.jsxs)(`dd`,{className:`flex items-center gap-1 text-fg`,children:[(0,O.jsx)(`span`,{className:`truncate font-mono`,children:A.customId??`—`}),A.customId&&(0,O.jsx)(f,{value:A.customId})]})]})]})]}),Fe&&Ie,(0,O.jsx)(de,{data:A.data,busy:he,editable:Pe===null,readOnlyReason:Pe??void 0,onSave:e=>ke(`Data`,()=>y.updateJobData(A.id,e))},`data-${A.id}`),Ae===`completed`&&(0,O.jsxs)(p,{children:[(0,O.jsx)(u,{title:`Result`,action:M.fetched&&M.value!==void 0&&M.value!==null?(0,O.jsx)(Oe,{value:M.value,filename:`job-${A.id}-result`}):void 0}),M.fetched&&M.value!==void 0&&M.value!==null?(0,O.jsx)(De,{value:M.value}):oe?(0,O.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,O.jsxs)(`p`,{className:`text-xs text-danger`,children:[`Couldn't load result — `,oe]}),(0,O.jsx)(b,{size:`sm`,disabled:se,onClick:()=>Y(A.id,`id`),children:`Retry`})]}):(0,O.jsx)(`p`,{className:`text-xs text-faint`,children:`No result stored for this job.`})]}),!Fe&&Ie,(0,O.jsx)(_e,{jobId:A.id},`logs-${A.id}`),Ne&&(0,O.jsx)(ue,{jobId:A.id},`children-${A.id}`),(0,O.jsx)(ve,{timeline:A.timeline}),(0,O.jsx)(le,{job:A})]}),(0,O.jsx)(`div`,{className:`order-first lg:order-none`,children:(0,O.jsx)(ae,{job:A,busy:he,act:ke})})]}):(0,O.jsx)(ne,{title:`No job loaded`,hint:`Enter a job ID above to inspect it.`})]})}function Q({k:e,v:t}){return(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`dt`,{className:`text-[11px] uppercase tracking-wider text-faint`,children:e}),(0,O.jsx)(`dd`,{className:`text-fg`,children:t})]})}function De({value:e}){return(0,O.jsx)(`pre`,{className:`max-h-64 overflow-auto rounded-lg bg-surface-2 p-3 font-mono text-xs text-muted`,children:JSON.stringify(e??null,null,2)})}function Oe({value:e,filename:t}){return(0,O.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,O.jsx)(f,{value:JSON.stringify(e??null,null,2)}),(0,O.jsx)(m,{"aria-label":`Download JSON`,title:`Download JSON`,onClick:()=>w(t,e??null),children:(0,O.jsx)(x,{className:`size-3.5`})})]})}export{Ee as JobInspector};
@@ -0,0 +1 @@
1
+ import{r as e}from"./cn-CMFYpumL.js";import{f as t,g as n,r,t as i}from"./react-vendor-Bjui4wS4.js";import{A as a,J as o,b as s,c,f as l,g as u,h as d,j as f,l as p,m,n as h,o as g,st as _,u as v,x as y}from"./index-Bn2R06qm.js";import{a as b,i as ee}from"./form-DsUq0w8s.js";import{r as te}from"./flowMutationSafety-DVD1IMr-.js";import{t as ne}from"./promisePool-BVfQ9n9Q.js";var x=e(n(),1),S=i(),C=`__all__`,w=[`all`,`waiting`,`active`,`completed`,`failed`],T=500,E=40,D=8,O=100,k=20,A=T*k;function j(e,t,n){if(typeof e!=`object`||!e||e.ok!==!0||!Array.isArray(e.queues)||!Number.isSafeInteger(e.total)||e.total<0||e.total>A||n!==null&&e.total!==n||e.offset!==t||e.limit!==T||e.queues.length!==Math.min(T,e.total-t)||e.queues.length>T||e.queues.some(e=>typeof e!=`object`||!e||typeof e.name!=`string`||e.name.length===0||e.name.length>256||!/^[a-zA-Z0-9_\-.:]+$/.test(e.name)))throw Error(`Queue discovery returned a malformed or unsafe page`)}async function M(){let e=await f.queues(T,0);j(e,0,null);let t=[...e.queues],n=new Set;for(let e of t){if(n.has(e.name))throw Error(`Queue discovery returned duplicate queue ${e.name}`);n.add(e.name)}let r=e.total,i=1;for(;t.length<r;){if(i>=k||t.length>=A)throw Error(`Queue discovery exceeds the safety limit of ${A}`);let e=t.length,a=await f.queues(T,e);j(a,e,r);for(let e of a.queues){if(n.has(e.name))throw Error(`Queue discovery pages overlap at queue ${e.name}`);n.add(e.name),t.push(e)}i+=1}return{...e,queues:t,total:r,limit:t.length,offset:0}}function N(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let t=e.name;return typeof t==`string`&&t.length>0?t:null}function P(){let[e]=t(),[n,i]=(0,x.useState)(e.get(`queue`)??C),[T,k]=(0,x.useState)(`all`),[A,j]=(0,x.useState)(``),{data:P,error:F,refetch:I}=a(M,[],{intervalMs:3e4}),{data:L,error:R,refetch:z}=a(()=>f.overview(),[]),B=(0,x.useMemo)(()=>(P?.queues??[]).map(e=>e.name),[P]),V=`${n}\u0000${T}\u0000${JSON.stringify(B)}`,{data:H,error:U,loading:W,refetch:G}=a((0,x.useCallback)(async e=>{if(n===C&&!P)return null;let t=n===C?B:[n];if(n===C&&t.length>100)return{scopeKey:V,jobs:[],failures:[],queueCount:t.length,blockedReason:`All-queue job browsing is limited to 100 queues; ${c(t.length)} were discovered. Select one queue to avoid an unsafe request fan-out.`};let r=T===`all`?void 0:[T],i=_.createServerTargetClient(_.captureServerRequestTarget(),e),a=await ne(t,D,async t=>(e.throwIfAborted(),(await i.jobsList(t,r,E)).jobs.map(e=>({...e,stacktrace:e.stacktrace??void 0,queue:e.queue??t}))),e);e.throwIfAborted();let o=[],s=[];return a.forEach((e,n)=>{e.status===`fulfilled`?o.push(...e.value):s.push({queue:t[n],message:e.reason instanceof Error?e.reason.message:String(e.reason)})}),{scopeKey:V,jobs:o.sort((e,t)=>(t.createdAt??0)-(e.createdAt??0)),failures:s,queueCount:t.length,blockedReason:null}},[n,T,P,B,V]),[V],{intervalMs:15e3}),K=H?.scopeKey===V?H:null,q=K?.blockedReason?null:K?.jobs??null,{rows:J,matchingCount:Y}=(0,x.useMemo)(()=>{let e=q??[],t=A.trim().toLowerCase(),n=t?e.filter(e=>typeof e.id==`string`&&e.id.toLowerCase().includes(t)||(N(e.data)?.toLowerCase().includes(t)??!1)):e;return{rows:n.slice(0,O),matchingCount:n.length}},[q,A]),X=L?.stats,Z=X?h(X.totalCompleted,X.totalFailed):null,Q=e=>X?c(e):`—`,re=!!K&&K.queueCount>0&&K.failures.length===K.queueCount,ie=n===C&&!P&&!F||W&&!K&&!U,$=`No jobs found.`;return K?.blockedReason?$=K.blockedReason:n===C&&F&&!P?$=`Queue discovery unavailable — ${F.message}`:U&&!K?$=`Could not load jobs — ${U.message}`:re?$=`Could not load jobs from any of the ${K.queueCount} queues.`:A.trim()&&K?.failures.length?$=`No matching jobs in the queue results that could be loaded.`:A.trim()&&($=`No jobs match this search.`),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(d,{title:`Jobs Explorer`,description:`Browse, inspect, and manage individual jobs.`,live:!!K&&!F&&!R&&!U&&!K.blockedReason&&K.failures.length===0}),F&&(0,S.jsx)(y,{message:`Queue discovery unavailable — ${F.message}`,onRetry:I}),R&&(0,S.jsx)(y,{message:`Job totals unavailable — ${R.message}`,onRetry:z}),U&&(0,S.jsx)(y,{message:`Could not load jobs — ${U.message}`,onRetry:G}),K?.blockedReason&&(0,S.jsx)(y,{message:K.blockedReason}),!!K?.failures.length&&(0,S.jsx)(y,{message:`Could not load jobs from ${K.failures.length} of ${K.queueCount} queues: ${K.failures.slice(0,3).map(e=>`${e.queue} (${e.message})`).join(`, `)}${K.failures.length>3?`, …`:``}`,onRetry:G}),(0,S.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-6`,children:[(0,S.jsx)(m,{label:`Total`,value:X?c(X.totalCompleted+X.totalFailed+X.waiting+X.active):`—`,compact:!0}),(0,S.jsx)(m,{label:`Waiting`,value:Q(X?.waiting),tone:`amber`,compact:!0}),(0,S.jsx)(m,{label:`Active`,value:Q(X?.active),tone:`blue`,compact:!0}),(0,S.jsx)(m,{label:`Completed`,value:Q(X?.totalCompleted),tone:`green`,compact:!0}),(0,S.jsx)(m,{label:`Failed`,value:Q(X?.totalFailed),tone:X?.totalFailed?`red`:`default`,compact:!0}),(0,S.jsx)(m,{label:`Error Rate`,value:Z==null?`—`:p(Z),tone:Z==null?`default`:Z>.05?`red`:`green`,compact:!0})]}),(0,S.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-3`,children:[(0,S.jsx)(`div`,{className:`w-48`,children:(0,S.jsxs)(b,{value:n,"aria-label":`Queue`,name:`jobs-queue`,autoComplete:`off`,onChange:e=>i(e.target.value),children:[(0,S.jsx)(`option`,{value:C,children:`All Queues`}),(P?.queues??[]).map(e=>(0,S.jsx)(`option`,{value:e.name,children:e.name},e.name))]})}),(0,S.jsx)(ee,{options:w,value:T,onChange:k}),(0,S.jsxs)(`div`,{className:`relative ml-auto min-w-56 flex-1 md:max-w-xs`,children:[(0,S.jsx)(o,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-faint`}),(0,S.jsx)(`input`,{value:A,onChange:e=>j(e.target.value),"aria-label":`Search jobs`,name:`jobs-search`,autoComplete:`off`,placeholder:`Search by ID or name…`,className:`h-9 w-full rounded-lg border border-line bg-surface pl-9 pr-3 text-sm text-fg placeholder:text-faint focus:border-accent/60 focus:outline-none focus:ring-2 focus:ring-accent/30`})]})]}),K&&!K.blockedReason&&(0,S.jsxs)(`p`,{role:`status`,className:`mb-3 text-xs text-faint`,children:[n===C?`Queried all ${c(K.queueCount)} discovered queues`:`Queried ${n}`,` `,`· up to `,E,` recent jobs per queue`,Y>O?` · showing the newest ${O} of ${c(Y)} matches`:``]}),ie?(0,S.jsx)(s,{label:`Loading jobs…`}):(0,S.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,S.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,S.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Job ID`}),(0,S.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Name`}),(0,S.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queue`}),(0,S.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Status`}),(0,S.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Priority`}),(0,S.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Created`}),(0,S.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Duration`}),(0,S.jsx)(`th`,{className:`w-12 px-5 py-3`})]})}),(0,S.jsx)(`tbody`,{children:J.length===0?(0,S.jsx)(`tr`,{children:(0,S.jsx)(`td`,{colSpan:8,className:`px-5 py-12 text-center text-sm text-faint`,children:$})}):J.map(e=>(0,S.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,S.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs`,children:(0,S.jsx)(r,{to:`/job?id=${encodeURIComponent(e.id)}`,className:`text-accent/90 hover:text-accent hover:underline`,title:`Inspect job ${e.id}`,children:e.id})}),(0,S.jsx)(`td`,{className:`px-5 py-3 text-fg`,children:N(e.data)??`unnamed`}),(0,S.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-muted`,children:e.queue}),(0,S.jsx)(`td`,{className:`px-5 py-3`,children:(0,S.jsx)(u,{status:String(e.state??e.status??`waiting`)})}),(0,S.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:e.priority??0}),(0,S.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:v(e.createdAt)}),(0,S.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:g(l(e.startedAt??void 0,e.completedAt??void 0))}),(0,S.jsx)(`td`,{className:`px-5 py-3 text-right`,children:(0,S.jsx)(`span`,{className:`text-xs text-faint`,title:te,children:`Delete unavailable`})})]},`${e.queue}:${e.id}`))})]})})]})}export{P as Jobs,M as discoverAllQueues};
@@ -0,0 +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,B as s,J as c,T as ee,W as te,a as ne,b as l,c as u,ft as d,g as re,h as ie,l as ae,m as f,n as oe,o as se,st as p,w as m,x as h,y as ce,z as le}from"./index-Bn2R06qm.js";import{a as g}from"./form-DsUq0w8s.js";import{t as ue}from"./Pagination-DpxiBnt8.js";import{r as de,t as _}from"./useServerActionGuard-CItj3hvh.js";import{t as fe}from"./exportFile-C7xhE8Yh.js";import{t as v}from"./jobActions-LQD4KfCc.js";var y=e(r(),1),b=a(),x=[`all`,`waiting`,`prioritized`,`active`,`delayed`,`waiting-children`,`paused`,`completed`,`failed`],S=25;function pe(e,t){return e===t?`${t} selected`:`${e} of ${t} selected match this filter`}function me(e,t){let n=new Set(e);for(let e of t)n.delete(e);return n}function he(e=0){return e>=10?{t:`HIGH`,c:`text-warning`}:e>=1?{t:`MEDIUM`,c:`text-blue-400`}:{t:`LOW`,c:`text-faint`}}function C(){let[e,r]=n(),[a,C]=(0,y.useState)(e.get(`queue`)??``),[w,ge]=(0,y.useState)(()=>{let t=e.get(`status`);return t&&x.includes(t)?t:`all`}),[T,_e]=(0,y.useState)(``),[E,D]=(0,y.useState)(0),[O,k]=(0,y.useState)(new Set),[ve,A]=(0,y.useState)(new Set),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)(null),{data:F,error:I,loading:ye,refetch:be}=o(()=>p.queuesSummary(),[],{intervalMs:3e4}),{data:L,error:R,refetch:xe}=o(()=>p.stats(),[],{intervalMs:1e4});(0,y.useEffect)(()=>{!a&&F?.length&&C(F[0].name)},[F,a]);let z=`${a}|${w}|${E}`,B=de(`jobs:${a}`),{data:V,error:H,loading:Se,refetch:U}=o((0,y.useCallback)(async()=>{if(!a)return{view:z,jobs:[]};let e=w===`all`?void 0:[w],t=await p.jobsList(a,e,S,E*S);return{view:z,jobs:(t.jobs??[]).map(e=>({...e,queue:e.queue??a}))}},[a,w,E,z]),[a,w,E]),W=V&&V.view===z?V.jobs:null;(0,y.useEffect)(()=>{A(new Set),M(!1),P(null)},[B.scopeKey]);let Ce=(W?.length??0)===S,G=(0,y.useMemo)(()=>{let e=T.trim().toLowerCase();return e?(W??[]).filter(t=>t.id.toLowerCase().includes(e)):W??[]},[W,T]),K=L?.stats,q=(0,y.useMemo)(()=>F?.reduce((e,t)=>e+(t.counts?.failed??0),0)??null,[F]),J=K&&q!=null?oe(K.completed,q):null,Y=e=>K?u(e):`—`,X=()=>D(0),we=(e,t)=>{let n={};e&&(n.queue=e),t!==`all`&&(n.status=t),r(n,{replace:!0})};(0,y.useEffect)(()=>{k(new Set)},[a,w,E]);let Te=e=>k(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),Z=G.length>0&&G.every(e=>O.has(e.id)),Ee=()=>k(()=>Z?new Set:new Set(G.map(e=>e.id))),De=async(e,t,n,r)=>{if(r&&!window.confirm(r))return;let i=B.begin(`job:${e.id}`);if(i){A(t=>new Set(t).add(e.id)),P(null);try{if(_(await n(),t),!i.isCurrent())return;P({ok:!0,text:`${t} ✓`}),d.success(`${t} ✓`,e.id),U()}catch(e){if(!i.isCurrent())return;P({ok:!1,text:`${t} failed: ${e.message}`}),d.error(`${t} failed`,e.message)}finally{i.finish()&&A(t=>{let n=new Set(t);return n.delete(e.id),n})}}},Oe=async(e,t,n,r)=>{let i=G.filter(e=>O.has(e.id)&&n(e));if(i.length===0||r&&!window.confirm(r(i.length)))return;let a=B.begin([`bulk`,...i.map(e=>`job:${e.id}`)]);if(a){M(!0),P(null);try{let n=await Promise.allSettled(i.map(async n=>{_(await t(n),`${e} ${n.id}`)}));if(!a.isCurrent())return;let r=n.filter(e=>e.status===`fulfilled`).length,o=n.length-r,s=`${e}: ${r} succeeded${o?`, ${o} failed`:``}`;P({ok:o===0,text:s}),o===0?d.success(s):d.error(s);let c=i.map(e=>e.id);k(e=>me(e,c)),U()}finally{a.finish()&&M(!1)}}},ke={promote:e=>v(e.state).promote},Q=G.filter(e=>O.has(e.id)),$={promote:Q.some(ke.promote)};return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(ie,{title:`Jobs Explorer`,description:`Browse, inspect, and manage individual jobs.`,live:!!a&&W!=null&&!H&&!I&&!R,actions:(0,b.jsxs)(m,{size:`sm`,disabled:!W||G.length===0,onClick:()=>{if(G.length===0){d.info(`No jobs to export on this page`);return}let e=G.map(e=>({id:e.id,queue:e.queue??a,state:e.state??``,priority:e.priority??0,attempts:e.attempts??0,maxAttempts:e.maxAttempts??``,createdAt:e.createdAt?new Date(e.createdAt).toISOString():``,durationMs:e.startedAt&&e.completedAt?e.completedAt-e.startedAt:``}));fe(`jobs-${a}-${w}`,e,[`id`,`queue`,`state`,`priority`,`attempts`,`maxAttempts`,`createdAt`,`durationMs`])},children:[(0,b.jsx)(le,{className:`size-3.5`}),` Export CSV`]})}),I&&(0,b.jsx)(h,{onRetry:be,message:F?`Queue inventory refresh failed — showing the last successful queue totals. ${I.message}`:`Could not discover queues — ${I.message}. Select an existing queue from the URL or retry.`}),R&&(0,b.jsx)(h,{onRetry:xe,message:L?`Server-wide totals refresh failed — showing the last successful totals. ${R.message}`:`Server-wide job totals are unavailable — ${R.message}. The selected queue page may still be current.`}),(0,b.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4 xl:grid-cols-8`,children:[(0,b.jsx)(f,{label:`Total`,value:K&&q!=null?u(K.completed+q+K.waiting+K.prioritized+K.active+K.delayed+K[`waiting-children`]):`—`,hint:`all queues`,compact:!0}),(0,b.jsx)(f,{label:`Waiting`,value:Y(K?.waiting),tone:`amber`,hint:`standard priority`,compact:!0}),(0,b.jsx)(f,{label:`Prioritized`,value:Y(K?.prioritized),tone:`amber`,compact:!0}),(0,b.jsx)(f,{label:`Active`,value:Y(K?.active),tone:`blue`,compact:!0}),(0,b.jsx)(f,{label:`Flow-blocked`,value:Y(K?.[`waiting-children`]),tone:`blue`,compact:!0}),(0,b.jsx)(f,{label:`Completed`,value:Y(K?.completed),tone:`green`,compact:!0}),(0,b.jsx)(f,{label:`Failed`,value:q==null?`—`:u(q),tone:q!=null&&q>0?`red`:`default`,compact:!0}),(0,b.jsx)(f,{label:`Error Rate`,value:J==null?`—`:ae(J),tone:J==null?`default`:J>.05?`red`:`green`,compact:!0})]}),(0,b.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`w-48`,children:(0,b.jsx)(g,{value:a,"aria-label":`Queue`,name:`jobs-queue`,autoComplete:`off`,onChange:e=>{C(e.target.value),X(),we(e.target.value,w)},children:(F??[]).map(e=>(0,b.jsx)(`option`,{value:e.name,children:e.name},e.name))})}),(0,b.jsx)(`div`,{className:`w-48`,children:(0,b.jsx)(g,{"aria-label":`Job state`,name:`jobs-state`,value:w,onChange:e=>{let t=e.target.value;ge(t),X(),we(a,t)},children:x.map(e=>(0,b.jsx)(`option`,{value:e,children:e===`all`?`All states`:e},e))})}),(0,b.jsxs)(`div`,{className:`relative ml-auto min-w-56 flex-1 md:max-w-xs`,children:[(0,b.jsx)(c,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-faint`}),(0,b.jsx)(`input`,{value:T,onChange:e=>_e(e.target.value),placeholder:`Filter this page by ID…`,"aria-label":`Filter by job ID`,name:`jobs-id-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`})]})]}),O.size>0&&(0,b.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2 rounded-lg border border-line bg-surface-2 px-4 py-2 text-sm`,children:[(0,b.jsx)(`span`,{className:`mr-1 text-muted`,children:pe(Q.length,O.size)}),$.promote&&(0,b.jsx)(m,{size:`sm`,disabled:j,onClick:()=>Oe(`Promote`,e=>p.promoteJob(e.id),ke.promote),children:`Promote selected`}),!$.promote&&(0,b.jsx)(`span`,{className:`text-xs text-faint`,children:Q.length===0?`The selected jobs are hidden by the filter — clear it to act on them.`:`No actions apply to the selected job states.`})]}),N&&(0,b.jsx)(`div`,{role:`status`,className:t(`mb-3 text-sm`,N.ok?`text-success`:`text-danger`),children:N.text}),H&&W&&(0,b.jsx)(h,{message:`Job refresh failed — showing the last successful page.`,onRetry:U}),H&&!W?(0,b.jsx)(ce,{error:H,onRetry:U}):ye&&!F&&!a&&!I?(0,b.jsx)(l,{label:`Discovering queues…`}):Se&&!W?(0,b.jsx)(l,{label:`Loading jobs…`}):(0,b.jsxs)(b.Fragment,{children:[a&&(0,b.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm`,children:[(0,b.jsx)(`span`,{className:`text-faint`,children:`Jobs in queue`}),(0,b.jsx)(`span`,{className:`rounded-md bg-surface-2 px-2 py-0.5 font-mono text-xs text-fg`,children:a})]}),(0,b.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,b.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,b.jsx)(`thead`,{children:(0,b.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,b.jsx)(`th`,{scope:`col`,className:`w-10 px-5 py-3`,children:(0,b.jsx)(`input`,{type:`checkbox`,checked:Z,ref:e=>{e&&(e.indeterminate=O.size>0&&!Z)},"aria-checked":O.size>0&&!Z?`mixed`:Z,onChange:Ee,"aria-label":`Select all jobs on page`,className:`accent-accent`})}),(0,b.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Job ID`}),(0,b.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Status`}),(0,b.jsx)(`th`,{scope:`col`,className:`px-5 py-3 font-medium`,children:`Priority`}),(0,b.jsx)(`th`,{scope:`col`,className:`px-5 py-3 text-right font-medium`,children:`Created`}),(0,b.jsx)(`th`,{scope:`col`,className:`px-5 py-3 text-right font-medium`,children:`Duration`}),(0,b.jsx)(`th`,{scope:`col`,className:`w-28 px-5 py-3 text-right font-medium`,children:`Actions`})]})}),(0,b.jsx)(`tbody`,{children:G.length===0?(0,b.jsx)(`tr`,{children:(0,b.jsx)(`td`,{colSpan:7,className:`px-5 py-12 text-center text-sm text-faint`,children:T.trim()?`No jobs on this page match your ID filter.`:a?`No jobs found.`:I?`Queue discovery failed. Retry above.`:`Select a queue.`})}):G.map(e=>{let n=he(e.priority),r=v(e.state),a=j||ve.has(e.id);return(0,b.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,b.jsx)(`td`,{className:`px-5 py-3`,children:(0,b.jsx)(`input`,{type:`checkbox`,checked:O.has(e.id),onChange:()=>Te(e.id),"aria-label":`Select job ${e.id}`,className:`accent-accent`})}),(0,b.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-accent/90`,children:(0,b.jsx)(`span`,{className:`block max-w-[16rem] truncate`,title:e.id,children:e.id})}),(0,b.jsx)(`td`,{className:`px-5 py-3`,children:(0,b.jsx)(re,{status:String(e.state??`waiting`)})}),(0,b.jsx)(`td`,{className:t(`px-5 py-3 text-xs font-semibold`,n.c),children:n.t}),(0,b.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:ne(e.createdAt)}),(0,b.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:se(e.startedAt&&e.completedAt?e.completedAt-e.startedAt:void 0)}),(0,b.jsx)(`td`,{className:`px-5 py-3`,children:(0,b.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,b.jsx)(i,{to:`/job?id=${encodeURIComponent(e.id)}`,"aria-label":`Inspect job ${e.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,b.jsx)(s,{className:`size-3.5`})}),r.promote&&(0,b.jsx)(ee,{"aria-label":`Promote job`,disabled:a,onClick:()=>De(e,`Promote`,()=>p.promoteJob(e.id)),children:(0,b.jsx)(te,{className:`size-3.5`})})]})})]},e.id)})})]})}),(0,b.jsx)(ue,{page:E,pageSize:S,hasNext:Ce,onPageChange:D,label:`jobs`})]})]})}export{C as JobsPro};
@@ -0,0 +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,H as i,J as a,c as o,g as s,h as c,m as l,t as u,u as d,v as f,x as p}from"./index-Bn2R06qm.js";import{a as m,i as h}from"./form-DsUq0w8s.js";import{t as g}from"./Pagination-DpxiBnt8.js";import{discoverAllQueues as _}from"./Jobs-BUtcBKKk.js";var v=e(t(),1),y=n(),b=`__all__`,x=[`all`,`waiting`,`active`,`completed`,`failed`],S=10;async function C(){let e=await _();if(!Number.isFinite(e.timestamp)||e.queues.some(e=>!Number.isSafeInteger(e.waiting)||e.waiting<0||!Number.isSafeInteger(e.delayed)||e.delayed<0||!Number.isSafeInteger(e.active)||e.active<0||!Number.isSafeInteger(e.dlq)||e.dlq<0||typeof e.paused!=`boolean`))throw Error(`Queue discovery returned malformed queue summaries`);return e}function w(){let[e,t]=(0,v.useState)(b),[n,_]=(0,v.useState)(`all`),[w,T]=(0,v.useState)(``),[E,D]=(0,v.useState)(0),{data:O,error:k,refetch:A}=r(C,[],{intervalMs:3e4}),{events:j,counters:M,throughput:N,connected:P,error:F}=u(e===b?void 0:e),I=(0,v.useMemo)(()=>{let e=w.trim().toLowerCase();return j.filter(t=>n!==`all`&&t.status!==n?!1:!e||(t.jobId??``).toLowerCase().includes(e)||(t.name??``).toLowerCase().includes(e)||(t.queue??``).toLowerCase().includes(e))},[j,n,w]);(0,v.useEffect)(()=>D(0),[e,n,w]);let L=Math.max(1,Math.ceil(I.length/S)),R=Math.min(E,L-1);return(0,y.jsxs)(`div`,{children:[(0,y.jsx)(c,{title:`Activity Logs`,description:`Real-time job activity across all queues.`,live:P}),k&&(0,y.jsx)(p,{onRetry:A,message:`Could not discover queues — ${k.message}. The current stream can still be used.`}),F&&(0,y.jsx)(p,{message:`Event stream unavailable — ${F.message}. Retrying…`}),(0,y.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-6`,children:[(0,y.jsx)(l,{label:`Total Events`,value:o(M.total),compact:!0}),(0,y.jsx)(l,{label:`Completed`,value:o(M.completed),tone:`green`,compact:!0}),(0,y.jsx)(l,{label:`Failed`,value:o(M.failed),tone:M.failed?`red`:`default`,compact:!0}),(0,y.jsx)(l,{label:`Waiting`,value:o(M.waiting),tone:`amber`,compact:!0}),(0,y.jsx)(l,{label:`Active`,value:o(M.active),tone:`blue`,compact:!0}),(0,y.jsx)(l,{label:`Throughput`,value:`${N.toFixed(1)}/s`,tone:`accent`,compact:!0})]}),(0,y.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-3`,children:[(0,y.jsx)(`div`,{className:`w-48`,children:(0,y.jsxs)(m,{value:e,"aria-label":`Filter by queue`,name:`classic-activity-queue-filter`,autoComplete:`off`,onChange:e=>t(e.target.value),children:[(0,y.jsx)(`option`,{value:b,children:`All Queues`}),(O?.queues??[]).map(e=>(0,y.jsx)(`option`,{value:e.name,children:e.name},e.name))]})}),(0,y.jsx)(h,{options:x,value:n,onChange:_}),(0,y.jsxs)(`div`,{className:`relative ml-auto min-w-56 flex-1 md:max-w-xs`,children:[(0,y.jsx)(a,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-faint`}),(0,y.jsx)(`input`,{"aria-label":`Search by job name or ID`,name:`classic-activity-search`,autoComplete:`off`,value:w,onChange:e=>T(e.target.value),placeholder:`Search by job name or ID…`,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`})]})]}),I.length===0?(0,y.jsx)(f,{icon:(0,y.jsx)(i,{}),title:F?`Event stream unavailable`:P?`Waiting for activity…`:`Connecting to the event stream…`,hint:F?`${F.message}. The dashboard is retrying automatically.`:`Job events stream in here live as they happen on the server.`}):(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:`Status`}),(0,y.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Event`}),(0,y.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queue`}),(0,y.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Timestamp`}),(0,y.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`ID`})]})}),(0,y.jsx)(`tbody`,{children:I.slice(R*S,R*S+S).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`,children:(0,y.jsx)(s,{status:e.status})}),(0,y.jsx)(`td`,{className:`px-5 py-3 text-fg`,children:e.event||`job event`}),(0,y.jsx)(`td`,{className:`px-5 py-3`,children:(0,y.jsx)(`span`,{className:`rounded-md bg-surface-2 px-2 py-0.5 font-mono text-xs text-muted`,children:e.queue||`—`})}),(0,y.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:d(e.timestamp)}),(0,y.jsx)(`td`,{className:`px-5 py-3 text-right font-mono text-xs text-faint`,children:e.jobId||`—`})]},e.seq))})]})}),(0,y.jsx)(g,{page:R,pageSize:S,total:I.length,onPageChange:D,label:`events`})]})}export{w as Logs};
@@ -0,0 +1 @@
1
+ import{r as e}from"./cn-CMFYpumL.js";import{g as t,r as n,t as r}from"./react-vendor-Bjui4wS4.js";import{o as i}from"./connectionStore-Cd9-3Fw0.js";import{A as a,J as o,O as s,c,g as l,h as u,m as d,t as f,u as p,w as m,x as h}from"./index-Bn2R06qm.js";import{a as g,i as _}from"./form-DsUq0w8s.js";import{t as v}from"./Pagination-DpxiBnt8.js";import{loadAllQueuePages as y}from"./QueueControl-V0DJ6qk6.js";var b=e(t(),1),x=r(),S=`__all__`,C=[`all`,`waiting`,`active`,`completed`,`failed`],w=10,T=250;function E(){let[e,t]=(0,b.useState)(S),[r,E]=(0,b.useState)(`all`),[D,O]=(0,b.useState)(``),[k,A]=(0,b.useState)(0),[j,M]=(0,b.useState)(null),N=j!==null,P=i(t=>JSON.stringify([t.baseUrl,t.token,e])),{data:F,error:I,refetch:L}=a(y,[],{intervalMs:3e4}),{events:R,counters:z,throughput:B,connected:V,error:H}=f(e===S?void 0:e),U=(0,b.useMemo)(()=>{let e=j??R,t=D.trim().toLowerCase();return e.filter(e=>r!==`all`&&e.status!==r?!1:!t||(e.jobId??``).toLowerCase().includes(t)||(e.queue??``).toLowerCase().includes(t))},[R,j,r,D]),W=N?Math.max(0,(R[0]?.seq??0)-(j[0]?.seq??0)):0;(0,b.useEffect)(()=>A(0),[e,r,D]),(0,b.useEffect)(()=>M(null),[P]);let G=k*w,K=U.slice(G,G+w);return(0,x.jsxs)(`div`,{children:[(0,x.jsx)(u,{title:`Activity Logs`,description:`Real-time job activity across all queues.`,live:V&&!N}),I&&(0,x.jsx)(h,{onRetry:L,message:`Could not discover queues — ${I.message}. The current stream can still be used.`}),H&&(0,x.jsx)(h,{message:`Event stream unavailable — ${H.message}. Retrying…`}),(0,x.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-6`,children:[(0,x.jsx)(d,{label:`Total Events`,value:c(z.total),compact:!0}),(0,x.jsx)(d,{label:`Completed`,value:c(z.completed),tone:`green`,compact:!0}),(0,x.jsx)(d,{label:`Failed`,value:c(z.failed),tone:z.failed?`red`:`default`,compact:!0}),(0,x.jsx)(d,{label:`Waiting`,value:c(z.waiting),tone:`amber`,compact:!0}),(0,x.jsx)(d,{label:`Active`,value:c(z.active),tone:`blue`,compact:!0}),(0,x.jsx)(d,{label:`Throughput`,value:`${B.toFixed(1)}/s`,tone:`accent`,compact:!0})]}),(0,x.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-3`,children:[(0,x.jsx)(`div`,{className:`w-48`,children:(0,x.jsxs)(g,{"aria-label":`Filter by queue`,name:`activity-queue-filter`,autoComplete:`off`,value:e,onChange:e=>t(e.target.value),children:[(0,x.jsx)(`option`,{value:S,children:`All Queues`}),(F?.queues??[]).map(e=>(0,x.jsx)(`option`,{value:e.name,children:e.name},e.name))]})}),(0,x.jsx)(_,{options:C,value:r,onChange:E}),(0,x.jsx)(m,{size:`sm`,variant:N?`warning`:`default`,onClick:()=>M(N?null:R),title:N?`Resume applying live events to the list`:`Freeze the visible list while the stream keeps buffering`,children:N?`Resume${W?` — ${c(W)} new`:``}`:`Following · Pause`}),(0,x.jsxs)(`div`,{className:`relative ml-auto min-w-56 flex-1 md:max-w-xs`,children:[(0,x.jsx)(o,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-faint`}),(0,x.jsx)(`input`,{"aria-label":`Search by job ID or queue`,name:`activity-search`,autoComplete:`off`,value:D,onChange:e=>O(e.target.value),placeholder:`Search by job ID or queue…`,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,x.jsxs)(`p`,{className:`-mt-2 mb-4 text-xs text-faint`,children:[`Search and filters cover the last `,T,` streamed events held in this browser.`]}),(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:`Status`}),(0,x.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Event`}),(0,x.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Queue`}),(0,x.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Timestamp`}),(0,x.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`ID`})]})}),(0,x.jsx)(`tbody`,{children:K.length===0?(0,x.jsx)(`tr`,{children:(0,x.jsx)(`td`,{colSpan:5,className:`px-5 py-12 text-center text-sm text-faint`,children:H?`Event stream unavailable — ${H.message}. Retrying…`:V?R.length>0?`No events match the current filters.`:`Waiting for activity…`:`Connecting to the event stream…`})}):K.map(e=>(0,x.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,x.jsx)(`td`,{className:`px-5 py-3`,children:(0,x.jsx)(l,{status:e.status})}),(0,x.jsxs)(`td`,{className:`px-5 py-3 font-mono text-xs text-fg`,children:[e.event,e.status===`failed`&&e.error&&(0,x.jsx)(`div`,{className:`mt-0.5 max-w-64 truncate text-[11px] text-danger`,title:e.error,children:e.error})]}),(0,x.jsx)(`td`,{className:`px-5 py-3`,children:(0,x.jsx)(`span`,{className:`rounded-md bg-surface-2 px-2 py-0.5 font-mono text-xs text-muted`,children:e.queue||`—`})}),(0,x.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,title:new Date(e.timestamp).toISOString(),children:p(e.timestamp)}),(0,x.jsx)(`td`,{className:`px-5 py-3 text-right font-mono text-xs text-faint`,children:e.jobId?(0,x.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,x.jsx)(n,{to:`/job?id=${encodeURIComponent(e.jobId)}`,className:`text-accent hover:underline`,children:e.jobId}),(0,x.jsx)(s,{value:e.jobId})]}):`—`})]},e.seq))})]})}),(0,x.jsx)(v,{page:k,pageSize:w,total:U.length,onPageChange:A,label:`events`})]})}export{E as LogsPro};
@@ -0,0 +1,22 @@
1
+ import{t as e}from"./react-vendor-Bjui4wS4.js";import{C as t,O as n,S as r,h as i,m as a}from"./index-Bn2R06qm.js";var o=e(),s=`{
2
+ "mcpServers": {
3
+ "bunqueue": {
4
+ "command": "bunx",
5
+ "args": ["--package=bunqueue", "bunqueue-mcp"],
6
+ "env": { "DATA_PATH": "./data/bunq.db" }
7
+ }
8
+ }
9
+ }`,c=`{
10
+ "mcpServers": {
11
+ "bunqueue": {
12
+ "command": "bunx",
13
+ "args": ["--package=bunqueue", "bunqueue-mcp"],
14
+ "env": {
15
+ "BUNQUEUE_MODE": "tcp",
16
+ "BUNQUEUE_HOST": "localhost",
17
+ "BUNQUEUE_PORT": "6789",
18
+ "BUNQUEUE_TOKEN": "your-token"
19
+ }
20
+ }
21
+ }
22
+ }`,l=`claude mcp add bunqueue -- bunx --package=bunqueue bunqueue-mcp`,u=[{name:`Jobs`,count:11,examples:[`add_job`,`get_job`,`get_jobs`,`get_job_result`,`wait_for_job`]},{name:`Job management`,count:6,examples:[`cancel_job`,`change_job_priority`,`promote_job`,`update_job_data`]},{name:`Consumption`,count:8,examples:[`pull_job`,`pull_job_batch`,`ack_job`,`fail_job`,`job_heartbeat`]},{name:`Queues`,count:11,examples:[`list_queues`,`pause_queue`,`resume_queue`,`drain_queue`,`obliterate_queue`]},{name:`Dead letter queue`,count:4,examples:[`get_dlq`,`retry_dlq`,`purge_dlq`]},{name:`Cron`,count:4,examples:[`add_cron`,`list_crons`,`get_cron`,`delete_cron`]},{name:`Flows`,count:4,examples:[`add_flow`,`add_flow_chain`,`get_flow`,`get_children_values`]},{name:`Rate limits`,count:4,examples:[`set_rate_limit`,`set_concurrency`,`clear_rate_limit`]},{name:`Webhooks`,count:4,examples:[`add_webhook`,`list_webhooks`,`remove_webhook`,`set_webhook_enabled`]},{name:`Workers`,count:3,examples:[`register_worker`,`list_workers`,`worker_heartbeat`]},{name:`Handlers`,count:3,examples:[`register_handler`,`list_handlers`,`unregister_handler`]},{name:`Monitoring`,count:11,examples:[`get_stats`,`get_queue_stats`,`get_memory_stats`,`get_prometheus_metrics`]}],d=[`bunqueue://queues`,`bunqueue://stats`,`bunqueue://workers`,`bunqueue://crons`,`bunqueue://webhooks`],f=[`bunqueue_debug_queue`,`bunqueue_health_report`,`bunqueue_incident_response`],p=u.reduce((e,t)=>e+t.count,0);function m({code:e}){return(0,o.jsxs)(`div`,{className:`relative min-w-0 max-w-full`,children:[(0,o.jsx)(`div`,{className:`absolute right-2 top-2`,children:(0,o.jsx)(n,{value:e})}),(0,o.jsx)(`pre`,{className:`max-w-full overflow-x-auto overscroll-x-contain rounded-lg border border-line bg-surface-2 p-4 pr-12 font-mono text-xs leading-relaxed text-fg`,children:e})]})}function h({children:e}){return(0,o.jsx)(`span`,{className:`max-w-full break-all rounded-md border border-line bg-surface-2 px-1.5 py-0.5 font-mono text-[11px] text-muted`,children:e})}function g(){return(0,o.jsxs)(`div`,{className:`min-w-0 overflow-x-hidden`,children:[(0,o.jsx)(i,{title:`MCP Server`,description:`Connect bunqueue to AI agents (Claude Desktop, Claude Code) over the Model Context Protocol.`,actions:(0,o.jsx)(`a`,{href:`https://egeominotti.github.io/bunqueue-dashboard/docs/guide/mcp`,target:`_blank`,rel:`noopener noreferrer`,className:`rounded-lg border border-line px-3 py-1.5 text-sm text-muted hover:bg-surface-2 hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,children:`Docs`})}),(0,o.jsxs)(r,{className:`mb-6`,children:[(0,o.jsxs)(`p`,{className:`text-sm leading-relaxed text-muted`,children:[`bunqueue ships a Model Context Protocol server,`,` `,(0,o.jsx)(`span`,{className:`font-mono text-fg`,children:`bunqueue-mcp`}),`, that lets an AI agent drive the queue with tools, resources, and prompts. It is a separate`,` `,(0,o.jsx)(`span`,{className:`text-fg`,children:`stdio`}),` process, launched by the MCP client (not by this dashboard, and not part of the HTTP API), so this page is a setup and reference guide rather than a live monitor. It needs the optional peer dependency`,` `,(0,o.jsx)(`span`,{className:`font-mono text-fg`,children:`@modelcontextprotocol/sdk`}),`.`]}),(0,o.jsx)(`p`,{className:`mt-3 text-sm leading-relaxed text-warning`,children:`The upstream MCP includes destructive Cancel, Discard, Drain, Obliterate, DLQ Retry and DLQ Purge tools. They bypass this dashboard's v2.8.55 flow-safety gates and have no atomic reverse-dependency or job-generation precondition. Grant MCP write access only after independently proving the workload is not flow-linked.`})]}),(0,o.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 sm:grid-cols-4`,children:[(0,o.jsx)(a,{label:`Tools`,value:String(p)}),(0,o.jsx)(a,{label:`Categories`,value:String(u.length)}),(0,o.jsx)(a,{label:`Resources`,value:String(d.length)}),(0,o.jsx)(a,{label:`Prompts`,value:String(f.length)})]}),(0,o.jsxs)(`div`,{className:`mb-6 grid gap-4 lg:grid-cols-2`,children:[(0,o.jsxs)(r,{className:`min-w-0`,children:[(0,o.jsx)(t,{title:`Embedded mode (default)`}),(0,o.jsxs)(`p`,{className:`mb-3 text-sm text-muted`,children:[`Direct SQLite access, no running server. Point `,(0,o.jsx)(h,{children:`DATA_PATH`}),` at the bunqueue database file. Best for a local agent on the same machine.`]}),(0,o.jsx)(m,{code:s})]}),(0,o.jsxs)(r,{className:`min-w-0`,children:[(0,o.jsx)(t,{title:`TCP mode (remote server)`}),(0,o.jsxs)(`p`,{className:`mb-3 text-sm text-muted`,children:[`Connect to a running bunqueue server over its TCP protocol port (`,(0,o.jsx)(h,{children:`6789`}),`, distinct from the HTTP admin API on 6790). Use a `,(0,o.jsx)(h,{children:`BUNQUEUE_TOKEN`}),` if the server has one.`]}),(0,o.jsx)(m,{code:c})]})]}),(0,o.jsxs)(r,{className:`mb-6`,children:[(0,o.jsx)(t,{title:`Where to put it`}),(0,o.jsxs)(`p`,{className:`mb-3 text-sm text-muted`,children:[`Add the JSON above to your MCP client config (for Claude Desktop, its`,` `,(0,o.jsx)(`span`,{className:`font-mono text-fg`,children:`claude_desktop_config.json`}),`). For Claude Code, register it from the CLI:`]}),(0,o.jsx)(m,{code:l})]}),(0,o.jsxs)(r,{className:`mb-6`,children:[(0,o.jsx)(t,{title:`Tools`,action:(0,o.jsxs)(`span`,{className:`text-xs text-faint`,children:[p,` total`]})}),(0,o.jsx)(`div`,{className:`grid gap-x-6 gap-y-4 sm:grid-cols-2 lg:grid-cols-3`,children:u.map(e=>(0,o.jsxs)(`div`,{children:[(0,o.jsxs)(`div`,{className:`mb-1.5 flex items-baseline justify-between gap-2`,children:[(0,o.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:e.name}),(0,o.jsx)(`span`,{className:`text-xs text-faint`,children:e.count})]}),(0,o.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.examples.map(e=>(0,o.jsx)(h,{children:e},e))})]},e.name))}),(0,o.jsxs)(`p`,{className:`mt-4 text-xs text-faint`,children:[`Every tool name is prefixed `,(0,o.jsx)(`span`,{className:`font-mono`,children:`bunqueue_`}),` (examples above drop it). Counts total `,p,`.`]})]}),(0,o.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,o.jsxs)(r,{children:[(0,o.jsx)(t,{title:`Resources`,action:(0,o.jsx)(`span`,{className:`text-xs text-faint`,children:d.length})}),(0,o.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:d.map(e=>(0,o.jsx)(h,{children:e},e))})]}),(0,o.jsxs)(r,{children:[(0,o.jsx)(t,{title:`Prompts`,action:(0,o.jsx)(`span`,{className:`text-xs text-faint`,children:f.length})}),(0,o.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:f.map(e=>(0,o.jsx)(h,{children:e},e))})]})]})]})}export{g as McpServer};
@@ -0,0 +1 @@
1
+ import{t as e}from"./react-vendor-Bjui4wS4.js";import{A as t,C as n,S as r,b as i,c as a,h as o,j as s,m as c,r as l,x as u,y as d}from"./index-Bn2R06qm.js";var f=e(),p={ok:!1,stats:{waiting:0,active:0,delayed:0,completed:0,dlq:0,totalPushed:0,totalPulled:0,totalCompleted:0,totalFailed:0,uptime:0},throughput:{pushPerSec:0,pullPerSec:0,completePerSec:0,failPerSec:0},latency:{averages:{},percentiles:{}},memory:{heapUsed:0,heapTotal:0,rss:0},collections:{},workers:{total:0,active:0,list:[],truncated:!1},crons:{total:0,list:[],truncated:!1},storage:{},timestamp:0};function m(){let{data:e,error:m,loading:_,refetch:v}=t(()=>s.overview(),[]);if(_&&!e&&!m)return(0,f.jsx)(i,{label:`Loading metrics…`});if(m&&!e)return(0,f.jsxs)(`div`,{children:[(0,f.jsx)(o,{title:`Metrics`,description:`Throughput, latency, and resource internals.`}),(0,f.jsx)(d,{error:m,onRetry:v})]});let{stats:y,throughput:b,latency:x,memory:S,collections:C}=e??p,w={};for(let[e,t]of Object.entries(x.percentiles??{}))t&&typeof t==`object`&&(w[`${e} p50`]=t.p50,w[`${e} p95`]=t.p95,w[`${e} p99`]=t.p99);return(0,f.jsxs)(`div`,{children:[m&&(0,f.jsx)(u,{message:`Metrics refresh failed — showing the last successful snapshot.`,onRetry:v}),(0,f.jsx)(o,{title:`Metrics`,description:`Throughput, latency, and resource internals.`,live:!!e&&!m}),(0,f.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,f.jsx)(c,{label:`Pushed /s`,value:b.pushPerSec.toFixed(1),compact:!0}),(0,f.jsx)(c,{label:`Pulled /s`,value:b.pullPerSec.toFixed(1),tone:`blue`,compact:!0}),(0,f.jsx)(c,{label:`Completed /s`,value:b.completePerSec.toFixed(1),tone:`green`,compact:!0}),(0,f.jsx)(c,{label:`Failed /s`,value:b.failPerSec.toFixed(1),tone:`red`,compact:!0})]}),(0,f.jsxs)(`div`,{className:`mt-6 grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,f.jsxs)(r,{children:[(0,f.jsx)(n,{title:`Totals`}),(0,f.jsx)(h,{rows:[[`Pushed`,a(y.totalPushed)],[`Pulled`,a(y.totalPulled)],[`Completed`,a(y.totalCompleted)],[`Failed`,a(y.totalFailed)]]})]}),(0,f.jsxs)(r,{children:[(0,f.jsx)(n,{title:`Memory`}),(0,f.jsx)(h,{rows:[[`Heap Used`,l(S.heapUsed*1024*1024)],[`Heap Total`,l(S.heapTotal*1024*1024)],[`RSS`,l(S.rss*1024*1024)]]})]}),(0,f.jsxs)(r,{children:[(0,f.jsx)(n,{title:`Latency — percentiles (ms)`}),(0,f.jsx)(g,{record:w,suffix:`ms`})]}),(0,f.jsxs)(r,{children:[(0,f.jsx)(n,{title:`Latency — averages (ms)`}),(0,f.jsx)(g,{record:x.averages,suffix:`ms`})]})]}),(0,f.jsx)(`div`,{className:`mt-6`,children:(0,f.jsxs)(r,{children:[(0,f.jsx)(n,{title:`In-memory collections`}),(0,f.jsx)(g,{record:C})]})})]})}function h({rows:e}){return(0,f.jsx)(`div`,{className:`grid grid-cols-2 gap-4 sm:grid-cols-4`,children:e.map(([e,t])=>(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:e}),(0,f.jsx)(`div`,{className:`mt-1 text-xl font-semibold tnum text-fg`,children:t})]},e))})}function g({record:e,suffix:t}){let n=Object.entries(e??{});return n.length===0?(0,f.jsx)(`p`,{className:`py-4 text-sm text-faint`,children:`No data.`}):(0,f.jsx)(`dl`,{className:`divide-y divide-line`,children:n.map(([e,n])=>(0,f.jsxs)(`div`,{className:`flex items-center justify-between py-2 text-sm`,children:[(0,f.jsx)(`dt`,{className:`font-mono text-xs text-muted`,children:e}),(0,f.jsxs)(`dd`,{className:`tnum font-medium text-fg`,children:[typeof n==`number`?a(Math.round(n*100)/100):String(n),t&&(0,f.jsx)(`span`,{className:`ml-1 text-xs text-faint`,children:t})]})]},e))})}export{m as Metrics};
@@ -0,0 +1 @@
1
+ import{r as e,t}from"./cn-CMFYpumL.js";import{g as n,t as r}from"./react-vendor-Bjui4wS4.js";import{A as i,C as a,S as o,b as s,c,d as l,h as u,i as d,l as f,m as p,n as m,st as h,v as g,x as _}from"./index-Bn2R06qm.js";import{t as v}from"./Pagination-DpxiBnt8.js";import{t as y}from"./AreaChart-REK4ZsTC.js";import{n as b,t as x}from"./useThroughputSeries-tb26_lkb.js";var S=e(n(),1),C=r(),w=[`-60s`,`-45s`,`-30s`,`-15s`,`now`],T=15,E=[`push`,`pull`,`ack`],D=100;function O(){let e=b(60),[n,r]=(0,S.useState)(0),{data:O,error:M,loading:N,refetch:P}=i(async()=>({details:await h.queuesSummary()}),[]),F=O?.details??[],I=Math.max(1,Math.ceil(F.length/T)),L=Math.min(n,I-1),R=(0,S.useMemo)(()=>F.slice(L*T,L*T+T),[F,L]),z=(0,S.useMemo)(()=>O?F.reduce((e,t)=>e+(t.counts?.failed??0),0):null,[O,F]),B=e.latest?.stats,V=e.latest?.throughput,H=e.latest?.latency,U=B&&z!=null?m(B.completed,z):null,W=x(e.depth),G=e.depth.length?e.depth[e.depth.length-1]:null,K=!e.latest&&!e.error,q=N&&!O&&!M;return(0,C.jsxs)(`div`,{children:[(0,C.jsx)(u,{title:`Metrics`,description:`Real-time performance telemetry for your queues.`,live:!!e.latest&&!e.error&&!!O&&!M}),M&&(0,C.jsx)(_,{message:`Queue metrics unavailable — ${M.message}`,onRetry:P}),e.error&&(0,C.jsx)(_,{message:`Live telemetry unavailable — ${e.error.message}. Reconnecting automatically.`}),q&&(0,C.jsx)(`div`,{role:`status`,className:`mb-4 text-sm text-muted`,children:`Loading per-queue metrics…`}),K&&(0,C.jsx)(`div`,{role:`status`,className:`mb-4 text-sm text-muted`,children:`Connecting live telemetry…`}),(0,C.jsxs)(`div`,{className:`mb-6 grid grid-cols-2 gap-4 md:grid-cols-4`,children:[(0,C.jsx)(p,{label:`Total Completed`,value:B?d(B.completed):`—`,tone:`green`,hint:`recorded jobs`}),(0,C.jsx)(p,{label:`Total Failed`,value:z==null?`—`:c(z),tone:z?`red`:`default`,hint:`recorded jobs`}),(0,C.jsx)(p,{label:`Push/sec`,value:V?V.pushPerSec.toFixed(1):`—`,tone:`accent`,hint:`jobs/sec`}),(0,C.jsx)(p,{label:`Pull/sec`,value:V?V.pullPerSec.toFixed(1):`—`,tone:`accent`,hint:`jobs/sec`})]}),(0,C.jsxs)(o,{className:`mb-6`,children:[(0,C.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-start justify-between gap-3`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{className:`text-base font-semibold text-fg`,children:`Live Throughput`}),(0,C.jsx)(`p`,{className:`text-xs text-faint`,children:`Real-time jobs per second (rolling 60s window)`})]}),V&&(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 font-mono text-[11px] text-faint`,children:[(0,C.jsx)(A,{color:`#ec4899`,label:`Pushed`,value:V.pushPerSec}),(0,C.jsx)(A,{color:`#34d399`,label:`Completed`,value:V.completePerSec}),(0,C.jsx)(A,{color:`#f87171`,label:`Failed`,value:V.failPerSec})]})]}),e.latest?(0,C.jsx)(y,{xLabels:w,series:[{label:`Pushed`,color:`#ec4899`,points:e.push,area:!0},{label:`Completed`,color:`#34d399`,points:e.complete},{label:`Failed`,color:`#f87171`,points:e.fail}]}):e.error?(0,C.jsx)(g,{title:`Live throughput unavailable`,hint:e.error.message}):(0,C.jsx)(s,{label:`Connecting live throughput…`})]}),(0,C.jsxs)(o,{className:`mb-6`,children:[(0,C.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-start justify-between gap-3`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h2`,{className:`text-base font-semibold text-fg`,children:`Queue Depth`}),(0,C.jsx)(`p`,{className:`text-xs text-faint`,children:`All non-terminal jobs over time (waiting + prioritized + active + delayed + waiting-children). The trend says whether you're draining or falling behind.`})]}),(0,C.jsxs)(`div`,{className:`text-right`,children:[(0,C.jsx)(`div`,{className:`tnum text-2xl font-bold text-fg`,children:G==null?`—`:c(G)}),(0,C.jsx)(`div`,{className:t(`text-xs font-medium`,W.label===`draining`?`text-success`:W.label===`accumulating`?`text-danger`:`text-faint`),children:G==null?`unavailable`:W.label===`steady`?`steady`:`${W.slope>0?`+`:``}${W.slope.toFixed(1)}/s · ${W.label}`})]})]}),e.latest?(0,C.jsx)(y,{xLabels:w,ariaLabel:`queue depth chart`,series:[{label:`Depth`,color:W.draining?`#34d399`:`#f59e0b`,points:e.depth,area:!0}]}):e.error?(0,C.jsx)(g,{title:`Queue depth unavailable`,hint:e.error.message}):(0,C.jsx)(s,{label:`Connecting queue depth…`})]}),(0,C.jsxs)(`div`,{className:`mb-6 grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,C.jsxs)(o,{children:[(0,C.jsx)(a,{title:`Error Rate`}),(0,C.jsx)(`p`,{className:`-mt-3 mb-4 text-xs text-faint`,children:`Failed as percentage of total processed`}),(0,C.jsxs)(`div`,{className:`flex items-center justify-around`,children:[(0,C.jsxs)(`div`,{className:`text-center`,children:[(0,C.jsx)(`div`,{className:t(`text-3xl font-bold tnum`,U!=null&&U>.05?`text-danger`:`text-fg`),children:U==null?`—`:f(U)}),(0,C.jsx)(`div`,{className:`text-xs text-faint`,children:`error rate`})]}),(0,C.jsxs)(`div`,{className:`text-center`,children:[(0,C.jsx)(`div`,{className:t(`text-3xl font-bold tnum`,U==null?`text-fg`:`text-success`),children:U==null?`—`:f(1-U)}),(0,C.jsx)(`div`,{className:`text-xs text-faint`,children:`success rate`})]})]}),U==null?(0,C.jsx)(`div`,{className:`mt-4 h-2 overflow-hidden rounded-full bg-surface-2`}):(0,C.jsx)(`div`,{className:`mt-4 h-2 overflow-hidden rounded-full bg-red-500/40`,children:(0,C.jsx)(`div`,{className:`h-full rounded-full bg-emerald-500`,style:{width:`${(1-U)*100}%`}})})]}),(0,C.jsxs)(o,{children:[(0,C.jsx)(a,{title:`Server Overview`}),(0,C.jsx)(`p`,{className:`-mt-3 mb-4 text-xs text-faint`,children:`Current server-wide statistics`}),(0,C.jsxs)(`dl`,{className:`divide-y divide-line text-sm`,children:[(0,C.jsx)(j,{color:`bg-blue-400`,label:`Standard waiting`,value:B?c(B.waiting):`—`}),(0,C.jsx)(j,{color:`bg-accent`,label:`Processing`,value:B?c(B.active):`—`}),(0,C.jsx)(j,{color:`bg-amber-400`,label:`Delayed`,value:B?c(B.delayed):`—`}),(0,C.jsx)(j,{color:`bg-red-400`,label:`Dead Letter`,value:B?c(B.dlq):`—`}),(0,C.jsx)(j,{color:`bg-zinc-500`,label:`Pushed (since restart)`,value:B?d(B.totalPushed):`—`}),(0,C.jsx)(j,{color:`bg-zinc-500`,label:`Pulled (since restart)`,value:B?d(B.totalPulled):`—`}),(0,C.jsx)(j,{color:`bg-emerald-400`,label:`Uptime`,value:B?l(B.uptime/1e3):`—`})]})]})]}),(0,C.jsxs)(o,{className:`mb-6`,padded:!1,children:[(0,C.jsxs)(`div`,{className:`border-b border-line px-5 py-4`,children:[(0,C.jsx)(`h2`,{className:`text-base font-semibold text-fg`,children:`Operation Latency`}),(0,C.jsx)(`p`,{className:`text-xs text-faint`,children:`TCP round-trip per operation (p50 / p95 / p99, milliseconds)`})]}),(0,C.jsx)(`div`,{className:`overflow-x-auto`,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`,{className:`px-5 py-3 font-medium`,children:`Operation`}),(0,C.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Avg`}),(0,C.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`p50`}),(0,C.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`p95`}),(0,C.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`p99`})]})}),(0,C.jsx)(`tbody`,{children:E.map(e=>{let n=H?.percentiles?.[e],r=H?.averages?.[`${e}Ms`];return(0,C.jsxs)(`tr`,{className:`border-b border-line last:border-0`,children:[(0,C.jsx)(`td`,{className:`px-5 py-3 font-medium capitalize text-fg`,children:e}),(0,C.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:k(r)}),(0,C.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:k(n?.p50)}),(0,C.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:k(n?.p95)}),(0,C.jsx)(`td`,{className:t(`px-5 py-3 text-right tnum`,(n?.p99??0)>D?`text-warning`:`text-muted`),children:k(n?.p99)})]},e)})})]})})]}),(0,C.jsxs)(o,{padded:!1,children:[(0,C.jsxs)(`div`,{className:`border-b border-line px-5 py-4`,children:[(0,C.jsx)(`h2`,{className:`text-base font-semibold text-fg`,children:`Per-Queue Metrics`}),(0,C.jsx)(`p`,{className:`text-xs text-faint`,children:`Job counts breakdown by queue`})]}),(0,C.jsx)(`div`,{className:`overflow-x-auto`,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`,{className:`px-5 py-3 font-medium`,children:`Queue`}),(0,C.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Status`}),(0,C.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Waiting`}),(0,C.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Prioritized`}),(0,C.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Active`}),(0,C.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Completed`}),(0,C.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Failed`})]})}),(0,C.jsx)(`tbody`,{children:R.length===0?(0,C.jsx)(`tr`,{children:(0,C.jsx)(`td`,{colSpan:7,className:`px-5 py-12 text-center text-sm text-faint`,children:M&&!O?`Queue metrics unavailable — ${M.message}`:q?`Loading queue metrics…`:`No queues yet.`})}):R.map(e=>(0,C.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,C.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs text-accent`,children:e.name}),(0,C.jsx)(`td`,{className:`px-5 py-3`,children:(0,C.jsx)(`span`,{className:t(`rounded-full px-2 py-0.5 text-[11px] font-medium`,e.paused?`bg-orange-500/10 text-orange-400`:`bg-emerald-500/10 text-success`),children:e.paused?`paused`:`active`})}),(0,C.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-warning`,children:c(e.counts.waiting)}),(0,C.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-orange-400`,children:c(e.counts.prioritized)}),(0,C.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-blue-400`,children:c(e.counts.active)}),(0,C.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-success`,children:c(e.counts.completed)}),(0,C.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-danger`,children:c(e.counts.failed)})]},e.name))})]})}),(0,C.jsx)(`div`,{className:`px-5 pb-4`,children:(0,C.jsx)(v,{page:L,pageSize:T,total:F.length,onPageChange:r,label:`queues`})})]})]})}function k(e){return e==null||!Number.isFinite(e)?`—`:`${e<10?e.toFixed(1):Math.round(e)}ms`}function A({color:e,label:t,value:n}){return(0,C.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,C.jsx)(`span`,{className:`size-2 rounded-full`,style:{background:e}}),t,` `,(0,C.jsxs)(`span`,{className:`text-fg`,children:[n.toFixed(1),`/s`]})]})}function j({color:e,label:n,value:r}){return(0,C.jsxs)(`div`,{className:`flex items-center justify-between py-2.5`,children:[(0,C.jsxs)(`dt`,{className:`flex items-center gap-2 text-muted`,children:[(0,C.jsx)(`span`,{className:t(`size-2 rounded-full`,e)}),n]}),(0,C.jsx)(`dd`,{className:`font-semibold tnum text-fg`,children:r})]})}export{O as MetricsPro};
@@ -0,0 +1 @@
1
+ import{t as e}from"./react-vendor-Bjui4wS4.js";import{A as t,C as n,L as r,S as i,X as a,b as o,c as s,d as c,h as l,j as u,l as d,m as f,n as p,r as m,x as h,y as g}from"./index-Bn2R06qm.js";var _=e(),v={ok:!1,stats:{waiting:0,active:0,delayed:0,completed:0,dlq:0,totalPushed:0,totalPulled:0,totalCompleted:0,totalFailed:0,uptime:0},throughput:{pushPerSec:0,pullPerSec:0,completePerSec:0,failPerSec:0},latency:{averages:{},percentiles:{}},memory:{heapUsed:0,heapTotal:0,rss:0},collections:{},workers:{total:0,active:0,list:[],truncated:!1},crons:{total:0,list:[],truncated:!1},storage:{},timestamp:0};function y(){let{data:e,error:y,loading:S,refetch:C}=t(()=>u.overview(),[]);if(S&&!e&&!y)return(0,_.jsx)(o,{label:`Loading overview…`});if(y&&!e)return(0,_.jsxs)(`div`,{children:[(0,_.jsx)(l,{title:`Overview`,description:`Live health and throughput across all queues.`}),(0,_.jsx)(g,{error:y,onRetry:C})]});let{stats:w,throughput:T,memory:E,workers:D,crons:O,storage:k}=e??v,A=p(w.totalCompleted,w.totalFailed)??0,j=typeof k.diskFull==`boolean`;return(0,_.jsxs)(`div`,{children:[y&&(0,_.jsx)(h,{message:`Connection lost — showing the last successful overview snapshot.`,onRetry:C}),(0,_.jsx)(l,{title:`Overview`,description:`Live health and throughput across all queues.`,live:!!e&&!y&&j}),(0,_.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-6`,children:[(0,_.jsx)(f,{label:`Waiting`,value:s(w.waiting),tone:`amber`}),(0,_.jsx)(f,{label:`Active`,value:s(w.active),tone:`blue`}),(0,_.jsx)(f,{label:`Completed`,value:s(w.totalCompleted),tone:`green`}),(0,_.jsx)(f,{label:`Failed`,value:s(w.totalFailed),tone:`red`}),(0,_.jsx)(f,{label:`DLQ`,value:s(w.dlq),tone:w.dlq>0?`red`:`default`}),(0,_.jsx)(f,{label:`Error Rate`,value:d(A),tone:A>.05?`red`:`green`})]}),(0,_.jsxs)(`div`,{className:`mt-6 grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,_.jsxs)(i,{children:[(0,_.jsx)(n,{title:`Throughput`}),(0,_.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 sm:grid-cols-4`,children:[(0,_.jsx)(b,{label:`Pushed`,value:T.pushPerSec,tone:`text-fg`}),(0,_.jsx)(b,{label:`Pulled`,value:T.pullPerSec,tone:`text-blue-400`}),(0,_.jsx)(b,{label:`Completed`,value:T.completePerSec,tone:`text-emerald-400`}),(0,_.jsx)(b,{label:`Failed`,value:T.failPerSec,tone:`text-red-400`})]})]}),(0,_.jsxs)(i,{children:[(0,_.jsx)(n,{title:`Resources`}),(0,_.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 sm:grid-cols-4`,children:[(0,_.jsx)(x,{label:`Uptime`,value:c(w.uptime/1e3)}),(0,_.jsx)(x,{label:`Heap`,value:m(E.heapUsed*1024*1024)}),(0,_.jsx)(x,{label:`RSS`,value:m(E.rss*1024*1024)}),(0,_.jsx)(x,{label:`Storage`,value:j?k.diskFull?`Disk full`:`Healthy`:`Unavailable`,tone:j?k.diskFull?`text-red-400`:`text-emerald-400`:`text-muted`})]})]})]}),(0,_.jsxs)(`div`,{className:`mt-6 grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,_.jsxs)(i,{children:[(0,_.jsx)(n,{title:`Workers`,icon:(0,_.jsx)(a,{className:`size-4 text-faint`}),action:(0,_.jsxs)(`span`,{className:`text-sm text-muted`,children:[(0,_.jsx)(`span`,{className:`font-semibold text-emerald-400`,children:D.active}),` /`,` `,D.total,` active`]})}),D.list.length===0?(0,_.jsx)(`p`,{className:`py-6 text-center text-sm text-faint`,children:`No workers registered.`}):(0,_.jsx)(`ul`,{className:`divide-y divide-line`,children:D.list.slice(0,6).map(e=>(0,_.jsxs)(`li`,{className:`flex items-center justify-between py-2 text-sm`,children:[(0,_.jsx)(`span`,{className:`truncate font-medium text-fg`,children:e.name||e.id}),(0,_.jsxs)(`span`,{className:`text-xs text-faint`,children:[e.queues.join(`, `)||`—`,` · `,s(e.processedJobs),` done`]})]},e.id))})]}),(0,_.jsxs)(i,{children:[(0,_.jsx)(n,{title:`Cron Jobs`,icon:(0,_.jsx)(r,{className:`size-4 text-faint`}),action:(0,_.jsxs)(`span`,{className:`text-sm text-muted`,children:[O.total,` scheduled`]})}),O.list.length===0?(0,_.jsx)(`p`,{className:`py-6 text-center text-sm text-faint`,children:`No cron jobs.`}):(0,_.jsx)(`ul`,{className:`divide-y divide-line`,children:O.list.slice(0,6).map(e=>(0,_.jsxs)(`li`,{className:`flex items-center justify-between py-2 text-sm`,children:[(0,_.jsx)(`span`,{className:`truncate font-medium text-fg`,children:e.name}),(0,_.jsx)(`span`,{className:`font-mono text-xs text-faint`,children:e.schedule??(e.repeatEvery?`every ${e.repeatEvery}ms`:`—`)})]},e.name))})]})]})]})}function b({label:e,value:t,tone:n}){return(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:e}),(0,_.jsxs)(`div`,{className:`mt-1 text-2xl font-semibold tnum ${n}`,children:[t.toFixed(1),(0,_.jsx)(`span`,{className:`ml-0.5 text-sm font-normal text-faint`,children:`/s`})]})]})}function x({label:e,value:t,tone:n=`text-fg`}){return(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-faint`,children:e}),(0,_.jsx)(`div`,{className:`mt-1 text-base font-semibold ${n}`,children:t})]})}export{y as Overview};
@@ -1 +1 @@
1
- import{r as e}from"./cn-CMFYpumL.js";import{h as t,t as n}from"./react-vendor-BcouBxpZ.js";import{c as r}from"./index-BOcegTHa.js";var i=e(t(),1),a=n();function o({page:e,pageSize:t,total:n,hasNext:o,onPageChange:s,label:c=`items`,className:l}){let u=n!=null,d=u?Math.max(1,Math.ceil(n/t)):void 0;(0,i.useEffect)(()=>{u&&e>d-1&&s(d-1)},[u,e,d,s]);let f=u?Math.min(e,d-1):e,p=f*t,m=f>0,h=u?f<d-1:!!o;if(u&&n<=t&&f===0)return null;let g=u?n===0?`No ${c}`:`${r(p+1)}–${r(Math.min(p+t,n))} of ${r(n)} ${c}`:`Page ${f+1}`;return(0,a.jsxs)(`div`,{className:`mt-4 flex items-center justify-between text-sm text-faint ${l??``}`,children:[(0,a.jsx)(`span`,{children:g}),(0,a.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,a.jsx)(`button`,{type:`button`,disabled:!m,onClick:()=>s(f-1),className:`rounded-md px-3 py-1 text-xs hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 disabled:opacity-40 disabled:hover:text-faint`,children:`Previous`}),(0,a.jsx)(`span`,{className:`rounded-md bg-accent/15 px-2.5 py-1 text-xs font-medium text-accent tnum`,children:u?`${f+1} / ${d}`:f+1}),(0,a.jsx)(`button`,{type:`button`,disabled:!h,onClick:()=>s(f+1),className:`rounded-md px-3 py-1 text-xs hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 disabled:opacity-40 disabled:hover:text-faint`,children:`Next`})]})]})}export{o as t};
1
+ import{r as e}from"./cn-CMFYpumL.js";import{g as t,t as n}from"./react-vendor-Bjui4wS4.js";import{c as r}from"./index-Bn2R06qm.js";var i=e(t(),1),a=n();function o({page:e,pageSize:t,total:n,hasNext:o,onPageChange:s,label:c=`items`,className:l}){let u=n!=null,d=u?Math.max(1,Math.ceil(n/t)):void 0;(0,i.useEffect)(()=>{u&&e>d-1&&s(d-1)},[u,e,d,s]);let f=u?Math.min(e,d-1):e,p=f*t,m=f>0,h=u?f<d-1:!!o;if(u&&n<=t&&f===0)return null;let g=u?n===0?`No ${c}`:`${r(p+1)}–${r(Math.min(p+t,n))} of ${r(n)} ${c}`:`Page ${f+1}`;return(0,a.jsxs)(`div`,{className:`mt-4 flex items-center justify-between text-sm text-faint ${l??``}`,children:[(0,a.jsx)(`span`,{children:g}),(0,a.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,a.jsx)(`button`,{type:`button`,disabled:!m,onClick:()=>s(f-1),className:`rounded-md px-3 py-1 text-xs hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 disabled:opacity-40 disabled:hover:text-faint`,children:`Previous`}),(0,a.jsx)(`span`,{className:`rounded-md bg-accent/15 px-2.5 py-1 text-xs font-medium text-accent tnum`,children:u?`${f+1} / ${d}`:f+1}),(0,a.jsx)(`button`,{type:`button`,disabled:!h,onClick:()=>s(f+1),className:`rounded-md px-3 py-1 text-xs hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 disabled:opacity-40 disabled:hover:text-faint`,children:`Next`})]})]})}export{o as t};
@@ -0,0 +1 @@
1
+ import{r as e}from"./cn-CMFYpumL.js";import{g as t,t as n}from"./react-vendor-Bjui4wS4.js";import{o as r}from"./connectionStore-Cd9-3Fw0.js";import{C as i,S as a,st as o,w as s}from"./index-Bn2R06qm.js";import{a as c,n as l,o as u,t as d}from"./form-DsUq0w8s.js";import{n as f,r as p}from"./useServerActionGuard-CItj3hvh.js";import{i as m,n as h,r as g}from"./flowMutationSafety-DVD1IMr-.js";var _=e(t(),1),v=n();function y(e){if(e&&typeof e==`object`&&!Array.isArray(e)){let t=e;return JSON.stringify(Object.keys(t).sort().map(e=>[e,t[e]]))}return JSON.stringify(e)}function b(e){let[t,n]=(0,_.useState)(e),r=(0,_.useRef)(y(e));return(0,_.useEffect)(()=>{let t=y(e);t!==r.current&&(r.current=t,n(e))},[e]),[t,n,()=>{let e=r.current;return t=>{r.current===e&&(r.current=y(t))}}]}function x(e,t){let n=String(e).trim();if(n===``)return null;let r=Number(n);return Number.isSafeInteger(r)&&r>=t?r:null}function S(e){let t=x(e.stallInterval,0),n=x(e.maxStalls,0),r=x(e.gracePeriod,0);return t===null||n===null||r===null?{ok:!1,error:`Stall interval, max stalls, and grace period must be non-negative whole numbers.`}:{ok:!0,value:{enabled:e.enabled,stallInterval:t,maxStalls:n,gracePeriod:r}}}function C(e){let t=x(e.autoRetryInterval,0),n=x(e.maxAutoRetries,0);return t===null||n===null?{ok:!1,error:`Retry interval and max auto-retries must be non-negative whole numbers.`}:{ok:!0,value:{autoRetry:e.autoRetry,autoRetryInterval:t,maxAutoRetries:n}}}function w(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function T(e){return typeof e==`number`&&Number.isFinite(e)}function E(e){return w(e)&&typeof e.enabled==`boolean`&&T(e.stallInterval)&&T(e.maxStalls)&&T(e.gracePeriod)}function D(e){return w(e)&&typeof e.autoRetry==`boolean`&&T(e.autoRetryInterval)&&T(e.maxAutoRetries)&&(e.maxAge===null||T(e.maxAge))&&T(e.maxEntries)}function O(e,t){if(!w(e)||e.ok!==!0)throw Error(`Malformed ${t} response: expected { ok: true }.`)}function k(e){let{scopeKey:t,begin:n}=p(e),i=(0,_.useRef)(null),a=(0,_.useRef)(null),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(!1);return(0,_.useEffect)(()=>{i.current=null,s(!1),l(!1),a.current!==null&&(window.clearTimeout(a.current),a.current=null);let e=f(),t=r.subscribe(()=>{let t=f();t!==e&&(e=t,i.current=null,s(!1),l(!1),a.current!==null&&(window.clearTimeout(a.current),a.current=null))});return()=>{i.current=null,a.current!==null&&window.clearTimeout(a.current),t()}},[t]),{scopeKey:t,saving:o,saved:c,start:()=>{let e=n(`save`);return e?(i.current=e,s(!0),l(!1),e):null},finish:e=>{e.finish(),i.current===e&&(i.current=null,s(!1))},showSaved:e=>{i.current!==e||!e.isCurrent()||(l(!0),a.current!==null&&window.clearTimeout(a.current),a.current=window.setTimeout(()=>{e.isCurrent()&&l(!1),a.current=null},2e3))}}}function A({queue:e,config:t,onSaved:n}){let[r,c,f]=b(t),[p,m]=(0,_.useState)(null),h=k(`stall-config:${e}`);(0,_.useEffect)(()=>m(null),[h.scopeKey]);let g=S(r);return(0,v.jsxs)(a,{children:[(0,v.jsx)(i,{title:`Stall detection`}),(0,v.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,v.jsxs)(`div`,{className:`col-span-2 flex items-center gap-2`,children:[(0,v.jsx)(u,{checked:r.enabled,onChange:e=>c({...r,enabled:e}),label:`enabled`}),(0,v.jsx)(`span`,{className:`text-sm text-muted`,"aria-hidden":`true`,children:`enabled`})]}),(0,v.jsx)(d,{label:`Stall interval (ms)`,children:(0,v.jsx)(l,{name:`stall-interval-ms`,autoComplete:`off`,type:`number`,min:0,max:2**53-1,step:1,value:r.stallInterval,onChange:e=>c({...r,stallInterval:e.target.value})})}),(0,v.jsx)(d,{label:`Max stalls`,children:(0,v.jsx)(l,{name:`stall-max-count`,autoComplete:`off`,type:`number`,min:0,max:2**53-1,step:1,value:r.maxStalls,onChange:e=>c({...r,maxStalls:e.target.value})})}),(0,v.jsx)(d,{label:`Grace period (ms)`,children:(0,v.jsx)(l,{name:`stall-grace-period-ms`,autoComplete:`off`,type:`number`,min:0,max:2**53-1,step:1,value:r.gracePeriod,onChange:e=>c({...r,gracePeriod:e.target.value})})})]}),(0,v.jsxs)(`div`,{className:`mt-3 flex items-center gap-3`,children:[(0,v.jsx)(s,{variant:`accent`,size:`sm`,disabled:h.saving||!g.ok,onClick:async()=>{if(!g.ok)return;let t=h.start();if(t)try{m(null);let r=f();if(O(await o.setStallConfig(e,g.value),`/stall-config`),!t.isCurrent())return;r(g.value),await n(),h.showSaved(t)}catch(e){t.isCurrent()&&m(e.message)}finally{h.finish(t)}},children:`Save`}),h.saved&&(0,v.jsx)(`span`,{role:`status`,className:`text-xs text-success`,children:`Saved ✓`}),!g.ok&&(0,v.jsx)(`span`,{role:`alert`,className:`text-xs text-danger`,children:g.error}),p&&(0,v.jsx)(`span`,{role:`alert`,className:`text-xs text-danger`,children:p})]})]})}function j({queue:e,config:t,onSaved:n}){let[r,c,f]=b(t),[p,h]=(0,_.useState)(null),g=k(`dlq-config:${e}`);(0,_.useEffect)(()=>h(null),[g.scopeKey]);let y=C(r),x=y.ok&&y.value.autoRetry;return(0,v.jsxs)(a,{children:[(0,v.jsx)(i,{title:`DLQ policy`}),(0,v.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,v.jsxs)(`div`,{className:`col-span-2 flex items-center gap-2`,children:[(0,v.jsx)(u,{checked:r.autoRetry,disabled:!r.autoRetry,onChange:e=>c({...r,autoRetry:e}),label:`auto-retry`}),(0,v.jsx)(`span`,{className:`text-sm text-muted`,"aria-hidden":`true`,children:`auto-retry`})]}),(0,v.jsx)(`p`,{className:`col-span-2 text-xs text-warning`,children:`Auto-retry can only be disabled. Bunqueue v2.8.55 cannot prove that a DLQ entry has no hidden reverse flow dependents before a background retry.`}),(0,v.jsx)(d,{label:`Retry interval (ms)`,children:(0,v.jsx)(l,{name:`dlq-auto-retry-interval-ms`,autoComplete:`off`,type:`number`,min:0,max:2**53-1,step:1,value:r.autoRetryInterval,onChange:e=>c({...r,autoRetryInterval:e.target.value})})}),(0,v.jsx)(d,{label:`Max auto-retries`,children:(0,v.jsx)(l,{name:`dlq-max-auto-retries`,autoComplete:`off`,type:`number`,min:0,max:2**53-1,step:1,value:r.maxAutoRetries,onChange:e=>c({...r,maxAutoRetries:e.target.value})})}),(0,v.jsx)(d,{label:`Max age (ms)`,children:(0,v.jsx)(l,{name:`dlq-max-age-ms`,autoComplete:`off`,type:`number`,min:0,max:2**53-1,step:1,disabled:!0,title:m,value:r.maxAge??``,readOnly:!0})}),(0,v.jsx)(d,{label:`Max entries`,children:(0,v.jsx)(l,{name:`dlq-max-entries`,autoComplete:`off`,type:`number`,min:1,max:2**53-1,step:1,disabled:!0,title:m,value:r.maxEntries,readOnly:!0})}),(0,v.jsx)(`p`,{className:`col-span-2 text-xs text-warning`,children:m})]}),(0,v.jsxs)(`div`,{className:`mt-3 flex items-center gap-3`,children:[(0,v.jsx)(s,{variant:`accent`,size:`sm`,disabled:g.saving||!y.ok||x,onClick:async()=>{if(!y.ok)return;let t=g.start();if(t)try{h(null);let i=f();if(O(await o.setDlqConfig(e,y.value),`/dlq-config`),!t.isCurrent())return;i({...r,...y.value}),await n(),g.showSaved(t)}catch(e){t.isCurrent()&&h(e.message)}finally{g.finish(t)}},children:`Save`}),g.saved&&(0,v.jsx)(`span`,{role:`status`,className:`text-xs text-success`,children:`Saved ✓`}),!y.ok&&(0,v.jsx)(`span`,{role:`alert`,className:`text-xs text-danger`,children:y.error}),x&&(0,v.jsx)(`span`,{role:`alert`,className:`text-xs text-danger`,children:`Disable auto-retry before saving this policy.`}),p&&(0,v.jsx)(`span`,{role:`alert`,className:`text-xs text-danger`,children:p})]})]})}function M({title:e,onRetry:t}){return(0,v.jsxs)(a,{children:[(0,v.jsx)(i,{title:e}),(0,v.jsx)(`p`,{className:`mb-3 text-sm text-muted`,children:`Couldn't load this queue's config.`}),(0,v.jsx)(s,{size:`sm`,onClick:t,children:`Retry`})]})}function N(e,t){let n=Number(e),r=Number(t);return{grace:n,limit:r,valid:e.trim()!==``&&t.trim()!==``&&Number.isSafeInteger(n)&&Number.isSafeInteger(r)&&n>=0&&r>0}}function P(e){if(!e.trim())return{valid:!0};let t=Number(e);return Number.isSafeInteger(t)&&t>0?{count:t,valid:!0}:{valid:!1}}function F(e,t){return t===void 0?`Promote every delayed job in "${e}" and make it eligible to run now?`:`Promote up to ${t} delayed jobs in "${e}" and make them eligible to run now?`}function I(e,t,n){let r=e=>{if(!e.trim())return;let t=Number(e);return Number.isSafeInteger(t)&&t>0?t:null},i=r(e),a=r(t),o=r(n);return{limit:typeof i==`number`?i:0,duration:typeof a==`number`?a:0,...typeof o==`number`?{ttl:o}:{},valid:typeof i==`number`&&typeof a==`number`&&o!==null}}function L(e){let t=Number(e);return{value:t,valid:e.trim()!==``&&Number.isSafeInteger(t)&&t>0}}function R({queue:e,paused:t,busy:n,run:r}){let[u,f]=(0,_.useState)(`0`),[p,m]=(0,_.useState)(`1000`),[y,b]=(0,_.useState)(`completed`),[x,S]=(0,_.useState)(``),C=N(u,p),w=P(x);return(0,v.jsxs)(a,{className:`mb-6`,children:[(0,v.jsx)(i,{title:`Lifecycle`}),(0,v.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[t?(0,v.jsx)(s,{variant:`success`,size:`sm`,disabled:n,onClick:()=>r(`Resumed`,()=>o.resume(e)),children:`Resume`}):(0,v.jsx)(s,{variant:`warning`,size:`sm`,disabled:n,onClick:()=>r(`Paused`,()=>o.pause(e)),children:`Pause`}),(0,v.jsx)(s,{size:`sm`,disabled:!0,title:h,children:`Requeue completed`}),(0,v.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,v.jsx)(`div`,{className:`w-24`,children:(0,v.jsx)(d,{label:`Promote N`,children:(0,v.jsx)(l,{type:`number`,min:1,max:2**53-1,step:1,name:`promote-count`,"aria-invalid":!w.valid,value:x,onChange:e=>S(e.target.value),placeholder:`all`})})}),(0,v.jsx)(s,{size:`sm`,disabled:n||!w.valid,onClick:()=>r(`Promoted`,()=>o.promoteJobs(e,w.count),F(e,w.count)),children:`Promote delayed`}),!w.valid&&(0,v.jsx)(`span`,{role:`alert`,className:`pb-2 text-xs text-danger`,children:`Promote N must be a positive whole number, or blank for all.`})]})]}),(0,v.jsx)(`p`,{className:`mt-3 text-xs text-warning`,children:h}),(0,v.jsxs)(`div`,{className:`mt-4 border-t border-line pt-3`,children:[(0,v.jsx)(`p`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wider text-faint`,children:`Destructive — these permanently remove jobs`}),(0,v.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,v.jsx)(s,{size:`sm`,disabled:!0,title:g,children:`Drain`}),(0,v.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,v.jsx)(`div`,{className:`w-40`,children:(0,v.jsx)(d,{label:`State`,children:(0,v.jsxs)(c,{name:`clean-state`,disabled:!0,value:y,onChange:e=>b(e.target.value),children:[(0,v.jsx)(`option`,{value:`completed`,children:`Completed`}),(0,v.jsx)(`option`,{value:`failed`,children:`Failed / DLQ`}),(0,v.jsx)(`option`,{value:`waiting`,children:`Queued`})]})})}),(0,v.jsx)(`div`,{className:`w-24`,children:(0,v.jsx)(d,{label:`Grace (ms)`,children:(0,v.jsx)(l,{type:`number`,min:0,max:2**53-1,step:1,name:`clean-grace`,disabled:!0,"aria-invalid":!C.valid,value:u,onChange:e=>f(e.target.value)})})}),(0,v.jsx)(`div`,{className:`w-24`,children:(0,v.jsx)(d,{label:`Limit`,children:(0,v.jsx)(l,{type:`number`,min:1,max:2**53-1,step:1,name:`clean-limit`,disabled:!0,"aria-invalid":!C.valid,value:p,onChange:e=>m(e.target.value)})})}),(0,v.jsx)(s,{variant:`danger`,size:`sm`,disabled:!0,title:g,children:`Clean`}),!C.valid&&(0,v.jsx)(`span`,{role:`alert`,className:`pb-2 text-xs text-danger`,children:`Grace and limit must be whole numbers; limit must be positive.`})]})]}),(0,v.jsx)(`p`,{className:`mt-3 text-xs text-warning`,children:g})]})]})}function z({queue:e,busy:t,run:n}){let[r,u]=(0,_.useState)(``),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)(`permanent`),[g,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(``),[S,C]=(0,_.useState)(``),[w,T]=(0,_.useState)(``),[E,D]=(0,_.useState)(null),[O,k]=(0,_.useState)(null),A=I(r,f,m===`expires`?g:``),j=L(b);return(0,v.jsxs)(`div`,{className:`mb-6 grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,v.jsxs)(a,{children:[(0,v.jsx)(i,{title:`Rate-limit desired state`}),(0,v.jsx)(`p`,{className:`mb-3 text-xs text-warning`,children:`Bunqueue v2.8.55 has no read endpoint. This blindly replaces an unknown policy; a receipt proves only what this dashboard applied at that time.`}),(0,v.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,v.jsx)(`div`,{className:`min-w-24 flex-1`,children:(0,v.jsx)(d,{label:`Limit`,children:(0,v.jsx)(l,{type:`number`,min:1,max:2**53-1,step:1,name:`rate-limit`,value:r,onChange:e=>u(e.target.value),placeholder:`max per window`})})}),(0,v.jsx)(`div`,{className:`min-w-28 flex-1`,children:(0,v.jsx)(d,{label:`Window (ms)`,children:(0,v.jsx)(l,{type:`number`,min:1,max:2**53-1,step:1,name:`rate-duration`,value:f,onChange:e=>p(e.target.value),placeholder:`60000`})})}),(0,v.jsx)(`div`,{className:`min-w-28 flex-1`,children:(0,v.jsx)(d,{label:`TTL`,children:(0,v.jsxs)(c,{name:`rate-ttl-mode`,value:m,onChange:e=>h(e.target.value),children:[(0,v.jsx)(`option`,{value:`permanent`,children:`Permanent`}),(0,v.jsx)(`option`,{value:`expires`,children:`Expires after`})]})})}),(0,v.jsx)(`div`,{className:`min-w-24 flex-1`,children:(0,v.jsx)(d,{label:`TTL (ms)`,hint:m===`permanent`?`Not sent`:void 0,children:(0,v.jsx)(l,{type:`number`,min:1,max:2**53-1,step:1,name:`rate-ttl`,disabled:m===`permanent`,value:g,onChange:e=>y(e.target.value),placeholder:`—`})})}),(0,v.jsx)(s,{variant:`accent`,size:`sm`,disabled:t||!A.valid,onClick:()=>n(`Rate limit set`,()=>o.setRateLimit(e,A.limit,A.duration,A.ttl),`Replace the unknown rate-limit policy for "${e}" with limit ${A.limit}, window ${A.duration}ms${A.ttl===void 0?`, permanent`:`, TTL ${A.ttl}ms`}?`,()=>D(`Applied limit ${A.limit} per ${A.duration}ms${A.ttl===void 0?`, permanent`:`, TTL ${A.ttl}ms`} at ${new Date().toISOString()}. Current server state cannot be read.`)),children:`Replace policy`}),(0,v.jsx)(`div`,{className:`min-w-40 flex-1`,children:(0,v.jsx)(d,{label:`Type ${e} to clear`,children:(0,v.jsx)(l,{name:`rate-clear-queue`,autoComplete:`off`,spellCheck:!1,value:S,onChange:e=>C(e.target.value)})})}),(0,v.jsx)(s,{size:`sm`,disabled:t||S!==e,onClick:()=>n(`No rate limit ensured`,()=>o.clearRateLimit(e),`Ensure queue "${e}" has no rate-limit policy? Bunqueue v2.8.55 cannot report its previous value.`,()=>D(`Applied no rate-limit policy at ${new Date().toISOString()}. Current server state cannot be read.`)),children:`Ensure no rate limit`}),!A.valid&&(r.trim()||f.trim()||g.trim())&&(0,v.jsx)(`span`,{role:`alert`,className:`w-full text-xs text-danger`,children:`Limit and window are required; all values must be positive whole numbers.`}),E&&(0,v.jsx)(`span`,{role:`status`,className:`w-full text-xs text-success`,children:E})]})]}),(0,v.jsxs)(a,{children:[(0,v.jsx)(i,{title:`Concurrency desired state`}),(0,v.jsx)(`p`,{className:`mb-3 text-xs text-warning`,children:`Bunqueue v2.8.55 has no read endpoint. This blindly replaces an unknown policy; a receipt proves only what this dashboard applied at that time.`}),(0,v.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,v.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,v.jsx)(d,{label:`Concurrency`,children:(0,v.jsx)(l,{type:`number`,min:1,max:2**53-1,step:1,name:`concurrency`,value:b,onChange:e=>x(e.target.value),placeholder:`max in-flight`})})}),(0,v.jsx)(s,{variant:`accent`,size:`sm`,disabled:t||!j.valid,onClick:()=>n(`Concurrency set`,()=>o.setConcurrency(e,j.value),`Replace the unknown concurrency policy for "${e}" with ${j.value} maximum in-flight jobs?`,()=>k(`Applied concurrency ${j.value} at ${new Date().toISOString()}. Current server state cannot be read.`)),children:`Replace policy`}),(0,v.jsx)(`div`,{className:`min-w-40 flex-1`,children:(0,v.jsx)(d,{label:`Type ${e} to clear`,children:(0,v.jsx)(l,{name:`concurrency-clear-queue`,autoComplete:`off`,spellCheck:!1,value:w,onChange:e=>T(e.target.value)})})}),(0,v.jsx)(s,{size:`sm`,disabled:t||w!==e,onClick:()=>n(`No concurrency limit ensured`,()=>o.clearConcurrency(e),`Ensure queue "${e}" has no concurrency policy? Bunqueue v2.8.55 cannot report its previous value.`,()=>k(`Applied no concurrency policy at ${new Date().toISOString()}. Current server state cannot be read.`)),children:`Ensure no concurrency limit`}),!j.valid&&b.trim()&&(0,v.jsx)(`span`,{role:`alert`,className:`self-center text-xs text-danger`,children:`Concurrency must be a positive whole number.`}),O&&(0,v.jsx)(`span`,{role:`status`,className:`w-full text-xs text-success`,children:O})]})]})]})}export{A as a,j as i,z as n,D as o,M as r,E as s,R as t};
@@ -0,0 +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,_ as i,b as a,c as o,h as s,m as c,st as l,x as u,y as d}from"./index-Bn2R06qm.js";import{a as f}from"./form-DsUq0w8s.js";import{r as p}from"./useServerActionGuard-CItj3hvh.js";import{a as m,i as h,n as g,o as _,r as v,s as y,t as b}from"./QueueActions-D_QGBaVm.js";var x=e(t(),1),S=n(),C=[`waiting`,`prioritized`,`active`,`completed`,`failed`,`delayed`,`waiting-children`,`paused`],w=500,T=200,E=w*T;function D(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function O(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function k(e){return D(e)&&C.every(t=>O(e[t]))}function A(e,t){if(!D(e)||e.ok!==!0||!Array.isArray(e.queues)||!O(e.total)||!O(e.limit)||e.limit<1||!O(e.offset)||e.offset!==t||typeof e.timestamp!=`number`||!Number.isFinite(e.timestamp)||!e.queues.every(e=>D(e)&&typeof e.name==`string`&&e.name.length>0&&O(e.waiting)&&O(e.delayed)&&O(e.active)&&O(e.dlq)&&typeof e.paused==`boolean`))throw Error(`Malformed /dashboard/queues response.`)}async function j(){let e=await l.queues(w,0);A(e,0);let t=e.total;if(t>E)throw Error(`Queue discovery reported ${t} queues, above the safe dashboard limit of ${E}.`);if(e.queues.length!==Math.min(w,t))throw Error(`Incomplete /dashboard/queues page at offset 0: expected ${Math.min(w,t)} queues, received ${e.queues.length}.`);let n=new Map,r=e=>{for(let t of e.queues){if(n.has(t.name))throw Error(`Overlapping /dashboard/queues pages: queue "${t.name}" appeared more than once.`);n.set(t.name,t)}};r(e);let i=e.queues.length,a=1;for(;i<t;){if(a>=T)throw Error(`Queue discovery exceeded the safe limit of ${T} pages.`);let e=await l.queues(w,i);if(A(e,i),e.total!==t)throw Error(`Queue discovery changed during pagination: total moved from ${t} to ${e.total}. Retry the snapshot.`);let n=Math.min(w,t-i);if(e.queues.length!==n)throw Error(`Incomplete /dashboard/queues page at offset ${i}: expected ${n} queues, received ${e.queues.length}.`);r(e),i+=e.queues.length,a+=1}if(n.size!==t)throw Error(`Incomplete /dashboard/queues snapshot: expected ${t} unique queues, received ${n.size}.`);return{...e,queues:[...n.values()],total:t,limit:w,offset:0}}function M(e,t){if(!D(e)||e.ok!==!0||e.name!==t||typeof e.paused!=`boolean`||!k(e.counts))throw Error(`Malformed queue detail response for "${t}".`)}function N(e){if(!D(e)||e.ok!==!0||!y(e.config))throw Error(`Malformed /stall-config response.`);return e.config}function P(e){if(!D(e)||e.ok!==!0||!_(e.config))throw Error(`Malformed /dlq-config response.`);return e.config}function F(e){if(!D(e)||e.ok!==!0)throw Error(`Malformed queue action response: expected { ok: true }.`);if(e.count!==void 0){if(!O(e.count))throw Error(`Malformed queue action response: count must be a non-negative integer.`);return e.count}}function I(e,t){return t.some(t=>t.name===e)?e:t[0]?.name??``}function L(){let[e,t]=(0,x.useState)(``),[n,_]=(0,x.useState)(!1),[y,w]=(0,x.useState)(null),T=p(`queue-control:${e}`);(0,x.useEffect)(()=>{_(!1),w(null)},[T.scopeKey]);let{data:E,error:D,loading:O,refetch:k}=r(j,[],{intervalMs:3e4});(0,x.useEffect)(()=>{E&&t(e=>I(e,E.queues))},[E]);let{data:A,error:L,loading:R,refetch:z}=r((0,x.useCallback)(async()=>{if(!e)return null;let[t,n,r]=await Promise.all([l.queueDetail(e,!1),l.getStallConfig(e).then(N).catch(()=>null),l.getDlqConfig(e).then(P).catch(()=>null)]);return M(t,e),{queue:e,detail:t,stall:n,dlq:r}},[e]),[e]),B=!E||E.queues.some(t=>t.name===e),V=A&&A.queue===e&&B?A:null,H=(t,n,r,i)=>{let a=e;if(!a||r&&!window.confirm(r))return;let o=T.begin(`queue-write`);o&&(_(!0),w(null),(async()=>{try{let e=await l.queuesSummary();if(!o.isCurrent())return;if(!e.some(e=>e.name===a))throw Error(`Queue "${a}" no longer exists`);let r=F(await n());if(!o.isCurrent())return;w({queue:a,ok:!0,text:`${t}${r==null?` ✓`:`: ${r}`}`}),i?.(),await z()}catch(e){o.isCurrent()&&w({queue:a,ok:!1,text:e.message})}finally{o.finish()&&_(!1)}})())};return(0,S.jsxs)(`div`,{children:[(0,S.jsx)(s,{title:`Queue Control`,description:`Full per-queue operations and configuration.`,live:!!e&&!!V?.detail&&!!V.stall&&!!V.dlq&&!L&&!D}),(0,S.jsxs)(`div`,{className:`mb-6 flex flex-wrap items-center gap-3`,children:[(0,S.jsx)(`div`,{className:`w-56`,children:(0,S.jsx)(f,{value:e,"aria-label":`Queue`,name:`queue-control-queue`,autoComplete:`off`,onChange:e=>t(e.target.value),children:(E?.queues??[]).map(e=>(0,S.jsx)(`option`,{value:e.name,children:e.name},e.name))})}),V?.detail&&(0,S.jsx)(i,{label:V.detail.paused?`Paused`:`Active`,tone:V.detail.paused?`amber`:`green`}),y?.queue===e&&(0,S.jsx)(`span`,{role:`status`,className:y.ok?`text-xs text-success`:`text-xs text-danger`,children:y.text})]}),D&&(0,S.jsx)(u,{onRetry:k,message:`Could not discover queues — ${D.message}. Retry to choose a queue.`}),L&&V&&(0,S.jsx)(u,{message:`Queue refresh failed — showing the last successful configuration.`,onRetry:z}),L&&!V?(0,S.jsx)(d,{error:L,onRetry:z}):O&&!E&&!e&&!D?(0,S.jsx)(a,{label:`Discovering queues…`}):R&&!V?(0,S.jsx)(a,{}):D&&!e?(0,S.jsx)(`p`,{role:`alert`,className:`text-sm text-warning`,children:`Queue discovery failed. Retry the request above before choosing a queue.`}):V?.detail?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`mb-6 grid grid-cols-2 gap-3 md:grid-cols-4 xl:grid-cols-8`,children:C.map(e=>(0,S.jsx)(c,{label:e,value:o(V.detail.counts[e]),compact:!0},e))}),(0,S.jsx)(b,{queue:e,paused:V.detail.paused,busy:n,run:H},`${e}:lifecycle`),(0,S.jsx)(g,{queue:e,busy:n,run:H},`${e}:limits`),(0,S.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[V.stall?(0,S.jsx)(m,{queue:e,config:V.stall,onSaved:async()=>{w({queue:e,ok:!0,text:`Stall config saved ✓`}),await z()}},`${e}:stall`):(0,S.jsx)(v,{title:`Stall detection`,onRetry:z}),V.dlq?(0,S.jsx)(h,{queue:e,config:V.dlq,onSaved:async()=>{w({queue:e,ok:!0,text:`DLQ config saved ✓`}),await z()}},`${e}:dlq`):(0,S.jsx)(v,{title:`DLQ policy`,onRetry:z})]})]}):!L&&(0,S.jsx)(`p`,{className:`text-sm text-faint`,children:E?.queues.length===0?`No queues are available.`:`Select a queue.`})]})}export{L as QueueControl,j as loadAllQueuePages};
@@ -0,0 +1 @@
1
+ import{r as e}from"./cn-CMFYpumL.js";import{d as t,g as n,r,t as i}from"./react-vendor-Bjui4wS4.js";import{A as a,M as o,P as s,S as c,U as l,V as u,W as d,X as f,_ as p,b as m,c as h,f as g,g as _,j as v,l as y,m as b,n as x,o as S,st as C,u as w,v as T,w as E,x as D}from"./index-Bn2R06qm.js";import{a as O,n as k,t as A}from"./form-DsUq0w8s.js";import{r as j,t as M}from"./useServerActionGuard-CItj3hvh.js";import{r as N}from"./flowMutationSafety-DVD1IMr-.js";var P=e(n(),1),F=i();function I({queue:e}){return(0,F.jsxs)(`div`,{className:`mt-8`,children:[(0,F.jsx)(`h2`,{className:`mb-3 text-lg font-semibold text-fg`,children:`Configuration`}),(0,F.jsx)(`p`,{className:`mb-4 text-xs text-warning`,children:`Bunqueue v2.8.55 cannot read either current policy. Every command below is an explicit blind desired-state write; a receipt proves only what this dashboard applied at that time.`}),(0,F.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 lg:grid-cols-2`,children:[(0,F.jsx)(z,{queue:e}),(0,F.jsx)(B,{queue:e})]})]})}function L(e){if(!e.trim())return null;let t=Number(e);return Number.isSafeInteger(t)&&t>0?t:null}function R(e,t){let[n,r]=(0,P.useState)(!1),[i,a]=(0,P.useState)(null),[o,s]=(0,P.useState)(null),c=j(`classic-queue-policy:${e}:${t}`);return(0,P.useEffect)(()=>{r(!1),a(null),s(null)},[c.scopeKey]),{busy:n,error:i,receipt:o,run:async(n,i,o)=>{if(!window.confirm(i))return;let l=c.begin(t);if(l){r(!0),a(null),s(null);try{let t=await C.queuesSummary();if(!l.isCurrent())return;if(!t.some(t=>t.name===e))throw Error(`Queue "${e}" no longer exists`);if(M(await o(),n),!l.isCurrent())return;s(`${n} applied at ${new Date().toISOString()}. Current server state cannot be read.`)}catch(e){l.isCurrent()&&a(e.message)}finally{l.finish()&&r(!1)}}}}}function z({queue:e}){let[t,n]=(0,P.useState)(``),[r,i]=(0,P.useState)(``),[a,o]=(0,P.useState)(`permanent`),[s,l]=(0,P.useState)(``),[d,f]=(0,P.useState)(``),{busy:p,error:m,receipt:h,run:g}=R(e,`rate-limit`),_=L(t),v=L(r),y=a===`expires`?L(s):void 0,b=_!==null&&v!==null&&(a===`permanent`||y!=null);return(0,F.jsxs)(c,{children:[(0,F.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,F.jsx)(`h3`,{className:`text-base font-semibold text-fg`,children:`Rate-limit desired state`}),(0,F.jsx)(u,{className:`size-4 text-faint`})]}),(0,F.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,F.jsx)(A,{label:`Limit`,children:(0,F.jsx)(k,{type:`number`,min:1,max:2**53-1,step:1,inputMode:`numeric`,name:`classic-rate-limit`,value:t,"aria-invalid":t.trim()!==``&&_===null,onChange:e=>n(e.target.value),placeholder:`100`})}),(0,F.jsx)(A,{label:`Window (ms)`,children:(0,F.jsx)(k,{type:`number`,min:1,max:2**53-1,step:1,inputMode:`numeric`,name:`classic-rate-duration`,value:r,"aria-invalid":r.trim()!==``&&v===null,onChange:e=>i(e.target.value),placeholder:`60000`})}),(0,F.jsx)(A,{label:`TTL`,children:(0,F.jsxs)(O,{name:`classic-rate-ttl-mode`,value:a,onChange:e=>o(e.target.value),children:[(0,F.jsx)(`option`,{value:`permanent`,children:`Permanent`}),(0,F.jsx)(`option`,{value:`expires`,children:`Expires after`})]})}),(0,F.jsx)(A,{label:`TTL (ms)`,hint:a===`permanent`?`Not sent`:void 0,children:(0,F.jsx)(k,{type:`number`,min:1,max:2**53-1,step:1,inputMode:`numeric`,name:`classic-rate-ttl`,disabled:a===`permanent`,value:s,"aria-invalid":a===`expires`&&s.trim()!==``&&y==null,onChange:e=>l(e.target.value),placeholder:`3600000`})})]}),(0,F.jsx)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:(0,F.jsx)(E,{variant:`accent`,size:`sm`,disabled:p||!b,onClick:()=>{if(_===null||v===null||a===`expires`&&y===null)return;let t=typeof y==`number`?y:void 0,n=a===`permanent`?`permanent`:`TTL ${y}ms`;g(`Rate-limit policy replaced`,`Replace the unknown rate-limit policy for "${e}" with limit ${_}, window ${v}ms, ${n}?`,()=>C.setRateLimit(e,_,v,t))},children:`Replace rate-limit policy`})}),(0,F.jsxs)(`div`,{className:`mt-4 border-t border-line pt-4`,children:[(0,F.jsx)(A,{label:`Type ${e} to clear`,children:(0,F.jsx)(k,{name:`classic-rate-clear-queue`,autoComplete:`off`,spellCheck:!1,value:d,onChange:e=>f(e.target.value)})}),(0,F.jsx)(E,{className:`mt-2`,size:`sm`,disabled:p||d!==e,onClick:()=>void g(`No rate limit ensured`,`Ensure queue "${e}" has no rate-limit policy? The previous value is unavailable.`,()=>C.clearRateLimit(e)),children:`Ensure no rate limit`})]}),h&&(0,F.jsx)(`p`,{role:`status`,className:`mt-3 text-xs text-success`,children:h}),m&&(0,F.jsx)(`p`,{role:`alert`,className:`mt-3 text-xs text-danger`,children:m})]})}function B({queue:e}){let[t,n]=(0,P.useState)(``),[r,i]=(0,P.useState)(``),{busy:a,error:o,receipt:s,run:l}=R(e,`concurrency`),u=L(t);return(0,F.jsxs)(c,{children:[(0,F.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,F.jsx)(`h3`,{className:`text-base font-semibold text-fg`,children:`Concurrency desired state`}),(0,F.jsx)(f,{className:`size-4 text-faint`})]}),(0,F.jsx)(A,{label:`Maximum in-flight jobs`,children:(0,F.jsx)(k,{type:`number`,min:1,max:2**53-1,step:1,inputMode:`numeric`,name:`classic-concurrency`,value:t,"aria-invalid":t.trim()!==``&&u===null,onChange:e=>n(e.target.value),placeholder:`5`})}),(0,F.jsx)(`div`,{className:`mt-4 flex items-center gap-2`,children:(0,F.jsx)(E,{variant:`accent`,size:`sm`,disabled:a||u===null,onClick:()=>{u!==null&&l(`Concurrency policy replaced`,`Replace the unknown concurrency policy for "${e}" with ${u} maximum in-flight jobs?`,()=>C.setConcurrency(e,u))},children:`Replace concurrency policy`})}),(0,F.jsxs)(`div`,{className:`mt-4 border-t border-line pt-4`,children:[(0,F.jsx)(A,{label:`Type ${e} to clear`,children:(0,F.jsx)(k,{name:`classic-concurrency-clear-queue`,autoComplete:`off`,spellCheck:!1,value:r,onChange:e=>i(e.target.value)})}),(0,F.jsx)(E,{className:`mt-2`,size:`sm`,disabled:a||r!==e,onClick:()=>void l(`No concurrency limit ensured`,`Ensure queue "${e}" has no concurrency policy? The previous value is unavailable.`,()=>C.clearConcurrency(e)),children:`Ensure no concurrency limit`})]}),s&&(0,F.jsx)(`p`,{role:`status`,className:`mt-3 text-xs text-success`,children:s}),o&&(0,F.jsx)(`p`,{role:`alert`,className:`mt-3 text-xs text-danger`,children:o})]})}var V=[`active`,`waiting`,`prioritized`,`waiting-children`,`completed`,`failed`,`delayed`,`paused`],H={detail:{ok:!1,name:``,counts:{waiting:0,active:0,completed:0,failed:0,delayed:0,prioritized:0,"waiting-children":0,paused:0},paused:!1,priorityCounts:{},dlqPreview:[],timestamp:0},jobs:[],recentJobsError:null};function U(){let{name:e=``}=t(),[n,i]=(0,P.useState)(null),[c,u]=(0,P.useState)(null),f=j(`classic-queue:${e}`);(0,P.useEffect)(()=>{i(null),u(null)},[f.scopeKey]);let{data:O,error:k,loading:A,refetch:L}=a((0,P.useCallback)(async()=>{if(!(await C.queuesSummary()).some(t=>t.name===e))return{exists:!1,detail:null,jobs:[],recentJobsError:null};let[t,n]=await Promise.all([v.queueDetail(e,!1),v.jobsList(e,{states:V,limit:12}).then(e=>({jobs:e.jobs??[],error:null})).catch(e=>({jobs:[],error:e.message||`Unknown error`}))]);if(t.ok!==!0||t.name!==e)throw Error(`Malformed queue detail response for "${e}"`);return{exists:!0,detail:t,jobs:n.jobs,recentJobsError:n.error}},[e]),[e]),R=async(t,n,r)=>{if(r&&!window.confirm(r))return;let a=f.begin(t);if(a){i(t),u(null);try{let r=await C.queuesSummary();if(!a.isCurrent())return;if(!r.some(t=>t.name===e))throw Error(`Queue "${e}" no longer exists`);if(M(await n(),t),!a.isCurrent())return;await L()}catch(e){a.isCurrent()&&u(e.message)}finally{a.finish()&&i(null)}}};if(A&&!O&&!k)return(0,F.jsx)(m,{label:`Loading ${e}…`});if(k&&!O)return(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`h1`,{className:`mb-4 font-mono text-2xl font-bold tracking-tight text-fg`,children:e}),(0,F.jsx)(D,{onRetry:L})]});if(O?.exists===!1)return(0,F.jsxs)(`div`,{children:[k&&(0,F.jsx)(D,{onRetry:L}),(0,F.jsx)(`h1`,{className:`mb-4 font-mono text-2xl font-bold tracking-tight text-fg`,children:e}),(0,F.jsx)(T,{title:`Queue not found`,hint:`No queue named "${e}" exists on the current Bunqueue server.`,action:(0,F.jsx)(r,{to:`/queues-classic`,className:`rounded-lg border border-line px-3 py-1.5 text-sm text-muted hover:bg-surface-2 hover:text-fg`,children:`Back to classic queues`})})]});let z=O?.exists===!0?O:H,{detail:B}=z,U=B.counts,W=x(U.completed??0,U.failed??0),G=[...z.jobs].sort((e,t)=>(t.createdAt??0)-(e.createdAt??0));return(0,F.jsxs)(`div`,{children:[k&&(0,F.jsx)(D,{onRetry:L}),(0,F.jsxs)(`div`,{className:`mb-6 flex flex-wrap items-start justify-between gap-4`,children:[(0,F.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,F.jsx)(r,{to:`/queues-classic`,"aria-label":`Back to classic queues`,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,F.jsx)(s,{className:`size-4`})}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`h1`,{className:`font-mono text-2xl font-bold tracking-tight text-fg`,children:e}),(0,F.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-3`,children:[(0,F.jsx)(p,{label:B.paused?`Paused`:`Active`,tone:B.paused?`amber`:`green`}),(0,F.jsx)(p,{label:k?`Stale`:`Live`,tone:k?`amber`:`green`})]})]})]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[B.paused?(0,F.jsxs)(E,{variant:`success`,size:`sm`,disabled:n!=null,onClick:()=>R(`resume`,()=>v.resume(e)),children:[(0,F.jsx)(d,{className:`size-3.5`}),` Resume`]}):(0,F.jsxs)(E,{variant:`warning`,size:`sm`,disabled:n!=null,onClick:()=>R(`pause`,()=>v.pause(e)),children:[(0,F.jsx)(l,{className:`size-3.5`}),` Pause`]}),(0,F.jsx)(E,{size:`sm`,disabled:!0,title:N,children:`Drain`}),(0,F.jsx)(E,{variant:`danger`,size:`sm`,disabled:!0,title:N,children:`Obliterate`})]})]}),c&&(0,F.jsx)(`div`,{className:`mb-4 rounded-lg border border-red-500/20 bg-red-500/5 px-4 py-2 text-sm text-red-400`,children:c}),(0,F.jsx)(`p`,{className:`mb-4 text-xs text-warning`,children:N}),(0,F.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-6`,children:[(0,F.jsx)(b,{label:`Waiting`,value:h(U.waiting),tone:`amber`}),(0,F.jsx)(b,{label:`Active`,value:h(U.active),tone:`blue`}),(0,F.jsx)(b,{label:`Completed`,value:h(U.completed),tone:`green`}),(0,F.jsx)(b,{label:`Failed`,value:h(U.failed),tone:U.failed?`red`:`default`}),(0,F.jsx)(b,{label:`Delayed`,value:h(U.delayed),tone:`default`}),(0,F.jsx)(b,{label:`Error Rate`,value:W==null?`—`:y(W),tone:W==null?`default`:W>.05?`red`:`green`})]}),(0,F.jsxs)(`div`,{className:`mt-8`,children:[(0,F.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,F.jsx)(`h2`,{className:`text-lg font-semibold text-fg`,children:`Recent Jobs`}),(0,F.jsxs)(r,{to:`/jobs-classic?queue=${encodeURIComponent(e)}`,className:`flex items-center gap-1 text-sm text-muted hover:text-fg`,children:[`View all jobs `,(0,F.jsx)(o,{className:`size-3.5`})]})]}),(0,F.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-line bg-surface`,children:(0,F.jsxs)(`table`,{className:`w-full min-w-[44rem] text-sm`,children:[(0,F.jsx)(`thead`,{children:(0,F.jsxs)(`tr`,{className:`border-b border-line text-left text-[11px] uppercase tracking-wider text-faint`,children:[(0,F.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`ID`}),(0,F.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Name`}),(0,F.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Status`}),(0,F.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Duration`}),(0,F.jsx)(`th`,{className:`px-5 py-3 text-right font-medium`,children:`Created`})]})}),(0,F.jsx)(`tbody`,{children:z.recentJobsError?(0,F.jsx)(`tr`,{children:(0,F.jsxs)(`td`,{colSpan:5,className:`px-5 py-12 text-center text-sm text-danger`,children:[`Could not load recent jobs — `,z.recentJobsError,`. Retry the page.`]})}):G.length===0?(0,F.jsx)(`tr`,{children:(0,F.jsx)(`td`,{colSpan:5,className:`px-5 py-12 text-center text-sm text-faint`,children:`No recent jobs.`})}):G.map(e=>(0,F.jsxs)(`tr`,{className:`border-b border-line last:border-0 hover:bg-surface-2/40`,children:[(0,F.jsx)(`td`,{className:`px-5 py-3 font-mono text-xs`,children:(0,F.jsx)(r,{to:`/job?id=${encodeURIComponent(e.id)}`,className:`rounded text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50`,children:e.id})}),(0,F.jsx)(`td`,{className:`px-5 py-3 text-fg`,children:e.data?.name||`unknown`}),(0,F.jsx)(`td`,{className:`px-5 py-3`,children:(0,F.jsx)(_,{status:String(e.state??e.status??`waiting`)})}),(0,F.jsx)(`td`,{className:`px-5 py-3 text-right tnum text-muted`,children:S(g(e.startedAt,e.completedAt))}),(0,F.jsx)(`td`,{className:`px-5 py-3 text-right text-faint`,children:w(e.createdAt)})]},e.id))})]})})]}),(0,F.jsx)(I,{queue:e})]})}export{U as QueueDetail};