openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
109 lines (108 loc) • 4.57 kB
JavaScript
import { n as resolveOpenClawPackageRoot } from "./openclaw-root-C-ayo09z.mjs";
import { o as resolveRuntimeServiceBuildId } from "./version-GlxUMdxI.mjs";
import { n as runCommandWithTimeout } from "./exec-runner-Br73vG-X.mjs";
import "./exec-aRIvS9s4.mjs";
import { n as ensureControlUiAssetsBuilt, o as resolveControlUiAssetHealth, r as formatControlUiSourceCommand, s as resolveControlUiDistIndexPathForRoot } from "./control-ui-assets-DgSDpYwf.mjs";
import { n as readInstallOwner, t as formatInstallOwnerMessage } from "./install-owner-DDPQXcjQ.mjs";
import { t as note } from "./note-CnLgHvug.mjs";
import path from "node:path";
import fs from "node:fs/promises";
//#region src/commands/doctor-ui.ts
async function detectUiProtocolFreshnessIssues() {
const e = await resolveOpenClawPackageRoot({
moduleUrl: import.meta.url,
argv1: process.argv[1],
cwd: process.cwd()
});
if (!e) return [];
const t = await readInstallOwner(e);
const n = await resolveControlUiAssetHealth({
root: e,
expectedBuildId: resolveRuntimeServiceBuildId()
});
const r = n.indexPath ?? resolveControlUiDistIndexPathForRoot(e);
try {
const i = !t && await fs.stat(path.join(e, "ui/package.json")).then(() => true, () => false);
const a = {
root: e,
uiIndexPath: r,
canBuild: i,
...t ? { installOwner: t } : {}
};
if (n.kind !== "ready") return [n.kind === "stale" ? {
...a,
kind: "stale-assets",
changesSinceBuild: []
} : {
...a,
kind: "missing-assets"
}];
if (!i) return [];
const o = (await fs.stat(r)).mtime;
const s = await runCommandWithTimeout([
"git",
"-C",
e,
"log",
`--since=${o.toISOString()}`,
"--format=%h %s",
"packages/gateway-protocol/src"
], { timeoutMs: 5e3 });
const c = s.code === 0 ? s.stdout.trim() : "";
if (!c) return [];
return [{
...a,
kind: "stale-assets",
changesSinceBuild: c.split("\n")
}];
} catch {
return [];
}
}
function uiProtocolFreshnessIssueToHealthFinding(e) {
return {
checkId: "core/doctor/ui-protocol-freshness",
severity: "warning",
category: "fix-now",
docsUrl: "https://docs.openclaw.ai/web/control-ui",
message: formatUiProtocolFreshnessIssue(e),
path: e.uiIndexPath,
fixHint: e.installOwner ? formatInstallOwnerMessage(e.installOwner) : e.canBuild ? e.kind === "missing-assets" ? "Run `openclaw doctor --fix` to build Control UI assets." : `Run \`openclaw doctor --fix --force\` to rebuild Control UI assets, or run \`${formatControlUiSourceCommand(e.root, "build")}\`.` : "Reinstall OpenClaw to restore bundled Control UI assets."
};
}
function uiProtocolFreshnessIssueToRepairEffects(e) {
if (!e.canBuild) return [];
return [{
kind: "process",
action: e.kind === "missing-assets" ? "would-build-control-ui" : "would-rebuild-control-ui",
target: e.root,
dryRunSafe: false
}];
}
function formatUiProtocolFreshnessIssue(e) {
return [e.kind === "missing-assets" ? "- Control UI assets are missing or incomplete." : e.changesSinceBuild.length === 0 ? "Control UI assets do not match the current Gateway build." : `UI assets are older than the protocol schema.\nFunctional changes since last build:\n${e.changesSinceBuild.map((e) => `- ${e}`).join("\n")}`, e.installOwner ? formatInstallOwnerMessage(e.installOwner) : e.canBuild ? `- Run: ${formatControlUiSourceCommand(e.root, "build")}` : "- Reinstall OpenClaw to restore bundled Control UI assets."].join("\n");
}
async function maybeRepairUiProtocolFreshness(e, t) {
for (const n of await detectUiProtocolFreshnessIssues()) {
const r = n.kind === "stale-assets";
note(formatUiProtocolFreshnessIssue(n), r ? "UI Freshness" : "UI");
if (n.installOwner) continue;
if (!n.canBuild) {
note(`Skipping UI ${r ? "rebuild" : "build"}: ui/ sources not present.`, "UI");
continue;
}
if (!await t[r ? "confirmAggressiveAutoFix" : "confirmAutoFix"]({
message: r ? "Rebuild stale Control UI assets now?" : "Build Control UI assets now?",
initialValue: true
})) continue;
const i = await ensureControlUiAssetsBuilt(e, {
root: n.root,
expectedBuildId: resolveRuntimeServiceBuildId(),
force: r,
onBuildStart: () => note(`${r ? "Rebuilding stale" : "Building Control"} UI assets... (this may take a moment)`, "UI")
});
note(i.ok ? `UI ${r ? "rebuild" : "build"} complete.` : i.message ?? `UI ${r ? "rebuild" : "build"} failed.`, "UI");
}
}
//#endregion
export { uiProtocolFreshnessIssueToRepairEffects as i, maybeRepairUiProtocolFreshness as n, uiProtocolFreshnessIssueToHealthFinding as r, detectUiProtocolFreshnessIssues as t };