@ai-setting/roy-agent-core 1.7.36 → 1.7.38
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 +7 -7
- package/dist/env/agent/index.js +10 -10
- package/dist/env/commands/index.js +7 -7
- package/dist/env/context/index.js +3 -3
- package/dist/env/debug/index.js +7 -7
- package/dist/env/event-source/index.js +24 -14
- package/dist/env/hook/index.js +5 -5
- package/dist/env/index.js +33 -32
- package/dist/env/llm/index.js +7 -7
- package/dist/env/log-trace/index.js +7 -7
- package/dist/env/mcp/index.js +7 -7
- package/dist/env/memory/index.js +7 -7
- package/dist/env/plugin/index.js +7 -7
- package/dist/env/prompt/index.js +7 -7
- package/dist/env/session/index.js +7 -7
- package/dist/env/skill/index.js +7 -7
- package/dist/env/task/delegate/index.js +7 -6
- package/dist/env/task/index.js +12 -11
- package/dist/env/task/plugins/index.js +7 -7
- package/dist/env/task/storage/index.js +2 -2
- package/dist/env/task/tools/index.js +3 -3
- package/dist/env/tool/built-in/index.js +2 -2
- package/dist/env/tool/index.js +8 -8
- package/dist/env/workflow/engine/index.js +9 -9
- package/dist/env/workflow/index.js +17 -17
- package/dist/env/workflow/nodes/index.js +2 -2
- package/dist/env/workflow/service/index.js +2 -2
- package/dist/env/workflow/storage/index.js +3 -3
- package/dist/env/workflow/tools/index.js +11 -11
- package/dist/env/workflow/utils/index.js +4 -4
- package/dist/index.js +53 -43
- package/dist/shared/@ai-setting/{roy-agent-core-yf0ex8y1.js → roy-agent-core-333apxaa.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-axh3vn8k.js → roy-agent-core-3m7j2wcb.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-9drbkjfr.js → roy-agent-core-4cj6hram.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-zda3rfr3.js → roy-agent-core-4kbvfnn1.js} +54 -5
- package/dist/shared/@ai-setting/{roy-agent-core-821bsh3r.js → roy-agent-core-5gpf5j51.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-jq7g5nxz.js → roy-agent-core-5j4awbgc.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-wgttzq8e.js → roy-agent-core-6vbgswjw.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-52yt7e1t.js → roy-agent-core-83j0v0hs.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-j9ejsmsj.js → roy-agent-core-8nv07zgr.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-0czz1ynz.js → roy-agent-core-970btnjh.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-yw07bvqz.js → roy-agent-core-9cqpdrnk.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-q3zvkbj6.js → roy-agent-core-9qn92jhf.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-t2vwy92b.js → roy-agent-core-9wsy4yfv.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-qhjm0bxm.js → roy-agent-core-a9pbda78.js} +23 -13
- package/dist/shared/@ai-setting/{roy-agent-core-2adayzfa.js → roy-agent-core-cd9h49ng.js} +13 -13
- package/dist/shared/@ai-setting/{roy-agent-core-ds5f75pg.js → roy-agent-core-ck60j1q9.js} +19 -1
- package/dist/shared/@ai-setting/{roy-agent-core-z7q1re07.js → roy-agent-core-dfnyvxr9.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-h1zamsb9.js → roy-agent-core-e02f0ywc.js} +69 -24
- package/dist/shared/@ai-setting/{roy-agent-core-gcnvcbft.js → roy-agent-core-e5pnnzdm.js} +29 -7
- package/dist/shared/@ai-setting/{roy-agent-core-krmhhje6.js → roy-agent-core-e8rxb9a6.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-1kcstbn3.js → roy-agent-core-ff2ssff5.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-xgarc0t2.js → roy-agent-core-gh6szaj5.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-tft0pa6h.js → roy-agent-core-gpf33hn9.js} +264 -14
- package/dist/shared/@ai-setting/{roy-agent-core-zfcwa3w7.js → roy-agent-core-hfmpmt0k.js} +27 -5
- package/dist/shared/@ai-setting/{roy-agent-core-qz9jb9sp.js → roy-agent-core-hkj5v9xq.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-anwh7050.js → roy-agent-core-mzyzdf33.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-zma7p5p7.js → roy-agent-core-nz4n1w28.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-hs75rxp3.js → roy-agent-core-p0c98phj.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-1dacps3n.js → roy-agent-core-p2ham63a.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-d5gwqrr5.js → roy-agent-core-pd0exvnq.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-63nkhqa4.js → roy-agent-core-q3vbxprp.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-e3qjt852.js → roy-agent-core-rgpkygbc.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-j6h99erf.js → roy-agent-core-rhfywyz1.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-k5csz66y.js → roy-agent-core-tm57tmds.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-bny3nd8q.js → roy-agent-core-vh10qamt.js} +8 -8
- package/dist/shared/@ai-setting/{roy-agent-core-dz3m7dt4.js → roy-agent-core-vn6f4nxv.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-2aq5f4e1.js → roy-agent-core-wacnvjaq.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-dzfyjzgw.js → roy-agent-core-wb1b61f8.js} +20 -2
- package/dist/shared/@ai-setting/{roy-agent-core-3x6ej9vm.js → roy-agent-core-wfpzny0h.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-ddq5hcp5.js → roy-agent-core-x6c45yqd.js} +3 -1
- package/dist/shared/@ai-setting/roy-agent-core-xyys5m1a.js +159 -0
- package/dist/shared/@ai-setting/{roy-agent-core-wphva2vs.js → roy-agent-core-y1n63tse.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-n094tbjh.js → roy-agent-core-y7atw1kw.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-jcdsghyr.js → roy-agent-core-yjjqm4ww.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-743510fc.js → roy-agent-core-yjyvwxs4.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-6thjwx6v.js → roy-agent-core-ym1hwrcm.js} +113 -2
- package/dist/shared/@ai-setting/{roy-agent-core-62c1t7wr.js → roy-agent-core-yv4anf1c.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-jxgprc5a.js → roy-agent-core-z4486eek.js} +3 -2
- package/dist/shared/@ai-setting/{roy-agent-core-n3pwkwjh.js → roy-agent-core-za09t5g3.js} +1 -1
- package/package.json +1 -1
- /package/dist/shared/@ai-setting/{roy-agent-core-k5hxvaf0.js → roy-agent-core-3ztzc83c.js} +0 -0
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultLarkCliRunner
|
|
3
|
+
} from "./roy-agent-core-ck60j1q9.js";
|
|
4
|
+
import {
|
|
5
|
+
getSharedEventStore
|
|
6
|
+
} from "./roy-agent-core-xyys5m1a.js";
|
|
1
7
|
import {
|
|
2
8
|
TaskTagPlugin,
|
|
3
9
|
createLarkCliTaskNotifyHook,
|
|
4
10
|
createPerTaskGroupChatPlugin
|
|
5
|
-
} from "./roy-agent-core-
|
|
11
|
+
} from "./roy-agent-core-e5pnnzdm.js";
|
|
6
12
|
import {
|
|
7
13
|
normalizeLarkAtMentions
|
|
8
14
|
} from "./roy-agent-core-rmn29nrh.js";
|
|
@@ -11,22 +17,23 @@ import {
|
|
|
11
17
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
12
18
|
import {
|
|
13
19
|
BaseComponent
|
|
14
|
-
} from "./roy-agent-core-
|
|
20
|
+
} from "./roy-agent-core-yv4anf1c.js";
|
|
15
21
|
import {
|
|
16
22
|
globalHookManager,
|
|
17
23
|
init_global_hook_manager
|
|
18
|
-
} from "./roy-agent-core-
|
|
24
|
+
} from "./roy-agent-core-yjyvwxs4.js";
|
|
19
25
|
import {
|
|
20
26
|
init_context
|
|
21
|
-
} from "./roy-agent-core-
|
|
27
|
+
} from "./roy-agent-core-ff2ssff5.js";
|
|
22
28
|
import {
|
|
23
29
|
createEnvContext,
|
|
24
30
|
runWithEnvContext
|
|
25
|
-
} from "./roy-agent-core-
|
|
31
|
+
} from "./roy-agent-core-z4486eek.js";
|
|
26
32
|
import {
|
|
27
33
|
TracedAs,
|
|
28
|
-
init_decorator
|
|
29
|
-
|
|
34
|
+
init_decorator,
|
|
35
|
+
wrapFunction
|
|
36
|
+
} from "./roy-agent-core-a9pbda78.js";
|
|
30
37
|
import {
|
|
31
38
|
createLogger,
|
|
32
39
|
getTracerProvider,
|
|
@@ -593,8 +600,8 @@ var bountyIMHandler = {
|
|
|
593
600
|
};
|
|
594
601
|
|
|
595
602
|
// src/env/event-source/event-source-handlers.ts
|
|
596
|
-
init_global_hook_manager();
|
|
597
603
|
import { spawn as spawn2 } from "child_process";
|
|
604
|
+
init_global_hook_manager();
|
|
598
605
|
init_context();
|
|
599
606
|
|
|
600
607
|
// src/env/event-source/bounty-cli-handler.ts
|
|
@@ -832,6 +839,9 @@ var bountyCliHandler = {
|
|
|
832
839
|
// src/env/event-source/event-source-handlers.ts
|
|
833
840
|
init_logger();
|
|
834
841
|
var logger = createLogger("lark-cli:event-source");
|
|
842
|
+
function isPluginDebugEnabled() {
|
|
843
|
+
return process.env.ROY_TASK_NOTIFY_DEBUG === "1" || process.env.ROY_TRACE_DEBUG === "1";
|
|
844
|
+
}
|
|
835
845
|
var BUILT_IN_PLUGIN_FACTORIES = {
|
|
836
846
|
LarkCliTaskNotifyPlugin: (cfg) => createLarkCliTaskNotifyHook(cfg),
|
|
837
847
|
PerTaskGroupChatPlugin: (cfg) => createPerTaskGroupChatPlugin(cfg),
|
|
@@ -1148,6 +1158,7 @@ class LarkCliInstance {
|
|
|
1148
1158
|
registerPluginHooks(plugin) {
|
|
1149
1159
|
const pluginName = plugin.name || "unknown";
|
|
1150
1160
|
this.injectTaskUpdater(plugin);
|
|
1161
|
+
this.injectSessionComponent(plugin);
|
|
1151
1162
|
if (typeof plugin.init === "function") {
|
|
1152
1163
|
const pluginEnv = {
|
|
1153
1164
|
getComponent: () => null,
|
|
@@ -1233,6 +1244,48 @@ class LarkCliInstance {
|
|
|
1233
1244
|
};
|
|
1234
1245
|
plugin.setTaskUpdater(taskUpdater);
|
|
1235
1246
|
}
|
|
1247
|
+
injectSessionComponent(plugin) {
|
|
1248
|
+
if (typeof plugin.setSessionComponent !== "function") {
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
if (typeof plugin.hasSessionComponent === "function" && plugin.hasSessionComponent()) {
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
if (!this.environment?.getComponent) {
|
|
1255
|
+
if (isPluginDebugEnabled()) {
|
|
1256
|
+
console.debug(`[LarkCliInstance] ${plugin.name || "plugin"} has setSessionComponent but ` + `environment not injected (setEnvironment not called). ` + `chat↔task 绑定将不会写入。`);
|
|
1257
|
+
}
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
const sessionComponent = this.environment.getComponent("session");
|
|
1261
|
+
if (!sessionComponent?.upsertChatTaskBinding) {
|
|
1262
|
+
if (isPluginDebugEnabled()) {
|
|
1263
|
+
console.debug(`[LarkCliInstance] ${plugin.name || "plugin"} has setSessionComponent but ` + `sessionComponent or upsertChatTaskBinding not found via env.getComponent('session'). ` + `chat↔task 绑定将不会写入。`);
|
|
1264
|
+
}
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1267
|
+
plugin.setSessionComponent(sessionComponent);
|
|
1268
|
+
if (isPluginDebugEnabled()) {
|
|
1269
|
+
console.debug(`[LarkCliInstance] SessionComponent injected for plugin ${plugin.name || "unknown"} ` + `(sourceId=${this.config.id})`);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
async resolveChatTaskBinding(chatId) {
|
|
1273
|
+
if (!chatId)
|
|
1274
|
+
return null;
|
|
1275
|
+
const sessionComponent = this.environment?.getComponent?.("session");
|
|
1276
|
+
if (!sessionComponent?.getChatTaskBinding)
|
|
1277
|
+
return null;
|
|
1278
|
+
try {
|
|
1279
|
+
const binding = await sessionComponent.getChatTaskBinding(chatId);
|
|
1280
|
+
if (binding && binding.status === "ready" && typeof binding.taskId === "number" && binding.taskId > 0) {
|
|
1281
|
+
return binding.taskId;
|
|
1282
|
+
}
|
|
1283
|
+
return null;
|
|
1284
|
+
} catch (err) {
|
|
1285
|
+
logger.warn(`[LarkCliInstance] resolveChatTaskBinding failed for chatId=${chatId}: ${err}. ` + `群消息将不会注入 parentTaskId。`);
|
|
1286
|
+
return null;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1236
1289
|
unloadPlugins() {
|
|
1237
1290
|
for (const plugin of this.loadedPlugins) {
|
|
1238
1291
|
for (const hook of plugin.hooks) {
|
|
@@ -1252,7 +1305,7 @@ class LarkCliInstance {
|
|
|
1252
1305
|
}
|
|
1253
1306
|
}
|
|
1254
1307
|
}
|
|
1255
|
-
handleEvent(rawData) {
|
|
1308
|
+
async handleEvent(rawData) {
|
|
1256
1309
|
let dedupKey;
|
|
1257
1310
|
try {
|
|
1258
1311
|
const parsed = JSON.parse(rawData);
|
|
@@ -1319,9 +1372,36 @@ class LarkCliInstance {
|
|
|
1319
1372
|
eventSourceId: this.config.id
|
|
1320
1373
|
};
|
|
1321
1374
|
const { metadata, replyChannel, recommendedAction } = extractMetadata(enrichedEvent, eventType);
|
|
1375
|
+
const parentTaskId = await this.resolveChatTaskBinding(metadata?.chatId);
|
|
1376
|
+
const userId = this.extractUserId(rawEvent);
|
|
1377
|
+
let triggerEventId;
|
|
1378
|
+
const sharedStore = getSharedEventStore();
|
|
1379
|
+
if (sharedStore && larkCliHandler.emitTriggerEvent) {
|
|
1380
|
+
try {
|
|
1381
|
+
triggerEventId = await larkCliHandler.emitTriggerEvent({
|
|
1382
|
+
senderId: userId,
|
|
1383
|
+
text: undefined,
|
|
1384
|
+
metadata: {
|
|
1385
|
+
eventType,
|
|
1386
|
+
appId: metadata?.appId,
|
|
1387
|
+
chatId: metadata?.chatId,
|
|
1388
|
+
chatType: metadata?.chatType,
|
|
1389
|
+
messageId: metadata?.messageId,
|
|
1390
|
+
messageType: metadata?.messageType,
|
|
1391
|
+
senderId: userId,
|
|
1392
|
+
tenantKey: metadata?.tenantKey,
|
|
1393
|
+
profile: this.config.profile
|
|
1394
|
+
},
|
|
1395
|
+
rawEvent
|
|
1396
|
+
}, sharedStore);
|
|
1397
|
+
} catch (err) {
|
|
1398
|
+
console.error(`[LarkCliInstance] emitTriggerEvent failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1322
1401
|
const message = JSON.stringify({
|
|
1323
1402
|
rawData,
|
|
1324
|
-
recommendedAction
|
|
1403
|
+
recommendedAction,
|
|
1404
|
+
...triggerEventId ? { triggerEventId } : {}
|
|
1325
1405
|
});
|
|
1326
1406
|
const timestamp = Date.now();
|
|
1327
1407
|
const plugins = this.config.handleRule?.plugins || [];
|
|
@@ -1341,7 +1421,9 @@ class LarkCliInstance {
|
|
|
1341
1421
|
plugins,
|
|
1342
1422
|
pluginEnabled,
|
|
1343
1423
|
replyChannel,
|
|
1344
|
-
agent
|
|
1424
|
+
agent,
|
|
1425
|
+
parentTaskId: parentTaskId ?? undefined,
|
|
1426
|
+
...triggerEventId ? { triggerEventId } : {}
|
|
1345
1427
|
},
|
|
1346
1428
|
payload: {
|
|
1347
1429
|
sourceId: this.config.id,
|
|
@@ -1351,10 +1433,11 @@ class LarkCliInstance {
|
|
|
1351
1433
|
metadata,
|
|
1352
1434
|
replyChannel,
|
|
1353
1435
|
recommendedAction,
|
|
1354
|
-
timestamp
|
|
1436
|
+
timestamp,
|
|
1437
|
+
parentTaskId: parentTaskId ?? undefined,
|
|
1438
|
+
...triggerEventId ? { triggerEventId } : {}
|
|
1355
1439
|
}
|
|
1356
1440
|
};
|
|
1357
|
-
const userId = this.extractUserId(rawEvent);
|
|
1358
1441
|
const envReplyChannel = this.buildReplyChannel(replyChannel);
|
|
1359
1442
|
const larkMessageId = replyChannel?.messageId ?? metadata?.messageId;
|
|
1360
1443
|
const envContext = createEnvContext({
|
|
@@ -1515,8 +1598,169 @@ var larkCliHandler = {
|
|
|
1515
1598
|
},
|
|
1516
1599
|
createInstance(config) {
|
|
1517
1600
|
return new LarkCliInstance(config);
|
|
1601
|
+
},
|
|
1602
|
+
async emitTriggerEvent(payload, store) {
|
|
1603
|
+
const eventId = await store.insertTriggerEvent(payload, "lark-cli");
|
|
1604
|
+
logger.info(`[larkCliHandler] emitTriggerEvent: id=${eventId}`, {
|
|
1605
|
+
chatId: payload.metadata?.chatId,
|
|
1606
|
+
senderId: payload.senderId
|
|
1607
|
+
});
|
|
1608
|
+
return eventId;
|
|
1609
|
+
},
|
|
1610
|
+
async replyMessage(input) {
|
|
1611
|
+
const runner = getLarkCliRunner();
|
|
1612
|
+
const profileFlag = input.profile ? `--profile ${input.profile} ` : "";
|
|
1613
|
+
const msgType = input.msgType ?? "text";
|
|
1614
|
+
const safeContent = input.content.replace(/'/g, `'\\''`);
|
|
1615
|
+
const command = `lark-cli ${profileFlag}im +messages-reply ` + `--message-id ${input.messageId} ` + `--chat-id ${input.chatId} ` + `--as bot ` + `--msg-type ${msgType} ` + `--content '${safeContent}'`;
|
|
1616
|
+
try {
|
|
1617
|
+
const result = await runner.run(command);
|
|
1618
|
+
if (result.code !== 0) {
|
|
1619
|
+
logger.error(`[larkCliHandler] replyMessage non-zero exit`, {
|
|
1620
|
+
code: result.code,
|
|
1621
|
+
stderr: result.stderr
|
|
1622
|
+
});
|
|
1623
|
+
return { success: false, error: result.stderr || `exit ${result.code}` };
|
|
1624
|
+
}
|
|
1625
|
+
let replyMessageId;
|
|
1626
|
+
try {
|
|
1627
|
+
const parsed = JSON.parse(result.stdout);
|
|
1628
|
+
replyMessageId = parsed?.data?.message_id ?? parsed?.message_id;
|
|
1629
|
+
} catch {}
|
|
1630
|
+
return { success: true, messageId: replyMessageId };
|
|
1631
|
+
} catch (err) {
|
|
1632
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
1633
|
+
logger.error(`[larkCliHandler] replyMessage spawn error`, { error: errMsg });
|
|
1634
|
+
return { success: false, error: errMsg };
|
|
1635
|
+
}
|
|
1636
|
+
},
|
|
1637
|
+
extractReplyContext(event, profile) {
|
|
1638
|
+
return {
|
|
1639
|
+
esType: "lark-cli",
|
|
1640
|
+
chatId: event.metadata?.chatId ?? "",
|
|
1641
|
+
messageId: event.metadata?.messageId ?? "",
|
|
1642
|
+
senderOpenId: event.metadata?.senderId ?? event.senderId,
|
|
1643
|
+
tenantKey: event.metadata?.tenantKey ?? undefined,
|
|
1644
|
+
profile: profile ?? event.metadata?.profile ?? undefined
|
|
1645
|
+
};
|
|
1646
|
+
},
|
|
1647
|
+
buildNotifyHandlePrompt(input) {
|
|
1648
|
+
const ctx = this.extractReplyContext?.(input.triggerEvent, input.profile) ?? {
|
|
1649
|
+
esType: "lark-cli",
|
|
1650
|
+
chatId: input.triggerEvent.metadata?.chatId ?? "",
|
|
1651
|
+
messageId: input.triggerEvent.metadata?.messageId ?? "",
|
|
1652
|
+
senderOpenId: input.triggerEvent.metadata?.senderId ?? input.triggerEvent.senderId,
|
|
1653
|
+
profile: input.profile
|
|
1654
|
+
};
|
|
1655
|
+
const profileFlag = ctx.profile ? `--profile ${ctx.profile} ` : "";
|
|
1656
|
+
const desc = input.notifyEvent.description ?? "(未命名任务)";
|
|
1657
|
+
const result = input.subAgentResult.summary ?? input.notifyEvent.result ?? "";
|
|
1658
|
+
const promptText = `
|
|
1659
|
+
## Notify Event: ${input.notifyEvent.type}
|
|
1660
|
+
|
|
1661
|
+
Sub-agent 完成了 Task #${input.notifyEvent.taskId ?? "?"}「${desc}」。
|
|
1662
|
+
|
|
1663
|
+
### Trigger event(原始飞书消息,来自 EventStore 反查)
|
|
1664
|
+
- ES: lark-cli
|
|
1665
|
+
- **chatId: ${ctx.chatId}** ← 关键!必须回复到这里
|
|
1666
|
+
- **messageId: ${ctx.messageId}** ← 必须 reply 这条
|
|
1667
|
+
- sender: ${ctx.senderOpenId}
|
|
1668
|
+
${ctx.profile ? `- profile: ${ctx.profile} ← 调用 lark-cli 必须带 --profile
|
|
1669
|
+
` : ""}
|
|
1670
|
+
### Sub-agent 输出
|
|
1671
|
+
${result}
|
|
1672
|
+
|
|
1673
|
+
### \uD83D\uDC49 你应该这样做
|
|
1674
|
+
用 lark-cli 调 im +messages-reply:
|
|
1675
|
+
lark-cli ${profileFlag}im +messages-reply --message-id ${ctx.messageId} --chat-id ${ctx.chatId} --as bot --msg-type text --content '<你的回复>'
|
|
1676
|
+
|
|
1677
|
+
⚠️ 不要 fallback 到 lastReplyChannel 或 metadata.replyChannel — 那个 chatId
|
|
1678
|
+
可能跟用户原始消息的 chatId 不一致(参见 #4035/#4038/#4039 bug)。
|
|
1679
|
+
`;
|
|
1680
|
+
const systemHint = `回复必须用 lark-cli im +messages-reply(${profileFlag.trim() ? `带 ${profileFlag.trim()};` : ""}` + `chatId=${ctx.chatId} / messageId=${ctx.messageId} 来自 trigger event,不要 fallback。`;
|
|
1681
|
+
return { promptText, systemHint };
|
|
1682
|
+
},
|
|
1683
|
+
setRunner(runner) {
|
|
1684
|
+
setLarkCliRunner(runner);
|
|
1685
|
+
},
|
|
1686
|
+
async postProcessNotifyEvent(input) {
|
|
1687
|
+
try {
|
|
1688
|
+
const chats = await searchChatsByTaskId(input.notifyEvent.taskId, input.profile);
|
|
1689
|
+
for (const chatId of chats) {
|
|
1690
|
+
try {
|
|
1691
|
+
await sendMarkdownToChat(chatId, input.formattedPrompt, input.profile);
|
|
1692
|
+
} catch (err) {
|
|
1693
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
1694
|
+
logger.error(`[larkCliHandler] postProcessNotifyEvent: send failed for chatId=${chatId}`, { error: errMsg });
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
} catch (err) {
|
|
1698
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
1699
|
+
logger.error(`[larkCliHandler] postProcessNotifyEvent failed`, {
|
|
1700
|
+
error: errMsg
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1518
1703
|
}
|
|
1519
1704
|
};
|
|
1705
|
+
if (larkCliHandler.extractReplyContext) {
|
|
1706
|
+
larkCliHandler.extractReplyContext = wrapFunction(larkCliHandler.extractReplyContext, "extractReplyContext", { recordParams: true, recordResult: true, recordError: true });
|
|
1707
|
+
}
|
|
1708
|
+
if (larkCliHandler.buildNotifyHandlePrompt) {
|
|
1709
|
+
larkCliHandler.buildNotifyHandlePrompt = wrapFunction(larkCliHandler.buildNotifyHandlePrompt, "buildNotifyHandlePrompt", { recordParams: true, recordResult: false, recordError: true });
|
|
1710
|
+
}
|
|
1711
|
+
if (larkCliHandler.postProcessNotifyEvent) {
|
|
1712
|
+
larkCliHandler.postProcessNotifyEvent = wrapFunction(larkCliHandler.postProcessNotifyEvent, "postProcessNotifyEvent", { recordParams: true, recordResult: false, recordError: true });
|
|
1713
|
+
}
|
|
1714
|
+
async function searchChatsByTaskId(taskId, profile) {
|
|
1715
|
+
if (!taskId)
|
|
1716
|
+
return [];
|
|
1717
|
+
const profileFlag = profile ? `--profile ${profile} ` : "";
|
|
1718
|
+
const runner = getLarkCliRunner();
|
|
1719
|
+
const command = `lark-cli ${profileFlag}im +chat-search ` + `--query "Task ${taskId}" --as bot --format json`;
|
|
1720
|
+
const result = await runner.run(command);
|
|
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);
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
return ids;
|
|
1746
|
+
}
|
|
1747
|
+
async function sendMarkdownToChat(chatId, markdown, profile) {
|
|
1748
|
+
const profileFlag = profile ? `--profile ${profile} ` : "";
|
|
1749
|
+
const runner = getLarkCliRunner();
|
|
1750
|
+
const safeMd = markdown.replace(/'/g, `'\\''`);
|
|
1751
|
+
const command = `lark-cli ${profileFlag}im +messages-send ` + `--chat-id "${chatId}" --as bot --markdown '${safeMd}'`;
|
|
1752
|
+
const result = await runner.run(command);
|
|
1753
|
+
if (result.code !== 0) {
|
|
1754
|
+
throw new Error(`messages-send exit ${result.code}: ${result.stderr || "(no stderr)"}`);
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
var _larkCliRunner = defaultLarkCliRunner;
|
|
1758
|
+
function getLarkCliRunner() {
|
|
1759
|
+
return _larkCliRunner;
|
|
1760
|
+
}
|
|
1761
|
+
function setLarkCliRunner(runner) {
|
|
1762
|
+
_larkCliRunner = runner;
|
|
1763
|
+
}
|
|
1520
1764
|
var builtInHandlers = [
|
|
1521
1765
|
larkCliHandler,
|
|
1522
1766
|
timerHandler,
|
|
@@ -1623,7 +1867,7 @@ class EventSourceComponent extends BaseComponent {
|
|
|
1623
1867
|
}
|
|
1624
1868
|
}
|
|
1625
1869
|
async executeInitHooks() {
|
|
1626
|
-
const { EventSourceInitHooks } = await import("./roy-agent-core-
|
|
1870
|
+
const { EventSourceInitHooks } = await import("./roy-agent-core-x6c45yqd.js");
|
|
1627
1871
|
await EventSourceInitHooks.execute(this);
|
|
1628
1872
|
}
|
|
1629
1873
|
registerHandler(handler) {
|
|
@@ -1970,5 +2214,11 @@ class EventSourceComponent extends BaseComponent {
|
|
|
1970
2214
|
__legacyDecorateClassTS([
|
|
1971
2215
|
TracedAs("event-source.update", { recordParams: false, log: false })
|
|
1972
2216
|
], EventSourceComponent.prototype, "update", null);
|
|
2217
|
+
__legacyDecorateClassTS([
|
|
2218
|
+
TracedAs("event_source.start", { recordParams: true, recordResult: false })
|
|
2219
|
+
], EventSourceComponent.prototype, "startSource", null);
|
|
2220
|
+
__legacyDecorateClassTS([
|
|
2221
|
+
TracedAs("event_source.stop", { recordParams: true, recordResult: false })
|
|
2222
|
+
], EventSourceComponent.prototype, "stopSource", null);
|
|
1973
2223
|
|
|
1974
2224
|
export { TimerInstance, timerHandler, buildDefaultBountyIMSystemPrompt, resolveBountyIMSystemPrompt, BountyIMInstance, bountyIMHandler, extractMetadata, larkCliHandler, builtInHandlers, getBuiltInHandler, EventSourceComponent };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
+
getEnvContextOrEmpty,
|
|
2
3
|
init_env_context,
|
|
3
4
|
setCurrentTaskId
|
|
4
|
-
} from "./roy-agent-core-
|
|
5
|
+
} from "./roy-agent-core-z4486eek.js";
|
|
5
6
|
import {
|
|
6
7
|
createLogger,
|
|
7
8
|
init_logger
|
|
@@ -333,6 +334,25 @@ function createTaskTool(taskComponent) {
|
|
|
333
334
|
rather than rejected, to preserve backward compatibility. The
|
|
334
335
|
auto-injection of \`created_at\` / \`worktree_path\` is best-effort.
|
|
335
336
|
|
|
337
|
+
## Task Binding Inheritance (Task #4023)
|
|
338
|
+
|
|
339
|
+
When this tool is called from inside a per-task group chat, the
|
|
340
|
+
event-source handler resolves the chat↔task binding and injects the
|
|
341
|
+
bound task id into \`EnvContext.parentTaskId\`. This tool reads that
|
|
342
|
+
value and uses it as the default \`parent_task_id\`, so the LLM
|
|
343
|
+
doesn't need to know the task tree to attach subtasks to the
|
|
344
|
+
correct parent.
|
|
345
|
+
|
|
346
|
+
Priority order (highest → lowest):
|
|
347
|
+
1. Caller's explicit \`parent_task_id\` (always wins)
|
|
348
|
+
2. \`EnvContext.parentTaskId\` injected from chat binding
|
|
349
|
+
3. No parent (creates a root task, as before)
|
|
350
|
+
|
|
351
|
+
When the env-injected parent doesn't exist in the DB, the tool
|
|
352
|
+
fails fast (does not silently create an orphan). When the
|
|
353
|
+
env-injected value is 0 / negative / non-integer, it's treated as
|
|
354
|
+
missing — only positive integers are honored.
|
|
355
|
+
|
|
336
356
|
`,
|
|
337
357
|
parameters: CreateTaskToolSchema,
|
|
338
358
|
execute: async (args, ctx) => {
|
|
@@ -340,12 +360,14 @@ function createTaskTool(taskComponent) {
|
|
|
340
360
|
const sessionId = ctx.session_id || "unknown";
|
|
341
361
|
const detectedWorktree = detectWorktree();
|
|
342
362
|
let enrichedContext = params.context;
|
|
363
|
+
const envParentTaskId = getEnvContextOrEmpty().parentTaskId;
|
|
364
|
+
const effectiveParentTaskId = params.parent_task_id !== undefined && params.parent_task_id !== null ? params.parent_task_id : envParentTaskId !== undefined && envParentTaskId !== null && Number.isInteger(envParentTaskId) && envParentTaskId > 0 ? envParentTaskId : undefined;
|
|
343
365
|
let inheritedProjectPath = params.project_path && params.project_path.trim() !== "" ? params.project_path : undefined;
|
|
344
366
|
let inheritedTags = params.tags;
|
|
345
367
|
let inheritedContext;
|
|
346
|
-
if (
|
|
368
|
+
if (effectiveParentTaskId !== undefined) {
|
|
347
369
|
try {
|
|
348
|
-
const parent = await taskComponent.getTask(
|
|
370
|
+
const parent = await taskComponent.getTask(effectiveParentTaskId);
|
|
349
371
|
if (parent) {
|
|
350
372
|
const inherited = inheritChildContext({
|
|
351
373
|
parent: {
|
|
@@ -370,7 +392,7 @@ function createTaskTool(taskComponent) {
|
|
|
370
392
|
inheritedContext = inherited.context;
|
|
371
393
|
}
|
|
372
394
|
} catch (err) {
|
|
373
|
-
logger2.debug(`[task_create] failed to pre-load parent #${
|
|
395
|
+
logger2.debug(`[task_create] failed to pre-load parent #${effectiveParentTaskId} for context inheritance: ${err instanceof Error ? err.message : String(err)}`);
|
|
374
396
|
}
|
|
375
397
|
}
|
|
376
398
|
try {
|
|
@@ -399,7 +421,7 @@ function createTaskTool(taskComponent) {
|
|
|
399
421
|
}
|
|
400
422
|
try {
|
|
401
423
|
const task = await taskComponent.createTask({
|
|
402
|
-
parent_task_id:
|
|
424
|
+
parent_task_id: effectiveParentTaskId,
|
|
403
425
|
title: params.title,
|
|
404
426
|
description: params.description,
|
|
405
427
|
priority: params.priority,
|
|
@@ -19,17 +19,17 @@ import {
|
|
|
19
19
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
20
20
|
import {
|
|
21
21
|
BaseComponent
|
|
22
|
-
} from "./roy-agent-core-
|
|
22
|
+
} from "./roy-agent-core-yv4anf1c.js";
|
|
23
23
|
import {
|
|
24
24
|
LLMHookPoints,
|
|
25
25
|
globalHookManager,
|
|
26
26
|
init_global_hook_manager
|
|
27
|
-
} from "./roy-agent-core-
|
|
27
|
+
} from "./roy-agent-core-yjyvwxs4.js";
|
|
28
28
|
import {
|
|
29
29
|
TracedAs,
|
|
30
30
|
init_decorator,
|
|
31
31
|
wrapFunction
|
|
32
|
-
} from "./roy-agent-core-
|
|
32
|
+
} from "./roy-agent-core-a9pbda78.js";
|
|
33
33
|
import {
|
|
34
34
|
createLogger,
|
|
35
35
|
init_logger
|
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
import {
|
|
10
10
|
globalHookManager,
|
|
11
11
|
init_global_hook_manager
|
|
12
|
-
} from "./roy-agent-core-
|
|
12
|
+
} from "./roy-agent-core-yjyvwxs4.js";
|
|
13
13
|
import {
|
|
14
14
|
TracedAs,
|
|
15
15
|
init_decorator,
|
|
16
16
|
wrapFunction
|
|
17
|
-
} from "./roy-agent-core-
|
|
17
|
+
} from "./roy-agent-core-a9pbda78.js";
|
|
18
18
|
import {
|
|
19
19
|
createLogger,
|
|
20
20
|
init_logger
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
4
4
|
import {
|
|
5
5
|
BaseComponent
|
|
6
|
-
} from "./roy-agent-core-
|
|
6
|
+
} from "./roy-agent-core-yv4anf1c.js";
|
|
7
7
|
import {
|
|
8
8
|
init_decorator
|
|
9
|
-
} from "./roy-agent-core-
|
|
9
|
+
} from "./roy-agent-core-a9pbda78.js";
|
|
10
10
|
import {
|
|
11
11
|
createLogger,
|
|
12
12
|
getTracerProvider,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
AgentComponentAdapter,
|
|
9
9
|
init_agent_component_adapter
|
|
10
|
-
} from "./roy-agent-core-
|
|
10
|
+
} from "./roy-agent-core-p0c98phj.js";
|
|
11
11
|
import {
|
|
12
12
|
PythonCallNode,
|
|
13
13
|
SkillNode,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
init_skill_node,
|
|
18
18
|
init_tool_node,
|
|
19
19
|
init_workflow_node
|
|
20
|
-
} from "./roy-agent-core-
|
|
20
|
+
} from "./roy-agent-core-yjjqm4ww.js";
|
|
21
21
|
import {
|
|
22
22
|
WORKFLOW_SUBMIT_OUTPUT_TOOL_NAME,
|
|
23
23
|
init_json_schema_to_zod,
|
|
@@ -29,11 +29,11 @@ import {
|
|
|
29
29
|
import {
|
|
30
30
|
TemplateResolver,
|
|
31
31
|
init_template_resolver
|
|
32
|
-
} from "./roy-agent-core-
|
|
32
|
+
} from "./roy-agent-core-333apxaa.js";
|
|
33
33
|
import {
|
|
34
34
|
DAGManager,
|
|
35
35
|
init_dag_manager
|
|
36
|
-
} from "./roy-agent-core-
|
|
36
|
+
} from "./roy-agent-core-tm57tmds.js";
|
|
37
37
|
import {
|
|
38
38
|
WorkflowError,
|
|
39
39
|
createWorkflowEvent,
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
import {
|
|
50
50
|
TracedAs,
|
|
51
51
|
init_decorator
|
|
52
|
-
} from "./roy-agent-core-
|
|
52
|
+
} from "./roy-agent-core-a9pbda78.js";
|
|
53
53
|
import {
|
|
54
54
|
createLogger,
|
|
55
55
|
init_logger
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
truncateOutputInline
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-wfpzny0h.js";
|
|
4
4
|
import {
|
|
5
5
|
AgentRegistry
|
|
6
|
-
} from "./roy-agent-core-
|
|
6
|
+
} from "./roy-agent-core-za09t5g3.js";
|
|
7
7
|
import {
|
|
8
8
|
enqueueToAddFakeUserMessage
|
|
9
|
-
} from "./roy-agent-core-
|
|
9
|
+
} from "./roy-agent-core-4cj6hram.js";
|
|
10
10
|
import {
|
|
11
11
|
SessionMessageConverter
|
|
12
12
|
} from "./roy-agent-core-djdwq743.js";
|
|
@@ -29,23 +29,23 @@ import {
|
|
|
29
29
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
30
30
|
import {
|
|
31
31
|
BaseComponent
|
|
32
|
-
} from "./roy-agent-core-
|
|
32
|
+
} from "./roy-agent-core-yv4anf1c.js";
|
|
33
33
|
import {
|
|
34
34
|
globalHookManager,
|
|
35
35
|
init_global_hook_manager
|
|
36
|
-
} from "./roy-agent-core-
|
|
36
|
+
} from "./roy-agent-core-yjyvwxs4.js";
|
|
37
37
|
import {
|
|
38
38
|
init_context
|
|
39
|
-
} from "./roy-agent-core-
|
|
39
|
+
} from "./roy-agent-core-ff2ssff5.js";
|
|
40
40
|
import {
|
|
41
41
|
getCurrentTaskId,
|
|
42
42
|
getEnvContext,
|
|
43
43
|
runWithEnvContextAsync
|
|
44
|
-
} from "./roy-agent-core-
|
|
44
|
+
} from "./roy-agent-core-z4486eek.js";
|
|
45
45
|
import {
|
|
46
46
|
TracedAs,
|
|
47
47
|
init_decorator
|
|
48
|
-
} from "./roy-agent-core-
|
|
48
|
+
} from "./roy-agent-core-a9pbda78.js";
|
|
49
49
|
import {
|
|
50
50
|
createLogger,
|
|
51
51
|
init_logger
|