openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
172 lines (171 loc) • 7.74 kB
JavaScript
import { t as listAgentWorkspaceDirs } from "./workspace-dirs-Dba0CE04.mjs";
import { a as getPluginCache, i as createPluginCache, w as withPluginCache } from "./plugin-cache-B_eRuqTM.mjs";
import { i as getGatewayPluginMetadataSnapshot } from "./current-plugin-metadata-state-BmYo9Q7A.mjs";
import { r as cloneEnvWithPlatformSemantics } from "./config-env-vars-ByeGN-9N.mjs";
import { _ as withSynchronousArtifactPreservingStateSnapshot } from "./openclaw-state-db-readonly-B6YHb1oF.mjs";
import { n as prepareBundledDiscoveryMode } from "./bundled-discovery-state-Bb0zCvZZ.mjs";
import { t as normalizePluginPolicyId } from "./plugin-policy-id-CkilMowp.mjs";
import { a as preparePluginMetadataMachineState, o as preparePluginMetadataMachineStateAsync } from "./installed-plugin-index-record-state-euCqi7PU.mjs";
import { i as loadInstalledPluginIndexInstallRecordsSync } from "./installed-plugin-index-record-reader-B-7uGQZ9.mjs";
import { t as loadPluginManifestRegistryCore } from "./manifest-registry-CuWv8ibc.mjs";
import { r as getCompatibleProcessGatewayPluginMetadataSnapshot } from "./current-plugin-metadata-snapshot-H0TP3PFt.mjs";
import { _ as restorePluginMetadataSnapshot, d as readPluginMetadataSnapshotCache, g as resolvePluginMetadataSnapshotInput, h as resolvePluginMetadataSnapshotCacheKey, n as buildPluginMetadataSnapshot, p as resolvePluginMetadataSnapshot, r as cachePluginMetadataSnapshot, u as projectPluginMetadataSnapshot } from "./plugin-metadata-snapshot-By9ySblt.mjs";
import { o as preparePluginRegistrySnapshotReader } from "./plugin-registry-snapshot-CcrTrj6P.mjs";
//#region src/config/io.plugin-metadata.ts
function mergeRegistries(e) {
const t = /* @__PURE__ */ new Map();
const n = e.flatMap((e) => e.diagnostics);
for (const n of e) for (const e of n.plugins) {
const n = normalizePluginPolicyId(e.id);
const r = t.get(n) ?? {
plugin: e,
sources: /* @__PURE__ */ new Set()
};
r.plugin = e;
r.sources.add(e.source);
t.set(n, r);
}
return {
plugins: [...t.entries()].flatMap(([e, t]) => {
if (t.sources.size === 1) return [t.plugin];
n.push({
level: "error",
pluginId: e,
message: `plugin id ${JSON.stringify(e)} is present in multiple agent workspaces: ${[...t.sources].toSorted().join(", ")}`
});
return [];
}),
diagnostics: n
};
}
/** Read complete installed ownership for maintenance, including older partial index caches. */
function discoverConfigWidePluginManifestRegistry(e) {
const t = e.env ?? process.env;
const n = e.workspaceDir !== void 0 ? [e.workspaceDir] : e.config ? listAgentWorkspaceDirs(e.config, t) : [];
const r = loadInstalledPluginIndexInstallRecordsSync({
env: t,
artifactPreservingReadOnly: e.artifactPreservingReadOnly
});
return mergeRegistries((n.length > 0 ? n : [void 0]).map((n) => loadPluginManifestRegistryCore({
config: e.config,
env: t,
workspaceDir: n,
installRecords: r
})));
}
function resolveReusableGatewayPluginMetadataSnapshot(e, t = true) {
if (e.allowCurrent === false || e.stateDir !== void 0 || e.installRecords !== void 0) return;
return getGatewayPluginMetadataSnapshot() ?? getCompatibleProcessGatewayPluginMetadataSnapshot({
config: e.config,
env: e.env,
allowWorkspaceScopedSnapshot: true,
allowSynchronousPolicyRead: t
});
}
/** Prepare database facts asynchronously before the existing metadata derivation. */
async function resolveConfigWidePluginMetadataSnapshotAsync(e) {
const t = {
...e,
env: cloneEnvWithPlatformSemantics(e.env ?? process.env)
};
if (t.allowCurrent === false && getPluginCache().kind !== "operation") return withPluginCache(createPluginCache(), () => resolveConfigWidePluginMetadataSnapshotAsync(t));
const n = resolveReusableGatewayPluginMetadataSnapshot(t, false);
if (n) return n;
const r = getPluginCache();
return withPluginCache(r, async () => {
(t.installRecords === void 0 ? await preparePluginMetadataMachineStateAsync({
env: t.env,
stateDir: t.stateDir
}) : await prepareBundledDiscoveryMode(t.env))();
return resolveConfigWidePluginMetadataSnapshot(t);
});
}
function resolveConfigWideMetadataSelection(e) {
const t = e.env ?? process.env;
const n = listAgentWorkspaceDirs(e.config, t);
const r = n.length ? n : [void 0];
return {
workspaceDirs: r,
key: JSON.stringify([
"config-wide",
resolvePluginMetadataSnapshotCacheKey(e),
r
])
};
}
function resolveConfigWidePluginMetadataSnapshot(e) {
if (e.allowCurrent === false && getPluginCache().kind !== "operation") return withPluginCache(createPluginCache(), () => resolveConfigWidePluginMetadataSnapshot(e));
const t = resolveReusableGatewayPluginMetadataSnapshot(e);
if (t) return t;
return withSynchronousArtifactPreservingStateSnapshot(() => {
if (e.installRecords === void 0) preparePluginMetadataMachineState({
env: e.env ?? process.env,
stateDir: e.stateDir
});
const { key: t, workspaceDirs: n } = resolveConfigWideMetadataSelection(e);
const r = readPluginMetadataSnapshotCache(t);
if (r) return r;
const i = resolveConfigWidePluginMetadataSnapshotImpl(e, n);
cachePluginMetadataSnapshot(t, i);
return i;
});
}
function resolveConfigWidePluginMetadataSnapshotImpl(e, t) {
const n = e.env ?? process.env;
const workspaceParams = (t) => ({
config: e.config,
...t ? { workspaceDir: t } : {},
...e.stateDir ? { stateDir: e.stateDir } : {},
env: n,
allowCurrent: e.allowCurrent,
...e.installRecords ? { installRecords: e.installRecords } : {},
allowWorkspaceScopedCurrent: true
});
if (t.length === 1) return resolvePluginMetadataSnapshot(workspaceParams(t[0]));
const r = preparePluginRegistrySnapshotReader({
...e,
...e.installRecords !== void 0 ? { preferPersisted: false } : {}
});
const i = resolvePluginMetadataSnapshotInput(workspaceParams(t[0]), r);
const a = [i, ...t.slice(1).map((e) => resolvePluginMetadataSnapshotInput(workspaceParams(e), r))];
const o = mergeRegistries(a.map((e) => e.manifestRegistry));
const s = new Map(o.plugins.map((e) => [normalizePluginPolicyId(e.id), e]));
const c = new Map(a.flatMap((e) => e.index.plugins.flatMap((e) => {
const t = normalizePluginPolicyId(e.pluginId);
const n = s.get(t);
return n && n.manifestPath === e.manifestPath ? [[t, e]] : [];
})));
const l = {
...i.index,
plugins: [...c.values()],
installRecords: Object.fromEntries(a.flatMap((e) => Object.entries(e.index.installRecords))),
diagnostics: o.diagnostics
};
const u = new Set(o.plugins.map((e) => e.source));
const d = a.every((e) => e.discovery) ? {
candidates: [...new Map(a.flatMap((e) => (e.discovery?.candidates ?? []).filter((e) => u.has(e.source)).map((e) => [`${e.effectivePluginId ?? e.idHint}\0${e.source}`, e]))).values()],
diagnostics: a.flatMap((e) => e.discovery?.diagnostics ?? [])
} : void 0;
const sumMetric = (e) => a.reduce((t, n) => t + n.metrics[e], 0);
return restorePluginMetadataSnapshot(buildPluginMetadataSnapshot({
...i,
index: l,
discovery: d,
manifestRegistry: o,
registryDiagnostics: a.flatMap((e) => e.registryDiagnostics),
metrics: {
registrySnapshotMs: sumMetric("registrySnapshotMs"),
manifestRegistryMs: sumMetric("manifestRegistryMs"),
ownerMapsMs: 0,
totalMs: sumMetric("totalMs"),
indexPluginCount: l.plugins.length,
manifestPluginCount: o.plugins.length
}
}, e));
}
function resolveConfigWidePluginManifestRegistry(e) {
const t = resolveConfigWidePluginMetadataSnapshot(e);
return projectPluginMetadataSnapshot(t, e.pluginIds).manifestRegistry;
}
//#endregion
export { resolveConfigWidePluginMetadataSnapshotAsync as i, resolveConfigWidePluginManifestRegistry as n, resolveConfigWidePluginMetadataSnapshot as r, discoverConfigWidePluginManifestRegistry as t };