@bratsos/workflow-engine-console 1.0.0-alpha.2

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.
@@ -0,0 +1,486 @@
1
+ import { ConsoleBadRequestError, ConsoleQueryTimeoutError, clampLimit, isConsoleStatus } from './chunk-THOZTVDT.js';
2
+
3
+ // src/generated/ui-bundle.ts
4
+ var UI_JS_NAME = "app.9b10515336.js";
5
+ var UI_CSS_NAME = "app.acfa97929e.css";
6
+ var UI_JS = '"use strict";(()=>{var ie,k,De,at,V,Ce,Re,xe,_e,ne,K,Pe,he,pe,fe,lt,oe={},ae=[],it=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,ue=Array.isArray;function F(t,n){for(var r in n)t[r]=n[r];return t}function me(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function ut(t,n,r){var o,l,a,i={};for(a in n)a=="key"?o=n[a]:a=="ref"?l=n[a]:i[a]=n[a];if(arguments.length>2&&(i.children=arguments.length>3?ie.call(arguments,2):r),typeof t=="function"&&t.defaultProps!=null)for(a in t.defaultProps)i[a]===void 0&&(i[a]=t.defaultProps[a]);return re(t,i,o,l,null)}function re(t,n,r,o,l){var a={type:t,props:n,key:r,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:l??++De,__i:-1,__u:0};return l==null&&k.vnode!=null&&k.vnode(a),a}function P(t){return t.children}function se(t,n){this.props=t,this.context=n}function B(t,n){if(n==null)return t.__?B(t.__,t.__i+1):null;for(var r;n<t.__k.length;n++)if((r=t.__k[n])!=null&&r.__e!=null)return r.__e;return typeof t.type=="function"?B(t):null}function ct(t){if(t.__P&&t.__d){var n=t.__v,r=n.__e,o=[],l=[],a=F({},n);a.__v=n.__v+1,k.vnode&&k.vnode(a),ve(t.__P,a,n,t.__n,t.__P.namespaceURI,32&n.__u?[r]:null,o,r??B(n),!!(32&n.__u),l),a.__v=n.__v,a.__.__k[a.__i]=a,qe(o,a,l),n.__e=n.__=null,a.__e!=r&&$e(a)}}function $e(t){if((t=t.__)!=null&&t.__c!=null)return t.__e=t.__c.base=null,t.__k.some(function(n){if(n!=null&&n.__e!=null)return t.__e=t.__c.base=n.__e}),$e(t)}function Ee(t){(!t.__d&&(t.__d=!0)&&V.push(t)&&!le.__r++||Ce!=k.debounceRendering)&&((Ce=k.debounceRendering)||Re)(le)}function le(){try{for(var t,n=1;V.length;)V.length>n&&V.sort(xe),t=V.shift(),n=V.length,ct(t)}finally{V.length=le.__r=0}}function Te(t,n,r,o,l,a,i,c,_,u,p){var f,s,h,v,y,b,w=o&&o.__k||ae,g=n.length;for(_=dt(r,n,w,_,g),f=0;f<g;f++)(h=r.__k[f])!=null&&(s=h.__i!=-1&&w[h.__i]||oe,h.__i=f,b=ve(t,h,s,l,a,i,c,_,u,p),v=h.__e,h.ref&&s.ref!=h.ref&&(s.ref&&ge(s.ref,null,h),p.push(h.ref,h.__c||v,h)),y==null&&v!=null&&(y=v),4&h.__u?(_=Le(h,_,t),s.__e&&(s.__e=null)):typeof h.type=="function"&&b!==void 0?_=b:v&&(_=v.nextSibling),h.__u&=-7);return r.__e=y,_}function dt(t,n,r,o,l){var a,i,c,_,u,p=r.length,f=p,s=0;for(t.__k=new Array(l),a=0;a<l;a++)(i=n[a])!=null&&typeof i!="boolean"&&typeof i!="function"?(typeof i=="string"||typeof i=="number"||typeof i=="bigint"||i.constructor==String?i=t.__k[a]=re(null,i,null,null,null):ue(i)?i=t.__k[a]=re(P,{children:i},null,null,null):i.constructor===void 0&&i.__b>0?i=t.__k[a]=re(i.type,i.props,i.key,i.ref?i.ref:null,i.__v):t.__k[a]=i,_=a+s,i.__=t,i.__b=t.__b+1,c=null,(u=i.__i=_t(i,r,_,f))!=-1&&(f--,(c=r[u])&&(c.__u|=2)),c==null||c.__v==null?(u==-1&&(l>p?s--:l<p&&s++),typeof i.type!="function"&&(i.__u|=4)):u!=_&&(u==_-1?s--:u==_+1?s++:(u>_?s--:s++,i.__u|=4))):t.__k[a]=null;if(f)for(a=0;a<p;a++)(c=r[a])!=null&&(2&c.__u)==0&&(c.__e==o&&(o=B(c)),He(c,c));return o}function Le(t,n,r){var o,l;if(typeof t.type=="function"){for(o=t.__k,l=0;o&&l<o.length;l++)o[l]&&(o[l].__=t,n=Le(o[l],n,r));return n}t.__e!=n&&(n&&t.type&&!n.parentNode&&(n=B(t)),n=r.insertBefore(t.__e,n||null));do n=n&&n.nextSibling;while(n!=null&&n.nodeType==8);return n}function _t(t,n,r,o){var l,a,i,c=t.key,_=t.type,u=n[r],p=u!=null&&(2&u.__u)==0;if(u===null&&c==null||p&&c==u.key&&_==u.type)return r;if(o>(p?1:0)){for(l=r-1,a=r+1;l>=0||a<n.length;)if((u=n[i=l>=0?l--:a++])!=null&&(2&u.__u)==0&&c==u.key&&_==u.type)return i}return-1}function Ne(t,n,r){n[0]=="-"?t.setProperty(n,r??""):t[n]=r==null?"":typeof r!="number"||it.test(n)?r:r+"px"}function te(t,n,r,o,l){var a,i;e:if(n=="style")if(typeof r=="string")t.style.cssText=r;else{if(typeof o=="string"&&(t.style.cssText=o=""),o)for(n in o)r&&n in r||Ne(t.style,n,"");if(r)for(n in r)o&&r[n]==o[n]||Ne(t.style,n,r[n])}else if(n[0]=="o"&&n[1]=="n")a=n!=(n=n.replace(Pe,"$1")),i=n.toLowerCase(),n=i in t||n=="onFocusOut"||n=="onFocusIn"?i.slice(2):n.slice(2),t.l||(t.l={}),t.l[n+a]=r,r?o?r[K]=o[K]:(r[K]=he,t.addEventListener(n,a?fe:pe,a)):t.removeEventListener(n,a?fe:pe,a);else{if(l=="http://www.w3.org/2000/svg")n=n.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(n!="width"&&n!="height"&&n!="href"&&n!="list"&&n!="form"&&n!="tabIndex"&&n!="download"&&n!="rowSpan"&&n!="colSpan"&&n!="role"&&n!="popover"&&n in t)try{t[n]=r??"";break e}catch{}typeof r=="function"||(r==null||r===!1&&n[4]!="-"?t.removeAttribute(n):t.setAttribute(n,n=="popover"&&r==1?"":r))}}function Ae(t){return function(n){if(this.l){var r=this.l[n.type+t];if(n[ne]==null)n[ne]=he++;else if(n[ne]<r[K])return;return r(k.event?k.event(n):n)}}}function ve(t,n,r,o,l,a,i,c,_,u){var p,f,s,h,v,y,b,w,g,C,U,T,O,L,R,H,D=n.type;if(n.constructor!==void 0)return null;128&r.__u&&(_=!!(32&r.__u),a=[c=n.__e=r.__e]),(p=k.__b)&&p(n);e:if(typeof D=="function"){f=i.length;try{if(g=n.props,C=D.prototype&&D.prototype.render,U=(p=D.contextType)&&o[p.__c],T=p?U?U.props.value:p.__:o,r.__c?w=(s=n.__c=r.__c).__=s.__E:(C?n.__c=s=new D(g,T):(n.__c=s=new se(g,T),s.constructor=D,s.render=ft),U&&U.sub(s),s.state||(s.state={}),s.__n=o,h=s.__d=!0,s.__h=[],s._sb=[]),C&&s.__s==null&&(s.__s=s.state),C&&D.getDerivedStateFromProps!=null&&(s.__s==s.state&&(s.__s=F({},s.__s)),F(s.__s,D.getDerivedStateFromProps(g,s.__s))),v=s.props,y=s.state,s.__v=n,h)C&&D.getDerivedStateFromProps==null&&s.componentWillMount!=null&&s.componentWillMount(),C&&s.componentDidMount!=null&&s.__h.push(s.componentDidMount);else{if(C&&D.getDerivedStateFromProps==null&&g!==v&&s.componentWillReceiveProps!=null&&s.componentWillReceiveProps(g,T),n.__v==r.__v||!s.__e&&s.shouldComponentUpdate!=null&&s.shouldComponentUpdate(g,s.__s,T)===!1){n.__v!=r.__v&&(s.props=g,s.state=s.__s,s.__d=!1),n.__e=r.__e,n.__k=r.__k,n.__k.some(function(x){x&&(x.__=n)}),ae.push.apply(s.__h,s._sb),s._sb=[],s.__h.length&&i.push(s),c=B(r);break e}s.componentWillUpdate!=null&&s.componentWillUpdate(g,s.__s,T),C&&s.componentDidUpdate!=null&&s.__h.push(function(){s.componentDidUpdate(v,y,b)})}if(s.context=T,s.props=g,s.__P=t,s.__e=!1,O=k.__r,L=0,C)s.state=s.__s,s.__d=!1,O&&O(n),p=s.render(s.props,s.state,s.context),ae.push.apply(s.__h,s._sb),s._sb=[];else do s.__d=!1,O&&O(n),p=s.render(s.props,s.state,s.context),s.state=s.__s;while(s.__d&&++L<25);s.state=s.__s,s.getChildContext!=null&&(o=F(F({},o),s.getChildContext())),C&&!h&&s.getSnapshotBeforeUpdate!=null&&(b=s.getSnapshotBeforeUpdate(v,y)),R=p!=null&&p.type===P&&p.key==null?Oe(p.props.children):p,c=Te(t,ue(R)?R:[R],n,r,o,l,a,i,c,_,u),s.base=n.__e,n.__u&=-161,s.__h.length&&i.push(s),w&&(s.__E=s.__=null)}catch(x){if(i.length=f,n.__v=null,_||a!=null){if(x.then){for(n.__u|=_?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;a!=null&&(a[a.indexOf(c)]=null),n.__e=c}else if(a!=null)for(H=a.length;H--;)me(a[H])}else n.__e=r.__e;n.__k==null&&(n.__k=r.__k||[]),x.then||Me(n),k.__e(x,n,r)}}else a==null&&n.__v==r.__v?(n.__k=r.__k,n.__e=r.__e):c=n.__e=pt(r.__e,n,r,o,l,a,i,_,u);return(p=k.diffed)&&p(n),128&n.__u?void 0:c}function Me(t){t&&(t.__c&&(t.__c.__e=!0),t.__k&&t.__k.some(Me))}function qe(t,n,r){for(var o=0;o<r.length;o++)ge(r[o],r[++o],r[++o]);k.__c&&k.__c(n,t),t.some(function(l){try{t=l.__h,l.__h=[],t.some(function(a){a.call(l)})}catch(a){k.__e(a,l.__v)}})}function Oe(t){return typeof t!="object"||t==null||t.__b>0?t:ue(t)?t.map(Oe):t.constructor!==void 0?null:F({},t)}function pt(t,n,r,o,l,a,i,c,_){var u,p,f,s,h,v,y,b=r.props||oe,w=n.props,g=n.type;if(g=="svg"?l="http://www.w3.org/2000/svg":g=="math"?l="http://www.w3.org/1998/Math/MathML":l||(l="http://www.w3.org/1999/xhtml"),a!=null){for(u=0;u<a.length;u++)if((h=a[u])&&"setAttribute"in h==!!g&&(g?h.localName==g:h.nodeType==3)){t=h,a[u]=null;break}}if(t==null){if(g==null)return document.createTextNode(w);t=document.createElementNS(l,g,w.is&&w),c&&(k.__m&&k.__m(n,a),c=!1),a=null}if(g==null)b===w||c&&t.data==w||(t.data=w);else{if(a=g=="textarea"&&w.defaultValue!=null?null:a&&ie.call(t.childNodes),!c&&a!=null)for(b={},u=0;u<t.attributes.length;u++)b[(h=t.attributes[u]).name]=h.value;for(u in b)h=b[u],u=="dangerouslySetInnerHTML"?f=h:u=="children"||u in w||u=="value"&&"defaultValue"in w||u=="checked"&&"defaultChecked"in w||te(t,u,null,h,l);for(u in w)h=w[u],u=="children"?s=h:u=="dangerouslySetInnerHTML"?p=h:u=="value"?v=h:u=="checked"?y=h:c&&typeof h!="function"||b[u]===h||te(t,u,h,b[u],l);if(p)c||f&&(p.__html==f.__html||p.__html==t.innerHTML)||(t.innerHTML=p.__html),n.__k=[];else if(f&&(t.innerHTML=""),Te(n.type=="template"?t.content:t,ue(s)?s:[s],n,r,o,g=="foreignObject"?"http://www.w3.org/1999/xhtml":l,a,i,a?a[0]:r.__k&&B(r,0),c,_),a!=null)for(u=a.length;u--;)me(a[u]);c&&g!="textarea"||(u="value",g=="progress"&&v==null?t.removeAttribute("value"):v!=null&&(v!==t[u]||g=="progress"&&!v||g=="option"&&v!=b[u])&&te(t,u,v,b[u],l),u="checked",y!=null&&y!=t[u]&&te(t,u,y,b[u],l))}return t}function ge(t,n,r){try{if(typeof t=="function"){var o=typeof t.__u=="function";o&&t.__u(),o&&n==null||(t.__u=t(n))}else t.current=n}catch(l){k.__e(l,r)}}function He(t,n,r){var o,l;if(k.unmount&&k.unmount(t),(o=t.ref)&&(o.current&&o.current!=t.__e||ge(o,null,n)),(o=t.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(a){k.__e(a,n)}o.base=o.__P=o.__n=null}if(o=t.__k)for(l=0;l<o.length;l++)o[l]&&He(o[l],n,r||typeof t.type!="function");r||me(t.__e),t.__c=t.__=t.__e=void 0}function ft(t,n,r){return this.constructor(t,r)}function Ue(t,n,r){var o,l,a,i;n==document&&(n=document.documentElement),k.__&&k.__(t,n),l=(o=typeof r=="function")?null:r&&r.__k||n.__k,a=[],i=[],ve(n,t=(!o&&r||n).__k=ut(P,null,[t]),l||oe,oe,n.namespaceURI,!o&&r?[r]:l?null:n.firstChild?ie.call(n.childNodes):null,a,!o&&r?r:l?l.__e:n.firstChild,o,i),qe(a,t,i),t.props.children=null}ie=ae.slice,k={__e:function(t,n,r,o){for(var l,a,i;n=n.__;)if((l=n.__c)&&!l.__)try{if((a=l.constructor)&&a.getDerivedStateFromError!=null&&(l.setState(a.getDerivedStateFromError(t)),i=l.__d),l.componentDidCatch!=null&&(l.componentDidCatch(t,o||{}),i=l.__d),i)return l.__E=l}catch(c){t=c}throw t}},De=0,at=function(t){return t!=null&&t.constructor===void 0},se.prototype.setState=function(t,n){var r;r=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=F({},this.state),typeof t=="function"&&(t=t(F({},r),this.props)),t&&F(r,t),t!=null&&this.__v&&(n&&this._sb.push(n),Ee(this))},se.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),Ee(this))},se.prototype.render=P,V=[],Re=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,xe=function(t,n){return t.__v.__b-n.__v.__b},le.__r=0,_e=Math.random().toString(8),ne="__d"+_e,K="__a"+_e,Pe=/(PointerCapture)$|Capture$/i,he=0,pe=Ae(!1),fe=Ae(!0),lt=0;var G,N,be,We,z=0,Ge=[],A=k,Fe=A.__b,Ve=A.__r,je=A.diffed,Be=A.__c,Je=A.unmount,Qe=A.__;function we(t,n){A.__h&&A.__h(N,t,z||n),z=0;var r=N.__H||(N.__H={__:[],__h:[]});return t>=r.__.length&&r.__.push({}),r.__[t]}function S(t){return z=1,ht(Xe,t)}function ht(t,n,r){var o=we(G++,2);if(o.t=t,!o.__c&&(o.__=[r?r(n):Xe(void 0,n),function(c){var _=o.__N?o.__N[0]:o.__[0],u=o.t(_,c);_!==u&&(o.__N=[u,o.__[1]],o.__c.setState({}))}],o.__c=N,!N.__f)){var l=function(c,_,u){if(!o.__c.__H)return!0;var p=!1,f=o.__c.props!==c;if(o.__c.__H.__.some(function(h){if(h.__N){p=!0;var v=h.__[0];h.__=h.__N,h.__N=void 0,v!==h.__[0]&&(f=!0)}}),a){var s=a.call(this,c,_,u);return p?s||f:s}return!p||f};N.__f=!0;var a=N.shouldComponentUpdate,i=N.componentWillUpdate;N.componentWillUpdate=function(c,_,u){if(this.__e){var p=a;a=void 0,l(c,_,u),a=p}i&&i.call(this,c,_,u)},N.shouldComponentUpdate=l}return o.__N||o.__}function Y(t,n){var r=we(G++,3);!A.__s&&Ye(r.__H,n)&&(r.__=t,r.u=n,N.__H.__h.push(r))}function ze(t){return z=5,j(function(){return{current:t}},[])}function j(t,n){var r=we(G++,7);return Ye(r.__H,n)&&(r.__=t(),r.__H=n,r.__h=t),r.__}function J(t,n){return z=8,j(function(){return t},n)}function mt(){for(var t;t=Ge.shift();){var n=t.__H;if(t.__P&&n)try{n.__h.some(ce),n.__h.some(ye),n.__h=[]}catch(r){n.__h=[],A.__e(r,t.__v)}}}A.__b=function(t){N=null,Fe&&Fe(t)},A.__=function(t,n){t&&n.__k&&n.__k.__m&&(t.__m=n.__k.__m),Qe&&Qe(t,n)},A.__r=function(t){Ve&&Ve(t),G=0;var n=(N=t.__c).__H;n&&(be===N?(n.__h=[],N.__h=[],n.__.some(function(r){r.__N&&(r.__=r.__N),r.u=r.__N=void 0})):(n.__h.some(ce),n.__h.some(ye),n.__h=[],G=0)),be=N},A.diffed=function(t){je&&je(t);var n=t.__c;n&&n.__H&&(n.__H.__h.length&&(Ge.push(n)!==1&&We===A.requestAnimationFrame||((We=A.requestAnimationFrame)||vt)(mt)),n.__H.__.some(function(r){r.u&&(r.__H=r.u,r.u=void 0)})),be=N=null},A.__c=function(t,n){n.some(function(r){try{r.__h.some(ce),r.__h=r.__h.filter(function(o){return!o.__||ye(o)})}catch(o){n.some(function(l){l.__h&&(l.__h=[])}),n=[],A.__e(o,r.__v)}}),Be&&Be(t,n)},A.unmount=function(t){Je&&Je(t);var n,r=t.__c;r&&r.__H&&(r.__H.__.some(function(o){try{ce(o)}catch(l){n=l}}),r.__H=void 0,n&&A.__e(n,r.__v))};var Ke=typeof requestAnimationFrame=="function";function vt(t){var n,r=function(){clearTimeout(o),Ke&&cancelAnimationFrame(n),setTimeout(t)},o=setTimeout(r,35);Ke&&(n=requestAnimationFrame(r))}function ce(t){var n=N,r=t.__c;typeof r=="function"&&(t.__c=void 0,r()),N=n}function ye(t){var n=N;t.__c=t.__(),N=n}function Ye(t,n){return!t||t.length!==n.length||n.some(function(r,o){return r!==t[o]})}function Xe(t,n){return typeof n=="function"?n(t):n}var gt=0;function e(t,n,r,o,l,a){n||(n={});var i,c,_=n;if("ref"in _)for(c in _={},n)c=="ref"?i=n[c]:_[c]=n[c];var u={type:t,props:_,key:r,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--gt,__i:-1,__u:0,__source:l,__self:a};if(typeof t=="function"&&(i=t.defaultProps))for(c in i)_[c]===void 0&&(_[c]=i[c]);return k.vnode&&k.vnode(u),u}var ke=class extends Error{code;constructor(n,r){super(r),this.name="ApiError",this.code=n}};function Q(t){if(!t)return"\\u2014";let n=Date.parse(t);if(Number.isNaN(n))return"\\u2014";let r=Date.now()-n;if(r>=0){let o=Math.floor(r/1e3);if(o<10)return"just now";if(o<60)return`${o}s ago`;let l=Math.floor(o/60);if(l<60)return`${l}m ago`;let a=Math.floor(l/60);return a<24?`${a}h ago`:`${Math.floor(a/24)}d ago`}else{let o=Math.floor(-r/1e3);if(o<10)return"just now";if(o<60)return`in ${o}s`;let l=Math.floor(o/60);if(l<60)return`in ${l}m`;let a=Math.floor(l/60);return a<24?`in ${a}h`:`in ${Math.floor(a/24)}d`}}function bt(t){if(!t)return"\\u2014";let n=Date.parse(t);if(Number.isNaN(n))return"\\u2014";let r=Date.now()-n;if(r>0){let o=Math.floor(r/1e3);if(o<60)return`overdue by ${o}s`;let l=Math.floor(o/60);if(l<60)return`overdue by ${l}m`;let a=Math.floor(l/60);return a<24?`overdue by ${a}h`:`overdue by ${Math.floor(a/24)}d`}return Q(t)}function de(t){if(t==null||Number.isNaN(t))return"\\u2014";if(t<0)return"0s";if(t<1e3)return`${t}ms`;if(t<1e4)return`${(t/1e3).toFixed(1)}s`;let n=Math.round(t/1e3);if(n<60)return`${n}s`;let r=Math.floor(n/60),o=n%60;if(r<60)return o>0?`${r}m ${o}s`:`${r}m`;let l=Math.floor(r/60),a=r%60;return a>0?`${l}h ${a}m`:`${l}h`}function Se(t){return typeof t!="number"||Number.isNaN(t)?"$0.0000":`$${t.toFixed(4)}`}function Ie(t){return typeof t!="number"||Number.isNaN(t)?"0":t.toLocaleString()}function $(t){if(!t)return"\\u2014";let n=new Date(t);return Number.isNaN(n.getTime())?"\\u2014":n.toLocaleString()}function rt(t){return t?t.length>8?`\\u2026${t.slice(-8)}`:t:"\\u2014"}async function q(t,n,r){let o=`${t.basePath}/api${n}`,l=new Headers(r?.headers);r?.body&&!l.has("content-type")&&l.set("content-type","application/json");let a=await fetch(o,{credentials:"same-origin",...r,headers:l});if(!a.ok){let i="unknown",c=`Request failed with status ${a.status}`;try{let _=await a.json();_?.error?.message&&(c=_.error.message,i=_.error.code??"unknown")}catch{}throw new ke(i,c)}return await a.json()}function Z(t,n,r,o){let[l,a]=S(null),[i,c]=S(null),[_,u]=S(!0),[p,f]=S(0),s=ze(t);s.current=t;let h=J(()=>{f(v=>v+1)},[]);return Y(()=>{let v=!0;u(!0);let y=async()=>{try{let C=await s.current();if(!v)return;a(C),c(null)}catch(C){if(!v)return;c(C instanceof Error?C:new Error(String(C)))}finally{v&&u(!1)}};y();let b=null,w=()=>{b&&clearInterval(b),b=null,!o&&r>0&&typeof document<"u"&&!document.hidden&&(b=setInterval(()=>{!o&&!document.hidden&&y()},r))},g=()=>{typeof document<"u"&&!document.hidden&&!o&&r>0?(y(),w()):b&&(clearInterval(b),b=null)};return w(),document.addEventListener("visibilitychange",g),()=>{v=!1,b&&clearInterval(b),document.removeEventListener("visibilitychange",g)}},[...n,p,r,o]),{data:l,error:i,loading:_,refresh:h}}function Ze(t){let n=t.startsWith("#")?t.slice(1):t,o=(n.startsWith("/")?n.slice(1):n).split("/").filter(Boolean),l=o[0];if(l==="runs"){let a=o[1];return o.length>=2&&a?{view:"run-detail",runId:decodeURIComponent(o.slice(1).join("/"))}:{view:"runs"}}return l==="queue"?{view:"queue"}:l==="dead-letters"?{view:"dead-letters"}:l==="costs"?{view:"costs"}:{view:"runs"}}function yt(){let[t,n]=S(()=>Ze(window.location.hash));return Y(()=>{let r=()=>{n(Ze(window.location.hash))};return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]),t}var st="workflow-console:poll";function wt(t){try{let n=localStorage.getItem(st);if(n!==null){let r=Number(n);if(Number.isFinite(r)&&[0,2e3,5e3,1e4,3e4,6e4].includes(r))return r}}catch{}return t}function kt(t){try{localStorage.setItem(st,String(t))}catch{}}function X({status:t}){let n=t.toLowerCase(),r=["pending","running","suspended","completed","failed","cancelled","skipped"].includes(n)?`pill-${n}`:"pill-pending";return e("span",{class:`pill ${r}`,children:t})}function ee({error:t,onDismiss:n}){if(!t)return null;let r="code"in t&&t.code==="query_timeout",o="code"in t&&t.code==="forbidden",l=t.message;return o?l="You are not permitted to view this.":r&&(l=`${t.message} Narrow the filter and try again.`),e("div",{class:"banner",role:"status",children:[e("span",{class:"banner-message",children:l}),e("button",{type:"button",class:"banner-dismiss",onClick:n,"aria-label":"Dismiss error",children:"\\xD7"})]})}var ot=["PENDING","RUNNING","SUSPENDED","COMPLETED","FAILED","CANCELLED","SKIPPED"];function et(t,n=300){let[r,o]=S(t);return Y(()=>{let l=setTimeout(()=>o(t),n);return()=>clearTimeout(l)},[t,n]),r}function St({config:t,pollInterval:n,paused:r,refreshSignal:o}){let[l,a]=S([]),[i,c]=S(""),[_,u]=S(""),[p,f]=S(""),[s,h]=S(""),v=et(i),y=et(_),[b,w]=S(void 0),[g,C]=S([]),[U,T]=S(null);Y(()=>{w(void 0),C([])},[l,v,y,p,s]);let O=m=>{a(M=>M.includes(m)?M.filter(W=>W!==m):[...M,m])},L=J(async()=>{let m=new URLSearchParams;for(let W of l)m.append("status",W);if(v.trim()&&m.set("workflowId",v.trim()),y.trim()&&m.set("definitionVersion",y.trim()),p){let W=new Date(p);Number.isNaN(W.getTime())||m.set("from",W.toISOString())}if(s){let W=new Date(s);Number.isNaN(W.getTime())||m.set("to",W.toISOString())}b&&m.set("cursor",b);let M=m.toString();return await q(t,`/runs${M?`?${M}`:""}`)},[t,l,v,y,p,s,b]),{data:R,error:H,loading:D}=Z(L,[L,o],n,r),x=H===U?null:H,d=x&&"code"in x&&x.code==="forbidden",I=()=>{R?.nextCursor&&(C(m=>[...m,b??""]),w(R.nextCursor))},E=()=>{if(g.length>0){let m=[...g],M=m.pop();C(m),w(M===""?void 0:M)}};return e("div",{children:[e("div",{class:"filter-bar",children:[e("div",{class:"filter-row",children:e("div",{class:"status-toggle-group",children:ot.map(m=>e("button",{type:"button",class:`status-toggle ${l.includes(m)?"active":""}`,onClick:()=>O(m),children:m},m))})}),e("div",{class:"filter-row",children:[e("label",{class:"sr-only",for:"wc-filter-workflow",children:"Workflow ID"}),e("input",{id:"wc-filter-workflow",type:"text",placeholder:"Filter workflow ID...",value:i,onInput:m=>c(m.target.value)}),e("label",{class:"sr-only",for:"wc-filter-version",children:"Definition version"}),e("input",{id:"wc-filter-version",type:"text",placeholder:"Filter definition version...",value:_,onInput:m=>u(m.target.value)}),e("label",{class:"sr-only",for:"wc-filter-from",children:"From"}),e("input",{id:"wc-filter-from",type:"datetime-local",value:p,onChange:m=>f(m.target.value)}),e("label",{class:"sr-only",for:"wc-filter-to",children:"To"}),e("input",{id:"wc-filter-to",type:"datetime-local",value:s,onChange:m=>h(m.target.value)})]})]}),e(ee,{error:x,onDismiss:()=>T(H)}),!d&&e(P,{children:[e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{scope:"col",children:"Status"}),e("th",{scope:"col",children:"Run ID"}),e("th",{scope:"col",children:"Workflow"}),e("th",{scope:"col",children:"Version"}),e("th",{scope:"col",children:"Started"}),e("th",{scope:"col",children:"Duration"}),e("th",{scope:"col",children:"Cost"}),e("th",{scope:"col",children:"Tokens"})]})}),e("tbody",{children:[(R?.runs??[]).map(m=>e("tr",{children:[e("td",{children:e(X,{status:m.status})}),e("td",{children:e("a",{href:`#/runs/${encodeURIComponent(m.id)}`,title:m.id,children:m.id.length>12?`\\u2026${m.id.slice(-12)}`:m.id})}),e("td",{children:m.workflowName||m.workflowId}),e("td",{title:m.definitionVersion??void 0,children:[rt(m.definitionVersion),m.redriveCount>0&&e("span",{title:`${m.redriveCount} redrives`,children:` +${m.redriveCount}`})]}),e("td",{children:Q(m.startedAt)}),e("td",{children:de(m.duration)}),e("td",{children:Se(m.totalCost)}),e("td",{children:Ie(m.totalTokens)})]},m.id)),R&&R.runs.length===0&&e("tr",{children:e("td",{colspan:8,class:"empty-state",children:"No workflow runs found."})})]})]})}),e("div",{class:"pagination",children:[e("button",{type:"button",disabled:g.length===0||D,onClick:E,children:"Previous"}),e("button",{type:"button",disabled:!R?.nextCursor||D,onClick:I,children:"Next"})]})]})]})}function tt({step:t,canSignal:n,busy:r,onSignal:o}){let[l,a]=S(!1),[i,c]=S("null"),[_,u]=S(null),p=t.kind==="signal"&&t.status==="pending",f=n&&p&&o!==void 0,s=async()=>{let h;try{h=i.trim()===""?null:JSON.parse(i)}catch(v){u(v instanceof Error?v.message:"Payload must be valid JSON.");return}u(null),await o?.(h),a(!1)};return e(P,{children:[e("tr",{children:[e("td",{style:{width:"50px"},children:t.seq}),e("td",{children:t.stepId}),e("td",{children:t.kind}),e("td",{children:[e(X,{status:t.status}),f&&e("button",{type:"button",class:"btn-sm step-signal-toggle",disabled:r,"aria-expanded":l,onClick:()=>a(h=>!h),children:"Deliver signal"})]}),e("td",{children:t.attempt}),e("td",{children:$(t.leaseExpiresAt)}),e("td",{children:$(t.deadlineAt)}),e("td",{title:t.externalKey??void 0,children:t.kind==="run"&&t.externalKey?e("code",{children:t.externalKey}):"\\u2014"}),e("td",{children:t.error||"\\u2014"})]}),f&&l&&e("tr",{class:"step-signal-row",children:e("td",{colspan:9,children:e("form",{class:"step-signal-form",onSubmit:h=>{h.preventDefault(),s()},children:[e("label",{class:"step-signal-label",for:`signal-${t.id}`,children:["Payload (JSON) for ",e("code",{children:t.stepId})]}),e("textarea",{id:`signal-${t.id}`,rows:3,spellcheck:!1,value:i,onInput:h=>{c(h.currentTarget.value),_&&u(null)}}),_&&e("div",{class:"step-signal-error",role:"alert",children:["Invalid JSON: ",_]}),e("div",{class:"step-signal-actions",children:[e("button",{type:"submit",class:"btn-sm btn-primary",disabled:r,children:"Send signal"}),e("button",{type:"button",class:"btn-sm",disabled:r,onClick:()=>{a(!1),u(null)},children:"Cancel"})]})]})})})]})}function It({config:t,runId:n,pollInterval:r,paused:o,refreshSignal:l}){let[a,i]=S(!1),[c,_]=S(null),[u,p]=S(null),f=J(async()=>await q(t,`/runs/${encodeURIComponent(n)}`),[t,n]),{data:s,error:h,refresh:v}=Z(f,[f,l],r,o),y=c??h,b=y===u?null:y,w=b&&"code"in b&&b.code==="forbidden",g=async()=>{if(window.confirm("Cancel this workflow run?")){i(!0),_(null);try{await q(t,`/runs/${encodeURIComponent(n)}/cancel`,{method:"POST",body:"{}"}),v()}catch(d){_(d instanceof Error?d:new Error(String(d)))}finally{i(!1)}}},C=async(d,I)=>{window.confirm(`Rerun workflow from stage "${I}"?`)&&await O({from:{kind:"stage",stageId:d}})},U=async()=>{window.confirm("Redrive this run from its last failure on the version this deployment serves?")&&await O({from:{kind:"lastFailure"},definitionVersion:"latest"})},T=async(d,I,E)=>{i(!0),_(null);try{await q(t,`/runs/${encodeURIComponent(n)}/stages/${encodeURIComponent(d)}/steps/${encodeURIComponent(I)}/signal`,{method:"POST",body:JSON.stringify({payload:E})}),v()}catch(m){_(m instanceof Error?m:new Error(String(m)))}finally{i(!1)}},O=async d=>{i(!0),_(null);try{await q(t,`/runs/${encodeURIComponent(n)}/rerun`,{method:"POST",body:JSON.stringify(d)}),v()}catch(I){_(I instanceof Error?I:new Error(String(I)))}finally{i(!1)}},L=j(()=>[...s?.stages??[]].sort((d,I)=>d.stageNumber-I.stageNumber),[s?.stages]),{runStartMs:R,totalDurationMs:H}=j(()=>{if(!s?.run)return{runStartMs:0,totalDurationMs:1};let d=L[0],I=s.run.startedAt?Date.parse(s.run.startedAt):d?.startedAt?Date.parse(d.startedAt):Date.parse(s.run.createdAt),E=s.run.completedAt?Date.parse(s.run.completedAt):Date.now();return{runStartMs:Number.isNaN(I)?0:I,totalDurationMs:Math.max(1,(Number.isNaN(E)?Date.now():E)-I)}},[s?.run,L]),{stepsByStage:D,unassignedSteps:x}=j(()=>{let d=new Map,I=[];for(let E of s?.steps??[])if(E.stageRecordId){let m=d.get(E.stageRecordId);m?m.push(E):d.set(E.stageRecordId,[E])}else I.push(E);return{stepsByStage:d,unassignedSteps:I}},[s?.steps]);return e("div",{children:[e(ee,{error:b,onDismiss:()=>{p(y),_(null)}}),s&&!w&&e(P,{children:[e("div",{class:"run-detail-header",children:[e("div",{class:"run-detail-title-row",children:[e("div",{class:"run-detail-title-left",children:[e("a",{href:"#/runs",children:"\\u2190 Back to runs"}),e("h2",{class:"header-title",style:{wordBreak:"break-all"},children:s.run.id}),e(X,{status:s.run.status})]}),!t.readOnly&&e("div",{class:"run-detail-actions",children:[s.run.definitionVersion&&e("button",{type:"button",disabled:a,onClick:U,title:"Move this run onto the definition version this deployment serves, then redrive it from its last failure",children:"Redrive on latest version"}),e("button",{type:"button",class:"btn-danger",disabled:a,onClick:g,children:"Cancel run"})]})]}),e("div",{class:"run-detail-meta",children:[e("div",{class:"meta-item",children:[e("span",{class:"meta-label",children:"Workflow"}),e("span",{class:"meta-value",children:s.run.workflowName||s.run.workflowId})]}),e("div",{class:"meta-item",children:[e("span",{class:"meta-label",children:"Version"}),e("span",{class:"meta-value",title:s.run.definitionVersion??void 0,children:rt(s.run.definitionVersion)})]}),e("div",{class:"meta-item",children:[e("span",{class:"meta-label",children:"Redrives"}),e("span",{class:"meta-value",children:s.run.redriveCount})]}),e("div",{class:"meta-item",children:[e("span",{class:"meta-label",children:"Started"}),e("span",{class:"meta-value",children:$(s.run.startedAt)})]}),e("div",{class:"meta-item",children:[e("span",{class:"meta-label",children:"Completed"}),e("span",{class:"meta-value",children:$(s.run.completedAt)})]}),e("div",{class:"meta-item",children:[e("span",{class:"meta-label",children:"Duration"}),e("span",{class:"meta-value",children:de(s.run.duration)})]}),e("div",{class:"meta-item",children:[e("span",{class:"meta-label",children:"Cost"}),e("span",{class:"meta-value",children:Se(s.run.totalCost)})]}),e("div",{class:"meta-item",children:[e("span",{class:"meta-label",children:"Tokens"}),e("span",{class:"meta-value",children:Ie(s.run.totalTokens)})]})]})]}),e("div",{class:"section-header",children:e("h3",{class:"section-title",children:"Stage timeline"})}),e("div",{class:"stage-timeline",children:[L.map(d=>{let I=0,E=0;if(d.startedAt&&R>0){let m=Date.parse(d.startedAt),M=d.completedAt?Date.parse(d.completedAt):Date.now();I=Math.max(0,Math.min(100,(m-R)/H*100)),E=Math.max(.5,Math.min(100-I,(M-m)/H*100))}return e("div",{class:"stage-timeline-row",children:[e("div",{class:"stage-timeline-meta",children:[e("div",{class:"stage-timeline-meta-left",children:[e("span",{class:"stage-num",children:["#",d.stageNumber]}),e("span",{class:"stage-name",children:d.stageName}),e(X,{status:d.status}),e("span",{class:"stage-timings",children:[e("span",{children:$(d.startedAt)}),e("span",{children:"\\u2192"}),e("span",{children:$(d.completedAt)}),e("span",{children:["(",de(d.duration),")"]})]})]}),!t.readOnly&&e("button",{type:"button",class:"btn-sm",disabled:a,onClick:()=>C(d.stageId,d.stageName),children:"Rerun from here"})]}),e("div",{class:"timeline-track",children:e("div",{class:"timeline-bar",style:{left:`${I}%`,width:`${E}%`}})}),d.errorMessage&&e("div",{class:"stage-error",children:d.errorMessage})]},d.id)}),L.length===0&&e("div",{class:"empty-state",children:"No stages recorded."})]}),e("div",{class:"section-header",children:e("h3",{class:"section-title",children:"Step ledger"})}),e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{scope:"col",children:"Seq"}),e("th",{scope:"col",children:"Step ID"}),e("th",{scope:"col",children:"Kind"}),e("th",{scope:"col",children:"Status"}),e("th",{scope:"col",children:"Attempt"}),e("th",{scope:"col",children:"Lease expires"}),e("th",{scope:"col",children:"Deadline"}),e("th",{scope:"col",children:"External key"}),e("th",{scope:"col",children:"Error"})]})}),e("tbody",{children:[L.map(d=>{let I=(D.get(d.id)??[]).sort((E,m)=>E.seq-m.seq);return I.length===0?null:e("tr",{children:e("td",{colspan:9,style:{padding:0},children:e("table",{style:{width:"100%",margin:0},children:[e("thead",{children:e("tr",{class:"table-group-header",children:e("th",{scope:"colgroup",colspan:9,children:["Stage #",d.stageNumber,": ",d.stageName]})})}),e("tbody",{children:I.map(E=>e(tt,{step:E,canSignal:!t.readOnly,busy:a,onSignal:m=>T(d.stageId,E.stepId,m)},E.id))})]})})},`group-${d.id}`)}),x.length>0&&e("tr",{children:e("td",{colspan:9,style:{padding:0},children:e("table",{style:{width:"100%",margin:0},children:[e("thead",{children:e("tr",{class:"table-group-header",children:e("th",{scope:"colgroup",colspan:9,children:"Other steps"})})}),e("tbody",{children:x.map(d=>e(tt,{step:d,canSignal:!1,busy:a},d.id))})]})})}),s.steps.length===0&&e("tr",{children:e("td",{colspan:9,class:"empty-state",children:"No steps recorded."})})]})]})}),s.truncated.steps&&e("p",{class:"truncated-note",children:["Showing the first ",s.steps.length," \\u2014 there are more."]}),e("div",{class:"section-header",children:e("h3",{class:"section-title",children:"Events"})}),e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{scope:"col",children:"Sequence"}),e("th",{scope:"col",children:"Event type"}),e("th",{scope:"col",children:"Occurred"}),e("th",{scope:"col",children:"Published"}),e("th",{scope:"col",children:"Retries"}),e("th",{scope:"col",children:"Dead-lettered"})]})}),e("tbody",{children:[s.events.map(d=>e("tr",{children:[e("td",{children:d.sequence}),e("td",{children:d.eventType}),e("td",{children:$(d.occurredAt)}),e("td",{children:d.publishedAt?$(d.publishedAt):"pending"}),e("td",{children:d.retryCount}),e("td",{children:d.dlqAt?e("span",{class:"badge badge-dlq",title:`DLQ at ${d.dlqAt}`,children:"Dead-lettered"}):"\\u2014"})]},d.id)),s.events.length===0&&e("tr",{children:e("td",{colspan:6,class:"empty-state",children:"No events recorded."})})]})]})}),s.truncated.events&&e("p",{class:"truncated-note",children:["Showing the first ",s.events.length," \\u2014 there are more."]}),e("div",{class:"section-header",children:e("h3",{class:"section-title",children:"Annotations"})}),e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{scope:"col",children:"Key"}),e("th",{scope:"col",children:"Value"}),e("th",{scope:"col",children:"Scope"}),e("th",{scope:"col",children:"Actor"}),e("th",{scope:"col",children:"Attempt"}),e("th",{scope:"col",children:"Created"})]})}),e("tbody",{children:[s.annotations.map(d=>e("tr",{children:[e("td",{children:d.key}),e("td",{children:e("code",{children:typeof d.value=="string"?d.value:JSON.stringify(d.value)})}),e("td",{children:[d.scope,d.scopeId?` (${d.scopeId})`:""]}),e("td",{children:d.actorKind||d.actorId?`${d.actorKind??""}:${d.actorId??""}`:"\\u2014"}),e("td",{children:d.attempt}),e("td",{children:$(d.createdAt)})]},d.id)),s.annotations.length===0&&e("tr",{children:e("td",{colspan:6,class:"empty-state",children:"No annotations recorded."})})]})]})}),s.truncated.annotations&&e("p",{class:"truncated-note",children:["Showing the first ",s.annotations.length," \\u2014 there are more."]}),e("div",{class:"section-header",children:e("h3",{class:"section-title",children:"Logs"})}),e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{scope:"col",children:"Time"}),e("th",{scope:"col",children:"Level"}),e("th",{scope:"col",children:"Stage"}),e("th",{scope:"col",children:"Message"})]})}),e("tbody",{children:[s.logs.map(d=>e("tr",{children:[e("td",{children:$(d.createdAt)}),e("td",{children:e("span",{class:`pill pill-log-${d.level.toLowerCase()}`,children:d.level})}),e("td",{children:d.workflowStageId||"\\u2014"}),e("td",{children:d.message})]},d.id)),s.logs.length===0&&e("tr",{children:e("td",{colspan:4,class:"empty-state",children:"No logs recorded."})})]})]})}),s.truncated.logs&&e("p",{class:"truncated-note",children:["Showing the first ",s.logs.length," \\u2014 there are more."]}),e("div",{class:"payload-sections",children:[e("details",{class:"payload-block",children:[e("summary",{children:"Input"}),e("pre",{children:JSON.stringify(s.run.input,null,2)})]}),e("details",{class:"payload-block",children:[e("summary",{children:"Output"}),e("pre",{children:JSON.stringify(s.run.output,null,2)})]}),e("details",{class:"payload-block",children:[e("summary",{children:"Config"}),e("pre",{children:JSON.stringify(s.run.config,null,2)})]}),e("details",{class:"payload-block",children:[e("summary",{children:"Metadata"}),e("pre",{children:JSON.stringify(s.run.metadata,null,2)})]})]})]})]})}function Ct({config:t,pollInterval:n,paused:r,refreshSignal:o}){let[l,a]=S(null),i=J(async()=>{let[f,s,h]=await Promise.all([t.capabilities.queue?q(t,"/queue"):Promise.resolve(null),t.capabilities.suspended?q(t,"/suspended"):Promise.resolve(null),t.capabilities.workers?q(t,"/workers"):Promise.resolve(null)]);return{queue:f,suspended:s,workers:h}},[t]),{data:c,error:_}=Z(i,[i,o],n,r),u=_===l?null:_,p=u&&"code"in u&&u.code==="forbidden";return e("div",{children:[e(ee,{error:u,onDismiss:()=>a(_)}),c&&!p&&e(P,{children:[t.capabilities.queue&&c.queue&&e(P,{children:[e("div",{class:"section-header",children:e("h3",{class:"section-title",children:"Queue health"})}),e("div",{class:"stat-tiles",children:[ot.map(f=>e("div",{class:"stat-tile",children:[e("span",{class:"stat-tile-value",children:c.queue?.countsByStatus[f]??0}),e("span",{class:"stat-tile-label",children:e(X,{status:f})})]},f)),e("div",{class:"stat-tile",children:[e("span",{class:"stat-tile-value",children:Q(c.queue.oldestPendingAt)}),e("span",{class:"stat-tile-label",children:"Oldest pending"})]}),e("div",{class:"stat-tile",children:[e("span",{class:"stat-tile-value",children:Q(c.queue.oldestLeaseAt)}),e("span",{class:"stat-tile-label",children:"Oldest lease"})]}),e("div",{class:"stat-tile",children:[e("span",{class:"stat-tile-value",children:c.queue.overduePolls}),e("span",{class:"stat-tile-label",children:"Overdue polls"})]})]})]}),t.capabilities.suspended&&c.suspended&&e(P,{children:[e("div",{class:"section-header",children:e("h3",{class:"section-title",children:"Suspended stages"})}),e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{scope:"col",children:"Stage"}),e("th",{scope:"col",children:"Workflow run"}),e("th",{scope:"col",children:"Attempt"}),e("th",{scope:"col",children:"Next poll"}),e("th",{scope:"col",children:"Poll interval"}),e("th",{scope:"col",children:"Max wait until"})]})}),e("tbody",{children:[c.suspended.map(f=>e("tr",{children:[e("td",{children:f.stageName}),e("td",{children:e("a",{href:`#/runs/${encodeURIComponent(f.workflowRunId)}`,title:f.workflowRunId,children:f.workflowRunId.length>12?`\\u2026${f.workflowRunId.slice(-12)}`:f.workflowRunId})}),e("td",{children:f.attempt}),e("td",{children:bt(f.nextPollAt)}),e("td",{children:f.pollInterval?de(f.pollInterval):"\\u2014"}),e("td",{children:$(f.maxWaitUntil)})]},f.id)),c.suspended.length===0&&e("tr",{children:e("td",{colspan:6,class:"empty-state",children:"No suspended stages."})})]})]})})]}),t.capabilities.workers&&c.workers&&e(P,{children:[e("div",{class:"section-header",children:e("h3",{class:"section-title",children:"Workers"})}),e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{scope:"col",children:"Worker ID"}),e("th",{scope:"col",children:"Running jobs"}),e("th",{scope:"col",children:"Oldest lease"}),e("th",{scope:"col",children:"Heartbeat age"})]})}),e("tbody",{children:[c.workers.map(f=>{let s=f.lastSeenAt?Date.now()-Date.parse(f.lastSeenAt)>6e4:!0;return e("tr",{class:s?"row-warning":"",children:[e("td",{children:f.workerId}),e("td",{children:f.runningJobs}),e("td",{children:Q(f.oldestLockedAt)}),e("td",{children:Q(f.lastSeenAt)})]},f.workerId)}),c.workers.length===0&&e("tr",{children:e("td",{colspan:4,class:"empty-state",children:"No active workers."})})]})]})})]})]})]})}function Et({config:t,pollInterval:n,paused:r,refreshSignal:o}){let[l,a]=S(!1),[i,c]=S(null),[_,u]=S(null),p=J(async()=>await q(t,"/dead-letters"),[t]),{data:f,error:s,refresh:h}=Z(p,[p,o],n,r),v=i??s,y=v===_?null:v,b=y&&"code"in y&&y.code==="forbidden",w=async()=>{if(window.confirm("Replay up to 100 dead letters?")){a(!0),c(null);try{await q(t,"/dead-letters/replay",{method:"POST",body:JSON.stringify({maxEvents:100})}),h()}catch(g){c(g instanceof Error?g:new Error(String(g)))}finally{a(!1)}}};return e("div",{children:[e("div",{class:"section-header",style:{marginTop:0},children:[e("h3",{class:"section-title",children:"Dead letter queue"}),!t.readOnly&&e("button",{type:"button",class:"btn-primary",disabled:l,onClick:w,children:l?"Replaying...":"Replay dead letters"})]}),e(ee,{error:y,onDismiss:()=>{u(v),c(null)}}),f&&!b&&e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{scope:"col",children:"Sequence"}),e("th",{scope:"col",children:"Workflow run"}),e("th",{scope:"col",children:"Event type"}),e("th",{scope:"col",children:"Retries"}),e("th",{scope:"col",children:"Occurred"}),e("th",{scope:"col",children:"DLQ time"})]})}),e("tbody",{children:[f.map(g=>e("tr",{children:[e("td",{children:g.sequence}),e("td",{children:e("a",{href:`#/runs/${encodeURIComponent(g.workflowRunId)}`,title:g.workflowRunId,children:g.workflowRunId.length>12?`\\u2026${g.workflowRunId.slice(-12)}`:g.workflowRunId})}),e("td",{children:g.eventType}),e("td",{children:g.retryCount}),e("td",{children:$(g.occurredAt)}),e("td",{children:$(g.dlqAt)})]},g.id)),f.length===0&&e("tr",{children:e("td",{colspan:6,class:"empty-state",children:"No dead letters."})})]})]})})]})}function Nt({config:t,pollInterval:n,paused:r,refreshSignal:o}){let[l,a]=S("workflow"),[i,c]=S(null),_=J(async()=>await q(t,`/costs?by=${l}`),[t,l]),{data:u,error:p}=Z(_,[_,o],n,r),f=p===i?null:p,s=f&&"code"in f&&f.code==="forbidden",h=j(()=>Math.max(1e-4,...(u??[]).map(v=>v.cost)),[u]);return e("div",{children:[e("div",{class:"section-header",style:{marginTop:0},children:[e("h3",{class:"section-title",children:"Cost rollups"}),e("div",{class:"toggle-group",children:[e("button",{type:"button",class:`btn-toggle ${l==="workflow"?"active":""}`,onClick:()=>a("workflow"),children:"By workflow"}),e("button",{type:"button",class:`btn-toggle ${l==="day"?"active":""}`,onClick:()=>a("day"),children:"By day"})]})]}),e(ee,{error:f,onDismiss:()=>c(p)}),u&&!s&&e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{scope:"col",children:l==="workflow"?"Workflow ID":"Date"}),e("th",{scope:"col",children:"Runs"}),e("th",{scope:"col",children:"Cost"}),e("th",{scope:"col",children:"Tokens"}),e("th",{scope:"col",style:{width:"30%"},children:"Proportion"})]})}),e("tbody",{children:[u.map(v=>{let y=Math.min(100,Math.max(.5,v.cost/h*100));return e("tr",{children:[e("td",{children:v.key}),e("td",{children:v.runs.toLocaleString()}),e("td",{children:Se(v.cost)}),e("td",{children:Ie(v.tokens)}),e("td",{children:e("div",{class:"cost-bar-track",children:e("div",{class:"cost-bar-fill",style:{width:`${y}%`}})})})]},v.key)}),u.length===0&&e("tr",{children:e("td",{colspan:5,class:"empty-state",children:"No cost data available."})})]})]})})]})}var At=[{label:"Off",value:0},{label:"2s",value:2e3},{label:"5s",value:5e3},{label:"10s",value:1e4},{label:"30s",value:3e4},{label:"60s",value:6e4}];function Dt({config:t}){let n=yt(),[r,o]=S(()=>t.forcePollInterval?t.pollIntervalMs:wt(t.pollIntervalMs)),[l,a]=S(0),i=p=>{o(p),kt(p)},c=()=>{a(p=>p+1)},_=t.capabilities.queue||t.capabilities.suspended||t.capabilities.workers,u=j(()=>n.view==="run-detail"?e(It,{config:t,runId:n.runId,pollInterval:r,paused:r===0,refreshSignal:l}):n.view==="queue"&&_?e(Ct,{config:t,pollInterval:r,paused:r===0,refreshSignal:l}):n.view==="dead-letters"&&t.capabilities.deadLetters?e(Et,{config:t,pollInterval:r,paused:r===0,refreshSignal:l}):n.view==="costs"&&t.capabilities.costs?e(Nt,{config:t,pollInterval:r,paused:r===0,refreshSignal:l}):e(St,{config:t,pollInterval:r,paused:r===0,refreshSignal:l}),[n,t,r,l,_]);return e("div",{children:[e("header",{class:"header",children:[e("div",{class:"header-title-group",children:[e("h1",{class:"header-title",children:"Workflow console"}),t.readOnly&&e("span",{class:"badge badge-readonly",children:"Read-only"})]}),e("div",{class:"header-controls",children:[!t.forcePollInterval&&e("div",{children:[e("label",{class:"sr-only",for:"wc-poll-select",children:"Poll interval"}),e("select",{id:"wc-poll-select",value:r,onChange:p=>i(Number(p.target.value)),children:At.map(p=>e("option",{value:p.value,children:p.label},p.value))})]}),e("button",{type:"button",class:"btn-refresh",onClick:c,children:"Refresh now"})]})]}),e("nav",{class:"nav-tabs","aria-label":"Console navigation",children:[t.capabilities.runs&&e("a",{href:"#/runs",class:`nav-tab ${n.view==="runs"||n.view==="run-detail"?"active":""}`,"aria-current":n.view==="runs"||n.view==="run-detail"?"page":void 0,children:"Runs"}),_&&e("a",{href:"#/queue",class:`nav-tab ${n.view==="queue"?"active":""}`,"aria-current":n.view==="queue"?"page":void 0,children:"Queue"}),t.capabilities.deadLetters&&e("a",{href:"#/dead-letters",class:`nav-tab ${n.view==="dead-letters"?"active":""}`,"aria-current":n.view==="dead-letters"?"page":void 0,children:"Dead letters"}),t.capabilities.costs&&e("a",{href:"#/costs",class:`nav-tab ${n.view==="costs"?"active":""}`,"aria-current":n.view==="costs"?"page":void 0,children:"Costs"})]}),e("main",{children:u})]})}function nt(){let t=document.getElementById("workflow-console");if(!t)return;let n=document.getElementById("workflow-console-config");if(!n||!n.textContent){t.textContent="Workflow console configuration element missing.";return}let r;try{r=JSON.parse(n.textContent)}catch{t.textContent="Workflow console configuration is invalid.";return}Ue(e(Dt,{config:r}),t)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",nt):nt();})();\n';
7
+ var UI_CSS = '#workflow-console{--wc-bg:#ffffff;--wc-text:#111827;--wc-text-muted:#6b7280;--wc-border:#e5e7eb;--wc-border-subtle:#f3f4f6;--wc-surface:#f9fafb;--wc-surface-hover:#f3f4f6;--wc-surface-active:#e5e7eb;--wc-primary:#2563eb;--wc-primary-hover:#1d4ed8;--wc-primary-text:#ffffff;--wc-focus-ring:#3b82f6;--wc-banner-bg:#fef2f2;--wc-banner-border:#fecaca;--wc-banner-text:#991b1b;--wc-status-pending-bg:#f3f4f6;--wc-status-pending-text:#374151;--wc-status-running-bg:#dbeafe;--wc-status-running-text:#1e40af;--wc-status-suspended-bg:#fef3c7;--wc-status-suspended-text:#92400e;--wc-status-completed-bg:#d1fae5;--wc-status-completed-text:#065f46;--wc-status-failed-bg:#fee2e2;--wc-status-failed-text:#991b1b;--wc-status-cancelled-bg:#f3f4f6;--wc-status-cancelled-text:#4b5563;--wc-status-skipped-bg:#f3f4f6;--wc-status-skipped-text:#4b5563;--wc-log-info-bg:#e0f2fe;--wc-log-info-text:#0369a1;--wc-log-warn-bg:#fef3c7;--wc-log-warn-text:#92400e;--wc-log-error-bg:#fee2e2;--wc-log-error-text:#991b1b;--wc-log-debug-bg:#f3f4f6;--wc-log-debug-text:#4b5563;--wc-bar-track:#e5e7eb;--wc-bar-fill:#2563eb;--wc-warning-bg:#fffbeb;--wc-warning-border:#fde68a;--wc-warning-text:#b45309;--wc-transparent:transparent}@media (prefers-color-scheme:dark){#workflow-console{--wc-bg:#111827;--wc-text:#f9fafb;--wc-text-muted:#9ca3af;--wc-border:#374151;--wc-border-subtle:#1f2937;--wc-surface:#1f2937;--wc-surface-hover:#374151;--wc-surface-active:#4b5563;--wc-primary:#3b82f6;--wc-primary-hover:#60a5fa;--wc-primary-text:#ffffff;--wc-focus-ring:#60a5fa;--wc-banner-bg:#450a0a;--wc-banner-border:#7f1d1d;--wc-banner-text:#fca5a5;--wc-status-pending-bg:#374151;--wc-status-pending-text:#e5e7eb;--wc-status-running-bg:#1e3a8a;--wc-status-running-text:#bfdbfe;--wc-status-suspended-bg:#78350f;--wc-status-suspended-text:#fde68a;--wc-status-completed-bg:#064e3b;--wc-status-completed-text:#a7f3d0;--wc-status-failed-bg:#7f1d1d;--wc-status-failed-text:#fecaca;--wc-status-cancelled-bg:#374151;--wc-status-cancelled-text:#9ca3af;--wc-status-skipped-bg:#374151;--wc-status-skipped-text:#9ca3af;--wc-log-info-bg:#075985;--wc-log-info-text:#bae6fd;--wc-log-warn-bg:#78350f;--wc-log-warn-text:#fde68a;--wc-log-error-bg:#7f1d1d;--wc-log-error-text:#fecaca;--wc-log-debug-bg:#374151;--wc-log-debug-text:#9ca3af;--wc-bar-track:#374151;--wc-bar-fill:#60a5fa;--wc-warning-bg:#451a03;--wc-warning-border:#78350f;--wc-warning-text:#fde68a;--wc-transparent:transparent}}#workflow-console{background-color:var(--wc-bg);color:var(--wc-text);font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;font-size:14px;line-height:1.5;box-sizing:border-box;width:100%;padding:1.5rem}#workflow-console *,#workflow-console *::before,#workflow-console *::after{box-sizing:border-box}#workflow-console a{color:var(--wc-primary);text-decoration:none}#workflow-console a:hover{text-decoration:underline}#workflow-console button{font-family:inherit;font-size:0.875rem;padding:0.375rem 0.75rem;border-radius:4px;border:1px solid var(--wc-border);background-color:var(--wc-surface);color:var(--wc-text);cursor:pointer;display:inline-flex;align-items:center;justify-content:center;gap:0.375rem}#workflow-console button:hover:not(:disabled){background-color:var(--wc-surface-hover)}#workflow-console button:disabled{opacity:0.5;cursor:not-allowed}#workflow-console button:focus-visible,#workflow-console input:focus-visible,#workflow-console select:focus-visible{outline:2px solid var(--wc-focus-ring);outline-offset:1px}#workflow-console .btn-primary{background-color:var(--wc-primary);color:var(--wc-primary-text);border-color:var(--wc-primary)}#workflow-console .btn-primary:hover:not(:disabled){background-color:var(--wc-primary-hover)}#workflow-console .btn-danger{background-color:var(--wc-banner-bg);color:var(--wc-banner-text);border-color:var(--wc-banner-border)}#workflow-console .btn-sm{font-size:0.75rem;padding:0.25rem 0.5rem}#workflow-console input[type="text"],#workflow-console input[type="datetime-local"],#workflow-console select{font-family:inherit;font-size:0.875rem;padding:0.375rem 0.5rem;border:1px solid var(--wc-border);border-radius:4px;background-color:var(--wc-bg);color:var(--wc-text)}#workflow-console textarea{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;font-size:0.8125rem;padding:0.375rem 0.5rem;border:1px solid var(--wc-border);border-radius:4px;background-color:var(--wc-bg);color:var(--wc-text);width:100%;max-width:40rem;resize:vertical}#workflow-console textarea:focus-visible{outline:2px solid var(--wc-focus-ring);outline-offset:1px}#workflow-console .step-signal-toggle{margin-left:0.5rem}#workflow-console .step-signal-form{display:flex;flex-direction:column;gap:0.375rem;padding:0.25rem 0}#workflow-console .step-signal-label{font-size:0.75rem;color:var(--wc-text-muted)}#workflow-console .step-signal-error{font-size:0.75rem;color:var(--wc-banner-text)}#workflow-console .step-signal-actions{display:flex;gap:0.5rem}#workflow-console .sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0}#workflow-console .header{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:1rem;padding-bottom:1rem;border-bottom:1px solid var(--wc-border);margin-bottom:1rem}#workflow-console .header-title-group{display:flex;align-items:center;gap:0.75rem}#workflow-console .header-title{margin:0;font-size:1.25rem;font-weight:700;color:var(--wc-text)}#workflow-console .header-controls{display:flex;align-items:center;gap:0.5rem}#workflow-console .nav-tabs{display:flex;gap:0.25rem;margin-bottom:1.25rem;border-bottom:1px solid var(--wc-border)}#workflow-console .nav-tab{padding:0.5rem 0.875rem;text-decoration:none;color:var(--wc-text-muted);font-weight:500;border-bottom:2px solid var(--wc-transparent);margin-bottom:-1px}#workflow-console .nav-tab:hover{color:var(--wc-text);text-decoration:none}#workflow-console .nav-tab.active{color:var(--wc-primary);border-bottom-color:var(--wc-primary);font-weight:600}#workflow-console .banner{display:flex;align-items:center;justify-content:space-between;gap:0.75rem;padding:0.75rem 1rem;border:1px solid var(--wc-banner-border);background-color:var(--wc-banner-bg);color:var(--wc-banner-text);border-radius:4px;margin-bottom:1rem}#workflow-console .banner-message{font-size:0.875rem}#workflow-console .banner-dismiss{background:var(--wc-transparent);border:none;color:var(--wc-banner-text);font-size:1.25rem;line-height:1;padding:0 0.25rem;cursor:pointer}#workflow-console .filter-bar{display:flex;flex-direction:column;gap:0.75rem;margin-bottom:1rem;padding:0.875rem;background-color:var(--wc-surface);border:1px solid var(--wc-border);border-radius:4px}#workflow-console .filter-row{display:flex;flex-wrap:wrap;align-items:center;gap:0.5rem}#workflow-console .status-toggle-group{display:flex;flex-wrap:wrap;gap:0.25rem}#workflow-console .status-toggle{padding:0.25rem 0.5rem;font-size:0.75rem;border-radius:4px;border:1px solid var(--wc-border);background-color:var(--wc-bg);color:var(--wc-text-muted)}#workflow-console .status-toggle.active{background-color:var(--wc-surface-active);color:var(--wc-text);font-weight:600;border-color:var(--wc-border)}#workflow-console .table-container{overflow-x:auto;max-width:100%;margin-bottom:1rem;border:1px solid var(--wc-border);border-radius:4px}#workflow-console table{width:100%;border-collapse:collapse;white-space:nowrap;font-size:0.875rem}#workflow-console th{background-color:var(--wc-surface);color:var(--wc-text-muted);font-weight:600;text-align:left;padding:0.5rem 0.75rem;border-bottom:1px solid var(--wc-border)}#workflow-console td{padding:0.5rem 0.75rem;border-bottom:1px solid var(--wc-border-subtle);color:var(--wc-text)}#workflow-console tr:last-child td{border-bottom:none}#workflow-console tr:hover td{background-color:var(--wc-surface-hover)}#workflow-console tr.table-group-header th{background-color:var(--wc-surface-active);color:var(--wc-text);font-weight:700;padding:0.5rem 0.75rem}#workflow-console tr.row-warning td{background-color:var(--wc-warning-bg);color:var(--wc-warning-text)}#workflow-console .pagination{display:flex;align-items:center;justify-content:flex-end;gap:0.5rem;margin-top:0.75rem;margin-bottom:1rem}#workflow-console .pill{display:inline-block;padding:0.125rem 0.5rem;border-radius:9999px;font-size:0.75rem;font-weight:600;text-transform:uppercase;letter-spacing:0.025em;line-height:1.2}#workflow-console .pill-pending{background-color:var(--wc-status-pending-bg);color:var(--wc-status-pending-text)}#workflow-console .pill-running{background-color:var(--wc-status-running-bg);color:var(--wc-status-running-text)}#workflow-console .pill-suspended{background-color:var(--wc-status-suspended-bg);color:var(--wc-status-suspended-text)}#workflow-console .pill-completed{background-color:var(--wc-status-completed-bg);color:var(--wc-status-completed-text)}#workflow-console .pill-failed{background-color:var(--wc-status-failed-bg);color:var(--wc-status-failed-text)}#workflow-console .pill-cancelled{background-color:var(--wc-status-cancelled-bg);color:var(--wc-status-cancelled-text)}#workflow-console .pill-skipped{background-color:var(--wc-status-skipped-bg);color:var(--wc-status-skipped-text)}#workflow-console .pill-log-info{background-color:var(--wc-log-info-bg);color:var(--wc-log-info-text)}#workflow-console .pill-log-warn{background-color:var(--wc-log-warn-bg);color:var(--wc-log-warn-text)}#workflow-console .pill-log-error{background-color:var(--wc-log-error-bg);color:var(--wc-log-error-text)}#workflow-console .pill-log-debug{background-color:var(--wc-log-debug-bg);color:var(--wc-log-debug-text)}#workflow-console .badge{display:inline-block;padding:0.125rem 0.375rem;border-radius:4px;font-size:0.75rem;font-weight:600;text-transform:uppercase}#workflow-console .badge-readonly{background-color:var(--wc-status-pending-bg);color:var(--wc-status-pending-text);border:1px solid var(--wc-border)}#workflow-console .badge-dlq{background-color:var(--wc-banner-bg);color:var(--wc-banner-text);border:1px solid var(--wc-banner-border)}#workflow-console .stat-tiles{display:flex;flex-wrap:wrap;gap:0.75rem;margin-bottom:1.5rem}#workflow-console .stat-tile{background-color:var(--wc-surface);border:1px solid var(--wc-border);border-radius:6px;padding:0.75rem 1rem;min-width:130px;display:flex;flex-direction:column}#workflow-console .stat-tile-value{font-size:1.25rem;font-weight:700;color:var(--wc-text)}#workflow-console .stat-tile-label{font-size:0.75rem;color:var(--wc-text-muted);text-transform:uppercase;margin-top:0.25rem}#workflow-console .run-detail-header{display:flex;flex-direction:column;gap:1rem;margin-bottom:1.5rem;padding:1rem;background-color:var(--wc-surface);border:1px solid var(--wc-border);border-radius:4px}#workflow-console .run-detail-title-row{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:0.75rem}#workflow-console .run-detail-title-left{display:flex;align-items:center;flex-wrap:wrap;gap:0.75rem}#workflow-console .run-detail-actions{display:flex;gap:0.5rem}#workflow-console .run-detail-meta{display:flex;flex-wrap:wrap;gap:1.5rem;font-size:0.875rem}#workflow-console .meta-item{display:flex;flex-direction:column}#workflow-console .meta-label{font-size:0.75rem;color:var(--wc-text-muted);text-transform:uppercase}#workflow-console .meta-value{font-weight:600}#workflow-console .section-header{display:flex;align-items:center;justify-content:space-between;margin-top:1.5rem;margin-bottom:0.75rem}#workflow-console .section-title{margin:0;font-size:1rem;font-weight:600;color:var(--wc-text)}#workflow-console .stage-timeline{display:flex;flex-direction:column;gap:0.5rem;margin-bottom:1.5rem}#workflow-console .stage-timeline-row{display:flex;flex-direction:column;gap:0.375rem;padding:0.75rem;border:1px solid var(--wc-border);border-radius:4px;background-color:var(--wc-surface)}#workflow-console .stage-timeline-meta{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:0.5rem}#workflow-console .stage-timeline-meta-left{display:flex;align-items:center;flex-wrap:wrap;gap:0.5rem}#workflow-console .stage-num{font-weight:700;color:var(--wc-text-muted)}#workflow-console .stage-name{font-weight:600}#workflow-console .stage-timings{font-size:0.75rem;color:var(--wc-text-muted);display:inline-flex;gap:0.375rem}#workflow-console .timeline-track{position:relative;height:8px;background-color:var(--wc-bar-track);border-radius:4px;overflow:hidden;width:100%}#workflow-console .timeline-bar{position:absolute;top:0;bottom:0;background-color:var(--wc-bar-fill);border-radius:4px}#workflow-console .stage-error{font-size:0.75rem;color:var(--wc-banner-text);background-color:var(--wc-banner-bg);padding:0.375rem 0.5rem;border-radius:4px;border:1px solid var(--wc-banner-border);margin-top:0.25rem}#workflow-console .cost-bar-track{position:relative;height:10px;background-color:var(--wc-bar-track);border-radius:5px;overflow:hidden;min-width:100px;width:100%}#workflow-console .cost-bar-fill{position:absolute;top:0;bottom:0;left:0;background-color:var(--wc-bar-fill);border-radius:5px}#workflow-console .toggle-group{display:inline-flex;border:1px solid var(--wc-border);border-radius:4px;overflow:hidden}#workflow-console .btn-toggle{border:none;border-radius:0;padding:0.375rem 0.75rem;font-size:0.8125rem;background-color:var(--wc-surface);color:var(--wc-text-muted)}#workflow-console .btn-toggle.active{background-color:var(--wc-surface-active);color:var(--wc-text);font-weight:600}#workflow-console .payload-sections{display:flex;flex-direction:column;gap:0.5rem;margin-top:1rem;margin-bottom:1.5rem}#workflow-console .payload-block{border:1px solid var(--wc-border);border-radius:4px;background-color:var(--wc-surface)}#workflow-console .payload-block summary{padding:0.5rem 0.75rem;cursor:pointer;font-weight:600;font-size:0.875rem}#workflow-console .payload-block pre{margin:0;padding:0.75rem;overflow-x:auto;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;font-size:12px;border-top:1px solid var(--wc-border);background-color:var(--wc-bg);color:var(--wc-text)}#workflow-console .truncated-note{font-size:0.75rem;color:var(--wc-text-muted);font-style:italic;margin-top:0.25rem;margin-bottom:1rem}#workflow-console .empty-state{text-align:center;color:var(--wc-text-muted);font-style:italic;padding:1.5rem 0.75rem}#workflow-console code{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;font-size:0.8125rem;background-color:var(--wc-surface-active);padding:0.125rem 0.25rem;border-radius:3px}';
8
+
9
+ // src/ui-assets.ts
10
+ var UI_ASSETS = {
11
+ [UI_JS_NAME]: {
12
+ body: UI_JS,
13
+ contentType: "application/javascript; charset=utf-8"
14
+ },
15
+ [UI_CSS_NAME]: { body: UI_CSS, contentType: "text/css; charset=utf-8" }
16
+ };
17
+ var HTML_ESCAPES = {
18
+ "&": "&amp;",
19
+ "<": "&lt;",
20
+ ">": "&gt;",
21
+ '"': "&quot;",
22
+ "'": "&#39;"
23
+ };
24
+ function escapeHtml(value) {
25
+ return value.replace(/[&<>"']/g, (char) => HTML_ESCAPES[char] ?? char);
26
+ }
27
+ function escapeJsonForScript(value) {
28
+ return value.replace(/</g, "\\u003c");
29
+ }
30
+ function renderIndexHtml(options) {
31
+ const config = escapeJsonForScript(
32
+ JSON.stringify({
33
+ basePath: options.basePath,
34
+ readOnly: options.readOnly,
35
+ pollIntervalMs: options.pollIntervalMs,
36
+ forcePollInterval: options.forcePollInterval,
37
+ capabilities: options.capabilities
38
+ })
39
+ );
40
+ const nonce = options.nonce === void 0 ? "" : ` nonce="${escapeHtml(options.nonce)}"`;
41
+ const base = escapeHtml(options.basePath);
42
+ return `<!doctype html>
43
+ <html lang="en">
44
+ <head>
45
+ <meta charset="utf-8">
46
+ <meta name="viewport" content="width=device-width, initial-scale=1">
47
+ <meta name="color-scheme" content="light dark">
48
+ <title>Workflow console</title>
49
+ <link rel="stylesheet" href="${base}/assets/${UI_CSS_NAME}">
50
+ </head>
51
+ <body>
52
+ <div id="workflow-console"></div>
53
+ <script type="application/json" id="workflow-console-config"${nonce}>${config}</script>
54
+ <script src="${base}/assets/${UI_JS_NAME}"${nonce} defer></script>
55
+ </body>
56
+ </html>
57
+ `;
58
+ }
59
+
60
+ // src/handler.ts
61
+ function signalErrorStatus(error) {
62
+ if (!(error instanceof Error)) return void 0;
63
+ const message = error.message;
64
+ if (/ not found$/.test(message)) return 404;
65
+ if (message.includes("was previously used as") || message.includes("has failed and cannot receive a signal") || message.endsWith("changed state")) {
66
+ return 409;
67
+ }
68
+ return void 0;
69
+ }
70
+ var JSON_HEADERS = { "content-type": "application/json; charset=utf-8" };
71
+ function json(body, status = 200) {
72
+ return new Response(JSON.stringify(body, dateReplacer), {
73
+ status,
74
+ headers: JSON_HEADERS
75
+ });
76
+ }
77
+ function dateReplacer(_key, value) {
78
+ return value instanceof Date ? value.toISOString() : value;
79
+ }
80
+ function errorResponse(code, message, status) {
81
+ return json({ error: { code, message } }, status);
82
+ }
83
+ function splitPath(pathname, configuredBase) {
84
+ if (configuredBase !== void 0) {
85
+ const base = normaliseBase(configuredBase);
86
+ const route = pathname.startsWith(base) ? pathname.slice(base.length) : pathname;
87
+ return { basePath: base, route: route === "" ? "/" : route };
88
+ }
89
+ for (const marker of ["/api/", "/assets/"]) {
90
+ const at = pathname.lastIndexOf(marker);
91
+ if (at !== -1) {
92
+ return {
93
+ basePath: normaliseBase(pathname.slice(0, at)),
94
+ route: pathname.slice(at)
95
+ };
96
+ }
97
+ }
98
+ return { basePath: normaliseBase(pathname), route: "/" };
99
+ }
100
+ function normaliseBase(path) {
101
+ const trimmed = path.replace(/\/+$/, "");
102
+ return trimmed === "" ? "" : trimmed;
103
+ }
104
+ function parseStatuses(raw) {
105
+ const statuses = [];
106
+ for (const entry of raw.flatMap((value) => value.split(","))) {
107
+ const candidate = entry.trim().toUpperCase();
108
+ if (candidate === "") continue;
109
+ if (!isConsoleStatus(candidate)) {
110
+ throw new ConsoleBadRequestError(`Unknown status "${entry.trim()}".`);
111
+ }
112
+ if (!statuses.includes(candidate)) statuses.push(candidate);
113
+ }
114
+ return statuses;
115
+ }
116
+ function parseDate(raw, field) {
117
+ if (raw === null || raw === "") return void 0;
118
+ const parsed = new Date(raw);
119
+ if (Number.isNaN(parsed.getTime())) {
120
+ throw new ConsoleBadRequestError(`Invalid ${field}: "${raw}".`);
121
+ }
122
+ return parsed;
123
+ }
124
+ function parseFilters(params) {
125
+ const filters = {};
126
+ const statuses = parseStatuses(params.getAll("status"));
127
+ if (statuses.length > 0) filters.status = statuses;
128
+ const workflowId = params.get("workflowId");
129
+ if (workflowId) filters.workflowId = workflowId;
130
+ const workflowType = params.get("workflowType");
131
+ if (workflowType) filters.workflowType = workflowType;
132
+ const definitionVersion = params.get("definitionVersion");
133
+ if (definitionVersion) filters.definitionVersion = definitionVersion;
134
+ const after = parseDate(params.get("from"), "from");
135
+ if (after) filters.createdAfter = after;
136
+ const before = parseDate(params.get("to"), "to");
137
+ if (before) filters.createdBefore = before;
138
+ return filters;
139
+ }
140
+ function parseLimit(params) {
141
+ const raw = params.get("limit");
142
+ if (raw === null || raw === "") return void 0;
143
+ const parsed = Number(raw);
144
+ if (!Number.isFinite(parsed)) {
145
+ throw new ConsoleBadRequestError(`Invalid limit: "${raw}".`);
146
+ }
147
+ return clampLimit(parsed);
148
+ }
149
+ function createWorkflowConsole(options) {
150
+ const {
151
+ reader,
152
+ kernel,
153
+ authorize,
154
+ actions = false,
155
+ basePath,
156
+ pollIntervalMs = 5e3,
157
+ forcePollInterval = false,
158
+ cspNonce,
159
+ onAction
160
+ } = options;
161
+ if (actions && !kernel) {
162
+ throw new Error(
163
+ "createWorkflowConsole: `actions: true` needs a `kernel` to dispatch to. Console writes go through kernel commands, never SQL."
164
+ );
165
+ }
166
+ const readOnly = !actions;
167
+ async function allowed(action, request, runId, scope) {
168
+ if (authorize === void 0) return false;
169
+ try {
170
+ return await authorize({ action, request, runId, ...scope }) === true;
171
+ } catch {
172
+ return false;
173
+ }
174
+ }
175
+ async function dispatch(request, action, command, runId, scope) {
176
+ if (readOnly) {
177
+ return errorResponse(
178
+ "read_only",
179
+ "This console is read-only. Construct it with `actions: true` to enable writes.",
180
+ 405
181
+ );
182
+ }
183
+ if (!await allowed(action, request, runId, scope)) {
184
+ return errorResponse("forbidden", "Not permitted.", 403);
185
+ }
186
+ const result = await kernel.dispatch(command);
187
+ if (onAction) {
188
+ await onAction({
189
+ action,
190
+ runId,
191
+ ...scope,
192
+ request,
193
+ result,
194
+ at: /* @__PURE__ */ new Date()
195
+ });
196
+ }
197
+ return json({ result });
198
+ }
199
+ async function readBody(request) {
200
+ const text = await request.text();
201
+ if (text.trim() === "") return {};
202
+ try {
203
+ const parsed = JSON.parse(text);
204
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
205
+ throw new ConsoleBadRequestError("Body must be a JSON object.");
206
+ }
207
+ return parsed;
208
+ } catch (error) {
209
+ if (error instanceof ConsoleBadRequestError) throw error;
210
+ throw new ConsoleBadRequestError("Body must be valid JSON.");
211
+ }
212
+ }
213
+ function parseRedriveFrom(value) {
214
+ if (value === void 0) return void 0;
215
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
216
+ throw new ConsoleBadRequestError("`from` must be an object.");
217
+ }
218
+ const kind = value.kind;
219
+ if (kind === "lastFailure" || kind === "start") return { kind };
220
+ if (kind === "stage") {
221
+ const stageId = value.stageId;
222
+ if (typeof stageId !== "string" || stageId === "") {
223
+ throw new ConsoleBadRequestError(
224
+ '`from.stageId` is required for `from.kind` "stage".'
225
+ );
226
+ }
227
+ return { kind: "stage", stageId };
228
+ }
229
+ throw new ConsoleBadRequestError(
230
+ '`from.kind` must be "lastFailure", "start" or "stage".'
231
+ );
232
+ }
233
+ async function guardedRead(request, action, runId, produce) {
234
+ if (!await allowed(action, request, runId)) {
235
+ return errorResponse("forbidden", "Not permitted.", 403);
236
+ }
237
+ return json(await produce());
238
+ }
239
+ return async function handle(request) {
240
+ const url = new URL(request.url);
241
+ const { basePath: base, route } = splitPath(url.pathname, basePath);
242
+ const params = url.searchParams;
243
+ const method = request.method.toUpperCase();
244
+ try {
245
+ if (route === "/" && (method === "GET" || method === "HEAD")) {
246
+ const html = renderIndexHtml({
247
+ basePath: base,
248
+ readOnly,
249
+ pollIntervalMs,
250
+ forcePollInterval,
251
+ capabilities: reader.capabilities,
252
+ nonce: cspNonce?.(request)
253
+ });
254
+ return new Response(method === "HEAD" ? null : html, {
255
+ headers: {
256
+ "content-type": "text/html; charset=utf-8",
257
+ // The document carries the mount path and the feature flags, so
258
+ // it must never be cached; the assets it points at are
259
+ // content-hashed and cached forever.
260
+ "cache-control": "no-store"
261
+ }
262
+ });
263
+ }
264
+ if (route.startsWith("/assets/")) {
265
+ if (method !== "GET" && method !== "HEAD") {
266
+ return errorResponse(
267
+ "method_not_allowed",
268
+ "Method not allowed.",
269
+ 405
270
+ );
271
+ }
272
+ const asset = UI_ASSETS[route.slice("/assets/".length)];
273
+ if (!asset) {
274
+ return errorResponse("not_found", "No such asset.", 404);
275
+ }
276
+ return new Response(method === "HEAD" ? null : asset.body, {
277
+ headers: {
278
+ "content-type": asset.contentType,
279
+ "cache-control": "public, max-age=31536000, immutable"
280
+ }
281
+ });
282
+ }
283
+ if (!route.startsWith("/api/")) {
284
+ return errorResponse("not_found", "No such route.", 404);
285
+ }
286
+ const api = route.slice("/api".length);
287
+ if (api === "/meta" && method === "GET") {
288
+ return json({
289
+ readOnly,
290
+ basePath: base,
291
+ pollIntervalMs,
292
+ forcePollInterval,
293
+ capabilities: reader.capabilities
294
+ });
295
+ }
296
+ if (api === "/runs" && method === "GET") {
297
+ return await guardedRead(
298
+ request,
299
+ "runs.read",
300
+ void 0,
301
+ () => reader.listRuns({
302
+ filters: parseFilters(params),
303
+ cursor: params.get("cursor") ?? void 0,
304
+ limit: parseLimit(params)
305
+ })
306
+ );
307
+ }
308
+ const runDetail = /^\/runs\/([^/]+)$/.exec(api);
309
+ if (runDetail && method === "GET") {
310
+ const runId = decodeURIComponent(runDetail[1]);
311
+ if (!await allowed("run.read", request, runId)) {
312
+ return errorResponse("forbidden", "Not permitted.", 403);
313
+ }
314
+ const detail = await reader.getRunDetail(runId);
315
+ if (detail === null) {
316
+ return errorResponse("not_found", "No such run.", 404);
317
+ }
318
+ return json(detail);
319
+ }
320
+ const runEvents = /^\/runs\/([^/]+)\/events$/.exec(api);
321
+ if (runEvents && method === "GET") {
322
+ const runId = decodeURIComponent(runEvents[1]);
323
+ const afterRaw = params.get("afterSequence") ?? "0";
324
+ const after = Number(afterRaw);
325
+ if (!Number.isFinite(after) || after < 0) {
326
+ throw new ConsoleBadRequestError(
327
+ `Invalid afterSequence: "${afterRaw}".`
328
+ );
329
+ }
330
+ return await guardedRead(
331
+ request,
332
+ "run.read",
333
+ runId,
334
+ () => reader.listRunEvents(runId, Math.floor(after), parseLimit(params))
335
+ );
336
+ }
337
+ if (api === "/queue" && method === "GET") {
338
+ return await guardedRead(
339
+ request,
340
+ "queue.read",
341
+ void 0,
342
+ () => reader.getQueueHealth()
343
+ );
344
+ }
345
+ if (api === "/suspended" && method === "GET") {
346
+ return await guardedRead(
347
+ request,
348
+ "suspended.read",
349
+ void 0,
350
+ () => reader.listSuspendedStages(parseLimit(params))
351
+ );
352
+ }
353
+ if (api === "/dead-letters" && method === "GET") {
354
+ return await guardedRead(
355
+ request,
356
+ "deadLetters.read",
357
+ void 0,
358
+ () => reader.listDeadLetters(parseLimit(params))
359
+ );
360
+ }
361
+ if (api === "/workers" && method === "GET") {
362
+ return await guardedRead(
363
+ request,
364
+ "workers.read",
365
+ void 0,
366
+ () => reader.listWorkers()
367
+ );
368
+ }
369
+ if (api === "/costs" && method === "GET") {
370
+ const by = params.get("by") ?? "workflow";
371
+ if (by !== "workflow" && by !== "day") {
372
+ throw new ConsoleBadRequestError(
373
+ `Invalid by: "${by}". Expected "workflow" or "day".`
374
+ );
375
+ }
376
+ return await guardedRead(
377
+ request,
378
+ "costs.read",
379
+ void 0,
380
+ () => reader.getCosts({
381
+ by,
382
+ from: parseDate(params.get("from"), "from"),
383
+ to: parseDate(params.get("to"), "to")
384
+ })
385
+ );
386
+ }
387
+ const cancel = /^\/runs\/([^/]+)\/cancel$/.exec(api);
388
+ if (cancel && method === "POST") {
389
+ const runId = decodeURIComponent(cancel[1]);
390
+ const body = await readBody(request);
391
+ const reason = typeof body.reason === "string" ? body.reason : void 0;
392
+ return await dispatch(
393
+ request,
394
+ "run.cancel",
395
+ { type: "run.cancel", workflowRunId: runId, reason },
396
+ runId
397
+ );
398
+ }
399
+ const rerun = /^\/runs\/([^/]+)\/rerun$/.exec(api);
400
+ if (rerun && method === "POST") {
401
+ const runId = decodeURIComponent(rerun[1]);
402
+ const body = await readBody(request);
403
+ const fromStageId = body.fromStageId;
404
+ const from = parseRedriveFrom(body.from);
405
+ if (from === void 0) {
406
+ if (typeof fromStageId !== "string" || fromStageId === "") {
407
+ throw new ConsoleBadRequestError(
408
+ "`fromStageId` is required and must be a non-empty string, or pass `from`."
409
+ );
410
+ }
411
+ }
412
+ const definitionVersion = body.definitionVersion;
413
+ if (definitionVersion !== void 0 && (typeof definitionVersion !== "string" || definitionVersion === "")) {
414
+ throw new ConsoleBadRequestError(
415
+ "`definitionVersion` must be a non-empty string or omitted."
416
+ );
417
+ }
418
+ return await dispatch(
419
+ request,
420
+ "run.rerun",
421
+ {
422
+ type: "run.redrive",
423
+ workflowRunId: runId,
424
+ from: from ?? { kind: "stage", stageId: fromStageId },
425
+ ...definitionVersion !== void 0 ? { definitionVersion } : {}
426
+ },
427
+ runId
428
+ );
429
+ }
430
+ const signal = /^\/runs\/([^/]+)\/stages\/([^/]+)\/steps\/([^/]+)\/signal$/.exec(api);
431
+ if (signal && method === "POST") {
432
+ const runId = decodeURIComponent(signal[1]);
433
+ const stageId = decodeURIComponent(signal[2]);
434
+ const stepId = decodeURIComponent(signal[3]);
435
+ const body = await readBody(request);
436
+ const payload = "payload" in body ? body.payload : null;
437
+ const command = {
438
+ type: "step.signal",
439
+ workflowRunId: runId,
440
+ stageId,
441
+ stepId,
442
+ payload
443
+ };
444
+ try {
445
+ return await dispatch(request, "step.signal", command, runId, {
446
+ stageId,
447
+ stepId
448
+ });
449
+ } catch (error) {
450
+ const status = signalErrorStatus(error);
451
+ if (status === void 0) throw error;
452
+ return errorResponse(
453
+ status === 404 ? "not_found" : "conflict",
454
+ error.message,
455
+ status
456
+ );
457
+ }
458
+ }
459
+ if (api === "/dead-letters/replay" && method === "POST") {
460
+ const body = await readBody(request);
461
+ const maxEvents = typeof body.maxEvents === "number" && Number.isFinite(body.maxEvents) ? Math.max(1, Math.floor(body.maxEvents)) : void 0;
462
+ return await dispatch(request, "deadLetters.replay", {
463
+ type: "plugin.replayDLQ",
464
+ maxEvents
465
+ });
466
+ }
467
+ return errorResponse("not_found", "No such route.", 404);
468
+ } catch (error) {
469
+ if (error instanceof ConsoleQueryTimeoutError) {
470
+ return errorResponse("query_timeout", error.message, 504);
471
+ }
472
+ if (error instanceof ConsoleBadRequestError) {
473
+ return errorResponse("bad_request", error.message, 400);
474
+ }
475
+ return errorResponse(
476
+ "internal_error",
477
+ error instanceof Error ? error.message : "Unexpected console error.",
478
+ 500
479
+ );
480
+ }
481
+ };
482
+ }
483
+
484
+ export { createWorkflowConsole };
485
+ //# sourceMappingURL=chunk-4RL6UAMS.js.map
486
+ //# sourceMappingURL=chunk-4RL6UAMS.js.map