feat(policy): add per-channel channelPolicies with hot-reload list mode/lists

This commit is contained in:
2026-02-26 00:23:47 +00:00
parent 6d463a4572
commit d6f908b813
7 changed files with 68 additions and 6 deletions

View File

@@ -29,6 +29,7 @@ Optional:
- `listMode` (`human-list` | `agent-list`, default `human-list`)
- `humanList` (default [])
- `agentList` (default [])
- `channelPolicies` (per-channel overrides by channelId)
- `bypassUserIds` (deprecated alias of `humanList`)
- `endSymbols` (default ["🔚"])
- `enableDiscordControlTool` (default true)

View File

@@ -178,9 +178,10 @@ export default {
const senderId = normalizeSender(e, c);
const content = typeof e.content === "string" ? e.content : "";
const channel = normalizeChannel(c);
const channelId = typeof c.channelId === "string" ? c.channelId : undefined;
const live = getLivePluginConfig(api, baseConfig as WhisperGateConfig);
const decision = evaluateDecision({ config: live, channel, senderId, content });
const decision = evaluateDecision({ config: live, channel, channelId, senderId, content });
sessionDecision.set(sessionKey, { decision, createdAt: Date.now() });
pruneDecisionMap();
api.logger.debug?.(

View File

@@ -13,6 +13,20 @@
"listMode": { "type": "string", "enum": ["human-list", "agent-list"], "default": "human-list" },
"humanList": { "type": "array", "items": { "type": "string" }, "default": [] },
"agentList": { "type": "array", "items": { "type": "string" }, "default": [] },
"channelPolicies": {
"type": "object",
"additionalProperties": {
"type": "object",
"additionalProperties": false,
"properties": {
"listMode": { "type": "string", "enum": ["human-list", "agent-list"] },
"humanList": { "type": "array", "items": { "type": "string" } },
"agentList": { "type": "array", "items": { "type": "string" } },
"endSymbols": { "type": "array", "items": { "type": "string" } }
}
},
"default": {}
},
"bypassUserIds": { "type": "array", "items": { "type": "string" }, "default": [] },
"endSymbols": { "type": "array", "items": { "type": "string" }, "default": ["🔚"] },
"noReplyProvider": { "type": "string" },

View File

@@ -4,6 +4,15 @@ export type WhisperGateConfig = {
listMode?: "human-list" | "agent-list";
humanList?: string[];
agentList?: string[];
channelPolicies?: Record<
string,
{
listMode?: "human-list" | "agent-list";
humanList?: string[];
agentList?: string[];
endSymbols?: string[];
}
>;
// backward compatibility
bypassUserIds?: string[];
endSymbols?: string[];
@@ -21,9 +30,34 @@ function getLastChar(input: string): string {
return t.length ? t[t.length - 1] : "";
}
function resolvePolicy(config: WhisperGateConfig, channelId?: string) {
const globalMode = config.listMode || "human-list";
const globalHuman = config.humanList || config.bypassUserIds || [];
const globalAgent = config.agentList || [];
const globalEnd = config.endSymbols || ["🔚"];
if (!channelId) {
return { listMode: globalMode, humanList: globalHuman, agentList: globalAgent, endSymbols: globalEnd };
}
const cp = config.channelPolicies || {};
const scoped = cp[channelId];
if (!scoped) {
return { listMode: globalMode, humanList: globalHuman, agentList: globalAgent, endSymbols: globalEnd };
}
return {
listMode: scoped.listMode || globalMode,
humanList: scoped.humanList || globalHuman,
agentList: scoped.agentList || globalAgent,
endSymbols: scoped.endSymbols || globalEnd,
};
}
export function evaluateDecision(params: {
config: WhisperGateConfig;
channel?: string;
channelId?: string;
senderId?: string;
content?: string;
}): Decision {
@@ -38,16 +72,18 @@ export function evaluateDecision(params: {
return { shouldUseNoReply: false, reason: "non_discord" };
}
const mode = config.listMode || "human-list";
const humanList = config.humanList || config.bypassUserIds || [];
const agentList = config.agentList || [];
const policy = resolvePolicy(config, params.channelId);
const mode = policy.listMode;
const humanList = policy.humanList;
const agentList = policy.agentList;
const senderId = params.senderId || "";
const inHumanList = !!senderId && humanList.includes(senderId);
const inAgentList = !!senderId && agentList.includes(senderId);
const lastChar = getLastChar(params.content || "");
const hasEnd = !!lastChar && (config.endSymbols || []).includes(lastChar);
const hasEnd = !!lastChar && policy.endSymbols.includes(lastChar);
if (mode === "human-list") {
if (inHumanList) {