UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

77 lines (76 loc) • 3.35 kB
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs"; import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { b as uniqueStrings } from "./string-normalization-DLmfYZXI.mjs"; import { a as getPluginCache } from "./plugin-cache-B_eRuqTM.mjs"; import { r as resolveOpenClawPackageRootSync } from "./openclaw-root-C-ayo09z.mjs"; import { l as readPluginCacheJsonFile, s as readPluginCacheDirectory } from "./plugin-cache-files-e1aGp2KM.mjs"; import { s as resolveBundledPluginsDir } from "./bundled-dir-BKvdAqkP.mjs"; import { t as BUNDLED_OFFICIAL_EXTERNAL_PLUGIN_CATALOG_ENTRIES } from "./official-external-plugin-bundled-catalogs-BXkCPIh3.mjs"; import path from "node:path"; //#region src/channels/bundled-channel-catalog-read.ts const OFFICIAL_CHANNEL_CATALOG_RELATIVE_PATH = path.join("dist", "channel-catalog.json"); function listPackageRoots() { return uniqueStrings([resolveOpenClawPackageRootSync({ cwd: process.cwd() }), resolveOpenClawPackageRootSync({ moduleUrl: import.meta.url })].filter((e) => Boolean(e))); } function readBundledExtensionCatalogEntriesSync(e) { if (!e) return []; try { return readPluginCacheDirectory(e).filter((e) => e.isDirectory()).flatMap((t) => { const n = path.join(e, t.name, "package.json"); const r = readPluginCacheJsonFile(n); return r.ok && isRecord(r.value) ? [r.value] : []; }); } catch { return []; } } function readOfficialCatalogFileSync() { const e = BUNDLED_OFFICIAL_EXTERNAL_PLUGIN_CATALOG_ENTRIES.filter((e) => typeof e === "object" && e !== null); for (const t of listPackageRoots()) { const n = path.join(t, OFFICIAL_CHANNEL_CATALOG_RELATIVE_PATH); const r = readPluginCacheJsonFile(n); if (r.ok && isRecord(r.value)) { const t = Array.isArray(r.value.entries) ? r.value.entries.filter((e) => isRecord(e)) : []; return [...e, ...t]; } } return e; } function toBundledChannelEntry(e) { const t = e.openclaw?.channel; const n = normalizeOptionalLowercaseString(t?.id); if (!n || !t) return null; return { id: n, channel: t, aliases: Array.isArray(t.aliases) ? t.aliases.map((e) => normalizeOptionalLowercaseString(e)).filter((e) => Boolean(e)) : [], order: typeof t.order === "number" && Number.isFinite(t.order) ? t.order : Number.MAX_SAFE_INTEGER }; } function listBundledChannelCatalogEntries() { const e = resolveBundledPluginsDir(); const t = getPluginCache().metadata.bundledChannelCatalogs; const n = JSON.stringify([process.cwd(), e]); const r = t.get(n); if (r) return r; const i = /* @__PURE__ */ new Map(); for (const t of readBundledExtensionCatalogEntriesSync(e)) { const e = toBundledChannelEntry(t); if (e) i.set(e.id, e); } for (const e of readOfficialCatalogFileSync()) { const t = toBundledChannelEntry(e); if (t) i.set(t.id, i.get(t.id) ?? t); } const a = Array.from(i.values()).toSorted((e, t) => e.order - t.order || e.id.localeCompare(t.id)); t.set(n, a); return a; } /** Finds bundled or generated channel metadata by id or alias. */ function findBundledChannelCatalogMetadata(e) { const t = normalizeOptionalLowercaseString(e); if (!t) return; return listBundledChannelCatalogEntries().find((e) => e.id === t || e.aliases.includes(t))?.channel; } //#endregion export { listBundledChannelCatalogEntries as n, findBundledChannelCatalogMetadata as t };