@keyou007/agent-bot 0.1.9 → 0.1.10
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/CHANGELOG.md +8 -0
- package/README.md +7 -1
- package/README.zh.md +7 -1
- package/dist/cli/FeishuAppConfiguration.js +84 -22
- package/dist/cli/FeishuAppConfiguration.js.map +1 -1
- package/dist/cli/FeishuAppRegistration.js +12 -9
- package/dist/cli/FeishuAppRegistration.js.map +1 -1
- package/dist/cli/Initializer.js +7 -6
- package/dist/cli/Initializer.js.map +1 -1
- package/dist/cli/LocalControlClient.js +3 -2
- package/dist/cli/LocalControlClient.js.map +1 -1
- package/dist/cli/LocalControlServer.js +2 -1
- package/dist/cli/LocalControlServer.js.map +1 -1
- package/dist/cli/OptionalAuthorizationSkip.js +27 -6
- package/dist/cli/OptionalAuthorizationSkip.js.map +1 -1
- package/dist/cli/ServerStarter.js +12 -3
- package/dist/cli/ServerStarter.js.map +1 -1
- package/dist/cli/SkillRegistry.js +5 -4
- package/dist/cli/SkillRegistry.js.map +1 -1
- package/dist/cli/VerificationOutput.js +2 -1
- package/dist/cli/VerificationOutput.js.map +1 -1
- package/dist/cli/help.js +48 -1
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/i18n.js +27 -0
- package/dist/cli/i18n.js.map +1 -0
- package/dist/cli/initOptions.js +5 -4
- package/dist/cli/initOptions.js.map +1 -1
- package/dist/cli/packageVersion.js +2 -1
- package/dist/cli/packageVersion.js.map +1 -1
- package/dist/cli/profile.js +4 -3
- package/dist/cli/profile.js.map +1 -1
- package/dist/cli/serverStatus.js +15 -14
- package/dist/cli/serverStatus.js.map +1 -1
- package/dist/cli/taskChatRoute.js +3 -2
- package/dist/cli/taskChatRoute.js.map +1 -1
- package/dist/cli.js +165 -107
- package/dist/cli.js.map +1 -1
- package/dist/commands/CommandRouter.js +49 -3
- package/dist/commands/CommandRouter.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +6 -0
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/docs/technical-reference.md +13 -2
- package/docs/technical-reference.zh.md +13 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/skills/agent-bot/SKILL.md +6 -6
- package/src/cli/FeishuAppConfiguration.ts +130 -18
- package/src/cli/FeishuAppRegistration.ts +24 -9
- package/src/cli/Initializer.ts +25 -6
- package/src/cli/LocalControlClient.ts +9 -2
- package/src/cli/LocalControlServer.ts +2 -1
- package/src/cli/OptionalAuthorizationSkip.ts +51 -6
- package/src/cli/ServerStarter.ts +20 -3
- package/src/cli/SkillRegistry.ts +17 -4
- package/src/cli/VerificationOutput.ts +4 -1
- package/src/cli/help.ts +50 -1
- package/src/cli/i18n.ts +38 -0
- package/src/cli/initOptions.ts +17 -4
- package/src/cli/packageVersion.ts +5 -1
- package/src/cli/profile.ts +13 -3
- package/src/cli/serverStatus.ts +19 -14
- package/src/cli/taskChatRoute.ts +9 -2
- package/src/cli.ts +290 -103
- package/src/commands/CommandRouter.ts +58 -3
- package/src/proxy/ProxySessionController.ts +6 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import net from "node:net";
|
|
2
2
|
import type { ControlRequest, ControlResponse } from "./controlProtocol.js";
|
|
3
|
+
import { cliText } from "./i18n.js";
|
|
3
4
|
|
|
4
5
|
export async function sendControlRequest(
|
|
5
6
|
endpoint: string,
|
|
@@ -17,7 +18,10 @@ export async function sendControlRequest(
|
|
|
17
18
|
socket.destroy();
|
|
18
19
|
operation();
|
|
19
20
|
};
|
|
20
|
-
const timer = setTimeout(() => finish(() => reject(new Error(
|
|
21
|
+
const timer = setTimeout(() => finish(() => reject(new Error(cliText(
|
|
22
|
+
"Timed out connecting to the Agent Bot control endpoint.",
|
|
23
|
+
"连接 Agent Bot 控制端点超时。",
|
|
24
|
+
)))), timeoutMs);
|
|
21
25
|
socket.setEncoding("utf8");
|
|
22
26
|
socket.once("connect", () => socket.write(`${JSON.stringify(request)}\n`));
|
|
23
27
|
socket.on("data", (chunk: string) => {
|
|
@@ -33,7 +37,10 @@ export async function sendControlRequest(
|
|
|
33
37
|
});
|
|
34
38
|
socket.once("error", (error) => finish(() => reject(error)));
|
|
35
39
|
socket.once("end", () => {
|
|
36
|
-
if (!settled) finish(() => reject(new Error(
|
|
40
|
+
if (!settled) finish(() => reject(new Error(cliText(
|
|
41
|
+
"The Agent Bot control endpoint returned no response.",
|
|
42
|
+
"Agent Bot 控制端点未返回响应。",
|
|
43
|
+
))));
|
|
37
44
|
});
|
|
38
45
|
});
|
|
39
46
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import net from "node:net";
|
|
3
3
|
import type { ControlRequest, ControlResponse } from "./controlProtocol.js";
|
|
4
|
+
import { cliText } from "./i18n.js";
|
|
4
5
|
|
|
5
6
|
export type ControlRequestHandler = (request: ControlRequest) => Promise<ControlResponse>;
|
|
6
7
|
|
|
@@ -61,7 +62,7 @@ export class LocalControlServer {
|
|
|
61
62
|
function parseRequest(line: string): ControlRequest {
|
|
62
63
|
const value = JSON.parse(line) as unknown;
|
|
63
64
|
if (!value || typeof value !== "object" || !("action" in value) || typeof value.action !== "string") {
|
|
64
|
-
throw new Error("Invalid local control request.");
|
|
65
|
+
throw new Error(cliText("Invalid local control request.", "无效的本地控制请求。"));
|
|
65
66
|
}
|
|
66
67
|
return value as ControlRequest;
|
|
67
68
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createInterface, type Interface } from "node:readline";
|
|
2
|
+
import { cliText } from "./i18n.js";
|
|
2
3
|
|
|
3
4
|
export interface OptionalAuthorizationSkipListener {
|
|
4
5
|
close(): void;
|
|
@@ -6,6 +7,45 @@ export interface OptionalAuthorizationSkipListener {
|
|
|
6
7
|
|
|
7
8
|
export function listenForOptionalAuthorizationSkip(
|
|
8
9
|
onSkip: () => void,
|
|
10
|
+
): OptionalAuthorizationSkipListener {
|
|
11
|
+
return listenForAuthorizationSkip(onSkip, {
|
|
12
|
+
prompt: cliText(
|
|
13
|
+
"Skip optional authorization? Enter Y and press Enter to skip.\n",
|
|
14
|
+
"是否跳过可选授权?输入 Y 并按回车键跳过。\n",
|
|
15
|
+
),
|
|
16
|
+
retry: cliText(
|
|
17
|
+
"Enter Y to skip optional authorization, or keep waiting.\n",
|
|
18
|
+
"输入 Y 跳过可选授权,或继续等待。\n",
|
|
19
|
+
),
|
|
20
|
+
skipped: cliText(
|
|
21
|
+
"Optional authorization skipped. Initialization will continue.\n",
|
|
22
|
+
"已跳过可选授权,初始化将继续。\n",
|
|
23
|
+
),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function listenForManualPermissionSkip(
|
|
28
|
+
onSkip: () => void,
|
|
29
|
+
): OptionalAuthorizationSkipListener {
|
|
30
|
+
return listenForAuthorizationSkip(onSkip, {
|
|
31
|
+
prompt: cliText(
|
|
32
|
+
"Skip waiting for this permission? Enter Y and press Enter to skip.\n",
|
|
33
|
+
"是否跳过等待此权限?输入 Y 并按回车键跳过。\n",
|
|
34
|
+
),
|
|
35
|
+
retry: cliText(
|
|
36
|
+
"Enter Y to skip this permission, or keep waiting.\n",
|
|
37
|
+
"输入 Y 跳过此权限,或继续等待。\n",
|
|
38
|
+
),
|
|
39
|
+
skipped: cliText(
|
|
40
|
+
"Permission wait skipped. Initialization will continue with limited group-message functionality.\n",
|
|
41
|
+
"已跳过权限等待,初始化将继续,但群消息功能受限。\n",
|
|
42
|
+
),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function listenForAuthorizationSkip(
|
|
47
|
+
onSkip: () => void,
|
|
48
|
+
messages: { prompt: string; retry: string; skipped: string },
|
|
9
49
|
): OptionalAuthorizationSkipListener {
|
|
10
50
|
if (!process.stdin.isTTY) return { close: () => undefined };
|
|
11
51
|
|
|
@@ -13,19 +53,24 @@ export function listenForOptionalAuthorizationSkip(
|
|
|
13
53
|
input: process.stdin,
|
|
14
54
|
output: process.stderr,
|
|
15
55
|
});
|
|
56
|
+
let closed = false;
|
|
57
|
+
const close = (): void => {
|
|
58
|
+
if (closed) return;
|
|
59
|
+
closed = true;
|
|
60
|
+
closeReadline(readline, onLine);
|
|
61
|
+
};
|
|
16
62
|
const onLine = (value: string): void => {
|
|
17
63
|
if (!isOptionalAuthorizationSkip(value)) {
|
|
18
|
-
process.stderr.write(
|
|
64
|
+
process.stderr.write(messages.retry);
|
|
19
65
|
return;
|
|
20
66
|
}
|
|
21
|
-
process.stderr.write(
|
|
67
|
+
process.stderr.write(messages.skipped);
|
|
68
|
+
close();
|
|
22
69
|
onSkip();
|
|
23
70
|
};
|
|
24
71
|
readline.on("line", onLine);
|
|
25
|
-
process.stderr.write(
|
|
26
|
-
return {
|
|
27
|
-
close: () => closeReadline(readline, onLine),
|
|
28
|
-
};
|
|
72
|
+
process.stderr.write(messages.prompt);
|
|
73
|
+
return { close };
|
|
29
74
|
}
|
|
30
75
|
|
|
31
76
|
export function isOptionalAuthorizationSkip(value: string): boolean {
|
package/src/cli/ServerStarter.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
resolveSupervisorDiagnosticsPaths,
|
|
10
10
|
} from "../supervision/SupervisorDiagnostics.js";
|
|
11
11
|
import { controlEndpoint } from "./controlProtocol.js";
|
|
12
|
+
import { cliText } from "./i18n.js";
|
|
12
13
|
import { isServerReachable, isServerRunning } from "./LocalControlClient.js";
|
|
13
14
|
|
|
14
15
|
export interface ServerStartResult {
|
|
@@ -47,7 +48,17 @@ export async function startServer(
|
|
|
47
48
|
config: AppConfig,
|
|
48
49
|
dependencies: ServerStarterDependencies = defaultDependencies,
|
|
49
50
|
): Promise<ServerStartResult> {
|
|
50
|
-
|
|
51
|
+
try {
|
|
52
|
+
requireServerFeishuTransport(config.feishu);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (error instanceof Error && /Lark bot is not configured/.test(error.message)) {
|
|
55
|
+
throw new Error(cliText(
|
|
56
|
+
"The Lark bot is not configured. Run agent-bot init first, or use agent-bot console for local-only testing.",
|
|
57
|
+
"尚未配置飞书机器人。请先运行 agent-bot init,或使用 agent-bot console 进行纯本地测试。",
|
|
58
|
+
));
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
51
62
|
const endpoint = controlEndpoint(config.storage.sqlitePath);
|
|
52
63
|
|
|
53
64
|
if (await dependencies.isRunning(endpoint)) {
|
|
@@ -56,7 +67,10 @@ export async function startServer(
|
|
|
56
67
|
if (await dependencies.isReachable(endpoint)) {
|
|
57
68
|
const running = await dependencies.waitUntilRunning(endpoint, SERVER_START_TIMEOUT_MS);
|
|
58
69
|
if (!running) {
|
|
59
|
-
throw new Error(
|
|
70
|
+
throw new Error(cliText(
|
|
71
|
+
"The Agent Bot server started but could not connect to Lark. Check the logs.",
|
|
72
|
+
"Agent Bot 服务已启动,但无法连接飞书。请检查日志。",
|
|
73
|
+
));
|
|
60
74
|
}
|
|
61
75
|
return { status: "started" };
|
|
62
76
|
}
|
|
@@ -64,7 +78,10 @@ export async function startServer(
|
|
|
64
78
|
dependencies.spawnSupervisor(config);
|
|
65
79
|
const running = await dependencies.waitUntilRunning(endpoint, SERVER_START_TIMEOUT_MS);
|
|
66
80
|
if (!running) {
|
|
67
|
-
throw new Error(
|
|
81
|
+
throw new Error(cliText(
|
|
82
|
+
"The Supervisor started, but the server did not connect to Lark within 45 seconds. Check the logs.",
|
|
83
|
+
"Supervisor 已启动,但服务未能在 45 秒内连接飞书。请检查日志。",
|
|
84
|
+
));
|
|
68
85
|
}
|
|
69
86
|
return { status: "started" };
|
|
70
87
|
}
|
package/src/cli/SkillRegistry.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { cliText } from "./i18n.js";
|
|
5
6
|
|
|
6
7
|
const SKILL_NAME = "agent-bot";
|
|
7
8
|
const MARKER_FILE = ".agent-bot-managed.json";
|
|
@@ -65,7 +66,10 @@ export class SkillRegistry {
|
|
|
65
66
|
this.assertValidSource();
|
|
66
67
|
const existing = fs.existsSync(this.targetPath);
|
|
67
68
|
if (existing && this.readMarker()?.managedBy !== "agent-bot") {
|
|
68
|
-
throw new Error(
|
|
69
|
+
throw new Error(cliText(
|
|
70
|
+
`The target directory exists and is not managed by Agent Bot: ${this.targetPath}`,
|
|
71
|
+
`目标目录已存在且不由 Agent Bot 管理:${this.targetPath}`,
|
|
72
|
+
));
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
const before = existing ? this.status() : undefined;
|
|
@@ -93,7 +97,10 @@ export class SkillRegistry {
|
|
|
93
97
|
uninstall(): boolean {
|
|
94
98
|
if (!fs.existsSync(this.targetPath)) return false;
|
|
95
99
|
if (this.readMarker()?.managedBy !== "agent-bot") {
|
|
96
|
-
throw new Error(
|
|
100
|
+
throw new Error(cliText(
|
|
101
|
+
`Refusing to remove a directory that is not managed by Agent Bot: ${this.targetPath}`,
|
|
102
|
+
`拒绝删除不由 Agent Bot 管理的目录:${this.targetPath}`,
|
|
103
|
+
));
|
|
97
104
|
}
|
|
98
105
|
this.removeManagedTarget();
|
|
99
106
|
return true;
|
|
@@ -101,13 +108,19 @@ export class SkillRegistry {
|
|
|
101
108
|
|
|
102
109
|
private assertValidSource(): void {
|
|
103
110
|
if (!fs.existsSync(path.join(this.sourcePath, "SKILL.md"))) {
|
|
104
|
-
throw new Error(
|
|
111
|
+
throw new Error(cliText(
|
|
112
|
+
`The built-in Agent Bot Skill was not found: ${this.sourcePath}`,
|
|
113
|
+
`未找到内置 Agent Bot Skill:${this.sourcePath}`,
|
|
114
|
+
));
|
|
105
115
|
}
|
|
106
116
|
}
|
|
107
117
|
|
|
108
118
|
private assertSafeTarget(): void {
|
|
109
119
|
if (path.dirname(this.targetPath) !== this.skillsRoot || path.basename(this.targetPath) !== SKILL_NAME) {
|
|
110
|
-
throw new Error(
|
|
120
|
+
throw new Error(cliText(
|
|
121
|
+
`Unsafe Skill target path: ${this.targetPath}`,
|
|
122
|
+
`不安全的 Skill 目标路径:${this.targetPath}`,
|
|
123
|
+
));
|
|
111
124
|
}
|
|
112
125
|
}
|
|
113
126
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import qrcode from "qrcode-terminal";
|
|
2
|
+
import { cliText, type CliLanguage } from "./i18n.js";
|
|
2
3
|
|
|
3
4
|
export interface VerificationOutputOptions {
|
|
4
5
|
verificationUrl: string;
|
|
5
6
|
json: boolean;
|
|
6
7
|
qrInstruction: string;
|
|
8
|
+
linkLabel?: string;
|
|
9
|
+
language?: CliLanguage;
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
export function printVerificationQrAndLink(
|
|
@@ -18,5 +21,5 @@ export function printVerificationQrAndLink(
|
|
|
18
21
|
write(`\n${options.qrInstruction}\n\n`);
|
|
19
22
|
renderQr(options.verificationUrl, (output) => write(`${output}\n`));
|
|
20
23
|
}
|
|
21
|
-
write(
|
|
24
|
+
write(`${options.linkLabel ?? cliText("Authorization link", "授权链接", options.language)}${cliText(":", ":", options.language)}\n${options.verificationUrl}\n\n`);
|
|
22
25
|
}
|
package/src/cli/help.ts
CHANGED
|
@@ -1,4 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
import { cliLanguage, type CliLanguage } from "./i18n.js";
|
|
2
|
+
|
|
3
|
+
export function renderCliHelp(version: string, language: CliLanguage = cliLanguage): string {
|
|
4
|
+
if (language === "zh") {
|
|
5
|
+
return `Agent Bot ${version}
|
|
6
|
+
通过飞书使用本地 Codex 和 ACP Agent。
|
|
7
|
+
|
|
8
|
+
用法:
|
|
9
|
+
agent-bot [选项] <命令>
|
|
10
|
+
|
|
11
|
+
常用命令:
|
|
12
|
+
init 初始化飞书应用并启动服务
|
|
13
|
+
init --reset 重置并重新配置显式指定的 Profile
|
|
14
|
+
console 打开本地控制台
|
|
15
|
+
server start 在后台启动 Agent Bot
|
|
16
|
+
server status 显示服务、飞书 App ID 和安全重启状态
|
|
17
|
+
server restart 安排安全重启
|
|
18
|
+
server stop 停止 Agent Bot
|
|
19
|
+
task list 列出任务
|
|
20
|
+
task status <任务> 显示任务状态
|
|
21
|
+
task chat <任务> 显示任务绑定的飞书会话
|
|
22
|
+
task prompt <任务> <提示词> 向任务发送提示词
|
|
23
|
+
task stop <任务> 停止任务
|
|
24
|
+
task title <任务> <标题> 重命名任务
|
|
25
|
+
skills status 显示内置 Skill 状态
|
|
26
|
+
skills install 安装内置 Skill
|
|
27
|
+
|
|
28
|
+
选项:
|
|
29
|
+
--profile <目录> 使用独立的 Profile 目录
|
|
30
|
+
--config <路径> 使用指定的配置文件
|
|
31
|
+
--json 在支持时输出 JSON
|
|
32
|
+
-h, --help 显示帮助
|
|
33
|
+
-v, --version 显示版本
|
|
34
|
+
|
|
35
|
+
初始化选项:
|
|
36
|
+
--reset 备份并重置显式指定的 Profile
|
|
37
|
+
--skip-feishu 仅初始化 Console 环境
|
|
38
|
+
--reconfigure-feishu 仅替换现有飞书凭据
|
|
39
|
+
|
|
40
|
+
示例:
|
|
41
|
+
agent-bot init
|
|
42
|
+
agent-bot --profile ~/.agent-bot init --reset
|
|
43
|
+
agent-bot --profile ~/.agent-bot-rescue init
|
|
44
|
+
agent-bot server start
|
|
45
|
+
agent-bot server status
|
|
46
|
+
agent-bot task list
|
|
47
|
+
agent-bot server restart --reason "更新 Agent Bot"
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
|
|
2
51
|
return `Agent Bot ${version}
|
|
3
52
|
Use local Codex and ACP agents from Lark/Feishu.
|
|
4
53
|
|
package/src/cli/i18n.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type CliLanguage = "en" | "zh";
|
|
2
|
+
|
|
3
|
+
export function detectCliLanguage(locale = systemLocale()): CliLanguage {
|
|
4
|
+
return /^zh(?:[-_]|$)/i.test(locale.trim()) ? "zh" : "en";
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const cliLanguage = detectCliLanguage();
|
|
8
|
+
|
|
9
|
+
export function cliText(
|
|
10
|
+
english: string,
|
|
11
|
+
chinese: string,
|
|
12
|
+
language: CliLanguage = cliLanguage,
|
|
13
|
+
): string {
|
|
14
|
+
return language === "zh" ? chinese : english;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function localizeCliErrorMessage(
|
|
18
|
+
message: string,
|
|
19
|
+
language: CliLanguage = cliLanguage,
|
|
20
|
+
): string {
|
|
21
|
+
if (language !== "zh") return message;
|
|
22
|
+
|
|
23
|
+
const missingConfig = /^Config file does not exist: (.+)$/u.exec(message);
|
|
24
|
+
if (missingConfig) return `配置文件不存在:${missingConfig[1]}`;
|
|
25
|
+
|
|
26
|
+
const missingAgent = /^Default agent "(.+)" is not configured\.$/u.exec(message);
|
|
27
|
+
if (missingAgent) return `默认 Agent“${missingAgent[1]}”尚未配置。`;
|
|
28
|
+
|
|
29
|
+
return message;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function systemLocale(): string {
|
|
33
|
+
try {
|
|
34
|
+
return Intl.DateTimeFormat().resolvedOptions().locale || "en";
|
|
35
|
+
} catch {
|
|
36
|
+
return "en";
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/cli/initOptions.ts
CHANGED
|
@@ -12,7 +12,10 @@ export function parseInitCommandOptions(
|
|
|
12
12
|
const supported = new Set(["--json", "--skip-feishu", "--reconfigure-feishu", "--reset"]);
|
|
13
13
|
const unsupported = input.filter((value) => !supported.has(value));
|
|
14
14
|
if (unsupported.length > 0) {
|
|
15
|
-
throw new Error(
|
|
15
|
+
throw new Error(cliText(
|
|
16
|
+
`Unsupported init options: ${unsupported.join(" ")}`,
|
|
17
|
+
`不支持的 init 选项:${unsupported.join(" ")}`,
|
|
18
|
+
));
|
|
16
19
|
}
|
|
17
20
|
const options = {
|
|
18
21
|
json: input.includes("--json"),
|
|
@@ -21,13 +24,23 @@ export function parseInitCommandOptions(
|
|
|
21
24
|
reset: input.includes("--reset"),
|
|
22
25
|
};
|
|
23
26
|
if (options.skipFeishu && options.reconfigureFeishu) {
|
|
24
|
-
throw new Error(
|
|
27
|
+
throw new Error(cliText(
|
|
28
|
+
"--skip-feishu and --reconfigure-feishu cannot be used together.",
|
|
29
|
+
"--skip-feishu 和 --reconfigure-feishu 不能同时使用。",
|
|
30
|
+
));
|
|
25
31
|
}
|
|
26
32
|
if (options.reset && !explicitProfile) {
|
|
27
|
-
throw new Error(
|
|
33
|
+
throw new Error(cliText(
|
|
34
|
+
"--reset requires an explicit --profile <directory>.",
|
|
35
|
+
"--reset 需要显式指定 --profile <目录>。",
|
|
36
|
+
));
|
|
28
37
|
}
|
|
29
38
|
if (options.reset && options.reconfigureFeishu) {
|
|
30
|
-
throw new Error(
|
|
39
|
+
throw new Error(cliText(
|
|
40
|
+
"--reset cannot be combined with --reconfigure-feishu because reset already replaces Lark credentials.",
|
|
41
|
+
"--reset 不能与 --reconfigure-feishu 同时使用,因为重置已经会替换飞书凭据。",
|
|
42
|
+
));
|
|
31
43
|
}
|
|
32
44
|
return options;
|
|
33
45
|
}
|
|
46
|
+
import { cliText } from "./i18n.js";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import { cliText } from "./i18n.js";
|
|
2
3
|
import { fileURLToPath } from "node:url";
|
|
3
4
|
|
|
4
5
|
export function readPackageVersion(
|
|
@@ -8,7 +9,10 @@ export function readPackageVersion(
|
|
|
8
9
|
fs.readFileSync(fileURLToPath(packageJsonUrl), "utf8"),
|
|
9
10
|
) as { version?: unknown };
|
|
10
11
|
if (typeof metadata.version !== "string" || !metadata.version.trim()) {
|
|
11
|
-
throw new Error(
|
|
12
|
+
throw new Error(cliText(
|
|
13
|
+
"package.json does not contain a valid version.",
|
|
14
|
+
"package.json 中不包含有效版本号。",
|
|
15
|
+
));
|
|
12
16
|
}
|
|
13
17
|
return metadata.version;
|
|
14
18
|
}
|
package/src/cli/profile.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { cliText } from "./i18n.js";
|
|
2
3
|
import {
|
|
3
4
|
AGENT_BOT_EXPLICIT_PROFILE_ENV,
|
|
4
5
|
AGENT_BOT_HOME_ENV,
|
|
@@ -22,7 +23,10 @@ export function parseGlobalOptions(input: string[]): ParsedGlobalOptions {
|
|
|
22
23
|
const configPath = removeOption(args, "--config");
|
|
23
24
|
const profilePath = removeOption(args, "--profile");
|
|
24
25
|
if (configPath && profilePath) {
|
|
25
|
-
throw new Error(
|
|
26
|
+
throw new Error(cliText(
|
|
27
|
+
"--profile and --config cannot be used together. A profile always uses config.yaml in its directory.",
|
|
28
|
+
"--profile 和 --config 不能同时使用。Profile 始终使用其目录中的 config.yaml。",
|
|
29
|
+
));
|
|
26
30
|
}
|
|
27
31
|
return {
|
|
28
32
|
args,
|
|
@@ -49,11 +53,17 @@ export function applyExplicitProfile(
|
|
|
49
53
|
|
|
50
54
|
function removeOption(args: string[], option: string): string | undefined {
|
|
51
55
|
const indexes = args.flatMap((value, index) => value === option ? [index] : []);
|
|
52
|
-
if (indexes.length > 1) throw new Error(
|
|
56
|
+
if (indexes.length > 1) throw new Error(cliText(
|
|
57
|
+
`${option} can only be specified once.`,
|
|
58
|
+
`${option} 只能指定一次。`,
|
|
59
|
+
));
|
|
53
60
|
const index = indexes[0];
|
|
54
61
|
if (index === undefined) return undefined;
|
|
55
62
|
const value = args[index + 1];
|
|
56
|
-
if (!value || value.startsWith("--")) throw new Error(
|
|
63
|
+
if (!value || value.startsWith("--")) throw new Error(cliText(
|
|
64
|
+
`${option} requires a directory or file path.`,
|
|
65
|
+
`${option} 需要目录或文件路径。`,
|
|
66
|
+
));
|
|
57
67
|
args.splice(index, 2);
|
|
58
68
|
return value;
|
|
59
69
|
}
|
package/src/cli/serverStatus.ts
CHANGED
|
@@ -12,28 +12,33 @@ export function withConfiguredFeishuAppId(
|
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export function formatServerStatus(data: unknown): string {
|
|
15
|
+
export function formatServerStatus(data: unknown, language: CliLanguage = cliLanguage): string {
|
|
16
16
|
const value = data && typeof data === "object" ? data as Record<string, unknown> : {};
|
|
17
17
|
const activity = value.activity && typeof value.activity === "object"
|
|
18
18
|
? value.activity as Record<string, unknown>
|
|
19
19
|
: {};
|
|
20
20
|
const state = value.running === false
|
|
21
|
-
? "not running"
|
|
21
|
+
? cliText("not running", "未运行", language)
|
|
22
22
|
: value.ready === false
|
|
23
|
-
? "starting (connecting to Lark)"
|
|
24
|
-
: "running";
|
|
23
|
+
? cliText("starting (connecting to Lark)", "正在启动(连接飞书中)", language)
|
|
24
|
+
: cliText("running", "运行中", language);
|
|
25
25
|
const safeRestart = value.safeRestartScheduled
|
|
26
|
-
?
|
|
27
|
-
|
|
26
|
+
? cliText(
|
|
27
|
+
`pending (${String(value.safeRestartReason ?? "no reason provided")})`,
|
|
28
|
+
`等待中(${String(value.safeRestartReason ?? "未提供原因")})`,
|
|
29
|
+
language,
|
|
30
|
+
)
|
|
31
|
+
: cliText("not scheduled", "未计划", language);
|
|
28
32
|
return [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
`${cliText("Agent Bot server: ", "Agent Bot 服务:", language)}${state}`,
|
|
34
|
+
`${cliText("Lark App ID: ", "飞书 App ID:", language)}${value.feishuAppId ?? cliText("not configured", "未配置", language)}`,
|
|
35
|
+
`${cliText("PID: ", "PID:", language)}${value.pid ?? "-"}`,
|
|
36
|
+
`${cliText("Started at: ", "启动时间:", language)}${value.startedAt ?? "-"}`,
|
|
37
|
+
`${cliText("Supervisor: ", "Supervisor:", language)}${value.supervised ? cliText("enabled", "已启用", language) : cliText("disabled", "未启用", language)}`,
|
|
38
|
+
`${cliText("Running tasks: ", "运行中任务:", language)}${activity.runningSessions ?? 0}`,
|
|
39
|
+
`${cliText("Pending final deliveries: ", "待发送最终结果:", language)}${activity.pendingFinalDeliveries ?? 0}`,
|
|
40
|
+
`${cliText("Safe restart: ", "安全重启:", language)}${safeRestart}`,
|
|
37
41
|
"",
|
|
38
42
|
].join("\n");
|
|
39
43
|
}
|
|
44
|
+
import { cliLanguage, cliText, type CliLanguage } from "./i18n.js";
|
package/src/cli/taskChatRoute.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { baseChatContextKey, isThreadContextKey } from "../feishu/contextKey.js";
|
|
2
2
|
import type { SessionRecord } from "../state/StateStore.js";
|
|
3
|
+
import { cliText } from "./i18n.js";
|
|
3
4
|
|
|
4
5
|
const CHAT_CONTEXT_PREFIX = "chat_id:";
|
|
5
6
|
const THREAD_CONTEXT_MARKER = ":thread_id:";
|
|
@@ -15,10 +16,16 @@ export function taskChatRoute(session: SessionRecord): TaskChatRoute {
|
|
|
15
16
|
const contextKey = session.contextKey;
|
|
16
17
|
const baseContextKey = baseChatContextKey(contextKey);
|
|
17
18
|
if (!baseContextKey.startsWith(CHAT_CONTEXT_PREFIX)) {
|
|
18
|
-
throw new Error(
|
|
19
|
+
throw new Error(cliText(
|
|
20
|
+
`The task is not bound to a Lark chat: ${session.remoteSessionId ?? session.acpSessionId ?? session.localSessionId}`,
|
|
21
|
+
`任务未绑定飞书会话:${session.remoteSessionId ?? session.acpSessionId ?? session.localSessionId}`,
|
|
22
|
+
));
|
|
19
23
|
}
|
|
20
24
|
const chatId = baseContextKey.slice(CHAT_CONTEXT_PREFIX.length);
|
|
21
|
-
if (!chatId) throw new Error(
|
|
25
|
+
if (!chatId) throw new Error(cliText(
|
|
26
|
+
`The task has an invalid Lark chat ID: ${contextKey}`,
|
|
27
|
+
`任务的飞书会话 ID 无效:${contextKey}`,
|
|
28
|
+
));
|
|
22
29
|
const threadId = isThreadContextKey(contextKey)
|
|
23
30
|
? contextKey.slice(contextKey.indexOf(THREAD_CONTEXT_MARKER) + THREAD_CONTEXT_MARKER.length)
|
|
24
31
|
: undefined;
|