@ai-setting/roy-agent-core 1.6.11 → 1.6.13

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 (43) hide show
  1. package/dist/env/agent/index.js +3 -3
  2. package/dist/env/event-source/index.js +5 -5
  3. package/dist/env/index.js +19 -19
  4. package/dist/env/prompt/index.js +2 -2
  5. package/dist/env/task/delegate/index.js +4 -4
  6. package/dist/env/task/index.js +7 -7
  7. package/dist/env/task/plugins/index.js +4 -4
  8. package/dist/env/task/storage/index.js +2 -1
  9. package/dist/env/task/tools/operation/index.js +1 -1
  10. package/dist/env/tool/built-in/index.js +2 -2
  11. package/dist/env/tool/index.js +3 -3
  12. package/dist/env/workflow/engine/index.js +3 -3
  13. package/dist/env/workflow/index.js +7 -7
  14. package/dist/env/workflow/service/index.js +1 -1
  15. package/dist/env/workflow/tools/index.js +4 -4
  16. package/dist/env/workflow/utils/index.js +2 -2
  17. package/dist/index.js +132 -21
  18. package/dist/shared/@ai-setting/{roy-agent-core-0n2a8cbn.js → roy-agent-core-0crh2g0m.js} +594 -237
  19. package/dist/shared/@ai-setting/{roy-agent-core-0cftbg62.js → roy-agent-core-0pbmweh4.js} +1 -1
  20. package/dist/shared/@ai-setting/{roy-agent-core-jenchn33.js → roy-agent-core-24rmf17n.js} +8 -0
  21. package/dist/shared/@ai-setting/{roy-agent-core-2ek596yd.js → roy-agent-core-2b4078kz.js} +1 -1
  22. package/dist/shared/@ai-setting/{roy-agent-core-z7f8hyv7.js → roy-agent-core-6jqpdjr4.js} +1 -1
  23. package/dist/shared/@ai-setting/{roy-agent-core-38kbfarg.js → roy-agent-core-6qbyfzsw.js} +1 -1
  24. package/dist/shared/@ai-setting/{roy-agent-core-mb7b62sm.js → roy-agent-core-8cbsjkkx.js} +2 -2
  25. package/dist/shared/@ai-setting/roy-agent-core-9abv4ewh.js +1122 -0
  26. package/dist/shared/@ai-setting/{roy-agent-core-trdpar9f.js → roy-agent-core-apz6v22z.js} +419 -60
  27. package/dist/shared/@ai-setting/{roy-agent-core-y5ymc4f8.js → roy-agent-core-deqpzcg7.js} +46 -14
  28. package/dist/shared/@ai-setting/{roy-agent-core-m38q2azm.js → roy-agent-core-fvkyv5j6.js} +4 -2
  29. package/dist/shared/@ai-setting/{roy-agent-core-3rs38pf7.js → roy-agent-core-fwxqevpf.js} +11 -8
  30. package/dist/shared/@ai-setting/{roy-agent-core-pzeexnhf.js → roy-agent-core-nv4yfy3m.js} +4 -3
  31. package/dist/shared/@ai-setting/roy-agent-core-rn57psp0.js +396 -0
  32. package/dist/shared/@ai-setting/{roy-agent-core-wqe84f84.js → roy-agent-core-v5nknfh0.js} +30 -8
  33. package/dist/shared/@ai-setting/{roy-agent-core-06574wqa.js → roy-agent-core-v77pp20w.js} +4 -4
  34. package/dist/shared/@ai-setting/roy-agent-core-vcjq65nz.js +436 -0
  35. package/dist/shared/@ai-setting/{roy-agent-core-8wd3qwx5.js → roy-agent-core-wjve1qr5.js} +1 -1
  36. package/dist/shared/@ai-setting/{roy-agent-core-5w9a1eqa.js → roy-agent-core-wpw37qqf.js} +88 -3
  37. package/dist/shared/@ai-setting/{roy-agent-core-p6x6n3k4.js → roy-agent-core-x7fgze6s.js} +1 -1
  38. package/dist/shared/@ai-setting/{roy-agent-core-p2vpsd1d.js → roy-agent-core-ywtmc0bh.js} +166 -6
  39. package/package.json +1 -1
  40. package/dist/shared/@ai-setting/roy-agent-core-4yq23m5g.js +0 -421
  41. package/dist/shared/@ai-setting/roy-agent-core-9xby523m.js +0 -961
  42. package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +0 -213
  43. /package/dist/shared/@ai-setting/{roy-agent-core-zs31w092.js → roy-agent-core-9nhwdq9r.js} +0 -0
@@ -6,7 +6,7 @@ import {
6
6
  WorkflowEngine,
7
7
  exports_engine,
8
8
  init_engine
9
- } from "./roy-agent-core-0n2a8cbn.js";
9
+ } from "./roy-agent-core-0crh2g0m.js";
10
10
  import {
11
11
  askUserTool,
12
12
  createRunWorkflowTool,
@@ -18,10 +18,10 @@ import {
18
18
  createWorkflowSearchTool,
19
19
  createWorkflowTagListTool,
20
20
  createWorkflowValidateTool
21
- } from "./roy-agent-core-mb7b62sm.js";
21
+ } from "./roy-agent-core-8cbsjkkx.js";
22
22
  import {
23
23
  WorkflowService
24
- } from "./roy-agent-core-p2vpsd1d.js";
24
+ } from "./roy-agent-core-ywtmc0bh.js";
25
25
  import {
26
26
  BaseComponent
27
27
  } from "./roy-agent-core-j62bjagf.js";
@@ -141,7 +141,7 @@ class WorkflowComponent extends BaseComponent {
141
141
  if (!agentRunner && this._workflowEnv) {
142
142
  const agentComponent = this._workflowEnv.getComponent("agent");
143
143
  if (agentComponent) {
144
- const { AgentComponentAdapter } = await import("./roy-agent-core-z7f8hyv7.js");
144
+ const { AgentComponentAdapter } = await import("./roy-agent-core-6jqpdjr4.js");
145
145
  agentRunner = new AgentComponentAdapter(agentComponent, {}, this.sessionComponent);
146
146
  }
147
147
  }
@@ -0,0 +1,436 @@
1
+ import {
2
+ TracedAs,
3
+ init_decorator
4
+ } from "./roy-agent-core-fdm579b1.js";
5
+ import {
6
+ __esm,
7
+ __legacyDecorateClassTS
8
+ } from "./roy-agent-core-fs0mn2jk.js";
9
+
10
+ // src/env/workflow/engine/dag-manager.ts
11
+ var DAGManager;
12
+ var init_dag_manager = __esm(() => {
13
+ init_decorator();
14
+ DAGManager = class DAGManager {
15
+ workflow;
16
+ nodeMap;
17
+ extendedDefinition = null;
18
+ cachedAnalysis = null;
19
+ allowCycles;
20
+ constructor(workflow, options) {
21
+ if (!workflow.nodes || workflow.nodes.length === 0) {
22
+ throw new Error("At least one node is required");
23
+ }
24
+ this.workflow = workflow;
25
+ this.nodeMap = new Map;
26
+ this.allowCycles = options?.allowCycles ?? false;
27
+ for (const node of workflow.nodes) {
28
+ if (node.id === "") {
29
+ throw new Error("Node ID cannot be empty");
30
+ }
31
+ if (this.nodeMap.has(node.id)) {
32
+ throw new Error(`Duplicate node ID: ${node.id}`);
33
+ }
34
+ this.nodeMap.set(node.id, node);
35
+ }
36
+ }
37
+ getExtendedDefinition() {
38
+ if (this.extendedDefinition) {
39
+ return this.extendedDefinition;
40
+ }
41
+ const analysis = this.analyze();
42
+ this.extendedDefinition = {
43
+ ...this.workflow,
44
+ computedEntry: analysis.entryNodes,
45
+ nodeMap: this.nodeMap,
46
+ topologicalOrder: this.getTopologicalOrder()
47
+ };
48
+ return this.extendedDefinition;
49
+ }
50
+ analyze() {
51
+ if (this.cachedAnalysis) {
52
+ return this.cachedAnalysis;
53
+ }
54
+ const dependencies = this.buildDependenciesMap();
55
+ const dependents = this.buildDependentsMap(dependencies);
56
+ const entryNodes = this.findEntryNodes(dependencies);
57
+ const exitNodes = this.findExitNodes(dependents);
58
+ const levels = this.computeLevels(dependencies);
59
+ const criticalPath = this.findCriticalPath(levels, dependencies);
60
+ this.cachedAnalysis = {
61
+ entryNodes,
62
+ exitNodes,
63
+ levels,
64
+ dependencies,
65
+ dependents,
66
+ criticalPath
67
+ };
68
+ return this.cachedAnalysis;
69
+ }
70
+ buildDependenciesMap() {
71
+ const dependencies = new Map;
72
+ for (const node of this.workflow.nodes) {
73
+ const deps = node.depends_on || [];
74
+ dependencies.set(node.id, [...deps]);
75
+ }
76
+ if (this.workflow.edges) {
77
+ for (const edge of this.workflow.edges) {
78
+ const targetDeps = dependencies.get(edge.to);
79
+ if (!targetDeps)
80
+ continue;
81
+ if (targetDeps.includes(edge.from))
82
+ continue;
83
+ if (!this.isReachable(edge.from, edge.to, dependencies)) {
84
+ targetDeps.push(edge.from);
85
+ }
86
+ }
87
+ }
88
+ return dependencies;
89
+ }
90
+ isReachable(source, target, dependencies) {
91
+ if (source === target)
92
+ return true;
93
+ const visited = new Set;
94
+ const queue = [source];
95
+ while (queue.length > 0) {
96
+ const current = queue.shift();
97
+ if (current === target)
98
+ return true;
99
+ if (visited.has(current))
100
+ continue;
101
+ visited.add(current);
102
+ const deps = dependencies.get(current) || [];
103
+ for (const dep of deps) {
104
+ if (!visited.has(dep))
105
+ queue.push(dep);
106
+ }
107
+ }
108
+ return false;
109
+ }
110
+ buildDependentsMap(dependencies) {
111
+ const dependentsMap = new Map;
112
+ for (const nodeId of dependencies.keys()) {
113
+ dependentsMap.set(nodeId, []);
114
+ }
115
+ for (const [nodeId, deps] of dependencies.entries()) {
116
+ for (const dep of deps) {
117
+ const nodeDependents = dependentsMap.get(dep) || [];
118
+ nodeDependents.push(nodeId);
119
+ dependentsMap.set(dep, nodeDependents);
120
+ }
121
+ }
122
+ return dependentsMap;
123
+ }
124
+ findEntryNodes(dependencies) {
125
+ const entryNodes = [];
126
+ for (const [nodeId, deps] of dependencies.entries()) {
127
+ if (deps.length === 0) {
128
+ entryNodes.push(nodeId);
129
+ }
130
+ }
131
+ return entryNodes;
132
+ }
133
+ findExitNodes(dependents) {
134
+ const exitNodes = [];
135
+ for (const [nodeId, deps] of dependents.entries()) {
136
+ if (deps.length === 0) {
137
+ exitNodes.push(nodeId);
138
+ }
139
+ }
140
+ return exitNodes;
141
+ }
142
+ computeLevels(dependencies) {
143
+ const levels = [];
144
+ const assigned = new Set;
145
+ const nodeLevels = new Map;
146
+ const dependentsMap = this.buildDependentsMap(dependencies);
147
+ const entryNodes = this.findEntryNodes(dependencies);
148
+ const queue = [];
149
+ for (const entry of entryNodes) {
150
+ queue.push({ nodeId: entry, level: 0 });
151
+ nodeLevels.set(entry, 0);
152
+ }
153
+ while (queue.length > 0) {
154
+ const { nodeId, level } = queue.shift();
155
+ if (assigned.has(nodeId)) {
156
+ const currentLevel = nodeLevels.get(nodeId) || 0;
157
+ if (level > currentLevel) {
158
+ nodeLevels.set(nodeId, level);
159
+ }
160
+ continue;
161
+ }
162
+ assigned.add(nodeId);
163
+ nodeLevels.set(nodeId, level);
164
+ const dependentsOfNode = dependentsMap.get(nodeId) || [];
165
+ for (const dependent of dependentsOfNode) {
166
+ if (!assigned.has(dependent)) {
167
+ queue.push({ nodeId: dependent, level: level + 1 });
168
+ }
169
+ }
170
+ }
171
+ for (const nodeId of dependencies.keys()) {
172
+ if (!nodeLevels.has(nodeId)) {
173
+ nodeLevels.set(nodeId, 0);
174
+ }
175
+ }
176
+ const maxLevel = Math.max(...nodeLevels.values(), 0);
177
+ for (let i = 0;i <= maxLevel; i++) {
178
+ levels.push([]);
179
+ }
180
+ for (const [nodeId, level] of nodeLevels.entries()) {
181
+ levels[level].push(nodeId);
182
+ }
183
+ return levels;
184
+ }
185
+ findCriticalPath(levels, dependencies) {
186
+ if (levels.length === 0) {
187
+ return [];
188
+ }
189
+ const longestPath = new Map;
190
+ const allNodes = [];
191
+ for (const level of levels) {
192
+ allNodes.push(...level);
193
+ }
194
+ for (const nodeId of allNodes) {
195
+ const deps = dependencies.get(nodeId) || [];
196
+ if (deps.length === 0) {
197
+ longestPath.set(nodeId, { length: 1, path: [nodeId] });
198
+ } else {
199
+ let maxLength2 = 0;
200
+ let maxPath = [];
201
+ for (const dep of deps) {
202
+ const depInfo = longestPath.get(dep);
203
+ if (depInfo && depInfo.length > maxLength2) {
204
+ maxLength2 = depInfo.length;
205
+ maxPath = depInfo.path;
206
+ }
207
+ }
208
+ longestPath.set(nodeId, {
209
+ length: maxLength2 + 1,
210
+ path: [...maxPath, nodeId]
211
+ });
212
+ }
213
+ }
214
+ let maxLength = 0;
215
+ let criticalPath = [];
216
+ for (const [, info] of longestPath.entries()) {
217
+ if (info.length > maxLength) {
218
+ maxLength = info.length;
219
+ criticalPath = info.path;
220
+ }
221
+ }
222
+ return criticalPath;
223
+ }
224
+ getTopologicalOrder() {
225
+ const dependencies = this.buildDependenciesMap();
226
+ const dependents = this.buildDependentsMap(dependencies);
227
+ const inDegree = new Map;
228
+ for (const nodeId of dependencies.keys()) {
229
+ inDegree.set(nodeId, dependencies.get(nodeId)?.length || 0);
230
+ }
231
+ const queue = [];
232
+ for (const [nodeId, degree] of inDegree.entries()) {
233
+ if (degree === 0) {
234
+ queue.push(nodeId);
235
+ }
236
+ }
237
+ const result = [];
238
+ while (queue.length > 0) {
239
+ const nodeId = queue.shift();
240
+ result.push(nodeId);
241
+ const nodeDependents = dependents.get(nodeId) || [];
242
+ for (const dependent of nodeDependents) {
243
+ const currentDegree = inDegree.get(dependent) || 0;
244
+ inDegree.set(dependent, currentDegree - 1);
245
+ if (currentDegree - 1 === 0) {
246
+ queue.push(dependent);
247
+ }
248
+ }
249
+ }
250
+ return result;
251
+ }
252
+ getReadyNodes(completedNodes) {
253
+ const dependencies = this.buildDependenciesMap();
254
+ const ready = [];
255
+ for (const nodeId of dependencies.keys()) {
256
+ if (completedNodes.has(nodeId)) {
257
+ continue;
258
+ }
259
+ if (this.areDependenciesMet(nodeId, completedNodes)) {
260
+ ready.push(nodeId);
261
+ }
262
+ }
263
+ return ready;
264
+ }
265
+ areDependenciesMet(nodeId, completedNodes) {
266
+ const analysis = this.analyze();
267
+ const deps = analysis.dependencies.get(nodeId);
268
+ if (!deps) {
269
+ return true;
270
+ }
271
+ for (const dep of deps) {
272
+ if (!completedNodes.has(dep)) {
273
+ return false;
274
+ }
275
+ }
276
+ return true;
277
+ }
278
+ isCyclic() {
279
+ const dependencies = this.buildDependenciesMap();
280
+ const order = this.getTopologicalOrderInternal(dependencies);
281
+ return order.length !== this.workflow.nodes.length;
282
+ }
283
+ getTopologicalOrderInternal(dependencies) {
284
+ const dependents = this.buildDependentsMap(dependencies);
285
+ const inDegree = new Map;
286
+ for (const nodeId of dependencies.keys()) {
287
+ inDegree.set(nodeId, dependencies.get(nodeId)?.length || 0);
288
+ }
289
+ const queue = [];
290
+ for (const [nodeId, degree] of inDegree.entries()) {
291
+ if (degree === 0) {
292
+ queue.push(nodeId);
293
+ }
294
+ }
295
+ const result = [];
296
+ while (queue.length > 0) {
297
+ const nodeId = queue.shift();
298
+ result.push(nodeId);
299
+ const nodeDependents = dependents.get(nodeId) || [];
300
+ for (const dependent of nodeDependents) {
301
+ const currentDegree = inDegree.get(dependent) || 0;
302
+ inDegree.set(dependent, currentDegree - 1);
303
+ if (currentDegree - 1 === 0) {
304
+ queue.push(dependent);
305
+ }
306
+ }
307
+ }
308
+ return result;
309
+ }
310
+ validate(options) {
311
+ const errors = [];
312
+ const nodeIds = new Set;
313
+ for (const node of this.workflow.nodes) {
314
+ if (node.id === "") {
315
+ errors.push("Node ID cannot be empty");
316
+ continue;
317
+ }
318
+ if (nodeIds.has(node.id)) {
319
+ errors.push(`Duplicate node ID: ${node.id}`);
320
+ }
321
+ nodeIds.add(node.id);
322
+ }
323
+ for (const node of this.workflow.nodes) {
324
+ const deps = node.depends_on || [];
325
+ for (const dep of deps) {
326
+ if (!nodeIds.has(dep)) {
327
+ errors.push(`Node '${node.id}' depends on non-existent node '${dep}'`);
328
+ }
329
+ }
330
+ }
331
+ if (!this.allowCycles && !options?.skipCycleCheck && this.isCyclic()) {
332
+ errors.push("Workflow contains a cycle");
333
+ }
334
+ return {
335
+ valid: errors.length === 0,
336
+ errors
337
+ };
338
+ }
339
+ addNode(node) {
340
+ if (!node.id || node.id.trim() === "") {
341
+ throw new Error("Node ID cannot be empty");
342
+ }
343
+ if (this.nodeMap.has(node.id)) {
344
+ throw new Error(`Node with ID '${node.id}' already exists`);
345
+ }
346
+ const deps = node.depends_on || [];
347
+ for (const dep of deps) {
348
+ if (!this.nodeMap.has(dep)) {
349
+ throw new Error(`Cannot add node '${node.id}': depends on non-existent node '${dep}'`);
350
+ }
351
+ }
352
+ const originalNodes = [...this.workflow.nodes];
353
+ this.workflow.nodes.push(node);
354
+ if (this.isCyclic()) {
355
+ this.workflow.nodes = originalNodes;
356
+ throw new Error(`Cannot add node '${node.id}': would create a cycle in the workflow`);
357
+ }
358
+ this.nodeMap.set(node.id, node);
359
+ this.cachedAnalysis = null;
360
+ this.extendedDefinition = null;
361
+ }
362
+ removeNode(nodeId) {
363
+ if (!this.nodeMap.has(nodeId)) {
364
+ throw new Error(`Node '${nodeId}' does not exist`);
365
+ }
366
+ const dependents = this.getDependents(nodeId);
367
+ if (dependents.length > 0) {
368
+ throw new Error(`Cannot remove node '${nodeId}': other nodes depend on it: ${dependents.join(", ")}`);
369
+ }
370
+ this.workflow.nodes = this.workflow.nodes.filter((n) => n.id !== nodeId);
371
+ this.nodeMap.delete(nodeId);
372
+ this.cachedAnalysis = null;
373
+ this.extendedDefinition = null;
374
+ }
375
+ getDependents(nodeId) {
376
+ const analysis = this.analyze();
377
+ return analysis.dependents.get(nodeId) || [];
378
+ }
379
+ getDownstreamUntil(fromNodeId, untilNodeId) {
380
+ const result = [];
381
+ const visited = new Set;
382
+ const queue = [...this.getDependents(fromNodeId)];
383
+ while (queue.length > 0) {
384
+ const nodeId = queue.shift();
385
+ if (visited.has(nodeId))
386
+ continue;
387
+ visited.add(nodeId);
388
+ result.push(nodeId);
389
+ if (nodeId === untilNodeId) {
390
+ continue;
391
+ }
392
+ for (const dependent of this.getDependents(nodeId)) {
393
+ if (!visited.has(dependent)) {
394
+ queue.push(dependent);
395
+ }
396
+ }
397
+ }
398
+ return result;
399
+ }
400
+ getDefinition() {
401
+ return this.workflow;
402
+ }
403
+ getNode(nodeId) {
404
+ return this.nodeMap.get(nodeId);
405
+ }
406
+ getNodeIds() {
407
+ return Array.from(this.nodeMap.keys());
408
+ }
409
+ getNodeCount() {
410
+ return this.nodeMap.size;
411
+ }
412
+ buildEdges(explicitEdges = []) {
413
+ const derivedEdges = [];
414
+ const explicitEdgeSet = new Set(explicitEdges.map((e) => `${e.from}->${e.to}`));
415
+ for (const node of this.workflow.nodes) {
416
+ const deps = node.depends_on || [];
417
+ for (const dep of deps) {
418
+ const edgeKey = `${dep}->${node.id}`;
419
+ if (!explicitEdgeSet.has(edgeKey)) {
420
+ derivedEdges.push({ from: dep, to: node.id });
421
+ }
422
+ }
423
+ }
424
+ return [...explicitEdges, ...derivedEdges];
425
+ }
426
+ };
427
+ __legacyDecorateClassTS([
428
+ TracedAs("workflow.dag-manager.areDependenciesMet", {
429
+ recordParams: true,
430
+ recordResult: true,
431
+ log: true
432
+ })
433
+ ], DAGManager.prototype, "areDependenciesMet", null);
434
+ });
435
+
436
+ export { DAGManager, init_dag_manager };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DAGManager,
3
3
  init_dag_manager
4
- } from "./roy-agent-core-4yq23m5g.js";
4
+ } from "./roy-agent-core-vcjq65nz.js";
5
5
 
6
6
  // src/env/workflow/utils/validate-workflow-definition.ts
7
7
  init_dag_manager();
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  ProcessRegistry,
3
3
  runWithProcessRegistryAsync
4
- } from "./roy-agent-core-pzeexnhf.js";
4
+ } from "./roy-agent-core-nv4yfy3m.js";
5
5
  import {
6
6
  builtInPrompts
7
- } from "./roy-agent-core-trdpar9f.js";
7
+ } from "./roy-agent-core-apz6v22z.js";
8
8
  import {
9
9
  runWithBgTaskIdAsync
10
10
  } from "./roy-agent-core-c1v263jn.js";
11
11
  import {
12
12
  DEFAULT_SUBAGENT_PROMPT
13
- } from "./roy-agent-core-wqe84f84.js";
13
+ } from "./roy-agent-core-v5nknfh0.js";
14
14
  import {
15
15
  TaskHookPoints
16
16
  } from "./roy-agent-core-1pg0fepg.js";
@@ -808,6 +808,77 @@ Use these as guidance to improve task execution efficiency.`;
808
808
  listTasks() {
809
809
  return Array.from(this.tasks.values());
810
810
  }
811
+ hasActiveTaskForParent(parentSessionId) {
812
+ if (!parentSessionId)
813
+ return false;
814
+ for (const task of this.tasks.values()) {
815
+ if (task.parentSessionId === parentSessionId && (task.status === "pending" || task.status === "running")) {
816
+ return true;
817
+ }
818
+ }
819
+ return false;
820
+ }
821
+ async stopAllForParent(parentSessionId) {
822
+ if (!parentSessionId) {
823
+ return { stoppedTaskIds: [] };
824
+ }
825
+ const stoppedTaskIds = [];
826
+ for (const [taskId, task] of this.tasks) {
827
+ if (task.parentSessionId === parentSessionId && (task.status === "running" || task.status === "pending")) {
828
+ try {
829
+ const res = await this.stopTask(taskId);
830
+ if (res?.success) {
831
+ stoppedTaskIds.push(taskId);
832
+ }
833
+ } catch (err) {
834
+ logger.warn(`[BackgroundTaskManager] stopAllForParent failed for ${taskId}: ${err instanceof Error ? err.message : String(err)}`);
835
+ }
836
+ }
837
+ }
838
+ return { stoppedTaskIds };
839
+ }
840
+ async forceStopAllAcrossParents() {
841
+ for (const [taskId, task] of this.tasks) {
842
+ try {
843
+ await this.processRegistries.get(taskId)?.killAll();
844
+ } catch (err) {
845
+ logger.warn(`[BackgroundTaskManager] forceStopAllAcrossParents killAll failed for ${taskId}: ${err instanceof Error ? err.message : String(err)}`);
846
+ }
847
+ try {
848
+ await this.propagateStopToWorkflowRuns(taskId, "force stop all");
849
+ } catch (err) {
850
+ logger.warn(`[BackgroundTaskManager] forceStopAllAcrossParents propagateStopToWorkflowRuns failed for ${taskId}: ${err instanceof Error ? err.message : String(err)}`);
851
+ }
852
+ let justMarkedStopped = false;
853
+ if (task.status === "running" || task.status === "pending") {
854
+ try {
855
+ task.status = "stopped";
856
+ task.completedAt = Date.now();
857
+ task.lastUpdatedAt = task.completedAt;
858
+ task.abortController?.abort();
859
+ justMarkedStopped = true;
860
+ } catch (err) {
861
+ logger.warn(`[BackgroundTaskManager] forceStopAllAcrossParents mark stopped failed for ${taskId}: ${err instanceof Error ? err.message : String(err)}`);
862
+ }
863
+ }
864
+ if (justMarkedStopped) {
865
+ const stoppedPayload = {
866
+ backgroundTaskId: task.id,
867
+ subSessionId: task.subSessionId,
868
+ parentSessionId: task.parentSessionId,
869
+ status: "stopped",
870
+ description: task.description,
871
+ error: "force stop all",
872
+ executionTimeMs: task.startedAt && task.completedAt ? task.completedAt - task.startedAt : 0,
873
+ associatedTaskId: task.associatedTaskId
874
+ };
875
+ this.publishBackgroundEvent(BackgroundTaskEventTypes.STOPPED, stoppedPayload, task.parentSessionId);
876
+ }
877
+ }
878
+ }
879
+ async forceStopAll() {
880
+ return this.forceStopAllAcrossParents();
881
+ }
811
882
  async dispose() {
812
883
  for (const [taskId, controller] of this.abortControllers) {
813
884
  controller.abort();
@@ -878,6 +949,20 @@ __legacyDecorateClassTS([
878
949
  __legacyDecorateClassTS([
879
950
  TracedAs("delegate.executeWithAbort", { recordParams: true, recordResult: true, log: true })
880
951
  ], BackgroundTaskManager.prototype, "executeWithAbort", null);
952
+ __legacyDecorateClassTS([
953
+ TracedAs("task.background.stopAllForParent", {
954
+ recordParams: true,
955
+ recordResult: true,
956
+ log: true
957
+ })
958
+ ], BackgroundTaskManager.prototype, "stopAllForParent", null);
959
+ __legacyDecorateClassTS([
960
+ TracedAs("task.background.forceStopAllAcrossParents", {
961
+ recordParams: false,
962
+ recordResult: true,
963
+ log: true
964
+ })
965
+ ], BackgroundTaskManager.prototype, "forceStopAllAcrossParents", null);
881
966
  function getAgentRegistry(taskComponent) {
882
967
  const agentComponent = taskComponent.env?.getComponent?.("agent");
883
968
  return agentComponent?.getRegistry?.();
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  getCurrentProcessRegistry,
9
9
  killProcessTree
10
- } from "./roy-agent-core-pzeexnhf.js";
10
+ } from "./roy-agent-core-nv4yfy3m.js";
11
11
  import {
12
12
  init_decorator,
13
13
  wrapFunction