mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-06-02 21:16:14 -04:00
* feat(agents): create agent registry and service * fix: mark agent offline only if the session was removed properly * refactor: centralize agent backup lifecycle state * refactor: simplify session management * refactor: move effect / async boundary in one place * chore: regen migration * refactor: improve error handling * chore: pr feedback
51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
import { runDbMigrations } from "../../db/db";
|
|
import { config } from "../../core/config";
|
|
import { startAgentController, startLocalAgent, stopAgentController, stopLocalAgent } from "../agents/agents-manager";
|
|
import { agentsService } from "../agents/agents.service";
|
|
import { runMigrations } from "./migrations";
|
|
import { startup } from "./startup";
|
|
|
|
let bootstrapPromise: Promise<void> | undefined;
|
|
|
|
const runBootstrap = async () => {
|
|
await runDbMigrations();
|
|
await runMigrations();
|
|
await agentsService.ensureLocalAgent();
|
|
|
|
try {
|
|
await startAgentController();
|
|
|
|
if (config.flags.enableLocalAgent) {
|
|
await startLocalAgent();
|
|
}
|
|
|
|
await startup();
|
|
} catch (error) {
|
|
await stopLocalAgent();
|
|
await stopAgentController();
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
export const bootstrapApplication = async () => {
|
|
if (!bootstrapPromise) {
|
|
bootstrapPromise = runBootstrap();
|
|
}
|
|
|
|
try {
|
|
await bootstrapPromise;
|
|
} catch (err) {
|
|
bootstrapPromise = undefined;
|
|
throw err;
|
|
}
|
|
};
|
|
|
|
export const stopApplicationRuntime = async () => {
|
|
try {
|
|
await stopLocalAgent();
|
|
await stopAgentController();
|
|
} finally {
|
|
bootstrapPromise = undefined;
|
|
}
|
|
};
|