aai-lark-bridge 0.2.16 → 0.2.18

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.16",
7
+ version: "0.2.18",
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",
@@ -7105,6 +7105,7 @@ import { join as join19 } from "path";
7105
7105
  var LOGOUT_TEXT = "\u9000\u51FA Claude \u767B\u5F55";
7106
7106
  var MIN_TOKEN_LEFT_MS = 2 * 60 * 6e4;
7107
7107
  var LOGIN_MAX_MS = 10 * 6e4;
7108
+ var SUBMIT_MAX_MS = 3e4;
7108
7109
  function readCredentials(dir) {
7109
7110
  const f = join19(dir, ".credentials.json");
7110
7111
  if (!existsSync6(f)) return void 0;
@@ -7330,11 +7331,25 @@ function realClaudeCli(binary = process.env.SDLC_REAL_CLAUDE || "claude") {
7330
7331
  return {
7331
7332
  url,
7332
7333
  async submit(code) {
7334
+ const before = out.length;
7333
7335
  p3.stdin.end(`${code}
7334
7336
  `);
7335
- const rc = await exited;
7337
+ const verdict = await new Promise((resolve3) => {
7338
+ const check2 = () => {
7339
+ if (/Invalid code/i.test(out.slice(before))) resolve3("invalid");
7340
+ };
7341
+ p3.stdout.on("data", check2);
7342
+ p3.stderr.on("data", check2);
7343
+ check2();
7344
+ void exited.then(resolve3);
7345
+ setTimeout(() => resolve3("invalid"), SUBMIT_MAX_MS).unref();
7346
+ });
7336
7347
  clearTimeout(timer);
7337
- return rc === 0 && /Login successful/i.test(out);
7348
+ if (verdict === "invalid") {
7349
+ p3.kill("SIGTERM");
7350
+ return false;
7351
+ }
7352
+ return verdict === 0 && /Login successful/i.test(out);
7338
7353
  },
7339
7354
  cancel() {
7340
7355
  clearTimeout(timer);
@@ -7357,7 +7372,7 @@ import { randomUUID } from "crypto";
7357
7372
  var HANDLE_ENV = "AAI_USER_READ_HANDLE";
7358
7373
  var GATEWAY_ENV = "AAI_USER_READ_GATEWAY";
7359
7374
  var REVOKE_TEXT = "\u64A4\u9500\u6388\u6743";
7360
- var TIMEOUT_MS = 15e3;
7375
+ var TIMEOUT_MS = 6e4;
7361
7376
  function readTokenByCommand(command) {
7362
7377
  const [bin, ...args] = command.trim().split(/\s+/);
7363
7378
  if (!bin) throw new Error("tokenCommand \u4E3A\u7A7A");
@@ -19257,6 +19272,7 @@ var CLOCK_SKEW_MS = 3e4;
19257
19272
  var USED_TTL_MS = MESSAGE_MAX_AGE_MS + CLOCK_SKEW_MS + 6e4;
19258
19273
  var AUTH_POLL_MS = 5e3;
19259
19274
  var AUTH_MAX_MS = 10 * 6e4;
19275
+ var RATE_LIMIT_BACKOFF_MS = [2e3, 5e3, 1e4];
19260
19276
  var REVOKE_TEXT2 = "\u64A4\u9500\u6388\u6743";
19261
19277
  var MESSAGE_ID = /^om_[A-Za-z0-9_-]{1,100}$/;
19262
19278
  var CHAT_ID = /^oc_[A-Za-z0-9_-]{1,100}$/;
@@ -19285,6 +19301,10 @@ function parseJson4(text) {
19285
19301
  }
19286
19302
  }
19287
19303
  }
19304
+ function isRateLimited(r) {
19305
+ return /rate_limit|HTTP 429|99991400/.test(`${r.stdout}
19306
+ ${r.stderr}`);
19307
+ }
19288
19308
  function firstLine(s) {
19289
19309
  return s.trim().split("\n")[0]?.trim().slice(0, 300) ?? "";
19290
19310
  }
@@ -19391,7 +19411,14 @@ function createGateway(opts) {
19391
19411
  }
19392
19412
  const asApp = async (args, timeoutMs = 3e4) => {
19393
19413
  await ensureBound(appDir, "bot-only");
19394
- return opts.exec(args, env(appDir), timeoutMs);
19414
+ let r = await opts.exec(args, env(appDir), timeoutMs);
19415
+ for (const wait of RATE_LIMIT_BACKOFF_MS) {
19416
+ if (r.code === 0 || !isRateLimited(r)) break;
19417
+ log.warn("user-gateway", "lark.rate-limited", { api: args.slice(0, 3).join(" "), retryInMs: wait });
19418
+ await sleep2(wait);
19419
+ r = await opts.exec(args, env(appDir), timeoutMs);
19420
+ }
19421
+ return r;
19395
19422
  };
19396
19423
  function sweep() {
19397
19424
  const t = now();