aai-lark-bridge 0.2.22 → 0.2.24
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 +69 -5
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
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.
|
|
7
|
+
version: "0.2.24",
|
|
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 = {};
|
|
@@ -7105,6 +7113,8 @@ import { tmpdir as tmpdir4 } from "os";
|
|
|
7105
7113
|
import { join as join19 } from "path";
|
|
7106
7114
|
var LOGOUT_TEXT = "\u9000\u51FA Claude \u767B\u5F55";
|
|
7107
7115
|
var MIN_TOKEN_LEFT_MS = 2 * 60 * 6e4;
|
|
7116
|
+
var MIN_AFTER_REFRESH_MS = 10 * 6e4;
|
|
7117
|
+
var REFRESH_COOLDOWN_MS = 30 * 6e4;
|
|
7108
7118
|
var LOGIN_MAX_MS = 10 * 6e4;
|
|
7109
7119
|
var SUBMIT_MAX_MS = 3e4;
|
|
7110
7120
|
function readCredentials(dir) {
|
|
@@ -7170,6 +7180,7 @@ function createClaudeSeat(opts) {
|
|
|
7170
7180
|
const dirOf = (openId) => join19(root, openId);
|
|
7171
7181
|
const logins = /* @__PURE__ */ new Map();
|
|
7172
7182
|
const starting = /* @__PURE__ */ new Set();
|
|
7183
|
+
const refreshedAt = /* @__PURE__ */ new Map();
|
|
7173
7184
|
const locks = /* @__PURE__ */ new Map();
|
|
7174
7185
|
const tail62 = (id) => id.slice(-6);
|
|
7175
7186
|
async function withLock(openId, fn) {
|
|
@@ -7230,13 +7241,18 @@ function createClaudeSeat(opts) {
|
|
|
7230
7241
|
const dir = dirOf(openId);
|
|
7231
7242
|
let c = readCredentials(dir);
|
|
7232
7243
|
if (!c) return { status: await startLogin(openId) };
|
|
7233
|
-
|
|
7244
|
+
const recent = now() - (refreshedAt.get(openId) ?? -Infinity) < REFRESH_COOLDOWN_MS && c.expiresAt - now() >= MIN_AFTER_REFRESH_MS;
|
|
7245
|
+
if (c.expiresAt - now() < MIN_TOKEN_LEFT_MS && !recent) {
|
|
7246
|
+
const before = c.expiresAt;
|
|
7234
7247
|
const ok = await opts.cli.refresh(dir).catch(() => false);
|
|
7235
7248
|
c = readCredentials(dir);
|
|
7236
|
-
|
|
7249
|
+
const left = c ? c.expiresAt - now() : 0;
|
|
7250
|
+
const fresh = Boolean(c) && (left >= MIN_TOKEN_LEFT_MS || c.expiresAt > before && left >= MIN_AFTER_REFRESH_MS);
|
|
7251
|
+
if (!ok || !c || !fresh) {
|
|
7237
7252
|
log.warn("user-gateway", "claude.refresh-failed", { sender: tail62(openId), proof, runId });
|
|
7238
7253
|
return { status: "refresh_failed" };
|
|
7239
7254
|
}
|
|
7255
|
+
refreshedAt.set(openId, now());
|
|
7240
7256
|
log.info("user-gateway", "claude.refreshed", { sender: tail62(openId), proof, runId });
|
|
7241
7257
|
}
|
|
7242
7258
|
log.info("user-gateway", "claude.token-issued", { sender: tail62(openId), proof, runId });
|
|
@@ -8777,7 +8793,7 @@ function digestCanonical(value) {
|
|
|
8777
8793
|
}
|
|
8778
8794
|
|
|
8779
8795
|
// src/bridge/policy/access.ts
|
|
8780
|
-
var GROUP_RUNS_DISABLED_HINT = "\u7FA4\u91CC\u4E0D\
|
|
8796
|
+
var GROUP_RUNS_DISABLED_HINT = "\u7FA4\u91CC\u4E0D\u63A5\u6D3B\uFF0C\u8BF7\u79C1\u804A\u6211";
|
|
8781
8797
|
function isCreator(controls, senderId) {
|
|
8782
8798
|
if (controls.ownerRefreshState === "unknown") return false;
|
|
8783
8799
|
return Boolean(controls.botOwnerId) && controls.botOwnerId === senderId;
|
|
@@ -13311,6 +13327,42 @@ async function removeRejectedResolvedFiles(attachments) {
|
|
|
13311
13327
|
);
|
|
13312
13328
|
}
|
|
13313
13329
|
|
|
13330
|
+
// src/bridge/bot/group-intake.ts
|
|
13331
|
+
import { execFile } from "child_process";
|
|
13332
|
+
var GROUP_INTAKE_TIMEOUT_MS = 3e4;
|
|
13333
|
+
var defaultRunner = (bin, args, timeoutMs) => new Promise((resolve3) => {
|
|
13334
|
+
execFile(bin, args, { encoding: "utf8", timeout: timeoutMs, maxBuffer: 1 << 20 }, (err, stdout) => {
|
|
13335
|
+
resolve3({ stdout: String(stdout ?? ""), ...err ? { error: err.killed ? "\u8D85\u65F6" : String(err.message ?? err) } : {} });
|
|
13336
|
+
});
|
|
13337
|
+
});
|
|
13338
|
+
function groupIntakeCovers(cfg, chatId) {
|
|
13339
|
+
return Boolean(cfg && cfg.command.trim() && cfg.chats.includes(chatId));
|
|
13340
|
+
}
|
|
13341
|
+
async function runGroupIntake(cfg, msg, run2 = defaultRunner) {
|
|
13342
|
+
const [bin, ...pre] = cfg.command.trim().split(/\s+/);
|
|
13343
|
+
const base = { chatId: msg.chatId, msgId: msg.messageId, sender: msg.senderId.slice(-6) };
|
|
13344
|
+
const r = await run2(bin, [...pre, "--group", "--message-id", msg.messageId], GROUP_INTAKE_TIMEOUT_MS);
|
|
13345
|
+
let out;
|
|
13346
|
+
try {
|
|
13347
|
+
out = JSON.parse(r.stdout.trim().split("\n").filter(Boolean).at(-1) ?? "");
|
|
13348
|
+
} catch {
|
|
13349
|
+
out = void 0;
|
|
13350
|
+
}
|
|
13351
|
+
if (out?.status === "created" || out?.status === "existing") {
|
|
13352
|
+
log.info("group-intake", out.status, base);
|
|
13353
|
+
const head = out.status === "created" ? "\u5DF2\u5EFA\u4EFB\u52A1" : "\u8FD9\u6761\u6D88\u606F\u5DF2\u7ECF\u5EFA\u8FC7\u4EFB\u52A1";
|
|
13354
|
+
return `${head}\uFF1A${out.url ?? ""}
|
|
13355
|
+
\u8D1F\u8D23\u4EBA\u662F\u4F60\uFF0C\u8C03\u5EA6 5 \u5206\u949F\u5185\u63A5\u8D70\uFF0C\u7ED3\u679C\u79C1\u804A\u4F60\u3002`;
|
|
13356
|
+
}
|
|
13357
|
+
if (out?.status === "refused" && out.reason) {
|
|
13358
|
+
log.info("group-intake", "refused", { ...base, reason: out.reason.slice(0, 200) });
|
|
13359
|
+
return out.reason;
|
|
13360
|
+
}
|
|
13361
|
+
const detail = (out?.reason ?? r.error ?? "\u547D\u4EE4\u6CA1\u6709\u8FD4\u56DE\u7ED3\u679C").slice(0, 200);
|
|
13362
|
+
log.warn("group-intake", "failed", { ...base, detail });
|
|
13363
|
+
return `\u5EFA\u4EFB\u52A1\u6CA1\u6210\u529F\uFF1A${detail}\uFF0C\u7A0D\u540E\u518D\u8BD5\u6216\u79C1\u804A\u6211`;
|
|
13364
|
+
}
|
|
13365
|
+
|
|
13314
13366
|
// src/bridge/policy/owner.ts
|
|
13315
13367
|
var OWNER_REFRESH_INTERVAL_MS = 30 * 60 * 1e3;
|
|
13316
13368
|
async function refreshOwnerControls(controls, source, appId) {
|
|
@@ -15765,6 +15817,13 @@ async function sendNonAllowedGroupHint(channel, chatId, replyToMessageId, overri
|
|
|
15765
15817
|
await channel.send(chatId, { text });
|
|
15766
15818
|
}
|
|
15767
15819
|
}
|
|
15820
|
+
async function sendGroupIntakeReply(channel, chatId, replyTo, text) {
|
|
15821
|
+
try {
|
|
15822
|
+
await channel.send(chatId, { text }, { replyTo, replyInThread: true });
|
|
15823
|
+
} catch {
|
|
15824
|
+
await channel.send(chatId, { text }, { replyTo });
|
|
15825
|
+
}
|
|
15826
|
+
}
|
|
15768
15827
|
var FORWARD_FETCH_FAILED_CONTENT = '<forwarded_messages status="fetch_failed"/>';
|
|
15769
15828
|
function isForwardFetchFailed(msg) {
|
|
15770
15829
|
return msg.rawContentType === "merge_forward" && msg.content.trim() === FORWARD_FETCH_FAILED_CONTENT;
|
|
@@ -15836,6 +15895,11 @@ async function intakeMessage(deps) {
|
|
|
15836
15895
|
reason: accessDecision.reason
|
|
15837
15896
|
});
|
|
15838
15897
|
if (msg.chatType !== "p2p" && (accessDecision.reason === "denied-chat" || accessDecision.reason === "denied-group-runs") && msg.mentionedBot) {
|
|
15898
|
+
const intake = controls.profileConfig.access.groupIntake;
|
|
15899
|
+
if (accessDecision.reason === "denied-group-runs" && intake && groupIntakeCovers(intake, msg.chatId)) {
|
|
15900
|
+
void runGroupIntake(intake, msg).then((text) => sendGroupIntakeReply(channel, msg.chatId, msg.messageId, text)).catch((err) => log.warn("group-intake", "reply-failed", { err: String(err) }));
|
|
15901
|
+
return;
|
|
15902
|
+
}
|
|
15839
15903
|
const hint = accessDecision.reason === "denied-group-runs" ? GROUP_RUNS_DISABLED_HINT : void 0;
|
|
15840
15904
|
void sendNonAllowedGroupHint(channel, msg.chatId, msg.messageId, hint).catch(
|
|
15841
15905
|
(err) => log.warn("intake", "non-allowed-hint-failed", { err: String(err) })
|