

























@@ -2,7 +2,11 @@ import path from "node:path";
22import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
33import { jsonResult } from "../../agents/tools/common.js";
44import { dispatchChannelMessageAction } from "../../channels/plugins/message-action-dispatch.js";
5-import type { ChannelMessageActionContext, ChannelPlugin } from "../../channels/plugins/types.js";
5+import type {
6+ChannelMessageActionContext,
7+ChannelMessageActionName,
8+ChannelPlugin,
9+} from "../../channels/plugins/types.js";
610import type { OpenClawConfig } from "../../config/config.js";
711import { getActivePluginRegistry, setActivePluginRegistry } from "../../plugins/runtime.js";
812import { createTestRegistry } from "../../test-utils/channel-plugins.js";
@@ -98,6 +102,39 @@ function createPollForwardingPlugin(params: {
98102};
99103}
100104105+function createGatewayActionPlugin(params: {
106+pluginId: string;
107+label: string;
108+blurb: string;
109+actions: ChannelMessageActionName[];
110+gatewayActions?: ChannelMessageActionName[];
111+capabilities?: ChannelPlugin["capabilities"];
112+messaging?: ChannelPlugin["messaging"];
113+handleAction: ChannelActionHandler;
114+}): ChannelPlugin {
115+const actions = new Set(params.actions);
116+const gatewayActions = new Set(params.gatewayActions ?? params.actions);
117+return {
118+id: params.pluginId,
119+meta: {
120+id: params.pluginId,
121+label: params.label,
122+selectionLabel: params.label,
123+docsPath: `/channels/${params.pluginId}`,
124+blurb: params.blurb,
125+},
126+capabilities: params.capabilities ?? { chatTypes: ["direct"] },
127+config: createAlwaysConfiguredPluginConfig(),
128+messaging: params.messaging,
129+actions: {
130+describeMessageTool: () => ({ actions: params.actions }),
131+supportsAction: ({ action }) => actions.has(action),
132+resolveExecutionMode: ({ action }) => (gatewayActions.has(action) ? "gateway" : "local"),
133+handleAction: params.handleAction,
134+},
135+};
136+}
137+101138async function executePluginAction(params: {
102139action: "send" | "poll";
103140ctx: Pick<
@@ -318,24 +355,14 @@ describe("runMessageAction plugin dispatch", () => {
318355local: true,
319356}),
320357);
321-const gatewayPlugin: ChannelPlugin = {
322-id: "gatewaychat",
323-meta: {
324-id: "gatewaychat",
325-label: "Gateway Chat",
326-selectionLabel: "Gateway Chat",
327-docsPath: "/channels/gatewaychat",
328-blurb: "Gateway Chat reaction test plugin.",
329-},
358+const gatewayPlugin = createGatewayActionPlugin({
359+pluginId: "gatewaychat",
360+label: "Gateway Chat",
361+blurb: "Gateway Chat reaction test plugin.",
362+actions: ["react"],
330363capabilities: { chatTypes: ["direct"], reactions: true },
331-config: createAlwaysConfiguredPluginConfig(),
332-actions: {
333-describeMessageTool: () => ({ actions: ["react"] }),
334-supportsAction: ({ action }) => action === "react",
335-resolveExecutionMode: ({ action }) => (action === "react" ? "gateway" : "local"),
336- handleAction,
337-},
338-};
364+ handleAction,
365+});
339366setActivePluginRegistry(
340367createTestRegistry([
341368{
@@ -414,29 +441,18 @@ describe("runMessageAction plugin dispatch", () => {
414441415442it("routes gateway-executed plugin sends through gateway RPC instead of local dispatch", async () => {
416443const handleAction = vi.fn(async () => jsonResult({ ok: true, local: true }));
417-const gatewayPlugin: ChannelPlugin = {
418-id: "gatewaychat",
419-meta: {
420-id: "gatewaychat",
421-label: "Gateway Chat",
422-selectionLabel: "Gateway Chat",
423-docsPath: "/channels/gatewaychat",
424-blurb: "Gateway Chat send test plugin.",
425-},
426-capabilities: { chatTypes: ["direct"] },
427-config: createAlwaysConfiguredPluginConfig(),
444+const gatewayPlugin = createGatewayActionPlugin({
445+pluginId: "gatewaychat",
446+label: "Gateway Chat",
447+blurb: "Gateway Chat send test plugin.",
448+actions: ["send"],
428449messaging: {
429450targetResolver: {
430451looksLikeId: () => true,
431452},
432453},
433-actions: {
434-describeMessageTool: () => ({ actions: ["send"] }),
435-supportsAction: ({ action }) => action === "send",
436-resolveExecutionMode: ({ action }) => (action === "send" ? "gateway" : "local"),
437- handleAction,
438-},
439-};
454+ handleAction,
455+});
440456setActivePluginRegistry(
441457createTestRegistry([
442458{
@@ -1003,19 +1019,18 @@ describe("runMessageAction plugin dispatch", () => {
1003101910041020it("routes gateway-executed plugin polls through gateway RPC instead of local dispatch", async () => {
10051021const handleAction = vi.fn(async () => jsonResult({ ok: true, local: true }));
1006-const pollGatewayPlugin = createPollForwardingPlugin({
1022+const pollGatewayPlugin = createGatewayActionPlugin({
10071023pluginId: "pollchat",
10081024label: "Poll Chat",
10091025blurb: "Poll chat gateway forwarding test plugin.",
1026+actions: ["poll"],
1027+messaging: {
1028+targetResolver: {
1029+looksLikeId: () => true,
1030+},
1031+},
10101032 handleAction,
10111033});
1012-const baseActions = pollGatewayPlugin.actions!;
1013-pollGatewayPlugin.actions = {
1014-describeMessageTool: baseActions.describeMessageTool,
1015-supportsAction: baseActions.supportsAction,
1016-handleAction: baseActions.handleAction,
1017-resolveExecutionMode: ({ action }) => (action === "poll" ? "gateway" : "local"),
1018-};
10191034setActivePluginRegistry(
10201035createTestRegistry([
10211036{
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。