@keyou007/agent-bot 0.1.13-alpha.0 → 0.1.13-alpha.1
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/.env.example +2 -2
- package/CHANGELOG.md +9 -0
- package/README.md +10 -4
- package/README.zh.md +10 -4
- package/dist/cli/ServerStarter.js +17 -2
- package/dist/cli/ServerStarter.js.map +1 -1
- package/dist/cli/controlProtocol.js.map +1 -1
- package/dist/cli/help.js +12 -2
- package/dist/cli/help.js.map +1 -1
- package/dist/cli.js +39 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/CommandRouter.js +5 -0
- package/dist/commands/CommandRouter.js.map +1 -1
- package/dist/config/FeishuUserOpenIdStore.js +76 -0
- package/dist/config/FeishuUserOpenIdStore.js.map +1 -0
- package/dist/config/loadConfig.js +3 -0
- package/dist/config/loadConfig.js.map +1 -1
- package/dist/feishu/CardRenderer.js +82 -22
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/index.js +103 -23
- package/dist/index.js.map +1 -1
- package/dist/presentation/turnGraph.js +36 -0
- package/dist/presentation/turnGraph.js.map +1 -0
- package/dist/proxy/ProxySessionController.js +270 -47
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/dist/startup/StartupNotifier.js +16 -7
- package/dist/startup/StartupNotifier.js.map +1 -1
- package/dist/startup/startFeishu.js +2 -2
- package/dist/startup/startFeishu.js.map +1 -1
- package/dist/state/StateStore.js +169 -0
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/migrations.js +21 -0
- package/dist/state/migrations.js.map +1 -1
- package/dist/supervision/SafeRestartNotifier.js +46 -3
- package/dist/supervision/SafeRestartNotifier.js.map +1 -1
- package/dist/supervision/SafeRestartScheduler.js +65 -6
- package/dist/supervision/SafeRestartScheduler.js.map +1 -1
- package/dist/supervision/replacementSupervisor.js +27 -2
- package/dist/supervision/replacementSupervisor.js.map +1 -1
- package/dist/supervisor.js +27 -2
- package/dist/supervisor.js.map +1 -1
- package/docs/technical-reference.md +11 -4
- package/docs/technical-reference.zh.md +11 -4
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/skills/agent-bot/SKILL.md +10 -4
- package/src/cli/ServerStarter.ts +25 -2
- package/src/cli/controlProtocol.ts +6 -1
- package/src/cli/help.ts +12 -2
- package/src/cli.ts +57 -0
- package/src/commands/CommandRouter.ts +4 -0
- package/src/commands/commandTypes.ts +1 -0
- package/src/config/FeishuUserOpenIdStore.ts +81 -0
- package/src/config/loadConfig.ts +3 -0
- package/src/feishu/CardRenderer.ts +109 -22
- package/src/index.ts +161 -21
- package/src/presentation/turnGraph.ts +48 -0
- package/src/proxy/ProxySessionController.ts +323 -55
- package/src/startup/StartupNotifier.ts +23 -7
- package/src/startup/startFeishu.ts +3 -2
- package/src/state/StateStore.ts +221 -0
- package/src/state/migrations.ts +21 -0
- package/src/supervision/SafeRestartNotifier.ts +53 -4
- package/src/supervision/SafeRestartScheduler.ts +78 -7
- package/src/supervision/replacementSupervisor.ts +27 -1
- package/src/supervisor.ts +33 -2
package/src/supervisor.ts
CHANGED
|
@@ -14,6 +14,10 @@ import {
|
|
|
14
14
|
} from "./supervision/restartPolicy.js";
|
|
15
15
|
import { SupervisorDiagnostics, nodeDiagnosticReportArguments } from "./supervision/SupervisorDiagnostics.js";
|
|
16
16
|
import { refreshedSystemEnvironment } from "./supervision/systemEnvironment.js";
|
|
17
|
+
import {
|
|
18
|
+
RESTART_GROUP_CONTEXTS_ENV,
|
|
19
|
+
restartGroupContextKeysFromEnvironment,
|
|
20
|
+
} from "./supervision/replacementSupervisor.js";
|
|
17
21
|
|
|
18
22
|
const childEntry = fileURLToPath(new URL("./index.js", import.meta.url));
|
|
19
23
|
const config = loadConfig();
|
|
@@ -24,9 +28,13 @@ const diagnostics = new SupervisorDiagnostics(config);
|
|
|
24
28
|
diagnostics.initialize();
|
|
25
29
|
let child: ChildProcess | undefined;
|
|
26
30
|
let restartTimer: NodeJS.Timeout | undefined;
|
|
31
|
+
let restartGroupContextExpiryTimer: NodeJS.Timeout | undefined;
|
|
27
32
|
let stopping = false;
|
|
28
33
|
let consecutiveFailures = 0;
|
|
29
34
|
let nextStartReason = process.env.AGENT_BOT_RESTART_REASON?.trim() || "Supervisor 启动";
|
|
35
|
+
let nextRestartGroupContextKeys = restartGroupContextKeysFromEnvironment(
|
|
36
|
+
process.env[RESTART_GROUP_CONTEXTS_ENV],
|
|
37
|
+
);
|
|
30
38
|
|
|
31
39
|
async function startChild(): Promise<void> {
|
|
32
40
|
if (stopping || child) return;
|
|
@@ -37,6 +45,7 @@ async function startChild(): Promise<void> {
|
|
|
37
45
|
}
|
|
38
46
|
const startedAt = Date.now();
|
|
39
47
|
const restartReason = nextStartReason;
|
|
48
|
+
const restartGroupContextKeys = nextRestartGroupContextKeys;
|
|
40
49
|
nextStartReason = "Supervisor 重新拉起进程";
|
|
41
50
|
const workerStderr = diagnostics.openWorkerStderr();
|
|
42
51
|
const environmentRefresh = refreshedSystemEnvironment();
|
|
@@ -51,11 +60,11 @@ async function startChild(): Promise<void> {
|
|
|
51
60
|
childEntry,
|
|
52
61
|
], {
|
|
53
62
|
cwd: process.cwd(),
|
|
54
|
-
env: {
|
|
63
|
+
env: workerEnvironment({
|
|
55
64
|
...environmentRefresh.environment,
|
|
56
65
|
AGENT_BOT_SUPERVISED: "1",
|
|
57
66
|
AGENT_BOT_RESTART_REASON: restartReason,
|
|
58
|
-
},
|
|
67
|
+
}, restartGroupContextKeys),
|
|
59
68
|
stdio: ["ignore", "ignore", workerStderr],
|
|
60
69
|
windowsHide: true,
|
|
61
70
|
});
|
|
@@ -66,6 +75,7 @@ async function startChild(): Promise<void> {
|
|
|
66
75
|
writeSupervisorLog("started", {
|
|
67
76
|
pid: child.pid,
|
|
68
77
|
restartReason,
|
|
78
|
+
restartGroupContextKeys,
|
|
69
79
|
workerStderrPath: diagnostics.paths.workerStderrPath,
|
|
70
80
|
crashReportDirectory: diagnostics.paths.crashReportDirectory,
|
|
71
81
|
});
|
|
@@ -76,6 +86,26 @@ async function startChild(): Promise<void> {
|
|
|
76
86
|
child.once("exit", (code, signal) => {
|
|
77
87
|
void handleChildExit(code, signal, startedAt, workerPid);
|
|
78
88
|
});
|
|
89
|
+
if (restartGroupContextKeys.length > 0) {
|
|
90
|
+
if (restartGroupContextExpiryTimer) clearTimeout(restartGroupContextExpiryTimer);
|
|
91
|
+
restartGroupContextExpiryTimer = setTimeout(() => {
|
|
92
|
+
nextRestartGroupContextKeys = [];
|
|
93
|
+
restartGroupContextExpiryTimer = undefined;
|
|
94
|
+
}, STABLE_UPTIME_MS);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function workerEnvironment(
|
|
99
|
+
environment: NodeJS.ProcessEnv,
|
|
100
|
+
restartGroupContextKeys: readonly string[],
|
|
101
|
+
): NodeJS.ProcessEnv {
|
|
102
|
+
const result = { ...environment };
|
|
103
|
+
if (restartGroupContextKeys.length > 0) {
|
|
104
|
+
result[RESTART_GROUP_CONTEXTS_ENV] = JSON.stringify(restartGroupContextKeys);
|
|
105
|
+
} else {
|
|
106
|
+
delete result[RESTART_GROUP_CONTEXTS_ENV];
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
79
109
|
}
|
|
80
110
|
|
|
81
111
|
async function handleChildExit(
|
|
@@ -134,6 +164,7 @@ function stop(signal: NodeJS.Signals): void {
|
|
|
134
164
|
if (stopping) return;
|
|
135
165
|
stopping = true;
|
|
136
166
|
if (restartTimer) clearTimeout(restartTimer);
|
|
167
|
+
if (restartGroupContextExpiryTimer) clearTimeout(restartGroupContextExpiryTimer);
|
|
137
168
|
if (child && !child.killed) {
|
|
138
169
|
child.kill(signal);
|
|
139
170
|
return;
|