openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
77 lines (76 loc) • 3.07 kB
JavaScript
import { d as resolveConfigDir } from "./utils-P__uGsPB.js";
import { i as loadBundledPluginPublicSurfaceModuleSyncCore } from "./facade-loader-CVT-xVW5.js";
import { t as note } from "./note-DqHk3fA1.js";
import fs from "node:fs";
import path from "node:path";
//#region src/commands/doctor-browser.ts
/** Facade-backed doctor checks and cleanup for bundled browser plugin state. */
function loadBrowserDoctorSurface() {
return loadBundledPluginPublicSurfaceModuleSyncCore({
dirName: "browser",
artifactBasename: "browser-doctor.js"
});
}
/** Repairs only already-owned Chrome native-host registration drift. */
async function maybeRepairOwnedChromeExtensionNativeHosts() {
try {
const repair = loadBrowserDoctorSurface().maybeRepairOwnedChromeExtensionNativeHosts;
return repair ? await repair() : {
changes: [],
warnings: []
};
} catch (error) {
return {
changes: [],
warnings: [`Browser extension native-host repair is unavailable: ${error instanceof Error ? error.message : String(error)}`]
};
}
}
function mayHaveLegacyClawdBrowserProfileResidue(deps) {
const configDir = deps?.configDir ?? resolveConfigDir(deps?.env ?? process.env);
const legacyProfileDir = path.join(configDir, "browser", "clawd");
const legacyUserDataDir = path.join(legacyProfileDir, "user-data");
const pathExists = deps?.pathExists ?? fs.existsSync;
try {
return pathExists(legacyProfileDir) || pathExists(legacyUserDataDir);
} catch {
return true;
}
}
/** Emits browser readiness notes through the bundled browser plugin doctor surface. */
async function noteChromeMcpBrowserReadiness(cfg, deps) {
try {
await loadBrowserDoctorSurface().noteChromeMcpBrowserReadiness(cfg, deps);
} catch (error) {
(deps?.noteFn ?? note)(`- Browser health check is unavailable: ${error instanceof Error ? error.message : String(error)}`, "Browser");
}
}
/** Detects old clawd browser profile residue without loading plugin cleanup when paths are absent. */
async function detectLegacyClawdBrowserProfileResidue(cfg, deps) {
if (!mayHaveLegacyClawdBrowserProfileResidue(deps)) return null;
const detect = loadBrowserDoctorSurface().detectLegacyClawdBrowserProfileResidue;
if (!detect) return null;
return detect(cfg, deps);
}
/** Archives legacy clawd browser profile residue through the browser plugin repair hook. */
async function maybeArchiveLegacyClawdBrowserProfileResidue(cfg, deps) {
if (!mayHaveLegacyClawdBrowserProfileResidue(deps)) return {
changes: [],
warnings: []
};
try {
const repair = loadBrowserDoctorSurface().maybeArchiveLegacyClawdBrowserProfileResidue;
if (!repair) return {
changes: [],
warnings: []
};
return await repair(cfg, deps);
} catch (error) {
return {
changes: [],
warnings: [`Browser profile cleanup is unavailable: ${error instanceof Error ? error.message : String(error)}`]
};
}
}
//#endregion
export { noteChromeMcpBrowserReadiness as i, maybeArchiveLegacyClawdBrowserProfileResidue as n, maybeRepairOwnedChromeExtensionNativeHosts as r, detectLegacyClawdBrowserProfileResidue as t };