@ai-setting/roy-agent-core 1.7.37 → 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.
Files changed (82) hide show
  1. package/dist/config/index.js +7 -7
  2. package/dist/env/agent/index.js +10 -10
  3. package/dist/env/commands/index.js +7 -7
  4. package/dist/env/context/index.js +7 -3
  5. package/dist/env/debug/index.js +7 -7
  6. package/dist/env/event-source/index.js +24 -14
  7. package/dist/env/hook/index.js +5 -5
  8. package/dist/env/index.js +33 -32
  9. package/dist/env/llm/index.js +7 -7
  10. package/dist/env/log-trace/index.js +7 -7
  11. package/dist/env/mcp/index.js +7 -7
  12. package/dist/env/memory/index.js +7 -7
  13. package/dist/env/plugin/index.js +7 -7
  14. package/dist/env/prompt/index.js +7 -7
  15. package/dist/env/session/index.js +7 -7
  16. package/dist/env/skill/index.js +7 -7
  17. package/dist/env/task/delegate/index.js +7 -6
  18. package/dist/env/task/index.js +12 -11
  19. package/dist/env/task/plugins/index.js +7 -7
  20. package/dist/env/task/storage/index.js +2 -2
  21. package/dist/env/task/tools/index.js +3 -3
  22. package/dist/env/tool/built-in/index.js +2 -2
  23. package/dist/env/tool/index.js +8 -8
  24. package/dist/env/workflow/engine/index.js +9 -9
  25. package/dist/env/workflow/index.js +17 -17
  26. package/dist/env/workflow/nodes/index.js +2 -2
  27. package/dist/env/workflow/service/index.js +2 -2
  28. package/dist/env/workflow/storage/index.js +3 -3
  29. package/dist/env/workflow/tools/index.js +11 -11
  30. package/dist/env/workflow/utils/index.js +4 -4
  31. package/dist/index.js +53 -43
  32. package/dist/shared/@ai-setting/{roy-agent-core-yf0ex8y1.js → roy-agent-core-333apxaa.js} +1 -1
  33. package/dist/shared/@ai-setting/{roy-agent-core-pxyyrxnn.js → roy-agent-core-34je386q.js} +4 -4
  34. package/dist/shared/@ai-setting/{roy-agent-core-q8vew3zh.js → roy-agent-core-3h7ajma5.js} +2 -2
  35. package/dist/shared/@ai-setting/{roy-agent-core-e4v61k3j.js → roy-agent-core-47wrv4ex.js} +94 -32
  36. package/dist/shared/@ai-setting/{roy-agent-core-9drbkjfr.js → roy-agent-core-4cj6hram.js} +1 -1
  37. package/dist/shared/@ai-setting/{roy-agent-core-fytqnxrd.js → roy-agent-core-4cqcdk7k.js} +3 -3
  38. package/dist/shared/@ai-setting/{roy-agent-core-zda3rfr3.js → roy-agent-core-4kbvfnn1.js} +54 -5
  39. package/dist/shared/@ai-setting/{roy-agent-core-bb57xjfh.js → roy-agent-core-5exnp10h.js} +11 -8
  40. package/dist/shared/@ai-setting/{roy-agent-core-jq7g5nxz.js → roy-agent-core-5j4awbgc.js} +3 -3
  41. package/dist/shared/@ai-setting/{roy-agent-core-1vj7dd14.js → roy-agent-core-6mnwqcqf.js} +1 -1
  42. package/dist/shared/@ai-setting/{roy-agent-core-wgttzq8e.js → roy-agent-core-6vbgswjw.js} +1 -1
  43. package/dist/shared/@ai-setting/{roy-agent-core-1q6gjxba.js → roy-agent-core-6vwf03cz.js} +10 -7
  44. package/dist/shared/@ai-setting/{roy-agent-core-a8zf7ts4.js → roy-agent-core-754b0078.js} +5 -5
  45. package/dist/shared/@ai-setting/{roy-agent-core-j9ejsmsj.js → roy-agent-core-8nv07zgr.js} +1 -1
  46. package/dist/shared/@ai-setting/{roy-agent-core-yw07bvqz.js → roy-agent-core-9cqpdrnk.js} +3 -3
  47. package/dist/shared/@ai-setting/{roy-agent-core-q3zvkbj6.js → roy-agent-core-9qn92jhf.js} +2 -2
  48. package/dist/shared/@ai-setting/{roy-agent-core-m7dppx2p.js → roy-agent-core-9t675te0.js} +2 -2
  49. package/dist/shared/@ai-setting/{roy-agent-core-fym6zz5a.js → roy-agent-core-a236mps6.js} +2 -2
  50. package/dist/shared/@ai-setting/{roy-agent-core-qhjm0bxm.js → roy-agent-core-a9pbda78.js} +23 -13
  51. package/dist/shared/@ai-setting/{roy-agent-core-s53yya0w.js → roy-agent-core-asxe1nt4.js} +5 -5
  52. package/dist/shared/@ai-setting/{roy-agent-core-em8618g6.js → roy-agent-core-cazvr63z.js} +237 -14
  53. package/dist/shared/@ai-setting/{roy-agent-core-ds5f75pg.js → roy-agent-core-ck60j1q9.js} +19 -1
  54. package/dist/shared/@ai-setting/{roy-agent-core-w457586k.js → roy-agent-core-cw89yj9d.js} +1 -1
  55. package/dist/shared/@ai-setting/{roy-agent-core-462v5d24.js → roy-agent-core-cysnmvcy.js} +1 -1
  56. package/dist/shared/@ai-setting/{roy-agent-core-88tfzaxg.js → roy-agent-core-f18jk3cw.js} +1 -1
  57. package/dist/shared/@ai-setting/{roy-agent-core-qz9jb9sp.js → roy-agent-core-hkj5v9xq.js} +1 -1
  58. package/dist/shared/@ai-setting/{roy-agent-core-dzfyjzgw.js → roy-agent-core-jadrj0bz.js} +27 -2
  59. package/dist/shared/@ai-setting/{roy-agent-core-dfay0w56.js → roy-agent-core-jawzpf5k.js} +2 -2
  60. package/dist/shared/@ai-setting/{roy-agent-core-zekkw27m.js → roy-agent-core-jg8cv1f7.js} +128 -29
  61. package/dist/shared/@ai-setting/{roy-agent-core-mwaesrpc.js → roy-agent-core-jjw7xcxv.js} +4 -4
  62. package/dist/shared/@ai-setting/{roy-agent-core-2qke91fm.js → roy-agent-core-krppch0s.js} +3 -3
  63. package/dist/shared/@ai-setting/{roy-agent-core-mxwaq8ey.js → roy-agent-core-m3ffkexb.js} +13 -13
  64. package/dist/shared/@ai-setting/{roy-agent-core-2wbdfrtg.js → roy-agent-core-n1ceexfz.js} +1 -1
  65. package/dist/shared/@ai-setting/{roy-agent-core-1btakphh.js → roy-agent-core-pc8x07p0.js} +1 -1
  66. package/dist/shared/@ai-setting/{roy-agent-core-d5gwqrr5.js → roy-agent-core-pd0exvnq.js} +1 -1
  67. package/dist/shared/@ai-setting/{roy-agent-core-1nvqn17p.js → roy-agent-core-qfktfbrr.js} +4 -4
  68. package/dist/shared/@ai-setting/{roy-agent-core-x4wev4rn.js → roy-agent-core-rczz7e81.js} +5 -5
  69. package/dist/shared/@ai-setting/{roy-agent-core-e3qjt852.js → roy-agent-core-rgpkygbc.js} +1 -1
  70. package/dist/shared/@ai-setting/{roy-agent-core-rx8whb18.js → roy-agent-core-s44egzrh.js} +35 -4
  71. package/dist/shared/@ai-setting/{roy-agent-core-k5csz66y.js → roy-agent-core-tm57tmds.js} +1 -1
  72. package/dist/shared/@ai-setting/{roy-agent-core-qhtejtpc.js → roy-agent-core-vsrfzaze.js} +1 -1
  73. package/dist/shared/@ai-setting/{roy-agent-core-whta3f53.js → roy-agent-core-wn59p0zw.js} +1 -1
  74. package/dist/shared/@ai-setting/{roy-agent-core-mdaew65f.js → roy-agent-core-wybj8emq.js} +1 -1
  75. package/dist/shared/@ai-setting/{roy-agent-core-ddq5hcp5.js → roy-agent-core-x6c45yqd.js} +3 -1
  76. package/dist/shared/@ai-setting/roy-agent-core-xyys5m1a.js +159 -0
  77. package/dist/shared/@ai-setting/{roy-agent-core-wphva2vs.js → roy-agent-core-y1n63tse.js} +2 -2
  78. package/dist/shared/@ai-setting/{roy-agent-core-jcdsghyr.js → roy-agent-core-yjjqm4ww.js} +1 -1
  79. package/dist/shared/@ai-setting/{roy-agent-core-n3pwkwjh.js → roy-agent-core-za09t5g3.js} +1 -1
  80. package/dist/shared/@ai-setting/{roy-agent-core-n82acszf.js → roy-agent-core-zbb3sk72.js} +17 -3
  81. package/package.json +1 -1
  82. /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-e4v61k3j.js";
11
+ } from "./roy-agent-core-47wrv4ex.js";
6
12
  import {
7
13
  normalizeLarkAtMentions
8
14
  } from "./roy-agent-core-rmn29nrh.js";
@@ -11,22 +17,24 @@ import {
11
17
  } from "./roy-agent-core-7hh0brvs.js";
12
18
  import {
13
19
  BaseComponent
14
- } from "./roy-agent-core-m7dppx2p.js";
20
+ } from "./roy-agent-core-9t675te0.js";
15
21
  import {
16
22
  globalHookManager,
17
23
  init_global_hook_manager
18
- } from "./roy-agent-core-fym6zz5a.js";
24
+ } from "./roy-agent-core-a236mps6.js";
19
25
  import {
20
26
  init_context
21
- } from "./roy-agent-core-whta3f53.js";
27
+ } from "./roy-agent-core-wn59p0zw.js";
22
28
  import {
23
29
  createEnvContext,
30
+ normalizeParentTaskId,
24
31
  runWithEnvContext
25
- } from "./roy-agent-core-n82acszf.js";
32
+ } from "./roy-agent-core-zbb3sk72.js";
26
33
  import {
27
34
  TracedAs,
28
- init_decorator
29
- } from "./roy-agent-core-qhjm0bxm.js";
35
+ init_decorator,
36
+ wrapFunction
37
+ } from "./roy-agent-core-a9pbda78.js";
30
38
  import {
31
39
  createLogger,
32
40
  getTracerProvider,
@@ -593,8 +601,8 @@ var bountyIMHandler = {
593
601
  };
594
602
 
595
603
  // src/env/event-source/event-source-handlers.ts
596
- init_global_hook_manager();
597
604
  import { spawn as spawn2 } from "child_process";
605
+ init_global_hook_manager();
598
606
  init_context();
599
607
 
600
608
  // src/env/event-source/bounty-cli-handler.ts
@@ -1151,6 +1159,7 @@ class LarkCliInstance {
1151
1159
  registerPluginHooks(plugin) {
1152
1160
  const pluginName = plugin.name || "unknown";
1153
1161
  this.injectTaskUpdater(plugin);
1162
+ this.injectTaskGetter(plugin);
1154
1163
  this.injectSessionComponent(plugin);
1155
1164
  if (typeof plugin.init === "function") {
1156
1165
  const pluginEnv = {
@@ -1237,6 +1246,25 @@ class LarkCliInstance {
1237
1246
  };
1238
1247
  plugin.setTaskUpdater(taskUpdater);
1239
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
+ }
1240
1268
  injectSessionComponent(plugin) {
1241
1269
  if (typeof plugin.setSessionComponent !== "function") {
1242
1270
  return;
@@ -1366,9 +1394,35 @@ class LarkCliInstance {
1366
1394
  };
1367
1395
  const { metadata, replyChannel, recommendedAction } = extractMetadata(enrichedEvent, eventType);
1368
1396
  const parentTaskId = await this.resolveChatTaskBinding(metadata?.chatId);
1397
+ const userId = this.extractUserId(rawEvent);
1398
+ let triggerEventId;
1399
+ const sharedStore = getSharedEventStore();
1400
+ if (sharedStore && larkCliHandler.emitTriggerEvent) {
1401
+ try {
1402
+ triggerEventId = await larkCliHandler.emitTriggerEvent({
1403
+ senderId: userId,
1404
+ text: undefined,
1405
+ metadata: {
1406
+ eventType,
1407
+ appId: metadata?.appId,
1408
+ chatId: metadata?.chatId,
1409
+ chatType: metadata?.chatType,
1410
+ messageId: metadata?.messageId,
1411
+ messageType: metadata?.messageType,
1412
+ senderId: userId,
1413
+ tenantKey: metadata?.tenantKey,
1414
+ profile: this.config.profile
1415
+ },
1416
+ rawEvent
1417
+ }, sharedStore);
1418
+ } catch (err) {
1419
+ console.error(`[LarkCliInstance] emitTriggerEvent failed: ${err instanceof Error ? err.message : String(err)}`);
1420
+ }
1421
+ }
1369
1422
  const message = JSON.stringify({
1370
1423
  rawData,
1371
- recommendedAction
1424
+ recommendedAction,
1425
+ ...triggerEventId ? { triggerEventId } : {}
1372
1426
  });
1373
1427
  const timestamp = Date.now();
1374
1428
  const plugins = this.config.handleRule?.plugins || [];
@@ -1389,7 +1443,8 @@ class LarkCliInstance {
1389
1443
  pluginEnabled,
1390
1444
  replyChannel,
1391
1445
  agent,
1392
- parentTaskId: parentTaskId ?? undefined
1446
+ parentTaskId: parentTaskId ?? undefined,
1447
+ ...triggerEventId ? { triggerEventId } : {}
1393
1448
  },
1394
1449
  payload: {
1395
1450
  sourceId: this.config.id,
@@ -1400,10 +1455,10 @@ class LarkCliInstance {
1400
1455
  replyChannel,
1401
1456
  recommendedAction,
1402
1457
  timestamp,
1403
- parentTaskId: parentTaskId ?? undefined
1458
+ parentTaskId: parentTaskId ?? undefined,
1459
+ ...triggerEventId ? { triggerEventId } : {}
1404
1460
  }
1405
1461
  };
1406
- const userId = this.extractUserId(rawEvent);
1407
1462
  const envReplyChannel = this.buildReplyChannel(replyChannel);
1408
1463
  const larkMessageId = replyChannel?.messageId ?? metadata?.messageId;
1409
1464
  const envContext = createEnvContext({
@@ -1426,7 +1481,8 @@ class LarkCliInstance {
1426
1481
  } : undefined,
1427
1482
  replyChannel: envReplyChannel,
1428
1483
  pluginEnabled,
1429
- plugins
1484
+ plugins,
1485
+ parentTaskId: normalizeParentTaskId(parentTaskId)
1430
1486
  });
1431
1487
  runWithEnvContext(envContext, () => {
1432
1488
  this.eventHandler?.(evt);
@@ -1553,6 +1609,15 @@ __legacyDecorateClassTS([
1553
1609
  __legacyDecorateClassTS([
1554
1610
  TracedAs("lark-cli.registerPluginHooks", { recordParams: true, log: true })
1555
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);
1556
1621
  __legacyDecorateClassTS([
1557
1622
  TracedAs("lark-cli.handleEvent", { recordParams: true, log: true })
1558
1623
  ], LarkCliInstance.prototype, "handleEvent", null);
@@ -1564,8 +1629,160 @@ var larkCliHandler = {
1564
1629
  },
1565
1630
  createInstance(config) {
1566
1631
  return new LarkCliInstance(config);
1632
+ },
1633
+ async emitTriggerEvent(payload, store) {
1634
+ const eventId = await store.insertTriggerEvent(payload, "lark-cli");
1635
+ logger.info(`[larkCliHandler] emitTriggerEvent: id=${eventId}`, {
1636
+ chatId: payload.metadata?.chatId,
1637
+ senderId: payload.senderId
1638
+ });
1639
+ return eventId;
1640
+ },
1641
+ async replyMessage(input) {
1642
+ const runner = getLarkCliRunner();
1643
+ const profileFlag = input.profile ? `--profile ${input.profile} ` : "";
1644
+ const msgType = input.msgType ?? "text";
1645
+ const safeContent = input.content.replace(/'/g, `'\\''`);
1646
+ const command = `lark-cli ${profileFlag}im +messages-reply ` + `--message-id ${input.messageId} ` + `--chat-id ${input.chatId} ` + `--as bot ` + `--msg-type ${msgType} ` + `--content '${safeContent}'`;
1647
+ try {
1648
+ const result = await runner.run(command);
1649
+ if (result.code !== 0) {
1650
+ logger.error(`[larkCliHandler] replyMessage non-zero exit`, {
1651
+ code: result.code,
1652
+ stderr: result.stderr
1653
+ });
1654
+ return { success: false, error: result.stderr || `exit ${result.code}` };
1655
+ }
1656
+ let replyMessageId;
1657
+ try {
1658
+ const parsed = JSON.parse(result.stdout);
1659
+ replyMessageId = parsed?.data?.message_id ?? parsed?.message_id;
1660
+ } catch {}
1661
+ return { success: true, messageId: replyMessageId };
1662
+ } catch (err) {
1663
+ const errMsg = err instanceof Error ? err.message : String(err);
1664
+ logger.error(`[larkCliHandler] replyMessage spawn error`, { error: errMsg });
1665
+ return { success: false, error: errMsg };
1666
+ }
1667
+ },
1668
+ extractReplyContext(event, profile) {
1669
+ return {
1670
+ esType: "lark-cli",
1671
+ chatId: event.metadata?.chatId ?? "",
1672
+ messageId: event.metadata?.messageId ?? "",
1673
+ senderOpenId: event.metadata?.senderId ?? event.senderId,
1674
+ tenantKey: event.metadata?.tenantKey ?? undefined,
1675
+ profile: profile ?? event.metadata?.profile ?? undefined
1676
+ };
1677
+ },
1678
+ buildNotifyHandlePrompt(input) {
1679
+ const ctx = this.extractReplyContext?.(input.triggerEvent, input.profile) ?? {
1680
+ esType: "lark-cli",
1681
+ chatId: input.triggerEvent.metadata?.chatId ?? "",
1682
+ messageId: input.triggerEvent.metadata?.messageId ?? "",
1683
+ senderOpenId: input.triggerEvent.metadata?.senderId ?? input.triggerEvent.senderId,
1684
+ profile: input.profile
1685
+ };
1686
+ const profileFlag = ctx.profile ? `--profile ${ctx.profile} ` : "";
1687
+ const desc = input.notifyEvent.description ?? "(未命名任务)";
1688
+ const result = input.subAgentResult.summary ?? input.notifyEvent.result ?? "";
1689
+ const promptText = `
1690
+ ## Notify Event: ${input.notifyEvent.type}
1691
+
1692
+ Sub-agent 完成了 Task #${input.notifyEvent.taskId ?? "?"}「${desc}」。
1693
+
1694
+ ### Trigger event(原始飞书消息,来自 EventStore 反查)
1695
+ - ES: lark-cli
1696
+ - **chatId: ${ctx.chatId}** ← 关键!必须回复到这里
1697
+ - **messageId: ${ctx.messageId}** ← 必须 reply 这条
1698
+ - sender: ${ctx.senderOpenId}
1699
+ ${ctx.profile ? `- profile: ${ctx.profile} ← 调用 lark-cli 必须带 --profile
1700
+ ` : ""}
1701
+ ### Sub-agent 输出
1702
+ ${result}
1703
+
1704
+ ### \uD83D\uDC49 你应该这样做
1705
+ 用 lark-cli 调 im +messages-reply:
1706
+ lark-cli ${profileFlag}im +messages-reply --message-id ${ctx.messageId} --chat-id ${ctx.chatId} --as bot --msg-type text --content '<你的回复>'
1707
+
1708
+ ⚠️ 不要 fallback 到 lastReplyChannel 或 metadata.replyChannel — 那个 chatId
1709
+ 可能跟用户原始消息的 chatId 不一致(参见 #4035/#4038/#4039 bug)。
1710
+ `;
1711
+ const systemHint = `回复必须用 lark-cli im +messages-reply(${profileFlag.trim() ? `带 ${profileFlag.trim()};` : ""}` + `chatId=${ctx.chatId} / messageId=${ctx.messageId} 来自 trigger event,不要 fallback。`;
1712
+ return { promptText, systemHint };
1713
+ },
1714
+ setRunner(runner) {
1715
+ setLarkCliRunner(runner);
1716
+ },
1717
+ async postProcessNotifyEvent(input) {
1718
+ try {
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
+ }
1724
+ for (const chatId of chats) {
1725
+ try {
1726
+ await sendMarkdownToChat(chatId, input.formattedPrompt, input.profile);
1727
+ } catch (err) {
1728
+ const errMsg = err instanceof Error ? err.message : String(err);
1729
+ logger.error(`[larkCliHandler] postProcessNotifyEvent: send failed for chatId=${chatId}`, { error: errMsg });
1730
+ }
1731
+ }
1732
+ } catch (err) {
1733
+ const errMsg = err instanceof Error ? err.message : String(err);
1734
+ logger.error(`[larkCliHandler] postProcessNotifyEvent failed`, {
1735
+ error: errMsg
1736
+ });
1737
+ }
1567
1738
  }
1568
1739
  };
1740
+ if (larkCliHandler.extractReplyContext) {
1741
+ larkCliHandler.extractReplyContext = wrapFunction(larkCliHandler.extractReplyContext, "extractReplyContext", { recordParams: true, recordResult: true, recordError: true });
1742
+ }
1743
+ if (larkCliHandler.buildNotifyHandlePrompt) {
1744
+ larkCliHandler.buildNotifyHandlePrompt = wrapFunction(larkCliHandler.buildNotifyHandlePrompt, "buildNotifyHandlePrompt", { recordParams: true, recordResult: false, recordError: true });
1745
+ }
1746
+ if (larkCliHandler.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
+ });
1757
+ }
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);
1765
+ }
1766
+ }
1767
+ return out;
1768
+ }
1769
+ async function sendMarkdownToChat(chatId, markdown, profile) {
1770
+ const profileFlag = profile ? `--profile ${profile} ` : "";
1771
+ const runner = getLarkCliRunner();
1772
+ const safeMd = markdown.replace(/'/g, `'\\''`);
1773
+ const command = `lark-cli ${profileFlag}im +messages-send ` + `--chat-id "${chatId}" --as bot --markdown '${safeMd}'`;
1774
+ const result = await runner.run(command);
1775
+ if (result.code !== 0) {
1776
+ throw new Error(`messages-send exit ${result.code}: ${result.stderr || "(no stderr)"}`);
1777
+ }
1778
+ }
1779
+ var _larkCliRunner = defaultLarkCliRunner;
1780
+ function getLarkCliRunner() {
1781
+ return _larkCliRunner;
1782
+ }
1783
+ function setLarkCliRunner(runner) {
1784
+ _larkCliRunner = runner;
1785
+ }
1569
1786
  var builtInHandlers = [
1570
1787
  larkCliHandler,
1571
1788
  timerHandler,
@@ -1672,7 +1889,7 @@ class EventSourceComponent extends BaseComponent {
1672
1889
  }
1673
1890
  }
1674
1891
  async executeInitHooks() {
1675
- const { EventSourceInitHooks } = await import("./roy-agent-core-ddq5hcp5.js");
1892
+ const { EventSourceInitHooks } = await import("./roy-agent-core-x6c45yqd.js");
1676
1893
  await EventSourceInitHooks.execute(this);
1677
1894
  }
1678
1895
  registerHandler(handler) {
@@ -2019,5 +2236,11 @@ class EventSourceComponent extends BaseComponent {
2019
2236
  __legacyDecorateClassTS([
2020
2237
  TracedAs("event-source.update", { recordParams: false, log: false })
2021
2238
  ], EventSourceComponent.prototype, "update", null);
2239
+ __legacyDecorateClassTS([
2240
+ TracedAs("event_source.start", { recordParams: true, recordResult: false })
2241
+ ], EventSourceComponent.prototype, "startSource", null);
2242
+ __legacyDecorateClassTS([
2243
+ TracedAs("event_source.stop", { recordParams: true, recordResult: false })
2244
+ ], EventSourceComponent.prototype, "stopSource", null);
2022
2245
 
2023
2246
  export { TimerInstance, timerHandler, buildDefaultBountyIMSystemPrompt, resolveBountyIMSystemPrompt, BountyIMInstance, bountyIMHandler, extractMetadata, larkCliHandler, builtInHandlers, getBuiltInHandler, EventSourceComponent };
@@ -1,3 +1,7 @@
1
+ import {
2
+ __require
3
+ } from "./roy-agent-core-fs0mn2jk.js";
4
+
1
5
  // src/env/event-source/types.ts
2
6
  var BUILT_IN_EVENT_SOURCE_TYPES = {
3
7
  LARK_CLI: "lark-cli",
@@ -5,6 +9,20 @@ var BUILT_IN_EVENT_SOURCE_TYPES = {
5
9
  BOUNTY_IM: "bounty-im"
6
10
  };
7
11
  var BUILT_IN_EVENT_SOURCE_TYPE_LIST = Object.values(BUILT_IN_EVENT_SOURCE_TYPES);
12
+ var defaultLarkCliRunner = {
13
+ async run(command) {
14
+ const { spawn } = await import("node:child_process");
15
+ return new Promise((resolve, reject) => {
16
+ const proc = spawn("sh", ["-c", command], { stdio: ["ignore", "pipe", "pipe"] });
17
+ let stdout = "";
18
+ let stderr = "";
19
+ proc.stdout.on("data", (d) => stdout += d.toString());
20
+ proc.stderr.on("data", (d) => stderr += d.toString());
21
+ proc.on("close", (code) => resolve({ stdout, stderr, code: code ?? 0 }));
22
+ proc.on("error", reject);
23
+ });
24
+ }
25
+ };
8
26
 
9
27
  class EventSourceInitHooks {
10
28
  static hooks = new Map;
@@ -63,4 +81,4 @@ function validateEventSourceConfig(config, handler) {
63
81
  return errors;
64
82
  }
65
83
 
66
- export { BUILT_IN_EVENT_SOURCE_TYPES, BUILT_IN_EVENT_SOURCE_TYPE_LIST, EventSourceInitHooks, isBuiltInEventSourceType, isValidEventSourceType, getDefaultConfigForType, validateEventSourceConfig };
84
+ export { BUILT_IN_EVENT_SOURCE_TYPES, BUILT_IN_EVENT_SOURCE_TYPE_LIST, defaultLarkCliRunner, EventSourceInitHooks, isBuiltInEventSourceType, isValidEventSourceType, getDefaultConfigForType, validateEventSourceConfig };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  init_global_hook_manager,
3
3
  init_hook_manager
4
- } from "./roy-agent-core-fym6zz5a.js";
4
+ } from "./roy-agent-core-a236mps6.js";
5
5
 
6
6
  // src/env/hook/types.ts
7
7
  function createHook(meta, fn) {
@@ -4,7 +4,7 @@ import {
4
4
  } from "./roy-agent-core-rvv6ydff.js";
5
5
  import {
6
6
  BaseComponent
7
- } from "./roy-agent-core-m7dppx2p.js";
7
+ } from "./roy-agent-core-9t675te0.js";
8
8
  import {
9
9
  __require
10
10
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -8,7 +8,7 @@ import {
8
8
  } from "./roy-agent-core-qxnbvgwe.js";
9
9
  import {
10
10
  BaseComponent
11
- } from "./roy-agent-core-m7dppx2p.js";
11
+ } from "./roy-agent-core-9t675te0.js";
12
12
  import {
13
13
  __require
14
14
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  TracedAs,
11
11
  init_decorator
12
- } from "./roy-agent-core-qhjm0bxm.js";
12
+ } from "./roy-agent-core-a9pbda78.js";
13
13
  import {
14
14
  createLogger,
15
15
  init_logger
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TracedAs,
3
3
  init_decorator
4
- } from "./roy-agent-core-qhjm0bxm.js";
4
+ } from "./roy-agent-core-a9pbda78.js";
5
5
  import {
6
6
  createLogger,
7
7
  init_logger
@@ -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,
@@ -686,11 +693,29 @@ var init_sqlite_task_store = __esm(() => {
686
693
  createdAt: new Date(row.created_at).toISOString(),
687
694
  updatedAt: new Date(row.updated_at).toISOString(),
688
695
  due_date: row.due_date ? String(row.due_date) : undefined,
689
- tags: row.tags ? JSON.parse(row.tags) : undefined,
696
+ tags: SQLiteTaskStore.parseTagsSafely(row.tags),
690
697
  project_path: String(row.project_path ?? "unknown"),
691
698
  context: row.context
692
699
  };
693
700
  }
701
+ static parseTagsSafely(raw) {
702
+ if (raw === null || raw === undefined || raw === "") {
703
+ return;
704
+ }
705
+ const str = typeof raw === "string" ? raw : String(raw);
706
+ try {
707
+ const parsed = JSON.parse(str);
708
+ if (Array.isArray(parsed)) {
709
+ return parsed;
710
+ }
711
+ if (typeof parsed === "string") {
712
+ return [parsed];
713
+ }
714
+ return;
715
+ } catch {
716
+ return [str];
717
+ }
718
+ }
694
719
  rowToOperation(row) {
695
720
  const milestoneType = row.milestone_type ?? row.action_type;
696
721
  const milestoneTitle = row.milestone_title ?? row.action_title;
@@ -3,10 +3,10 @@ import {
3
3
  } from "./roy-agent-core-7hh0brvs.js";
4
4
  import {
5
5
  BaseComponent
6
- } from "./roy-agent-core-m7dppx2p.js";
6
+ } from "./roy-agent-core-9t675te0.js";
7
7
  import {
8
8
  init_decorator
9
- } from "./roy-agent-core-qhjm0bxm.js";
9
+ } from "./roy-agent-core-a9pbda78.js";
10
10
  import {
11
11
  createLogger,
12
12
  getTracerProvider,