diff --git a/src/agents/tools/message-tool.test.ts b/src/agents/tools/message-tool.test.ts index 1e0965305d4..d6c03cabf75 100644 --- a/src/agents/tools/message-tool.test.ts +++ b/src/agents/tools/message-tool.test.ts @@ -486,6 +486,49 @@ describe("message tool schema scoping", () => { expect(getToolProperties(unscopedTool).interactive).toBeUndefined(); }); + it("uses discovery account scope for other configured channel actions", () => { + const currentPlugin = createChannelPlugin({ + id: "discord", + label: "Discord", + docsPath: "/channels/discord", + blurb: "Discord test plugin.", + actions: ["send"], + }); + const scopedOtherPlugin = createChannelPlugin({ + id: "telegram", + label: "Telegram", + docsPath: "/channels/telegram", + blurb: "Telegram test plugin.", + actions: ["send"], + }); + scopedOtherPlugin.actions = { + ...scopedOtherPlugin.actions, + listActions: ({ accountId }) => (accountId === "ops" ? ["react"] : []), + }; + + setActivePluginRegistry( + createTestRegistry([ + { pluginId: "discord", source: "test", plugin: currentPlugin }, + { pluginId: "telegram", source: "test", plugin: scopedOtherPlugin }, + ]), + ); + + const scopedTool = createMessageTool({ + config: {} as never, + currentChannelProvider: "discord", + agentAccountId: "ops", + }); + const unscopedTool = createMessageTool({ + config: {} as never, + currentChannelProvider: "discord", + }); + + expect(getActionEnum(getToolProperties(scopedTool))).toContain("react"); + expect(getActionEnum(getToolProperties(unscopedTool))).not.toContain("react"); + expect(scopedTool.description).toContain("telegram (react, send)"); + expect(unscopedTool.description).not.toContain("telegram (react, send)"); + }); + it("routes full discovery context into plugin action discovery", () => { const seenContexts: Record[] = []; const contextPlugin = createChannelPlugin({ diff --git a/src/agents/tools/message-tool.ts b/src/agents/tools/message-tool.ts index bf4a4d4c8cf..7fff178b933 100644 --- a/src/agents/tools/message-tool.ts +++ b/src/agents/tools/message-tool.ts @@ -433,7 +433,18 @@ function resolveMessageToolSchemaActions(params: { if (plugin.id === currentChannel) { continue; } - for (const action of listChannelSupportedActions({ cfg: params.cfg, channel: plugin.id })) { + for (const action of listChannelSupportedActions({ + cfg: params.cfg, + channel: plugin.id, + currentChannelId: params.currentChannelId, + currentThreadTs: params.currentThreadTs, + currentMessageId: params.currentMessageId, + accountId: params.currentAccountId, + sessionKey: params.sessionKey, + sessionId: params.sessionId, + agentId: params.agentId, + requesterSenderId: params.requesterSenderId, + })) { allActions.add(action); } } @@ -579,6 +590,14 @@ function buildMessageToolDescription(options?: { const actions = listChannelSupportedActions({ cfg: resolvedOptions.config, channel: plugin.id, + currentChannelId: resolvedOptions.currentChannelId, + currentThreadTs: resolvedOptions.currentThreadTs, + currentMessageId: resolvedOptions.currentMessageId, + accountId: resolvedOptions.currentAccountId, + sessionKey: resolvedOptions.sessionKey, + sessionId: resolvedOptions.sessionId, + agentId: resolvedOptions.agentId, + requesterSenderId: resolvedOptions.requesterSenderId, }); if (actions.length > 0) { const all = new Set(["send", ...actions]);