feat(tool): register optional discord_control tool in whispergate plugin and align defaults
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"plugins": {
|
"plugins": {
|
||||||
"load": {
|
"load": {
|
||||||
"paths": ["/path/to/WhisperGate/plugin"]
|
"paths": ["/path/to/WhisperGate/dist/whispergate"]
|
||||||
},
|
},
|
||||||
"entries": {
|
"entries": {
|
||||||
"whispergate": {
|
"whispergate": {
|
||||||
@@ -10,19 +10,45 @@
|
|||||||
"enabled": true,
|
"enabled": true,
|
||||||
"discordOnly": true,
|
"discordOnly": true,
|
||||||
"bypassUserIds": ["561921120408698910"],
|
"bypassUserIds": ["561921120408698910"],
|
||||||
"endSymbols": ["。", "!", "?", ".", "!", "?"],
|
"endSymbols": ["🔚"],
|
||||||
"noReplyProvider": "openai",
|
"noReplyProvider": "whisper-gateway",
|
||||||
"noReplyModel": "whispergate-no-reply-v1"
|
"noReplyModel": "no-reply",
|
||||||
|
"enableDiscordControlTool": true,
|
||||||
|
"discordControlApiBaseUrl": "http://127.0.0.1:8790",
|
||||||
|
"discordControlApiToken": "<DISCORD_CONTROL_AUTH_TOKEN>",
|
||||||
|
"discordControlCallerId": "agent-main"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"models": {
|
"models": {
|
||||||
"providers": {
|
"providers": {
|
||||||
"openai": {
|
"whisper-gateway": {
|
||||||
"apiKey": "<AUTH_TOKEN_OR_PLACEHOLDER>",
|
"apiKey": "<NO_REPLY_API_TOKEN_OR_PLACEHOLDER>",
|
||||||
"baseURL": "http://127.0.0.1:8787/v1"
|
"baseUrl": "http://127.0.0.1:8787/v1",
|
||||||
|
"api": "openai-completions",
|
||||||
|
"models": [
|
||||||
|
{
|
||||||
|
"id": "no-reply",
|
||||||
|
"name": "No Reply",
|
||||||
|
"reasoning": false,
|
||||||
|
"input": ["text"],
|
||||||
|
"cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 },
|
||||||
|
"contextWindow": 4096,
|
||||||
|
"maxTokens": 64
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"agents": {
|
||||||
|
"list": [
|
||||||
|
{
|
||||||
|
"id": "main",
|
||||||
|
"tools": {
|
||||||
|
"allow": ["whispergate"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
目标:补齐 OpenClaw 内置 message 工具当前未覆盖的两个能力:
|
目标:补齐 OpenClaw 内置 message 工具当前未覆盖的两个能力:
|
||||||
|
|
||||||
|
> 现在可以通过 WhisperGate 插件内置的可选工具 `discord_control` 直接调用(无需手写 curl)。
|
||||||
|
> 注意:该工具是 optional,需要在 agent tools allowlist 中显式允许(例如允许 `whispergate` 或 `discord_control`)。
|
||||||
|
|
||||||
1. 创建指定名单可见的私人频道
|
1. 创建指定名单可见的私人频道
|
||||||
2. 查看 server 成员列表(分页)
|
2. 查看 server 成员列表(分页)
|
||||||
|
|
||||||
|
|||||||
@@ -27,4 +27,20 @@ Optional:
|
|||||||
- `enabled` (default true)
|
- `enabled` (default true)
|
||||||
- `discordOnly` (default true)
|
- `discordOnly` (default true)
|
||||||
- `bypassUserIds` (default [])
|
- `bypassUserIds` (default [])
|
||||||
- `endSymbols` (default punctuation set)
|
- `endSymbols` (default ["🔚"])
|
||||||
|
- `enableDiscordControlTool` (default true)
|
||||||
|
- `discordControlApiBaseUrl` (default `http://127.0.0.1:8790`)
|
||||||
|
- `discordControlApiToken`
|
||||||
|
- `discordControlCallerId`
|
||||||
|
|
||||||
|
## Optional tool: `discord_control`
|
||||||
|
|
||||||
|
This plugin now registers an optional tool named `discord_control`.
|
||||||
|
To use it, add tool allowlist entry for either:
|
||||||
|
- tool name: `discord_control`
|
||||||
|
- plugin id: `whispergate`
|
||||||
|
|
||||||
|
Supported actions:
|
||||||
|
- `channel-private-create`
|
||||||
|
- `channel-private-update`
|
||||||
|
- `member-list`
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
||||||
import { evaluateDecision, type Decision, type WhisperGateConfig } from "./rules.js";
|
import { evaluateDecision, type Decision, type WhisperGateConfig } from "./rules.js";
|
||||||
|
|
||||||
|
type DiscordControlAction = "channel-private-create" | "channel-private-update" | "member-list";
|
||||||
|
|
||||||
type DecisionRecord = {
|
type DecisionRecord = {
|
||||||
decision: Decision;
|
decision: Decision;
|
||||||
createdAt: number;
|
createdAt: number;
|
||||||
@@ -53,11 +55,103 @@ function shouldInjectEndMarker(reason: string): boolean {
|
|||||||
return reason === "bypass_sender" || reason.startsWith("end_symbol:");
|
return reason === "bypass_sender" || reason.startsWith("end_symbol:");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pickDefined(input: Record<string, unknown>) {
|
||||||
|
const out: Record<string, unknown> = {};
|
||||||
|
for (const [k, v] of Object.entries(input)) {
|
||||||
|
if (v !== undefined) out[k] = v;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
id: "whispergate",
|
id: "whispergate",
|
||||||
name: "WhisperGate",
|
name: "WhisperGate",
|
||||||
register(api: OpenClawPluginApi) {
|
register(api: OpenClawPluginApi) {
|
||||||
const config = (api.pluginConfig || {}) as WhisperGateConfig;
|
const config = (api.pluginConfig || {}) as WhisperGateConfig & {
|
||||||
|
enableDiscordControlTool?: boolean;
|
||||||
|
discordControlApiBaseUrl?: string;
|
||||||
|
discordControlApiToken?: string;
|
||||||
|
discordControlCallerId?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (config.enableDiscordControlTool !== false) {
|
||||||
|
api.registerTool(
|
||||||
|
{
|
||||||
|
name: "discord_control",
|
||||||
|
description: "Discord admin extension actions: private channel create/update and member list.",
|
||||||
|
parameters: {
|
||||||
|
type: "object",
|
||||||
|
additionalProperties: false,
|
||||||
|
properties: {
|
||||||
|
action: {
|
||||||
|
type: "string",
|
||||||
|
enum: ["channel-private-create", "channel-private-update", "member-list"],
|
||||||
|
},
|
||||||
|
guildId: { type: "string" },
|
||||||
|
name: { type: "string" },
|
||||||
|
type: { type: "number" },
|
||||||
|
parentId: { type: "string" },
|
||||||
|
topic: { type: "string" },
|
||||||
|
position: { type: "number" },
|
||||||
|
nsfw: { type: "boolean" },
|
||||||
|
allowedUserIds: { type: "array", items: { type: "string" } },
|
||||||
|
allowedRoleIds: { type: "array", items: { type: "string" } },
|
||||||
|
allowMask: { type: "string" },
|
||||||
|
denyEveryoneMask: { type: "string" },
|
||||||
|
channelId: { type: "string" },
|
||||||
|
mode: { type: "string", enum: ["merge", "replace"] },
|
||||||
|
addUserIds: { type: "array", items: { type: "string" } },
|
||||||
|
addRoleIds: { type: "array", items: { type: "string" } },
|
||||||
|
removeTargetIds: { type: "array", items: { type: "string" } },
|
||||||
|
denyMask: { type: "string" },
|
||||||
|
limit: { type: "number" },
|
||||||
|
after: { type: "string" },
|
||||||
|
fields: { anyOf: [{ type: "string" }, { type: "array", items: { type: "string" } }] },
|
||||||
|
dryRun: { type: "boolean" },
|
||||||
|
},
|
||||||
|
required: ["action", "guildId"],
|
||||||
|
},
|
||||||
|
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 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;
|
||||||
|
|
||||||
|
const r = await fetch(`${baseUrl}/v1/discord/action`, {
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
const text = await r.text();
|
||||||
|
|
||||||
|
if (!r.ok) {
|
||||||
|
return {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
text: `discord_control failed (${r.status}): ${text}`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
isError: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ optional: true },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
api.registerHook("message:received", async (event, ctx) => {
|
api.registerHook("message:received", async (event, ctx) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -11,9 +11,13 @@
|
|||||||
"enabled": { "type": "boolean", "default": true },
|
"enabled": { "type": "boolean", "default": true },
|
||||||
"discordOnly": { "type": "boolean", "default": true },
|
"discordOnly": { "type": "boolean", "default": true },
|
||||||
"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" },
|
||||||
"noReplyModel": { "type": "string" }
|
"noReplyModel": { "type": "string" },
|
||||||
|
"enableDiscordControlTool": { "type": "boolean", "default": true },
|
||||||
|
"discordControlApiBaseUrl": { "type": "string", "default": "http://127.0.0.1:8790" },
|
||||||
|
"discordControlApiToken": { "type": "string" },
|
||||||
|
"discordControlCallerId": { "type": "string" }
|
||||||
},
|
},
|
||||||
"required": ["noReplyProvider", "noReplyModel"]
|
"required": ["noReplyProvider", "noReplyModel"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user