refactor: share account-scoped config adapter accessors

This commit is contained in:
Peter Steinberger
2026-03-07 23:44:16 +00:00
parent b6318d4df4
commit 846ec320e2
12 changed files with 182 additions and 103 deletions

View File

@@ -1,8 +1,8 @@
import {
buildAccountScopedDmSecurityPolicy,
collectOpenGroupPolicyRestrictSendersWarnings,
createScopedAccountConfigAccessors,
formatNormalizedAllowFromEntries,
mapAllowFromEntries,
} from "openclaw/plugin-sdk";
import {
applyAccountNameToChannelSection,
@@ -223,6 +223,16 @@ function formatAllowEntry(entry: string): string {
return trimmed.replace(/^(mattermost|user):/i, "").toLowerCase();
}
const mattermostConfigAccessors = createScopedAccountConfigAccessors({
resolveAccount: ({ cfg, accountId }) => resolveMattermostAccount({ cfg, accountId }),
resolveAllowFrom: (account: ResolvedMattermostAccount) => account.config.allowFrom,
formatAllowFrom: (allowFrom) =>
formatNormalizedAllowFromEntries({
allowFrom,
normalizeEntry: formatAllowEntry,
}),
});
export const mattermostPlugin: ChannelPlugin<ResolvedMattermostAccount> = {
id: "mattermost",
meta: {
@@ -276,13 +286,7 @@ export const mattermostPlugin: ChannelPlugin<ResolvedMattermostAccount> = {
botTokenSource: account.botTokenSource,
baseUrl: account.baseUrl,
}),
resolveAllowFrom: ({ cfg, accountId }) =>
mapAllowFromEntries(resolveMattermostAccount({ cfg, accountId }).config.allowFrom),
formatAllowFrom: ({ allowFrom }) =>
formatNormalizedAllowFromEntries({
allowFrom,
normalizeEntry: formatAllowEntry,
}),
...mattermostConfigAccessors,
},
security: {
resolveDmPolicy: ({ cfg, accountId, account }) => {