@keyou007/agent-bot 0.1.9 → 0.1.11
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 +23 -0
- package/README.md +22 -10
- package/README.zh.md +22 -10
- package/assets/agent-bot-logo.png +0 -0
- package/dist/acp/AcpSessionManager.js +78 -46
- package/dist/acp/AcpSessionManager.js.map +1 -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/codex/AppServerConnection.js +15 -1
- package/dist/codex/AppServerConnection.js.map +1 -1
- package/dist/codex/CodexLocalActivityDetector.js +4 -1
- package/dist/codex/CodexLocalActivityDetector.js.map +1 -1
- package/dist/codex/CodexProcessManager.js +1 -0
- package/dist/codex/CodexProcessManager.js.map +1 -1
- package/dist/codex/CodexRuntime.js +77 -2
- package/dist/codex/CodexRuntime.js.map +1 -1
- package/dist/commands/CommandRouter.js +108 -47
- package/dist/commands/CommandRouter.js.map +1 -1
- package/dist/console/ConsoleTurnPresenter.js +1 -1
- package/dist/console/ConsoleTurnPresenter.js.map +1 -1
- package/dist/feishu/CardRenderer.js +345 -11
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/feishu/FeishuMessageClient.js +51 -5
- package/dist/feishu/FeishuMessageClient.js.map +1 -1
- package/dist/feishu/FeishuTurnPresenter.js +8 -3
- package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
- package/dist/index.js +18 -17
- package/dist/index.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +595 -205
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/dist/runtime/AcpRuntimeAdapter.js +1 -0
- package/dist/runtime/AcpRuntimeAdapter.js.map +1 -1
- package/dist/runtime/AgentRuntimeRegistry.js +7 -4
- package/dist/runtime/AgentRuntimeRegistry.js.map +1 -1
- package/dist/runtime/createAgentRuntimeRegistry.js +22 -0
- package/dist/runtime/createAgentRuntimeRegistry.js.map +1 -0
- package/dist/startup/SessionMetadataHydrator.js +2 -2
- package/dist/startup/SessionMetadataHydrator.js.map +1 -1
- package/dist/startup/StartupNotifier.js +1 -0
- package/dist/startup/StartupNotifier.js.map +1 -1
- package/dist/state/StateStore.js +21 -15
- package/dist/state/StateStore.js.map +1 -1
- package/dist/supervision/SafeRestartScheduler.js +5 -0
- package/dist/supervision/SafeRestartScheduler.js.map +1 -1
- package/docs/technical-reference.md +27 -6
- package/docs/technical-reference.zh.md +27 -6
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
- package/skills/agent-bot/SKILL.md +19 -9
- package/src/acp/AcpSessionManager.ts +73 -54
- 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/codex/AppServerConnection.ts +21 -1
- package/src/codex/CodexLocalActivityDetector.ts +8 -1
- package/src/codex/CodexProcessManager.ts +1 -0
- package/src/codex/CodexRuntime.ts +91 -2
- package/src/commands/CommandRouter.ts +123 -46
- package/src/commands/commandTypes.ts +6 -11
- package/src/console/ConsoleTurnPresenter.ts +1 -1
- package/src/feishu/CardRenderer.ts +418 -11
- package/src/feishu/FeishuMessageClient.ts +66 -3
- package/src/feishu/FeishuTurnPresenter.ts +7 -2
- package/src/index.ts +21 -22
- package/src/proxy/ProxySessionController.ts +712 -208
- package/src/runtime/AcpRuntimeAdapter.ts +1 -0
- package/src/runtime/AgentRuntimeRegistry.ts +7 -6
- package/src/runtime/createAgentRuntimeRegistry.ts +25 -0
- package/src/runtime/types.ts +18 -0
- package/src/startup/SessionMetadataHydrator.ts +2 -2
- package/src/startup/StartupNotifier.ts +1 -0
- package/src/state/StateStore.ts +29 -15
- package/src/supervision/SafeRestartScheduler.ts +5 -0
|
@@ -152,6 +152,7 @@ export class FeishuTurnPresenter {
|
|
|
152
152
|
await entry.scheduler?.flush(entry.state);
|
|
153
153
|
} catch (error) {
|
|
154
154
|
this.options.onError?.(error);
|
|
155
|
+
return;
|
|
155
156
|
}
|
|
156
157
|
await this.syncThinkingCardReaction(entry);
|
|
157
158
|
}
|
|
@@ -393,16 +394,20 @@ export class FeishuTurnPresenter {
|
|
|
393
394
|
}
|
|
394
395
|
|
|
395
396
|
private async finalize(entry: TurnEntry, state: TurnViewState): Promise<void> {
|
|
397
|
+
let terminalCardError: unknown;
|
|
396
398
|
if (!entry.historySnapshot) {
|
|
397
399
|
try {
|
|
398
400
|
await entry.scheduler?.flush(state);
|
|
399
401
|
} catch (error) {
|
|
400
402
|
this.options.onError?.(error);
|
|
403
|
+
terminalCardError = error;
|
|
401
404
|
}
|
|
402
405
|
}
|
|
406
|
+
if (state.status === "completed" && state.finalResponse) {
|
|
407
|
+
await this.deliverFinal(entry.contextKey, state);
|
|
408
|
+
}
|
|
409
|
+
if (terminalCardError) throw terminalCardError;
|
|
403
410
|
await this.syncThinkingCardReaction(entry);
|
|
404
|
-
if (state.status !== "completed" || !state.finalResponse) return;
|
|
405
|
-
await this.deliverFinal(entry.contextKey, state);
|
|
406
411
|
}
|
|
407
412
|
|
|
408
413
|
private async syncThinkingCardReaction(entry: TurnEntry): Promise<void> {
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { AcpProcessManager } from "./acp/AcpProcessManager.js";
|
|
5
|
-
import { AcpSessionManager } from "./acp/AcpSessionManager.js";
|
|
6
|
-
import { CodexProcessManager } from "./codex/CodexProcessManager.js";
|
|
7
|
-
import { CodexRuntime } from "./codex/CodexRuntime.js";
|
|
8
4
|
import { LocalControlServer } from "./cli/LocalControlServer.js";
|
|
9
5
|
import { controlEndpoint, type ControlRequest, type ControlResponse } from "./cli/controlProtocol.js";
|
|
10
6
|
import { readPackageVersion } from "./cli/packageVersion.js";
|
|
@@ -20,8 +16,7 @@ import { requireServerFeishuTransport } from "./feishu/transport.js";
|
|
|
20
16
|
import { createLogger } from "./logging/logger.js";
|
|
21
17
|
import { OutboundRouter, type OutboundRoute } from "./presentation/OutboundRouter.js";
|
|
22
18
|
import { ProxySessionController } from "./proxy/ProxySessionController.js";
|
|
23
|
-
import {
|
|
24
|
-
import { AgentRuntimeRegistry } from "./runtime/AgentRuntimeRegistry.js";
|
|
19
|
+
import { createAgentRuntimeRegistry } from "./runtime/createAgentRuntimeRegistry.js";
|
|
25
20
|
import { StateStore } from "./state/StateStore.js";
|
|
26
21
|
import { StartupNotifier } from "./startup/StartupNotifier.js";
|
|
27
22
|
import { SessionMetadataHydrator } from "./startup/SessionMetadataHydrator.js";
|
|
@@ -47,18 +42,7 @@ const transport = consoleOnly ? "console" : requireServerFeishuTransport(config.
|
|
|
47
42
|
const logger = createLogger(config);
|
|
48
43
|
const store = new StateStore(config.storage.sqlitePath);
|
|
49
44
|
|
|
50
|
-
const
|
|
51
|
-
const acpSessionManager = new AcpSessionManager(config, acpProcessManager, logger);
|
|
52
|
-
const acpRuntime = new AcpRuntimeAdapter(acpSessionManager);
|
|
53
|
-
const codexAgent = Object.values(config.agents).find((agent) => agent.kind === "codex");
|
|
54
|
-
const codexProcessManager = new CodexProcessManager(
|
|
55
|
-
codexAgent?.command ?? "codex",
|
|
56
|
-
codexAgent?.args ?? ["app-server", "--listen", "stdio://"],
|
|
57
|
-
codexAgent?.env ?? {},
|
|
58
|
-
logger,
|
|
59
|
-
);
|
|
60
|
-
const codexRuntime = new CodexRuntime(codexProcessManager, logger);
|
|
61
|
-
const runtimes = new AgentRuntimeRegistry({ acp: acpRuntime, codex: codexRuntime });
|
|
45
|
+
const runtimes = createAgentRuntimeRegistry(config, logger);
|
|
62
46
|
|
|
63
47
|
const routes: OutboundRoute[] = [];
|
|
64
48
|
let feishuConnector: FeishuConnector | undefined;
|
|
@@ -149,8 +133,24 @@ if (feishuConnector && startupNotifier) {
|
|
|
149
133
|
}
|
|
150
134
|
consoleConnector?.start();
|
|
151
135
|
|
|
152
|
-
async function requestRestart(contextKey: string): Promise<void> {
|
|
153
|
-
|
|
136
|
+
async function requestRestart(contextKey: string, force: boolean): Promise<void> {
|
|
137
|
+
if (restartRequested) {
|
|
138
|
+
await outbound.sendText(contextKey, "Agent Bot 已在重启中,请稍候。").catch(() => undefined);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (force) {
|
|
142
|
+
await initiateRestart("用户执行 /restart --force 命令", contextKey);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const newlyScheduled = safeRestart.schedule("用户执行 /restart 命令");
|
|
146
|
+
await outbound.sendText(
|
|
147
|
+
contextKey,
|
|
148
|
+
newlyScheduled
|
|
149
|
+
? "已安排安全重启。Agent Bot 会等待所有任务完成、最终结果投递完成,并保持 15 秒无新消息后重启。"
|
|
150
|
+
: "安全重启已在等待中,已更新重启原因。",
|
|
151
|
+
).catch((error: unknown) => {
|
|
152
|
+
logger.warn({ error, contextKey }, "Failed to send safe restart acknowledgement.");
|
|
153
|
+
});
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
async function initiateRestart(reason: string, contextKey?: string): Promise<void> {
|
|
@@ -159,7 +159,7 @@ async function initiateRestart(reason: string, contextKey?: string): Promise<voi
|
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
161
|
restartRequested = true;
|
|
162
|
-
safeRestart.
|
|
162
|
+
await safeRestart.cancelCurrent();
|
|
163
163
|
await safeRestartNotifier?.flush();
|
|
164
164
|
if (contextKey) {
|
|
165
165
|
await outbound.sendText(contextKey, "Agent Bot 正在重启,恢复在线后会发送启动状态通知。").catch((error: unknown) => {
|
|
@@ -226,7 +226,6 @@ async function shutdown(exitCode: number, restartReason?: string): Promise<void>
|
|
|
226
226
|
delay(5_000),
|
|
227
227
|
]);
|
|
228
228
|
runtimes.close();
|
|
229
|
-
acpProcessManager.stopAll();
|
|
230
229
|
await controlServer?.close().catch((error: unknown) => logger.warn({ error }, "Failed to close local control endpoint."));
|
|
231
230
|
store.close();
|
|
232
231
|
if (restartReason) startReplacementSupervisor(restartReason);
|