openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
48 lines (47 loc) • 2.6 kB
JavaScript
import { f as normalizeStringEntries } from "./string-normalization-DLmfYZXI.mjs";
import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs";
import "./session-key-CqAyZeVk.mjs";
import { t as DEFAULT_ACCOUNT_ID } from "./account-id-BqKT3GuY.mjs";
import { i as resolveChannelAccountKey } from "./account-lookup-FhQZVFfo.mjs";
//#region src/channels/plugins/helpers.ts
function resolveChannelDefaultAccountId(e) {
return e.plugin.config.defaultAccountId?.(e.cfg) ?? (e.accountIds ?? e.plugin.config.listAccountIds(e.cfg))[0] ?? "default";
}
function formatPairingApproveHint(e) {
return `Approve via: ${formatCliCommand(`openclaw pairing list ${e}`)} / ${formatCliCommand(`openclaw pairing approve ${e} <code>`)}`;
}
function parseOptionalDelimitedEntries(e) {
if (!e?.trim()) return;
const t = normalizeStringEntries(e.split(/[\n,;]+/g));
return t.length > 0 ? t : void 0;
}
function buildAccountScopedDmSecurityPolicy(e) {
const t = e.accountId ?? e.fallbackAccountId ?? "default";
const n = e.cfg.channels?.[e.channelKey];
const resolveAccountKey = (t) => resolveChannelAccountKey(n?.accounts, t, e.channelKey, (e) => e);
const r = resolveAccountKey(t);
const i = resolveAccountKey(DEFAULT_ACCOUNT_ID);
const a = `channels.${e.channelKey}.`;
const o = `channels.${e.channelKey}.accounts.${r ?? t}.`;
const s = `channels.${e.channelKey}.accounts.${i ?? "default"}.`;
const c = r ? n?.accounts?.[r] : void 0;
const l = e.inheritSharedDefaultsFromDefaultAccount && t !== "default" ? i ? n?.accounts?.[i] : void 0 : void 0;
const resolveFieldName = (e, t) => e == null || e === "" ? t : /^[A-Za-z0-9_-]+$/.test(e) ? e : null;
const u = resolveFieldName(e.policyPathSuffix, "dmPolicy");
const d = resolveFieldName(e.allowFromPathSuffix, "allowFrom");
const matchesAnyField = (e) => [u, d].some((t) => t != null && e?.[t] !== void 0);
const f = u || d ? matchesAnyField(c) ? o : matchesAnyField(l) ? s : matchesAnyField(n) ? a : c ? o : a : c ? o : a;
const p = `${f}${e.allowFromPathSuffix ?? ""}`;
const m = e.policyPathSuffix != null ? `${f}${e.policyPathSuffix}` : void 0;
return {
policy: e.policy ?? e.defaultPolicy ?? "pairing",
allowFrom: e.allowFrom ?? [],
policyPath: m,
allowFromPath: p,
approveHint: e.approveHint ?? formatPairingApproveHint(e.approveChannelId ?? e.channelKey),
normalizeEntry: e.normalizeEntry,
classifyEntryAuthentication: e.classifyEntryAuthentication
};
}
//#endregion
export { resolveChannelDefaultAccountId as i, formatPairingApproveHint as n, parseOptionalDelimitedEntries as r, buildAccountScopedDmSecurityPolicy as t };