fix(agents): scope message tool schema by channel (#18215)

Co-authored-by: Shadow <shadow@openclaw.ai>
This commit is contained in:
Ayaan Zaidi
2026-02-16 22:04:18 +05:30
committed by GitHub
parent 3a2fffefdb
commit c8a536e30a
4 changed files with 189 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
import { describe, expect, it, vi } from "vitest";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { ChannelPlugin } from "../../channels/plugins/types.js";
import type { MessageActionRunResult } from "../../infra/outbound/message-action-runner.js";
import { setActivePluginRegistry } from "../../plugins/runtime.js";
@@ -93,6 +93,97 @@ describe("message tool path passthrough", () => {
});
});
describe("message tool schema scoping", () => {
const telegramPlugin: ChannelPlugin = {
id: "telegram",
meta: {
id: "telegram",
label: "Telegram",
selectionLabel: "Telegram",
docsPath: "/channels/telegram",
blurb: "Telegram test plugin.",
},
capabilities: { chatTypes: ["direct", "group"], media: true },
config: {
listAccountIds: () => ["default"],
resolveAccount: () => ({}),
},
actions: {
listActions: () => ["send", "react"] as const,
supportsButtons: () => true,
},
};
const discordPlugin: ChannelPlugin = {
id: "discord",
meta: {
id: "discord",
label: "Discord",
selectionLabel: "Discord",
docsPath: "/channels/discord",
blurb: "Discord test plugin.",
},
capabilities: { chatTypes: ["direct", "group"], media: true },
config: {
listAccountIds: () => ["default"],
resolveAccount: () => ({}),
},
actions: {
listActions: () => ["send", "poll"] as const,
},
};
afterEach(() => {
setActivePluginRegistry(createTestRegistry([]));
});
it("hides discord components when scoped to telegram", () => {
setActivePluginRegistry(
createTestRegistry([
{ pluginId: "telegram", source: "test", plugin: telegramPlugin },
{ pluginId: "discord", source: "test", plugin: discordPlugin },
]),
);
const tool = createMessageTool({
config: {} as never,
currentChannelProvider: "telegram",
});
const properties =
(tool.parameters as { properties?: Record<string, unknown> }).properties ?? {};
const actionEnum = (properties.action as { enum?: string[] } | undefined)?.enum ?? [];
expect(properties.components).toBeUndefined();
expect(properties.buttons).toBeDefined();
expect(actionEnum).toContain("send");
expect(actionEnum).toContain("react");
expect(actionEnum).not.toContain("poll");
});
it("shows discord components when scoped to discord", () => {
setActivePluginRegistry(
createTestRegistry([
{ pluginId: "telegram", source: "test", plugin: telegramPlugin },
{ pluginId: "discord", source: "test", plugin: discordPlugin },
]),
);
const tool = createMessageTool({
config: {} as never,
currentChannelProvider: "discord",
});
const properties =
(tool.parameters as { properties?: Record<string, unknown> }).properties ?? {};
const actionEnum = (properties.action as { enum?: string[] } | undefined)?.enum ?? [];
expect(properties.components).toBeDefined();
expect(properties.buttons).toBeUndefined();
expect(actionEnum).toContain("send");
expect(actionEnum).toContain("poll");
expect(actionEnum).not.toContain("react");
});
});
describe("message tool description", () => {
const bluebubblesPlugin: ChannelPlugin = {
id: "bluebubbles",