UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

112 lines (111 loc) • 4.19 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { m as normalizeTrimmedStringList } from "./string-normalization-DLmfYZXI.mjs"; import { p as shortenHomePath } from "./utils-C8YECn2Q.mjs"; import { Jn as string, Un as record, sr as unknown } from "./schemas-Cy6abvsu.mjs"; import { n as safeParseWithSchema, t as safeParseJsonWithSchema } from "./zod-parse-Bqd52uSa.mjs"; import { t as loadPluginManifestRegistryCore } from "./manifest-registry-CuWv8ibc.mjs"; import { t as note } from "./note-CnLgHvug.mjs"; import fs from "node:fs"; import path from "node:path"; import { isUtf8 } from "node:buffer"; //#region src/commands/doctor-plugin-manifests.ts const LEGACY_MANIFEST_CONTRACT_KEYS = [ "speechProviders", "mediaUnderstandingProviders", "imageGenerationProviders", "tools" ]; const LEGACY_PLUGIN_MANIFESTS_CHECK_ID = "core/doctor/legacy-plugin-manifests"; const JsonRecordSchema = record(string(), unknown()); function manifestSeenKey(e) { try { return fs.realpathSync.native(e); } catch { return path.resolve(e); } } function buildLegacyManifestContractMigration(e) { const t = { ...e.raw }; const n = safeParseWithSchema(JsonRecordSchema, e.raw.contracts); const r = n ? { ...n } : {}; const i = []; for (const n of LEGACY_MANIFEST_CONTRACT_KEYS) { if (!(n in e.raw)) continue; const a = normalizeTrimmedStringList(e.raw[n]); const o = normalizeTrimmedStringList(r[n]); if (a.length > 0 && o.length === 0) { r[n] = a; i.push(`- ${shortenHomePath(e.manifestPath)}: moved ${n} to contracts.${n}`); } else i.push(`- ${shortenHomePath(e.manifestPath)}: removed legacy ${n} (kept contracts.${n})`); delete t[n]; } if (i.length === 0) return null; if (Object.keys(r).length > 0) t.contracts = r; else delete t.contracts; const a = normalizeOptionalString(e.raw.id) ?? e.manifestPath; return { manifestPath: e.manifestPath, pluginId: a, nextRaw: t, changeLines: i }; } function collectLegacyPluginManifestContractMigrations(e) { const t = /* @__PURE__ */ new Set(); const n = []; for (const { manifestPath: r } of loadPluginManifestRegistryCore(e).plugins) { const i = manifestSeenKey(r); if (t.has(i)) continue; t.add(i); let a; try { const t = fs.readFileSync(r); if (!isUtf8(t)) { e.runtime?.error("Invalid UTF-8; plugin manifest left unchanged:", r); continue; } a = safeParseJsonWithSchema(JsonRecordSchema, t.toString("utf-8")); } catch { continue; } const o = a && buildLegacyManifestContractMigration({ manifestPath: r, raw: a }); if (o) n.push(o); } return n.toSorted((e, t) => e.manifestPath.localeCompare(t.manifestPath)); } function legacyPluginManifestContractMigrationToHealthFinding(e) { return { checkId: LEGACY_PLUGIN_MANIFESTS_CHECK_ID, severity: "warning", category: "fix-now", docsUrl: "https://docs.openclaw.ai/cli/doctor/checks", message: `Plugin manifest ${e.pluginId} uses legacy top-level capability keys.`, path: e.manifestPath, target: e.pluginId, requirement: "contracts-capability-keys", fixHint: "Run `openclaw doctor --fix` to rewrite legacy plugin manifest capability keys under contracts.*." }; } async function maybeRepairLegacyPluginManifestContracts(e) { const t = collectLegacyPluginManifestContractMigrations(e); if (t.length === 0) return false; note(["Legacy plugin manifest capability keys detected.", ...t.flatMap((e) => e.changeLines)].join("\n"), "Plugin manifests"); if (!(e.prompter.shouldRepair || await e.prompter.confirmAutoFix({ message: "Rewrite legacy plugin manifest capability keys into contracts now?", initialValue: true }))) return false; const n = []; for (const r of t) try { fs.writeFileSync(r.manifestPath, `${JSON.stringify(r.nextRaw, null, 2)}\n`, "utf-8"); n.push(...r.changeLines); } catch (t) { e.runtime.error(`Failed to rewrite legacy plugin manifest at ${r.manifestPath}: ${String(t)}`); } if (n.length > 0) note(n.join("\n"), "Doctor changes"); return n.length > 0; } //#endregion export { collectLegacyPluginManifestContractMigrations, legacyPluginManifestContractMigrationToHealthFinding, maybeRepairLegacyPluginManifestContracts };