openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
47 lines (46 loc) • 3.56 kB
JavaScript
import { d as normalizeStringEntries } from "./string-normalization-CECOqf64.mjs";
import { t as formatCliCommand } from "./command-format-DwEdrDKL.mjs";
import "./session-key-C09ow4h0.mjs";
import { t as DEFAULT_ACCOUNT_ID } from "./account-id-DbRsdayc.mjs";
import { i as resolveChannelAccountKey } from "./account-lookup-D_rRUHd5.mjs";
//#region src/channels/plugins/helpers.ts
function resolveChannelDefaultAccountId(params) {
return params.plugin.config.defaultAccountId?.(params.cfg) ?? (params.accountIds ?? params.plugin.config.listAccountIds(params.cfg))[0] ?? "default";
}
function formatPairingApproveHint(channelId) {
return `Approve via: ${formatCliCommand(`openclaw pairing list ${channelId}`)} / ${formatCliCommand(`openclaw pairing approve ${channelId} <code>`)}`;
}
function parseOptionalDelimitedEntries(value) {
if (!value?.trim()) return;
const parsed = normalizeStringEntries(value.split(/[\n,;]+/g));
return parsed.length > 0 ? parsed : void 0;
}
function buildAccountScopedDmSecurityPolicy(params) {
const resolvedAccountId = params.accountId ?? params.fallbackAccountId ?? "default";
const channelConfig = params.cfg.channels?.[params.channelKey];
const accountKey = resolveChannelAccountKey(channelConfig?.accounts, resolvedAccountId, params.channelKey, (id) => id);
const defaultAccountKey = resolveChannelAccountKey(channelConfig?.accounts, DEFAULT_ACCOUNT_ID, params.channelKey, (id) => id);
const rootBasePath = `channels.${params.channelKey}.`;
const accountBasePath = `channels.${params.channelKey}.accounts.${accountKey ?? resolvedAccountId}.`;
const defaultBasePath = `channels.${params.channelKey}.accounts.${defaultAccountKey ?? "default"}.`;
const accountConfig = accountKey ? channelConfig?.accounts?.[accountKey] : void 0;
const defaultAccountConfig = params.inheritSharedDefaultsFromDefaultAccount && resolvedAccountId !== "default" ? defaultAccountKey ? channelConfig?.accounts?.[defaultAccountKey] : void 0 : void 0;
const resolveFieldName = (suffix, fallbackField) => suffix == null || suffix === "" ? fallbackField : /^[A-Za-z0-9_-]+$/.test(suffix) ? suffix : null;
const simplePolicyField = resolveFieldName(params.policyPathSuffix, "dmPolicy");
const simpleAllowFromField = resolveFieldName(params.allowFromPathSuffix, "allowFrom");
const matchesAnyField = (config, fields) => fields.some((field) => field != null && config?.[field] !== void 0);
const basePath = simplePolicyField || simpleAllowFromField ? matchesAnyField(accountConfig, [simplePolicyField, simpleAllowFromField]) ? accountBasePath : matchesAnyField(defaultAccountConfig, [simplePolicyField, simpleAllowFromField]) ? defaultBasePath : matchesAnyField(channelConfig, [simplePolicyField, simpleAllowFromField]) ? rootBasePath : accountConfig ? accountBasePath : rootBasePath : accountConfig ? accountBasePath : rootBasePath;
const allowFromPath = `${basePath}${params.allowFromPathSuffix ?? ""}`;
const policyPath = params.policyPathSuffix != null ? `${basePath}${params.policyPathSuffix}` : void 0;
return {
policy: params.policy ?? params.defaultPolicy ?? "pairing",
allowFrom: params.allowFrom ?? [],
policyPath,
allowFromPath,
approveHint: params.approveHint ?? formatPairingApproveHint(params.approveChannelId ?? params.channelKey),
normalizeEntry: params.normalizeEntry,
classifyEntryAuthentication: params.classifyEntryAuthentication
};
}
//#endregion
export { resolveChannelDefaultAccountId as i, formatPairingApproveHint as n, parseOptionalDelimitedEntries as r, buildAccountScopedDmSecurityPolicy as t };