openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
53 lines (52 loc) • 2.8 kB
JavaScript
import { i as isUpdateRehearsalReadOnlyPath } from "./update-rehearsal-paths-FgHeU_TR.mjs";
import { t as DoctorUnreadableStateDatabaseError } from "./state-repair-message-BvQp5mZ3.mjs";
import { n as resolveRelativeSessionStoreMigrationTargets } from "./doctor-relative-session-store-paths-uvD2_8cA.mjs";
import path from "node:path";
//#region src/commands/doctor-database-preflight.ts
/** Prepare fleet facts through the artifact-preserving schema readers. */
async function prepareDoctorDatabasePreflight(options = {}) {
const { scope, preserveSourceArtifacts } = options;
const databasePreflight = await import("./openclaw-database-preflight-B5LWN22M.mjs");
const [{ createConfigIO }, targets, { listAgentIds, resolveAgentDir }, { openDoctorStateSchemaReadAdmission }] = await Promise.all([
import("./io-Cgrbekpk.mjs"),
import("./targets-5qHRX6W6.mjs"),
import("./agent-scope-config-BL6YJ64J.mjs"),
import("./openclaw-state-db-doctor-schema-acXXjvxI.mjs")
]);
const snapshot = scope === "state" || options.cfg ? void 0 : await createConfigIO({
env: { ...process.env },
observe: false,
pluginValidation: "core-only"
}).readConfigFileSnapshot();
const cfg = scope === "state" ? void 0 : options.cfg ?? snapshot?.sourceConfig ?? snapshot?.config;
let agentDatabaseMigrationDiscovery;
const databaseSchemas = await databasePreflight.preflightOpenClawDatabaseSchemas({
env: process.env,
scope,
openStateSchemaReadAdmission: openDoctorStateSchemaReadAdmission,
preserveSourceArtifacts,
...cfg ? {
configuredAgentDatabaseTargets: (registered) => [...listAgentIds(cfg).map((agentId) => ({
agentId,
path: path.join(resolveAgentDir(cfg, agentId), "openclaw-agent.sqlite")
})), ...resolveRelativeSessionStoreMigrationTargets(cfg, process.env, registered).filter((target) => !isUpdateRehearsalReadOnlyPath(target.path, process.env))],
configuredAgentDatabaseCandidatePaths: targets.resolveConfiguredAgentDatabaseCandidatePaths(cfg, { env: process.env }),
agentAdmissionConfig: cfg,
onAgentDatabaseDiscovery: (prepared) => {
agentDatabaseMigrationDiscovery = prepared;
}
} : {}
});
if (databaseSchemas.incompatible.length > 0) throw new databasePreflight.OpenClawDatabaseSchemaPreflightError(databaseSchemas.incompatible, { operation: "doctor" });
const unreadableStateDatabase = databaseSchemas.indeterminate.find((database) => database.kind === "state");
if (unreadableStateDatabase) throw new DoctorUnreadableStateDatabaseError(unreadableStateDatabase.path, unreadableStateDatabase.reason);
return {
...databaseSchemas,
...agentDatabaseMigrationDiscovery ? {
agentDatabaseMigrationDiscovery,
agentDatabaseRecoveryConfigValid: snapshot?.valid === true
} : {}
};
}
//#endregion
export { prepareDoctorDatabasePreflight as t };