openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
60 lines (59 loc) • 3.58 kB
JavaScript
import { l as normalizeOptionalString, o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs";
import { r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs";
import "./session-key-CqAyZeVk.mjs";
import { n as normalizeAccountId, r as normalizeOptionalAccountId, t as DEFAULT_ACCOUNT_ID } from "./account-id-BqKT3GuY.mjs";
import { i as normalizeChatChannelId } from "./ids-BRSWrLzE.mjs";
import { i as listRouteBindings } from "./bindings-C2C-UuI7.mjs";
import { n as formatSetExplicitDefaultInstruction, r as formatSetExplicitDefaultToConfiguredInstruction, t as formatChannelAccountsDefaultPath } from "./default-account-warnings-Bly3xQ0b.mjs";
//#region src/commands/doctor/shared/default-account-warnings.ts
function normalizeBindingChannelKey(e) {
return normalizeChatChannelId(e) || normalizeLowercaseStringOrEmpty(e);
}
function collectChannelsMissingDefaultAccount(e) {
const t = [];
for (const [n, r] of Object.entries(asNullableRecord(e.channels) ?? {})) {
const e = asNullableRecord(r);
const i = asNullableRecord(e?.accounts);
if (!e || !i) continue;
const a = Array.from(new Set(Object.keys(i).map(normalizeAccountId))).toSorted((e, t) => e.localeCompare(t));
if (a.length === 0 || a.includes("default")) continue;
t.push({
channelKey: n,
channel: e,
normalizedAccountIds: a
});
}
return t;
}
function collectMissingDefaultAccountBindingWarnings(e) {
const t = listRouteBindings(e);
return collectChannelsMissingDefaultAccount(e).flatMap(({ channelKey: e, normalizedAccountIds: n }) => {
const r = new Set(n);
const i = normalizeBindingChannelKey(e);
const a = /* @__PURE__ */ new Set();
for (const e of t) {
const t = asNullableRecord(asNullableRecord(e)?.match);
if (!t) continue;
const n = typeof t.channel === "string" ? normalizeBindingChannelKey(t.channel) : "";
if (!n || n !== i) continue;
const o = normalizeOptionalString(t.accountId);
if (!o) continue;
if (o === "*") return [];
const s = normalizeAccountId(o);
if (r.has(s)) a.add(s);
}
const o = n.filter((e) => !a.has(e));
if (o.length === 0) return [];
return [a.size > 0 ? `- channels.${e}: accounts.default is missing and account bindings only cover a subset of configured accounts. Uncovered accounts: ${o.join(", ")}. Add bindings[].match.accountId for uncovered accounts (or "*"), or add ${formatChannelAccountsDefaultPath(e)}.` : `- channels.${e}: accounts.default is missing and no valid account-scoped binding exists for configured accounts (${n.join(", ")}). Channel-only bindings (no accountId) match only default. Add bindings[].match.accountId for one of these accounts (or "*"), or add ${formatChannelAccountsDefaultPath(e)}.`];
});
}
function collectMissingExplicitDefaultAccountWarnings(e) {
return collectChannelsMissingDefaultAccount(e).flatMap(({ channelKey: e, channel: t, normalizedAccountIds: n }) => {
if (n.length < 2) return [];
const r = normalizeOptionalAccountId(typeof t.defaultAccount === "string" ? t.defaultAccount : void 0);
if (r && n.includes(r)) return [];
return [r ? `- channels.${e}: defaultAccount is set to "${r}" but does not match configured accounts (${n.join(", ")}). ${formatSetExplicitDefaultToConfiguredInstruction({ channelKey: e })} to avoid fallback routing.` : `- channels.${e}: multiple accounts are configured but no explicit default is set. ${formatSetExplicitDefaultInstruction(e)} to avoid fallback routing.`];
});
}
//#endregion
export { collectMissingDefaultAccountBindingWarnings, collectMissingExplicitDefaultAccountWarnings };