UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

79 lines (78 loc) 4.94 kB
import { a as getPluginCache, f as withPluginCache, i as createPluginCache } from "./plugin-cache-DGWspMEc.js"; import { r as createLazyRuntimeModule } from "./lazy-runtime-CgCh8H_K.js"; import { s as readConfigFileSnapshot, u as readConfigFileSnapshotWithPluginMetadata } from "./io.runtime-B9iJRs3w.js"; import { n as sanitizeTerminalText } from "./safe-text-BGBqp1a4.js"; import "./io-bdCzpGWJ.js"; import { t as addDoctorLegacyIssues } from "./legacy-config-issues-Bz1S8JF8.js"; import { t as completeDoctorPluginMetadataSnapshot } from "./plugin-metadata-snapshot-scope-BQf8TDa9.js"; //#region src/commands/doctor-config-preflight-plugin-index.ts const loadInstalledPluginIndexStoreWrite = createLazyRuntimeModule(() => import("./installed-plugin-index-store-write-CCiAI2D9.js")); function throwPluginRegistryPersistenceFailed(reason, repair = "Run \"openclaw doctor --fix\" and retry.") { throw new Error(`OpenClaw refreshed the plugin registry but could not verify the persisted replacement (${reason}); refusing to write the migration checkpoint. ${repair}`); } function formatPluginRegistryDifferences(snapshot) { const differences = new Map(snapshot?.registryDiagnostics.flatMap((diagnostic) => diagnostic.differences ?? []).map((difference) => [JSON.stringify(difference), difference])); if (differences.size === 0) return; return [...differences.values()].toSorted((left, right) => [ left.pluginId, left.persistedSource, left.derivedSource ].join("\0").localeCompare([ right.pluginId, right.persistedSource, right.derivedSource ].join("\0"))).map((difference) => `${sanitizeTerminalText(difference.pluginId)} (persisted source: ${JSON.stringify(difference.persistedSource)}; derived source: ${JSON.stringify(difference.derivedSource)})`).join(", "); } async function readDoctorConfigPreflightSnapshot(params) { const cache = params.allowCurrentPluginMetadata ? getPluginCache() : createPluginCache(); return withPluginCache(cache, async () => { const sharedOptions = { ...params.observe === false ? { observe: false } : {}, ...params.measure ? { measure: params.measure } : {}, ...params.allowCurrentPluginMetadata ? {} : { allowCurrentPluginMetadata: false } }; if (params.includePluginMetadata && !params.skipPluginValidation) { const result = await readConfigFileSnapshotWithPluginMetadata(sharedOptions); const pluginMetadataSnapshot = params.preparePluginMetadataSnapshot ? completeDoctorPluginMetadataSnapshot({ snapshot: result.pluginMetadataSnapshot, config: result.snapshot.sourceConfig ?? result.snapshot.config ?? {} }) : result.pluginMetadataSnapshot; return { snapshot: addDoctorLegacyIssues(result.snapshot, pluginMetadataSnapshot), pluginMigrationFingerprint: pluginMetadataSnapshot?.configFingerprint?.trim() || null, ...pluginMetadataSnapshot ? { pluginMetadataSnapshot } : {} }; } return { snapshot: addDoctorLegacyIssues(await readConfigFileSnapshot({ ...sharedOptions, skipPluginValidation: params.skipPluginValidation })), pluginMigrationFingerprint: null }; }); } function needsRefreshedPluginIndexPersistence(snapshotRead) { return snapshotRead.pluginMetadataSnapshot?.registrySource === "derived"; } async function persistRefreshedPluginIndex(params) { const derivedPluginMetadataSnapshot = params.snapshotRead.pluginMetadataSnapshot; if (!derivedPluginMetadataSnapshot || !params.snapshotRead.pluginMigrationFingerprint) throwPluginRegistryPersistenceFailed("derived metadata was incomplete"); const lease = params.lease; if (!lease) throwPluginRegistryPersistenceFailed("startup migration lease was not acquired"); const { writePersistedInstalledPluginIndexWithLeaseSync } = await params.measure("plugin-index-store-import", loadInstalledPluginIndexStoreWrite); await params.measure("plugin-index-persistence", () => writePersistedInstalledPluginIndexWithLeaseSync(derivedPluginMetadataSnapshot.registryIndex, { env: params.env, lease })); const persistedSnapshotRead = await params.readPersistedSnapshot(); const persistedPluginMetadataSnapshot = persistedSnapshotRead.pluginMetadataSnapshot; if (persistedPluginMetadataSnapshot?.registrySource !== "persisted") { const diagnosticCodes = persistedPluginMetadataSnapshot?.registryDiagnostics.map((diagnostic) => diagnostic.code); const differences = formatPluginRegistryDifferences(persistedPluginMetadataSnapshot); throwPluginRegistryPersistenceFailed(`reread source was ${persistedPluginMetadataSnapshot?.registrySource ?? "missing"}${differences ? `; differences: ${differences}` : ""}${diagnosticCodes?.length ? `; diagnostics: ${diagnosticCodes.join(", ")}` : ""}`, "Stop plugin package changes, run \"openclaw plugins registry --refresh\", then retry."); } return persistedSnapshotRead; } //#endregion export { persistRefreshedPluginIndex as n, readDoctorConfigPreflightSnapshot as r, needsRefreshedPluginIndexPersistence as t };