@clawos-dev/clawd 0.2.423 → 0.2.424

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/dist/cli.cjs +36 -18
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -54342,8 +54342,9 @@ function routeClaimedEvents(items, opts) {
54342
54342
  for (const it of items) {
54343
54343
  opts.dedupe.add(it.payload.eventId);
54344
54344
  const env = { ...it.payload, iat: opts.nowSec, exp: opts.nowSec + 300 };
54345
- if (it.status === "forwarded" && it.payload.type === "message") resume.push(env);
54346
- else opts.router.handleEnvelope(env);
54345
+ if (it.status === "forwarded" && (it.payload.type === "message" || it.payload.type === "doc_comment")) {
54346
+ resume.push(env);
54347
+ } else opts.router.handleEnvelope(env);
54347
54348
  }
54348
54349
  if (resume.length > 0) opts.router.handleResume(resume);
54349
54350
  }
@@ -54406,7 +54407,17 @@ function createLarkChatRouter(deps) {
54406
54407
  }
54407
54408
  return lines;
54408
54409
  };
54410
+ const replyAnchorOf = (env) => env.type === "doc_comment" ? env.commentId : env.messageId;
54411
+ const buildDocCommentSection = (env) => {
54412
+ const lines = [];
54413
+ if (env.quote) lines.push(`[\u6587\u6863\u539F\u6587] ${env.quote}`);
54414
+ const body = env.text?.trim();
54415
+ if (body) lines.push(body);
54416
+ if (lines.length === 0) lines.push("[\u6709\u4EBA\u5728\u98DE\u4E66\u6587\u6863\u91CC @ \u4E86\u4F60\uFF0C\u4F46\u8BC4\u8BBA\u5185\u5BB9\u62C9\u53D6\u5931\u8D25]");
54417
+ return lines.join("\n");
54418
+ };
54409
54419
  const buildSection = async (env) => {
54420
+ if (env.type === "doc_comment") return buildDocCommentSection(env);
54410
54421
  const parentLines = env.parentMessageId ? [
54411
54422
  ...await imageLinesFor(env, env.parentMessageId, env.parentImageKeys ?? []),
54412
54423
  ...await fileLinesFor(env, env.parentMessageId, env.parentFiles ?? [])
@@ -54432,14 +54443,16 @@ ${body}
54432
54443
  const runBatch = async (batchEnvs, opts) => {
54433
54444
  if (deps.isShuttingDown?.()) return;
54434
54445
  const envs = batchEnvs.filter((e) => {
54435
- if (e.messageId) return true;
54436
- deps.logger?.warn(`larkBot chat-router: message envelope missing messageId, drop ${e.eventId}`);
54446
+ if (replyAnchorOf(e)) return true;
54447
+ deps.logger?.warn(`larkBot chat-router: envelope missing reply anchor, drop ${e.eventId}`);
54437
54448
  return false;
54438
54449
  });
54439
54450
  if (envs.length === 0) return;
54440
54451
  const last = envs[envs.length - 1];
54441
54452
  const speaker = last.senderName || last.senderOpenId || "\u672A\u77E5\u6210\u5458";
54442
- const idxByMessageId = new Map(envs.map((e, i) => [e.messageId, i]));
54453
+ const idxByMessageId = new Map(
54454
+ envs.flatMap((e, i) => e.messageId ? [[e.messageId, i]] : [])
54455
+ );
54443
54456
  const sections = [];
54444
54457
  for (const [i, env] of envs.entries()) {
54445
54458
  const sectionBody = await buildSection(env);
@@ -54494,9 +54507,12 @@ ${formatLarkSpeakerReminder(speaker)}`
54494
54507
  await deps.cloud.reply({
54495
54508
  appId: last.appId,
54496
54509
  chatId: last.chatId,
54497
- replyToMessageId: last.messageId,
54510
+ // envs 已过滤保证锚点非空
54511
+ replyToMessageId: replyAnchorOf(last),
54498
54512
  text: replyText,
54499
54513
  eventId: last.eventId,
54514
+ // 文档评论:云端据此走评论回复接口而非 IM(显式字段,不靠 chatId 前缀猜)
54515
+ ...last.type === "doc_comment" ? { docComment: { fileToken: last.fileToken, fileType: last.fileType ?? "docx" } } : {},
54500
54516
  ...absorbed.length > 0 ? { absorbedEventIds: absorbed } : {}
54501
54517
  });
54502
54518
  return;
@@ -54520,11 +54536,12 @@ ${formatLarkSpeakerReminder(speaker)}`
54520
54536
  if (queues.get(chatId) === next) queues.delete(chatId);
54521
54537
  });
54522
54538
  };
54523
- const flushPending = (chatId) => {
54524
- const batch = pending.get(chatId);
54539
+ const debounceKeyOf = (env) => env.type === "doc_comment" ? `${env.chatId}|${env.commentId ?? ""}` : env.chatId;
54540
+ const flushPending = (key) => {
54541
+ const batch = pending.get(key);
54525
54542
  if (!batch) return;
54526
54543
  clearTimeout(batch.timer);
54527
- pending.delete(chatId);
54544
+ pending.delete(key);
54528
54545
  enqueueBatch(batch.envelopes);
54529
54546
  };
54530
54547
  return {
@@ -54542,26 +54559,27 @@ ${formatLarkSpeakerReminder(speaker)}`
54542
54559
  return;
54543
54560
  }
54544
54561
  const sender = env.senderOpenId ?? "";
54545
- const cur = pending.get(env.chatId);
54546
- if (cur && cur.senderOpenId !== sender) flushPending(env.chatId);
54547
- const batch = pending.get(env.chatId);
54562
+ const key = debounceKeyOf(env);
54563
+ const cur = pending.get(key);
54564
+ if (cur && cur.senderOpenId !== sender) flushPending(key);
54565
+ const batch = pending.get(key);
54548
54566
  if (batch) {
54549
54567
  batch.envelopes.push(env);
54550
54568
  clearTimeout(batch.timer);
54551
- batch.timer = setTimeout(() => flushPending(env.chatId), debounceMs);
54569
+ batch.timer = setTimeout(() => flushPending(key), debounceMs);
54552
54570
  } else {
54553
- pending.set(env.chatId, {
54571
+ pending.set(key, {
54554
54572
  envelopes: [env],
54555
54573
  senderOpenId: sender,
54556
- timer: setTimeout(() => flushPending(env.chatId), debounceMs)
54574
+ timer: setTimeout(() => flushPending(key), debounceMs)
54557
54575
  });
54558
54576
  }
54559
54577
  },
54560
54578
  handleResume(envelopes) {
54561
54579
  const groups = /* @__PURE__ */ new Map();
54562
54580
  for (const env of envelopes) {
54563
- if (env.type !== "message") continue;
54564
- const key = `${env.chatId}|${env.senderOpenId ?? ""}`;
54581
+ if (env.type !== "message" && env.type !== "doc_comment") continue;
54582
+ const key = `${debounceKeyOf(env)}|${env.senderOpenId ?? ""}`;
54565
54583
  const group = groups.get(key);
54566
54584
  if (group) group.push(env);
54567
54585
  else groups.set(key, [env]);
@@ -62312,7 +62330,7 @@ function computeMethodAccess(args) {
62312
62330
  }
62313
62331
 
62314
62332
  // src/version.ts
62315
- var version = "0.2.423".length > 0 ? "0.2.423" : "dev";
62333
+ var version = "0.2.424".length > 0 ? "0.2.424" : "dev";
62316
62334
 
62317
62335
  // src/cli-probe/probe.ts
62318
62336
  var fs65 = __toESM(require("fs"), 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawos-dev/clawd",
3
- "version": "0.2.423",
3
+ "version": "0.2.424",
4
4
  "description": "Standalone clawd daemon — Claude Code (and future Codex) session server over WebSocket",
5
5
  "type": "module",
6
6
  "license": "MIT",