@ai-setting/roy-agent-core 1.5.46 → 1.5.47

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.
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  AgentComponent,
3
3
  AgentComponentConfigSchema
4
- } from "../../shared/@ai-setting/roy-agent-core-3t82jyqb.js";
4
+ } from "../../shared/@ai-setting/roy-agent-core-38sc085e.js";
5
5
  import"../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
6
- import"../../shared/@ai-setting/roy-agent-core-fg3j215p.js";
6
+ import"../../shared/@ai-setting/roy-agent-core-emk3q2nt.js";
7
7
  import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
8
8
  import"../../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
9
9
  import {
package/dist/env/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BaseEnvironment
3
- } from "../shared/@ai-setting/roy-agent-core-r9hq4cjx.js";
3
+ } from "../shared/@ai-setting/roy-agent-core-a23brrex.js";
4
4
  import {
5
5
  EventSourceComponent,
6
6
  builtInHandlers,
@@ -21,11 +21,11 @@ import"../shared/@ai-setting/roy-agent-core-4gmxjdhn.js";
21
21
  import"../shared/@ai-setting/roy-agent-core-az13yzmc.js";
22
22
  import {
23
23
  WorkflowComponent
24
- } from "../shared/@ai-setting/roy-agent-core-frjr619w.js";
24
+ } from "../shared/@ai-setting/roy-agent-core-1t5esk1r.js";
25
25
  import"../shared/@ai-setting/roy-agent-core-9bmtxmp6.js";
26
- import"../shared/@ai-setting/roy-agent-core-btvxttqf.js";
27
- import"../shared/@ai-setting/roy-agent-core-44g4dhzg.js";
28
- import"../shared/@ai-setting/roy-agent-core-dbxm76wf.js";
26
+ import"../shared/@ai-setting/roy-agent-core-1rzpnycm.js";
27
+ import"../shared/@ai-setting/roy-agent-core-2rtka82a.js";
28
+ import"../shared/@ai-setting/roy-agent-core-kzbj10gk.js";
29
29
  import"../shared/@ai-setting/roy-agent-core-6atd905e.js";
30
30
  import"../shared/@ai-setting/roy-agent-core-v002ynpa.js";
31
31
  import"../shared/@ai-setting/roy-agent-core-4t40mkpv.js";
@@ -38,15 +38,15 @@ import"../shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
38
38
  import {
39
39
  AgentComponent,
40
40
  AgentComponentConfigSchema
41
- } from "../shared/@ai-setting/roy-agent-core-3t82jyqb.js";
41
+ } from "../shared/@ai-setting/roy-agent-core-38sc085e.js";
42
42
  import"../shared/@ai-setting/roy-agent-core-e25xkv53.js";
43
43
  import {
44
44
  TaskComponent
45
- } from "../shared/@ai-setting/roy-agent-core-6z063hns.js";
45
+ } from "../shared/@ai-setting/roy-agent-core-t1ytby5n.js";
46
46
  import"../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
47
- import"../shared/@ai-setting/roy-agent-core-8y804aat.js";
47
+ import"../shared/@ai-setting/roy-agent-core-jqq7c2rk.js";
48
48
  import"../shared/@ai-setting/roy-agent-core-hsxn8m1j.js";
49
- import"../shared/@ai-setting/roy-agent-core-fg3j215p.js";
49
+ import"../shared/@ai-setting/roy-agent-core-emk3q2nt.js";
50
50
  import {
51
51
  XDG_PATHS,
52
52
  getXDGPath,
@@ -3,8 +3,8 @@ import {
3
3
  BackgroundTaskManager,
4
4
  createDelegateTool,
5
5
  createStopTool
6
- } from "../../../shared/@ai-setting/roy-agent-core-8y804aat.js";
7
- import"../../../shared/@ai-setting/roy-agent-core-fg3j215p.js";
6
+ } from "../../../shared/@ai-setting/roy-agent-core-jqq7c2rk.js";
7
+ import"../../../shared/@ai-setting/roy-agent-core-emk3q2nt.js";
8
8
  import"../../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
9
9
  import"../../../shared/@ai-setting/roy-agent-core-92z6t4he.js";
10
10
  import"../../../shared/@ai-setting/roy-agent-core-q5qj0fes.js";
@@ -4,15 +4,15 @@ import {
4
4
  TaskConfigSchema,
5
5
  TaskPriorityEnum,
6
6
  TaskStatusEnum
7
- } from "../../shared/@ai-setting/roy-agent-core-6z063hns.js";
7
+ } from "../../shared/@ai-setting/roy-agent-core-t1ytby5n.js";
8
8
  import {
9
9
  TaskEntityEventTypes
10
10
  } from "../../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
11
- import"../../shared/@ai-setting/roy-agent-core-8y804aat.js";
11
+ import"../../shared/@ai-setting/roy-agent-core-jqq7c2rk.js";
12
12
  import {
13
13
  SQLiteTaskStore
14
14
  } from "../../shared/@ai-setting/roy-agent-core-hsxn8m1j.js";
15
- import"../../shared/@ai-setting/roy-agent-core-fg3j215p.js";
15
+ import"../../shared/@ai-setting/roy-agent-core-emk3q2nt.js";
16
16
  import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
17
17
  import"../../shared/@ai-setting/roy-agent-core-wa1kzqky.js";
18
18
  import"../../shared/@ai-setting/roy-agent-core-t94ktchq.js";
@@ -6,9 +6,9 @@ import {
6
6
  Scheduler,
7
7
  WorkflowEngine,
8
8
  init_engine
9
- } from "../../../shared/@ai-setting/roy-agent-core-btvxttqf.js";
10
- import"../../../shared/@ai-setting/roy-agent-core-44g4dhzg.js";
11
- import"../../../shared/@ai-setting/roy-agent-core-dbxm76wf.js";
9
+ } from "../../../shared/@ai-setting/roy-agent-core-1rzpnycm.js";
10
+ import"../../../shared/@ai-setting/roy-agent-core-2rtka82a.js";
11
+ import"../../../shared/@ai-setting/roy-agent-core-kzbj10gk.js";
12
12
  import"../../../shared/@ai-setting/roy-agent-core-6atd905e.js";
13
13
  import"../../../shared/@ai-setting/roy-agent-core-v002ynpa.js";
14
14
  import"../../../shared/@ai-setting/roy-agent-core-6vxg2gmr.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  WorkflowComponent
3
- } from "../../shared/@ai-setting/roy-agent-core-frjr619w.js";
3
+ } from "../../shared/@ai-setting/roy-agent-core-1t5esk1r.js";
4
4
  import"../../shared/@ai-setting/roy-agent-core-9bmtxmp6.js";
5
- import"../../shared/@ai-setting/roy-agent-core-btvxttqf.js";
6
- import"../../shared/@ai-setting/roy-agent-core-44g4dhzg.js";
7
- import"../../shared/@ai-setting/roy-agent-core-dbxm76wf.js";
5
+ import"../../shared/@ai-setting/roy-agent-core-1rzpnycm.js";
6
+ import"../../shared/@ai-setting/roy-agent-core-2rtka82a.js";
7
+ import"../../shared/@ai-setting/roy-agent-core-kzbj10gk.js";
8
8
  import"../../shared/@ai-setting/roy-agent-core-6atd905e.js";
9
9
  import"../../shared/@ai-setting/roy-agent-core-v002ynpa.js";
10
10
  import"../../shared/@ai-setting/roy-agent-core-4t40mkpv.js";
package/dist/index.js CHANGED
@@ -61,7 +61,7 @@ import {
61
61
  BaseEnvironment,
62
62
  generateDescendingId,
63
63
  generateId
64
- } from "./shared/@ai-setting/roy-agent-core-r9hq4cjx.js";
64
+ } from "./shared/@ai-setting/roy-agent-core-a23brrex.js";
65
65
  import {
66
66
  EventSourceComponent,
67
67
  builtInHandlers,
@@ -92,14 +92,14 @@ import {
92
92
  } from "./shared/@ai-setting/roy-agent-core-az13yzmc.js";
93
93
  import {
94
94
  WorkflowComponent
95
- } from "./shared/@ai-setting/roy-agent-core-frjr619w.js";
95
+ } from "./shared/@ai-setting/roy-agent-core-1t5esk1r.js";
96
96
  import {
97
97
  init_node_registry_helper,
98
98
  registerDecoratorNodeType
99
99
  } from "./shared/@ai-setting/roy-agent-core-9bmtxmp6.js";
100
- import"./shared/@ai-setting/roy-agent-core-btvxttqf.js";
101
- import"./shared/@ai-setting/roy-agent-core-44g4dhzg.js";
102
- import"./shared/@ai-setting/roy-agent-core-dbxm76wf.js";
100
+ import"./shared/@ai-setting/roy-agent-core-1rzpnycm.js";
101
+ import"./shared/@ai-setting/roy-agent-core-2rtka82a.js";
102
+ import"./shared/@ai-setting/roy-agent-core-kzbj10gk.js";
103
103
  import"./shared/@ai-setting/roy-agent-core-6atd905e.js";
104
104
  import"./shared/@ai-setting/roy-agent-core-v002ynpa.js";
105
105
  import"./shared/@ai-setting/roy-agent-core-4t40mkpv.js";
@@ -118,20 +118,20 @@ import"./shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
118
118
  import {
119
119
  AgentComponent,
120
120
  AgentComponentConfigSchema
121
- } from "./shared/@ai-setting/roy-agent-core-3t82jyqb.js";
121
+ } from "./shared/@ai-setting/roy-agent-core-38sc085e.js";
122
122
  import {
123
123
  AskUserError,
124
124
  init_workflow_hil
125
125
  } from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
126
126
  import {
127
127
  TaskComponent
128
- } from "./shared/@ai-setting/roy-agent-core-6z063hns.js";
128
+ } from "./shared/@ai-setting/roy-agent-core-t1ytby5n.js";
129
129
  import"./shared/@ai-setting/roy-agent-core-8gxth0eh.js";
130
- import"./shared/@ai-setting/roy-agent-core-8y804aat.js";
130
+ import"./shared/@ai-setting/roy-agent-core-jqq7c2rk.js";
131
131
  import"./shared/@ai-setting/roy-agent-core-hsxn8m1j.js";
132
132
  import {
133
133
  AgentRegistry
134
- } from "./shared/@ai-setting/roy-agent-core-fg3j215p.js";
134
+ } from "./shared/@ai-setting/roy-agent-core-emk3q2nt.js";
135
135
  import {
136
136
  XDG_PATHS,
137
137
  getXDGPath,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AgentComponentAdapter,
3
3
  init_agent_component_adapter
4
- } from "./roy-agent-core-44g4dhzg.js";
4
+ } from "./roy-agent-core-2rtka82a.js";
5
5
  import {
6
6
  buildWorkflowNodeMetadata,
7
7
  getWorkflowNodeIdFromMetadata,
@@ -1136,6 +1136,7 @@ function extractAgentJsonOutput(agentResult, schema) {
1136
1136
  const candidates = [
1137
1137
  agentResult.structuredOutput,
1138
1138
  asRecord(agentResult.output),
1139
+ extractFromOutputText(agentResult.output),
1139
1140
  extractFromToolCalls(agentResult),
1140
1141
  extractFromMessages(agentResult.messages)
1141
1142
  ];
@@ -1153,6 +1154,66 @@ function asRecord(value) {
1153
1154
  }
1154
1155
  return;
1155
1156
  }
1157
+ function extractFromOutputText(output) {
1158
+ if (typeof output !== "string" || !output.trim()) {
1159
+ return;
1160
+ }
1161
+ const trimmed = output.trim();
1162
+ try {
1163
+ const parsed = JSON.parse(trimmed);
1164
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
1165
+ return parsed;
1166
+ }
1167
+ } catch {}
1168
+ const jsonBlockMatch = trimmed.match(/```(?:json)?\s*\n?(\{[\s\S]*?\})\n?\s*```/);
1169
+ if (jsonBlockMatch) {
1170
+ try {
1171
+ const parsed = JSON.parse(jsonBlockMatch[1]);
1172
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
1173
+ return parsed;
1174
+ }
1175
+ } catch {}
1176
+ }
1177
+ for (let i = 0;i < trimmed.length; i++) {
1178
+ if (trimmed[i] !== "{")
1179
+ continue;
1180
+ let depth = 0;
1181
+ let inString = false;
1182
+ let escape = false;
1183
+ for (let j = i;j < trimmed.length; j++) {
1184
+ const ch = trimmed[j];
1185
+ if (escape) {
1186
+ escape = false;
1187
+ continue;
1188
+ }
1189
+ if (ch === "\\" && inString) {
1190
+ escape = true;
1191
+ continue;
1192
+ }
1193
+ if (ch === '"') {
1194
+ inString = !inString;
1195
+ continue;
1196
+ }
1197
+ if (inString)
1198
+ continue;
1199
+ if (ch === "{")
1200
+ depth++;
1201
+ else if (ch === "}")
1202
+ depth--;
1203
+ if (depth === 0) {
1204
+ const candidate = trimmed.slice(i, j + 1);
1205
+ try {
1206
+ const parsed = JSON.parse(candidate);
1207
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
1208
+ return parsed;
1209
+ }
1210
+ } catch {}
1211
+ break;
1212
+ }
1213
+ }
1214
+ }
1215
+ return;
1216
+ }
1156
1217
  function extractFromToolCalls(agentResult) {
1157
1218
  const toolCalls = agentResult.metadata?.toolCallsDetail;
1158
1219
  if (!toolCalls?.length) {
@@ -1216,7 +1277,18 @@ function buildAgentNodeOutput(agentResult, outputConfig) {
1216
1277
  const schema = outputConfig.schema;
1217
1278
  const jsonData = extractAgentJsonOutput(agentResult, schema);
1218
1279
  if (!jsonData) {
1219
- throw new Error("AgentNode json output mode requires structured JSON from workflow_submit_output");
1280
+ const defaults = buildSchemaDefaults(schema);
1281
+ const fallbackData = { ...defaults, rawOutput: agentResult.output };
1282
+ return {
1283
+ result: fallbackData,
1284
+ ...fallbackData,
1285
+ metadata: {
1286
+ ...agentResult.metadata,
1287
+ outputMode: "json_fallback",
1288
+ _extractionWarning: "JSON extraction failed, using defaults"
1289
+ },
1290
+ workflowHistory: agentResult.messages
1291
+ };
1220
1292
  }
1221
1293
  return {
1222
1294
  result: jsonData,
@@ -1233,6 +1305,31 @@ function buildAgentNodeOutput(agentResult, outputConfig) {
1233
1305
  ...base
1234
1306
  };
1235
1307
  }
1308
+ function buildSchemaDefaults(schema) {
1309
+ const defaults = {};
1310
+ if (!schema?.properties || !schema?.required)
1311
+ return defaults;
1312
+ for (const key of schema.required) {
1313
+ const prop = schema.properties[key];
1314
+ if (!prop?.type)
1315
+ continue;
1316
+ switch (prop.type) {
1317
+ case "boolean":
1318
+ defaults[key] = false;
1319
+ break;
1320
+ case "string":
1321
+ defaults[key] = "";
1322
+ break;
1323
+ case "number":
1324
+ case "integer":
1325
+ defaults[key] = 0;
1326
+ break;
1327
+ default:
1328
+ defaults[key] = null;
1329
+ }
1330
+ }
1331
+ return defaults;
1332
+ }
1236
1333
  var init_build_agent_node_output = __esm(() => {
1237
1334
  init_extract_agent_json_output();
1238
1335
  });
@@ -1292,7 +1389,7 @@ var init_agent_node = __esm(() => {
1292
1389
  await context.attachAgentSessionToLastStart(this.definition.id, agentSessionId);
1293
1390
  }
1294
1391
  }
1295
- const allowedTools = ["ask_user"];
1392
+ const allowedTools = options.allowedTools?.length ? options.allowedTools : ["ask_user"];
1296
1393
  const agentConfig = {
1297
1394
  type: agentType,
1298
1395
  prompt: resolvedPrompt,
@@ -6,7 +6,7 @@ import {
6
6
  WorkflowEngine,
7
7
  exports_engine,
8
8
  init_engine
9
- } from "./roy-agent-core-btvxttqf.js";
9
+ } from "./roy-agent-core-1rzpnycm.js";
10
10
  import {
11
11
  WorkflowService
12
12
  } from "./roy-agent-core-4t40mkpv.js";
@@ -136,7 +136,7 @@ class WorkflowComponent extends BaseComponent {
136
136
  const agentComponent = this._workflowEnv.getComponent("agent");
137
137
  const llmComponent = this._workflowEnv.getComponent("llm");
138
138
  if (agentComponent) {
139
- const { AgentComponentAdapter } = await import("./roy-agent-core-ye0z728h.js");
139
+ const { AgentComponentAdapter } = await import("./roy-agent-core-twd8kzag.js");
140
140
  agentRunner = new AgentComponentAdapter(agentComponent, {}, this.sessionComponent, llmComponent);
141
141
  }
142
142
  }
@@ -208,7 +208,7 @@ class WorkflowComponent extends BaseComponent {
208
208
  const sessionComponent = this._workflowEnv?.getComponent("session");
209
209
  componentLogger.info(`initSqliteService - toolComponent: ${!!toolComponent}, llmComponent: ${!!llmComponent}, skillRegistry: ${!!skillComponent}, sessionComponent: ${!!sessionComponent}`);
210
210
  if (llmComponent) {
211
- const { registerWorkflowJsonOutputPlugin } = await import("./roy-agent-core-68qy97r3.js");
211
+ const { registerWorkflowJsonOutputPlugin } = await import("./roy-agent-core-ebap34m2.js");
212
212
  registerWorkflowJsonOutputPlugin(llmComponent);
213
213
  }
214
214
  this.createService({
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  WORKFLOW_JSON_OUTPUT_PLUGIN_KEY,
3
- extractStructuredJsonViaLlm,
4
3
  init_workflow_json_output_plugin,
5
- registerWorkflowJsonOutputPlugin
6
- } from "./roy-agent-core-dbxm76wf.js";
4
+ registerWorkflowJsonOutputPlugin,
5
+ tracedExtractStructuredJsonViaLlm
6
+ } from "./roy-agent-core-kzbj10gk.js";
7
7
  import {
8
8
  AskUserError,
9
9
  init_workflow_hil
@@ -229,7 +229,7 @@ class AgentComponentAdapter {
229
229
  role: m.role,
230
230
  content: m.content ?? ""
231
231
  }));
232
- return await extractStructuredJsonViaLlm(this._llmComponent, history, outputSchema, {
232
+ return await tracedExtractStructuredJsonViaLlm(this._llmComponent, history, outputSchema, {
233
233
  model: config.options?.model,
234
234
  sessionId: agentSessionId
235
235
  });
@@ -4,7 +4,7 @@ import {
4
4
  } from "./roy-agent-core-e25xkv53.js";
5
5
  import {
6
6
  AgentRegistry
7
- } from "./roy-agent-core-fg3j215p.js";
7
+ } from "./roy-agent-core-emk3q2nt.js";
8
8
  import {
9
9
  ContextError
10
10
  } from "./roy-agent-core-ctdhjv68.js";
@@ -889,12 +889,10 @@ class AgentComponent extends BaseComponent {
889
889
  sessionId: effectiveContext.sessionId,
890
890
  summary: result.finalText
891
891
  };
892
- await this.executePluginHooks(agent, "agent:after.react", {
893
- ...hookCtx,
894
- ...reactContext
895
- });
896
- if (hookCtx.structuredOutputExtracted) {
897
- result.structuredOutput = hookCtx.structuredOutputExtracted;
892
+ const mergedHookCtx = { ...hookCtx, ...reactContext };
893
+ await this.executePluginHooks(agent, "agent:after.react", mergedHookCtx);
894
+ if (mergedHookCtx.structuredOutputExtracted) {
895
+ result.structuredOutput = mergedHookCtx.structuredOutputExtracted;
898
896
  }
899
897
  await this.executePluginHooks(agent, "agent:after.complete", hookCtx);
900
898
  if (this.aborted.get(runId) === true || hookCtx._stopped) {
@@ -82,6 +82,14 @@ class BaseEnvironment extends BaseComponent {
82
82
  if (!agentComponent) {
83
83
  throw new Error("AgentComponent not found. Please register AgentComponent before calling handle_query.");
84
84
  }
85
+ const agentName = context?.agentType && context.agentType !== "default" ? context.agentType : "default";
86
+ const registry = agentComponent.getRegistry?.();
87
+ if (registry) {
88
+ const agentDef = registry.get(agentName);
89
+ if (agentDef?.type === "workflow") {
90
+ return await this.handleWorkflowAgentQuery(agentName, query, agentComponent);
91
+ }
92
+ }
85
93
  let systemPrompt = "You are a helpful assistant.";
86
94
  let promptSource = "fallback";
87
95
  try {
@@ -118,7 +126,6 @@ class BaseEnvironment extends BaseComponent {
118
126
  finalSystemPrompt = finalSystemPrompt.replace("{{workspace_dir}}", workspaceDir);
119
127
  logger.debug(`[handle_query] Injected workspace_dir: ${workspaceDir}`);
120
128
  }
121
- const agentName = context?.agentType && context.agentType !== "default" ? context.agentType : "default";
122
129
  let agent = agentComponent.getAgent(agentName);
123
130
  if (!agent) {
124
131
  if (agentName !== "default") {
@@ -155,6 +162,56 @@ class BaseEnvironment extends BaseComponent {
155
162
  }
156
163
  return result.finalText || "";
157
164
  }
165
+ async handleWorkflowAgentQuery(agentName, query, agentComponent) {
166
+ const registry = agentComponent.getRegistry?.();
167
+ if (!registry) {
168
+ return null;
169
+ }
170
+ const agentDef = registry.get(agentName);
171
+ if (!agentDef || agentDef.type !== "workflow") {
172
+ return null;
173
+ }
174
+ const workflowComponent = this.getComponent("workflow");
175
+ if (!workflowComponent) {
176
+ throw new Error(`WorkflowComponent not available — cannot run workflow agent "${agentName}". ` + `Ensure the workflow component is registered.`);
177
+ }
178
+ const workflowName = agentDef.workflow;
179
+ if (!workflowName) {
180
+ throw new Error(`Agent "${agentName}" has type 'workflow' but no workflow configured.`);
181
+ }
182
+ const svc = workflowComponent.getService?.();
183
+ if (!svc || typeof svc.getWorkflowByName !== "function") {
184
+ throw new Error(`WorkflowService not available. Cannot run workflow agent "${agentName}".`);
185
+ }
186
+ const workflow = svc.getWorkflowByName(workflowName);
187
+ if (!workflow) {
188
+ throw new Error(`Workflow "${workflowName}" not found. ` + `Use 'roy-agent workflow add' to register it first.`);
189
+ }
190
+ const wfResult = await workflowComponent.runWorkflow(workflow.definition, { query }, {});
191
+ if (wfResult.status === "paused") {
192
+ return JSON.stringify({
193
+ status: "paused",
194
+ message: `Workflow "${workflowName}" paused, waiting for user input.`,
195
+ pendingNodeId: wfResult.pendingNodeId,
196
+ query: wfResult.query,
197
+ sessionId: wfResult.sessionId,
198
+ hint: `Resume with: roy-agent workflow run -s ${wfResult.sessionId} --input "your response"`
199
+ });
200
+ }
201
+ if (wfResult.status === "failed") {
202
+ throw new Error(`Workflow "${workflowName}" execution failed: ${wfResult.error || "Unknown error (status: " + wfResult.status + ")"}`);
203
+ }
204
+ if (typeof wfResult.output === "string") {
205
+ return wfResult.output;
206
+ }
207
+ if (wfResult.output !== undefined && wfResult.output !== null) {
208
+ return JSON.stringify(wfResult.output);
209
+ }
210
+ if (wfResult.error) {
211
+ throw new Error(`Workflow "${workflowName}" completed with error: ${wfResult.error}`);
212
+ }
213
+ return "";
214
+ }
158
215
  async handle_action(action, context) {
159
216
  throw new Error("handle_action not implemented. Override in subclass.");
160
217
  }
@@ -424,6 +481,9 @@ class BaseEnvironment extends BaseComponent {
424
481
  __legacyDecorateClassTS([
425
482
  TracedAs("env.handle_query", { recordParams: true, recordResult: true, log: true })
426
483
  ], BaseEnvironment.prototype, "handle_query", null);
484
+ __legacyDecorateClassTS([
485
+ TracedAs("env.handle_workflow_agent_query", { recordParams: true, recordResult: true, log: true })
486
+ ], BaseEnvironment.prototype, "handleWorkflowAgentQuery", null);
427
487
 
428
488
  // src/env/index.ts
429
489
  init_context();
@@ -7,10 +7,13 @@ import {
7
7
  isWorkflowJsonOutputEnabled,
8
8
  registerWorkflowJsonOutputPlugin,
9
9
  runWorkflowJsonOutputExtraction,
10
+ tracedExtractStructuredJsonViaLlm,
11
+ tracedRunWorkflowJsonOutputExtraction,
10
12
  unregisterWorkflowJsonOutputPlugin
11
- } from "./roy-agent-core-dbxm76wf.js";
13
+ } from "./roy-agent-core-kzbj10gk.js";
12
14
  import"./roy-agent-core-nhfy3p8q.js";
13
15
  import"./roy-agent-core-e25xkv53.js";
16
+ import"./roy-agent-core-q5qj0fes.js";
14
17
  import"./roy-agent-core-rgj6hq15.js";
15
18
  import"./roy-agent-core-rm3hay00.js";
16
19
  import"./roy-agent-core-10n2jh7p.js";
@@ -21,6 +24,8 @@ init_workflow_json_output_plugin();
21
24
 
22
25
  export {
23
26
  unregisterWorkflowJsonOutputPlugin,
27
+ tracedRunWorkflowJsonOutputExtraction,
28
+ tracedExtractStructuredJsonViaLlm,
24
29
  runWorkflowJsonOutputExtraction,
25
30
  registerWorkflowJsonOutputPlugin,
26
31
  isWorkflowJsonOutputEnabled,
@@ -24,7 +24,8 @@ init_decorator();
24
24
  var logger = createLogger("agent:registry");
25
25
  var AgentConfigSchema = z.object({
26
26
  name: z.string(),
27
- type: z.enum(["primary", "sub"]),
27
+ type: z.enum(["primary", "sub", "workflow"]),
28
+ workflow: z.string().optional(),
28
29
  description: z.string().optional(),
29
30
  systemPromptRef: z.string().optional(),
30
31
  systemPrompt: z.string().optional(),
@@ -37,7 +38,7 @@ var AgentConfigSchema = z.object({
37
38
  toolRetries: z.number().optional(),
38
39
  doomLoopThreshold: z.number().optional(),
39
40
  filterHistory: z.boolean().optional()
40
- });
41
+ }).refine((data) => data.type !== "workflow" || data.workflow && data.workflow.length > 0, { message: "workflow is required when type is 'workflow'" });
41
42
 
42
43
  class AgentRegistry {
43
44
  agents = new Map;
@@ -78,6 +79,10 @@ class AgentRegistry {
78
79
  if (!agent.name) {
79
80
  throw new Error("Agent name is required");
80
81
  }
82
+ const validation = AgentConfigSchema.safeParse(agent);
83
+ if (!validation.success) {
84
+ throw new Error(`Invalid agent config for "${agent.name}": ${validation.error.issues.map((i) => i.message).join("; ")}`);
85
+ }
81
86
  this.agents.set(agent.name, { ...agent });
82
87
  logger.info(`[AgentRegistry] Registered agent: ${agent.name}`, { type: agent.type });
83
88
  }
@@ -133,6 +138,13 @@ class AgentRegistry {
133
138
  }
134
139
  return agent.systemPrompt;
135
140
  }
141
+ getWorkflowName(name) {
142
+ const agent = this.agents.get(name);
143
+ if (!agent || agent.type !== "workflow") {
144
+ return;
145
+ }
146
+ return agent.workflow;
147
+ }
136
148
  async load() {
137
149
  try {
138
150
  return await this.loadFromDirectory(this.configDir);
@@ -193,6 +205,11 @@ class AgentRegistry {
193
205
  }
194
206
  async saveAgent(agent) {
195
207
  try {
208
+ const validation = AgentConfigSchema.safeParse(agent);
209
+ if (!validation.success) {
210
+ logger.error(`[AgentRegistry] Invalid agent config for "${agent.name}": ${validation.error.message}`);
211
+ return false;
212
+ }
196
213
  await this.ensureConfigDir();
197
214
  const yamlContent = this.agentToYaml(agent);
198
215
  const filePath = join(this.configDir, `${agent.name}.yaml`);
@@ -226,7 +243,8 @@ class AgentRegistry {
226
243
  ...agent.toolTimeout !== undefined ? { toolTimeout: agent.toolTimeout } : {},
227
244
  ...agent.toolRetries !== undefined ? { toolRetries: agent.toolRetries } : {},
228
245
  ...agent.doomLoopThreshold !== undefined ? { doomLoopThreshold: agent.doomLoopThreshold } : {},
229
- ...agent.filterHistory !== undefined ? { filterHistory: agent.filterHistory } : {}
246
+ ...agent.filterHistory !== undefined ? { filterHistory: agent.filterHistory } : {},
247
+ ...agent.workflow !== undefined ? { workflow: agent.workflow } : {}
230
248
  };
231
249
  return yaml.stringify(config).trimEnd() + `
232
250
  `;
@@ -282,6 +300,9 @@ __legacyDecorateClassTS([
282
300
  __legacyDecorateClassTS([
283
301
  TracedAs("agent.registry.getSystemPrompt", { recordParams: true, recordResult: true, log: true })
284
302
  ], AgentRegistry.prototype, "getSystemPrompt", null);
303
+ __legacyDecorateClassTS([
304
+ TracedAs("agent.registry.getWorkflowName", { recordParams: true, recordResult: true })
305
+ ], AgentRegistry.prototype, "getWorkflowName", null);
285
306
  __legacyDecorateClassTS([
286
307
  TracedAs("agent.registry.load", { recordParams: false, recordResult: true, log: true })
287
308
  ], AgentRegistry.prototype, "load", null);
@@ -1,9 +1,13 @@
1
1
  import {
2
2
  DEFAULT_SUBAGENT_PROMPT
3
- } from "./roy-agent-core-fg3j215p.js";
3
+ } from "./roy-agent-core-emk3q2nt.js";
4
4
  import {
5
5
  TaskHookPoints
6
6
  } from "./roy-agent-core-92z6t4he.js";
7
+ import {
8
+ TracedAs,
9
+ init_decorator
10
+ } from "./roy-agent-core-q5qj0fes.js";
7
11
  import {
8
12
  globalHookManager,
9
13
  init_global_hook_manager
@@ -12,9 +16,13 @@ import {
12
16
  createLogger,
13
17
  init_logger
14
18
  } from "./roy-agent-core-10n2jh7p.js";
19
+ import {
20
+ __legacyDecorateClassTS
21
+ } from "./roy-agent-core-fs0mn2jk.js";
15
22
 
16
23
  // src/env/task/delegate/delegate-tool.ts
17
24
  init_logger();
25
+ init_decorator();
18
26
  import { z } from "zod";
19
27
 
20
28
  // src/env/task/delegate/subagent-resolver.ts
@@ -65,8 +73,14 @@ ${customAgentNote}
65
73
  }
66
74
  function listKnownSubagentDescriptions(registry) {
67
75
  const builtInLines = builtInSubAgents.map((agent) => `- ${agent.id}: ${agent.description}`);
68
- const registryAgents = registry?.listAgentsByType("sub") ?? [];
69
- const customLines = registryAgents.filter((agent) => !builtInSubAgents.some((builtIn) => builtIn.id === agent.name)).map((agent) => `- ${agent.name}: ${agent.description || "Custom agent"}`);
76
+ const registryAgents = registry?.list() ?? [];
77
+ const customLines = registryAgents.filter((agent) => !builtInSubAgents.some((builtIn) => builtIn.id === agent.name)).map((agent) => {
78
+ if (agent.type === "workflow") {
79
+ const workflowInfo = agent.workflow ? ` (workflow: ${agent.workflow})` : "";
80
+ return `- ${agent.name}: ${agent.description || "Workflow agent"}${workflowInfo}`;
81
+ }
82
+ return `- ${agent.name}: ${agent.description || "Custom agent"}`;
83
+ });
70
84
  const lines = [...builtInLines, ...customLines];
71
85
  const guidance = buildAgentSelectionGuide({ hasCustomAgents: customLines.length > 0 });
72
86
  return lines.join(`
@@ -163,6 +177,14 @@ function getSubAgentSpec(id) {
163
177
  return builtInSubAgents.find((agent) => agent.id === id);
164
178
  }
165
179
  function ensureSubAgentRegistered(agentComponent, subagentType, basePrompt, subAgent, deniedTools) {
180
+ const registry = agentComponent.getRegistry?.();
181
+ if (registry) {
182
+ const agentDef = registry.get(subagentType);
183
+ if (agentDef?.type === "workflow") {
184
+ logger.debug(`[delegate] Skipping registration for workflow agent: ${subagentType}`);
185
+ return null;
186
+ }
187
+ }
166
188
  let agentInstance = agentComponent.getAgent(subagentType);
167
189
  if (!agentInstance) {
168
190
  const agentConfig = {
@@ -444,6 +466,8 @@ ${prompt}
444
466
  deniedTools
445
467
  } : undefined;
446
468
  ensureSubAgentRegistered(agentComponent, subagentType, basePrompt, subAgentForRegister, deniedTools);
469
+ const isWorkflowAgent = registry?.get(subagentType)?.type === "workflow";
470
+ const delegateQuery = isWorkflowAgent ? prompt : fullPrompt;
447
471
  return new Promise((resolve, reject) => {
448
472
  const timer = setTimeout(() => {
449
473
  reject(new Error(`Task execution timeout after ${timeoutMs}ms`));
@@ -452,7 +476,7 @@ ${prompt}
452
476
  clearTimeout(timer);
453
477
  reject(new Error("Task execution stopped"));
454
478
  });
455
- this.env.handle_query?.(fullPrompt, {
479
+ this.env.handle_query?.(delegateQuery, {
456
480
  sessionId,
457
481
  deniedTools: deniedTools.length > 0 ? deniedTools : undefined,
458
482
  agentType: subagentType
@@ -509,6 +533,9 @@ ${prompt}
509
533
  logger.info(`[BackgroundTaskManager] Disposed`);
510
534
  }
511
535
  }
536
+ __legacyDecorateClassTS([
537
+ TracedAs("delegate.executeWithAbort", { recordParams: true, recordResult: true, log: true })
538
+ ], BackgroundTaskManager.prototype, "executeWithAbort", null);
512
539
  function getAgentRegistry(taskComponent) {
513
540
  const agentComponent = taskComponent.env?.getComponent?.("agent");
514
541
  return agentComponent?.getRegistry?.();
@@ -675,11 +702,13 @@ ${prompt}
675
702
  deniedTools
676
703
  } : undefined;
677
704
  ensureSubAgentRegistered(agentComponent, subagentType, basePrompt, subAgentForRegister, deniedTools);
705
+ const isWorkflowAgent = registry?.get(subagentType)?.type === "workflow";
706
+ const delegateQuery = isWorkflowAgent ? prompt : fullPrompt;
678
707
  const timeoutMs = timeout || DEFAULT_TIMEOUT;
679
708
  let result;
680
709
  try {
681
710
  result = await Promise.race([
682
- taskComponent.env?.handle_query?.(fullPrompt, {
711
+ taskComponent.env?.handle_query?.(delegateQuery, {
683
712
  sessionId: subSession.id,
684
713
  deniedTools: deniedTools.length > 0 ? deniedTools : undefined,
685
714
  agentType: subagentType
@@ -8,6 +8,10 @@ import {
8
8
  AskUserError,
9
9
  init_workflow_hil
10
10
  } from "./roy-agent-core-e25xkv53.js";
11
+ import {
12
+ init_decorator,
13
+ wrapFunction
14
+ } from "./roy-agent-core-q5qj0fes.js";
11
15
  import {
12
16
  globalHookManager,
13
17
  init_global_hook_manager
@@ -57,7 +61,7 @@ function registerWorkflowJsonOutputPlugin(llmComponent) {
57
61
  description: "Extract structured JSON after ReAct via a dedicated LLM invoke",
58
62
  execute: async (wrapper) => {
59
63
  const hookCtx = wrapper.data;
60
- await runWorkflowJsonOutputExtraction(hookCtx, llmComponent);
64
+ await tracedRunWorkflowJsonOutputExtraction(hookCtx, llmComponent);
61
65
  }
62
66
  });
63
67
  logger.info("Workflow JSON output plugin registered on agent:after.react");
@@ -175,16 +179,19 @@ function toLLMMessage(msg) {
175
179
  }
176
180
  return { role: msg.role, content: "" };
177
181
  }
178
- var logger, WORKFLOW_JSON_OUTPUT_SOURCE_ID = "workflow", WORKFLOW_JSON_OUTPUT_PLUGIN_NAME = "json-output", WORKFLOW_JSON_OUTPUT_PLUGIN_KEY, HOOK_POINT = "agent:after.react", HOOK_NAME, registered = false;
182
+ var logger, WORKFLOW_JSON_OUTPUT_SOURCE_ID = "workflow", WORKFLOW_JSON_OUTPUT_PLUGIN_NAME = "json-output", WORKFLOW_JSON_OUTPUT_PLUGIN_KEY, HOOK_POINT = "agent:after.react", HOOK_NAME, registered = false, tracedRunWorkflowJsonOutputExtraction, tracedExtractStructuredJsonViaLlm;
179
183
  var init_workflow_json_output_plugin = __esm(() => {
180
184
  init_global_hook_manager();
181
185
  init_workflow_hil();
182
186
  init_submit_json_output_tool();
183
187
  init_output_schema_hint();
184
188
  init_logger();
189
+ init_decorator();
185
190
  logger = createLogger("WorkflowJsonOutputPlugin");
186
191
  WORKFLOW_JSON_OUTPUT_PLUGIN_KEY = `${WORKFLOW_JSON_OUTPUT_SOURCE_ID}:${WORKFLOW_JSON_OUTPUT_PLUGIN_NAME}`;
187
192
  HOOK_NAME = `${WORKFLOW_JSON_OUTPUT_PLUGIN_NAME}:${HOOK_POINT}`;
193
+ tracedRunWorkflowJsonOutputExtraction = wrapFunction(runWorkflowJsonOutputExtraction, "workflow.json_output.extraction", { recordParams: true, recordResult: true, log: true });
194
+ tracedExtractStructuredJsonViaLlm = wrapFunction(extractStructuredJsonViaLlm, "workflow.json_output.extract_via_llm", { recordParams: false, recordResult: true, log: true });
188
195
  });
189
196
 
190
- export { WORKFLOW_JSON_OUTPUT_SOURCE_ID, WORKFLOW_JSON_OUTPUT_PLUGIN_NAME, WORKFLOW_JSON_OUTPUT_PLUGIN_KEY, isWorkflowJsonOutputEnabled, registerWorkflowJsonOutputPlugin, unregisterWorkflowJsonOutputPlugin, runWorkflowJsonOutputExtraction, extractStructuredJsonViaLlm, init_workflow_json_output_plugin };
197
+ export { WORKFLOW_JSON_OUTPUT_SOURCE_ID, WORKFLOW_JSON_OUTPUT_PLUGIN_NAME, WORKFLOW_JSON_OUTPUT_PLUGIN_KEY, isWorkflowJsonOutputEnabled, registerWorkflowJsonOutputPlugin, unregisterWorkflowJsonOutputPlugin, runWorkflowJsonOutputExtraction, extractStructuredJsonViaLlm, tracedRunWorkflowJsonOutputExtraction, tracedExtractStructuredJsonViaLlm, init_workflow_json_output_plugin };
@@ -5,7 +5,7 @@ import {
5
5
  BackgroundTaskManager,
6
6
  createDelegateTool,
7
7
  createStopTool
8
- } from "./roy-agent-core-8y804aat.js";
8
+ } from "./roy-agent-core-jqq7c2rk.js";
9
9
  import {
10
10
  SQLiteTaskStore,
11
11
  getDefaultTaskDbPath
@@ -1,10 +1,11 @@
1
1
  import {
2
2
  AgentComponentAdapter,
3
3
  init_agent_component_adapter
4
- } from "./roy-agent-core-44g4dhzg.js";
5
- import"./roy-agent-core-dbxm76wf.js";
4
+ } from "./roy-agent-core-2rtka82a.js";
5
+ import"./roy-agent-core-kzbj10gk.js";
6
6
  import"./roy-agent-core-nhfy3p8q.js";
7
7
  import"./roy-agent-core-e25xkv53.js";
8
+ import"./roy-agent-core-q5qj0fes.js";
8
9
  import"./roy-agent-core-rgj6hq15.js";
9
10
  import"./roy-agent-core-rm3hay00.js";
10
11
  import"./roy-agent-core-10n2jh7p.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.5.46",
3
+ "version": "1.5.47",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",
@@ -83,4 +83,4 @@
83
83
  "bugs": {
84
84
  "url": "https://github.com/ai-setting/roy-agent/issues"
85
85
  }
86
- }
86
+ }