aai-lark-bridge 0.2.53 → 0.2.54
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 +54 -18
- 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.54",
|
|
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",
|
|
@@ -7108,7 +7108,7 @@ import { randomBytes as randomBytes5 } from "crypto";
|
|
|
7108
7108
|
// src/bridge/user-gateway/claude-seat.ts
|
|
7109
7109
|
import { spawn } from "child_process";
|
|
7110
7110
|
import { randomBytes as randomBytes4 } from "crypto";
|
|
7111
|
-
import { existsSync as existsSync6, readFileSync as readFileSync3 } from "fs";
|
|
7111
|
+
import { existsSync as existsSync6, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
7112
7112
|
import { mkdir as mkdir13, mkdtemp, rm as rm11 } from "fs/promises";
|
|
7113
7113
|
import { tmpdir as tmpdir4 } from "os";
|
|
7114
7114
|
import { join as join19 } from "path";
|
|
@@ -7133,6 +7133,40 @@ function readCredentials(dir) {
|
|
|
7133
7133
|
return void 0;
|
|
7134
7134
|
}
|
|
7135
7135
|
}
|
|
7136
|
+
function forceExpire(dir, nowMs) {
|
|
7137
|
+
const f = join19(dir, ".credentials.json");
|
|
7138
|
+
const noop2 = () => {
|
|
7139
|
+
};
|
|
7140
|
+
let raw;
|
|
7141
|
+
let j;
|
|
7142
|
+
try {
|
|
7143
|
+
raw = readFileSync3(f, "utf8");
|
|
7144
|
+
j = JSON.parse(raw);
|
|
7145
|
+
} catch {
|
|
7146
|
+
return noop2;
|
|
7147
|
+
}
|
|
7148
|
+
const o = j.claudeAiOauth;
|
|
7149
|
+
if (!o || typeof o.expiresAt !== "number" || o.expiresAt <= nowMs) return noop2;
|
|
7150
|
+
const original = o.expiresAt;
|
|
7151
|
+
const forced = nowMs - 1e3;
|
|
7152
|
+
try {
|
|
7153
|
+
o.expiresAt = forced;
|
|
7154
|
+
writeFileSync3(f, JSON.stringify(j), { mode: 384 });
|
|
7155
|
+
} catch {
|
|
7156
|
+
return noop2;
|
|
7157
|
+
}
|
|
7158
|
+
return () => {
|
|
7159
|
+
try {
|
|
7160
|
+
const cur = JSON.parse(readFileSync3(f, "utf8"));
|
|
7161
|
+
const c = cur.claudeAiOauth;
|
|
7162
|
+
if (c && c.expiresAt === forced) {
|
|
7163
|
+
c.expiresAt = original;
|
|
7164
|
+
writeFileSync3(f, JSON.stringify(cur), { mode: 384 });
|
|
7165
|
+
}
|
|
7166
|
+
} catch {
|
|
7167
|
+
}
|
|
7168
|
+
};
|
|
7169
|
+
}
|
|
7136
7170
|
function covers(sw, openId) {
|
|
7137
7171
|
return sw.mode === "all" || sw.mode === "list" && sw.list.includes(openId);
|
|
7138
7172
|
}
|
|
@@ -7248,7 +7282,9 @@ function createClaudeSeat(opts) {
|
|
|
7248
7282
|
const recent = now() - (refreshedAt.get(openId) ?? -Infinity) < REFRESH_COOLDOWN_MS && c.expiresAt - now() >= MIN_AFTER_REFRESH_MS;
|
|
7249
7283
|
if (c.expiresAt - now() < MIN_TOKEN_LEFT_MS && !recent) {
|
|
7250
7284
|
const attempt = async (n) => {
|
|
7285
|
+
const restore = forceExpire(dir, now());
|
|
7251
7286
|
const r = normalizeRefresh(await opts.cli.refresh(dir).catch((err) => ({ ok: false, spawnError: scrubOutput(String(err)) })));
|
|
7287
|
+
restore();
|
|
7252
7288
|
const cur = readCredentials(dir);
|
|
7253
7289
|
const left = cur ? cur.expiresAt - now() : 0;
|
|
7254
7290
|
const good = r.ok && !!cur && left >= MIN_AFTER_REFRESH_MS;
|
|
@@ -7819,7 +7855,7 @@ function modelLabel(agentKind, value) {
|
|
|
7819
7855
|
// src/bridge/bot/router.ts
|
|
7820
7856
|
import { spawn as spawn2 } from "child_process";
|
|
7821
7857
|
import { randomBytes as randomBytes6 } from "crypto";
|
|
7822
|
-
import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as
|
|
7858
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
7823
7859
|
import { isAbsolute as isAbsolute2, join as join20 } from "path";
|
|
7824
7860
|
var SAFE = /^[A-Za-z0-9_.:@+-]{1,200}$/;
|
|
7825
7861
|
var ROUTER_TIMEOUT_MS = 6e4;
|
|
@@ -7934,7 +7970,7 @@ function writePending(workspace, pending) {
|
|
|
7934
7970
|
const dir = join20(stateDir(workspace), "route-pending");
|
|
7935
7971
|
mkdirSync3(dir, { recursive: true, mode: 448 });
|
|
7936
7972
|
const f = join20(dir, `${pending.nonce}.json`);
|
|
7937
|
-
|
|
7973
|
+
writeFileSync4(`${f}.new`, JSON.stringify(pending), { mode: 384 });
|
|
7938
7974
|
renameSync2(`${f}.new`, f);
|
|
7939
7975
|
return true;
|
|
7940
7976
|
}
|
|
@@ -8013,7 +8049,7 @@ import {
|
|
|
8013
8049
|
rmSync as rmSync2,
|
|
8014
8050
|
statSync,
|
|
8015
8051
|
unlinkSync as unlinkSync2,
|
|
8016
|
-
writeFileSync as
|
|
8052
|
+
writeFileSync as writeFileSync5
|
|
8017
8053
|
} from "fs";
|
|
8018
8054
|
import { basename as basename5, dirname as dirname14, isAbsolute as isAbsolute3, join as join21, sep as sep2 } from "path";
|
|
8019
8055
|
var BINDING_VERSION = 1;
|
|
@@ -8132,7 +8168,7 @@ function registerDispatchRoot(dir, rootMessageId, chatId, now = /* @__PURE__ */
|
|
|
8132
8168
|
const file = join21(folder, `${rootMessageId}.json`);
|
|
8133
8169
|
if (existsSync8(file)) return;
|
|
8134
8170
|
const tmp = `${file}.${randomBytes7(4).toString("hex")}.tmp`;
|
|
8135
|
-
|
|
8171
|
+
writeFileSync5(tmp, `${JSON.stringify({ chat_id: chatId, at: now.toISOString() })}
|
|
8136
8172
|
`);
|
|
8137
8173
|
renameSync3(tmp, file);
|
|
8138
8174
|
pruneDispatchRoots(folder, now);
|
|
@@ -8211,7 +8247,7 @@ function switchToTask(rawConfig, chatId, senderOpenId, taskId, { messageId = nul
|
|
|
8211
8247
|
if (from) queue.unshift(from);
|
|
8212
8248
|
const next = { ...doc, active: item, queue, updated_at: now.toISOString() };
|
|
8213
8249
|
const tmp = `${file}.new-${process.pid}`;
|
|
8214
|
-
|
|
8250
|
+
writeFileSync5(tmp, JSON.stringify(next, null, 2), { mode: 384 });
|
|
8215
8251
|
renameSync3(tmp, file);
|
|
8216
8252
|
return { from: from?.task_id ?? null, to: taskId };
|
|
8217
8253
|
});
|
|
@@ -8222,7 +8258,7 @@ function switchToTask(rawConfig, chatId, senderOpenId, taskId, { messageId = nul
|
|
|
8222
8258
|
const eventsDir = join21(cfg.dir, "events");
|
|
8223
8259
|
mkdirSync4(eventsDir, { recursive: true });
|
|
8224
8260
|
const tmp = join21(eventsDir, `.${randomBytes7(6).toString("hex")}.tmp`);
|
|
8225
|
-
|
|
8261
|
+
writeFileSync5(tmp, JSON.stringify(event));
|
|
8226
8262
|
renameSync3(tmp, join21(eventsDir, `switch-${now.getTime()}-${randomBytes7(4).toString("hex")}.json`));
|
|
8227
8263
|
eventWritten = true;
|
|
8228
8264
|
} catch {
|
|
@@ -8265,7 +8301,7 @@ function writeBudgetHitEvent(dir, event) {
|
|
|
8265
8301
|
return false;
|
|
8266
8302
|
}
|
|
8267
8303
|
const tmp = join21(eventsDir, `.${randomBytes7(6).toString("hex")}.tmp`);
|
|
8268
|
-
|
|
8304
|
+
writeFileSync5(tmp, JSON.stringify(event));
|
|
8269
8305
|
try {
|
|
8270
8306
|
linkSync(tmp, file);
|
|
8271
8307
|
return true;
|
|
@@ -8320,7 +8356,7 @@ function dropTaskEvent(workspace, taskId, event, route3) {
|
|
|
8320
8356
|
const key = createHash2("sha256").update(`${taskId}\0${event.id}`).digest("hex").slice(0, 32);
|
|
8321
8357
|
const target = join21(inbox, `${key}.json`);
|
|
8322
8358
|
const tmp = `${target}.new-${process.pid}`;
|
|
8323
|
-
|
|
8359
|
+
writeFileSync5(tmp, JSON.stringify({ task_id: taskId, event, ...route3 ? { route: route3 } : {} }), { mode: 384 });
|
|
8324
8360
|
renameSync3(tmp, target);
|
|
8325
8361
|
return true;
|
|
8326
8362
|
}
|
|
@@ -8365,7 +8401,7 @@ function taskRunHooks(input) {
|
|
|
8365
8401
|
|
|
8366
8402
|
// src/bridge/binding/awaiting.ts
|
|
8367
8403
|
import { createHash as createHash3 } from "crypto";
|
|
8368
|
-
import { existsSync as existsSync9, mkdirSync as mkdirSync5, readFileSync as readFileSync6, renameSync as renameSync4, rmSync as rmSync3, writeFileSync as
|
|
8404
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync5, readFileSync as readFileSync6, renameSync as renameSync4, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "fs";
|
|
8369
8405
|
import { join as join22 } from "path";
|
|
8370
8406
|
var AWAITING_TTL_MS = 24 * 36e5;
|
|
8371
8407
|
var DECISION_SHOW_MAX = 200;
|
|
@@ -8400,7 +8436,7 @@ function submitDecision(dir, handoffDir, a, msg) {
|
|
|
8400
8436
|
const file = join22(handoffDir, name);
|
|
8401
8437
|
if (!existsSync9(file)) {
|
|
8402
8438
|
const tmp = join22(handoffDir, `.${name}.${process.pid}.tmp`);
|
|
8403
|
-
|
|
8439
|
+
writeFileSync6(
|
|
8404
8440
|
tmp,
|
|
8405
8441
|
JSON.stringify({
|
|
8406
8442
|
event_id: "",
|
|
@@ -13043,7 +13079,7 @@ async function lookupMessageRoot(channel, messageId) {
|
|
|
13043
13079
|
|
|
13044
13080
|
// src/bridge/card/handoff.ts
|
|
13045
13081
|
import { createHash as createHash5 } from "crypto";
|
|
13046
|
-
import { existsSync as existsSync10, mkdirSync as mkdirSync6, renameSync as renameSync5, writeFileSync as
|
|
13082
|
+
import { existsSync as existsSync10, mkdirSync as mkdirSync6, renameSync as renameSync5, writeFileSync as writeFileSync7 } from "fs";
|
|
13047
13083
|
import { isAbsolute as isAbsolute5, join as join25 } from "path";
|
|
13048
13084
|
function handoffDirs(raw) {
|
|
13049
13085
|
if (!raw || typeof raw !== "object") return {};
|
|
@@ -13072,7 +13108,7 @@ function tryHandoff(evt, dirs) {
|
|
|
13072
13108
|
const file = join25(dir, name);
|
|
13073
13109
|
if (existsSync10(file)) return true;
|
|
13074
13110
|
const tmp = join25(dir, `.${name}.${process.pid}.tmp`);
|
|
13075
|
-
|
|
13111
|
+
writeFileSync7(
|
|
13076
13112
|
tmp,
|
|
13077
13113
|
JSON.stringify({
|
|
13078
13114
|
event_id: eventId,
|
|
@@ -14864,7 +14900,7 @@ function preview(text) {
|
|
|
14864
14900
|
|
|
14865
14901
|
// src/bridge/bot/doc-confirmation.ts
|
|
14866
14902
|
import { createHash as createHash8 } from "crypto";
|
|
14867
|
-
import { mkdirSync as mkdirSync7, realpathSync as realpathSync2, renameSync as renameSync6, writeFileSync as
|
|
14903
|
+
import { mkdirSync as mkdirSync7, realpathSync as realpathSync2, renameSync as renameSync6, writeFileSync as writeFileSync8 } from "fs";
|
|
14868
14904
|
import { isAbsolute as isAbsolute6, join as join27, sep as sep3 } from "path";
|
|
14869
14905
|
import { spawn as spawn3 } from "child_process";
|
|
14870
14906
|
var waking = /* @__PURE__ */ new Set();
|
|
@@ -14884,7 +14920,7 @@ function enqueueDocConfirmation(workspace, event, { selfReply = false } = {}) {
|
|
|
14884
14920
|
const key = createHash8("sha256").update(JSON.stringify([hint.file_token, hint.comment_id, hint.reply_id])).digest("hex");
|
|
14885
14921
|
const target = join27(inbox, key + ".json");
|
|
14886
14922
|
const tmp = target + `.new-${process.pid}`;
|
|
14887
|
-
|
|
14923
|
+
writeFileSync8(tmp, JSON.stringify(hint), { mode: 384 });
|
|
14888
14924
|
renameSync6(tmp, target);
|
|
14889
14925
|
if (!waking.has(root)) {
|
|
14890
14926
|
waking.add(root);
|
|
@@ -20544,7 +20580,7 @@ function toResult(r) {
|
|
|
20544
20580
|
|
|
20545
20581
|
// src/bridge/user-gateway/gateway.ts
|
|
20546
20582
|
import { createHash as createHash9, randomBytes as randomBytes11 } from "crypto";
|
|
20547
|
-
import { existsSync as existsSync12, readFileSync as readFileSync9, renameSync as renameSync7, rmSync as rmSync5, writeFileSync as
|
|
20583
|
+
import { existsSync as existsSync12, readFileSync as readFileSync9, renameSync as renameSync7, rmSync as rmSync5, writeFileSync as writeFileSync9 } from "fs";
|
|
20548
20584
|
import { mkdir as mkdir19, readdir as readdir6, readFile as readFileFs, rm as rm14, stat as stat8, writeFile as writeFile9 } from "fs/promises";
|
|
20549
20585
|
import { join as join31 } from "path";
|
|
20550
20586
|
|
|
@@ -21362,7 +21398,7 @@ function createGateway(opts) {
|
|
|
21362
21398
|
function saveProofState() {
|
|
21363
21399
|
const tmp = `${holdsFile}.${process.pid}.tmp`;
|
|
21364
21400
|
try {
|
|
21365
|
-
|
|
21401
|
+
writeFileSync9(tmp, JSON.stringify({ holds: Object.fromEntries(holds), used: Object.fromEntries(used) }), { mode: 384 });
|
|
21366
21402
|
renameSync7(tmp, holdsFile);
|
|
21367
21403
|
} catch (err) {
|
|
21368
21404
|
log.warn("user-gateway", "proof-state.write-failed", { detail: String(err) });
|