@ai-setting/roy-agent-core 1.7.30 → 1.7.32
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/env/event-source/index.js +2 -2
- package/dist/env/index.js +4 -4
- package/dist/env/task/index.js +1 -1
- package/dist/env/task/plugins/index.js +5 -1
- package/dist/index.js +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-91rzfw8d.js → roy-agent-core-4csc7ars.js} +126 -31
- package/dist/shared/@ai-setting/{roy-agent-core-62mfe44h.js → roy-agent-core-4t6m600m.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-9z6gcy77.js +1520 -0
- package/dist/shared/@ai-setting/{roy-agent-core-pp140n9r.js → roy-agent-core-m09a4xwh.js} +2 -1
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-h4h6n9vk.js +0 -801
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
larkCliHandler,
|
|
12
12
|
resolveBountyIMSystemPrompt,
|
|
13
13
|
timerHandler
|
|
14
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
14
|
+
} from "../../shared/@ai-setting/roy-agent-core-4csc7ars.js";
|
|
15
15
|
import"../../shared/@ai-setting/roy-agent-core-0nz53t5v.js";
|
|
16
16
|
import {
|
|
17
17
|
BUILT_IN_EVENT_SOURCE_TYPES,
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
isValidEventSourceType,
|
|
23
23
|
validateEventSourceConfig
|
|
24
24
|
} from "../../shared/@ai-setting/roy-agent-core-ds5f75pg.js";
|
|
25
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
25
|
+
import"../../shared/@ai-setting/roy-agent-core-9z6gcy77.js";
|
|
26
26
|
import"../../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
|
|
27
27
|
import"../../shared/@ai-setting/roy-agent-core-skqt40yy.js";
|
|
28
28
|
import"../../shared/@ai-setting/roy-agent-core-1df0grva.js";
|
package/dist/env/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseEnvironment
|
|
3
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
3
|
+
} from "../shared/@ai-setting/roy-agent-core-4t6m600m.js";
|
|
4
4
|
import {
|
|
5
5
|
TaskComponent
|
|
6
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
6
|
+
} from "../shared/@ai-setting/roy-agent-core-m09a4xwh.js";
|
|
7
7
|
import"../shared/@ai-setting/roy-agent-core-htwb9yj6.js";
|
|
8
8
|
import"../shared/@ai-setting/roy-agent-core-rn57psp0.js";
|
|
9
9
|
import"../shared/@ai-setting/roy-agent-core-amkqnyzy.js";
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
EventSourceComponent,
|
|
16
16
|
builtInHandlers,
|
|
17
17
|
larkCliHandler
|
|
18
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
18
|
+
} from "../shared/@ai-setting/roy-agent-core-4csc7ars.js";
|
|
19
19
|
import"../shared/@ai-setting/roy-agent-core-0nz53t5v.js";
|
|
20
20
|
import {
|
|
21
21
|
EventSourceInitHooks,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
isValidEventSourceType,
|
|
25
25
|
validateEventSourceConfig
|
|
26
26
|
} from "../shared/@ai-setting/roy-agent-core-ds5f75pg.js";
|
|
27
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
27
|
+
import"../shared/@ai-setting/roy-agent-core-9z6gcy77.js";
|
|
28
28
|
import"../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
|
|
29
29
|
import"../shared/@ai-setting/roy-agent-core-skqt40yy.js";
|
|
30
30
|
import {
|
package/dist/env/task/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
TaskPriorityEnum,
|
|
6
6
|
TaskStatusEnum,
|
|
7
7
|
TaskTypeEnum
|
|
8
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
8
|
+
} from "../../shared/@ai-setting/roy-agent-core-m09a4xwh.js";
|
|
9
9
|
import"../../shared/@ai-setting/roy-agent-core-htwb9yj6.js";
|
|
10
10
|
import"../../shared/@ai-setting/roy-agent-core-rn57psp0.js";
|
|
11
11
|
import"../../shared/@ai-setting/roy-agent-core-amkqnyzy.js";
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
LarkCliTaskNotifyHook,
|
|
3
3
|
NotifyType,
|
|
4
|
+
PerTaskGroupChatPlugin,
|
|
4
5
|
TaskTagPlugin,
|
|
5
6
|
WORKFLOW_EXTRACTOR_PROMPT,
|
|
6
7
|
createAutoTaskPlugin,
|
|
7
8
|
createLarkCliTaskNotifyHook,
|
|
9
|
+
createPerTaskGroupChatPlugin,
|
|
8
10
|
formatExtractorInput,
|
|
9
11
|
formatExtractorInputFromDescription,
|
|
10
12
|
parseExtractorOutput
|
|
11
|
-
} from "../../../shared/@ai-setting/roy-agent-core-
|
|
13
|
+
} from "../../../shared/@ai-setting/roy-agent-core-9z6gcy77.js";
|
|
12
14
|
import"../../../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
|
|
13
15
|
import"../../../shared/@ai-setting/roy-agent-core-skqt40yy.js";
|
|
14
16
|
import"../../../shared/@ai-setting/roy-agent-core-1df0grva.js";
|
|
@@ -27,10 +29,12 @@ export {
|
|
|
27
29
|
parseExtractorOutput,
|
|
28
30
|
formatExtractorInputFromDescription,
|
|
29
31
|
formatExtractorInput,
|
|
32
|
+
createPerTaskGroupChatPlugin,
|
|
30
33
|
createLarkCliTaskNotifyHook,
|
|
31
34
|
createAutoTaskPlugin,
|
|
32
35
|
WORKFLOW_EXTRACTOR_PROMPT,
|
|
33
36
|
TaskTagPlugin,
|
|
37
|
+
PerTaskGroupChatPlugin,
|
|
34
38
|
NotifyType,
|
|
35
39
|
LarkCliTaskNotifyHook
|
|
36
40
|
};
|
package/dist/index.js
CHANGED
|
@@ -66,10 +66,10 @@ import {
|
|
|
66
66
|
BaseEnvironment,
|
|
67
67
|
generateDescendingId,
|
|
68
68
|
generateId
|
|
69
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
69
|
+
} from "./shared/@ai-setting/roy-agent-core-4t6m600m.js";
|
|
70
70
|
import {
|
|
71
71
|
TaskComponent
|
|
72
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
72
|
+
} from "./shared/@ai-setting/roy-agent-core-m09a4xwh.js";
|
|
73
73
|
import"./shared/@ai-setting/roy-agent-core-htwb9yj6.js";
|
|
74
74
|
import"./shared/@ai-setting/roy-agent-core-rn57psp0.js";
|
|
75
75
|
import"./shared/@ai-setting/roy-agent-core-amkqnyzy.js";
|
|
@@ -92,7 +92,7 @@ import {
|
|
|
92
92
|
larkCliHandler,
|
|
93
93
|
resolveBountyIMSystemPrompt,
|
|
94
94
|
timerHandler
|
|
95
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
95
|
+
} from "./shared/@ai-setting/roy-agent-core-4csc7ars.js";
|
|
96
96
|
import {
|
|
97
97
|
LogTraceComponent,
|
|
98
98
|
LogTraceConfigSchema
|
|
@@ -109,7 +109,7 @@ import {
|
|
|
109
109
|
import {
|
|
110
110
|
TaskTagPlugin,
|
|
111
111
|
createAutoTaskPlugin
|
|
112
|
-
} from "./shared/@ai-setting/roy-agent-core-
|
|
112
|
+
} from "./shared/@ai-setting/roy-agent-core-9z6gcy77.js";
|
|
113
113
|
import {
|
|
114
114
|
TaskHookPoints
|
|
115
115
|
} from "./shared/@ai-setting/roy-agent-core-1pg0fepg.js";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TaskTagPlugin,
|
|
3
|
-
createLarkCliTaskNotifyHook
|
|
4
|
-
|
|
3
|
+
createLarkCliTaskNotifyHook,
|
|
4
|
+
createPerTaskGroupChatPlugin
|
|
5
|
+
} from "./roy-agent-core-9z6gcy77.js";
|
|
5
6
|
import {
|
|
6
7
|
envKeyToConfigKey
|
|
7
8
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
@@ -325,9 +326,13 @@ class BountyIMInstance {
|
|
|
325
326
|
ws = null;
|
|
326
327
|
buffer = "";
|
|
327
328
|
eventHandler;
|
|
329
|
+
environment;
|
|
328
330
|
constructor(config) {
|
|
329
331
|
this.config = config;
|
|
330
332
|
}
|
|
333
|
+
setEnvironment(env) {
|
|
334
|
+
this.environment = env;
|
|
335
|
+
}
|
|
331
336
|
getCurrentIdentity() {
|
|
332
337
|
const { email } = readBountyIMConfig(this.config);
|
|
333
338
|
return { email };
|
|
@@ -663,9 +668,13 @@ class BountyCliInstance {
|
|
|
663
668
|
child;
|
|
664
669
|
buffer = "";
|
|
665
670
|
eventHandler;
|
|
671
|
+
environment;
|
|
666
672
|
constructor(config) {
|
|
667
673
|
this.config = config;
|
|
668
674
|
}
|
|
675
|
+
setEnvironment(env) {
|
|
676
|
+
this.environment = env;
|
|
677
|
+
}
|
|
669
678
|
getStatus() {
|
|
670
679
|
return this.status;
|
|
671
680
|
}
|
|
@@ -818,8 +827,11 @@ var bountyCliHandler = {
|
|
|
818
827
|
};
|
|
819
828
|
|
|
820
829
|
// src/env/event-source/event-source-handlers.ts
|
|
830
|
+
init_logger();
|
|
831
|
+
var logger = createLogger("lark-cli:event-source");
|
|
821
832
|
var BUILT_IN_PLUGIN_FACTORIES = {
|
|
822
833
|
LarkCliTaskNotifyPlugin: (cfg) => createLarkCliTaskNotifyHook(cfg),
|
|
834
|
+
PerTaskGroupChatPlugin: (cfg) => createPerTaskGroupChatPlugin(cfg),
|
|
823
835
|
"task-tag": () => new TaskTagPlugin
|
|
824
836
|
};
|
|
825
837
|
function generateTraceId() {
|
|
@@ -894,7 +906,10 @@ function extractMetadata(rawEvent, eventType) {
|
|
|
894
906
|
const larkInnerEvent = event.event;
|
|
895
907
|
const header = larkInnerEvent?.header || event.header;
|
|
896
908
|
const sender = larkInnerEvent?.sender || event.sender;
|
|
897
|
-
|
|
909
|
+
let senderId = sender?.sender_id;
|
|
910
|
+
if (!senderId && typeof event.sender_id === "string") {
|
|
911
|
+
senderId = event.sender_id;
|
|
912
|
+
}
|
|
898
913
|
let messageData;
|
|
899
914
|
if (larkInnerEvent?.message) {
|
|
900
915
|
messageData = larkInnerEvent.message;
|
|
@@ -920,7 +935,9 @@ function extractMetadata(rawEvent, eventType) {
|
|
|
920
935
|
metadata.messageId = messageData.message_id;
|
|
921
936
|
metadata.messageType = messageData.message_type;
|
|
922
937
|
}
|
|
923
|
-
if (senderId) {
|
|
938
|
+
if (typeof senderId === "string") {
|
|
939
|
+
metadata.senderId = senderId;
|
|
940
|
+
} else if (senderId) {
|
|
924
941
|
metadata.senderId = senderId.open_id || senderId.user_id || senderId.union_id;
|
|
925
942
|
}
|
|
926
943
|
let recommendedAction;
|
|
@@ -935,12 +952,16 @@ function extractMetadata(rawEvent, eventType) {
|
|
|
935
952
|
});
|
|
936
953
|
}
|
|
937
954
|
const profile = event.profile;
|
|
955
|
+
const senderOpenId = typeof senderId === "string" ? senderId : senderId?.open_id;
|
|
938
956
|
const replyChannel = {
|
|
939
957
|
type: "lark-cli",
|
|
940
958
|
appId: metadata.appId,
|
|
941
959
|
profile,
|
|
942
960
|
chatId: messageData?.chat_id,
|
|
943
|
-
messageId: messageData?.message_id
|
|
961
|
+
messageId: messageData?.message_id,
|
|
962
|
+
params: {
|
|
963
|
+
userId: senderOpenId
|
|
964
|
+
}
|
|
944
965
|
};
|
|
945
966
|
return { metadata, replyChannel, recommendedAction };
|
|
946
967
|
}
|
|
@@ -951,10 +972,17 @@ class LarkCliInstance {
|
|
|
951
972
|
child;
|
|
952
973
|
buffer = "";
|
|
953
974
|
eventHandler;
|
|
975
|
+
recentEventIds = new Map;
|
|
976
|
+
DEDUP_WINDOW_MS = 60000;
|
|
977
|
+
DEDUP_MAX_SIZE = 100;
|
|
978
|
+
environment;
|
|
954
979
|
loadedPlugins = [];
|
|
955
980
|
constructor(config) {
|
|
956
981
|
this.config = config;
|
|
957
982
|
}
|
|
983
|
+
setEnvironment(env) {
|
|
984
|
+
this.environment = env;
|
|
985
|
+
}
|
|
958
986
|
async start() {
|
|
959
987
|
if (this.status === "running")
|
|
960
988
|
return;
|
|
@@ -1040,6 +1068,11 @@ class LarkCliInstance {
|
|
|
1040
1068
|
}
|
|
1041
1069
|
async loadPlugins() {
|
|
1042
1070
|
const plugins = this.config.handleRule?.plugins || [];
|
|
1071
|
+
if (plugins.length === 0) {
|
|
1072
|
+
console.debug(`[LarkCliInstance] No plugins configured in handleRule.plugins ` + `(sourceId=${this.config.id}). Skipping plugin loading.`);
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
console.debug(`[LarkCliInstance] Loading ${plugins.length} plugin(s) for sourceId=${this.config.id}: ` + `[${plugins.join(", ")}]; env injected=${!!this.environment}`);
|
|
1043
1076
|
for (const pluginName of plugins) {
|
|
1044
1077
|
const plugin = await this.importPlugin(pluginName);
|
|
1045
1078
|
if (plugin) {
|
|
@@ -1049,6 +1082,9 @@ class LarkCliInstance {
|
|
|
1049
1082
|
name: pluginName,
|
|
1050
1083
|
hooks: hookPoints.map((h) => ({ point: h, name: `${pluginName}:${h}` }))
|
|
1051
1084
|
});
|
|
1085
|
+
console.debug(`[LarkCliInstance] Loaded plugin "${pluginName}" with ${hookPoints.length} hook(s): ` + `[${hookPoints.join(", ")}]; setTaskUpdater=${typeof plugin.setTaskUpdater === "function"}, ` + `taskUpdaterInjected=${typeof plugin.hasTaskUpdater === "function" ? plugin.hasTaskUpdater() : "n/a"}`);
|
|
1086
|
+
} else {
|
|
1087
|
+
console.error(`[LarkCliInstance] Failed to import plugin "${pluginName}". ` + `plugin name=${pluginName} 不在 BUILT_IN_PLUGIN_FACTORIES 注册表里`);
|
|
1052
1088
|
}
|
|
1053
1089
|
}
|
|
1054
1090
|
}
|
|
@@ -1063,7 +1099,8 @@ class LarkCliInstance {
|
|
|
1063
1099
|
return [
|
|
1064
1100
|
"task:after.create",
|
|
1065
1101
|
"task:after.update",
|
|
1066
|
-
"task:operation:after.create"
|
|
1102
|
+
"task:operation:after.create",
|
|
1103
|
+
"task:after.complete"
|
|
1067
1104
|
];
|
|
1068
1105
|
}
|
|
1069
1106
|
return [];
|
|
@@ -1075,9 +1112,11 @@ class LarkCliInstance {
|
|
|
1075
1112
|
return null;
|
|
1076
1113
|
}
|
|
1077
1114
|
try {
|
|
1115
|
+
const pluginConfig = this.config.handleRule?.pluginConfig?.[name] ?? {};
|
|
1078
1116
|
return factory({
|
|
1079
1117
|
sourceId: this.config.id,
|
|
1080
|
-
pluginName: name
|
|
1118
|
+
pluginName: name,
|
|
1119
|
+
...pluginConfig
|
|
1081
1120
|
});
|
|
1082
1121
|
} catch (error) {
|
|
1083
1122
|
console.error(`[LarkCliInstance] Failed to instantiate plugin ${name}:`, error);
|
|
@@ -1086,6 +1125,7 @@ class LarkCliInstance {
|
|
|
1086
1125
|
}
|
|
1087
1126
|
registerPluginHooks(plugin) {
|
|
1088
1127
|
const pluginName = plugin.name || "unknown";
|
|
1128
|
+
this.injectTaskUpdater(plugin);
|
|
1089
1129
|
if (typeof plugin.init === "function") {
|
|
1090
1130
|
const pluginEnv = {
|
|
1091
1131
|
getComponent: () => null,
|
|
@@ -1150,6 +1190,27 @@ class LarkCliInstance {
|
|
|
1150
1190
|
return;
|
|
1151
1191
|
}
|
|
1152
1192
|
}
|
|
1193
|
+
injectTaskUpdater(plugin) {
|
|
1194
|
+
if (typeof plugin.setTaskUpdater !== "function") {
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
if (typeof plugin.hasTaskUpdater === "function" && plugin.hasTaskUpdater()) {
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
if (!this.environment?.getComponent) {
|
|
1201
|
+
console.debug(`[LarkCliInstance] ${plugin.name || "plugin"} has setTaskUpdater but ` + `environment not injected (setEnvironment not called). ` + `chat_id 持久化将只在 in-memory,DB 不会写入。`);
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
const taskComponent = this.environment.getComponent("task");
|
|
1205
|
+
if (!taskComponent?.updateTask) {
|
|
1206
|
+
console.debug(`[LarkCliInstance] ${plugin.name || "plugin"} has setTaskUpdater but ` + `taskComponent or updateTask method not found. ` + `chat_id 持久化将只在 in-memory,DB 不会写入。`);
|
|
1207
|
+
return;
|
|
1208
|
+
}
|
|
1209
|
+
const taskUpdater = async (taskId, context) => {
|
|
1210
|
+
await taskComponent.updateTask(taskId, { context });
|
|
1211
|
+
};
|
|
1212
|
+
plugin.setTaskUpdater(taskUpdater);
|
|
1213
|
+
}
|
|
1153
1214
|
unloadPlugins() {
|
|
1154
1215
|
for (const plugin of this.loadedPlugins) {
|
|
1155
1216
|
for (const hook of plugin.hooks) {
|
|
@@ -1170,6 +1231,30 @@ class LarkCliInstance {
|
|
|
1170
1231
|
}
|
|
1171
1232
|
}
|
|
1172
1233
|
handleEvent(rawData) {
|
|
1234
|
+
let dedupKey;
|
|
1235
|
+
try {
|
|
1236
|
+
const parsed = JSON.parse(rawData);
|
|
1237
|
+
const eid = parsed.event_id ?? parsed.header?.event_id ?? parsed.id;
|
|
1238
|
+
if (typeof eid === "string" && eid.length > 0) {
|
|
1239
|
+
dedupKey = eid;
|
|
1240
|
+
}
|
|
1241
|
+
} catch {}
|
|
1242
|
+
if (dedupKey) {
|
|
1243
|
+
const now = Date.now();
|
|
1244
|
+
const last = this.recentEventIds.get(dedupKey);
|
|
1245
|
+
if (last !== undefined && now - last < this.DEDUP_WINDOW_MS) {
|
|
1246
|
+
logger.warn(`[LarkCliInstance] duplicate lark-cli event suppressed (event_id=${dedupKey}, ` + `lastSeen=${now - last}ms ago). ` + `Task #3977/3978: 防止同一飞书事件触发两次任务创建。`);
|
|
1247
|
+
return;
|
|
1248
|
+
}
|
|
1249
|
+
this.recentEventIds.set(dedupKey, now);
|
|
1250
|
+
if (this.recentEventIds.size > this.DEDUP_MAX_SIZE) {
|
|
1251
|
+
const cutoff = now - this.DEDUP_WINDOW_MS;
|
|
1252
|
+
for (const [k, t] of this.recentEventIds) {
|
|
1253
|
+
if (t < cutoff)
|
|
1254
|
+
this.recentEventIds.delete(k);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1173
1258
|
const provider = getTracerProvider();
|
|
1174
1259
|
const tracer = provider.getTracer("roy-tracer");
|
|
1175
1260
|
const rootTraceId = generateTraceId();
|
|
@@ -1288,6 +1373,12 @@ class LarkCliInstance {
|
|
|
1288
1373
|
const message = innerEvent?.message || event.message;
|
|
1289
1374
|
const sender = innerEvent?.sender || event.sender || message?.sender;
|
|
1290
1375
|
const senderId = sender?.sender_id;
|
|
1376
|
+
if (typeof event.sender_id === "string") {
|
|
1377
|
+
return event.sender_id;
|
|
1378
|
+
}
|
|
1379
|
+
if (typeof senderId === "string") {
|
|
1380
|
+
return senderId;
|
|
1381
|
+
}
|
|
1291
1382
|
return senderId?.open_id || senderId?.user_id || senderId?.union_id || "unknown";
|
|
1292
1383
|
}
|
|
1293
1384
|
buildReplyChannel(replyChannel) {
|
|
@@ -1300,6 +1391,7 @@ class LarkCliInstance {
|
|
|
1300
1391
|
messageId: replyChannel.messageId,
|
|
1301
1392
|
chatId: replyChannel.chatId,
|
|
1302
1393
|
userId: replyChannel.params?.userId,
|
|
1394
|
+
appId: replyChannel.appId,
|
|
1303
1395
|
profile,
|
|
1304
1396
|
identity: "bot",
|
|
1305
1397
|
sendText: async (text) => {
|
|
@@ -1436,7 +1528,7 @@ var EVENT_SOURCE_CONFIG_REGISTRATION = {
|
|
|
1436
1528
|
};
|
|
1437
1529
|
|
|
1438
1530
|
// src/env/event-source/event-source-component.ts
|
|
1439
|
-
var
|
|
1531
|
+
var logger2 = createLogger("event-source");
|
|
1440
1532
|
|
|
1441
1533
|
class EventSourceComponent extends BaseComponent {
|
|
1442
1534
|
name = "event-source";
|
|
@@ -1503,7 +1595,7 @@ class EventSourceComponent extends BaseComponent {
|
|
|
1503
1595
|
for (const handler of builtInHandlers) {
|
|
1504
1596
|
if (!this.handlers.has(handler.type)) {
|
|
1505
1597
|
this.handlers.set(handler.type, handler);
|
|
1506
|
-
|
|
1598
|
+
logger2.debug(`Registered built-in handler: ${handler.type}`);
|
|
1507
1599
|
}
|
|
1508
1600
|
}
|
|
1509
1601
|
}
|
|
@@ -1513,15 +1605,15 @@ class EventSourceComponent extends BaseComponent {
|
|
|
1513
1605
|
}
|
|
1514
1606
|
registerHandler(handler) {
|
|
1515
1607
|
if (this.handlers.has(handler.type)) {
|
|
1516
|
-
|
|
1608
|
+
logger2.warn(`Handler already registered for type: ${handler.type}, overwriting`);
|
|
1517
1609
|
}
|
|
1518
1610
|
this.handlers.set(handler.type, handler);
|
|
1519
|
-
|
|
1611
|
+
logger2.debug(`Handler registered: ${handler.type}`);
|
|
1520
1612
|
}
|
|
1521
1613
|
unregisterHandler(type) {
|
|
1522
1614
|
const deleted = this.handlers.delete(type);
|
|
1523
1615
|
if (deleted) {
|
|
1524
|
-
|
|
1616
|
+
logger2.debug(`Handler unregistered: ${type}`);
|
|
1525
1617
|
}
|
|
1526
1618
|
return deleted;
|
|
1527
1619
|
}
|
|
@@ -1611,7 +1703,7 @@ class EventSourceComponent extends BaseComponent {
|
|
|
1611
1703
|
});
|
|
1612
1704
|
}
|
|
1613
1705
|
onConfigChange(event) {
|
|
1614
|
-
|
|
1706
|
+
logger2.info(`EventSource config changed: ${event.key}`, {
|
|
1615
1707
|
oldValue: event.oldValue,
|
|
1616
1708
|
newValue: event.newValue
|
|
1617
1709
|
});
|
|
@@ -1630,9 +1722,9 @@ class EventSourceComponent extends BaseComponent {
|
|
|
1630
1722
|
}
|
|
1631
1723
|
this.sources.set(config.id, config);
|
|
1632
1724
|
this.statuses.set(config.id, "created");
|
|
1633
|
-
|
|
1725
|
+
logger2.debug(`EventSource registered: ${config.id} (${config.type})`);
|
|
1634
1726
|
this.saveConfig().catch((err) => {
|
|
1635
|
-
|
|
1727
|
+
logger2.error(`Failed to save config after registering ${config.id}:`, err);
|
|
1636
1728
|
});
|
|
1637
1729
|
}
|
|
1638
1730
|
unregister(id) {
|
|
@@ -1647,9 +1739,9 @@ class EventSourceComponent extends BaseComponent {
|
|
|
1647
1739
|
this.eventHandlers.delete(id);
|
|
1648
1740
|
this.buffers.delete(id);
|
|
1649
1741
|
if (existed) {
|
|
1650
|
-
|
|
1742
|
+
logger2.debug(`EventSource unregistered: ${id}`);
|
|
1651
1743
|
this.saveConfig().catch((err) => {
|
|
1652
|
-
|
|
1744
|
+
logger2.error(`Failed to save config after unregistering ${id}:`, err);
|
|
1653
1745
|
});
|
|
1654
1746
|
}
|
|
1655
1747
|
return existed;
|
|
@@ -1687,13 +1779,13 @@ class EventSourceComponent extends BaseComponent {
|
|
|
1687
1779
|
}
|
|
1688
1780
|
}
|
|
1689
1781
|
this.sources.set(id, updated);
|
|
1690
|
-
|
|
1782
|
+
logger2.info(`EventSource updated: ${id}`, {
|
|
1691
1783
|
fields: Object.keys(partial)
|
|
1692
1784
|
});
|
|
1693
1785
|
try {
|
|
1694
1786
|
await this.saveConfig();
|
|
1695
1787
|
} catch (err) {
|
|
1696
|
-
|
|
1788
|
+
logger2.error(`Failed to save config after updating ${id}:`, err);
|
|
1697
1789
|
throw err;
|
|
1698
1790
|
}
|
|
1699
1791
|
return {
|
|
@@ -1751,6 +1843,9 @@ class EventSourceComponent extends BaseComponent {
|
|
|
1751
1843
|
}
|
|
1752
1844
|
const instance = handler.createInstance(config);
|
|
1753
1845
|
this.instances.set(id, instance);
|
|
1846
|
+
if (typeof instance.setEnvironment === "function") {
|
|
1847
|
+
instance.setEnvironment(this.getEnv());
|
|
1848
|
+
}
|
|
1754
1849
|
const eventHandler = this.eventHandlers.get(id) ?? this.createDefaultEventHandler(id, config.type);
|
|
1755
1850
|
instance.onEvent(eventHandler);
|
|
1756
1851
|
await instance.start();
|
|
@@ -1759,18 +1854,18 @@ class EventSourceComponent extends BaseComponent {
|
|
|
1759
1854
|
type: "event-source.started",
|
|
1760
1855
|
payload: { sourceId: id, sourceType: config.type }
|
|
1761
1856
|
});
|
|
1762
|
-
|
|
1857
|
+
logger2.info(`EventSource started: ${id} (${config.type})`);
|
|
1763
1858
|
} catch (error) {
|
|
1764
1859
|
this.statuses.set(id, "error");
|
|
1765
|
-
|
|
1860
|
+
logger2.error(`EventSource failed to start: ${id}`, error);
|
|
1766
1861
|
throw error;
|
|
1767
1862
|
}
|
|
1768
1863
|
}
|
|
1769
1864
|
async stopSource(id) {
|
|
1770
1865
|
const status = this.statuses.get(id);
|
|
1771
|
-
|
|
1866
|
+
logger2.info(`[EventSource ${id}] stopSource called, current status: ${status}`);
|
|
1772
1867
|
if (status === "stopped" || status === "created") {
|
|
1773
|
-
|
|
1868
|
+
logger2.info(`[EventSource ${id}] already stopped/created, skipping`);
|
|
1774
1869
|
return;
|
|
1775
1870
|
}
|
|
1776
1871
|
this.statuses.set(id, "stopping");
|
|
@@ -1786,10 +1881,10 @@ class EventSourceComponent extends BaseComponent {
|
|
|
1786
1881
|
type: "event-source.stopped",
|
|
1787
1882
|
payload: { sourceId: id, sourceType: config?.type }
|
|
1788
1883
|
});
|
|
1789
|
-
|
|
1884
|
+
logger2.info(`EventSource stopped: ${id}`);
|
|
1790
1885
|
} catch (error) {
|
|
1791
1886
|
this.statuses.set(id, "error");
|
|
1792
|
-
|
|
1887
|
+
logger2.error(`EventSource failed to stop: ${id}`, error);
|
|
1793
1888
|
throw error;
|
|
1794
1889
|
}
|
|
1795
1890
|
}
|
|
@@ -1814,9 +1909,9 @@ class EventSourceComponent extends BaseComponent {
|
|
|
1814
1909
|
sources: Array.from(this.sources.values())
|
|
1815
1910
|
};
|
|
1816
1911
|
writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
1817
|
-
|
|
1912
|
+
logger2.debug(`Saved ${this.sources.size} event source configurations`);
|
|
1818
1913
|
} catch (error) {
|
|
1819
|
-
|
|
1914
|
+
logger2.error("Failed to save event source configurations:", error);
|
|
1820
1915
|
throw error;
|
|
1821
1916
|
}
|
|
1822
1917
|
}
|
|
@@ -1826,13 +1921,13 @@ class EventSourceComponent extends BaseComponent {
|
|
|
1826
1921
|
try {
|
|
1827
1922
|
const configPath = this.getConfigFilePath();
|
|
1828
1923
|
if (!existsSync(configPath)) {
|
|
1829
|
-
|
|
1924
|
+
logger2.debug(`No event source config file found at ${configPath}`);
|
|
1830
1925
|
return;
|
|
1831
1926
|
}
|
|
1832
1927
|
const content = readFileSync(configPath, "utf-8");
|
|
1833
1928
|
const config = JSON.parse(content);
|
|
1834
1929
|
if (!config.sources || !Array.isArray(config.sources)) {
|
|
1835
|
-
|
|
1930
|
+
logger2.warn("Invalid event source config format, skipping load");
|
|
1836
1931
|
return;
|
|
1837
1932
|
}
|
|
1838
1933
|
let loadedCount = 0;
|
|
@@ -1843,9 +1938,9 @@ class EventSourceComponent extends BaseComponent {
|
|
|
1843
1938
|
loadedCount++;
|
|
1844
1939
|
}
|
|
1845
1940
|
}
|
|
1846
|
-
|
|
1941
|
+
logger2.info(`Loaded ${loadedCount} event source configurations`);
|
|
1847
1942
|
} catch (error) {
|
|
1848
|
-
|
|
1943
|
+
logger2.error("Failed to load event source configurations:", error);
|
|
1849
1944
|
}
|
|
1850
1945
|
}
|
|
1851
1946
|
}
|