openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
45 lines (44 loc) • 2.31 kB
JavaScript
import { i as parseConcreteConfigPathTokens } from "./dot-path-BJ4tyWKJ.mjs";
import { i as getPluginRegistryForContext } from "./gateway-request-scope-BvvDhs5D.mjs";
import { t as resolveWebSearchInstallCatalogEntries } from "./web-search-install-catalog-jaCvnE6H.mjs";
import { n as resolveBundledExplicitWebFetchProvidersFromPublicArtifacts, r as resolveBundledExplicitWebSearchProvidersFromPublicArtifacts } from "./web-provider-public-artifacts.explicit-DpeYTBV-.mjs";
//#region src/plugins/credential-descriptors.ts
function projectPluginCredentialDescriptors(e, t) {
const n = /* @__PURE__ */ new Map();
for (const r of t) {
if (!r.credentialPath || !r.credentialLabel) continue;
let t;
try {
t = parseConcreteConfigPathTokens(r.credentialPath);
} catch {
continue;
}
if (t.length < 5 || t.length > 32 || t[0] !== "plugins" || t[1] !== "entries" || t[2] !== e || t[3] !== "config") continue;
const i = JSON.stringify(t);
if (n.has(i)) continue;
const a = r.signupUrl && URL.parse(r.signupUrl)?.protocol;
const o = a === "https:" || a === "http:" ? r.signupUrl : void 0;
n.set(i, {
path: t,
label: r.credentialLabel,
envVars: [...r.envVars],
...r.placeholder ? { placeholder: r.placeholder } : {},
...o ? { signupUrl: o } : {},
...r.requiresCredential !== void 0 ? { requiresCredential: r.requiresCredential } : {}
});
}
return [...n.values()];
}
/** Metadata inspection must never enable or activate a plugin to discover a key field. */
function resolvePluginCredentialDescriptors(e) {
const t = getPluginRegistryForContext();
const n = [...t?.webSearchProviders ?? [], ...t?.webFetchProviders ?? []].filter((t) => t.pluginId === e.id).map((e) => e.provider);
if (e.origin === "bundled") {
const t = { onlyPluginIds: [e.id] };
if (e.contracts?.webSearchProviders?.length) n.push(...resolveBundledExplicitWebSearchProvidersFromPublicArtifacts(t) ?? []);
if (e.contracts?.webFetchProviders?.length) n.push(...resolveBundledExplicitWebFetchProvidersFromPublicArtifacts(t) ?? []);
} else if (e.trustedOfficialInstall) n.push(...resolveWebSearchInstallCatalogEntries().filter((t) => t.pluginId === e.id).map((e) => e.provider));
return projectPluginCredentialDescriptors(e.id, n);
}
//#endregion
export { resolvePluginCredentialDescriptors as t };