aai-lark-bridge 0.2.21 → 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.21",
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) })
@@ -19931,27 +19987,36 @@ function createGateway(opts) {
19931
19987
  /**
19932
19988
  * POST /db/task-handle:调度的只读运行(只读分析、出文档、补报告)起 claude 前凭任务申请查库句柄(intent 0049 R-04)。
19933
19989
  * 负责人得是这个任务的 assignee(网关向飞书核对,同 0048 的 /claude/task-token);不看私聊查库名单(spec D-3)。
19990
+ * 评测(intent 0050,带 eval: true):评测的任务号不是真飞书任务,不带 taskGuid,改按私聊查库名单放行,日志记 task=eval。
19934
19991
  */
19935
19992
  async dbTaskHandle(input) {
19936
- let taskGuid, openId, runId;
19993
+ const isEval = input.eval === true;
19994
+ let taskGuid = null, openId, runId;
19937
19995
  try {
19938
- taskGuid = str2(input, "taskGuid", TASK_GUID);
19996
+ if (!isEval) taskGuid = str2(input, "taskGuid", TASK_GUID);
19939
19997
  openId = str2(input, "openId", OPEN_ID2);
19940
19998
  runId = str2(input, "runId", RUN_ID);
19941
19999
  } catch {
19942
20000
  return { status: "bad_request" };
19943
20001
  }
19944
20002
  if (!db.enabled) return { status: "off" };
19945
- const assignees = await taskAssignees(taskGuid);
19946
- if (assignees === "lark_error") return { status: "lark_error" };
19947
- if (!assignees.includes(openId)) {
19948
- log.warn("user-gateway", "db.handle-refused", { sender: tail6(openId), runId, result: "not_assignee" });
19949
- return { status: "not_assignee" };
20003
+ if (taskGuid === null) {
20004
+ if (!db.readers.includes(openId)) {
20005
+ log.warn("user-gateway", "db.handle-refused", { sender: tail6(openId), runId, task: "eval", result: "not_reader" });
20006
+ return { status: "not_reader" };
20007
+ }
20008
+ } else {
20009
+ const assignees = await taskAssignees(taskGuid);
20010
+ if (assignees === "lark_error") return { status: "lark_error" };
20011
+ if (!assignees.includes(openId)) {
20012
+ log.warn("user-gateway", "db.handle-refused", { sender: tail6(openId), runId, result: "not_assignee" });
20013
+ return { status: "not_assignee" };
20014
+ }
19950
20015
  }
19951
20016
  const handle2 = randomBytes10(32).toString("base64url");
19952
20017
  const expiresAt = now() + TASK_HANDLE_TTL_MS;
19953
20018
  handles.set(handle2, { openId, messageId: "", runId, expiresAt, kind: "task", db: true });
19954
- log.info("user-gateway", "db.handle-issued", { sender: tail6(openId), runId, task: taskGuid });
20019
+ log.info("user-gateway", "db.handle-issued", { sender: tail6(openId), runId, task: taskGuid ?? "eval" });
19955
20020
  return { status: "ok", handle: handle2, expiresAt };
19956
20021
  },
19957
20022
  /** POST /db/query:凭句柄替 agent 查一条,每次记一条 db.query(intent 0049 R-01、R-03、R-05)。 */