aai-lark-bridge 0.1.8 → 0.2.0
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/README.md +4 -0
- package/dist/cli.js +241 -43
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,6 +47,10 @@ lark-cli --version # 见下方说明
|
|
|
47
47
|
会话;不要通过删历史、改会话元数据或自动另开会话处理兼容问题。
|
|
48
48
|
- 启动失败会显示 stderr 的最后 500 字符,避免真正的终止错误被前面的插件警告盖住。
|
|
49
49
|
|
|
50
|
+
### SDLC 文档评论确认(可选)
|
|
51
|
+
|
|
52
|
+
`preferences.sdlcConfirmationWorkspace` 可设为 SDLC 工作区绝对路径,默认关闭。普通文档评论先保存最小线索,再唤醒固定只读核验;事件正文不作为授权。需同时安装并启用 SDLC 评论核验,部署后实测事件覆盖;配置与暂停方式见仓库 `plugins/aai-sdlc/agent/README.md`。
|
|
53
|
+
|
|
50
54
|
### 第 2 步:安装
|
|
51
55
|
|
|
52
56
|
```bash
|
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.
|
|
7
|
+
version: "0.2.0",
|
|
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 join24 } 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,138 @@ function preview(text) {
|
|
|
13328
13388
|
return text.length > 80 ? `${text.slice(0, 80)}\u2026` : text;
|
|
13329
13389
|
}
|
|
13330
13390
|
|
|
13391
|
+
// src/bridge/bot/doc-confirmation.ts
|
|
13392
|
+
import { createHash as createHash6 } from "crypto";
|
|
13393
|
+
import { mkdirSync as mkdirSync4, realpathSync, renameSync as renameSync3, writeFileSync as writeFileSync4 } from "fs";
|
|
13394
|
+
import { isAbsolute as isAbsolute4, join as join23, sep as sep2 } from "path";
|
|
13395
|
+
import { spawn } from "child_process";
|
|
13396
|
+
var waking = /* @__PURE__ */ new Set();
|
|
13397
|
+
function enqueueDocConfirmation(workspace, event, { selfReply = false } = {}) {
|
|
13398
|
+
if (!workspace || selfReply) return false;
|
|
13399
|
+
if (!isAbsolute4(workspace)) throw new Error("SDLC \u5DE5\u4F5C\u533A\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
|
|
13400
|
+
if (event.fileType !== "docx") return false;
|
|
13401
|
+
if (![event.fileToken, event.commentId, event.replyId ?? "none"].every((x) => /^[\w:-]{1,128}$/.test(x))) return false;
|
|
13402
|
+
const root = realpathSync(workspace);
|
|
13403
|
+
const script = realpathSync(join23(root, ".sdlc-intake/intake.mjs"));
|
|
13404
|
+
if (!script.startsWith(root + sep2)) throw new Error("SDLC \u6838\u9A8C\u5165\u53E3\u8D85\u51FA\u5DE5\u4F5C\u533A");
|
|
13405
|
+
const inbox = join23(root, ".sdlc-intake/state/confirmation-inbox");
|
|
13406
|
+
mkdirSync4(inbox, { recursive: true });
|
|
13407
|
+
if (!realpathSync(inbox).startsWith(root + sep2)) throw new Error("SDLC \u6536\u4EF6\u76EE\u5F55\u8D85\u51FA\u5DE5\u4F5C\u533A");
|
|
13408
|
+
const { fileToken: fileId, commentId: comment_id } = event;
|
|
13409
|
+
const hint = { file_token: fileId, comment_id, reply_id: event.replyId ?? null, received_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
13410
|
+
const key = createHash6("sha256").update(JSON.stringify([hint.file_token, hint.comment_id, hint.reply_id])).digest("hex");
|
|
13411
|
+
const target = join23(inbox, key + ".json");
|
|
13412
|
+
const tmp = target + `.new-${process.pid}`;
|
|
13413
|
+
writeFileSync4(tmp, JSON.stringify(hint), { mode: 384 });
|
|
13414
|
+
renameSync3(tmp, target);
|
|
13415
|
+
if (!waking.has(root)) {
|
|
13416
|
+
waking.add(root);
|
|
13417
|
+
try {
|
|
13418
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([key2]) => !key2.startsWith("LARK_CHANNEL") && !key2.startsWith("LARKSUITE_CLI_")));
|
|
13419
|
+
const child = spawn(process.execPath, [script, "reconcile-confirmations"], { cwd: root, env, stdio: "ignore", timeout: 7e4 });
|
|
13420
|
+
child.once("error", () => waking.delete(root));
|
|
13421
|
+
child.once("exit", () => waking.delete(root));
|
|
13422
|
+
child.unref();
|
|
13423
|
+
} catch (err) {
|
|
13424
|
+
waking.delete(root);
|
|
13425
|
+
throw err;
|
|
13426
|
+
}
|
|
13427
|
+
}
|
|
13428
|
+
return true;
|
|
13429
|
+
}
|
|
13430
|
+
|
|
13431
|
+
// src/bridge/bot/inbound-mark.ts
|
|
13432
|
+
import { readFile as readFile14 } from "fs/promises";
|
|
13433
|
+
function inboundGapFields(prev, now) {
|
|
13434
|
+
if (!prev) return { first: true };
|
|
13435
|
+
const gapMs = now - prev.at;
|
|
13436
|
+
if (!prev.acrossRestart) return { gapMs };
|
|
13437
|
+
if (gapMs < 0) return { first: true };
|
|
13438
|
+
return { gapMs, acrossRestart: true };
|
|
13439
|
+
}
|
|
13440
|
+
var InboundMarkStore = class {
|
|
13441
|
+
path;
|
|
13442
|
+
appId;
|
|
13443
|
+
write;
|
|
13444
|
+
// Only the newest time matters, so writes coalesce: at most one in flight,
|
|
13445
|
+
// plus the latest value waiting behind it. `pending` = a record() not yet
|
|
13446
|
+
// attempted; each record() buys at most one write attempt, so a failing
|
|
13447
|
+
// disk never makes this spin, yet a failure is retried on the next record()
|
|
13448
|
+
// even when it carries the same millisecond.
|
|
13449
|
+
latest;
|
|
13450
|
+
written;
|
|
13451
|
+
pending = false;
|
|
13452
|
+
inFlight;
|
|
13453
|
+
constructor(path, appId, opts = {}) {
|
|
13454
|
+
this.path = path;
|
|
13455
|
+
this.appId = appId;
|
|
13456
|
+
this.write = opts.write ?? ((p3, data) => writeFileAtomic(p3, data, { mode: 384 }));
|
|
13457
|
+
}
|
|
13458
|
+
/** Persisted time, or undefined when missing, invalid or from another app. Never throws. */
|
|
13459
|
+
async load() {
|
|
13460
|
+
let raw;
|
|
13461
|
+
try {
|
|
13462
|
+
raw = await readFile14(this.path, "utf8");
|
|
13463
|
+
} catch (err) {
|
|
13464
|
+
if (err.code === "ENOENT") return void 0;
|
|
13465
|
+
log.warn("ws", "inbound-state-invalid", { reason: "read", err: String(err) });
|
|
13466
|
+
return void 0;
|
|
13467
|
+
}
|
|
13468
|
+
let parsed;
|
|
13469
|
+
try {
|
|
13470
|
+
parsed = JSON.parse(raw);
|
|
13471
|
+
} catch {
|
|
13472
|
+
log.warn("ws", "inbound-state-invalid", { reason: "json" });
|
|
13473
|
+
return void 0;
|
|
13474
|
+
}
|
|
13475
|
+
if (!isRecord3(parsed)) {
|
|
13476
|
+
log.warn("ws", "inbound-state-invalid", { reason: "shape" });
|
|
13477
|
+
return void 0;
|
|
13478
|
+
}
|
|
13479
|
+
if (parsed.appId !== this.appId) return void 0;
|
|
13480
|
+
return parsed.at;
|
|
13481
|
+
}
|
|
13482
|
+
/** Remember `at` and persist it in the background. Returns immediately, never throws. */
|
|
13483
|
+
record(at) {
|
|
13484
|
+
this.latest = at;
|
|
13485
|
+
this.pending = true;
|
|
13486
|
+
this.kick();
|
|
13487
|
+
}
|
|
13488
|
+
kick() {
|
|
13489
|
+
if (this.inFlight) return;
|
|
13490
|
+
const run = this.drain().finally(() => {
|
|
13491
|
+
if (this.inFlight !== run) return;
|
|
13492
|
+
this.inFlight = void 0;
|
|
13493
|
+
if (this.pending) this.kick();
|
|
13494
|
+
});
|
|
13495
|
+
this.inFlight = run;
|
|
13496
|
+
}
|
|
13497
|
+
/** Wait for in-flight and queued writes (disconnect and tests). */
|
|
13498
|
+
async flush() {
|
|
13499
|
+
while (this.inFlight) await this.inFlight;
|
|
13500
|
+
}
|
|
13501
|
+
async drain() {
|
|
13502
|
+
while (this.pending) {
|
|
13503
|
+
this.pending = false;
|
|
13504
|
+
const at = this.latest;
|
|
13505
|
+
if (at === void 0 || at === this.written) continue;
|
|
13506
|
+
const record = { v: 1, appId: this.appId, at };
|
|
13507
|
+
try {
|
|
13508
|
+
await this.write(this.path, `${JSON.stringify(record)}
|
|
13509
|
+
`);
|
|
13510
|
+
this.written = at;
|
|
13511
|
+
} catch (err) {
|
|
13512
|
+
log.fail("ws", err, { step: "inbound-persist" });
|
|
13513
|
+
}
|
|
13514
|
+
}
|
|
13515
|
+
}
|
|
13516
|
+
};
|
|
13517
|
+
function isRecord3(value) {
|
|
13518
|
+
if (!value || typeof value !== "object") return false;
|
|
13519
|
+
const v = value;
|
|
13520
|
+
return v.v === 1 && typeof v.appId === "string" && v.appId.length > 0 && typeof v.at === "number" && Number.isSafeInteger(v.at) && v.at > 0;
|
|
13521
|
+
}
|
|
13522
|
+
|
|
13331
13523
|
// src/bridge/bot/keepalive.ts
|
|
13332
13524
|
var KEEPALIVE_INTERVAL_MS = 15e3;
|
|
13333
13525
|
var SLEEP_DETECT_MS = 3e4;
|
|
@@ -14152,7 +14344,7 @@ async function startChannel(deps) {
|
|
|
14152
14344
|
const pool = new ProcessPool(() => getMaxConcurrentRuns(controls.cfg));
|
|
14153
14345
|
const executor = new RunExecutor({ agent, pool, activeRuns });
|
|
14154
14346
|
const appSecret = await resolveAppSecret(cfg, deps.appPaths);
|
|
14155
|
-
const callbackNonceStore = deps.appPaths?.mediaDir ? new CallbackNonceStore(
|
|
14347
|
+
const callbackNonceStore = deps.appPaths?.mediaDir ? new CallbackNonceStore(join24(dirname18(deps.appPaths.mediaDir), "callback-nonces.json")) : void 0;
|
|
14156
14348
|
await callbackNonceStore?.load();
|
|
14157
14349
|
const callbackAuth = callbackNonceStore ? new CallbackAuth({
|
|
14158
14350
|
keys: [{ version: 1, secret: appSecret }],
|
|
@@ -14262,14 +14454,14 @@ async function startChannel(deps) {
|
|
|
14262
14454
|
});
|
|
14263
14455
|
});
|
|
14264
14456
|
let consecutiveReconnects = 0;
|
|
14265
|
-
|
|
14457
|
+
const inboundMarks = deps.appPaths?.inboundStateFile ? new InboundMarkStore(deps.appPaths.inboundStateFile, cfg.accounts.app.id) : void 0;
|
|
14458
|
+
const persistedInboundAt = await inboundMarks?.load();
|
|
14459
|
+
let lastInbound = persistedInboundAt !== void 0 ? { at: persistedInboundAt, acrossRestart: true } : void 0;
|
|
14266
14460
|
const markInbound = (kind) => {
|
|
14267
14461
|
const at = Date.now();
|
|
14268
|
-
log.info("ws", "inbound", {
|
|
14269
|
-
|
|
14270
|
-
|
|
14271
|
-
});
|
|
14272
|
-
lastInboundAt = at;
|
|
14462
|
+
log.info("ws", "inbound", { kind, ...inboundGapFields(lastInbound, at) });
|
|
14463
|
+
lastInbound = { at, acrossRestart: false };
|
|
14464
|
+
inboundMarks?.record(at);
|
|
14273
14465
|
};
|
|
14274
14466
|
channel.on({
|
|
14275
14467
|
message: async (msg) => {
|
|
@@ -14320,6 +14512,11 @@ async function startChannel(deps) {
|
|
|
14320
14512
|
},
|
|
14321
14513
|
comment: async (evt) => {
|
|
14322
14514
|
markInbound("comment");
|
|
14515
|
+
try {
|
|
14516
|
+
enqueueDocConfirmation(controls.profileConfig.preferences.sdlcConfirmationWorkspace, evt, { selfReply: isBridgeSelfReply(channel, evt) });
|
|
14517
|
+
} catch (err) {
|
|
14518
|
+
log.fail("doc-confirmation", err);
|
|
14519
|
+
}
|
|
14323
14520
|
await withTrace({ chatId: "comment" }, async () => {
|
|
14324
14521
|
await handleCommentMention({
|
|
14325
14522
|
channel,
|
|
@@ -14454,7 +14651,8 @@ async function startChannel(deps) {
|
|
|
14454
14651
|
sessions2.flush(),
|
|
14455
14652
|
sessionCatalog?.flush(),
|
|
14456
14653
|
callbackNonceStore?.flush(),
|
|
14457
|
-
workspaces.flush()
|
|
14654
|
+
workspaces.flush(),
|
|
14655
|
+
inboundMarks?.flush()
|
|
14458
14656
|
]);
|
|
14459
14657
|
if (stopAllResult.status === "rejected") {
|
|
14460
14658
|
log.fail("disconnect", stopAllResult.reason, { step: "stopAll" });
|
|
@@ -15626,11 +15824,11 @@ function parseJson2(text) {
|
|
|
15626
15824
|
return void 0;
|
|
15627
15825
|
}
|
|
15628
15826
|
}
|
|
15629
|
-
function
|
|
15827
|
+
function isRecord4(v) {
|
|
15630
15828
|
return Boolean(v) && typeof v === "object" && !Array.isArray(v);
|
|
15631
15829
|
}
|
|
15632
15830
|
function pickString(obj, keys, depth = 0) {
|
|
15633
|
-
if (depth > 4 || !
|
|
15831
|
+
if (depth > 4 || !isRecord4(obj)) return void 0;
|
|
15634
15832
|
for (const key of keys) {
|
|
15635
15833
|
const v = obj[key];
|
|
15636
15834
|
if (typeof v === "string" && v.trim()) return v;
|
|
@@ -15642,7 +15840,7 @@ function pickString(obj, keys, depth = 0) {
|
|
|
15642
15840
|
return void 0;
|
|
15643
15841
|
}
|
|
15644
15842
|
function findString(obj, re, depth = 0) {
|
|
15645
|
-
if (depth > 4 || !
|
|
15843
|
+
if (depth > 4 || !isRecord4(obj)) return void 0;
|
|
15646
15844
|
for (const [k, v] of Object.entries(obj)) {
|
|
15647
15845
|
if (typeof v === "string" && re.test(k) && v.trim()) return v;
|
|
15648
15846
|
}
|
|
@@ -15655,8 +15853,8 @@ function findString(obj, re, depth = 0) {
|
|
|
15655
15853
|
async function getUserAuthStatus(ctx, exec = defaultExec) {
|
|
15656
15854
|
const r = await exec(["auth", "status", "--json"], larkCliEnv(ctx), 15e3);
|
|
15657
15855
|
const json = parseJson2(r.stdout);
|
|
15658
|
-
const user =
|
|
15659
|
-
if (!
|
|
15856
|
+
const user = isRecord4(json) && isRecord4(json.identities) ? json.identities.user : void 0;
|
|
15857
|
+
if (!isRecord4(user)) return { loggedIn: false, scopes: [] };
|
|
15660
15858
|
const loggedIn = user.available === true && (user.tokenStatus === "valid" || user.status === "ready");
|
|
15661
15859
|
const scopes = typeof user.scope === "string" ? user.scope.split(/\s+/).filter(Boolean) : [];
|
|
15662
15860
|
return {
|
|
@@ -15693,7 +15891,7 @@ async function startDeviceLogin(ctx, scopes = LIST_CHAT_SCOPES, exec = defaultEx
|
|
|
15693
15891
|
`\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
15892
|
);
|
|
15695
15893
|
}
|
|
15696
|
-
const expiresIn =
|
|
15894
|
+
const expiresIn = isRecord4(json) && typeof json.expiresIn === "number" ? json.expiresIn : isRecord4(json) && typeof json.expires_in === "number" ? json.expires_in : void 0;
|
|
15697
15895
|
return { verificationUrl, deviceCode, ...userCode ? { userCode } : {}, ...expiresIn ? { expiresIn } : {} };
|
|
15698
15896
|
}
|
|
15699
15897
|
async function completeDeviceLogin(ctx, deviceCode, exec = defaultExec) {
|
|
@@ -15711,7 +15909,7 @@ var DEFAULT_PAGE_SIZE = 8;
|
|
|
15711
15909
|
function toChats(items) {
|
|
15712
15910
|
const chats = [];
|
|
15713
15911
|
for (const it of items) {
|
|
15714
|
-
if (!
|
|
15912
|
+
if (!isRecord4(it)) continue;
|
|
15715
15913
|
const id = typeof it.chat_id === "string" ? it.chat_id : typeof it.id === "string" ? it.id : "";
|
|
15716
15914
|
if (!id) continue;
|
|
15717
15915
|
const name = typeof it.name === "string" && it.name.trim() ? it.name : "(\u65E0\u540D\u7FA4)";
|
|
@@ -15722,7 +15920,7 @@ function toChats(items) {
|
|
|
15722
15920
|
function parseChatsPage(r, prefix) {
|
|
15723
15921
|
if (r.code !== 0) throw new Error(cliError(r, prefix));
|
|
15724
15922
|
const json = parseJson2(r.stdout);
|
|
15725
|
-
const data =
|
|
15923
|
+
const data = isRecord4(json) && isRecord4(json.data) ? json.data : isRecord4(json) ? json : {};
|
|
15726
15924
|
const hasMore = data.has_more === true;
|
|
15727
15925
|
const pageToken = typeof data.page_token === "string" ? data.page_token : void 0;
|
|
15728
15926
|
return {
|
|
@@ -15780,11 +15978,11 @@ async function addBotToChat(ctx, chatId, botAppId, exec = defaultExec) {
|
|
|
15780
15978
|
3e4
|
|
15781
15979
|
);
|
|
15782
15980
|
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 :
|
|
15981
|
+
const data = isRecord4(json) && isRecord4(json.data) ? json.data : isRecord4(json) ? json : {};
|
|
15982
|
+
const invalid = extractArray(isRecord4(data) ? data.invalid_id_list : void 0);
|
|
15983
|
+
const notExisted = extractArray(isRecord4(data) ? data.not_existed_id_list : void 0);
|
|
15984
|
+
const pendingList = extractArray(isRecord4(data) ? data.pending_approval_id_list : void 0);
|
|
15985
|
+
const inList = (arr) => arr.some((x) => typeof x === "string" ? x === botAppId : isRecord4(x) && x.id === botAppId);
|
|
15788
15986
|
if (r.code === 0 && (inList(invalid) || inList(notExisted))) {
|
|
15789
15987
|
return {
|
|
15790
15988
|
ok: false,
|
|
@@ -15802,11 +16000,11 @@ async function addBotToChat(ctx, chatId, botAppId, exec = defaultExec) {
|
|
|
15802
16000
|
}
|
|
15803
16001
|
function extractArray(v) {
|
|
15804
16002
|
if (Array.isArray(v)) return v;
|
|
15805
|
-
if (!
|
|
16003
|
+
if (!isRecord4(v)) return [];
|
|
15806
16004
|
const keys = ["items", "chats", "list", "invalid_id_list", "not_existed_id_list", "pending_approval_id_list"];
|
|
15807
16005
|
for (const container of [v, v.data]) {
|
|
15808
16006
|
if (Array.isArray(container)) return container;
|
|
15809
|
-
if (
|
|
16007
|
+
if (isRecord4(container)) {
|
|
15810
16008
|
for (const key of keys) {
|
|
15811
16009
|
if (Array.isArray(container[key])) return container[key];
|
|
15812
16010
|
}
|
|
@@ -15854,7 +16052,7 @@ var defaultExec2 = (args, env) => new Promise((resolve3) => {
|
|
|
15854
16052
|
resolve3({ code, stdout, stderr });
|
|
15855
16053
|
});
|
|
15856
16054
|
});
|
|
15857
|
-
function
|
|
16055
|
+
function isRecord5(v) {
|
|
15858
16056
|
return Boolean(v) && typeof v === "object" && !Array.isArray(v);
|
|
15859
16057
|
}
|
|
15860
16058
|
function parseJson3(text) {
|
|
@@ -15881,13 +16079,13 @@ function classifyPreflight(payload) {
|
|
|
15881
16079
|
requiredEvents: MEETING_REQUIRED_EVENTS,
|
|
15882
16080
|
requiredScopes: MEETING_REQUIRED_SCOPES
|
|
15883
16081
|
};
|
|
15884
|
-
if (!
|
|
16082
|
+
if (!isRecord5(payload)) {
|
|
15885
16083
|
return { ...base, status: "unknown", message: "\u65E0\u6CD5\u89E3\u6790 lark-cli \u8F93\u51FA" };
|
|
15886
16084
|
}
|
|
15887
16085
|
if (payload.ok === true) {
|
|
15888
16086
|
return { ...base, status: "ok", message: "\u5E94\u7528\u8EAB\u4EFD\u6743\u9650\u5DF2\u5C31\u7EEA" };
|
|
15889
16087
|
}
|
|
15890
|
-
const err =
|
|
16088
|
+
const err = isRecord5(payload.error) ? payload.error : {};
|
|
15891
16089
|
const code = typeof err.code === "number" ? err.code : void 0;
|
|
15892
16090
|
const subtype = typeof err.subtype === "string" ? err.subtype : "";
|
|
15893
16091
|
const message = typeof err.message === "string" ? err.message : "\u6743\u9650\u68C0\u67E5\u5931\u8D25";
|
|
@@ -16758,7 +16956,7 @@ async function route(req, res, deps, url) {
|
|
|
16758
16956
|
}
|
|
16759
16957
|
|
|
16760
16958
|
// src/bridge/session/store.ts
|
|
16761
|
-
import { readFile as
|
|
16959
|
+
import { readFile as readFile15 } from "fs/promises";
|
|
16762
16960
|
var SessionStore = class {
|
|
16763
16961
|
data = {};
|
|
16764
16962
|
saving = Promise.resolve();
|
|
@@ -16769,7 +16967,7 @@ var SessionStore = class {
|
|
|
16769
16967
|
}
|
|
16770
16968
|
async load() {
|
|
16771
16969
|
try {
|
|
16772
|
-
const text = await
|
|
16970
|
+
const text = await readFile15(this.path, "utf8");
|
|
16773
16971
|
const raw = JSON.parse(text);
|
|
16774
16972
|
this.data = {};
|
|
16775
16973
|
for (const [chatId, entry] of Object.entries(raw)) {
|
|
@@ -16882,7 +17080,7 @@ var SessionStore = class {
|
|
|
16882
17080
|
|
|
16883
17081
|
// src/bridge/session/catalog.ts
|
|
16884
17082
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
16885
|
-
import { open as open3, readFile as
|
|
17083
|
+
import { open as open3, readFile as readFile16, rename as rename5, mkdir as mkdir16 } from "fs/promises";
|
|
16886
17084
|
import { dirname as dirname19 } from "path";
|
|
16887
17085
|
var DEFAULT_MAX_ARCHIVED_AGE_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
16888
17086
|
var DEFAULT_MAX_ENTRIES_PER_SCOPE = 20;
|
|
@@ -16905,7 +17103,7 @@ var SessionCatalog = class {
|
|
|
16905
17103
|
}
|
|
16906
17104
|
async load() {
|
|
16907
17105
|
try {
|
|
16908
|
-
const raw = JSON.parse(await
|
|
17106
|
+
const raw = JSON.parse(await readFile16(this.path, "utf8"));
|
|
16909
17107
|
if (!Array.isArray(raw)) {
|
|
16910
17108
|
this.data.clear();
|
|
16911
17109
|
return;
|
|
@@ -17079,7 +17277,7 @@ function assertAgentIdentity(input) {
|
|
|
17079
17277
|
}
|
|
17080
17278
|
|
|
17081
17279
|
// src/bridge/workspace/store.ts
|
|
17082
|
-
import { readFile as
|
|
17280
|
+
import { readFile as readFile17 } from "fs/promises";
|
|
17083
17281
|
var WorkspaceStore = class {
|
|
17084
17282
|
data = { chats: {}, named: {} };
|
|
17085
17283
|
saving = Promise.resolve();
|
|
@@ -17089,7 +17287,7 @@ var WorkspaceStore = class {
|
|
|
17089
17287
|
}
|
|
17090
17288
|
async load() {
|
|
17091
17289
|
try {
|
|
17092
|
-
const text = await
|
|
17290
|
+
const text = await readFile17(this.path, "utf8");
|
|
17093
17291
|
const parsed = JSON.parse(text);
|
|
17094
17292
|
this.data = {
|
|
17095
17293
|
chats: parsed.chats ?? {},
|