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,7 +1,7 @@
import {
buildAccountScopedDmSecurityPolicy,
collectOpenGroupPolicyRestrictSendersWarnings,
mapAllowFromEntries,
createScopedAccountConfigAccessors,
} from "openclaw/plugin-sdk";
import {
buildChannelConfigSchema,
@@ -34,6 +34,17 @@ const meta = {
systemImage: "message.fill",
};
const lineConfigAccessors = createScopedAccountConfigAccessors({
resolveAccount: ({ cfg, accountId }) =>
getLineRuntime().channel.line.resolveLineAccount({ cfg, accountId: accountId ?? undefined }),
resolveAllowFrom: (account: ResolvedLineAccount) => account.config.allowFrom,
formatAllowFrom: (allowFrom) =>
allowFrom
.map((entry) => String(entry).trim())
.filter(Boolean)
.map((entry) => entry.replace(/^line:(?:user:)?/i, "")),
});
function patchLineAccountConfig(
cfg: OpenClawConfig,
lineConfig: LineConfig,
@@ -147,19 +158,7 @@ export const linePlugin: ChannelPlugin<ResolvedLineAccount> = {
configured: Boolean(account.channelAccessToken?.trim() && account.channelSecret?.trim()),
tokenSource: account.tokenSource ?? undefined,
}),
resolveAllowFrom: ({ cfg, accountId }) =>
mapAllowFromEntries(
getLineRuntime().channel.line.resolveLineAccount({ cfg, accountId: accountId ?? undefined })
.config.allowFrom,
),
formatAllowFrom: ({ allowFrom }) =>
allowFrom
.map((entry) => String(entry).trim())
.filter(Boolean)
.map((entry) => {
// LINE sender IDs are case-sensitive; keep original casing.
return entry.replace(/^line:(?:user:)?/i, "");
}),
...lineConfigAccessors,
},
security: {
resolveDmPolicy: ({ cfg, accountId, account }) => {