aai-lark-bridge 0.1.8 → 0.1.9
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 +196 -43
- 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.1.
|
|
7
|
+
version: "0.1.9",
|
|
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",
|
|
@@ -978,6 +978,7 @@ function resolveAppPaths(opts = {}) {
|
|
|
978
978
|
configFile: join4(rootDir, "config.json"),
|
|
979
979
|
activeProfileFile: join4(rootDir, "active-profile"),
|
|
980
980
|
sessionsFile: join4(profileDir, "sessions.json"),
|
|
981
|
+
inboundStateFile: join4(profileDir, "inbound.json"),
|
|
981
982
|
workspacesFile: join4(profileDir, "workspaces.json"),
|
|
982
983
|
secretsFile: join4(profileDir, "secrets.enc"),
|
|
983
984
|
keystoreSaltFile: join4(profileDir, ".keystore.salt"),
|
|
@@ -1782,6 +1783,9 @@ function enable(profile2) {
|
|
|
1782
1783
|
function kickstart(profile2) {
|
|
1783
1784
|
return runLaunchctl(["kickstart", "-k", serviceTarget(profile2)]);
|
|
1784
1785
|
}
|
|
1786
|
+
function nudge(profile2) {
|
|
1787
|
+
return runLaunchctl(["kickstart", serviceTarget(profile2)]);
|
|
1788
|
+
}
|
|
1785
1789
|
function isLoaded(profile2) {
|
|
1786
1790
|
const r = spawnSync("launchctl", ["print", serviceTarget(profile2)], {
|
|
1787
1791
|
stdio: ["ignore", "ignore", "ignore"]
|
|
@@ -2023,7 +2027,10 @@ function makeLaunchdAdapter(profile2, runArgs) {
|
|
|
2023
2027
|
// DB, where it would stay dead through bootstrap. Always enable first.
|
|
2024
2028
|
start: () => {
|
|
2025
2029
|
enable(profile2);
|
|
2026
|
-
|
|
2030
|
+
const loaded = bootstrap(profile2);
|
|
2031
|
+
if (!loaded.ok) return loaded;
|
|
2032
|
+
const nudged = nudge(profile2);
|
|
2033
|
+
return nudged.ok ? loaded : nudged;
|
|
2027
2034
|
},
|
|
2028
2035
|
stop: () => bootout(profile2),
|
|
2029
2036
|
// bootout alone is session-scoped: the plist keeps RunAtLoad=true, so
|
|
@@ -6980,7 +6987,7 @@ function isWindowsCommandNotFoundLine2(line) {
|
|
|
6980
6987
|
|
|
6981
6988
|
// src/bridge/bot/channel.ts
|
|
6982
6989
|
import { createLarkChannel } from "@larksuite/channel";
|
|
6983
|
-
import { dirname as dirname18, join as
|
|
6990
|
+
import { dirname as dirname18, join as join23 } from "path";
|
|
6984
6991
|
|
|
6985
6992
|
// src/bridge/agent/capability.ts
|
|
6986
6993
|
function claudeCapability(profile2) {
|
|
@@ -7022,9 +7029,11 @@ function codexCapability(profile2) {
|
|
|
7022
7029
|
var DEFAULT_MODEL = "default";
|
|
7023
7030
|
var CLAUDE_MODELS = [
|
|
7024
7031
|
{ value: DEFAULT_MODEL, label: "\u8DDF\u968F\u9ED8\u8BA4\uFF08\u4E0D\u6307\u5B9A\uFF09" },
|
|
7032
|
+
{ value: "claude-opus-5-5", label: "Opus 5.5" },
|
|
7025
7033
|
{ value: "claude-opus-5", label: "Opus 5\uFF08\u6700\u65B0\uFF09" },
|
|
7026
7034
|
{ value: "claude-opus-4-8", label: "Opus 4.8" },
|
|
7027
7035
|
{ value: "claude-opus-4-7", label: "Opus 4.7" },
|
|
7036
|
+
{ value: "claude-sonnet-5-5", label: "Sonnet 5.5" },
|
|
7028
7037
|
{ value: "claude-sonnet-5", label: "Sonnet 5\uFF08\u6700\u65B0\uFF09" },
|
|
7029
7038
|
{ value: "claude-sonnet-4-6", label: "Sonnet 4.6" },
|
|
7030
7039
|
{ value: "claude-haiku-4-5", label: "Haiku 4.5\uFF08\u6700\u65B0\uFF09" },
|
|
@@ -11636,12 +11645,63 @@ async function lookupMessageThreadId(channel, messageId) {
|
|
|
11636
11645
|
}
|
|
11637
11646
|
}
|
|
11638
11647
|
|
|
11648
|
+
// src/bridge/card/handoff.ts
|
|
11649
|
+
import { createHash as createHash3 } from "crypto";
|
|
11650
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync3, renameSync as renameSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
11651
|
+
import { isAbsolute as isAbsolute3, join as join21 } from "path";
|
|
11652
|
+
function handoffDirs(raw) {
|
|
11653
|
+
if (!raw || typeof raw !== "object") return {};
|
|
11654
|
+
const out = {};
|
|
11655
|
+
for (const [kind, dir] of Object.entries(raw)) {
|
|
11656
|
+
if (typeof dir === "string" && isAbsolute3(dir)) out[kind] = dir;
|
|
11657
|
+
else log.warn("cardAction", "handoff-bad-dir", { kind });
|
|
11658
|
+
}
|
|
11659
|
+
return out;
|
|
11660
|
+
}
|
|
11661
|
+
function tryHandoff(evt, dirs) {
|
|
11662
|
+
const value = evt.action?.value;
|
|
11663
|
+
if (!value || typeof value !== "object") return false;
|
|
11664
|
+
const kind = value.kind;
|
|
11665
|
+
if (typeof kind !== "string" || !dirs[kind]) return false;
|
|
11666
|
+
const raw = evt.raw;
|
|
11667
|
+
const token = typeof raw?.token === "string" && raw.token.startsWith("c-") ? raw.token : "";
|
|
11668
|
+
const eventId = typeof raw?.event_id === "string" ? raw.event_id : "";
|
|
11669
|
+
const key = eventId || `${evt.messageId}:${evt.operator.openId}:${JSON.stringify(value)}`;
|
|
11670
|
+
const name = `${createHash3("sha256").update(key).digest("hex").slice(0, 24)}.json`;
|
|
11671
|
+
const dir = dirs[kind];
|
|
11672
|
+
try {
|
|
11673
|
+
mkdirSync3(dir, { recursive: true });
|
|
11674
|
+
const file = join21(dir, name);
|
|
11675
|
+
if (existsSync6(file)) return true;
|
|
11676
|
+
const tmp = join21(dir, `.${name}.${process.pid}.tmp`);
|
|
11677
|
+
writeFileSync3(
|
|
11678
|
+
tmp,
|
|
11679
|
+
JSON.stringify({
|
|
11680
|
+
event_id: eventId,
|
|
11681
|
+
kind,
|
|
11682
|
+
value,
|
|
11683
|
+
operator_open_id: evt.operator.openId,
|
|
11684
|
+
message_id: evt.messageId,
|
|
11685
|
+
chat_id: evt.chatId,
|
|
11686
|
+
token,
|
|
11687
|
+
received_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
11688
|
+
})
|
|
11689
|
+
);
|
|
11690
|
+
renameSync2(tmp, file);
|
|
11691
|
+
log.info("cardAction", "handoff", { kind, file: name });
|
|
11692
|
+
} catch (err) {
|
|
11693
|
+
log.fail("cardAction", err, { kind, step: "handoff" });
|
|
11694
|
+
}
|
|
11695
|
+
return true;
|
|
11696
|
+
}
|
|
11697
|
+
|
|
11639
11698
|
// src/bridge/card/dispatcher.ts
|
|
11640
11699
|
var BRIDGE_CALLBACK_MARKER = "__bridge_cb";
|
|
11641
11700
|
var LEGACY_CLAUDE_CALLBACK_MARKER = "__claude_cb";
|
|
11642
11701
|
async function handleCardAction(deps) {
|
|
11643
11702
|
const value = deps.evt.action.value;
|
|
11644
11703
|
if (!value || typeof value !== "object") return;
|
|
11704
|
+
if (tryHandoff(deps.evt, handoffDirs(deps.controls.profileConfig.preferences.cardHandoffs))) return;
|
|
11645
11705
|
const payload = value;
|
|
11646
11706
|
const operatorId = deps.evt.operator.openId;
|
|
11647
11707
|
const chatId = deps.evt.chatId;
|
|
@@ -12064,10 +12124,10 @@ function footerLine(status, apiRetry) {
|
|
|
12064
12124
|
}
|
|
12065
12125
|
|
|
12066
12126
|
// src/bridge/media/cache.ts
|
|
12067
|
-
import { createHash as
|
|
12127
|
+
import { createHash as createHash4 } from "crypto";
|
|
12068
12128
|
import { createReadStream as createReadStream2 } from "fs";
|
|
12069
12129
|
import { mkdir as mkdir14, readdir as readdir5, rename as rename4, rm as rm12, stat as stat7 } from "fs/promises";
|
|
12070
|
-
import { join as
|
|
12130
|
+
import { join as join22 } from "path";
|
|
12071
12131
|
|
|
12072
12132
|
// src/bridge/media/attachment.ts
|
|
12073
12133
|
var DEFAULT_POLICY = {
|
|
@@ -12203,7 +12263,7 @@ var MediaCache = class {
|
|
|
12203
12263
|
return null;
|
|
12204
12264
|
}
|
|
12205
12265
|
const kind = r.type;
|
|
12206
|
-
const tmpPath =
|
|
12266
|
+
const tmpPath = join22(
|
|
12207
12267
|
this.rootDir,
|
|
12208
12268
|
`.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`
|
|
12209
12269
|
);
|
|
@@ -12217,7 +12277,7 @@ var MediaCache = class {
|
|
|
12217
12277
|
const hash = await hashFile(tmpPath);
|
|
12218
12278
|
const mime = contentType ?? defaultMime(kind);
|
|
12219
12279
|
const ext = safeExtensionForMime(mime);
|
|
12220
|
-
const absPath =
|
|
12280
|
+
const absPath = join22(this.rootDir, `${hash}.${ext}`);
|
|
12221
12281
|
try {
|
|
12222
12282
|
await stat7(absPath);
|
|
12223
12283
|
await rm12(tmpPath, { force: true });
|
|
@@ -12259,7 +12319,7 @@ async function listFiles(root) {
|
|
|
12259
12319
|
const out = [];
|
|
12260
12320
|
const entries = await readdir5(root, { withFileTypes: true }).catch(() => []);
|
|
12261
12321
|
for (const entry of entries) {
|
|
12262
|
-
const full =
|
|
12322
|
+
const full = join22(root, entry.name);
|
|
12263
12323
|
if (entry.isDirectory()) {
|
|
12264
12324
|
out.push(...await listFiles(full));
|
|
12265
12325
|
} else if (entry.isFile()) {
|
|
@@ -12269,7 +12329,7 @@ async function listFiles(root) {
|
|
|
12269
12329
|
return out;
|
|
12270
12330
|
}
|
|
12271
12331
|
async function hashFile(path) {
|
|
12272
|
-
const hash =
|
|
12332
|
+
const hash = createHash4("sha256");
|
|
12273
12333
|
for await (const chunk of createReadStream2(path)) {
|
|
12274
12334
|
hash.update(chunk);
|
|
12275
12335
|
}
|
|
@@ -12774,9 +12834,9 @@ import { mkdir as mkdir15 } from "fs/promises";
|
|
|
12774
12834
|
import { dirname as dirname17 } from "path";
|
|
12775
12835
|
|
|
12776
12836
|
// src/bridge/bot/comment-resource.ts
|
|
12777
|
-
import { createHash as
|
|
12837
|
+
import { createHash as createHash5 } from "crypto";
|
|
12778
12838
|
function commentTokenDigest(token) {
|
|
12779
|
-
return
|
|
12839
|
+
return createHash5("sha256").update(token).digest("hex").slice(0, 16);
|
|
12780
12840
|
}
|
|
12781
12841
|
function commentDocumentScopeId(fileToken) {
|
|
12782
12842
|
return `comment-doc:${commentTokenDigest(fileToken)}`;
|
|
@@ -13328,6 +13388,98 @@ function preview(text) {
|
|
|
13328
13388
|
return text.length > 80 ? `${text.slice(0, 80)}\u2026` : text;
|
|
13329
13389
|
}
|
|
13330
13390
|
|
|
13391
|
+
// src/bridge/bot/inbound-mark.ts
|
|
13392
|
+
import { readFile as readFile14 } from "fs/promises";
|
|
13393
|
+
function inboundGapFields(prev, now) {
|
|
13394
|
+
if (!prev) return { first: true };
|
|
13395
|
+
const gapMs = now - prev.at;
|
|
13396
|
+
if (!prev.acrossRestart) return { gapMs };
|
|
13397
|
+
if (gapMs < 0) return { first: true };
|
|
13398
|
+
return { gapMs, acrossRestart: true };
|
|
13399
|
+
}
|
|
13400
|
+
var InboundMarkStore = class {
|
|
13401
|
+
path;
|
|
13402
|
+
appId;
|
|
13403
|
+
write;
|
|
13404
|
+
// Only the newest time matters, so writes coalesce: at most one in flight,
|
|
13405
|
+
// plus the latest value waiting behind it. `pending` = a record() not yet
|
|
13406
|
+
// attempted; each record() buys at most one write attempt, so a failing
|
|
13407
|
+
// disk never makes this spin, yet a failure is retried on the next record()
|
|
13408
|
+
// even when it carries the same millisecond.
|
|
13409
|
+
latest;
|
|
13410
|
+
written;
|
|
13411
|
+
pending = false;
|
|
13412
|
+
inFlight;
|
|
13413
|
+
constructor(path, appId, opts = {}) {
|
|
13414
|
+
this.path = path;
|
|
13415
|
+
this.appId = appId;
|
|
13416
|
+
this.write = opts.write ?? ((p3, data) => writeFileAtomic(p3, data, { mode: 384 }));
|
|
13417
|
+
}
|
|
13418
|
+
/** Persisted time, or undefined when missing, invalid or from another app. Never throws. */
|
|
13419
|
+
async load() {
|
|
13420
|
+
let raw;
|
|
13421
|
+
try {
|
|
13422
|
+
raw = await readFile14(this.path, "utf8");
|
|
13423
|
+
} catch (err) {
|
|
13424
|
+
if (err.code === "ENOENT") return void 0;
|
|
13425
|
+
log.warn("ws", "inbound-state-invalid", { reason: "read", err: String(err) });
|
|
13426
|
+
return void 0;
|
|
13427
|
+
}
|
|
13428
|
+
let parsed;
|
|
13429
|
+
try {
|
|
13430
|
+
parsed = JSON.parse(raw);
|
|
13431
|
+
} catch {
|
|
13432
|
+
log.warn("ws", "inbound-state-invalid", { reason: "json" });
|
|
13433
|
+
return void 0;
|
|
13434
|
+
}
|
|
13435
|
+
if (!isRecord3(parsed)) {
|
|
13436
|
+
log.warn("ws", "inbound-state-invalid", { reason: "shape" });
|
|
13437
|
+
return void 0;
|
|
13438
|
+
}
|
|
13439
|
+
if (parsed.appId !== this.appId) return void 0;
|
|
13440
|
+
return parsed.at;
|
|
13441
|
+
}
|
|
13442
|
+
/** Remember `at` and persist it in the background. Returns immediately, never throws. */
|
|
13443
|
+
record(at) {
|
|
13444
|
+
this.latest = at;
|
|
13445
|
+
this.pending = true;
|
|
13446
|
+
this.kick();
|
|
13447
|
+
}
|
|
13448
|
+
kick() {
|
|
13449
|
+
if (this.inFlight) return;
|
|
13450
|
+
const run = this.drain().finally(() => {
|
|
13451
|
+
if (this.inFlight !== run) return;
|
|
13452
|
+
this.inFlight = void 0;
|
|
13453
|
+
if (this.pending) this.kick();
|
|
13454
|
+
});
|
|
13455
|
+
this.inFlight = run;
|
|
13456
|
+
}
|
|
13457
|
+
/** Wait for in-flight and queued writes (disconnect and tests). */
|
|
13458
|
+
async flush() {
|
|
13459
|
+
while (this.inFlight) await this.inFlight;
|
|
13460
|
+
}
|
|
13461
|
+
async drain() {
|
|
13462
|
+
while (this.pending) {
|
|
13463
|
+
this.pending = false;
|
|
13464
|
+
const at = this.latest;
|
|
13465
|
+
if (at === void 0 || at === this.written) continue;
|
|
13466
|
+
const record = { v: 1, appId: this.appId, at };
|
|
13467
|
+
try {
|
|
13468
|
+
await this.write(this.path, `${JSON.stringify(record)}
|
|
13469
|
+
`);
|
|
13470
|
+
this.written = at;
|
|
13471
|
+
} catch (err) {
|
|
13472
|
+
log.fail("ws", err, { step: "inbound-persist" });
|
|
13473
|
+
}
|
|
13474
|
+
}
|
|
13475
|
+
}
|
|
13476
|
+
};
|
|
13477
|
+
function isRecord3(value) {
|
|
13478
|
+
if (!value || typeof value !== "object") return false;
|
|
13479
|
+
const v = value;
|
|
13480
|
+
return v.v === 1 && typeof v.appId === "string" && v.appId.length > 0 && typeof v.at === "number" && Number.isSafeInteger(v.at) && v.at > 0;
|
|
13481
|
+
}
|
|
13482
|
+
|
|
13331
13483
|
// src/bridge/bot/keepalive.ts
|
|
13332
13484
|
var KEEPALIVE_INTERVAL_MS = 15e3;
|
|
13333
13485
|
var SLEEP_DETECT_MS = 3e4;
|
|
@@ -14152,7 +14304,7 @@ async function startChannel(deps) {
|
|
|
14152
14304
|
const pool = new ProcessPool(() => getMaxConcurrentRuns(controls.cfg));
|
|
14153
14305
|
const executor = new RunExecutor({ agent, pool, activeRuns });
|
|
14154
14306
|
const appSecret = await resolveAppSecret(cfg, deps.appPaths);
|
|
14155
|
-
const callbackNonceStore = deps.appPaths?.mediaDir ? new CallbackNonceStore(
|
|
14307
|
+
const callbackNonceStore = deps.appPaths?.mediaDir ? new CallbackNonceStore(join23(dirname18(deps.appPaths.mediaDir), "callback-nonces.json")) : void 0;
|
|
14156
14308
|
await callbackNonceStore?.load();
|
|
14157
14309
|
const callbackAuth = callbackNonceStore ? new CallbackAuth({
|
|
14158
14310
|
keys: [{ version: 1, secret: appSecret }],
|
|
@@ -14262,14 +14414,14 @@ async function startChannel(deps) {
|
|
|
14262
14414
|
});
|
|
14263
14415
|
});
|
|
14264
14416
|
let consecutiveReconnects = 0;
|
|
14265
|
-
|
|
14417
|
+
const inboundMarks = deps.appPaths?.inboundStateFile ? new InboundMarkStore(deps.appPaths.inboundStateFile, cfg.accounts.app.id) : void 0;
|
|
14418
|
+
const persistedInboundAt = await inboundMarks?.load();
|
|
14419
|
+
let lastInbound = persistedInboundAt !== void 0 ? { at: persistedInboundAt, acrossRestart: true } : void 0;
|
|
14266
14420
|
const markInbound = (kind) => {
|
|
14267
14421
|
const at = Date.now();
|
|
14268
|
-
log.info("ws", "inbound", {
|
|
14269
|
-
|
|
14270
|
-
|
|
14271
|
-
});
|
|
14272
|
-
lastInboundAt = at;
|
|
14422
|
+
log.info("ws", "inbound", { kind, ...inboundGapFields(lastInbound, at) });
|
|
14423
|
+
lastInbound = { at, acrossRestart: false };
|
|
14424
|
+
inboundMarks?.record(at);
|
|
14273
14425
|
};
|
|
14274
14426
|
channel.on({
|
|
14275
14427
|
message: async (msg) => {
|
|
@@ -14454,7 +14606,8 @@ async function startChannel(deps) {
|
|
|
14454
14606
|
sessions2.flush(),
|
|
14455
14607
|
sessionCatalog?.flush(),
|
|
14456
14608
|
callbackNonceStore?.flush(),
|
|
14457
|
-
workspaces.flush()
|
|
14609
|
+
workspaces.flush(),
|
|
14610
|
+
inboundMarks?.flush()
|
|
14458
14611
|
]);
|
|
14459
14612
|
if (stopAllResult.status === "rejected") {
|
|
14460
14613
|
log.fail("disconnect", stopAllResult.reason, { step: "stopAll" });
|
|
@@ -15626,11 +15779,11 @@ function parseJson2(text) {
|
|
|
15626
15779
|
return void 0;
|
|
15627
15780
|
}
|
|
15628
15781
|
}
|
|
15629
|
-
function
|
|
15782
|
+
function isRecord4(v) {
|
|
15630
15783
|
return Boolean(v) && typeof v === "object" && !Array.isArray(v);
|
|
15631
15784
|
}
|
|
15632
15785
|
function pickString(obj, keys, depth = 0) {
|
|
15633
|
-
if (depth > 4 || !
|
|
15786
|
+
if (depth > 4 || !isRecord4(obj)) return void 0;
|
|
15634
15787
|
for (const key of keys) {
|
|
15635
15788
|
const v = obj[key];
|
|
15636
15789
|
if (typeof v === "string" && v.trim()) return v;
|
|
@@ -15642,7 +15795,7 @@ function pickString(obj, keys, depth = 0) {
|
|
|
15642
15795
|
return void 0;
|
|
15643
15796
|
}
|
|
15644
15797
|
function findString(obj, re, depth = 0) {
|
|
15645
|
-
if (depth > 4 || !
|
|
15798
|
+
if (depth > 4 || !isRecord4(obj)) return void 0;
|
|
15646
15799
|
for (const [k, v] of Object.entries(obj)) {
|
|
15647
15800
|
if (typeof v === "string" && re.test(k) && v.trim()) return v;
|
|
15648
15801
|
}
|
|
@@ -15655,8 +15808,8 @@ function findString(obj, re, depth = 0) {
|
|
|
15655
15808
|
async function getUserAuthStatus(ctx, exec = defaultExec) {
|
|
15656
15809
|
const r = await exec(["auth", "status", "--json"], larkCliEnv(ctx), 15e3);
|
|
15657
15810
|
const json = parseJson2(r.stdout);
|
|
15658
|
-
const user =
|
|
15659
|
-
if (!
|
|
15811
|
+
const user = isRecord4(json) && isRecord4(json.identities) ? json.identities.user : void 0;
|
|
15812
|
+
if (!isRecord4(user)) return { loggedIn: false, scopes: [] };
|
|
15660
15813
|
const loggedIn = user.available === true && (user.tokenStatus === "valid" || user.status === "ready");
|
|
15661
15814
|
const scopes = typeof user.scope === "string" ? user.scope.split(/\s+/).filter(Boolean) : [];
|
|
15662
15815
|
return {
|
|
@@ -15693,7 +15846,7 @@ async function startDeviceLogin(ctx, scopes = LIST_CHAT_SCOPES, exec = defaultEx
|
|
|
15693
15846
|
`\u65E0\u6CD5\u5F00\u59CB\u6388\u6743\uFF1A${r.stderr.trim() || r.stdout.trim() || "lark-cli auth login \u672A\u8FD4\u56DE\u9A8C\u8BC1\u94FE\u63A5"}`
|
|
15694
15847
|
);
|
|
15695
15848
|
}
|
|
15696
|
-
const expiresIn =
|
|
15849
|
+
const expiresIn = isRecord4(json) && typeof json.expiresIn === "number" ? json.expiresIn : isRecord4(json) && typeof json.expires_in === "number" ? json.expires_in : void 0;
|
|
15697
15850
|
return { verificationUrl, deviceCode, ...userCode ? { userCode } : {}, ...expiresIn ? { expiresIn } : {} };
|
|
15698
15851
|
}
|
|
15699
15852
|
async function completeDeviceLogin(ctx, deviceCode, exec = defaultExec) {
|
|
@@ -15711,7 +15864,7 @@ var DEFAULT_PAGE_SIZE = 8;
|
|
|
15711
15864
|
function toChats(items) {
|
|
15712
15865
|
const chats = [];
|
|
15713
15866
|
for (const it of items) {
|
|
15714
|
-
if (!
|
|
15867
|
+
if (!isRecord4(it)) continue;
|
|
15715
15868
|
const id = typeof it.chat_id === "string" ? it.chat_id : typeof it.id === "string" ? it.id : "";
|
|
15716
15869
|
if (!id) continue;
|
|
15717
15870
|
const name = typeof it.name === "string" && it.name.trim() ? it.name : "(\u65E0\u540D\u7FA4)";
|
|
@@ -15722,7 +15875,7 @@ function toChats(items) {
|
|
|
15722
15875
|
function parseChatsPage(r, prefix) {
|
|
15723
15876
|
if (r.code !== 0) throw new Error(cliError(r, prefix));
|
|
15724
15877
|
const json = parseJson2(r.stdout);
|
|
15725
|
-
const data =
|
|
15878
|
+
const data = isRecord4(json) && isRecord4(json.data) ? json.data : isRecord4(json) ? json : {};
|
|
15726
15879
|
const hasMore = data.has_more === true;
|
|
15727
15880
|
const pageToken = typeof data.page_token === "string" ? data.page_token : void 0;
|
|
15728
15881
|
return {
|
|
@@ -15780,11 +15933,11 @@ async function addBotToChat(ctx, chatId, botAppId, exec = defaultExec) {
|
|
|
15780
15933
|
3e4
|
|
15781
15934
|
);
|
|
15782
15935
|
const json = parseJson2(r.stdout);
|
|
15783
|
-
const data =
|
|
15784
|
-
const invalid = extractArray(
|
|
15785
|
-
const notExisted = extractArray(
|
|
15786
|
-
const pendingList = extractArray(
|
|
15787
|
-
const inList = (arr) => arr.some((x) => typeof x === "string" ? x === botAppId :
|
|
15936
|
+
const data = isRecord4(json) && isRecord4(json.data) ? json.data : isRecord4(json) ? json : {};
|
|
15937
|
+
const invalid = extractArray(isRecord4(data) ? data.invalid_id_list : void 0);
|
|
15938
|
+
const notExisted = extractArray(isRecord4(data) ? data.not_existed_id_list : void 0);
|
|
15939
|
+
const pendingList = extractArray(isRecord4(data) ? data.pending_approval_id_list : void 0);
|
|
15940
|
+
const inList = (arr) => arr.some((x) => typeof x === "string" ? x === botAppId : isRecord4(x) && x.id === botAppId);
|
|
15788
15941
|
if (r.code === 0 && (inList(invalid) || inList(notExisted))) {
|
|
15789
15942
|
return {
|
|
15790
15943
|
ok: false,
|
|
@@ -15802,11 +15955,11 @@ async function addBotToChat(ctx, chatId, botAppId, exec = defaultExec) {
|
|
|
15802
15955
|
}
|
|
15803
15956
|
function extractArray(v) {
|
|
15804
15957
|
if (Array.isArray(v)) return v;
|
|
15805
|
-
if (!
|
|
15958
|
+
if (!isRecord4(v)) return [];
|
|
15806
15959
|
const keys = ["items", "chats", "list", "invalid_id_list", "not_existed_id_list", "pending_approval_id_list"];
|
|
15807
15960
|
for (const container of [v, v.data]) {
|
|
15808
15961
|
if (Array.isArray(container)) return container;
|
|
15809
|
-
if (
|
|
15962
|
+
if (isRecord4(container)) {
|
|
15810
15963
|
for (const key of keys) {
|
|
15811
15964
|
if (Array.isArray(container[key])) return container[key];
|
|
15812
15965
|
}
|
|
@@ -15854,7 +16007,7 @@ var defaultExec2 = (args, env) => new Promise((resolve3) => {
|
|
|
15854
16007
|
resolve3({ code, stdout, stderr });
|
|
15855
16008
|
});
|
|
15856
16009
|
});
|
|
15857
|
-
function
|
|
16010
|
+
function isRecord5(v) {
|
|
15858
16011
|
return Boolean(v) && typeof v === "object" && !Array.isArray(v);
|
|
15859
16012
|
}
|
|
15860
16013
|
function parseJson3(text) {
|
|
@@ -15881,13 +16034,13 @@ function classifyPreflight(payload) {
|
|
|
15881
16034
|
requiredEvents: MEETING_REQUIRED_EVENTS,
|
|
15882
16035
|
requiredScopes: MEETING_REQUIRED_SCOPES
|
|
15883
16036
|
};
|
|
15884
|
-
if (!
|
|
16037
|
+
if (!isRecord5(payload)) {
|
|
15885
16038
|
return { ...base, status: "unknown", message: "\u65E0\u6CD5\u89E3\u6790 lark-cli \u8F93\u51FA" };
|
|
15886
16039
|
}
|
|
15887
16040
|
if (payload.ok === true) {
|
|
15888
16041
|
return { ...base, status: "ok", message: "\u5E94\u7528\u8EAB\u4EFD\u6743\u9650\u5DF2\u5C31\u7EEA" };
|
|
15889
16042
|
}
|
|
15890
|
-
const err =
|
|
16043
|
+
const err = isRecord5(payload.error) ? payload.error : {};
|
|
15891
16044
|
const code = typeof err.code === "number" ? err.code : void 0;
|
|
15892
16045
|
const subtype = typeof err.subtype === "string" ? err.subtype : "";
|
|
15893
16046
|
const message = typeof err.message === "string" ? err.message : "\u6743\u9650\u68C0\u67E5\u5931\u8D25";
|
|
@@ -16758,7 +16911,7 @@ async function route(req, res, deps, url) {
|
|
|
16758
16911
|
}
|
|
16759
16912
|
|
|
16760
16913
|
// src/bridge/session/store.ts
|
|
16761
|
-
import { readFile as
|
|
16914
|
+
import { readFile as readFile15 } from "fs/promises";
|
|
16762
16915
|
var SessionStore = class {
|
|
16763
16916
|
data = {};
|
|
16764
16917
|
saving = Promise.resolve();
|
|
@@ -16769,7 +16922,7 @@ var SessionStore = class {
|
|
|
16769
16922
|
}
|
|
16770
16923
|
async load() {
|
|
16771
16924
|
try {
|
|
16772
|
-
const text = await
|
|
16925
|
+
const text = await readFile15(this.path, "utf8");
|
|
16773
16926
|
const raw = JSON.parse(text);
|
|
16774
16927
|
this.data = {};
|
|
16775
16928
|
for (const [chatId, entry] of Object.entries(raw)) {
|
|
@@ -16882,7 +17035,7 @@ var SessionStore = class {
|
|
|
16882
17035
|
|
|
16883
17036
|
// src/bridge/session/catalog.ts
|
|
16884
17037
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
16885
|
-
import { open as open3, readFile as
|
|
17038
|
+
import { open as open3, readFile as readFile16, rename as rename5, mkdir as mkdir16 } from "fs/promises";
|
|
16886
17039
|
import { dirname as dirname19 } from "path";
|
|
16887
17040
|
var DEFAULT_MAX_ARCHIVED_AGE_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
16888
17041
|
var DEFAULT_MAX_ENTRIES_PER_SCOPE = 20;
|
|
@@ -16905,7 +17058,7 @@ var SessionCatalog = class {
|
|
|
16905
17058
|
}
|
|
16906
17059
|
async load() {
|
|
16907
17060
|
try {
|
|
16908
|
-
const raw = JSON.parse(await
|
|
17061
|
+
const raw = JSON.parse(await readFile16(this.path, "utf8"));
|
|
16909
17062
|
if (!Array.isArray(raw)) {
|
|
16910
17063
|
this.data.clear();
|
|
16911
17064
|
return;
|
|
@@ -17079,7 +17232,7 @@ function assertAgentIdentity(input) {
|
|
|
17079
17232
|
}
|
|
17080
17233
|
|
|
17081
17234
|
// src/bridge/workspace/store.ts
|
|
17082
|
-
import { readFile as
|
|
17235
|
+
import { readFile as readFile17 } from "fs/promises";
|
|
17083
17236
|
var WorkspaceStore = class {
|
|
17084
17237
|
data = { chats: {}, named: {} };
|
|
17085
17238
|
saving = Promise.resolve();
|
|
@@ -17089,7 +17242,7 @@ var WorkspaceStore = class {
|
|
|
17089
17242
|
}
|
|
17090
17243
|
async load() {
|
|
17091
17244
|
try {
|
|
17092
|
-
const text = await
|
|
17245
|
+
const text = await readFile17(this.path, "utf8");
|
|
17093
17246
|
const parsed = JSON.parse(text);
|
|
17094
17247
|
this.data = {
|
|
17095
17248
|
chats: parsed.chats ?? {},
|