|
| 1 | +// CUA config migrations belong to the plugin so doctor can repair a shipped |
| 2 | +// driverPath setting before strict manifest validation reaches this plugin. |
| 3 | +import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts"; |
| 4 | +import { asObjectRecord } from "openclaw/plugin-sdk/runtime-doctor"; |
| 5 | + |
| 6 | +const DRIVER_PATH = ["plugins", "entries", "cua-computer", "config", "driverPath"]; |
| 7 | + |
| 8 | +/** Retired CUA daemon configuration that `openclaw doctor --fix` removes. */ |
| 9 | +export const legacyConfigRules = [ |
| 10 | + { |
| 11 | + path: DRIVER_PATH, |
| 12 | + message: |
| 13 | + 'plugins.entries.cua-computer.config.driverPath is retired; the CUA Driver SDK is configured directly by OpenClaw. Run "openclaw doctor --fix".', |
| 14 | + }, |
| 15 | +]; |
| 16 | + |
| 17 | +/** Removes the retired daemon path without making it a runtime compatibility key. */ |
| 18 | +export function normalizeCompatibilityConfig({ cfg }: { cfg: OpenClawConfig }): { |
| 19 | + config: OpenClawConfig; |
| 20 | + changes: string[]; |
| 21 | +} { |
| 22 | + const entry = asObjectRecord(cfg.plugins?.entries?.["cua-computer"]); |
| 23 | + const pluginConfig = asObjectRecord(entry?.config); |
| 24 | + if (!pluginConfig || !Object.hasOwn(pluginConfig, "driverPath")) { |
| 25 | + return { config: cfg, changes: [] }; |
| 26 | + } |
| 27 | + |
| 28 | + const nextConfig = structuredClone(cfg); |
| 29 | + const nextEntry = asObjectRecord(nextConfig.plugins?.entries?.["cua-computer"]); |
| 30 | + const nextPluginConfig = asObjectRecord(nextEntry?.config); |
| 31 | + if (!nextPluginConfig) { |
| 32 | + return { config: cfg, changes: [] }; |
| 33 | + } |
| 34 | + delete nextPluginConfig.driverPath; |
| 35 | + |
| 36 | + return { |
| 37 | + config: nextConfig, |
| 38 | + changes: [ |
| 39 | + "Removed retired plugins.entries.cua-computer.config.driverPath; CUA Driver SDK is configured directly by OpenClaw.", |
| 40 | + ], |
| 41 | + }; |
| 42 | +} |
0 commit comments