@ai-setting/roy-agent-core 1.5.84 → 1.5.85

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 (22) hide show
  1. package/dist/env/agent/index.js +2 -2
  2. package/dist/env/index.js +8 -9
  3. package/dist/env/prompt/index.js +1 -1
  4. package/dist/env/task/delegate/index.js +2 -2
  5. package/dist/env/task/index.js +3 -3
  6. package/dist/env/workflow/engine/index.js +3 -4
  7. package/dist/env/workflow/index.js +4 -5
  8. package/dist/env/workflow/tools/index.js +1 -1
  9. package/dist/index.js +9 -10
  10. package/dist/shared/@ai-setting/{roy-agent-core-f6p7wwpd.js → roy-agent-core-0kt57b72.js} +1 -6
  11. package/dist/shared/@ai-setting/{roy-agent-core-whw7jap0.js → roy-agent-core-1db4vpc6.js} +3 -2
  12. package/dist/shared/@ai-setting/{roy-agent-core-m4qjnhz6.js → roy-agent-core-5kdw0p98.js} +114 -68
  13. package/dist/shared/@ai-setting/{roy-agent-core-mbre4fxg.js → roy-agent-core-7z4xtrmw.js} +16 -0
  14. package/dist/shared/@ai-setting/{roy-agent-core-bt7wezvg.js → roy-agent-core-dp73ghtz.js} +5 -16
  15. package/dist/shared/@ai-setting/{roy-agent-core-qjv8537d.js → roy-agent-core-dv12wpdv.js} +1 -1
  16. package/dist/shared/@ai-setting/{roy-agent-core-6b0r2e7j.js → roy-agent-core-gttz2jpm.js} +15 -52
  17. package/dist/shared/@ai-setting/{roy-agent-core-akepggsr.js → roy-agent-core-mmkyydw7.js} +26 -1
  18. package/dist/shared/@ai-setting/{roy-agent-core-nc0n0bdc.js → roy-agent-core-xckhrs2p.js} +2 -3
  19. package/dist/shared/@ai-setting/{roy-agent-core-015vw11k.js → roy-agent-core-yx0vw1aw.js} +8 -6
  20. package/package.json +1 -1
  21. package/dist/shared/@ai-setting/roy-agent-core-7z8fzxck.js +0 -265
  22. package/dist/shared/@ai-setting/roy-agent-core-qf9gvx02.js +0 -39
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  AgentComponent,
3
3
  AgentComponentConfigSchema
4
- } from "../../shared/@ai-setting/roy-agent-core-015vw11k.js";
4
+ } from "../../shared/@ai-setting/roy-agent-core-yx0vw1aw.js";
5
5
  import"../../shared/@ai-setting/roy-agent-core-r0m0at3x.js";
6
6
  import"../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
7
- import"../../shared/@ai-setting/roy-agent-core-mbre4fxg.js";
7
+ import"../../shared/@ai-setting/roy-agent-core-7z4xtrmw.js";
8
8
  import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
9
9
  import"../../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
10
10
  import {
package/dist/env/index.js CHANGED
@@ -21,11 +21,10 @@ import"../shared/@ai-setting/roy-agent-core-7fdzfsm6.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-bt7wezvg.js";
24
+ } from "../shared/@ai-setting/roy-agent-core-dp73ghtz.js";
25
25
  import"../shared/@ai-setting/roy-agent-core-fjexv5nm.js";
26
- import"../shared/@ai-setting/roy-agent-core-6b0r2e7j.js";
27
- import"../shared/@ai-setting/roy-agent-core-m4qjnhz6.js";
28
- import"../shared/@ai-setting/roy-agent-core-7z8fzxck.js";
26
+ import"../shared/@ai-setting/roy-agent-core-gttz2jpm.js";
27
+ import"../shared/@ai-setting/roy-agent-core-5kdw0p98.js";
29
28
  import"../shared/@ai-setting/roy-agent-core-6atd905e.js";
30
29
  import"../shared/@ai-setting/roy-agent-core-gb9gbkc3.js";
31
30
  import"../shared/@ai-setting/roy-agent-core-ddwa0n6h.js";
@@ -33,23 +32,23 @@ import"../shared/@ai-setting/roy-agent-core-hhrg314p.js";
33
32
  import"../shared/@ai-setting/roy-agent-core-j754zgb4.js";
34
33
  import"../shared/@ai-setting/roy-agent-core-qnrf2aw6.js";
35
34
  import"../shared/@ai-setting/roy-agent-core-r5axf0ad.js";
36
- import"../shared/@ai-setting/roy-agent-core-whw7jap0.js";
35
+ import"../shared/@ai-setting/roy-agent-core-1db4vpc6.js";
37
36
  import"../shared/@ai-setting/roy-agent-core-tq9528d3.js";
38
37
  import"../shared/@ai-setting/roy-agent-core-h0x19xgn.js";
39
38
  import"../shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
40
39
  import {
41
40
  AgentComponent,
42
41
  AgentComponentConfigSchema
43
- } from "../shared/@ai-setting/roy-agent-core-015vw11k.js";
42
+ } from "../shared/@ai-setting/roy-agent-core-yx0vw1aw.js";
44
43
  import"../shared/@ai-setting/roy-agent-core-r0m0at3x.js";
45
44
  import"../shared/@ai-setting/roy-agent-core-e25xkv53.js";
46
45
  import {
47
46
  TaskComponent
48
- } from "../shared/@ai-setting/roy-agent-core-qjv8537d.js";
47
+ } from "../shared/@ai-setting/roy-agent-core-dv12wpdv.js";
49
48
  import"../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
50
- import"../shared/@ai-setting/roy-agent-core-f6p7wwpd.js";
49
+ import"../shared/@ai-setting/roy-agent-core-0kt57b72.js";
51
50
  import"../shared/@ai-setting/roy-agent-core-pcdzfwdv.js";
52
- import"../shared/@ai-setting/roy-agent-core-mbre4fxg.js";
51
+ import"../shared/@ai-setting/roy-agent-core-7z4xtrmw.js";
53
52
  import {
54
53
  XDG_PATHS,
55
54
  getXDGPath,
@@ -3,7 +3,7 @@ import {
3
3
  PromptConfigSchema,
4
4
  PromptPathSchema,
5
5
  PromptRenderer
6
- } from "../../shared/@ai-setting/roy-agent-core-akepggsr.js";
6
+ } from "../../shared/@ai-setting/roy-agent-core-mmkyydw7.js";
7
7
  import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
8
8
  import"../../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
9
9
  import"../../shared/@ai-setting/roy-agent-core-rgckng3p.js";
@@ -3,8 +3,8 @@ import {
3
3
  BackgroundTaskManager,
4
4
  createDelegateTool,
5
5
  createStopTool
6
- } from "../../../shared/@ai-setting/roy-agent-core-f6p7wwpd.js";
7
- import"../../../shared/@ai-setting/roy-agent-core-mbre4fxg.js";
6
+ } from "../../../shared/@ai-setting/roy-agent-core-0kt57b72.js";
7
+ import"../../../shared/@ai-setting/roy-agent-core-7z4xtrmw.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-7tp56w6n.js";
@@ -5,16 +5,16 @@ import {
5
5
  TaskPriorityEnum,
6
6
  TaskStatusEnum,
7
7
  TaskTypeEnum
8
- } from "../../shared/@ai-setting/roy-agent-core-qjv8537d.js";
8
+ } from "../../shared/@ai-setting/roy-agent-core-dv12wpdv.js";
9
9
  import {
10
10
  TaskEntityEventTypes
11
11
  } from "../../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
12
- import"../../shared/@ai-setting/roy-agent-core-f6p7wwpd.js";
12
+ import"../../shared/@ai-setting/roy-agent-core-0kt57b72.js";
13
13
  import {
14
14
  SQLiteTaskStore,
15
15
  getDefaultTaskDbPath
16
16
  } from "../../shared/@ai-setting/roy-agent-core-pcdzfwdv.js";
17
- import"../../shared/@ai-setting/roy-agent-core-mbre4fxg.js";
17
+ import"../../shared/@ai-setting/roy-agent-core-7z4xtrmw.js";
18
18
  import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
19
19
  import"../../shared/@ai-setting/roy-agent-core-7nh5h9fn.js";
20
20
  import"../../shared/@ai-setting/roy-agent-core-t94ktchq.js";
@@ -6,15 +6,14 @@ import {
6
6
  Scheduler,
7
7
  WorkflowEngine,
8
8
  init_engine
9
- } from "../../../shared/@ai-setting/roy-agent-core-6b0r2e7j.js";
10
- import"../../../shared/@ai-setting/roy-agent-core-m4qjnhz6.js";
11
- import"../../../shared/@ai-setting/roy-agent-core-7z8fzxck.js";
9
+ } from "../../../shared/@ai-setting/roy-agent-core-gttz2jpm.js";
10
+ import"../../../shared/@ai-setting/roy-agent-core-5kdw0p98.js";
12
11
  import"../../../shared/@ai-setting/roy-agent-core-6atd905e.js";
13
12
  import"../../../shared/@ai-setting/roy-agent-core-gb9gbkc3.js";
14
13
  import"../../../shared/@ai-setting/roy-agent-core-ddwa0n6h.js";
15
14
  import"../../../shared/@ai-setting/roy-agent-core-j754zgb4.js";
16
15
  import"../../../shared/@ai-setting/roy-agent-core-qnrf2aw6.js";
17
- import"../../../shared/@ai-setting/roy-agent-core-whw7jap0.js";
16
+ import"../../../shared/@ai-setting/roy-agent-core-1db4vpc6.js";
18
17
  import"../../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
19
18
  import"../../../shared/@ai-setting/roy-agent-core-7tp56w6n.js";
20
19
  import"../../../shared/@ai-setting/roy-agent-core-qg4rma4c.js";
@@ -1,10 +1,9 @@
1
1
  import {
2
2
  WorkflowComponent
3
- } from "../../shared/@ai-setting/roy-agent-core-bt7wezvg.js";
3
+ } from "../../shared/@ai-setting/roy-agent-core-dp73ghtz.js";
4
4
  import"../../shared/@ai-setting/roy-agent-core-fjexv5nm.js";
5
- import"../../shared/@ai-setting/roy-agent-core-6b0r2e7j.js";
6
- import"../../shared/@ai-setting/roy-agent-core-m4qjnhz6.js";
7
- import"../../shared/@ai-setting/roy-agent-core-7z8fzxck.js";
5
+ import"../../shared/@ai-setting/roy-agent-core-gttz2jpm.js";
6
+ import"../../shared/@ai-setting/roy-agent-core-5kdw0p98.js";
8
7
  import"../../shared/@ai-setting/roy-agent-core-6atd905e.js";
9
8
  import"../../shared/@ai-setting/roy-agent-core-gb9gbkc3.js";
10
9
  import"../../shared/@ai-setting/roy-agent-core-ddwa0n6h.js";
@@ -62,7 +61,7 @@ import {
62
61
  unresolvedVariable
63
62
  } from "../../shared/@ai-setting/roy-agent-core-qnrf2aw6.js";
64
63
  import"../../shared/@ai-setting/roy-agent-core-r5axf0ad.js";
65
- import"../../shared/@ai-setting/roy-agent-core-whw7jap0.js";
64
+ import"../../shared/@ai-setting/roy-agent-core-1db4vpc6.js";
66
65
  import"../../shared/@ai-setting/roy-agent-core-tq9528d3.js";
67
66
  import {
68
67
  Edge,
@@ -29,7 +29,7 @@ import {
29
29
  createSubmitJsonOutputTool,
30
30
  init_submit_json_output_tool,
31
31
  parseWorkflowJsonOutput
32
- } from "../../../shared/@ai-setting/roy-agent-core-whw7jap0.js";
32
+ } from "../../../shared/@ai-setting/roy-agent-core-1db4vpc6.js";
33
33
  import"../../../shared/@ai-setting/roy-agent-core-tq9528d3.js";
34
34
  import"../../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
35
35
  import"../../../shared/@ai-setting/roy-agent-core-k05v31rc.js";
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  PromptStore,
4
4
  getBuiltInPrompt,
5
5
  getBuiltInPromptNames
6
- } from "./shared/@ai-setting/roy-agent-core-akepggsr.js";
6
+ } from "./shared/@ai-setting/roy-agent-core-mmkyydw7.js";
7
7
  import {
8
8
  LLMComponent,
9
9
  LLMConfigSchema,
@@ -90,14 +90,13 @@ import {
90
90
  } from "./shared/@ai-setting/roy-agent-core-az13yzmc.js";
91
91
  import {
92
92
  WorkflowComponent
93
- } from "./shared/@ai-setting/roy-agent-core-bt7wezvg.js";
93
+ } from "./shared/@ai-setting/roy-agent-core-dp73ghtz.js";
94
94
  import {
95
95
  init_node_registry_helper,
96
96
  registerDecoratorNodeType
97
97
  } from "./shared/@ai-setting/roy-agent-core-fjexv5nm.js";
98
- import"./shared/@ai-setting/roy-agent-core-6b0r2e7j.js";
99
- import"./shared/@ai-setting/roy-agent-core-m4qjnhz6.js";
100
- import"./shared/@ai-setting/roy-agent-core-7z8fzxck.js";
98
+ import"./shared/@ai-setting/roy-agent-core-gttz2jpm.js";
99
+ import"./shared/@ai-setting/roy-agent-core-5kdw0p98.js";
101
100
  import"./shared/@ai-setting/roy-agent-core-6atd905e.js";
102
101
  import"./shared/@ai-setting/roy-agent-core-gb9gbkc3.js";
103
102
  import"./shared/@ai-setting/roy-agent-core-ddwa0n6h.js";
@@ -105,7 +104,7 @@ import"./shared/@ai-setting/roy-agent-core-hhrg314p.js";
105
104
  import"./shared/@ai-setting/roy-agent-core-j754zgb4.js";
106
105
  import"./shared/@ai-setting/roy-agent-core-qnrf2aw6.js";
107
106
  import"./shared/@ai-setting/roy-agent-core-r5axf0ad.js";
108
- import"./shared/@ai-setting/roy-agent-core-whw7jap0.js";
107
+ import"./shared/@ai-setting/roy-agent-core-1db4vpc6.js";
109
108
  import"./shared/@ai-setting/roy-agent-core-tq9528d3.js";
110
109
  import {
111
110
  Edge,
@@ -118,7 +117,7 @@ import"./shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
118
117
  import {
119
118
  AgentComponent,
120
119
  AgentComponentConfigSchema
121
- } from "./shared/@ai-setting/roy-agent-core-015vw11k.js";
120
+ } from "./shared/@ai-setting/roy-agent-core-yx0vw1aw.js";
122
121
  import {
123
122
  createInvokeConfig,
124
123
  invoke,
@@ -131,16 +130,16 @@ import {
131
130
  } from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
132
131
  import {
133
132
  TaskComponent
134
- } from "./shared/@ai-setting/roy-agent-core-qjv8537d.js";
133
+ } from "./shared/@ai-setting/roy-agent-core-dv12wpdv.js";
135
134
  import"./shared/@ai-setting/roy-agent-core-8gxth0eh.js";
136
- import"./shared/@ai-setting/roy-agent-core-f6p7wwpd.js";
135
+ import"./shared/@ai-setting/roy-agent-core-0kt57b72.js";
137
136
  import {
138
137
  SQLiteTaskStore,
139
138
  getDefaultTaskDbPath
140
139
  } from "./shared/@ai-setting/roy-agent-core-pcdzfwdv.js";
141
140
  import {
142
141
  AgentRegistry
143
- } from "./shared/@ai-setting/roy-agent-core-mbre4fxg.js";
142
+ } from "./shared/@ai-setting/roy-agent-core-7z4xtrmw.js";
144
143
  import {
145
144
  XDG_PATHS,
146
145
  getXDGPath,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DEFAULT_SUBAGENT_PROMPT
3
- } from "./roy-agent-core-mbre4fxg.js";
3
+ } from "./roy-agent-core-7z4xtrmw.js";
4
4
  import {
5
5
  TaskHookPoints
6
6
  } from "./roy-agent-core-92z6t4he.js";
@@ -442,10 +442,6 @@ class BackgroundTaskManager {
442
442
  this.stopProgressReporter(taskId);
443
443
  return;
444
444
  }
445
- if (task.startedAt) {
446
- const elapsedMs = Date.now() - task.startedAt;
447
- task.progress = Math.min(95, Math.floor(elapsedMs / PROGRESS_INTERVAL * 100));
448
- }
449
445
  const currentTaskId = getCurrentTaskId();
450
446
  if (currentTaskId !== undefined) {
451
447
  task.associatedTaskId = currentTaskId;
@@ -456,7 +452,6 @@ class BackgroundTaskManager {
456
452
  parentSessionId,
457
453
  description: task.description,
458
454
  status: task.status,
459
- progress: task.progress,
460
455
  associatedTaskId: task.associatedTaskId
461
456
  };
462
457
  this.publishBackgroundEvent(BackgroundTaskEventTypes.PROGRESS, progressPayload, parentSessionId);
@@ -109,7 +109,7 @@ var init_json_schema_to_zod = __esm(() => {
109
109
  });
110
110
 
111
111
  // src/env/workflow/tools/submit-json-output-tool.ts
112
- function createSubmitJsonOutputTool(schema) {
112
+ function createSubmitJsonOutputTool(schema, hookCtx) {
113
113
  const parameters = jsonSchemaToZod(schema);
114
114
  return {
115
115
  name: WORKFLOW_SUBMIT_OUTPUT_TOOL_NAME,
@@ -117,6 +117,7 @@ function createSubmitJsonOutputTool(schema) {
117
117
  parameters,
118
118
  async execute(args) {
119
119
  const parsed = parameters.parse(args);
120
+ hookCtx.structuredOutputExtracted = parsed;
120
121
  return {
121
122
  success: true,
122
123
  output: `${WorkflowJsonOutputMarker}:${JSON.stringify(parsed)}`
@@ -125,7 +126,7 @@ function createSubmitJsonOutputTool(schema) {
125
126
  metadata: {
126
127
  category: "workflow",
127
128
  tags: ["structured-output"],
128
- version: "1.0.0"
129
+ version: "1.1.0"
129
130
  }
130
131
  };
131
132
  }
@@ -1,59 +1,138 @@
1
- import {
2
- WORKFLOW_JSON_OUTPUT_PLUGIN_KEY,
3
- init_workflow_json_output_plugin,
4
- registerWorkflowJsonOutputPlugin,
5
- tracedExtractStructuredJsonViaLlm
6
- } from "./roy-agent-core-7z8fzxck.js";
7
1
  import {
8
2
  createSubmitJsonOutputTool,
9
3
  init_submit_json_output_tool
10
- } from "./roy-agent-core-whw7jap0.js";
4
+ } from "./roy-agent-core-1db4vpc6.js";
11
5
  import {
12
6
  AskUserError,
13
7
  init_workflow_hil
14
8
  } from "./roy-agent-core-e25xkv53.js";
9
+ import {
10
+ globalHookManager,
11
+ init_global_hook_manager
12
+ } from "./roy-agent-core-7tp56w6n.js";
15
13
  import {
16
14
  TracedAs,
17
- init_decorator
15
+ init_decorator,
16
+ wrapFunction
18
17
  } from "./roy-agent-core-k05v31rc.js";
18
+ import {
19
+ createLogger,
20
+ init_logger
21
+ } from "./roy-agent-core-shme7set.js";
19
22
  import {
20
23
  __esm,
21
24
  __legacyDecorateClassTS
22
25
  } from "./roy-agent-core-fs0mn2jk.js";
23
26
 
27
+ // src/env/workflow/plugins/workflow-json-output-plugin.ts
28
+ function registerWorkflowJsonOutputPlugin(options = undefined) {
29
+ if (registered) {
30
+ return;
31
+ }
32
+ if (options?.agentComponent) {
33
+ agentComponentRef = options.agentComponent;
34
+ }
35
+ registered = true;
36
+ globalHookManager.register(HOOK_POINT, {
37
+ name: HOOK_NAME,
38
+ pluginName: WORKFLOW_JSON_OUTPUT_PLUGIN_NAME,
39
+ sourceId: WORKFLOW_JSON_OUTPUT_SOURCE_ID,
40
+ priority: 100,
41
+ description: "Extract structured JSON output by invoking the json-extract sub-agent on the main session history",
42
+ execute: async (wrapper) => {
43
+ const hookCtx = wrapper.data;
44
+ await tracedRunWorkflowJsonOutputExtraction(hookCtx);
45
+ }
46
+ });
47
+ logger.info("Workflow JSON output plugin registered on agent:after.react");
48
+ }
49
+ async function runWorkflowJsonOutputExtraction(hookCtx) {
50
+ const schema = hookCtx.context.metadata?.outputSchema;
51
+ if (!schema) {
52
+ return;
53
+ }
54
+ if (hookCtx.error instanceof AskUserError) {
55
+ return;
56
+ }
57
+ if (hookCtx.structuredOutputExtracted) {
58
+ return;
59
+ }
60
+ if (!agentComponentRef) {
61
+ logger.warn("Workflow JSON extraction: agentComponent not registered. " + "Plugin cannot invoke json-extract sub-agent. " + "Ensure registerWorkflowJsonOutputPlugin({ agentComponent }) was called.");
62
+ return;
63
+ }
64
+ const sessionId = hookCtx.context.sessionId;
65
+ if (!sessionId) {
66
+ logger.warn("Workflow JSON extraction: no sessionId in hookCtx.context. " + "Cannot reuse main session history for json-extract sub-agent.");
67
+ return;
68
+ }
69
+ try {
70
+ const submitTool = createSubmitJsonOutputTool(schema, hookCtx);
71
+ const submitToolAsExtra = {
72
+ name: submitTool.name,
73
+ description: submitTool.description ?? "",
74
+ parameters: submitTool.parameters,
75
+ execute: submitTool.execute
76
+ };
77
+ const extractContext = {
78
+ sessionId,
79
+ extraTools: [submitToolAsExtra],
80
+ persistSession: false,
81
+ abort: hookCtx.context.abort
82
+ };
83
+ const result = await agentComponentRef.run("json-extract", "", extractContext);
84
+ if (result.error) {
85
+ logger.warn(`Workflow JSON extraction: json-extract sub-agent returned error: ${result.error}`);
86
+ return;
87
+ }
88
+ if (hookCtx.structuredOutputExtracted) {
89
+ logger.info("Workflow JSON output extracted via json-extract sub-agent " + `(iterations=${result.iterations}, toolCalls=${result.toolCalls?.length ?? 0})`);
90
+ } else {
91
+ logger.warn("Workflow JSON extraction: json-extract sub-agent did not call workflow_submit_output. " + "Check that the model supports tool calls.");
92
+ }
93
+ } catch (error) {
94
+ logger.error(`Workflow JSON extraction: json-extract sub-agent threw: ${error instanceof Error ? error.message : String(error)}`);
95
+ }
96
+ }
97
+ 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, agentComponentRef = null, tracedRunWorkflowJsonOutputExtraction;
98
+ var init_workflow_json_output_plugin = __esm(() => {
99
+ init_global_hook_manager();
100
+ init_workflow_hil();
101
+ init_submit_json_output_tool();
102
+ init_logger();
103
+ init_decorator();
104
+ logger = createLogger("WorkflowJsonOutputPlugin");
105
+ WORKFLOW_JSON_OUTPUT_PLUGIN_KEY = `${WORKFLOW_JSON_OUTPUT_SOURCE_ID}:${WORKFLOW_JSON_OUTPUT_PLUGIN_NAME}`;
106
+ HOOK_NAME = `${WORKFLOW_JSON_OUTPUT_PLUGIN_NAME}:${HOOK_POINT}`;
107
+ tracedRunWorkflowJsonOutputExtraction = wrapFunction(runWorkflowJsonOutputExtraction, "workflow.json_output.extraction", { recordParams: true, recordResult: true, log: true });
108
+ });
109
+
24
110
  // src/env/workflow/nodes/agent-component-adapter.ts
25
111
  var AgentComponentAdapter;
26
112
  var init_agent_component_adapter = __esm(() => {
27
113
  init_workflow_hil();
28
114
  init_workflow_json_output_plugin();
29
115
  init_decorator();
30
- init_submit_json_output_tool();
31
116
  AgentComponentAdapter = class AgentComponentAdapter {
32
117
  agentComponent;
33
118
  options;
34
119
  _sessionComponent;
35
- _llmComponent;
36
120
  agentSessionPrefix = "agent";
37
121
  _currentAgentSessionId;
38
122
  pendingSessions = new Map;
39
123
  runSessionToAgentSessions = new Map;
40
124
  jsonOutputPluginRegistered = false;
41
- constructor(agentComponent, options = {}, _sessionComponent, _llmComponent) {
125
+ constructor(agentComponent, options = {}, _sessionComponent) {
42
126
  this.agentComponent = agentComponent;
43
127
  this.options = options;
44
128
  this._sessionComponent = _sessionComponent;
45
- this._llmComponent = _llmComponent;
46
- this.ensureJsonOutputPluginRegistered();
47
- }
48
- setLLMComponent(llmComponent) {
49
- this._llmComponent = llmComponent;
50
129
  this.ensureJsonOutputPluginRegistered();
51
130
  }
52
131
  ensureJsonOutputPluginRegistered() {
53
- if (this.jsonOutputPluginRegistered || !this._llmComponent) {
132
+ if (this.jsonOutputPluginRegistered) {
54
133
  return;
55
134
  }
56
- registerWorkflowJsonOutputPlugin(this._llmComponent);
135
+ registerWorkflowJsonOutputPlugin({ agentComponent: this.agentComponent });
57
136
  this.jsonOutputPluginRegistered = true;
58
137
  }
59
138
  setSessionComponent(sessionComponent) {
@@ -84,19 +163,21 @@ var init_agent_component_adapter = __esm(() => {
84
163
  const workflowSessionId = config.workflowSessionId;
85
164
  const isResume = !!resumeOptions?.userQuery;
86
165
  let agentSessionId = resumeOptions?.agentSessionId || config.agentSessionId || this._currentAgentSessionId;
87
- if (!agentSessionId && this._sessionComponent) {
166
+ if (!agentSessionId) {
88
167
  agentSessionId = `${this.agentSessionPrefix}_${runId}_${nodeId}_${Date.now()}`;
89
- try {
90
- await this._sessionComponent.create({
91
- title: `Agent Session: ${config.type} (${agentSessionId})`,
92
- metadata: {
93
- type: "agent",
94
- workflowRunId: runId,
95
- workflowNodeId: nodeId
96
- }
97
- });
98
- } catch (error) {
99
- console.warn(`Failed to create agent session ${agentSessionId}:`, error);
168
+ if (this._sessionComponent) {
169
+ try {
170
+ await this._sessionComponent.create({
171
+ title: `Agent Session: ${config.type} (${agentSessionId})`,
172
+ metadata: {
173
+ type: "agent",
174
+ workflowRunId: runId,
175
+ workflowNodeId: nodeId
176
+ }
177
+ });
178
+ } catch (error) {
179
+ console.warn(`Failed to create agent session ${agentSessionId}:`, error);
180
+ }
100
181
  }
101
182
  }
102
183
  if (agentSessionId) {
@@ -126,9 +207,7 @@ var init_agent_component_adapter = __esm(() => {
126
207
  if (config.options?.timeout) {
127
208
  context.abort = new AbortController;
128
209
  }
129
- if (agentSessionId) {
130
- context.sessionId = agentSessionId;
131
- }
210
+ context.sessionId = agentSessionId;
132
211
  if (config.options?.allowedTools) {
133
212
  context.allowedTools = config.options.allowedTools;
134
213
  }
@@ -139,24 +218,13 @@ var init_agent_component_adapter = __esm(() => {
139
218
  runId,
140
219
  nodeId,
141
220
  sessionId: agentSessionId,
142
- outputSchema,
143
- workflowJsonOutputFallbackModel: config.options?.workflowJsonOutputFallbackModel
221
+ outputSchema
144
222
  };
145
223
  if (outputSchema) {
146
224
  context.pluginEnabled = {
147
225
  ...context.pluginEnabled ?? {},
148
226
  [WORKFLOW_JSON_OUTPUT_PLUGIN_KEY]: true
149
227
  };
150
- const submitTool = createSubmitJsonOutputTool(outputSchema);
151
- context.extraTools = [
152
- ...context.extraTools ?? [],
153
- {
154
- name: submitTool.name,
155
- description: submitTool.description ?? "",
156
- parameters: submitTool.parameters,
157
- execute: submitTool.execute
158
- }
159
- ];
160
228
  }
161
229
  if (config.workflowHistory) {
162
230
  context.workflowHistory = config.workflowHistory;
@@ -183,7 +251,7 @@ var init_agent_component_adapter = __esm(() => {
183
251
  if (agentSessionId) {
184
252
  this.pendingSessions.delete(agentSessionId);
185
253
  }
186
- const structuredOutput = await this.resolveStructuredOutput(result.structuredOutput, outputSchema, config, agentSessionId);
254
+ const structuredOutput = result.structuredOutput;
187
255
  return {
188
256
  output: structuredOutput ?? result.finalText ?? result.output,
189
257
  structuredOutput,
@@ -256,28 +324,6 @@ var init_agent_component_adapter = __esm(() => {
256
324
  getAgentComponent() {
257
325
  return this.agentComponent;
258
326
  }
259
- async resolveStructuredOutput(fromPlugin, outputSchema, config, agentSessionId) {
260
- if (fromPlugin) {
261
- return fromPlugin;
262
- }
263
- if (!outputSchema || !this._llmComponent || !agentSessionId || !this._sessionComponent) {
264
- return;
265
- }
266
- try {
267
- const sessionMessages = await this._sessionComponent.getMessages(agentSessionId);
268
- const history = sessionMessages.map((m) => ({
269
- role: m.role,
270
- content: m.content ?? ""
271
- }));
272
- return await tracedExtractStructuredJsonViaLlm(this._llmComponent, history, outputSchema, {
273
- model: config.options?.model,
274
- sessionId: agentSessionId
275
- });
276
- } catch (error) {
277
- console.warn("Workflow JSON extraction fallback failed:", error);
278
- return;
279
- }
280
- }
281
327
  agentSessionPrefixes = new Map;
282
328
  };
283
329
  __legacyDecorateClassTS([
@@ -177,6 +177,22 @@ class AgentRegistry {
177
177
  };
178
178
  this.agents.set(name, agent);
179
179
  }
180
+ registerJsonExtractAgent() {
181
+ const name = "json-extract";
182
+ if (this.agents.has(name))
183
+ return;
184
+ const agent = {
185
+ name,
186
+ type: "sub",
187
+ description: "JSON 提取子智能体 — 从父 session 历史中提取结构化 JSON,通过 workflow_submit_output 工具提交",
188
+ systemPromptRef: "json-extract",
189
+ allowedTools: ["workflow_submit_output"],
190
+ deniedTools: [],
191
+ maxIterations: 1,
192
+ filterHistory: false
193
+ };
194
+ this.agents.set(name, agent);
195
+ }
180
196
  async load() {
181
197
  try {
182
198
  return await this.loadFromDirectory(this.configDir);
@@ -6,7 +6,7 @@ import {
6
6
  WorkflowEngine,
7
7
  exports_engine,
8
8
  init_engine
9
- } from "./roy-agent-core-6b0r2e7j.js";
9
+ } from "./roy-agent-core-gttz2jpm.js";
10
10
  import {
11
11
  askUserTool,
12
12
  createRunWorkflowTool,
@@ -73,7 +73,6 @@ class WorkflowComponent extends BaseComponent {
73
73
  return this.workflowService;
74
74
  }
75
75
  toolComponent;
76
- llmComponent;
77
76
  logTraceComponent;
78
77
  _workflowEnv;
79
78
  skillRegistry;
@@ -83,7 +82,6 @@ class WorkflowComponent extends BaseComponent {
83
82
  this._status = "initializing";
84
83
  componentLogger.info("Initializing WorkflowComponent...");
85
84
  this.toolComponent = opts.toolComponent;
86
- this.llmComponent = opts.llmComponent;
87
85
  this.logTraceComponent = opts.logTraceComponent;
88
86
  this._workflowEnv = opts.env;
89
87
  this.skillRegistry = opts.skillRegistry;
@@ -123,7 +121,6 @@ class WorkflowComponent extends BaseComponent {
123
121
  const registry = new NodeRegistry({
124
122
  toolRegistry: options.toolComponent,
125
123
  agentComponent: options.env?.getComponent("agent"),
126
- llmComponent: options.env?.getComponent("llm"),
127
124
  skillRegistry: skillRegistryAdapter,
128
125
  sessionComponent: sessionComponentForEngine
129
126
  });
@@ -142,18 +139,16 @@ class WorkflowComponent extends BaseComponent {
142
139
  let agentRunner = this.agentRunner;
143
140
  if (!agentRunner && this._workflowEnv) {
144
141
  const agentComponent = this._workflowEnv.getComponent("agent");
145
- const llmComponent = this._workflowEnv.getComponent("llm");
146
142
  if (agentComponent) {
147
- const { AgentComponentAdapter } = await import("./roy-agent-core-nc0n0bdc.js");
148
- agentRunner = new AgentComponentAdapter(agentComponent, {}, this.sessionComponent, llmComponent);
143
+ const { AgentComponentAdapter } = await import("./roy-agent-core-xckhrs2p.js");
144
+ agentRunner = new AgentComponentAdapter(agentComponent, {}, this.sessionComponent);
149
145
  }
150
146
  }
151
147
  const registry = new NodeRegistry({
152
148
  toolRegistry: toolComponent,
153
149
  skillRegistry: skillComponent,
154
150
  agentRunner,
155
- sessionComponent: this.sessionComponent,
156
- llmComponent: this._workflowEnv?.getComponent("llm")
151
+ sessionComponent: this.sessionComponent
157
152
  });
158
153
  registerDecoratorNodeType2(registry);
159
154
  const engine = new WorkflowEngine(registry, this.sessionComponent);
@@ -242,20 +237,14 @@ class WorkflowComponent extends BaseComponent {
242
237
  const workflowRepository = new WorkflowRepository(db);
243
238
  const tagRepository = new TagRepository(db);
244
239
  const toolComponent = this.toolComponent || this._workflowEnv?.getComponent("tool");
245
- const llmComponent = this.llmComponent || this._workflowEnv?.getComponent("llm");
246
240
  const agentComponent = this._workflowEnv?.getComponent("agent");
247
241
  const skillComponent = this.skillRegistry || this._workflowEnv?.getComponent("skill");
248
242
  const sessionComponent = this._workflowEnv?.getComponent("session");
249
- componentLogger.info(`initSqliteService - toolComponent: ${!!toolComponent}, llmComponent: ${!!llmComponent}, skillRegistry: ${!!skillComponent}, sessionComponent: ${!!sessionComponent}`);
250
- if (llmComponent) {
251
- const { registerWorkflowJsonOutputPlugin } = await import("./roy-agent-core-qf9gvx02.js");
252
- registerWorkflowJsonOutputPlugin(llmComponent);
253
- }
243
+ componentLogger.info(`initSqliteService - toolComponent: ${!!toolComponent}, skillRegistry: ${!!skillComponent}, sessionComponent: ${!!sessionComponent}`);
254
244
  this.createService({
255
245
  workflowRepository,
256
246
  tagRepository,
257
247
  toolComponent,
258
- llmComponent,
259
248
  env: this._workflowEnv,
260
249
  skillRegistry: skillComponent,
261
250
  sessionComponent
@@ -5,7 +5,7 @@ import {
5
5
  BackgroundTaskManager,
6
6
  createDelegateTool,
7
7
  createStopTool
8
- } from "./roy-agent-core-f6p7wwpd.js";
8
+ } from "./roy-agent-core-0kt57b72.js";
9
9
  import {
10
10
  SQLiteTaskStore,
11
11
  getDefaultTaskDbPath
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AgentComponentAdapter,
3
3
  init_agent_component_adapter
4
- } from "./roy-agent-core-m4qjnhz6.js";
4
+ } from "./roy-agent-core-5kdw0p98.js";
5
5
  import {
6
6
  buildWorkflowNodeMetadata,
7
7
  getWorkflowNodeIdFromMetadata,
@@ -34,7 +34,7 @@ import {
34
34
  jsonSchemaToZod,
35
35
  parseWorkflowJsonOutput,
36
36
  validateJsonOutputSchema
37
- } from "./roy-agent-core-whw7jap0.js";
37
+ } from "./roy-agent-core-1db4vpc6.js";
38
38
  import {
39
39
  AskUserError,
40
40
  createNodeInterruptEvent,
@@ -1305,67 +1305,37 @@ var init_extract_agent_json_output = __esm(() => {
1305
1305
 
1306
1306
  // src/env/workflow/utils/build-agent-node-output.ts
1307
1307
  function buildAgentNodeOutput(agentResult, outputConfig) {
1308
- const base = {
1309
- metadata: agentResult.metadata,
1310
- workflowHistory: agentResult.messages
1311
- };
1312
1308
  if (outputConfig.mode === "json") {
1313
1309
  const schema = outputConfig.schema;
1314
1310
  const jsonData = extractAgentJsonOutput(agentResult, schema);
1315
- if (!jsonData) {
1316
- const defaults = buildSchemaDefaults(schema);
1317
- const fallbackData = { ...defaults, rawOutput: agentResult.output };
1311
+ if (jsonData) {
1318
1312
  return {
1319
- result: fallbackData,
1320
- ...fallbackData,
1313
+ result: jsonData,
1314
+ ...jsonData,
1321
1315
  metadata: {
1322
1316
  ...agentResult.metadata,
1323
- outputMode: "json_fallback",
1324
- _extractionWarning: "JSON extraction failed, using defaults"
1317
+ outputMode: "json"
1325
1318
  },
1326
1319
  workflowHistory: agentResult.messages
1327
1320
  };
1328
1321
  }
1322
+ const rawText = typeof agentResult.output === "string" ? agentResult.output : JSON.stringify(agentResult.output ?? {});
1329
1323
  return {
1330
- result: jsonData,
1331
- ...jsonData,
1324
+ result: rawText,
1332
1325
  metadata: {
1333
1326
  ...agentResult.metadata,
1334
- outputMode: "json"
1327
+ outputMode: "json_error",
1328
+ _extractionWarning: "JSON extraction failed — raw output surfaced"
1335
1329
  },
1336
1330
  workflowHistory: agentResult.messages
1337
1331
  };
1338
1332
  }
1339
1333
  return {
1340
1334
  result: agentResult.output,
1341
- ...base
1335
+ metadata: agentResult.metadata,
1336
+ workflowHistory: agentResult.messages
1342
1337
  };
1343
1338
  }
1344
- function buildSchemaDefaults(schema) {
1345
- const defaults = {};
1346
- if (!schema?.properties || !schema?.required)
1347
- return defaults;
1348
- for (const key of schema.required) {
1349
- const prop = schema.properties[key];
1350
- if (!prop?.type)
1351
- continue;
1352
- switch (prop.type) {
1353
- case "boolean":
1354
- defaults[key] = false;
1355
- break;
1356
- case "string":
1357
- defaults[key] = "";
1358
- break;
1359
- case "number":
1360
- case "integer":
1361
- defaults[key] = 0;
1362
- break;
1363
- default:
1364
- defaults[key] = null;
1365
- }
1366
- }
1367
- return defaults;
1368
- }
1369
1339
  var init_build_agent_node_output = __esm(() => {
1370
1340
  init_extract_agent_json_output();
1371
1341
  });
@@ -1452,8 +1422,7 @@ var init_agent_node = __esm(() => {
1452
1422
  model: effectiveModel,
1453
1423
  allowedTools: effectiveAllowedTools,
1454
1424
  deniedTools: effectiveDeniedTools,
1455
- outputSchema: outputConfig.schema,
1456
- workflowJsonOutputFallbackModel: options.workflowJsonOutputFallbackModel
1425
+ outputSchema: outputConfig.schema
1457
1426
  },
1458
1427
  workflowHistory: context.workflowHistory,
1459
1428
  nodeId: this.definition.id,
@@ -1595,8 +1564,7 @@ class NodeRegistry {
1595
1564
  agentComponent,
1596
1565
  agentRunner,
1597
1566
  workflowRunner,
1598
- sessionComponent,
1599
- llmComponent
1567
+ sessionComponent
1600
1568
  } = options ?? {};
1601
1569
  this.toolRegistry = toolRegistry;
1602
1570
  this.skillRegistry = skillRegistry;
@@ -1607,11 +1575,8 @@ class NodeRegistry {
1607
1575
  if (agentRunner.setSessionComponent && sessionComponent) {
1608
1576
  agentRunner.setSessionComponent(sessionComponent);
1609
1577
  }
1610
- if (llmComponent && "setLLMComponent" in agentRunner && typeof agentRunner.setLLMComponent === "function") {
1611
- agentRunner.setLLMComponent(llmComponent);
1612
- }
1613
1578
  } else if (agentComponent) {
1614
- this.agentComponentAdapter = new AgentComponentAdapter(agentComponent, {}, sessionComponent, llmComponent);
1579
+ this.agentComponentAdapter = new AgentComponentAdapter(agentComponent, {}, sessionComponent);
1615
1580
  this.agentRunner = this.agentComponentAdapter;
1616
1581
  }
1617
1582
  this.registerBuiltInTypes();
@@ -1728,12 +1693,10 @@ var init_engine = __esm(() => {
1728
1693
  static async create(options) {
1729
1694
  const agentComponent = options.env?.getComponent("agent");
1730
1695
  const sessionComponent = options.sessionComponent;
1731
- const llmComponent = options.env?.getComponent("llm");
1732
1696
  const nodeRegistry = new NodeRegistry({
1733
1697
  toolRegistry: options.toolRegistry,
1734
1698
  skillRegistry: options.skillRegistry,
1735
1699
  agentComponent,
1736
- llmComponent,
1737
1700
  workflowRunner: options.workflowRunner,
1738
1701
  sessionComponent
1739
1702
  });
@@ -1074,7 +1074,32 @@ workflow_run(workflow_name="strict-task-agent", input={"task_description": "修
1074
1074
  ## 重要规则
1075
1075
  - delegate_task 是后台模式,调用后立即返回 bgProcessId
1076
1076
  - 调用 delegate_task 后立即停止,不要再做其他操作
1077
- - 通过 task_operation_create 记录里程碑`
1077
+ - 通过 task_operation_create 记录里程碑`,
1078
+ "json-extract": `# JSON Extract Agent
1079
+
1080
+ 你是一个 JSON 提取子智能体。**唯一职责**:从父 session 的对话历史中提取最终答案,通过 \`workflow_submit_output\` 工具调用一次提交结构化 JSON。
1081
+
1082
+ ## 工具
1083
+
1084
+ 你**只有**一个工具:\`workflow_submit_output\`。
1085
+
1086
+ - 工具参数本身就是你要提交的 JSON 对象(由 zod schema 动态构建并验证)
1087
+ - 只调用一次,不要重复
1088
+ - 不要使用其他任何工具
1089
+
1090
+ ## 行为
1091
+
1092
+ 1. 读取 session 历史(通过 sessionId 自动加载)
1093
+ 2. 从对话中提取最终答案
1094
+ 3. 调用 \`workflow_submit_output(参数 = 最终 JSON)\`
1095
+ 4. 立即停止
1096
+
1097
+ ## 禁止
1098
+
1099
+ - ❌ 不要输出普通文本或解释
1100
+ - ❌ 不要输出 \`\`\`json 代码块
1101
+ - ❌ 不要调用其他工具
1102
+ - ❌ 不要问澄清问题`
1078
1103
  };
1079
1104
  function getBuiltInPromptNames() {
1080
1105
  return Object.keys(builtInPrompts);
@@ -1,9 +1,8 @@
1
1
  import {
2
2
  AgentComponentAdapter,
3
3
  init_agent_component_adapter
4
- } from "./roy-agent-core-m4qjnhz6.js";
5
- import"./roy-agent-core-7z8fzxck.js";
6
- import"./roy-agent-core-whw7jap0.js";
4
+ } from "./roy-agent-core-5kdw0p98.js";
5
+ import"./roy-agent-core-1db4vpc6.js";
7
6
  import"./roy-agent-core-e25xkv53.js";
8
7
  import"./roy-agent-core-7tp56w6n.js";
9
8
  import"./roy-agent-core-qg4rma4c.js";
@@ -7,7 +7,7 @@ import {
7
7
  } from "./roy-agent-core-e25xkv53.js";
8
8
  import {
9
9
  AgentRegistry
10
- } from "./roy-agent-core-mbre4fxg.js";
10
+ } from "./roy-agent-core-7z4xtrmw.js";
11
11
  import {
12
12
  ContextError
13
13
  } from "./roy-agent-core-ctdhjv68.js";
@@ -301,6 +301,8 @@ class AgentComponent extends BaseComponent {
301
301
  logger.info(`[AgentComponent] Loaded ${loadedCount} agents from config directory`);
302
302
  this.registry.registerWorkflowAgent();
303
303
  logger.info("[AgentComponent] Registered built-in workflow-agent");
304
+ this.registry.registerJsonExtractAgent();
305
+ logger.info("[AgentComponent] Registered built-in json-extract agent");
304
306
  for (const agentDef of this.registry.list()) {
305
307
  if (!this.agents.has(agentDef.name)) {
306
308
  const systemPrompt = await this.registry.getSystemPrompt(agentDef.name);
@@ -935,6 +937,11 @@ class AgentComponent extends BaseComponent {
935
937
  result.finalText = "Maximum iterations reached.";
936
938
  }
937
939
  const newMessages = hookCtx.messages.slice(historyMessageCount);
940
+ if (effectiveContext.persistSession !== false) {
941
+ await this.recordSessionMessages(effectiveContext.sessionId, newMessages);
942
+ } else {
943
+ logger.debug(`Skipping session message recording (persistSession=false, sessionId=${effectiveContext.sessionId})`);
944
+ }
938
945
  const reactContext = {
939
946
  messages: hookCtx.messages,
940
947
  sessionId: effectiveContext.sessionId,
@@ -979,11 +986,6 @@ class AgentComponent extends BaseComponent {
979
986
  historyMessageCount,
980
987
  sessionId: effectiveContext.sessionId
981
988
  });
982
- if (effectiveContext.persistSession !== false) {
983
- await this.recordSessionMessages(effectiveContext.sessionId, newMessages);
984
- } else {
985
- logger.debug(`Skipping session message recording (persistSession=false, sessionId=${effectiveContext.sessionId})`);
986
- }
987
989
  return this.finalizeResult(result, hookCtx);
988
990
  });
989
991
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.5.84",
3
+ "version": "1.5.85",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",
@@ -1,265 +0,0 @@
1
- import {
2
- WORKFLOW_SUBMIT_OUTPUT_TOOL_NAME,
3
- createSubmitJsonOutputTool,
4
- init_submit_json_output_tool,
5
- parseWorkflowJsonOutput
6
- } from "./roy-agent-core-whw7jap0.js";
7
- import {
8
- AskUserError,
9
- init_workflow_hil
10
- } from "./roy-agent-core-e25xkv53.js";
11
- import {
12
- globalHookManager,
13
- init_global_hook_manager
14
- } from "./roy-agent-core-7tp56w6n.js";
15
- import {
16
- init_decorator,
17
- wrapFunction
18
- } from "./roy-agent-core-k05v31rc.js";
19
- import {
20
- createLogger,
21
- init_logger
22
- } from "./roy-agent-core-shme7set.js";
23
- import {
24
- __esm
25
- } from "./roy-agent-core-fs0mn2jk.js";
26
-
27
- // src/env/workflow/utils/output-schema-hint.ts
28
- function describeOutputSchema(schema) {
29
- if (!schema || typeof schema !== "object") {
30
- return "Submit a JSON object matching the configured output schema";
31
- }
32
- const obj = schema;
33
- if (!obj.properties || Object.keys(obj.properties).length === 0) {
34
- return "Submit a JSON object matching the configured output schema";
35
- }
36
- const required = new Set(obj.required ?? []);
37
- const fields = Object.entries(obj.properties).map(([name, prop]) => {
38
- const type = prop.type ?? "unknown";
39
- const req = required.has(name) ? "required" : "optional";
40
- const desc = prop.description ? ` — ${prop.description}` : "";
41
- return `${name}: ${type} (${req})${desc}`;
42
- });
43
- return `Expected fields: ${fields.join("; ")}`;
44
- }
45
- var init_output_schema_hint = () => {};
46
-
47
- // src/env/workflow/plugins/workflow-json-output-plugin.ts
48
- function getFallbackModel(hookCtx) {
49
- const fromMetadata = hookCtx.context.metadata?.workflowJsonOutputFallbackModel;
50
- if (typeof fromMetadata === "string" && fromMetadata.length > 0)
51
- return fromMetadata;
52
- return process.env.WORKFLOW_JSON_OUTPUT_FALLBACK_MODEL || DEFAULT_FALLBACK_MODEL;
53
- }
54
- function isWorkflowJsonOutputEnabled(pluginEnabled) {
55
- return pluginEnabled?.[WORKFLOW_JSON_OUTPUT_PLUGIN_KEY] === true;
56
- }
57
- function registerWorkflowJsonOutputPlugin(llmComponent) {
58
- if (registered) {
59
- return;
60
- }
61
- registered = true;
62
- globalHookManager.register(HOOK_POINT, {
63
- name: HOOK_NAME,
64
- pluginName: WORKFLOW_JSON_OUTPUT_PLUGIN_NAME,
65
- sourceId: WORKFLOW_JSON_OUTPUT_SOURCE_ID,
66
- priority: 100,
67
- description: "Extract structured JSON after ReAct via a dedicated LLM invoke",
68
- execute: async (wrapper) => {
69
- const hookCtx = wrapper.data;
70
- await tracedRunWorkflowJsonOutputExtraction(hookCtx, llmComponent);
71
- }
72
- });
73
- logger.info("Workflow JSON output plugin registered on agent:after.react");
74
- }
75
- function unregisterWorkflowJsonOutputPlugin() {
76
- globalHookManager.unregister(HOOK_POINT, HOOK_NAME);
77
- registered = false;
78
- }
79
- async function runWorkflowJsonOutputExtraction(hookCtx, llmComponent) {
80
- const schema = hookCtx.context.metadata?.outputSchema;
81
- if (!schema) {
82
- return;
83
- }
84
- if (hookCtx.error instanceof AskUserError) {
85
- return;
86
- }
87
- if (hookCtx.structuredOutputExtracted) {
88
- return;
89
- }
90
- const extracted = extractStructuredJsonFromMessages(hookCtx.messages, schema);
91
- if (extracted) {
92
- hookCtx.structuredOutputExtracted = extracted;
93
- logger.info("Workflow JSON output extracted from ReAct messages (no second LLM invoke)");
94
- return;
95
- }
96
- logger.warn(`Workflow JSON extraction: Phase 1 (ReAct messages) returned no workflow_submit_output. ` + `Attempting Phase 2 fallback with model=${getFallbackModel(hookCtx)}.`);
97
- try {
98
- const fallbackExtracted = await extractStructuredJsonViaLlm(llmComponent, hookCtx.messages, schema, {
99
- model: getFallbackModel(hookCtx),
100
- sessionId: hookCtx.context.sessionId,
101
- abortSignal: hookCtx.context.abort
102
- });
103
- if (fallbackExtracted) {
104
- hookCtx.structuredOutputExtracted = fallbackExtracted;
105
- logger.info(`Workflow JSON output extracted via fallback LLM (${getFallbackModel(hookCtx)})`);
106
- } else {
107
- logger.warn(`Workflow JSON extraction: Phase 2 fallback (${getFallbackModel(hookCtx)}) also failed to extract structured output. ` + `Check if the fallback model is available and supports forced toolChoice.`);
108
- }
109
- } catch (error) {
110
- logger.error(`Workflow JSON extraction: Phase 2 fallback (${getFallbackModel(hookCtx)}) threw error`, { error: String(error) });
111
- }
112
- }
113
- function tryExtractToolCall(submitTool, tc) {
114
- const name = tc.function?.name ?? tc.name;
115
- if (name !== WORKFLOW_SUBMIT_OUTPUT_TOOL_NAME)
116
- return;
117
- const argsRaw = tc.function?.arguments ?? tc.arguments;
118
- const argsStr = typeof argsRaw === "string" ? argsRaw : JSON.stringify(argsRaw ?? {});
119
- try {
120
- return submitTool.parameters.parse(JSON.parse(argsStr));
121
- } catch {
122
- return;
123
- }
124
- }
125
- function extractStructuredJsonFromMessages(messages, schema) {
126
- const submitTool = createSubmitJsonOutputTool(schema);
127
- for (let i = messages.length - 1;i >= 0; i--) {
128
- const msg = messages[i];
129
- if (msg.role !== "assistant")
130
- continue;
131
- const toolCalls = msg.tool_calls ?? msg.toolCalls ?? [];
132
- if (toolCalls.length) {
133
- for (let j = toolCalls.length - 1;j >= 0; j--) {
134
- const result = tryExtractToolCall(submitTool, toolCalls[j]);
135
- if (result)
136
- return result;
137
- }
138
- }
139
- if (Array.isArray(msg.content)) {
140
- for (let k = msg.content.length - 1;k >= 0; k--) {
141
- const part = msg.content[k];
142
- if (part?.type !== "tool-call")
143
- continue;
144
- const result = tryExtractToolCall(submitTool, {
145
- name: part.toolName,
146
- arguments: part.args ?? part.arguments
147
- });
148
- if (result)
149
- return result;
150
- }
151
- }
152
- }
153
- return;
154
- }
155
- async function extractStructuredJsonViaLlm(llmComponent, historyMessages, schema, options = {}) {
156
- const submitTool = createSubmitJsonOutputTool(schema);
157
- const extractionUserMessage = {
158
- role: "user",
159
- content: "Based on the conversation above, call workflow_submit_output exactly once with structured JSON. " + `${describeOutputSchema(schema)}.`
160
- };
161
- const messages = [...historyMessages, extractionUserMessage].map(toLLMMessage);
162
- for (let attempt = 0;attempt < 2; attempt++) {
163
- const msgs = [...messages];
164
- if (attempt === 1) {
165
- msgs.push({
166
- role: "user",
167
- content: "You MUST call workflow_submit_output now with the structured JSON. Do NOT write text. Only call the tool."
168
- });
169
- }
170
- const result = await llmComponent.invoke({
171
- messages: msgs,
172
- tools: [
173
- {
174
- name: submitTool.name,
175
- description: submitTool.description ?? "",
176
- parameters: submitTool.parameters
177
- }
178
- ],
179
- model: options.model,
180
- context: {
181
- sessionId: options.sessionId
182
- },
183
- abortSignal: options.abortSignal,
184
- skipThresholdCheck: true
185
- });
186
- const toolCalls = result.output?.toolCalls ?? [];
187
- for (let i = toolCalls.length - 1;i >= 0; i--) {
188
- const tc = toolCalls[i];
189
- const name = tc.function?.name ?? tc.name;
190
- if (name !== WORKFLOW_SUBMIT_OUTPUT_TOOL_NAME) {
191
- continue;
192
- }
193
- const argsRaw = tc.function?.arguments ?? tc.arguments;
194
- const argsStr = typeof argsRaw === "string" ? argsRaw : JSON.stringify(argsRaw ?? {});
195
- try {
196
- const parsed = submitTool.parameters.parse(JSON.parse(argsStr));
197
- return parsed;
198
- } catch {
199
- const fromExecute = await submitTool.execute(JSON.parse(argsStr));
200
- const fromMarker = parseWorkflowJsonOutput(fromExecute.output);
201
- if (fromMarker) {
202
- return fromMarker;
203
- }
204
- }
205
- }
206
- }
207
- logger.warn("Workflow JSON extraction invoke did not return workflow_submit_output");
208
- return;
209
- }
210
- function toLLMMessage(msg) {
211
- if (typeof msg.content === "string") {
212
- return {
213
- role: msg.role,
214
- content: msg.content
215
- };
216
- }
217
- if (Array.isArray(msg.content)) {
218
- if (msg.role === "tool") {
219
- const toolResult = msg.content.find((part) => part.type === "tool-result");
220
- const output = toolResult?.output;
221
- const content = typeof output === "string" ? output : output && typeof output === "object" && ("value" in output) ? String(output.value ?? "") : JSON.stringify(output ?? "");
222
- return {
223
- role: "tool",
224
- content,
225
- toolCallId: toolResult?.toolCallId,
226
- name: toolResult?.toolName
227
- };
228
- }
229
- const text = msg.content.filter((part) => part.type === "text").map((part) => part.text ?? "").join(`
230
- `);
231
- const toolCallParts = msg.content.filter((part) => part.type === "tool-call");
232
- const toolCalls = msg.role === "assistant" && toolCallParts.length > 0 ? toolCallParts.map((part) => {
233
- const argsString = typeof part.input === "string" ? part.input : JSON.stringify(part.input ?? {});
234
- const toolName = part.toolName ?? "unknown";
235
- return {
236
- id: part.toolCallId ?? "",
237
- name: toolName,
238
- arguments: argsString,
239
- function: { name: toolName, arguments: argsString }
240
- };
241
- }) : undefined;
242
- return {
243
- role: msg.role,
244
- content: text,
245
- ...toolCalls?.length ? { toolCalls } : {}
246
- };
247
- }
248
- return { role: msg.role, content: "" };
249
- }
250
- var logger, WORKFLOW_JSON_OUTPUT_SOURCE_ID = "workflow", WORKFLOW_JSON_OUTPUT_PLUGIN_NAME = "json-output", WORKFLOW_JSON_OUTPUT_PLUGIN_KEY, DEFAULT_FALLBACK_MODEL = "minimax/MiniMax-M3", HOOK_POINT = "agent:after.react", HOOK_NAME, registered = false, tracedRunWorkflowJsonOutputExtraction, tracedExtractStructuredJsonViaLlm;
251
- var init_workflow_json_output_plugin = __esm(() => {
252
- init_global_hook_manager();
253
- init_workflow_hil();
254
- init_submit_json_output_tool();
255
- init_output_schema_hint();
256
- init_logger();
257
- init_decorator();
258
- logger = createLogger("WorkflowJsonOutputPlugin");
259
- WORKFLOW_JSON_OUTPUT_PLUGIN_KEY = `${WORKFLOW_JSON_OUTPUT_SOURCE_ID}:${WORKFLOW_JSON_OUTPUT_PLUGIN_NAME}`;
260
- HOOK_NAME = `${WORKFLOW_JSON_OUTPUT_PLUGIN_NAME}:${HOOK_POINT}`;
261
- tracedRunWorkflowJsonOutputExtraction = wrapFunction(runWorkflowJsonOutputExtraction, "workflow.json_output.extraction", { recordParams: true, recordResult: true, log: true });
262
- tracedExtractStructuredJsonViaLlm = wrapFunction(extractStructuredJsonViaLlm, "workflow.json_output.extract_via_llm", { recordParams: false, recordResult: true, log: true });
263
- });
264
-
265
- export { WORKFLOW_JSON_OUTPUT_SOURCE_ID, WORKFLOW_JSON_OUTPUT_PLUGIN_NAME, WORKFLOW_JSON_OUTPUT_PLUGIN_KEY, isWorkflowJsonOutputEnabled, registerWorkflowJsonOutputPlugin, unregisterWorkflowJsonOutputPlugin, runWorkflowJsonOutputExtraction, extractStructuredJsonFromMessages, extractStructuredJsonViaLlm, tracedRunWorkflowJsonOutputExtraction, tracedExtractStructuredJsonViaLlm, init_workflow_json_output_plugin };
@@ -1,39 +0,0 @@
1
- import {
2
- WORKFLOW_JSON_OUTPUT_PLUGIN_KEY,
3
- WORKFLOW_JSON_OUTPUT_PLUGIN_NAME,
4
- WORKFLOW_JSON_OUTPUT_SOURCE_ID,
5
- extractStructuredJsonFromMessages,
6
- extractStructuredJsonViaLlm,
7
- init_workflow_json_output_plugin,
8
- isWorkflowJsonOutputEnabled,
9
- registerWorkflowJsonOutputPlugin,
10
- runWorkflowJsonOutputExtraction,
11
- tracedExtractStructuredJsonViaLlm,
12
- tracedRunWorkflowJsonOutputExtraction,
13
- unregisterWorkflowJsonOutputPlugin
14
- } from "./roy-agent-core-7z8fzxck.js";
15
- import"./roy-agent-core-whw7jap0.js";
16
- import"./roy-agent-core-e25xkv53.js";
17
- import"./roy-agent-core-7tp56w6n.js";
18
- import"./roy-agent-core-qg4rma4c.js";
19
- import"./roy-agent-core-y5d04fm3.js";
20
- import"./roy-agent-core-k05v31rc.js";
21
- import"./roy-agent-core-shme7set.js";
22
- import"./roy-agent-core-7z9b1fm8.js";
23
- import"./roy-agent-core-c6592r3c.js";
24
- import"./roy-agent-core-fs0mn2jk.js";
25
- init_workflow_json_output_plugin();
26
-
27
- export {
28
- unregisterWorkflowJsonOutputPlugin,
29
- tracedRunWorkflowJsonOutputExtraction,
30
- tracedExtractStructuredJsonViaLlm,
31
- runWorkflowJsonOutputExtraction,
32
- registerWorkflowJsonOutputPlugin,
33
- isWorkflowJsonOutputEnabled,
34
- extractStructuredJsonViaLlm,
35
- extractStructuredJsonFromMessages,
36
- WORKFLOW_JSON_OUTPUT_SOURCE_ID,
37
- WORKFLOW_JSON_OUTPUT_PLUGIN_NAME,
38
- WORKFLOW_JSON_OUTPUT_PLUGIN_KEY
39
- };