@ai-setting/roy-agent-core 1.4.13 → 1.4.14
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/packages/core/src/config/index.js +32 -0
- package/dist/packages/core/src/env/agent/index.js +24 -0
- package/dist/packages/core/src/env/commands/index.js +14 -0
- package/dist/packages/core/src/env/debug/formatters/index.js +11 -0
- package/dist/packages/core/src/env/debug/index.js +26 -0
- package/dist/packages/core/src/env/hook/index.js +29 -0
- package/dist/packages/core/src/env/index.js +81 -0
- package/dist/packages/core/src/env/llm/index.js +40 -0
- package/dist/packages/core/src/env/log-trace/index.js +83 -0
- package/dist/packages/core/src/env/mcp/index.js +39 -0
- package/dist/packages/core/src/env/mcp/tool/index.js +14 -0
- package/dist/packages/core/src/env/memory/built-in/index.js +11 -0
- package/dist/packages/core/src/env/memory/index.js +56 -0
- package/dist/packages/core/src/env/memory/plugin/index.js +36 -0
- package/dist/packages/core/src/env/prompt/index.js +20 -0
- package/dist/packages/core/src/env/session/index.js +25 -0
- package/dist/packages/core/src/env/session/storage/index.js +18 -0
- package/dist/packages/core/src/env/skill/index.js +34 -0
- package/dist/packages/core/src/env/skill/tool/index.js +9 -0
- package/dist/packages/core/src/env/task/delegate/index.js +18 -0
- package/dist/packages/core/src/env/task/hooks/index.js +7 -0
- package/dist/packages/core/src/env/task/index.js +30 -0
- package/dist/packages/core/src/env/task/plugins/index.js +23 -0
- package/dist/packages/core/src/env/task/storage/index.js +14 -0
- package/dist/packages/core/src/env/task/tools/index.js +17 -0
- package/dist/packages/core/src/env/task/tools/operation/index.js +15 -0
- package/dist/{shared/chunk-1d4rwms4.js → packages/core/src/env/tool/built-in/index.js} +4 -4
- package/dist/packages/core/src/env/tool/index.js +39 -0
- package/dist/packages/core/src/env/workflow/decorators/index.js +27 -0
- package/dist/packages/core/src/env/workflow/engine/index.js +28 -0
- package/dist/packages/core/src/env/workflow/index.js +132 -0
- package/dist/packages/core/src/env/workflow/nodes/index.js +19 -0
- package/dist/packages/core/src/env/workflow/service/index.js +13 -0
- package/dist/packages/core/src/env/workflow/storage/index.js +27 -0
- package/dist/packages/core/src/env/workflow/tools/index.js +159 -0
- package/dist/packages/core/src/env/workflow/types/index.js +94 -0
- package/dist/packages/core/src/env/workflow/utils/index.js +637 -0
- package/dist/packages/core/src/index.js +398 -0
- package/dist/shared/@ai-setting/roy-agent-core-04fm8177.js +393 -0
- package/dist/shared/@ai-setting/roy-agent-core-04qgbjbe.js +172 -0
- package/dist/shared/@ai-setting/roy-agent-core-084qqd7t.js +11 -0
- package/dist/shared/@ai-setting/roy-agent-core-0gekht4e.js +1130 -0
- package/dist/shared/@ai-setting/roy-agent-core-0hdry23r.js +419 -0
- package/dist/shared/{chunk-ze20rksg.js → @ai-setting/roy-agent-core-0sgn3de4.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-12x57kf1.js +286 -0
- package/dist/shared/@ai-setting/roy-agent-core-1f3xrrm6.js +393 -0
- package/dist/shared/{chunk-q9j99fsm.js → @ai-setting/roy-agent-core-1k28kg7h.js} +6 -6
- package/dist/shared/{chunk-2b5kbhx3.js → @ai-setting/roy-agent-core-1z1zv5g8.js} +9 -117
- package/dist/shared/@ai-setting/roy-agent-core-2hqxnaf3.js +851 -0
- package/dist/shared/@ai-setting/roy-agent-core-3dfq8awb.js +587 -0
- package/dist/shared/@ai-setting/roy-agent-core-3takar0s.js +93 -0
- package/dist/shared/@ai-setting/roy-agent-core-3tnb2005.js +117 -0
- package/dist/shared/@ai-setting/roy-agent-core-4vmcvkav.js +14 -0
- package/dist/shared/{chunk-25x2pdtp.js → @ai-setting/roy-agent-core-4ws8atva.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-5fbp24se.js +603 -0
- package/dist/shared/@ai-setting/roy-agent-core-5my94ywp.js +66 -0
- package/dist/shared/{chunk-rncy3rtd.js → @ai-setting/roy-agent-core-6j0zcmwk.js} +128 -1122
- package/dist/shared/@ai-setting/roy-agent-core-6w4pmxc7.js +266 -0
- package/dist/shared/{chunk-yqmx37vm.js → @ai-setting/roy-agent-core-7vrk3add.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-8dvbn7tw.js +64 -0
- package/dist/shared/@ai-setting/roy-agent-core-8mbmrwzs.js +171 -0
- package/dist/shared/@ai-setting/roy-agent-core-8wzz66qe.js +620 -0
- package/dist/shared/@ai-setting/roy-agent-core-9ykq91jc.js +762 -0
- package/dist/shared/@ai-setting/roy-agent-core-dde19zke.js +1305 -0
- package/dist/shared/@ai-setting/roy-agent-core-f7g67gce.js +913 -0
- package/dist/shared/@ai-setting/roy-agent-core-fq5mtxsy.js +341 -0
- package/dist/shared/@ai-setting/roy-agent-core-fvd9g6k8.js +1205 -0
- package/dist/shared/@ai-setting/roy-agent-core-gv1hrn3x.js +378 -0
- package/dist/shared/@ai-setting/roy-agent-core-gy0wp5h7.js +213 -0
- package/dist/shared/{chunk-mf5xqbdh.js → @ai-setting/roy-agent-core-hyza1gm7.js} +3 -2
- package/dist/shared/{chunk-1qwabsm0.js → @ai-setting/roy-agent-core-j8zx62zr.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-jb2exr0d.js +442 -0
- package/dist/shared/@ai-setting/roy-agent-core-jv3b7v9w.js +57 -0
- package/dist/shared/@ai-setting/roy-agent-core-k1rxf9ya.js +513 -0
- package/dist/shared/@ai-setting/roy-agent-core-kydc9nwb.js +60 -0
- package/dist/shared/@ai-setting/roy-agent-core-m2x48hw6.js +97 -0
- package/dist/shared/@ai-setting/roy-agent-core-m6y668cc.js +377 -0
- package/dist/shared/{chunk-1aakcfp1.js → @ai-setting/roy-agent-core-nczzf0ms.js} +3 -3
- package/dist/shared/@ai-setting/roy-agent-core-nfj6knp5.js +36 -0
- package/dist/shared/@ai-setting/roy-agent-core-ntrp979d.js +204 -0
- package/dist/shared/@ai-setting/roy-agent-core-pd7g8z5v.js +1387 -0
- package/dist/shared/@ai-setting/roy-agent-core-pzk1syce.js +14 -0
- package/dist/shared/@ai-setting/roy-agent-core-q50tg9m2.js +862 -0
- package/dist/shared/{chunk-9qzt1v1p.js → @ai-setting/roy-agent-core-qg9tcaph.js} +3 -2
- package/dist/shared/{chunk-91bas8w5.js → @ai-setting/roy-agent-core-qhyerewk.js} +5 -5
- package/dist/shared/{chunk-1pf5mfgd.js → @ai-setting/roy-agent-core-qxybm159.js} +3 -3
- package/dist/shared/{chunk-g6j5n3gv.js → @ai-setting/roy-agent-core-rh9dpkpw.js} +10 -10
- package/dist/shared/{chunk-0q6s9wm6.js → @ai-setting/roy-agent-core-rr9p1g43.js} +7 -51
- package/dist/shared/@ai-setting/roy-agent-core-sbzvpfn7.js +284 -0
- package/dist/shared/@ai-setting/roy-agent-core-t22nqt4d.js +788 -0
- package/dist/shared/{chunk-t1rh6jtm.js → @ai-setting/roy-agent-core-tkr5ynkh.js} +8 -13
- package/dist/shared/@ai-setting/roy-agent-core-v4aabsf0.js +303 -0
- package/dist/shared/@ai-setting/roy-agent-core-w75rafhy.js +202 -0
- package/dist/shared/@ai-setting/roy-agent-core-w76hqkmg.js +584 -0
- package/dist/shared/@ai-setting/roy-agent-core-yfbgwes2.js +408 -0
- package/dist/shared/{chunk-a9qmy3sc.js → @ai-setting/roy-agent-core-yn761yve.js} +7 -4
- package/dist/shared/@ai-setting/roy-agent-core-yrzmn4m1.js +492 -0
- package/dist/shared/@ai-setting/roy-agent-core-yt8wdh2w.js +206 -0
- package/package.json +8 -7
- package/dist/index.d.ts +0 -7825
- package/dist/index.js +0 -16551
- package/dist/shared/chunk-hs7tbmje.js +0 -24
- /package/dist/shared/{chunk-wbkh7wat.js → @ai-setting/roy-agent-core-fs0mn2jk.js} +0 -0
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__esm
|
|
3
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
4
|
+
|
|
5
|
+
// packages/core/src/env/workflow/nodes/tool-node.ts
|
|
6
|
+
class ToolNode {
|
|
7
|
+
definition;
|
|
8
|
+
toolRegistry;
|
|
9
|
+
type = "tool";
|
|
10
|
+
id;
|
|
11
|
+
constructor(definition, toolRegistry) {
|
|
12
|
+
this.definition = definition;
|
|
13
|
+
this.toolRegistry = toolRegistry;
|
|
14
|
+
this.id = definition.id;
|
|
15
|
+
}
|
|
16
|
+
async execute(context) {
|
|
17
|
+
const startTime = Date.now();
|
|
18
|
+
try {
|
|
19
|
+
const toolName = this.definition.config?.tool ?? this.definition.config?.toolName;
|
|
20
|
+
if (!toolName) {
|
|
21
|
+
throw new Error("Tool name is required. Please specify config.tool or config.toolName in the node definition.");
|
|
22
|
+
}
|
|
23
|
+
let tool;
|
|
24
|
+
if (this.toolRegistry.getTool) {
|
|
25
|
+
const result = this.toolRegistry.getTool(toolName);
|
|
26
|
+
if (!result) {
|
|
27
|
+
throw new Error(`Tool not found: ${toolName}`);
|
|
28
|
+
}
|
|
29
|
+
if ("tool" in result) {
|
|
30
|
+
tool = result.tool;
|
|
31
|
+
} else {
|
|
32
|
+
tool = result;
|
|
33
|
+
}
|
|
34
|
+
} else if (this.toolRegistry.getToolByName) {
|
|
35
|
+
tool = this.toolRegistry.getToolByName(toolName);
|
|
36
|
+
}
|
|
37
|
+
if (!tool) {
|
|
38
|
+
throw new Error(`Tool not found: ${toolName}`);
|
|
39
|
+
}
|
|
40
|
+
let input;
|
|
41
|
+
if (this.definition.config?.command !== undefined) {
|
|
42
|
+
const commandTemplate = this.definition.config.command;
|
|
43
|
+
const resolvedCommand = this.resolveTemplateReferences(commandTemplate, context.previousOutputs, context.input);
|
|
44
|
+
input = { command: resolvedCommand };
|
|
45
|
+
console.log(`[ToolNode] command input: ${resolvedCommand}`);
|
|
46
|
+
} else if (this.definition.config?.message !== undefined && Object.keys(this.definition.config).length === 1) {
|
|
47
|
+
const messageTemplate = this.definition.config.message;
|
|
48
|
+
const resolvedMessage = this.resolveTemplateReferences(messageTemplate, context.previousOutputs, context.input);
|
|
49
|
+
input = { message: resolvedMessage };
|
|
50
|
+
console.log(`[ToolNode] message input: ${resolvedMessage}`);
|
|
51
|
+
} else {
|
|
52
|
+
input = this.definition.config?.input ?? this.definition.config?.args ?? {};
|
|
53
|
+
input = this.resolveTemplateReferences(input, context.previousOutputs, context.input);
|
|
54
|
+
}
|
|
55
|
+
let output;
|
|
56
|
+
try {
|
|
57
|
+
const toolContext = {
|
|
58
|
+
session_id: context.sessionId || `workflow_${context.runId}`,
|
|
59
|
+
message_id: context.nodeId,
|
|
60
|
+
metadata: {
|
|
61
|
+
workflowRunId: context.runId,
|
|
62
|
+
workflowName: context.workflowName,
|
|
63
|
+
nodeId: context.nodeId
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const executePromise = tool.execute(input, toolContext);
|
|
67
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
68
|
+
setTimeout(() => reject(new Error(`Tool ${toolName} execution timeout after 30s`)), 30000);
|
|
69
|
+
});
|
|
70
|
+
output = await Promise.race([executePromise, timeoutPromise]);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.log(`[ToolNode] Tool ${toolName} doesn't support context, retrying without context...`);
|
|
73
|
+
output = await tool.execute(input);
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
output,
|
|
77
|
+
error: undefined,
|
|
78
|
+
durationMs: Date.now() - startTime
|
|
79
|
+
};
|
|
80
|
+
} catch (error) {
|
|
81
|
+
return {
|
|
82
|
+
output: undefined,
|
|
83
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
84
|
+
durationMs: Date.now() - startTime
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
resolveTemplateReferences(input, previousOutputs, workflowInput) {
|
|
89
|
+
if (typeof input === "string") {
|
|
90
|
+
const pureTemplate = this.extractPureTemplate(input) || this.extractDollarTemplate(input);
|
|
91
|
+
if (pureTemplate) {
|
|
92
|
+
return this.resolvePureTemplate(pureTemplate, previousOutputs, workflowInput);
|
|
93
|
+
}
|
|
94
|
+
return this.resolveStringTemplate(input, previousOutputs, workflowInput);
|
|
95
|
+
}
|
|
96
|
+
if (Array.isArray(input)) {
|
|
97
|
+
return input.map((item) => this.resolveTemplateReferences(item, previousOutputs, workflowInput));
|
|
98
|
+
}
|
|
99
|
+
if (input !== null && typeof input === "object") {
|
|
100
|
+
const resolved = {};
|
|
101
|
+
for (const [key, value] of Object.entries(input)) {
|
|
102
|
+
resolved[key] = this.resolveTemplateReferences(value, previousOutputs, workflowInput);
|
|
103
|
+
}
|
|
104
|
+
return resolved;
|
|
105
|
+
}
|
|
106
|
+
return input;
|
|
107
|
+
}
|
|
108
|
+
extractPureTemplate(str) {
|
|
109
|
+
const trimmed = str.trim();
|
|
110
|
+
if (trimmed.startsWith("{{") && trimmed.endsWith("}}") && trimmed.length > 4) {
|
|
111
|
+
const content = trimmed.slice(2, -2).trim();
|
|
112
|
+
if (!content.includes("{{") && !content.includes("}}")) {
|
|
113
|
+
return content;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
extractDollarTemplate(str) {
|
|
119
|
+
const trimmed = str.trim();
|
|
120
|
+
if (trimmed.startsWith("${") && trimmed.endsWith("}") && trimmed.length > 3) {
|
|
121
|
+
const content = trimmed.slice(2, -1).trim();
|
|
122
|
+
if (!content.includes("${") && !content.includes("}")) {
|
|
123
|
+
return content;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
resolvePureTemplate(templateContent, previousOutputs, workflowInput) {
|
|
129
|
+
const trimmed = templateContent.trim();
|
|
130
|
+
const originalTemplate = `{{${templateContent}}}`;
|
|
131
|
+
if (trimmed.startsWith("input.")) {
|
|
132
|
+
const value = this.getNestedValue(workflowInput, trimmed.slice(6));
|
|
133
|
+
return value !== undefined ? value : originalTemplate;
|
|
134
|
+
}
|
|
135
|
+
if (trimmed.startsWith("nodes.")) {
|
|
136
|
+
const path = trimmed.slice(6);
|
|
137
|
+
const segments = path.split(".");
|
|
138
|
+
const nodeId = segments[0];
|
|
139
|
+
const restPath = segments.slice(1).join(".") || undefined;
|
|
140
|
+
const value = this.resolvePath(nodeId, restPath, previousOutputs);
|
|
141
|
+
return value !== undefined ? value : originalTemplate;
|
|
142
|
+
}
|
|
143
|
+
if (trimmed !== "input" && trimmed !== "nodes") {
|
|
144
|
+
const segments = trimmed.split(".");
|
|
145
|
+
const nodeId = segments[0];
|
|
146
|
+
const restPath = segments.slice(1).join(".") || undefined;
|
|
147
|
+
const value = this.resolvePath(nodeId, restPath, previousOutputs);
|
|
148
|
+
return value !== undefined ? value : originalTemplate;
|
|
149
|
+
}
|
|
150
|
+
return originalTemplate;
|
|
151
|
+
}
|
|
152
|
+
resolveStringTemplate(template, previousOutputs, workflowInput) {
|
|
153
|
+
let resolved = template;
|
|
154
|
+
resolved = resolved.replace(/\{\{input\.([^}]+)\}\}/g, (match, path) => {
|
|
155
|
+
const value = this.getNestedValue(workflowInput, path.trim());
|
|
156
|
+
return this.stringifyValue(value, match);
|
|
157
|
+
});
|
|
158
|
+
resolved = resolved.replace(/\$\{input\.([^}]+)\}/g, (match, path) => {
|
|
159
|
+
const value = this.getNestedValue(workflowInput, path.trim());
|
|
160
|
+
return this.stringifyValue(value, match);
|
|
161
|
+
});
|
|
162
|
+
resolved = resolved.replace(/\{\{([^:.{}][^}]*?)\}\}/g, (match, path) => {
|
|
163
|
+
if (path.trim().startsWith("nodes.") || path.trim().startsWith("input.")) {
|
|
164
|
+
return match;
|
|
165
|
+
}
|
|
166
|
+
const segments = path.trim().split(".");
|
|
167
|
+
const nodeId = segments[0];
|
|
168
|
+
const restPath = segments.slice(1).join(".") || undefined;
|
|
169
|
+
const value = this.resolvePath(nodeId, restPath, previousOutputs);
|
|
170
|
+
return this.stringifyValue(value, match);
|
|
171
|
+
});
|
|
172
|
+
resolved = resolved.replace(/\$\{([^}]+)\}/g, (match, path) => {
|
|
173
|
+
if (path.trim().startsWith("nodes.") || path.trim().startsWith("input.")) {
|
|
174
|
+
return match;
|
|
175
|
+
}
|
|
176
|
+
const segments = path.trim().split(".");
|
|
177
|
+
const nodeId = segments[0];
|
|
178
|
+
const restPath = segments.slice(1).join(".") || undefined;
|
|
179
|
+
const value = this.resolvePath(nodeId, restPath, previousOutputs);
|
|
180
|
+
return this.stringifyValue(value, match);
|
|
181
|
+
});
|
|
182
|
+
resolved = resolved.replace(/\{\{nodes\.([^}]+)\}\}/g, (match, path) => {
|
|
183
|
+
const segments = path.trim().split(".");
|
|
184
|
+
const nodeId = segments[0];
|
|
185
|
+
const restPath = segments.slice(1).join(".") || undefined;
|
|
186
|
+
const nodeOutput = this.resolvePath(nodeId, undefined, previousOutputs);
|
|
187
|
+
let extractedValue = this.extractFromWrapper(nodeOutput);
|
|
188
|
+
if (typeof extractedValue === "string" && restPath === "output") {
|
|
189
|
+
return this.stringifyValue(extractedValue, match);
|
|
190
|
+
}
|
|
191
|
+
if (restPath) {
|
|
192
|
+
const value = this.getNestedValue(extractedValue, restPath);
|
|
193
|
+
return this.stringifyValue(value, match);
|
|
194
|
+
} else {
|
|
195
|
+
return this.stringifyValue(extractedValue, match);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
return resolved;
|
|
199
|
+
}
|
|
200
|
+
resolvePath(nodeId, path, previousOutputs) {
|
|
201
|
+
let nodeOutput = previousOutputs.get(nodeId);
|
|
202
|
+
if (nodeOutput === undefined) {
|
|
203
|
+
const normalizedUnderscore = nodeId.replace(/-/g, "_");
|
|
204
|
+
const normalizedHyphen = nodeId.replace(/_/g, "-");
|
|
205
|
+
if (normalizedUnderscore !== nodeId) {
|
|
206
|
+
nodeOutput = previousOutputs.get(normalizedUnderscore);
|
|
207
|
+
}
|
|
208
|
+
if (nodeOutput === undefined && normalizedHyphen !== nodeId) {
|
|
209
|
+
nodeOutput = previousOutputs.get(normalizedHyphen);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (nodeOutput === undefined) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (path === undefined || path === "") {
|
|
216
|
+
return nodeOutput;
|
|
217
|
+
}
|
|
218
|
+
return this.getNestedValue(nodeOutput, path);
|
|
219
|
+
}
|
|
220
|
+
getNestedValue(obj, path) {
|
|
221
|
+
if (obj === null || obj === undefined) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const segments = path.split(".");
|
|
225
|
+
let current = obj;
|
|
226
|
+
for (const segment of segments) {
|
|
227
|
+
if (current === null || current === undefined) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
current = current[segment];
|
|
231
|
+
}
|
|
232
|
+
return current;
|
|
233
|
+
}
|
|
234
|
+
extractFromWrapper(value) {
|
|
235
|
+
if (value === null || value === undefined) {
|
|
236
|
+
return value;
|
|
237
|
+
}
|
|
238
|
+
if (typeof value !== "object") {
|
|
239
|
+
return value;
|
|
240
|
+
}
|
|
241
|
+
let result;
|
|
242
|
+
if ("output" in value) {
|
|
243
|
+
result = value.output;
|
|
244
|
+
} else if ("result" in value && !("output" in value)) {
|
|
245
|
+
result = value.result;
|
|
246
|
+
} else {
|
|
247
|
+
return value;
|
|
248
|
+
}
|
|
249
|
+
if (typeof result === "string") {
|
|
250
|
+
return result.trimEnd();
|
|
251
|
+
}
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
stringifyValue(value, fallback) {
|
|
255
|
+
if (value === undefined || value === null) {
|
|
256
|
+
return fallback;
|
|
257
|
+
}
|
|
258
|
+
let str;
|
|
259
|
+
if (typeof value === "object") {
|
|
260
|
+
str = JSON.stringify(value);
|
|
261
|
+
} else {
|
|
262
|
+
str = String(value);
|
|
263
|
+
}
|
|
264
|
+
return str.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/"/g, "\\\"").replace(/`/g, "\\`").replace(/\$/g, "\\$");
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
var init_tool_node = () => {};
|
|
268
|
+
|
|
269
|
+
// packages/core/src/env/workflow/nodes/skill-node.ts
|
|
270
|
+
class SkillNode {
|
|
271
|
+
definition;
|
|
272
|
+
skillRegistry;
|
|
273
|
+
type = "skill";
|
|
274
|
+
id;
|
|
275
|
+
constructor(definition, skillRegistry) {
|
|
276
|
+
this.definition = definition;
|
|
277
|
+
this.skillRegistry = skillRegistry;
|
|
278
|
+
this.id = definition.id;
|
|
279
|
+
}
|
|
280
|
+
async execute(context) {
|
|
281
|
+
const startTime = Date.now();
|
|
282
|
+
try {
|
|
283
|
+
const skillName = this.definition.config?.skill;
|
|
284
|
+
if (!skillName) {
|
|
285
|
+
throw new Error("Skill name is required. Please specify config.skill in the node definition.");
|
|
286
|
+
}
|
|
287
|
+
const skill = this.skillRegistry.getSkill(skillName);
|
|
288
|
+
if (!skill) {
|
|
289
|
+
throw new Error(`Skill not found: ${skillName}`);
|
|
290
|
+
}
|
|
291
|
+
const input = this.definition.config?.input ?? {};
|
|
292
|
+
const resolvedInput = this.resolveTemplateReferences(input, context.previousOutputs, context.input);
|
|
293
|
+
const skillContext = {
|
|
294
|
+
runId: context.runId,
|
|
295
|
+
workflowName: context.workflowName,
|
|
296
|
+
nodeId: context.nodeId,
|
|
297
|
+
debug: context.debug
|
|
298
|
+
};
|
|
299
|
+
const output = await skill.invoke(resolvedInput, skillContext);
|
|
300
|
+
return {
|
|
301
|
+
output,
|
|
302
|
+
error: undefined,
|
|
303
|
+
durationMs: Date.now() - startTime
|
|
304
|
+
};
|
|
305
|
+
} catch (error) {
|
|
306
|
+
return {
|
|
307
|
+
output: undefined,
|
|
308
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
309
|
+
durationMs: Date.now() - startTime
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
resolveTemplateReferences(input, previousOutputs, workflowInput) {
|
|
314
|
+
if (typeof input === "string") {
|
|
315
|
+
const pureTemplate = this.extractPureTemplate(input);
|
|
316
|
+
if (pureTemplate) {
|
|
317
|
+
return this.resolvePureTemplate(pureTemplate, previousOutputs, workflowInput);
|
|
318
|
+
}
|
|
319
|
+
return this.resolveStringTemplate(input, previousOutputs, workflowInput);
|
|
320
|
+
}
|
|
321
|
+
if (Array.isArray(input)) {
|
|
322
|
+
return input.map((item) => this.resolveTemplateReferences(item, previousOutputs, workflowInput));
|
|
323
|
+
}
|
|
324
|
+
if (input !== null && typeof input === "object") {
|
|
325
|
+
const resolved = {};
|
|
326
|
+
for (const [key, value] of Object.entries(input)) {
|
|
327
|
+
resolved[key] = this.resolveTemplateReferences(value, previousOutputs, workflowInput);
|
|
328
|
+
}
|
|
329
|
+
return resolved;
|
|
330
|
+
}
|
|
331
|
+
return input;
|
|
332
|
+
}
|
|
333
|
+
extractPureTemplate(str) {
|
|
334
|
+
const trimmed = str.trim();
|
|
335
|
+
if (trimmed.startsWith("{{") && trimmed.endsWith("}}") && trimmed.length > 4) {
|
|
336
|
+
const content = trimmed.slice(2, -2).trim();
|
|
337
|
+
if (!content.includes("{{") && !content.includes("}}")) {
|
|
338
|
+
return content;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
resolvePureTemplate(templateContent, previousOutputs, workflowInput) {
|
|
344
|
+
const trimmed = templateContent.trim();
|
|
345
|
+
const originalTemplate = `{{${templateContent}}}`;
|
|
346
|
+
if (trimmed.startsWith("input.")) {
|
|
347
|
+
const value = this.getNestedValue(workflowInput, trimmed.slice(6));
|
|
348
|
+
return value !== undefined ? value : originalTemplate;
|
|
349
|
+
}
|
|
350
|
+
if (trimmed.startsWith("nodes.")) {
|
|
351
|
+
const path = trimmed.slice(6);
|
|
352
|
+
const segments = path.split(".");
|
|
353
|
+
const nodeId = segments[0];
|
|
354
|
+
const restPath = segments.slice(1).join(".") || undefined;
|
|
355
|
+
const value = this.resolvePath(nodeId, restPath, previousOutputs);
|
|
356
|
+
return value !== undefined ? value : originalTemplate;
|
|
357
|
+
}
|
|
358
|
+
if (trimmed !== "input" && trimmed !== "nodes") {
|
|
359
|
+
const segments = trimmed.split(".");
|
|
360
|
+
const nodeId = segments[0];
|
|
361
|
+
const restPath = segments.slice(1).join(".") || undefined;
|
|
362
|
+
const value = this.resolvePath(nodeId, restPath, previousOutputs);
|
|
363
|
+
return value !== undefined ? value : originalTemplate;
|
|
364
|
+
}
|
|
365
|
+
return originalTemplate;
|
|
366
|
+
}
|
|
367
|
+
resolveStringTemplate(template, previousOutputs, workflowInput) {
|
|
368
|
+
let resolved = template;
|
|
369
|
+
resolved = resolved.replace(/\{\{input\.([^}]+)\}\}/g, (match, path) => {
|
|
370
|
+
const value = this.getNestedValue(workflowInput, path.trim());
|
|
371
|
+
return this.stringifyValue(value, match);
|
|
372
|
+
});
|
|
373
|
+
resolved = resolved.replace(/\{\{([^:.{}][^}]*?)\}\}/g, (match, path) => {
|
|
374
|
+
if (path.trim().startsWith("nodes.") || path.trim().startsWith("input.")) {
|
|
375
|
+
return match;
|
|
376
|
+
}
|
|
377
|
+
const segments = path.trim().split(".");
|
|
378
|
+
const nodeId = segments[0];
|
|
379
|
+
const restPath = segments.slice(1).join(".") || undefined;
|
|
380
|
+
const value = this.resolvePath(nodeId, restPath, previousOutputs);
|
|
381
|
+
return this.stringifyValue(value, match);
|
|
382
|
+
});
|
|
383
|
+
resolved = resolved.replace(/\{\{nodes\.([^}]+)\}\}/g, (match, path) => {
|
|
384
|
+
const segments = path.trim().split(".");
|
|
385
|
+
const nodeId = segments[0];
|
|
386
|
+
const restPath = segments.slice(1).join(".") || undefined;
|
|
387
|
+
const value = this.resolvePath(nodeId, restPath, previousOutputs);
|
|
388
|
+
return this.stringifyValue(value, match);
|
|
389
|
+
});
|
|
390
|
+
return resolved;
|
|
391
|
+
}
|
|
392
|
+
resolvePath(nodeId, path, previousOutputs) {
|
|
393
|
+
let nodeOutput = previousOutputs.get(nodeId);
|
|
394
|
+
if (nodeOutput === undefined) {
|
|
395
|
+
const normalizedUnderscore = nodeId.replace(/-/g, "_");
|
|
396
|
+
const normalizedHyphen = nodeId.replace(/_/g, "-");
|
|
397
|
+
if (normalizedUnderscore !== nodeId) {
|
|
398
|
+
nodeOutput = previousOutputs.get(normalizedUnderscore);
|
|
399
|
+
}
|
|
400
|
+
if (nodeOutput === undefined && normalizedHyphen !== nodeId) {
|
|
401
|
+
nodeOutput = previousOutputs.get(normalizedHyphen);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (nodeOutput === undefined) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
let value = this.extractFromWrapper(nodeOutput);
|
|
408
|
+
if (!path) {
|
|
409
|
+
return value;
|
|
410
|
+
}
|
|
411
|
+
let segments = path.split(".");
|
|
412
|
+
if (segments.length > 1 && (segments[0] === "output" || segments[0] === "result" || segments[0] === "metadata")) {
|
|
413
|
+
segments = segments.slice(1);
|
|
414
|
+
}
|
|
415
|
+
let current = value;
|
|
416
|
+
for (const segment of segments) {
|
|
417
|
+
if (current === null || current === undefined) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
current = current[segment];
|
|
421
|
+
}
|
|
422
|
+
return current;
|
|
423
|
+
}
|
|
424
|
+
extractFromWrapper(value) {
|
|
425
|
+
if (value === null || value === undefined) {
|
|
426
|
+
return value;
|
|
427
|
+
}
|
|
428
|
+
if (typeof value !== "object") {
|
|
429
|
+
return value;
|
|
430
|
+
}
|
|
431
|
+
if ("result" in value && "metadata" in value) {
|
|
432
|
+
return value.result;
|
|
433
|
+
}
|
|
434
|
+
if ("output" in value) {
|
|
435
|
+
return value.output;
|
|
436
|
+
}
|
|
437
|
+
return value;
|
|
438
|
+
}
|
|
439
|
+
getNestedValue(obj, path) {
|
|
440
|
+
if (!obj) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if ("input" in obj && path in obj["input"]) {
|
|
444
|
+
return obj["input"][path];
|
|
445
|
+
}
|
|
446
|
+
return path.split(".").reduce((current, key) => {
|
|
447
|
+
if (current && typeof current === "object") {
|
|
448
|
+
return current[key];
|
|
449
|
+
}
|
|
450
|
+
return;
|
|
451
|
+
}, obj);
|
|
452
|
+
}
|
|
453
|
+
stringifyValue(value, originalTemplate) {
|
|
454
|
+
if (value === undefined) {
|
|
455
|
+
return originalTemplate;
|
|
456
|
+
}
|
|
457
|
+
if (value === null) {
|
|
458
|
+
return "null";
|
|
459
|
+
}
|
|
460
|
+
if (typeof value === "string") {
|
|
461
|
+
return value;
|
|
462
|
+
}
|
|
463
|
+
return JSON.stringify(value);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
var init_skill_node = () => {};
|
|
467
|
+
|
|
468
|
+
// packages/core/src/env/workflow/nodes/workflow-node.ts
|
|
469
|
+
class WorkflowNode {
|
|
470
|
+
workflowRunner;
|
|
471
|
+
type = "workflow";
|
|
472
|
+
id;
|
|
473
|
+
config;
|
|
474
|
+
constructor(definition, workflowRunner) {
|
|
475
|
+
this.workflowRunner = workflowRunner;
|
|
476
|
+
this.id = definition.id;
|
|
477
|
+
this.config = definition.config ?? {};
|
|
478
|
+
}
|
|
479
|
+
async execute(context) {
|
|
480
|
+
const startTime = Date.now();
|
|
481
|
+
try {
|
|
482
|
+
const workflowName = this.config.workflow_name;
|
|
483
|
+
if (!workflowName) {
|
|
484
|
+
throw new Error("workflow_name is required in config. Please specify config.workflow_name in the node definition.");
|
|
485
|
+
}
|
|
486
|
+
const previousOutputs = context.previousOutputs ?? this.convertToMap(context.nodeOutputs ?? {});
|
|
487
|
+
const resolvedInput = this.resolveInput(this.config.input ?? {}, previousOutputs);
|
|
488
|
+
const result = await this.workflowRunner.run(workflowName, resolvedInput);
|
|
489
|
+
const success = result.status === "completed";
|
|
490
|
+
return {
|
|
491
|
+
success,
|
|
492
|
+
output: result.output,
|
|
493
|
+
error: success ? undefined : result.error,
|
|
494
|
+
duration: Date.now() - startTime
|
|
495
|
+
};
|
|
496
|
+
} catch (error) {
|
|
497
|
+
return {
|
|
498
|
+
success: false,
|
|
499
|
+
output: undefined,
|
|
500
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
501
|
+
duration: Date.now() - startTime
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
convertToMap(nodeOutputs) {
|
|
506
|
+
const map = new Map;
|
|
507
|
+
for (const [nodeId, result] of Object.entries(nodeOutputs)) {
|
|
508
|
+
map.set(nodeId, result.output);
|
|
509
|
+
}
|
|
510
|
+
return map;
|
|
511
|
+
}
|
|
512
|
+
resolveInput(input, previousOutputs) {
|
|
513
|
+
const resolved = {};
|
|
514
|
+
for (const [key, value] of Object.entries(input)) {
|
|
515
|
+
resolved[key] = this.resolveValue(value, previousOutputs);
|
|
516
|
+
}
|
|
517
|
+
return resolved;
|
|
518
|
+
}
|
|
519
|
+
resolveValue(value, previousOutputs) {
|
|
520
|
+
if (typeof value === "string") {
|
|
521
|
+
return this.resolveStringTemplate(value, previousOutputs);
|
|
522
|
+
}
|
|
523
|
+
if (Array.isArray(value)) {
|
|
524
|
+
return value.map((item) => this.resolveValue(item, previousOutputs));
|
|
525
|
+
}
|
|
526
|
+
if (value !== null && typeof value === "object") {
|
|
527
|
+
const resolved = {};
|
|
528
|
+
for (const [k, v] of Object.entries(value)) {
|
|
529
|
+
resolved[k] = this.resolveValue(v, previousOutputs);
|
|
530
|
+
}
|
|
531
|
+
return resolved;
|
|
532
|
+
}
|
|
533
|
+
return value;
|
|
534
|
+
}
|
|
535
|
+
resolveStringTemplate(template, previousOutputs) {
|
|
536
|
+
const templatePattern = /\{\{([^}]+)\}\}/g;
|
|
537
|
+
return template.replace(templatePattern, (match, path) => {
|
|
538
|
+
const trimmedPath = path.trim();
|
|
539
|
+
const value = this.resolvePath(trimmedPath, previousOutputs);
|
|
540
|
+
if (value !== undefined) {
|
|
541
|
+
return this.stringifyValue(value, match);
|
|
542
|
+
}
|
|
543
|
+
return match;
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
resolvePath(path, previousOutputs) {
|
|
547
|
+
const segments = path.split(".");
|
|
548
|
+
if (segments.length === 0) {
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
const nodeId = segments[0];
|
|
552
|
+
let nodeOutput = previousOutputs.get(nodeId);
|
|
553
|
+
if (nodeOutput === undefined) {
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
nodeOutput = this.extractFromWrapper(nodeOutput);
|
|
557
|
+
if (segments.length === 1) {
|
|
558
|
+
return nodeOutput;
|
|
559
|
+
}
|
|
560
|
+
let current = nodeOutput;
|
|
561
|
+
let startIndex = 1;
|
|
562
|
+
if (segments.length > 1 && (segments[1] === "output" || segments[1] === "result" || segments[1] === "metadata")) {
|
|
563
|
+
startIndex = 2;
|
|
564
|
+
}
|
|
565
|
+
for (let i = startIndex;i < segments.length; i++) {
|
|
566
|
+
if (current === null || current === undefined) {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
current = current[segments[i]];
|
|
570
|
+
}
|
|
571
|
+
return current;
|
|
572
|
+
}
|
|
573
|
+
extractFromWrapper(value) {
|
|
574
|
+
if (value === null || value === undefined) {
|
|
575
|
+
return value;
|
|
576
|
+
}
|
|
577
|
+
if (typeof value !== "object") {
|
|
578
|
+
return value;
|
|
579
|
+
}
|
|
580
|
+
if ("result" in value && "metadata" in value) {
|
|
581
|
+
return value.result;
|
|
582
|
+
}
|
|
583
|
+
if ("output" in value) {
|
|
584
|
+
return value.output;
|
|
585
|
+
}
|
|
586
|
+
return value;
|
|
587
|
+
}
|
|
588
|
+
stringifyValue(value, originalTemplate) {
|
|
589
|
+
if (value === undefined) {
|
|
590
|
+
return originalTemplate;
|
|
591
|
+
}
|
|
592
|
+
if (value === null) {
|
|
593
|
+
return "null";
|
|
594
|
+
}
|
|
595
|
+
if (typeof value === "string") {
|
|
596
|
+
return value;
|
|
597
|
+
}
|
|
598
|
+
return JSON.stringify(value);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
var init_workflow_node = () => {};
|
|
602
|
+
|
|
603
|
+
export { ToolNode, init_tool_node, SkillNode, init_skill_node, WorkflowNode, init_workflow_node };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__require
|
|
3
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
4
|
+
|
|
5
|
+
// packages/core/src/env/paths.ts
|
|
6
|
+
import os from "os";
|
|
7
|
+
import path from "path";
|
|
8
|
+
var APP_NAME = "roy-agent";
|
|
9
|
+
function getXdgBase() {
|
|
10
|
+
const home = os.homedir();
|
|
11
|
+
try {
|
|
12
|
+
const xdg = __require("xdg-basedir");
|
|
13
|
+
return {
|
|
14
|
+
config: xdg.xdgConfig || path.join(home, ".config"),
|
|
15
|
+
state: xdg.xdgState || path.join(home, ".local", "state"),
|
|
16
|
+
data: xdg.xdgData || path.join(home, ".local", "share"),
|
|
17
|
+
cache: xdg.xdgCache || path.join(home, ".cache")
|
|
18
|
+
};
|
|
19
|
+
} catch {
|
|
20
|
+
return {
|
|
21
|
+
config: path.join(home, ".config"),
|
|
22
|
+
state: path.join(home, ".local", "state"),
|
|
23
|
+
data: path.join(home, ".local", "share"),
|
|
24
|
+
cache: path.join(home, ".cache")
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function computeXDGPaths() {
|
|
29
|
+
const home = os.homedir();
|
|
30
|
+
const xdg = getXdgBase();
|
|
31
|
+
return {
|
|
32
|
+
home,
|
|
33
|
+
config: path.join(xdg.config, APP_NAME),
|
|
34
|
+
state: path.join(xdg.state, APP_NAME),
|
|
35
|
+
data: path.join(xdg.data, APP_NAME),
|
|
36
|
+
cache: path.join(xdg.cache, APP_NAME)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class XDGPathsCalculator {
|
|
41
|
+
_paths;
|
|
42
|
+
get paths() {
|
|
43
|
+
if (!this._paths) {
|
|
44
|
+
this._paths = computeXDGPaths();
|
|
45
|
+
}
|
|
46
|
+
return this._paths;
|
|
47
|
+
}
|
|
48
|
+
getPath(type) {
|
|
49
|
+
return this.paths[type];
|
|
50
|
+
}
|
|
51
|
+
getComponentPath(base, subPath) {
|
|
52
|
+
return path.join(this.paths[base], subPath);
|
|
53
|
+
}
|
|
54
|
+
reset() {
|
|
55
|
+
this._paths = undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
var XDG_PATHS = new XDGPathsCalculator;
|
|
59
|
+
function getXDGPaths() {
|
|
60
|
+
return XDG_PATHS.paths;
|
|
61
|
+
}
|
|
62
|
+
function getXDGPath(type) {
|
|
63
|
+
return XDG_PATHS.getPath(type);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { XDG_PATHS, getXDGPaths, getXDGPath };
|