@reopt-ai/opt-workflow 0.0.0-stage → 0.1.0
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 +13 -0
- package/LICENSE +21 -0
- package/README.md +213 -2
- package/dist/ai-stream-APc3uCiQ.js +389 -0
- package/dist/ai-stream-B_lk9_Rf.cjs +628 -0
- package/dist/branch-resolver-BDi6Wu6m.js +589 -0
- package/dist/branch-resolver-D_wM183Q.cjs +714 -0
- package/dist/core-CtqBb-6v.d.cts +919 -0
- package/dist/core-z3nXmUBj.d.ts +919 -0
- package/dist/core.cjs +301 -0
- package/dist/core.d.cts +5 -0
- package/dist/core.d.ts +5 -0
- package/dist/core.js +184 -0
- package/dist/define-template-Bmn96lF_.cjs +74 -0
- package/dist/define-template-BvGNB5Tv.js +69 -0
- package/dist/end-node-ids-D6WBaCLm.cjs +109 -0
- package/dist/end-node-ids-p85jFEcP.js +86 -0
- package/dist/execution-context-DVeybULC.d.cts +258 -0
- package/dist/execution-context-YFTRCj0y.d.ts +258 -0
- package/dist/grid-workflow-dto-C86EArJP.d.cts +300 -0
- package/dist/grid-workflow-dto-C86EArJP.d.ts +300 -0
- package/dist/index.cjs +11873 -0
- package/dist/index.d.cts +794 -0
- package/dist/index.d.ts +794 -0
- package/dist/index.js +11828 -0
- package/dist/mock.cjs +7295 -0
- package/dist/mock.d.cts +88 -0
- package/dist/mock.d.ts +88 -0
- package/dist/mock.js +7287 -0
- package/dist/node-definitions-C-GMfjMm.js +797 -0
- package/dist/node-definitions-pS1Zp1dK.cjs +940 -0
- package/dist/nodes-D_a8ZkRp.d.cts +50 -0
- package/dist/nodes-myp8R2zo.d.ts +50 -0
- package/dist/nodes.cjs +36 -0
- package/dist/nodes.d.cts +3 -0
- package/dist/nodes.d.ts +3 -0
- package/dist/nodes.js +4 -0
- package/dist/shadcn-bridge.css +72 -0
- package/dist/simulate.cjs +6 -0
- package/dist/simulate.d.cts +111 -0
- package/dist/simulate.d.ts +111 -0
- package/dist/simulate.js +1 -0
- package/dist/step-type-for-node-Blf5DKrp.js +228 -0
- package/dist/step-type-for-node-D9sdHfWA.cjs +281 -0
- package/dist/styles.css +4 -0
- package/dist/test-executor-C2AvI73G.cjs +342 -0
- package/dist/test-executor-DpT3qXIT.js +313 -0
- package/dist/types-Bj0VWFny.d.cts +126 -0
- package/dist/types-C5744w6f.d.cts +184 -0
- package/dist/types-DQcmIuAl.d.ts +126 -0
- package/dist/types-dVHX2CyI.d.ts +184 -0
- package/dist/workflow-preview-B0kul6f-.js +1742 -0
- package/dist/workflow-preview-CZzXKXqK.cjs +2065 -0
- package/package.json +119 -4
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
const require_branch_resolver = require("./branch-resolver-D_wM183Q.cjs");
|
|
2
|
+
const require_end_node_ids = require("./end-node-ids-D6WBaCLm.cjs");
|
|
3
|
+
// src/lib/id.ts
|
|
4
|
+
/**
|
|
5
|
+
* 스텝·연결·실행에 붙이는 짧은 고유 id. 저장 형식은 문자열이면 되고(기존 문서는 nanoid를 쓴다),
|
|
6
|
+
* 충돌만 없으면 된다.
|
|
7
|
+
*/
|
|
8
|
+
function createId(size = 21) {
|
|
9
|
+
const alphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
10
|
+
const bytes = new Uint8Array(size);
|
|
11
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
12
|
+
let id = "";
|
|
13
|
+
for (let i = 0; i < size; i++) id += alphabet[bytes[i] & 63];
|
|
14
|
+
return id;
|
|
15
|
+
}
|
|
16
|
+
// src/engine/test-executor.ts
|
|
17
|
+
/**
|
|
18
|
+
* 테스트 모드 실행기
|
|
19
|
+
* 워크플로우를 실제 실행 없이 검증하고 시뮬레이션합니다.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* 테스트 실행기 클래스
|
|
23
|
+
*/
|
|
24
|
+
var TestExecutor = class {
|
|
25
|
+
constructor(definition, context, config = {}) {
|
|
26
|
+
this.stepResults = [];
|
|
27
|
+
this.executionPath = [];
|
|
28
|
+
this.definition = definition;
|
|
29
|
+
this.context = require_end_node_ids._objectSpread2(require_end_node_ids._objectSpread2({}, context), {}, {
|
|
30
|
+
previousResults: new Map(context.previousResults),
|
|
31
|
+
variables: require_end_node_ids._objectSpread2(require_end_node_ids._objectSpread2({}, context.variables), config.mockVariables)
|
|
32
|
+
});
|
|
33
|
+
this.config = config;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 테스트 실행
|
|
37
|
+
*/
|
|
38
|
+
async execute() {
|
|
39
|
+
const startTime = Date.now();
|
|
40
|
+
const runId = `test-${createId()}`;
|
|
41
|
+
const validationErrors = [];
|
|
42
|
+
const validationWarnings = [];
|
|
43
|
+
const validation = this.validateDefinition();
|
|
44
|
+
validationErrors.push(...validation.errors);
|
|
45
|
+
validationWarnings.push(...validation.warnings);
|
|
46
|
+
if (validationErrors.length > 0) return {
|
|
47
|
+
success: false,
|
|
48
|
+
runId,
|
|
49
|
+
mode: "validation",
|
|
50
|
+
executionPath: [],
|
|
51
|
+
stepResults: [],
|
|
52
|
+
validationErrors,
|
|
53
|
+
validationWarnings,
|
|
54
|
+
coverage: {
|
|
55
|
+
totalSteps: this.definition.steps.length,
|
|
56
|
+
executedSteps: 0,
|
|
57
|
+
skippedSteps: this.definition.steps.length,
|
|
58
|
+
coveragePercent: 0
|
|
59
|
+
},
|
|
60
|
+
duration: Date.now() - startTime,
|
|
61
|
+
finalVariables: this.context.variables
|
|
62
|
+
};
|
|
63
|
+
await this.simulateExecution();
|
|
64
|
+
const executedSteps = this.stepResults.filter((r) => r.executed).length;
|
|
65
|
+
const skippedSteps = this.stepResults.filter((r) => r.skipped).length;
|
|
66
|
+
return {
|
|
67
|
+
success: !this.stepResults.some((result) => result.forcedFail),
|
|
68
|
+
runId,
|
|
69
|
+
mode: "test",
|
|
70
|
+
executionPath: this.executionPath,
|
|
71
|
+
stepResults: this.stepResults,
|
|
72
|
+
validationErrors,
|
|
73
|
+
validationWarnings,
|
|
74
|
+
coverage: {
|
|
75
|
+
totalSteps: this.definition.steps.length,
|
|
76
|
+
executedSteps,
|
|
77
|
+
skippedSteps,
|
|
78
|
+
coveragePercent: Math.round(executedSteps / this.definition.steps.length * 100)
|
|
79
|
+
},
|
|
80
|
+
duration: Date.now() - startTime,
|
|
81
|
+
finalVariables: this.context.variables
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 정의 검증
|
|
86
|
+
*/
|
|
87
|
+
validateDefinition() {
|
|
88
|
+
const errors = [];
|
|
89
|
+
const warnings = [];
|
|
90
|
+
const triggerSteps = this.definition.steps.filter((s) => s.type === "trigger");
|
|
91
|
+
if (triggerSteps.length === 0) errors.push("트리거 스텝이 없습니다");
|
|
92
|
+
if (triggerSteps.length > 1) errors.push("트리거 스텝은 하나만 있어야 합니다");
|
|
93
|
+
if (this.definition.steps.filter((s) => s.type === "end").length === 0) warnings.push("종료 스텝이 없습니다. 마지막 스텝에서 종료됩니다.");
|
|
94
|
+
const connectedStepIds = /* @__PURE__ */ new Set();
|
|
95
|
+
for (const conn of this.definition.connections) {
|
|
96
|
+
connectedStepIds.add(conn.fromStepId);
|
|
97
|
+
connectedStepIds.add(conn.toStepId);
|
|
98
|
+
}
|
|
99
|
+
const orphanedSteps = this.definition.steps.filter((s) => s.type !== "trigger" && !connectedStepIds.has(s.id));
|
|
100
|
+
if (orphanedSteps.length > 0) warnings.push(require_branch_resolver.msgf("연결되지 않은 스텝이 있습니다: {labels}", { labels: orphanedSteps.map((s) => s.label).join(", ") }));
|
|
101
|
+
if (this.hasCycle()) errors.push("순환 참조가 감지되었습니다");
|
|
102
|
+
for (const step of this.definition.steps) {
|
|
103
|
+
const stepErrors = this.validateStep(step);
|
|
104
|
+
errors.push(...stepErrors.map((e) => `[${step.label}] ${e}`));
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
errors,
|
|
108
|
+
warnings
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 개별 스텝 검증
|
|
113
|
+
*/
|
|
114
|
+
validateStep(step) {
|
|
115
|
+
const errors = [];
|
|
116
|
+
if (!step.id) errors.push("스텝 ID가 없습니다");
|
|
117
|
+
if (!step.label) errors.push("스텝 레이블이 없습니다");
|
|
118
|
+
switch (step.type) {
|
|
119
|
+
case "condition":
|
|
120
|
+
errors.push(...require_branch_resolver.validateConditionConfig(step.config).errors);
|
|
121
|
+
break;
|
|
122
|
+
case "action": if (!step.nodeDefinitionId && !step.nodeDefinition) errors.push("액션 타입이 지정되지 않았습니다");
|
|
123
|
+
}
|
|
124
|
+
return errors;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 순환 참조 확인
|
|
128
|
+
*/
|
|
129
|
+
hasCycle() {
|
|
130
|
+
const visited = /* @__PURE__ */ new Set();
|
|
131
|
+
const recursionStack = /* @__PURE__ */ new Set();
|
|
132
|
+
const adjacencyList = /* @__PURE__ */ new Map();
|
|
133
|
+
for (const conn of this.definition.connections) {
|
|
134
|
+
var _adjacencyList$get;
|
|
135
|
+
const existing = (_adjacencyList$get = adjacencyList.get(conn.fromStepId)) !== null && _adjacencyList$get !== void 0 ? _adjacencyList$get : [];
|
|
136
|
+
adjacencyList.set(conn.fromStepId, [...existing, conn.toStepId]);
|
|
137
|
+
}
|
|
138
|
+
const dfs = (nodeId) => {
|
|
139
|
+
var _adjacencyList$get2;
|
|
140
|
+
visited.add(nodeId);
|
|
141
|
+
recursionStack.add(nodeId);
|
|
142
|
+
const neighbors = (_adjacencyList$get2 = adjacencyList.get(nodeId)) !== null && _adjacencyList$get2 !== void 0 ? _adjacencyList$get2 : [];
|
|
143
|
+
for (const neighbor of neighbors) if (!visited.has(neighbor)) {
|
|
144
|
+
if (dfs(neighbor)) return true;
|
|
145
|
+
} else if (recursionStack.has(neighbor)) return true;
|
|
146
|
+
recursionStack.delete(nodeId);
|
|
147
|
+
return false;
|
|
148
|
+
};
|
|
149
|
+
for (const step of this.definition.steps) if (!visited.has(step.id) && dfs(step.id)) return true;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 실행 시뮬레이션
|
|
154
|
+
*/
|
|
155
|
+
async simulateExecution() {
|
|
156
|
+
const triggerStep = this.definition.steps.find((s) => s.type === "trigger");
|
|
157
|
+
if (!triggerStep) return;
|
|
158
|
+
const visited = /* @__PURE__ */ new Set();
|
|
159
|
+
await this.simulateStep(triggerStep, visited);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 개별 스텝 시뮬레이션
|
|
163
|
+
*/
|
|
164
|
+
async simulateStep(step, visited) {
|
|
165
|
+
var _this$config$forceFai, _this$config$stepDela, _this$config$stepDela2, _this$config$mockResp, _this$config$mockResp2;
|
|
166
|
+
if (visited.has(step.id)) return;
|
|
167
|
+
visited.add(step.id);
|
|
168
|
+
const startTime = Date.now();
|
|
169
|
+
const notes = [];
|
|
170
|
+
let conditionResult;
|
|
171
|
+
const input = structuredClone(step.type === "trigger" ? this.context.params : require_branch_resolver.resolveObjectVariables(step.config, this.context));
|
|
172
|
+
const unresolvedVariables = step.type === "trigger" ? [] : require_branch_resolver.collectUnresolvedVariables(step.config, this.context);
|
|
173
|
+
let forcedFail = false;
|
|
174
|
+
if ((_this$config$forceFai = this.config.forceFailSteps) === null || _this$config$forceFai === void 0 ? void 0 : _this$config$forceFai.includes(step.id)) {
|
|
175
|
+
forcedFail = true;
|
|
176
|
+
notes.push("강제 실패 설정됨");
|
|
177
|
+
}
|
|
178
|
+
const delay = (_this$config$stepDela = (_this$config$stepDela2 = this.config.stepDelays) === null || _this$config$stepDela2 === void 0 ? void 0 : _this$config$stepDela2[step.id]) !== null && _this$config$stepDela !== void 0 ? _this$config$stepDela : 10;
|
|
179
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
180
|
+
if (step.type === "condition") {
|
|
181
|
+
var _this$config$conditio, _this$config$conditio2;
|
|
182
|
+
conditionResult = (_this$config$conditio = (_this$config$conditio2 = this.config.conditionOverrides) === null || _this$config$conditio2 === void 0 ? void 0 : _this$config$conditio2[step.id]) !== null && _this$config$conditio !== void 0 ? _this$config$conditio : await require_branch_resolver.evaluateCondition(step.config, this.context);
|
|
183
|
+
notes.push(require_branch_resolver.msgf("조건 결과: {result}", { result: typeof conditionResult === "boolean" ? conditionResult ? "참" : "거짓" : String(conditionResult) }, { translate: ["result"] }));
|
|
184
|
+
}
|
|
185
|
+
const mockOutput = Object.hasOwn((_this$config$mockResp = this.config.mockResponses) !== null && _this$config$mockResp !== void 0 ? _this$config$mockResp : {}, step.id) ? (_this$config$mockResp2 = this.config.mockResponses) === null || _this$config$mockResp2 === void 0 ? void 0 : _this$config$mockResp2[step.id] : step.type === "trigger" ? this.context.params : conditionResult;
|
|
186
|
+
if (mockOutput !== void 0) {
|
|
187
|
+
var _this$config$mockResp3;
|
|
188
|
+
if (Object.hasOwn((_this$config$mockResp3 = this.config.mockResponses) !== null && _this$config$mockResp3 !== void 0 ? _this$config$mockResp3 : {}, step.id)) notes.push("모의 출력 적용됨");
|
|
189
|
+
else if (step.type === "trigger") notes.push("시작 입력을 출력으로 전달했습니다.");
|
|
190
|
+
this.context.variables[`${step.id}_output`] = mockOutput;
|
|
191
|
+
}
|
|
192
|
+
this.context.previousResults.set(step.id, {
|
|
193
|
+
stepId: step.id,
|
|
194
|
+
success: !forcedFail,
|
|
195
|
+
output: mockOutput,
|
|
196
|
+
executedAt: /* @__PURE__ */ new Date(),
|
|
197
|
+
duration: Date.now() - startTime
|
|
198
|
+
});
|
|
199
|
+
this.stepResults.push({
|
|
200
|
+
stepId: step.id,
|
|
201
|
+
stepLabel: step.label,
|
|
202
|
+
stepType: step.type,
|
|
203
|
+
executed: true,
|
|
204
|
+
skipped: false,
|
|
205
|
+
forcedFail,
|
|
206
|
+
mockOutput,
|
|
207
|
+
input,
|
|
208
|
+
unresolvedVariables,
|
|
209
|
+
conditionResult,
|
|
210
|
+
duration: Date.now() - startTime,
|
|
211
|
+
notes
|
|
212
|
+
});
|
|
213
|
+
this.executionPath.push(step.id);
|
|
214
|
+
if (step.nodeDefinitionId === "end-failure") {
|
|
215
|
+
this.stepResults[this.stepResults.length - 1].forcedFail = true;
|
|
216
|
+
notes.push("실패 종료 — 실제 실행이면 런이 여기서 실패로 끝납니다.");
|
|
217
|
+
}
|
|
218
|
+
if (step.type === "end" || forcedFail && !step.continueOnError) return;
|
|
219
|
+
const outgoingConnections = this.definition.connections.filter((c) => c.fromStepId === step.id);
|
|
220
|
+
const chosenStepId = step.type === "condition" ? require_branch_resolver.resolveBranchPath(step, outgoingConnections, conditionResult) : null;
|
|
221
|
+
const followedConnections = step.type === "condition" || step.type === "parallel" ? outgoingConnections : outgoingConnections.slice(0, 1);
|
|
222
|
+
for (const conn of followedConnections) {
|
|
223
|
+
if (step.type === "condition") {
|
|
224
|
+
if (!(conn.toStepId === chosenStepId)) {
|
|
225
|
+
const skippedStep = this.definition.steps.find((s) => s.id === conn.toStepId);
|
|
226
|
+
if (skippedStep && !visited.has(skippedStep.id)) this.stepResults.push({
|
|
227
|
+
stepId: skippedStep.id,
|
|
228
|
+
stepLabel: skippedStep.label,
|
|
229
|
+
stepType: skippedStep.type,
|
|
230
|
+
executed: false,
|
|
231
|
+
skipped: true,
|
|
232
|
+
forcedFail: false,
|
|
233
|
+
duration: 0,
|
|
234
|
+
notes: ["조건 분기로 인해 건너뜀"]
|
|
235
|
+
});
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const nextStep = this.definition.steps.find((s) => s.id === conn.toStepId);
|
|
240
|
+
if (nextStep) await this.simulateStep(nextStep, visited);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* 테스트 실행 헬퍼 함수
|
|
246
|
+
*/
|
|
247
|
+
async function executeTestMode(definition, context, config = {}) {
|
|
248
|
+
return new TestExecutor(definition, context, config).execute();
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* 검증만 수행
|
|
252
|
+
*/
|
|
253
|
+
function validateWorkflow(definition) {
|
|
254
|
+
const validation = new TestExecutor(definition, {
|
|
255
|
+
runId: "validation",
|
|
256
|
+
workflowId: "validation",
|
|
257
|
+
workspaceId: "validation",
|
|
258
|
+
userId: "validation",
|
|
259
|
+
params: {},
|
|
260
|
+
variables: {},
|
|
261
|
+
previousResults: /* @__PURE__ */ new Map(),
|
|
262
|
+
triggeredBy: "manual",
|
|
263
|
+
emit: async () => {}
|
|
264
|
+
}, {}).validateDefinition();
|
|
265
|
+
return {
|
|
266
|
+
valid: validation.errors.length === 0,
|
|
267
|
+
errors: validation.errors,
|
|
268
|
+
warnings: validation.warnings
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* 실행 경로 분석
|
|
273
|
+
*/
|
|
274
|
+
function analyzeExecutionPaths(definition) {
|
|
275
|
+
const triggerStep = definition.steps.find((s) => s.type === "trigger");
|
|
276
|
+
if (!triggerStep) return {
|
|
277
|
+
paths: [],
|
|
278
|
+
maxDepth: 0,
|
|
279
|
+
branchPoints: []
|
|
280
|
+
};
|
|
281
|
+
const paths = [];
|
|
282
|
+
const branchPoints = /* @__PURE__ */ new Set();
|
|
283
|
+
const adjacencyList = /* @__PURE__ */ new Map();
|
|
284
|
+
for (const conn of definition.connections) {
|
|
285
|
+
var _adjacencyList$get3;
|
|
286
|
+
const existing = (_adjacencyList$get3 = adjacencyList.get(conn.fromStepId)) !== null && _adjacencyList$get3 !== void 0 ? _adjacencyList$get3 : [];
|
|
287
|
+
adjacencyList.set(conn.fromStepId, [...existing, conn]);
|
|
288
|
+
}
|
|
289
|
+
for (const [stepId, connections] of adjacencyList) if (connections.length > 1) branchPoints.add(stepId);
|
|
290
|
+
const findPaths = (stepId, currentPath) => {
|
|
291
|
+
var _adjacencyList$get4;
|
|
292
|
+
if (currentPath.includes(stepId)) return;
|
|
293
|
+
const newPath = [...currentPath, stepId];
|
|
294
|
+
const step = definition.steps.find((s) => s.id === stepId);
|
|
295
|
+
if (!step || step.type === "end") {
|
|
296
|
+
paths.push(newPath);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const outgoing = (_adjacencyList$get4 = adjacencyList.get(stepId)) !== null && _adjacencyList$get4 !== void 0 ? _adjacencyList$get4 : [];
|
|
300
|
+
if (outgoing.length === 0) {
|
|
301
|
+
paths.push(newPath);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
for (const conn of outgoing) findPaths(conn.toStepId, newPath);
|
|
305
|
+
};
|
|
306
|
+
findPaths(triggerStep.id, []);
|
|
307
|
+
return {
|
|
308
|
+
paths,
|
|
309
|
+
maxDepth: Math.max(...paths.map((p) => p.length), 0),
|
|
310
|
+
branchPoints: Array.from(branchPoints)
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
Object.defineProperty(exports, "TestExecutor", {
|
|
314
|
+
enumerable: true,
|
|
315
|
+
get: function() {
|
|
316
|
+
return TestExecutor;
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
Object.defineProperty(exports, "analyzeExecutionPaths", {
|
|
320
|
+
enumerable: true,
|
|
321
|
+
get: function() {
|
|
322
|
+
return analyzeExecutionPaths;
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
Object.defineProperty(exports, "createId", {
|
|
326
|
+
enumerable: true,
|
|
327
|
+
get: function() {
|
|
328
|
+
return createId;
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
Object.defineProperty(exports, "executeTestMode", {
|
|
332
|
+
enumerable: true,
|
|
333
|
+
get: function() {
|
|
334
|
+
return executeTestMode;
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
Object.defineProperty(exports, "validateWorkflow", {
|
|
338
|
+
enumerable: true,
|
|
339
|
+
get: function() {
|
|
340
|
+
return validateWorkflow;
|
|
341
|
+
}
|
|
342
|
+
});
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { a as evaluateCondition, d as collectUnresolvedVariables, m as resolveObjectVariables, r as resolveBranchPath, u as validateConditionConfig, x as msgf } from "./branch-resolver-BDi6Wu6m.js";
|
|
2
|
+
import { r as _objectSpread2 } from "./end-node-ids-p85jFEcP.js";
|
|
3
|
+
// src/lib/id.ts
|
|
4
|
+
/**
|
|
5
|
+
* 스텝·연결·실행에 붙이는 짧은 고유 id. 저장 형식은 문자열이면 되고(기존 문서는 nanoid를 쓴다),
|
|
6
|
+
* 충돌만 없으면 된다.
|
|
7
|
+
*/
|
|
8
|
+
function createId(size = 21) {
|
|
9
|
+
const alphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
10
|
+
const bytes = new Uint8Array(size);
|
|
11
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
12
|
+
let id = "";
|
|
13
|
+
for (let i = 0; i < size; i++) id += alphabet[bytes[i] & 63];
|
|
14
|
+
return id;
|
|
15
|
+
}
|
|
16
|
+
// src/engine/test-executor.ts
|
|
17
|
+
/**
|
|
18
|
+
* 테스트 모드 실행기
|
|
19
|
+
* 워크플로우를 실제 실행 없이 검증하고 시뮬레이션합니다.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* 테스트 실행기 클래스
|
|
23
|
+
*/
|
|
24
|
+
var TestExecutor = class {
|
|
25
|
+
constructor(definition, context, config = {}) {
|
|
26
|
+
this.stepResults = [];
|
|
27
|
+
this.executionPath = [];
|
|
28
|
+
this.definition = definition;
|
|
29
|
+
this.context = _objectSpread2(_objectSpread2({}, context), {}, {
|
|
30
|
+
previousResults: new Map(context.previousResults),
|
|
31
|
+
variables: _objectSpread2(_objectSpread2({}, context.variables), config.mockVariables)
|
|
32
|
+
});
|
|
33
|
+
this.config = config;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 테스트 실행
|
|
37
|
+
*/
|
|
38
|
+
async execute() {
|
|
39
|
+
const startTime = Date.now();
|
|
40
|
+
const runId = `test-${createId()}`;
|
|
41
|
+
const validationErrors = [];
|
|
42
|
+
const validationWarnings = [];
|
|
43
|
+
const validation = this.validateDefinition();
|
|
44
|
+
validationErrors.push(...validation.errors);
|
|
45
|
+
validationWarnings.push(...validation.warnings);
|
|
46
|
+
if (validationErrors.length > 0) return {
|
|
47
|
+
success: false,
|
|
48
|
+
runId,
|
|
49
|
+
mode: "validation",
|
|
50
|
+
executionPath: [],
|
|
51
|
+
stepResults: [],
|
|
52
|
+
validationErrors,
|
|
53
|
+
validationWarnings,
|
|
54
|
+
coverage: {
|
|
55
|
+
totalSteps: this.definition.steps.length,
|
|
56
|
+
executedSteps: 0,
|
|
57
|
+
skippedSteps: this.definition.steps.length,
|
|
58
|
+
coveragePercent: 0
|
|
59
|
+
},
|
|
60
|
+
duration: Date.now() - startTime,
|
|
61
|
+
finalVariables: this.context.variables
|
|
62
|
+
};
|
|
63
|
+
await this.simulateExecution();
|
|
64
|
+
const executedSteps = this.stepResults.filter((r) => r.executed).length;
|
|
65
|
+
const skippedSteps = this.stepResults.filter((r) => r.skipped).length;
|
|
66
|
+
return {
|
|
67
|
+
success: !this.stepResults.some((result) => result.forcedFail),
|
|
68
|
+
runId,
|
|
69
|
+
mode: "test",
|
|
70
|
+
executionPath: this.executionPath,
|
|
71
|
+
stepResults: this.stepResults,
|
|
72
|
+
validationErrors,
|
|
73
|
+
validationWarnings,
|
|
74
|
+
coverage: {
|
|
75
|
+
totalSteps: this.definition.steps.length,
|
|
76
|
+
executedSteps,
|
|
77
|
+
skippedSteps,
|
|
78
|
+
coveragePercent: Math.round(executedSteps / this.definition.steps.length * 100)
|
|
79
|
+
},
|
|
80
|
+
duration: Date.now() - startTime,
|
|
81
|
+
finalVariables: this.context.variables
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 정의 검증
|
|
86
|
+
*/
|
|
87
|
+
validateDefinition() {
|
|
88
|
+
const errors = [];
|
|
89
|
+
const warnings = [];
|
|
90
|
+
const triggerSteps = this.definition.steps.filter((s) => s.type === "trigger");
|
|
91
|
+
if (triggerSteps.length === 0) errors.push("트리거 스텝이 없습니다");
|
|
92
|
+
if (triggerSteps.length > 1) errors.push("트리거 스텝은 하나만 있어야 합니다");
|
|
93
|
+
if (this.definition.steps.filter((s) => s.type === "end").length === 0) warnings.push("종료 스텝이 없습니다. 마지막 스텝에서 종료됩니다.");
|
|
94
|
+
const connectedStepIds = /* @__PURE__ */ new Set();
|
|
95
|
+
for (const conn of this.definition.connections) {
|
|
96
|
+
connectedStepIds.add(conn.fromStepId);
|
|
97
|
+
connectedStepIds.add(conn.toStepId);
|
|
98
|
+
}
|
|
99
|
+
const orphanedSteps = this.definition.steps.filter((s) => s.type !== "trigger" && !connectedStepIds.has(s.id));
|
|
100
|
+
if (orphanedSteps.length > 0) warnings.push(msgf("연결되지 않은 스텝이 있습니다: {labels}", { labels: orphanedSteps.map((s) => s.label).join(", ") }));
|
|
101
|
+
if (this.hasCycle()) errors.push("순환 참조가 감지되었습니다");
|
|
102
|
+
for (const step of this.definition.steps) {
|
|
103
|
+
const stepErrors = this.validateStep(step);
|
|
104
|
+
errors.push(...stepErrors.map((e) => `[${step.label}] ${e}`));
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
errors,
|
|
108
|
+
warnings
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 개별 스텝 검증
|
|
113
|
+
*/
|
|
114
|
+
validateStep(step) {
|
|
115
|
+
const errors = [];
|
|
116
|
+
if (!step.id) errors.push("스텝 ID가 없습니다");
|
|
117
|
+
if (!step.label) errors.push("스텝 레이블이 없습니다");
|
|
118
|
+
switch (step.type) {
|
|
119
|
+
case "condition":
|
|
120
|
+
errors.push(...validateConditionConfig(step.config).errors);
|
|
121
|
+
break;
|
|
122
|
+
case "action": if (!step.nodeDefinitionId && !step.nodeDefinition) errors.push("액션 타입이 지정되지 않았습니다");
|
|
123
|
+
}
|
|
124
|
+
return errors;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 순환 참조 확인
|
|
128
|
+
*/
|
|
129
|
+
hasCycle() {
|
|
130
|
+
const visited = /* @__PURE__ */ new Set();
|
|
131
|
+
const recursionStack = /* @__PURE__ */ new Set();
|
|
132
|
+
const adjacencyList = /* @__PURE__ */ new Map();
|
|
133
|
+
for (const conn of this.definition.connections) {
|
|
134
|
+
var _adjacencyList$get;
|
|
135
|
+
const existing = (_adjacencyList$get = adjacencyList.get(conn.fromStepId)) !== null && _adjacencyList$get !== void 0 ? _adjacencyList$get : [];
|
|
136
|
+
adjacencyList.set(conn.fromStepId, [...existing, conn.toStepId]);
|
|
137
|
+
}
|
|
138
|
+
const dfs = (nodeId) => {
|
|
139
|
+
var _adjacencyList$get2;
|
|
140
|
+
visited.add(nodeId);
|
|
141
|
+
recursionStack.add(nodeId);
|
|
142
|
+
const neighbors = (_adjacencyList$get2 = adjacencyList.get(nodeId)) !== null && _adjacencyList$get2 !== void 0 ? _adjacencyList$get2 : [];
|
|
143
|
+
for (const neighbor of neighbors) if (!visited.has(neighbor)) {
|
|
144
|
+
if (dfs(neighbor)) return true;
|
|
145
|
+
} else if (recursionStack.has(neighbor)) return true;
|
|
146
|
+
recursionStack.delete(nodeId);
|
|
147
|
+
return false;
|
|
148
|
+
};
|
|
149
|
+
for (const step of this.definition.steps) if (!visited.has(step.id) && dfs(step.id)) return true;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 실행 시뮬레이션
|
|
154
|
+
*/
|
|
155
|
+
async simulateExecution() {
|
|
156
|
+
const triggerStep = this.definition.steps.find((s) => s.type === "trigger");
|
|
157
|
+
if (!triggerStep) return;
|
|
158
|
+
const visited = /* @__PURE__ */ new Set();
|
|
159
|
+
await this.simulateStep(triggerStep, visited);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 개별 스텝 시뮬레이션
|
|
163
|
+
*/
|
|
164
|
+
async simulateStep(step, visited) {
|
|
165
|
+
var _this$config$forceFai, _this$config$stepDela, _this$config$stepDela2, _this$config$mockResp, _this$config$mockResp2;
|
|
166
|
+
if (visited.has(step.id)) return;
|
|
167
|
+
visited.add(step.id);
|
|
168
|
+
const startTime = Date.now();
|
|
169
|
+
const notes = [];
|
|
170
|
+
let conditionResult;
|
|
171
|
+
const input = structuredClone(step.type === "trigger" ? this.context.params : resolveObjectVariables(step.config, this.context));
|
|
172
|
+
const unresolvedVariables = step.type === "trigger" ? [] : collectUnresolvedVariables(step.config, this.context);
|
|
173
|
+
let forcedFail = false;
|
|
174
|
+
if ((_this$config$forceFai = this.config.forceFailSteps) === null || _this$config$forceFai === void 0 ? void 0 : _this$config$forceFai.includes(step.id)) {
|
|
175
|
+
forcedFail = true;
|
|
176
|
+
notes.push("강제 실패 설정됨");
|
|
177
|
+
}
|
|
178
|
+
const delay = (_this$config$stepDela = (_this$config$stepDela2 = this.config.stepDelays) === null || _this$config$stepDela2 === void 0 ? void 0 : _this$config$stepDela2[step.id]) !== null && _this$config$stepDela !== void 0 ? _this$config$stepDela : 10;
|
|
179
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
180
|
+
if (step.type === "condition") {
|
|
181
|
+
var _this$config$conditio, _this$config$conditio2;
|
|
182
|
+
conditionResult = (_this$config$conditio = (_this$config$conditio2 = this.config.conditionOverrides) === null || _this$config$conditio2 === void 0 ? void 0 : _this$config$conditio2[step.id]) !== null && _this$config$conditio !== void 0 ? _this$config$conditio : await evaluateCondition(step.config, this.context);
|
|
183
|
+
notes.push(msgf("조건 결과: {result}", { result: typeof conditionResult === "boolean" ? conditionResult ? "참" : "거짓" : String(conditionResult) }, { translate: ["result"] }));
|
|
184
|
+
}
|
|
185
|
+
const mockOutput = Object.hasOwn((_this$config$mockResp = this.config.mockResponses) !== null && _this$config$mockResp !== void 0 ? _this$config$mockResp : {}, step.id) ? (_this$config$mockResp2 = this.config.mockResponses) === null || _this$config$mockResp2 === void 0 ? void 0 : _this$config$mockResp2[step.id] : step.type === "trigger" ? this.context.params : conditionResult;
|
|
186
|
+
if (mockOutput !== void 0) {
|
|
187
|
+
var _this$config$mockResp3;
|
|
188
|
+
if (Object.hasOwn((_this$config$mockResp3 = this.config.mockResponses) !== null && _this$config$mockResp3 !== void 0 ? _this$config$mockResp3 : {}, step.id)) notes.push("모의 출력 적용됨");
|
|
189
|
+
else if (step.type === "trigger") notes.push("시작 입력을 출력으로 전달했습니다.");
|
|
190
|
+
this.context.variables[`${step.id}_output`] = mockOutput;
|
|
191
|
+
}
|
|
192
|
+
this.context.previousResults.set(step.id, {
|
|
193
|
+
stepId: step.id,
|
|
194
|
+
success: !forcedFail,
|
|
195
|
+
output: mockOutput,
|
|
196
|
+
executedAt: /* @__PURE__ */ new Date(),
|
|
197
|
+
duration: Date.now() - startTime
|
|
198
|
+
});
|
|
199
|
+
this.stepResults.push({
|
|
200
|
+
stepId: step.id,
|
|
201
|
+
stepLabel: step.label,
|
|
202
|
+
stepType: step.type,
|
|
203
|
+
executed: true,
|
|
204
|
+
skipped: false,
|
|
205
|
+
forcedFail,
|
|
206
|
+
mockOutput,
|
|
207
|
+
input,
|
|
208
|
+
unresolvedVariables,
|
|
209
|
+
conditionResult,
|
|
210
|
+
duration: Date.now() - startTime,
|
|
211
|
+
notes
|
|
212
|
+
});
|
|
213
|
+
this.executionPath.push(step.id);
|
|
214
|
+
if (step.nodeDefinitionId === "end-failure") {
|
|
215
|
+
this.stepResults[this.stepResults.length - 1].forcedFail = true;
|
|
216
|
+
notes.push("실패 종료 — 실제 실행이면 런이 여기서 실패로 끝납니다.");
|
|
217
|
+
}
|
|
218
|
+
if (step.type === "end" || forcedFail && !step.continueOnError) return;
|
|
219
|
+
const outgoingConnections = this.definition.connections.filter((c) => c.fromStepId === step.id);
|
|
220
|
+
const chosenStepId = step.type === "condition" ? resolveBranchPath(step, outgoingConnections, conditionResult) : null;
|
|
221
|
+
const followedConnections = step.type === "condition" || step.type === "parallel" ? outgoingConnections : outgoingConnections.slice(0, 1);
|
|
222
|
+
for (const conn of followedConnections) {
|
|
223
|
+
if (step.type === "condition") {
|
|
224
|
+
if (!(conn.toStepId === chosenStepId)) {
|
|
225
|
+
const skippedStep = this.definition.steps.find((s) => s.id === conn.toStepId);
|
|
226
|
+
if (skippedStep && !visited.has(skippedStep.id)) this.stepResults.push({
|
|
227
|
+
stepId: skippedStep.id,
|
|
228
|
+
stepLabel: skippedStep.label,
|
|
229
|
+
stepType: skippedStep.type,
|
|
230
|
+
executed: false,
|
|
231
|
+
skipped: true,
|
|
232
|
+
forcedFail: false,
|
|
233
|
+
duration: 0,
|
|
234
|
+
notes: ["조건 분기로 인해 건너뜀"]
|
|
235
|
+
});
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const nextStep = this.definition.steps.find((s) => s.id === conn.toStepId);
|
|
240
|
+
if (nextStep) await this.simulateStep(nextStep, visited);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* 테스트 실행 헬퍼 함수
|
|
246
|
+
*/
|
|
247
|
+
async function executeTestMode(definition, context, config = {}) {
|
|
248
|
+
return new TestExecutor(definition, context, config).execute();
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* 검증만 수행
|
|
252
|
+
*/
|
|
253
|
+
function validateWorkflow(definition) {
|
|
254
|
+
const validation = new TestExecutor(definition, {
|
|
255
|
+
runId: "validation",
|
|
256
|
+
workflowId: "validation",
|
|
257
|
+
workspaceId: "validation",
|
|
258
|
+
userId: "validation",
|
|
259
|
+
params: {},
|
|
260
|
+
variables: {},
|
|
261
|
+
previousResults: /* @__PURE__ */ new Map(),
|
|
262
|
+
triggeredBy: "manual",
|
|
263
|
+
emit: async () => {}
|
|
264
|
+
}, {}).validateDefinition();
|
|
265
|
+
return {
|
|
266
|
+
valid: validation.errors.length === 0,
|
|
267
|
+
errors: validation.errors,
|
|
268
|
+
warnings: validation.warnings
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* 실행 경로 분석
|
|
273
|
+
*/
|
|
274
|
+
function analyzeExecutionPaths(definition) {
|
|
275
|
+
const triggerStep = definition.steps.find((s) => s.type === "trigger");
|
|
276
|
+
if (!triggerStep) return {
|
|
277
|
+
paths: [],
|
|
278
|
+
maxDepth: 0,
|
|
279
|
+
branchPoints: []
|
|
280
|
+
};
|
|
281
|
+
const paths = [];
|
|
282
|
+
const branchPoints = /* @__PURE__ */ new Set();
|
|
283
|
+
const adjacencyList = /* @__PURE__ */ new Map();
|
|
284
|
+
for (const conn of definition.connections) {
|
|
285
|
+
var _adjacencyList$get3;
|
|
286
|
+
const existing = (_adjacencyList$get3 = adjacencyList.get(conn.fromStepId)) !== null && _adjacencyList$get3 !== void 0 ? _adjacencyList$get3 : [];
|
|
287
|
+
adjacencyList.set(conn.fromStepId, [...existing, conn]);
|
|
288
|
+
}
|
|
289
|
+
for (const [stepId, connections] of adjacencyList) if (connections.length > 1) branchPoints.add(stepId);
|
|
290
|
+
const findPaths = (stepId, currentPath) => {
|
|
291
|
+
var _adjacencyList$get4;
|
|
292
|
+
if (currentPath.includes(stepId)) return;
|
|
293
|
+
const newPath = [...currentPath, stepId];
|
|
294
|
+
const step = definition.steps.find((s) => s.id === stepId);
|
|
295
|
+
if (!step || step.type === "end") {
|
|
296
|
+
paths.push(newPath);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const outgoing = (_adjacencyList$get4 = adjacencyList.get(stepId)) !== null && _adjacencyList$get4 !== void 0 ? _adjacencyList$get4 : [];
|
|
300
|
+
if (outgoing.length === 0) {
|
|
301
|
+
paths.push(newPath);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
for (const conn of outgoing) findPaths(conn.toStepId, newPath);
|
|
305
|
+
};
|
|
306
|
+
findPaths(triggerStep.id, []);
|
|
307
|
+
return {
|
|
308
|
+
paths,
|
|
309
|
+
maxDepth: Math.max(...paths.map((p) => p.length), 0),
|
|
310
|
+
branchPoints: Array.from(branchPoints)
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
export { createId as a, validateWorkflow as i, analyzeExecutionPaths as n, executeTestMode as r, TestExecutor as t };
|