fix: hot reload agents
This commit is contained in:
parent
8374bc0496
commit
9dbb94fce0
2 changed files with 20 additions and 8 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import type { ChildProcess } from "node:child_process";
|
||||
import { createAgentManagerRuntime, type AgentManagerRuntime } from "./controller/server";
|
||||
import type { AgentManagerRuntime } from "./controller/server";
|
||||
import { spawnLocalAgentProcess, stopLocalAgentProcess } from "./local/process";
|
||||
|
||||
export type { AgentBackupEventHandlers } from "./controller/server";
|
||||
|
||||
type AgentRuntimeState = {
|
||||
agentManager: AgentManagerRuntime;
|
||||
agentManager: AgentManagerRuntime | null;
|
||||
localAgent: ChildProcess | null;
|
||||
};
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ const getAgentRuntimeState = () => {
|
|||
}
|
||||
|
||||
const runtime = {
|
||||
agentManager: createAgentManagerRuntime(),
|
||||
agentManager: null,
|
||||
localAgent: null,
|
||||
};
|
||||
|
||||
|
|
@ -32,6 +32,20 @@ const getAgentRuntimeState = () => {
|
|||
|
||||
const getAgentManagerRuntime = () => getAgentRuntimeState().agentManager;
|
||||
|
||||
export const startAgentRuntime = async () => {
|
||||
const runtime = getAgentRuntimeState();
|
||||
|
||||
if (runtime.agentManager) {
|
||||
await runtime.agentManager.stop();
|
||||
}
|
||||
|
||||
const { createAgentManagerRuntime } = await import("./controller/server");
|
||||
const agentManager = createAgentManagerRuntime();
|
||||
|
||||
await agentManager.start();
|
||||
runtime.agentManager = agentManager;
|
||||
};
|
||||
|
||||
export const spawnLocalAgent = async () => {
|
||||
await spawnLocalAgentProcess(getAgentRuntimeState());
|
||||
};
|
||||
|
|
@ -40,9 +54,7 @@ export const stopLocalAgent = async () => {
|
|||
await stopLocalAgentProcess(getAgentRuntimeState());
|
||||
};
|
||||
|
||||
export const agentManager = getAgentManagerRuntime();
|
||||
|
||||
export const stopAgentRuntime = async () => {
|
||||
await getAgentManagerRuntime().stop();
|
||||
await getAgentManagerRuntime()?.stop();
|
||||
await stopLocalAgent();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { runDbMigrations } from "../../db/db";
|
||||
import { agentManager, spawnLocalAgent, stopAgentRuntime } from "../agents/agents-manager";
|
||||
import { spawnLocalAgent, startAgentRuntime, stopAgentRuntime } from "../agents/agents-manager";
|
||||
import { runMigrations } from "./migrations";
|
||||
import { startup } from "./startup";
|
||||
|
||||
|
|
@ -9,7 +9,7 @@ const runBootstrap = async () => {
|
|||
await runDbMigrations();
|
||||
await runMigrations();
|
||||
if (process.env.ENABLE_LOCAL_AGENT === "true") {
|
||||
await agentManager.start();
|
||||
await startAgentRuntime();
|
||||
await spawnLocalAgent();
|
||||
}
|
||||
await startup();
|
||||
|
|
|
|||
Loading…
Reference in a new issue