@keyou007/agent-bot 0.1.1 → 0.1.2

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.
@@ -1,24 +1,15 @@
1
1
  import type { AppConfig } from "../config/schema.js";
2
2
 
3
- export type FeishuTransportMode = "sdk" | "console";
4
-
5
3
  type FeishuTransportConfig = Pick<
6
4
  AppConfig["feishu"],
7
- "transport" | "appId" | "appSecret" | "useConsoleWhenMissingCredentials"
5
+ "appId" | "appSecret"
8
6
  >;
9
7
 
10
- export function resolveFeishuTransport(config: FeishuTransportConfig): FeishuTransportMode {
11
- if (config.transport === "console") {
12
- return "console";
13
- }
14
-
15
- const hasCredentials = Boolean(config.appId && config.appSecret);
16
- if (config.transport === "sdk" || !config.useConsoleWhenMissingCredentials) {
17
- if (!hasCredentials) {
18
- throw new Error("Feishu appId/appSecret are required.");
19
- }
20
- return "sdk";
8
+ export function requireServerFeishuTransport(config: FeishuTransportConfig): "sdk" {
9
+ if (!config.appId || !config.appSecret) {
10
+ throw new Error(
11
+ "飞书机器人尚未配置。请先运行 agent-bot init 完成初始化;仅需本地调试时请使用 agent-bot console。",
12
+ );
21
13
  }
22
-
23
- return hasCredentials ? "sdk" : "console";
14
+ return "sdk";
24
15
  }
package/src/index.ts CHANGED
@@ -15,7 +15,7 @@ import { ConsoleFeishuClient } from "./feishu/ConsoleFeishuClient.js";
15
15
  import { FeishuConnector } from "./feishu/FeishuConnector.js";
16
16
  import { FeishuMessageClient } from "./feishu/FeishuMessageClient.js";
17
17
  import { FeishuTurnPresenter } from "./feishu/FeishuTurnPresenter.js";
18
- import { resolveFeishuTransport } from "./feishu/transport.js";
18
+ import { requireServerFeishuTransport } from "./feishu/transport.js";
19
19
  import { createLogger } from "./logging/logger.js";
20
20
  import { OutboundRouter, type OutboundRoute } from "./presentation/OutboundRouter.js";
21
21
  import { ProxySessionController } from "./proxy/ProxySessionController.js";
@@ -36,6 +36,7 @@ const startupReason = process.env.AGENT_BOT_RESTART_REASON?.trim()
36
36
  || (supervised ? "Supervisor 启动" : "直接启动");
37
37
  const consoleOnly = process.env.AGENT_BOT_CONSOLE_ONLY === "1";
38
38
  const config = loadConfig();
39
+ const transport = consoleOnly ? "console" : requireServerFeishuTransport(config.feishu);
39
40
  const logger = createLogger(config);
40
41
  const store = new StateStore(config.storage.sqlitePath);
41
42
 
@@ -52,13 +53,13 @@ const codexProcessManager = new CodexProcessManager(
52
53
  const codexRuntime = new CodexRuntime(codexProcessManager, logger);
53
54
  const runtimes = new AgentRuntimeRegistry({ acp: acpRuntime, codex: codexRuntime });
54
55
 
55
- const transport = consoleOnly ? "console" : resolveFeishuTransport(config.feishu);
56
56
  const routes: OutboundRoute[] = [];
57
57
  let feishuConnector: FeishuConnector | undefined;
58
58
  let consoleConnector: ConsoleConnector | undefined;
59
59
  let startupNotifier: StartupNotifier | undefined;
60
60
  let safeRestartNotifier: SafeRestartNotifier | undefined;
61
61
  let controlServer: LocalControlServer | undefined;
62
+ let serverReady = false;
62
63
 
63
64
  const feishuOutbound = transport === "sdk" ? new FeishuMessageClient(config, logger) : undefined;
64
65
  if (feishuOutbound) {
@@ -123,10 +124,18 @@ const startControlServer = async (): Promise<void> => {
123
124
  };
124
125
 
125
126
  if (feishuConnector && startupNotifier) {
126
- await startFeishu(feishuConnector, startupNotifier, processStartedAt, startupReason, startControlServer);
127
+ await startFeishu(
128
+ feishuConnector,
129
+ startupNotifier,
130
+ processStartedAt,
131
+ startupReason,
132
+ startControlServer,
133
+ () => { serverReady = true; },
134
+ );
127
135
  } else {
128
136
  await startControlServer();
129
137
  await feishuConnector?.start();
138
+ serverReady = true;
130
139
  }
131
140
  consoleConnector?.start();
132
141
 
@@ -156,6 +165,8 @@ async function handleControlRequest(request: ControlRequest): Promise<ControlRes
156
165
  return {
157
166
  ok: true,
158
167
  data: {
168
+ ready: serverReady,
169
+ phase: serverReady ? "ready" : "connecting_feishu",
159
170
  pid: process.pid,
160
171
  startedAt: processStartedAt.toISOString(),
161
172
  supervised,
@@ -12,8 +12,10 @@ export async function startFeishu(
12
12
  startedAt: Date,
13
13
  restartReason: string,
14
14
  prepare?: () => Promise<void>,
15
+ onConnected?: () => void,
15
16
  ): Promise<void> {
16
17
  await prepare?.();
17
18
  await connector.start();
19
+ onConnected?.();
18
20
  await notifier.notify(startedAt, restartReason);
19
21
  }
package/src/supervisor.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { spawn, type ChildProcess } from "node:child_process";
2
2
  import { fileURLToPath } from "node:url";
3
- import { isServerRunning } from "./cli/LocalControlClient.js";
3
+ import { isServerReachable } from "./cli/LocalControlClient.js";
4
4
  import { controlEndpoint } from "./cli/controlProtocol.js";
5
5
  import { loadConfig } from "./config/loadConfig.js";
6
+ import { requireServerFeishuTransport } from "./feishu/transport.js";
6
7
  import {
7
8
  crashRestartDelayMs,
8
9
  describeRestartReason,
@@ -13,7 +14,9 @@ import {
13
14
  } from "./supervision/restartPolicy.js";
14
15
 
15
16
  const childEntry = fileURLToPath(new URL("./index.js", import.meta.url));
16
- const sqlitePath = loadConfig().storage.sqlitePath;
17
+ const config = loadConfig();
18
+ requireServerFeishuTransport(config.feishu);
19
+ const sqlitePath = config.storage.sqlitePath;
17
20
  const serverEndpoint = controlEndpoint(sqlitePath);
18
21
  let child: ChildProcess | undefined;
19
22
  let restartTimer: NodeJS.Timeout | undefined;
@@ -23,7 +26,7 @@ let nextStartReason = process.env.AGENT_BOT_RESTART_REASON?.trim() || "Superviso
23
26
 
24
27
  async function startChild(): Promise<void> {
25
28
  if (stopping || child) return;
26
- if (await isServerRunning(serverEndpoint)) {
29
+ if (await isServerReachable(serverEndpoint)) {
27
30
  writeSupervisorLog("existing_server_detected", { endpoint: serverEndpoint });
28
31
  process.exit(0);
29
32
  return;
@@ -64,7 +67,7 @@ async function handleChildExit(
64
67
  process.exit(0);
65
68
  return;
66
69
  }
67
- if (await isServerRunning(serverEndpoint)) {
70
+ if (await isServerReachable(serverEndpoint)) {
68
71
  writeSupervisorLog("duplicate_supervisor_stopped", { endpoint: serverEndpoint });
69
72
  process.exit(0);
70
73
  return;