aion-server 0.23.0

Aion workflow server library: HTTP, gRPC, WebSocket, and worker endpoints. Run it with the `aion` binary from the aion-cli crate.
Documentation
1
import{r as f,u as J,j as n,a8 as se,N as ae,B as oe,E as le,o as ie,a9 as ue}from"./index-BGjxMRjp.js";import{d as ce,s as de,u as fe,h as me}from"./startWorkflowDraft-CtmQRYl9.js";function pe(e){const[r,t]=f.useState(()=>e.getState().draft),s=f.useCallback(a=>{t(l=>({...l,...a})),e.getState().setDraft(a)},[e]),o=f.useCallback(()=>{e.getState().clearDraft(),t(e.getState().draft)},[e]);return{draft:r,updateDraft:s,clearDraft:o}}function xe(e,r){return r&&e.length>0}function ge(e,r){return e.find(t=>t.workflowType===r&&t.routeActive)??null}function he(e){return e.enabled?e.versions.isError?{schema:null,isLoading:!1}:e.versions.isPending?{schema:null,isLoading:!0}:e.active===null?{schema:null,isLoading:!1}:e.document.isError?{schema:null,isLoading:!1}:e.document.isPending||e.document.data===void 0?{schema:null,isLoading:!0}:{schema:e.document.data.inputSchema,isLoading:!1}:{schema:null,isLoading:!1}}function je({workflowType:e,deployGranted:r,client:t=ce}){const s=xe(e,r),o=f.useCallback(i=>ge(i,e),[e]),a=J({enabled:s,queryKey:["actions","start-schema","versions"],queryFn:()=>t.listDeployedVersions(),select:o,retry:!1}),l=a.data??null,u=J({enabled:s&&l!==null,queryKey:["actions","start-schema","document",l?.workflowType,l?.contentHash],queryFn:()=>t.loadDeployedDocument(l?.workflowType??"",l?.contentHash??""),staleTime:Number.POSITIVE_INFINITY,retry:!1});return he({enabled:s,versions:{isPending:a.isPending,isError:a.isError},active:l,document:{isPending:u.isPending,isError:u.isError,data:u.data}})}function I(e){const r=e.trim();if(r.length===0)return{ok:!0,value:{}};let t;try{t=JSON.parse(r)}catch(s){return{ok:!1,error:be(s)}}return typeof t!="object"||t===null||Array.isArray(t)?{ok:!1,error:'Input must be a JSON object, e.g. {"key": "value"}.'}:{ok:!0,value:t}}function be(e){return e instanceof Error?`Invalid JSON: ${e.message}`:"Invalid JSON."}function ye(e){if(!p(e)||e.type!==void 0&&e.type!=="object")return null;const r=e.properties;if(!p(r))return null;const t=Object.keys(r);if(t.length===0)return null;const s=W(e);return{fields:t.map(o=>V(o,[o],r[o],s.has(o)))}}function V(e,r,t,s){const o={name:e,path:r,required:s,description:p(t)&&typeof t.description=="string"?t.description:null,defaultValue:p(t)?t.default:void 0};if(!p(t))return{...o,kind:"json"};const a=K(t.enum);if(a!==null)return{...o,kind:"enum",options:a};switch(t.type){case"string":case"number":case"integer":case"boolean":return{...o,kind:"scalar",scalar:t.type};case"object":{const l=t.properties;if(!p(l))return{...o,kind:"json"};const u=W(t);return{...o,kind:"object",fields:Object.keys(l).map(i=>V(i,[...r,i],l[i],u.has(i)))}}case"array":{const l=ve(t.items);return l===null?{...o,kind:"json"}:{...o,kind:"array",item:l}}default:return{...o,kind:"json"}}}function ve(e){if(!p(e))return null;const r=K(e.enum);return r!==null?{kind:"enum",options:r}:e.type==="string"||e.type==="number"||e.type==="integer"||e.type==="boolean"?{kind:"scalar",scalar:e.type}:null}function K(e){if(!Array.isArray(e)||e.length===0)return null;const r=[];for(const t of e)if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")r.push({value:t,label:String(t)});else return null;return r}function W(e){const r=e.required;return Array.isArray(r)?new Set(r.filter(t=>typeof t=="string")):new Set}function k(e,r){let t=e;for(const s of r){if(!p(t))return;t=t[s]}return t}function T(e,r,t){const[s,...o]=r;if(s===void 0)return e;const a={...e};if(o.length===0)return t===void 0?delete a[s]:a[s]=t,a;const l=a[s];return a[s]=T(p(l)?l:{},o,t),a}function Ne(e,r){let t=r;const s=o=>{for(const a of o)a.defaultValue!==void 0&&k(t,a.path)===void 0&&(t=T(t,a.path,a.defaultValue)),a.kind==="object"&&s(a.fields)};return s(e.fields),t}function ke(e,r){const t=[],s=o=>{for(const a of o){const l=k(r,a.path)!==void 0;a.required&&!l&&t.push(a.path.join(".")),a.kind==="object"&&l&&s(a.fields)}};return s(e.fields),t}function p(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function q(e,r){if(e.length===0)return{kind:"write",value:void 0,warning:null};if(r==="string")return{kind:"write",value:e,warning:null};const t=Number(e.trim());return!Number.isFinite(t)||e.trim().length===0?{kind:"reject",warning:"Not a number — kept here until it parses."}:r==="integer"&&!Number.isInteger(t)?{kind:"write",value:t,warning:"The schema says integer — the server may refuse this value."}:{kind:"write",value:t,warning:null}}function Se(e){if(e==="true")return!0;if(e==="false")return!1}function we(e){return e===!0?"true":e===!1?"false":""}function Ee(e,r){if(r==="")return;const t=Number(r);if(!(!Number.isInteger(t)||t<0||t>=e.length))return e[t]?.value}function Fe(e,r){const t=e.findIndex(s=>s.value===r);return t===-1?"":String(t)}function B(e,r){return e===void 0||r?null:`Current value ${JSON.stringify(e)} is outside the schema's domain.`}function Ie(e,r){const t=k(e,r);return t===void 0||p(t)?null:`Current value ${JSON.stringify(t)} is not an object — editing a field below replaces it.`}const A="h-9 rounded-md border border-input bg-transparent px-3 text-sm outline-none focus:border-muted-foreground",Te="min-h-20 rounded-md border border-input bg-transparent px-3 py-2 font-mono text-sm outline-none focus:border-muted-foreground";function Ae({fields:e,value:r,onChange:t}){return n.jsx("div",{className:"grid gap-3",children:e.map(s=>n.jsx(Q,{field:s,onChange:t,root:r},s.path.join(".")))})}function Q({field:e,root:r,onChange:t}){const s=f.useId(),o=k(r,e.path),a=l=>t(T(r,e.path,l));if(e.kind==="object"){const l=Ie(r,e.path);return n.jsxs("fieldset",{className:"grid gap-3 rounded-md border border-border p-3",children:[n.jsx("legend",{className:"px-1 font-medium text-sm",children:n.jsx(P,{field:e})}),n.jsx($,{field:e}),l===null?null:n.jsx(y,{text:l}),e.fields.map(u=>n.jsx(Q,{field:u,onChange:t,root:r},u.path.join(".")))]})}return n.jsxs("label",{className:"flex flex-col gap-2 font-medium text-sm",htmlFor:s,children:[n.jsx("span",{children:n.jsx(P,{field:e})}),n.jsx(De,{current:o,field:e,id:s,write:a}),n.jsx($,{field:e})]})}function De({current:e,field:r,id:t,write:s}){switch(r.kind){case"scalar":return r.scalar==="boolean"?n.jsx(z,{current:e,id:t,write:s}):n.jsx(H,{current:e,id:t,scalar:r.scalar,write:s});case"enum":return n.jsx(Y,{current:e,id:t,options:r.options,write:s});case"array":return n.jsx(Oe,{current:e,id:t,item:r.item,write:s});case"json":return n.jsx(Je,{current:e,id:t,write:s})}}function _(e){const[r,t]=f.useState({base:e,text:e});return{text:r.base===e?r.text:e,accept:(o,a)=>t({base:a,text:o}),keep:o=>t({base:e,text:o})}}function H({current:e,id:r,scalar:t,write:s}){const o=L(e),{text:a,accept:l,keep:u}=_(o),i=q(a,t);return n.jsxs(n.Fragment,{children:[n.jsx("input",{className:A,id:r,inputMode:t==="string"?void 0:"decimal",type:"text",value:a,onChange:c=>{const m=c.currentTarget.value,x=q(m,t);x.kind==="write"?(l(m,L(x.value)),s(x.value)):u(m)}}),a.length===0||i.warning===null?null:n.jsx(y,{text:i.warning})]})}function L(e){return e==null?"":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):JSON.stringify(e)}function z({current:e,id:r,write:t}){const s=B(e,e===!0||e===!1);return n.jsxs(n.Fragment,{children:[n.jsxs("select",{className:A,id:r,value:we(e),onChange:o=>t(Se(o.currentTarget.value)),children:[n.jsx("option",{value:"",children:"(not set)"}),n.jsx("option",{value:"true",children:"true"}),n.jsx("option",{value:"false",children:"false"})]}),s===null?null:n.jsx(y,{text:s})]})}function Y({current:e,id:r,options:t,write:s}){const o=B(e,t.some(a=>a.value===e));return n.jsxs(n.Fragment,{children:[n.jsxs("select",{className:A,id:r,value:Fe(t,e),onChange:a=>s(Ee(t,a.currentTarget.value)),children:[n.jsx("option",{value:"",children:"(not set)"}),t.map((a,l)=>n.jsx("option",{value:String(l),children:a.label},a.label))]}),o===null?null:n.jsx(y,{text:o})]})}function Oe({current:e,id:r,item:t,write:s}){const o=Array.isArray(e)?e:[],a=l=>s(l);return n.jsxs("div",{className:"grid gap-2",id:r,children:[o.map((l,u)=>n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("div",{className:"flex-1",children:n.jsx(Ce,{element:l,item:t,write:i=>{const c=[...o];c[u]=i,a(c)}})}),n.jsx("button",{"aria-label":`Remove item ${u+1}`,className:"rounded-md border border-input px-2 py-1 text-muted-foreground text-xs hover:text-foreground",onClick:()=>a(o.filter((i,c)=>c!==u)),type:"button",children:"Remove"})]},u)),n.jsx("button",{className:"justify-self-start rounded-md border border-input px-2 py-1 text-muted-foreground text-xs hover:text-foreground",onClick:()=>a([...o,t.kind==="scalar"&&t.scalar==="string"?"":null]),type:"button",children:"Add item"})]})}function Ce({element:e,item:r,write:t}){const s=f.useId(),o=a=>t(a===void 0?null:a);return r.kind==="enum"?n.jsx(Y,{current:e,id:s,options:r.options,write:o}):r.scalar==="boolean"?n.jsx(z,{current:e,id:s,write:o}):n.jsx(H,{current:e,id:s,scalar:r.scalar,write:o})}function Je({current:e,id:r,write:t}){const s=e===void 0?"":JSON.stringify(e,null,2),{text:o,accept:a,keep:l}=_(s),[u,i]=f.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx("textarea",{className:Te,id:r,placeholder:"JSON value",value:o,onChange:c=>{const m=c.currentTarget.value;if(m.trim().length===0){i(!1),a(m,""),t(void 0);return}try{const x=JSON.parse(m);a(m,JSON.stringify(x,null,2)),t(x),i(!1)}catch{l(m),i(!0)}}}),u?n.jsx(y,{text:"Not valid JSON — the last valid value is kept until this parses."}):null]})}function P({field:e}){return n.jsxs(n.Fragment,{children:[e.name,e.required?n.jsxs("span",{className:"text-destructive",children:[" *",n.jsx("span",{className:"sr-only",children:"(required)"})]}):null]})}function $({field:e}){return e.description===null?null:n.jsx("span",{className:"font-normal text-muted-foreground text-xs",children:e.description})}function y({text:e}){return n.jsx("span",{className:"font-normal text-warning text-xs",role:"status",children:e})}const qe="min-h-28 rounded-md border border-input bg-transparent px-3 py-2 font-mono text-sm outline-none focus:border-muted-foreground";function Le({inputId:e,inputText:r,onInputTextChange:t,model:s,loading:o,mode:a,onModeChange:l}){if(s===null)return o?n.jsxs("div",{className:"flex flex-col gap-2 font-medium text-sm",children:[n.jsx("span",{children:"Input"}),n.jsx(se,{className:"min-h-28 w-full rounded-md"}),n.jsx("span",{className:"font-normal text-muted-foreground text-xs",children:"Checking the deployed contract for an input schema…"})]}):n.jsxs("label",{className:"flex flex-col gap-2 font-medium text-sm",htmlFor:e,children:["Input (JSON)",n.jsx(R,{inputId:e,inputText:r,onInputTextChange:t}),n.jsx("span",{className:"font-normal text-muted-foreground text-xs",children:"Blank sends an empty object. The engine requires a payload."})]});const u=I(r),i=u.ok,c=i?a:"json";return n.jsxs("fieldset",{className:"flex flex-col gap-2",children:[n.jsx("legend",{className:"sr-only",children:"Input"}),n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("span",{"aria-hidden":"true",className:"font-medium text-sm",children:"Input"}),n.jsxs("fieldset",{"aria-label":"Input mode",className:"flex rounded-lg border border-border bg-surface-elevated p-0.5",children:[n.jsx(M,{disabled:!i,label:"Form",mode:"form",onSelect:l,selected:c}),n.jsx(M,{disabled:!1,label:"JSON",mode:"json",onSelect:l,selected:c})]})]}),i?null:n.jsx("p",{className:"text-destructive text-xs",role:"status",children:"The form view needs the input to parse as a JSON object — fix it here first."}),c==="form"&&u.ok?n.jsx(Ae,{fields:s.fields,onChange:m=>t(G(m)),value:u.value}):n.jsxs("label",{className:"flex flex-col gap-2 font-medium text-sm",htmlFor:e,children:[n.jsx("span",{className:"sr-only",children:"Input (JSON)"}),n.jsx(R,{inputId:e,inputText:r,onInputTextChange:t}),n.jsx("span",{className:"font-normal text-muted-foreground text-xs",children:"Blank sends an empty object. The engine requires a payload."})]})]})}function G(e){return JSON.stringify(e,null,2)}function R({inputId:e,inputText:r,onInputTextChange:t}){return n.jsx("textarea",{className:qe,id:e,placeholder:'{} or {"to": "ops@aion"}',value:r,onChange:s=>t(s.currentTarget.value)})}function M({disabled:e,label:r,mode:t,onSelect:s,selected:o}){return n.jsx("button",{"aria-pressed":o===t,className:ae("rounded-md px-2.5 py-1 text-xs outline-none focus-visible:ring-2 focus-visible:ring-accent-primary",o===t?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground",e&&"cursor-not-allowed opacity-50"),disabled:e,onClick:()=>s(t),type:"button",children:r})}const b="h-9 rounded-md border border-input bg-transparent px-3 text-sm outline-none focus:border-muted-foreground";function Ve({namespace:e,apiClient:r,initialWorkflowType:t,deployGranted:s=!1,schemaClient:o,draftScope:a}){const l=$e(),u=f.useMemo(()=>de(a),[a]),{draft:i,updateDraft:c,clearDraft:m}=pe(u),[x,v]=f.useState(null),[U,X]=f.useState(null);f.useEffect(()=>{t!==void 0&&c({workflowType:t})},[t,c]);const D=i.namespaceEntry.trim(),N=e??(D.length>0?D:null),j=fe({namespace:N,apiClient:r}),O=i.workflowType.trim(),Z=N!==null&&O.length>0&&!j.isPending,{schema:S,isLoading:ee}=je({workflowType:O,deployGranted:s,client:o}),g=f.useMemo(()=>S===null?null:ye(S),[S]),[te,ne]=f.useState("form"),C=f.useRef(null);f.useEffect(()=>{if(g===null||C.current===g)return;const d=I(i.inputText);if(!d.ok)return;C.current=g;const h=Ne(g,d.value);h!==d.value&&c({inputText:G(h)})},[g,i.inputText,c]);function re(d){d.preventDefault(),v(null);const h=I(i.inputText);if(!h.ok){v(h.error);return}if(g!==null){const E=ke(g,h.value);if(E.length>0){v(`Missing required input field${E.length===1?"":"s"}: ${E.join(", ")}`);return}}const w=me(i,h.value);if(!w.ok){v(w.error);return}X(N),j.mutate(w.params,{onSuccess:()=>m()})}return n.jsxs("div",{className:"space-y-4",children:[n.jsxs("form",{className:"grid gap-3 rounded-lg border border-border p-4",onSubmit:re,children:[e===null?n.jsxs("label",{className:"flex flex-col gap-2 font-medium text-sm",htmlFor:l.namespace,children:["Namespace",n.jsx("input",{className:b,id:l.namespace,placeholder:"e.g. orders — created on start if new",value:i.namespaceEntry,onChange:d=>c({namespaceEntry:d.currentTarget.value})}),n.jsx("span",{className:"font-normal text-muted-foreground text-xs",children:"No namespace is selected. Type one to target — an unseen namespace is created when the run starts."})]}):null,n.jsxs("label",{className:"flex flex-col gap-2 font-medium text-sm",htmlFor:l.workflowType,children:["Workflow type",n.jsx("input",{className:b,id:l.workflowType,placeholder:"e.g. EmailDigest",value:i.workflowType,onChange:d=>c({workflowType:d.currentTarget.value})})]}),n.jsx(Le,{inputId:l.input,inputText:i.inputText,loading:ee,mode:te,model:g,onInputTextChange:d=>c({inputText:d}),onModeChange:ne}),n.jsxs("label",{className:"flex flex-col gap-2 font-medium text-sm",htmlFor:l.routingKey,children:["Routing key (optional)",n.jsx("input",{className:b,id:l.routingKey,placeholder:"steers placement; blank = unsteered",value:i.routingKey,onChange:d=>c({routingKey:d.currentTarget.value})})]}),n.jsxs("label",{className:"flex flex-col gap-2 font-medium text-sm",htmlFor:l.taskQueue,children:["Task queue (optional)",n.jsx("input",{className:b,id:l.taskQueue,placeholder:"default activity queue; blank = namespace default",value:i.taskQueue,onChange:d=>c({taskQueue:d.currentTarget.value})})]}),n.jsxs("label",{className:"flex flex-col gap-2 font-medium text-sm",htmlFor:l.displayName,children:["Display name (optional)",n.jsx("input",{className:b,id:l.displayName,placeholder:"a label for this run; omit it to show the bare id",value:i.displayName,onChange:d=>c({displayName:d.currentTarget.value})}),n.jsx("span",{className:"font-normal text-muted-foreground text-xs",children:"A label only — the run is still addressed by its id, and it can be renamed later."})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(oe,{disabled:!Z,type:"submit",children:j.isPending?"Starting…":"Start workflow"}),x===null?null:n.jsx("p",{className:"text-destructive text-sm",children:x})]})]}),n.jsx(Pe,{error:j.error,isError:j.isError,namespace:U??N,result:j.data??null})]})}function Pe({isError:e,error:r,namespace:t,result:s}){return e?n.jsx(le,{error:r,title:"Start failed"}):s===null?null:n.jsxs("div",{className:"rounded-lg border border-primary/40 bg-primary-glow p-4",children:[n.jsx("h3",{className:"font-medium text-foreground text-sm",children:"Workflow started"}),n.jsxs("dl",{className:"mt-2 space-y-1 text-sm",children:[n.jsx(F,{label:"Namespace",value:t??""}),n.jsx(F,{label:"Workflow ID",value:s.workflowId}),n.jsx(F,{label:"Run ID",value:s.runId})]}),n.jsx(ie,{className:"mt-3 inline-block text-primary text-sm underline-offset-4 hover:underline",to:ue(s.workflowId),children:"Open run →"})]})}function F({label:e,value:r}){return n.jsxs("div",{className:"flex gap-2",children:[n.jsx("dt",{className:"text-muted-foreground",children:e}),n.jsx("dd",{className:"font-mono text-foreground",children:r})]})}function $e(){const e=f.useId();return{namespace:`${e}-namespace`,workflowType:`${e}-workflow-type`,input:`${e}-input`,routingKey:`${e}-routing-key`,taskQueue:`${e}-task-queue`,displayName:`${e}-display-name`}}export{Ve as S,I as p};