@ai-setting/roy-agent-core 1.5.41 → 1.5.43

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.
@@ -10,7 +10,7 @@ import {
10
10
  parseJSONCWithProtocols,
11
11
  substituteEnvVars,
12
12
  substituteProtocolRefs
13
- } from "../shared/@ai-setting/roy-agent-core-frx4p6d1.js";
13
+ } from "../shared/@ai-setting/roy-agent-core-nj8yerg9.js";
14
14
  import"../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
15
15
  import"../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
16
16
  import"../shared/@ai-setting/roy-agent-core-4jqq077c.js";
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  AgentComponent,
3
3
  AgentComponentConfigSchema
4
- } from "../../shared/@ai-setting/roy-agent-core-c8f2hync.js";
4
+ } from "../../shared/@ai-setting/roy-agent-core-r6rwsr54.js";
5
5
  import"../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
6
+ import"../../shared/@ai-setting/roy-agent-core-fg3j215p.js";
7
+ import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
6
8
  import"../../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
7
9
  import {
8
10
  SummaryAgent
package/dist/env/index.js CHANGED
@@ -1,11 +1,6 @@
1
1
  import {
2
2
  BaseEnvironment
3
3
  } from "../shared/@ai-setting/roy-agent-core-ee6nnnqw.js";
4
- import {
5
- XDG_PATHS,
6
- getXDGPath,
7
- getXDGPaths
8
- } from "../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
9
4
  import {
10
5
  EventSourceComponent,
11
6
  builtInHandlers,
@@ -26,7 +21,7 @@ import"../shared/@ai-setting/roy-agent-core-e9fdm13a.js";
26
21
  import"../shared/@ai-setting/roy-agent-core-az13yzmc.js";
27
22
  import {
28
23
  WorkflowComponent
29
- } from "../shared/@ai-setting/roy-agent-core-yc543gnq.js";
24
+ } from "../shared/@ai-setting/roy-agent-core-bmr6bdfb.js";
30
25
  import"../shared/@ai-setting/roy-agent-core-0rtxwr28.js";
31
26
  import"../shared/@ai-setting/roy-agent-core-2jnzv9at.js";
32
27
  import"../shared/@ai-setting/roy-agent-core-69jskqjg.js";
@@ -39,20 +34,26 @@ import"../shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
39
34
  import {
40
35
  AgentComponent,
41
36
  AgentComponentConfigSchema
42
- } from "../shared/@ai-setting/roy-agent-core-c8f2hync.js";
37
+ } from "../shared/@ai-setting/roy-agent-core-r6rwsr54.js";
43
38
  import"../shared/@ai-setting/roy-agent-core-e25xkv53.js";
44
39
  import {
45
40
  TaskComponent
46
- } from "../shared/@ai-setting/roy-agent-core-15x8fe5h.js";
47
- import"../shared/@ai-setting/roy-agent-core-v53rfk99.js";
41
+ } from "../shared/@ai-setting/roy-agent-core-1zq3p19q.js";
42
+ import"../shared/@ai-setting/roy-agent-core-9p43ap7h.js";
48
43
  import"../shared/@ai-setting/roy-agent-core-hsxn8m1j.js";
44
+ import"../shared/@ai-setting/roy-agent-core-fg3j215p.js";
45
+ import {
46
+ XDG_PATHS,
47
+ getXDGPath,
48
+ getXDGPaths
49
+ } from "../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
49
50
  import"../shared/@ai-setting/roy-agent-core-wa1kzqky.js";
50
51
  import"../shared/@ai-setting/roy-agent-core-t94ktchq.js";
51
52
  import"../shared/@ai-setting/roy-agent-core-92z6t4he.js";
52
53
  import"../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
53
54
  import {
54
55
  McpComponent
55
- } from "../shared/@ai-setting/roy-agent-core-ycg9rk6z.js";
56
+ } from "../shared/@ai-setting/roy-agent-core-xkb264a8.js";
56
57
  import"../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
57
58
  import"../shared/@ai-setting/roy-agent-core-1bfmxx89.js";
58
59
  import"../shared/@ai-setting/roy-agent-core-kwhv9dcd.js";
@@ -8,7 +8,7 @@ import {
8
8
  McpServerLocalConfigSchema,
9
9
  McpServerRemoteConfigSchema,
10
10
  getMcpPathPriority
11
- } from "../../shared/@ai-setting/roy-agent-core-ycg9rk6z.js";
11
+ } from "../../shared/@ai-setting/roy-agent-core-xkb264a8.js";
12
12
  import"../../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
13
13
  import {
14
14
  adaptMcpTool,
@@ -3,7 +3,8 @@ import {
3
3
  PromptConfigSchema,
4
4
  PromptPathSchema,
5
5
  PromptRenderer
6
- } from "../../shared/@ai-setting/roy-agent-core-wb43x8hd.js";
6
+ } from "../../shared/@ai-setting/roy-agent-core-z1xf2fdk.js";
7
+ import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
7
8
  import"../../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
8
9
  import"../../shared/@ai-setting/roy-agent-core-4jqq077c.js";
9
10
  import"../../shared/@ai-setting/roy-agent-core-2dhd60aw.js";
@@ -3,8 +3,11 @@ import {
3
3
  BackgroundTaskManager,
4
4
  createDelegateTool,
5
5
  createStopTool
6
- } from "../../../shared/@ai-setting/roy-agent-core-v53rfk99.js";
6
+ } from "../../../shared/@ai-setting/roy-agent-core-9p43ap7h.js";
7
+ import"../../../shared/@ai-setting/roy-agent-core-fg3j215p.js";
8
+ import"../../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
7
9
  import"../../../shared/@ai-setting/roy-agent-core-92z6t4he.js";
10
+ import"../../../shared/@ai-setting/roy-agent-core-q5qj0fes.js";
8
11
  import"../../../shared/@ai-setting/roy-agent-core-jqy2mdyq.js";
9
12
  import"../../../shared/@ai-setting/roy-agent-core-z33en0cz.js";
10
13
  import"../../../shared/@ai-setting/roy-agent-core-10n2jh7p.js";
@@ -4,11 +4,13 @@ import {
4
4
  TaskConfigSchema,
5
5
  TaskPriorityEnum,
6
6
  TaskStatusEnum
7
- } from "../../shared/@ai-setting/roy-agent-core-15x8fe5h.js";
8
- import"../../shared/@ai-setting/roy-agent-core-v53rfk99.js";
7
+ } from "../../shared/@ai-setting/roy-agent-core-1zq3p19q.js";
8
+ import"../../shared/@ai-setting/roy-agent-core-9p43ap7h.js";
9
9
  import {
10
10
  SQLiteTaskStore
11
11
  } from "../../shared/@ai-setting/roy-agent-core-hsxn8m1j.js";
12
+ import"../../shared/@ai-setting/roy-agent-core-fg3j215p.js";
13
+ import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
12
14
  import"../../shared/@ai-setting/roy-agent-core-wa1kzqky.js";
13
15
  import"../../shared/@ai-setting/roy-agent-core-t94ktchq.js";
14
16
  import"../../shared/@ai-setting/roy-agent-core-92z6t4he.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  WorkflowComponent
3
- } from "../../shared/@ai-setting/roy-agent-core-yc543gnq.js";
3
+ } from "../../shared/@ai-setting/roy-agent-core-bmr6bdfb.js";
4
4
  import"../../shared/@ai-setting/roy-agent-core-0rtxwr28.js";
5
5
  import"../../shared/@ai-setting/roy-agent-core-2jnzv9at.js";
6
6
  import"../../shared/@ai-setting/roy-agent-core-69jskqjg.js";
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  } from "./shared/@ai-setting/roy-agent-core-kajktp3d.js";
13
13
  import {
14
14
  ConfigComponent
15
- } from "./shared/@ai-setting/roy-agent-core-frx4p6d1.js";
15
+ } from "./shared/@ai-setting/roy-agent-core-nj8yerg9.js";
16
16
  import {
17
17
  CommandsComponent
18
18
  } from "./shared/@ai-setting/roy-agent-core-b4wd9tn6.js";
@@ -33,9 +33,13 @@ import {
33
33
  } from "./shared/@ai-setting/roy-agent-core-rsybkb38.js";
34
34
  import {
35
35
  PromptComponent,
36
+ PromptStore,
36
37
  getBuiltInPrompt,
37
38
  getBuiltInPromptNames
38
- } from "./shared/@ai-setting/roy-agent-core-wb43x8hd.js";
39
+ } from "./shared/@ai-setting/roy-agent-core-z1xf2fdk.js";
40
+ import {
41
+ closeDatabase
42
+ } from "./shared/@ai-setting/roy-agent-core-9ffsvvcf.js";
39
43
  import"./shared/@ai-setting/roy-agent-core-2grcjaad.js";
40
44
  import {
41
45
  MemoryComponent
@@ -58,11 +62,6 @@ import {
58
62
  generateDescendingId,
59
63
  generateId
60
64
  } from "./shared/@ai-setting/roy-agent-core-ee6nnnqw.js";
61
- import {
62
- XDG_PATHS,
63
- getXDGPath,
64
- getXDGPaths
65
- } from "./shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
66
65
  import {
67
66
  EventSourceComponent,
68
67
  builtInHandlers,
@@ -93,7 +92,7 @@ import {
93
92
  } from "./shared/@ai-setting/roy-agent-core-az13yzmc.js";
94
93
  import {
95
94
  WorkflowComponent
96
- } from "./shared/@ai-setting/roy-agent-core-yc543gnq.js";
95
+ } from "./shared/@ai-setting/roy-agent-core-bmr6bdfb.js";
97
96
  import {
98
97
  init_node_registry_helper,
99
98
  registerDecoratorNodeType
@@ -115,16 +114,24 @@ import"./shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
115
114
  import {
116
115
  AgentComponent,
117
116
  AgentComponentConfigSchema
118
- } from "./shared/@ai-setting/roy-agent-core-c8f2hync.js";
117
+ } from "./shared/@ai-setting/roy-agent-core-r6rwsr54.js";
119
118
  import {
120
119
  AskUserError,
121
120
  init_workflow_hil
122
121
  } from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
123
122
  import {
124
123
  TaskComponent
125
- } from "./shared/@ai-setting/roy-agent-core-15x8fe5h.js";
126
- import"./shared/@ai-setting/roy-agent-core-v53rfk99.js";
124
+ } from "./shared/@ai-setting/roy-agent-core-1zq3p19q.js";
125
+ import"./shared/@ai-setting/roy-agent-core-9p43ap7h.js";
127
126
  import"./shared/@ai-setting/roy-agent-core-hsxn8m1j.js";
127
+ import {
128
+ AgentRegistry
129
+ } from "./shared/@ai-setting/roy-agent-core-fg3j215p.js";
130
+ import {
131
+ XDG_PATHS,
132
+ getXDGPath,
133
+ getXDGPaths
134
+ } from "./shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
128
135
  import"./shared/@ai-setting/roy-agent-core-wa1kzqky.js";
129
136
  import"./shared/@ai-setting/roy-agent-core-t94ktchq.js";
130
137
  import {
@@ -137,7 +144,7 @@ import {
137
144
  import"./shared/@ai-setting/roy-agent-core-psvxt4c9.js";
138
145
  import {
139
146
  McpComponent
140
- } from "./shared/@ai-setting/roy-agent-core-ycg9rk6z.js";
147
+ } from "./shared/@ai-setting/roy-agent-core-xkb264a8.js";
141
148
  import {
142
149
  AgentError,
143
150
  ComponentError,
@@ -365,6 +372,7 @@ export {
365
372
  createLogger,
366
373
  createInvokeConfig,
367
374
  createHook,
375
+ closeDatabase,
368
376
  builtInHandlers,
369
377
  bashTool,
370
378
  XDG_PATHS,
@@ -392,6 +400,7 @@ export {
392
400
  ReplFormatter,
393
401
  ProviderConfigSchema,
394
402
  ProviderCapabilitiesSchema,
403
+ PromptStore,
395
404
  PromptComponent,
396
405
  PluginComponent,
397
406
  OTelTracerProvider,
@@ -423,6 +432,7 @@ export {
423
432
  BUILT_IN_EVENT_SOURCE_TYPE_LIST,
424
433
  BUILT_IN_EVENT_SOURCE_TYPES,
425
434
  AskUserError,
435
+ AgentRegistry,
426
436
  AgentError,
427
437
  AgentComponentConfigSchema,
428
438
  AgentComponent
@@ -2,7 +2,7 @@ import {
2
2
  BackgroundTaskManager,
3
3
  createDelegateTool,
4
4
  createStopTool
5
- } from "./roy-agent-core-v53rfk99.js";
5
+ } from "./roy-agent-core-9p43ap7h.js";
6
6
  import {
7
7
  SQLiteTaskStore,
8
8
  getDefaultTaskDbPath
@@ -1,3 +1,6 @@
1
+ import {
2
+ DEFAULT_SUBAGENT_PROMPT
3
+ } from "./roy-agent-core-fg3j215p.js";
1
4
  import {
2
5
  TaskHookPoints
3
6
  } from "./roy-agent-core-92z6t4he.js";
@@ -12,6 +15,64 @@ import {
12
15
  // src/env/task/delegate/delegate-tool.ts
13
16
  init_logger();
14
17
  import { z } from "zod";
18
+
19
+ // src/env/task/delegate/subagent-resolver.ts
20
+ function isKnownSubagentType(subagentType, registry) {
21
+ if (getSubAgentSpec(subagentType)) {
22
+ return true;
23
+ }
24
+ return registry?.hasAgent(subagentType) ?? false;
25
+ }
26
+ async function resolveSubAgentConfig(subagentType, options = {}) {
27
+ const getBuiltIn = options.getBuiltIn ?? getSubAgentSpec;
28
+ const builtIn = getBuiltIn(subagentType);
29
+ const agentDef = options.registry?.get(subagentType);
30
+ if (!builtIn && !agentDef) {
31
+ return;
32
+ }
33
+ if (agentDef) {
34
+ return resolveFromRegistry(subagentType, agentDef, builtIn, options.registry);
35
+ }
36
+ return {
37
+ subagentType,
38
+ description: builtIn.description,
39
+ basePrompt: builtIn.promptOverride || DEFAULT_SUBAGENT_PROMPT,
40
+ allowedTools: builtIn.allowedTools,
41
+ deniedTools: builtIn.deniedTools ?? ["delegate_task", "stop_task"],
42
+ fromRegistry: false
43
+ };
44
+ }
45
+ async function resolveFromRegistry(subagentType, agentDef, builtIn, registry) {
46
+ const resolvedPrompt = registry ? await registry.getSystemPrompt(subagentType) : agentDef.systemPrompt;
47
+ return {
48
+ subagentType,
49
+ description: agentDef.description || builtIn?.description || "Custom agent",
50
+ basePrompt: resolvedPrompt || builtIn?.promptOverride || DEFAULT_SUBAGENT_PROMPT,
51
+ allowedTools: agentDef.allowedTools ?? builtIn?.allowedTools,
52
+ deniedTools: agentDef.deniedTools ?? builtIn?.deniedTools ?? ["delegate_task", "stop_task"],
53
+ fromRegistry: true
54
+ };
55
+ }
56
+ function buildAgentSelectionGuide(options) {
57
+ const customAgentNote = options.hasCustomAgents ? "- Custom agents from AgentRegistry are listed above." : "- Custom agents from AgentRegistry appear above when registered.";
58
+ return `
59
+ ## Agent Selection Guide
60
+
61
+ - Choose \`subagent_type\` from the list above; use \`general\` when no specialized agent fits (default).
62
+ ${customAgentNote}
63
+ - For full metadata: \`roy-agent agents list\`, \`roy-agent agents get <name>\`, \`roy-agent prompt list\`.`;
64
+ }
65
+ function listKnownSubagentDescriptions(registry) {
66
+ const builtInLines = builtInSubAgents.map((agent) => `- ${agent.id}: ${agent.description}`);
67
+ const registryAgents = registry?.listAgentsByType("sub") ?? [];
68
+ const customLines = registryAgents.filter((agent) => !builtInSubAgents.some((builtIn) => builtIn.id === agent.name)).map((agent) => `- ${agent.name}: ${agent.description || "Custom agent"}`);
69
+ const lines = [...builtInLines, ...customLines];
70
+ const guidance = buildAgentSelectionGuide({ hasCustomAgents: customLines.length > 0 });
71
+ return lines.join(`
72
+ `) + guidance;
73
+ }
74
+
75
+ // src/env/task/delegate/delegate-tool.ts
15
76
  var logger = createLogger("task:delegate");
16
77
  var BackgroundTaskEventTypes = {
17
78
  STARTED: "task.background.started",
@@ -99,10 +160,6 @@ var builtInSubAgents = [
99
160
  function getSubAgentSpec(id) {
100
161
  return builtInSubAgents.find((agent) => agent.id === id);
101
162
  }
102
- function getSubAgentToolDescription() {
103
- return builtInSubAgents.map((agent) => `- ${agent.id}: ${agent.description}`).join(`
104
- `);
105
- }
106
163
  function ensureSubAgentRegistered(agentComponent, subagentType, basePrompt, subAgent, deniedTools) {
107
164
  let agentInstance = agentComponent.getAgent(subagentType);
108
165
  if (!agentInstance) {
@@ -341,24 +398,20 @@ class BackgroundTaskManager {
341
398
  }
342
399
  }
343
400
  async executeWithAbort(subSession, prompt, timeoutMs, signal) {
344
- return new Promise((resolve, reject) => {
345
- const timer = setTimeout(() => {
346
- reject(new Error(`Task execution timeout after ${timeoutMs}ms`));
347
- }, timeoutMs);
348
- signal?.addEventListener("abort", () => {
349
- clearTimeout(timer);
350
- reject(new Error("Task execution stopped"));
351
- });
352
- const metadata = subSession.info?.metadata || {};
353
- const taskId = metadata.task_id;
354
- const taskDescription = metadata.task_description || "";
355
- const sessionId = subSession.id;
356
- const subagentType = metadata.subagent_type || "general";
357
- const subAgent = getSubAgentSpec(subagentType);
358
- let basePrompt = subAgent?.promptOverride || `You are a subagent. Complete this task: {task_description}`;
359
- const deniedTools = subAgent?.deniedTools || [];
360
- let fullPrompt = basePrompt.replace(/{task_description}/g, taskDescription || "N/A");
361
- fullPrompt += `
401
+ const metadata = subSession.info?.metadata || {};
402
+ const taskId = metadata.task_id;
403
+ const taskDescription = metadata.task_description || "";
404
+ const sessionId = subSession.id;
405
+ const subagentType = metadata.subagent_type || "general";
406
+ const agentComponent = this.env?.getComponent?.("agent");
407
+ const registry = agentComponent?.getRegistry?.();
408
+ const resolved = await resolveSubAgentConfig(subagentType, { registry });
409
+ const subAgent = getSubAgentSpec(subagentType);
410
+ const basePrompt = resolved?.basePrompt || subAgent?.promptOverride || `You are a subagent. Complete this task: {task_description}`;
411
+ const deniedTools = resolved?.deniedTools || subAgent?.deniedTools || [];
412
+ const allowedTools = resolved?.allowedTools || subAgent?.allowedTools;
413
+ let fullPrompt = basePrompt.replace(/{task_description}/g, taskDescription || "N/A");
414
+ fullPrompt += `
362
415
 
363
416
  ---
364
417
 
@@ -377,18 +430,31 @@ ${prompt}
377
430
  - 使用可用工具完成任务
378
431
  - 返回清晰的任务执行结果摘要
379
432
  - 适时调用 task_operation_create 记录进展`;
380
- const agentComponent = this.env?.getComponent?.("agent");
381
- if (!agentComponent) {
433
+ if (!agentComponent) {
434
+ throw new Error("AgentComponent not found");
435
+ }
436
+ const subAgentForRegister = subAgent ? { ...subAgent, allowedTools } : allowedTools ? {
437
+ id: subagentType,
438
+ name: subagentType,
439
+ mode: "subagent",
440
+ description: resolved?.description || "Custom agent",
441
+ allowedTools,
442
+ deniedTools
443
+ } : undefined;
444
+ ensureSubAgentRegistered(agentComponent, subagentType, basePrompt, subAgentForRegister, deniedTools);
445
+ return new Promise((resolve, reject) => {
446
+ const timer = setTimeout(() => {
447
+ reject(new Error(`Task execution timeout after ${timeoutMs}ms`));
448
+ }, timeoutMs);
449
+ signal?.addEventListener("abort", () => {
382
450
  clearTimeout(timer);
383
- reject(new Error("AgentComponent not found"));
384
- return;
385
- }
386
- ensureSubAgentRegistered(agentComponent, subagentType, basePrompt, subAgent, deniedTools);
451
+ reject(new Error("Task execution stopped"));
452
+ });
387
453
  this.env.handle_query?.(fullPrompt, {
388
454
  sessionId,
389
455
  deniedTools: deniedTools.length > 0 ? deniedTools : undefined,
390
456
  agentType: subagentType
391
- }).then((result) => {
457
+ })?.then((result) => {
392
458
  clearTimeout(timer);
393
459
  resolve(result);
394
460
  }).catch((error) => {
@@ -441,16 +507,21 @@ ${prompt}
441
507
  logger.info(`[BackgroundTaskManager] Disposed`);
442
508
  }
443
509
  }
510
+ function getAgentRegistry(taskComponent) {
511
+ const agentComponent = taskComponent.env?.getComponent?.("agent");
512
+ return agentComponent?.getRegistry?.();
513
+ }
444
514
  function createDelegateTool(taskComponent) {
445
515
  const env = taskComponent.env;
446
516
  const backgroundTaskManager = new BackgroundTaskManager(env);
517
+ const registry = getAgentRegistry(taskComponent);
447
518
  taskComponent._backgroundTaskManager = backgroundTaskManager;
448
519
  const tool = {
449
520
  name: "delegate_task",
450
521
  description: `Launch a new sub-agent to handle complex, multistep tasks autonomously.
451
522
 
452
523
  Available agent types:
453
- ${getSubAgentToolDescription()}
524
+ ${listKnownSubagentDescriptions(registry)}
454
525
 
455
526
  When using the delegate_task tool, you must specify a subagent_type parameter to select which agent type to use.
456
527
 
@@ -477,8 +548,8 @@ When using the delegate_task tool, you must specify a subagent_type parameter to
477
548
  const { description, prompt, subagent_type = "general", background = false, timeout, cleanup, task_id, reason } = params;
478
549
  const parentSessionId = ctx.session_id || "default";
479
550
  logger.info(`[delegate_task] Called: description=${description}, subagent_type=${subagent_type}, background=${background}, task_id=${task_id}`);
480
- const subAgent = getSubAgentSpec(subagent_type);
481
- if (!subAgent) {
551
+ const registry2 = getAgentRegistry(taskComponent);
552
+ if (!isKnownSubagentType(subagent_type, registry2)) {
482
553
  return {
483
554
  success: false,
484
555
  output: "",
@@ -558,9 +629,13 @@ async function handleSyncTask(taskComponent, parentSessionId, description, promp
558
629
  metadata: { execution_time_ms: Date.now() - startTime }
559
630
  };
560
631
  }
632
+ const agentComponent = taskComponent.env?.getComponent?.("agent");
633
+ const registry = getAgentRegistry(taskComponent);
634
+ const resolved = await resolveSubAgentConfig(subagentType, { registry });
561
635
  const subAgent = getSubAgentSpec(subagentType);
562
- let basePrompt = subAgent?.promptOverride || `You are a subagent. Complete this task: {task_description}`;
563
- const deniedTools = subAgent?.deniedTools || [];
636
+ let basePrompt = resolved?.basePrompt || subAgent?.promptOverride || `You are a subagent. Complete this task: {task_description}`;
637
+ const deniedTools = resolved?.deniedTools || subAgent?.deniedTools || [];
638
+ const allowedTools = resolved?.allowedTools || subAgent?.allowedTools;
564
639
  let fullPrompt = basePrompt.replace(/{task_description}/g, description || "N/A");
565
640
  fullPrompt += `
566
641
 
@@ -581,7 +656,6 @@ ${prompt}
581
656
  - 使用可用工具完成任务
582
657
  - 返回清晰的任务执行结果摘要
583
658
  - 适时调用 task_operation_create 记录进展`;
584
- const agentComponent = taskComponent.env?.getComponent?.("agent");
585
659
  if (!agentComponent) {
586
660
  return {
587
661
  success: false,
@@ -590,7 +664,15 @@ ${prompt}
590
664
  metadata: { execution_time_ms: Date.now() - startTime }
591
665
  };
592
666
  }
593
- ensureSubAgentRegistered(agentComponent, subagentType, basePrompt, subAgent, deniedTools);
667
+ const subAgentForRegister = subAgent ? { ...subAgent, allowedTools } : allowedTools ? {
668
+ id: subagentType,
669
+ name: subagentType,
670
+ mode: "subagent",
671
+ description: resolved?.description || "Custom agent",
672
+ allowedTools,
673
+ deniedTools
674
+ } : undefined;
675
+ ensureSubAgentRegistered(agentComponent, subagentType, basePrompt, subAgentForRegister, deniedTools);
594
676
  const timeoutMs = timeout || DEFAULT_TIMEOUT;
595
677
  let result;
596
678
  try {
@@ -259,6 +259,10 @@ class WorkflowComponent extends BaseComponent {
259
259
  this._status = "stopping";
260
260
  this.workflowService = null;
261
261
  this.nodeRegistry = null;
262
+ try {
263
+ const { closeDatabase } = await import("./roy-agent-core-zwp3jp02.js");
264
+ closeDatabase();
265
+ } catch {}
262
266
  this._status = "stopped";
263
267
  componentLogger.info("WorkflowComponent stopped");
264
268
  }