openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
49 lines (48 loc) • 1.92 kB
JavaScript
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs";
import { i as resolveChannelAccountKey, n as resolveAccountKey } from "./account-lookup-FhQZVFfo.mjs";
//#region src/config/channel-account-config.ts
/** Merge authored account overrides over channel defaults, with owner-selected collection rules. */
function mergeAccountConfig(e) {
const t = /* @__PURE__ */ new Set(["accounts", ...e.omitKeys ?? []]);
const n = Object.fromEntries(Object.entries(e.channelConfig ?? {}).filter(([e]) => !t.has(e)));
const r = e.accountConfig;
const i = {
...n,
...r
};
const a = i;
for (const [t, i] of Object.entries(e.inheritEmptyKeys ?? {})) {
const e = r?.[t];
const o = i === "array" ? Array.isArray(e) ? e : void 0 : asOptionalRecord(e);
if (o && Object.keys(o).length === 0) a[t] = n[t];
}
for (const t of e.nestedObjectKeys ?? []) {
const e = asOptionalRecord(n[t]);
const i = asOptionalRecord(r?.[t]);
if (e && i) a[t] = {
...e,
...i
};
}
if (e.preserveRootAllowFrom && Array.isArray(n.allowFrom) && Array.isArray(r?.allowFrom)) {
if (n.allowFrom.some((e) => {
const t = String(e).trim();
return t.length > 0 && t !== "*";
}) && r.allowFrom.some((e) => String(e).trim() === "*")) {
const e = r.allowFrom.filter((e) => String(e).trim() !== "*");
a.allowFrom = e.length > 0 ? e : n.allowFrom;
}
}
return i;
}
/** Resolve a named account before applying the shared channel inheritance rules. */
function resolveMergedAccountConfig(e) {
const t = e.channelId ? resolveChannelAccountKey(e.accounts, e.accountId, e.channelId, e.normalizeAccountId, e.accountKeyPolicy) : resolveAccountKey(e.accounts, e.accountId, e.normalizeAccountId, e.accountKeyPolicy);
const n = t === void 0 ? void 0 : e.accounts?.[t];
return mergeAccountConfig({
...e,
accountConfig: n
});
}
//#endregion
export { resolveMergedAccountConfig as n, mergeAccountConfig as t };