@ai-setting/roy-agent-core 1.5.44 → 1.5.45
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.js +5 -5
- package/dist/env/agent/index.js +5 -5
- package/dist/env/commands/index.js +5 -5
- package/dist/env/context/index.js +4 -1
- package/dist/env/debug/index.js +5 -5
- package/dist/env/event-source/index.js +7 -7
- package/dist/env/hook/index.js +3 -3
- package/dist/env/index.js +19 -16
- package/dist/env/llm/index.js +5 -5
- package/dist/env/log-trace/index.js +5 -5
- package/dist/env/mcp/index.js +20 -6
- package/dist/env/memory/index.js +5 -5
- package/dist/env/plugin/index.js +5 -5
- package/dist/env/prompt/index.js +5 -5
- package/dist/env/session/index.js +6 -6
- package/dist/env/session/storage/index.js +1 -1
- package/dist/env/skill/index.js +5 -5
- package/dist/env/task/delegate/index.js +3 -3
- package/dist/env/task/index.js +6 -6
- package/dist/env/task/plugins/index.js +2 -2
- package/dist/env/tool/index.js +5 -5
- package/dist/env/workflow/engine/index.js +7 -2
- package/dist/env/workflow/index.js +10 -7
- package/dist/env/workflow/tools/index.js +14 -0
- package/dist/index.js +29 -26
- package/dist/shared/@ai-setting/{roy-agent-core-kajktp3d.js → roy-agent-core-20fm423j.js} +47 -26
- package/dist/shared/@ai-setting/{roy-agent-core-23gw9c4s.js → roy-agent-core-2vhsccvz.js} +52 -10
- package/dist/shared/@ai-setting/{roy-agent-core-69jskqjg.js → roy-agent-core-44g4dhzg.js} +75 -7
- package/dist/shared/@ai-setting/{roy-agent-core-e9fdm13a.js → roy-agent-core-4gmxjdhn.js} +4 -2
- package/dist/shared/@ai-setting/{roy-agent-core-b4wd9tn6.js → roy-agent-core-4k9a823d.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-68qy97r3.js +31 -0
- package/dist/shared/@ai-setting/roy-agent-core-6atd905e.js +42 -0
- package/dist/shared/@ai-setting/{roy-agent-core-4jqq077c.js → roy-agent-core-6e3wz81d.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-pwkk12p4.js → roy-agent-core-6mcb7nqa.js} +60 -0
- package/dist/shared/@ai-setting/{roy-agent-core-9p43ap7h.js → roy-agent-core-8y804aat.js} +4 -2
- package/dist/shared/@ai-setting/{roy-agent-core-r6rwsr54.js → roy-agent-core-9p604xjf.js} +29 -9
- package/dist/shared/@ai-setting/{roy-agent-core-z1xf2fdk.js → roy-agent-core-a67e90d1.js} +6 -4
- package/dist/shared/@ai-setting/{roy-agent-core-xkb264a8.js → roy-agent-core-bp3xggmb.js} +192 -26
- package/dist/shared/@ai-setting/{roy-agent-core-zrja5v78.js → roy-agent-core-ce9w0j8n.js} +10 -2
- package/dist/shared/@ai-setting/{roy-agent-core-2ms7296b.js → roy-agent-core-cr8xer31.js} +12 -5
- package/dist/shared/@ai-setting/roy-agent-core-dbxm76wf.js +190 -0
- package/dist/shared/@ai-setting/{roy-agent-core-nj8yerg9.js → roy-agent-core-eftqdsy5.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-psvwzdhj.js → roy-agent-core-hdszq729.js} +9 -5
- package/dist/shared/@ai-setting/{roy-agent-core-dxbsc1zy.js → roy-agent-core-ja9qhg6d.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-cevpwnq7.js → roy-agent-core-mjbfgqen.js} +5 -3
- package/dist/shared/@ai-setting/roy-agent-core-nhfy3p8q.js +132 -0
- package/dist/shared/@ai-setting/{roy-agent-core-38dkek2y.js → roy-agent-core-nn9dmffw.js} +325 -114
- package/dist/shared/@ai-setting/{roy-agent-core-ee6nnnqw.js → roy-agent-core-r9hq4cjx.js} +8 -1
- package/dist/shared/@ai-setting/{roy-agent-core-jqy2mdyq.js → roy-agent-core-rgj6hq15.js} +52 -41
- package/dist/shared/@ai-setting/{roy-agent-core-z33en0cz.js → roy-agent-core-rm3hay00.js} +15 -2
- package/dist/shared/@ai-setting/{roy-agent-core-ryw3ckfy.js → roy-agent-core-rx74rye7.js} +5 -3
- package/dist/shared/@ai-setting/{roy-agent-core-pxcrzyv9.js → roy-agent-core-sk535ft2.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-2dhd60aw.js → roy-agent-core-vdwvamre.js} +10 -0
- package/dist/shared/@ai-setting/{roy-agent-core-1zq3p19q.js → roy-agent-core-w64zachx.js} +8 -4
- package/dist/shared/@ai-setting/roy-agent-core-ye0z728h.js +18 -0
- package/dist/shared/@ai-setting/{roy-agent-core-eg6nv09z.js → roy-agent-core-ztx5eh72.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-nqgrjja0.js → roy-agent-core-zwq6vhpj.js} +1 -1
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-dh9d7a3m.js +0 -11
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildWorkflowNodeMetadata,
|
|
3
|
+
getWorkflowNodeIdFromMetadata,
|
|
4
|
+
init_workflow_message_metadata,
|
|
5
|
+
patchAgentSessionIdOnMessage
|
|
6
|
+
} from "./roy-agent-core-6atd905e.js";
|
|
1
7
|
import {
|
|
2
8
|
AgentComponentAdapter,
|
|
3
9
|
init_agent_component_adapter
|
|
4
|
-
} from "./roy-agent-core-
|
|
10
|
+
} from "./roy-agent-core-44g4dhzg.js";
|
|
5
11
|
import {
|
|
6
12
|
SkillNode,
|
|
7
13
|
ToolNode,
|
|
@@ -10,6 +16,14 @@ import {
|
|
|
10
16
|
init_tool_node,
|
|
11
17
|
init_workflow_node
|
|
12
18
|
} from "./roy-agent-core-6vxg2gmr.js";
|
|
19
|
+
import {
|
|
20
|
+
WORKFLOW_SUBMIT_OUTPUT_TOOL_NAME,
|
|
21
|
+
init_json_schema_to_zod,
|
|
22
|
+
init_submit_json_output_tool,
|
|
23
|
+
jsonSchemaToZod,
|
|
24
|
+
parseWorkflowJsonOutput,
|
|
25
|
+
validateJsonOutputSchema
|
|
26
|
+
} from "./roy-agent-core-nhfy3p8q.js";
|
|
13
27
|
import {
|
|
14
28
|
TemplateResolver,
|
|
15
29
|
init_template_resolver
|
|
@@ -754,6 +768,7 @@ var init_executor = __esm(() => {
|
|
|
754
768
|
init_event();
|
|
755
769
|
init_types();
|
|
756
770
|
init_decorator();
|
|
771
|
+
init_workflow_message_metadata();
|
|
757
772
|
Executor = class Executor {
|
|
758
773
|
nodeRegistry;
|
|
759
774
|
eventBus;
|
|
@@ -946,15 +961,33 @@ var init_executor = __esm(() => {
|
|
|
946
961
|
role: "workflow.node.start",
|
|
947
962
|
content: contentSummary,
|
|
948
963
|
parts: [part],
|
|
949
|
-
metadata: {
|
|
950
|
-
_workflowNodeMetadata: true,
|
|
951
|
-
type: "workflow.node.start",
|
|
952
|
-
workflowNodeId: nodeId,
|
|
953
|
-
workflowNodeType: nodeType,
|
|
964
|
+
metadata: buildWorkflowNodeMetadata("workflow.node.start", nodeId, nodeType, {
|
|
954
965
|
...agentSessionId ? { agentSessionId } : {}
|
|
955
|
-
}
|
|
966
|
+
})
|
|
956
967
|
});
|
|
957
968
|
}
|
|
969
|
+
async attachAgentSessionToLastStart(sessionId, nodeId, agentSessionId) {
|
|
970
|
+
if (!this.sessionComponent?.getMessages || !this.sessionComponent.updateMessage) {
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
const messages = await this.sessionComponent.getMessages(sessionId);
|
|
974
|
+
for (let i = messages.length - 1;i >= 0; i--) {
|
|
975
|
+
const msg = messages[i];
|
|
976
|
+
const meta = msg.metadata;
|
|
977
|
+
if (meta?.type !== "workflow.node.start") {
|
|
978
|
+
continue;
|
|
979
|
+
}
|
|
980
|
+
if (getWorkflowNodeIdFromMetadata(meta) !== nodeId) {
|
|
981
|
+
continue;
|
|
982
|
+
}
|
|
983
|
+
if (meta.agentSessionId) {
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
const patched = patchAgentSessionIdOnMessage(meta, msg.parts, agentSessionId);
|
|
987
|
+
await this.sessionComponent.updateMessage(sessionId, msg.id, patched);
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
958
991
|
summarizeCall(nodeType, nodeId, input) {
|
|
959
992
|
if (input === undefined || input === null) {
|
|
960
993
|
return `[${nodeType}] ${nodeId} started`;
|
|
@@ -986,14 +1019,11 @@ var init_executor = __esm(() => {
|
|
|
986
1019
|
role: "workflow.node.interrupt",
|
|
987
1020
|
content: query,
|
|
988
1021
|
parts: [part],
|
|
989
|
-
metadata: {
|
|
990
|
-
_workflowNodeMetadata: true,
|
|
991
|
-
type: "workflow.node.interrupt",
|
|
992
|
-
workflowNodeId: nodeId,
|
|
993
|
-
workflowNodeType: nodeType,
|
|
1022
|
+
metadata: buildWorkflowNodeMetadata("workflow.node.interrupt", nodeId, nodeType, {
|
|
994
1023
|
query,
|
|
995
|
-
agentSessionId
|
|
996
|
-
|
|
1024
|
+
...agentSessionId ? { agentSessionId } : {},
|
|
1025
|
+
timestamp
|
|
1026
|
+
})
|
|
997
1027
|
});
|
|
998
1028
|
}
|
|
999
1029
|
async writeNodeEnd(sessionId, nodeId, nodeType, output, error, durationMs, agentSessionId) {
|
|
@@ -1013,14 +1043,10 @@ var init_executor = __esm(() => {
|
|
|
1013
1043
|
role: "workflow.node.end",
|
|
1014
1044
|
content: contentSummary,
|
|
1015
1045
|
parts: [part],
|
|
1016
|
-
metadata: {
|
|
1017
|
-
_workflowNodeMetadata: true,
|
|
1018
|
-
type: "workflow.node.end",
|
|
1019
|
-
workflowNodeId: nodeId,
|
|
1020
|
-
workflowNodeType: nodeType,
|
|
1046
|
+
metadata: buildWorkflowNodeMetadata("workflow.node.end", nodeId, nodeType, {
|
|
1021
1047
|
success: !error,
|
|
1022
1048
|
...agentSessionId ? { agentSessionId } : {}
|
|
1023
|
-
}
|
|
1049
|
+
})
|
|
1024
1050
|
});
|
|
1025
1051
|
}
|
|
1026
1052
|
summarizeResult(nodeId, output, error, durationMs) {
|
|
@@ -1042,7 +1068,7 @@ var init_executor = __esm(() => {
|
|
|
1042
1068
|
const truncated = strOutput.length > 100 ? strOutput.substring(0, 100) + "..." : strOutput;
|
|
1043
1069
|
return `✅ ${nodeId}: ${truncated} (${durationMs}ms)`;
|
|
1044
1070
|
}
|
|
1045
|
-
async writeNodeResume(sessionId, nodeId, response, agentSessionId) {
|
|
1071
|
+
async writeNodeResume(sessionId, nodeId, nodeType, response, agentSessionId) {
|
|
1046
1072
|
if (!this.sessionComponent)
|
|
1047
1073
|
return;
|
|
1048
1074
|
const timestamp = Date.now();
|
|
@@ -1057,12 +1083,11 @@ var init_executor = __esm(() => {
|
|
|
1057
1083
|
role: "workflow.node.resume",
|
|
1058
1084
|
content: response,
|
|
1059
1085
|
parts: [part],
|
|
1060
|
-
metadata: {
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
}
|
|
1086
|
+
metadata: buildWorkflowNodeMetadata("workflow.node.resume", nodeId, nodeType, {
|
|
1087
|
+
response,
|
|
1088
|
+
...agentSessionId ? { agentSessionId } : {},
|
|
1089
|
+
timestamp
|
|
1090
|
+
})
|
|
1066
1091
|
});
|
|
1067
1092
|
}
|
|
1068
1093
|
};
|
|
@@ -1072,6 +1097,9 @@ var init_executor = __esm(() => {
|
|
|
1072
1097
|
__legacyDecorateClassTS([
|
|
1073
1098
|
TracedAs("workflow.executor.writeNodeStart", { recordParams: true, recordResult: true, log: true })
|
|
1074
1099
|
], Executor.prototype, "writeNodeStart", null);
|
|
1100
|
+
__legacyDecorateClassTS([
|
|
1101
|
+
TracedAs("workflow.executor.attachAgentSessionToLastStart", { log: true })
|
|
1102
|
+
], Executor.prototype, "attachAgentSessionToLastStart", null);
|
|
1075
1103
|
__legacyDecorateClassTS([
|
|
1076
1104
|
TracedAs("workflow.executor.writeNodeInterrupt", { recordParams: true, recordResult: true, log: true })
|
|
1077
1105
|
], Executor.prototype, "writeNodeInterrupt", null);
|
|
@@ -1083,11 +1111,139 @@ var init_executor = __esm(() => {
|
|
|
1083
1111
|
], Executor.prototype, "writeNodeResume", null);
|
|
1084
1112
|
});
|
|
1085
1113
|
|
|
1114
|
+
// src/env/workflow/utils/parse-agent-output-config.ts
|
|
1115
|
+
function parseAgentOutputConfig(config) {
|
|
1116
|
+
const output = config.output;
|
|
1117
|
+
if (!output) {
|
|
1118
|
+
return { mode: "string" };
|
|
1119
|
+
}
|
|
1120
|
+
const mode = output.mode === "json" ? "json" : "string";
|
|
1121
|
+
if (mode === "json") {
|
|
1122
|
+
if (output.schema === undefined) {
|
|
1123
|
+
throw new Error("AgentNode output.mode=json requires output.schema");
|
|
1124
|
+
}
|
|
1125
|
+
const schema = validateJsonOutputSchema(output.schema);
|
|
1126
|
+
return { mode, schema };
|
|
1127
|
+
}
|
|
1128
|
+
return { mode: "string" };
|
|
1129
|
+
}
|
|
1130
|
+
var init_parse_agent_output_config = __esm(() => {
|
|
1131
|
+
init_json_schema_to_zod();
|
|
1132
|
+
});
|
|
1133
|
+
|
|
1134
|
+
// src/env/workflow/utils/extract-agent-json-output.ts
|
|
1135
|
+
function extractAgentJsonOutput(agentResult, schema) {
|
|
1136
|
+
const candidates = [
|
|
1137
|
+
agentResult.structuredOutput,
|
|
1138
|
+
asRecord(agentResult.output),
|
|
1139
|
+
extractFromToolCalls(agentResult),
|
|
1140
|
+
extractFromMessages(agentResult.messages)
|
|
1141
|
+
];
|
|
1142
|
+
for (const candidate of candidates) {
|
|
1143
|
+
const validated = validateAgainstSchema(candidate, schema);
|
|
1144
|
+
if (validated) {
|
|
1145
|
+
return validated;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
function asRecord(value) {
|
|
1151
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
1152
|
+
return value;
|
|
1153
|
+
}
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
function extractFromToolCalls(agentResult) {
|
|
1157
|
+
const toolCalls = agentResult.metadata?.toolCallsDetail;
|
|
1158
|
+
if (!toolCalls?.length) {
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
for (let i = toolCalls.length - 1;i >= 0; i--) {
|
|
1162
|
+
const tc = toolCalls[i];
|
|
1163
|
+
if (tc.name === WORKFLOW_SUBMIT_OUTPUT_TOOL_NAME && tc.arguments) {
|
|
1164
|
+
return tc.arguments;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
function extractFromMessages(messages) {
|
|
1170
|
+
if (!messages?.length) {
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
for (let i = messages.length - 1;i >= 0; i--) {
|
|
1174
|
+
const msg = messages[i];
|
|
1175
|
+
if (msg.toolName !== WORKFLOW_SUBMIT_OUTPUT_TOOL_NAME || !msg.content) {
|
|
1176
|
+
continue;
|
|
1177
|
+
}
|
|
1178
|
+
const fromMarker = parseWorkflowJsonOutput(msg.content);
|
|
1179
|
+
if (fromMarker) {
|
|
1180
|
+
return fromMarker;
|
|
1181
|
+
}
|
|
1182
|
+
try {
|
|
1183
|
+
const parsed = JSON.parse(msg.content);
|
|
1184
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1185
|
+
return parsed;
|
|
1186
|
+
}
|
|
1187
|
+
} catch {}
|
|
1188
|
+
}
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
1191
|
+
function validateAgainstSchema(data, schema) {
|
|
1192
|
+
if (!data) {
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1195
|
+
if (!schema) {
|
|
1196
|
+
return data;
|
|
1197
|
+
}
|
|
1198
|
+
try {
|
|
1199
|
+
return jsonSchemaToZod(schema).parse(data);
|
|
1200
|
+
} catch {
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
var init_extract_agent_json_output = __esm(() => {
|
|
1205
|
+
init_submit_json_output_tool();
|
|
1206
|
+
init_json_schema_to_zod();
|
|
1207
|
+
});
|
|
1208
|
+
|
|
1209
|
+
// src/env/workflow/utils/build-agent-node-output.ts
|
|
1210
|
+
function buildAgentNodeOutput(agentResult, outputConfig) {
|
|
1211
|
+
const base = {
|
|
1212
|
+
metadata: agentResult.metadata,
|
|
1213
|
+
workflowHistory: agentResult.messages
|
|
1214
|
+
};
|
|
1215
|
+
if (outputConfig.mode === "json") {
|
|
1216
|
+
const schema = outputConfig.schema;
|
|
1217
|
+
const jsonData = extractAgentJsonOutput(agentResult, schema);
|
|
1218
|
+
if (!jsonData) {
|
|
1219
|
+
throw new Error("AgentNode json output mode requires structured JSON from workflow_submit_output");
|
|
1220
|
+
}
|
|
1221
|
+
return {
|
|
1222
|
+
result: jsonData,
|
|
1223
|
+
...jsonData,
|
|
1224
|
+
metadata: {
|
|
1225
|
+
...agentResult.metadata,
|
|
1226
|
+
outputMode: "json"
|
|
1227
|
+
},
|
|
1228
|
+
workflowHistory: agentResult.messages
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
return {
|
|
1232
|
+
result: agentResult.output,
|
|
1233
|
+
...base
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
var init_build_agent_node_output = __esm(() => {
|
|
1237
|
+
init_extract_agent_json_output();
|
|
1238
|
+
});
|
|
1239
|
+
|
|
1086
1240
|
// src/env/workflow/nodes/agent-node.ts
|
|
1087
1241
|
var AgentNode;
|
|
1088
1242
|
var init_agent_node = __esm(() => {
|
|
1089
1243
|
init_workflow_hil();
|
|
1090
1244
|
init_decorator();
|
|
1245
|
+
init_parse_agent_output_config();
|
|
1246
|
+
init_build_agent_node_output();
|
|
1091
1247
|
AgentNode = class AgentNode {
|
|
1092
1248
|
definition;
|
|
1093
1249
|
agentRunner;
|
|
@@ -1104,6 +1260,7 @@ var init_agent_node = __esm(() => {
|
|
|
1104
1260
|
const config = context.resolvedConfig ?? this.definition.config ?? {};
|
|
1105
1261
|
const agentType = config.agent_type || "general";
|
|
1106
1262
|
const options = config.options || {};
|
|
1263
|
+
const outputConfig = parseAgentOutputConfig(config);
|
|
1107
1264
|
let resolvedPrompt;
|
|
1108
1265
|
if (context.resolvedConfig && context.templateResolver) {
|
|
1109
1266
|
resolvedPrompt = config.prompt || "";
|
|
@@ -1120,19 +1277,30 @@ var init_agent_node = __esm(() => {
|
|
|
1120
1277
|
});
|
|
1121
1278
|
}
|
|
1122
1279
|
}
|
|
1123
|
-
const userQuery = context.input?.userQuery;
|
|
1280
|
+
const userQuery = context.input?.userQuery ?? context.workflowInput?.userQuery;
|
|
1124
1281
|
let agentSessionId = context.agentSessionId;
|
|
1282
|
+
if (!agentSessionId && context.sessionComponent) {
|
|
1283
|
+
agentSessionId = await this.resolveAgentSessionIdFromWorkflow(context);
|
|
1284
|
+
if (agentSessionId) {
|
|
1285
|
+
context.agentSessionId = agentSessionId;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1125
1288
|
if (!agentSessionId && context.sessionComponent) {
|
|
1126
1289
|
agentSessionId = await this.createAgentSubSession(context);
|
|
1127
1290
|
context.agentSessionId = agentSessionId;
|
|
1291
|
+
if (context.attachAgentSessionToLastStart) {
|
|
1292
|
+
await context.attachAgentSessionToLastStart(this.definition.id, agentSessionId);
|
|
1293
|
+
}
|
|
1128
1294
|
}
|
|
1295
|
+
const allowedTools = ["ask_user"];
|
|
1129
1296
|
const agentConfig = {
|
|
1130
1297
|
type: agentType,
|
|
1131
1298
|
prompt: resolvedPrompt,
|
|
1132
1299
|
options: {
|
|
1133
1300
|
timeout: options.timeout,
|
|
1134
1301
|
model: options.model,
|
|
1135
|
-
allowedTools
|
|
1302
|
+
allowedTools,
|
|
1303
|
+
outputSchema: outputConfig.schema
|
|
1136
1304
|
},
|
|
1137
1305
|
workflowHistory: context.workflowHistory,
|
|
1138
1306
|
nodeId: this.definition.id,
|
|
@@ -1145,11 +1313,7 @@ var init_agent_node = __esm(() => {
|
|
|
1145
1313
|
const result = await this.agentRunner.run(agentConfig, resumeOptions);
|
|
1146
1314
|
const duration = Date.now() - startTime;
|
|
1147
1315
|
return {
|
|
1148
|
-
output:
|
|
1149
|
-
result: result.output,
|
|
1150
|
-
metadata: result.metadata,
|
|
1151
|
-
workflowHistory: result.messages
|
|
1152
|
-
},
|
|
1316
|
+
output: buildAgentNodeOutput(result, outputConfig),
|
|
1153
1317
|
error: undefined,
|
|
1154
1318
|
duration
|
|
1155
1319
|
};
|
|
@@ -1170,6 +1334,18 @@ var init_agent_node = __esm(() => {
|
|
|
1170
1334
|
};
|
|
1171
1335
|
}
|
|
1172
1336
|
}
|
|
1337
|
+
async resolveAgentSessionIdFromWorkflow(context) {
|
|
1338
|
+
const sessionComponent = context.sessionComponent;
|
|
1339
|
+
if (!sessionComponent) {
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
const workflowSession = await sessionComponent.get(context.sessionId);
|
|
1343
|
+
const agentSessions = workflowSession?.metadata?.agentSessions;
|
|
1344
|
+
if (!agentSessions?.length) {
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
return agentSessions.find((ref) => ref.nodeId === this.definition.id)?.sessionId;
|
|
1348
|
+
}
|
|
1173
1349
|
async createAgentSubSession(context) {
|
|
1174
1350
|
const sessionComponent = context.sessionComponent;
|
|
1175
1351
|
if (!sessionComponent) {
|
|
@@ -1266,7 +1442,8 @@ class NodeRegistry {
|
|
|
1266
1442
|
agentComponent,
|
|
1267
1443
|
agentRunner,
|
|
1268
1444
|
workflowRunner,
|
|
1269
|
-
sessionComponent
|
|
1445
|
+
sessionComponent,
|
|
1446
|
+
llmComponent
|
|
1270
1447
|
} = options ?? {};
|
|
1271
1448
|
this.toolRegistry = toolRegistry;
|
|
1272
1449
|
this.skillRegistry = skillRegistry;
|
|
@@ -1277,8 +1454,11 @@ class NodeRegistry {
|
|
|
1277
1454
|
if (agentRunner.setSessionComponent && sessionComponent) {
|
|
1278
1455
|
agentRunner.setSessionComponent(sessionComponent);
|
|
1279
1456
|
}
|
|
1457
|
+
if (llmComponent && "setLLMComponent" in agentRunner && typeof agentRunner.setLLMComponent === "function") {
|
|
1458
|
+
agentRunner.setLLMComponent(llmComponent);
|
|
1459
|
+
}
|
|
1280
1460
|
} else if (agentComponent) {
|
|
1281
|
-
this.agentComponentAdapter = new AgentComponentAdapter(agentComponent, {}, sessionComponent);
|
|
1461
|
+
this.agentComponentAdapter = new AgentComponentAdapter(agentComponent, {}, sessionComponent, llmComponent);
|
|
1282
1462
|
this.agentRunner = this.agentComponentAdapter;
|
|
1283
1463
|
}
|
|
1284
1464
|
this.registerBuiltInTypes();
|
|
@@ -1348,6 +1528,21 @@ var init_node_registry = __esm(() => {
|
|
|
1348
1528
|
init_ask_user_node();
|
|
1349
1529
|
});
|
|
1350
1530
|
|
|
1531
|
+
// src/env/workflow/utils/agent-session-metadata.ts
|
|
1532
|
+
function updateAgentSessionStatus(agentSessions, nodeId, status) {
|
|
1533
|
+
if (!agentSessions?.length) {
|
|
1534
|
+
return agentSessions ?? [];
|
|
1535
|
+
}
|
|
1536
|
+
return agentSessions.map((ref) => ref.nodeId === nodeId ? { ...ref, status } : ref);
|
|
1537
|
+
}
|
|
1538
|
+
function markAllAgentSessionsCompleted(agentSessions) {
|
|
1539
|
+
if (!agentSessions?.length) {
|
|
1540
|
+
return agentSessions ?? [];
|
|
1541
|
+
}
|
|
1542
|
+
return agentSessions.map((ref) => ref.status === "active" || ref.status === "paused" ? { ...ref, status: "completed" } : ref);
|
|
1543
|
+
}
|
|
1544
|
+
var init_agent_session_metadata = () => {};
|
|
1545
|
+
|
|
1351
1546
|
// src/env/workflow/engine/engine.ts
|
|
1352
1547
|
import { EventEmitter } from "events";
|
|
1353
1548
|
var logger2, WorkflowEngine;
|
|
@@ -1359,6 +1554,7 @@ var init_engine = __esm(() => {
|
|
|
1359
1554
|
init_scheduler();
|
|
1360
1555
|
init_executor();
|
|
1361
1556
|
init_node_registry();
|
|
1557
|
+
init_agent_session_metadata();
|
|
1362
1558
|
init_logger();
|
|
1363
1559
|
init_decorator();
|
|
1364
1560
|
init_template_resolver();
|
|
@@ -1379,10 +1575,12 @@ var init_engine = __esm(() => {
|
|
|
1379
1575
|
static async create(options) {
|
|
1380
1576
|
const agentComponent = options.env?.getComponent("agent");
|
|
1381
1577
|
const sessionComponent = options.sessionComponent;
|
|
1578
|
+
const llmComponent = options.env?.getComponent("llm");
|
|
1382
1579
|
const nodeRegistry = new NodeRegistry({
|
|
1383
1580
|
toolRegistry: options.toolRegistry,
|
|
1384
1581
|
skillRegistry: options.skillRegistry,
|
|
1385
1582
|
agentComponent,
|
|
1583
|
+
llmComponent,
|
|
1386
1584
|
workflowRunner: options.workflowRunner,
|
|
1387
1585
|
sessionComponent
|
|
1388
1586
|
});
|
|
@@ -1410,6 +1608,8 @@ var init_engine = __esm(() => {
|
|
|
1410
1608
|
workflowName,
|
|
1411
1609
|
workflowVersion: definition.version,
|
|
1412
1610
|
status: "running",
|
|
1611
|
+
runId,
|
|
1612
|
+
startedAt: Date.now(),
|
|
1413
1613
|
input: options?.input,
|
|
1414
1614
|
agentSessions: []
|
|
1415
1615
|
};
|
|
@@ -1494,14 +1694,20 @@ var init_engine = __esm(() => {
|
|
|
1494
1694
|
}
|
|
1495
1695
|
}
|
|
1496
1696
|
const messages = this.sessionComponent ? await this.sessionComponent.getMessages(sessionId) : [];
|
|
1497
|
-
const {
|
|
1697
|
+
const {
|
|
1698
|
+
inferNextNode,
|
|
1699
|
+
extractResumeInfo,
|
|
1700
|
+
enrichResumeInfoWithAgentSessions,
|
|
1701
|
+
enrichResumePointWithAgentSessions
|
|
1702
|
+
} = await import("./roy-agent-core-2vhsccvz.js");
|
|
1498
1703
|
const entry = workflowDef.entry;
|
|
1499
1704
|
const entryNode = Array.isArray(entry) ? entry[0] : entry;
|
|
1500
|
-
const
|
|
1501
|
-
const
|
|
1705
|
+
const agentSessions = metadata.agentSessions ?? [];
|
|
1706
|
+
const resumeInfo = enrichResumeInfoWithAgentSessions(extractResumeInfo(messages), agentSessions);
|
|
1707
|
+
const resumePoint = enrichResumePointWithAgentSessions(inferNextNode(messages, {
|
|
1502
1708
|
entryNode: entryNode !== "__default_entry__" ? entryNode : undefined,
|
|
1503
1709
|
edges: undefined
|
|
1504
|
-
});
|
|
1710
|
+
}), agentSessions);
|
|
1505
1711
|
const sessionState = await this.initializeSessionState(sessionId, workflowDef, workflowId, workflowName, options);
|
|
1506
1712
|
this.activeSessions.set(sessionId, sessionState);
|
|
1507
1713
|
return this.runWithResume(sessionId, resumePoint, resumeInfo, options);
|
|
@@ -1522,7 +1728,20 @@ var init_engine = __esm(() => {
|
|
|
1522
1728
|
debug: options?.debug ?? definition.config?.debug ?? false
|
|
1523
1729
|
};
|
|
1524
1730
|
const executor = new Executor(this.nodeRegistry, eventBus, executorOptions, this.sessionComponent);
|
|
1525
|
-
const
|
|
1731
|
+
const rawRuntimeInput = options?.workflowInput ?? options?.input;
|
|
1732
|
+
let persistedInput = {};
|
|
1733
|
+
if (this.sessionComponent) {
|
|
1734
|
+
const existingSession = await this.sessionComponent.get(sessionId);
|
|
1735
|
+
const metaInput = existingSession?.metadata?.input;
|
|
1736
|
+
if (metaInput) {
|
|
1737
|
+
const { userQuery: _omit, ...rest } = metaInput;
|
|
1738
|
+
persistedInput = rest;
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
const { stripEphemeralResumeInput } = await import("./roy-agent-core-2vhsccvz.js");
|
|
1742
|
+
const { workflowInput: runtimeInput } = stripEphemeralResumeInput(rawRuntimeInput);
|
|
1743
|
+
const mergedWorkflowInput = { ...persistedInput, ...runtimeInput };
|
|
1744
|
+
const workflowInput = Object.keys(mergedWorkflowInput).length > 0 ? mergedWorkflowInput : undefined;
|
|
1526
1745
|
const config = {
|
|
1527
1746
|
parallelLimit,
|
|
1528
1747
|
timeout: options?.timeout ?? definition.config?.timeout ?? null,
|
|
@@ -1698,15 +1917,22 @@ var init_engine = __esm(() => {
|
|
|
1698
1917
|
sessionState.abortController.abort();
|
|
1699
1918
|
if (this.sessionComponent) {
|
|
1700
1919
|
const metadata = await this.getSessionMetadata(sessionId);
|
|
1920
|
+
const agentSessions = updateAgentSessionStatus(metadata.agentSessions, event.node_id, "paused");
|
|
1701
1921
|
await this.sessionComponent.update(sessionId, {
|
|
1702
|
-
metadata: {
|
|
1922
|
+
metadata: {
|
|
1923
|
+
...metadata,
|
|
1924
|
+
status: "paused",
|
|
1925
|
+
pendingNodeId: event.node_id,
|
|
1926
|
+
pauseReason: "ask_user",
|
|
1927
|
+
agentSessions
|
|
1928
|
+
}
|
|
1703
1929
|
});
|
|
1704
1930
|
}
|
|
1705
1931
|
await eventBus.publish(createWorkflowEvent("workflow.paused", runId, {
|
|
1706
1932
|
pendingNodeId: event.node_id,
|
|
1707
1933
|
query: event.query
|
|
1708
1934
|
}));
|
|
1709
|
-
await
|
|
1935
|
+
await sessionState.executor.writeNodeInterrupt(sessionId, event.node_id, event.node_type, event.query, event.agent_session_id);
|
|
1710
1936
|
sessionState.resolveCompleted({
|
|
1711
1937
|
runId,
|
|
1712
1938
|
status: "paused",
|
|
@@ -1716,29 +1942,15 @@ var init_engine = __esm(() => {
|
|
|
1716
1942
|
});
|
|
1717
1943
|
});
|
|
1718
1944
|
}
|
|
1719
|
-
async writeNodeInterrupt(sessionId, nodeId, nodeType, query, agentSessionId) {
|
|
1720
|
-
if (this.sessionComponent) {
|
|
1721
|
-
await this.sessionComponent.addMessage(sessionId, {
|
|
1722
|
-
role: "workflow.node.interrupt",
|
|
1723
|
-
content: query,
|
|
1724
|
-
metadata: {
|
|
1725
|
-
type: "workflow.node.interrupt",
|
|
1726
|
-
workflowNodeId: nodeId,
|
|
1727
|
-
workflowNodeType: nodeType,
|
|
1728
|
-
query,
|
|
1729
|
-
agentSessionId,
|
|
1730
|
-
timestamp: Date.now()
|
|
1731
|
-
}
|
|
1732
|
-
});
|
|
1733
|
-
}
|
|
1734
|
-
}
|
|
1735
1945
|
async scheduleAndExecute(sessionState, options) {
|
|
1736
1946
|
const { scheduler, executor, eventBus, abortController, nodeOutputs } = sessionState;
|
|
1737
1947
|
const { input: globalInput, pendingNodeId, agentSessionId, restoredOutputs } = options || {};
|
|
1738
|
-
|
|
1948
|
+
const { stripEphemeralResumeInput } = await import("./roy-agent-core-2vhsccvz.js");
|
|
1949
|
+
const { workflowInput: inputToPersist, userQuery: resumeUserQuery } = stripEphemeralResumeInput(globalInput);
|
|
1950
|
+
if (inputToPersist) {
|
|
1739
1951
|
sessionState.config.workflowInput = {
|
|
1740
1952
|
...sessionState.config.workflowInput || {},
|
|
1741
|
-
...
|
|
1953
|
+
...inputToPersist
|
|
1742
1954
|
};
|
|
1743
1955
|
}
|
|
1744
1956
|
sessionState.loopIterationCount = 0;
|
|
@@ -1770,7 +1982,7 @@ var init_engine = __esm(() => {
|
|
|
1770
1982
|
if (pendingNodeId) {
|
|
1771
1983
|
await this.resumeNode(sessionState, pendingNodeId, {
|
|
1772
1984
|
agentSessionId,
|
|
1773
|
-
userQuery:
|
|
1985
|
+
userQuery: resumeUserQuery
|
|
1774
1986
|
});
|
|
1775
1987
|
} else {
|
|
1776
1988
|
await scheduleAvailableNodes();
|
|
@@ -1855,58 +2067,35 @@ var init_engine = __esm(() => {
|
|
|
1855
2067
|
});
|
|
1856
2068
|
}
|
|
1857
2069
|
}
|
|
1858
|
-
async writeNodeResume(sessionId, nodeId, userResponse) {
|
|
1859
|
-
if (this.sessionComponent && userResponse) {
|
|
1860
|
-
await this.sessionComponent.addMessage(sessionId, {
|
|
1861
|
-
role: "workflow.node.resume",
|
|
1862
|
-
content: JSON.stringify({ userResponse }),
|
|
1863
|
-
metadata: {
|
|
1864
|
-
type: "workflow.node.resume",
|
|
1865
|
-
workflowNodeId: nodeId,
|
|
1866
|
-
timestamp: Date.now()
|
|
1867
|
-
}
|
|
1868
|
-
});
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
2070
|
async resumeNode(sessionState, nodeId, options) {
|
|
1872
2071
|
const { scheduler, executor, eventBus, dagManager } = sessionState;
|
|
1873
2072
|
const sessionId = sessionState.sessionId;
|
|
1874
2073
|
const runId = this.getRunIdFromSessionId(sessionId);
|
|
1875
2074
|
scheduler.markStarted(nodeId);
|
|
1876
|
-
await this.writeNodeResume(sessionId, nodeId, options?.userQuery);
|
|
1877
|
-
await eventBus.publish(createWorkflowEvent("node.started", runId, {
|
|
1878
|
-
node_id: nodeId,
|
|
1879
|
-
agentSessionId: options?.agentSessionId,
|
|
1880
|
-
userQuery: options?.userQuery
|
|
1881
|
-
}));
|
|
1882
2075
|
const nodeDef = dagManager.getNode(nodeId);
|
|
1883
2076
|
if (!nodeDef) {
|
|
1884
2077
|
scheduler.markFailed(nodeId);
|
|
1885
2078
|
return;
|
|
1886
2079
|
}
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
} catch (error) {
|
|
1907
|
-
console.error(`Failed to resume agent node ${nodeId}:`, error);
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
2080
|
+
let agentSessionId = options?.agentSessionId;
|
|
2081
|
+
if (!agentSessionId && this.sessionComponent) {
|
|
2082
|
+
const session = await this.sessionComponent.get(sessionId);
|
|
2083
|
+
const agentSessions = session?.metadata?.agentSessions;
|
|
2084
|
+
const { resolveAgentSessionId } = await import("./roy-agent-core-2vhsccvz.js");
|
|
2085
|
+
agentSessionId = resolveAgentSessionId(nodeId, undefined, agentSessions);
|
|
2086
|
+
}
|
|
2087
|
+
await sessionState.executor.writeNodeResume(sessionId, nodeId, nodeDef.type, options?.userQuery ?? "", agentSessionId);
|
|
2088
|
+
await eventBus.publish(createWorkflowEvent("node.started", runId, {
|
|
2089
|
+
node_id: nodeId,
|
|
2090
|
+
agentSessionId,
|
|
2091
|
+
userQuery: options?.userQuery
|
|
2092
|
+
}));
|
|
2093
|
+
const context = this.buildNodeContext(sessionState, nodeId, sessionState.config.workflowInput);
|
|
2094
|
+
if (options?.userQuery !== undefined) {
|
|
2095
|
+
context.input.userQuery = options.userQuery;
|
|
2096
|
+
}
|
|
2097
|
+
if (agentSessionId) {
|
|
2098
|
+
context.agentSessionId = agentSessionId;
|
|
1910
2099
|
}
|
|
1911
2100
|
await this.validateAndExecute(nodeDef, context, sessionState);
|
|
1912
2101
|
}
|
|
@@ -1990,7 +2179,17 @@ var init_engine = __esm(() => {
|
|
|
1990
2179
|
}));
|
|
1991
2180
|
}
|
|
1992
2181
|
if (edgeResult.reEntries.length > 0) {
|
|
1993
|
-
sessionState.
|
|
2182
|
+
if (sessionState.config.loopEnabled) {
|
|
2183
|
+
const nextCount = sessionState.loopIterationCount + edgeResult.reEntries.length;
|
|
2184
|
+
if (nextCount > sessionState.config.maxIterations) {
|
|
2185
|
+
logger2.error(`[WorkflowEngine] Max loop iterations ${sessionState.config.maxIterations} exceeded (next=${nextCount})`);
|
|
2186
|
+
await this.failWorkflow(sessionState, new WorkflowError(`Workflow exceeded maximum loop iterations: ${sessionState.config.maxIterations}`));
|
|
2187
|
+
return;
|
|
2188
|
+
}
|
|
2189
|
+
sessionState.loopIterationCount = nextCount;
|
|
2190
|
+
} else {
|
|
2191
|
+
sessionState.loopIterationCount += edgeResult.reEntries.length;
|
|
2192
|
+
}
|
|
1994
2193
|
logger2.debug(`[WorkflowEngine] Loop iteration #${sessionState.loopIterationCount}: re-entering ${edgeResult.reEntries.join(", ")}`);
|
|
1995
2194
|
}
|
|
1996
2195
|
const workflowInput = sessionState.config.workflowInput || {};
|
|
@@ -2015,7 +2214,8 @@ var init_engine = __esm(() => {
|
|
|
2015
2214
|
input[depId] = depOutput;
|
|
2016
2215
|
}
|
|
2017
2216
|
}
|
|
2018
|
-
const
|
|
2217
|
+
const rawWorkflowInput = globalInput ?? sessionState.config.workflowInput ?? {};
|
|
2218
|
+
const { userQuery: _ephemeral, ...workflowInput } = rawWorkflowInput;
|
|
2019
2219
|
const templateResolver = new TemplateResolver({
|
|
2020
2220
|
input: workflowInput,
|
|
2021
2221
|
previousOutputs: new Map(sessionState.nodeOutputs)
|
|
@@ -2037,6 +2237,9 @@ var init_engine = __esm(() => {
|
|
|
2037
2237
|
workflowHistory: sessionState.workflowHistory,
|
|
2038
2238
|
sessionComponent: this.sessionComponent,
|
|
2039
2239
|
askUser,
|
|
2240
|
+
attachAgentSessionToLastStart: async (targetNodeId, agentSessionId) => {
|
|
2241
|
+
await sessionState.executor.attachAgentSessionToLastStart(sessionState.sessionId, targetNodeId, agentSessionId);
|
|
2242
|
+
},
|
|
2040
2243
|
workflowInput,
|
|
2041
2244
|
templateResolver,
|
|
2042
2245
|
resolvedConfig: templateResolver.resolveValue(nodeDef.config ?? {})
|
|
@@ -2068,7 +2271,16 @@ var init_engine = __esm(() => {
|
|
|
2068
2271
|
if (this.sessionComponent) {
|
|
2069
2272
|
const metadata = await this.getSessionMetadata(sessionId);
|
|
2070
2273
|
await this.sessionComponent.update(sessionId, {
|
|
2071
|
-
metadata: {
|
|
2274
|
+
metadata: {
|
|
2275
|
+
...metadata,
|
|
2276
|
+
status: "completed",
|
|
2277
|
+
completedAt: Date.now(),
|
|
2278
|
+
durationMs,
|
|
2279
|
+
output,
|
|
2280
|
+
pendingNodeId: undefined,
|
|
2281
|
+
pauseReason: undefined,
|
|
2282
|
+
agentSessions: markAllAgentSessionsCompleted(metadata.agentSessions)
|
|
2283
|
+
}
|
|
2072
2284
|
});
|
|
2073
2285
|
}
|
|
2074
2286
|
await sessionState.eventBus.publish(createWorkflowEvent("workflow.completed", runId, {
|
|
@@ -2095,7 +2307,12 @@ var init_engine = __esm(() => {
|
|
|
2095
2307
|
if (this.sessionComponent) {
|
|
2096
2308
|
const metadata = await this.getSessionMetadata(sessionId);
|
|
2097
2309
|
await this.sessionComponent.update(sessionId, {
|
|
2098
|
-
metadata: {
|
|
2310
|
+
metadata: {
|
|
2311
|
+
...metadata,
|
|
2312
|
+
status: "failed",
|
|
2313
|
+
failedAt: Date.now(),
|
|
2314
|
+
durationMs
|
|
2315
|
+
}
|
|
2099
2316
|
});
|
|
2100
2317
|
}
|
|
2101
2318
|
await sessionState.eventBus.publish(createWorkflowEvent("workflow.failed", runId, {
|
|
@@ -2168,9 +2385,6 @@ var init_engine = __esm(() => {
|
|
|
2168
2385
|
__legacyDecorateClassTS([
|
|
2169
2386
|
TracedAs("workflow.engine.stop", { recordParams: true, recordResult: true, log: true })
|
|
2170
2387
|
], WorkflowEngine.prototype, "stop", null);
|
|
2171
|
-
__legacyDecorateClassTS([
|
|
2172
|
-
TracedAs("workflow.engine.writeNodeInterrupt", { recordParams: true, recordResult: true, log: true })
|
|
2173
|
-
], WorkflowEngine.prototype, "writeNodeInterrupt", null);
|
|
2174
2388
|
__legacyDecorateClassTS([
|
|
2175
2389
|
TracedAs("workflow.engine.scheduleAndExecute", { recordParams: true, recordResult: true, log: true })
|
|
2176
2390
|
], WorkflowEngine.prototype, "scheduleAndExecute", null);
|
|
@@ -2183,9 +2397,6 @@ var init_engine = __esm(() => {
|
|
|
2183
2397
|
__legacyDecorateClassTS([
|
|
2184
2398
|
TracedAs("workflow.engine.writeNodeStart", { recordParams: true, recordResult: true, log: true })
|
|
2185
2399
|
], WorkflowEngine.prototype, "writeNodeStart", null);
|
|
2186
|
-
__legacyDecorateClassTS([
|
|
2187
|
-
TracedAs("workflow.engine.writeNodeResume", { recordParams: true, recordResult: true, log: true })
|
|
2188
|
-
], WorkflowEngine.prototype, "writeNodeResume", null);
|
|
2189
2400
|
__legacyDecorateClassTS([
|
|
2190
2401
|
TracedAs("workflow.engine.resumeNode", { recordParams: true, recordResult: true, log: true })
|
|
2191
2402
|
], WorkflowEngine.prototype, "resumeNode", null);
|