aai-lark-bridge 0.2.16 → 0.2.17

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.17",
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",
@@ -7357,7 +7357,7 @@ import { randomUUID } from "crypto";
7357
7357
  var HANDLE_ENV = "AAI_USER_READ_HANDLE";
7358
7358
  var GATEWAY_ENV = "AAI_USER_READ_GATEWAY";
7359
7359
  var REVOKE_TEXT = "\u64A4\u9500\u6388\u6743";
7360
- var TIMEOUT_MS = 15e3;
7360
+ var TIMEOUT_MS = 6e4;
7361
7361
  function readTokenByCommand(command) {
7362
7362
  const [bin, ...args] = command.trim().split(/\s+/);
7363
7363
  if (!bin) throw new Error("tokenCommand \u4E3A\u7A7A");
@@ -19257,6 +19257,7 @@ var CLOCK_SKEW_MS = 3e4;
19257
19257
  var USED_TTL_MS = MESSAGE_MAX_AGE_MS + CLOCK_SKEW_MS + 6e4;
19258
19258
  var AUTH_POLL_MS = 5e3;
19259
19259
  var AUTH_MAX_MS = 10 * 6e4;
19260
+ var RATE_LIMIT_BACKOFF_MS = [2e3, 5e3, 1e4];
19260
19261
  var REVOKE_TEXT2 = "\u64A4\u9500\u6388\u6743";
19261
19262
  var MESSAGE_ID = /^om_[A-Za-z0-9_-]{1,100}$/;
19262
19263
  var CHAT_ID = /^oc_[A-Za-z0-9_-]{1,100}$/;
@@ -19285,6 +19286,10 @@ function parseJson4(text) {
19285
19286
  }
19286
19287
  }
19287
19288
  }
19289
+ function isRateLimited(r) {
19290
+ return /rate_limit|HTTP 429|99991400/.test(`${r.stdout}
19291
+ ${r.stderr}`);
19292
+ }
19288
19293
  function firstLine(s) {
19289
19294
  return s.trim().split("\n")[0]?.trim().slice(0, 300) ?? "";
19290
19295
  }
@@ -19391,7 +19396,14 @@ function createGateway(opts) {
19391
19396
  }
19392
19397
  const asApp = async (args, timeoutMs = 3e4) => {
19393
19398
  await ensureBound(appDir, "bot-only");
19394
- return opts.exec(args, env(appDir), timeoutMs);
19399
+ let r = await opts.exec(args, env(appDir), timeoutMs);
19400
+ for (const wait of RATE_LIMIT_BACKOFF_MS) {
19401
+ if (r.code === 0 || !isRateLimited(r)) break;
19402
+ log.warn("user-gateway", "lark.rate-limited", { api: args.slice(0, 3).join(" "), retryInMs: wait });
19403
+ await sleep2(wait);
19404
+ r = await opts.exec(args, env(appDir), timeoutMs);
19405
+ }
19406
+ return r;
19395
19407
  };
19396
19408
  function sweep() {
19397
19409
  const t = now();