@qihoo/tuitui-openclaw-channel 1.0.28 → 1.0.30
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/openclaw.plugin.json +2 -2
- package/package.json +1 -1
- package/src/chat_record.ts +11 -1
- package/src/monitor.ts +32 -23
package/openclaw.plugin.json
CHANGED
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
"advanced": true
|
|
132
132
|
},
|
|
133
133
|
"monitorEnabled": {
|
|
134
|
-
"help": "是否开启agent事件信息上报(默认 false
|
|
134
|
+
"help": "是否开启agent事件信息上报(默认 false)。",
|
|
135
135
|
"order": 17,
|
|
136
136
|
"advanced": true
|
|
137
137
|
},
|
|
@@ -185,7 +185,7 @@
|
|
|
185
185
|
"advanced": true
|
|
186
186
|
},
|
|
187
187
|
"accounts.*.monitorEnabled": {
|
|
188
|
-
"help": "是否开启agent事件信息上报(默认 false
|
|
188
|
+
"help": "是否开启agent事件信息上报(默认 false)。",
|
|
189
189
|
"order": 311,
|
|
190
190
|
"advanced": true
|
|
191
191
|
}
|
package/package.json
CHANGED
package/src/chat_record.ts
CHANGED
|
@@ -381,9 +381,19 @@ export async function getPostChainByChatId(
|
|
|
381
381
|
|
|
382
382
|
async function getChannelPostList(
|
|
383
383
|
account: any,
|
|
384
|
-
|
|
384
|
+
chatId: string,
|
|
385
385
|
options: GetChatRecordOptions = {}
|
|
386
386
|
): Promise<any> {
|
|
387
|
+
// chatId 支持2种格式:
|
|
388
|
+
// case1: 在频道中发送:总结当前频道最近3天内容,此时传入 chatId 为sessionKey,即 teams_xxx
|
|
389
|
+
// case2: 在私聊中发消息:总结频道 12345 最近3天内容,此时传入 chatId 为 12345
|
|
390
|
+
let channel_id = chatId;
|
|
391
|
+
const guessType = guessChatType(chatId);
|
|
392
|
+
if(guessType == CHAT_TYPE_CHANNEL) {
|
|
393
|
+
const target = teamsParseChatId(chatId);
|
|
394
|
+
channel_id = target.channel_id;
|
|
395
|
+
}
|
|
396
|
+
|
|
387
397
|
const channel_info = await getChannelInfoById(account, channel_id);
|
|
388
398
|
const team_id = channel_info?.team_id;
|
|
389
399
|
const channel_name = channel_info?.name;
|
package/src/monitor.ts
CHANGED
|
@@ -34,7 +34,9 @@ export type MonitorEventType =
|
|
|
34
34
|
| 'after_tool_call'
|
|
35
35
|
| 'session_start'
|
|
36
36
|
| 'session_end'
|
|
37
|
-
| 'agent_end'
|
|
37
|
+
| 'agent_end'
|
|
38
|
+
| 'subagent_spawned'
|
|
39
|
+
| 'subagent_ended';
|
|
38
40
|
|
|
39
41
|
export interface MonitorPayload {
|
|
40
42
|
event: MonitorEventType;
|
|
@@ -176,26 +178,22 @@ function resolveMonitorTargets(cfg: any): MonitorTarget[] {
|
|
|
176
178
|
// ─────────────────────────────────────────────────────────────
|
|
177
179
|
|
|
178
180
|
/**
|
|
179
|
-
* 从
|
|
180
|
-
* sessionKey 格式:agent:<agentId
|
|
181
|
+
* 从 sessionKey 字符串中解析出 agentId。
|
|
182
|
+
* sessionKey 格式:agent:<agentId>:...
|
|
181
183
|
*/
|
|
182
|
-
function
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return parts[agentIdx + 1];
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return null;
|
|
184
|
+
function extractAgentId(sessionKey: unknown): string | null {
|
|
185
|
+
if (typeof sessionKey !== 'string') return null;
|
|
186
|
+
const parts = sessionKey.split(':');
|
|
187
|
+
const idx = parts.indexOf('agent');
|
|
188
|
+
if (idx === -1 || !parts[idx + 1]) return null;
|
|
189
|
+
return parts[idx + 1];
|
|
192
190
|
}
|
|
193
191
|
|
|
194
192
|
// ─────────────────────────────────────────────────────────────
|
|
195
193
|
// 大字段裁剪
|
|
196
194
|
// ─────────────────────────────────────────────────────────────
|
|
197
195
|
|
|
198
|
-
const TRUNCATE_LIMIT =
|
|
196
|
+
const TRUNCATE_LIMIT = 64 * 1024; // 64 KB
|
|
199
197
|
|
|
200
198
|
function truncate(s: unknown): unknown {
|
|
201
199
|
if (typeof s !== 'string' || s.length <= TRUNCATE_LIMIT) return s;
|
|
@@ -265,7 +263,7 @@ function trimData(eventType: MonitorEventType, data: unknown): unknown {
|
|
|
265
263
|
}
|
|
266
264
|
|
|
267
265
|
// ─────────────────────────────────────────────────────────────
|
|
268
|
-
// 主入口:收到 hook
|
|
266
|
+
// 主入口:收到 hook 事件后入队
|
|
269
267
|
// ─────────────────────────────────────────────────────────────
|
|
270
268
|
|
|
271
269
|
function report(
|
|
@@ -274,7 +272,15 @@ function report(
|
|
|
274
272
|
ctx: unknown,
|
|
275
273
|
data: unknown,
|
|
276
274
|
): void {
|
|
277
|
-
|
|
275
|
+
let agentId: string | null;
|
|
276
|
+
|
|
277
|
+
// subagent hook 的 ctx 有 childSessionKey,普通 hook 有 sessionKey
|
|
278
|
+
if (eventType === 'subagent_spawned' || eventType === 'subagent_ended') {
|
|
279
|
+
agentId = extractAgentId((ctx as any)?.childSessionKey);
|
|
280
|
+
} else {
|
|
281
|
+
agentId = extractAgentId((ctx as any)?.sessionKey);
|
|
282
|
+
}
|
|
283
|
+
|
|
278
284
|
if (!agentId) return;
|
|
279
285
|
|
|
280
286
|
for (const target of targets) {
|
|
@@ -295,16 +301,17 @@ function report(
|
|
|
295
301
|
}
|
|
296
302
|
|
|
297
303
|
// ─────────────────────────────────────────────────────────────
|
|
298
|
-
// 注册全量 Hook
|
|
304
|
+
// 注册全量 Hook
|
|
299
305
|
// ─────────────────────────────────────────────────────────────
|
|
300
306
|
|
|
301
307
|
export function registerMonitorHooks(api: OpenClawPluginApi) {
|
|
302
|
-
const targets = resolveMonitorTargets(api.config);
|
|
303
|
-
if (targets.length === 0) return;
|
|
304
|
-
|
|
305
|
-
// targets 通过闭包捕获,所有 hook 共享,零运行时开销
|
|
306
308
|
const on = (eventType: MonitorEventType) =>
|
|
307
|
-
api.on(eventType, (event, ctx) => {
|
|
309
|
+
api.on(eventType as any, (event: unknown, ctx: unknown) => {
|
|
310
|
+
const targets = resolveMonitorTargets(api.runtime.config.loadConfig());
|
|
311
|
+
if (targets.length > 0) {
|
|
312
|
+
report(targets, eventType, ctx, event);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
308
315
|
|
|
309
316
|
// ── Agent run 阶段 ────────────────────────────────────────
|
|
310
317
|
on('llm_input');
|
|
@@ -327,5 +334,7 @@ export function registerMonitorHooks(api: OpenClawPluginApi) {
|
|
|
327
334
|
on('session_start');
|
|
328
335
|
on('session_end');
|
|
329
336
|
|
|
330
|
-
|
|
337
|
+
// ── Subagent 阶段 ─────────────────────────────────────────
|
|
338
|
+
on('subagent_spawned');
|
|
339
|
+
on('subagent_ended');
|
|
331
340
|
}
|