openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
94 lines (93 loc) • 5.4 kB
JavaScript
import { t as safeParseJson } from "./json-coercion-CaJLaav-.mjs";
import { a as getPluginCache, h as preparePluginCacheFact } from "./plugin-cache-B_eRuqTM.mjs";
import { a as readPluginMetadataStateRow, i as readBundledDiscoveryModeMemoized, n as prepareBundledDiscoveryMode, o as readPluginMetadataStateRows, r as readBundledDiscoveryMode } from "./bundled-discovery-state-Bb0zCvZZ.mjs";
import { n as readPluginMetadataStateRowsSync, r as INSTALLED_PLUGIN_INDEX_STATE_KEY, s as inspectPluginInstallRecordMap, t as readPluginMetadataStateRowSync } from "./installed-plugin-index-row-CdwQuK63.mjs";
import { n as resolveInstalledPluginIndexStateDatabaseOptions, r as resolveInstalledPluginIndexStorePath } from "./installed-plugin-index-store-path-VYnur1Rc.mjs";
import path from "node:path";
//#region src/plugins/installed-plugin-index-record-state.ts
/** Read failures must escape before either projection can authorize recovery or rebuilding. */
function readPersistedInstalledPluginIndexRowSync(e) {
if (e.filePath?.endsWith(".json")) return;
return readPluginMetadataStateRowSync("installed-index", resolveInstalledPluginIndexStateDatabaseOptions(e), e.artifactPreservingReadOnly);
}
/** Share the SQLite row while validating install records independently from index metadata. */
function getPersistedInstalledPluginIndexCacheEntry(e, t = () => readPersistedInstalledPluginIndexRowSync(e)) {
const n = getPluginCache().persistedInstalledIndex;
const r = path.resolve(resolveInstalledPluginIndexStorePath(e));
const i = n.get(r);
if (i && "value" in i) return i.value;
const a = t();
const o = { state: a ? {
status: "present",
value: safeParseJson(a.value_json)
} : { status: "missing" } };
n.set(r, { value: o });
return o;
}
/** Prepare missing policy and inventory facts without replacing their lifecycle owners. */
function preparePluginMetadataMachineState(e) {
const t = e.env ?? process.env;
readBundledDiscoveryModeMemoized(t, e, (n) => {
const r = path.resolve(resolveInstalledPluginIndexStorePath(e));
const i = getPluginCache().persistedInstalledIndex.get(r);
if (path.resolve(n) !== r || e.filePath?.endsWith(".json") || i && "value" in i) return readBundledDiscoveryMode({ env: t }, e);
const a = readPluginMetadataStateRowsSync(["plugins.bundledDiscovery", INSTALLED_PLUGIN_INDEX_STATE_KEY], resolveInstalledPluginIndexStateDatabaseOptions(e), e.artifactPreservingReadOnly);
const o = a.find((e) => e.state_key === "plugins.bundledDiscovery");
const s = o ? JSON.parse(o.value_json) : void 0;
getPersistedInstalledPluginIndexCacheEntry(e, () => a.find((e) => e.state_key === INSTALLED_PLUGIN_INDEX_STATE_KEY));
return s;
});
}
/** Coalesce cold policy and inventory reads without refreshing lifecycle-owned warm facts. */
async function preparePluginMetadataMachineStateAsync(e) {
const t = path.resolve(resolveInstalledPluginIndexStorePath(e));
const n = resolveInstalledPluginIndexStateDatabaseOptions(e);
let r;
const readRows = () => r ??= readPluginMetadataStateRows(["plugins.bundledDiscovery", INSTALLED_PLUGIN_INDEX_STATE_KEY], n, e.artifactPreservingReadOnly);
const i = await prepareBundledDiscoveryMode(e.env, async (n) => {
const r = getPluginCache().persistedInstalledIndex.get(t);
if (path.resolve(n) !== t || e.filePath?.endsWith(".json") || r) return readPluginMetadataStateRow("bundled-discovery", {
path: n,
env: e.env
}, e.artifactPreservingReadOnly);
return (await readRows()).find((e) => e.state_key === "plugins.bundledDiscovery");
});
i();
const a = await preparePersistedInstalledPluginIndexCacheEntry(e, r ? async () => (await readRows()).find((e) => e.state_key === INSTALLED_PLUGIN_INDEX_STATE_KEY) : void 0);
i();
a.assertCurrent();
return () => {
i();
a.assertCurrent();
};
}
/** Await one shared row, retaining its cache generation until publication completes. */
async function preparePersistedInstalledPluginIndexCacheEntry(e = {}, t) {
const n = getPluginCache();
const r = path.resolve(resolveInstalledPluginIndexStorePath(e));
const i = resolveInstalledPluginIndexStateDatabaseOptions(e);
const a = await preparePluginCacheFact(n, n.persistedInstalledIndex, r, async () => {
const n = e.filePath?.endsWith(".json") ? void 0 : t ? await t() : await readPluginMetadataStateRow("installed-index", i, e.artifactPreservingReadOnly);
return { state: n ? {
status: "present",
value: safeParseJson(n.value_json)
} : { status: "missing" } };
});
return {
entry: a.value,
assertCurrent: a.assertCurrent
};
}
function inspectPersistedInstalledPluginIndexInstallRecords(e) {
if (!e.records) {
const t = e.state;
const n = (t.status === "present" ? t.value : void 0)?.index?.installRecords;
e.records = t.status === "missing" ? { status: "missing" } : n === void 0 ? { status: "invalid" } : inspectPluginInstallRecordMap(n);
}
return e.records;
}
function inspectPersistedInstalledPluginIndexInstallRecordsSync(e = {}) {
return inspectPersistedInstalledPluginIndexInstallRecords(getPersistedInstalledPluginIndexCacheEntry(e));
}
//#endregion
export { preparePluginMetadataMachineState as a, preparePersistedInstalledPluginIndexCacheEntry as i, inspectPersistedInstalledPluginIndexInstallRecords as n, preparePluginMetadataMachineStateAsync as o, inspectPersistedInstalledPluginIndexInstallRecordsSync as r, getPersistedInstalledPluginIndexCacheEntry as t };