Mattermost: consolidate message tool discovery

This commit is contained in:
Gustavo Madeira Santana 2026-03-18 00:07:01 +00:00
parent 60104de428
commit 28ab5061bf
No known key found for this signature in database

View File

@ -43,7 +43,9 @@ import { mattermostSetupAdapter } from "./setup-core.js";
import { mattermostSetupWizard } from "./setup-surface.js";
const mattermostMessageActions: ChannelMessageActionAdapter = {
listActions: ({ cfg }) => {
describeMessageTool: ({
cfg,
}: Parameters<NonNullable<ChannelMessageActionAdapter["describeMessageTool"]>>[0]) => {
const enabledAccounts = listMattermostAccountIds(cfg)
.map((accountId) => resolveMattermostAccount({ cfg, accountId }))
.filter((account) => account.enabled)
@ -67,29 +69,22 @@ const mattermostMessageActions: ChannelMessageActionAdapter = {
actions.push("react");
}
return actions;
return {
actions,
capabilities: enabledAccounts.length > 0 ? ["buttons"] : [],
schema:
enabledAccounts.length > 0
? {
properties: {
buttons: createMessageToolButtonsSchema(),
},
}
: null,
};
},
supportsAction: ({ action }) => {
return action === "send" || action === "react";
},
getCapabilities: ({ cfg }) => {
const accounts = listMattermostAccountIds(cfg)
.map((id) => resolveMattermostAccount({ cfg, accountId: id }))
.filter((a) => a.enabled && a.botToken?.trim() && a.baseUrl?.trim());
return accounts.length > 0 ? (["buttons"] as const) : [];
},
getToolSchema: ({ cfg }) => {
const accounts = listMattermostAccountIds(cfg)
.map((id) => resolveMattermostAccount({ cfg, accountId: id }))
.filter((a) => a.enabled && a.botToken?.trim() && a.baseUrl?.trim());
return accounts.length > 0
? {
properties: {
buttons: createMessageToolButtonsSchema(),
},
}
: null;
},
handleAction: async ({ action, params, cfg, accountId }) => {
if (action === "react") {
// Check reactions gate: per-account config takes precedence over base config