Files
zerobyte/app/server/modules/lifecycle/bootstrap.ts
Nico e65a135676 feat(agents): create agent registry and service (#849)
* 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
2026-05-05 19:34:10 +02:00

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;
}
};