@ai-setting/roy-agent-core 1.5.107 → 1.5.109

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 (31) hide show
  1. package/dist/env/agent/index.js +3 -4
  2. package/dist/env/event-source/index.js +3 -4
  3. package/dist/env/index.js +14 -15
  4. package/dist/env/prompt/index.js +2 -2
  5. package/dist/env/task/delegate/index.js +3 -3
  6. package/dist/env/task/index.js +4 -4
  7. package/dist/env/task/plugins/index.js +3 -5
  8. package/dist/env/tool/index.js +1 -2
  9. package/dist/env/workflow/engine/index.js +2 -2
  10. package/dist/env/workflow/index.js +5 -5
  11. package/dist/env/workflow/nodes/index.js +1 -1
  12. package/dist/env/workflow/service/index.js +1 -1
  13. package/dist/env/workflow/tools/index.js +2 -2
  14. package/dist/index.js +17 -19
  15. package/dist/shared/@ai-setting/{roy-agent-core-kbasdf13.js → roy-agent-core-415rxkzy.js} +20 -6
  16. package/dist/shared/@ai-setting/{roy-agent-core-n6dgm687.js → roy-agent-core-84aqc5c0.js} +1 -1
  17. package/dist/shared/@ai-setting/{roy-agent-core-8y4ccnfh.js → roy-agent-core-84ex7khq.js} +3 -3
  18. package/dist/shared/@ai-setting/{roy-agent-core-44tqfctj.js → roy-agent-core-8cwb4fmp.js} +23 -96
  19. package/dist/shared/@ai-setting/{roy-agent-core-g2mth323.js → roy-agent-core-9gde0s9d.js} +1 -1
  20. package/dist/shared/@ai-setting/{roy-agent-core-nbsw8k13.js → roy-agent-core-a8pm6hya.js} +0 -27
  21. package/dist/shared/@ai-setting/{roy-agent-core-k31c3kvz.js → roy-agent-core-as3phr7n.js} +1 -1
  22. package/dist/shared/@ai-setting/{roy-agent-core-e7t3rj0e.js → roy-agent-core-b75jtybq.js} +39 -0
  23. package/dist/shared/@ai-setting/{roy-agent-core-5zbfs2v9.js → roy-agent-core-btpjdb97.js} +63 -12
  24. package/dist/shared/@ai-setting/{roy-agent-core-yd9ydk9a.js → roy-agent-core-ftdapf99.js} +3 -4
  25. package/dist/shared/@ai-setting/{roy-agent-core-0azsw550.js → roy-agent-core-ks3nm336.js} +1 -1
  26. package/dist/shared/@ai-setting/{roy-agent-core-7aqhafd9.js → roy-agent-core-mnc0hy7j.js} +2 -2
  27. package/dist/shared/@ai-setting/{roy-agent-core-rj9qpdm5.js → roy-agent-core-skfr9wjk.js} +1 -1
  28. package/dist/shared/@ai-setting/{roy-agent-core-ztjpg1p3.js → roy-agent-core-txk4gcwm.js} +64 -24
  29. package/dist/shared/@ai-setting/{roy-agent-core-nz5wn9yc.js → roy-agent-core-y8fvmh8q.js} +2 -2
  30. package/package.json +1 -1
  31. package/dist/shared/@ai-setting/roy-agent-core-xjdcx45t.js +0 -117
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TAG_MAX_COUNT,
3
3
  TAG_MIN_COUNT
4
- } from "./roy-agent-core-e7t3rj0e.js";
4
+ } from "./roy-agent-core-b75jtybq.js";
5
5
  import {
6
6
  validateWorkflowDefinition
7
7
  } from "./roy-agent-core-8wd3qwx5.js";
@@ -38,7 +38,7 @@ var askUserTool = {
38
38
  parameters: AskUserInputSchema,
39
39
  async execute(args, context) {
40
40
  const runId = context.metadata?.runId || "unknown";
41
- const sessionId = context.metadata?.sessionId || `workflow_${runId}`;
41
+ const sessionId = context.metadata?.sessionId || runId;
42
42
  const nodeId = context.metadata?.nodeId || "unknown";
43
43
  let fullQuery = args.query;
44
44
  if (args.options && args.options.length > 0) {
@@ -619,12 +619,13 @@ var RunWorkflowInputSchema = z8.object({
619
619
  workflow_name: z8.string().describe("Name of the workflow to run"),
620
620
  input: z8.record(z8.any()).optional().describe("Input to pass to the workflow"),
621
621
  sync: z8.boolean().default(true).describe("Wait for completion (default: true)"),
622
- timeout: z8.number().positive().optional().describe("Timeout in milliseconds (default: 1800000 = 30 min)")
622
+ timeout: z8.number().positive().optional().describe("Timeout in milliseconds (default: 1800000 = 30 min)"),
623
+ 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.")
623
624
  });
624
625
  function createRunWorkflowTool(workflowService) {
625
626
  return {
626
627
  name: "workflow_run",
627
- description: "Run a workflow by name with optional input. Returns run_id, status, output, error, and duration_ms. Default timeout: 30 minutes.",
628
+ 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.",
628
629
  parameters: RunWorkflowInputSchema,
629
630
  sandbox: {
630
631
  enabled: false
@@ -640,8 +641,13 @@ function createRunWorkflowTool(workflowService) {
640
641
  },
641
642
  execute: async (args, ctx) => {
642
643
  const startTime = Date.now();
643
- const { workflow_name, input, sync = true, timeout = 1800000 } = args;
644
- logger7.info(`Running workflow: ${workflow_name}`, { input, sync, timeout });
644
+ const { workflow_name, input, session, sync = true, timeout = 1800000 } = args;
645
+ logger7.info(`Running workflow: ${workflow_name}`, {
646
+ input,
647
+ sync,
648
+ timeout,
649
+ ...session ? { resumeSession: session } : {}
650
+ });
645
651
  const ctxSessionId = typeof ctx?.session_id === "string" && isValidSessionId(ctx.session_id) ? ctx.session_id : undefined;
646
652
  const envSessionId = typeof process.env.ROY_PARENT_SESSION_ID === "string" && isValidSessionId(process.env.ROY_PARENT_SESSION_ID) ? process.env.ROY_PARENT_SESSION_ID : undefined;
647
653
  if (process.env.ROY_PARENT_SESSION_ID && !envSessionId) {
@@ -650,14 +656,29 @@ function createRunWorkflowTool(workflowService) {
650
656
  const parentSessionId = ctxSessionId ?? envSessionId;
651
657
  let timeoutHandle;
652
658
  let durationMs;
659
+ let capturedRunId = session ? session : undefined;
660
+ const onSessionCreated = (sid) => {
661
+ capturedRunId = sid;
662
+ };
653
663
  try {
654
664
  let result;
665
+ const baseOptions = {
666
+ sync,
667
+ ...parentSessionId ? { parentSessionId } : {},
668
+ onSessionCreated
669
+ };
670
+ const executeCall = async () => {
671
+ if (session) {
672
+ return workflowService.resumeSession(session, {
673
+ ...baseOptions,
674
+ ...input ? { input } : {}
675
+ });
676
+ }
677
+ return workflowService.runWorkflow(workflow_name, input, baseOptions);
678
+ };
655
679
  if (timeout) {
656
680
  result = await Promise.race([
657
- workflowService.runWorkflow(workflow_name, input, {
658
- sync,
659
- ...parentSessionId ? { parentSessionId } : {}
660
- }),
681
+ executeCall(),
661
682
  new Promise((_, reject) => {
662
683
  timeoutHandle = setTimeout(() => {
663
684
  reject(new Error("Workflow execution timed out"));
@@ -665,39 +686,39 @@ function createRunWorkflowTool(workflowService) {
665
686
  })
666
687
  ]);
667
688
  } else {
668
- result = await workflowService.runWorkflow(workflow_name, input, {
669
- sync,
670
- ...parentSessionId ? { parentSessionId } : {}
671
- });
689
+ result = await executeCall();
672
690
  }
673
691
  if (timeoutHandle) {
674
692
  clearTimeout(timeoutHandle);
675
693
  }
676
694
  durationMs = Date.now() - startTime;
695
+ const finalRunId = capturedRunId ?? result.runId ?? "";
677
696
  if (sync) {
678
697
  return {
679
698
  success: result.status === "completed",
680
699
  output: {
681
- run_id: result.runId,
700
+ run_id: finalRunId,
682
701
  status: result.status,
683
702
  output: result.output,
684
703
  error: result.error,
685
704
  duration_ms: result.durationMs || durationMs
686
705
  },
687
706
  metadata: {
688
- execution_time_ms: durationMs
707
+ execution_time_ms: durationMs,
708
+ run_id: finalRunId
689
709
  }
690
710
  };
691
711
  } else {
692
712
  return {
693
713
  success: true,
694
714
  output: {
695
- run_id: result.runId,
715
+ run_id: finalRunId,
696
716
  status: result.status,
697
717
  duration_ms: durationMs
698
718
  },
699
719
  metadata: {
700
- execution_time_ms: durationMs
720
+ execution_time_ms: durationMs,
721
+ run_id: finalRunId
701
722
  }
702
723
  };
703
724
  }
@@ -707,23 +728,36 @@ function createRunWorkflowTool(workflowService) {
707
728
  }
708
729
  durationMs = Date.now() - startTime;
709
730
  const errorMessage = error instanceof Error ? error.message : String(error);
731
+ const errorRunId = capturedRunId ?? "";
710
732
  if (errorMessage.includes("Workflow not found")) {
711
733
  return {
712
734
  success: false,
713
- output: "",
735
+ output: {
736
+ run_id: errorRunId,
737
+ status: "failed",
738
+ error: `Workflow not found: ${workflow_name}`,
739
+ duration_ms: durationMs
740
+ },
714
741
  error: `Workflow not found: ${workflow_name}`,
715
742
  metadata: {
716
- execution_time_ms: durationMs
743
+ execution_time_ms: durationMs,
744
+ run_id: errorRunId
717
745
  }
718
746
  };
719
747
  }
720
748
  if (errorMessage.includes("abort") || errorMessage.includes("timed out")) {
721
749
  return {
722
750
  success: false,
723
- output: "",
751
+ output: {
752
+ run_id: errorRunId,
753
+ status: "timeout",
754
+ error: `Workflow execution timed out or was aborted: ${workflow_name}`,
755
+ duration_ms: durationMs
756
+ },
724
757
  error: `Workflow execution timed out or was aborted: ${workflow_name}`,
725
758
  metadata: {
726
- execution_time_ms: durationMs
759
+ execution_time_ms: durationMs,
760
+ run_id: errorRunId
727
761
  }
728
762
  };
729
763
  }
@@ -732,10 +766,16 @@ function createRunWorkflowTool(workflowService) {
732
766
  }
733
767
  return {
734
768
  success: false,
735
- output: "",
769
+ output: {
770
+ run_id: errorRunId,
771
+ status: "failed",
772
+ error: `Failed to run workflow ${workflow_name}: ${errorMessage}`,
773
+ duration_ms: durationMs
774
+ },
736
775
  error: `Failed to run workflow ${workflow_name}: ${errorMessage}`,
737
776
  metadata: {
738
- execution_time_ms: durationMs
777
+ execution_time_ms: durationMs,
778
+ run_id: errorRunId
739
779
  }
740
780
  };
741
781
  }
@@ -3,14 +3,14 @@ import {
3
3
  } from "./roy-agent-core-j7jeqxhd.js";
4
4
  import {
5
5
  truncateOutputInline
6
- } from "./roy-agent-core-nbsw8k13.js";
6
+ } from "./roy-agent-core-a8pm6hya.js";
7
7
  import {
8
8
  AskUserError,
9
9
  init_workflow_hil
10
10
  } from "./roy-agent-core-e25xkv53.js";
11
11
  import {
12
12
  AgentRegistry
13
- } from "./roy-agent-core-k31c3kvz.js";
13
+ } from "./roy-agent-core-as3phr7n.js";
14
14
  import {
15
15
  ContextError
16
16
  } from "./roy-agent-core-ctdhjv68.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.5.107",
3
+ "version": "1.5.109",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",
@@ -1,117 +0,0 @@
1
- import {
2
- init_decorator,
3
- wrapFunction
4
- } from "./roy-agent-core-cg146hmg.js";
5
- import {
6
- createLogger,
7
- init_logger
8
- } from "./roy-agent-core-vyygk314.js";
9
-
10
- // src/env/task/plugins/auto-task-plugin.ts
11
- init_logger();
12
- init_decorator();
13
- var logger = createLogger("AutoTaskPlugin");
14
- var ITERATION_TASK_TRIGGER_BEGIN = `
15
- [[ITERATION_TASK_TRIGGER_BEGIN]]
16
- `;
17
- var ITERATION_TASK_TRIGGER_END = `[[ITERATION_TASK_TRIGGER_END]]
18
- `;
19
- function wrapAutoTaskMetadata(content) {
20
- return `${ITERATION_TASK_TRIGGER_BEGIN}${content}${ITERATION_TASK_TRIGGER_END}`;
21
- }
22
- function createAutoTaskPlugin(config) {
23
- const threshold = config?.threshold ?? 20;
24
- const agentName = config?.agentName ?? "default";
25
- const agentComponent = config?.agentComponent ?? null;
26
- const subagentType = config?.subagentType ?? "task-agent";
27
- let lastProcessedTraceId = "";
28
- async function executeImpl(ctx) {
29
- try {
30
- logger.info(`[AutoTaskPlugin:ENTER] agentName=${ctx.agent.name} iteration=${ctx.iteration} threshold=${threshold}`);
31
- logger.debug(`[AutoTaskPlugin] agentName=${ctx.agent.name} iteration=${ctx.iteration} threshold=${threshold}) expected=${agentName})`);
32
- if (ctx.agent.name !== agentName)
33
- return { continue: true };
34
- logger.debug(`[AutoTaskPlugin] iteration=${ctx.iteration} (threshold=${threshold})`);
35
- if (ctx.iteration !== threshold)
36
- return { continue: true };
37
- const traceId = ctx.context?.traceId ?? ctx.context?.sessionId ?? "unknown";
38
- const sid = ctx.context?.sessionId ?? "unknown";
39
- if (traceId === lastProcessedTraceId) {
40
- logger.debug(`[AutoTaskPlugin] skip - traceId=${traceId.slice(0, 20)}... already processed`);
41
- return { continue: true };
42
- }
43
- lastProcessedTraceId = traceId;
44
- logger.debug(`[AutoTaskPlugin] new query detected (traceId=${traceId.slice(0, 20)}...)`);
45
- if (!agentComponent || typeof agentComponent.run !== "function") {
46
- logger.warn(`[AutoTaskPlugin] agentComponent not provided or invalid (session=${sid.slice(0, 12)}...)`);
47
- return { continue: true };
48
- }
49
- let userQuery = "";
50
- for (let i = ctx.messages.length - 1;i >= 0; i--) {
51
- const m = ctx.messages[i];
52
- if (m.role === "user") {
53
- userQuery = typeof m.content === "string" ? m.content : JSON.stringify(m.content);
54
- break;
55
- }
56
- }
57
- if (!userQuery) {
58
- userQuery = "分析项目结构并执行相关任务";
59
- }
60
- logger.info(`[AutoTaskPlugin] Calling agentComponent.run("${subagentType}") at iteration ${ctx.iteration} (session=${sid.slice(0, 12)}..., persistSession=false)`);
61
- const shortDesc = typeof userQuery === "string" ? userQuery.slice(0, 50) : "分析需求";
62
- const placeholderContent = `⏳ **${subagentType} 正在执行**: ${shortDesc}(等待结果...)`;
63
- const placeholderBlock = wrapAutoTaskMetadata(placeholderContent);
64
- if (ctx.toolResult?.result?.output !== undefined) {
65
- const originalOutput = ctx.toolResult.result.output;
66
- ctx.toolResult.result.output = placeholderBlock + `
67
-
68
- ` + originalOutput;
69
- logger.info(`[AutoTaskPlugin] placeholder prepended (session=${sid.slice(0, 12)}...)`);
70
- }
71
- let taskAgentFinalText = "";
72
- try {
73
- const taskAgentResult = await agentComponent.run(subagentType, userQuery, {
74
- sessionId: sid,
75
- traceId,
76
- persistSession: false
77
- });
78
- taskAgentFinalText = taskAgentResult?.finalText || "";
79
- logger.info(`[AutoTaskPlugin] task-agent completed (session=${sid.slice(0, 12)}..., finalTextLength=${taskAgentFinalText.length})`);
80
- } catch (err) {
81
- logger.error(`[AutoTaskPlugin] task-agent failed: ${err instanceof Error ? err.message : String(err)}`);
82
- taskAgentFinalText = `❌ **${subagentType} 执行失败**: ${err instanceof Error ? err.message : String(err)}`;
83
- }
84
- if (taskAgentFinalText && ctx.toolResult?.result?.output !== undefined) {
85
- const finalBlock = wrapAutoTaskMetadata(taskAgentFinalText);
86
- const current = ctx.toolResult.result.output;
87
- const updated = placeholderBlock && current.includes(placeholderBlock) ? current.replace(placeholderBlock, finalBlock) : finalBlock + `
88
-
89
- ` + current;
90
- ctx.toolResult.result.output = updated;
91
- logger.info(`[AutoTaskPlugin] task-agent finalText injected (session=${sid.slice(0, 12)}...)`);
92
- } else if (!ctx.toolResult?.result?.output) {
93
- logger.warn(`[AutoTaskPlugin] toolResult unavailable for injection`);
94
- }
95
- return { continue: true };
96
- } catch (err) {
97
- logger.error(`[AutoTaskPlugin] hook failed: ${err instanceof Error ? err.message : String(err)}`);
98
- return { continue: true };
99
- }
100
- }
101
- const execute = wrapFunction(executeImpl, "plugin.auto-task.launch-agent", {
102
- recordParams: false,
103
- recordResult: true,
104
- log: true
105
- });
106
- return {
107
- name: "AutoTaskPlugin",
108
- version: "4.6.0",
109
- description: "ReAct iteration 达到阈值时 await task-agent 执行并提取 delegate_task 结果注入 tool result",
110
- hooks: [
111
- { point: "agent:after.tool", priority: 50 }
112
- ],
113
- execute
114
- };
115
- }
116
-
117
- export { ITERATION_TASK_TRIGGER_BEGIN, ITERATION_TASK_TRIGGER_END, createAutoTaskPlugin };