openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
539 lines (538 loc) • 21.8 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { o as redactSensitiveUrlLikeString } from "./redact-sensitive-url-D-E7DGoc.mjs";
import { n as formatConcreteConfigPath } from "./dot-path-BJ4tyWKJ.mjs";
import { p as isValidSecretRef } from "./ref-contract-b8L-9DrQ.mjs";
import { S as resolveIsConfigReadOnly } from "./paths-DAcAg5aV.mjs";
import { a as getPluginCache, d as getProcessPluginCache, i as createPluginCache, w as withPluginCache } from "./plugin-cache-B_eRuqTM.mjs";
import { a as getProcessGatewayPluginMetadataSnapshot } from "./current-plugin-metadata-state-BmYo9Q7A.mjs";
import { r as cloneEnvWithPlatformSemantics } from "./config-env-vars-ByeGN-9N.mjs";
import { c as normalizePluginId, u as normalizePluginsConfig } from "./config-state-B1JlHgba.mjs";
import { i as isInstalledPluginEnabled, t as createInstalledPluginEnabledPredicate } from "./installed-plugin-index-DYqse_gE.mjs";
import { r as normalizeManifestCatalog } from "./manifest-capability-normalizers-mW51WFYi.mjs";
import { d as hasUnresolvedConfigPath, p as resolveConfigSecretRef } from "./resolution-facts-xaIKuREs.mjs";
import { h as resolveOfficialExternalPluginLabel, l as listOfficialExternalPluginCatalogEntries } from "./official-external-plugin-catalog-DtkWz1Xo.mjs";
import { o as preparePluginMetadataMachineStateAsync } from "./installed-plugin-index-record-state-euCqi7PU.mjs";
import { g as resolveOfficialExternalPluginId, o as getOfficialExternalPluginCatalogManifest } from "./official-external-plugin-catalog-source-4o5oPhVN.mjs";
import { c as loadPluginMetadataSnapshot, p as resolvePluginMetadataSnapshot } from "./plugin-metadata-snapshot-By9ySblt.mjs";
import { n as resolvePluginControlPlaneWorkspace, t as appendPluginControlPlaneWorkspaceDiagnostic } from "./control-plane-workspace-OscAdfLv.mjs";
import { t as createInstalledPluginOwnershipResolver } from "./installed-plugin-package-ownership-BAh5IZ9-.mjs";
import { r as resolveConfigWidePluginMetadataSnapshot } from "./io.plugin-metadata-CBwzHw3m.mjs";
import { i as validatePluginSchemaValue } from "./schema-validator-NvoOmaWr.mjs";
import { t as ManagedPluginLifecycleError } from "./management-lifecycle-error-COJYzrtT.mjs";
import { t as resolvePluginActivationSourceConfig } from "./activation-source-config-BX9rE6k7.mjs";
import { i as resolveManifestProviderAuthChoices } from "./provider-auth-choices-BfC_56hU.mjs";
import { c as projectPluginOverviewCapabilities, d as projectInstalledPluginComponents, l as readInstalledPluginOverview, o as projectClawHubPluginInspection, u as emptyInstalledPluginComponents } from "./catalog-discovery-q1OWXMsX.mjs";
import { c as resolvePluginInstallRecordIntegrity, l as resolvePluginInstallRecordTrust, n as buildPluginCapabilitySummary, r as computeDeclaredSurfaceHash, u as resolvePluginPackageDeclaredSurface } from "./capability-summary-Dfhfz0nD.mjs";
import { v as resolveClawHubBaseUrl } from "./clawhub-client-BLg-dsn2.mjs";
import { r as fetchClawHubPluginDetail } from "./clawhub-plugin-catalog-BC-4D5Jm.mjs";
import { _ as resolvePluginActivityIconSource, a as loadInstalledPluginPublisherHandle, b as withManagedPluginCache, c as normalizeKinds, d as prepareCatalogEntry, f as projectPluginCatalogCategoryFacts, g as resolveOfficialEntryById, h as resolveInstalledPluginPresentation, i as loadInstalledPluginCategories, l as pluginVersionKey, m as resolveInstalledPluginClawHubIconSource, n as compareCatalogEntries, o as loadOfficialCatalog, p as resolveInstalledHostedOfficialEntry, r as firstPluginError, s as normalizeFeaturedAt, u as prepareCatalogEntries, v as resolvePluginIconSource, y as resolvePluginIconSources } from "./management-catalog-CIUzoNKS.mjs";
import { i as resolvePendingPluginCapabilityReview } from "./capability-consent-ByRkpzSz.mjs";
import { t as listRecommendedToolInstalls } from "./recommended-tool-installs-CzXPiP1e.mjs";
import { t as normalizeCatalogIconUrl } from "./catalog-icon-registry-Bql9JZh5.mjs";
import { t as resolvePluginCredentialDescriptors } from "./credential-descriptors-Dn1a2JsY.mjs";
import { t as readPluginMcpAuthStatus } from "./mcp-auth-status-wwhN90-8.mjs";
import { n as projectPluginInstallHealth } from "./status-snapshot-CtUxanh4.mjs";
//#region src/plugins/credential-inspection.ts
/** Never resolve references; authored literals require the explicit administrator reveal flow. */
function inspectPluginCredentialValue(e, t, n, r = false) {
let i = e;
for (const e of t.path) i = i !== null && typeof i === "object" && Object.hasOwn(i, e) ? Reflect.get(i, e) : void 0;
const a = formatConcreteConfigPath(t.path, e);
const o = resolveConfigSecretRef({
config: e,
path: a,
value: i,
defaults: e.secrets?.defaults,
includeResolved: true
});
if (o && isValidSecretRef(o)) return {
kind: "reference",
ref: o,
unresolved: hasUnresolvedConfigPath(e, a)
};
if (typeof i === "string" && i.length) return {
kind: "literal",
...r ? { value: i } : {}
};
if (i !== void 0 && i !== "") return { kind: "invalid" };
const s = t.envVars.find((e) => Boolean(n[e]?.trim()));
return s ? {
kind: "environment",
envVar: s
} : { kind: "missing" };
}
//#endregion
//#region src/plugins/plugin-config-enablement.ts
function resolvePluginConfigEnablement(e) {
const t = e.manifest;
if (!t?.configSchema) return { mode: "ready" };
const n = normalizePluginsConfig(e.config.plugins).entries[normalizePluginId(e.pluginId)]?.config;
const r = n !== void 0;
const i = validatePluginSchemaValue({
origin: t.origin,
schema: t.configSchema,
cacheKey: t.schemaCacheKey ?? t.manifestPath,
value: r ? n : {},
applyDefaults: true
});
if (i.ok) return { mode: "ready" };
if (!r && !i.schemaError) return { mode: "missing" };
return {
mode: "invalid",
error: i.errors[0]?.text ?? "invalid plugin config"
};
}
//#endregion
//#region src/plugins/management-service.ts
const CLAWHUB_CATEGORY_BATCH_LIMIT = 200;
function resolveManagedPluginMetadataParams(e, t) {
const n = resolvePluginControlPlaneWorkspace({
config: e,
env: t
});
return {
config: e,
env: t,
...n.workspaceDir !== void 0 ? { workspaceDir: n.workspaceDir } : {}
};
}
function resolveManagedPluginMetadata(e, t) {
const n = getProcessGatewayPluginMetadataSnapshot();
const r = getProcessPluginCache().desiredMetadata;
return r && r.boot === n ? r.snapshot : resolvePluginMetadataSnapshot(resolveManagedPluginMetadataParams(e, t));
}
function loadFreshManagedPluginMetadata(e, t) {
const n = cloneEnvWithPlatformSemantics(t);
const r = getPluginCache();
const i = r.kind === "operation" ? r : createPluginCache();
return withPluginCache(i, async () => {
const t = Boolean(getProcessGatewayPluginMetadataSnapshot());
const r = t ? {
config: e,
env: n
} : resolveManagedPluginMetadataParams(e, n);
(await preparePluginMetadataMachineStateAsync({ env: n }))();
return t ? resolveConfigWidePluginMetadataSnapshot({
...r,
allowCurrent: false
}) : loadPluginMetadataSnapshot({
...r,
allowCurrent: false
});
});
}
/** Publish desired install state for management without replacing the Gateway's boot facts. */
async function refreshManagedPluginMetadata(e) {
const t = e.env ?? process.env;
const n = getProcessGatewayPluginMetadataSnapshot();
const r = getProcessPluginCache();
const i = e.assertCurrent;
const a = createPluginCache();
const o = await withPluginCache(a, () => loadFreshManagedPluginMetadata(e.config, t));
i?.();
if (n && getProcessGatewayPluginMetadataSnapshot() === n && getProcessPluginCache() === r) r.desiredMetadata = {
boot: n,
cache: a,
snapshot: o
};
return o;
}
/** Resolve ordered branding sources from package bytes and exact installed provenance. */
const resolveManagedPluginIconSources = withManagedPluginCache(async (e) => {
const t = e.env ?? process.env;
const n = resolveManagedPluginMetadata(e.config, t);
return resolvePluginIconSources({
metadata: n,
pluginId: e.pluginId,
env: t
});
});
const resolveManagedPluginActivityIconSource = withManagedPluginCache(async (e) => {
const t = resolveManagedPluginMetadata(e.config, e.env ?? process.env);
return resolvePluginActivityIconSource({
...e,
metadata: t
});
});
/** Resolve only URLs currently owned by a manifest or bundled presentation catalog. */
function resolveManagedSetupCatalogIconUrl(e) {
const t = normalizeCatalogIconUrl(normalizeOptionalString(e.iconUrl) ?? "");
if (!t) return;
return [...resolveManifestProviderAuthChoices({
config: e.config,
includeUntrustedWorkspacePlugins: false,
includeWorkspacePlugins: false
}).map((e) => e.icon), ...listRecommendedToolInstalls().map((e) => e.icon)].some((e) => normalizeCatalogIconUrl(normalizeOptionalString(e) ?? "") === t) ? t : void 0;
}
/** Build cold installed state merged with the hosted official catalog and bundled curation. */
const listManagedPlugins = withManagedPluginCache(async (e) => {
const t = resolvePluginActivationSourceConfig({ config: e.config });
const n = e.env ?? process.env;
const r = resolvePluginControlPlaneWorkspace({
config: e.config,
env: n
});
const i = e.metadata ?? resolveManagedPluginMetadata(e.config, n);
const a = e.officialCatalog ?? await loadOfficialCatalog(e.cachedCatalogOnly);
const o = createInstalledPluginEnabledPredicate(i.index.plugins, e.config, n);
const s = createInstalledPluginOwnershipResolver(i.index, n);
const { diagnostics: c } = projectPluginInstallHealth({
plugins: i.index.plugins.map((e) => {
const t = i.byPluginId.get(e.pluginId);
const n = o(e.pluginId);
return {
id: e.pluginId,
source: t?.source ?? e.source ?? e.manifestPath,
enabled: n,
status: n ? "loaded" : "disabled"
};
}),
diagnostics: [...i.diagnostics]
}, {
metadata: i,
config: e.config,
env: n
}, s);
const l = prepareCatalogEntries(a.entries);
const u = prepareCatalogEntries(listOfficialExternalPluginCatalogEntries());
const d = /* @__PURE__ */ new Map();
const f = /* @__PURE__ */ new Map();
const p = /* @__PURE__ */ new Set();
const m = resolveClawHubBaseUrl();
const h = /* @__PURE__ */ new Map();
let g = 0;
const _ = i.index.plugins.map((e) => {
const n = o(e.pluginId);
const r = i.byPluginId.get(e.pluginId);
const _ = normalizeManifestCatalog(r?.catalog);
const v = s.resolvePackage(e.pluginId);
const y = v.ok ? v.value.installOwner : void 0;
const b = y ? i.index.installRecords[y] : void 0;
const { entry: x, clawhubPackage: S } = resolveInstalledHostedOfficialEntry({
record: e,
...y ? { installOwner: y } : {},
installRecord: b,
officialEntries: l,
bundledOfficialEntries: u
});
if (S) p.add(S);
const C = x ? normalizeManifestCatalog(getOfficialExternalPluginCatalogManifest(x)?.catalog) : void 0;
const w = S && a.hostedFeaturedAuthoritative ? {
..._,
...C,
featured: x?.featured === true
} : C ? {
..._,
...C
} : _;
const T = resolvePluginConfigEnablement({
config: t,
pluginId: e.pluginId,
manifest: r
});
const E = T.mode === "invalid" ? T.error : void 0;
const D = firstPluginError(c, e.pluginId) ?? E;
const O = normalizeKinds(r?.kind);
const k = e.origin !== "bundled" && Boolean(y);
const A = Boolean(S) && a.hostedFeaturedAuthoritative === true;
const j = A && w?.featured === true ? normalizeFeaturedAt(x?.featuredAt) : void 0;
const M = resolveInstalledPluginPresentation({
record: e,
manifest: r,
officialEntry: x,
hostedListingAuthoritative: A
});
const N = {
id: e.pluginId,
name: M.name,
installed: true,
enabled: n,
state: D ? "error" : n ? "enabled" : T.mode === "missing" ? "needs-setup" : "disabled",
removable: k,
hasNativeUi: r ? Boolean(r.controlUi) : void 0
};
Object.assign(N, projectPluginCatalogCategoryFacts(r, n));
if (e.packageName) N.packageName = e.packageName;
const P = resolveInstalledPluginClawHubIconSource({
installRecord: b,
clawhubPackage: S
});
const F = P?.baseUrl === m ? P.packageName : void 0;
if (F) N.clawhubPackage = F;
if (M.description) N.description = M.description;
if (M.version) N.version = M.version;
if (O) N.kind = O;
if (e.origin) N.origin = e.origin;
if (w?.featured !== void 0) N.featured = w.featured;
if (j !== void 0) N.featuredAt = j;
if (w?.order !== void 0) N.order = w.order;
const I = i.normalizePluginId(e.pluginId);
if (!d.has(I)) {
d.set(I, Boolean(resolvePluginIconSource({
metadata: i,
pluginId: e.pluginId
}) || P));
if (e.origin !== "bundled" && P) f.set(I, P);
}
if (d.get(I)) N.hasIcon = true;
const L = i.byPluginId.get(I);
if (L?.activityIconPath) N.hasActivityIcon = true;
if (L?.toolActivityIconPaths) N.activityIconTools = Object.keys(L.toolActivityIconPaths).toSorted();
if (r?.channels.length) N.channelIds = [...r.channels];
if (D) N.error = D;
if (!N.categories?.length && e.origin !== "bundled" && b?.source === "clawhub") {
const e = normalizeOptionalString(b.clawhubPackage);
const t = normalizeOptionalString(b.version);
if (e && t) {
const n = resolveClawHubBaseUrl(b.clawhubUrl);
let r = h.get(n);
if (!r) {
r = /* @__PURE__ */ new Map();
h.set(n, r);
}
const i = pluginVersionKey(e, t);
const a = r.get(i);
if (a) a.plugins.push(N);
else if (g < CLAWHUB_CATEGORY_BATCH_LIMIT) {
r.set(i, {
request: {
name: e,
version: t
},
plugins: [N]
});
g += 1;
}
}
}
return N;
});
const v = /* @__PURE__ */ new Set();
await Promise.all([...f].map(async ([t, n]) => {
const r = await loadInstalledPluginPublisherHandle(n, e.cachedCatalogOnly);
if (r && r !== "openclaw") v.add(t);
}));
for (const e of _) if (e.origin !== "bundled" && v.has(i.normalizePluginId(e.id))) e.hasToolBrandIcon = true;
for (const [t, n] of h) {
const r = await loadInstalledPluginCategories({
baseUrl: t,
packages: [...n.values()].map((e) => e.request),
cachedOnly: e.cachedCatalogOnly
});
if (!r) {
c.push({
level: "warn",
message: r === null ? "Installed plugin category enrichment unavailable; reload plugins or restart the Gateway to retry." : "Installed plugin category enrichment pending; refresh the plugin list to see completed enrichment."
});
continue;
}
for (const [e, t] of n) {
const n = r.get(e);
if (!n?.length) continue;
for (const e of t.plugins) e.categories = [...n];
}
}
const y = new Set(_.map((e) => e.id));
const b = new Set(_.flatMap((e) => e.packageName ? [e.packageName] : []));
for (const e of l()) {
const { entry: t, clawhub: n, npmPackage: r } = e;
const i = resolveOfficialExternalPluginId(t);
const a = getOfficialExternalPluginCatalogManifest(t);
const o = normalizeManifestCatalog(a?.catalog);
const s = o || typeof t.featured === "boolean" ? {
...o,
...o?.featured === void 0 && typeof t.featured === "boolean" ? { featured: t.featured } : {}
} : void 0;
if (!i || !s || y.has(i) || n && (b.has(n.name) || p.has(n.name)) || r && b.has(r)) continue;
const c = normalizeKinds(t.kind);
const l = e.selectedSource?.source === "clawhub" && n && !n.version ? {
source: "clawhub",
packageName: n.name
} : e.install ? {
source: "official",
pluginId: i
} : void 0;
const u = r ?? n?.name;
const d = normalizeOptionalString(t.description);
const f = normalizeOptionalString(t.version);
const m = s.featured === true ? normalizeFeaturedAt(t.featuredAt) : void 0;
_.push({
id: i,
name: resolveOfficialExternalPluginLabel(t),
...u ? { packageName: u } : {},
...n ? { clawhubPackage: n.name } : {},
...d ? { description: d } : {},
...f ? { version: f } : {},
...c ? { kind: c } : {},
origin: "official",
installed: false,
enabled: false,
state: "not-installed",
...s.featured !== void 0 ? { featured: s.featured } : {},
...m !== void 0 ? { featuredAt: m } : {},
...s.order !== void 0 ? { order: s.order } : {},
...l ? { install: l } : {}
});
}
const x = getProcessGatewayPluginMetadataSnapshot() ? c : appendPluginControlPlaneWorkspaceDiagnostic(c, r);
if (a.error) x.push({
level: "warn",
message: `Official plugin catalog fallback: ${a.error}`
});
return {
plugins: _.toSorted(compareCatalogEntries),
diagnostics: x,
mutationAllowed: !resolveIsConfigReadOnly(n)
};
});
/** Inspect one plugin's manifest, operator grants, and recorded install provenance. */
const inspectManagedPlugin = withManagedPluginCache(async (e) => {
const t = e.env ?? process.env;
if (e.clawhub) {
const [n, r] = await Promise.all([fetchClawHubPluginDetail(e.clawhub), listManagedPlugins({
config: e.config,
env: t
})]);
return projectClawHubPluginInspection({
remote: n,
local: r,
config: e.config
});
}
if (!e.pluginId) throw new ManagedPluginLifecycleError("A plugin inspection identity is required.", { kind: "invalid-request" });
const n = resolveManagedPluginMetadata(e.config, t);
const r = n.normalizePluginId(e.pluginId);
const i = n.index.plugins.find((e) => e.pluginId === r);
const a = isInstalledPluginEnabled(n.index, r, e.config);
const o = resolvePendingPluginCapabilityReview(r);
if (o) {
const e = n.byPluginId.get(r);
return {
ok: true,
plugin: {
id: r,
name: o.name,
...o.version ? { version: o.version } : {},
...i?.origin ? { origin: i.origin } : {},
installed: Boolean(i),
enabled: a
},
declared: o.declared,
overview: readInstalledPluginOverview(e),
components: projectInstalledPluginComponents({
manifest: e,
declared: o.declared
}),
grants: o.grants,
reviewToken: o.reviewToken,
...o.source ? { source: o.source } : {},
...o.trust ? { trust: o.trust } : {}
};
}
const s = await loadOfficialCatalog();
if (i) {
const o = n.byPluginId.get(r);
const c = createInstalledPluginOwnershipResolver(n.index, t).resolvePackage(r);
const l = c.ok ? c.value.installOwner : void 0;
const u = l ? n.index.installRecords[l] : void 0;
const { entry: d, clawhubPackage: f } = resolveInstalledHostedOfficialEntry({
record: i,
...l ? { installOwner: l } : {},
installRecord: u,
officialEntries: prepareCatalogEntries(s.entries),
bundledOfficialEntries: prepareCatalogEntries(listOfficialExternalPluginCatalogEntries())
});
const p = u?.resolvedSpec ?? u?.spec;
const m = u?.clawhubPackage ?? i.packageName;
const h = u ? {
kind: u.source,
...p ? { spec: redactSensitiveUrlLikeString(p) } : {},
...m ? { packageName: m } : {},
...resolvePluginInstallRecordIntegrity(u)
} : i.origin === "bundled" ? { kind: "bundled" } : void 0;
const g = resolvePluginInstallRecordTrust(u);
const _ = buildPluginCapabilitySummary({
manifest: o ?? {},
origin: i.origin,
entryConfig: e.config.plugins?.entries?.[r]
});
const v = c.ok ? resolvePluginPackageDeclaredSurface(c.value, n.byPluginId) : _.declared;
if (!v) throw new ManagedPluginLifecycleError(`Plugin package "${l}" has incomplete manifest metadata.`);
const y = a ? await readPluginMcpAuthStatus({
config: e.config,
pluginId: r,
metadata: n
}) : void 0;
return {
ok: true,
plugin: {
id: r,
...resolveInstalledPluginPresentation({
record: i,
manifest: o,
officialEntry: d,
hostedListingAuthoritative: Boolean(f) && s.hostedFeaturedAuthoritative === true
}),
origin: i.origin,
installed: true,
enabled: a
},
...h ? { source: h } : {},
..._,
declared: v,
components: projectInstalledPluginComponents({
manifest: o,
declared: v
}),
overview: readInstalledPluginOverview(o),
credentials: o ? resolvePluginCredentialDescriptors(o).map((n) => {
const r = inspectPluginCredentialValue(e.config, n, t);
const i = r.kind === "reference" ? r.unresolved ? "unresolved" : "configured" : r.kind === "literal" || r.kind === "environment" ? "configured" : r.kind;
return Object.assign({}, n, { status: i });
}) : [],
...y ? { mcpAuth: y } : {},
reviewToken: computeDeclaredSurfaceHash(v),
...g ? { trust: g } : {}
};
}
const c = resolveOfficialEntryById(s.entries, r);
if (!c) throw new ManagedPluginLifecycleError(`Plugin "${r}" not found.`, { kind: "invalid-request" });
const l = getOfficialExternalPluginCatalogManifest(c);
const { selectedSource: u, clawhub: d, npmPackage: f } = prepareCatalogEntry(c);
const p = f ?? d?.name;
const m = u?.spec;
const h = normalizeOptionalString(c.description);
const g = normalizeOptionalString(c.version);
const _ = buildPluginCapabilitySummary({
manifest: l ?? {},
origin: "official",
entryConfig: e.config.plugins?.entries?.[r]
});
return {
ok: true,
plugin: {
id: r,
name: resolveOfficialExternalPluginLabel(c),
...g ? { version: g } : {},
...h ? { description: h } : {},
origin: "official",
installed: false,
enabled: false
},
source: {
kind: "official-catalog",
...m ? { spec: redactSensitiveUrlLikeString(m) } : {},
...p ? { packageName: p } : {},
...u?.expectedIntegrity ? {
integrity: u.expectedIntegrity,
integrityKind: u.source === "clawhub" ? "sha256" : "ssri"
} : {}
},
..._,
components: emptyInstalledPluginComponents(),
overview: { capabilities: projectPluginOverviewCapabilities(_.declared, l?.uiCapabilities) },
reviewToken: computeDeclaredSurfaceHash(_.declared)
};
});
//#endregion
export { resolveManagedPluginActivityIconSource as a, resolveManagedSetupCatalogIconUrl as c, refreshManagedPluginMetadata as i, resolvePluginConfigEnablement as l, listManagedPlugins as n, resolveManagedPluginIconSources as o, loadFreshManagedPluginMetadata as r, resolveManagedPluginMetadata as s, inspectManagedPlugin as t, inspectPluginCredentialValue as u };