fix: use parameters + content[] format per OpenClaw plugin spec

- inputSchema → parameters
- { result: text } → { content: [{ type: "text", text }] }

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
zhi
2026-04-22 12:04:41 +00:00
parent 76ac2e959a
commit 6a70a68c7e

View File

@@ -18,7 +18,7 @@ export function registerPromptRulesTool(
"test (preview which prompts would be injected for an agent), " + "test (preview which prompts would be injected for an agent), " +
"reload-routers (hot-reload all router functions), " + "reload-routers (hot-reload all router functions), " +
"list-routers (show loaded routers).", "list-routers (show loaded routers).",
inputSchema: { parameters: {
type: "object", type: "object",
properties: { properties: {
action: { action: {
@@ -55,51 +55,45 @@ export function registerPromptRulesTool(
switch (action) { switch (action) {
case "add": { case "add": {
if (!router || !key || !file) { if (!router || !key || !file) {
return { result: "Error: add requires router, key, and file" }; return { content: [{ type: "text", text: "Error: add requires router, key, and file" }] };
} }
addRule(router, key, file); addRule(router, key, file);
return { result: `Rule added: ${router}:${key}${file}` }; return { content: [{ type: "text", text: `Rule added: ${router}:${key}${file}` }] };
} }
case "remove": { case "remove": {
if (!router || !key) { if (!router || !key) {
return { result: "Error: remove requires router and key" }; return { content: [{ type: "text", text: "Error: remove requires router and key" }] };
} }
const removed = removeRule(router, key); const removed = removeRule(router, key);
return { const msg = removed ? `Rule removed: ${router}:${key}` : `Rule not found: ${router}:${key}`;
result: removed return { content: [{ type: "text", text: msg }] };
? `Rule removed: ${router}:${key}`
: `Rule not found: ${router}:${key}`,
};
} }
case "list": { case "list": {
const rules = listRules(); const rules = listRules();
const entries = Object.entries(rules); const entries = Object.entries(rules);
if (entries.length === 0) return { result: "No rules registered." }; if (entries.length === 0) return { content: [{ type: "text", text: "No rules registered." }] };
return { result: entries.map(([k, v]) => `${k}${v}`).join("\n") }; return { content: [{ type: "text", text: entries.map(([k, v]) => `${k}${v}`).join("\n") }] };
} }
case "test": { case "test": {
if (!agent) return { result: "Error: test requires agent" }; if (!agent) return { content: [{ type: "text", text: "Error: test requires agent" }] };
const result = await resolveInjection({ agentId: agent }, api.logger); const result = await resolveInjection({ agentId: agent }, api.logger);
if (!result.appendSystemContext) { if (!result.appendSystemContext) {
return { result: `No prompts matched for agent: ${agent}` }; return { content: [{ type: "text", text: `No prompts matched for agent: ${agent}` }] };
} }
return { result: `Matched prompts for ${agent}:\n\n${result.appendSystemContext}` }; return { content: [{ type: "text", text: `Matched prompts for ${agent}:\n\n${result.appendSystemContext}` }] };
} }
case "reload-routers": { case "reload-routers": {
await loadRouters(routersDir, api.logger); await loadRouters(routersDir, api.logger);
const names = getRouterNames(); const names = getRouterNames();
return { result: `Routers reloaded: ${names.join(", ") || "(none)"}` }; return { content: [{ type: "text", text: `Routers reloaded: ${names.join(", ") || "(none)"}` }] };
} }
case "list-routers": { case "list-routers": {
const names = getRouterNames(); const names = getRouterNames();
return { const msg = names.length > 0 ? `Loaded routers: ${names.join(", ")}` : "No routers loaded.";
result: names.length > 0 return { content: [{ type: "text", text: msg }] };
? `Loaded routers: ${names.join(", ")}`
: "No routers loaded.",
};
} }
default: default:
return { result: `Unknown action: ${action}` }; return { content: [{ type: "text", text: `Unknown action: ${action}` }] };
} }
}, },
}); });