Slack: consolidate message tool discovery
This commit is contained in:
parent
bb365dba73
commit
c9ba985839
@ -8,7 +8,7 @@ import {
|
||||
handleSlackMessageAction,
|
||||
} from "../../plugin-sdk/slack.js";
|
||||
import { createSlackMessageToolBlocksSchema } from "./message-tool-schema.js";
|
||||
import type { ChannelMessageActionAdapter } from "./types.js";
|
||||
import type { ChannelMessageActionAdapter, ChannelMessageToolDiscovery } from "./types.js";
|
||||
|
||||
type SlackActionInvoke = (
|
||||
action: Record<string, unknown>,
|
||||
@ -20,26 +20,34 @@ export function createSlackActions(
|
||||
providerId: string,
|
||||
options?: { invoke?: SlackActionInvoke },
|
||||
): ChannelMessageActionAdapter {
|
||||
return {
|
||||
listActions: ({ cfg }) => listSlackMessageActions(cfg),
|
||||
getCapabilities: ({ cfg }) => {
|
||||
const capabilities = new Set<"interactive" | "blocks">();
|
||||
if (listSlackMessageActions(cfg).includes("send")) {
|
||||
capabilities.add("blocks");
|
||||
}
|
||||
if (isSlackInteractiveRepliesEnabled({ cfg })) {
|
||||
capabilities.add("interactive");
|
||||
}
|
||||
return Array.from(capabilities);
|
||||
},
|
||||
getToolSchema: ({ cfg }) =>
|
||||
listSlackMessageActions(cfg).includes("send")
|
||||
function describeMessageTool({
|
||||
cfg,
|
||||
}: Parameters<
|
||||
NonNullable<ChannelMessageActionAdapter["describeMessageTool"]>
|
||||
>[0]): ChannelMessageToolDiscovery {
|
||||
const actions = listSlackMessageActions(cfg);
|
||||
const capabilities = new Set<"blocks" | "interactive">();
|
||||
if (actions.includes("send")) {
|
||||
capabilities.add("blocks");
|
||||
}
|
||||
if (isSlackInteractiveRepliesEnabled({ cfg })) {
|
||||
capabilities.add("interactive");
|
||||
}
|
||||
return {
|
||||
actions,
|
||||
capabilities: Array.from(capabilities),
|
||||
schema: actions.includes("send")
|
||||
? {
|
||||
properties: {
|
||||
blocks: createSlackMessageToolBlocksSchema(),
|
||||
},
|
||||
}
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
describeMessageTool,
|
||||
extractToolSend: ({ args }) => extractSlackToolSend(args),
|
||||
handleAction: async (ctx) => {
|
||||
return await handleSlackMessageAction({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user