aai-lark-bridge 0.2.24 → 0.2.26
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 +23 -8
- 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.26",
|
|
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",
|
|
@@ -630,7 +630,7 @@ function normalizeAccess(access3, legacyRequireMentionInGroup) {
|
|
|
630
630
|
function groupIntakeOf(input) {
|
|
631
631
|
if (!input || typeof input !== "object" || Array.isArray(input)) return {};
|
|
632
632
|
const raw = input;
|
|
633
|
-
const chats = stringArray(raw.chats).filter((c) => /^oc_[A-Za-z0-9_-]+$/.test(c));
|
|
633
|
+
const chats = stringArray(raw.chats).filter((c) => c === "*" || /^oc_[A-Za-z0-9_-]+$/.test(c));
|
|
634
634
|
const command = typeof raw.command === "string" ? raw.command.trim() : "";
|
|
635
635
|
return chats.length && command ? { groupIntake: { chats, command } } : {};
|
|
636
636
|
}
|
|
@@ -13336,7 +13336,7 @@ var defaultRunner = (bin, args, timeoutMs) => new Promise((resolve3) => {
|
|
|
13336
13336
|
});
|
|
13337
13337
|
});
|
|
13338
13338
|
function groupIntakeCovers(cfg, chatId) {
|
|
13339
|
-
return Boolean(cfg && cfg.command.trim() && cfg.chats.includes(chatId));
|
|
13339
|
+
return Boolean(cfg && cfg.command.trim() && (cfg.chats.includes("*") || cfg.chats.includes(chatId)));
|
|
13340
13340
|
}
|
|
13341
13341
|
async function runGroupIntake(cfg, msg, run2 = defaultRunner) {
|
|
13342
13342
|
const [bin, ...pre] = cfg.command.trim().split(/\s+/);
|
|
@@ -13351,8 +13351,9 @@ async function runGroupIntake(cfg, msg, run2 = defaultRunner) {
|
|
|
13351
13351
|
if (out?.status === "created" || out?.status === "existing") {
|
|
13352
13352
|
log.info("group-intake", out.status, base);
|
|
13353
13353
|
const head = out.status === "created" ? "\u5DF2\u5EFA\u4EFB\u52A1" : "\u8FD9\u6761\u6D88\u606F\u5DF2\u7ECF\u5EFA\u8FC7\u4EFB\u52A1";
|
|
13354
|
+
const next = out.note?.trim() ? `\u8D1F\u8D23\u4EBA\u662F\u4F60\u3002${out.note.trim()}` : "\u8D1F\u8D23\u4EBA\u662F\u4F60\uFF0C\u8C03\u5EA6 5 \u5206\u949F\u5185\u63A5\u8D70\uFF0C\u7ED3\u679C\u79C1\u804A\u4F60\u3002";
|
|
13354
13355
|
return `${head}\uFF1A${out.url ?? ""}
|
|
13355
|
-
|
|
13356
|
+
${next}`;
|
|
13356
13357
|
}
|
|
13357
13358
|
if (out?.status === "refused" && out.reason) {
|
|
13358
13359
|
log.info("group-intake", "refused", { ...base, reason: out.reason.slice(0, 200) });
|
|
@@ -19325,9 +19326,11 @@ var SQL_LOG_MAX = 2e3;
|
|
|
19325
19326
|
var LOCK_WAIT_SEC = 60;
|
|
19326
19327
|
var DB_NAME = /^[a-z0-9_-]{1,40}$/;
|
|
19327
19328
|
var OPEN_ID = /^ou_[A-Za-z0-9_-]{1,100}$/;
|
|
19329
|
+
var ALL = "*";
|
|
19330
|
+
var isDbReader = (db, openId) => db.readers.includes(ALL) || db.readers.includes(openId);
|
|
19328
19331
|
function dbFromEnv(env, cmd = "") {
|
|
19329
19332
|
const argv = cmd.trim() ? cmd.trim().split(/\s+/) : [];
|
|
19330
|
-
const readers = (env.SDLC_DB_READERS ?? "").split(",").map((s) => s.trim()).filter((s) => OPEN_ID.test(s));
|
|
19333
|
+
const readers = (env.SDLC_DB_READERS ?? "").split(",").map((s) => s.trim()).filter((s) => s === ALL || OPEN_ID.test(s));
|
|
19331
19334
|
return { enabled: (env.SDLC_DB_GATEWAY ?? "").trim() === "on" && argv.length > 0, readers, cmd: argv };
|
|
19332
19335
|
}
|
|
19333
19336
|
function realDbRunner(cmd) {
|
|
@@ -19417,6 +19420,16 @@ function isAppTokenInvalid(r) {
|
|
|
19417
19420
|
return /\b9999166[1-8]\b|token_invalid/.test(`${r.stdout}
|
|
19418
19421
|
${r.stderr}`);
|
|
19419
19422
|
}
|
|
19423
|
+
function brandOfTenant(tenant) {
|
|
19424
|
+
return tenant === "feishu" ? "feishu" : "lark";
|
|
19425
|
+
}
|
|
19426
|
+
function sourceBrand(sourceConfigFile) {
|
|
19427
|
+
try {
|
|
19428
|
+
return brandOfTenant(JSON.parse(readFileSync5(sourceConfigFile, "utf8")).accounts?.app?.tenant);
|
|
19429
|
+
} catch {
|
|
19430
|
+
return "lark";
|
|
19431
|
+
}
|
|
19432
|
+
}
|
|
19420
19433
|
var FETCH_SCRIPT = `
|
|
19421
19434
|
const chunks = [];
|
|
19422
19435
|
process.stdin.on('data', (c) => chunks.push(c)).on('end', async () => {
|
|
@@ -19462,7 +19475,7 @@ function realAppTokenFetcher(sourceConfigFile) {
|
|
|
19462
19475
|
cred = res.values?.[ref.id];
|
|
19463
19476
|
}
|
|
19464
19477
|
if (!cred) throw new Error("\u53D6\u4E0D\u5230 App Secret");
|
|
19465
|
-
const host = app.tenant === "feishu" ? "https://open.feishu.cn" : "https://open.larksuite.com";
|
|
19478
|
+
const host = brandOfTenant(app.tenant) === "feishu" ? "https://open.feishu.cn" : "https://open.larksuite.com";
|
|
19466
19479
|
const out = JSON.parse(
|
|
19467
19480
|
await run(process.execPath, ["--no-warnings", "-e", FETCH_SCRIPT], JSON.stringify({ url: `${host}/open-apis/auth/v3/tenant_access_token/internal`, appId: app.id, secret: cred }), { ...process.env, NODE_USE_ENV_PROXY: "1" }, 2e4)
|
|
19468
19481
|
);
|
|
@@ -19609,9 +19622,11 @@ function createGateway(opts) {
|
|
|
19609
19622
|
const userDir = (openId) => join27(tokenRoot, openId);
|
|
19610
19623
|
const authorizedMark = (openId) => join27(userDir(openId), ".authorized");
|
|
19611
19624
|
const isAuthorized = (openId) => existsSync9(authorizedMark(openId));
|
|
19625
|
+
const brand = sourceBrand(opts.larkSourceConfig);
|
|
19612
19626
|
function env(dir) {
|
|
19613
19627
|
return {
|
|
19614
19628
|
...buildLarkChannelEnv({ larkCliSourceConfigFile: opts.larkSourceConfig, larkCliConfigDir: dir }),
|
|
19629
|
+
LARKSUITE_CLI_BRAND: brand,
|
|
19615
19630
|
LARKSUITE_CLI_DATA_DIR: dir,
|
|
19616
19631
|
LARKSUITE_CLI_NO_UPDATE_NOTIFIER: "1",
|
|
19617
19632
|
LARKSUITE_CLI_NO_SKILLS_NOTIFIER: "1"
|
|
@@ -19852,7 +19867,7 @@ function createGateway(opts) {
|
|
|
19852
19867
|
}
|
|
19853
19868
|
const handle2 = randomBytes10(32).toString("base64url");
|
|
19854
19869
|
const expiresAt = now() + HANDLE_TTL_MS;
|
|
19855
|
-
const canDb = db.enabled && db
|
|
19870
|
+
const canDb = db.enabled && isDbReader(db, v.openId);
|
|
19856
19871
|
handles.set(handle2, { openId: v.openId, messageId, runId, expiresAt, kind: "dm", db: canDb });
|
|
19857
19872
|
log.info("user-gateway", "handle.issued", { identity: "user", sender: tail6(v.openId), messageId, runId, db: canDb });
|
|
19858
19873
|
return { status: "ok", handle: handle2, expiresAt, db: canDb };
|
|
@@ -20009,7 +20024,7 @@ function createGateway(opts) {
|
|
|
20009
20024
|
}
|
|
20010
20025
|
if (!db.enabled) return { status: "off" };
|
|
20011
20026
|
if (taskGuid === null) {
|
|
20012
|
-
if (!db
|
|
20027
|
+
if (!isDbReader(db, openId)) {
|
|
20013
20028
|
log.warn("user-gateway", "db.handle-refused", { sender: tail6(openId), runId, task: "eval", result: "not_reader" });
|
|
20014
20029
|
return { status: "not_reader" };
|
|
20015
20030
|
}
|