openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
88 lines (87 loc) • 3.59 kB
JavaScript
import { i as asOptionalObjectRecord, r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs";
import { f as normalizeStringEntries } from "./string-normalization-DLmfYZXI.mjs";
import { t as findBundledChannelCatalogMetadata } from "./bundled-channel-catalog-read-CmfX8BTg.mjs";
import { n as getBundledChannelPlugin } from "./bundled-BnH1gY8j.mjs";
import { t as normalizeAnyChannelId } from "./registry-normalize-guW5_4yo.mjs";
import "./registry-BB86xKJa.mjs";
import { t as getChannelPlugin } from "./registry-ByqVE5S3.mjs";
import "./plugins-BoMiRtiY.mjs";
import { r as resolveChannelAccount } from "./account-resolution-D7u1J1M0.mjs";
//#region src/commands/doctor/channel-capabilities.ts
const DEFAULT_DOCTOR_CHANNEL_CAPABILITIES = {
dmAllowFromMode: "topOnly",
groupModel: "sender",
groupAllowFromFallbackToAllowFrom: true,
warnOnEmptyGroupSenderAllowlist: true
};
function mergeDoctorChannelCapabilities(e) {
const valueFor = (t) => e?.[t] ?? DEFAULT_DOCTOR_CHANNEL_CAPABILITIES[t];
return {
dmAllowFromMode: valueFor("dmAllowFromMode"),
...typeof e?.openDmRequiresAllowFromWildcard === "boolean" ? { openDmRequiresAllowFromWildcard: e.openDmRequiresAllowFromWildcard } : {},
groupModel: valueFor("groupModel"),
groupAllowFromFallbackToAllowFrom: valueFor("groupAllowFromFallbackToAllowFrom"),
warnOnEmptyGroupSenderAllowlist: valueFor("warnOnEmptyGroupSenderAllowlist")
};
}
function getDoctorChannelCapabilities(e) {
if (!e) return DEFAULT_DOCTOR_CHANNEL_CAPABILITIES;
const t = findBundledChannelCatalogMetadata(e)?.doctorCapabilities;
if (t) return mergeDoctorChannelCapabilities(t);
const n = normalizeAnyChannelId(e);
if (!n) return DEFAULT_DOCTOR_CHANNEL_CAPABILITIES;
return mergeDoctorChannelCapabilities((getChannelPlugin(n)?.doctor ?? getBundledChannelPlugin(n)?.doctor) || findBundledChannelCatalogMetadata(n)?.doctorCapabilities);
}
/** Resolve configured and runtime account ids through the channel plugin's own semantics. */
async function resolveDoctorChannelAccountIds(e, t, n) {
const r = normalizeAnyChannelId(e);
if (!r) return;
try {
const e = getChannelPlugin(r) ?? getBundledChannelPlugin(r);
if (!e) return;
const resolveAccountIds = async (n) => {
const r = await Promise.all(n.map(async (n) => {
const r = await resolveChannelAccount({
plugin: e,
cfg: t,
accountId: n
});
const i = asOptionalObjectRecord(r)?.accountId;
return typeof i === "string" && i ? i : void 0;
}));
return r.every((e) => e !== void 0) ? r : void 0;
};
const i = await resolveAccountIds(n);
const a = await resolveAccountIds(e.config.listAccountIds(t));
return i && a ? {
configured: i,
runtime: a
} : void 0;
} catch {
return;
}
}
//#endregion
//#region src/commands/doctor/shared/allowlist.ts
/** Return true when an allowFrom-like list has at least one normalized sender entry. */
function hasAllowFromEntries(e) {
return Array.isArray(e) && normalizeStringEntries(e).length > 0;
}
/** Visit the channel before reading accounts so repairs retain parent-first semantics. */
function* iterateDoctorChannelAccounts(e, t, n = false) {
yield {
account: e,
prefix: t
};
for (const [r, i] of Object.entries(asNullableRecord(e.accounts) ?? {})) {
const a = asOptionalObjectRecord(i);
if (a && (!n || a.enabled !== false)) yield {
account: a,
parent: e,
accountId: r,
prefix: `${t}.accounts.${r}`
};
}
}
//#endregion
export { resolveDoctorChannelAccountIds as i, iterateDoctorChannelAccounts as n, getDoctorChannelCapabilities as r, hasAllowFromEntries as t };