refactor(channels): centralize match metadata
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import type { SlackReactionNotificationMode } from "../../config/config.js";
|
||||
import type { SlackMessageEvent } from "../types.js";
|
||||
import {
|
||||
applyChannelMatchMeta,
|
||||
buildChannelKeyCandidates,
|
||||
resolveChannelEntryMatchWithFallback,
|
||||
type ChannelMatchSource,
|
||||
} from "../../channels/channel-config.js";
|
||||
import { allowListMatches, normalizeAllowListLower, normalizeSlackSlug } from "./allow-list.js";
|
||||
|
||||
@@ -14,7 +16,7 @@ export type SlackChannelConfigResolved = {
|
||||
skills?: string[];
|
||||
systemPrompt?: string;
|
||||
matchKey?: string;
|
||||
matchSource?: "direct" | "wildcard";
|
||||
matchSource?: ChannelMatchSource;
|
||||
};
|
||||
|
||||
function firstDefined<T>(...values: Array<T | undefined>) {
|
||||
@@ -89,16 +91,12 @@ export function resolveSlackChannelConfig(params: {
|
||||
directName,
|
||||
normalizedName,
|
||||
);
|
||||
const {
|
||||
entry: matched,
|
||||
wildcardEntry: fallback,
|
||||
matchKey,
|
||||
matchSource,
|
||||
} = resolveChannelEntryMatchWithFallback({
|
||||
const match = resolveChannelEntryMatchWithFallback({
|
||||
entries,
|
||||
keys: candidates,
|
||||
wildcardKey: "*",
|
||||
});
|
||||
const { entry: matched, wildcardEntry: fallback } = match;
|
||||
|
||||
const requireMentionDefault = defaultRequireMention ?? true;
|
||||
if (keys.length === 0) {
|
||||
@@ -127,11 +125,7 @@ export function resolveSlackChannelConfig(params: {
|
||||
skills,
|
||||
systemPrompt,
|
||||
};
|
||||
if (matchKey) result.matchKey = matchKey;
|
||||
if (matchSource === "direct" || matchSource === "wildcard") {
|
||||
result.matchSource = matchSource;
|
||||
}
|
||||
return result;
|
||||
return applyChannelMatchMeta(result, match);
|
||||
}
|
||||
|
||||
export type { SlackMessageEvent };
|
||||
|
||||
@@ -8,6 +8,7 @@ import { createDedupeCache } from "../../infra/dedupe.js";
|
||||
import { getChildLogger } from "../../logging.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
import type { SlackMessageEvent } from "../types.js";
|
||||
import { formatAllowlistMatchMeta } from "../../channels/allowlist-match.js";
|
||||
|
||||
import { normalizeAllowList, normalizeAllowListLower, normalizeSlackSlug } from "./allow-list.js";
|
||||
import { resolveSlackChannelConfig } from "./channel-config.js";
|
||||
@@ -310,9 +311,7 @@ export function createSlackMonitorContext(params: {
|
||||
channels: params.channelsConfig,
|
||||
defaultRequireMention,
|
||||
});
|
||||
const channelMatchMeta = `matchKey=${channelConfig?.matchKey ?? "none"} matchSource=${
|
||||
channelConfig?.matchSource ?? "none"
|
||||
}`;
|
||||
const channelMatchMeta = formatAllowlistMatchMeta(channelConfig);
|
||||
const channelAllowed = channelConfig?.allowed !== false;
|
||||
const channelAllowlistConfigured =
|
||||
Boolean(params.channelsConfig) && Object.keys(params.channelsConfig ?? {}).length > 0;
|
||||
|
||||
@@ -22,6 +22,7 @@ import { resolveThreadSessionKeys } from "../../../routing/session-key.js";
|
||||
import { resolveMentionGatingWithBypass } from "../../../channels/mention-gating.js";
|
||||
import { resolveConversationLabel } from "../../../channels/conversation-label.js";
|
||||
import { resolveControlCommandGate } from "../../../channels/command-gating.js";
|
||||
import { formatAllowlistMatchMeta } from "../../../channels/allowlist-match.js";
|
||||
import {
|
||||
readSessionUpdatedAt,
|
||||
recordSessionMetaFromInbound,
|
||||
@@ -131,9 +132,7 @@ export async function prepareSlackMessage(params: {
|
||||
allowList: allowFromLower,
|
||||
id: directUserId,
|
||||
});
|
||||
const allowMatchMeta = `matchKey=${allowMatch.matchKey ?? "none"} matchSource=${
|
||||
allowMatch.matchSource ?? "none"
|
||||
}`;
|
||||
const allowMatchMeta = formatAllowlistMatchMeta(allowMatch);
|
||||
if (!allowMatch.allowed) {
|
||||
if (ctx.dmPolicy === "pairing") {
|
||||
const sender = await ctx.resolveUserName(directUserId);
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
import { resolveAgentRoute } from "../../routing/resolve-route.js";
|
||||
import { resolveConversationLabel } from "../../channels/conversation-label.js";
|
||||
import { resolveCommandAuthorizedFromAuthorizers } from "../../channels/command-gating.js";
|
||||
import { formatAllowlistMatchMeta } from "../../channels/allowlist-match.js";
|
||||
|
||||
import type { ResolvedSlackAccount } from "../accounts.js";
|
||||
|
||||
@@ -206,9 +207,7 @@ export function registerSlackMonitorSlashCommands(params: {
|
||||
id: command.user_id,
|
||||
name: senderName,
|
||||
});
|
||||
const allowMatchMeta = `matchKey=${allowMatch.matchKey ?? "none"} matchSource=${
|
||||
allowMatch.matchSource ?? "none"
|
||||
}`;
|
||||
const allowMatchMeta = formatAllowlistMatchMeta(allowMatch);
|
||||
if (!allowMatch.allowed) {
|
||||
if (ctx.dmPolicy === "pairing") {
|
||||
const { code, created } = await upsertChannelPairingRequest({
|
||||
|
||||
Reference in New Issue
Block a user