UNPKG

miniflare

Version:

Fun, full-featured, fully-local simulator for Cloudflare Workers

1 lines 30.1 kB
import{t as e}from"./ArrowClockwise.es-D3ltv0_F.js";import{n as t,r as n,t as r}from"./input-group-lxdd09p60cf27pe1-CRAZ_Isa.js";import{c as i,d as a,f as o,i as s,l as c,p as l,s as u,t as d,u as f}from"./types-Xf_TaJtQ.js";import{t as p}from"./DotsThree.es-DlSAzjaQ.js";import{n as m,t as h}from"./async-H4wXUxPi.js";import{n as g,t as _}from"./Spinner.es-C_n6HP-q.js";import{n as v,t as y}from"./dialog-oqh8l3l3zutpibxx-5_bvLLm7.js";import{t as b}from"./dropdown-ncwhcd912vmone8k-B21iHmGo.js";import{r as x,t as S}from"./Breadcrumbs-CEo9kTmA.js";import{Ct as C,Dn as w,Et as T,Fn as E,Gn as D,Hn as O,In as k,Jn as A,Jt as j,Kn as M,Ln as N,Mn as P,Nn as F,Pn as ee,Pt as I,Qt as L,St as te,Tt as R,Vt as ne,Zt as z,_n as B,_t as V,bt as re,in as H,ln as U,mn as ie,on as ae,rt as oe,s as se,tn as ce,vt as W,wn as G,xn as le,yn as ue,yt as de}from"./index-BPLH0X4i.js";var K=A(D(),1),fe=new Map([[`bold`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M208.49,199.51a12,12,0,0,1-17,17l-80-80a12,12,0,0,1,0-17l80-80a12,12,0,0,1,17,17L137,128ZM57,128l71.52-71.51a12,12,0,0,0-17-17l-80,80a12,12,0,0,0,0,17l80,80a12,12,0,0,0,17-17Z`}))],[`duotone`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M200,48V208l-80-80Z`,opacity:`0.2`}),K.createElement(`path`,{d:`M203.06,40.61a8,8,0,0,0-8.72,1.73l-80,80a8,8,0,0,0,0,11.32l80,80A8,8,0,0,0,208,208V48A8,8,0,0,0,203.06,40.61ZM192,188.69,131.31,128,192,67.31Zm-66.34,13.65a8,8,0,0,1-11.32,11.32l-80-80a8,8,0,0,1,0-11.32l80-80a8,8,0,0,1,11.32,11.32L51.31,128Z`}))],[`fill`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M208,48V208a8,8,0,0,1-13.66,5.66L128,147.31V208a8,8,0,0,1-13.66,5.66l-80-80a8,8,0,0,1,0-11.32l80-80A8,8,0,0,1,128,48v60.69l66.34-66.35A8,8,0,0,1,208,48Z`}))],[`light`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M204.24,203.76a6,6,0,1,1-8.48,8.48l-80-80a6,6,0,0,1,0-8.48l80-80a6,6,0,0,1,8.48,8.48L128.49,128ZM48.49,128l75.75-75.76a6,6,0,0,0-8.48-8.48l-80,80a6,6,0,0,0,0,8.48l80,80a6,6,0,1,0,8.48-8.48Z`}))],[`regular`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M205.66,202.34a8,8,0,0,1-11.32,11.32l-80-80a8,8,0,0,1,0-11.32l80-80a8,8,0,0,1,11.32,11.32L131.31,128ZM51.31,128l74.35-74.34a8,8,0,0,0-11.32-11.32l-80,80a8,8,0,0,0,0,11.32l80,80a8,8,0,0,0,11.32-11.32Z`}))],[`thin`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M202.83,205.17a4,4,0,0,1-5.66,5.66l-80-80a4,4,0,0,1,0-5.66l80-80a4,4,0,1,1,5.66,5.66L125.66,128ZM45.66,128l77.17-77.17a4,4,0,0,0-5.66-5.66l-80,80a4,4,0,0,0,0,5.66l80,80a4,4,0,1,0,5.66-5.66Z`}))]]),pe=new Map([[`bold`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M144.49,136.49l-80,80a12,12,0,0,1-17-17L119,128,47.51,56.49a12,12,0,0,1,17-17l80,80A12,12,0,0,1,144.49,136.49Zm80-17-80-80a12,12,0,1,0-17,17L199,128l-71.52,71.51a12,12,0,0,0,17,17l80-80A12,12,0,0,0,224.49,119.51Z`}))],[`duotone`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M136,128,56,208V48Z`,opacity:`0.2`}),K.createElement(`path`,{d:`M141.66,122.34l-80-80A8,8,0,0,0,48,48V208a8,8,0,0,0,13.66,5.66l80-80A8,8,0,0,0,141.66,122.34ZM64,188.69V67.31L124.69,128Zm157.66-55-80,80a8,8,0,0,1-11.32-11.32L204.69,128,130.34,53.66a8,8,0,0,1,11.32-11.32l80,80A8,8,0,0,1,221.66,133.66Z`}))],[`fill`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M221.66,133.66l-80,80A8,8,0,0,1,128,208V147.31L61.66,213.66A8,8,0,0,1,48,208V48a8,8,0,0,1,13.66-5.66L128,108.69V48a8,8,0,0,1,13.66-5.66l80,80A8,8,0,0,1,221.66,133.66Z`}))],[`light`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M140.24,132.24l-80,80a6,6,0,0,1-8.48-8.48L127.51,128,51.76,52.24a6,6,0,0,1,8.48-8.48l80,80A6,6,0,0,1,140.24,132.24Zm80-8.48-80-80a6,6,0,0,0-8.48,8.48L207.51,128l-75.75,75.76a6,6,0,1,0,8.48,8.48l80-80A6,6,0,0,0,220.24,123.76Z`}))],[`regular`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M141.66,133.66l-80,80a8,8,0,0,1-11.32-11.32L124.69,128,50.34,53.66A8,8,0,0,1,61.66,42.34l80,80A8,8,0,0,1,141.66,133.66Zm80-11.32-80-80a8,8,0,0,0-11.32,11.32L204.69,128l-74.35,74.34a8,8,0,0,0,11.32,11.32l80-80A8,8,0,0,0,221.66,122.34Z`}))],[`thin`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M138.83,130.83l-80,80a4,4,0,0,1-5.66-5.66L130.34,128,53.17,50.83a4,4,0,0,1,5.66-5.66l80,80A4,4,0,0,1,138.83,130.83Zm80-5.66-80-80a4,4,0,0,0-5.66,5.66L210.34,128l-77.17,77.17a4,4,0,0,0,5.66,5.66l80-80A4,4,0,0,0,218.83,125.17Z`}))]]),me=new Map([[`bold`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M208,28H48A20,20,0,0,0,28,48V208a20,20,0,0,0,20,20H208a20,20,0,0,0,20-20V48A20,20,0,0,0,208,28Zm-4,176H52V52H204Z`}))],[`duotone`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M216,48V208a8,8,0,0,1-8,8H48a8,8,0,0,1-8-8V48a8,8,0,0,1,8-8H208A8,8,0,0,1,216,48Z`,opacity:`0.2`}),K.createElement(`path`,{d:`M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32Zm0,176H48V48H208V208Z`}))],[`fill`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M224,48V208a16,16,0,0,1-16,16H48a16,16,0,0,1-16-16V48A16,16,0,0,1,48,32H208A16,16,0,0,1,224,48Z`}))],[`light`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M208,34H48A14,14,0,0,0,34,48V208a14,14,0,0,0,14,14H208a14,14,0,0,0,14-14V48A14,14,0,0,0,208,34Zm2,174a2,2,0,0,1-2,2H48a2,2,0,0,1-2-2V48a2,2,0,0,1,2-2H208a2,2,0,0,1,2,2Z`}))],[`regular`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32Zm0,176H48V48H208V208Z`}))],[`thin`,K.createElement(K.Fragment,null,K.createElement(`path`,{d:`M208,36H48A12,12,0,0,0,36,48V208a12,12,0,0,0,12,12H208a12,12,0,0,0,12-12V48A12,12,0,0,0,208,36Zm4,172a4,4,0,0,1-4,4H48a4,4,0,0,1-4-4V48a4,4,0,0,1,4-4H208a4,4,0,0,1,4,4Z`}))]]),he=K.forwardRef((e,t)=>K.createElement(k,{ref:t,...e,weights:fe}));he.displayName=`CaretDoubleLeftIcon`;var ge=K.forwardRef((e,t)=>K.createElement(k,{ref:t,...e,weights:pe}));ge.displayName=`CaretDoubleRightIcon`;var _e=K.forwardRef((e,t)=>K.createElement(k,{ref:t,...e,weights:me}));_e.displayName=`SquareIcon`;var q=M();function ve(e){if(typeof e!=`object`||!e||Array.isArray(e)||`$$typeof`in e||e instanceof Promise)return!1;let t=e;return`label`in t&&t.label!==void 0}function ye(e){return Array.isArray(e)?e:Object.entries(e).map(([e,t])=>({value:e,label:ve(t)?t.label:t}))}function be(e){let t=ye(e),n=new Map;if(!Array.isArray(e))for(let[t,r]of Object.entries(e))ve(r)&&n.set(t,{disabled:r.disabled});return t.filter(e=>e.value!==null).map((e,t)=>{let r=typeof e.value==`string`?e.value:`option-${t}`,i=typeof e.value==`string`?n.get(e.value):void 0;return(0,q.jsx)(xe,{value:e.value,disabled:i?.disabled,children:e.label},r)})}function J({children:e,className:n,renderValue:r,label:i,hideLabel:a,placeholder:o,loading:s,labelTooltip:c,description:l,error:u,required:d,container:f,...p}){let m=(0,K.useId)(),h=w(),g=f??h??void 0,_=p,v=_[`aria-label`],y=_[`aria-labelledby`],b=typeof i==`string`?i:o,S=i&&a!==!0,C=S?void 0:y??(i?m:void 0),E=v??(C?void 0:b),D=p.items?ye(p.items):void 0,O=e??(p.items?be(p.items):null),{items:k,...A}=p,M=(0,q.jsxs)(ne,{...A,items:D,disabled:s||p.disabled,children:[(0,q.jsxs)(L,{className:N(T(),`justify-between font-normal`,`focus:opacity-100 focus-visible:ring-1 focus-visible:ring-kumo-hairline *:in-focus:opacity-100`,p.disabled&&`cursor-not-allowed opacity-50`,n),"aria-label":E,"aria-labelledby":C,children:[s?(0,q.jsx)(x,{className:`w-32`}):(0,q.jsx)(B,{placeholder:o,className:`min-w-0 truncate`,children:r}),(0,q.jsx)(U,{className:`flex shrink-0 items-center`,children:(0,q.jsx)(F,{})})]}),(0,q.jsx)(ie,{container:g,children:(0,q.jsx)(j,{children:(0,q.jsx)(H,{className:N(`flex flex-col`,`max-h-[var(--available-height)] bg-kumo-base text-kumo-default`,`rounded-lg shadow-lg ring ring-kumo-hairline`,`min-w-[calc(var(--anchor-width)+3px)] py-1.5`),children:(0,q.jsx)(ue,{className:N(`min-h-0 flex-1 overflow-y-auto overscroll-none scroll-pt-2 scroll-pb-2`),children:O})})})})]});if(S)return(0,q.jsx)(t,{label:i,required:d,labelTooltip:c,description:l,error:u?typeof u==`string`?{message:u,match:!0}:u:void 0,children:M});let P=u?typeof u==`string`?{message:u}:u:void 0;return(0,q.jsxs)(`div`,{className:`grid gap-2`,children:[i&&(0,q.jsx)(`span`,{id:m,className:`sr-only`,children:i}),M,P?(0,q.jsx)(`span`,{className:`text-sm text-kumo-danger`,children:P.message}):l&&(0,q.jsx)(`span`,{className:`text-sm leading-snug text-kumo-subtle`,children:l})]})}function xe({children:e,value:t,disabled:n,className:r}){return(0,q.jsxs)(z,{value:t,disabled:n,className:N(`group mx-1.5 flex cursor-pointer items-center justify-between gap-2 rounded px-2 py-1.5 text-base data-highlighted:bg-kumo-tint`,`data-[disabled]:pointer-events-none data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50`,r),children:[(0,q.jsx)(ae,{children:e}),(0,q.jsx)(ce,{children:(0,q.jsx)(P,{})})]})}var Se=(0,K.forwardRef)(({children:e,className:t},n)=>(0,q.jsx)(le,{ref:n,className:N(t),children:e}));Se.displayName=`Select.Group`;var Ce=(0,K.forwardRef)(({children:e,className:t},n)=>(0,q.jsx)(G,{ref:n,className:N(`px-3.5 py-1.5 text-sm font-semibold text-kumo-subtle`,t),children:e}));Ce.displayName=`Select.GroupLabel`;var we=(0,K.forwardRef)(({className:e},t)=>(0,q.jsx)(I,{ref:t,className:N(`-mx-1 my-1 h-px bg-kumo-line`,e)}));we.displayName=`Select.Separator`,J.Option=xe,J.Group=Se,J.GroupLabel=Ce,J.Separator=we,J.Option.displayName=`Select.Option`;var Te=[25,50,100,250],Ee=(e,t,n)=>Math.min(Math.max(e,t),n),Y={controls:`full`},X=(0,K.createContext)(null);function De(){let e=(0,K.useContext)(X);if(!e)throw Error(`Pagination compound components must be used within a Pagination component`);return e}function Oe({children:e,className:t}){let{page:n,perPage:r,totalCount:i,pageShowingRange:a}=De(),o=e?e({page:n,perPage:r,totalCount:i,pageShowingRange:a}):i&&i>0?(0,q.jsxs)(q.Fragment,{children:[`Showing `,(0,q.jsx)(`span`,{className:`tabular-nums`,children:a}),` of`,` `,(0,q.jsx)(`span`,{className:`tabular-nums`,children:i})]}):null;return(0,q.jsx)(`div`,{"data-slot":`pagination-info`,className:N(`text-sm text-kumo-strong`,t),children:o})}Oe.displayName=`Pagination.Info`;function ke({value:e,onChange:t,options:n=Te,label:r=`Per page:`,className:i}){return(0,q.jsxs)(`div`,{"data-slot":`pagination-page-size`,className:N(`flex items-center gap-2`,i),children:[r&&(0,q.jsx)(`span`,{className:`text-sm text-kumo-strong`,children:r}),(0,q.jsx)(J,{"aria-label":`Page size`,value:e,onValueChange:e=>t(e),children:n.map(e=>(0,q.jsx)(J.Option,{value:e,children:e},e))})]})}ke.displayName=`Pagination.PageSize`;function Z({controls:e=Y.controls,pageSelector:t=`input`,className:i}){let{page:a,maxPage:o,setPage:s,editingPage:c,setEditingPage:l}=De();return(0,q.jsx)(`div`,{"data-slot":`pagination-controls`,className:N(`grow flex flex-col items-end`,i),children:(0,q.jsx)(`div`,{children:(0,q.jsxs)(r,{focusMode:`individual`,children:[e===`full`&&(0,q.jsx)(r.Button,{variant:`secondary`,"aria-label":`First page`,disabled:a<=1,onClick:()=>{s(1),l(1)},children:(0,q.jsx)(he,{size:16})}),(0,q.jsx)(r.Button,{variant:`secondary`,"aria-label":`Previous page`,disabled:a<=1,onClick:()=>{let e=Math.max(a-1,1);s(e),l(e)},children:(0,q.jsx)(n,{size:16})}),e===`full`&&(t===`dropdown`?(0,q.jsx)(J,{"aria-label":`Page number`,className:`rounded-none ring-kumo-line`,value:a,onValueChange:e=>{let t=e;s(t),l(t)},children:Array.from({length:o},(e,t)=>t+1).map(e=>(0,q.jsx)(J.Option,{value:e,children:e},e))}):(0,q.jsx)(r.Input,{style:{width:50},className:`text-center`,"aria-label":`Page number`,value:c,onValueChange:e=>{l(Number(e))},onBlur:()=>{let e=Ee(c,1,o);s(e),l(e)},onKeyDown:e=>{if(e.key===`Enter`){let e=Ee(c,1,o);s(e),l(e)}},autoComplete:`off`,"data-1p-ignore":!0,"data-lpignore":`true`,"data-form-type":`other`})),(0,q.jsx)(r.Button,{variant:`secondary`,"aria-label":`Next page`,disabled:a===o,onClick:()=>{let e=Math.min(a+1,o);s(e),l(e)},children:(0,q.jsx)(ee,{size:16})}),e===`full`&&(0,q.jsx)(r.Button,{variant:`secondary`,"aria-label":`Last page`,disabled:a===o,onClick:()=>{s(o),l(o)},children:(0,q.jsx)(ge,{size:16})})]})})})}Z.displayName=`Pagination.Controls`;function Ae({className:e}){return(0,q.jsx)(`div`,{"data-slot":`pagination-separator`,className:N(`mx-2 h-6 border-l border-kumo-line`,e)})}Ae.displayName=`Pagination.Separator`;function Q(e){let{page:t=1,perPage:n,totalCount:r,setPage:i,children:a,className:o}=e,s=`text`in e?e.text:void 0,c=`controls`in e?e.controls??Y.controls:Y.controls,[l,u]=(0,K.useState)(1);(0,K.useEffect)(()=>{u(t)},[t]);let d=(0,K.useMemo)(()=>{let e=t*(n??1)-(n??0)+1,i=Math.min(t*(n??0),r??0);return Number.isNaN(e)&&(e=0),Number.isNaN(i)&&(i=0),`${e}-${i}`},[t,n,r]),f={page:t,perPage:n,totalCount:r,maxPage:(0,K.useMemo)(()=>Math.ceil((r??1)/(n??1)),[r,n]),pageShowingRange:d,setPage:i,editingPage:l,setEditingPage:u};return a?(0,q.jsx)(X.Provider,{value:f,children:(0,q.jsx)(`div`,{"data-slot":`pagination`,className:N(`flex items-center gap-2 w-full`,o),children:a})}):(0,q.jsx)(X.Provider,{value:f,children:(0,q.jsxs)(`div`,{"data-slot":`pagination`,className:N(`flex items-center gap-2 w-full`,o),children:[(0,q.jsx)(`div`,{"data-slot":`pagination-info`,className:`grow text-sm text-kumo-strong`,children:s?s({page:t,perPage:n,totalCount:r,pageShowingRange:d}):r&&r>0?(0,q.jsxs)(q.Fragment,{children:[`Showing `,(0,q.jsx)(`span`,{className:`tabular-nums`,children:d}),` of`,` `,(0,q.jsx)(`span`,{className:`tabular-nums`,children:r})]}):null}),(0,q.jsx)(Z,{controls:c})]})})}Q.displayName=`Pagination`;var je=Object.assign(Q,{Info:Oe,PageSize:ke,Controls:Z,Separator:Ae});function Me({onCreated:e,onOpenChange:t,open:n,workflowName:r}){let[i,a]=(0,K.useState)(!1),[o,s]=(0,K.useState)(null),[c,l]=(0,K.useState)(``),[u,d]=(0,K.useState)(``),[f,p]=(0,K.useState)(null),m=(0,K.useCallback)(()=>{l(``),d(``),s(null),p(null)},[]);function h(e){e||m(),t(e)}function g(){if(!u.trim())return p(null),{valid:!0,value:void 0};try{let e=JSON.parse(u);return p(null),{valid:!0,value:e}}catch{return p(`Invalid JSON`),{valid:!1}}}async function _(){let t=g();if(t.valid){a(!0),s(null);try{let n={};c.trim()&&(n.id=c.trim()),t.value!==void 0&&(n.params=t.value);let i=(await W({path:{workflow_name:r},body:n})).data?.result?.id;if(!i){s(`Instance was created but no ID was returned`);return}m(),e(i)}catch(e){s(e instanceof Error?e.message:`Failed to create instance`)}finally{a(!1)}}}return(0,q.jsx)(y.Root,{open:n,onOpenChange:h,children:(0,q.jsxs)(y,{size:`lg`,children:[(0,q.jsxs)(`div`,{className:`border-b border-kumo-fill px-6 pt-6 pb-4`,children:[(0,q.jsx)(y.Title,{className:`text-lg font-semibold text-kumo-default`,children:`Trigger this workflow?`}),(0,q.jsx)(`p`,{className:`mt-1 text-sm text-kumo-subtle`,children:`Manually trigger an instance of this Workflow using the payload below.`})]}),(0,q.jsxs)(`div`,{className:`px-6 py-6`,children:[o&&(0,q.jsx)(`div`,{className:`mb-5 rounded-lg border border-kumo-danger/20 bg-kumo-danger/8 p-3 text-sm text-kumo-danger`,children:o}),(0,q.jsxs)(`div`,{className:`mb-5`,children:[(0,q.jsxs)(`label`,{className:`mb-2 block text-sm font-medium text-kumo-default`,children:[`Instance ID`,` `,(0,q.jsx)(`span`,{className:`font-normal text-kumo-subtle`,children:`(optional)`})]}),(0,q.jsx)(`input`,{className:`focus-visible:ring-kumo-ring w-full rounded-lg border border-kumo-fill bg-kumo-base px-3 py-2.5 text-sm text-kumo-default placeholder:text-kumo-subtle focus:border-kumo-brand focus:outline-none focus-visible:ring-2`,onChange:e=>l(e.target.value),placeholder:`Auto-generated UUID if empty`,type:`text`,value:c})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`mb-2 block text-sm font-medium text-kumo-default`,children:`Params`}),(0,q.jsx)(`textarea`,{className:`focus-visible:ring-kumo-ring w-full resize-y rounded-lg border bg-kumo-base px-3 py-2.5 font-mono text-sm text-kumo-default placeholder:text-kumo-subtle focus:outline-none focus-visible:ring-2 ${f?`border-kumo-danger focus:border-kumo-danger`:`border-kumo-fill focus:border-kumo-brand`}`,onChange:e=>{d(e.target.value),f&&p(null)},placeholder:`{"key": "value"}`,rows:8,value:u}),f?(0,q.jsx)(`p`,{className:`mt-1 text-xs text-kumo-danger`,children:f}):(0,q.jsx)(`p`,{className:`mt-1 text-xs text-kumo-subtle`,children:`JSON payload passed to the workflow`})]})]}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-kumo-fill px-6 py-4`,children:[(0,q.jsx)(R,{variant:`secondary`,onClick:()=>h(!1),disabled:i,children:`Cancel`}),(0,q.jsx)(R,{variant:`primary`,disabled:i,loading:i,onClick:_,children:i?`Triggering...`:`Trigger Instance`})]})]})})}var $=[{key:`complete`,label:`Complete`,icon:l,color:`text-kumo-link`,weight:`fill`},{key:`errored`,label:`Errored`,icon:i,color:`text-kumo-danger`,weight:`fill`},{key:`queued`,label:`Queued`,icon:o,color:`text-kumo-subtle`,weight:`regular`},{key:`running`,label:`Running`,icon:g,color:`text-kumo-subtle`,weight:`fill`},{key:`paused`,label:`Paused`,icon:f,color:`text-kumo-subtle`,weight:`fill`},{key:`waiting`,label:`Waiting`,icon:_,color:`text-kumo-subtle`,weight:`regular`},{key:`terminated`,label:`Terminated`,icon:_e,color:`text-kumo-subtle`,weight:`fill`}],Ne=(0,K.memo)(function({statusCounts:e}){return(0,q.jsx)(`div`,{className:`mb-4 flex divide-x divide-kumo-fill overflow-hidden rounded-lg border border-kumo-fill bg-kumo-base`,children:$.map(({key:t,label:n,icon:r,color:i,weight:a})=>(0,q.jsxs)(`div`,{className:`flex-1 space-y-1 px-4.5 pt-4 pb-3.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-kumo-subtle`,children:[(0,q.jsx)(r,{className:i,size:12,weight:a}),n]}),(0,q.jsx)(`div`,{className:`mt-0.5 text-base text-kumo-default`,children:e[t]??0})]},t))})}),Pe={pause:{icon:f,style:`border-kumo-fill bg-kumo-base text-kumo-default hover:bg-kumo-fill`,weight:`fill`},resume:{icon:g,style:`border-kumo-fill bg-kumo-base text-kumo-default hover:bg-kumo-fill`,weight:`fill`},restart:{icon:e,style:`border-kumo-fill bg-kumo-base text-kumo-default hover:bg-kumo-fill`,weight:`regular`},terminate:{icon:c,style:`border-kumo-fill bg-kumo-base text-kumo-danger hover:bg-kumo-badge-red/10`,weight:`fill`}},Fe=(0,K.memo)(function({instance:e,onActionComplete:t,workflowName:n}){let r=O(),[i,o]=(0,K.useState)(null),[c,l]=(0,K.useState)(!1),[f,p]=(0,K.useState)(!1),[m,h]=(0,K.useState)(``),[g,_]=(0,K.useState)(``),[b,x]=(0,K.useState)(!1),S=e.status??`unknown`,w=d(S);async function T(r,i){r.stopPropagation(),o(i);try{await V({path:{workflow_name:n,instance_id:e.id??``},body:{action:i}}),t()}catch{t()}finally{o(null)}}function E(e){e.stopPropagation(),l(!0)}async function D(){l(!1),o(`terminate`);try{await de({path:{workflow_name:n,instance_id:e.id??``}}),t()}catch{t()}finally{o(null)}}function k(e){e.stopPropagation(),p(!0)}async function A(){if(!m.trim())return;let r;if(g.trim())try{r=JSON.parse(g)}catch{return}x(!0);try{await C({path:{workflow_name:n,instance_id:e.id??``,event_type:m.trim()},body:r}),p(!1),h(``),_(``),t()}catch{p(!1),t()}finally{x(!1)}}function j(){r({to:`/workflows/$workflowName/$instanceId`,params:{instanceId:e.id??``,workflowName:n},search:e=>e})}return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`border-b border-kumo-fill bg-kumo-base p-1 last:border-b-0`,children:(0,q.jsxs)(`div`,{className:`grid h-10 cursor-pointer grid-cols-[100px_60px_1fr_auto] items-center gap-3 rounded-lg px-2 transition-colors hover:bg-kumo-fill`,onClick:j,children:[(0,q.jsx)(`div`,{children:(0,q.jsx)(s,{status:S})}),(0,q.jsx)(`span`,{className:`text-sm text-kumo-subtle`,children:u(e.created_on)||`—`}),(0,q.jsx)(`span`,{className:`truncate font-mono text-xs text-kumo-default`,children:e.id}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[w.map(e=>{let t=Pe[e],n=t.icon;return(0,q.jsx)(`button`,{className:`inline-flex size-7 cursor-pointer items-center justify-center rounded-md border transition-colors disabled:cursor-not-allowed disabled:opacity-40 ${t.style}`,disabled:i!==null,onClick:t=>void T(t,e),title:e.charAt(0).toUpperCase()+e.slice(1),children:(0,q.jsx)(n,{size:14,weight:t.weight,className:i===e?`animate-spin`:``})},e)}),S!==`complete`&&S!==`errored`&&S!==`terminated`&&(0,q.jsx)(`button`,{className:`ml-1 inline-flex size-7 cursor-pointer items-center justify-center rounded-md border border-kumo-fill bg-kumo-base text-kumo-default transition-colors hover:bg-kumo-fill disabled:cursor-not-allowed disabled:opacity-40`,disabled:i!==null,onClick:k,title:`Send Event`,children:(0,q.jsx)(a,{size:14})}),(0,q.jsx)(`button`,{className:`inline-flex size-7 cursor-pointer items-center justify-center rounded-md border border-kumo-fill bg-kumo-base text-kumo-danger transition-colors hover:bg-kumo-badge-red/10 disabled:cursor-not-allowed disabled:opacity-40`,disabled:i!==null,onClick:E,title:`Delete`,children:(0,q.jsx)(v,{size:14})})]})]})}),(0,q.jsx)(y.Root,{open:c,onOpenChange:l,children:(0,q.jsxs)(y,{size:`lg`,children:[(0,q.jsxs)(`div`,{className:`border-b border-kumo-fill px-6 pt-6 pb-4`,children:[(0,q.jsx)(y.Title,{className:`text-lg font-semibold text-kumo-default`,children:`Delete this instance?`}),(0,q.jsx)(`p`,{className:`mt-1 text-sm text-kumo-subtle`,children:`This will permanently delete the instance and its persistence data. This action cannot be undone.`})]}),(0,q.jsx)(`div`,{className:`px-6 py-4`,children:(0,q.jsxs)(`div`,{className:`rounded-lg border border-kumo-fill bg-kumo-elevated px-4 py-3`,children:[(0,q.jsx)(`span`,{className:`text-xs text-kumo-subtle`,children:`Instance ID`}),(0,q.jsx)(`p`,{className:`mt-0.5 font-mono text-sm text-kumo-default`,children:e.id})]})}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-kumo-fill px-6 py-4`,children:[(0,q.jsx)(R,{variant:`secondary`,onClick:()=>l(!1),children:`Cancel`}),(0,q.jsx)(R,{variant:`destructive`,onClick:()=>void D(),children:`Delete Instance`})]})]})}),(0,q.jsx)(y.Root,{open:f,onOpenChange:e=>{p(e),e||(h(``),_(``))},children:(0,q.jsxs)(y,{size:`lg`,className:`w-lg`,children:[(0,q.jsx)(`div`,{className:`border-b border-kumo-fill px-6 py-4`,children:(0,q.jsx)(y.Title,{className:`text-lg font-semibold text-kumo-default`,children:`Send Event`})}),(0,q.jsxs)(`div`,{className:`space-y-4 px-6 py-5`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{className:`mb-2 block text-sm font-medium text-kumo-default`,children:`Event Type`}),(0,q.jsx)(`input`,{className:`focus-visible:ring-kumo-ring w-full rounded-lg border border-kumo-fill bg-kumo-base px-3 py-2.5 text-sm text-kumo-default placeholder:text-kumo-subtle focus:border-kumo-brand focus:outline-none focus-visible:ring-2`,onChange:e=>h(e.target.value),placeholder:`my-event`,type:`text`,value:m})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`label`,{className:`mb-2 block text-sm font-medium text-kumo-default`,children:[`Payload`,` `,(0,q.jsx)(`span`,{className:`font-normal text-kumo-subtle`,children:`(optional)`})]}),(0,q.jsx)(`textarea`,{className:`focus-visible:ring-kumo-ring w-full resize-y rounded-lg border border-kumo-fill bg-kumo-base px-3 py-2.5 font-mono text-sm text-kumo-default placeholder:text-kumo-subtle focus:border-kumo-brand focus:outline-none focus-visible:ring-2`,onChange:e=>_(e.target.value),placeholder:`{"key": "value"}`,rows:4,value:g})]})]}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-kumo-fill px-6 py-4`,children:[(0,q.jsx)(R,{variant:`secondary`,onClick:()=>p(!1),disabled:b,children:`Cancel`}),(0,q.jsx)(R,{variant:`primary`,disabled:!m.trim()||b,loading:b,onClick:()=>void A(),children:`Send`})]})]})})]})});function Ie(){let e=se.useParams(),t=se.useLoaderData(),n=O(),[r,i]=(0,K.useState)(!1),[a,o]=(0,K.useState)(!1),[s,c]=(0,K.useState)(null),[l,u]=(0,K.useState)(!1),[d,f]=(0,K.useState)(null),[_,x]=(0,K.useState)(t.instances),[C,w]=(0,K.useState)(t.instances.length===0&&(t.resultInfo.total_count??0)===0),[T,D]=(0,K.useState)(!1),[k,A]=(0,K.useState)(!1),[j,M]=(0,K.useState)(t.resultInfo.page??1),[N,P]=(0,K.useState)(t.resultInfo.per_page??25),[ee,I]=(0,K.useState)(t.resultInfo.status_counts??{}),[L,ne]=(0,K.useState)(`all`),[z,B]=(0,K.useState)(t.resultInfo.total_count??0);(0,K.useEffect)(()=>{x(t.instances),B(t.resultInfo.total_count??0),I(t.resultInfo.status_counts??{}),f(null),w(!1),D(!1)},[t]);let V=(0,K.useCallback)(async(t,n,r,i)=>{try{r||D(!0),f(null);let a=t??j,o=n??N,s=i??L,c=await te({path:{workflow_name:e.workflowName},query:{page:a,per_page:o,...s===`all`?{}:{status:s}}});x(c.data?.result??[]),B(c.data?.result_info?.total_count??0),(!s||s===`all`)&&I(c.data?.result_info?.status_counts??{}),M(c.data?.result_info?.page??a),w(!1)}catch(e){f(e instanceof Error?e.message:`Failed to fetch instances`)}finally{D(!1)}},[e.workflowName,j,N,L]),H=(0,K.useCallback)(async()=>{A(!0);try{await h(V(void 0,void 0,!0))}finally{A(!1)}},[V]),U=(0,K.useRef)(null);(0,K.useEffect)(()=>(U.current=setInterval(()=>{V(void 0,void 0,!0)},1e4),()=>{U.current&&clearInterval(U.current)}),[V]);function ie(e){M(e),V(e)}function ae(e){P(e),M(1),V(1,e)}function ce(t){u(!1),n({to:`/workflows/$workflowName/$instanceId`,params:{workflowName:e.workflowName,instanceId:t}})}function W(e){ne(e),M(1),V(1,void 0,!1,e)}function G(e){i(e),e||c(null)}async function le(){o(!0),c(null);try{await re({path:{workflow_name:e.workflowName}}),G(!1),V(1)}catch(e){c(e instanceof Error?e.message:`Failed to delete instances`)}finally{o(!1)}}return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(S,{icon:oe,items:[(0,q.jsx)(`span`,{className:`flex items-center gap-1.5`,children:e.workflowName},`workflow-name`)],title:`Workflows`}),(0,q.jsxs)(`div`,{className:`px-8 py-6`,children:[(0,q.jsx)(Ne,{statusCounts:ee}),(0,q.jsx)(`hr`,{className:`-mx-8 my-4 border-kumo-fill`}),(0,q.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,q.jsxs)(b,{children:[(0,q.jsx)(b.Trigger,{render:(0,q.jsxs)(`button`,{className:`inline-flex h-9 min-w-36 cursor-pointer items-center justify-between rounded-lg border border-kumo-fill bg-kumo-base px-3 text-sm text-kumo-default transition-colors hover:bg-kumo-fill`,children:[(0,q.jsx)(`span`,{children:L===`all`?`All`:$.find(e=>e.key===L)?.label??L}),(0,q.jsx)(F,{size:14,className:`text-kumo-subtle`})]})}),(0,q.jsxs)(b.Content,{align:`start`,className:`w-36 bg-kumo-base`,side:`bottom`,children:[(0,q.jsx)(b.Item,{className:`cursor-pointer gap-2 rounded-md transition-colors hover:bg-kumo-fill`,icon:(0,q.jsx)(m,{}),onClick:()=>W(`all`),children:`All`}),$.map(({key:e,label:t,icon:n})=>(0,q.jsx)(b.Item,{className:`cursor-pointer gap-2 rounded-md transition-colors hover:bg-kumo-fill`,icon:(0,q.jsx)(n,{}),onClick:()=>W(e),children:t},e))]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(R,{onClick:e=>{e.target.blur(),u(!0)},variant:`primary`,children:[(0,q.jsx)(g,{size:14,weight:`fill`}),`Trigger`]}),(0,q.jsx)(R,{"aria-label":`Refresh`,disabled:k,onClick:()=>void H(),shape:`square`,variant:`secondary`,children:(0,q.jsx)(E,{size:18,className:k?`animate-spin`:``})}),(0,q.jsxs)(b,{children:[(0,q.jsx)(b.Trigger,{render:(0,q.jsx)(R,{"aria-label":`More actions`,shape:`square`,children:(0,q.jsx)(p,{size:14,weight:`bold`})})}),(0,q.jsx)(b.Content,{align:`end`,sideOffset:4,children:(0,q.jsxs)(b.Item,{className:`flex cursor-pointer items-center gap-2 text-kumo-danger`,onClick:()=>G(!0),children:[(0,q.jsx)(v,{}),(0,q.jsx)(`span`,{children:`Delete all instances`})]})})]})]})]}),d&&(0,q.jsx)(`div`,{className:`mb-4 rounded-md border border-kumo-danger/20 bg-kumo-danger/8 p-4 text-kumo-danger`,children:d}),C?(0,q.jsx)(`div`,{className:`p-12 text-center text-kumo-subtle`,children:`Loading...`}):_.length===0&&!T?(0,q.jsx)(`div`,{className:`rounded-lg border border-kumo-fill bg-kumo-elevated px-5 py-8 text-center text-sm text-kumo-subtle`,children:`No instances found`}):_.length===0?(0,q.jsx)(`div`,{className:`rounded-lg border border-kumo-fill bg-kumo-elevated px-5 py-8 text-center text-sm text-kumo-subtle`,children:L===`all`?`No instances found`:(0,q.jsxs)(q.Fragment,{children:[`No instances found in state ‘`,L,`’`]})}):(0,q.jsxs)(`div`,{className:`transition-opacity duration-150 ${T?`opacity-60`:`opacity-100`}`,children:[(0,q.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-kumo-fill bg-kumo-base`,children:_.map(t=>(0,q.jsx)(Fe,{instance:t,onActionComplete:H,workflowName:e.workflowName},t.id))}),z>0&&(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-4`,children:[(0,q.jsxs)(b,{children:[(0,q.jsx)(b.Trigger,{render:(0,q.jsxs)(R,{children:[N,` `,(0,q.jsx)(F,{size:14})]})}),(0,q.jsx)(b.Content,{align:`start`,className:`bg-kumo-base`,side:`top`,children:[10,25,50,100].map(e=>(0,q.jsxs)(b.Item,{className:`cursor-pointer rounded-md transition-colors hover:bg-kumo-fill`,onClick:()=>ae(e),children:[e,e===N&&(0,q.jsx)(`span`,{className:`ml-2 text-kumo-subtle`,children:`✓`})]},e))})]}),(0,q.jsx)(je,{page:j,perPage:N,setPage:ie,totalCount:z})]})]})]}),(0,q.jsx)(y.Root,{open:r,onOpenChange:G,children:(0,q.jsxs)(y,{size:`lg`,className:`w-lg`,children:[(0,q.jsx)(`div`,{className:`border-b border-kumo-fill px-6 py-4`,children:(0,q.jsx)(y.Title,{className:`text-lg font-semibold text-kumo-default`,children:`Delete all instances`})}),(0,q.jsxs)(`div`,{className:`px-6 py-5`,children:[s&&(0,q.jsx)(`div`,{className:`mb-4 rounded-lg border border-kumo-danger/20 bg-kumo-danger/8 p-3 text-sm text-kumo-danger`,children:s}),(0,q.jsxs)(`p`,{className:`text-sm text-kumo-subtle`,children:[`This will permanently delete all instances of`,` `,(0,q.jsx)(`span`,{className:`font-semibold text-kumo-default`,children:e.workflowName}),`. All instance data and persistence files will be removed. This action cannot be undone.`]})]}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-kumo-fill px-6 py-4`,children:[(0,q.jsx)(R,{variant:`secondary`,onClick:()=>G(!1),disabled:a,children:`Cancel`}),(0,q.jsx)(R,{variant:`destructive`,disabled:a,loading:a,onClick:()=>void le(),children:`Delete`})]})]})}),(0,q.jsx)(Me,{onCreated:ce,onOpenChange:u,open:l,workflowName:e.workflowName})]})}export{Ie as component};