aai-lark-bridge 0.2.22 → 0.2.23

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.22",
7
+ version: "0.2.23",
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",
@@ -623,9 +623,17 @@ function normalizeAccess(access3, legacyRequireMentionInGroup) {
623
623
  requireMentionInGroup: access3?.requireMentionInGroup ?? legacyRequireMentionInGroup ?? true,
624
624
  // Omit when empty so configs without per-chat overrides stay clean.
625
625
  ...Object.keys(chatRequireMention).length > 0 ? { chatRequireMention } : {},
626
- ...access3?.disableGroupRuns === true ? { disableGroupRuns: true } : {}
626
+ ...access3?.disableGroupRuns === true ? { disableGroupRuns: true } : {},
627
+ ...groupIntakeOf(access3?.groupIntake)
627
628
  };
628
629
  }
630
+ function groupIntakeOf(input) {
631
+ if (!input || typeof input !== "object" || Array.isArray(input)) return {};
632
+ const raw = input;
633
+ const chats = stringArray(raw.chats).filter((c) => /^oc_[A-Za-z0-9_-]+$/.test(c));
634
+ const command = typeof raw.command === "string" ? raw.command.trim() : "";
635
+ return chats.length && command ? { groupIntake: { chats, command } } : {};
636
+ }
629
637
  function normalizeChatMentionMap(input) {
630
638
  if (!input || typeof input !== "object" || Array.isArray(input)) return {};
631
639
  const out = {};
@@ -8777,7 +8785,7 @@ function digestCanonical(value) {
8777
8785
  }
8778
8786
 
8779
8787
  // src/bridge/policy/access.ts
8780
- var GROUP_RUNS_DISABLED_HINT = "\u7FA4\u91CC\u4E0D\u518D\u63A5\u6D3B\uFF0C\u8BF7\u79C1\u804A Coach";
8788
+ var GROUP_RUNS_DISABLED_HINT = "\u7FA4\u91CC\u4E0D\u63A5\u6D3B\uFF0C\u8BF7\u79C1\u804A\u6211";
8781
8789
  function isCreator(controls, senderId) {
8782
8790
  if (controls.ownerRefreshState === "unknown") return false;
8783
8791
  return Boolean(controls.botOwnerId) && controls.botOwnerId === senderId;
@@ -13311,6 +13319,42 @@ async function removeRejectedResolvedFiles(attachments) {
13311
13319
  );
13312
13320
  }
13313
13321
 
13322
+ // src/bridge/bot/group-intake.ts
13323
+ import { execFile } from "child_process";
13324
+ var GROUP_INTAKE_TIMEOUT_MS = 3e4;
13325
+ var defaultRunner = (bin, args, timeoutMs) => new Promise((resolve3) => {
13326
+ execFile(bin, args, { encoding: "utf8", timeout: timeoutMs, maxBuffer: 1 << 20 }, (err, stdout) => {
13327
+ resolve3({ stdout: String(stdout ?? ""), ...err ? { error: err.killed ? "\u8D85\u65F6" : String(err.message ?? err) } : {} });
13328
+ });
13329
+ });
13330
+ function groupIntakeCovers(cfg, chatId) {
13331
+ return Boolean(cfg && cfg.command.trim() && cfg.chats.includes(chatId));
13332
+ }
13333
+ async function runGroupIntake(cfg, msg, run2 = defaultRunner) {
13334
+ const [bin, ...pre] = cfg.command.trim().split(/\s+/);
13335
+ const base = { chatId: msg.chatId, msgId: msg.messageId, sender: msg.senderId.slice(-6) };
13336
+ const r = await run2(bin, [...pre, "--group", "--message-id", msg.messageId], GROUP_INTAKE_TIMEOUT_MS);
13337
+ let out;
13338
+ try {
13339
+ out = JSON.parse(r.stdout.trim().split("\n").filter(Boolean).at(-1) ?? "");
13340
+ } catch {
13341
+ out = void 0;
13342
+ }
13343
+ if (out?.status === "created" || out?.status === "existing") {
13344
+ log.info("group-intake", out.status, base);
13345
+ const head = out.status === "created" ? "\u5DF2\u5EFA\u4EFB\u52A1" : "\u8FD9\u6761\u6D88\u606F\u5DF2\u7ECF\u5EFA\u8FC7\u4EFB\u52A1";
13346
+ return `${head}\uFF1A${out.url ?? ""}
13347
+ \u8D1F\u8D23\u4EBA\u662F\u4F60\uFF0C\u8C03\u5EA6 5 \u5206\u949F\u5185\u63A5\u8D70\uFF0C\u7ED3\u679C\u79C1\u804A\u4F60\u3002`;
13348
+ }
13349
+ if (out?.status === "refused" && out.reason) {
13350
+ log.info("group-intake", "refused", { ...base, reason: out.reason.slice(0, 200) });
13351
+ return out.reason;
13352
+ }
13353
+ const detail = (out?.reason ?? r.error ?? "\u547D\u4EE4\u6CA1\u6709\u8FD4\u56DE\u7ED3\u679C").slice(0, 200);
13354
+ log.warn("group-intake", "failed", { ...base, detail });
13355
+ return `\u5EFA\u4EFB\u52A1\u6CA1\u6210\u529F\uFF1A${detail}\uFF0C\u7A0D\u540E\u518D\u8BD5\u6216\u79C1\u804A\u6211`;
13356
+ }
13357
+
13314
13358
  // src/bridge/policy/owner.ts
13315
13359
  var OWNER_REFRESH_INTERVAL_MS = 30 * 60 * 1e3;
13316
13360
  async function refreshOwnerControls(controls, source, appId) {
@@ -15765,6 +15809,13 @@ async function sendNonAllowedGroupHint(channel, chatId, replyToMessageId, overri
15765
15809
  await channel.send(chatId, { text });
15766
15810
  }
15767
15811
  }
15812
+ async function sendGroupIntakeReply(channel, chatId, replyTo, text) {
15813
+ try {
15814
+ await channel.send(chatId, { text }, { replyTo, replyInThread: true });
15815
+ } catch {
15816
+ await channel.send(chatId, { text }, { replyTo });
15817
+ }
15818
+ }
15768
15819
  var FORWARD_FETCH_FAILED_CONTENT = '<forwarded_messages status="fetch_failed"/>';
15769
15820
  function isForwardFetchFailed(msg) {
15770
15821
  return msg.rawContentType === "merge_forward" && msg.content.trim() === FORWARD_FETCH_FAILED_CONTENT;
@@ -15836,6 +15887,11 @@ async function intakeMessage(deps) {
15836
15887
  reason: accessDecision.reason
15837
15888
  });
15838
15889
  if (msg.chatType !== "p2p" && (accessDecision.reason === "denied-chat" || accessDecision.reason === "denied-group-runs") && msg.mentionedBot) {
15890
+ const intake = controls.profileConfig.access.groupIntake;
15891
+ if (accessDecision.reason === "denied-group-runs" && intake && groupIntakeCovers(intake, msg.chatId)) {
15892
+ void runGroupIntake(intake, msg).then((text) => sendGroupIntakeReply(channel, msg.chatId, msg.messageId, text)).catch((err) => log.warn("group-intake", "reply-failed", { err: String(err) }));
15893
+ return;
15894
+ }
15839
15895
  const hint = accessDecision.reason === "denied-group-runs" ? GROUP_RUNS_DISABLED_HINT : void 0;
15840
15896
  void sendNonAllowedGroupHint(channel, msg.chatId, msg.messageId, hint).catch(
15841
15897
  (err) => log.warn("intake", "non-allowed-hint-failed", { err: String(err) })