@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
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentComponentAdapter,
|
|
3
3
|
init_agent_component_adapter
|
|
4
|
-
} from "./
|
|
5
|
-
import"./
|
|
4
|
+
} from "./roy-agent-core-rr9p1g43.js";
|
|
5
|
+
import"./roy-agent-core-8dvbn7tw.js";
|
|
6
|
+
import"./roy-agent-core-fs0mn2jk.js";
|
|
6
7
|
init_agent_component_adapter();
|
|
7
8
|
|
|
8
9
|
export {
|
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
initDatabase,
|
|
6
6
|
initializeTables,
|
|
7
7
|
resetDatabase
|
|
8
|
-
} from "./
|
|
9
|
-
import"./
|
|
10
|
-
import"./
|
|
11
|
-
import"./
|
|
12
|
-
import"./
|
|
8
|
+
} from "./roy-agent-core-qxybm159.js";
|
|
9
|
+
import"./roy-agent-core-yn761yve.js";
|
|
10
|
+
import"./roy-agent-core-1k28kg7h.js";
|
|
11
|
+
import"./roy-agent-core-j8zx62zr.js";
|
|
12
|
+
import"./roy-agent-core-fs0mn2jk.js";
|
|
13
13
|
export {
|
|
14
14
|
resetDatabase,
|
|
15
15
|
initializeTables,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createLogger,
|
|
3
3
|
init_logger
|
|
4
|
-
} from "./
|
|
4
|
+
} from "./roy-agent-core-yn761yve.js";
|
|
5
5
|
import {
|
|
6
6
|
__require
|
|
7
|
-
} from "./
|
|
7
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
8
8
|
|
|
9
|
-
// src/env/workflow/storage/sqlite.ts
|
|
9
|
+
// packages/core/src/env/workflow/storage/sqlite.ts
|
|
10
10
|
init_logger();
|
|
11
11
|
import { join } from "path";
|
|
12
12
|
var logger = createLogger("workflow:sqlite");
|
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
init_propagation,
|
|
4
4
|
init_tracer_provider,
|
|
5
5
|
propagation
|
|
6
|
-
} from "./
|
|
6
|
+
} from "./roy-agent-core-1k28kg7h.js";
|
|
7
7
|
import {
|
|
8
8
|
__toCommonJS
|
|
9
|
-
} from "./
|
|
9
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
10
10
|
|
|
11
|
-
// src/env/tool/built-in/bash.ts
|
|
11
|
+
// packages/core/src/env/tool/built-in/bash.ts
|
|
12
12
|
init_propagation();
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
import { exec } from "child_process";
|
|
@@ -156,7 +156,7 @@ var bashTool = {
|
|
|
156
156
|
}
|
|
157
157
|
};
|
|
158
158
|
|
|
159
|
-
// src/env/tool/built-in/echo.ts
|
|
159
|
+
// packages/core/src/env/tool/built-in/echo.ts
|
|
160
160
|
var echoTool = {
|
|
161
161
|
name: "echo",
|
|
162
162
|
description: "Echo a message to the console. Useful for logging in workflows.",
|
|
@@ -179,7 +179,7 @@ var echoTool = {
|
|
|
179
179
|
}
|
|
180
180
|
};
|
|
181
181
|
|
|
182
|
-
// src/env/tool/built-in/glob.ts
|
|
182
|
+
// packages/core/src/env/tool/built-in/glob.ts
|
|
183
183
|
import { z as z2 } from "zod";
|
|
184
184
|
import { glob as globAsync } from "glob";
|
|
185
185
|
var globTool = {
|
|
@@ -235,7 +235,7 @@ var globTool = {
|
|
|
235
235
|
}
|
|
236
236
|
};
|
|
237
237
|
|
|
238
|
-
// src/env/tool/built-in/read-file.ts
|
|
238
|
+
// packages/core/src/env/tool/built-in/read-file.ts
|
|
239
239
|
import { z as z3 } from "zod";
|
|
240
240
|
import { readFile } from "fs/promises";
|
|
241
241
|
var readFileTool = {
|
|
@@ -303,7 +303,7 @@ var readFileTool = {
|
|
|
303
303
|
}
|
|
304
304
|
};
|
|
305
305
|
|
|
306
|
-
// src/env/tool/built-in/write-file.ts
|
|
306
|
+
// packages/core/src/env/tool/built-in/write-file.ts
|
|
307
307
|
import { z as z4 } from "zod";
|
|
308
308
|
import { writeFile, mkdir } from "fs/promises";
|
|
309
309
|
import { dirname } from "path";
|
|
@@ -364,7 +364,7 @@ var writeFileTool = {
|
|
|
364
364
|
}
|
|
365
365
|
};
|
|
366
366
|
|
|
367
|
-
// src/env/tool/built-in/edit-file.ts
|
|
367
|
+
// packages/core/src/env/tool/built-in/edit-file.ts
|
|
368
368
|
import { z as z5 } from "zod";
|
|
369
369
|
import { readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
|
|
370
370
|
var editFileTool = {
|
|
@@ -435,7 +435,7 @@ function escapeRegExp(string) {
|
|
|
435
435
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
436
436
|
}
|
|
437
437
|
|
|
438
|
-
// src/env/tool/built-in/grep.ts
|
|
438
|
+
// packages/core/src/env/tool/built-in/grep.ts
|
|
439
439
|
import { z as z6 } from "zod";
|
|
440
440
|
import { readFile as readFile3 } from "fs/promises";
|
|
441
441
|
import { glob as globAsync2 } from "glob";
|
|
@@ -529,7 +529,7 @@ var grepTool = {
|
|
|
529
529
|
}
|
|
530
530
|
};
|
|
531
531
|
|
|
532
|
-
// src/env/tool/built-in/index.ts
|
|
532
|
+
// packages/core/src/env/tool/built-in/index.ts
|
|
533
533
|
function getAllBuiltInTools() {
|
|
534
534
|
return [
|
|
535
535
|
bashTool,
|
|
@@ -1,56 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AskUserError,
|
|
3
|
+
init_workflow_hil
|
|
4
|
+
} from "./roy-agent-core-8dvbn7tw.js";
|
|
1
5
|
import {
|
|
2
6
|
__esm
|
|
3
|
-
} from "./
|
|
4
|
-
|
|
5
|
-
// src/env/workflow/types/workflow-hil.ts
|
|
6
|
-
function createNodeInterruptEvent(runId, nodeId, nodeType, query, agentSessionId) {
|
|
7
|
-
return {
|
|
8
|
-
type: "node.interrupt",
|
|
9
|
-
run_id: runId,
|
|
10
|
-
timestamp: Date.now(),
|
|
11
|
-
node_id: nodeId,
|
|
12
|
-
node_type: nodeType,
|
|
13
|
-
query,
|
|
14
|
-
...agentSessionId ? { agent_session_id: agentSessionId } : {}
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
var AskUserError;
|
|
18
|
-
var init_workflow_hil = __esm(() => {
|
|
19
|
-
AskUserError = class AskUserError extends Error {
|
|
20
|
-
runId;
|
|
21
|
-
sessionId;
|
|
22
|
-
nodeId;
|
|
23
|
-
nodeType;
|
|
24
|
-
query;
|
|
25
|
-
agentSessionId;
|
|
26
|
-
timestamp;
|
|
27
|
-
type = "ask-user";
|
|
28
|
-
name = "AskUserError";
|
|
29
|
-
constructor(runId, sessionId, nodeId, nodeType, query, agentSessionId, timestamp = Date.now()) {
|
|
30
|
-
super(`[${nodeType}:${nodeId}] Ask user: ${query}`);
|
|
31
|
-
this.runId = runId;
|
|
32
|
-
this.sessionId = sessionId;
|
|
33
|
-
this.nodeId = nodeId;
|
|
34
|
-
this.nodeType = nodeType;
|
|
35
|
-
this.query = query;
|
|
36
|
-
this.agentSessionId = agentSessionId;
|
|
37
|
-
this.timestamp = timestamp;
|
|
38
|
-
}
|
|
39
|
-
toEvent() {
|
|
40
|
-
return {
|
|
41
|
-
type: "workflow.ask-user",
|
|
42
|
-
run_id: this.runId,
|
|
43
|
-
timestamp: this.timestamp,
|
|
44
|
-
session_id: this.sessionId,
|
|
45
|
-
node_id: this.nodeId,
|
|
46
|
-
node_type: this.nodeType,
|
|
47
|
-
query: this.query
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
});
|
|
7
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
52
8
|
|
|
53
|
-
// src/env/workflow/nodes/agent-component-adapter.ts
|
|
9
|
+
// packages/core/src/env/workflow/nodes/agent-component-adapter.ts
|
|
54
10
|
class AgentComponentAdapter {
|
|
55
11
|
agentComponent;
|
|
56
12
|
options;
|
|
@@ -246,4 +202,4 @@ var init_agent_component_adapter = __esm(() => {
|
|
|
246
202
|
init_workflow_hil();
|
|
247
203
|
});
|
|
248
204
|
|
|
249
|
-
export {
|
|
205
|
+
export { AgentComponentAdapter, init_agent_component_adapter };
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_decorator_node
|
|
3
|
+
} from "./roy-agent-core-3tnb2005.js";
|
|
4
|
+
|
|
5
|
+
// packages/core/src/env/workflow/decorators/workflow.ts
|
|
6
|
+
import"reflect-metadata";
|
|
7
|
+
|
|
8
|
+
// packages/core/src/env/workflow/metadata/keys.ts
|
|
9
|
+
var WORKFLOW_METADATA_KEY = Symbol("workflow:metadata");
|
|
10
|
+
var NODE_METADATA_KEY = Symbol("workflow:node");
|
|
11
|
+
var EDGE_METADATA_KEY = Symbol("workflow:edges");
|
|
12
|
+
|
|
13
|
+
// packages/core/src/env/workflow/decorators/workflow.ts
|
|
14
|
+
function Workflow(options) {
|
|
15
|
+
return function(target) {
|
|
16
|
+
const metadata = {
|
|
17
|
+
name: options.name,
|
|
18
|
+
version: options.version || "1.0",
|
|
19
|
+
description: options.description,
|
|
20
|
+
entry: options.entry,
|
|
21
|
+
config: options.config,
|
|
22
|
+
tags: options.tags || [],
|
|
23
|
+
author: options.author
|
|
24
|
+
};
|
|
25
|
+
Reflect.defineMetadata(WORKFLOW_METADATA_KEY, metadata, target);
|
|
26
|
+
return target;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function getWorkflowMetadata(target) {
|
|
30
|
+
return Reflect.getMetadata(WORKFLOW_METADATA_KEY, target);
|
|
31
|
+
}
|
|
32
|
+
// packages/core/src/env/workflow/decorators/node-as.ts
|
|
33
|
+
import"reflect-metadata";
|
|
34
|
+
function NodeAs(options = {}) {
|
|
35
|
+
return function(target, propertyKey, descriptor) {
|
|
36
|
+
const methodName = String(propertyKey);
|
|
37
|
+
const nodeMetadata = {
|
|
38
|
+
nodeId: options.nodeId || methodName,
|
|
39
|
+
nodeType: options.nodeType || "tool",
|
|
40
|
+
name: options.name,
|
|
41
|
+
dependsOn: normalizeDependsOn(options.dependsOn),
|
|
42
|
+
condition: options.condition,
|
|
43
|
+
retry: options.retry,
|
|
44
|
+
timeout: options.timeout,
|
|
45
|
+
config: options.config || {},
|
|
46
|
+
methodName,
|
|
47
|
+
method: descriptor.value
|
|
48
|
+
};
|
|
49
|
+
const existingNodes = Reflect.getMetadata(NODE_METADATA_KEY, target) || [];
|
|
50
|
+
const existingIndex = existingNodes.findIndex((n) => n.methodName === methodName);
|
|
51
|
+
if (existingIndex >= 0) {
|
|
52
|
+
existingNodes[existingIndex] = nodeMetadata;
|
|
53
|
+
} else {
|
|
54
|
+
existingNodes.push(nodeMetadata);
|
|
55
|
+
}
|
|
56
|
+
Reflect.defineMetadata(NODE_METADATA_KEY, existingNodes, target);
|
|
57
|
+
return descriptor;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function normalizeDependsOn(dependsOn) {
|
|
61
|
+
if (!dependsOn) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
return Array.isArray(dependsOn) ? dependsOn : [dependsOn];
|
|
65
|
+
}
|
|
66
|
+
function getNodeMetadatas(target) {
|
|
67
|
+
return Reflect.getMetadata(NODE_METADATA_KEY, target) || [];
|
|
68
|
+
}
|
|
69
|
+
// packages/core/src/env/workflow/decorators/edge.ts
|
|
70
|
+
import"reflect-metadata";
|
|
71
|
+
function Edge(from, to) {
|
|
72
|
+
return function(target, propertyKey, descriptor) {
|
|
73
|
+
const edge = { from, to };
|
|
74
|
+
const existingEdges = Reflect.getMetadata(EDGE_METADATA_KEY, target) || [];
|
|
75
|
+
existingEdges.push(edge);
|
|
76
|
+
Reflect.defineMetadata(EDGE_METADATA_KEY, existingEdges, target);
|
|
77
|
+
return descriptor;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function WorkflowEdges(edges) {
|
|
81
|
+
return function(target) {
|
|
82
|
+
const edgeMetadatas = edges.map((edge) => ({
|
|
83
|
+
from: edge.from,
|
|
84
|
+
to: edge.to,
|
|
85
|
+
condition: edge.condition
|
|
86
|
+
}));
|
|
87
|
+
Reflect.defineMetadata(EDGE_METADATA_KEY, edgeMetadatas, target);
|
|
88
|
+
return target;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function getEdgeMetadatas(target) {
|
|
92
|
+
return Reflect.getMetadata(EDGE_METADATA_KEY, target) || [];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// packages/core/src/env/workflow/decorators/index.ts
|
|
96
|
+
init_decorator_node();
|
|
97
|
+
|
|
98
|
+
// packages/core/src/env/workflow/extractor/workflow-converter.ts
|
|
99
|
+
import"reflect-metadata";
|
|
100
|
+
class WorkflowConverter {
|
|
101
|
+
static extractWorkflowMetadata(targetClass) {
|
|
102
|
+
return getWorkflowMetadata(targetClass);
|
|
103
|
+
}
|
|
104
|
+
static extractNodeMetadatas(targetClass) {
|
|
105
|
+
return getNodeMetadatas(targetClass.prototype);
|
|
106
|
+
}
|
|
107
|
+
static extractEdgeMetadatas(targetClass) {
|
|
108
|
+
return getEdgeMetadatas(targetClass);
|
|
109
|
+
}
|
|
110
|
+
static fromClass(targetClass, instance) {
|
|
111
|
+
const workflowMeta = this.extractWorkflowMetadata(targetClass);
|
|
112
|
+
if (!workflowMeta) {
|
|
113
|
+
throw new Error("Class must be decorated with @Workflow");
|
|
114
|
+
}
|
|
115
|
+
const nodeMetadatas = this.extractNodeMetadatas(targetClass);
|
|
116
|
+
if (nodeMetadatas.length === 0) {
|
|
117
|
+
throw new Error("At least one method must be decorated with @NodeAs");
|
|
118
|
+
}
|
|
119
|
+
const edgeMetadatas = this.extractEdgeMetadatas(targetClass);
|
|
120
|
+
const nodeMap = this.buildNodeMap(nodeMetadatas, edgeMetadatas);
|
|
121
|
+
const nodes = Array.from(nodeMap.values()).map((meta) => ({
|
|
122
|
+
id: meta.nodeId,
|
|
123
|
+
type: meta.nodeType,
|
|
124
|
+
name: meta.name,
|
|
125
|
+
config: {
|
|
126
|
+
...meta.config,
|
|
127
|
+
_methodName: meta.methodName,
|
|
128
|
+
_instance: instance
|
|
129
|
+
},
|
|
130
|
+
depends_on: meta.dependsOn,
|
|
131
|
+
condition: meta.condition,
|
|
132
|
+
retry: meta.retry,
|
|
133
|
+
timeout: meta.timeout
|
|
134
|
+
}));
|
|
135
|
+
const entry = workflowMeta.entry || nodeMetadatas[0]?.nodeId || "unknown";
|
|
136
|
+
return {
|
|
137
|
+
name: workflowMeta.name,
|
|
138
|
+
version: workflowMeta.version || "1.0",
|
|
139
|
+
description: workflowMeta.description,
|
|
140
|
+
config: workflowMeta.config || {},
|
|
141
|
+
nodes,
|
|
142
|
+
entry,
|
|
143
|
+
outputs: [],
|
|
144
|
+
metadata: {
|
|
145
|
+
tags: workflowMeta.tags || [],
|
|
146
|
+
author: workflowMeta.author
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
static buildNodeMap(nodeMetadatas, edgeMetadatas) {
|
|
151
|
+
const nodeMap = new Map;
|
|
152
|
+
for (const nodeMeta of nodeMetadatas) {
|
|
153
|
+
nodeMap.set(nodeMeta.nodeId, { ...nodeMeta });
|
|
154
|
+
}
|
|
155
|
+
for (const edge of edgeMetadatas) {
|
|
156
|
+
const targetNode = nodeMap.get(edge.to);
|
|
157
|
+
if (targetNode) {
|
|
158
|
+
if (!targetNode.dependsOn.includes(edge.from)) {
|
|
159
|
+
targetNode.dependsOn = [...targetNode.dependsOn, edge.from];
|
|
160
|
+
}
|
|
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
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return nodeMap;
|
|
171
|
+
}
|
|
172
|
+
static validateWorkflowClass(targetClass) {
|
|
173
|
+
const errors = [];
|
|
174
|
+
const warnings = [];
|
|
175
|
+
const workflowMeta = this.extractWorkflowMetadata(targetClass);
|
|
176
|
+
if (!workflowMeta) {
|
|
177
|
+
errors.push("Class must be decorated with @Workflow");
|
|
178
|
+
return { valid: false, errors, warnings };
|
|
179
|
+
}
|
|
180
|
+
const nodeMetadatas = this.extractNodeMetadatas(targetClass);
|
|
181
|
+
if (nodeMetadatas.length === 0) {
|
|
182
|
+
errors.push("At least one method must be decorated with @NodeAs");
|
|
183
|
+
return { valid: false, errors, warnings };
|
|
184
|
+
}
|
|
185
|
+
const entry = workflowMeta.entry;
|
|
186
|
+
if (entry) {
|
|
187
|
+
const entries = Array.isArray(entry) ? entry : [entry];
|
|
188
|
+
for (const e of entries) {
|
|
189
|
+
if (!nodeMetadatas.find((n) => n.nodeId === e)) {
|
|
190
|
+
errors.push(`Entry node '${e}' not found`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
for (const node of nodeMetadatas) {
|
|
195
|
+
for (const dep of node.dependsOn) {
|
|
196
|
+
if (!nodeMetadatas.find((n) => n.nodeId === dep)) {
|
|
197
|
+
errors.push(`Node '${node.nodeId}' depends on non-existent node '${dep}'`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (this.hasCycle(nodeMetadatas)) {
|
|
202
|
+
errors.push("Workflow contains a cycle");
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
valid: errors.length === 0,
|
|
206
|
+
errors,
|
|
207
|
+
warnings
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
static hasCycle(nodeMetadatas) {
|
|
211
|
+
const visited = new Set;
|
|
212
|
+
const recStack = new Set;
|
|
213
|
+
const adjList = new Map;
|
|
214
|
+
for (const node of nodeMetadatas) {
|
|
215
|
+
adjList.set(node.nodeId, []);
|
|
216
|
+
}
|
|
217
|
+
for (const node of nodeMetadatas) {
|
|
218
|
+
for (const dep of node.dependsOn) {
|
|
219
|
+
const deps = adjList.get(dep);
|
|
220
|
+
if (deps) {
|
|
221
|
+
deps.push(node.nodeId);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const dfs = (nodeId) => {
|
|
226
|
+
visited.add(nodeId);
|
|
227
|
+
recStack.add(nodeId);
|
|
228
|
+
const neighbors = adjList.get(nodeId) || [];
|
|
229
|
+
for (const neighbor of neighbors) {
|
|
230
|
+
if (!visited.has(neighbor)) {
|
|
231
|
+
if (dfs(neighbor)) {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
} else if (recStack.has(neighbor)) {
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
recStack.delete(nodeId);
|
|
239
|
+
return false;
|
|
240
|
+
};
|
|
241
|
+
for (const node of nodeMetadatas) {
|
|
242
|
+
if (!visited.has(node.nodeId)) {
|
|
243
|
+
if (dfs(node.nodeId)) {
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
static async executeNode(nodeDef, context) {
|
|
251
|
+
const instance = nodeDef.config._instance;
|
|
252
|
+
const methodName = nodeDef.config._methodName;
|
|
253
|
+
if (!instance || !methodName) {
|
|
254
|
+
return { output: undefined, error: new Error("Missing method information") };
|
|
255
|
+
}
|
|
256
|
+
const method = instance[methodName];
|
|
257
|
+
if (typeof method !== "function") {
|
|
258
|
+
return { output: undefined, error: new Error(`Method ${methodName} is not a function`) };
|
|
259
|
+
}
|
|
260
|
+
const deps = nodeDef.depends_on || [];
|
|
261
|
+
let input = context.input;
|
|
262
|
+
if (deps.length > 0) {
|
|
263
|
+
input = {};
|
|
264
|
+
for (const depId of deps) {
|
|
265
|
+
input[depId] = context.previousOutputs.get(depId);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
const result = await method.call(instance, input);
|
|
270
|
+
return { output: result };
|
|
271
|
+
} catch (error) {
|
|
272
|
+
return {
|
|
273
|
+
output: undefined,
|
|
274
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// packages/core/src/env/workflow/utils/create-workflow.ts
|
|
280
|
+
function createWorkflowFromClass(targetClass, options) {
|
|
281
|
+
const instance = options?.instance ?? new targetClass(...options?.constructorArgs ?? []);
|
|
282
|
+
return WorkflowConverter.fromClass(targetClass, instance);
|
|
283
|
+
}
|
|
284
|
+
export { Workflow, getWorkflowMetadata, NodeAs, getNodeMetadatas, Edge, WorkflowEdges, getEdgeMetadatas, WorkflowConverter, createWorkflowFromClass };
|