next-workflow-builder 0.7.3 → 0.7.5
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.
- package/CHANGELOG.md +23 -0
- package/dist/{chunk-4BSNRZZU.js → chunk-CI7FTYZR.js} +2 -2
- package/dist/{chunk-5M2LRKT5.js → chunk-CYVALTSI.js} +9 -9
- package/dist/{chunk-HJKTLN6E.js → chunk-WT4BSMUD.js} +1 -1
- package/dist/client/index.d.ts +12 -2
- package/dist/client/index.js +19 -19
- package/dist/{condition-CEH7OSFJ.js → condition-CFAA7UDI.js} +1 -1
- package/dist/{handler-PF3O3IEZ.js → handler-67JKCHM5.js} +1 -1
- package/dist/{loop-E2EVYWUK.js → loop-5LPVY452.js} +1 -1
- package/dist/{merge-XFCABPCI.js → merge-HYBHX22D.js} +1 -1
- package/dist/next/index.js +1 -1
- package/dist/{run-workflow-KBAEB2FV.js → run-workflow-VFZV5YLI.js} +1 -1
- package/dist/{run-workflows-in-sequence-S44K3HKF.js → run-workflows-in-sequence-3APONBOX.js} +1 -1
- package/dist/server/api/index.js +7 -7
- package/dist/server/index.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/{switch-FN4UA62F.js → switch-ZPVREROE.js} +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# next-workflow-builder
|
|
2
2
|
|
|
3
|
+
## 0.7.5
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
- Fix **Clear** and **Delete** buttons on the Workflow Panel doing nothing when clicked — they were setting unused Jotai atoms instead of opening confirmation overlays. Now uses the same `ConfirmOverlay` pattern as the toolbar
|
|
8
|
+
- Fix **Clear Workflow** not persisting — `clearWorkflowAtom` was missing the `autosaveAtom` trigger, so cleared state was never saved to the database
|
|
9
|
+
- Fix **Clear Workflow** removing the Trigger node — now preserves trigger nodes, consistent with delete-node and multi-select delete behavior
|
|
10
|
+
- Fix deleting a workflow failing with a foreign key constraint error when the workflow has execution history — execution logs and executions are now deleted before the workflow itself
|
|
11
|
+
|
|
12
|
+
## 0.7.4
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- Add `canvas` prop to `Layout` for configuring the workflow canvas
|
|
17
|
+
- `canvas.snapToGrid` — enable/disable snap-to-grid alignment (default: `true`)
|
|
18
|
+
- `canvas.edgeStyle` — set edge rendering style: `"smoothstep"` or `"bezier"` (default: `"smoothstep"`)
|
|
19
|
+
- Export `LayoutProps`, `CanvasOptions`, and `EdgeStyle` types from `next-workflow-builder/client`
|
|
20
|
+
|
|
21
|
+
### Improvements
|
|
22
|
+
|
|
23
|
+
- Default canvas to snap-to-grid for more precise node placement
|
|
24
|
+
- Default edge style to smooth step for cleaner, more angular connections
|
|
25
|
+
|
|
3
26
|
## 0.7.3
|
|
4
27
|
|
|
5
28
|
### Features
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as k}from"./chunk-
|
|
1
|
+
import{a as k}from"./chunk-WT4BSMUD.js";import{j as l}from"./chunk-VUDOAZ3W.js";import{a as m,b as w}from"./chunk-IEOZJAW2.js";import{l as d,m as p}from"./chunk-BNX2SV7E.js";import{r as f,t as u}from"./chunk-QRG4O4PE.js";import{k as c,o as g}from"./chunk-5J6TNMJG.js";async function b(e){let r=m();if(r.getUser)return r.getUser(e);let t=await w.api.getSession({headers:e.headers});return t?.user?{id:t.user.id,email:t.user.email??void 0,name:t.user.name??void 0}:null}import{eq as x}from"drizzle-orm";import{readdir as h,readFile as R}from"fs/promises";import{join as y}from"path";var T={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type, Authorization"};function _(e){let t=new URL(e.url).pathname,n="/api/workflow-builder/",s=t.indexOf(n);if(s===-1){let i=t.indexOf("/api/");return i===-1?[]:t.slice(i+5).split("/").filter(Boolean)}return t.slice(s+n.length).split("/").filter(Boolean)}function q(e,r){return new Request(r,{method:e.method,headers:e.headers,body:e.body,duplex:"half"})}async function D(e,r,t,n,s){try{await k({nodes:t,edges:n,triggerInput:s,executionId:e,workflowId:r})}catch(o){console.error("[Workflow Execute] Error during execution:",o),await g.update(c).set({status:"error",error:o instanceof Error?o.message:"Unknown error",completedAt:new Date}).where(x(c.id,e))}}function S(e){let r={updatedAt:new Date};return e.name!==void 0&&(r.name=e.name),e.description!==void 0&&(r.description=e.description),e.nodes!==void 0&&(r.nodes=e.nodes),e.edges!==void 0&&(r.edges=e.edges),e.visibility!==void 0&&(r.visibility=e.visibility),r}function B(e){return e.map(r=>{let t={...r};if(t.data&&typeof t.data=="object"&&t.data!==null){let n={...t.data};if(n.config&&typeof n.config=="object"&&n.config!==null){let{integrationId:s,...o}=n.config;n.config=o}t.data=n}return t})}async function A(e,r=e){let t={},n=await h(e,{withFileTypes:!0});for(let s of n){let o=y(e,s.name);if(s.isDirectory()){let i=await A(o,r);Object.assign(t,i)}else if(s.isFile()){let i=await R(o,"utf-8"),a=o.substring(r.length+1);t[a]=i}}return t}function z(e){let r={},n=`${e.name.replace(d,"").split(p).map((i,a)=>a===0?i.toLowerCase():i.charAt(0).toUpperCase()+i.slice(1).toLowerCase()).join("")||"execute"}Workflow`,s=l(e.name,e.nodes,e.edges,{functionName:n}),o=N(e.name);return r[`workflows/${o}.ts`]=s,r[`app/api/workflows/${o}/route.ts`]=`import { start } from 'workflow/api';
|
|
2
2
|
import { ${n} } from '@/workflows/${o}';
|
|
3
3
|
import { NextResponse } from 'next/server';
|
|
4
4
|
|
|
@@ -38,5 +38,5 @@ export async function POST(request: Request) {
|
|
|
38
38
|
</main>
|
|
39
39
|
);
|
|
40
40
|
}
|
|
41
|
-
`,r}function H(e){let r=e.filter(t=>t.data.type==="action").map(t=>t.data.config?.actionType).filter(Boolean);return
|
|
41
|
+
`,r}function H(e){let r=e.filter(t=>t.data.type==="action").map(t=>t.data.config?.actionType).filter(Boolean);return f(r)}function V(){let e=["# Add your environment variables here"];e.push(""),e.push("# For database integrations"),e.push("DATABASE_URL=your_database_url");let r=u(),t={};for(let n of r){let s=n.name.split("_")[0];t[s]||(t[s]=[]),t[s].push(n)}for(let[n,s]of Object.entries(t)){e.push(`# For ${n.charAt(0)+n.slice(1).toLowerCase()} integration`);for(let o of s)e.push(`${o.name}=your_${o.name.toLowerCase()}`);e.push("")}return e.join(`
|
|
42
42
|
`)}function N(e){return e.toLowerCase().replace(/[^a-z0-9]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}export{b as a,T as b,_ as c,q as d,D as e,S as f,B as g,A as h,z as i,H as j,V as k,N as l};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as l,b as T,c as
|
|
1
|
+
import{a as l,b as T,c as d,d as f,e as I,f as h,g as A,h as b,i as F}from"./chunk-BNX2SV7E.js";import{e as g,i as u,j as S}from"./chunk-QRG4O4PE.js";import{createJiti as P}from"jiti";import{existsSync as y,mkdirSync as w,readdirSync as $,readFileSync as x,statSync as C,writeFileSync as c}from"fs";import{dirname as v,join as E,relative as L}from"path";import p from"typescript";async function O(t){try{return await(await import("prettier")).format(t,{parser:"typescript"})}catch(e){return console.warn(" Warning: Failed to format generated code:",e),t}}var D=new Map;function R(t){let n=`/**
|
|
2
2
|
* Plugins Index (Auto-Generated)
|
|
3
3
|
*
|
|
4
4
|
* This file is automatically generated by scripts/discover-plugins.ts
|
|
@@ -49,7 +49,7 @@ export type {
|
|
|
49
49
|
IntegrationPlugin,
|
|
50
50
|
PluginAction,
|
|
51
51
|
} from "next-workflow-builder/plugins";
|
|
52
|
-
`;c(T,n,"utf-8")}async function N(){let t=v(
|
|
52
|
+
`;c(T,n,"utf-8")}async function N(){let t=v(d);y(t)||w(t,{recursive:!0});let n=[...S(),...b].sort(),i=n.map(o=>` | "${o}"`).join(`
|
|
53
53
|
`),r=`/**
|
|
54
54
|
* Integration Types (Auto-Generated)
|
|
55
55
|
*
|
|
@@ -70,7 +70,7 @@ ${i};
|
|
|
70
70
|
|
|
71
71
|
// Generic config type - plugins define their own keys via formFields[].configKey
|
|
72
72
|
export type IntegrationConfig = Record<string, string | undefined>;
|
|
73
|
-
`;c(
|
|
73
|
+
`;c(d,r,"utf-8"),console.log(`Generated lib/types/integration.ts with ${n.length} type(s)`)}function _(){let t=Array.from(D.entries());if(t.length===0){console.log("No codegen templates generated");return}let e=t.map(([i,{template:r}])=>{let o=r.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${");return` "${i}": \`${o}\`,`}).join(`
|
|
74
74
|
|
|
75
75
|
`),n=`/**
|
|
76
76
|
* Codegen Registry (Auto-Generated)
|
|
@@ -98,7 +98,7 @@ ${e}
|
|
|
98
98
|
export function getAutoGeneratedTemplate(actionId: string): string | undefined {
|
|
99
99
|
return AUTO_GENERATED_TEMPLATES[actionId];
|
|
100
100
|
}
|
|
101
|
-
`;c(A,n,"utf-8"),console.log(`Generated lib/codegen-registry.ts with ${t.length} template(s)`)}async function U(){let t=
|
|
101
|
+
`;c(A,n,"utf-8"),console.log(`Generated lib/codegen-registry.ts with ${t.length} template(s)`)}async function U(){let t=u(),e=[];for(let o of t)for(let s of o.actions){let a=g(o.type,s.slug);e.push({actionId:a,label:s.label,integration:o.type,stepImportPath:s.stepImportPath,stepFunction:s.stepFunction})}let n=e.flatMap(({actionId:o,integration:s,stepImportPath:a,stepFunction:m})=>[` "${o}": {
|
|
102
102
|
importer: () => import("@/plugins/${s}/steps/${a}"),
|
|
103
103
|
stepFunction: "${m}",
|
|
104
104
|
},`]).join(`
|
|
@@ -156,7 +156,7 @@ export function getStepImporter(actionType: string): StepImporter | undefined {
|
|
|
156
156
|
export function getActionLabel(actionType: string): string | undefined {
|
|
157
157
|
return ACTION_LABELS[actionType];
|
|
158
158
|
}
|
|
159
|
-
`;c(I,r,"utf-8"),console.log(`Generated lib/step-registry.ts with ${e.length} step(s)`)}async function M(){let t=
|
|
159
|
+
`;c(I,r,"utf-8"),console.log(`Generated lib/step-registry.ts with ${e.length} step(s)`)}async function M(){let t=u(),e=[];for(let r of t)for(let o of r.actions)o.outputConfig&&o.outputConfig.type!=="component"&&e.push({actionId:g(r.type,o.slug),type:o.outputConfig.type,field:o.outputConfig.field});let n=e.map(({actionId:r,type:o,field:s})=>` "${r}": { type: "${o}", field: "${s}" },`).join(`
|
|
160
160
|
`),i=`/**
|
|
161
161
|
* Output Display Configs (Auto-Generated)
|
|
162
162
|
*
|
|
@@ -188,7 +188,7 @@ ${n}
|
|
|
188
188
|
export function getOutputDisplayConfig(actionType: string): OutputDisplayConfig | undefined {
|
|
189
189
|
return OUTPUT_DISPLAY_CONFIGS[actionType];
|
|
190
190
|
}
|
|
191
|
-
`;c(h,i,"utf-8"),console.log(`Generated lib/output-display-configs.ts with ${e.length} config(s)`)}function j(t,e){return!(t.startsWith("@/")||t.startsWith(".")||e.includes("server-only"))}function W(t,e){if(!(t.name&&t.body))return null;let n=t.parameters.map(o=>e.slice(o.pos,o.end).trim()).join(", "),i=t.type?e.slice(t.type.pos,t.type.end).trim():"Promise<unknown>",r=e.slice(t.body.pos,t.body.end).trim();return{name:t.name.text,params:n,returnType:i,body:r}}function Y(){return{hasExportCore:!1,integrationType:null,coreFunction:null,inputTypes:[],imports:[]}}function k(t,e){if(!p.isIdentifier(t.name))return;let n=t.name.text,i=t.initializer;n==="_integrationType"&&i&&p.isStringLiteral(i)&&(e.integrationType=i.text)}function V(t,e){if(t.modifiers?.some(i=>i.kind===p.SyntaxKind.ExportKeyword))for(let i of t.declarationList.declarations)k(i,e)}function B(t){return t.endsWith("Result")||t.endsWith("Credentials")||t.endsWith("CoreInput")}function z(t,e,n){B(t.name.text)&&n.inputTypes.push(e.slice(t.pos,t.end).trim())}function H(t,e,n){let i=t.moduleSpecifier;if(!p.isStringLiteral(i))return;let r=e.slice(t.pos,t.end).trim();j(i.text,r)&&n.imports.push(r)}function K(t,e,n){if(p.isVariableStatement(t)){V(t,n);return}if(p.isTypeAliasDeclaration(t)){z(t,e,n);return}if(p.isImportDeclaration(t)){H(t,e,n);return}p.isFunctionDeclaration(t)&&t.name?.text==="stepHandler"&&(n.hasExportCore=!0,n.coreFunction=W(t,e))}function J(t){let e=Y();if(!y(t))return e;let n=x(t,"utf-8"),i=p.createSourceFile(t,n,p.ScriptTarget.Latest,!0);return p.forEachChild(i,r=>{K(r,n,e)}),e}async function q(t,e){let n=J(t);if(!(n.hasExportCore&&n.coreFunction))return null;let{coreFunction:i,integrationType:r,inputTypes:o,imports:s}=n,a=i.body.trim();a.startsWith("{")&&(a=a.slice(1)),a.endsWith("}")&&(a=a.slice(0,-1)),a=a.trim();let m=i.params.split(",")[0].replace(
|
|
191
|
+
`;c(h,i,"utf-8"),console.log(`Generated lib/output-display-configs.ts with ${e.length} config(s)`)}function j(t,e){return!(t.startsWith("@/")||t.startsWith(".")||e.includes("server-only"))}function W(t,e){if(!(t.name&&t.body))return null;let n=t.parameters.map(o=>e.slice(o.pos,o.end).trim()).join(", "),i=t.type?e.slice(t.type.pos,t.type.end).trim():"Promise<unknown>",r=e.slice(t.body.pos,t.body.end).trim();return{name:t.name.text,params:n,returnType:i,body:r}}function Y(){return{hasExportCore:!1,integrationType:null,coreFunction:null,inputTypes:[],imports:[]}}function k(t,e){if(!p.isIdentifier(t.name))return;let n=t.name.text,i=t.initializer;n==="_integrationType"&&i&&p.isStringLiteral(i)&&(e.integrationType=i.text)}function V(t,e){if(t.modifiers?.some(i=>i.kind===p.SyntaxKind.ExportKeyword))for(let i of t.declarationList.declarations)k(i,e)}function B(t){return t.endsWith("Result")||t.endsWith("Credentials")||t.endsWith("CoreInput")}function z(t,e,n){B(t.name.text)&&n.inputTypes.push(e.slice(t.pos,t.end).trim())}function H(t,e,n){let i=t.moduleSpecifier;if(!p.isStringLiteral(i))return;let r=e.slice(t.pos,t.end).trim();j(i.text,r)&&n.imports.push(r)}function K(t,e,n){if(p.isVariableStatement(t)){V(t,n);return}if(p.isTypeAliasDeclaration(t)){z(t,e,n);return}if(p.isImportDeclaration(t)){H(t,e,n);return}p.isFunctionDeclaration(t)&&t.name?.text==="stepHandler"&&(n.hasExportCore=!0,n.coreFunction=W(t,e))}function J(t){let e=Y();if(!y(t))return e;let n=x(t,"utf-8"),i=p.createSourceFile(t,n,p.ScriptTarget.Latest,!0);return p.forEachChild(i,r=>{K(r,n,e)}),e}async function q(t,e){let n=J(t);if(!(n.hasExportCore&&n.coreFunction))return null;let{coreFunction:i,integrationType:r,inputTypes:o,imports:s}=n,a=i.body.trim();a.startsWith("{")&&(a=a.slice(1)),a.endsWith("}")&&(a=a.slice(0,-1)),a=a.trim();let m=i.params.split(",")[0].replace(F,"").split(":")[1]?.trim()||"unknown",G=`${s.join(`
|
|
192
192
|
`)}
|
|
193
193
|
import { fetchCredentials } from './lib/credential-helper';
|
|
194
194
|
|
|
@@ -205,14 +205,14 @@ export async function ${e}(input: ${m}): ${i.returnType} {
|
|
|
205
205
|
"use step";
|
|
206
206
|
const credentials = await fetchCredentials("${r||"unknown"}");
|
|
207
207
|
${a}
|
|
208
|
-
}`;return await O(G)}async function Q(){let t=
|
|
209
|
-
# Auto-generated by discover-plugins`,n=[
|
|
208
|
+
}`;return await O(G)}async function Q(){let t=u();for(let e of t)for(let n of e.actions){let i=E(l,e.type,"steps",`${n.stepImportPath}.ts`),r=await q(i,n.stepFunction);if(r){let o=g(e.type,n.slug);D.set(o,{template:r,integrationType:e.type}),console.log(` Generated codegen template for ${o}`)}}}function X(){let t=`
|
|
209
|
+
# Auto-generated by discover-plugins`,n=[d,A,I,h,T].map(s=>L(process.cwd(),s)),i="";y(f)&&(i=x(f,"utf-8"));let r=new Set(i.split(`
|
|
210
210
|
`).map(s=>s.trim())),o=n.filter(s=>!r.has(s));if(o.length>0){let s="";i.length>0&&!i.endsWith(`
|
|
211
211
|
`)&&(s+=`
|
|
212
212
|
`),i.includes(t)||(s+=`${t}
|
|
213
213
|
`),s+=o.join(`
|
|
214
214
|
`)+`
|
|
215
|
-
`,c(
|
|
215
|
+
`,c(f,i+s,"utf-8"),console.log(`Updated .gitignore with ${o.length} new file(s).`)}}async function rt(){console.log("Discovering plugins..."),y(l)||(w(l,{recursive:!0}),console.log("Created plugins/ directory"));let e=$(l).filter(n=>{if(n.startsWith("_")||n.startsWith(".")||n==="index.ts"||n==="registry.ts")return!1;let i=E(l,n);try{return C(i).isDirectory()}catch{return!1}}).sort();if(e.length===0)console.log("No plugins found in plugins/ directory");else{console.log(`Found ${e.length} plugin(s):`);for(let n of e)console.log(` - ${n}`)}if(X(),console.log("Generating plugins/index.ts..."),R(e),e.length>0){console.log(`Registering plugins...
|
|
216
216
|
`);let n=P(import.meta.url,{jsx:!0});for(let i of e)try{await n.import(E(l,i)),console.log(` Registered: ${i}`)}catch(r){console.warn(` Warning: Failed to import plugin ${i}:`,r)}}console.log("Generating lib/types/integration.ts..."),await N(),console.log("Generating lib/step-registry.ts..."),await U(),console.log("Generating lib/output-display-configs.ts..."),await M(),console.log(`
|
|
217
217
|
Processing step files for codegen templates...`),await Q(),console.log("Generating lib/codegen-registry.ts..."),_(),console.log(`Done! Plugin registry updated.
|
|
218
218
|
`)}export{rt as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as L}from"./chunk-3YVRTDK2.js";import{b as A}from"./chunk-6UXAINJQ.js";import{k as _,o as v,p as q,q as z}from"./chunk-5J6TNMJG.js";import{eq as Q}from"drizzle-orm";import"server-only";function J(n){return{success:!0,data:n.triggerData}}async function D(n){"use step";return n._workflowComplete?(await q(n._workflowComplete),{success:!0,data:{}}):z(n,()=>Promise.resolve(J(n)))}D.maxRetries=0;var M={"Database Query":{importer:()=>import("./database-query-OHFQUPLV.js"),stepFunction:"databaseQueryStep"},"HTTP Request":{importer:()=>import("./http-request-EHJHOTNA.js"),stepFunction:"httpRequestStep"},Condition:{importer:()=>import("./condition-
|
|
1
|
+
import{c as L}from"./chunk-3YVRTDK2.js";import{b as A}from"./chunk-6UXAINJQ.js";import{k as _,o as v,p as q,q as z}from"./chunk-5J6TNMJG.js";import{eq as Q}from"drizzle-orm";import"server-only";function J(n){return{success:!0,data:n.triggerData}}async function D(n){"use step";return n._workflowComplete?(await q(n._workflowComplete),{success:!0,data:{}}):z(n,()=>Promise.resolve(J(n)))}D.maxRetries=0;var M={"Database Query":{importer:()=>import("./database-query-OHFQUPLV.js"),stepFunction:"databaseQueryStep"},"HTTP Request":{importer:()=>import("./http-request-EHJHOTNA.js"),stepFunction:"httpRequestStep"},Condition:{importer:()=>import("./condition-CFAA7UDI.js"),stepFunction:"conditionStep"},Loop:{importer:()=>import("./loop-5LPVY452.js"),stepFunction:"loopStep"},Switch:{importer:()=>import("./switch-ZPVREROE.js"),stepFunction:"switchStep"},Merge:{importer:()=>import("./merge-HYBHX22D.js"),stepFunction:"mergeStep"},"Run Workflow":{importer:()=>import("./run-workflow-VFZV5YLI.js"),stepFunction:"runWorkflowStep"},"Run Workflows in Sequence":{importer:()=>import("./run-workflows-in-sequence-3APONBOX.js"),stepFunction:"runWorkflowsInSequenceStep"}};function $(n,w){if(n===void 0||n==="")return;let p=/\{\{@([^:]+):([^}]+)\}\}/g,d=[...n.matchAll(p)];if(d.length===0)return n;function s(y,o){let a=y.replace(/[^a-zA-Z0-9]/g,"_"),i=w[a];if(!i)return;let f=o.indexOf(".");if(f===-1)return i.data;if(i.data===null||i.data===void 0)return;let k=o.substring(f+1).split("."),c=i.data,N=k[0];c&&typeof c=="object"&&"success"in c&&"data"in c&&N!=="success"&&N!=="data"&&N!=="error"&&!(N in c)&&(c=c.data);for(let C of k)if(c&&typeof c=="object")c=c[C];else return;return c}return d.length===1&&d[0][0]===n?s(d[0][1],d[0][2]):n.replace(p,(y,o,a)=>{let i=s(o,a);return i==null?"":typeof i=="object"?JSON.stringify(i):String(i)})}function H(n,w){let p=n.dataType||"string",d=n.operator,s=n.leftValue,y=n.rightValue,o=$(s,w),a=$(y,w);return console.log("[Condition] Evaluating:",{dataType:p,operator:d,leftResolved:o,rightResolved:a}),{result:L(p,d,o,a),resolvedValues:{leftValue:o,rightValue:a}}}async function B(n){let{actionType:w,config:p,outputs:d,context:s}=n,y={...p,_context:s};if(w==="Condition"){let f=M.Condition,x=await f.importer(),{result:k,resolvedValues:c}=H(p,d);return console.log("[Condition] Final result:",k),await x[f.stepFunction]({condition:k,dataType:p.dataType,operator:p.operator,leftValue:c.leftValue,rightValue:c.rightValue,_context:s})}let o=M[w];if(o){let x=(await o.importer())[o.stepFunction];return await x(y)}let{getStepImporter:a}=await import("virtual:workflow-builder-step-registry"),i=a(w);if(i){let x=(await i.importer())[i.stepFunction];return x?await x(y):{success:!1,error:`Step function "${i.stepFunction}" not found in module for action "${w}". Check that the plugin exports the correct function name.`}}return{success:!1,error:`Unknown action type: "${w}". This action is not registered in the plugin system. Available system actions: ${Object.keys(M).join(", ")}.`}}function U(n,w){let p={};for(let[d,s]of Object.entries(n))if(typeof s=="string"){let y=s,o=/\{\{@([^:]+):([^}]+)\}\}/g;y=y.replace(o,(a,i,f)=>{let x=i.replace(/[^a-zA-Z0-9]/g,"_"),k=w[x];if(!k)return a;let c=f.indexOf(".");if(c===-1){let e=k.data;return e==null?"":typeof e=="object"?JSON.stringify(e):String(e)}if(k.data===null||k.data===void 0)return"";let C=f.substring(c+1).split("."),l=k.data,b=C[0];l&&typeof l=="object"&&"success"in l&&"data"in l&&b!=="success"&&b!=="data"&&b!=="error"&&!(b in l)&&(l=l.data);for(let e of C)if(l&&typeof l=="object")l=l[e];else return"";return l==null?"":typeof l=="object"?JSON.stringify(l):String(l)}),p[d]=y}else p[d]=s;return p}async function se(n){"use workflow";console.log("[Workflow Executor] Starting workflow execution");let{nodes:w,edges:p,triggerInput:d={},executionId:s,workflowId:y}=n;console.log("[Workflow Executor] Input:",{nodeCount:w.length,edgeCount:p.length,hasExecutionId:!!s,workflowId:y||"none"});let o={},a={},i=new Map(w.map(e=>[e.id,e])),f=new Map,x=new Map;for(let e of p){let u=f.get(e.source)||[];u.push(e.target),f.set(e.source,u);let t=x.get(e.target)||[];t.push(e.source),x.set(e.target,t)}let k=new Set(p.map(e=>e.target)),c=w.filter(e=>e.data.type==="trigger"&&!k.has(e.id));console.log("[Workflow Executor] Found",c.length,"trigger nodes");let{getActionLabel:N}=await import("virtual:workflow-builder-step-registry");function C(e){if(e.data.label)return e.data.label;if(e.data.type==="action"){let u=e.data.config?.actionType;if(u){let t=N(u);if(t)return t}return"Action"}return e.data.type==="trigger"?e.data.config?.triggerType||"Trigger":e.data.type}async function l(){return s?(await v.query.workflowExecutions.findFirst({where:Q(_.id,s),columns:{status:!0}}))?.status==="cancelled":!1}async function b(e,u=new Set){if(console.log("[Workflow Executor] Executing node:",e),await l()){console.log("[Workflow Executor] Execution cancelled, stopping");return}if(u.has(e)){console.log("[Workflow Executor] Node already visited, skipping");return}u.add(e);let t=i.get(e);if(!t){console.log("[Workflow Executor] Node not found:",e);return}if(t.data.enabled===!1){console.log("[Workflow Executor] Skipping disabled node:",e);let r=e.replace(/[^a-zA-Z0-9]/g,"_");o[r]={label:t.data.label||e,data:null};let F=f.get(e)||[];await Promise.all(F.map(h=>b(h,u)));return}try{let r;if(t.data.type==="trigger"){console.log("[Workflow Executor] Executing trigger node");let h=t.data.config||{},W=h.triggerType,g={triggered:!0,timestamp:Date.now()};if(W==="Webhook"&&h.webhookMockRequest&&(!d||Object.keys(d).length===0))try{let T=JSON.parse(h.webhookMockRequest);g={...g,...T},console.log("[Workflow Executor] Using webhook mock request data:",T)}catch(T){console.error("[Workflow Executor] Failed to parse webhook mock request:",T)}else d&&Object.keys(d).length>0&&(g={...g,...d});let m={executionId:s,nodeId:t.id,nodeName:C(t),nodeType:t.data.type},E=await D({triggerData:g,_context:m});r={success:E.success,data:E.data}}else if(t.data.type==="action"){let h=t.data.config||{},W=h.actionType;if(console.log("[Workflow Executor] Executing action node:",W),!W){r={success:!1,error:`Action node "${t.data.label||t.id}" has no action type configured`},a[e]=r;return}let g=U(h,o),m={executionId:s,nodeId:t.id,nodeName:C(t),nodeType:W},E={},T=x.get(e)||[];for(let P of T){let O=P.replace(/[^a-zA-Z0-9]/g,"_"),I=o[O];if(I?.data&&typeof I.data=="object"){let S=I.data;"success"in S&&"data"in S&&S.data&&typeof S.data=="object"&&(S=S.data);for(let[j,Z]of Object.entries(S))j!=="success"&&j!=="error"&&(E[j]=Z)}}console.log("[Workflow Executor] Calling executeActionStep");let R=await B({actionType:W,config:{...E,...g},outputs:o,context:m});if(console.log("[Workflow Executor] Step result received:",{hasResult:!!R,resultType:typeof R}),R&&typeof R=="object"&&"success"in R&&R.success===!1){let P=R,O=typeof P.error=="string"?P.error:P.error?.message||`Step "${W}" in node "${t.data.label||t.id}" failed without a specific error message.`;console.error(`[Workflow Executor] Step "${W}" failed:`,O),r={success:!1,error:O}}else r={success:!0,data:R}}else console.log("[Workflow Executor] Unknown node type:",t.data.type),r={success:!1,error:`Unknown node type "${t.data.type}" in node "${t.data.label||t.id}". Expected "trigger" or "action".`};a[e]=r;let F=e.replace(/[^a-zA-Z0-9]/g,"_");if(o[F]={label:t.data.label||e,data:r.data},console.log("[Workflow Executor] Node execution completed:",{nodeId:e,success:r.success}),r.success){let h=t.data.type==="action"&&t.data.config?.actionType==="Condition",W=t.data.type==="action"&&t.data.config?.actionType==="Loop";if(h){let g=r.data?.condition;if(console.log("[Workflow Executor] Condition node result:",g),g===!0){let m=f.get(e)||[];console.log("[Workflow Executor] Condition is true, executing",m.length,"next nodes in parallel"),await Promise.all(m.map(E=>b(E,u)))}else console.log("[Workflow Executor] Condition is false, skipping next nodes")}else if(W){let g=f.get(e)||[],m=r.data;if(m&&g.length>0){let E=new Set(u),T=0;for(;;){console.log("[Workflow Executor] Loop iteration",T,"- batchIndex:",m.currentBatchIndex,"hasMore:",m.hasMore);let R=new Set(E);if(await Promise.all(g.map(j=>b(j,R))),!m.hasMore)break;if(await l()){console.log("[Workflow Executor] Loop cancelled between iterations");break}let V=m.currentBatchIndex+1,P=t.data.config||{},O=U(P,o),I={executionId:s,nodeId:t.id,nodeName:C(t),nodeType:"Loop"},S=await B({actionType:"Loop",config:{...O,currentBatchIndex:V},outputs:o,context:I});o[F]={label:t.data.label||e,data:S},a[e]={success:!0,data:S},m=S,T++}}else g.length>0&&await Promise.all(g.map(E=>b(E,u)))}else{let g=f.get(e)||[];console.log("[Workflow Executor] Executing",g.length,"next nodes in parallel"),await Promise.all(g.map(m=>b(m,u)))}}}catch(r){console.error("[Workflow Executor] Error executing node:",e,r);let h={success:!1,error:await A(r)};a[e]=h}}try{console.log("[Workflow Executor] Starting execution from trigger nodes");let e=Date.now();await Promise.all(c.map(r=>b(r.id)));let u=Object.values(a).every(r=>r.success),t=Date.now()-e;if(console.log("[Workflow Executor] Workflow execution completed:",{success:u,resultCount:Object.keys(a).length,duration:t}),s&&!await l())try{await D({triggerData:{},_workflowComplete:{executionId:s,status:u?"success":"error",output:Object.values(a).at(-1)?.data,error:Object.values(a).find(r=>!r.success)?.error,startTime:e}}),console.log("[Workflow Executor] Updated execution record")}catch(r){console.error("[Workflow Executor] Failed to update execution record:",r)}return{success:u,results:a,outputs:o}}catch(e){console.error("[Workflow Executor] Fatal error during workflow execution:",e);let u=await A(e);if(s)try{await D({triggerData:{},_workflowComplete:{executionId:s,status:"error",error:u,startTime:Date.now()}})}catch(t){console.error("[Workflow Executor] Failed to log error:",t)}return{success:!1,results:a,outputs:o,error:u}}}export{se as a};
|
package/dist/client/index.d.ts
CHANGED
|
@@ -8,7 +8,17 @@ type Props = {
|
|
|
8
8
|
};
|
|
9
9
|
declare const WorkflowEditor: ({ workflowId }: Props) => react_jsx_runtime.JSX.Element;
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
type EdgeStyle = "smoothstep" | "bezier";
|
|
12
|
+
type CanvasOptions = {
|
|
13
|
+
snapToGrid?: boolean;
|
|
14
|
+
edgeStyle?: EdgeStyle;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type LayoutProps = Omit<AuthUIProviderProps, "authClient"> & {
|
|
18
|
+
/** Canvas configuration options */
|
|
19
|
+
canvas?: CanvasOptions;
|
|
20
|
+
};
|
|
21
|
+
declare const Layout: (props: LayoutProps) => react_jsx_runtime.JSX.Element;
|
|
12
22
|
|
|
13
23
|
/**
|
|
14
24
|
* AI Gateway Managed Keys Configuration
|
|
@@ -29,4 +39,4 @@ declare function isAiGatewayManagedKeysEnabled(): boolean;
|
|
|
29
39
|
*/
|
|
30
40
|
declare function isAiGatewayManagedKeysEnabledClient(): boolean;
|
|
31
41
|
|
|
32
|
-
export { Layout, WorkflowEditor, WorkflowPage, isAiGatewayManagedKeysEnabled, isAiGatewayManagedKeysEnabledClient };
|
|
42
|
+
export { type CanvasOptions, type EdgeStyle, Layout, type LayoutProps, WorkflowEditor, WorkflowPage, isAiGatewayManagedKeysEnabled, isAiGatewayManagedKeysEnabledClient };
|