@yeaft/webchat-agent 0.0.31 → 0.0.33

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.
Files changed (2) hide show
  1. package/claude.js +22 -1
  2. package/package.json +1 -1
package/claude.js CHANGED
@@ -284,6 +284,7 @@ async function processClaudeOutput(conversationId, claudeQuery, state) {
284
284
  if (message.type === 'system') {
285
285
  // 新格式: subtype: 'status', status: 'compacting'
286
286
  if (message.subtype === 'status' && message.status === 'compacting') {
287
+ state._compacting = true;
287
288
  console.log(`[${conversationId}] Compact started (status)`);
288
289
  ctx.sendToServer({
289
290
  type: 'compact_status',
@@ -292,8 +293,10 @@ async function processClaudeOutput(conversationId, claudeQuery, state) {
292
293
  message: 'Context compacting in progress...'
293
294
  });
294
295
  }
295
- // compact 边界标记 — 表示 compact 完成
296
+ // compact 边界标记 — 表示 compact 完成,后续会有 summary user 消息需要过滤
296
297
  if (message.subtype === 'compact_boundary') {
298
+ state._compacting = false;
299
+ state._compactSummaryPending = true;
297
300
  console.log(`[${conversationId}] Compact completed (boundary)`);
298
301
  ctx.sendToServer({
299
302
  type: 'compact_status',
@@ -304,6 +307,7 @@ async function processClaudeOutput(conversationId, claudeQuery, state) {
304
307
  }
305
308
  // 旧格式兼容
306
309
  if (message.subtype === 'compact_start' || message.message?.includes?.('Compacting')) {
310
+ state._compacting = true;
307
311
  console.log(`[${conversationId}] Compact started`);
308
312
  ctx.sendToServer({
309
313
  type: 'compact_status',
@@ -313,6 +317,8 @@ async function processClaudeOutput(conversationId, claudeQuery, state) {
313
317
  });
314
318
  }
315
319
  if (message.subtype === 'compact_complete' || message.subtype === 'compact_end') {
320
+ state._compacting = false;
321
+ state._compactSummaryPending = true;
316
322
  console.log(`[${conversationId}] Compact completed`);
317
323
  ctx.sendToServer({
318
324
  type: 'compact_status',
@@ -323,6 +329,21 @@ async function processClaudeOutput(conversationId, claudeQuery, state) {
323
329
  }
324
330
  }
325
331
 
332
+ // 过滤 compact 过程中的 system 消息(如 status:null、重新 init)
333
+ if (message.type === 'system' && state._compacting) {
334
+ continue;
335
+ }
336
+
337
+ // 过滤 compact summary 消息(compact_boundary 之后的 user 消息)
338
+ if (message.type === 'user' && state._compactSummaryPending) {
339
+ console.log(`[${conversationId}] Filtering compact summary message`);
340
+ continue;
341
+ }
342
+ // compact 后的 <local-command-stdout>Compacted </local-command-stdout> 标记 summary 结束
343
+ if (state._compactSummaryPending && message.type !== 'user') {
344
+ state._compactSummaryPending = false;
345
+ }
346
+
326
347
  // 捕获 result 消息中的 usage 信息
327
348
  if (message.type === 'result') {
328
349
  // 累计 usage(无论是否重复,始终统计)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "description": "Remote agent for Yeaft WebChat — connects worker machines to the central server",
5
5
  "main": "index.js",
6
6
  "type": "module",