openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
445 lines (444 loc) • 17.5 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { o as asRecord } from "./record-coerce-CVPuDqcc.mjs";
import { y as sortUniqueStrings } from "./string-normalization-DLmfYZXI.mjs";
import { c as readPluginCacheFile, n as parsePluginCacheJson } from "./plugin-cache-files-e1aGp2KM.mjs";
import { n as validatePluginUiCapabilities } from "./plugin-ui-capabilities-CphHLqKu.mjs";
import { t as shouldRejectHardlinkedPluginFiles } from "./hardlink-policy-Kq1Lxk7_.mjs";
import { n as inspectBundleMcpRuntimeSupport, r as inspectNativePluginMcpRuntimeSupport } from "./bundle-mcp-DKz8uq8U.mjs";
import { n as buildPluginCapabilitySummary } from "./capability-summary-Dfhfz0nD.mjs";
import { t as loadHookEntriesFromDir } from "./discovery-GDR4z5qw.mjs";
import { r as resolvePluginSkillDetails } from "./plugin-skills-CL-RMSJw.mjs";
import { t as inspectBundleLspRuntimeSupport } from "./bundle-lsp-BPvu9pN4.mjs";
import { n as inspectBundlePluginArtifact } from "./install-artifact-inspection-CWGsODru.mjs";
import path from "node:path";
//#region packages/plugin-package-contract/src/catalog-order.ts
/** Compare registry-issued category priorities, then downloads and canonical identity. */
function comparePluginCatalogEntries(e, t, n) {
if (n) {
const r = e.catalog.categoryRanks?.[n] ?? Number.MAX_SAFE_INTEGER;
const i = t.catalog.categoryRanks?.[n] ?? Number.MAX_SAFE_INTEGER;
if (r !== i) return r - i;
}
const r = (t.catalog.downloads ?? 0) - (e.catalog.downloads ?? 0);
const i = e.catalog.packageName ?? e.id;
const a = t.catalog.packageName ?? t.id;
return r || (i < a ? -1 : i > a ? 1 : 0);
}
//#endregion
//#region src/plugins/installed-plugin-components.ts
function emptyInstalledPluginComponents() {
return {
mapped: [],
skills: [],
mcpServers: [],
commands: [],
hooks: [],
lspServers: [],
unavailable: {
capabilities: [],
mcpServers: [],
lspServers: []
}
};
}
/** Projects only components that the installed OpenClaw runtime can actually use. */
function projectInstalledPluginComponents(e) {
const { manifest: t, declared: n } = e;
const r = t?.rootDir ? resolvePluginSkillDetails(t) : void 0;
const i = r?.map((e) => e.name) ?? sortUniqueStrings(n.skills);
if (t?.format !== "bundle" || !t.bundleFormat) {
const e = t?.rootDir ? inspectNativePluginMcpRuntimeSupport({
rootDir: t.rootDir,
mcpServers: t.mcpServers ?? {}
}) : void 0;
const a = i;
const o = sortUniqueStrings(e?.supportedServerNames ?? n.mcpServers);
const s = sortUniqueStrings(n.cliCommands);
const c = sortUniqueStrings(n.hooks);
return {
mapped: [
...a.length > 0 ? ["skills"] : [],
...o.length > 0 ? ["mcpServers"] : [],
...s.length > 0 ? ["commands"] : [],
...c.length > 0 ? ["hooks"] : []
],
skills: a,
...r ? { skillDetails: r } : {},
mcpServers: o,
commands: s,
hooks: c,
lspServers: [],
unavailable: {
capabilities: [],
mcpServers: sortUniqueStrings(e?.unsupportedServerNames ?? []),
lspServers: []
}
};
}
const a = inspectBundlePluginArtifact({
format: t.bundleFormat,
capabilities: t.bundleCapabilities ?? []
});
const o = new Set(a.mapped);
const s = o.has("hooks") && t.rootDir ? sortUniqueStrings((t.hooks ?? []).filter((e) => loadHookEntriesFromDir({
dir: path.resolve(t.rootDir, e),
rootDir: t.rootDir,
pluginId: t.id,
source: "openclaw-plugin"
}).some(({ hook: e }) => Boolean(e.handlerPath)))) : [];
if (o.has("hooks") && s.length === 0) {
o.delete("hooks");
a.unavailable.push("hooks");
}
const c = t.rootDir ? inspectBundleMcpRuntimeSupport({
pluginId: t.id,
rootDir: t.rootDir,
bundleFormat: t.bundleFormat
}) : void 0;
const l = t.rootDir ? inspectBundleLspRuntimeSupport({
pluginId: t.id,
rootDir: t.rootDir,
bundleFormat: t.bundleFormat
}) : void 0;
return {
mapped: sortUniqueStrings(o),
skills: o.has("skills") ? i : [],
...o.has("skills") && r ? { skillDetails: r } : {},
mcpServers: o.has("mcpServers") ? sortUniqueStrings(c?.supportedServerNames ?? []) : [],
commands: [],
hooks: s,
lspServers: o.has("lspServers") ? sortUniqueStrings(l?.supportedServerNames ?? []) : [],
unavailable: {
capabilities: sortUniqueStrings(a.unavailable),
mcpServers: sortUniqueStrings(c?.unsupportedServerNames ?? []),
lspServers: sortUniqueStrings(l?.unsupportedServerNames ?? [])
}
};
}
//#endregion
//#region src/plugins/installed-plugin-overview.ts
/** Project a selected manifest's summary, never its package-wide consent union. */
function projectPluginOverviewCapabilities(e, t) {
const n = {};
for (const t of e.contracts) {
const e = t.indexOf(": ");
(n[t.slice(0, e)] ??= []).push(t.slice(e + 2));
}
const r = validatePluginUiCapabilities(t);
if (!r.ok) throw new Error(`Invalid plugin uiCapabilities: ${r.error}`);
return {
providers: e.providers,
channels: e.channels,
contracts: n,
...r.capabilities !== void 0 ? { ui: r.capabilities } : {}
};
}
/** Read presentation artifacts through the lifecycle-owned, bounded plugin root cache. */
function readInstalledPluginOverview(e) {
if (!e) return;
const read = (t) => readPluginCacheFile({
rootDir: e.rootDir,
relativePath: t,
rejectHardlinks: shouldRejectHardlinkedPluginFiles(e),
maxBytes: 524288
});
const t = read("README.md");
const n = read("package.json");
const r = n.ok ? parsePluginCacheJson(n) : void 0;
const i = asRecord(r?.ok ? r.value : void 0);
const a = typeof i.repository === "string" ? i.repository : asRecord(i.repository).url;
const o = normalizeOptionalString(a);
const s = normalizeOptionalString(i.homepage);
const c = normalizeOptionalString(asRecord(i.author).name);
return {
hasNativeUi: Boolean(e.controlUi),
capabilities: projectPluginOverviewCapabilities(buildPluginCapabilitySummary({
manifest: e,
origin: e.origin
}).declared, e.uiCapabilities),
...t.ok ? { readme: t.contents.toString("utf8") } : {},
...o ? { repositoryUrl: o } : {},
...s ? { documentationUrl: s } : {},
...c ? { publisherName: c } : {}
};
}
//#endregion
//#region src/plugins/catalog-discovery.ts
const DISCOVERY_ID_PREFIX = "ch_";
const LOCAL_DISCOVERY_ID_PREFIX = "local_";
const DISCOVERY_ID_PAYLOAD = /^[A-Za-z0-9_-]+$/u;
function normalizedAlias(e) {
return e?.trim().toLowerCase() || void 0;
}
function indexClawHubPlugins(e) {
const t = /* @__PURE__ */ new Map();
for (const n of e) {
const e = normalizedAlias(localClawHubIdentity(n));
if (e) t.set(e, n);
}
return t;
}
function projectLocalFacts(e, t, n = true) {
if (!e) return {
present: false,
installed: false,
enabled: false,
state: "not-installed",
action: t ? "install" : "unavailable"
};
return {
present: true,
installed: e.installed,
enabled: e.enabled,
state: e.state,
pluginId: e.id,
...!e.installed && e.install ? { install: e.install } : {},
action: e.installed ? "manage" : t && (n || e.install) ? "install" : "unavailable"
};
}
/** URL-safe route identity. Package aliases remain private to the Gateway join. */
function encodeDiscoveryId(e, t) {
const n = t.trim();
if (!n) throw new Error("Cannot encode an empty plugin discovery identity.");
return `${e}${Buffer.from(n, "utf8").toString("base64url")}`;
}
function encodePluginDiscoveryId(e) {
const t = e.trim();
if (!t) throw new Error("Cannot encode an empty ClawHub package identity.");
return encodeDiscoveryId(DISCOVERY_ID_PREFIX, t);
}
function encodeLocalPluginDiscoveryId(e) {
return encodeDiscoveryId(LOCAL_DISCOVERY_ID_PREFIX, e);
}
/** Discovery identity that joins an installed inventory row to its catalog entry. */
function pluginCatalogId(e) {
return e.clawhubPackage ? encodePluginDiscoveryId(e.clawhubPackage) : encodeLocalPluginDiscoveryId(e.id);
}
function resolvePluginDiscoveryIdentity(e) {
const t = e.startsWith(DISCOVERY_ID_PREFIX) ? DISCOVERY_ID_PREFIX : e.startsWith(LOCAL_DISCOVERY_ID_PREFIX) ? LOCAL_DISCOVERY_ID_PREFIX : void 0;
if (!t) return;
const n = e.slice(t.length);
if (!n || !DISCOVERY_ID_PAYLOAD.test(n)) return;
try {
const r = Buffer.from(n, "base64url").toString("utf8");
return encodeDiscoveryId(t, r) === e ? {
origin: t === DISCOVERY_ID_PREFIX ? "clawhub" : "local",
identity: r
} : void 0;
} catch {
return;
}
}
function joinClawHubPluginCatalog(e) {
const t = indexClawHubPlugins(e.local.plugins);
const n = e.remote.map((n) => {
const r = t.get(normalizedAlias(n.packageName) ?? "");
const i = [.../* @__PURE__ */ new Set([...n.categories, ...r?.capabilityCategories ?? []])];
return {
id: encodePluginDiscoveryId(n.packageName),
catalog: {
name: n.displayName,
packageName: n.packageName,
...n.summary ? { summary: n.summary } : {},
family: n.family,
...n.ownerHandle ? { author: n.ownerHandle } : {},
official: n.isOfficial,
categories: i,
...categoryPriorityFacts(n.packageName, i, e.categories),
...n.iconUrl ? { imageUrl: n.iconUrl } : {},
...n.latestVersion ? { latestVersion: n.latestVersion } : {},
...n.downloads !== void 0 ? { downloads: n.downloads } : {},
...n.installs !== void 0 ? { installs: n.installs } : {},
...n.verificationTier ? { verificationTier: n.verificationTier } : {},
...n.featured !== void 0 ? { featured: n.featured } : {},
...n.trending !== void 0 ? { trending: n.trending } : {},
...n.featuredRank !== void 0 ? { featuredRank: n.featuredRank } : {},
...n.trendingRank !== void 0 ? { trendingRank: n.trendingRank } : {},
publishedToClawHub: true
},
local: projectLocalFacts(r, e.local.mutationAllowed)
};
});
if (!e.includeBundledOnly && e.intent !== "all" || e.cursor) return n;
const r = new Set(e.remote.map((e) => normalizedAlias(e.packageName)));
const i = normalizedAlias(e.query);
const a = [...e.local.plugins.filter((t) => !r.has(normalizedAlias(localClawHubIdentity(t))) && (e.intent === "all" && t.installed && (!e.categories || e.query?.trim() || t.capabilityCategories?.some((t) => !e.category || t === e.category)) || e.includeBundledOnly && t.origin === "bundled" && (e.intent !== "bundled" || !localClawHubIdentity(t)))).filter((t) => {
const n = localDiscoveryCategories(t);
if (e.category && !n.includes(e.category)) return false;
if (!i) return true;
return [
t.id,
t.packageName,
t.name,
t.description,
...n
].flatMap((e) => e ? [e.toLowerCase()] : []).some((e) => e.includes(i));
}).toSorted((e, t) => e.name.localeCompare(t.name)).map((t) => projectLocalDiscoveryEntry(t, e.local.mutationAllowed, e.includeBundledOnly && t.origin === "bundled", e.categories)), ...n];
return e.intent === "all" && !i ? a.toSorted((t, n) => comparePluginCatalogEntries(t, n, e.category)) : a;
}
function localDiscoveryCategories(e) {
return [.../* @__PURE__ */ new Set([...e.categories ?? (e.category ? [e.category] : []), ...e.capabilityCategories ?? []])];
}
function localClawHubIdentity(e) {
return e.clawhubPackage ?? (e.install?.source === "clawhub" ? e.install.packageName : void 0);
}
function projectLocalDiscoveryEntry(e, t, n = false, r) {
const i = localClawHubIdentity(e);
const a = i ? true : n ? false : void 0;
const o = e.clawhubPackage ?? e.packageName;
const s = e.origin === "bundled";
return {
id: i ? encodePluginDiscoveryId(i) : encodeLocalPluginDiscoveryId(e.id),
catalog: {
name: e.name,
...o ? { packageName: o } : {},
...e.description ? { summary: e.description } : {},
official: s,
...s ? { author: "openclaw" } : {},
categories: localDiscoveryCategories(e),
...s ? categoryPriorityFacts(o, localDiscoveryCategories(e), r) : {},
...a !== void 0 ? { publishedToClawHub: a } : {},
...e.version ? { latestVersion: e.version } : {}
},
local: projectLocalFacts(e, t, false)
};
}
function categoryPriorityFacts(e, t, n = []) {
const r = n.flatMap((n) => {
const r = e && t.includes(n.slug) ? n.pinnedPackages?.indexOf(e) ?? -1 : -1;
return r >= 0 ? [[n.slug, r]] : [];
});
return r.length ? { categoryRanks: Object.fromEntries(r) } : {};
}
function findLocalPluginByIdentity(e, t, n = "clawhub") {
return n === "local" ? e.plugins.find((e) => e.id === t) : indexClawHubPlugins(e.plugins).get(normalizedAlias(t) ?? "");
}
function joinLocalPluginDetail(e) {
const t = projectLocalDiscoveryEntry(e.plugin, e.local.mutationAllowed);
const n = e.inspection;
const r = n?.overview?.capabilities;
const i = { ...r?.contracts };
if (n?.declared.tools.length) i.tools = n.declared.tools;
return {
plugin: t,
detail: {
origin: "local",
...t.catalog.official ? { author: {
handle: "openclaw",
displayName: "OpenClaw",
official: true
} } : n?.overview?.publisherName ? { author: { displayName: n.overview.publisherName } } : {},
...e.plugin.packageName ? { packageName: e.plugin.packageName } : {},
topics: [],
...n?.overview?.readme ? { readme: n.overview.readme } : {},
...n?.overview?.repositoryUrl ? { repositoryUrl: n.overview.repositoryUrl } : {},
...n?.overview?.documentationUrl ? { documentationUrl: n.overview.documentationUrl } : {},
...Object.keys(i).length ? { contracts: i } : {},
...r?.providers.length ? { providers: r.providers } : {},
...r?.channels.length ? { channels: r.channels } : {},
...r?.ui !== void 0 ? { uiCapabilities: r.ui } : {},
configuration: [],
mcpServers: n?.components.mcpServers ?? [],
skills: (n?.components.skills ?? []).map((e) => ({ name: e })),
versions: [],
selectedRelease: null,
downloadability: {
status: "unknown",
reason: "Local metadata does not establish ClawHub release downloadability."
}
}
};
}
function joinClawHubPluginDetail(e) {
const [t] = joinClawHubPluginCatalog({
remote: [e.remote],
local: e.local
});
if (!t) throw new Error("ClawHub returned no plugin detail.");
return {
plugin: t,
detail: {
origin: "clawhub",
packageName: e.remote.packageName,
registry: e.remote.registry,
tags: e.remote.tags,
selectedRelease: e.remote.selectedRelease,
downloadability: e.remote.downloadability,
metadata: e.remote.metadata,
...e.remote.owner ? { author: e.remote.owner } : {},
topics: e.remote.topics,
...e.remote.createdAt !== void 0 ? { createdAt: e.remote.createdAt } : {},
...e.remote.updatedAt !== void 0 ? { updatedAt: e.remote.updatedAt } : {},
...e.remote.readme ? { readme: e.remote.readme } : {},
...e.remote.repositoryUrl ? { repositoryUrl: e.remote.repositoryUrl } : {},
...e.remote.documentationUrl ? { documentationUrl: e.remote.documentationUrl } : {},
...e.remote.compatibility ? { compatibility: e.remote.compatibility } : {},
...e.remote.contracts ? { contracts: e.remote.contracts } : {},
...e.remote.providers ? { providers: e.remote.providers } : {},
...e.remote.channels ? { channels: e.remote.channels } : {},
...e.remote.uiCapabilities !== void 0 ? { uiCapabilities: e.remote.uiCapabilities } : {},
configuration: e.remote.configFields,
mcpServers: e.remote.mcpServers,
...e.remote.mcpServerDetails ? { mcpServerDetails: e.remote.mcpServerDetails } : {},
skills: e.remote.skills,
versions: e.remote.versions,
...e.remote.verification ? { verification: e.remote.verification } : {},
...e.remote.security ? { security: e.remote.security } : {}
}
};
}
/** Project advisory registry metadata without issuing package capability consent. */
function projectClawHubPluginInspection(e) {
const { remote: t, local: n, config: r } = e;
const i = findLocalPluginByIdentity(n, t.packageName);
const a = i?.installed ? i : void 0;
const o = t.runtimeId ? findLocalPluginByIdentity({
...n,
plugins: n.plugins.filter((e) => e.id === t.runtimeId)
}, t.packageName) : void 0;
const s = buildPluginCapabilitySummary({
manifest: {
contracts: t.contracts,
channels: t.channels,
providers: t.providers,
mcpServers: Object.fromEntries(t.mcpServers.map((e) => [e, {}])),
skills: t.skills.map((e) => e.name)
},
origin: "global",
entryConfig: o?.installed ? r.plugins?.entries?.[o.id] : void 0
});
const c = joinClawHubPluginDetail({
remote: t,
local: n
});
return {
ok: true,
plugin: {
id: a?.id ?? c.plugin.id,
name: t.displayName,
...t.selectedRelease ? { version: t.selectedRelease.version } : {},
...t.summary ? { description: t.summary } : {},
origin: "clawhub",
installed: Boolean(a),
enabled: a?.enabled ?? false
},
source: {
kind: "clawhub",
packageName: t.packageName
},
...s,
declaredSurfaceStatus: t.metadata.manifest === "available" ? "partial" : "unavailable",
components: emptyInstalledPluginComponents(),
overview: {
...t.metadata.manifest === "available" ? { capabilities: projectPluginOverviewCapabilities(s.declared, t.uiCapabilities) } : {},
...t.readme ? { readme: t.readme } : {},
...t.repositoryUrl ? { repositoryUrl: t.repositoryUrl } : {},
...t.documentationUrl ? { documentationUrl: t.documentationUrl } : {},
...t.owner?.displayName ? { publisherName: t.owner.displayName } : {}
},
...t.trust ? { trust: t.trust } : {},
catalog: c
};
}
//#endregion
export { pluginCatalogId as a, projectPluginOverviewCapabilities as c, projectInstalledPluginComponents as d, joinLocalPluginDetail as i, readInstalledPluginOverview as l, joinClawHubPluginCatalog as n, projectClawHubPluginInspection as o, joinClawHubPluginDetail as r, resolvePluginDiscoveryIdentity as s, findLocalPluginByIdentity as t, emptyInstalledPluginComponents as u };