@ai-setting/roy-agent-core 1.7.38 → 1.7.40
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 +9 -9
- package/dist/env/hook/index.js +4 -4
- package/dist/env/index.js +23 -23
- 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 +7 -7
- package/dist/env/session/index.js +6 -6
- package/dist/env/skill/index.js +6 -6
- package/dist/env/task/delegate/index.js +5 -5
- package/dist/env/task/index.js +10 -10
- package/dist/env/task/plugins/index.js +5 -4
- 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 +33 -33
- package/dist/shared/@ai-setting/{roy-agent-core-skqt40yy.js → roy-agent-core-223v204d.js} +213 -134
- 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-mzyzdf33.js → roy-agent-core-4cqcdk7k.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-e02f0ywc.js → roy-agent-core-4m0t4y9w.js} +86 -32
- 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-8xgk89y4.js} +9 -6
- 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-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-wfpzny0h.js → roy-agent-core-jjw7xcxv.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-970btnjh.js → roy-agent-core-ncydpb6b.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-vh10qamt.js → roy-agent-core-p3kp447d.js} +35 -20
- 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-dfnyvxr9.js → roy-agent-core-ts56bz5e.js} +4 -4
- 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-gpf33hn9.js → roy-agent-core-wqbpddyr.js} +109 -45
- 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/dist/shared/@ai-setting/{roy-agent-core-e5pnnzdm.js → roy-agent-core-zmr3jzpe.js} +178 -40
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
13
13
|
import {
|
|
14
14
|
BaseComponent
|
|
15
|
-
} from "./roy-agent-core-
|
|
15
|
+
} from "./roy-agent-core-9t675te0.js";
|
|
16
16
|
import {
|
|
17
17
|
TracedAs,
|
|
18
18
|
init_decorator
|
|
@@ -337,6 +337,23 @@ class SessionComponent extends BaseComponent {
|
|
|
337
337
|
chatBindingCache = new Map;
|
|
338
338
|
static CHAT_BINDING_CACHE_TTL_MS = 60000;
|
|
339
339
|
static CHAT_BINDING_CACHE_MAX = 1000;
|
|
340
|
+
chatBindingLocks = new Map;
|
|
341
|
+
runChatBindingExclusive(chatId, fn) {
|
|
342
|
+
const prev = this.chatBindingLocks.get(chatId) ?? Promise.resolve();
|
|
343
|
+
const run = prev.catch(() => {}).then(() => fn());
|
|
344
|
+
const tail = run.then(() => {
|
|
345
|
+
return;
|
|
346
|
+
}, () => {
|
|
347
|
+
return;
|
|
348
|
+
});
|
|
349
|
+
this.chatBindingLocks.set(chatId, tail);
|
|
350
|
+
tail.then(() => {
|
|
351
|
+
if (this.chatBindingLocks.get(chatId) === tail) {
|
|
352
|
+
this.chatBindingLocks.delete(chatId);
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
return run;
|
|
356
|
+
}
|
|
340
357
|
async upsertChatTaskBinding(opts) {
|
|
341
358
|
if (!opts.chatId || typeof opts.chatId !== "string") {
|
|
342
359
|
throw new Error("upsertChatTaskBinding: chatId is required (non-empty string)");
|
|
@@ -344,6 +361,9 @@ class SessionComponent extends BaseComponent {
|
|
|
344
361
|
if (typeof opts.taskId !== "number" || !Number.isInteger(opts.taskId) || opts.taskId <= 0) {
|
|
345
362
|
throw new Error(`upsertChatTaskBinding: taskId must be a positive integer, got ${JSON.stringify(opts.taskId)}`);
|
|
346
363
|
}
|
|
364
|
+
return this.runChatBindingExclusive(opts.chatId, () => this.upsertChatTaskBindingLocked(opts));
|
|
365
|
+
}
|
|
366
|
+
async upsertChatTaskBindingLocked(opts) {
|
|
347
367
|
const now = new Date().toISOString();
|
|
348
368
|
const desiredStatus = opts.status ?? "ready";
|
|
349
369
|
const existing = await this.getChatTaskBinding(opts.chatId);
|
|
@@ -959,14 +979,25 @@ __legacyDecorateClassTS([
|
|
|
959
979
|
TracedAs("session.upsertChatTaskBinding", {
|
|
960
980
|
recordParams: false,
|
|
961
981
|
recordResult: false,
|
|
962
|
-
log: true
|
|
982
|
+
log: true,
|
|
983
|
+
resultFilter: (binding) => ({
|
|
984
|
+
chatId: binding?.chatId ?? null,
|
|
985
|
+
taskId: binding?.taskId ?? null,
|
|
986
|
+
status: binding?.status ?? null,
|
|
987
|
+
rebindCount: binding?.rebindCount ?? null
|
|
988
|
+
})
|
|
963
989
|
})
|
|
964
990
|
], SessionComponent.prototype, "upsertChatTaskBinding", null);
|
|
965
991
|
__legacyDecorateClassTS([
|
|
966
992
|
TracedAs("session.getChatTaskBinding", {
|
|
967
993
|
recordParams: false,
|
|
968
994
|
recordResult: false,
|
|
969
|
-
log: false
|
|
995
|
+
log: false,
|
|
996
|
+
resultFilter: (binding) => ({
|
|
997
|
+
found: !!binding,
|
|
998
|
+
taskId: binding?.taskId ?? null,
|
|
999
|
+
status: binding?.status ?? null
|
|
1000
|
+
})
|
|
970
1001
|
})
|
|
971
1002
|
], SessionComponent.prototype, "getChatTaskBinding", null);
|
|
972
1003
|
__legacyDecorateClassTS([
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
builtInPrompts
|
|
3
|
-
} from "./roy-agent-core-
|
|
3
|
+
} from "./roy-agent-core-223v204d.js";
|
|
4
4
|
import {
|
|
5
5
|
getXDGPath
|
|
6
6
|
} from "./roy-agent-core-qxnbvgwe.js";
|
|
@@ -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
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defaultLarkCliRunner
|
|
3
3
|
} from "./roy-agent-core-ck60j1q9.js";
|
|
4
|
-
import {
|
|
5
|
-
getSharedEventStore
|
|
6
|
-
} from "./roy-agent-core-xyys5m1a.js";
|
|
7
4
|
import {
|
|
8
5
|
TaskTagPlugin,
|
|
9
6
|
createLarkCliTaskNotifyHook,
|
|
10
7
|
createPerTaskGroupChatPlugin
|
|
11
|
-
} from "./roy-agent-core-
|
|
8
|
+
} from "./roy-agent-core-zmr3jzpe.js";
|
|
9
|
+
import {
|
|
10
|
+
getSharedEventStore
|
|
11
|
+
} from "./roy-agent-core-xyys5m1a.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,9 +1609,45 @@ __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);
|
|
1624
|
+
var NOTIFY_TERMINAL_TYPES = new Set([
|
|
1625
|
+
"task.background.completed",
|
|
1626
|
+
"task.background.failed",
|
|
1627
|
+
"task.background.timeout",
|
|
1628
|
+
"task.background.stopped"
|
|
1629
|
+
]);
|
|
1630
|
+
function describeNotifyEvent(type, taskId, desc) {
|
|
1631
|
+
const actionable = NOTIFY_TERMINAL_TYPES.has(type);
|
|
1632
|
+
switch (type) {
|
|
1633
|
+
case "task.background.completed":
|
|
1634
|
+
return { headline: `Sub-agent 完成了 Task #${taskId}「${desc}」。`, actionable };
|
|
1635
|
+
case "task.background.failed":
|
|
1636
|
+
return { headline: `Sub-agent 执行 Task #${taskId}「${desc}」失败。`, actionable };
|
|
1637
|
+
case "task.background.timeout":
|
|
1638
|
+
return { headline: `Sub-agent 执行 Task #${taskId}「${desc}」超时。`, actionable };
|
|
1639
|
+
case "task.background.stopped":
|
|
1640
|
+
return { headline: `Sub-agent 已停止 Task #${taskId}「${desc}」。`, actionable };
|
|
1641
|
+
case "task.background.ask_user":
|
|
1642
|
+
return { headline: `Sub-agent 在 Task #${taskId}「${desc}」中请求用户输入。`, actionable };
|
|
1643
|
+
case "task.background.started":
|
|
1644
|
+
return { headline: `Sub-agent 已启动 Task #${taskId}「${desc}」(后台运行中)。`, actionable };
|
|
1645
|
+
case "task.background.progress":
|
|
1646
|
+
return { headline: `Sub-agent 仍在执行 Task #${taskId}「${desc}」(进行中)。`, actionable };
|
|
1647
|
+
default:
|
|
1648
|
+
return { headline: `Sub-agent 更新了 Task #${taskId}「${desc}」。`, actionable };
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1593
1651
|
var larkCliHandler = {
|
|
1594
1652
|
type: "lark-cli",
|
|
1595
1653
|
validateConfig(config) {
|
|
@@ -1655,10 +1713,13 @@ var larkCliHandler = {
|
|
|
1655
1713
|
const profileFlag = ctx.profile ? `--profile ${ctx.profile} ` : "";
|
|
1656
1714
|
const desc = input.notifyEvent.description ?? "(未命名任务)";
|
|
1657
1715
|
const result = input.subAgentResult.summary ?? input.notifyEvent.result ?? "";
|
|
1658
|
-
const
|
|
1659
|
-
|
|
1716
|
+
const notifyType = input.notifyEvent.type;
|
|
1717
|
+
const taskId = input.notifyEvent.taskId ?? "?";
|
|
1718
|
+
const { headline, actionable } = describeNotifyEvent(notifyType, taskId, desc);
|
|
1719
|
+
const promptText = actionable ? `
|
|
1720
|
+
## Notify Event: ${notifyType}
|
|
1660
1721
|
|
|
1661
|
-
|
|
1722
|
+
${headline}
|
|
1662
1723
|
|
|
1663
1724
|
### Trigger event(原始飞书消息,来自 EventStore 反查)
|
|
1664
1725
|
- ES: lark-cli
|
|
@@ -1676,8 +1737,20 @@ ${result}
|
|
|
1676
1737
|
|
|
1677
1738
|
⚠️ 不要 fallback 到 lastReplyChannel 或 metadata.replyChannel — 那个 chatId
|
|
1678
1739
|
可能跟用户原始消息的 chatId 不一致(参见 #4035/#4038/#4039 bug)。
|
|
1740
|
+
` : `
|
|
1741
|
+
## Notify Event: ${notifyType}
|
|
1742
|
+
|
|
1743
|
+
${headline}
|
|
1744
|
+
|
|
1745
|
+
### Trigger event
|
|
1746
|
+
- ES: lark-cli
|
|
1747
|
+
- chatId: ${ctx.chatId}
|
|
1748
|
+
- messageId: ${ctx.messageId}
|
|
1749
|
+
|
|
1750
|
+
(这是中间态通知:仅作状态同步,**不要**回复用户,也不要调用 lark-cli 发消息。
|
|
1751
|
+
等收到 task.background.completed / failed / timeout / stopped 终态通知后再回复。)
|
|
1679
1752
|
`;
|
|
1680
|
-
const systemHint = `回复必须用 lark-cli im +messages-reply(${profileFlag.trim() ? `带 ${profileFlag.trim()};` : ""}` + `chatId=${ctx.chatId} / messageId=${ctx.messageId} 来自 trigger event,不要 fallback
|
|
1753
|
+
const systemHint = actionable ? `回复必须用 lark-cli im +messages-reply(${profileFlag.trim() ? `带 ${profileFlag.trim()};` : ""}` + `chatId=${ctx.chatId} / messageId=${ctx.messageId} 来自 trigger event,不要 fallback。` : `这是 ${notifyType} 中间态通知,不要回复用户;仅等待终态通知。`;
|
|
1681
1754
|
return { promptText, systemHint };
|
|
1682
1755
|
},
|
|
1683
1756
|
setRunner(runner) {
|
|
@@ -1685,7 +1758,11 @@ ${result}
|
|
|
1685
1758
|
},
|
|
1686
1759
|
async postProcessNotifyEvent(input) {
|
|
1687
1760
|
try {
|
|
1688
|
-
const chats =
|
|
1761
|
+
const chats = dedupeChatIds(input.resolvedChatIds ?? []);
|
|
1762
|
+
if (chats.length === 0) {
|
|
1763
|
+
logger.info(`[larkCliHandler] postProcessNotifyEvent: no resolved target chat for ` + `taskId=${input.notifyEvent.taskId}; skip mirror.`);
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1689
1766
|
for (const chatId of chats) {
|
|
1690
1767
|
try {
|
|
1691
1768
|
await sendMarkdownToChat(chatId, input.formattedPrompt, input.profile);
|
|
@@ -1709,40 +1786,27 @@ if (larkCliHandler.buildNotifyHandlePrompt) {
|
|
|
1709
1786
|
larkCliHandler.buildNotifyHandlePrompt = wrapFunction(larkCliHandler.buildNotifyHandlePrompt, "buildNotifyHandlePrompt", { recordParams: true, recordResult: false, recordError: true });
|
|
1710
1787
|
}
|
|
1711
1788
|
if (larkCliHandler.postProcessNotifyEvent) {
|
|
1712
|
-
larkCliHandler.postProcessNotifyEvent = wrapFunction(larkCliHandler.postProcessNotifyEvent, "postProcessNotifyEvent", {
|
|
1789
|
+
larkCliHandler.postProcessNotifyEvent = wrapFunction(larkCliHandler.postProcessNotifyEvent, "postProcessNotifyEvent", {
|
|
1790
|
+
recordParams: true,
|
|
1791
|
+
recordResult: false,
|
|
1792
|
+
recordError: true,
|
|
1793
|
+
paramFilter: (args) => ({
|
|
1794
|
+
taskId: args[0]?.notifyEvent?.taskId,
|
|
1795
|
+
resolvedChatIds: args[0]?.resolvedChatIds
|
|
1796
|
+
}),
|
|
1797
|
+
flattenParamFilter: true
|
|
1798
|
+
});
|
|
1713
1799
|
}
|
|
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);
|
|
1800
|
+
function dedupeChatIds(ids) {
|
|
1801
|
+
const out = [];
|
|
1802
|
+
const seen = new Set;
|
|
1803
|
+
for (const id of ids) {
|
|
1804
|
+
if (typeof id === "string" && id.length > 0 && !seen.has(id)) {
|
|
1805
|
+
seen.add(id);
|
|
1806
|
+
out.push(id);
|
|
1743
1807
|
}
|
|
1744
1808
|
}
|
|
1745
|
-
return
|
|
1809
|
+
return out;
|
|
1746
1810
|
}
|
|
1747
1811
|
async function sendMarkdownToChat(chatId, markdown, profile) {
|
|
1748
1812
|
const profileFlag = profile ? `--profile ${profile} ` : "";
|
|
@@ -111,6 +111,9 @@ async function runWithEnvContextAsync(context, fn) {
|
|
|
111
111
|
}
|
|
112
112
|
return fn();
|
|
113
113
|
}
|
|
114
|
+
function normalizeParentTaskId(value) {
|
|
115
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : undefined;
|
|
116
|
+
}
|
|
114
117
|
function createEnvContext(options) {
|
|
115
118
|
let replyChannel = options.replyChannel;
|
|
116
119
|
if (replyChannel && options.messageId && !replyChannel.messageId) {
|
|
@@ -184,13 +187,24 @@ function getEventFromEnvContext(ctx) {
|
|
|
184
187
|
}
|
|
185
188
|
return;
|
|
186
189
|
}
|
|
187
|
-
var logger, envContextStorage, setCurrentTaskId;
|
|
190
|
+
var logger, envContextStorage, resolveEnvParentTaskId, setCurrentTaskId;
|
|
188
191
|
var init_env_context = __esm(() => {
|
|
189
192
|
init_logger();
|
|
190
193
|
init_decorator();
|
|
191
194
|
init_env_event();
|
|
192
195
|
logger = createLogger("env:context:env-context");
|
|
193
196
|
envContextStorage = new AsyncLocalStorage;
|
|
197
|
+
resolveEnvParentTaskId = wrapFunction(function _resolveEnvParentTaskId(envEvent, parentEnvContext) {
|
|
198
|
+
const fromEvent = normalizeParentTaskId(envEvent?.metadata?.parentTaskId);
|
|
199
|
+
return fromEvent ?? normalizeParentTaskId(parentEnvContext?.parentTaskId);
|
|
200
|
+
}, "env-context.resolveEnvParentTaskId", {
|
|
201
|
+
recordParams: false,
|
|
202
|
+
recordResult: false,
|
|
203
|
+
log: false,
|
|
204
|
+
resultFilter: (parentTaskId) => ({
|
|
205
|
+
parentTaskId: parentTaskId ?? null
|
|
206
|
+
})
|
|
207
|
+
});
|
|
194
208
|
setCurrentTaskId = wrapFunction(function _setCurrentTaskId(taskId) {
|
|
195
209
|
const prev = getCurrentTaskId();
|
|
196
210
|
const ctx = envContextStorage.getStore();
|
|
@@ -204,4 +218,4 @@ var init_env_context = __esm(() => {
|
|
|
204
218
|
}, "env-context.setCurrentTaskId", { recordParams: true, recordResult: false, log: true });
|
|
205
219
|
});
|
|
206
220
|
|
|
207
|
-
export { isLarkEvent, isGithubEvent, isJiraEvent, getLarkMessageId, getLarkChatId, getLarkUserId, EVENT_ENV_PREFIX, serializeEventToEnv, restoreEventFromEnv, init_env_event, envContextStorage, getEnvContext, getEnvContextOrEmpty, hasEnvContext, getCurrentTaskId, runWithEnvContext, runWithEnvContextAsync, createEnvContext, mergeEnvContext, setCurrentTaskId, getEventFromEnvContext, init_env_context };
|
|
221
|
+
export { isLarkEvent, isGithubEvent, isJiraEvent, getLarkMessageId, getLarkChatId, getLarkUserId, EVENT_ENV_PREFIX, serializeEventToEnv, restoreEventFromEnv, init_env_event, envContextStorage, getEnvContext, getEnvContextOrEmpty, hasEnvContext, getCurrentTaskId, runWithEnvContext, runWithEnvContextAsync, normalizeParentTaskId, resolveEnvParentTaskId, createEnvContext, mergeEnvContext, setCurrentTaskId, getEventFromEnvContext, init_env_context };
|