aai-lark-bridge 0.2.11 → 0.2.13
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/bin/aai-user-read.mjs +92 -0
- package/dist/cli.js +203 -33
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// aai-user-read:agent 用提问人的身份只读(intent 0046)。凭 bridge 给的句柄请求边车网关,
|
|
3
|
+
// 句柄和网关地址从环境变量来(AAI_USER_READ_HANDLE、AAI_USER_READ_GATEWAY),令牌只在网关里。
|
|
4
|
+
// 输出网关返回的 JSON;退出码:0 成功,2 用法不对,3 句柄过期或没有,1 其他失败。
|
|
5
|
+
// 不依赖 dist,零依赖,方便单测直接跑。
|
|
6
|
+
|
|
7
|
+
const SUBCOMMANDS = {
|
|
8
|
+
'search-messages': { '--query': 'query', '--page-size': 'pageSize', '--page-token': 'pageToken' },
|
|
9
|
+
'get-message': { '--message-id': 'messageId' },
|
|
10
|
+
'list-chat-messages': { '--chat-id': 'chatId', '--page-size': 'pageSize', '--page-token': 'pageToken', '--sort': 'sortType' },
|
|
11
|
+
'search-docs': { '--query': 'query', '--page-size': 'pageSize', '--page-token': 'pageToken' },
|
|
12
|
+
'fetch-doc': { '--doc': 'doc' },
|
|
13
|
+
};
|
|
14
|
+
const SORT = { asc: 'ByCreateTimeAsc', desc: 'ByCreateTimeDesc' };
|
|
15
|
+
|
|
16
|
+
const USAGE = `用法:aai-user-read <子命令> [参数]
|
|
17
|
+
search-messages --query <关键词> [--page-size N] [--page-token T]
|
|
18
|
+
get-message --message-id om_xxx
|
|
19
|
+
list-chat-messages --chat-id oc_xxx [--page-size N] [--page-token T] [--sort asc|desc]
|
|
20
|
+
search-docs --query <关键词> [--page-size N] [--page-token T]
|
|
21
|
+
fetch-doc --doc <文档链接或 token>`;
|
|
22
|
+
|
|
23
|
+
export function parseArgs(argv) {
|
|
24
|
+
const [sub, ...rest] = argv;
|
|
25
|
+
const flags = SUBCOMMANDS[sub];
|
|
26
|
+
if (!flags) throw new Error(sub ? `不认识的子命令:${sub}` : '缺子命令');
|
|
27
|
+
const body = {};
|
|
28
|
+
for (let i = 0; i < rest.length; i++) {
|
|
29
|
+
let flag = rest[i];
|
|
30
|
+
let value;
|
|
31
|
+
const eq = flag.indexOf('=');
|
|
32
|
+
if (flag.startsWith('--') && eq !== -1) {
|
|
33
|
+
value = flag.slice(eq + 1);
|
|
34
|
+
flag = flag.slice(0, eq);
|
|
35
|
+
} else {
|
|
36
|
+
value = rest[++i];
|
|
37
|
+
}
|
|
38
|
+
const key = flags[flag];
|
|
39
|
+
if (!key) throw new Error(`${sub} 不认识参数 ${flag}`);
|
|
40
|
+
if (value === undefined) throw new Error(`${flag} 缺值`);
|
|
41
|
+
if (key === 'pageSize') {
|
|
42
|
+
const n = Number(value);
|
|
43
|
+
if (!Number.isInteger(n)) throw new Error('--page-size 要是整数');
|
|
44
|
+
body.pageSize = n;
|
|
45
|
+
} else if (key === 'sortType') {
|
|
46
|
+
if (!SORT[value]) throw new Error('--sort 只能是 asc 或 desc');
|
|
47
|
+
body.sortType = SORT[value];
|
|
48
|
+
} else {
|
|
49
|
+
body[key] = value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const required = { 'search-messages': 'query', 'get-message': 'messageId', 'list-chat-messages': 'chatId', 'search-docs': 'query', 'fetch-doc': 'doc' }[sub];
|
|
53
|
+
if (body[required] === undefined) throw new Error(`${sub} 要带 ${Object.keys(flags).find((f) => flags[f] === required)}`);
|
|
54
|
+
return { api: sub, body };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function main(argv = process.argv.slice(2), env = process.env, doFetch = fetch) {
|
|
58
|
+
let req;
|
|
59
|
+
try {
|
|
60
|
+
req = parseArgs(argv);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
process.stderr.write(`${err.message}\n${USAGE}\n`);
|
|
63
|
+
return 2;
|
|
64
|
+
}
|
|
65
|
+
const handle = env.AAI_USER_READ_HANDLE;
|
|
66
|
+
const gateway = env.AAI_USER_READ_GATEWAY;
|
|
67
|
+
if (!handle || !gateway) {
|
|
68
|
+
process.stdout.write(`${JSON.stringify({ status: 'expired', detail: '这一轮没有提问人的读权限' })}\n`);
|
|
69
|
+
return 3;
|
|
70
|
+
}
|
|
71
|
+
let res;
|
|
72
|
+
try {
|
|
73
|
+
res = await doFetch(`${gateway.replace(/\/+$/, '')}/read/${req.api}`, {
|
|
74
|
+
method: 'POST',
|
|
75
|
+
headers: { 'content-type': 'application/json', authorization: `Bearer ${handle}` },
|
|
76
|
+
body: JSON.stringify(req.body),
|
|
77
|
+
signal: AbortSignal.timeout(90_000),
|
|
78
|
+
});
|
|
79
|
+
} catch (err) {
|
|
80
|
+
process.stdout.write(`${JSON.stringify({ status: 'gateway_unreachable', detail: String(err?.message ?? err) })}\n`);
|
|
81
|
+
return 1;
|
|
82
|
+
}
|
|
83
|
+
const json = await res.json().catch(() => ({ status: 'bad_response', code: res.status }));
|
|
84
|
+
process.stdout.write(`${JSON.stringify(json)}\n`);
|
|
85
|
+
if (json.status === 'ok') return 0;
|
|
86
|
+
return json.status === 'expired' ? 3 : 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const self = new URL(import.meta.url).pathname;
|
|
90
|
+
if (process.argv[1] && (await import('node:fs')).realpathSync(process.argv[1]) === (await import('node:fs')).realpathSync(self)) {
|
|
91
|
+
process.exitCode = await main();
|
|
92
|
+
}
|
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.13",
|
|
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",
|
|
@@ -62,7 +62,8 @@ var package_default = {
|
|
|
62
62
|
url: "https://gitlab.ariseai.co.th/ariseai/ai-infra"
|
|
63
63
|
},
|
|
64
64
|
bin: {
|
|
65
|
-
"aai-lark-bridge": "./bin/aai-lark-bridge.mjs"
|
|
65
|
+
"aai-lark-bridge": "./bin/aai-lark-bridge.mjs",
|
|
66
|
+
"aai-user-read": "./bin/aai-user-read.mjs"
|
|
66
67
|
}
|
|
67
68
|
};
|
|
68
69
|
|
|
@@ -551,7 +552,7 @@ function normalizeProfileConfig(input) {
|
|
|
551
552
|
const workspaces = normalizeWorkspaces(raw.workspaces);
|
|
552
553
|
const comments = normalizeComments(raw.comments);
|
|
553
554
|
const meeting = normalizeMeeting(raw.meeting);
|
|
554
|
-
const larkCli = normalizeLarkCli(raw.larkCli);
|
|
555
|
+
const larkCli = normalizeLarkCli(raw.larkCli, raw.agentKind);
|
|
555
556
|
return {
|
|
556
557
|
schemaVersion: 2,
|
|
557
558
|
agentKind: raw.agentKind,
|
|
@@ -688,18 +689,35 @@ function clampNumber(value, min, max, fallback) {
|
|
|
688
689
|
if (!Number.isFinite(n)) return fallback;
|
|
689
690
|
return Math.min(max, Math.max(min, Math.floor(n)));
|
|
690
691
|
}
|
|
691
|
-
function normalizeLarkCli(input) {
|
|
692
|
+
function normalizeLarkCli(input, agentKind) {
|
|
692
693
|
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
693
694
|
return { identityPreset: "bot-only" };
|
|
694
695
|
}
|
|
695
696
|
const raw = input;
|
|
696
697
|
const identityPreset = raw.identityPreset === "user-default" ? "user-default" : "bot-only";
|
|
697
698
|
const localUserImport = normalizeLarkCliUserImport(raw.localUserImport);
|
|
699
|
+
const perSenderUser = normalizePerSenderUser(raw.perSenderUser, agentKind);
|
|
698
700
|
return {
|
|
699
701
|
identityPreset,
|
|
700
|
-
...localUserImport ? { localUserImport } : {}
|
|
702
|
+
...localUserImport ? { localUserImport } : {},
|
|
703
|
+
...perSenderUser ? { perSenderUser } : {}
|
|
701
704
|
};
|
|
702
705
|
}
|
|
706
|
+
function normalizePerSenderUser(input, agentKind) {
|
|
707
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return void 0;
|
|
708
|
+
const raw = input;
|
|
709
|
+
if (raw.enabled !== true) {
|
|
710
|
+
return raw.enabled === false ? { enabled: false, gatewayUrl: String(raw.gatewayUrl ?? ""), tokenCommand: String(raw.tokenCommand ?? "") } : void 0;
|
|
711
|
+
}
|
|
712
|
+
if (agentKind !== "claude") throw new Error("larkCli.perSenderUser \u53EA\u652F\u6301 claude profile");
|
|
713
|
+
if (typeof raw.gatewayUrl !== "string" || !/^https?:\/\/[^\s]+$/.test(raw.gatewayUrl)) {
|
|
714
|
+
throw new Error("larkCli.perSenderUser.gatewayUrl \u8981\u662F http(s) \u5730\u5740");
|
|
715
|
+
}
|
|
716
|
+
if (typeof raw.tokenCommand !== "string" || !raw.tokenCommand.trim()) {
|
|
717
|
+
throw new Error("larkCli.perSenderUser.tokenCommand \u4E0D\u80FD\u4E3A\u7A7A");
|
|
718
|
+
}
|
|
719
|
+
return { enabled: true, gatewayUrl: raw.gatewayUrl.replace(/\/+$/, ""), tokenCommand: raw.tokenCommand };
|
|
720
|
+
}
|
|
703
721
|
function normalizeLarkCliUserImport(input) {
|
|
704
722
|
if (!input || typeof input !== "object" || Array.isArray(input)) return void 0;
|
|
705
723
|
const raw = input;
|
|
@@ -5429,9 +5447,12 @@ async function persistLarkCliConfig(opts, update) {
|
|
|
5429
5447
|
...update.importStatus === "imported" ? { importedAt: now } : {},
|
|
5430
5448
|
reason: update.reason
|
|
5431
5449
|
};
|
|
5450
|
+
const perSenderUser = opts.profileConfig?.larkCli.perSenderUser;
|
|
5432
5451
|
const nextLarkCli = {
|
|
5433
5452
|
identityPreset: update.identityPreset,
|
|
5434
|
-
localUserImport
|
|
5453
|
+
localUserImport,
|
|
5454
|
+
// 按提问人只读的开关原样留着(intent 0046)
|
|
5455
|
+
...perSenderUser ? { perSenderUser } : {}
|
|
5435
5456
|
};
|
|
5436
5457
|
let persistAttempted = false;
|
|
5437
5458
|
let saveSucceeded = false;
|
|
@@ -6342,9 +6363,7 @@ var ClaudeAdapter = class {
|
|
|
6342
6363
|
const bridgePrompt = buildBridgeSystemPrompt(this.botIdentity);
|
|
6343
6364
|
const extraPrompt = opts.extraSystemPromptFile ? readFileSync2(opts.extraSystemPromptFile, "utf8") : "";
|
|
6344
6365
|
const systemPromptFile = writeSystemPromptFile(
|
|
6345
|
-
extraPrompt.
|
|
6346
|
-
|
|
6347
|
-
${extraPrompt}` : bridgePrompt
|
|
6366
|
+
[bridgePrompt, extraPrompt].filter((p3) => p3.trim()).join("\n\n")
|
|
6348
6367
|
);
|
|
6349
6368
|
const args = [
|
|
6350
6369
|
"-p",
|
|
@@ -6365,7 +6384,7 @@ ${extraPrompt}` : bridgePrompt
|
|
|
6365
6384
|
try {
|
|
6366
6385
|
child = spawnProcess(this.binary, args, {
|
|
6367
6386
|
cwd: opts.cwd,
|
|
6368
|
-
env: mergeProcessEnv(process.env, buildLarkChannelEnv(this.larkChannel)),
|
|
6387
|
+
env: mergeProcessEnv(process.env, { ...buildLarkChannelEnv(this.larkChannel), ...opts.extraEnv }),
|
|
6369
6388
|
stdio: ["pipe", "pipe", "pipe"]
|
|
6370
6389
|
});
|
|
6371
6390
|
} catch (err) {
|
|
@@ -7469,8 +7488,103 @@ function taskRunHooks(input) {
|
|
|
7469
7488
|
};
|
|
7470
7489
|
}
|
|
7471
7490
|
|
|
7472
|
-
// src/bridge/
|
|
7491
|
+
// src/bridge/bot/user-read.ts
|
|
7492
|
+
import { spawnSync as spawnSync4 } from "child_process";
|
|
7473
7493
|
import { randomUUID } from "crypto";
|
|
7494
|
+
var HANDLE_ENV = "AAI_USER_READ_HANDLE";
|
|
7495
|
+
var GATEWAY_ENV = "AAI_USER_READ_GATEWAY";
|
|
7496
|
+
var REVOKE_TEXT = "\u64A4\u9500\u6388\u6743";
|
|
7497
|
+
var TIMEOUT_MS = 15e3;
|
|
7498
|
+
function readTokenByCommand(command) {
|
|
7499
|
+
const [bin, ...args] = command.trim().split(/\s+/);
|
|
7500
|
+
if (!bin) throw new Error("tokenCommand \u4E3A\u7A7A");
|
|
7501
|
+
const r = spawnSync4(bin, args, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 15e3 });
|
|
7502
|
+
const value = r.status === 0 ? r.stdout.trim() : "";
|
|
7503
|
+
if (!value) throw new Error(`\u53D6\u7F51\u5173\u53E3\u4EE4\u5931\u8D25\uFF08${bin} \u9000\u51FA\u7801 ${r.status}\uFF09`);
|
|
7504
|
+
return value;
|
|
7505
|
+
}
|
|
7506
|
+
async function callGateway(cfg, method, path, body, deps) {
|
|
7507
|
+
const doFetch = deps.fetch ?? fetch;
|
|
7508
|
+
const pass = (deps.readToken ?? readTokenByCommand)(cfg.tokenCommand);
|
|
7509
|
+
const res = await doFetch(`${cfg.gatewayUrl}${path}`, {
|
|
7510
|
+
method,
|
|
7511
|
+
headers: { "content-type": "application/json", "x-gateway-token": pass },
|
|
7512
|
+
...body === void 0 ? {} : { body: JSON.stringify(body) },
|
|
7513
|
+
signal: AbortSignal.timeout(TIMEOUT_MS)
|
|
7514
|
+
});
|
|
7515
|
+
const json = await res.json().catch(() => ({}));
|
|
7516
|
+
if (!res.ok) throw new Error(`\u7F51\u5173\u8FD4\u56DE ${res.status} ${String(json.status ?? "")}`);
|
|
7517
|
+
return json;
|
|
7518
|
+
}
|
|
7519
|
+
var PROMPT_TOOL = `## \u7528\u63D0\u95EE\u4EBA\u7684\u8EAB\u4EFD\u53EA\u8BFB\uFF08aai-user-read\uFF09
|
|
7520
|
+
|
|
7521
|
+
\u8FD9\u4E00\u8F6E\u63D0\u95EE\u4EBA\u5DF2\u6388\u6743\uFF0C\u4F60\u53EF\u4EE5\u7528 \`aai-user-read\` \u4EE5\u4ED6\u7684\u8EAB\u4EFD**\u53EA\u8BFB**\u4ED6\u80FD\u770B\u5230\u7684\u6D88\u606F\u548C\u6587\u6863\u3002\u8FD9\u662F\u8BFB\u4ED6\u4E2A\u4EBA\u6570\u636E\u7684\u552F\u4E00\u9014\u5F84\uFF0C\u522B\u7528 \`lark-cli --as user\`\uFF0C\u4E5F\u522B\u8DD1 \`lark-cli auth login\`\u3002
|
|
7522
|
+
|
|
7523
|
+
- \`aai-user-read search-messages --query <\u5173\u952E\u8BCD> [--page-size N] [--page-token T]\`\uFF1A\u641C\u4ED6\u7684\u6D88\u606F
|
|
7524
|
+
- \`aai-user-read get-message --message-id om_xxx\`\uFF1A\u53D6\u4E00\u6761\u6D88\u606F\u5168\u6587
|
|
7525
|
+
- \`aai-user-read list-chat-messages --chat-id oc_xxx [--page-size N] [--page-token T] [--sort asc|desc]\`\uFF1A\u62C9\u4E00\u4E2A\u4F1A\u8BDD\u7684\u5386\u53F2
|
|
7526
|
+
- \`aai-user-read search-docs --query <\u5173\u952E\u8BCD> [--page-size N] [--page-token T]\`\uFF1A\u641C\u4ED6\u80FD\u770B\u7684\u6587\u6863
|
|
7527
|
+
- \`aai-user-read fetch-doc --doc <\u6587\u6863\u94FE\u63A5\u6216 token>\`\uFF1A\u8BFB\u6587\u6863\u6B63\u6587
|
|
7528
|
+
|
|
7529
|
+
\u8F93\u51FA\u662F JSON\u3002\u53EA\u5728\u56DE\u7B54\u4ED6\u7684\u95EE\u9898\u9700\u8981\u65F6\u8BFB\uFF0C\u8BFB\u5230\u7684\u5185\u5BB9\u53EA\u7528\u6765\u56DE\u7B54\u8FD9\u4E2A\u4EBA\uFF0C\u522B\u8F6C\u8FF0\u5230\u522B\u5904\u3002\u8FD4\u56DE expired \u8BF4\u660E\u8FD9\u4E00\u8F6E\u7684\u6388\u6743\u5DF2\u8FC7\u671F\uFF0C\u544A\u8BC9\u4ED6\u91CD\u65B0\u53D1\u4E00\u6B21\u95EE\u9898\u3002
|
|
7530
|
+
|
|
7531
|
+
\u6388\u6743\u72B6\u6001\u4EE5\u8FD9\u4E00\u8F6E\u8FD9\u6BB5\u8BF4\u660E\u4E3A\u51C6\uFF1A\u5BF9\u8BDD\u91CC\u66F4\u65E9\u8BF4\u8FC7\u7684\u300C\u8FD8\u6CA1\u6388\u6743\u300D\u300C\u8BF7\u70B9\u6388\u6743\u5361\u7247\u300D\u90FD\u5DF2\u8FC7\u65F6\u3002\u9700\u8981\u8BFB\u4ED6\u7684\u6570\u636E\u65F6\u76F4\u63A5\u8DD1 \`aai-user-read\`\uFF0C\u4EE5\u5B83\u7684\u8FD4\u56DE\u4E3A\u51C6\uFF0C\u4E0D\u8981\u5148\u7528 \`lark-cli auth status\` \u4E4B\u7C7B\u7684\u547D\u4EE4\u786E\u8BA4\u6388\u6743\u3002`;
|
|
7532
|
+
var PROMPT_NEED_AUTH = `## \u63D0\u95EE\u4EBA\u8FD8\u6CA1\u6388\u6743\u53EA\u8BFB
|
|
7533
|
+
|
|
7534
|
+
\u4ED6\u8FD8\u6CA1\u6388\u6743\u4F60\u7528\u4ED6\u7684\u8EAB\u4EFD\u8BFB\u6D88\u606F\u548C\u6587\u6863\u3002\u4F60\u5DF2\u7ECF\u5728\u4ED6\u7684\u79C1\u804A\u91CC\u6536\u5230\u4E00\u5F20\u300C\u6388\u6743 bot \u7528\u4F60\u7684\u8EAB\u4EFD\u53EA\u8BFB\u300D\u7684\u5361\u7247\uFF08\u7531\u7CFB\u7EDF\u53D1\u51FA\uFF09\u3002\u8FD9\u4E00\u8F6E\u7528\u5E94\u7528\u8EAB\u4EFD\u5C3D\u91CF\u56DE\u7B54\uFF1B\u5982\u679C\u95EE\u9898\u9700\u8981\u8BFB\u4ED6\u81EA\u5DF1\u7684\u6D88\u606F\u6216\u6587\u6863\uFF0C\u544A\u8BC9\u4ED6\u70B9\u90A3\u5F20\u5361\u7247\u6388\u6743\uFF0C\u6388\u6743\u540E\u91CD\u65B0\u53D1\u4E00\u6B21\u95EE\u9898\u3002\u4E0D\u8981\u81EA\u5DF1\u8DD1 \`lark-cli auth login\`\u3002`;
|
|
7535
|
+
var PROMPT_AUTH_FAILED = `## \u53EA\u8BFB\u6388\u6743\u6682\u65F6\u53D1\u4E0D\u51FA
|
|
7536
|
+
|
|
7537
|
+
\u4ED6\u8FD8\u6CA1\u6388\u6743\u7528\u4ED6\u7684\u8EAB\u4EFD\u8BFB\u6570\u636E\uFF0C\u800C\u4E14\u8FD9\u6B21\u6388\u6743\u5361\u7247\u6CA1\u53D1\u51FA\u53BB\u3002\u8FD9\u4E00\u8F6E\u7528\u5E94\u7528\u8EAB\u4EFD\u5C3D\u91CF\u56DE\u7B54\uFF1B\u5982\u679C\u95EE\u9898\u9700\u8981\u8BFB\u4ED6\u81EA\u5DF1\u7684\u6D88\u606F\u6216\u6587\u6863\uFF0C\u544A\u8BC9\u4ED6\u6388\u6743\u6682\u65F6\u53D1\u4E0D\u51FA\uFF0C\u7A0D\u540E\u518D\u95EE\u4E00\u6B21\u3002\u4E0D\u8981\u81EA\u5DF1\u8DD1 \`lark-cli auth login\`\u3002`;
|
|
7538
|
+
var PROMPT_UNAVAILABLE = `## \u8FD9\u4E00\u8F6E\u8BFB\u4E0D\u4E86\u63D0\u95EE\u4EBA\u7684\u6570\u636E
|
|
7539
|
+
|
|
7540
|
+
\u8FD9\u4E00\u8F6E\u6CA1\u62FF\u5230\u8BFB\u4ED6\u4E2A\u4EBA\u6570\u636E\u7684\u6743\u9650\uFF08\u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528\u6216\u8FD9\u6761\u6D88\u606F\u6CA1\u901A\u8FC7\u6838\u5B9E\uFF09\u3002\u7528\u5E94\u7528\u8EAB\u4EFD\u5C3D\u91CF\u56DE\u7B54\uFF1B\u5982\u679C\u95EE\u9898\u9700\u8981\u8BFB\u4ED6\u81EA\u5DF1\u7684\u6D88\u606F\u6216\u6587\u6863\uFF0C\u544A\u8BC9\u4ED6\u7A0D\u540E\u91CD\u65B0\u53D1\u4E00\u6B21\u3002\u4E0D\u8981\u81EA\u5DF1\u8DD1 \`lark-cli auth login\`\u3002`;
|
|
7541
|
+
async function requestUserRead(cfg, messageId, deps = {}) {
|
|
7542
|
+
const gatewayRunId = randomUUID();
|
|
7543
|
+
try {
|
|
7544
|
+
const r = await callGateway(cfg, "POST", "/handles", { messageId, runId: gatewayRunId }, deps);
|
|
7545
|
+
if (r.status === "ok" && typeof r.handle === "string") {
|
|
7546
|
+
log.info("user-read", "handle", { messageId, gatewayRunId });
|
|
7547
|
+
return {
|
|
7548
|
+
kind: "handle",
|
|
7549
|
+
gatewayRunId,
|
|
7550
|
+
env: { [HANDLE_ENV]: r.handle, [GATEWAY_ENV]: cfg.gatewayUrl },
|
|
7551
|
+
prompt: PROMPT_TOOL
|
|
7552
|
+
};
|
|
7553
|
+
}
|
|
7554
|
+
log.info("user-read", "no-handle", { messageId, status: String(r.status) });
|
|
7555
|
+
if (r.status === "need_auth") return { kind: "need_auth", prompt: PROMPT_NEED_AUTH };
|
|
7556
|
+
if (r.status === "auth_failed") return { kind: "auth_failed", prompt: PROMPT_AUTH_FAILED };
|
|
7557
|
+
return { kind: "unavailable", prompt: PROMPT_UNAVAILABLE };
|
|
7558
|
+
} catch (err) {
|
|
7559
|
+
log.warn("user-read", "gateway-failed", { messageId, step: "handle", detail: String(err) });
|
|
7560
|
+
return { kind: "unavailable", prompt: PROMPT_UNAVAILABLE };
|
|
7561
|
+
}
|
|
7562
|
+
}
|
|
7563
|
+
async function dropUserRead(cfg, gatewayRunId, deps = {}) {
|
|
7564
|
+
try {
|
|
7565
|
+
await callGateway(cfg, "DELETE", `/handles/${encodeURIComponent(gatewayRunId)}`, void 0, deps);
|
|
7566
|
+
} catch (err) {
|
|
7567
|
+
log.warn("user-read", "gateway-failed", { gatewayRunId, step: "drop", detail: String(err) });
|
|
7568
|
+
}
|
|
7569
|
+
}
|
|
7570
|
+
function isRevokeRequest(text) {
|
|
7571
|
+
return text.trim() === REVOKE_TEXT;
|
|
7572
|
+
}
|
|
7573
|
+
async function revokeUserRead(cfg, messageId, deps = {}) {
|
|
7574
|
+
try {
|
|
7575
|
+
const r = await callGateway(cfg, "POST", "/revoke", { messageId }, deps);
|
|
7576
|
+
log.info("user-read", "revoke", { messageId, status: String(r.status) });
|
|
7577
|
+
if (r.status === "revoked") return "\u5DF2\u64A4\u9500\uFF1Abot \u4E0D\u80FD\u518D\u7528\u4F60\u7684\u8EAB\u4EFD\u8BFB\u4F60\u7684\u6D88\u606F\u548C\u6587\u6863\u4E86\u3002\u4EE5\u540E\u9700\u8981\u65F6\u518D\u79C1\u804A\u63D0\u95EE\uFF0C\u4F1A\u91CD\u65B0\u7ED9\u4F60\u53D1\u6388\u6743\u5361\u7247\u3002";
|
|
7578
|
+
if (r.status === "not_authorized") return "\u4F60\u8FD8\u6CA1\u6709\u6388\u6743\u8FC7\uFF0C\u4E0D\u7528\u64A4\u9500\u3002";
|
|
7579
|
+
return "\u8FD9\u6B21\u6CA1\u80FD\u64A4\u9500\uFF0C\u8BF7\u7A0D\u540E\u518D\u53D1\u4E00\u6B21\u300C\u64A4\u9500\u6388\u6743\u300D\u3002";
|
|
7580
|
+
} catch (err) {
|
|
7581
|
+
log.warn("user-read", "gateway-failed", { messageId, step: "revoke", detail: String(err) });
|
|
7582
|
+
return "\u8FD9\u6B21\u6CA1\u80FD\u64A4\u9500\uFF0C\u8BF7\u7A0D\u540E\u518D\u53D1\u4E00\u6B21\u300C\u64A4\u9500\u6388\u6743\u300D\u3002";
|
|
7583
|
+
}
|
|
7584
|
+
}
|
|
7585
|
+
|
|
7586
|
+
// src/bridge/commands/index.ts
|
|
7587
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
7474
7588
|
import { readFile as readFile12 } from "fs/promises";
|
|
7475
7589
|
import { homedir as homedir6 } from "os";
|
|
7476
7590
|
import { dirname as dirname17, isAbsolute as isAbsolute3 } from "path";
|
|
@@ -8414,7 +8528,9 @@ async function savePreferencesConfig(state, preferences, requireMentionInGroup,
|
|
|
8414
8528
|
status: "not-needed",
|
|
8415
8529
|
attemptedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8416
8530
|
reason: larkCliIdentity === "user-default" ? "manual-user-default" : "manual-bot-only"
|
|
8417
|
-
}
|
|
8531
|
+
},
|
|
8532
|
+
// 按提问人只读的开关不归这个设置页管,原样留着(intent 0046)
|
|
8533
|
+
...state.profileConfig.larkCli.perSenderUser ? { perSenderUser: state.profileConfig.larkCli.perSenderUser } : {}
|
|
8418
8534
|
};
|
|
8419
8535
|
await withConfigFileLock(state.configPath, async () => {
|
|
8420
8536
|
const root = await loadRootConfig(state.configPath);
|
|
@@ -10042,6 +10158,7 @@ ${runPolicy.prompt}` } : {}
|
|
|
10042
10158
|
// 绑定任务的私聊只按任务剩余额度(2026-10-16 河英定,不再和每次运行上限取小)。
|
|
10043
10159
|
...input.capability.agentId === "claude" ? { maxBudgetUsd: input.task ? input.task.maxBudgetUsd : getMaxRunBudgetUsd(input.profileConfig.preferences) } : {},
|
|
10044
10160
|
...binding ? { settingsFile: binding.settingsFile, extraSystemPromptFile: binding.systemPromptFile, strictMcp: true } : {},
|
|
10161
|
+
...input.extraEnv ? { extraEnv: input.extraEnv } : {},
|
|
10045
10162
|
observability: input.observability
|
|
10046
10163
|
});
|
|
10047
10164
|
} catch (err) {
|
|
@@ -10742,8 +10859,8 @@ async function applyResume(sessionId, ctx) {
|
|
|
10742
10859
|
}
|
|
10743
10860
|
function issueResumeCandidate(identity, target) {
|
|
10744
10861
|
pruneResumeCandidates();
|
|
10745
|
-
let nonce =
|
|
10746
|
-
while (resumeCandidates.has(nonce)) nonce =
|
|
10862
|
+
let nonce = randomUUID2().slice(0, 12);
|
|
10863
|
+
while (resumeCandidates.has(nonce)) nonce = randomUUID2().slice(0, 12);
|
|
10747
10864
|
resumeCandidates.set(nonce, {
|
|
10748
10865
|
scopeId: identity.scopeId,
|
|
10749
10866
|
agentId: identity.agentId,
|
|
@@ -12841,7 +12958,7 @@ async function fetchOwnerId(source) {
|
|
|
12841
12958
|
}
|
|
12842
12959
|
|
|
12843
12960
|
// src/bridge/runtime/run-executor.ts
|
|
12844
|
-
import { randomUUID as
|
|
12961
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
12845
12962
|
|
|
12846
12963
|
// src/bridge/bot/active-runs.ts
|
|
12847
12964
|
var ActiveRuns = class {
|
|
@@ -12990,7 +13107,7 @@ var RunExecutor = class {
|
|
|
12990
13107
|
this.agent = deps.agent;
|
|
12991
13108
|
this.pool = deps.pool;
|
|
12992
13109
|
this.activeRuns = deps.activeRuns;
|
|
12993
|
-
this.createRunId = deps.createRunId ??
|
|
13110
|
+
this.createRunId = deps.createRunId ?? randomUUID3;
|
|
12994
13111
|
this.now = deps.now ?? Date.now;
|
|
12995
13112
|
this.postDoneExitGraceMs = deps.postDoneExitGraceMs ?? DEFAULT_POST_DONE_EXIT_GRACE_MS;
|
|
12996
13113
|
}
|
|
@@ -13039,7 +13156,8 @@ var RunExecutor = class {
|
|
|
13039
13156
|
...input.maxBudgetUsd !== void 0 ? { maxBudgetUsd: input.maxBudgetUsd } : {},
|
|
13040
13157
|
...input.settingsFile ? { settingsFile: input.settingsFile } : {},
|
|
13041
13158
|
...input.extraSystemPromptFile ? { extraSystemPromptFile: input.extraSystemPromptFile } : {},
|
|
13042
|
-
...input.strictMcp ? { strictMcp: true } : {}
|
|
13159
|
+
...input.strictMcp ? { strictMcp: true } : {},
|
|
13160
|
+
...input.extraEnv ? { extraEnv: input.extraEnv } : {}
|
|
13043
13161
|
};
|
|
13044
13162
|
let run;
|
|
13045
13163
|
try {
|
|
@@ -13259,7 +13377,7 @@ var ChatModeCache = class {
|
|
|
13259
13377
|
};
|
|
13260
13378
|
|
|
13261
13379
|
// src/bridge/bot/comments.ts
|
|
13262
|
-
import { randomUUID as
|
|
13380
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
13263
13381
|
import { mkdir as mkdir15 } from "fs/promises";
|
|
13264
13382
|
import { dirname as dirname18 } from "path";
|
|
13265
13383
|
|
|
@@ -13656,7 +13774,7 @@ function commentRunRejectedReply(code) {
|
|
|
13656
13774
|
}
|
|
13657
13775
|
}
|
|
13658
13776
|
function commentExecutionScopeId(commentThreadScopeId) {
|
|
13659
|
-
return `${commentThreadScopeId}:${
|
|
13777
|
+
return `${commentThreadScopeId}:${randomUUID4().slice(0, 12)}`;
|
|
13660
13778
|
}
|
|
13661
13779
|
function commentDocumentSessionScopeId(fileToken) {
|
|
13662
13780
|
return `doc:${commentTokenDigest(fileToken)}`;
|
|
@@ -15410,6 +15528,31 @@ function spawnFailedReply() {
|
|
|
15410
15528
|
return "\u26A0\uFE0F \u8FD9\u6761\u6D88\u606F\u6CA1\u6709\u4EA4\u7ED9 agent\uFF1Abridge \u6CA1\u80FD\u542F\u52A8 agent\u3002\u8BF7\u7A0D\u540E\u91CD\u53D1\uFF1B\u8FDE\u7EED\u5931\u8D25\u8BF7\u8054\u7CFB bridge \u7BA1\u7406\u5458\u91CD\u542F bridge" + (traceId ? `\uFF0C\u5E76\u9644\u4E0A\u6392\u67E5\u7F16\u53F7 ${traceId}\u3002` : "\u3002");
|
|
15411
15529
|
}
|
|
15412
15530
|
async function runAgentBatch(deps) {
|
|
15531
|
+
const first = deps.batch[0];
|
|
15532
|
+
const last = deps.batch[deps.batch.length - 1];
|
|
15533
|
+
const cfg = deps.controls.profileConfig.larkCli.perSenderUser;
|
|
15534
|
+
if (!first || !last || first.chatType !== "p2p" || !cfg?.enabled || deps.controls.profileConfig.agentKind !== "claude") {
|
|
15535
|
+
return runAgentBatchInner(deps);
|
|
15536
|
+
}
|
|
15537
|
+
const preBinding = { result: dmBinding(deps.controls, first, deps.scope) };
|
|
15538
|
+
if (preBinding.result?.kind === "bound") return runAgentBatchInner({ ...deps, preBinding });
|
|
15539
|
+
if (deps.batch.length === 1 && isRevokeRequest(last.content)) {
|
|
15540
|
+
const text = await revokeUserRead(cfg, last.messageId);
|
|
15541
|
+
await deps.channel.send(first.chatId, { markdown: text }, { replyTo: last.messageId });
|
|
15542
|
+
return;
|
|
15543
|
+
}
|
|
15544
|
+
const outcome = await requestUserRead(cfg, last.messageId);
|
|
15545
|
+
try {
|
|
15546
|
+
await runAgentBatchInner({
|
|
15547
|
+
...deps,
|
|
15548
|
+
preBinding,
|
|
15549
|
+
userRead: { ...outcome.kind === "handle" ? { extraEnv: outcome.env } : {}, instruction: outcome.prompt }
|
|
15550
|
+
});
|
|
15551
|
+
} finally {
|
|
15552
|
+
if (outcome.kind === "handle") await dropUserRead(cfg, outcome.gatewayRunId);
|
|
15553
|
+
}
|
|
15554
|
+
}
|
|
15555
|
+
async function runAgentBatchInner(deps) {
|
|
15413
15556
|
const {
|
|
15414
15557
|
channel,
|
|
15415
15558
|
executor,
|
|
@@ -15432,7 +15575,7 @@ async function runAgentBatch(deps) {
|
|
|
15432
15575
|
if (!firstMsg || !lastMsg) return;
|
|
15433
15576
|
const chatId = firstMsg.chatId;
|
|
15434
15577
|
const threadId = firstMsg.threadId;
|
|
15435
|
-
const bindingResult = firstMsg.chatType === "p2p" ? dmBinding(controls, firstMsg, scope) : void 0;
|
|
15578
|
+
const bindingResult = deps.preBinding ? deps.preBinding.result : firstMsg.chatType === "p2p" ? dmBinding(controls, firstMsg, scope) : void 0;
|
|
15436
15579
|
const binding = bindingResult?.kind === "bound" ? bindingResult.binding : void 0;
|
|
15437
15580
|
const taskPlan = binding ? planTaskRun(binding) : void 0;
|
|
15438
15581
|
if (binding && taskPlan && !taskPlan.ok) {
|
|
@@ -15491,9 +15634,12 @@ async function runAgentBatch(deps) {
|
|
|
15491
15634
|
const prevModel = lastRunModelByScope.get(scope);
|
|
15492
15635
|
const modelSwitched = prevModel !== void 0 && prevModel !== modelSelection;
|
|
15493
15636
|
lastRunModelByScope.set(scope, modelSelection);
|
|
15494
|
-
const extraInstructions =
|
|
15495
|
-
|
|
15496
|
-
|
|
15637
|
+
const extraInstructions = [
|
|
15638
|
+
...modelSwitched ? [
|
|
15639
|
+
`\u7528\u6237\u521A\u628A\u672C\u4F1A\u8BDD\u4F7F\u7528\u7684\u6A21\u578B\u5207\u6362\u4E3A\u300C${modelLabel(agentKind, modelPref)}\u300D\u3002\u4E4B\u524D\u7684\u5BF9\u8BDD\u91CC\u53EF\u80FD\u63D0\u5230\u522B\u7684\u6A21\u578B,\u8BF7\u4EE5\u5F53\u524D\u6A21\u578B\u4E3A\u51C6;\u82E5\u88AB\u95EE\u5230\u4F60\u7528\u7684\u662F\u4EC0\u4E48\u6A21\u578B,\u636E\u6B64\u56DE\u7B54\u3002`
|
|
15640
|
+
] : [],
|
|
15641
|
+
...deps.userRead ? [deps.userRead.instruction] : []
|
|
15642
|
+
];
|
|
15497
15643
|
const prompt = buildPrompt(
|
|
15498
15644
|
batch,
|
|
15499
15645
|
attachments,
|
|
@@ -15548,6 +15694,7 @@ async function runAgentBatch(deps) {
|
|
|
15548
15694
|
now: Date.now(),
|
|
15549
15695
|
stopGraceMs: getAgentStopGraceMs(controls.cfg),
|
|
15550
15696
|
...binding && taskPlan?.ok ? { task: { binding, maxBudgetUsd: taskPlan.maxBudgetUsd } } : {},
|
|
15697
|
+
...deps.userRead?.extraEnv ? { extraEnv: deps.userRead.extraEnv } : {},
|
|
15551
15698
|
observability: {
|
|
15552
15699
|
profile: controls.profile,
|
|
15553
15700
|
agent: capability.agentId,
|
|
@@ -17781,7 +17928,7 @@ var SessionStore = class {
|
|
|
17781
17928
|
};
|
|
17782
17929
|
|
|
17783
17930
|
// src/bridge/session/catalog.ts
|
|
17784
|
-
import { randomUUID as
|
|
17931
|
+
import { randomUUID as randomUUID5 } from "crypto";
|
|
17785
17932
|
import { open as open3, readFile as readFile16, rename as rename5, mkdir as mkdir16 } from "fs/promises";
|
|
17786
17933
|
import { dirname as dirname20 } from "path";
|
|
17787
17934
|
var DEFAULT_MAX_ARCHIVED_AGE_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
@@ -17939,7 +18086,7 @@ var SessionCatalog = class {
|
|
|
17939
18086
|
}
|
|
17940
18087
|
async persist() {
|
|
17941
18088
|
await mkdir16(dirname20(this.path), { recursive: true });
|
|
17942
|
-
const tmp = `${this.path}.${process.pid}.${Date.now()}.${
|
|
18089
|
+
const tmp = `${this.path}.${process.pid}.${Date.now()}.${randomUUID5()}.tmp`;
|
|
17943
18090
|
const payload = `${JSON.stringify(this.entries(), null, 2)}
|
|
17944
18091
|
`;
|
|
17945
18092
|
const fh = await open3(tmp, "w", 384);
|
|
@@ -18680,7 +18827,7 @@ function openBrowser(url) {
|
|
|
18680
18827
|
}
|
|
18681
18828
|
|
|
18682
18829
|
// src/bridge/cli/commands/user-gateway.ts
|
|
18683
|
-
import { spawnSync as
|
|
18830
|
+
import { spawnSync as spawnSync5 } from "child_process";
|
|
18684
18831
|
import { existsSync as existsSync9 } from "fs";
|
|
18685
18832
|
import { join as join27 } from "path";
|
|
18686
18833
|
|
|
@@ -18707,7 +18854,7 @@ var CLOCK_SKEW_MS = 3e4;
|
|
|
18707
18854
|
var USED_TTL_MS = MESSAGE_MAX_AGE_MS + CLOCK_SKEW_MS + 6e4;
|
|
18708
18855
|
var AUTH_POLL_MS = 5e3;
|
|
18709
18856
|
var AUTH_MAX_MS = 10 * 6e4;
|
|
18710
|
-
var
|
|
18857
|
+
var REVOKE_TEXT2 = "\u64A4\u9500\u6388\u6743";
|
|
18711
18858
|
var MESSAGE_ID = /^om_[A-Za-z0-9_-]{1,100}$/;
|
|
18712
18859
|
var CHAT_ID = /^oc_[A-Za-z0-9_-]{1,100}$/;
|
|
18713
18860
|
var OPEN_ID = /^ou_[A-Za-z0-9_-]{1,100}$/;
|
|
@@ -18813,7 +18960,20 @@ function createGateway(opts) {
|
|
|
18813
18960
|
};
|
|
18814
18961
|
}
|
|
18815
18962
|
const appDir = join26(opts.stateDir, "app");
|
|
18816
|
-
const
|
|
18963
|
+
const bound2 = /* @__PURE__ */ new Set();
|
|
18964
|
+
async function ensureBound(dir, identity) {
|
|
18965
|
+
if (bound2.has(dir)) return;
|
|
18966
|
+
if (!existsSync8(join26(dir, "lark-channel", "config.json"))) {
|
|
18967
|
+
await mkdir18(dir, { recursive: true, mode: 448 });
|
|
18968
|
+
const r = await opts.exec(["config", "bind", "--source", "lark-channel", "--identity", identity], env(dir), 3e4);
|
|
18969
|
+
if (r.code !== 0) throw new Error(`lark-cli \u7ED1\u5B9A\u5931\u8D25\uFF1A${firstLine(r.stderr || r.stdout)}`);
|
|
18970
|
+
}
|
|
18971
|
+
bound2.add(dir);
|
|
18972
|
+
}
|
|
18973
|
+
const asApp = async (args, timeoutMs = 3e4) => {
|
|
18974
|
+
await ensureBound(appDir, "bot-only");
|
|
18975
|
+
return opts.exec(args, env(appDir), timeoutMs);
|
|
18976
|
+
};
|
|
18817
18977
|
function sweep() {
|
|
18818
18978
|
const t = now();
|
|
18819
18979
|
for (const [h, v] of handles) if (v.expiresAt <= t) handles.delete(h);
|
|
@@ -18828,6 +18988,9 @@ function createGateway(opts) {
|
|
|
18828
18988
|
inFlight.add(messageId);
|
|
18829
18989
|
try {
|
|
18830
18990
|
return await check2(messageId);
|
|
18991
|
+
} catch (err) {
|
|
18992
|
+
log.warn("user-gateway", "verify.failed", { messageId, detail: String(err) });
|
|
18993
|
+
return "lark_error";
|
|
18831
18994
|
} finally {
|
|
18832
18995
|
inFlight.delete(messageId);
|
|
18833
18996
|
}
|
|
@@ -18870,7 +19033,7 @@ function createGateway(opts) {
|
|
|
18870
19033
|
{
|
|
18871
19034
|
tag: "markdown",
|
|
18872
19035
|
content: `\u6388\u6743\u540E\uFF0C\u4F60\u79C1\u804A\u6211\u63D0\u95EE\u65F6\uFF0C\u6211\u53EF\u4EE5\u7528\u4F60\u7684\u8EAB\u4EFD**\u53EA\u8BFB**\u4F60\u7684\u6D88\u606F\u548C\u6587\u6863\uFF08\u641C\u6D88\u606F\u3001\u770B\u6D88\u606F\u3001\u770B\u4F1A\u8BDD\u5386\u53F2\u3001\u641C\u6587\u6863\u3001\u8BFB\u6587\u6863\uFF09\uFF0C\u4E0D\u80FD\u53D1\u6D88\u606F\u3001\u4E0D\u80FD\u6539\u6587\u6863\u3002
|
|
18873
|
-
\u94FE\u63A5 10 \u5206\u949F\u5185\u6709\u6548\u3002\u4E0D\u60F3\u7528\u4E86\uFF0C\u79C1\u804A\u6211\u53D1\u300C${
|
|
19036
|
+
\u94FE\u63A5 10 \u5206\u949F\u5185\u6709\u6548\u3002\u4E0D\u60F3\u7528\u4E86\uFF0C\u79C1\u804A\u6211\u53D1\u300C${REVOKE_TEXT2}\u300D\u3002`
|
|
18874
19037
|
},
|
|
18875
19038
|
{ tag: "action", actions: [{ tag: "button", type: "primary", text: { tag: "plain_text", content: "\u53BB\u6388\u6743" }, url }] }
|
|
18876
19039
|
]
|
|
@@ -18909,7 +19072,7 @@ function createGateway(opts) {
|
|
|
18909
19072
|
}
|
|
18910
19073
|
async function beginAuth(openId) {
|
|
18911
19074
|
const dir = userDir(openId);
|
|
18912
|
-
await
|
|
19075
|
+
await ensureBound(dir, "user-default");
|
|
18913
19076
|
const start = await opts.exec(
|
|
18914
19077
|
["auth", "login", "--no-wait", "--json", "--scope", USER_READ_SCOPES.join(" ")],
|
|
18915
19078
|
env(dir),
|
|
@@ -18994,8 +19157,14 @@ function createGateway(opts) {
|
|
|
18994
19157
|
} catch (err) {
|
|
18995
19158
|
return { status: "bad_request", detail: err instanceof BadRequest ? err.message : String(err) };
|
|
18996
19159
|
}
|
|
18997
|
-
const r = await opts.exec(args, env(userDir(h.openId)), 6e4);
|
|
18998
19160
|
const fields = { identity: "user", sender: tail6(h.openId), messageId: h.messageId, runId: h.runId, api };
|
|
19161
|
+
try {
|
|
19162
|
+
await ensureBound(userDir(h.openId), "user-default");
|
|
19163
|
+
} catch (err) {
|
|
19164
|
+
log.warn("user-gateway", "read.failed", { ...fields, result: "lark_error" });
|
|
19165
|
+
return { status: "lark_error", detail: String(err instanceof Error ? err.message : err) };
|
|
19166
|
+
}
|
|
19167
|
+
const r = await opts.exec(args, env(userDir(h.openId)), 6e4);
|
|
18999
19168
|
if (r.code !== 0) {
|
|
19000
19169
|
log.warn("user-gateway", "read.failed", { ...fields, result: "lark_error" });
|
|
19001
19170
|
return { status: "lark_error", detail: r.timedOut ? "\u547D\u4EE4\u8D85\u65F6" : firstLine(r.stderr || r.stdout) };
|
|
@@ -19013,10 +19182,11 @@ function createGateway(opts) {
|
|
|
19013
19182
|
}
|
|
19014
19183
|
const v = await verify(messageId);
|
|
19015
19184
|
if (typeof v === "string") return { status: v };
|
|
19016
|
-
if (v.text?.trim() !==
|
|
19185
|
+
if (v.text?.trim() !== REVOKE_TEXT2) return { status: "not_revoke" };
|
|
19017
19186
|
for (const [h, x] of handles) if (x.openId === v.openId) handles.delete(h);
|
|
19018
19187
|
const had = existsSync8(userDir(v.openId));
|
|
19019
19188
|
await rm13(userDir(v.openId), { recursive: true, force: true });
|
|
19189
|
+
bound2.delete(userDir(v.openId));
|
|
19020
19190
|
log.info("user-gateway", "auth.revoked", { sender: tail6(v.openId), messageId, had });
|
|
19021
19191
|
return { status: had ? "revoked" : "not_authorized" };
|
|
19022
19192
|
},
|
|
@@ -19111,7 +19281,7 @@ function createGatewayServer(opts) {
|
|
|
19111
19281
|
function fetchToken(cmd) {
|
|
19112
19282
|
const [bin, ...args] = cmd.trim().split(/\s+/);
|
|
19113
19283
|
if (!bin) throw new Error("--token-cmd \u4E3A\u7A7A");
|
|
19114
|
-
const r =
|
|
19284
|
+
const r = spawnSync5(bin, args, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 3e4 });
|
|
19115
19285
|
const value = r.status === 0 ? r.stdout.trim() : "";
|
|
19116
19286
|
if (!value) throw new Error(`\u53D6\u7F51\u5173\u53E3\u4EE4\u5931\u8D25\uFF08${bin} \u9000\u51FA\u7801 ${r.status}\uFF09`);
|
|
19117
19287
|
return value;
|