aai-lark-bridge 0.2.23 → 0.2.25
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 +24 -4
- 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.25",
|
|
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",
|
|
@@ -7113,6 +7113,8 @@ import { tmpdir as tmpdir4 } from "os";
|
|
|
7113
7113
|
import { join as join19 } from "path";
|
|
7114
7114
|
var LOGOUT_TEXT = "\u9000\u51FA Claude \u767B\u5F55";
|
|
7115
7115
|
var MIN_TOKEN_LEFT_MS = 2 * 60 * 6e4;
|
|
7116
|
+
var MIN_AFTER_REFRESH_MS = 10 * 6e4;
|
|
7117
|
+
var REFRESH_COOLDOWN_MS = 30 * 6e4;
|
|
7116
7118
|
var LOGIN_MAX_MS = 10 * 6e4;
|
|
7117
7119
|
var SUBMIT_MAX_MS = 3e4;
|
|
7118
7120
|
function readCredentials(dir) {
|
|
@@ -7178,6 +7180,7 @@ function createClaudeSeat(opts) {
|
|
|
7178
7180
|
const dirOf = (openId) => join19(root, openId);
|
|
7179
7181
|
const logins = /* @__PURE__ */ new Map();
|
|
7180
7182
|
const starting = /* @__PURE__ */ new Set();
|
|
7183
|
+
const refreshedAt = /* @__PURE__ */ new Map();
|
|
7181
7184
|
const locks = /* @__PURE__ */ new Map();
|
|
7182
7185
|
const tail62 = (id) => id.slice(-6);
|
|
7183
7186
|
async function withLock(openId, fn) {
|
|
@@ -7238,13 +7241,18 @@ function createClaudeSeat(opts) {
|
|
|
7238
7241
|
const dir = dirOf(openId);
|
|
7239
7242
|
let c = readCredentials(dir);
|
|
7240
7243
|
if (!c) return { status: await startLogin(openId) };
|
|
7241
|
-
|
|
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;
|
|
7242
7247
|
const ok = await opts.cli.refresh(dir).catch(() => false);
|
|
7243
7248
|
c = readCredentials(dir);
|
|
7244
|
-
|
|
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) {
|
|
7245
7252
|
log.warn("user-gateway", "claude.refresh-failed", { sender: tail62(openId), proof, runId });
|
|
7246
7253
|
return { status: "refresh_failed" };
|
|
7247
7254
|
}
|
|
7255
|
+
refreshedAt.set(openId, now());
|
|
7248
7256
|
log.info("user-gateway", "claude.refreshed", { sender: tail62(openId), proof, runId });
|
|
7249
7257
|
}
|
|
7250
7258
|
log.info("user-gateway", "claude.token-issued", { sender: tail62(openId), proof, runId });
|
|
@@ -19409,6 +19417,16 @@ function isAppTokenInvalid(r) {
|
|
|
19409
19417
|
return /\b9999166[1-8]\b|token_invalid/.test(`${r.stdout}
|
|
19410
19418
|
${r.stderr}`);
|
|
19411
19419
|
}
|
|
19420
|
+
function brandOfTenant(tenant) {
|
|
19421
|
+
return tenant === "feishu" ? "feishu" : "lark";
|
|
19422
|
+
}
|
|
19423
|
+
function sourceBrand(sourceConfigFile) {
|
|
19424
|
+
try {
|
|
19425
|
+
return brandOfTenant(JSON.parse(readFileSync5(sourceConfigFile, "utf8")).accounts?.app?.tenant);
|
|
19426
|
+
} catch {
|
|
19427
|
+
return "lark";
|
|
19428
|
+
}
|
|
19429
|
+
}
|
|
19412
19430
|
var FETCH_SCRIPT = `
|
|
19413
19431
|
const chunks = [];
|
|
19414
19432
|
process.stdin.on('data', (c) => chunks.push(c)).on('end', async () => {
|
|
@@ -19454,7 +19472,7 @@ function realAppTokenFetcher(sourceConfigFile) {
|
|
|
19454
19472
|
cred = res.values?.[ref.id];
|
|
19455
19473
|
}
|
|
19456
19474
|
if (!cred) throw new Error("\u53D6\u4E0D\u5230 App Secret");
|
|
19457
|
-
const host = app.tenant === "feishu" ? "https://open.feishu.cn" : "https://open.larksuite.com";
|
|
19475
|
+
const host = brandOfTenant(app.tenant) === "feishu" ? "https://open.feishu.cn" : "https://open.larksuite.com";
|
|
19458
19476
|
const out = JSON.parse(
|
|
19459
19477
|
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)
|
|
19460
19478
|
);
|
|
@@ -19601,9 +19619,11 @@ function createGateway(opts) {
|
|
|
19601
19619
|
const userDir = (openId) => join27(tokenRoot, openId);
|
|
19602
19620
|
const authorizedMark = (openId) => join27(userDir(openId), ".authorized");
|
|
19603
19621
|
const isAuthorized = (openId) => existsSync9(authorizedMark(openId));
|
|
19622
|
+
const brand = sourceBrand(opts.larkSourceConfig);
|
|
19604
19623
|
function env(dir) {
|
|
19605
19624
|
return {
|
|
19606
19625
|
...buildLarkChannelEnv({ larkCliSourceConfigFile: opts.larkSourceConfig, larkCliConfigDir: dir }),
|
|
19626
|
+
LARKSUITE_CLI_BRAND: brand,
|
|
19607
19627
|
LARKSUITE_CLI_DATA_DIR: dir,
|
|
19608
19628
|
LARKSUITE_CLI_NO_UPDATE_NOTIFIER: "1",
|
|
19609
19629
|
LARKSUITE_CLI_NO_SKILLS_NOTIFIER: "1"
|