openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
100 lines (99 loc) • 3.64 kB
JavaScript
import { l as pathExists } from "../../utils-P__uGsPB.js";
import "../../text-utility-runtime-BjzvUG99.js";
import { n as migrateCanvasHostConfig, r as resolveLegacyCanvasDocumentsDir, t as listLegacyCanvasDocumentIds } from "../../config-migration-BHn_68oV.js";
import path from "node:path";
import fs from "node:fs/promises";
//#region extensions/canvas/doctor-contract-api.ts
const RETIRED_CANVAS_HOST_CONFIG_PATH = [
"plugins",
"entries",
"canvas",
"config",
"host"
];
/** Retired Canvas file-host settings detected before strict plugin validation. */
const legacyConfigRules = [{
path: ["canvasHost"],
message: "canvasHost is retired; only plugins.entries.canvas.config.host.enabled remains. Run \"openclaw doctor --fix\"."
}, ...[
"root",
"port",
"liveReload"
].map((key) => ({
path: [...RETIRED_CANVAS_HOST_CONFIG_PATH, key],
message: `${[...RETIRED_CANVAS_HOST_CONFIG_PATH, key].join(".")} is retired. Run "openclaw doctor --fix".`
}))];
/** Removes retired file-host config while preserving the surviving enablement switch. */
function normalizeCompatibilityConfig({ cfg }) {
return migrateCanvasHostConfig(cfg) ?? {
config: cfg,
changes: []
};
}
const stateMigrations = [{
id: "canvas-custom-root-documents-to-core",
label: "Canvas documents in a custom host root",
async detectLegacyState(params) {
const legacyDir = resolveLegacyCanvasDocumentsDir(params);
if (!legacyDir) return null;
const documentIds = listLegacyCanvasDocumentIds(legacyDir);
if (documentIds.length === 0) return null;
return { preview: [`- Canvas documents: ${legacyDir} -> ${path.resolve(params.stateDir, "canvas", "documents")} (${documentIds.length} document(s))`] };
},
async migrateLegacyState(params) {
const changes = [];
const warnings = [];
const legacyDir = resolveLegacyCanvasDocumentsDir(params);
if (!legacyDir) return {
changes,
warnings
};
const documentIds = listLegacyCanvasDocumentIds(legacyDir);
if (documentIds.length === 0) return {
changes,
warnings
};
const coreDir = path.resolve(params.stateDir, "canvas", "documents");
await fs.mkdir(coreDir, { recursive: true });
let migrated = 0;
for (const documentId of documentIds) {
const sourceDir = path.join(legacyDir, documentId);
const targetDir = path.join(coreDir, documentId);
let tempParent;
try {
if (await pathExists(targetDir)) throw new Error("core target already exists");
tempParent = await fs.mkdtemp(path.join(coreDir, ".canvas-migrate-"));
const tempDocumentDir = path.join(tempParent, documentId);
await fs.cp(sourceDir, tempDocumentDir, {
recursive: true,
errorOnExist: true,
force: false
});
if (await pathExists(targetDir)) throw new Error("core target was created during migration");
await fs.rename(tempDocumentDir, targetDir);
await fs.rm(sourceDir, {
recursive: true,
force: true
});
migrated += 1;
} catch (error) {
warnings.push(`Skipped Canvas document ${documentId}; core target may already exist: ${String(error)}. Keep plugins.entries.canvas.config.host.root, resolve the copy or target conflict, then rerun "openclaw doctor --fix".`);
} finally {
if (tempParent) await fs.rm(tempParent, {
recursive: true,
force: true
}).catch(() => void 0);
}
}
if (migrated > 0) changes.push(`Migrated ${migrated} Canvas document(s) into core storage`);
try {
if ((await fs.readdir(legacyDir)).length === 0) await fs.rmdir(legacyDir);
} catch {}
return {
changes,
warnings
};
}
}];
//#endregion
export { legacyConfigRules, normalizeCompatibilityConfig, stateMigrations };