@ai-setting/roy-agent-core 1.5.43 → 1.5.44
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/dist/env/index.js +7 -6
- package/dist/env/tool/built-in/index.js +1 -1
- package/dist/env/tool/index.js +2 -2
- package/dist/env/workflow/decorators/index.js +1 -1
- package/dist/env/workflow/engine/index.js +4 -3
- package/dist/env/workflow/index.js +34 -19
- package/dist/env/workflow/nodes/index.js +5 -1
- package/dist/env/workflow/types/index.js +16 -2
- package/dist/env/workflow/utils/index.js +15 -196
- package/dist/index.js +9 -8
- package/dist/shared/@ai-setting/{roy-agent-core-ffb9fq4v.js → roy-agent-core-23gw9c4s.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-bmr6bdfb.js → roy-agent-core-2ms7296b.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-2jnzv9at.js → roy-agent-core-38dkek2y.js} +319 -189
- package/dist/shared/@ai-setting/roy-agent-core-6vxg2gmr.js +321 -0
- package/dist/shared/@ai-setting/{roy-agent-core-0rtxwr28.js → roy-agent-core-9bmtxmp6.js} +77 -120
- package/dist/shared/@ai-setting/{roy-agent-core-7fgf85wc.js → roy-agent-core-h0x19xgn.js} +6 -7
- package/dist/shared/@ai-setting/roy-agent-core-qnrf2aw6.js +441 -0
- package/dist/shared/@ai-setting/roy-agent-core-v002ynpa.js +435 -0
- package/dist/shared/@ai-setting/{roy-agent-core-rsybkb38.js → roy-agent-core-ysvh8er9.js} +36 -39
- package/dist/shared/@ai-setting/{roy-agent-core-9yxb3ty9.js → roy-agent-core-z5sxe4p7.js} +5 -1
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-5x94xmt6.js +0 -350
- package/dist/shared/@ai-setting/roy-agent-core-jvatggbb.js +0 -603
- /package/dist/shared/@ai-setting/{roy-agent-core-e130w7mv.js → roy-agent-core-ryw3ckfy.js} +0 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TracedAs,
|
|
3
|
+
init_decorator
|
|
4
|
+
} from "./roy-agent-core-q5qj0fes.js";
|
|
5
|
+
import {
|
|
6
|
+
__esm,
|
|
7
|
+
__legacyDecorateClassTS
|
|
8
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
9
|
+
|
|
10
|
+
// src/env/workflow/nodes/tool-node.ts
|
|
11
|
+
var ToolNode;
|
|
12
|
+
var init_tool_node = __esm(() => {
|
|
13
|
+
init_decorator();
|
|
14
|
+
ToolNode = class ToolNode {
|
|
15
|
+
definition;
|
|
16
|
+
toolRegistry;
|
|
17
|
+
type = "tool";
|
|
18
|
+
id;
|
|
19
|
+
constructor(definition, toolRegistry) {
|
|
20
|
+
this.definition = definition;
|
|
21
|
+
this.toolRegistry = toolRegistry;
|
|
22
|
+
this.id = definition.id;
|
|
23
|
+
}
|
|
24
|
+
async execute(context) {
|
|
25
|
+
const startTime = Date.now();
|
|
26
|
+
try {
|
|
27
|
+
const toolName = this.definition.config?.tool ?? this.definition.config?.toolName;
|
|
28
|
+
if (!toolName) {
|
|
29
|
+
throw new Error("Tool name is required. Please specify config.tool or config.toolName in the node definition.");
|
|
30
|
+
}
|
|
31
|
+
let tool;
|
|
32
|
+
if (this.toolRegistry.getTool) {
|
|
33
|
+
const result = this.toolRegistry.getTool(toolName);
|
|
34
|
+
if (!result) {
|
|
35
|
+
throw new Error(`Tool not found: ${toolName}`);
|
|
36
|
+
}
|
|
37
|
+
if ("tool" in result) {
|
|
38
|
+
tool = result.tool;
|
|
39
|
+
} else {
|
|
40
|
+
tool = result;
|
|
41
|
+
}
|
|
42
|
+
} else if (this.toolRegistry.getToolByName) {
|
|
43
|
+
tool = this.toolRegistry.getToolByName(toolName);
|
|
44
|
+
}
|
|
45
|
+
if (!tool) {
|
|
46
|
+
throw new Error(`Tool not found: ${toolName}`);
|
|
47
|
+
}
|
|
48
|
+
const config = context.resolvedConfig ?? (this.definition.config || {});
|
|
49
|
+
const rawInput = config.input ?? config.inputs ?? config.args;
|
|
50
|
+
const rawCommand = config.command;
|
|
51
|
+
const rawMessage = config.message;
|
|
52
|
+
const hasResolvedConfig = context.resolvedConfig !== undefined;
|
|
53
|
+
let input;
|
|
54
|
+
if (rawCommand !== undefined) {
|
|
55
|
+
input = {
|
|
56
|
+
command: hasResolvedConfig ? rawCommand : context.templateResolver ? context.templateResolver.resolveValue(rawCommand) : rawCommand
|
|
57
|
+
};
|
|
58
|
+
} else if (rawMessage !== undefined) {
|
|
59
|
+
input = {
|
|
60
|
+
message: hasResolvedConfig ? rawMessage : context.templateResolver ? context.templateResolver.resolveValue(rawMessage) : rawMessage
|
|
61
|
+
};
|
|
62
|
+
} else if (rawInput !== undefined) {
|
|
63
|
+
input = hasResolvedConfig ? rawInput : context.templateResolver ? context.templateResolver.resolveValue(rawInput) : rawInput;
|
|
64
|
+
} else {
|
|
65
|
+
input = {};
|
|
66
|
+
}
|
|
67
|
+
let output;
|
|
68
|
+
try {
|
|
69
|
+
const toolContext = {
|
|
70
|
+
session_id: context.sessionId || `workflow_${context.runId}`,
|
|
71
|
+
message_id: context.nodeId,
|
|
72
|
+
metadata: {
|
|
73
|
+
workflowRunId: context.runId,
|
|
74
|
+
workflowName: context.workflowName,
|
|
75
|
+
nodeId: context.nodeId
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const executePromise = tool.execute(input, toolContext);
|
|
79
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
80
|
+
setTimeout(() => reject(new Error(`Tool '${toolName}' execution timeout after 60 seconds`)), 60000);
|
|
81
|
+
});
|
|
82
|
+
output = await Promise.race([executePromise, timeoutPromise]);
|
|
83
|
+
} catch (toolError) {
|
|
84
|
+
if (toolError instanceof TypeError && toolError.message.includes("context") && toolError.message.includes("not a function")) {
|
|
85
|
+
output = await tool.execute(input);
|
|
86
|
+
} else {
|
|
87
|
+
throw toolError;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const extractedOutput = this.extractFromWrapper(output);
|
|
91
|
+
return {
|
|
92
|
+
output: extractedOutput,
|
|
93
|
+
error: undefined,
|
|
94
|
+
durationMs: Date.now() - startTime
|
|
95
|
+
};
|
|
96
|
+
} catch (error) {
|
|
97
|
+
return {
|
|
98
|
+
output: undefined,
|
|
99
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
100
|
+
durationMs: Date.now() - startTime
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
extractFromWrapper(value) {
|
|
105
|
+
if (value === null || value === undefined) {
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
if (typeof value !== "object") {
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
let result;
|
|
112
|
+
if ("output" in value) {
|
|
113
|
+
result = value.output;
|
|
114
|
+
} else if ("result" in value && !("output" in value)) {
|
|
115
|
+
result = value.result;
|
|
116
|
+
} else {
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
if (typeof result === "string") {
|
|
120
|
+
return result.trimEnd();
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
__legacyDecorateClassTS([
|
|
126
|
+
TracedAs("workflow.tool.execute", { log: true })
|
|
127
|
+
], ToolNode.prototype, "execute", null);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// src/env/workflow/nodes/skill-node.ts
|
|
131
|
+
var SkillNode;
|
|
132
|
+
var init_skill_node = __esm(() => {
|
|
133
|
+
init_decorator();
|
|
134
|
+
SkillNode = class SkillNode {
|
|
135
|
+
definition;
|
|
136
|
+
skillRegistry;
|
|
137
|
+
type = "skill";
|
|
138
|
+
id;
|
|
139
|
+
constructor(definition, skillRegistry) {
|
|
140
|
+
this.definition = definition;
|
|
141
|
+
this.skillRegistry = skillRegistry;
|
|
142
|
+
this.id = definition.id;
|
|
143
|
+
}
|
|
144
|
+
async execute(context) {
|
|
145
|
+
const startTime = Date.now();
|
|
146
|
+
try {
|
|
147
|
+
const skillName = this.definition.config?.skill;
|
|
148
|
+
if (!skillName) {
|
|
149
|
+
throw new Error("Skill name is required. Please specify config.skill in the node definition.");
|
|
150
|
+
}
|
|
151
|
+
const skill = this.skillRegistry.getSkill(skillName);
|
|
152
|
+
if (!skill) {
|
|
153
|
+
throw new Error(`Skill not found: ${skillName}`);
|
|
154
|
+
}
|
|
155
|
+
const config = context.resolvedConfig ?? this.definition.config ?? {};
|
|
156
|
+
const input = config.input ?? {};
|
|
157
|
+
const resolvedInput = context.templateResolver ? context.templateResolver.resolveValue(input) : input;
|
|
158
|
+
const skillContext = {
|
|
159
|
+
runId: context.runId,
|
|
160
|
+
workflowName: context.workflowName,
|
|
161
|
+
nodeId: context.nodeId,
|
|
162
|
+
debug: context.debug,
|
|
163
|
+
sessionId: context.sessionId
|
|
164
|
+
};
|
|
165
|
+
const output = await skill.invoke(resolvedInput, skillContext);
|
|
166
|
+
return {
|
|
167
|
+
output,
|
|
168
|
+
error: undefined,
|
|
169
|
+
durationMs: Date.now() - startTime
|
|
170
|
+
};
|
|
171
|
+
} catch (error) {
|
|
172
|
+
return {
|
|
173
|
+
output: undefined,
|
|
174
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
175
|
+
durationMs: Date.now() - startTime
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
__legacyDecorateClassTS([
|
|
181
|
+
TracedAs("workflow.skill.execute", { log: true })
|
|
182
|
+
], SkillNode.prototype, "execute", null);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// src/env/workflow/nodes/workflow-node.ts
|
|
186
|
+
class WorkflowNode {
|
|
187
|
+
definition;
|
|
188
|
+
workflowRunner;
|
|
189
|
+
type = "workflow";
|
|
190
|
+
id;
|
|
191
|
+
constructor(definition, workflowRunner) {
|
|
192
|
+
this.definition = definition;
|
|
193
|
+
this.workflowRunner = workflowRunner;
|
|
194
|
+
this.id = definition.id;
|
|
195
|
+
}
|
|
196
|
+
async execute(context) {
|
|
197
|
+
const startTime = Date.now();
|
|
198
|
+
try {
|
|
199
|
+
const config = context.resolvedConfig ?? this.definition.config ?? {};
|
|
200
|
+
const workflowName = config.workflow_name;
|
|
201
|
+
if (!workflowName) {
|
|
202
|
+
throw new Error("workflow_name is required in config. Please specify config.workflow_name in the node definition.");
|
|
203
|
+
}
|
|
204
|
+
const previousOutputs = context.previousOutputs ?? this.convertToMap(context.nodeOutputs ?? {});
|
|
205
|
+
const resolvedInput = this.resolveInput(config.input ?? {}, previousOutputs);
|
|
206
|
+
const result = await this.workflowRunner.run(workflowName, resolvedInput);
|
|
207
|
+
const success = result.status === "completed";
|
|
208
|
+
return {
|
|
209
|
+
success,
|
|
210
|
+
output: result.output,
|
|
211
|
+
error: success ? undefined : result.error,
|
|
212
|
+
duration: Date.now() - startTime
|
|
213
|
+
};
|
|
214
|
+
} catch (error) {
|
|
215
|
+
return {
|
|
216
|
+
success: false,
|
|
217
|
+
output: undefined,
|
|
218
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
219
|
+
duration: Date.now() - startTime
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
convertToMap(nodeOutputs) {
|
|
224
|
+
const map = new Map;
|
|
225
|
+
for (const [nodeId, result] of Object.entries(nodeOutputs)) {
|
|
226
|
+
map.set(nodeId, result.output);
|
|
227
|
+
}
|
|
228
|
+
return map;
|
|
229
|
+
}
|
|
230
|
+
resolveInput(input, previousOutputs) {
|
|
231
|
+
const resolved = {};
|
|
232
|
+
for (const [key, value] of Object.entries(input)) {
|
|
233
|
+
resolved[key] = this.resolveValue(value, previousOutputs);
|
|
234
|
+
}
|
|
235
|
+
return resolved;
|
|
236
|
+
}
|
|
237
|
+
resolveValue(value, previousOutputs) {
|
|
238
|
+
if (typeof value === "string") {
|
|
239
|
+
return this.resolveStringTemplate(value, previousOutputs);
|
|
240
|
+
}
|
|
241
|
+
if (Array.isArray(value)) {
|
|
242
|
+
return value.map((item) => this.resolveValue(item, previousOutputs));
|
|
243
|
+
}
|
|
244
|
+
if (value !== null && typeof value === "object") {
|
|
245
|
+
const resolved = {};
|
|
246
|
+
for (const [k, v] of Object.entries(value)) {
|
|
247
|
+
resolved[k] = this.resolveValue(v, previousOutputs);
|
|
248
|
+
}
|
|
249
|
+
return resolved;
|
|
250
|
+
}
|
|
251
|
+
return value;
|
|
252
|
+
}
|
|
253
|
+
resolveStringTemplate(template, previousOutputs) {
|
|
254
|
+
const templatePattern = /\{\{([^}]+)\}\}/g;
|
|
255
|
+
return template.replace(templatePattern, (match, path) => {
|
|
256
|
+
const trimmedPath = path.trim();
|
|
257
|
+
const value = this.resolvePath(trimmedPath, previousOutputs);
|
|
258
|
+
if (value !== undefined) {
|
|
259
|
+
return this.stringifyValue(value, match);
|
|
260
|
+
}
|
|
261
|
+
return match;
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
resolvePath(path, previousOutputs) {
|
|
265
|
+
const segments = path.split(".");
|
|
266
|
+
if (segments.length === 0) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const nodeId = segments[0];
|
|
270
|
+
let nodeOutput = previousOutputs.get(nodeId);
|
|
271
|
+
if (nodeOutput === undefined) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
nodeOutput = this.extractFromWrapper(nodeOutput);
|
|
275
|
+
if (segments.length === 1) {
|
|
276
|
+
return nodeOutput;
|
|
277
|
+
}
|
|
278
|
+
let current = nodeOutput;
|
|
279
|
+
let startIndex = 1;
|
|
280
|
+
if (segments.length > 1 && (segments[1] === "output" || segments[1] === "result" || segments[1] === "metadata")) {
|
|
281
|
+
startIndex = 2;
|
|
282
|
+
}
|
|
283
|
+
for (let i = startIndex;i < segments.length; i++) {
|
|
284
|
+
if (current === null || current === undefined) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
current = current[segments[i]];
|
|
288
|
+
}
|
|
289
|
+
return current;
|
|
290
|
+
}
|
|
291
|
+
extractFromWrapper(value) {
|
|
292
|
+
if (value === null || value === undefined) {
|
|
293
|
+
return value;
|
|
294
|
+
}
|
|
295
|
+
if (typeof value !== "object") {
|
|
296
|
+
return value;
|
|
297
|
+
}
|
|
298
|
+
if ("result" in value && "metadata" in value) {
|
|
299
|
+
return value.result;
|
|
300
|
+
}
|
|
301
|
+
if ("output" in value) {
|
|
302
|
+
return value.output;
|
|
303
|
+
}
|
|
304
|
+
return value;
|
|
305
|
+
}
|
|
306
|
+
stringifyValue(value, originalTemplate) {
|
|
307
|
+
if (value === undefined) {
|
|
308
|
+
return originalTemplate;
|
|
309
|
+
}
|
|
310
|
+
if (value === null) {
|
|
311
|
+
return "null";
|
|
312
|
+
}
|
|
313
|
+
if (typeof value === "string") {
|
|
314
|
+
return value;
|
|
315
|
+
}
|
|
316
|
+
return JSON.stringify(value);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
var init_workflow_node = () => {};
|
|
320
|
+
|
|
321
|
+
export { ToolNode, init_tool_node, SkillNode, init_skill_node, WorkflowNode, init_workflow_node };
|
|
@@ -2,143 +2,100 @@ import {
|
|
|
2
2
|
DecoratorNode,
|
|
3
3
|
init_decorator_node
|
|
4
4
|
} from "./roy-agent-core-1ce3fqrk.js";
|
|
5
|
+
import {
|
|
6
|
+
TracedAs,
|
|
7
|
+
init_decorator
|
|
8
|
+
} from "./roy-agent-core-q5qj0fes.js";
|
|
9
|
+
import {
|
|
10
|
+
createLogger,
|
|
11
|
+
init_logger
|
|
12
|
+
} from "./roy-agent-core-10n2jh7p.js";
|
|
5
13
|
import {
|
|
6
14
|
__esm,
|
|
7
|
-
__export
|
|
15
|
+
__export,
|
|
16
|
+
__legacyDecorateClassTS
|
|
8
17
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
9
18
|
|
|
10
19
|
// src/env/workflow/nodes/condition-node.ts
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
var logger, ConditionNode;
|
|
21
|
+
var init_condition_node = __esm(() => {
|
|
22
|
+
init_decorator();
|
|
23
|
+
init_logger();
|
|
24
|
+
logger = createLogger("workflow.condition");
|
|
25
|
+
ConditionNode = class ConditionNode {
|
|
26
|
+
definition;
|
|
27
|
+
type = "condition";
|
|
28
|
+
id;
|
|
29
|
+
constructor(definition) {
|
|
30
|
+
this.definition = definition;
|
|
31
|
+
this.id = definition.id;
|
|
32
|
+
}
|
|
33
|
+
async execute(context) {
|
|
34
|
+
const startTime = Date.now();
|
|
35
|
+
try {
|
|
36
|
+
const rawCondition = this.definition.config?.condition;
|
|
37
|
+
if (rawCondition === undefined) {
|
|
38
|
+
return {
|
|
39
|
+
output: { success: true, condition: true },
|
|
40
|
+
error: undefined,
|
|
41
|
+
durationMs: Date.now() - startTime
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
let conditionConfig;
|
|
45
|
+
if (context.resolvedConfig !== undefined) {
|
|
46
|
+
conditionConfig = context.resolvedConfig.condition;
|
|
47
|
+
} else {
|
|
48
|
+
const containsTemplate = typeof rawCondition === "string" && /\{\{.*\}\}/.test(rawCondition);
|
|
49
|
+
if (containsTemplate && !context.templateResolver) {
|
|
50
|
+
logger.warn(`[ConditionNode:${this.id}] Condition contains template references "{{...}}" but ` + `templateResolver is not available. The condition will be evaluated as-is. ` + `To resolve templates, ensure the workflow engine provides a templateResolver.`);
|
|
51
|
+
conditionConfig = rawCondition;
|
|
52
|
+
} else if (context.templateResolver) {
|
|
53
|
+
conditionConfig = context.templateResolver.resolveValue(rawCondition);
|
|
54
|
+
} else {
|
|
55
|
+
conditionConfig = rawCondition;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const result = this.evaluateCondition(conditionConfig);
|
|
24
59
|
return {
|
|
25
|
-
output: { success:
|
|
60
|
+
output: { success: result, condition: conditionConfig },
|
|
26
61
|
error: undefined,
|
|
27
62
|
durationMs: Date.now() - startTime
|
|
28
63
|
};
|
|
64
|
+
} catch (error) {
|
|
65
|
+
return {
|
|
66
|
+
output: undefined,
|
|
67
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
68
|
+
durationMs: Date.now() - startTime
|
|
69
|
+
};
|
|
29
70
|
}
|
|
30
|
-
const resolvedCondition = this.resolveCondition(conditionConfig, context);
|
|
31
|
-
const result = this.evaluateCondition(resolvedCondition);
|
|
32
|
-
return {
|
|
33
|
-
output: { success: result, condition: resolvedCondition },
|
|
34
|
-
error: undefined,
|
|
35
|
-
durationMs: Date.now() - startTime
|
|
36
|
-
};
|
|
37
|
-
} catch (error) {
|
|
38
|
-
return {
|
|
39
|
-
output: undefined,
|
|
40
|
-
error: error instanceof Error ? error : new Error(String(error)),
|
|
41
|
-
durationMs: Date.now() - startTime
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
resolveCondition(condition, context) {
|
|
46
|
-
if (typeof condition === "string") {
|
|
47
|
-
const templateMatch = condition.match(/^\{\{([^}]+)\}\}$/);
|
|
48
|
-
if (templateMatch) {
|
|
49
|
-
const path = templateMatch[1].trim();
|
|
50
|
-
return this.resolveTemplate(path, context);
|
|
51
|
-
}
|
|
52
|
-
if (condition === "true")
|
|
53
|
-
return true;
|
|
54
|
-
if (condition === "false")
|
|
55
|
-
return false;
|
|
56
|
-
return condition;
|
|
57
71
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const trimmed = path.trim();
|
|
62
|
-
if (trimmed.startsWith("input.")) {
|
|
63
|
-
const key = trimmed.slice(6);
|
|
64
|
-
return context.input?.[key];
|
|
65
|
-
}
|
|
66
|
-
if (trimmed.startsWith("nodes.")) {
|
|
67
|
-
const rest = trimmed.slice(6);
|
|
68
|
-
const segments2 = rest.split(".");
|
|
69
|
-
const nodeId2 = segments2[0];
|
|
70
|
-
let nodeOutput2 = context.previousOutputs.get(nodeId2);
|
|
71
|
-
if (nodeOutput2 === undefined) {
|
|
72
|
-
const normalizedUnderscore = nodeId2.replace(/-/g, "_");
|
|
73
|
-
const normalizedHyphen = nodeId2.replace(/_/g, "-");
|
|
74
|
-
if (normalizedUnderscore !== nodeId2) {
|
|
75
|
-
nodeOutput2 = context.previousOutputs.get(normalizedUnderscore);
|
|
76
|
-
}
|
|
77
|
-
if (nodeOutput2 === undefined && normalizedHyphen !== nodeId2) {
|
|
78
|
-
nodeOutput2 = context.previousOutputs.get(normalizedHyphen);
|
|
79
|
-
}
|
|
72
|
+
evaluateCondition(value) {
|
|
73
|
+
if (typeof value === "boolean") {
|
|
74
|
+
return value;
|
|
80
75
|
}
|
|
81
|
-
if (
|
|
82
|
-
return;
|
|
83
|
-
let value2 = nodeOutput2;
|
|
84
|
-
for (const segment of segments2.slice(1)) {
|
|
85
|
-
if (value2 && typeof value2 === "object") {
|
|
86
|
-
value2 = value2[segment];
|
|
87
|
-
} else {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
76
|
+
if (typeof value === "string") {
|
|
77
|
+
return value.toLowerCase() === "true" || value === "1";
|
|
90
78
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const segments = trimmed.split(".");
|
|
94
|
-
const nodeId = segments[0];
|
|
95
|
-
let nodeOutput = context.previousOutputs.get(nodeId);
|
|
96
|
-
if (nodeOutput === undefined) {
|
|
97
|
-
const normalizedUnderscore = nodeId.replace(/-/g, "_");
|
|
98
|
-
const normalizedHyphen = nodeId.replace(/_/g, "-");
|
|
99
|
-
if (normalizedUnderscore !== nodeId) {
|
|
100
|
-
nodeOutput = context.previousOutputs.get(normalizedUnderscore);
|
|
79
|
+
if (typeof value === "number") {
|
|
80
|
+
return value !== 0;
|
|
101
81
|
}
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (nodeOutput === undefined)
|
|
107
|
-
return;
|
|
108
|
-
let value = nodeOutput;
|
|
109
|
-
for (const segment of segments.slice(1)) {
|
|
110
|
-
if (value && typeof value === "object") {
|
|
111
|
-
value = value[segment];
|
|
112
|
-
} else {
|
|
113
|
-
return;
|
|
82
|
+
if (value === null || value === undefined) {
|
|
83
|
+
return false;
|
|
114
84
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
if (typeof value === "string") {
|
|
123
|
-
return value.toLowerCase() === "true" || value === "1";
|
|
124
|
-
}
|
|
125
|
-
if (typeof value === "number") {
|
|
126
|
-
return value !== 0;
|
|
127
|
-
}
|
|
128
|
-
if (value === null || value === undefined) {
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
if (typeof value === "object") {
|
|
132
|
-
const obj = value;
|
|
133
|
-
if ("success" in obj) {
|
|
134
|
-
return Boolean(obj.success);
|
|
85
|
+
if (typeof value === "object") {
|
|
86
|
+
const obj = value;
|
|
87
|
+
if ("success" in obj) {
|
|
88
|
+
return Boolean(obj.success);
|
|
89
|
+
}
|
|
90
|
+
return Object.keys(obj).length > 0;
|
|
135
91
|
}
|
|
136
|
-
return
|
|
92
|
+
return Boolean(value);
|
|
137
93
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
94
|
+
};
|
|
95
|
+
__legacyDecorateClassTS([
|
|
96
|
+
TracedAs("workflow.condition.execute", { log: true })
|
|
97
|
+
], ConditionNode.prototype, "execute", null);
|
|
98
|
+
});
|
|
142
99
|
|
|
143
100
|
// src/env/workflow/nodes/merge-node.ts
|
|
144
101
|
class MergeNode {
|
|
@@ -132,6 +132,11 @@ class WorkflowConverter {
|
|
|
132
132
|
retry: meta.retry,
|
|
133
133
|
timeout: meta.timeout
|
|
134
134
|
}));
|
|
135
|
+
const edges = edgeMetadatas.map((edge) => ({
|
|
136
|
+
from: edge.from,
|
|
137
|
+
to: edge.to,
|
|
138
|
+
when: edge.condition
|
|
139
|
+
}));
|
|
135
140
|
const entry = workflowMeta.entry || nodeMetadatas[0]?.nodeId || "unknown";
|
|
136
141
|
return {
|
|
137
142
|
name: workflowMeta.name,
|
|
@@ -139,6 +144,7 @@ class WorkflowConverter {
|
|
|
139
144
|
description: workflowMeta.description,
|
|
140
145
|
config: workflowMeta.config || {},
|
|
141
146
|
nodes,
|
|
147
|
+
edges,
|
|
142
148
|
entry,
|
|
143
149
|
outputs: [],
|
|
144
150
|
metadata: {
|
|
@@ -158,13 +164,6 @@ class WorkflowConverter {
|
|
|
158
164
|
if (!targetNode.dependsOn.includes(edge.from)) {
|
|
159
165
|
targetNode.dependsOn = [...targetNode.dependsOn, edge.from];
|
|
160
166
|
}
|
|
161
|
-
if (edge.condition) {
|
|
162
|
-
if (targetNode.condition) {
|
|
163
|
-
targetNode.condition = `(${targetNode.condition}) AND (${edge.condition})`;
|
|
164
|
-
} else {
|
|
165
|
-
targetNode.condition = edge.condition;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
167
|
}
|
|
169
168
|
}
|
|
170
169
|
return nodeMap;
|