openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
222 lines (221 loc) • 8.87 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { c as resolveUserPath } from "./home-dir-EKmgmdPG.mjs";
import { b as uniqueStrings, f as normalizeStringEntries } from "./string-normalization-DLmfYZXI.mjs";
import "./utils-C8YECn2Q.mjs";
import { t as PLUGIN_ORIGIN_PRIORITIES } from "./record-groups-DII71OvH.mjs";
import { r as resolveOpenClawPackageRootSync } from "./openclaw-root-C-ayo09z.mjs";
import { l as readPluginCacheJsonFile } from "./plugin-cache-files-e1aGp2KM.mjs";
import { t as MANIFEST_KEY } from "./legacy-names-Cq8ruaO5.mjs";
import { s as listOfficialExternalChannelCatalogEntries } from "./official-external-plugin-catalog-DtkWz1Xo.mjs";
import { o as isPrereleaseSemverVersion, s as parseRegistryNpmSpec } from "./npm-registry-spec-HKkAvl6N.mjs";
import { t as describePluginInstallSource } from "./install-source-info-CLoSLSDu.mjs";
import { t as listChannelCatalogEntries } from "./channel-catalog-registry-DPZYoC27.mjs";
import { t as buildManifestChannelMeta } from "./channel-meta-CbOcOgly.mjs";
import { n as resolveExternalPluginCatalogPaths, t as parseExternalPluginCatalogEntries } from "./plugin-catalog-source-D0kzFnjF.mjs";
import path from "node:path";
//#region src/channels/plugins/catalog.ts
function shouldExcludeCatalogEntry(e, t, n) {
const r = normalizeOptionalString(t);
return e.excludeWorkspace === true && n === "workspace" || n !== void 0 && (e.excludeOrigins?.includes(n) ?? false) || Boolean(r && e.excludePluginRefs?.some((e) => e.pluginId === r && (e.origin === void 0 || e.origin === n)));
}
const EXTERNAL_CATALOG_PRIORITY = PLUGIN_ORIGIN_PRIORITIES.bundled.explicit + 1;
const FALLBACK_CATALOG_PRIORITY = EXTERNAL_CATALOG_PRIORITY + 1;
const OFFICIAL_CHANNEL_CATALOG_RELATIVE_PATH = path.join("dist", "channel-catalog.json");
function loadCatalogEntriesFromPaths(e) {
const t = [];
for (const n of e) {
const e = readPluginCacheJsonFile(n);
if (e.ok) t.push(...parseExternalPluginCatalogEntries(e.value));
}
return t;
}
function resolveOfficialCatalogPaths(e) {
if (e.officialCatalogPaths && e.officialCatalogPaths.length > 0) return normalizeStringEntries(e.officialCatalogPaths);
const t = uniqueStrings([resolveOpenClawPackageRootSync({ cwd: process.cwd() }), resolveOpenClawPackageRootSync({ moduleUrl: import.meta.url })].filter((e) => Boolean(e))).map((e) => path.join(e, OFFICIAL_CHANNEL_CATALOG_RELATIVE_PATH));
if (process.execPath) {
const e = path.dirname(process.execPath);
t.push(path.join(e, OFFICIAL_CHANNEL_CATALOG_RELATIVE_PATH));
t.push(path.join(e, "channel-catalog.json"));
}
return uniqueStrings(t);
}
function resolveInstallInfo(e) {
const t = normalizeOptionalString(e.install?.clawhubSpec);
const n = normalizeOptionalString(e.packageName);
let r = normalizeOptionalString(e.install?.npmSpec) ?? (t ? void 0 : n);
const i = normalizeOptionalString(e.packageVersion);
const a = r ? parseRegistryNpmSpec(r) : null;
const o = n ? parseRegistryNpmSpec(n) : null;
if (r && i && isPrereleaseSemverVersion(i) && a?.selectorKind === "none" && (!o || a.name === o.name)) r = `${a.name}@${i}`;
if (!t && !r) return null;
let s = normalizeOptionalString(e.install?.localPath);
if (!s && e.workspaceDir && e.packageDir) s = path.relative(e.workspaceDir, e.packageDir) || void 0;
const c = e.install?.defaultChoice === "local" && s ? "local" : r ? "npm" : "clawhub";
const l = {
...s ? { localPath: s } : {},
defaultChoice: c,
...e.install?.minHostVersion ? { minHostVersion: e.install.minHostVersion } : {},
...e.install?.expectedIntegrity ? { expectedIntegrity: e.install.expectedIntegrity } : {},
...e.install?.allowInvalidConfigRecovery === true ? { allowInvalidConfigRecovery: true } : {}
};
if (t) return {
clawhubSpec: t,
...r ? { npmSpec: r } : {},
...l
};
if (!r) return null;
return {
npmSpec: r,
...l
};
}
function buildCatalogEntryFromManifest(e) {
const t = e.channel;
const n = t?.id?.trim();
const r = t?.label?.trim();
if (!t || !n || !r) return null;
const i = resolveInstallInfo(e);
if (!i) return null;
const a = normalizeOptionalString(e.pluginId);
const o = t.systemImage?.trim();
return {
id: n,
...a ? { pluginId: a } : {},
...e.origin ? { origin: e.origin } : {},
...e.trustedSourceLinkedOfficialInstall ? { trustedSourceLinkedOfficialInstall: true } : {},
channel: t,
meta: buildManifestChannelMeta({
id: n,
channel: t,
label: r,
selectionLabel: t.selectionLabel?.trim() || r,
docsPath: t.docsPath?.trim() || `/channels/${n}`,
docsLabel: normalizeOptionalString(t.docsLabel),
blurb: t.blurb?.trim() || "",
detailLabel: t.detailLabel?.trim(),
...o ? { systemImage: o } : {},
arrayFieldMode: "defined"
}),
install: i,
installSource: describePluginInstallSource(i, { expectedPackageName: e.packageName })
};
}
function buildExternalCatalogEntry(e, t = false) {
const n = e[MANIFEST_KEY];
return buildCatalogEntryFromManifest({
pluginId: n?.plugin?.id,
packageName: e.name,
packageVersion: e.version,
trustedSourceLinkedOfficialInstall: t,
channel: n?.channel,
install: n?.install
});
}
function resolveOfficialCatalogDocsPath(e, t, n) {
let r;
if (e.origin === "bundled" || e.origin === void 0 && e.trustedSourceLinkedOfficialInstall) r = e;
else if ((e.origin === "global" || e.origin === "config") && n) r = t.find((t) => t.id === e.id && (t.pluginId ?? t.id) === e.pluginId && [
t.installSource?.npm?.expectedPackageName,
t.installSource?.npm?.packageName,
t.installSource?.clawhub?.packageName
].includes(n));
const i = r?.meta.docsPath.trim();
if (!i || !i.startsWith("/") || i.startsWith("//") || i.includes("\\")) return;
const a = "https://docs.openclaw.ai";
const o = new URL(i, a);
return o.origin === a && !o.pathname.startsWith("//") ? `${o.pathname}${o.search}${o.hash}` : void 0;
}
function buildChannelUiCatalog(e) {
const t = e.map((e) => {
const t = e.meta.detailLabel ?? e.meta.selectionLabel ?? e.meta.label;
return {
id: e.id,
label: e.meta.label,
detailLabel: t,
...e.meta.systemImage ? { systemImage: e.meta.systemImage } : {}
};
});
const n = t.map((e) => e.id);
const r = {};
const i = {};
const a = {};
for (const e of t) {
r[e.id] = e.label;
i[e.id] = e.detailLabel;
if (e.systemImage) a[e.id] = e.systemImage;
}
return {
entries: t,
order: n,
labels: r,
detailLabels: i,
systemImages: a
};
}
/**
* Raw catalog primitive. This may include untrusted workspace entries and
* workspace shadows. Security-sensitive or execution-facing callers should
* prefer `listTrustedChannelPluginCatalogEntries`; use this primitive only when
* the caller immediately applies trust filtering or explicitly excludes
* workspace entries.
*
* @internal
*/
function listRawChannelPluginCatalogEntries(e = {}) {
const t = listChannelCatalogEntries({
workspaceDir: e.workspaceDir,
env: e.env,
extraPaths: e.extraPaths,
installRecords: e.installRecords,
discovery: e.discovery
});
const n = loadCatalogEntriesFromPaths(resolveOfficialCatalogPaths(e));
const r = [...listOfficialExternalChannelCatalogEntries(), ...n].map((e) => buildExternalCatalogEntry(e, true)).filter((e) => e !== null);
const i = /* @__PURE__ */ new Map();
const rememberCatalogEntry = (e, t, n) => {
const a = i.get(e.id);
if (!a || t < a.priority) {
const a = resolveOfficialCatalogDocsPath(e, r, n);
i.set(e.id, {
entry: a ? {
...e,
officialDocsPath: a
} : e,
priority: t
});
}
};
for (const n of t) {
if (shouldExcludeCatalogEntry(e, n.pluginId, n.origin)) continue;
const t = buildCatalogEntryFromManifest({
pluginId: n.pluginId,
packageName: n.packageName,
packageDir: n.rootDir,
origin: n.origin,
workspaceDir: n.workspaceDir ?? e.workspaceDir,
channel: n.channel,
install: n.install
});
if (!t) continue;
rememberCatalogEntry(t, PLUGIN_ORIGIN_PRIORITIES[n.origin]?.explicit ?? 99, n.trustedOfficialInstall ? n.packageName : void 0);
}
for (const e of r) rememberCatalogEntry(e, FALLBACK_CATALOG_PRIORITY);
const a = resolveExternalPluginCatalogPaths(e).map((t) => resolveUserPath(t, e.env ?? process.env));
for (const e of loadCatalogEntriesFromPaths(a)) {
const t = buildExternalCatalogEntry(e);
if (t) rememberCatalogEntry(t, EXTERNAL_CATALOG_PRIORITY);
}
return Array.from(i.values()).map(({ entry: e }) => e).toSorted((e, t) => {
const n = e.meta.order ?? 999;
const r = t.meta.order ?? 999;
if (n !== r) return n - r;
return e.meta.label.localeCompare(t.meta.label);
});
}
function getChannelPluginCatalogEntry(e, t = {}) {
const n = e.trim();
if (!n) return;
return listRawChannelPluginCatalogEntries(t).find((e) => e.id === n);
}
//#endregion
export { getChannelPluginCatalogEntry as n, listRawChannelPluginCatalogEntries as r, buildChannelUiCatalog as t };