aai-lark-bridge 0.2.43 → 0.2.44

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/dist/cli.js CHANGED
@@ -4,7 +4,7 @@ import { Command } from "commander";
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "aai-lark-bridge",
7
- version: "0.2.43",
7
+ version: "0.2.44",
8
8
  description: "Lark AI Native Bridge - Lark\u57FA\u7840\u8BBE\u65BD\u5C42\u548CCLI\u96C6\u6210",
9
9
  type: "module",
10
10
  main: "./dist/index.js",
@@ -15336,6 +15336,24 @@ async function removeReaction(channel, messageId, reactionId) {
15336
15336
  var POSITIVE_EMOJIS = /* @__PURE__ */ new Set(["OK", "THUMBSUP", "DONE", "JIAYI", "LGTM"]);
15337
15337
  var CONFIRM_WINDOW_MS = 45 * 6e4;
15338
15338
  var SCOPE_MAX = 500;
15339
+ function extractText(content) {
15340
+ if (!content) return "";
15341
+ let tree;
15342
+ try {
15343
+ tree = JSON.parse(content);
15344
+ } catch {
15345
+ return content;
15346
+ }
15347
+ const out = [];
15348
+ const walk = (v, key) => {
15349
+ if (typeof v === "string") {
15350
+ if (key === "text" || key === "content" || key === "title") out.push(v);
15351
+ } else if (Array.isArray(v)) v.forEach((x) => walk(x, key));
15352
+ else if (v && typeof v === "object") for (const [k, x] of Object.entries(v)) walk(x, k);
15353
+ };
15354
+ walk(tree);
15355
+ return out.join("\n");
15356
+ }
15339
15357
  function isConfirmQuestion(text) {
15340
15358
  const tail = text.trim().split(/[。!!\n]/).map((s) => s.trim()).filter(Boolean).pop() ?? "";
15341
15359
  return /[??]$/.test(tail) && /吗|是否|要不要|可不可以|对不对|行不行|可以不/.test(tail);
@@ -15371,20 +15389,20 @@ var ReactionConfirmer = class {
15371
15389
  if (this.used.has(evt.messageId)) return reject4("already-used");
15372
15390
  let bot;
15373
15391
  try {
15374
- bot = await channel.fetchMessage(evt.messageId);
15392
+ bot = (await channel.fetchRawMessage(evt.messageId))[0];
15375
15393
  } catch (err) {
15376
15394
  log.warn("reaction-confirm", "fetch-failed", { messageId: evt.messageId, err: String(err) });
15377
15395
  return void 0;
15378
15396
  }
15379
- if (!bot) return reject4("message-not-found");
15380
- if (bot.senderIsBot !== true) return reject4("not-bot-message");
15381
- const parentId = bot.replyToMessageId;
15397
+ if (!bot?.message_id) return reject4("message-not-found");
15398
+ if (bot.sender?.sender_type !== "app" && bot.sender?.sender_type !== "bot") return reject4("not-bot-message");
15399
+ const parentId = bot.parent_id;
15382
15400
  const handled = parentId ? this.byUserMsg.get(parentId) : void 0;
15383
15401
  if (!handled || !parentId) return reject4("not-reply-to-handled-message");
15384
15402
  if (this.latestByScope.get(handled.scope) !== parentId) return reject4("not-latest");
15385
- if (handled.msg.chatId !== bot.chatId) return reject4("chat-mismatch");
15403
+ if (handled.msg.chatId !== bot.chat_id) return reject4("chat-mismatch");
15386
15404
  if (evt.operator.openId !== handled.msg.senderId) return reject4("not-asker");
15387
- if (!isConfirmQuestion(bot.content)) return reject4("not-a-question");
15405
+ if (!isConfirmQuestion(extractText(bot.body?.content))) return reject4("not-a-question");
15388
15406
  const t = this.now();
15389
15407
  if (t - handled.msg.createTime > CONFIRM_WINDOW_MS) return reject4("expired");
15390
15408
  this.used.add(evt.messageId);