openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
56 lines (55 loc) • 2.44 kB
JavaScript
import { i as truncateWithMarker } from "./utf16-slice-D_ngcYKd.js";
import { p as redactSensitiveText } from "./redact-BtvPPfTi.js";
import { t as createSubsystemLogger } from "./subsystem-Dy2tqXOS.js";
import { n as sanitizeTerminalText } from "./safe-text-BGBqp1a4.js";
//#region src/infra/state-migrations.messages.ts
const STARTUP_MIGRATION_FOLLOW_UP = "Run \"openclaw doctor --fix\" against the same state/config, then restart the gateway.";
function formatStartupMigrationFailure(errors) {
return [
"OpenClaw startup migrations did not complete cleanly; refusing to report the gateway ready.",
...errors.map((error) => `- ${error}`),
STARTUP_MIGRATION_FOLLOW_UP
].join("\n");
}
let startupMigrationWarning;
/** The running Gateway owns this boot fact; status and Doctor must not rerun migrations to infer it. */
function recordStartupMigrationWarnings(warnings) {
if (warnings.length === 0) return;
const details = sanitizeTerminalText(redactSensitiveText([...new Set(warnings)].map((warning) => `- ${warning}`).join("\n"), { mode: "tools" }));
const summary = `${truncateWithMarker(details, 2e3, {
marker: "… (see startup log)",
reserve: 20,
trimEnd: true
})}\n${STARTUP_MIGRATION_FOLLOW_UP}`;
if (startupMigrationWarning !== summary) {
startupMigrationWarning = summary;
createSubsystemLogger("state-migrations").warn(`Startup migration warnings; continuing with degraded state.\n${details}\n${STARTUP_MIGRATION_FOLLOW_UP}`);
}
}
function readStartupMigrationWarning(includeSensitive = true) {
return startupMigrationWarning && (includeSensitive ? startupMigrationWarning : `Startup migrations need attention. ${STARTUP_MIGRATION_FOLLOW_UP}`);
}
function mergeNotices(sources) {
return [...new Set(sources.flatMap((source) => source?.notices ? [...source.notices] : []))];
}
function logStateMigrationResult(result, logger = createSubsystemLogger("state-migrations")) {
for (const [key, title, level] of [
[
"changes",
"Auto-migrated legacy state",
"info"
],
[
"warnings",
"Legacy state migration warnings",
"warn"
],
[
"notices",
"Legacy state migration notes",
"info"
]
]) if (result[key]?.length) logger[level](`${title}:\n${result[key].map((entry) => `- ${entry}`).join("\n")}`);
}
//#endregion
export { recordStartupMigrationWarnings as a, readStartupMigrationWarning as i, logStateMigrationResult as n, mergeNotices as r, formatStartupMigrationFailure as t };