@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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qihoo/tuitui-openclaw-channel",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "maintainers": [
5
5
  {
6
6
  "name": "huzunjie",
@@ -381,9 +381,19 @@ export async function getPostChainByChatId(
381
381
 
382
382
  async function getChannelPostList(
383
383
  account: any,
384
- channel_id: string,
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
- * 从 ctx.sessionKey 中解析出 agentId。
180
- * sessionKey 格式:agent:<agentId>:tuitui:<accountId>:<chatType>:<chatId>
181
+ * 从 sessionKey 字符串中解析出 agentId。
182
+ * sessionKey 格式:agent:<agentId>:...
181
183
  */
182
- function extractAgentIdFromCtx(ctx: unknown): string | null {
183
- const c = ctx as any;
184
- if (typeof c?.sessionKey === 'string') {
185
- const parts = c.sessionKey.split(':');
186
- const agentIdx = parts.indexOf('agent');
187
- if (agentIdx !== -1 && agentIdx + 1 < parts.length && parts[agentIdx + 1]) {
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 = 500;
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 事件后入队(targets 由注册时闭包捕获)
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
- const agentId = extractAgentIdFromCtx(ctx);
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) => { report(targets, eventType, ctx, event); });
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
- console.log(`[${CHANNEL_ID}][monitor] Monitor hooks registered for ${targets.length} account(s): ${targets.map(t => t.accountId).join(', ')} (batch_size=${BATCH_MAX_SIZE} interval=${BATCH_INTERVAL_MS}ms).`);
337
+ // ── Subagent 阶段 ─────────────────────────────────────────
338
+ on('subagent_spawned');
339
+ on('subagent_ended');
331
340
  }