refactor(tooling): merge discord_control and whispergate_policy into whispergateway_tools

This commit is contained in:
2026-02-26 01:31:31 +00:00
parent 46e56c6760
commit ca96779159
2 changed files with 112 additions and 130 deletions

View File

@@ -31,6 +31,11 @@ Optional:
- `agentList` (default []) - `agentList` (default [])
- `channelPoliciesFile` (per-channel overrides in a standalone JSON file) - `channelPoliciesFile` (per-channel overrides in a standalone JSON file)
- `enableWhispergatePolicyTool` (default true) - `enableWhispergatePolicyTool` (default true)
Unified optional tool:
- `whispergateway_tools`
- Discord actions: `channel-private-create`, `channel-private-update`, `member-list`
- Policy actions: `policy-get`, `policy-set-channel`, `policy-delete-channel`
- `bypassUserIds` (deprecated alias of `humanList`) - `bypassUserIds` (deprecated alias of `humanList`)
- `endSymbols` (default ["🔚"]) - `endSymbols` (default ["🔚"])
- `enableDiscordControlTool` (default true) - `enableDiscordControlTool` (default true)
@@ -44,16 +49,15 @@ Policy file behavior:
- loaded once on startup into memory - loaded once on startup into memory
- runtime decisions read memory state only - runtime decisions read memory state only
- direct file edits do NOT affect memory state - direct file edits do NOT affect memory state
- `whispergate_policy` tool updates memory first, then persists to file (atomic write) - `whispergateway_tools` policy actions update memory first, then persist to file (atomic write)
## Optional tool: `discord_control` ## Optional tool: `whispergateway_tools`
This plugin now registers an optional tool named `discord_control`. This plugin registers one unified optional tool: `whispergateway_tools`.
To use it, add tool allowlist entry for either: To use it, add tool allowlist entry for either:
- tool name: `discord_control` - tool name: `whispergateway_tools`
- plugin id: `whispergate` - plugin id: `whispergate`
Supported actions: Supported actions:
- `channel-private-create` - Discord: `channel-private-create`, `channel-private-update`, `member-list`
- `channel-private-update` - Policy: `policy-get`, `policy-set-channel`, `policy-delete-channel`
- `member-list`

View File

@@ -137,18 +137,17 @@ export default {
const liveAtRegister = getLivePluginConfig(api, baseConfig as WhisperGateConfig); const liveAtRegister = getLivePluginConfig(api, baseConfig as WhisperGateConfig);
ensurePolicyStateLoaded(api, liveAtRegister); ensurePolicyStateLoaded(api, liveAtRegister);
if (baseConfig.enableDiscordControlTool !== false) {
api.registerTool( api.registerTool(
{ {
name: "discord_control", name: "whispergateway_tools",
description: "Discord admin extension actions: private channel create/update and member list.", description: "WhisperGate unified tool: Discord admin actions + in-memory policy management.",
parameters: { parameters: {
type: "object", type: "object",
additionalProperties: false, additionalProperties: false,
properties: { properties: {
action: { action: {
type: "string", type: "string",
enum: ["channel-private-create", "channel-private-update", "member-list"], enum: ["channel-private-create", "channel-private-update", "member-list", "policy-get", "policy-set-channel", "policy-delete-channel"],
}, },
guildId: { type: "string" }, guildId: { type: "string" },
name: { type: "string" }, name: { type: "string" },
@@ -171,19 +170,32 @@ export default {
after: { type: "string" }, after: { type: "string" },
fields: { anyOf: [{ type: "string" }, { type: "array", items: { type: "string" } }] }, fields: { anyOf: [{ type: "string" }, { type: "array", items: { type: "string" } }] },
dryRun: { type: "boolean" }, dryRun: { type: "boolean" },
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" } },
}, },
required: ["action", "guildId"], required: ["action"],
}, },
async execute(_id: string, params: Record<string, unknown>) { async execute(_id: string, params: Record<string, unknown>) {
const action = String(params.action || "") as DiscordControlAction;
const live = getLivePluginConfig(api, baseConfig as WhisperGateConfig) as WhisperGateConfig & { const live = getLivePluginConfig(api, baseConfig as WhisperGateConfig) as WhisperGateConfig & {
discordControlApiBaseUrl?: string; discordControlApiBaseUrl?: string;
discordControlApiToken?: string; discordControlApiToken?: string;
discordControlCallerId?: string; discordControlCallerId?: string;
enableDiscordControlTool?: boolean;
enableWhispergatePolicyTool?: boolean;
}; };
const baseUrl = (live.discordControlApiBaseUrl || "http://127.0.0.1:8790").replace(/\/$/, ""); ensurePolicyStateLoaded(api, live);
const body = pickDefined({ ...params, action });
const action = String(params.action || "");
const discordActions = new Set(["channel-private-create", "channel-private-update", "member-list"]);
if (discordActions.has(action)) {
if (live.enableDiscordControlTool === false) {
return { content: [{ type: "text", text: "discord actions disabled by config" }], isError: true };
}
const baseUrl = (live.discordControlApiBaseUrl || "http://127.0.0.1:8790").replace(/\/$/, "");
const body = pickDefined({ ...params, action: action as DiscordControlAction });
const headers: Record<string, string> = { "Content-Type": "application/json" }; const headers: Record<string, string> = { "Content-Type": "application/json" };
if (live.discordControlApiToken) headers.Authorization = `Bearer ${live.discordControlApiToken}`; if (live.discordControlApiToken) headers.Authorization = `Bearer ${live.discordControlApiToken}`;
if (live.discordControlCallerId) headers["X-OpenClaw-Caller-Id"] = live.discordControlCallerId; if (live.discordControlCallerId) headers["X-OpenClaw-Caller-Id"] = live.discordControlCallerId;
@@ -194,59 +206,26 @@ export default {
body: JSON.stringify(body), body: JSON.stringify(body),
}); });
const text = await r.text(); const text = await r.text();
if (!r.ok) { if (!r.ok) {
return { return {
content: [{ type: "text", text: `discord_control failed (${r.status}): ${text}` }], content: [{ type: "text", text: `whispergateway_tools discord failed (${r.status}): ${text}` }],
isError: true, isError: true,
}; };
} }
return { content: [{ type: "text", text }] }; return { content: [{ type: "text", text }] };
},
},
{ optional: true },
);
} }
if (baseConfig.enableWhispergatePolicyTool !== false) { if (live.enableWhispergatePolicyTool === false) {
api.registerTool( return { content: [{ type: "text", text: "policy actions disabled by config" }], isError: true };
{ }
name: "whispergate_policy",
description: "Manage WhisperGate in-memory channel policies and persist to file.",
parameters: {
type: "object",
additionalProperties: false,
properties: {
action: {
type: "string",
enum: ["get", "set-channel", "delete-channel"],
},
channelId: { type: "string" },
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" } },
},
required: ["action"],
},
async execute(_id: string, params: Record<string, unknown>) {
const live = getLivePluginConfig(api, baseConfig as WhisperGateConfig);
ensurePolicyStateLoaded(api, live);
const action = String(params.action || "");
if (action === "get") { if (action === "policy-get") {
return { return {
content: [ content: [{ type: "text", text: JSON.stringify({ file: policyState.filePath, policies: policyState.channelPolicies }, null, 2) }],
{
type: "text",
text: JSON.stringify({ file: policyState.filePath, policies: policyState.channelPolicies }, null, 2),
},
],
}; };
} }
if (action === "set-channel") { if (action === "policy-set-channel") {
const channelId = String(params.channelId || "").trim(); const channelId = String(params.channelId || "").trim();
if (!channelId) return { content: [{ type: "text", text: "channelId is required" }], isError: true }; if (!channelId) return { content: [{ type: "text", text: "channelId is required" }], isError: true };
@@ -267,7 +246,7 @@ export default {
} }
} }
if (action === "delete-channel") { if (action === "policy-delete-channel") {
const channelId = String(params.channelId || "").trim(); const channelId = String(params.channelId || "").trim();
if (!channelId) return { content: [{ type: "text", text: "channelId is required" }], isError: true }; if (!channelId) return { content: [{ type: "text", text: "channelId is required" }], isError: true };
const prev = JSON.parse(JSON.stringify(policyState.channelPolicies)); const prev = JSON.parse(JSON.stringify(policyState.channelPolicies));
@@ -286,7 +265,6 @@ export default {
}, },
{ optional: true }, { optional: true },
); );
}
api.on("message_received", async (event, ctx) => { api.on("message_received", async (event, ctx) => {
try { try {