@ai-setting/roy-agent-core 1.6.5 → 1.6.7

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.
Files changed (30) hide show
  1. package/dist/env/agent/index.js +3 -3
  2. package/dist/env/event-source/index.js +1 -1
  3. package/dist/env/index.js +12 -12
  4. package/dist/env/llm/index.js +2 -2
  5. package/dist/env/plugin/index.js +1 -1
  6. package/dist/env/task/index.js +2 -2
  7. package/dist/env/task/tools/index.js +1 -1
  8. package/dist/env/tool/built-in/index.js +1 -1
  9. package/dist/env/tool/index.js +2 -2
  10. package/dist/env/workflow/engine/index.js +3 -3
  11. package/dist/env/workflow/index.js +5 -5
  12. package/dist/env/workflow/nodes/index.js +6 -2
  13. package/dist/env/workflow/tools/index.js +1 -1
  14. package/dist/index.js +14 -14
  15. package/dist/shared/@ai-setting/{roy-agent-core-ba6243hr.js → roy-agent-core-0tfv18rf.js} +175 -1
  16. package/dist/shared/@ai-setting/{roy-agent-core-z7dxedn6.js → roy-agent-core-2r1rc0fe.js} +12 -2
  17. package/dist/shared/@ai-setting/{roy-agent-core-xxfkvqqh.js → roy-agent-core-34xt19yg.js} +8 -7
  18. package/dist/shared/@ai-setting/{roy-agent-core-fb3wyr3d.js → roy-agent-core-39rvx3fw.js} +41 -3
  19. package/dist/shared/@ai-setting/{roy-agent-core-y1m7c2v7.js → roy-agent-core-8jmkghjc.js} +1 -1
  20. package/dist/shared/@ai-setting/{roy-agent-core-65qs21kf.js → roy-agent-core-dcd1s7ct.js} +4 -1
  21. package/dist/shared/@ai-setting/{roy-agent-core-bcd3y74k.js → roy-agent-core-gdkq55yg.js} +3 -2
  22. package/dist/shared/@ai-setting/{roy-agent-core-r3209bcd.js → roy-agent-core-gw43m8yd.js} +2 -2
  23. package/dist/shared/@ai-setting/{roy-agent-core-hp1n198d.js → roy-agent-core-jzza6c2r.js} +166 -45
  24. package/dist/shared/@ai-setting/{roy-agent-core-5rjccr3c.js → roy-agent-core-ka4b12eg.js} +88 -47
  25. package/dist/shared/@ai-setting/{roy-agent-core-p8zgxdgy.js → roy-agent-core-kenhsgnf.js} +3 -3
  26. package/dist/shared/@ai-setting/{roy-agent-core-155408xq.js → roy-agent-core-r08qk37k.js} +1 -1
  27. package/dist/shared/@ai-setting/{roy-agent-core-ktbkp661.js → roy-agent-core-sxqy40cs.js} +3 -3
  28. package/dist/shared/@ai-setting/{roy-agent-core-vf72n6qn.js → roy-agent-core-w7mhnc4c.js} +22 -4
  29. package/package.json +1 -1
  30. /package/dist/shared/@ai-setting/{roy-agent-core-6kygfd9x.js → roy-agent-core-02n40zbs.js} +0 -0
@@ -613,8 +613,37 @@ function createWorkflowSearchTool(workflowService) {
613
613
 
614
614
  // src/env/workflow/tools/run-workflow.ts
615
615
  init_logger();
616
+ init_decorator();
616
617
  import { z as z8 } from "zod";
617
618
  var logger7 = createLogger("run-workflow-tool");
619
+ function synthFallbackRunId(now = Date.now()) {
620
+ return `workflow_${now}_fallback_${Math.random().toString(36).slice(2, 8)}`;
621
+ }
622
+ function attemptStopOnTimeout(workflowService, runId, reason) {
623
+ if (typeof workflowService.stopRun !== "function")
624
+ return;
625
+ workflowService.stopRun(runId, reason).catch((stopErr) => {
626
+ logger7.warn(`Failed to stop workflow ${runId} after timeout: ${stopErr instanceof Error ? stopErr.message : String(stopErr)}`);
627
+ });
628
+ }
629
+ function buildErrorReturn(args) {
630
+ const { errorRunId, status, errorMessage, durationMs } = args;
631
+ const errorWithRunId = `${errorMessage} (runId: ${errorRunId})`;
632
+ return {
633
+ success: false,
634
+ output: {
635
+ run_id: errorRunId,
636
+ status,
637
+ error: errorWithRunId,
638
+ duration_ms: durationMs
639
+ },
640
+ error: errorWithRunId,
641
+ metadata: {
642
+ execution_time_ms: durationMs,
643
+ run_id: errorRunId
644
+ }
645
+ };
646
+ }
618
647
  var RunWorkflowInputSchema = z8.object({
619
648
  workflow_name: z8.string().describe("Name of the workflow to run"),
620
649
  input: z8.record(z8.any()).optional().describe("Input to pass to the workflow"),
@@ -622,8 +651,24 @@ var RunWorkflowInputSchema = z8.object({
622
651
  node_config: z8.record(z8.string(), z8.record(z8.string(), z8.any())).optional().describe("Per-node runtime config overrides keyed by node id (Task #1974). " + "Shallow-merged into each node's effective config; input wins over nodeDef.config."),
623
652
  session: z8.string().regex(/^workflow_/, { message: "session must start with 'workflow_'" }).optional().describe("Existing session ID (workflow_xxx) to resume from. Mutually exclusive with fresh `input` runs.")
624
653
  }).strict();
654
+
655
+ class RunWorkflowToolRunner {
656
+ executeImpl;
657
+ constructor(executeImpl) {
658
+ this.executeImpl = executeImpl;
659
+ }
660
+ async execute(args, ctx) {
661
+ return this.executeImpl(args, ctx);
662
+ }
663
+ }
664
+ __legacyDecorateClassTS([
665
+ TracedAs("workflow.run-workflow-tool.execute", {
666
+ recordParams: true,
667
+ recordResult: true
668
+ })
669
+ ], RunWorkflowToolRunner.prototype, "execute", null);
625
670
  function createRunWorkflowTool(workflowService) {
626
- return {
671
+ const tool = {
627
672
  name: "workflow_run",
628
673
  description: "Run a workflow by name with optional input, OR resume an existing workflow run via the `session` field (the runId itself acts as session ID, both have `workflow_` prefix natively — pass the workflow run's runId directly). Returns run_id (== session_id, ALWAYS populated — even on timeout/abort/error paths), status, output, error, and duration_ms. Default timeout: 30 minutes.",
629
674
  parameters: RunWorkflowInputSchema,
@@ -655,14 +700,23 @@ function createRunWorkflowTool(workflowService) {
655
700
  const parentSessionId = ctxSessionId ?? envSessionId;
656
701
  let timeoutHandle;
657
702
  let durationMs;
658
- let capturedRunId = session ? session : undefined;
703
+ const reservedRunId = synthFallbackRunId();
704
+ let timedOut = false;
705
+ let capturedByCallback = false;
706
+ let capturedRunId = session ? session : reservedRunId;
659
707
  const onSessionCreated = (sid) => {
660
708
  capturedRunId = sid;
709
+ capturedByCallback = true;
710
+ if (timedOut) {
711
+ attemptStopOnTimeout(workflowService, sid, "timed out");
712
+ }
661
713
  };
662
714
  try {
663
715
  let result;
716
+ const fallbackRunId = reservedRunId;
664
717
  const baseOptions = {
665
718
  ...parentSessionId ? { parentSessionId } : {},
719
+ ...session ? {} : { runId: reservedRunId },
666
720
  onSessionCreated,
667
721
  ...node_config ? { nodeConfig: node_config } : {}
668
722
  };
@@ -680,6 +734,8 @@ function createRunWorkflowTool(workflowService) {
680
734
  executeCall(),
681
735
  new Promise((_, reject) => {
682
736
  timeoutHandle = setTimeout(() => {
737
+ timedOut = true;
738
+ attemptStopOnTimeout(workflowService, capturedRunId ?? reservedRunId, "timed out");
683
739
  reject(new Error("Workflow execution timed out"));
684
740
  }, timeout);
685
741
  })
@@ -691,7 +747,7 @@ function createRunWorkflowTool(workflowService) {
691
747
  clearTimeout(timeoutHandle);
692
748
  }
693
749
  durationMs = Date.now() - startTime;
694
- const finalRunId = capturedRunId ?? result.runId ?? "";
750
+ const finalRunId = capturedByCallback ? capturedRunId : result.runId ?? "";
695
751
  return {
696
752
  success: result.status === "completed" || result.status === "paused",
697
753
  output: {
@@ -715,59 +771,44 @@ function createRunWorkflowTool(workflowService) {
715
771
  }
716
772
  durationMs = Date.now() - startTime;
717
773
  const errorMessage = error instanceof Error ? error.message : String(error);
718
- const errorRunId = capturedRunId ?? "";
774
+ const errorRunId = capturedRunId ?? reservedRunId;
719
775
  if (errorMessage.includes("Workflow not found")) {
720
- return {
721
- success: false,
722
- output: {
723
- run_id: errorRunId,
724
- status: "failed",
725
- error: `Workflow not found: ${workflow_name}`,
726
- duration_ms: durationMs
727
- },
728
- error: `Workflow not found: ${workflow_name}`,
729
- metadata: {
730
- execution_time_ms: durationMs,
731
- run_id: errorRunId
732
- }
733
- };
776
+ return buildErrorReturn({
777
+ errorRunId,
778
+ status: "failed",
779
+ errorMessage: `Workflow not found: ${workflow_name}`,
780
+ durationMs
781
+ });
734
782
  }
735
- if (errorMessage.includes("abort") || errorMessage.includes("timed out")) {
736
- return {
737
- success: false,
738
- output: {
739
- run_id: errorRunId,
740
- status: "timeout",
741
- error: `Workflow execution timed out or was aborted: ${workflow_name}`,
742
- duration_ms: durationMs
743
- },
744
- error: `Workflow execution timed out or was aborted: ${workflow_name}`,
745
- metadata: {
746
- execution_time_ms: durationMs,
747
- run_id: errorRunId
748
- }
749
- };
783
+ const isTimeoutLike = errorMessage.includes("abort") || errorMessage.includes("timed out") || errorMessage.includes("execution timeout:");
784
+ if (isTimeoutLike) {
785
+ if (!timedOut) {
786
+ attemptStopOnTimeout(workflowService, errorRunId, "timed out");
787
+ }
788
+ return buildErrorReturn({
789
+ errorRunId,
790
+ status: "timeout",
791
+ errorMessage: `Workflow execution timed out or was aborted: ${workflow_name}`,
792
+ durationMs
793
+ });
750
794
  }
751
795
  if (logger7?.error) {
752
796
  logger7.error(`Failed to run workflow: ${workflow_name}`, { error: errorMessage });
753
797
  }
754
- return {
755
- success: false,
756
- output: {
757
- run_id: errorRunId,
758
- status: "failed",
759
- error: `Failed to run workflow ${workflow_name}: ${errorMessage}`,
760
- duration_ms: durationMs
761
- },
762
- error: `Failed to run workflow ${workflow_name}: ${errorMessage}`,
763
- metadata: {
764
- execution_time_ms: durationMs,
765
- run_id: errorRunId
766
- }
767
- };
798
+ return buildErrorReturn({
799
+ errorRunId,
800
+ status: "failed",
801
+ errorMessage: `Failed to run workflow ${workflow_name}: ${errorMessage}`,
802
+ durationMs
803
+ });
768
804
  }
769
805
  }
770
806
  };
807
+ const runner = new RunWorkflowToolRunner(tool.execute);
808
+ return {
809
+ ...tool,
810
+ execute: runner.execute.bind(runner)
811
+ };
771
812
  }
772
813
  var _runWorkflowTool = null;
773
814
  var _workflowService = null;
@@ -6,7 +6,7 @@ import {
6
6
  WorkflowEngine,
7
7
  exports_engine,
8
8
  init_engine
9
- } from "./roy-agent-core-fb3wyr3d.js";
9
+ } from "./roy-agent-core-39rvx3fw.js";
10
10
  import {
11
11
  askUserTool,
12
12
  createRunWorkflowTool,
@@ -18,7 +18,7 @@ import {
18
18
  createWorkflowSearchTool,
19
19
  createWorkflowTagListTool,
20
20
  createWorkflowValidateTool
21
- } from "./roy-agent-core-5rjccr3c.js";
21
+ } from "./roy-agent-core-ka4b12eg.js";
22
22
  import {
23
23
  WorkflowService
24
24
  } from "./roy-agent-core-b75jtybq.js";
@@ -141,7 +141,7 @@ class WorkflowComponent extends BaseComponent {
141
141
  if (!agentRunner && this._workflowEnv) {
142
142
  const agentComponent = this._workflowEnv.getComponent("agent");
143
143
  if (agentComponent) {
144
- const { AgentComponentAdapter } = await import("./roy-agent-core-y1m7c2v7.js");
144
+ const { AgentComponentAdapter } = await import("./roy-agent-core-8jmkghjc.js");
145
145
  agentRunner = new AgentComponentAdapter(agentComponent, {}, this.sessionComponent);
146
146
  }
147
147
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  invoke
3
- } from "./roy-agent-core-65qs21kf.js";
3
+ } from "./roy-agent-core-dcd1s7ct.js";
4
4
  import {
5
5
  ContextError,
6
6
  ErrorCodes
@@ -98,10 +98,10 @@ function createTaskTool(taskComponent) {
98
98
  description: `
99
99
  Create a new task for tracking work.
100
100
 
101
- ## ⚠️ CALL task_tree(depth=2) BEFORE THIS TOOL
101
+ ## ⚠️ CALL task_tree(depth=1) BEFORE THIS TOOL
102
102
 
103
103
  Before calling \`task_create\`, you **MUST** first call
104
- \`task_tree(depth=2)\` to inspect the existing task hierarchy.
104
+ \`task_tree(depth=1)\` to inspect the existing task hierarchy.
105
105
  This is critical because:
106
106
 
107
107
  1. Avoid duplicating root tasks (root tasks should stay ≤ 10).
@@ -109,7 +109,7 @@ function createTaskTool(taskComponent) {
109
109
  3. Avoid creating stranded/orphan tasks.
110
110
 
111
111
  Workflow:
112
- step 1: task_tree({depth: 2})
112
+ step 1: task_tree({depth: 1})
113
113
  step 2: read the tree, then decide per "Decision Tree" below
114
114
  step 3: task_create({...})
115
115
 
@@ -241,15 +241,30 @@ var init_agent_component_adapter = __esm(() => {
241
241
  });
242
242
  }
243
243
  }
244
+ let timeoutHandle;
244
245
  try {
245
246
  const outputSchema = config.options?.outputSchema;
246
247
  const context = {};
247
248
  context.model = config.options?.model;
248
- if (config.options?.timeout) {
249
- context.abort = new AbortController;
249
+ const configuredTimeout = config.options?.timeout;
250
+ const deadlineController = typeof configuredTimeout === "number" && configuredTimeout > 0 ? new AbortController : undefined;
251
+ if (deadlineController) {
252
+ const timeoutMsFinal = configuredTimeout;
253
+ timeoutHandle = setTimeout(() => {
254
+ if (process.env["DEBUG"]) {
255
+ console.warn(`[AgentComponentAdapter] agent '${config.type || "general"}' timeout ${timeoutMsFinal}ms elapsed, aborting THIS run only.`);
256
+ }
257
+ deadlineController.abort(new Error(`Agent ${config.type || "general"} timed out after ${timeoutMsFinal}ms`));
258
+ }, timeoutMsFinal);
259
+ if (typeof timeoutHandle.unref === "function") {
260
+ timeoutHandle.unref();
261
+ }
250
262
  }
251
- if (signal) {
252
- context.abort = signal;
263
+ const signals = [signal, deadlineController?.signal].filter((value) => value !== undefined);
264
+ if (signals.length === 1) {
265
+ context.abort = signals[0];
266
+ } else if (signals.length > 1) {
267
+ context.abort = AbortSignal.any(signals);
253
268
  }
254
269
  context.sessionId = agentSessionId;
255
270
  if (config.options?.allowedTools) {
@@ -326,6 +341,9 @@ var init_agent_component_adapter = __esm(() => {
326
341
  }
327
342
  };
328
343
  } finally {
344
+ if (timeoutHandle) {
345
+ clearTimeout(timeoutHandle);
346
+ }
329
347
  if (isResume) {
330
348
  this._currentAgentSessionId = undefined;
331
349
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.6.5",
3
+ "version": "1.6.7",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",