openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
62 lines (61 loc) • 1.96 kB
JavaScript
import "./session-key-CqAyZeVk.mjs";
import { t as DEFAULT_ACCOUNT_ID } from "./account-id-BqKT3GuY.mjs";
import { b as patchChannelConfigForAccount, t as addWildcardAllowFrom } from "./setup-wizard-helpers-BVntL4dp.mjs";
//#region src/plugin-sdk/channel-dm-policy.ts
/** Build an account-aware DM policy descriptor for channel setup flows. */
function createChannelDmPolicy(e) {
const t = e.policyPath ?? "dmPolicy";
const n = e.allowFromPath ?? "allowFrom";
const r = `channels.${e.channel}`;
const resolveContext = (t, n) => ({
cfg: t,
requestedAccountId: n,
account: e.resolveAccount(t, n)
});
const resolveDefaultConfigKeys = (e) => {
const i = e.account.accountId === "default" ? r : `${r}.accounts.${e.account.accountId}`;
return {
policyKey: `${i}.${t}`,
allowFromKey: `${i}.${n}`
};
};
return {
label: e.label,
channel: e.channel,
policyKey: e.policyKey ?? `${r}.${t}`,
allowFromKey: e.allowFromKey ?? `${r}.${n}`,
resolveConfigKeys: (t, n) => {
const r = resolveContext(t, n);
return (e.resolveConfigKeys ?? resolveDefaultConfigKeys)(r);
},
getCurrent: (e, t) => resolveContext(e, t).account.config.dmPolicy ?? "pairing",
setPolicy: (t, n, r) => {
const i = resolveContext(t, r);
const a = {
...i,
policy: n,
allowFrom: e.resolveAllowFrom ? e.resolveAllowFrom({
...i,
policy: n
}) : n === "open" ? addWildcardAllowFrom(i.account.config.allowFrom) : void 0
};
const o = e.buildPatch?.(a) ?? {
dmPolicy: n,
...a.allowFrom === void 0 ? {} : { allowFrom: a.allowFrom }
};
return e.applyPatch ? e.applyPatch({
...i,
patch: o
}) : patchChannelConfigForAccount({
cfg: t,
channel: e.channel,
accountId: i.account.accountId,
patch: o,
setupSurface: typeof e.setupSurface === "function" ? e.setupSurface() : e.setupSurface
});
},
promptAllowFrom: e.promptAllowFrom
};
}
//#endregion
export { createChannelDmPolicy as t };