@ai-setting/roy-agent-core 1.5.50 → 1.5.52

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 (59) hide show
  1. package/dist/config/index.js +6 -6
  2. package/dist/env/agent/index.js +7 -7
  3. package/dist/env/commands/index.js +6 -6
  4. package/dist/env/context/index.js +2 -2
  5. package/dist/env/debug/index.js +6 -6
  6. package/dist/env/event-source/index.js +8 -8
  7. package/dist/env/hook/index.js +4 -4
  8. package/dist/env/index.js +20 -20
  9. package/dist/env/llm/index.js +6 -6
  10. package/dist/env/log-trace/index.js +6 -6
  11. package/dist/env/mcp/index.js +6 -6
  12. package/dist/env/memory/index.js +6 -6
  13. package/dist/env/plugin/index.js +6 -6
  14. package/dist/env/prompt/index.js +6 -6
  15. package/dist/env/session/index.js +8 -8
  16. package/dist/env/session/storage/index.js +2 -2
  17. package/dist/env/skill/index.js +6 -6
  18. package/dist/env/task/delegate/index.js +4 -4
  19. package/dist/env/task/index.js +8 -8
  20. package/dist/env/task/plugins/index.js +3 -3
  21. package/dist/env/task/tools/index.js +2 -2
  22. package/dist/env/tool/index.js +6 -6
  23. package/dist/env/workflow/engine/index.js +6 -6
  24. package/dist/env/workflow/index.js +9 -9
  25. package/dist/index.js +30 -30
  26. package/dist/shared/@ai-setting/{roy-agent-core-fpb999vd.js → roy-agent-core-0frwccap.js} +5 -5
  27. package/dist/shared/@ai-setting/{roy-agent-core-ezfwx334.js → roy-agent-core-0x3g6snw.js} +8 -6
  28. package/dist/shared/@ai-setting/{roy-agent-core-c7cm1wjt.js → roy-agent-core-13vzexp2.js} +1 -1
  29. package/dist/shared/@ai-setting/{roy-agent-core-9a2n122m.js → roy-agent-core-29867p67.js} +1 -1
  30. package/dist/shared/@ai-setting/{roy-agent-core-y30njf6b.js → roy-agent-core-2g5j2nw6.js} +1 -1
  31. package/dist/shared/@ai-setting/{roy-agent-core-hd6kd06t.js → roy-agent-core-2xah3h0z.js} +8 -3
  32. package/dist/shared/@ai-setting/{roy-agent-core-5ng0awvn.js → roy-agent-core-3jk7ngmx.js} +4 -4
  33. package/dist/shared/@ai-setting/{roy-agent-core-a8gvea2f.js → roy-agent-core-4hk6ey73.js} +17 -2
  34. package/dist/shared/@ai-setting/{roy-agent-core-pa9wz5q0.js → roy-agent-core-4mw6rs37.js} +22 -9
  35. package/dist/shared/@ai-setting/{roy-agent-core-8nd895aq.js → roy-agent-core-5k8watmp.js} +20 -5
  36. package/dist/shared/@ai-setting/{roy-agent-core-qfdgg56t.js → roy-agent-core-5t6cryce.js} +1 -1
  37. package/dist/shared/@ai-setting/{roy-agent-core-w65c5gac.js → roy-agent-core-88d3k0p0.js} +1 -1
  38. package/dist/shared/@ai-setting/{roy-agent-core-9sarrbw9.js → roy-agent-core-9m9m6fe1.js} +2 -2
  39. package/dist/shared/@ai-setting/roy-agent-core-awmae5ax.js +258 -0
  40. package/dist/shared/@ai-setting/{roy-agent-core-rjf59e7k.js → roy-agent-core-cssnkkkg.js} +2 -2
  41. package/dist/shared/@ai-setting/{roy-agent-core-vfk5mtbx.js → roy-agent-core-ct95gkee.js} +34 -30
  42. package/dist/shared/@ai-setting/{roy-agent-core-pvswd18d.js → roy-agent-core-e68xspar.js} +1 -1
  43. package/dist/shared/@ai-setting/{roy-agent-core-7b35emr7.js → roy-agent-core-ew29335n.js} +3 -2
  44. package/dist/shared/@ai-setting/{roy-agent-core-y85xsddt.js → roy-agent-core-f336bk4g.js} +2 -2
  45. package/dist/shared/@ai-setting/{roy-agent-core-yq4fv8ce.js → roy-agent-core-hd9p5490.js} +1 -1
  46. package/dist/shared/@ai-setting/{roy-agent-core-t32gmaqn.js → roy-agent-core-kjdpe2ey.js} +1 -1
  47. package/dist/shared/@ai-setting/{roy-agent-core-d8v4n80n.js → roy-agent-core-mab4mzg3.js} +1 -1
  48. package/dist/shared/@ai-setting/{roy-agent-core-6mcb7nqa.js → roy-agent-core-pcjenbaf.js} +1 -1
  49. package/dist/shared/@ai-setting/{roy-agent-core-48v06q1b.js → roy-agent-core-qmr365f5.js} +2 -2
  50. package/dist/shared/@ai-setting/{roy-agent-core-316v7cm4.js → roy-agent-core-rmndq0sb.js} +1 -1
  51. package/dist/shared/@ai-setting/{roy-agent-core-mangq9x1.js → roy-agent-core-rz57pqpa.js} +2 -2
  52. package/dist/shared/@ai-setting/{roy-agent-core-4b18eceq.js → roy-agent-core-smwwze1m.js} +4 -4
  53. package/dist/shared/@ai-setting/{roy-agent-core-s7bgrtch.js → roy-agent-core-v7583cf9.js} +12 -2
  54. package/dist/shared/@ai-setting/{roy-agent-core-5qe84a90.js → roy-agent-core-vbyct0e7.js} +21 -16
  55. package/dist/shared/@ai-setting/{roy-agent-core-m5g2jx7f.js → roy-agent-core-vehgmfj1.js} +2 -2
  56. package/dist/shared/@ai-setting/{roy-agent-core-wtnwxn8h.js → roy-agent-core-wbqmmavh.js} +4 -4
  57. package/dist/shared/@ai-setting/{roy-agent-core-sxd8snnj.js → roy-agent-core-zmw5d68q.js} +1 -1
  58. package/package.json +1 -1
  59. package/dist/shared/@ai-setting/roy-agent-core-fy1y1aqx.js +0 -248
@@ -0,0 +1,258 @@
1
+ import {
2
+ WORKFLOW_JSON_OUTPUT_PLUGIN_KEY,
3
+ init_workflow_json_output_plugin,
4
+ registerWorkflowJsonOutputPlugin,
5
+ tracedExtractStructuredJsonViaLlm
6
+ } from "./roy-agent-core-29867p67.js";
7
+ import {
8
+ AskUserError,
9
+ init_workflow_hil
10
+ } from "./roy-agent-core-e25xkv53.js";
11
+ import {
12
+ TracedAs,
13
+ init_decorator
14
+ } from "./roy-agent-core-q5qj0fes.js";
15
+ import {
16
+ __esm,
17
+ __legacyDecorateClassTS
18
+ } from "./roy-agent-core-fs0mn2jk.js";
19
+
20
+ // src/env/workflow/nodes/agent-component-adapter.ts
21
+ var AgentComponentAdapter;
22
+ var init_agent_component_adapter = __esm(() => {
23
+ init_workflow_hil();
24
+ init_workflow_json_output_plugin();
25
+ init_decorator();
26
+ AgentComponentAdapter = class AgentComponentAdapter {
27
+ agentComponent;
28
+ options;
29
+ _sessionComponent;
30
+ _llmComponent;
31
+ agentSessionPrefix = "agent";
32
+ _currentAgentSessionId;
33
+ pendingSessions = new Map;
34
+ runSessionToAgentSessions = new Map;
35
+ jsonOutputPluginRegistered = false;
36
+ constructor(agentComponent, options = {}, _sessionComponent, _llmComponent) {
37
+ this.agentComponent = agentComponent;
38
+ this.options = options;
39
+ this._sessionComponent = _sessionComponent;
40
+ this._llmComponent = _llmComponent;
41
+ this.ensureJsonOutputPluginRegistered();
42
+ }
43
+ setLLMComponent(llmComponent) {
44
+ this._llmComponent = llmComponent;
45
+ this.ensureJsonOutputPluginRegistered();
46
+ }
47
+ ensureJsonOutputPluginRegistered() {
48
+ if (this.jsonOutputPluginRegistered || !this._llmComponent) {
49
+ return;
50
+ }
51
+ registerWorkflowJsonOutputPlugin(this._llmComponent);
52
+ this.jsonOutputPluginRegistered = true;
53
+ }
54
+ setSessionComponent(sessionComponent) {
55
+ this._sessionComponent = sessionComponent;
56
+ }
57
+ getCurrentAgentSessionId() {
58
+ return this._currentAgentSessionId;
59
+ }
60
+ registerAgent(name, config) {
61
+ this.agentComponent.registerAgent(name, {
62
+ type: config.type || "general",
63
+ model: config.model,
64
+ systemPrompt: config.systemPrompt,
65
+ maxIterations: config.maxIterations,
66
+ allowedTools: config.allowedTools,
67
+ deniedTools: config.deniedTools,
68
+ timeout: config.timeout,
69
+ maxErrorRetries: config.maxErrorRetries
70
+ });
71
+ if (config.sessionIdPrefix) {
72
+ this.agentSessionPrefixes.set(name, config.sessionIdPrefix);
73
+ }
74
+ }
75
+ async run(config, resumeOptions) {
76
+ const startTime = Date.now();
77
+ const nodeId = config.nodeId || "unknown";
78
+ const runId = config.runId || "unknown";
79
+ const workflowSessionId = config.workflowSessionId;
80
+ const isResume = !!resumeOptions?.userQuery;
81
+ let agentSessionId = resumeOptions?.agentSessionId || config.agentSessionId || this._currentAgentSessionId;
82
+ if (!agentSessionId && this._sessionComponent) {
83
+ agentSessionId = `${this.agentSessionPrefix}_${runId}_${nodeId}_${Date.now()}`;
84
+ try {
85
+ await this._sessionComponent.create({
86
+ title: `Agent Session: ${config.type} (${agentSessionId})`,
87
+ metadata: {
88
+ type: "agent",
89
+ workflowRunId: runId,
90
+ workflowNodeId: nodeId
91
+ }
92
+ });
93
+ } catch (error) {
94
+ console.warn(`Failed to create agent session ${agentSessionId}:`, error);
95
+ }
96
+ }
97
+ if (agentSessionId) {
98
+ this._currentAgentSessionId = agentSessionId;
99
+ if (workflowSessionId && this._sessionComponent) {
100
+ const mapping = this.runSessionToAgentSessions.get(workflowSessionId) || [];
101
+ if (!mapping.includes(agentSessionId)) {
102
+ mapping.push(agentSessionId);
103
+ this.runSessionToAgentSessions.set(workflowSessionId, mapping);
104
+ }
105
+ }
106
+ if (isResume) {
107
+ this.pendingSessions.delete(agentSessionId);
108
+ } else {
109
+ this.pendingSessions.set(agentSessionId, {
110
+ agentSessionId,
111
+ nodeId,
112
+ runId,
113
+ createdAt: Date.now()
114
+ });
115
+ }
116
+ }
117
+ try {
118
+ const outputSchema = config.options?.outputSchema;
119
+ const context = {};
120
+ if (config.options?.timeout) {
121
+ context.abort = new AbortController;
122
+ }
123
+ if (agentSessionId) {
124
+ context.sessionId = agentSessionId;
125
+ }
126
+ if (config.options?.allowedTools) {
127
+ context.allowedTools = config.options.allowedTools;
128
+ }
129
+ if (config.options?.deniedTools) {
130
+ context.deniedTools = config.options.deniedTools;
131
+ }
132
+ context.metadata = {
133
+ runId,
134
+ nodeId,
135
+ sessionId: agentSessionId,
136
+ outputSchema
137
+ };
138
+ if (outputSchema) {
139
+ context.pluginEnabled = {
140
+ ...context.pluginEnabled ?? {},
141
+ [WORKFLOW_JSON_OUTPUT_PLUGIN_KEY]: true
142
+ };
143
+ }
144
+ if (config.workflowHistory) {
145
+ context.workflowHistory = config.workflowHistory;
146
+ }
147
+ let additionInfo = config.prompt;
148
+ let userInput = resumeOptions?.userQuery || "";
149
+ if (agentSessionId && this._sessionComponent && !isResume) {
150
+ try {
151
+ const priorMessages = await this._sessionComponent.getMessages(agentSessionId);
152
+ const hasPriorAssistant = priorMessages.some((m) => m.role === "assistant" && (Boolean(m.content?.trim()) || m.parts?.some((p) => p.type === "tool-call" || p.type === "text")));
153
+ if (hasPriorAssistant && !userInput) {
154
+ userInput = "[Workflow re-run] Inputs were updated since your last reply. Produce a new result for this run.";
155
+ }
156
+ } catch {}
157
+ }
158
+ context.additionInfo = additionInfo;
159
+ const result = await this.agentComponent.run(config.type || "general", userInput, context);
160
+ if (result.error?.startsWith("__ASK_USER_ERROR__:")) {
161
+ const jsonStr = result.error.substring("__ASK_USER_ERROR__:".length);
162
+ const errorInfo = JSON.parse(jsonStr);
163
+ throw new AskUserError(runId, errorInfo.sessionId, errorInfo.nodeId, errorInfo.nodeType || "agent", errorInfo.query);
164
+ }
165
+ const duration = Date.now() - startTime;
166
+ if (agentSessionId) {
167
+ this.pendingSessions.delete(agentSessionId);
168
+ }
169
+ const structuredOutput = await this.resolveStructuredOutput(result.structuredOutput, outputSchema, config, agentSessionId);
170
+ return {
171
+ output: structuredOutput ?? result.finalText ?? result.output,
172
+ structuredOutput,
173
+ metadata: {
174
+ duration,
175
+ iterations: result.iterations,
176
+ toolCalls: result.toolCalls?.length,
177
+ toolCallsDetail: result.toolCalls,
178
+ agentSessionId
179
+ }
180
+ };
181
+ } catch (error) {
182
+ const isAskUserError = error instanceof Error && error.name === "AskUserError";
183
+ if (isAskUserError) {
184
+ throw error;
185
+ }
186
+ const duration = Date.now() - startTime;
187
+ const errorMessage = error instanceof Error ? error.message : String(error);
188
+ if (agentSessionId) {
189
+ this.pendingSessions.delete(agentSessionId);
190
+ }
191
+ return {
192
+ output: undefined,
193
+ metadata: {
194
+ duration,
195
+ error: errorMessage,
196
+ agentSessionId
197
+ }
198
+ };
199
+ } finally {
200
+ if (isResume) {
201
+ this._currentAgentSessionId = undefined;
202
+ }
203
+ }
204
+ }
205
+ async resumeAgent(agentSessionId, userQuery, config) {
206
+ this.pendingSessions.delete(agentSessionId);
207
+ this._currentAgentSessionId = agentSessionId;
208
+ config.agentSessionId = agentSessionId;
209
+ return this.run(config, { userQuery, agentSessionId });
210
+ }
211
+ getPendingSession(agentSessionId) {
212
+ return this.pendingSessions.get(agentSessionId);
213
+ }
214
+ getPendingSessionsForRun(runId) {
215
+ return Array.from(this.pendingSessions.values()).filter((session) => session.runId === runId);
216
+ }
217
+ getAgentSessionsForWorkflowSession(workflowSessionId) {
218
+ return this.runSessionToAgentSessions.get(workflowSessionId) || [];
219
+ }
220
+ hasAgent(name) {
221
+ return this.agentComponent.getAgent(name) !== undefined;
222
+ }
223
+ listAgents() {
224
+ return this.agentComponent.listAgents().map((a) => a.name);
225
+ }
226
+ getAgentComponent() {
227
+ return this.agentComponent;
228
+ }
229
+ async resolveStructuredOutput(fromPlugin, outputSchema, config, agentSessionId) {
230
+ if (fromPlugin) {
231
+ return fromPlugin;
232
+ }
233
+ if (!outputSchema || !this._llmComponent || !agentSessionId || !this._sessionComponent) {
234
+ return;
235
+ }
236
+ try {
237
+ const sessionMessages = await this._sessionComponent.getMessages(agentSessionId);
238
+ const history = sessionMessages.map((m) => ({
239
+ role: m.role,
240
+ content: m.content ?? ""
241
+ }));
242
+ return await tracedExtractStructuredJsonViaLlm(this._llmComponent, history, outputSchema, {
243
+ model: config.options?.model,
244
+ sessionId: agentSessionId
245
+ });
246
+ } catch (error) {
247
+ console.warn("Workflow JSON extraction fallback failed:", error);
248
+ return;
249
+ }
250
+ }
251
+ agentSessionPrefixes = new Map;
252
+ };
253
+ __legacyDecorateClassTS([
254
+ TracedAs("workflow.agent_adapter.run", { recordParams: true, recordResult: true, log: true })
255
+ ], AgentComponentAdapter.prototype, "run", null);
256
+ });
257
+
258
+ export { AgentComponentAdapter, init_agent_component_adapter };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createHook
3
- } from "./roy-agent-core-yq4fv8ce.js";
3
+ } from "./roy-agent-core-hd9p5490.js";
4
4
  import {
5
5
  HookManager
6
- } from "./roy-agent-core-48v06q1b.js";
6
+ } from "./roy-agent-core-qmr365f5.js";
7
7
 
8
8
  // src/env/component.ts
9
9
  class BaseComponent {
@@ -8,12 +8,12 @@ import {
8
8
  } from "./roy-agent-core-qxhq8ven.js";
9
9
  import {
10
10
  BaseComponent
11
- } from "./roy-agent-core-rjf59e7k.js";
11
+ } from "./roy-agent-core-cssnkkkg.js";
12
12
  import {
13
13
  LLMHookPoints,
14
14
  globalHookManager,
15
15
  init_global_hook_manager
16
- } from "./roy-agent-core-48v06q1b.js";
16
+ } from "./roy-agent-core-qmr365f5.js";
17
17
  import {
18
18
  TracedAs,
19
19
  init_decorator
@@ -371,9 +371,10 @@ function convertToSDKMessages(messages) {
371
371
  if (tc.function?.arguments) {
372
372
  if (typeof tc.function.arguments === "string") {
373
373
  try {
374
- input = JSON.parse(tc.function.arguments);
374
+ const parsed = JSON.parse(tc.function.arguments);
375
+ input = typeof parsed === "string" ? { _raw: parsed } : parsed;
375
376
  } catch {
376
- input = tc.function.arguments;
377
+ input = { _raw: tc.function.arguments };
377
378
  }
378
379
  } else {
379
380
  input = tc.function.arguments;
@@ -381,9 +382,10 @@ function convertToSDKMessages(messages) {
381
382
  } else if (tc.arguments) {
382
383
  if (typeof tc.arguments === "string") {
383
384
  try {
384
- input = JSON.parse(tc.arguments);
385
+ const parsed = JSON.parse(tc.arguments);
386
+ input = typeof parsed === "string" ? { _raw: parsed } : parsed;
385
387
  } catch {
386
- input = tc.arguments;
388
+ input = { _raw: tc.arguments };
387
389
  }
388
390
  } else {
389
391
  input = tc.arguments;
@@ -529,9 +531,9 @@ function processThinkingStream(textDelta, config, state) {
529
531
  }
530
532
  const tags = config.tags || ["thinking"];
531
533
  let remainingText = textDelta;
532
- const reasoningEvents = [];
533
- let isOpen = state.isOpen;
534
- let currentContent = state.content;
534
+ const reasoningEvents2 = [];
535
+ let isOpen2 = state.isOpen;
536
+ let currentContent2 = state.content;
535
537
  for (const tag of tags) {
536
538
  const openTag = `<${tag}>`;
537
539
  const closeTag = `</${tag}>`;
@@ -542,35 +544,35 @@ function processThinkingStream(textDelta, config, state) {
542
544
  if (openIndex !== -1 && (closeIndex === -1 || openIndex < closeIndex)) {
543
545
  const beforeOpen = text.substring(0, openIndex);
544
546
  const afterOpen = text.substring(openIndex + openTag.length);
545
- if (!isOpen) {
546
- isOpen = true;
547
- currentContent = "";
548
- reasoningEvents.push("");
547
+ if (!isOpen2) {
548
+ isOpen2 = true;
549
+ currentContent2 = "";
550
+ reasoningEvents2.push("");
549
551
  }
550
552
  result += beforeOpen;
551
553
  const innerCloseIndex = afterOpen.toLowerCase().indexOf(closeTag.toLowerCase());
552
554
  if (innerCloseIndex !== -1) {
553
555
  const thinkingContent = afterOpen.substring(0, innerCloseIndex);
554
556
  const afterClose = afterOpen.substring(innerCloseIndex + closeTag.length);
555
- currentContent += thinkingContent;
556
- reasoningEvents.push(currentContent);
557
- isOpen = false;
558
- currentContent = "";
557
+ currentContent2 += thinkingContent;
558
+ reasoningEvents2.push(currentContent2);
559
+ isOpen2 = false;
560
+ currentContent2 = "";
559
561
  result += afterClose;
560
562
  } else {
561
- currentContent += afterOpen;
562
- reasoningEvents.push(currentContent);
563
+ currentContent2 += afterOpen;
564
+ reasoningEvents2.push(currentContent2);
563
565
  result += "";
564
566
  }
565
567
  remainingText = result;
566
568
  } else if (closeIndex !== -1) {
567
569
  const beforeClose = text.substring(0, closeIndex);
568
570
  const afterClose = text.substring(closeIndex + closeTag.length);
569
- if (isOpen) {
570
- currentContent += beforeClose;
571
- reasoningEvents.push(currentContent);
572
- isOpen = false;
573
- currentContent = "";
571
+ if (isOpen2) {
572
+ currentContent2 += beforeClose;
573
+ reasoningEvents2.push(currentContent2);
574
+ isOpen2 = false;
575
+ currentContent2 = "";
574
576
  result = afterClose;
575
577
  } else {
576
578
  result = text;
@@ -578,11 +580,16 @@ function processThinkingStream(textDelta, config, state) {
578
580
  remainingText = result;
579
581
  }
580
582
  }
583
+ if (isOpen2 && remainingText === textDelta) {
584
+ currentContent2 += remainingText;
585
+ reasoningEvents2.push(currentContent2);
586
+ remainingText = "";
587
+ }
581
588
  return {
582
589
  cleanedText: remainingText,
583
- isThinkingTagOpen: isOpen,
584
- currentThinkingContent: currentContent,
585
- reasoningEvents
590
+ isThinkingTagOpen: isOpen2,
591
+ currentThinkingContent: currentContent2,
592
+ reasoningEvents: reasoningEvents2
586
593
  };
587
594
  }
588
595
  async function invoke(config, options, ctx) {
@@ -705,9 +712,6 @@ async function invoke(config, options, ctx) {
705
712
  break;
706
713
  }
707
714
  case "reasoning-end":
708
- if (emitToEnv) {
709
- emitToEnv({ type: "reasoning", content: reasoningContent, phase: "end" });
710
- }
711
715
  break;
712
716
  case "tool-call": {
713
717
  const toolInput = streamPart.input;
@@ -7,7 +7,7 @@ import {
7
7
  } from "./roy-agent-core-qxhq8ven.js";
8
8
  import {
9
9
  BaseComponent
10
- } from "./roy-agent-core-rjf59e7k.js";
10
+ } from "./roy-agent-core-cssnkkkg.js";
11
11
  import {
12
12
  __require
13
13
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -26,7 +26,8 @@ class SessionMessageConverter {
26
26
  let parsedArgs = {};
27
27
  if (typeof toolPart.arguments === "string") {
28
28
  try {
29
- parsedArgs = JSON.parse(toolPart.arguments);
29
+ const parsed = JSON.parse(toolPart.arguments);
30
+ parsedArgs = typeof parsed === "string" ? { _raw: parsed } : parsed;
30
31
  } catch {
31
32
  parsedArgs = { _raw: toolPart.arguments };
32
33
  }
@@ -98,7 +99,7 @@ class SessionMessageConverter {
98
99
  type: "tool-call",
99
100
  toolCallId: p.toolCallId,
100
101
  toolName: p.toolName,
101
- arguments: p.input,
102
+ arguments: typeof p.input === "string" ? { _raw: p.input } : p.input,
102
103
  state: "pending"
103
104
  });
104
105
  } else if (p.type === "tool-result") {
@@ -6,10 +6,10 @@ import {
6
6
  } from "./roy-agent-core-92z6t4he.js";
7
7
  import {
8
8
  init_context
9
- } from "./roy-agent-core-c7cm1wjt.js";
9
+ } from "./roy-agent-core-13vzexp2.js";
10
10
  import {
11
11
  getEnvContextOrEmpty
12
- } from "./roy-agent-core-s7bgrtch.js";
12
+ } from "./roy-agent-core-v7583cf9.js";
13
13
  import {
14
14
  TracedAs,
15
15
  init_decorator
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  init_global_hook_manager,
3
3
  init_hook_manager
4
- } from "./roy-agent-core-48v06q1b.js";
4
+ } from "./roy-agent-core-qmr365f5.js";
5
5
 
6
6
  // src/env/hook/types.ts
7
7
  function createHook(meta, fn) {
@@ -4,7 +4,7 @@ import {
4
4
  } from "./roy-agent-core-qxhq8ven.js";
5
5
  import {
6
6
  BaseComponent
7
- } from "./roy-agent-core-rjf59e7k.js";
7
+ } from "./roy-agent-core-cssnkkkg.js";
8
8
  import {
9
9
  createLogger,
10
10
  init_logger
@@ -6,7 +6,7 @@ import {
6
6
  } from "./roy-agent-core-qxhq8ven.js";
7
7
  import {
8
8
  BaseComponent
9
- } from "./roy-agent-core-rjf59e7k.js";
9
+ } from "./roy-agent-core-cssnkkkg.js";
10
10
  import {
11
11
  createLogger,
12
12
  init_logger
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SessionMessageConverter
3
- } from "./roy-agent-core-7b35emr7.js";
3
+ } from "./roy-agent-core-ew29335n.js";
4
4
  import {
5
5
  __require
6
6
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  init_context
3
- } from "./roy-agent-core-c7cm1wjt.js";
3
+ } from "./roy-agent-core-13vzexp2.js";
4
4
  import {
5
5
  getEnvContext
6
- } from "./roy-agent-core-s7bgrtch.js";
6
+ } from "./roy-agent-core-v7583cf9.js";
7
7
  import {
8
8
  __esm
9
9
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AgentComponentAdapter,
3
3
  init_agent_component_adapter
4
- } from "./roy-agent-core-fy1y1aqx.js";
4
+ } from "./roy-agent-core-awmae5ax.js";
5
5
  import {
6
6
  buildWorkflowNodeMetadata,
7
7
  getWorkflowNodeIdFromMetadata,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  BaseComponent
3
- } from "./roy-agent-core-rjf59e7k.js";
3
+ } from "./roy-agent-core-cssnkkkg.js";
4
4
  import {
5
5
  globalHookManager,
6
6
  init_global_hook_manager
7
- } from "./roy-agent-core-48v06q1b.js";
7
+ } from "./roy-agent-core-qmr365f5.js";
8
8
  import {
9
9
  createLogger,
10
10
  init_logger
@@ -6,7 +6,7 @@ import {
6
6
  WorkflowEngine,
7
7
  exports_engine,
8
8
  init_engine
9
- } from "./roy-agent-core-316v7cm4.js";
9
+ } from "./roy-agent-core-rmndq0sb.js";
10
10
  import {
11
11
  WorkflowService
12
12
  } from "./roy-agent-core-4t40mkpv.js";
@@ -15,7 +15,7 @@ import {
15
15
  } from "./roy-agent-core-0vbdz0x7.js";
16
16
  import {
17
17
  BaseComponent
18
- } from "./roy-agent-core-rjf59e7k.js";
18
+ } from "./roy-agent-core-cssnkkkg.js";
19
19
  import {
20
20
  createLogger,
21
21
  init_logger
@@ -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-fpb999vd.js");
139
+ const { AgentComponentAdapter } = await import("./roy-agent-core-0frwccap.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-5ng0awvn.js");
211
+ const { registerWorkflowJsonOutputPlugin } = await import("./roy-agent-core-3jk7ngmx.js");
212
212
  registerWorkflowJsonOutputPlugin(llmComponent);
213
213
  }
214
214
  this.createService({
@@ -22,7 +22,7 @@ function hasEnvContext() {
22
22
  return envContextStorage.getStore() !== undefined;
23
23
  }
24
24
  function getCurrentTaskId() {
25
- return envContextStorage.getStore()?.currentTaskId;
25
+ return envContextStorage.getStore()?.agentContext?.currentTaskId;
26
26
  }
27
27
  function runWithEnvContext(context, fn) {
28
28
  if (context) {
@@ -52,6 +52,10 @@ function createEnvContext(options) {
52
52
  function mergeEnvContext(partial) {
53
53
  const current = envContextStorage.getStore();
54
54
  if (current) {
55
+ if (partial.agentContext && current.agentContext) {
56
+ Object.assign(current.agentContext, partial.agentContext);
57
+ delete partial.agentContext;
58
+ }
55
59
  Object.assign(current, partial);
56
60
  }
57
61
  }
@@ -63,7 +67,13 @@ var init_env_context = __esm(() => {
63
67
  envContextStorage = new AsyncLocalStorage;
64
68
  setCurrentTaskId = wrapFunction(function _setCurrentTaskId(taskId) {
65
69
  const prev = getCurrentTaskId();
66
- mergeEnvContext({ currentTaskId: taskId });
70
+ const ctx = envContextStorage.getStore();
71
+ if (ctx) {
72
+ if (!ctx.agentContext) {
73
+ ctx.agentContext = {};
74
+ }
75
+ ctx.agentContext.currentTaskId = taskId;
76
+ }
67
77
  logger.info(`[setCurrentTaskId] taskId=${taskId ?? "undefined"} (was: ${prev ?? "undefined"})`);
68
78
  }, "env-context.setCurrentTaskId", { recordParams: true, recordResult: false, log: true });
69
79
  });
@@ -7,14 +7,14 @@ import {
7
7
  } from "./roy-agent-core-qxhq8ven.js";
8
8
  import {
9
9
  BaseComponent
10
- } from "./roy-agent-core-rjf59e7k.js";
10
+ } from "./roy-agent-core-cssnkkkg.js";
11
11
  import {
12
12
  createHook
13
- } from "./roy-agent-core-yq4fv8ce.js";
13
+ } from "./roy-agent-core-hd9p5490.js";
14
14
  import {
15
15
  globalHookManager,
16
16
  init_global_hook_manager
17
- } from "./roy-agent-core-48v06q1b.js";
17
+ } from "./roy-agent-core-qmr365f5.js";
18
18
  import {
19
19
  createLogger,
20
20
  init_logger
@@ -110,23 +110,26 @@ var builtInPrompts = {
110
110
  | 工具 | 描述 |
111
111
  |------|------|
112
112
  | \`delegate_task\` | 委托复杂/多步骤任务给子智能体执行 |
113
- | \`bash\` | **仅**用于执行简单的 Roy Agent 相关命令(如 \`bun packages/cli/dist/bin/roy-agent.js ...\`) |
113
+ | \`bash\` | **仅**用于执行一行简单的 Roy Agent 命令或一次性操作 |
114
114
 
115
115
  ### 工具使用规则
116
116
 
117
- **\`delegate_task\`** — 用于一切复杂、多步骤、需要读文件、运行命令、搜索、实现功能等场景。这是你的主要工具。
117
+ **\`delegate_task\`** — 这是你的**主要工具**。用于一切复杂、多步骤、需要读文件、运行命令、代码分析、搜索、实现功能等场景。**当不确定用哪个时,选 \`delegate_task\`。**
118
118
 
119
- **\`bash\`** — **仅限**以下简单场景:
120
- - 执行简单的 \`roy-agent\` 命令(如 \`bun packages/cli/dist/bin/roy-agent.js act "你好"\`)
121
- - 检查 Roy Agent 版本或帮助信息
122
- - 运行已经由子智能体构建好的脚本
123
- - 创建简单的问候或快速测试
119
+ **\`bash\`** — **仅限**以下**一次性简单操作**:
120
+ - 调用一行 \`roy-agent\` 命令(如 \`bun packages/cli/dist/bin/roy-agent.js tasks list\`)
121
+ - 执行一个简单的 shell 命令(如 \`ls\`、\`echo hello\`)
122
+ - 检查版本或帮助信息
123
+
124
+ **\`bash\` 的边界判定:**
125
+ > 如果需要 **2 步以上**、涉及**条件判断**、需要**读取结果后再决策**,或者**不确认能否一行完成**,**一律用 \`delegate_task\`**。
124
126
 
125
127
  **\`bash\` 禁止用于:**
126
- - 任何需要多步骤的复杂逻辑
127
- - 代码分析、文件读写、搜索
128
- - 功能开发、调试、重构
129
- - 即使可以用 bash 实现,复杂任务也必须使用 \`delegate_task\`
128
+ - 任何需要多步骤的复杂逻辑
129
+ - 代码分析、文件读写、搜索
130
+ - 功能开发、调试、重构
131
+ - 读取文件内容、grep 代码
132
+ - ❌ 即使可以用 bash 实现,**只要超过 1 步**就必须用 \`delegate_task\`
130
133
 
131
134
  ## 何时委托
132
135
 
@@ -139,10 +142,12 @@ var builtInPrompts = {
139
142
  - **不明确的请求** — 需要探索才能明确方向的任务
140
143
  - **文件/代码/数据访问** — 任何需要读文件、运行命令或查询数据的请求
141
144
 
142
- **不需要委托的情况:**
145
+ **不需要委托的情况(极少):**
143
146
  - 简单的问候 / 闲聊
144
147
  - 你凭自身知识就能回答的一次性简单问题
145
148
 
149
+ > ⚠️ **当你不确定是否需要委托时,一律委托。** 宁可多委托一次,也不要自己用 bash 做多步骤操作。
150
+
146
151
  ## 子智能体选择策略
147
152
 
148
153
  你有两个子智能体。**默认首次委托使用 \`roy\`**。仅在需要严格 Plan→Execute→Verify 纪律时使用 \`strict-task-agent\`。
@@ -199,7 +204,7 @@ delegate_task(
199
204
  ## 行为规则
200
205
 
201
206
  1. **复杂任务必须委托** — 不要尝试自己解决复杂任务。使用 \`delegate_task\` 委托给子智能体。
202
- 2. **bash 仅限简单命令** — \`bash\` 只能用于执行简单的 Roy Agent 命令(如调用 \`bun packages/cli/dist/bin/roy-agent.js ...\`)。任何需要多步骤逻辑的复杂工作,即使可以用 bash 实现,也必须使用 \`delegate_task\`。
207
+ 2. **bash 仅限一次操作** — \`bash\` 只能用于执行一行简单的 shell 命令或 \`roy-agent\` 命令。**任何超过 1 步的操作,即使可以用一行 bash 实现,也必须使用 \`delegate_task\`**。如果不确定,就委托。
203
208
  3. **保持简洁** — 简短分析,然后立即委托。不要冗长。
204
209
  4. **首选 roy** — 首次委托默认使用 \`roy\`
205
210
  5. **次选 strict-task-agent** — 需要严格 Plan→Execute→Verify 纪律时使用