@ai-setting/roy-agent-core 1.6.22 → 1.6.23

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.
@@ -2,7 +2,7 @@ import {
2
2
  AgentComponent,
3
3
  AgentComponentConfigSchema,
4
4
  SummaryAgent
5
- } from "../../shared/@ai-setting/roy-agent-core-mz69jdvv.js";
5
+ } from "../../shared/@ai-setting/roy-agent-core-3c1b7xh5.js";
6
6
  import"../../shared/@ai-setting/roy-agent-core-c1stgqnw.js";
7
7
  import"../../shared/@ai-setting/roy-agent-core-h28gcd77.js";
8
8
  import"../../shared/@ai-setting/roy-agent-core-br7dmedr.js";
@@ -10,6 +10,7 @@ import"../../shared/@ai-setting/roy-agent-core-t3yqzgse.js";
10
10
  import"../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
11
11
  import"../../shared/@ai-setting/roy-agent-core-x0yztmm6.js";
12
12
  import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
13
+ import"../../shared/@ai-setting/roy-agent-core-c1v263jn.js";
13
14
  import"../../shared/@ai-setting/roy-agent-core-ctdhjv68.js";
14
15
  import"../../shared/@ai-setting/roy-agent-core-1k9j90s7.js";
15
16
  import"../../shared/@ai-setting/roy-agent-core-12gac5zn.js";
package/dist/env/index.js CHANGED
@@ -41,7 +41,7 @@ import"../shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
41
41
  import {
42
42
  AgentComponent,
43
43
  AgentComponentConfigSchema
44
- } from "../shared/@ai-setting/roy-agent-core-mz69jdvv.js";
44
+ } from "../shared/@ai-setting/roy-agent-core-3c1b7xh5.js";
45
45
  import"../shared/@ai-setting/roy-agent-core-c1stgqnw.js";
46
46
  import"../shared/@ai-setting/roy-agent-core-h28gcd77.js";
47
47
  import"../shared/@ai-setting/roy-agent-core-br7dmedr.js";
@@ -49,20 +49,20 @@ import"../shared/@ai-setting/roy-agent-core-t3yqzgse.js";
49
49
  import"../shared/@ai-setting/roy-agent-core-e25xkv53.js";
50
50
  import {
51
51
  TaskComponent
52
- } from "../shared/@ai-setting/roy-agent-core-h4sm7fyb.js";
52
+ } from "../shared/@ai-setting/roy-agent-core-8s7qyr5y.js";
53
53
  import"../shared/@ai-setting/roy-agent-core-amkqnyzy.js";
54
54
  import"../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
55
- import"../shared/@ai-setting/roy-agent-core-067w3nt1.js";
55
+ import"../shared/@ai-setting/roy-agent-core-50jdqb7r.js";
56
56
  import"../shared/@ai-setting/roy-agent-core-mvs5sen6.js";
57
57
  import"../shared/@ai-setting/roy-agent-core-3ep1dxf1.js";
58
58
  import"../shared/@ai-setting/roy-agent-core-skqt40yy.js";
59
- import"../shared/@ai-setting/roy-agent-core-c1v263jn.js";
60
59
  import"../shared/@ai-setting/roy-agent-core-x0yztmm6.js";
61
60
  import {
62
61
  XDG_PATHS,
63
62
  getXDGPath,
64
63
  getXDGPaths
65
64
  } from "../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
65
+ import"../shared/@ai-setting/roy-agent-core-c1v263jn.js";
66
66
  import"../shared/@ai-setting/roy-agent-core-hks28tys.js";
67
67
  import"../shared/@ai-setting/roy-agent-core-rn57psp0.js";
68
68
  import"../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
@@ -3,12 +3,12 @@ import {
3
3
  BackgroundTaskManager,
4
4
  createDelegateTool,
5
5
  createStopTool
6
- } from "../../../shared/@ai-setting/roy-agent-core-067w3nt1.js";
6
+ } from "../../../shared/@ai-setting/roy-agent-core-50jdqb7r.js";
7
7
  import"../../../shared/@ai-setting/roy-agent-core-mvs5sen6.js";
8
8
  import"../../../shared/@ai-setting/roy-agent-core-skqt40yy.js";
9
- import"../../../shared/@ai-setting/roy-agent-core-c1v263jn.js";
10
9
  import"../../../shared/@ai-setting/roy-agent-core-x0yztmm6.js";
11
10
  import"../../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
11
+ import"../../../shared/@ai-setting/roy-agent-core-c1v263jn.js";
12
12
  import"../../../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
13
13
  import"../../../shared/@ai-setting/roy-agent-core-j29yg06n.js";
14
14
  import"../../../shared/@ai-setting/roy-agent-core-h7ak839w.js";
@@ -5,21 +5,21 @@ import {
5
5
  TaskPriorityEnum,
6
6
  TaskStatusEnum,
7
7
  TaskTypeEnum
8
- } from "../../shared/@ai-setting/roy-agent-core-h4sm7fyb.js";
8
+ } from "../../shared/@ai-setting/roy-agent-core-8s7qyr5y.js";
9
9
  import"../../shared/@ai-setting/roy-agent-core-amkqnyzy.js";
10
10
  import {
11
11
  TaskEntityEventTypes
12
12
  } from "../../shared/@ai-setting/roy-agent-core-8gxth0eh.js";
13
- import"../../shared/@ai-setting/roy-agent-core-067w3nt1.js";
13
+ import"../../shared/@ai-setting/roy-agent-core-50jdqb7r.js";
14
14
  import"../../shared/@ai-setting/roy-agent-core-mvs5sen6.js";
15
15
  import {
16
16
  SQLiteTaskStore,
17
17
  getDefaultTaskDbPath
18
18
  } from "../../shared/@ai-setting/roy-agent-core-3ep1dxf1.js";
19
19
  import"../../shared/@ai-setting/roy-agent-core-skqt40yy.js";
20
- import"../../shared/@ai-setting/roy-agent-core-c1v263jn.js";
21
20
  import"../../shared/@ai-setting/roy-agent-core-x0yztmm6.js";
22
21
  import"../../shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
22
+ import"../../shared/@ai-setting/roy-agent-core-c1v263jn.js";
23
23
  import"../../shared/@ai-setting/roy-agent-core-hks28tys.js";
24
24
  import"../../shared/@ai-setting/roy-agent-core-rn57psp0.js";
25
25
  import"../../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
package/dist/index.js CHANGED
@@ -131,7 +131,7 @@ import"./shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
131
131
  import {
132
132
  AgentComponent,
133
133
  AgentComponentConfigSchema
134
- } from "./shared/@ai-setting/roy-agent-core-mz69jdvv.js";
134
+ } from "./shared/@ai-setting/roy-agent-core-3c1b7xh5.js";
135
135
  import {
136
136
  createInvokeConfig,
137
137
  invoke,
@@ -151,10 +151,10 @@ import {
151
151
  } from "./shared/@ai-setting/roy-agent-core-e25xkv53.js";
152
152
  import {
153
153
  TaskComponent
154
- } from "./shared/@ai-setting/roy-agent-core-h4sm7fyb.js";
154
+ } from "./shared/@ai-setting/roy-agent-core-8s7qyr5y.js";
155
155
  import"./shared/@ai-setting/roy-agent-core-amkqnyzy.js";
156
156
  import"./shared/@ai-setting/roy-agent-core-8gxth0eh.js";
157
- import"./shared/@ai-setting/roy-agent-core-067w3nt1.js";
157
+ import"./shared/@ai-setting/roy-agent-core-50jdqb7r.js";
158
158
  import"./shared/@ai-setting/roy-agent-core-mvs5sen6.js";
159
159
  import {
160
160
  SQLiteTaskStore,
@@ -164,7 +164,6 @@ import {
164
164
  getBuiltInPrompt,
165
165
  getBuiltInPromptNames
166
166
  } from "./shared/@ai-setting/roy-agent-core-skqt40yy.js";
167
- import"./shared/@ai-setting/roy-agent-core-c1v263jn.js";
168
167
  import {
169
168
  AgentRegistry
170
169
  } from "./shared/@ai-setting/roy-agent-core-x0yztmm6.js";
@@ -173,6 +172,7 @@ import {
173
172
  getXDGPath,
174
173
  getXDGPaths
175
174
  } from "./shared/@ai-setting/roy-agent-core-qxnbvgwe.js";
175
+ import"./shared/@ai-setting/roy-agent-core-c1v263jn.js";
176
176
  import"./shared/@ai-setting/roy-agent-core-hks28tys.js";
177
177
  import"./shared/@ai-setting/roy-agent-core-rn57psp0.js";
178
178
  import {
@@ -14,6 +14,9 @@ import {
14
14
  import {
15
15
  AgentRegistry
16
16
  } from "./roy-agent-core-x0yztmm6.js";
17
+ import {
18
+ getCurrentBgTaskId
19
+ } from "./roy-agent-core-c1v263jn.js";
17
20
  import {
18
21
  ContextError
19
22
  } from "./roy-agent-core-ctdhjv68.js";
@@ -780,7 +783,16 @@ class AgentComponent extends BaseComponent {
780
783
  if (!agent) {
781
784
  throw new Error(`Agent not found: ${agentName}`);
782
785
  }
783
- const runId = `${agentName}:${++this.runCounter}`;
786
+ if (context?.runId !== undefined && context.runId.trim() === "") {
787
+ throw new Error(`AgentComponent._run: caller-provided runId must not be empty`);
788
+ }
789
+ const internalRunId = `${agentName}:${++this.runCounter}`;
790
+ const runId = context?.runId ?? internalRunId;
791
+ if (context?.runId) {
792
+ if (this.aborted.has(runId) || this.abortControllers.has(runId)) {
793
+ throw new Error(`AgentComponent._run: caller-provided runId '${runId}' is already in use`);
794
+ }
795
+ }
784
796
  const querySummary = typeof query === "string" ? query.substring(0, 100) : query.filter((p) => p.type === "text").map((p) => p.text).join(" ").substring(0, 100) || "[multimodal query]";
785
797
  logger2.info(`Starting agent run: ${agentName} (runId=${runId})`, { query: querySummary });
786
798
  agent.status = "running";
@@ -1276,6 +1288,36 @@ class AgentComponent extends BaseComponent {
1276
1288
  }
1277
1289
  logger2.info(`Agent aborted: ${agentName}`);
1278
1290
  }
1291
+ abortRun(runId, reason) {
1292
+ if (!runId) {
1293
+ return false;
1294
+ }
1295
+ const foundInAborted = this.aborted.has(runId);
1296
+ const foundInControllers = this.abortControllers.has(runId);
1297
+ if (!foundInAborted && !foundInControllers) {
1298
+ logger2.debug(`[abort] abortRun: runId not found (already finalized?)`, {
1299
+ runId,
1300
+ reason
1301
+ });
1302
+ return false;
1303
+ }
1304
+ if (foundInAborted) {
1305
+ this.aborted.set(runId, true);
1306
+ }
1307
+ const controller = this.abortControllers.get(runId);
1308
+ if (controller && !controller.signal.aborted) {
1309
+ try {
1310
+ controller.abort();
1311
+ } catch {}
1312
+ }
1313
+ logger2.info(`[abort] run-scoped abort`, {
1314
+ runId,
1315
+ reason,
1316
+ currentBgTaskId: getCurrentBgTaskId(),
1317
+ currentTaskId: getCurrentTaskId()
1318
+ });
1319
+ return true;
1320
+ }
1279
1321
  abortAll() {
1280
1322
  for (const key of this.aborted.keys()) {
1281
1323
  this.aborted.set(key, true);
@@ -5,12 +5,12 @@ import {
5
5
  import {
6
6
  builtInPrompts
7
7
  } from "./roy-agent-core-skqt40yy.js";
8
- import {
9
- runWithBgTaskIdAsync
10
- } from "./roy-agent-core-c1v263jn.js";
11
8
  import {
12
9
  DEFAULT_SUBAGENT_PROMPT
13
10
  } from "./roy-agent-core-x0yztmm6.js";
11
+ import {
12
+ runWithBgTaskIdAsync
13
+ } from "./roy-agent-core-c1v263jn.js";
14
14
  import {
15
15
  TaskHookPoints
16
16
  } from "./roy-agent-core-1pg0fepg.js";
@@ -984,10 +984,12 @@ class BackgroundTaskManager {
984
984
  this.terminalTasks.set(taskId, task);
985
985
  }
986
986
  const abortCtl = this.abortControllers.get(taskId);
987
- if (abortCtl) {
988
- try {
989
- abortCtl.abort();
990
- } catch {}
987
+ if (abortCtl && reason !== "completed") {
988
+ if (!abortCtl.signal.aborted) {
989
+ try {
990
+ abortCtl.abort();
991
+ } catch {}
992
+ }
991
993
  }
992
994
  this.abortControllers.delete(taskId);
993
995
  this.workflowRunRegistries.delete(taskId);
@@ -1132,8 +1134,10 @@ class BackgroundTaskManager {
1132
1134
  const processRegistry = new ProcessRegistry;
1133
1135
  this.processRegistries.set(taskIdGen, processRegistry);
1134
1136
  const createdAt = Date.now();
1137
+ const taskRunId = `${subagentType}:bg_${taskIdGen}`;
1135
1138
  const task = {
1136
1139
  id: taskIdGen,
1140
+ runId: taskRunId,
1137
1141
  subSessionId: subSession.id,
1138
1142
  parentSessionId,
1139
1143
  description,
@@ -1182,7 +1186,7 @@ class BackgroundTaskManager {
1182
1186
  throw new Error(`Sub session not found: ${task.subSessionId}`);
1183
1187
  }
1184
1188
  const taskRegistry = this.processRegistries.get(taskId);
1185
- const result = await this.executeWithAbort(subSession, prompt, timeoutMs, taskId, abortController?.signal, task.similarTaskIds, taskRegistry);
1189
+ const result = await this.executeWithAbort(subSession, prompt, timeoutMs, taskId, abortController?.signal, task.similarTaskIds, taskRegistry, () => abortController?.abort());
1186
1190
  if (abortController?.signal.aborted) {
1187
1191
  logger3.info(`[BackgroundTaskManager] Task was aborted`, { taskId });
1188
1192
  return;
@@ -1311,7 +1315,7 @@ class BackgroundTaskManager {
1311
1315
  this.progressTimers.delete(taskId);
1312
1316
  }
1313
1317
  }
1314
- async executeWithAbort(subSession, prompt, timeoutMs, bgTaskId, signal, similarTaskIds, processRegistry) {
1318
+ async executeWithAbort(subSession, prompt, timeoutMs, bgTaskId, signal, similarTaskIds, processRegistry, abortTask) {
1315
1319
  const metadata = subSession.info?.metadata || {};
1316
1320
  const taskId = metadata.task_id;
1317
1321
  const taskDescription = metadata.task_description || "";
@@ -1453,37 +1457,84 @@ ${reuseSection.markdown}`;
1453
1457
  });
1454
1458
  }
1455
1459
  };
1456
- const timer = setTimeout(async () => {
1457
- await killProcessTreeSafely();
1458
- reject(new Error(`Task execution timeout after ${timeoutMs}ms`));
1460
+ let settled = false;
1461
+ let timer;
1462
+ let capturedRunId;
1463
+ const task = this.tasks.get(bgTaskId);
1464
+ if (task?.runId) {
1465
+ capturedRunId = task.runId;
1466
+ }
1467
+ const detachAbortListener = () => {
1468
+ if (signal && onAbort) {
1469
+ try {
1470
+ signal.removeEventListener("abort", onAbort);
1471
+ } catch {}
1472
+ }
1473
+ };
1474
+ let onAbort;
1475
+ onAbort = () => {
1476
+ if (settled)
1477
+ return;
1478
+ settled = true;
1479
+ if (timer)
1480
+ clearTimeout(timer);
1481
+ detachAbortListener();
1459
1482
  try {
1460
- agentComponent?.abort?.(subagentType);
1483
+ const agentComp = this.env?.getComponent?.("agent");
1484
+ if (agentComp?.abortRun && capturedRunId) {
1485
+ agentComp.abortRun(capturedRunId, "task_signal_abort");
1486
+ }
1487
+ } catch {}
1488
+ killProcessTreeSafely().catch(() => {}).then(() => {
1489
+ reject(new Error("Task execution stopped"));
1490
+ });
1491
+ };
1492
+ timer = setTimeout(() => {
1493
+ if (settled)
1494
+ return;
1495
+ settled = true;
1496
+ if (timer)
1497
+ clearTimeout(timer);
1498
+ detachAbortListener();
1499
+ try {
1500
+ abortTask?.();
1461
1501
  } catch {}
1462
- }, timeoutMs);
1463
- signal?.addEventListener("abort", async () => {
1464
- clearTimeout(timer);
1465
1502
  try {
1466
- const env = this.env;
1467
- const agentComp = env?.getComponent?.("agent");
1468
- if (agentComp?.abort) {
1469
- agentComp.abort(subagentType);
1503
+ const agentComp = this.env?.getComponent?.("agent");
1504
+ if (agentComp?.abortRun && capturedRunId) {
1505
+ agentComp.abortRun(capturedRunId, "task_timeout");
1470
1506
  }
1471
1507
  } catch {}
1472
- await killProcessTreeSafely();
1473
- reject(new Error("Task execution stopped"));
1474
- });
1508
+ killProcessTreeSafely().catch(() => {}).then(() => {
1509
+ reject(new Error(`Task execution timeout after ${timeoutMs}ms`));
1510
+ });
1511
+ }, timeoutMs);
1512
+ if (signal) {
1513
+ signal.addEventListener("abort", onAbort);
1514
+ }
1475
1515
  const invokeHandleQuery = () => this.env.handle_query?.(delegateQuery, {
1476
1516
  sessionId,
1477
1517
  deniedTools: deniedTools.length > 0 ? deniedTools : undefined,
1478
1518
  agentType: subagentType,
1479
- abort: signal
1519
+ abort: signal,
1520
+ runId: capturedRunId
1480
1521
  });
1481
1522
  const wrappedPromise = processRegistry ? runWithProcessRegistryAsync(processRegistry, () => runWithBgTaskIdAsync(bgTaskId, () => invokeHandleQuery())) : runWithBgTaskIdAsync(bgTaskId, () => invokeHandleQuery());
1482
1523
  wrappedPromise?.then((result) => {
1483
- clearTimeout(timer);
1524
+ if (settled)
1525
+ return;
1526
+ settled = true;
1527
+ if (timer)
1528
+ clearTimeout(timer);
1529
+ detachAbortListener();
1484
1530
  resolve(result);
1485
1531
  }).catch((error) => {
1486
- clearTimeout(timer);
1532
+ if (settled)
1533
+ return;
1534
+ settled = true;
1535
+ if (timer)
1536
+ clearTimeout(timer);
1537
+ detachAbortListener();
1487
1538
  reject(error);
1488
1539
  });
1489
1540
  });
@@ -1510,6 +1561,18 @@ ${reuseSection.markdown}`;
1510
1561
  const completedAt = Date.now();
1511
1562
  task.status = "stopped";
1512
1563
  task.abortController?.abort();
1564
+ if (task.runId) {
1565
+ try {
1566
+ const agentComp = this.env?.getComponent?.("agent");
1567
+ agentComp?.abortRun?.(task.runId, "stop_task");
1568
+ } catch (err) {
1569
+ logger3.warn(`[BackgroundTaskManager] abortRun failed during stopTask`, {
1570
+ taskId,
1571
+ runId: task.runId,
1572
+ error: err instanceof Error ? err.message : String(err)
1573
+ });
1574
+ }
1575
+ }
1513
1576
  task.completedAt = completedAt;
1514
1577
  task.lastUpdatedAt = completedAt;
1515
1578
  try {
@@ -8,7 +8,7 @@ import {
8
8
  BackgroundTaskManager,
9
9
  createDelegateTool,
10
10
  createStopTool
11
- } from "./roy-agent-core-067w3nt1.js";
11
+ } from "./roy-agent-core-50jdqb7r.js";
12
12
  import {
13
13
  SQLiteTaskStore,
14
14
  getDefaultTaskDbPath
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.6.22",
3
+ "version": "1.6.23",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",