@ai-setting/roy-agent-core 1.5.5 → 1.5.6
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/config/index.d.ts +1250 -0
- package/dist/env/agent/index.d.ts +2279 -0
- package/dist/env/agent/index.js +1 -1
- package/dist/env/commands/index.d.ts +1131 -0
- package/dist/env/debug/formatters/index.d.ts +236 -0
- package/dist/env/debug/index.d.ts +1652 -0
- package/dist/env/hook/index.d.ts +279 -0
- package/dist/env/index.d.ts +3460 -0
- package/dist/env/index.js +8 -8
- package/dist/env/llm/index.d.ts +1760 -0
- package/dist/env/log-trace/index.d.ts +1574 -0
- package/dist/env/mcp/index.d.ts +1331 -0
- package/dist/env/mcp/index.js +2 -2
- package/dist/env/mcp/tool/index.d.ts +183 -0
- package/dist/env/mcp/tool/index.js +1 -1
- package/dist/env/memory/built-in/index.d.ts +232 -0
- package/dist/env/memory/index.d.ts +1799 -0
- package/dist/env/memory/plugin/index.d.ts +747 -0
- package/dist/env/prompt/index.d.ts +1164 -0
- package/dist/env/session/index.d.ts +1908 -0
- package/dist/env/session/storage/index.d.ts +564 -0
- package/dist/env/skill/index.d.ts +1266 -0
- package/dist/env/skill/tool/index.d.ts +193 -0
- package/dist/env/task/delegate/index.d.ts +1622 -0
- package/dist/env/task/hooks/index.d.ts +607 -0
- package/dist/env/task/index.d.ts +1415 -0
- package/dist/env/task/plugins/index.d.ts +462 -0
- package/dist/env/task/storage/index.d.ts +224 -0
- package/dist/env/task/tools/index.d.ts +1464 -0
- package/dist/env/task/tools/operation/index.d.ts +1463 -0
- package/dist/env/tool/built-in/index.d.ts +218 -0
- package/dist/env/tool/index.d.ts +1396 -0
- package/dist/env/workflow/decorators/index.d.ts +2161 -0
- package/dist/env/workflow/engine/index.d.ts +3453 -0
- package/dist/env/workflow/engine/index.js +4 -4
- package/dist/env/workflow/index.d.ts +3546 -0
- package/dist/env/workflow/index.js +9 -5
- package/dist/env/workflow/nodes/index.d.ts +2092 -0
- package/dist/env/workflow/nodes/index.js +1 -1
- package/dist/env/workflow/service/index.d.ts +227 -0
- package/dist/env/workflow/storage/index.d.ts +165 -0
- package/dist/env/workflow/tools/index.d.ts +416 -0
- package/dist/env/workflow/types/index.d.ts +2255 -0
- package/dist/env/workflow/types/index.js +5 -1
- package/dist/env/workflow/utils/index.d.ts +2031 -0
- package/dist/index.d.ts +7837 -0
- package/dist/index.js +8 -8
- package/dist/shared/@ai-setting/{roy-agent-core-nhdrvfp8.js → roy-agent-core-1akcqxj9.js} +49 -3
- package/dist/shared/@ai-setting/{roy-agent-core-rzp9kxne.js → roy-agent-core-5x94xmt6.js} +14 -5
- package/dist/shared/@ai-setting/{roy-agent-core-pc9g3962.js → roy-agent-core-69jskqjg.js} +41 -66
- package/dist/shared/@ai-setting/{roy-agent-core-f0cc2ep9.js → roy-agent-core-b0x5dda6.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-ya8krqzt.js → roy-agent-core-dc497hmk.js} +5 -4
- package/dist/shared/@ai-setting/{roy-agent-core-z2t8hse8.js → roy-agent-core-dh9d7a3m.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-qw0ebh1d.js → roy-agent-core-gq20wsgv.js} +49 -17
- package/dist/shared/@ai-setting/{roy-agent-core-3agad0d9.js → roy-agent-core-jvatggbb.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-c0jcxnf4.js → roy-agent-core-pjr12nnd.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-kkp3qmc3.js → roy-agent-core-wrcy0h6z.js} +132 -180
- package/package.json +11 -9
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentComponentAdapter,
|
|
3
3
|
init_agent_component_adapter
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-69jskqjg.js";
|
|
5
5
|
import {
|
|
6
6
|
SkillNode,
|
|
7
7
|
ToolNode,
|
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
init_skill_node,
|
|
10
10
|
init_tool_node,
|
|
11
11
|
init_workflow_node
|
|
12
|
-
} from "./roy-agent-core-
|
|
12
|
+
} from "./roy-agent-core-jvatggbb.js";
|
|
13
13
|
import {
|
|
14
14
|
createWorkflowEvent,
|
|
15
15
|
init_event,
|
|
16
16
|
init_types
|
|
17
|
-
} from "./roy-agent-core-
|
|
17
|
+
} from "./roy-agent-core-5x94xmt6.js";
|
|
18
18
|
import {
|
|
19
19
|
AskUserError,
|
|
20
20
|
createNodeInterruptEvent,
|
|
@@ -645,7 +645,7 @@ var init_executor = __esm(() => {
|
|
|
645
645
|
node_id: nodeId,
|
|
646
646
|
input: context.input
|
|
647
647
|
}));
|
|
648
|
-
await this.
|
|
648
|
+
await this.writeNodeStart(context.sessionId, nodeId, nodeType, context.input, agentSessionId);
|
|
649
649
|
const abortController = new AbortController;
|
|
650
650
|
this.abortControllers.set(nodeId, abortController);
|
|
651
651
|
const timeout = definition.timeout ?? this.options.globalTimeout ?? undefined;
|
|
@@ -673,14 +673,14 @@ var init_executor = __esm(() => {
|
|
|
673
673
|
stack: errorStack
|
|
674
674
|
}
|
|
675
675
|
}));
|
|
676
|
-
await this.
|
|
676
|
+
await this.writeNodeEnd(context.sessionId, nodeId, nodeType, result.output, errorMessage, result.durationMs ?? 0, agentSessionId);
|
|
677
677
|
} else {
|
|
678
678
|
await this.eventBus.publish(createWorkflowEvent("node.completed", context.runId, {
|
|
679
679
|
node_id: nodeId,
|
|
680
680
|
output: result.output,
|
|
681
681
|
duration_ms: result.durationMs ?? 0
|
|
682
682
|
}));
|
|
683
|
-
await this.
|
|
683
|
+
await this.writeNodeEnd(context.sessionId, nodeId, nodeType, result.output, undefined, result.durationMs ?? 0, agentSessionId);
|
|
684
684
|
}
|
|
685
685
|
return result;
|
|
686
686
|
} finally {
|
|
@@ -800,12 +800,12 @@ var init_executor = __esm(() => {
|
|
|
800
800
|
sleep(ms) {
|
|
801
801
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
802
802
|
}
|
|
803
|
-
async
|
|
803
|
+
async writeNodeStart(sessionId, nodeId, nodeType, input, agentSessionId) {
|
|
804
804
|
if (!this.sessionComponent)
|
|
805
805
|
return;
|
|
806
806
|
const startTime = Date.now();
|
|
807
807
|
const part = {
|
|
808
|
-
type: "workflow-node-
|
|
808
|
+
type: "workflow-node-start",
|
|
809
809
|
nodeId,
|
|
810
810
|
nodeType,
|
|
811
811
|
input,
|
|
@@ -814,12 +814,12 @@ var init_executor = __esm(() => {
|
|
|
814
814
|
};
|
|
815
815
|
const contentSummary = this.summarizeCall(nodeType, nodeId, input);
|
|
816
816
|
await this.sessionComponent.addMessage(sessionId, {
|
|
817
|
-
role: "workflow.node.
|
|
817
|
+
role: "workflow.node.start",
|
|
818
818
|
content: contentSummary,
|
|
819
819
|
parts: [part],
|
|
820
820
|
metadata: {
|
|
821
821
|
_workflowNodeMetadata: true,
|
|
822
|
-
type: "workflow.node.
|
|
822
|
+
type: "workflow.node.start",
|
|
823
823
|
workflowNodeId: nodeId,
|
|
824
824
|
workflowNodeType: nodeType,
|
|
825
825
|
...agentSessionId ? { agentSessionId } : {}
|
|
@@ -831,11 +831,12 @@ var init_executor = __esm(() => {
|
|
|
831
831
|
return `[${nodeType}] ${nodeId} started`;
|
|
832
832
|
}
|
|
833
833
|
if (typeof input === "object") {
|
|
834
|
-
const
|
|
834
|
+
const inputObj = input;
|
|
835
|
+
const keys = Object.keys(inputObj);
|
|
835
836
|
if (keys.length === 0) {
|
|
836
837
|
return `[${nodeType}] ${nodeId} started`;
|
|
837
838
|
}
|
|
838
|
-
const summary = keys.slice(0, 3).map((k) => `${k}: ${JSON.stringify(
|
|
839
|
+
const summary = keys.slice(0, 3).map((k) => `${k}: ${JSON.stringify(inputObj[k])}`).join(", ");
|
|
839
840
|
return `[${nodeType}] ${nodeId}: ${summary}`;
|
|
840
841
|
}
|
|
841
842
|
return `[${nodeType}] ${nodeId}: ${String(input)}`;
|
|
@@ -866,28 +867,30 @@ var init_executor = __esm(() => {
|
|
|
866
867
|
}
|
|
867
868
|
});
|
|
868
869
|
}
|
|
869
|
-
async
|
|
870
|
+
async writeNodeEnd(sessionId, nodeId, nodeType, output, error, durationMs, agentSessionId) {
|
|
870
871
|
if (!this.sessionComponent)
|
|
871
872
|
return;
|
|
872
873
|
const part = {
|
|
873
|
-
type: "workflow-node-
|
|
874
|
+
type: "workflow-node-end",
|
|
874
875
|
nodeId,
|
|
875
876
|
nodeType,
|
|
876
877
|
output,
|
|
877
878
|
error,
|
|
878
|
-
durationMs
|
|
879
|
+
durationMs,
|
|
880
|
+
...agentSessionId ? { agentSessionId } : {}
|
|
879
881
|
};
|
|
880
882
|
const contentSummary = this.summarizeResult(nodeId, output, error, durationMs);
|
|
881
883
|
await this.sessionComponent.addMessage(sessionId, {
|
|
882
|
-
role: "workflow.node.
|
|
884
|
+
role: "workflow.node.end",
|
|
883
885
|
content: contentSummary,
|
|
884
886
|
parts: [part],
|
|
885
887
|
metadata: {
|
|
886
888
|
_workflowNodeMetadata: true,
|
|
887
|
-
type: "workflow.node.
|
|
889
|
+
type: "workflow.node.end",
|
|
888
890
|
workflowNodeId: nodeId,
|
|
889
891
|
workflowNodeType: nodeType,
|
|
890
|
-
success: !error
|
|
892
|
+
success: !error,
|
|
893
|
+
...agentSessionId ? { agentSessionId } : {}
|
|
891
894
|
}
|
|
892
895
|
});
|
|
893
896
|
}
|
|
@@ -910,21 +913,26 @@ var init_executor = __esm(() => {
|
|
|
910
913
|
const truncated = strOutput.length > 100 ? strOutput.substring(0, 100) + "..." : strOutput;
|
|
911
914
|
return `✅ ${nodeId}: ${truncated} (${durationMs}ms)`;
|
|
912
915
|
}
|
|
913
|
-
async writeNodeResume(sessionId, response) {
|
|
916
|
+
async writeNodeResume(sessionId, nodeId, response, agentSessionId) {
|
|
914
917
|
if (!this.sessionComponent)
|
|
915
918
|
return;
|
|
916
919
|
const timestamp = Date.now();
|
|
917
920
|
const part = {
|
|
918
921
|
type: "workflow-node-resume",
|
|
922
|
+
nodeId,
|
|
919
923
|
response,
|
|
920
|
-
timestamp
|
|
924
|
+
timestamp,
|
|
925
|
+
...agentSessionId ? { agentSessionId } : {}
|
|
921
926
|
};
|
|
922
927
|
await this.sessionComponent.addMessage(sessionId, {
|
|
923
928
|
role: "workflow.node.resume",
|
|
924
929
|
content: response,
|
|
925
930
|
parts: [part],
|
|
926
931
|
metadata: {
|
|
927
|
-
_workflowNodeMetadata: true
|
|
932
|
+
_workflowNodeMetadata: true,
|
|
933
|
+
type: "workflow.node.resume",
|
|
934
|
+
workflowNodeId: nodeId,
|
|
935
|
+
...agentSessionId ? { agentSessionId } : {}
|
|
928
936
|
}
|
|
929
937
|
});
|
|
930
938
|
}
|
|
@@ -933,14 +941,14 @@ var init_executor = __esm(() => {
|
|
|
933
941
|
TracedAs("workflow.executor.executeNode", { recordParams: true, recordResult: true, log: true })
|
|
934
942
|
], Executor.prototype, "executeNode", null);
|
|
935
943
|
__legacyDecorateClassTS([
|
|
936
|
-
TracedAs("workflow.executor.
|
|
937
|
-
], Executor.prototype, "
|
|
944
|
+
TracedAs("workflow.executor.writeNodeStart", { recordParams: true, recordResult: true, log: true })
|
|
945
|
+
], Executor.prototype, "writeNodeStart", null);
|
|
938
946
|
__legacyDecorateClassTS([
|
|
939
947
|
TracedAs("workflow.executor.writeNodeInterrupt", { recordParams: true, recordResult: true, log: true })
|
|
940
948
|
], Executor.prototype, "writeNodeInterrupt", null);
|
|
941
949
|
__legacyDecorateClassTS([
|
|
942
|
-
TracedAs("workflow.executor.
|
|
943
|
-
], Executor.prototype, "
|
|
950
|
+
TracedAs("workflow.executor.writeNodeEnd", { recordParams: true, recordResult: true, log: true })
|
|
951
|
+
], Executor.prototype, "writeNodeEnd", null);
|
|
944
952
|
__legacyDecorateClassTS([
|
|
945
953
|
TracedAs("workflow.executor.writeNodeResume", { recordParams: true, recordResult: true, log: true })
|
|
946
954
|
], Executor.prototype, "writeNodeResume", null);
|
|
@@ -978,9 +986,9 @@ var init_agent_node = __esm(() => {
|
|
|
978
986
|
});
|
|
979
987
|
}
|
|
980
988
|
}
|
|
981
|
-
const
|
|
989
|
+
const userQuery = context.input?.userQuery;
|
|
982
990
|
let agentSessionId = context.agentSessionId;
|
|
983
|
-
if (!
|
|
991
|
+
if (!agentSessionId && context.sessionComponent) {
|
|
984
992
|
agentSessionId = await this.createAgentSubSession(context);
|
|
985
993
|
context.agentSessionId = agentSessionId;
|
|
986
994
|
}
|
|
@@ -996,7 +1004,10 @@ var init_agent_node = __esm(() => {
|
|
|
996
1004
|
nodeId: this.definition.id,
|
|
997
1005
|
agentSessionId
|
|
998
1006
|
};
|
|
999
|
-
const resumeOptions =
|
|
1007
|
+
const resumeOptions = {
|
|
1008
|
+
userQuery,
|
|
1009
|
+
agentSessionId
|
|
1010
|
+
};
|
|
1000
1011
|
const result = await this.agentRunner.run(agentConfig, resumeOptions);
|
|
1001
1012
|
const duration = Date.now() - startTime;
|
|
1002
1013
|
return {
|
|
@@ -1030,14 +1041,15 @@ var init_agent_node = __esm(() => {
|
|
|
1030
1041
|
if (!sessionComponent) {
|
|
1031
1042
|
return "";
|
|
1032
1043
|
}
|
|
1033
|
-
const
|
|
1044
|
+
const nodeId = this.definition.id || "unknown";
|
|
1045
|
+
const agentSessionId = `agent_${nodeId}_${Date.now()}`;
|
|
1034
1046
|
await sessionComponent.create({
|
|
1035
1047
|
id: agentSessionId,
|
|
1036
|
-
title: `Agent: ${
|
|
1048
|
+
title: `Agent: ${nodeId}`,
|
|
1037
1049
|
metadata: {
|
|
1038
1050
|
type: "agent",
|
|
1039
1051
|
parentSessionId: context.sessionId,
|
|
1040
|
-
nodeId
|
|
1052
|
+
nodeId,
|
|
1041
1053
|
workflowName: context.workflowName
|
|
1042
1054
|
}
|
|
1043
1055
|
});
|
|
@@ -1076,7 +1088,17 @@ var init_agent_node = __esm(() => {
|
|
|
1076
1088
|
}
|
|
1077
1089
|
let resolved = template;
|
|
1078
1090
|
resolved = resolved.replace(/\{\{input\.([^}]+)\}\}/g, (match, path) => {
|
|
1079
|
-
|
|
1091
|
+
let value = this.getNestedValue(context.input, path);
|
|
1092
|
+
if (value === undefined && context.workflowInput) {
|
|
1093
|
+
value = this.getNestedValue(context.workflowInput, path);
|
|
1094
|
+
}
|
|
1095
|
+
return this.stringifyValue(value, match);
|
|
1096
|
+
});
|
|
1097
|
+
resolved = resolved.replace(/\{\{inputs\.([^}]+)\}\}/g, (match, path) => {
|
|
1098
|
+
let value = this.getNestedValue(context.input, path);
|
|
1099
|
+
if (value === undefined && context.workflowInput) {
|
|
1100
|
+
value = this.getNestedValue(context.workflowInput, path);
|
|
1101
|
+
}
|
|
1080
1102
|
return this.stringifyValue(value, match);
|
|
1081
1103
|
});
|
|
1082
1104
|
resolved = resolved.replace(/\{\{nodes\.([^}]+)\}\}/g, (match, path) => {
|
|
@@ -1430,7 +1452,9 @@ var init_engine = __esm(() => {
|
|
|
1430
1452
|
workflowId,
|
|
1431
1453
|
workflowName,
|
|
1432
1454
|
workflowVersion: workflowDef.version,
|
|
1433
|
-
status: "running"
|
|
1455
|
+
status: "running",
|
|
1456
|
+
input: options?.input,
|
|
1457
|
+
agentSessions: []
|
|
1434
1458
|
};
|
|
1435
1459
|
await this.sessionComponent.create({
|
|
1436
1460
|
id: sessionId,
|
|
@@ -1450,8 +1474,23 @@ var init_engine = __esm(() => {
|
|
|
1450
1474
|
if (metadata.status === "failed") {
|
|
1451
1475
|
return { runId: this.getRunIdFromSessionId(sessionId), status: "failed" };
|
|
1452
1476
|
}
|
|
1477
|
+
if (options?.input && this.sessionComponent) {
|
|
1478
|
+
const hasNewInput = typeof options.input === "string" ? options.input !== undefined && options.input !== "" : Object.keys(options.input).length > 0;
|
|
1479
|
+
if (hasNewInput) {
|
|
1480
|
+
const existingInput = metadata.input || {};
|
|
1481
|
+
const newInput = typeof options.input === "string" ? { userQuery: options.input } : options.input;
|
|
1482
|
+
await this.sessionComponent.update(sessionId, {
|
|
1483
|
+
metadata: {
|
|
1484
|
+
...metadata,
|
|
1485
|
+
input: { ...existingInput, ...newInput }
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
metadata.input = { ...existingInput, ...newInput };
|
|
1489
|
+
logger.info(`[WorkflowEngine] Updated session ${sessionId} input with resume user input`);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1453
1492
|
const messages = this.sessionComponent ? await this.sessionComponent.getMessages(sessionId) : [];
|
|
1454
|
-
const { inferNextNode } = await import("./roy-agent-core-
|
|
1493
|
+
const { inferNextNode } = await import("./roy-agent-core-gq20wsgv.js");
|
|
1455
1494
|
const entry = workflowDef.entry;
|
|
1456
1495
|
const entryNode = Array.isArray(entry) ? entry[0] : entry;
|
|
1457
1496
|
const resumePoint = inferNextNode(messages, {
|
|
@@ -1535,12 +1574,16 @@ var init_engine = __esm(() => {
|
|
|
1535
1574
|
agentSessionId = resumePoint.agentSessionId;
|
|
1536
1575
|
break;
|
|
1537
1576
|
}
|
|
1538
|
-
|
|
1577
|
+
let inputForExecution;
|
|
1578
|
+
if (typeof options?.input === "string") {
|
|
1579
|
+
inputForExecution = { userQuery: options.input };
|
|
1580
|
+
} else if (options?.input && typeof options.input === "object") {
|
|
1581
|
+
inputForExecution = options.input;
|
|
1582
|
+
}
|
|
1539
1583
|
this.scheduleAndExecute(sessionState, {
|
|
1540
|
-
input:
|
|
1584
|
+
input: inputForExecution,
|
|
1541
1585
|
pendingNodeId,
|
|
1542
|
-
agentSessionId
|
|
1543
|
-
userResponse
|
|
1586
|
+
agentSessionId
|
|
1544
1587
|
}).catch((error) => {
|
|
1545
1588
|
logger.error(`Workflow ${sessionId} scheduling error:`, error);
|
|
1546
1589
|
this.failWorkflow(sessionState, error);
|
|
@@ -1579,117 +1622,6 @@ var init_engine = __esm(() => {
|
|
|
1579
1622
|
await sessionState.eventBus.publish(createWorkflowEvent("workflow.paused", this.getRunIdFromSessionId(sessionId), {}));
|
|
1580
1623
|
logger.info(`[WorkflowEngine] Workflow paused: ${sessionId}`);
|
|
1581
1624
|
}
|
|
1582
|
-
async resume(sessionId, options) {
|
|
1583
|
-
const sessionState = this.activeSessions.get(sessionId);
|
|
1584
|
-
if (!sessionState) {
|
|
1585
|
-
logger.info(`[WorkflowEngine] Session not in memory, attempting to restore from DB: ${sessionId}`);
|
|
1586
|
-
return this.resumeFromDatabase(sessionId, options);
|
|
1587
|
-
}
|
|
1588
|
-
if (options?.response) {
|
|
1589
|
-
await this.writeNodeResume(sessionId, options.response);
|
|
1590
|
-
}
|
|
1591
|
-
if (sessionState.status === "running") {
|
|
1592
|
-
return { runId: this.getRunIdFromSessionId(sessionId), status: "running" };
|
|
1593
|
-
}
|
|
1594
|
-
if (sessionState.status !== "paused") {
|
|
1595
|
-
throw new Error(`Session ${sessionId} is not paused (current: ${sessionState.status})`);
|
|
1596
|
-
}
|
|
1597
|
-
sessionState.status = "running";
|
|
1598
|
-
sessionState.abortController = new AbortController;
|
|
1599
|
-
if (this.sessionComponent) {
|
|
1600
|
-
const metadata = await this.getSessionMetadata(sessionId);
|
|
1601
|
-
await this.sessionComponent.update(sessionId, {
|
|
1602
|
-
metadata: { ...metadata, status: "running" }
|
|
1603
|
-
});
|
|
1604
|
-
}
|
|
1605
|
-
await sessionState.eventBus.publish(createWorkflowEvent("workflow.resumed", this.getRunIdFromSessionId(sessionId), {
|
|
1606
|
-
userResponse: options?.response
|
|
1607
|
-
}));
|
|
1608
|
-
const runtimeState = await this.restoreRuntimeState(sessionId);
|
|
1609
|
-
this.scheduleAndExecute(sessionState, {
|
|
1610
|
-
pendingNodeId: runtimeState.pendingNodeId || undefined,
|
|
1611
|
-
agentSessionId: runtimeState.agentSessionId,
|
|
1612
|
-
userResponse: options?.response,
|
|
1613
|
-
restoredOutputs: runtimeState.nodeOutputs
|
|
1614
|
-
});
|
|
1615
|
-
return {
|
|
1616
|
-
runId: this.getRunIdFromSessionId(sessionId),
|
|
1617
|
-
status: "running"
|
|
1618
|
-
};
|
|
1619
|
-
}
|
|
1620
|
-
async resumeFromDatabase(sessionId, options) {
|
|
1621
|
-
const session = await this.sessionComponent?.get(sessionId);
|
|
1622
|
-
if (!session) {
|
|
1623
|
-
throw new Error(`Session not found: ${sessionId}`);
|
|
1624
|
-
}
|
|
1625
|
-
const metadata = session.metadata;
|
|
1626
|
-
if (metadata.type !== "workflow") {
|
|
1627
|
-
throw new Error(`Session is not a workflow session: ${sessionId}`);
|
|
1628
|
-
}
|
|
1629
|
-
if (metadata.status !== "paused") {
|
|
1630
|
-
throw new Error(`Workflow is not paused: ${sessionId}, status: ${metadata.status}`);
|
|
1631
|
-
}
|
|
1632
|
-
const runtimeState = await this.restoreRuntimeState(sessionId);
|
|
1633
|
-
if (!runtimeState.pendingNodeId) {
|
|
1634
|
-
throw new Error(`No pending node found in session: ${sessionId}`);
|
|
1635
|
-
}
|
|
1636
|
-
if (options?.response) {
|
|
1637
|
-
await this.writeNodeResume(sessionId, options.response);
|
|
1638
|
-
}
|
|
1639
|
-
if (this.sessionComponent) {
|
|
1640
|
-
await this.sessionComponent.update(sessionId, {
|
|
1641
|
-
metadata: { ...metadata, status: "running" }
|
|
1642
|
-
});
|
|
1643
|
-
}
|
|
1644
|
-
logger.info(`[WorkflowEngine] Resumed from database: ${sessionId}, pendingNode: ${runtimeState.pendingNodeId}`);
|
|
1645
|
-
throw new Error(`Cannot resume from database without workflow definition. Session ${sessionId} is paused at node "${runtimeState.pendingNodeId}". Please ensure the workflow is registered before resuming.`);
|
|
1646
|
-
}
|
|
1647
|
-
async restoreRuntimeState(sessionId) {
|
|
1648
|
-
const messages = this.sessionComponent ? await this.sessionComponent.getMessages(sessionId) : [];
|
|
1649
|
-
const nodeOutputs = new Map;
|
|
1650
|
-
let lastCallNodeId = null;
|
|
1651
|
-
let lastInterruptMessage = null;
|
|
1652
|
-
let agentSessionId;
|
|
1653
|
-
for (const msg of messages) {
|
|
1654
|
-
const msgMetadata = msg.metadata;
|
|
1655
|
-
if (msgMetadata?.type === "workflow.node.call") {
|
|
1656
|
-
lastCallNodeId = msgMetadata.workflowNodeId;
|
|
1657
|
-
} else if (msgMetadata?.type === "workflow.node.result") {
|
|
1658
|
-
if (lastCallNodeId) {
|
|
1659
|
-
try {
|
|
1660
|
-
nodeOutputs.set(lastCallNodeId, JSON.parse(msg.content));
|
|
1661
|
-
} catch {
|
|
1662
|
-
nodeOutputs.set(lastCallNodeId, msg.content);
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
lastCallNodeId = null;
|
|
1666
|
-
} else if (msgMetadata?.type === "workflow.node.interrupt") {
|
|
1667
|
-
lastInterruptMessage = msg;
|
|
1668
|
-
lastCallNodeId = msgMetadata.workflowNodeId;
|
|
1669
|
-
agentSessionId = msgMetadata.agentSessionId;
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
return {
|
|
1673
|
-
nodeOutputs,
|
|
1674
|
-
pendingNodeId: lastCallNodeId,
|
|
1675
|
-
waitingForUser: !!lastInterruptMessage,
|
|
1676
|
-
agentSessionId,
|
|
1677
|
-
lastInterruptMessage
|
|
1678
|
-
};
|
|
1679
|
-
}
|
|
1680
|
-
async writeNodeResume(sessionId, response) {
|
|
1681
|
-
if (this.sessionComponent) {
|
|
1682
|
-
await this.sessionComponent.addMessage(sessionId, {
|
|
1683
|
-
role: "workflow.node.resume",
|
|
1684
|
-
content: response,
|
|
1685
|
-
metadata: {
|
|
1686
|
-
type: "workflow.node.resume",
|
|
1687
|
-
response,
|
|
1688
|
-
timestamp: Date.now()
|
|
1689
|
-
}
|
|
1690
|
-
});
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
1625
|
async stop(sessionId, reason) {
|
|
1694
1626
|
const sessionState = this.activeSessions.get(sessionId);
|
|
1695
1627
|
if (!sessionState) {
|
|
@@ -1787,7 +1719,7 @@ var init_engine = __esm(() => {
|
|
|
1787
1719
|
}
|
|
1788
1720
|
async scheduleAndExecute(sessionState, options) {
|
|
1789
1721
|
const { scheduler, executor, eventBus, abortController, nodeOutputs } = sessionState;
|
|
1790
|
-
const { input: globalInput, pendingNodeId, agentSessionId,
|
|
1722
|
+
const { input: globalInput, pendingNodeId, agentSessionId, restoredOutputs } = options || {};
|
|
1791
1723
|
if (restoredOutputs) {
|
|
1792
1724
|
for (const [nodeId, output] of restoredOutputs) {
|
|
1793
1725
|
nodeOutputs.set(nodeId, output);
|
|
@@ -1815,7 +1747,7 @@ var init_engine = __esm(() => {
|
|
|
1815
1747
|
if (pendingNodeId) {
|
|
1816
1748
|
await this.resumeNode(sessionState, pendingNodeId, {
|
|
1817
1749
|
agentSessionId,
|
|
1818
|
-
|
|
1750
|
+
userQuery: globalInput?.userQuery
|
|
1819
1751
|
});
|
|
1820
1752
|
} else {
|
|
1821
1753
|
await scheduleAvailableNodes();
|
|
@@ -1877,7 +1809,7 @@ var init_engine = __esm(() => {
|
|
|
1877
1809
|
scheduler.markFailed(nodeId);
|
|
1878
1810
|
return;
|
|
1879
1811
|
}
|
|
1880
|
-
await this.
|
|
1812
|
+
await this.writeNodeStart(sessionId, nodeId, nodeDef.type, input);
|
|
1881
1813
|
const context = this.createExecutionContext(sessionState, nodeId, input);
|
|
1882
1814
|
executor.executeNode(nodeDef, context).catch(async (error) => {
|
|
1883
1815
|
if (error instanceof AskUserError) {
|
|
@@ -1887,13 +1819,13 @@ var init_engine = __esm(() => {
|
|
|
1887
1819
|
scheduler.markFailed(nodeId);
|
|
1888
1820
|
});
|
|
1889
1821
|
}
|
|
1890
|
-
async
|
|
1822
|
+
async writeNodeStart(sessionId, nodeId, nodeType, input) {
|
|
1891
1823
|
if (this.sessionComponent) {
|
|
1892
1824
|
await this.sessionComponent.addMessage(sessionId, {
|
|
1893
|
-
role: "workflow.node.
|
|
1825
|
+
role: "workflow.node.start",
|
|
1894
1826
|
content: JSON.stringify({ input }),
|
|
1895
1827
|
metadata: {
|
|
1896
|
-
type: "workflow.node.
|
|
1828
|
+
type: "workflow.node.start",
|
|
1897
1829
|
workflowNodeId: nodeId,
|
|
1898
1830
|
workflowNodeType: nodeType,
|
|
1899
1831
|
timestamp: Date.now()
|
|
@@ -1901,25 +1833,55 @@ var init_engine = __esm(() => {
|
|
|
1901
1833
|
});
|
|
1902
1834
|
}
|
|
1903
1835
|
}
|
|
1836
|
+
async writeNodeResume(sessionId, nodeId, userResponse) {
|
|
1837
|
+
if (this.sessionComponent && userResponse) {
|
|
1838
|
+
await this.sessionComponent.addMessage(sessionId, {
|
|
1839
|
+
role: "workflow.node.resume",
|
|
1840
|
+
content: JSON.stringify({ userResponse }),
|
|
1841
|
+
metadata: {
|
|
1842
|
+
type: "workflow.node.resume",
|
|
1843
|
+
workflowNodeId: nodeId,
|
|
1844
|
+
timestamp: Date.now()
|
|
1845
|
+
}
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1904
1849
|
async resumeNode(sessionState, nodeId, options) {
|
|
1905
1850
|
const { scheduler, executor, eventBus, dagManager } = sessionState;
|
|
1906
1851
|
const sessionId = sessionState.sessionId;
|
|
1907
1852
|
const runId = this.getRunIdFromSessionId(sessionId);
|
|
1908
1853
|
scheduler.markStarted(nodeId);
|
|
1854
|
+
await this.writeNodeResume(sessionId, nodeId, options?.userQuery);
|
|
1909
1855
|
await eventBus.publish(createWorkflowEvent("node.started", runId, {
|
|
1910
1856
|
node_id: nodeId,
|
|
1911
1857
|
agentSessionId: options?.agentSessionId,
|
|
1912
|
-
|
|
1858
|
+
userQuery: options?.userQuery
|
|
1913
1859
|
}));
|
|
1914
1860
|
const nodeDef = dagManager.getNode(nodeId);
|
|
1915
1861
|
if (!nodeDef) {
|
|
1916
1862
|
scheduler.markFailed(nodeId);
|
|
1917
1863
|
return;
|
|
1918
1864
|
}
|
|
1919
|
-
const context = this.createExecutionContext(sessionState, nodeId,
|
|
1920
|
-
if (options?.agentSessionId
|
|
1865
|
+
const context = this.createExecutionContext(sessionState, nodeId, { userQuery: options?.userQuery }, true);
|
|
1866
|
+
if (options?.agentSessionId) {
|
|
1921
1867
|
context.agentSessionId = options.agentSessionId;
|
|
1922
|
-
|
|
1868
|
+
}
|
|
1869
|
+
if (nodeDef.type === "agent" && options?.agentSessionId) {
|
|
1870
|
+
const agentAdapter = this.nodeRegistry.getAgentAdapter?.();
|
|
1871
|
+
if (agentAdapter?.resumeAgent) {
|
|
1872
|
+
const agentConfig = {
|
|
1873
|
+
type: nodeDef.config?.agent_type || "general",
|
|
1874
|
+
prompt: nodeDef.config?.prompt || "",
|
|
1875
|
+
nodeId,
|
|
1876
|
+
runId,
|
|
1877
|
+
workflowSessionId: sessionId
|
|
1878
|
+
};
|
|
1879
|
+
try {
|
|
1880
|
+
await agentAdapter.resumeAgent(options.agentSessionId, options.userQuery || "", agentConfig);
|
|
1881
|
+
} catch (error) {
|
|
1882
|
+
console.error(`Failed to resume agent node ${nodeId}:`, error);
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1923
1885
|
}
|
|
1924
1886
|
executor.executeNode(nodeDef, context).catch((error) => {
|
|
1925
1887
|
if (error instanceof AskUserError) {
|
|
@@ -1930,7 +1892,7 @@ var init_engine = __esm(() => {
|
|
|
1930
1892
|
scheduler.markFailed(nodeId);
|
|
1931
1893
|
});
|
|
1932
1894
|
}
|
|
1933
|
-
createExecutionContext(sessionState, nodeId, globalInput) {
|
|
1895
|
+
createExecutionContext(sessionState, nodeId, globalInput, forceGlobalInput) {
|
|
1934
1896
|
const nodeDef = sessionState.dagManager.getNode(nodeId);
|
|
1935
1897
|
const runId = this.getRunIdFromSessionId(sessionState.sessionId);
|
|
1936
1898
|
const deps = nodeDef.depends_on || [];
|
|
@@ -1942,7 +1904,8 @@ var init_engine = __esm(() => {
|
|
|
1942
1904
|
}
|
|
1943
1905
|
}
|
|
1944
1906
|
const analysis = sessionState.dagManager.analyze();
|
|
1945
|
-
|
|
1907
|
+
const isEntryNode = analysis.entryNodes.includes(nodeId);
|
|
1908
|
+
if ((isEntryNode || forceGlobalInput) && globalInput) {
|
|
1946
1909
|
Object.assign(input, globalInput);
|
|
1947
1910
|
}
|
|
1948
1911
|
const askUser = (query) => {
|
|
@@ -2069,48 +2032,37 @@ var init_engine = __esm(() => {
|
|
|
2069
2032
|
__legacyDecorateClassTS([
|
|
2070
2033
|
TracedAs("workflow.engine.run", { recordParams: true, recordResult: true, log: true })
|
|
2071
2034
|
], WorkflowEngine.prototype, "run", null);
|
|
2035
|
+
__legacyDecorateClassTS([
|
|
2036
|
+
TracedAs("workflow.engine.runWithResume", { recordParams: true, recordResult: true, log: true })
|
|
2037
|
+
], WorkflowEngine.prototype, "runWithResume", null);
|
|
2072
2038
|
__legacyDecorateClassTS([
|
|
2073
2039
|
TracedAs("workflow.engine.runWorkflow", { recordParams: true, recordResult: true, log: true })
|
|
2074
2040
|
], WorkflowEngine.prototype, "runWorkflow", null);
|
|
2075
2041
|
__legacyDecorateClassTS([
|
|
2076
2042
|
TracedAs("workflow.engine.pause", { recordParams: true, recordResult: true, log: true })
|
|
2077
2043
|
], WorkflowEngine.prototype, "pause", null);
|
|
2078
|
-
__legacyDecorateClassTS([
|
|
2079
|
-
TracedAs("workflow.engine.resume", { recordParams: true, recordResult: true, log: true })
|
|
2080
|
-
], WorkflowEngine.prototype, "resume", null);
|
|
2081
|
-
__legacyDecorateClassTS([
|
|
2082
|
-
TracedAs("workflow.engine.resumeFromDatabase", { recordParams: true, recordResult: true, log: true })
|
|
2083
|
-
], WorkflowEngine.prototype, "resumeFromDatabase", null);
|
|
2084
|
-
__legacyDecorateClassTS([
|
|
2085
|
-
TracedAs("workflow.engine.restoreRuntimeState", { recordParams: true, recordResult: true, log: true })
|
|
2086
|
-
], WorkflowEngine.prototype, "restoreRuntimeState", null);
|
|
2087
|
-
__legacyDecorateClassTS([
|
|
2088
|
-
TracedAs("workflow.engine.writeNodeResume", { recordParams: true, recordResult: true, log: true })
|
|
2089
|
-
], WorkflowEngine.prototype, "writeNodeResume", null);
|
|
2090
2044
|
__legacyDecorateClassTS([
|
|
2091
2045
|
TracedAs("workflow.engine.stop", { recordParams: true, recordResult: true, log: true })
|
|
2092
2046
|
], WorkflowEngine.prototype, "stop", null);
|
|
2093
2047
|
__legacyDecorateClassTS([
|
|
2094
|
-
TracedAs("workflow.engine.writeNodeInterrupt", { recordParams: true, recordResult: true, log: true }),
|
|
2095
2048
|
TracedAs("workflow.engine.writeNodeInterrupt", { recordParams: true, recordResult: true, log: true })
|
|
2096
2049
|
], WorkflowEngine.prototype, "writeNodeInterrupt", null);
|
|
2097
2050
|
__legacyDecorateClassTS([
|
|
2098
|
-
TracedAs("workflow.engine.scheduleAndExecute", { recordParams: true, recordResult: true, log: true }),
|
|
2099
2051
|
TracedAs("workflow.engine.scheduleAndExecute", { recordParams: true, recordResult: true, log: true })
|
|
2100
2052
|
], WorkflowEngine.prototype, "scheduleAndExecute", null);
|
|
2101
2053
|
__legacyDecorateClassTS([
|
|
2102
2054
|
TracedAs("workflow.engine.waitForNextNodeEvent", { recordParams: true, recordResult: true, log: true })
|
|
2103
2055
|
], WorkflowEngine.prototype, "waitForNextNodeEvent", null);
|
|
2104
2056
|
__legacyDecorateClassTS([
|
|
2105
|
-
TracedAs("workflow.engine.startNode", { recordParams: true, recordResult: true, log: true }),
|
|
2106
2057
|
TracedAs("workflow.engine.startNode", { recordParams: true, recordResult: true, log: true })
|
|
2107
2058
|
], WorkflowEngine.prototype, "startNode", null);
|
|
2108
2059
|
__legacyDecorateClassTS([
|
|
2109
|
-
TracedAs("workflow.engine.
|
|
2110
|
-
|
|
2111
|
-
|
|
2060
|
+
TracedAs("workflow.engine.writeNodeStart", { recordParams: true, recordResult: true, log: true })
|
|
2061
|
+
], WorkflowEngine.prototype, "writeNodeStart", null);
|
|
2062
|
+
__legacyDecorateClassTS([
|
|
2063
|
+
TracedAs("workflow.engine.writeNodeResume", { recordParams: true, recordResult: true, log: true })
|
|
2064
|
+
], WorkflowEngine.prototype, "writeNodeResume", null);
|
|
2112
2065
|
__legacyDecorateClassTS([
|
|
2113
|
-
TracedAs("workflow.engine.resumeNode", { recordParams: true, recordResult: true, log: true }),
|
|
2114
2066
|
TracedAs("workflow.engine.resumeNode", { recordParams: true, recordResult: true, log: true })
|
|
2115
2067
|
], WorkflowEngine.prototype, "resumeNode", null);
|
|
2116
2068
|
__legacyDecorateClassTS([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-setting/roy-agent-core",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"import": "./dist/index.js",
|
|
12
|
-
"types": "./dist/index.d.ts"
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"require": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
13
15
|
},
|
|
14
16
|
"./*": {
|
|
15
17
|
"import": "./dist/*/index.js",
|
|
@@ -25,12 +27,6 @@
|
|
|
25
27
|
"dist",
|
|
26
28
|
"README.md"
|
|
27
29
|
],
|
|
28
|
-
"scripts": {
|
|
29
|
-
"build": "bunup",
|
|
30
|
-
"build:main": "bunup -- --entry src/index.ts",
|
|
31
|
-
"clean": "rm -rf dist",
|
|
32
|
-
"typecheck": "npx tsc --noEmit --skipLibCheck --project tsconfig.json"
|
|
33
|
-
},
|
|
34
30
|
"dependencies": {
|
|
35
31
|
"@ai-sdk/anthropic": "^3.0.0",
|
|
36
32
|
"@ai-sdk/google": "^3.0.0",
|
|
@@ -77,5 +73,11 @@
|
|
|
77
73
|
"license": "MIT",
|
|
78
74
|
"bugs": {
|
|
79
75
|
"url": "https://github.com/ai-setting/roy-agent/issues"
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"build": "bunup",
|
|
79
|
+
"build:main": "bunup -- --entry src/index.ts",
|
|
80
|
+
"clean": "rm -rf dist",
|
|
81
|
+
"typecheck": "npx tsc --noEmit --skipLibCheck --project tsconfig.json"
|
|
80
82
|
}
|
|
81
|
-
}
|
|
83
|
+
}
|