From 10660fe47dc0222a247058b355d4a201e69f4c28 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 17 Mar 2026 04:24:01 +0000 Subject: [PATCH] refactor(channels): share legacy dm allowlist paths --- extensions/discord/src/channel.ts | 14 +++++--------- extensions/slack/src/channel.ts | 14 +++++--------- src/plugin-sdk/allowlist-config-edit.ts | 10 ++++++++++ src/plugin-sdk/index.ts | 5 ++++- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/extensions/discord/src/channel.ts b/extensions/discord/src/channel.ts index d12813e66a6..a9db3a7937f 100644 --- a/extensions/discord/src/channel.ts +++ b/extensions/discord/src/channel.ts @@ -1,5 +1,8 @@ import { Separator, TextDisplay } from "@buape/carbon"; -import { buildAccountScopedAllowlistConfigEditor } from "openclaw/plugin-sdk/allowlist-config-edit"; +import { + buildAccountScopedAllowlistConfigEditor, + resolveLegacyDmAllowlistConfigPaths, +} from "openclaw/plugin-sdk/allowlist-config-edit"; import { buildAccountScopedDmSecurityPolicy, collectOpenGroupPolicyConfiguredRouteWarnings, @@ -347,14 +350,7 @@ export const discordPlugin: ChannelPlugin = { channelId: "discord", normalize: ({ cfg, accountId, values }) => discordConfigAccessors.formatAllowFrom!({ cfg, accountId, allowFrom: values }), - resolvePaths: (scope) => - scope === "dm" - ? { - readPaths: [["allowFrom"], ["dm", "allowFrom"]], - writePath: ["allowFrom"], - cleanupPaths: [["dm", "allowFrom"]], - } - : null, + resolvePaths: resolveLegacyDmAllowlistConfigPaths, }), }, security: { diff --git a/extensions/slack/src/channel.ts b/extensions/slack/src/channel.ts index 3dfb195be86..4890ab88eaa 100644 --- a/extensions/slack/src/channel.ts +++ b/extensions/slack/src/channel.ts @@ -1,4 +1,7 @@ -import { buildAccountScopedAllowlistConfigEditor } from "openclaw/plugin-sdk/allowlist-config-edit"; +import { + buildAccountScopedAllowlistConfigEditor, + resolveLegacyDmAllowlistConfigPaths, +} from "openclaw/plugin-sdk/allowlist-config-edit"; import { buildAccountScopedDmSecurityPolicy, collectOpenGroupPolicyConfiguredRouteWarnings, @@ -410,14 +413,7 @@ export const slackPlugin: ChannelPlugin = { channelId: "slack", normalize: ({ cfg, accountId, values }) => slackConfigAccessors.formatAllowFrom!({ cfg, accountId, allowFrom: values }), - resolvePaths: (scope) => - scope === "dm" - ? { - readPaths: [["allowFrom"], ["dm", "allowFrom"]], - writePath: ["allowFrom"], - cleanupPaths: [["dm", "allowFrom"]], - } - : null, + resolvePaths: resolveLegacyDmAllowlistConfigPaths, }), }, security: { diff --git a/src/plugin-sdk/allowlist-config-edit.ts b/src/plugin-sdk/allowlist-config-edit.ts index c9f2a92e3be..e92e4cb8551 100644 --- a/src/plugin-sdk/allowlist-config-edit.ts +++ b/src/plugin-sdk/allowlist-config-edit.ts @@ -11,6 +11,16 @@ type AllowlistConfigPaths = { cleanupPaths?: string[][]; }; +const LEGACY_DM_ALLOWLIST_CONFIG_PATHS: AllowlistConfigPaths = { + readPaths: [["allowFrom"], ["dm", "allowFrom"]], + writePath: ["allowFrom"], + cleanupPaths: [["dm", "allowFrom"]], +}; + +export function resolveLegacyDmAllowlistConfigPaths(scope: "dm" | "group") { + return scope === "dm" ? LEGACY_DM_ALLOWLIST_CONFIG_PATHS : null; +} + function resolveAccountScopedWriteTarget( parsed: Record, channelId: ChannelId, diff --git a/src/plugin-sdk/index.ts b/src/plugin-sdk/index.ts index 50949a31a89..acfca49d6ab 100644 --- a/src/plugin-sdk/index.ts +++ b/src/plugin-sdk/index.ts @@ -270,7 +270,10 @@ export { buildChannelSendResult } from "./channel-send-result.js"; export type { ChannelSendRawResult } from "./channel-send-result.js"; export { createPluginRuntimeStore } from "./runtime-store.js"; export { createScopedChannelConfigBase } from "./channel-config-helpers.js"; -export { buildAccountScopedAllowlistConfigEditor } from "./allowlist-config-edit.js"; +export { + buildAccountScopedAllowlistConfigEditor, + resolveLegacyDmAllowlistConfigPaths, +} from "./allowlist-config-edit.js"; export { AllowFromEntrySchema, AllowFromListSchema,