feat(config): add hot-reload config + listMode (human-list/agent-list)

This commit is contained in:
2026-02-26 00:18:05 +00:00
parent 0f526346f4
commit 6d463a4572
8 changed files with 79 additions and 25 deletions

View File

@@ -9,7 +9,9 @@
"config": { "config": {
"enabled": true, "enabled": true,
"discordOnly": true, "discordOnly": true,
"bypassUserIds": ["561921120408698910"], "listMode": "human-list",
"humanList": ["561921120408698910"],
"agentList": [],
"endSymbols": ["🔚"], "endSymbols": ["🔚"],
"noReplyProvider": "whisper-gateway", "noReplyProvider": "whisper-gateway",
"noReplyModel": "no-reply", "noReplyModel": "no-reply",

View File

@@ -51,7 +51,9 @@ Environment overrides:
- `NO_REPLY_MODEL_ID` - `NO_REPLY_MODEL_ID`
- `NO_REPLY_BASE_URL` - `NO_REPLY_BASE_URL`
- `NO_REPLY_API_KEY` - `NO_REPLY_API_KEY`
- `BYPASS_USER_IDS_JSON` - `LIST_MODE` (`human-list` or `agent-list`)
- `HUMAN_LIST_JSON`
- `AGENT_LIST_JSON`
- `END_SYMBOLS_JSON` - `END_SYMBOLS_JSON`
The script: The script:

View File

@@ -10,14 +10,14 @@
- Enable plugin with: - Enable plugin with:
- `discordOnly=true` - `discordOnly=true`
- narrow `bypassUserIds` - `listMode=human-list` with narrow `humanList` (or `agent-list` with narrow `agentList`)
- strict `endSymbols` - strict `endSymbols`
- Point no-reply provider/model to local API - Point no-reply provider/model to local API
- Verify 4 rule paths in `docs/VERIFY.md` - Verify 4 rule paths in `docs/VERIFY.md`
## Stage 2: Wider channel rollout ## Stage 2: Wider channel rollout
- Expand `bypassUserIds` and symbol list based on canary outcomes - Expand `humanList`/`agentList` and symbol list based on canary outcomes
- Monitor false-silent turns - Monitor false-silent turns
- Keep fallback model available - Keep fallback model available

View File

@@ -26,7 +26,10 @@ Required:
Optional: Optional:
- `enabled` (default true) - `enabled` (default true)
- `discordOnly` (default true) - `discordOnly` (default true)
- `bypassUserIds` (default []) - `listMode` (`human-list` | `agent-list`, default `human-list`)
- `humanList` (default [])
- `agentList` (default [])
- `bypassUserIds` (deprecated alias of `humanList`)
- `endSymbols` (default ["🔚"]) - `endSymbols` (default ["🔚"])
- `enableDiscordControlTool` (default true) - `enableDiscordControlTool` (default true)
- `discordControlApiBaseUrl` (default `http://127.0.0.1:8790`) - `discordControlApiBaseUrl` (default `http://127.0.0.1:8790`)

View File

@@ -52,7 +52,17 @@ function pruneDecisionMap(now = Date.now()) {
} }
function shouldInjectEndMarker(reason: string): boolean { function shouldInjectEndMarker(reason: string): boolean {
return reason === "bypass_sender" || reason.startsWith("end_symbol:"); return reason.startsWith("end_symbol:");
}
function getLivePluginConfig(api: OpenClawPluginApi, fallback: WhisperGateConfig): WhisperGateConfig {
const root = (api.config as Record<string, unknown>) || {};
const plugins = (root.plugins as Record<string, unknown>) || {};
const entries = (plugins.entries as Record<string, unknown>) || {};
const entry = (entries.whispergate as Record<string, unknown>) || {};
const cfg = (entry.config as Record<string, unknown>) || {};
if (Object.keys(cfg).length > 0) return cfg as unknown as WhisperGateConfig;
return fallback;
} }
function pickDefined(input: Record<string, unknown>) { function pickDefined(input: Record<string, unknown>) {
@@ -67,14 +77,14 @@ export default {
id: "whispergate", id: "whispergate",
name: "WhisperGate", name: "WhisperGate",
register(api: OpenClawPluginApi) { register(api: OpenClawPluginApi) {
const config = (api.pluginConfig || {}) as WhisperGateConfig & { const baseConfig = (api.pluginConfig || {}) as WhisperGateConfig & {
enableDiscordControlTool?: boolean; enableDiscordControlTool?: boolean;
discordControlApiBaseUrl?: string; discordControlApiBaseUrl?: string;
discordControlApiToken?: string; discordControlApiToken?: string;
discordControlCallerId?: string; discordControlCallerId?: string;
}; };
if (config.enableDiscordControlTool !== false) { if (baseConfig.enableDiscordControlTool !== false) {
api.registerTool( api.registerTool(
{ {
name: "discord_control", name: "discord_control",
@@ -113,12 +123,17 @@ export default {
}, },
async execute(_id: string, params: Record<string, unknown>) { async execute(_id: string, params: Record<string, unknown>) {
const action = String(params.action || "") as DiscordControlAction; const action = String(params.action || "") as DiscordControlAction;
const baseUrl = (config.discordControlApiBaseUrl || "http://127.0.0.1:8790").replace(/\/$/, ""); const live = getLivePluginConfig(api, baseConfig as WhisperGateConfig) as WhisperGateConfig & {
discordControlApiBaseUrl?: string;
discordControlApiToken?: string;
discordControlCallerId?: string;
};
const baseUrl = (live.discordControlApiBaseUrl || "http://127.0.0.1:8790").replace(/\/$/, "");
const body = pickDefined({ ...params, action }); const body = pickDefined({ ...params, action });
const headers: Record<string, string> = { "Content-Type": "application/json" }; const headers: Record<string, string> = { "Content-Type": "application/json" };
if (config.discordControlApiToken) headers.Authorization = `Bearer ${config.discordControlApiToken}`; if (live.discordControlApiToken) headers.Authorization = `Bearer ${live.discordControlApiToken}`;
if (config.discordControlCallerId) headers["X-OpenClaw-Caller-Id"] = config.discordControlCallerId; if (live.discordControlCallerId) headers["X-OpenClaw-Caller-Id"] = live.discordControlCallerId;
const r = await fetch(`${baseUrl}/v1/discord/action`, { const r = await fetch(`${baseUrl}/v1/discord/action`, {
method: "POST", method: "POST",
@@ -153,7 +168,7 @@ export default {
); );
} }
api.registerHook("message:received", async (event, ctx) => { api.on("message_received", async (event, ctx) => {
try { try {
const c = (ctx || {}) as Record<string, unknown>; const c = (ctx || {}) as Record<string, unknown>;
const e = (event || {}) as Record<string, unknown>; const e = (event || {}) as Record<string, unknown>;
@@ -164,7 +179,8 @@ export default {
const content = typeof e.content === "string" ? e.content : ""; const content = typeof e.content === "string" ? e.content : "";
const channel = normalizeChannel(c); const channel = normalizeChannel(c);
const decision = evaluateDecision({ config, channel, senderId, content }); const live = getLivePluginConfig(api, baseConfig as WhisperGateConfig);
const decision = evaluateDecision({ config: live, channel, senderId, content });
sessionDecision.set(sessionKey, { decision, createdAt: Date.now() }); sessionDecision.set(sessionKey, { decision, createdAt: Date.now() });
pruneDecisionMap(); pruneDecisionMap();
api.logger.debug?.( api.logger.debug?.(
@@ -190,13 +206,14 @@ export default {
// no-reply path is consumed here // no-reply path is consumed here
sessionDecision.delete(key); sessionDecision.delete(key);
const live = getLivePluginConfig(api, baseConfig as WhisperGateConfig);
api.logger.info( api.logger.info(
`whispergate: override model for session=${key}, provider=${config.noReplyProvider}, model=${config.noReplyModel}, reason=${rec.decision.reason}`, `whispergate: override model for session=${key}, provider=${live.noReplyProvider}, model=${live.noReplyModel}, reason=${rec.decision.reason}`,
); );
return { return {
providerOverride: config.noReplyProvider, providerOverride: live.noReplyProvider,
modelOverride: config.noReplyModel, modelOverride: live.noReplyModel,
}; };
}); });

View File

@@ -10,6 +10,9 @@
"properties": { "properties": {
"enabled": { "type": "boolean", "default": true }, "enabled": { "type": "boolean", "default": true },
"discordOnly": { "type": "boolean", "default": true }, "discordOnly": { "type": "boolean", "default": true },
"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": [] },
"bypassUserIds": { "type": "array", "items": { "type": "string" }, "default": [] }, "bypassUserIds": { "type": "array", "items": { "type": "string" }, "default": [] },
"endSymbols": { "type": "array", "items": { "type": "string" }, "default": ["🔚"] }, "endSymbols": { "type": "array", "items": { "type": "string" }, "default": ["🔚"] },
"noReplyProvider": { "type": "string" }, "noReplyProvider": { "type": "string" },

View File

@@ -1,6 +1,10 @@
export type WhisperGateConfig = { export type WhisperGateConfig = {
enabled?: boolean; enabled?: boolean;
discordOnly?: boolean; discordOnly?: boolean;
listMode?: "human-list" | "agent-list";
humanList?: string[];
agentList?: string[];
// backward compatibility
bypassUserIds?: string[]; bypassUserIds?: string[];
endSymbols?: string[]; endSymbols?: string[];
noReplyProvider: string; noReplyProvider: string;
@@ -34,14 +38,33 @@ export function evaluateDecision(params: {
return { shouldUseNoReply: false, reason: "non_discord" }; return { shouldUseNoReply: false, reason: "non_discord" };
} }
if (params.senderId && (config.bypassUserIds || []).includes(params.senderId)) { const mode = config.listMode || "human-list";
return { shouldUseNoReply: false, reason: "bypass_sender" }; const humanList = config.humanList || config.bypassUserIds || [];
} const agentList = config.agentList || [];
const senderId = params.senderId || "";
const inHumanList = !!senderId && humanList.includes(senderId);
const inAgentList = !!senderId && agentList.includes(senderId);
const lastChar = getLastChar(params.content || ""); const lastChar = getLastChar(params.content || "");
if (lastChar && (config.endSymbols || []).includes(lastChar)) { const hasEnd = !!lastChar && (config.endSymbols || []).includes(lastChar);
return { shouldUseNoReply: false, reason: `end_symbol:${lastChar}` };
if (mode === "human-list") {
if (inHumanList) {
return { shouldUseNoReply: false, reason: "human_list_sender" };
}
if (hasEnd) {
return { shouldUseNoReply: false, reason: `end_symbol:${lastChar}` };
}
return { shouldUseNoReply: true, reason: "rule_match_no_end_symbol" };
} }
return { shouldUseNoReply: true, reason: "rule_match_no_end_symbol" }; // agent-list mode: listed senders require end symbol; others bypass requirement.
if (!inAgentList) {
return { shouldUseNoReply: false, reason: "non_agent_list_sender" };
}
if (hasEnd) {
return { shouldUseNoReply: false, reason: `end_symbol:${lastChar}` };
}
return { shouldUseNoReply: true, reason: "agent_list_missing_end_symbol" };
} }

View File

@@ -14,7 +14,9 @@ NO_REPLY_PROVIDER_ID="${NO_REPLY_PROVIDER_ID:-whisper-gateway}"
NO_REPLY_MODEL_ID="${NO_REPLY_MODEL_ID:-no-reply}" NO_REPLY_MODEL_ID="${NO_REPLY_MODEL_ID:-no-reply}"
NO_REPLY_BASE_URL="${NO_REPLY_BASE_URL:-http://127.0.0.1:8787/v1}" NO_REPLY_BASE_URL="${NO_REPLY_BASE_URL:-http://127.0.0.1:8787/v1}"
NO_REPLY_API_KEY="${NO_REPLY_API_KEY:-wg-local-test-token}" NO_REPLY_API_KEY="${NO_REPLY_API_KEY:-wg-local-test-token}"
BYPASS_USER_IDS_JSON="${BYPASS_USER_IDS_JSON:-[\"561921120408698910\",\"1474088632750047324\"]}" LIST_MODE="${LIST_MODE:-human-list}"
HUMAN_LIST_JSON="${HUMAN_LIST_JSON:-[\"561921120408698910\",\"1474088632750047324\"]}"
AGENT_LIST_JSON="${AGENT_LIST_JSON:-[]}"
END_SYMBOLS_JSON="${END_SYMBOLS_JSON:-[\"🔚\"]}" END_SYMBOLS_JSON="${END_SYMBOLS_JSON:-[\"🔚\"]}"
STATE_DIR="${STATE_DIR:-$HOME/.openclaw/whispergate-install-records}" STATE_DIR="${STATE_DIR:-$HOME/.openclaw/whispergate-install-records}"
@@ -136,7 +138,7 @@ PY
current_plugins_json='{}' current_plugins_json='{}'
fi fi
new_plugins_json="$(CURRENT_PLUGINS_JSON="$current_plugins_json" PLUGIN_PATH="$PLUGIN_PATH" BYPASS_USER_IDS_JSON="$BYPASS_USER_IDS_JSON" END_SYMBOLS_JSON="$END_SYMBOLS_JSON" NO_REPLY_PROVIDER_ID="$NO_REPLY_PROVIDER_ID" NO_REPLY_MODEL_ID="$NO_REPLY_MODEL_ID" python3 - <<'PY' new_plugins_json="$(CURRENT_PLUGINS_JSON="$current_plugins_json" PLUGIN_PATH="$PLUGIN_PATH" LIST_MODE="$LIST_MODE" HUMAN_LIST_JSON="$HUMAN_LIST_JSON" AGENT_LIST_JSON="$AGENT_LIST_JSON" END_SYMBOLS_JSON="$END_SYMBOLS_JSON" NO_REPLY_PROVIDER_ID="$NO_REPLY_PROVIDER_ID" NO_REPLY_MODEL_ID="$NO_REPLY_MODEL_ID" python3 - <<'PY'
import json, os import json, os
plugins=json.loads(os.environ['CURRENT_PLUGINS_JSON']) plugins=json.loads(os.environ['CURRENT_PLUGINS_JSON'])
if not isinstance(plugins,dict): if not isinstance(plugins,dict):
@@ -157,7 +159,9 @@ entries['whispergate']={
'config': { 'config': {
'enabled': True, 'enabled': True,
'discordOnly': True, 'discordOnly': True,
'bypassUserIds': json.loads(os.environ['BYPASS_USER_IDS_JSON']), 'listMode': os.environ['LIST_MODE'],
'humanList': json.loads(os.environ['HUMAN_LIST_JSON']),
'agentList': json.loads(os.environ['AGENT_LIST_JSON']),
'endSymbols': json.loads(os.environ['END_SYMBOLS_JSON']), 'endSymbols': json.loads(os.environ['END_SYMBOLS_JSON']),
'noReplyProvider': os.environ['NO_REPLY_PROVIDER_ID'], 'noReplyProvider': os.environ['NO_REPLY_PROVIDER_ID'],
'noReplyModel': os.environ['NO_REPLY_MODEL_ID'], 'noReplyModel': os.environ['NO_REPLY_MODEL_ID'],