openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
109 lines (108 loc) • 3.14 kB
JavaScript
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { i as matchRootFileOpenFailure } from "./boundary-file-read-BfaFLDqt.mjs";
import "./utils-C8YECn2Q.mjs";
import { c as readPluginCacheFile, n as parsePluginCacheJson } from "./plugin-cache-files-e1aGp2KM.mjs";
import { p as resolveEffectivePluginActivationState, u as normalizePluginsConfig } from "./config-state-B1JlHgba.mjs";
import { t as applyMergePatch } from "./merge-patch-D-7aajuy.mjs";
import { n as loadPluginManifestRegistryForPluginRegistry } from "./plugin-registry-contributions-iAw3gSDD.mjs";
import "./plugin-registry-BrQav-kR.mjs";
//#region src/plugins/bundle-config-shared.ts
function extractBundleServerMap(e, t) {
if (!isRecord(e)) return {};
let n = e;
for (const r of t) if (isRecord(e[r])) {
n = e[r];
break;
}
const r = {};
for (const [e, t] of Object.entries(n)) if (isRecord(t)) r[e] = { ...t };
return r;
}
function readBundleJsonObject(e) {
const t = readPluginCacheFile({
rootDir: e.rootDir,
relativePath: e.relativePath,
rejectHardlinks: true,
maxBytes: null
});
if (!t.ok && t.failurePhase !== "read") {
if (e.allowMissing === void 0) return {
ok: true,
raw: {}
};
return matchRootFileOpenFailure(t.failure, {
path: () => e.allowMissing ? {
ok: true,
raw: {}
} : {
ok: false,
error: `unable to read ${e.relativePath}: path`,
reason: "open"
},
fallback: (t) => ({
ok: false,
error: `unable to read ${e.relativePath}: ${t.reason}`,
reason: "open"
})
});
}
const n = t.ok ? parsePluginCacheJson(t) : {
ok: false,
error: t.failure.error
};
if (!n.ok) return {
ok: false,
error: `failed to parse ${e.relativePath}: ${String(n.error)}`
};
return isRecord(n.value) ? {
ok: true,
raw: structuredClone(n.value)
} : {
ok: false,
error: `${e.relativePath} must contain a JSON object`
};
}
function loadEnabledBundleConfig(e) {
const t = normalizePluginsConfig(e.cfg?.plugins);
if (!t.enabled) return {
config: e.createEmptyConfig(),
diagnostics: []
};
const n = e.manifestRegistry ?? loadPluginManifestRegistryForPluginRegistry({
workspaceDir: e.workspaceDir,
config: e.cfg,
includeDisabled: true
});
const r = [];
let i = e.createEmptyConfig();
for (const a of n.plugins) {
const n = a.format === "bundle" && Boolean(a.bundleFormat);
const o = a.format !== "bundle" && e.loadNativePluginConfig !== void 0;
if (!n && !o) continue;
if (!resolveEffectivePluginActivationState({
id: a.id,
origin: a.origin,
channelIds: a.channels,
config: t,
rootConfig: e.cfg,
enabledByDefault: a.enabledByDefault
}).activated) continue;
const s = n && a.bundleFormat ? e.loadBundleConfig({
pluginId: a.id,
rootDir: a.rootDir,
bundleFormat: a.bundleFormat
}) : e.loadNativePluginConfig?.({ record: a });
if (!s) continue;
i = applyMergePatch(i, s.config);
for (const e of s.diagnostics) r.push({
pluginId: a.id,
message: e
});
}
return {
config: i,
diagnostics: r
};
}
//#endregion
export { loadEnabledBundleConfig as n, readBundleJsonObject as r, extractBundleServerMap as t };