openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
465 lines (464 loc) • 20.8 kB
JavaScript
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs";
import { c as resolveUserPath } from "./home-dir-EKmgmdPG.mjs";
import { r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs";
import "./utils-C8YECn2Q.mjs";
import { a as resolveCompatibilityHostVersion } from "./version-GlxUMdxI.mjs";
import { a as safeRealpathSync } from "./path-safety-CTChYC4Z.mjs";
import { f as resolveEffectiveEnableState, u as normalizePluginsConfig } from "./config-state-B1JlHgba.mjs";
import { n as isBundledPluginInsideDevSourceRoot } from "./dev-source-root-HNpp2lb0.mjs";
import { r as normalizePluginDependencySpecs, t as buildManagedPluginDependencyStatus } from "./status-dependencies-core-BbL--1ba.mjs";
import { S as resolveOfficialExternalWebProviderContractPluginIdsForEnv, a as isExternallyDistributedPlugin, b as resolveOfficialExternalProviderPluginIds, h as resolveOfficialExternalPluginLabel, l as listOfficialExternalPluginCatalogEntries, p as resolveOfficialExternalPluginInstall, x as resolveOfficialExternalProviderPluginIdsForEnv, y as resolveOfficialExternalProviderContractPluginIds } from "./official-external-plugin-catalog-DtkWz1Xo.mjs";
import { n as compareOpenClawReleaseVersions, s as parseRegistryNpmSpec } from "./npm-registry-spec-HKkAvl6N.mjs";
import { s as resolveRetainedManagedNpmInstallPackageInfo } from "./managed-npm-retention-1zEp6KL9.mjs";
import { r as loadInstalledPluginIndexInstallRecords } from "./installed-plugin-index-record-reader-B-7uGQZ9.mjs";
import { c as normalizeUpdateChannel, u as resolveRegistryUpdateChannel } from "./update-channels-CDc4OFaS.mjs";
import { g as resolveOfficialExternalPluginId } from "./official-external-plugin-catalog-source-4o5oPhVN.mjs";
import { t as loadPluginManifestRegistryCore } from "./manifest-registry-CuWv8ibc.mjs";
import { t as createInstalledPluginOwnershipResolver } from "./installed-plugin-package-ownership-BAh5IZ9-.mjs";
import { m as resolveConfiguredChannelPresencePolicy } from "./channel-presence-policy-6XNqNGJr.mjs";
import { n as resolveWebSearchInstallCatalogEntriesForEnv, r as resolveWebSearchInstallCatalogEntry } from "./web-search-install-catalog-jaCvnE6H.mjs";
import { s as loadManifestMetadataSnapshot } from "./manifest-contract-eligibility-DoGGge-2.mjs";
import { i as isNativeSessionCatalogOptOutOnly } from "./native-session-catalog-config-CCzXMHUi.mjs";
import { t as normalizeLowercaseStringSet } from "./normalized-string-set-CJDHSDuW.mjs";
import { n as removePluginInstallRecordFromRecords } from "./installed-plugin-index-records-MNCNSlg8.mjs";
import { _ as collectConfiguredMemoryEmbeddingProviderIds } from "./gateway-startup-plugin-config-DY4atCe0.mjs";
import { t as collectConfiguredSpeechProviderIds } from "./gateway-startup-speech-providers-BTIWPL7P.mjs";
import "./gateway-startup-plugin-ids-G2tS16W7.mjs";
import "./channel-plugin-ids-DZDzcpUB.mjs";
import { n as VERSION_BOUND_RUNTIME_PLUGIN_IDS, t as CONFIGURED_RUNTIME_PLUGIN_INSTALL_CANDIDATES } from "./official-runtime-plugins-m31mbS3Z.mjs";
import { h as shouldDeferConfiguredPluginInstallRepair } from "./update-phase-YdZvaQsy.mjs";
import { t as listDoctorConfiguredChannelIds } from "./configured-channel-ids-4FVS0H72.mjs";
import { n as isPayloadMissing } from "./payload-verification-BFPGDf3M.mjs";
import { r as listRawChannelPluginCatalogEntries } from "./catalog-B7x9RZv9.mjs";
import { n as resolveProviderInstallCatalogEntries } from "./provider-install-catalog-DH6EFiCw.mjs";
import { n as collectConfiguredModelProviderSelectionIds, r as collectConfiguredProviderSelectionIds, t as collectConfiguredMediaProviderSelectionIds } from "./configured-provider-selection-ids-X9wFFU-f.mjs";
import { t as collectConfiguredRuntimePluginIds } from "./configured-runtime-plugin-owners-DtRsZbQR.mjs";
import path from "node:path";
//#region src/commands/doctor/shared/configured-provider-plugin-ids.ts
/** Lists official external provider plugins without loading installed plugin registries. */
function collectConfiguredOfficialProviderPluginIds(e) {
const t = collectConfiguredModelProviderSelectionIds(e.cfg);
const n = collectConfiguredMediaProviderSelectionIds(e.cfg);
return [.../* @__PURE__ */ new Set([
...resolveOfficialExternalProviderPluginIds({ providerIds: t }),
...resolveOfficialExternalProviderPluginIdsForEnv(e.env ?? process.env),
...resolveOfficialExternalProviderContractPluginIds({
contract: "mediaUnderstandingProviders",
providerIds: n
}),
...resolveOfficialExternalProviderContractPluginIds({
contract: "speechProviders",
providerIds: t
})
])].toSorted((e, t) => e.localeCompare(t));
}
function collectConfiguredWebSearchPluginIds(e, t, n) {
const r = e.tools?.web?.search;
if (r?.enabled === false) return [];
const i = n === "backfill" ? typeof r?.provider === "string" ? r.provider : void 0 : normalizeOptionalLowercaseString(r?.provider);
const a = i !== void 0 ? resolveWebSearchInstallCatalogEntry({ providerId: i }) : void 0;
return [...a?.pluginId ? [a.pluginId] : [], ...n === "backfill" || !i ? resolveWebSearchInstallCatalogEntriesForEnv(t).map((e) => e.pluginId) : []];
}
function collectConfiguredWebFetchPluginIds(e, t) {
const n = e.tools?.web?.fetch;
if (n?.enabled === false) return [];
const r = normalizeOptionalLowercaseString(n?.provider);
return [...r ? resolveOfficialExternalProviderContractPluginIds({
contract: "webFetchProviders",
providerIds: /* @__PURE__ */ new Set([r])
}) : [], ...resolveOfficialExternalWebProviderContractPluginIdsForEnv({ env: t })];
}
//#endregion
//#region src/commands/doctor/shared/configured-provider-plugin-installs.ts
function collectConfiguredProviderPluginIds(e) {
const t = collectConfiguredProviderSelectionIds(e.cfg);
const n = new Set(collectConfiguredOfficialProviderPluginIds(e));
if (t.size > 0) {
for (const r of resolveProviderInstallCatalogEntries({
config: e.cfg,
env: e.env,
includeUntrustedWorkspacePlugins: false
})) if ([r.providerId, ...r.providerAliases ?? []].some((e) => t.has(e.toLowerCase()))) n.add(r.pluginId);
}
return [...n].toSorted((e, t) => e.localeCompare(t));
}
//#endregion
//#region src/commands/doctor/shared/missing-configured-plugin-install.ids.ts
function addConfiguredPluginId(e, t) {
if (typeof t !== "string") return;
const n = t.trim();
if (n) e.add(n);
}
function collectConfiguredPluginIds(e, t) {
const n = /* @__PURE__ */ new Set();
const r = asNullableRecord(e.plugins);
if (r?.enabled === false) return n;
const i = asNullableRecord(r?.entries);
for (const [e, t] of Object.entries(i ?? {})) {
if (asNullableRecord(t)?.enabled === false || isNativeSessionCatalogOptOutOnly(e, t)) continue;
addConfiguredPluginId(n, e);
}
for (const r of collectConfiguredWebSearchPluginIds(e, t ?? process.env, "selected")) n.add(r);
for (const r of collectConfiguredRuntimePluginIds(e, { env: t })) n.add(r);
for (const r of collectConfiguredProviderPluginIds({
cfg: e,
env: t
})) n.add(r);
const a = collectConfiguredMemoryEmbeddingProviderIds(e);
if (a.size > 0) for (const e of resolveOfficialExternalProviderContractPluginIds({
contract: "embeddingProviders",
providerIds: a
})) n.add(e);
for (const t of resolveOfficialExternalProviderContractPluginIds({
contract: "speechProviders",
providerIds: collectConfiguredSpeechProviderIds(e)
})) n.add(t);
for (const r of collectConfiguredWebFetchPluginIds(e, t ?? process.env)) n.add(r);
return n;
}
function collectBlockedPluginIds(e) {
const t = /* @__PURE__ */ new Set();
const n = e.plugins?.deny;
if (Array.isArray(n)) for (const e of n) addConfiguredPluginId(t, e);
const r = asNullableRecord(e.plugins?.entries);
for (const [e, n] of Object.entries(r ?? {})) if (asNullableRecord(n)?.enabled === false) addConfiguredPluginId(t, e);
return t;
}
function collectConfiguredChannelIds(e, t) {
if (asNullableRecord(e.plugins)?.enabled === false) return /* @__PURE__ */ new Set();
const n = listRawChannelPluginCatalogEntries({
env: t,
excludeWorkspace: true
}).map((e) => e.id);
return new Set(listDoctorConfiguredChannelIds(e, {
configEntryPolicy: "meaningful",
env: t ?? process.env,
candidateChannelIds: n,
skipWhenPluginsDisabled: true,
excludeExplicitlyDisabled: true
}));
}
function collectEffectiveConfiguredChannelOwnerPluginIds(e) {
const t = /* @__PURE__ */ new Map();
const n = normalizeLowercaseStringSet(e.configuredChannelIds);
if (n.size === 0) return t;
for (const r of resolveConfiguredChannelPresencePolicy({
config: e.cfg,
env: e.env,
includePersistedAuthState: false,
manifestRecords: e.snapshot.plugins
})) {
if (!r.effective || !n.has(r.channelId)) continue;
const e = new Set(r.pluginIds);
if (e.size > 0) t.set(r.channelId, e);
}
return t;
}
//#endregion
//#region src/commands/doctor/shared/missing-configured-plugin-install.candidates.ts
/** Collects dependency failures only for enabled, canonically recorded npm installs. */
function collectInstalledPluginMissingRequiredDependencies(e) {
const t = /* @__PURE__ */ new Map();
const n = normalizePluginsConfig(e.cfg.plugins);
for (const r of e.snapshot.plugins) {
const i = Object.hasOwn(e.installRecords, r.id) ? e.installRecords[r.id] : void 0;
if (!e.isRepairTarget(r.id) || r.origin === "bundled" || e.blockedPluginIds?.has(r.id) || i?.source !== "npm" || !i.installPath?.trim() || !i.spec?.trim()) continue;
const a = parseRegistryNpmSpec(i.spec);
if (!a || r.packageName !== a.name || i.resolvedName && i.resolvedName !== a.name || !resolveEffectiveEnableState({
id: r.id,
origin: r.origin,
config: n,
rootConfig: e.cfg,
enabledByDefault: r.enabledByDefault,
channelIds: r.channels
}).enabled) continue;
const o = e.resolvePathIdentity(r.rootDir);
if (o !== e.resolvePathIdentity(i.installPath)) continue;
const { missing: s } = buildManagedPluginDependencyStatus({
rootDir: o,
dependencyRootDir: resolveRetainedManagedNpmInstallPackageInfo(o)?.projectRoot ?? o,
...normalizePluginDependencySpecs({
dependencies: r.packageDependencies,
optionalDependencies: r.packageOptionalDependencies
})
});
if (s.length > 0) t.set(r.id, {
rootDir: o,
missingRequired: s
});
}
return t;
}
/** Keep doctor diagnostics and actual package repair on the same discovery snapshot. */
async function resolveConfiguredPluginInstallContext(e) {
const t = /* @__PURE__ */ new Map();
const resolvePathIdentity = (n) => {
const r = path.resolve(resolveUserPath(n, e.env));
return safeRealpathSync(r, t) ?? r;
};
const n = loadManifestMetadataSnapshot({
config: e.cfg,
env: e.env
});
const r = loadPluginManifestRegistryCore({
config: e.cfg,
env: e.env,
installRecords: {}
}).plugins.filter((e) => e.origin === "bundled");
const i = /* @__PURE__ */ new Set([...n.plugins.filter((e) => e.origin !== "bundled").map((e) => e.id), ...r.map((e) => e.id)]);
const a = collectEffectiveConfiguredChannelOwnerPluginIds({
cfg: e.cfg,
env: e.env,
snapshot: n,
configuredChannelIds: e.configuredChannelIds
});
const isRepairTarget = (t) => e.configuredPluginIds.has(t) || e.configuredChannelIds.has(t) || [...a.values()].some((e) => e.has(t));
const o = new Map(r.flatMap((t) => {
const n = isExternallyDistributedPlugin({
pluginId: t.id,
packageName: t.packageName,
packageBuild: t.packageManifest?.build
});
const r = isBundledPluginInsideDevSourceRoot({
rootDir: t.rootDir,
env: e.env
});
return !n || r ? [[t.id, {
packageName: t.packageName,
preserveExternalInstallRecord: n && r
}]] : [];
}));
const { configuredPluginIds: s, configuredChannelIds: c } = e;
const l = (() => {
const e = /* @__PURE__ */ new Set();
const t = new Map(n.plugins.map((e) => [e.id, e]));
for (const r of n.diagnostics) {
const n = r.pluginId?.trim();
if (!n || !r.message.includes(MISSING_CHANNEL_CONFIG_DESCRIPTOR_DIAGNOSTIC)) continue;
const i = t.get(n)?.channels.some((e) => c.has(e));
if (s.has(n) || i) e.add(n);
}
return e;
})();
const u = e.baselineRecords ?? await loadInstalledPluginIndexInstallRecords({ env: e.env });
const d = /* @__PURE__ */ new Set();
if (e.cfg.plugins?.load?.paths?.length) {
const t = createInstalledPluginOwnershipResolver({
...n.index,
installRecords: u
}, e.env);
for (const e of n.index.plugins) {
const n = t.resolveUpdate(e.pluginId);
if (n.ok && n.value.kind === "operator-managed") {
d.add(e.pluginId);
if (n.value.shadowedInstallOwner) d.add(n.value.shadowedInstallOwner);
}
}
}
const f = e.coreVersion ?? resolveCompatibilityHostVersion(e.env);
const p = resolveRegistryUpdateChannel({
configChannel: normalizeUpdateChannel(e.cfg.update?.channel),
currentVersion: f
});
const m = (() => {
const e = /* @__PURE__ */ new Set();
for (const t of n.diagnostics) {
const n = t.pluginId?.trim();
if (!n || !Object.hasOwn(u, n)) continue;
const r = u[n]?.installPath;
if (r && t.source && resolvePathIdentity(t.source) === resolvePathIdentity(r) && REPAIRABLE_PACKAGE_ENTRY_DIAGNOSTIC_MARKERS.some((e) => t.message.includes(e))) e.add(n);
}
return e;
})();
const h = e.configuredPluginIds;
const g = (() => {
const e = /* @__PURE__ */ new Set();
const t = normalizeOptionalLowercaseString(f);
if (!t) return e;
for (const r of CONFIGURED_RUNTIME_PLUGIN_INSTALL_CANDIDATES) {
if (!VERSION_BOUND_RUNTIME_PLUGIN_IDS.has(r.pluginId) || !h.has(r.pluginId)) continue;
const i = u[r.pluginId];
if (!i) continue;
const a = n.byPluginId?.get(r.pluginId) ?? n.plugins.find((e) => e.id === r.pluginId);
const o = normalizeOptionalLowercaseString(i.resolvedVersion ?? i.version ?? a?.packageVersion ?? a?.version);
if (!o) continue;
const s = compareOpenClawReleaseVersions(o, t);
if (s === null ? o !== t : s < 0) e.add(r.pluginId);
}
return e;
})();
const _ = collectInstalledPluginMissingRequiredDependencies({
cfg: e.cfg,
isRepairTarget,
snapshot: n,
installRecords: u,
blockedPluginIds: e.blockedPluginIds,
resolvePathIdentity
});
const v = /* @__PURE__ */ new Set([
...m,
...g,
..._.keys()
]);
const y = new Set([...v].filter((e) => !_.has(e) && isRepairTarget(e)));
const b = new Set(y.size === 0 ? [] : collectDownloadableInstallCandidates({
...e,
configuredChannelOwnerPluginIds: a,
missingPluginIds: y
}).filter((e) => y.has(e.pluginId) && e.trustedSourceLinkedOfficialInstall).map((e) => e.pluginId));
const x = new Set(n.discovery?.candidates.filter((e) => e.configSelected).flatMap((e) => [e.rootDir, e.source]).map(resolvePathIdentity));
const S = /* @__PURE__ */ new Map();
for (const e of n.plugins) if (e.origin === "config" || x.size > 0 && [e.rootDir, e.source].some((e) => x.has(resolvePathIdentity(e)))) S.set(e.id, e.rootDir);
const C = /* @__PURE__ */ new Set();
for (const [t, n] of Object.entries(u)) {
if (v.has(t)) continue;
const r = S.get(t);
const i = [n.installPath, n.sourcePath].filter((e) => Boolean(e?.trim()));
if (!r || n.source !== "path" || i.length === 0) continue;
const a = resolvePathIdentity(r);
if (isPayloadMissing(e.env, n.installPath) && i.every((e) => resolvePathIdentity(e) !== a)) C.add(t);
}
let w = u;
for (const e of C) w = removePluginInstallRecordFromRecords(w, e);
return {
knownIds: i,
configuredChannelOwnerPluginIds: a,
bundledPluginsById: o,
configuredPluginIdsWithStaleDescriptors: l,
operatorManagedPluginIds: d,
stalePathInstallPluginIds: C,
records: w,
persistedRecords: u,
updateChannel: p,
installedPluginIdsWithRepairablePackageDiagnostics: m,
installedPluginIdsWithStaleVersionBoundRuntimePackages: g,
installedPluginIdsWithRepairablePackages: v,
installedPluginMissingRequiredDependencies: _,
officialReplacementPluginIds: b,
collectDeferredRepairs(t) {
const n = new Set(shouldDeferConfiguredPluginInstallRepair(e.env) ? [...collectUpdateDeferredPluginIds({
...e,
configuredChannelOwnerPluginIds: a
})].filter((e) => !d.has(e)) : []);
return {
pluginIds: n,
repairPluginIds: [...n].filter((n) => {
const r = t[n];
return r && (isPayloadMissing(e.env, r.installPath) || _.has(n));
})
};
},
collectRecordedRepairs(t, n, r) {
return Object.entries(w).filter(([a]) => !d.has(a) && !n.has(a) && !b.has(a) && Object.hasOwn(t, a) && !o.has(a) && (e.configuredPluginIds.has(a) && (!i.has(a) || isPayloadMissing(e.env, t[a]?.installPath)) || l.has(a) || v.has(a) || r?.has(a)));
},
collectInstallCandidates(t, n) {
const r = [...e.configuredPluginIds].filter((r) => {
if (d.has(r) || n.has(r)) return false;
const a = Object.hasOwn(t, r);
return !o.has(r) && (a ? isPayloadMissing(e.env, t[r]?.installPath) : !i.has(r));
});
return collectDownloadableInstallCandidates({
...e,
configuredChannelOwnerPluginIds: a,
missingPluginIds: /* @__PURE__ */ new Set([...r, ...b]),
blockedPluginIds: /* @__PURE__ */ new Set([
...e.blockedPluginIds ?? [],
...n,
...d
])
});
}
};
}
const MISSING_CHANNEL_CONFIG_DESCRIPTOR_DIAGNOSTIC = "without channelConfigs metadata";
const REPAIRABLE_PACKAGE_ENTRY_DIAGNOSTIC_MARKERS = [
"extension entry not found",
"extension entry escapes package directory",
"extension entry unreadable",
"requires compiled runtime output"
];
function collectDownloadableInstallCandidates(e) {
const { configuredPluginIds: t, configuredChannelIds: n } = e;
if (e.missingPluginIds.size === 0 && t.size === 0 && n.size === 0) return [];
const r = /* @__PURE__ */ new Map();
function setDownloadableInstallCandidate(e) {
const t = e.install.npmSpec?.trim();
const n = e.install.clawhubSpec?.trim();
if (!t && !n) return;
r.set(e.pluginId, {
pluginId: e.pluginId,
label: e.label,
...t ? { npmSpec: t } : {},
...n ? { clawhubSpec: n } : {},
...e.install.expectedIntegrity ? { expectedIntegrity: e.install.expectedIntegrity } : {},
...e.trustedSourceLinkedOfficialInstall ? { trustedSourceLinkedOfficialInstall: true } : {},
...e.install.defaultChoice ? { defaultChoice: e.install.defaultChoice } : {}
});
}
const isRequestedPlugin = (n) => t.has(n) || e.missingPluginIds.has(n);
for (const t of listRawChannelPluginCatalogEntries({
env: e.env,
excludeWorkspace: true
})) {
if (t.origin === "bundled") continue;
const r = t.pluginId ?? t.id;
const i = normalizeOptionalLowercaseString(t.id);
if (e.blockedPluginIds?.has(r)) continue;
const a = !isRequestedPlugin(r) && (i ? n.has(i) : n.has(t.id));
const o = i ? e.configuredChannelOwnerPluginIds?.get(i) : void 0;
if (a && o && o.size > 0 && !o.has(r)) continue;
if (!isRequestedPlugin(r) && !n.has(t.id)) continue;
setDownloadableInstallCandidate({
pluginId: r,
label: t.meta.label,
install: t.install,
trustedSourceLinkedOfficialInstall: t.trustedSourceLinkedOfficialInstall
});
}
for (const t of resolveProviderInstallCatalogEntries({
config: e.cfg,
env: e.env,
includeUntrustedWorkspacePlugins: false
})) {
if (!isRequestedPlugin(t.pluginId) || e.blockedPluginIds?.has(t.pluginId)) continue;
setDownloadableInstallCandidate({
pluginId: t.pluginId,
label: t.label,
install: t.install,
trustedSourceLinkedOfficialInstall: t.origin === "bundled"
});
}
for (const t of listOfficialExternalPluginCatalogEntries()) {
const n = resolveOfficialExternalPluginId(t);
if (!n || r.has(n) || e.blockedPluginIds?.has(n)) continue;
if (!isRequestedPlugin(n)) continue;
const i = resolveOfficialExternalPluginInstall(t);
if (!i) continue;
setDownloadableInstallCandidate({
pluginId: n,
label: resolveOfficialExternalPluginLabel(t),
install: i,
trustedSourceLinkedOfficialInstall: true
});
}
for (const t of CONFIGURED_RUNTIME_PLUGIN_INSTALL_CANDIDATES) {
if (!isRequestedPlugin(t.pluginId) || e.blockedPluginIds?.has(t.pluginId)) continue;
const n = r.get(t.pluginId);
if (n && t.versionBoundToOpenClaw) r.set(t.pluginId, {
...n,
versionBoundToOpenClaw: true
});
else if (!n) r.set(t.pluginId, t);
}
return [...r.values()].toSorted((e, t) => e.pluginId.localeCompare(t.pluginId));
}
function collectUpdateDeferredPluginIds(e) {
const t = new Set(e.configuredPluginIds);
for (const n of collectDownloadableInstallCandidates({
...e,
missingPluginIds: /* @__PURE__ */ new Set()
})) t.add(n.pluginId);
return t;
}
//#endregion
export { collectConfiguredChannelIds as a, collectConfiguredWebFetchPluginIds as c, collectBlockedPluginIds as i, collectConfiguredWebSearchPluginIds as l, collectUpdateDeferredPluginIds as n, collectConfiguredPluginIds as o, resolveConfiguredPluginInstallContext as r, collectConfiguredProviderPluginIds as s, collectDownloadableInstallCandidates as t };