openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
41 lines (40 loc) • 2 kB
JavaScript
import { a as setProviderWebSearchPluginConfigValue, i as resolveProviderWebSearchPluginConfig, n as getTopLevelCredentialValue, o as setScopedCredentialValue, s as setTopLevelCredentialValue, t as getScopedCredentialValue } from "./web-search-provider-config-DP_T4wzm.js";
//#region src/plugin-sdk/provider-web-search-contract-fields.ts
function createSearchCredentialFields(credential) {
switch (credential.type) {
case "scoped": return {
getCredentialValue: (searchConfig) => getScopedCredentialValue(searchConfig, credential.scopeId),
setCredentialValue: (searchConfigTarget, value) => setScopedCredentialValue(searchConfigTarget, credential.scopeId, value)
};
case "top-level": return {
getCredentialValue: getTopLevelCredentialValue,
setCredentialValue: setTopLevelCredentialValue
};
case "none": return {
getCredentialValue: () => void 0,
setCredentialValue: () => {}
};
}
throw new Error("Unsupported web search credential type");
}
function createConfiguredCredentialFields(configuredCredential) {
if (!configuredCredential) return null;
const field = configuredCredential.field ?? "apiKey";
return {
getConfiguredCredentialValue: (config) => resolveProviderWebSearchPluginConfig(config, configuredCredential.pluginId)?.[field],
setConfiguredCredentialValue: (configTarget, value) => {
setProviderWebSearchPluginConfigValue(configTarget, configuredCredential.pluginId, field, value);
}
};
}
/** Create the common credential hooks that web-search provider plugins spread into their entry. */
function createBaseWebSearchProviderContractFields(options) {
const configuredCredentialFields = createConfiguredCredentialFields(options.configuredCredential);
return {
inactiveSecretPaths: options.inactiveSecretPaths ?? (options.credentialPath ? [options.credentialPath] : []),
...createSearchCredentialFields(options.searchCredential),
...configuredCredentialFields
};
}
//#endregion
export { createBaseWebSearchProviderContractFields as t };