@ai-setting/roy-agent-core 1.7.38 → 1.7.39
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.
- package/dist/config/index.js +6 -6
- package/dist/env/agent/index.js +7 -7
- package/dist/env/commands/index.js +6 -6
- package/dist/env/context/index.js +6 -2
- package/dist/env/debug/index.js +6 -6
- package/dist/env/event-source/index.js +8 -8
- package/dist/env/hook/index.js +4 -4
- package/dist/env/index.js +22 -22
- package/dist/env/llm/index.js +6 -6
- package/dist/env/log-trace/index.js +6 -6
- package/dist/env/mcp/index.js +6 -6
- package/dist/env/memory/index.js +6 -6
- package/dist/env/plugin/index.js +6 -6
- package/dist/env/prompt/index.js +6 -6
- package/dist/env/session/index.js +6 -6
- package/dist/env/skill/index.js +6 -6
- package/dist/env/task/delegate/index.js +4 -4
- package/dist/env/task/index.js +9 -9
- package/dist/env/task/plugins/index.js +3 -3
- package/dist/env/task/storage/index.js +1 -1
- package/dist/env/task/tools/index.js +2 -2
- package/dist/env/tool/index.js +6 -6
- package/dist/env/workflow/engine/index.js +5 -5
- package/dist/env/workflow/index.js +10 -10
- package/dist/env/workflow/tools/index.js +7 -7
- package/dist/index.js +29 -29
- package/dist/shared/@ai-setting/{roy-agent-core-83j0v0hs.js → roy-agent-core-34je386q.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-p0c98phj.js → roy-agent-core-3h7ajma5.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-e5pnnzdm.js → roy-agent-core-47wrv4ex.js} +89 -27
- package/dist/shared/@ai-setting/{roy-agent-core-mzyzdf33.js → roy-agent-core-4cqcdk7k.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-vh10qamt.js → roy-agent-core-5exnp10h.js} +8 -5
- package/dist/shared/@ai-setting/{roy-agent-core-nz4n1w28.js → roy-agent-core-6mnwqcqf.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-vn6f4nxv.js → roy-agent-core-6vwf03cz.js} +9 -6
- package/dist/shared/@ai-setting/{roy-agent-core-970btnjh.js → roy-agent-core-754b0078.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-yv4anf1c.js → roy-agent-core-9t675te0.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-yjyvwxs4.js → roy-agent-core-a236mps6.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-gh6szaj5.js → roy-agent-core-asxe1nt4.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-gpf33hn9.js → roy-agent-core-cazvr63z.js} +60 -38
- package/dist/shared/@ai-setting/{roy-agent-core-y7atw1kw.js → roy-agent-core-cw89yj9d.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-9wsy4yfv.js → roy-agent-core-cysnmvcy.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-5gpf5j51.js → roy-agent-core-f18jk3cw.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-wb1b61f8.js → roy-agent-core-jadrj0bz.js} +7 -0
- package/dist/shared/@ai-setting/{roy-agent-core-p2ham63a.js → roy-agent-core-jawzpf5k.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-e02f0ywc.js → roy-agent-core-jg8cv1f7.js} +85 -31
- package/dist/shared/@ai-setting/{roy-agent-core-wfpzny0h.js → roy-agent-core-jjw7xcxv.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-dfnyvxr9.js → roy-agent-core-krppch0s.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-cd9h49ng.js → roy-agent-core-m3ffkexb.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-rhfywyz1.js → roy-agent-core-n1ceexfz.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-e8rxb9a6.js → roy-agent-core-pc8x07p0.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-wacnvjaq.js → roy-agent-core-qfktfbrr.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-q3vbxprp.js → roy-agent-core-rczz7e81.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-ym1hwrcm.js → roy-agent-core-s44egzrh.js} +34 -3
- package/dist/shared/@ai-setting/{roy-agent-core-hfmpmt0k.js → roy-agent-core-vsrfzaze.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-ff2ssff5.js → roy-agent-core-wn59p0zw.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-3m7j2wcb.js → roy-agent-core-wybj8emq.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-z4486eek.js → roy-agent-core-zbb3sk72.js} +16 -2
- package/package.json +1 -1
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
searchTasksTool,
|
|
10
10
|
treeTasksTool,
|
|
11
11
|
updateTaskTool
|
|
12
|
-
} from "./roy-agent-core-
|
|
12
|
+
} from "./roy-agent-core-vsrfzaze.js";
|
|
13
13
|
import {
|
|
14
14
|
createOperationTool,
|
|
15
15
|
deleteOperationTool,
|
|
@@ -27,11 +27,11 @@ import {
|
|
|
27
27
|
BackgroundTaskManager,
|
|
28
28
|
createDelegateTool,
|
|
29
29
|
createStopTool
|
|
30
|
-
} from "./roy-agent-core-
|
|
30
|
+
} from "./roy-agent-core-jg8cv1f7.js";
|
|
31
31
|
import {
|
|
32
32
|
SQLiteTaskStore,
|
|
33
33
|
getDefaultTaskDbPath
|
|
34
|
-
} from "./roy-agent-core-
|
|
34
|
+
} from "./roy-agent-core-jadrj0bz.js";
|
|
35
35
|
import {
|
|
36
36
|
TaskHookPoints
|
|
37
37
|
} from "./roy-agent-core-1pg0fepg.js";
|
|
@@ -40,15 +40,15 @@ import {
|
|
|
40
40
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
41
41
|
import {
|
|
42
42
|
BaseComponent
|
|
43
|
-
} from "./roy-agent-core-
|
|
43
|
+
} from "./roy-agent-core-9t675te0.js";
|
|
44
44
|
import {
|
|
45
45
|
globalHookManager,
|
|
46
46
|
init_global_hook_manager
|
|
47
|
-
} from "./roy-agent-core-
|
|
47
|
+
} from "./roy-agent-core-a236mps6.js";
|
|
48
48
|
import {
|
|
49
49
|
getEnvContextOrEmpty,
|
|
50
50
|
init_env_context
|
|
51
|
-
} from "./roy-agent-core-
|
|
51
|
+
} from "./roy-agent-core-zbb3sk72.js";
|
|
52
52
|
import {
|
|
53
53
|
TracedAs,
|
|
54
54
|
init_decorator
|
|
@@ -432,6 +432,9 @@ class TaskComponent extends BaseComponent {
|
|
|
432
432
|
async getTask(id) {
|
|
433
433
|
return this.store.getTask(id);
|
|
434
434
|
}
|
|
435
|
+
async getTaskIdBySessionId(sessionId) {
|
|
436
|
+
return this.store.getTaskIdBySessionId(sessionId);
|
|
437
|
+
}
|
|
435
438
|
async getTaskWithOperations(id) {
|
|
436
439
|
const task = await this.store.getTask(id);
|
|
437
440
|
if (!task)
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createAutoTaskPlugin
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-47wrv4ex.js";
|
|
4
4
|
import {
|
|
5
5
|
ContextError,
|
|
6
6
|
ErrorCodes
|
|
7
7
|
} from "./roy-agent-core-ctdhjv68.js";
|
|
8
8
|
import {
|
|
9
9
|
BaseComponent
|
|
10
|
-
} from "./roy-agent-core-
|
|
10
|
+
} from "./roy-agent-core-9t675te0.js";
|
|
11
11
|
import {
|
|
12
12
|
init_context
|
|
13
|
-
} from "./roy-agent-core-
|
|
13
|
+
} from "./roy-agent-core-wn59p0zw.js";
|
|
14
14
|
import {
|
|
15
15
|
getEnvContext,
|
|
16
16
|
init_env_context,
|
|
17
17
|
runWithEnvContextAsync
|
|
18
|
-
} from "./roy-agent-core-
|
|
18
|
+
} from "./roy-agent-core-zbb3sk72.js";
|
|
19
19
|
import {
|
|
20
20
|
TracedAs,
|
|
21
21
|
init_decorator
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createHook
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-cw89yj9d.js";
|
|
4
4
|
import {
|
|
5
5
|
HookManager
|
|
6
|
-
} from "./roy-agent-core-
|
|
6
|
+
} from "./roy-agent-core-a236mps6.js";
|
|
7
7
|
|
|
8
8
|
// src/env/component.ts
|
|
9
9
|
class BaseComponent {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
init_context
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-wn59p0zw.js";
|
|
4
4
|
import {
|
|
5
5
|
getEnvContext
|
|
6
|
-
} from "./roy-agent-core-
|
|
6
|
+
} from "./roy-agent-core-zbb3sk72.js";
|
|
7
7
|
import {
|
|
8
8
|
__esm
|
|
9
9
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentComponentAdapter,
|
|
3
3
|
init_agent_component_adapter
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-3h7ajma5.js";
|
|
5
5
|
import"./roy-agent-core-1db4vpc6.js";
|
|
6
6
|
import"./roy-agent-core-e25xkv53.js";
|
|
7
|
-
import"./roy-agent-core-
|
|
8
|
-
import"./roy-agent-core-
|
|
9
|
-
import"./roy-agent-core-
|
|
7
|
+
import"./roy-agent-core-a236mps6.js";
|
|
8
|
+
import"./roy-agent-core-wn59p0zw.js";
|
|
9
|
+
import"./roy-agent-core-zbb3sk72.js";
|
|
10
10
|
import"./roy-agent-core-a9pbda78.js";
|
|
11
11
|
import"./roy-agent-core-8seq65bp.js";
|
|
12
12
|
import"./roy-agent-core-jnszp0jq.js";
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
TaskTagPlugin,
|
|
9
9
|
createLarkCliTaskNotifyHook,
|
|
10
10
|
createPerTaskGroupChatPlugin
|
|
11
|
-
} from "./roy-agent-core-
|
|
11
|
+
} from "./roy-agent-core-47wrv4ex.js";
|
|
12
12
|
import {
|
|
13
13
|
normalizeLarkAtMentions
|
|
14
14
|
} from "./roy-agent-core-rmn29nrh.js";
|
|
@@ -17,18 +17,19 @@ import {
|
|
|
17
17
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
18
18
|
import {
|
|
19
19
|
BaseComponent
|
|
20
|
-
} from "./roy-agent-core-
|
|
20
|
+
} from "./roy-agent-core-9t675te0.js";
|
|
21
21
|
import {
|
|
22
22
|
globalHookManager,
|
|
23
23
|
init_global_hook_manager
|
|
24
|
-
} from "./roy-agent-core-
|
|
24
|
+
} from "./roy-agent-core-a236mps6.js";
|
|
25
25
|
import {
|
|
26
26
|
init_context
|
|
27
|
-
} from "./roy-agent-core-
|
|
27
|
+
} from "./roy-agent-core-wn59p0zw.js";
|
|
28
28
|
import {
|
|
29
29
|
createEnvContext,
|
|
30
|
+
normalizeParentTaskId,
|
|
30
31
|
runWithEnvContext
|
|
31
|
-
} from "./roy-agent-core-
|
|
32
|
+
} from "./roy-agent-core-zbb3sk72.js";
|
|
32
33
|
import {
|
|
33
34
|
TracedAs,
|
|
34
35
|
init_decorator,
|
|
@@ -1158,6 +1159,7 @@ class LarkCliInstance {
|
|
|
1158
1159
|
registerPluginHooks(plugin) {
|
|
1159
1160
|
const pluginName = plugin.name || "unknown";
|
|
1160
1161
|
this.injectTaskUpdater(plugin);
|
|
1162
|
+
this.injectTaskGetter(plugin);
|
|
1161
1163
|
this.injectSessionComponent(plugin);
|
|
1162
1164
|
if (typeof plugin.init === "function") {
|
|
1163
1165
|
const pluginEnv = {
|
|
@@ -1244,6 +1246,25 @@ class LarkCliInstance {
|
|
|
1244
1246
|
};
|
|
1245
1247
|
plugin.setTaskUpdater(taskUpdater);
|
|
1246
1248
|
}
|
|
1249
|
+
injectTaskGetter(plugin) {
|
|
1250
|
+
if (typeof plugin.setTaskGetter !== "function") {
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
if (typeof plugin.hasTaskGetter === "function" && plugin.hasTaskGetter()) {
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1256
|
+
if (!this.environment?.getComponent) {
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
const taskComponent = this.environment.getComponent("task");
|
|
1260
|
+
if (!taskComponent?.getTask) {
|
|
1261
|
+
if (isPluginDebugEnabled()) {
|
|
1262
|
+
console.debug(`[LarkCliInstance] ${plugin.name || "plugin"} has setTaskGetter but ` + `taskComponent or getTask method not found. ` + `sub-task 上溯祖先群将不可用。`);
|
|
1263
|
+
}
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1266
|
+
plugin.setTaskGetter((id) => taskComponent.getTask(id));
|
|
1267
|
+
}
|
|
1247
1268
|
injectSessionComponent(plugin) {
|
|
1248
1269
|
if (typeof plugin.setSessionComponent !== "function") {
|
|
1249
1270
|
return;
|
|
@@ -1460,7 +1481,8 @@ class LarkCliInstance {
|
|
|
1460
1481
|
} : undefined,
|
|
1461
1482
|
replyChannel: envReplyChannel,
|
|
1462
1483
|
pluginEnabled,
|
|
1463
|
-
plugins
|
|
1484
|
+
plugins,
|
|
1485
|
+
parentTaskId: normalizeParentTaskId(parentTaskId)
|
|
1464
1486
|
});
|
|
1465
1487
|
runWithEnvContext(envContext, () => {
|
|
1466
1488
|
this.eventHandler?.(evt);
|
|
@@ -1587,6 +1609,15 @@ __legacyDecorateClassTS([
|
|
|
1587
1609
|
__legacyDecorateClassTS([
|
|
1588
1610
|
TracedAs("lark-cli.registerPluginHooks", { recordParams: true, log: true })
|
|
1589
1611
|
], LarkCliInstance.prototype, "registerPluginHooks", null);
|
|
1612
|
+
__legacyDecorateClassTS([
|
|
1613
|
+
TracedAs("lark-cli.resolveChatTaskBinding", {
|
|
1614
|
+
recordParams: true,
|
|
1615
|
+
recordResult: false,
|
|
1616
|
+
paramFilter: (args) => ({ chatId: args[0] }),
|
|
1617
|
+
flattenParamFilter: true,
|
|
1618
|
+
resultFilter: (taskId) => ({ resolvedTaskId: taskId })
|
|
1619
|
+
})
|
|
1620
|
+
], LarkCliInstance.prototype, "resolveChatTaskBinding", null);
|
|
1590
1621
|
__legacyDecorateClassTS([
|
|
1591
1622
|
TracedAs("lark-cli.handleEvent", { recordParams: true, log: true })
|
|
1592
1623
|
], LarkCliInstance.prototype, "handleEvent", null);
|
|
@@ -1685,7 +1716,11 @@ ${result}
|
|
|
1685
1716
|
},
|
|
1686
1717
|
async postProcessNotifyEvent(input) {
|
|
1687
1718
|
try {
|
|
1688
|
-
const chats =
|
|
1719
|
+
const chats = dedupeChatIds(input.resolvedChatIds ?? []);
|
|
1720
|
+
if (chats.length === 0) {
|
|
1721
|
+
logger.info(`[larkCliHandler] postProcessNotifyEvent: no resolved target chat for ` + `taskId=${input.notifyEvent.taskId}; skip mirror.`);
|
|
1722
|
+
return;
|
|
1723
|
+
}
|
|
1689
1724
|
for (const chatId of chats) {
|
|
1690
1725
|
try {
|
|
1691
1726
|
await sendMarkdownToChat(chatId, input.formattedPrompt, input.profile);
|
|
@@ -1709,40 +1744,27 @@ if (larkCliHandler.buildNotifyHandlePrompt) {
|
|
|
1709
1744
|
larkCliHandler.buildNotifyHandlePrompt = wrapFunction(larkCliHandler.buildNotifyHandlePrompt, "buildNotifyHandlePrompt", { recordParams: true, recordResult: false, recordError: true });
|
|
1710
1745
|
}
|
|
1711
1746
|
if (larkCliHandler.postProcessNotifyEvent) {
|
|
1712
|
-
larkCliHandler.postProcessNotifyEvent = wrapFunction(larkCliHandler.postProcessNotifyEvent, "postProcessNotifyEvent", {
|
|
1747
|
+
larkCliHandler.postProcessNotifyEvent = wrapFunction(larkCliHandler.postProcessNotifyEvent, "postProcessNotifyEvent", {
|
|
1748
|
+
recordParams: true,
|
|
1749
|
+
recordResult: false,
|
|
1750
|
+
recordError: true,
|
|
1751
|
+
paramFilter: (args) => ({
|
|
1752
|
+
taskId: args[0]?.notifyEvent?.taskId,
|
|
1753
|
+
resolvedChatIds: args[0]?.resolvedChatIds
|
|
1754
|
+
}),
|
|
1755
|
+
flattenParamFilter: true
|
|
1756
|
+
});
|
|
1713
1757
|
}
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
const
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
if (result.code !== 0) {
|
|
1722
|
-
logger.warn(`[larkCliHandler] chat-search non-zero exit`, {
|
|
1723
|
-
code: result.code,
|
|
1724
|
-
stderr: result.stderr
|
|
1725
|
-
});
|
|
1726
|
-
return [];
|
|
1727
|
-
}
|
|
1728
|
-
let parsed;
|
|
1729
|
-
try {
|
|
1730
|
-
parsed = JSON.parse(result.stdout);
|
|
1731
|
-
} catch {
|
|
1732
|
-
logger.warn(`[larkCliHandler] chat-search stdout is not JSON`, {
|
|
1733
|
-
stdout: result.stdout.slice(0, 200)
|
|
1734
|
-
});
|
|
1735
|
-
return [];
|
|
1736
|
-
}
|
|
1737
|
-
const items = parsed?.items ?? parsed?.data?.items ?? parsed?.data?.chats ?? [];
|
|
1738
|
-
const ids = [];
|
|
1739
|
-
for (const item of items) {
|
|
1740
|
-
const cid = item?.chat_id ?? item?.chatId ?? item?.id;
|
|
1741
|
-
if (typeof cid === "string" && cid.length > 0) {
|
|
1742
|
-
ids.push(cid);
|
|
1758
|
+
function dedupeChatIds(ids) {
|
|
1759
|
+
const out = [];
|
|
1760
|
+
const seen = new Set;
|
|
1761
|
+
for (const id of ids) {
|
|
1762
|
+
if (typeof id === "string" && id.length > 0 && !seen.has(id)) {
|
|
1763
|
+
seen.add(id);
|
|
1764
|
+
out.push(id);
|
|
1743
1765
|
}
|
|
1744
1766
|
}
|
|
1745
|
-
return
|
|
1767
|
+
return out;
|
|
1746
1768
|
}
|
|
1747
1769
|
async function sendMarkdownToChat(chatId, markdown, profile) {
|
|
1748
1770
|
const profileFlag = profile ? `--profile ${profile} ` : "";
|
|
@@ -671,6 +671,13 @@ var init_sqlite_task_store = __esm(() => {
|
|
|
671
671
|
const limit = options.limit || 20;
|
|
672
672
|
return ops.slice(offset, offset + limit);
|
|
673
673
|
}
|
|
674
|
+
async getTaskIdBySessionId(sessionId) {
|
|
675
|
+
await this.initialize();
|
|
676
|
+
if (!sessionId)
|
|
677
|
+
return;
|
|
678
|
+
const row = this.db.prepare("SELECT task_id FROM task_operation WHERE session_id = ? AND milestone_type = 'create' ORDER BY timestamp ASC LIMIT 1").get(sessionId);
|
|
679
|
+
return typeof row?.task_id === "number" ? row.task_id : undefined;
|
|
680
|
+
}
|
|
674
681
|
rowToTask(row) {
|
|
675
682
|
return {
|
|
676
683
|
id: row.id,
|
|
@@ -20,14 +20,14 @@ import {
|
|
|
20
20
|
import {
|
|
21
21
|
globalHookManager,
|
|
22
22
|
init_global_hook_manager
|
|
23
|
-
} from "./roy-agent-core-
|
|
23
|
+
} from "./roy-agent-core-a236mps6.js";
|
|
24
24
|
import {
|
|
25
25
|
init_context
|
|
26
|
-
} from "./roy-agent-core-
|
|
26
|
+
} from "./roy-agent-core-wn59p0zw.js";
|
|
27
27
|
import {
|
|
28
28
|
getCurrentTaskId,
|
|
29
29
|
getEnvContext
|
|
30
|
-
} from "./roy-agent-core-
|
|
30
|
+
} from "./roy-agent-core-zbb3sk72.js";
|
|
31
31
|
import {
|
|
32
32
|
TracedAs,
|
|
33
33
|
init_decorator,
|
|
@@ -1046,7 +1046,19 @@ class BackgroundTaskManager {
|
|
|
1046
1046
|
getSessionComponent() {
|
|
1047
1047
|
return this.env?.getComponent?.("session");
|
|
1048
1048
|
}
|
|
1049
|
-
|
|
1049
|
+
async resolveAssociatedTaskIdBySubSession(subSessionId) {
|
|
1050
|
+
if (!subSessionId)
|
|
1051
|
+
return;
|
|
1052
|
+
try {
|
|
1053
|
+
const taskComponent = this.env?.getComponent?.("task");
|
|
1054
|
+
const id = await taskComponent?.getTaskIdBySessionId?.(subSessionId);
|
|
1055
|
+
return typeof id === "number" && id > 0 ? id : undefined;
|
|
1056
|
+
} catch (err) {
|
|
1057
|
+
logger3.debug(`[BackgroundTaskManager] resolveAssociatedTaskIdBySubSession failed for ${subSessionId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
publishBackgroundEvent(type, payload, parentSessionId, triggerEventId, replyChannel) {
|
|
1050
1062
|
if (this.env?.pushEnvEvent) {
|
|
1051
1063
|
this.env.pushEnvEvent({
|
|
1052
1064
|
type,
|
|
@@ -1054,16 +1066,18 @@ class BackgroundTaskManager {
|
|
|
1054
1066
|
metadata: {
|
|
1055
1067
|
source: "task.background",
|
|
1056
1068
|
trigger_session_id: parentSessionId,
|
|
1057
|
-
...triggerEventId ? { triggerEventId } : {}
|
|
1069
|
+
...triggerEventId ? { triggerEventId } : {},
|
|
1070
|
+
...replyChannel ? { replyChannel } : {}
|
|
1058
1071
|
}
|
|
1059
1072
|
});
|
|
1060
1073
|
logger3.info(`[BackgroundTaskManager] Event published: ${type}`, {
|
|
1061
|
-
triggerEventId
|
|
1074
|
+
triggerEventId,
|
|
1075
|
+
replyChannelChatId: replyChannel?.chatId
|
|
1062
1076
|
});
|
|
1063
1077
|
}
|
|
1064
1078
|
}
|
|
1065
|
-
publishBackgroundEventWithTrigger(type, payload, parentSessionId, triggerEventId) {
|
|
1066
|
-
this.publishBackgroundEvent(type, payload, parentSessionId, triggerEventId);
|
|
1079
|
+
publishBackgroundEventWithTrigger(type, payload, parentSessionId, triggerEventId, replyChannel) {
|
|
1080
|
+
this.publishBackgroundEvent(type, payload, parentSessionId, triggerEventId, replyChannel);
|
|
1067
1081
|
}
|
|
1068
1082
|
static parseAskUserErrorFromMessage(error) {
|
|
1069
1083
|
const rawErrorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -1171,6 +1185,7 @@ class BackgroundTaskManager {
|
|
|
1171
1185
|
throw new Error("Failed to create sub-session");
|
|
1172
1186
|
}
|
|
1173
1187
|
}
|
|
1188
|
+
const replyChannelSnapshot = captureReplyChannelSnapshot();
|
|
1174
1189
|
const abortController = new AbortController;
|
|
1175
1190
|
if (this.processRegistries.size >= this.maxProcessRegistries) {
|
|
1176
1191
|
this.cleanupEmptyProcessRegistries();
|
|
@@ -1194,7 +1209,8 @@ class BackgroundTaskManager {
|
|
|
1194
1209
|
lastUpdatedAt: createdAt,
|
|
1195
1210
|
abortController,
|
|
1196
1211
|
similarTaskIds,
|
|
1197
|
-
triggerEventId
|
|
1212
|
+
triggerEventId,
|
|
1213
|
+
replyChannel: replyChannelSnapshot
|
|
1198
1214
|
};
|
|
1199
1215
|
this.tasks.set(taskIdGen, task);
|
|
1200
1216
|
this.abortControllers.set(taskIdGen, abortController);
|
|
@@ -1205,7 +1221,7 @@ class BackgroundTaskManager {
|
|
|
1205
1221
|
description,
|
|
1206
1222
|
subagentType
|
|
1207
1223
|
};
|
|
1208
|
-
this.publishBackgroundEvent(BackgroundTaskEventTypes.STARTED, startedPayload, parentSessionId, triggerEventId);
|
|
1224
|
+
this.publishBackgroundEvent(BackgroundTaskEventTypes.STARTED, startedPayload, parentSessionId, triggerEventId, replyChannelSnapshot);
|
|
1209
1225
|
this.executeTask(taskIdGen, prompt, timeout, parentSessionId).catch((err) => {
|
|
1210
1226
|
logger3.error(`[BackgroundTaskManager] executeTask unhandled rejection`, {
|
|
1211
1227
|
taskId: taskIdGen,
|
|
@@ -1246,11 +1262,8 @@ class BackgroundTaskManager {
|
|
|
1246
1262
|
task.result = result;
|
|
1247
1263
|
const executionTimeMs = task.completedAt - task.startedAt;
|
|
1248
1264
|
task.associatedTaskId = getCurrentTaskId();
|
|
1249
|
-
if (task.associatedTaskId === undefined
|
|
1250
|
-
|
|
1251
|
-
if (match) {
|
|
1252
|
-
task.associatedTaskId = parseInt(match[1], 10);
|
|
1253
|
-
}
|
|
1265
|
+
if (task.associatedTaskId === undefined) {
|
|
1266
|
+
task.associatedTaskId = await this.resolveAssociatedTaskIdBySubSession(task.subSessionId);
|
|
1254
1267
|
}
|
|
1255
1268
|
const completedPayload = {
|
|
1256
1269
|
backgroundTaskId: task.id,
|
|
@@ -1262,7 +1275,7 @@ class BackgroundTaskManager {
|
|
|
1262
1275
|
executionTimeMs,
|
|
1263
1276
|
associatedTaskId: task.associatedTaskId
|
|
1264
1277
|
};
|
|
1265
|
-
this.publishBackgroundEvent(BackgroundTaskEventTypes.COMPLETED, completedPayload, parentSessionId || task.parentSessionId, task.triggerEventId);
|
|
1278
|
+
this.publishBackgroundEvent(BackgroundTaskEventTypes.COMPLETED, completedPayload, parentSessionId || task.parentSessionId, task.triggerEventId, task.replyChannel);
|
|
1266
1279
|
logger3.info(`[BackgroundTaskManager] Task completed successfully`, {
|
|
1267
1280
|
taskId,
|
|
1268
1281
|
executionTimeMs
|
|
@@ -1276,6 +1289,9 @@ class BackgroundTaskManager {
|
|
|
1276
1289
|
task.completedAt = completedAt;
|
|
1277
1290
|
task.lastUpdatedAt = completedAt;
|
|
1278
1291
|
task.associatedTaskId = getCurrentTaskId();
|
|
1292
|
+
if (task.associatedTaskId === undefined) {
|
|
1293
|
+
task.associatedTaskId = await this.resolveAssociatedTaskIdBySubSession(task.subSessionId);
|
|
1294
|
+
}
|
|
1279
1295
|
if (askUserInfo) {
|
|
1280
1296
|
task.status = "awaiting-user";
|
|
1281
1297
|
task.error = askUserInfo.rawErrorMessage;
|
|
@@ -1299,7 +1315,7 @@ class BackgroundTaskManager {
|
|
|
1299
1315
|
],
|
|
1300
1316
|
associatedTaskId: task.associatedTaskId
|
|
1301
1317
|
};
|
|
1302
|
-
this.publishBackgroundEvent(BackgroundTaskEventTypes.ASK_USER, askUserPayload, parentSessionId || task.parentSessionId, task.triggerEventId);
|
|
1318
|
+
this.publishBackgroundEvent(BackgroundTaskEventTypes.ASK_USER, askUserPayload, parentSessionId || task.parentSessionId, task.triggerEventId, task.replyChannel);
|
|
1303
1319
|
logger3.info(`[BackgroundTaskManager] Task awaiting user input (ask_user cascade)`, {
|
|
1304
1320
|
taskId,
|
|
1305
1321
|
subSessionId: task.subSessionId,
|
|
@@ -1321,7 +1337,7 @@ class BackgroundTaskManager {
|
|
|
1321
1337
|
executionTimeMs,
|
|
1322
1338
|
associatedTaskId: task.associatedTaskId
|
|
1323
1339
|
};
|
|
1324
|
-
this.publishBackgroundEvent(BackgroundTaskEventTypes.STOPPED, stoppedPayload, parentSessionId || task.parentSessionId, task.triggerEventId);
|
|
1340
|
+
this.publishBackgroundEvent(BackgroundTaskEventTypes.STOPPED, stoppedPayload, parentSessionId || task.parentSessionId, task.triggerEventId, task.replyChannel);
|
|
1325
1341
|
} else if (errorMessage.startsWith("Task execution timeout after")) {
|
|
1326
1342
|
task.status = "timeout";
|
|
1327
1343
|
const timeoutPayload = {
|
|
@@ -1334,7 +1350,7 @@ class BackgroundTaskManager {
|
|
|
1334
1350
|
executionTimeMs,
|
|
1335
1351
|
associatedTaskId: task.associatedTaskId
|
|
1336
1352
|
};
|
|
1337
|
-
this.publishBackgroundEvent(BackgroundTaskEventTypes.TIMEOUT, timeoutPayload, parentSessionId || task.parentSessionId, task.triggerEventId);
|
|
1353
|
+
this.publishBackgroundEvent(BackgroundTaskEventTypes.TIMEOUT, timeoutPayload, parentSessionId || task.parentSessionId, task.triggerEventId, task.replyChannel);
|
|
1338
1354
|
} else {
|
|
1339
1355
|
task.status = "failed";
|
|
1340
1356
|
const failedPayload = {
|
|
@@ -1346,7 +1362,7 @@ class BackgroundTaskManager {
|
|
|
1346
1362
|
executionTimeMs,
|
|
1347
1363
|
associatedTaskId: task.associatedTaskId
|
|
1348
1364
|
};
|
|
1349
|
-
this.publishBackgroundEvent(BackgroundTaskEventTypes.FAILED, failedPayload, parentSessionId || task.parentSessionId, task.triggerEventId);
|
|
1365
|
+
this.publishBackgroundEvent(BackgroundTaskEventTypes.FAILED, failedPayload, parentSessionId || task.parentSessionId, task.triggerEventId, task.replyChannel);
|
|
1350
1366
|
}
|
|
1351
1367
|
task.error = errorMessage;
|
|
1352
1368
|
logger3.error(`[BackgroundTaskManager] Task execution error`, {
|
|
@@ -1389,7 +1405,7 @@ class BackgroundTaskManager {
|
|
|
1389
1405
|
status: task.status,
|
|
1390
1406
|
associatedTaskId: task.associatedTaskId
|
|
1391
1407
|
};
|
|
1392
|
-
this.publishBackgroundEvent(BackgroundTaskEventTypes.PROGRESS, progressPayload, parentSessionId, task.triggerEventId);
|
|
1408
|
+
this.publishBackgroundEvent(BackgroundTaskEventTypes.PROGRESS, progressPayload, parentSessionId, task.triggerEventId, task.replyChannel);
|
|
1393
1409
|
}, PROGRESS_INTERVAL);
|
|
1394
1410
|
this.progressTimers.set(taskId, timer);
|
|
1395
1411
|
}
|
|
@@ -1679,7 +1695,7 @@ ${reuseSection.markdown}`;
|
|
|
1679
1695
|
executionTimeMs: task.startedAt ? task.completedAt - task.startedAt : 0,
|
|
1680
1696
|
associatedTaskId: task.associatedTaskId
|
|
1681
1697
|
};
|
|
1682
|
-
this.publishBackgroundEvent(BackgroundTaskEventTypes.STOPPED, stoppedPayload, task.parentSessionId, task.triggerEventId);
|
|
1698
|
+
this.publishBackgroundEvent(BackgroundTaskEventTypes.STOPPED, stoppedPayload, task.parentSessionId, task.triggerEventId, task.replyChannel);
|
|
1683
1699
|
this.finalizeTask(taskId, "stopped");
|
|
1684
1700
|
return {
|
|
1685
1701
|
success: true,
|
|
@@ -1770,7 +1786,7 @@ ${reuseSection.markdown}`;
|
|
|
1770
1786
|
executionTimeMs: taskSafe.startedAt && taskSafe.completedAt ? taskSafe.completedAt - taskSafe.startedAt : 0,
|
|
1771
1787
|
associatedTaskId: taskSafe.associatedTaskId
|
|
1772
1788
|
};
|
|
1773
|
-
this.publishBackgroundEvent(BackgroundTaskEventTypes.STOPPED, stoppedPayload, taskSafe.parentSessionId, taskSafe.triggerEventId);
|
|
1789
|
+
this.publishBackgroundEvent(BackgroundTaskEventTypes.STOPPED, stoppedPayload, taskSafe.parentSessionId, taskSafe.triggerEventId, taskSafe.replyChannel);
|
|
1774
1790
|
}
|
|
1775
1791
|
}
|
|
1776
1792
|
}
|
|
@@ -1920,19 +1936,23 @@ No need to poll — just wait for the notification and use \`task_get\` with the
|
|
|
1920
1936
|
execute: async (args, ctx) => {
|
|
1921
1937
|
const startTime = Date.now();
|
|
1922
1938
|
const params = DelegateToolParameters.parse(args);
|
|
1923
|
-
const { description, prompt, subagent_type = "general", timeout, reason, similar_task_ids
|
|
1939
|
+
const { description, prompt, subagent_type = "general", timeout, reason, similar_task_ids } = params;
|
|
1924
1940
|
const parentSessionId = ctx.session_id || "default";
|
|
1925
|
-
|
|
1926
|
-
if (triggerEventId) {
|
|
1941
|
+
const resolvedTriggerEventId = params.triggerEventId ?? deriveTriggerEventIdFromEnvContext();
|
|
1942
|
+
if (resolvedTriggerEventId && resolvedTriggerEventId !== params.triggerEventId) {
|
|
1943
|
+
logger3.info(`[delegate_task] triggerEventId auto-derived from EnvContext: ${resolvedTriggerEventId}`);
|
|
1944
|
+
}
|
|
1945
|
+
logger3.info(`[delegate_task] Called: description=${description}, subagent_type=${subagent_type}, triggerEventId=${resolvedTriggerEventId ?? "(none)"}`);
|
|
1946
|
+
if (resolvedTriggerEventId) {
|
|
1927
1947
|
const store = getSharedEventStore();
|
|
1928
1948
|
if (store) {
|
|
1929
1949
|
try {
|
|
1930
|
-
const persisted = await store.getEventById(
|
|
1950
|
+
const persisted = await store.getEventById(resolvedTriggerEventId);
|
|
1931
1951
|
if (!persisted) {
|
|
1932
1952
|
return {
|
|
1933
1953
|
success: false,
|
|
1934
1954
|
output: "",
|
|
1935
|
-
error: `Unknown triggerEventId: ${
|
|
1955
|
+
error: `Unknown triggerEventId: ${resolvedTriggerEventId} (not found in EventStore)`,
|
|
1936
1956
|
metadata: { execution_time_ms: Date.now() - startTime }
|
|
1937
1957
|
};
|
|
1938
1958
|
}
|
|
@@ -1940,12 +1960,12 @@ No need to poll — just wait for the notification and use \`task_get\` with the
|
|
|
1940
1960
|
return {
|
|
1941
1961
|
success: false,
|
|
1942
1962
|
output: "",
|
|
1943
|
-
error: `Failed to verify triggerEventId ${
|
|
1963
|
+
error: `Failed to verify triggerEventId ${resolvedTriggerEventId}: ${err instanceof Error ? err.message : String(err)}`,
|
|
1944
1964
|
metadata: { execution_time_ms: Date.now() - startTime }
|
|
1945
1965
|
};
|
|
1946
1966
|
}
|
|
1947
1967
|
} else {
|
|
1948
|
-
logger3.warn(`[delegate_task] triggerEventId=${
|
|
1968
|
+
logger3.warn(`[delegate_task] triggerEventId=${resolvedTriggerEventId} supplied but no shared EventStore registered; skipping verification`);
|
|
1949
1969
|
}
|
|
1950
1970
|
}
|
|
1951
1971
|
const registry2 = getAgentRegistry(taskComponent);
|
|
@@ -1975,7 +1995,7 @@ No need to poll — just wait for the notification and use \`task_get\` with the
|
|
|
1975
1995
|
};
|
|
1976
1996
|
await globalHookManager.execute(TaskHookPoints.DELEGATE_BEFORE, delegateCtx, { sessionId: parentSessionId });
|
|
1977
1997
|
promptWithTaskInfo = delegateCtx.prompt;
|
|
1978
|
-
return await handleBackgroundTask(backgroundTaskManager, parentSessionId, description, promptWithTaskInfo, delegateCtx.subagentType, delegateCtx.timeout, similar_task_ids, params.sub_session_id,
|
|
1998
|
+
return await handleBackgroundTask(backgroundTaskManager, parentSessionId, description, promptWithTaskInfo, delegateCtx.subagentType, delegateCtx.timeout, similar_task_ids, params.sub_session_id, resolvedTriggerEventId);
|
|
1979
1999
|
}
|
|
1980
2000
|
};
|
|
1981
2001
|
tool.execute = wrapFunction(tool.execute, "delegate.execute", {
|
|
@@ -1985,6 +2005,40 @@ No need to poll — just wait for the notification and use \`task_get\` with the
|
|
|
1985
2005
|
});
|
|
1986
2006
|
return tool;
|
|
1987
2007
|
}
|
|
2008
|
+
function _deriveTriggerEventIdFromEnvContext() {
|
|
2009
|
+
const env = getEnvContext();
|
|
2010
|
+
if (!env)
|
|
2011
|
+
return;
|
|
2012
|
+
const envEvent = env.envEvent;
|
|
2013
|
+
const fromMeta = envEvent?.metadata?.triggerEventId;
|
|
2014
|
+
if (typeof fromMeta === "string" && fromMeta.length > 0)
|
|
2015
|
+
return fromMeta;
|
|
2016
|
+
const fromPayload = envEvent?.payload?.triggerEventId;
|
|
2017
|
+
if (typeof fromPayload === "string" && fromPayload.length > 0)
|
|
2018
|
+
return fromPayload;
|
|
2019
|
+
return;
|
|
2020
|
+
}
|
|
2021
|
+
var deriveTriggerEventIdFromEnvContext = wrapFunction(_deriveTriggerEventIdFromEnvContext, "delegate.deriveTriggerEventId", { recordParams: false, recordResult: true, recordError: true });
|
|
2022
|
+
function _captureReplyChannelSnapshot() {
|
|
2023
|
+
const replyChannel = getEnvContext()?.replyChannel;
|
|
2024
|
+
if (!replyChannel)
|
|
2025
|
+
return;
|
|
2026
|
+
if (!replyChannel.chatId && !replyChannel.messageId)
|
|
2027
|
+
return;
|
|
2028
|
+
const params = { ...replyChannel.params ?? {} };
|
|
2029
|
+
if (replyChannel.userId && params.userId === undefined) {
|
|
2030
|
+
params.userId = replyChannel.userId;
|
|
2031
|
+
}
|
|
2032
|
+
return {
|
|
2033
|
+
type: replyChannel.type,
|
|
2034
|
+
appId: replyChannel.appId,
|
|
2035
|
+
chatId: replyChannel.chatId,
|
|
2036
|
+
messageId: replyChannel.messageId,
|
|
2037
|
+
profile: replyChannel.profile,
|
|
2038
|
+
params: Object.keys(params).length > 0 ? params : undefined
|
|
2039
|
+
};
|
|
2040
|
+
}
|
|
2041
|
+
var captureReplyChannelSnapshot = wrapFunction(_captureReplyChannelSnapshot, "delegate.captureReplyChannel", { recordParams: false, recordResult: true, recordError: true });
|
|
1988
2042
|
async function handleBackgroundTask(backgroundTaskManager, parentSessionId, description, prompt, subagentType, timeout, similarTaskIds, existingSubSessionId, triggerEventId) {
|
|
1989
2043
|
const startTime = Date.now();
|
|
1990
2044
|
try {
|
|
@@ -11,16 +11,16 @@ import {
|
|
|
11
11
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
12
12
|
import {
|
|
13
13
|
BaseComponent
|
|
14
|
-
} from "./roy-agent-core-
|
|
14
|
+
} from "./roy-agent-core-9t675te0.js";
|
|
15
15
|
import {
|
|
16
16
|
ToolHookPoints,
|
|
17
17
|
globalHookManager,
|
|
18
18
|
init_global_hook_manager
|
|
19
|
-
} from "./roy-agent-core-
|
|
19
|
+
} from "./roy-agent-core-a236mps6.js";
|
|
20
20
|
import {
|
|
21
21
|
getCurrentTaskId,
|
|
22
22
|
init_env_context
|
|
23
|
-
} from "./roy-agent-core-
|
|
23
|
+
} from "./roy-agent-core-zbb3sk72.js";
|
|
24
24
|
import {
|
|
25
25
|
TracedAs,
|
|
26
26
|
init_decorator
|
|
@@ -10,14 +10,14 @@ import {
|
|
|
10
10
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
11
11
|
import {
|
|
12
12
|
BaseComponent
|
|
13
|
-
} from "./roy-agent-core-
|
|
13
|
+
} from "./roy-agent-core-9t675te0.js";
|
|
14
14
|
import {
|
|
15
15
|
createHook
|
|
16
|
-
} from "./roy-agent-core-
|
|
16
|
+
} from "./roy-agent-core-cw89yj9d.js";
|
|
17
17
|
import {
|
|
18
18
|
globalHookManager,
|
|
19
19
|
init_global_hook_manager
|
|
20
|
-
} from "./roy-agent-core-
|
|
20
|
+
} from "./roy-agent-core-a236mps6.js";
|
|
21
21
|
import {
|
|
22
22
|
createLogger,
|
|
23
23
|
init_logger
|