feat(config): add hot-reload config + listMode (human-list/agent-list)
This commit is contained in:
@@ -52,7 +52,17 @@ function pruneDecisionMap(now = Date.now()) {
|
||||
}
|
||||
|
||||
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>) {
|
||||
@@ -67,14 +77,14 @@ export default {
|
||||
id: "whispergate",
|
||||
name: "WhisperGate",
|
||||
register(api: OpenClawPluginApi) {
|
||||
const config = (api.pluginConfig || {}) as WhisperGateConfig & {
|
||||
const baseConfig = (api.pluginConfig || {}) as WhisperGateConfig & {
|
||||
enableDiscordControlTool?: boolean;
|
||||
discordControlApiBaseUrl?: string;
|
||||
discordControlApiToken?: string;
|
||||
discordControlCallerId?: string;
|
||||
};
|
||||
|
||||
if (config.enableDiscordControlTool !== false) {
|
||||
if (baseConfig.enableDiscordControlTool !== false) {
|
||||
api.registerTool(
|
||||
{
|
||||
name: "discord_control",
|
||||
@@ -113,12 +123,17 @@ export default {
|
||||
},
|
||||
async execute(_id: string, params: Record<string, unknown>) {
|
||||
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 headers: Record<string, string> = { "Content-Type": "application/json" };
|
||||
if (config.discordControlApiToken) headers.Authorization = `Bearer ${config.discordControlApiToken}`;
|
||||
if (config.discordControlCallerId) headers["X-OpenClaw-Caller-Id"] = config.discordControlCallerId;
|
||||
if (live.discordControlApiToken) headers.Authorization = `Bearer ${live.discordControlApiToken}`;
|
||||
if (live.discordControlCallerId) headers["X-OpenClaw-Caller-Id"] = live.discordControlCallerId;
|
||||
|
||||
const r = await fetch(`${baseUrl}/v1/discord/action`, {
|
||||
method: "POST",
|
||||
@@ -153,7 +168,7 @@ export default {
|
||||
);
|
||||
}
|
||||
|
||||
api.registerHook("message:received", async (event, ctx) => {
|
||||
api.on("message_received", async (event, ctx) => {
|
||||
try {
|
||||
const c = (ctx || {}) 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 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() });
|
||||
pruneDecisionMap();
|
||||
api.logger.debug?.(
|
||||
@@ -190,13 +206,14 @@ export default {
|
||||
|
||||
// no-reply path is consumed here
|
||||
sessionDecision.delete(key);
|
||||
const live = getLivePluginConfig(api, baseConfig as WhisperGateConfig);
|
||||
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 {
|
||||
providerOverride: config.noReplyProvider,
|
||||
modelOverride: config.noReplyModel,
|
||||
providerOverride: live.noReplyProvider,
|
||||
modelOverride: live.noReplyModel,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user