refactor: deduplicate channel runtime helpers

This commit is contained in:
Peter Steinberger
2026-03-18 16:36:09 +00:00
parent 3e02635df3
commit 27f655ed11
47 changed files with 2595 additions and 1151 deletions

View File

@@ -1,4 +1,4 @@
import { buildAccountScopedAllowlistConfigEditor } from "openclaw/plugin-sdk/allowlist-config-edit";
import { buildDmGroupAccountAllowlistAdapter } from "openclaw/plugin-sdk/allowlist-config-edit";
import { resolveOutboundSendDep } from "openclaw/plugin-sdk/channel-runtime";
import { buildOutboundBaseSessionKey } from "openclaw/plugin-sdk/core";
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
@@ -21,6 +21,7 @@ import { imessageSetupAdapter } from "./setup-core.js";
import {
collectIMessageSecurityWarnings,
createIMessagePluginBase,
imessageConfigAdapter,
imessageResolveDmPolicy,
imessageSetupWizard,
} from "./shared.js";
@@ -113,26 +114,15 @@ export const imessagePlugin: ChannelPlugin<ResolvedIMessageAccount> = {
notifyApproval: async ({ id }) =>
await (await loadIMessageChannelRuntime()).notifyIMessageApproval(id),
},
allowlist: {
supportsScope: ({ scope }) => scope === "dm" || scope === "group" || scope === "all",
readConfig: ({ cfg, accountId }) => {
const account = resolveIMessageAccount({ cfg, accountId });
return {
dmAllowFrom: (account.config.allowFrom ?? []).map(String),
groupAllowFrom: (account.config.groupAllowFrom ?? []).map(String),
dmPolicy: account.config.dmPolicy,
groupPolicy: account.config.groupPolicy,
};
},
applyConfigEdit: buildAccountScopedAllowlistConfigEditor({
channelId: "imessage",
normalize: ({ values }) => formatTrimmedAllowFromEntries(values),
resolvePaths: (scope) => ({
readPaths: [[scope === "dm" ? "allowFrom" : "groupAllowFrom"]],
writePath: [scope === "dm" ? "allowFrom" : "groupAllowFrom"],
}),
}),
},
allowlist: buildDmGroupAccountAllowlistAdapter({
channelId: "imessage",
resolveAccount: ({ cfg, accountId }) => resolveIMessageAccount({ cfg, accountId }),
normalize: ({ values }) => formatTrimmedAllowFromEntries(values),
resolveDmAllowFrom: (account) => account.config.allowFrom,
resolveGroupAllowFrom: (account) => account.config.groupAllowFrom,
resolveDmPolicy: (account) => account.config.dmPolicy,
resolveGroupPolicy: (account) => account.config.groupPolicy,
}),
security: {
resolveDmPolicy: imessageResolveDmPolicy,
collectWarnings: collectIMessageSecurityWarnings,

View File

@@ -1,9 +1,9 @@
import {
collectAllowlistProviderRestrictSendersWarnings,
createScopedChannelConfigAdapter,
createScopedDmSecurityResolver,
formatTrimmedAllowFromEntries,
} from "openclaw/plugin-sdk/channel-config-helpers";
import { createAllowlistProviderRestrictSendersWarningCollector } from "openclaw/plugin-sdk/channel-policy";
import { createChannelPluginBase } from "openclaw/plugin-sdk/core";
import {
buildChannelConfigSchema,
@@ -47,21 +47,16 @@ export const imessageResolveDmPolicy = createScopedDmSecurityResolver<ResolvedIM
policyPathSuffix: "dmPolicy",
});
export function collectIMessageSecurityWarnings(params: {
account: ResolvedIMessageAccount;
cfg: Parameters<typeof resolveIMessageAccount>[0]["cfg"];
}) {
return collectAllowlistProviderRestrictSendersWarnings({
cfg: params.cfg,
providerConfigPresent: params.cfg.channels?.imessage !== undefined,
configuredGroupPolicy: params.account.config.groupPolicy,
export const collectIMessageSecurityWarnings =
createAllowlistProviderRestrictSendersWarningCollector<ResolvedIMessageAccount>({
providerConfigPresent: (cfg) => cfg.channels?.imessage !== undefined,
resolveGroupPolicy: (account) => account.config.groupPolicy,
surface: "iMessage groups",
openScope: "any member",
groupPolicyPath: "channels.imessage.groupPolicy",
groupAllowFromPath: "channels.imessage.groupAllowFrom",
mentionGated: false,
});
}
export function createIMessagePluginBase(params: {
setupWizard?: NonNullable<ChannelPlugin<ResolvedIMessageAccount>["setupWizard"]>;