refactor: share config adapter allowFrom and defaultTo helpers

This commit is contained in:
Peter Steinberger
2026-03-07 23:02:59 +00:00
parent feac26c3b7
commit 556aa8a702
17 changed files with 100 additions and 57 deletions

View File

@@ -2,6 +2,8 @@ import {
buildAccountScopedDmSecurityPolicy,
buildOpenGroupPolicyConfigureRouteAllowlistWarning,
formatNormalizedAllowFromEntries,
mapAllowFromEntries,
resolveOptionalConfigString,
} from "openclaw/plugin-sdk";
import {
applyAccountNameToChannelSection,
@@ -69,9 +71,7 @@ export const googlechatDock: ChannelDock = {
outbound: { textChunkLimit: 4000 },
config: {
resolveAllowFrom: ({ cfg, accountId }) =>
(resolveGoogleChatAccount({ cfg: cfg, accountId }).config.dm?.allowFrom ?? []).map((entry) =>
String(entry),
),
mapAllowFromEntries(resolveGoogleChatAccount({ cfg: cfg, accountId }).config.dm?.allowFrom),
formatAllowFrom: ({ allowFrom }) =>
formatNormalizedAllowFromEntries({
allowFrom,
@@ -177,19 +177,19 @@ export const googlechatPlugin: ChannelPlugin<ResolvedGoogleChatAccount> = {
credentialSource: account.credentialSource,
}),
resolveAllowFrom: ({ cfg, accountId }) =>
(
mapAllowFromEntries(
resolveGoogleChatAccount({
cfg: cfg,
accountId,
}).config.dm?.allowFrom ?? []
).map((entry) => String(entry)),
}).config.dm?.allowFrom,
),
formatAllowFrom: ({ allowFrom }) =>
formatNormalizedAllowFromEntries({
allowFrom,
normalizeEntry: formatAllowFromEntry,
}),
resolveDefaultTo: ({ cfg, accountId }) =>
resolveGoogleChatAccount({ cfg, accountId }).config.defaultTo?.trim() || undefined,
resolveOptionalConfigString(resolveGoogleChatAccount({ cfg, accountId }).config.defaultTo),
},
security: {
resolveDmPolicy: ({ cfg, accountId, account }) => {