openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
49 lines (48 loc) • 1.89 kB
JavaScript
import { r as normalizeProviderId } from "./provider-id-Cjha-r0T.js";
//#region src/plugins/provider-auth-choice-helpers.ts
function resolveProviderMatch(providers, rawProvider) {
const raw = rawProvider?.trim();
if (!raw) return null;
const normalized = normalizeProviderId(raw);
return providers.find((provider) => normalizeProviderId(provider.id) === normalized) ?? providers.find((provider) => provider.aliases?.some((alias) => normalizeProviderId(alias) === normalized) ?? false) ?? null;
}
function pickAuthMethod(provider, rawMethod) {
const raw = rawMethod?.trim();
if (!raw) return null;
const normalized = raw.toLowerCase();
return provider.auth.find((method) => method.id.toLowerCase() === normalized) ?? provider.auth.find((method) => method.label.toLowerCase() === normalized) ?? null;
}
function isPlainRecord(value) {
return Boolean(value && typeof value === "object" && !Array.isArray(value));
}
function mergeConfigPatch(base, patch) {
if (!isPlainRecord(base) || !isPlainRecord(patch)) return patch;
const next = { ...base };
for (const [key, value] of Object.entries(patch)) {
const existing = next[key];
if (isPlainRecord(existing) && isPlainRecord(value)) next[key] = mergeConfigPatch(existing, value);
else next[key] = value;
}
return next;
}
function applyDefaultModel(cfg, model) {
const models = { ...cfg.agents?.defaults?.models };
models[model] = models[model] ?? {};
const existingModel = cfg.agents?.defaults?.model;
return {
...cfg,
agents: {
...cfg.agents,
defaults: {
...cfg.agents?.defaults,
models,
model: {
...existingModel && typeof existingModel === "object" && "fallbacks" in existingModel ? { fallbacks: existingModel.fallbacks } : void 0,
primary: model
}
}
}
};
}
//#endregion
export { resolveProviderMatch as i, mergeConfigPatch as n, pickAuthMethod as r, applyDefaultModel as t };