cc-claw 0.20.19 → 0.20.20

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.js +72 -3
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -33,7 +33,7 @@ var VERSION;
33
33
  var init_version = __esm({
34
34
  "src/version.ts"() {
35
35
  "use strict";
36
- VERSION = true ? "0.20.19" : (() => {
36
+ VERSION = true ? "0.20.20" : (() => {
37
37
  try {
38
38
  return JSON.parse(readFileSync(join(process.cwd(), "package.json"), "utf-8")).version ?? "unknown";
39
39
  } catch {
@@ -18537,7 +18537,8 @@ async function handleMedia(msg, channel) {
18537
18537
  await channel.sendText(chatId, mLimitMsg, { parseMode: "plain" });
18538
18538
  return;
18539
18539
  }
18540
- await channel.sendText(chatId, "Processing your file...", { parseMode: "plain" });
18540
+ const fileCount = 1 + (msg.extraFiles?.length ?? 0);
18541
+ await channel.sendText(chatId, fileCount > 1 ? `Processing ${fileCount} files...` : "Processing your file...", { parseMode: "plain" });
18541
18542
  try {
18542
18543
  if (msg.type === "video") {
18543
18544
  const fileId = msg.metadata?.fileId ?? fileName;
@@ -18620,13 +18621,39 @@ Acknowledge receipt. Do NOT analyze the video unless they ask you to.`;
18620
18621
  if (msg.type === "photo" || isImageExt(ext)) {
18621
18622
  const imgExt = msg.type === "photo" ? "jpg" : ext || "jpg";
18622
18623
  tempFilePath = await saveMedia(fileBuffer, "img", imgExt);
18623
- prompt = caption ? `The user sent an image with caption: "${caption}"
18624
+ const allPaths = [tempFilePath];
18625
+ if (msg.extraFiles?.length) {
18626
+ for (const extra of msg.extraFiles) {
18627
+ try {
18628
+ const extraBuffer = await channel.downloadFile(extra.fileName);
18629
+ const extraExt = extra.mimeType.startsWith("image/") ? extra.mimeType.split("/")[1] || "jpg" : "jpg";
18630
+ const extraPath = await saveMedia(extraBuffer, "img", extraExt);
18631
+ allPaths.push(extraPath);
18632
+ } catch (err) {
18633
+ log(`[media] Failed to download extra file: ${errorMessage(err)}`);
18634
+ }
18635
+ }
18636
+ }
18637
+ if (allPaths.length === 1) {
18638
+ prompt = caption ? `The user sent an image with caption: "${caption}"
18624
18639
 
18625
18640
  The image has been saved to: ${tempFilePath}
18626
18641
 
18627
18642
  Please read the image file and respond to their caption/question.` : `The user sent an image. It has been saved to: ${tempFilePath}
18628
18643
 
18629
18644
  Please read the image file and describe what you see.`;
18645
+ } else {
18646
+ const pathList = allPaths.map((p, i) => `${i + 1}. ${p}`).join("\n");
18647
+ prompt = caption ? `The user sent ${allPaths.length} images with caption: "${caption}"
18648
+
18649
+ The images have been saved to:
18650
+ ${pathList}
18651
+
18652
+ Please read all image files and respond to their caption/question.` : `The user sent ${allPaths.length} images. They have been saved to:
18653
+ ${pathList}
18654
+
18655
+ Please read all image files and describe what you see.`;
18656
+ }
18630
18657
  } else if (isTextExt(ext)) {
18631
18658
  const MAX_TEXT_FILE_BYTES = 1048576;
18632
18659
  if (fileBuffer.length > MAX_TEXT_FILE_BYTES) {
@@ -28009,6 +28036,11 @@ var init_telegram2 = __esm({
28009
28036
  // messageId → chatId
28010
28037
  reactionHandlers = [];
28011
28038
  throttle;
28039
+ // ── Media group debouncing ─────────────────────────────────────────
28040
+ // Telegram sends each photo in a media group as a separate update.
28041
+ // We buffer them by media_group_id and emit one merged IncomingMessage.
28042
+ mediaGroupBuffer = /* @__PURE__ */ new Map();
28043
+ static MEDIA_GROUP_DEBOUNCE_MS = 500;
28012
28044
  // ── Polling health tracking ─────────────────────────────────────────
28013
28045
  /** Timestamp of last update received from Telegram (message, callback, reaction) */
28014
28046
  lastUpdateAt = 0;
@@ -28171,6 +28203,19 @@ var init_telegram2 = __esm({
28171
28203
  return;
28172
28204
  }
28173
28205
  log(`[telegram] Processing ${msg.type}: "${msg.text?.slice(0, 50) || msg.command || "(media)"}"`);
28206
+ const mediaGroupId = ctx.message?.media_group_id;
28207
+ if (mediaGroupId && (msg.type === "photo" || msg.type === "video" || msg.type === "document")) {
28208
+ const existing = this.mediaGroupBuffer.get(mediaGroupId);
28209
+ if (existing) {
28210
+ existing.messages.push(msg);
28211
+ clearTimeout(existing.timer);
28212
+ existing.timer = setTimeout(() => this.flushMediaGroup(mediaGroupId), _TelegramChannel.MEDIA_GROUP_DEBOUNCE_MS);
28213
+ } else {
28214
+ const timer = setTimeout(() => this.flushMediaGroup(mediaGroupId), _TelegramChannel.MEDIA_GROUP_DEBOUNCE_MS);
28215
+ this.mediaGroupBuffer.set(mediaGroupId, { messages: [msg], timer, handler, channel: this });
28216
+ }
28217
+ return;
28218
+ }
28174
28219
  if (isFastPathMessage(msg)) {
28175
28220
  handler(msg, this).catch((err) => {
28176
28221
  error("[telegram] Fast-path handler error:", err);
@@ -28619,6 +28664,30 @@ var init_telegram2 = __esm({
28619
28664
  }
28620
28665
  this.agentMessageIds.set(messageId, chatId);
28621
28666
  }
28667
+ /**
28668
+ * Flush a buffered media group — merge all files into a single IncomingMessage
28669
+ * with the first file as primary and the rest in extraFiles.
28670
+ */
28671
+ flushMediaGroup(groupId) {
28672
+ const group = this.mediaGroupBuffer.get(groupId);
28673
+ if (!group) return;
28674
+ this.mediaGroupBuffer.delete(groupId);
28675
+ const [primary, ...rest] = group.messages;
28676
+ if (rest.length > 0) {
28677
+ primary.extraFiles = rest.map((m) => ({
28678
+ fileName: m.fileName,
28679
+ mimeType: m.mimeType ?? "application/octet-stream"
28680
+ }));
28681
+ if (!primary.caption) {
28682
+ const withCaption = rest.find((m) => m.caption);
28683
+ if (withCaption) primary.caption = withCaption.caption;
28684
+ }
28685
+ log(`[telegram] Media group ${groupId}: merged ${group.messages.length} files into one message`);
28686
+ }
28687
+ group.handler(primary, group.channel).catch((err) => {
28688
+ error("[telegram] Media group handler error:", err);
28689
+ });
28690
+ }
28622
28691
  buildIncomingMessage(ctx) {
28623
28692
  const chatId = ctx.chat.id.toString();
28624
28693
  const messageId = ctx.message?.message_id?.toString() ?? "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-claw",
3
- "version": "0.20.19",
3
+ "version": "0.20.20",
4
4
  "description": "CC-Claw: Personal AI assistant on Telegram — multi-backend (Claude, Gemini, Codex, Cursor), sub-agent orchestration, MCP management",
5
5
  "type": "module",
6
6
  "main": "dist/cli.js",