diff --git a/extensions/matrix/src/matrix/monitor/allowlist.ts b/extensions/matrix/src/matrix/monitor/allowlist.ts index 326360cade5..a48fe63bdb0 100644 --- a/extensions/matrix/src/matrix/monitor/allowlist.ts +++ b/extensions/matrix/src/matrix/monitor/allowlist.ts @@ -1,7 +1,7 @@ import { compileAllowlist, normalizeStringEntries, - resolveAllowlistCandidates, + resolveCompiledAllowlistMatch, type AllowlistMatch, } from "openclaw/plugin-sdk/matrix"; @@ -77,19 +77,13 @@ export function resolveMatrixAllowListMatch(params: { userId?: string; }): MatrixAllowListMatch { const compiledAllowList = compileAllowlist(params.allowList); - if (compiledAllowList.set.size === 0) { - return { allowed: false }; - } - if (compiledAllowList.wildcard) { - return { allowed: true, matchKey: "*", matchSource: "wildcard" }; - } const userId = normalizeMatrixUser(params.userId); const candidates: Array<{ value?: string; source: MatrixAllowListSource }> = [ { value: userId, source: "id" }, { value: userId ? `matrix:${userId}` : "", source: "prefixed-id" }, { value: userId ? `user:${userId}` : "", source: "prefixed-user" }, ]; - return resolveAllowlistCandidates({ + return resolveCompiledAllowlistMatch({ compiledAllowlist: compiledAllowList, candidates, }); diff --git a/src/channels/allowlist-match.ts b/src/channels/allowlist-match.ts index f32d5a2487c..8c105f1e51b 100644 --- a/src/channels/allowlist-match.ts +++ b/src/channels/allowlist-match.ts @@ -60,11 +60,24 @@ export function resolveAllowlistCandidates(params: { return { allowed: false }; } +export function resolveCompiledAllowlistMatch(params: { + compiledAllowlist: CompiledAllowlist; + candidates: Array<{ value?: string; source: TSource }>; +}): AllowlistMatch { + if (params.compiledAllowlist.set.size === 0) { + return { allowed: false }; + } + if (params.compiledAllowlist.wildcard) { + return { allowed: true, matchKey: "*", matchSource: "wildcard" as TSource }; + } + return resolveAllowlistCandidates(params); +} + export function resolveAllowlistMatchByCandidates(params: { allowList: ReadonlyArray; candidates: Array<{ value?: string; source: TSource }>; }): AllowlistMatch { - return resolveAllowlistCandidates({ + return resolveCompiledAllowlistMatch({ compiledAllowlist: compileAllowlist(params.allowList), candidates: params.candidates, }); diff --git a/src/plugin-sdk/matrix.ts b/src/plugin-sdk/matrix.ts index 577a690a4cb..ba4cad93a92 100644 --- a/src/plugin-sdk/matrix.ts +++ b/src/plugin-sdk/matrix.ts @@ -11,6 +11,7 @@ export { export type { ReplyPayload } from "../auto-reply/types.js"; export { compileAllowlist, + resolveCompiledAllowlistMatch, resolveAllowlistCandidates, resolveAllowlistMatchByCandidates, } from "../channels/allowlist-match.js"; diff --git a/src/slack/monitor/allow-list.ts b/src/slack/monitor/allow-list.ts index 53fc6c58505..36417f22839 100644 --- a/src/slack/monitor/allow-list.ts +++ b/src/slack/monitor/allow-list.ts @@ -1,6 +1,6 @@ import { compileAllowlist, - resolveAllowlistCandidates, + resolveCompiledAllowlistMatch, type AllowlistMatch, } from "../../channels/allowlist-match.js"; import { @@ -58,12 +58,6 @@ export function resolveSlackAllowListMatch(params: { allowNameMatching?: boolean; }): SlackAllowListMatch { const compiledAllowList = compileAllowlist(params.allowList); - if (compiledAllowList.set.size === 0) { - return { allowed: false }; - } - if (compiledAllowList.wildcard) { - return { allowed: true, matchKey: "*", matchSource: "wildcard" }; - } const id = params.id?.toLowerCase(); const name = params.name?.toLowerCase(); const slug = normalizeSlackSlug(name); @@ -79,7 +73,7 @@ export function resolveSlackAllowListMatch(params: { ] satisfies Array<{ value?: string; source: SlackAllowListSource }>) : []), ]; - return resolveAllowlistCandidates({ + return resolveCompiledAllowlistMatch({ compiledAllowlist: compiledAllowList, candidates, });