@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
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSharedEventStore
|
|
3
|
+
} from "./roy-agent-core-xyys5m1a.js";
|
|
1
4
|
import {
|
|
2
5
|
TaskHookPoints
|
|
3
6
|
} from "./roy-agent-core-1pg0fepg.js";
|
|
4
7
|
import {
|
|
5
8
|
WORKFLOW_EXTRACT_PROMPT
|
|
6
|
-
} from "./roy-agent-core-
|
|
9
|
+
} from "./roy-agent-core-223v204d.js";
|
|
7
10
|
import {
|
|
8
11
|
validateWorkflowDefinition
|
|
9
12
|
} from "./roy-agent-core-6vbgswjw.js";
|
|
@@ -16,13 +19,13 @@ import {
|
|
|
16
19
|
} from "./roy-agent-core-rmn29nrh.js";
|
|
17
20
|
import {
|
|
18
21
|
init_context
|
|
19
|
-
} from "./roy-agent-core-
|
|
22
|
+
} from "./roy-agent-core-wn59p0zw.js";
|
|
20
23
|
import {
|
|
21
24
|
getEnvContextOrEmpty,
|
|
22
25
|
getEventFromEnvContext,
|
|
23
26
|
getLarkMessageId,
|
|
24
27
|
isLarkEvent
|
|
25
|
-
} from "./roy-agent-core-
|
|
28
|
+
} from "./roy-agent-core-zbb3sk72.js";
|
|
26
29
|
import {
|
|
27
30
|
TracedAs,
|
|
28
31
|
init_decorator,
|
|
@@ -378,6 +381,30 @@ var logger3 = createLogger("lark-cli:task-notify");
|
|
|
378
381
|
function isTaskNotifyDebugEnabled() {
|
|
379
382
|
return process.env.ROY_TASK_NOTIFY_DEBUG === "1" || process.env.ROY_TRACE_DEBUG === "1";
|
|
380
383
|
}
|
|
384
|
+
var CTX_FIELD_CHAT_ID = "larkPerTaskChatId";
|
|
385
|
+
var CTX_FIELD_CHAT_PROFILE = "larkPerTaskChatProfile";
|
|
386
|
+
function parseLarkPerTaskChatId(ctxStr) {
|
|
387
|
+
if (!ctxStr)
|
|
388
|
+
return;
|
|
389
|
+
try {
|
|
390
|
+
const obj = JSON.parse(ctxStr);
|
|
391
|
+
const id = obj[CTX_FIELD_CHAT_ID];
|
|
392
|
+
return typeof id === "string" ? id : undefined;
|
|
393
|
+
} catch {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function parseLarkPerTaskChatProfile(ctxStr) {
|
|
398
|
+
if (!ctxStr)
|
|
399
|
+
return;
|
|
400
|
+
try {
|
|
401
|
+
const obj = JSON.parse(ctxStr);
|
|
402
|
+
const profile = obj[CTX_FIELD_CHAT_PROFILE];
|
|
403
|
+
return typeof profile === "string" ? profile : undefined;
|
|
404
|
+
} catch {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
381
408
|
function extractLarkFields(env) {
|
|
382
409
|
const event = getEventFromEnvContext(env);
|
|
383
410
|
if (!isLarkEvent(event)) {
|
|
@@ -407,6 +434,7 @@ class LarkCliTaskNotifyHook {
|
|
|
407
434
|
pluginName;
|
|
408
435
|
sourceId;
|
|
409
436
|
config;
|
|
437
|
+
eventStore;
|
|
410
438
|
lastNotifyTimestamps = new Map;
|
|
411
439
|
constructor(config = {}) {
|
|
412
440
|
this.name = config.pluginName || "LarkCliTaskNotifyHook";
|
|
@@ -515,14 +543,41 @@ class LarkCliTaskNotifyHook {
|
|
|
515
543
|
async sendNotify(options) {
|
|
516
544
|
const { type, title, content, _hookContext } = options;
|
|
517
545
|
const env = getEnvContextOrEmpty();
|
|
518
|
-
|
|
546
|
+
const taskFromCtx = _hookContext?.data?.task ?? env.metadata?.task;
|
|
547
|
+
const taskContext = taskFromCtx?.context;
|
|
548
|
+
const taskChatId = taskContext ? parseLarkPerTaskChatId(taskContext) : undefined;
|
|
549
|
+
const taskChatProfile = taskContext ? parseLarkPerTaskChatProfile(taskContext) : undefined;
|
|
550
|
+
let replyChannel = taskChatId ? {
|
|
551
|
+
chatId: taskChatId,
|
|
552
|
+
messageId: undefined,
|
|
553
|
+
profile: taskChatProfile,
|
|
554
|
+
type: "lark-cli"
|
|
555
|
+
} : env.replyChannel;
|
|
519
556
|
const envContextFromMetadata = env.metadata?.envContext;
|
|
520
|
-
if (!replyChannel && envContextFromMetadata) {
|
|
557
|
+
if (!replyChannel?.chatId && envContextFromMetadata?.replyChannel) {
|
|
521
558
|
replyChannel = envContextFromMetadata.replyChannel;
|
|
522
559
|
}
|
|
523
|
-
if (!replyChannel && _hookContext?.metadata?.envContext) {
|
|
560
|
+
if (!replyChannel?.chatId && _hookContext?.metadata?.envContext?.replyChannel) {
|
|
524
561
|
replyChannel = _hookContext.metadata.envContext.replyChannel;
|
|
525
562
|
}
|
|
563
|
+
const triggerEventId = env.envEvent?.metadata?.triggerEventId ?? env.envEvent?.payload?.triggerEventId ?? env.event?.metadata?.triggerEventId;
|
|
564
|
+
const fallbackStore = this.eventStore ?? getSharedEventStore() ?? undefined;
|
|
565
|
+
if (!replyChannel?.chatId && fallbackStore && triggerEventId) {
|
|
566
|
+
try {
|
|
567
|
+
const triggerEvent = await fallbackStore.getEventById(triggerEventId);
|
|
568
|
+
const triggerChatId = triggerEvent?.metadata?.chatId ?? triggerEvent?.metadata?.replyChannel?.chatId;
|
|
569
|
+
if (triggerChatId) {
|
|
570
|
+
replyChannel = {
|
|
571
|
+
chatId: triggerChatId,
|
|
572
|
+
messageId: undefined,
|
|
573
|
+
profile: triggerEvent?.metadata?.profile ?? triggerEvent?.metadata?.replyChannel?.profile,
|
|
574
|
+
type: "lark-cli"
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
} catch (err) {
|
|
578
|
+
logger3.debug(`EventStore fallback failed: ${err.message}`);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
526
581
|
const larkFields = extractLarkFields(env);
|
|
527
582
|
if (!larkFields.isLark && env.event) {
|
|
528
583
|
logger3.debug(`Skipping notification for non-lark event source: ${larkFields.source}`);
|
|
@@ -797,8 +852,12 @@ __legacyDecorateClassTS([
|
|
|
797
852
|
__legacyDecorateClassTS([
|
|
798
853
|
TracedAs("lark-cli-task-notify.sendLarkMessage")
|
|
799
854
|
], LarkCliTaskNotifyHook.prototype, "sendLarkMessage", null);
|
|
800
|
-
function createLarkCliTaskNotifyHook(config = {}) {
|
|
801
|
-
|
|
855
|
+
function createLarkCliTaskNotifyHook(config = {}, options = {}) {
|
|
856
|
+
const hook = new LarkCliTaskNotifyHook(config);
|
|
857
|
+
if (options.eventStore) {
|
|
858
|
+
hook.eventStore = options.eventStore;
|
|
859
|
+
}
|
|
860
|
+
return hook;
|
|
802
861
|
}
|
|
803
862
|
// src/env/task/plugins/per-task-group-chat-plugin.ts
|
|
804
863
|
init_decorator();
|
|
@@ -809,8 +868,8 @@ var logger4 = createLogger("lark-cli:per-task-group");
|
|
|
809
868
|
function isPluginDebugEnabled() {
|
|
810
869
|
return process.env.ROY_TASK_NOTIFY_DEBUG === "1" || process.env.ROY_TRACE_DEBUG === "1";
|
|
811
870
|
}
|
|
812
|
-
var
|
|
813
|
-
var
|
|
871
|
+
var CTX_FIELD_CHAT_ID2 = "larkPerTaskChatId";
|
|
872
|
+
var CTX_FIELD_CHAT_PROFILE2 = "larkPerTaskChatProfile";
|
|
814
873
|
var CTX_FIELD_CHAT_CREATED_AT = "larkPerTaskChatCreatedAt";
|
|
815
874
|
var CTX_FIELD_CHAT_TASK_ID = "larkPerTaskChatTaskId";
|
|
816
875
|
|
|
@@ -822,6 +881,7 @@ class PerTaskGroupChatPlugin {
|
|
|
822
881
|
config;
|
|
823
882
|
lastNotifyTimestamps = new Map;
|
|
824
883
|
taskUpdater;
|
|
884
|
+
taskGetter;
|
|
825
885
|
sessionComponent;
|
|
826
886
|
constructor(config = {}) {
|
|
827
887
|
this.config = {
|
|
@@ -839,7 +899,8 @@ class PerTaskGroupChatPlugin {
|
|
|
839
899
|
disableSubTaskSkip: config.disableSubTaskSkip ?? false,
|
|
840
900
|
requireReplyChannel: config.requireReplyChannel ?? true,
|
|
841
901
|
fallbackProfile: config.fallbackProfile ?? "",
|
|
842
|
-
sendWelcomeMessage: config.sendWelcomeMessage ?? true
|
|
902
|
+
sendWelcomeMessage: config.sendWelcomeMessage ?? true,
|
|
903
|
+
resolveToTriggerChatFallback: config.resolveToTriggerChatFallback ?? false
|
|
843
904
|
};
|
|
844
905
|
this.name = this.config.pluginName;
|
|
845
906
|
this.priority = this.config.priority;
|
|
@@ -853,6 +914,13 @@ class PerTaskGroupChatPlugin {
|
|
|
853
914
|
hasTaskUpdater() {
|
|
854
915
|
return this.taskUpdater !== undefined;
|
|
855
916
|
}
|
|
917
|
+
setTaskGetter(getter) {
|
|
918
|
+
this.taskGetter = getter;
|
|
919
|
+
logger4.debug(`TaskGetter injected for plugin ${this.name} (sourceId=${this.sourceId})`);
|
|
920
|
+
}
|
|
921
|
+
hasTaskGetter() {
|
|
922
|
+
return this.taskGetter !== undefined;
|
|
923
|
+
}
|
|
856
924
|
setSessionComponent(sessionComponent) {
|
|
857
925
|
this.sessionComponent = sessionComponent;
|
|
858
926
|
logger4.debug(`SessionComponent injected for plugin ${this.name} (sourceId=${this.sourceId})`);
|
|
@@ -923,29 +991,17 @@ class PerTaskGroupChatPlugin {
|
|
|
923
991
|
const botAppIds = this.resolveBotAppIds(replyChannel ?? {});
|
|
924
992
|
const userIds = this.resolveUserIds(replyChannel);
|
|
925
993
|
logger4.debug(`onAfterCreate[${this.pluginName}]: creating group chat for task #${task.id} ` + `name="${name}" profile="${profile}" botAppIds=${JSON.stringify(botAppIds)} ` + `userIds=${JSON.stringify(userIds)}`);
|
|
994
|
+
let chatId;
|
|
926
995
|
try {
|
|
927
|
-
|
|
996
|
+
chatId = await this.createGroupChat({
|
|
928
997
|
name,
|
|
929
998
|
description,
|
|
930
999
|
profile,
|
|
931
1000
|
botAppIds,
|
|
932
1001
|
userIds
|
|
933
1002
|
});
|
|
1003
|
+
await this.writeChatBinding(task, chatId, profile, "creating");
|
|
934
1004
|
await this.attachChatIdToTask(task, chatId, profile);
|
|
935
|
-
if (this.sessionComponent) {
|
|
936
|
-
try {
|
|
937
|
-
await this.sessionComponent.upsertChatTaskBinding({
|
|
938
|
-
chatId,
|
|
939
|
-
taskId: task.id,
|
|
940
|
-
profile,
|
|
941
|
-
status: "ready"
|
|
942
|
-
});
|
|
943
|
-
} catch (bindErr) {
|
|
944
|
-
logger4.warn(`onAfterCreate[${this.pluginName}]: failed to write chat-task binding for ` + `chat ${chatId} / task #${task.id}: ${bindErr}. ` + `群消息 handler 将无法自动注入 parentTaskId。`);
|
|
945
|
-
}
|
|
946
|
-
} else if (isPluginDebugEnabled()) {
|
|
947
|
-
logger4.debug(`onAfterCreate[${this.pluginName}]: no sessionComponent injected, ` + `skip chat-task binding for chat ${chatId}`);
|
|
948
|
-
}
|
|
949
1005
|
if (this.config.sendWelcomeMessage) {
|
|
950
1006
|
try {
|
|
951
1007
|
await this.sendToChat({
|
|
@@ -974,13 +1030,36 @@ class PerTaskGroupChatPlugin {
|
|
|
974
1030
|
} else {
|
|
975
1031
|
logger4.debug(`onAfterCreate[${this.pluginName}]: skip "群聊已创建" main-chat notification ` + `(no replyChannel.chatId)`);
|
|
976
1032
|
}
|
|
1033
|
+
await this.writeChatBinding(task, chatId, profile, "ready");
|
|
977
1034
|
logger4.info(`Created per-task group chat ${chatId} for task #${task.id}`);
|
|
978
1035
|
} catch (error) {
|
|
979
1036
|
logger4.error(`Failed to create per-task group chat for task #${task.id}: ${error}`);
|
|
1037
|
+
if (chatId) {
|
|
1038
|
+
await this.writeChatBinding(task, chatId, profile, "failed", String(error));
|
|
1039
|
+
}
|
|
980
1040
|
if (!this.config.fallbackToMain)
|
|
981
1041
|
throw error;
|
|
982
1042
|
}
|
|
983
1043
|
}
|
|
1044
|
+
async writeChatBinding(task, chatId, profile, status, errorMessage) {
|
|
1045
|
+
if (!this.sessionComponent) {
|
|
1046
|
+
if (isPluginDebugEnabled()) {
|
|
1047
|
+
logger4.debug(`writeChatBinding[${this.pluginName}]: no sessionComponent injected, ` + `skip chat-task binding for chat ${chatId} (status=${status})`);
|
|
1048
|
+
}
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
try {
|
|
1052
|
+
await this.sessionComponent.upsertChatTaskBinding({
|
|
1053
|
+
chatId,
|
|
1054
|
+
taskId: task.id,
|
|
1055
|
+
profile,
|
|
1056
|
+
status,
|
|
1057
|
+
errorMessage: errorMessage ?? null
|
|
1058
|
+
});
|
|
1059
|
+
} catch (bindErr) {
|
|
1060
|
+
logger4.warn(`writeChatBinding[${this.pluginName}]: failed to write chat-task binding for ` + `chat ${chatId} / task #${task.id} (status=${status}): ${bindErr}. ` + `群消息 handler 将无法自动注入 parentTaskId。`);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
984
1063
|
async onAfterUpdate(ctx) {
|
|
985
1064
|
const data = ctx.data;
|
|
986
1065
|
if (!data?.task) {
|
|
@@ -988,13 +1067,13 @@ class PerTaskGroupChatPlugin {
|
|
|
988
1067
|
return;
|
|
989
1068
|
}
|
|
990
1069
|
const { task, changes } = data;
|
|
991
|
-
const chatId = this.
|
|
1070
|
+
const { chatId, profile: inheritedProfile } = await this.resolveEffectiveChat(task);
|
|
992
1071
|
if (!chatId) {
|
|
993
1072
|
logger4.debug(`onAfterUpdate[${this.pluginName}]: task #${task.id} has no per-task chat_id, skip. ` + `诊断:检查 task.context JSON 是否含 larkPerTaskChatId 字段 ` + `(sqlite: SELECT context FROM task WHERE id=${task.id})`);
|
|
994
1073
|
return;
|
|
995
1074
|
}
|
|
996
1075
|
const replyChannel = this.getReplyChannelFromCtx(ctx);
|
|
997
|
-
const profile = replyChannel?.profile ??
|
|
1076
|
+
const profile = replyChannel?.profile ?? inheritedProfile ?? undefined;
|
|
998
1077
|
if (!this.hasMeaningfulChange(changes)) {
|
|
999
1078
|
logger4.debug(`onAfterUpdate[${this.pluginName}]: no meaningful change for task #${task.id}, skip`);
|
|
1000
1079
|
return;
|
|
@@ -1023,13 +1102,13 @@ class PerTaskGroupChatPlugin {
|
|
|
1023
1102
|
return;
|
|
1024
1103
|
}
|
|
1025
1104
|
const taskFromCtx = ctx.metadata?.task;
|
|
1026
|
-
const chatId = taskFromCtx ? this.
|
|
1105
|
+
const { chatId, profile: inheritedProfile } = taskFromCtx ? await this.resolveEffectiveChat(taskFromCtx) : {};
|
|
1027
1106
|
if (!chatId || !taskFromCtx) {
|
|
1028
1107
|
logger4.debug(`onAfterOperationCreate[${this.pluginName}]: no per-task chat_id for task #${taskId}, skip. ` + `诊断:ctx.metadata.task 是否包含完整 task 对象?task.context.larkPerTaskChatId 是否存在?`);
|
|
1029
1108
|
return;
|
|
1030
1109
|
}
|
|
1031
1110
|
const replyChannel = this.getReplyChannelFromCtx(ctx);
|
|
1032
|
-
const profile = replyChannel?.profile ??
|
|
1111
|
+
const profile = replyChannel?.profile ?? inheritedProfile ?? undefined;
|
|
1033
1112
|
logger4.debug(`onAfterOperationCreate[${this.pluginName}]: send operation #${operation.id} ` + `for task #${taskId} to chat_id=${chatId}`);
|
|
1034
1113
|
await this.sendToChat({
|
|
1035
1114
|
chatId,
|
|
@@ -1044,13 +1123,13 @@ class PerTaskGroupChatPlugin {
|
|
|
1044
1123
|
return;
|
|
1045
1124
|
}
|
|
1046
1125
|
const { task, terminalStatus } = data;
|
|
1047
|
-
const chatId = this.
|
|
1126
|
+
const { chatId, profile: inheritedProfile } = await this.resolveEffectiveChat(task);
|
|
1048
1127
|
if (!chatId) {
|
|
1049
1128
|
logger4.debug(`onAfterComplete[${this.pluginName}]: task #${task.id} has no per-task chat_id, skip`);
|
|
1050
1129
|
return;
|
|
1051
1130
|
}
|
|
1052
1131
|
const replyChannel = this.getReplyChannelFromCtx(ctx);
|
|
1053
|
-
const profile = replyChannel?.profile ??
|
|
1132
|
+
const profile = replyChannel?.profile ?? inheritedProfile ?? undefined;
|
|
1054
1133
|
const emoji = terminalStatus === "completed" ? "✅" : terminalStatus === "failed" ? "❌" : terminalStatus === "cancelled" ? "\uD83D\uDEAB" : terminalStatus === "timeout" ? "⏰" : "\uD83C\uDFC1";
|
|
1055
1134
|
logger4.debug(`onAfterComplete[${this.pluginName}]: send complete notification for task #${task.id} ` + `status=${terminalStatus} to chat_id=${chatId}`);
|
|
1056
1135
|
await this.sendToChat({
|
|
@@ -1136,8 +1215,8 @@ class PerTaskGroupChatPlugin {
|
|
|
1136
1215
|
} catch {
|
|
1137
1216
|
parsed = {};
|
|
1138
1217
|
}
|
|
1139
|
-
parsed[
|
|
1140
|
-
parsed[
|
|
1218
|
+
parsed[CTX_FIELD_CHAT_ID2] = chatId;
|
|
1219
|
+
parsed[CTX_FIELD_CHAT_PROFILE2] = profile;
|
|
1141
1220
|
parsed[CTX_FIELD_CHAT_CREATED_AT] = new Date().toISOString();
|
|
1142
1221
|
parsed[CTX_FIELD_CHAT_TASK_ID] = task.id;
|
|
1143
1222
|
const newContext = JSON.stringify(parsed);
|
|
@@ -1244,30 +1323,77 @@ ${opts.content}`);
|
|
|
1244
1323
|
}
|
|
1245
1324
|
return;
|
|
1246
1325
|
}
|
|
1247
|
-
|
|
1248
|
-
const ctxStr = task.context;
|
|
1326
|
+
parseChatIdFromContext(ctxStr) {
|
|
1249
1327
|
if (!ctxStr)
|
|
1250
1328
|
return;
|
|
1251
1329
|
try {
|
|
1252
1330
|
const obj = JSON.parse(ctxStr);
|
|
1253
|
-
const id = obj[
|
|
1331
|
+
const id = obj[CTX_FIELD_CHAT_ID2];
|
|
1254
1332
|
return typeof id === "string" ? id : undefined;
|
|
1255
1333
|
} catch {
|
|
1256
1334
|
return;
|
|
1257
1335
|
}
|
|
1258
1336
|
}
|
|
1259
|
-
|
|
1260
|
-
const ctxStr = task.context;
|
|
1337
|
+
parseProfileFromContext(ctxStr) {
|
|
1261
1338
|
if (!ctxStr)
|
|
1262
1339
|
return;
|
|
1263
1340
|
try {
|
|
1264
1341
|
const obj = JSON.parse(ctxStr);
|
|
1265
|
-
const profile = obj[
|
|
1342
|
+
const profile = obj[CTX_FIELD_CHAT_PROFILE2];
|
|
1266
1343
|
return typeof profile === "string" ? profile : undefined;
|
|
1267
1344
|
} catch {
|
|
1268
1345
|
return;
|
|
1269
1346
|
}
|
|
1270
1347
|
}
|
|
1348
|
+
getTaskChatId(task) {
|
|
1349
|
+
return this.parseChatIdFromContext(task.context);
|
|
1350
|
+
}
|
|
1351
|
+
getTaskChatProfile(task) {
|
|
1352
|
+
return this.parseProfileFromContext(task.context);
|
|
1353
|
+
}
|
|
1354
|
+
async resolveEffectiveChat(task) {
|
|
1355
|
+
const ownChatId = this.getTaskChatId(task);
|
|
1356
|
+
if (ownChatId) {
|
|
1357
|
+
return { chatId: ownChatId, profile: this.getTaskChatProfile(task) };
|
|
1358
|
+
}
|
|
1359
|
+
if (!this.taskGetter)
|
|
1360
|
+
return {};
|
|
1361
|
+
const seen = new Set;
|
|
1362
|
+
let id = task.parent_task_id;
|
|
1363
|
+
while (typeof id === "number" && id > 0 && !seen.has(id) && seen.size < 8) {
|
|
1364
|
+
seen.add(id);
|
|
1365
|
+
let parent;
|
|
1366
|
+
try {
|
|
1367
|
+
parent = await this.taskGetter(id);
|
|
1368
|
+
} catch {
|
|
1369
|
+
return {};
|
|
1370
|
+
}
|
|
1371
|
+
if (!parent)
|
|
1372
|
+
return {};
|
|
1373
|
+
const chatId = this.parseChatIdFromContext(parent.context);
|
|
1374
|
+
if (chatId) {
|
|
1375
|
+
return { chatId, profile: this.parseProfileFromContext(parent.context) };
|
|
1376
|
+
}
|
|
1377
|
+
id = parent.parent_task_id ?? undefined;
|
|
1378
|
+
}
|
|
1379
|
+
if (this.config.resolveToTriggerChatFallback) {
|
|
1380
|
+
const store = getSharedEventStore();
|
|
1381
|
+
const triggerEventId = getEnvContextOrEmpty()?.envEvent?.metadata?.triggerEventId;
|
|
1382
|
+
if (store && typeof triggerEventId === "string" && triggerEventId.length > 0) {
|
|
1383
|
+
try {
|
|
1384
|
+
const triggerEvent = await store.getEventById(triggerEventId);
|
|
1385
|
+
const fallbackChatId = triggerEvent?.metadata?.chatId ?? triggerEvent?.metadata?.replyChannel?.chatId;
|
|
1386
|
+
if (fallbackChatId) {
|
|
1387
|
+
return {
|
|
1388
|
+
chatId: fallbackChatId,
|
|
1389
|
+
profile: triggerEvent?.metadata?.profile ?? triggerEvent?.metadata?.replyChannel?.profile
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
} catch {}
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
return {};
|
|
1396
|
+
}
|
|
1271
1397
|
resolveBotAppIds(replyChannel) {
|
|
1272
1398
|
if (this.config.botAppIds.length > 0) {
|
|
1273
1399
|
logger4.debug(`resolveBotAppIds[${this.pluginName}]: using config.botAppIds=${JSON.stringify(this.config.botAppIds)}`);
|
|
@@ -1455,6 +1581,18 @@ __legacyDecorateClassTS([
|
|
|
1455
1581
|
__legacyDecorateClassTS([
|
|
1456
1582
|
TracedAs("per-task-group-chat.onAfterCreate", { recordParams: false })
|
|
1457
1583
|
], PerTaskGroupChatPlugin.prototype, "onAfterCreate", null);
|
|
1584
|
+
__legacyDecorateClassTS([
|
|
1585
|
+
TracedAs("per-task-group-chat.writeChatBinding", {
|
|
1586
|
+
recordParams: true,
|
|
1587
|
+
recordResult: false,
|
|
1588
|
+
flattenParamFilter: true,
|
|
1589
|
+
paramFilter: (args) => ({
|
|
1590
|
+
taskId: args[0]?.id,
|
|
1591
|
+
chatId: args[1],
|
|
1592
|
+
status: args[3]
|
|
1593
|
+
})
|
|
1594
|
+
})
|
|
1595
|
+
], PerTaskGroupChatPlugin.prototype, "writeChatBinding", null);
|
|
1458
1596
|
__legacyDecorateClassTS([
|
|
1459
1597
|
TracedAs("per-task-group-chat.onAfterUpdate", { recordParams: false })
|
|
1460
1598
|
], PerTaskGroupChatPlugin.prototype, "onAfterUpdate", null);
|