openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
95 lines (94 loc) • 3.25 kB
JavaScript
import { i as isMissingPathError } from "./errno-DFcoqIT9.mjs";
import { c as getPluginCacheRoot } from "./plugin-cache-B_eRuqTM.mjs";
import { a as pluginCacheRealpathSync, r as pluginCacheExistsSync, s as readPluginCacheDirectory } from "./plugin-cache-files-e1aGp2KM.mjs";
import { h as resolvePreferredBundledRootArtifact, m as resolvePluginRuntimeExecutionArtifact } from "./bundled-dir-BKvdAqkP.mjs";
import { fileURLToPath } from "node:url";
import path from "node:path";
//#region src/plugins/root-artifact-path.ts
/** Resolves artifact paths in the caller's layout and filename preference order. */
function resolvePluginRootArtifactPath(e, t) {
let n;
let r = false;
for (const i of t) {
const t = path.join(e, i);
if (path.dirname(i) !== ".") {
const e = path.dirname(t);
if (e !== n) {
try {
r = readPluginCacheDirectory(e).length === 0;
} catch (e) {
r = isMissingPathError(e);
}
n = e;
}
if (r) continue;
}
if (pluginCacheExistsSync(t)) return t;
}
return null;
}
//#endregion
//#region src/plugins/doctor-contract-artifact.ts
/** Resolves the Doctor artifact shared by loading, index hashing, and freshness. */
const CONTRACT_API_EXTENSIONS = [
".js",
".mjs",
".cjs",
".ts",
".mts",
".cts"
];
const CURRENT_MODULE_PATH = fileURLToPath(import.meta.url);
const RUNNING_FROM_BUILT_ARTIFACT = CURRENT_MODULE_PATH.includes(`${path.sep}dist${path.sep}`) || CURRENT_MODULE_PATH.includes(`${path.sep}dist-runtime${path.sep}`);
const ORDERED_EXTENSIONS = RUNNING_FROM_BUILT_ARTIFACT ? CONTRACT_API_EXTENSIONS : [...CONTRACT_API_EXTENSIONS.slice(3), ...CONTRACT_API_EXTENSIONS.slice(0, 3)];
const ARTIFACT_CANDIDATES = ["doctor-contract-api", "contract-api"].map((e) => {
const t = ORDERED_EXTENSIONS.map((t) => `${e}${t}`);
return {
rootPaths: t,
paths: t.flatMap((e) => [e, path.join("dist", e)])
};
});
function resolvePluginDoctorContractArtifact(e) {
const t = getPluginCacheRoot(e.rootDir).artifacts;
const n = JSON.stringify([
"doctor-contract",
RUNNING_FROM_BUILT_ARTIFACT,
e.origin,
e.sourcePreferred === true,
e.packageManifest?.build?.bundledDist
]);
const r = t.get(n);
if (r !== void 0) return r;
for (const { rootPaths: r, paths: i } of ARTIFACT_CANDIDATES) {
const a = resolvePluginRootArtifactPath(e.rootDir, i);
if (!a) continue;
let o = {
modulePath: a,
boundaryRoot: e.rootDir
};
if (RUNNING_FROM_BUILT_ARTIFACT && e.origin === "bundled" && !e.sourcePreferred) {
const t = e.packageManifest?.build?.bundledDist === false ? resolvePluginRootArtifactPath(e.rootDir, r) : r.includes(path.relative(e.rootDir, a)) ? a : null;
if (t) {
const n = resolvePluginRuntimeExecutionArtifact(resolvePreferredBundledRootArtifact({
rootDir: e.rootDir,
source: t,
packageManifest: e.packageManifest
}));
o = {
modulePath: n.source,
boundaryRoot: n.rootDir
};
}
}
const s = {
modulePath: pluginCacheRealpathSync(o.modulePath) ?? o.modulePath,
boundaryRoot: pluginCacheRealpathSync(o.boundaryRoot) ?? o.boundaryRoot
};
t.set(n, s);
return s;
}
t.set(n, null);
return null;
}
//#endregion
export { resolvePluginRootArtifactPath as n, resolvePluginDoctorContractArtifact as t };