mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 20:20:42 +00:00
Tests: fast-path Slack message tool discovery
This commit is contained in:
1
extensions/slack/message-tool-api.ts
Normal file
1
extensions/slack/message-tool-api.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { describeSlackMessageTool as describeMessageTool } from "./src/message-tool-api.js";
|
||||
@@ -1,14 +1,9 @@
|
||||
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||
import { Type } from "@sinclair/typebox";
|
||||
import {
|
||||
type ChannelMessageActionAdapter,
|
||||
type ChannelMessageToolDiscovery,
|
||||
} from "openclaw/plugin-sdk/channel-contract";
|
||||
import type { ChannelMessageActionAdapter } from "openclaw/plugin-sdk/channel-contract";
|
||||
import type { SlackActionContext } from "./action-runtime.js";
|
||||
import { isSlackInteractiveRepliesEnabled } from "./interactive-replies.js";
|
||||
import { handleSlackMessageAction } from "./message-action-dispatch.js";
|
||||
import { extractSlackToolSend, listSlackMessageActions } from "./message-actions.js";
|
||||
import { createSlackMessageToolBlocksSchema } from "./message-tool-schema.js";
|
||||
import { extractSlackToolSend } from "./message-actions.js";
|
||||
import { describeSlackMessageTool } from "./message-tool-api.js";
|
||||
import { resolveSlackChannelId } from "./targets.js";
|
||||
|
||||
type SlackActionInvoke = (
|
||||
@@ -28,35 +23,8 @@ export function createSlackActions(
|
||||
providerId: string,
|
||||
options?: { invoke?: SlackActionInvoke },
|
||||
): ChannelMessageActionAdapter {
|
||||
function describeMessageTool({
|
||||
cfg,
|
||||
accountId,
|
||||
}: Parameters<
|
||||
NonNullable<ChannelMessageActionAdapter["describeMessageTool"]>
|
||||
>[0]): ChannelMessageToolDiscovery {
|
||||
const actions = listSlackMessageActions(cfg, accountId);
|
||||
const capabilities = new Set<"blocks" | "interactive">();
|
||||
if (actions.includes("send")) {
|
||||
capabilities.add("blocks");
|
||||
}
|
||||
if (isSlackInteractiveRepliesEnabled({ cfg, accountId })) {
|
||||
capabilities.add("interactive");
|
||||
}
|
||||
return {
|
||||
actions,
|
||||
capabilities: Array.from(capabilities),
|
||||
schema: actions.includes("send")
|
||||
? {
|
||||
properties: {
|
||||
blocks: Type.Optional(createSlackMessageToolBlocksSchema()),
|
||||
},
|
||||
}
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
describeMessageTool,
|
||||
describeMessageTool: describeSlackMessageTool,
|
||||
extractToolSend: ({ args }) => extractSlackToolSend(args),
|
||||
handleAction: async (ctx) => {
|
||||
return await handleSlackMessageAction({
|
||||
|
||||
44
extensions/slack/src/message-tool-api.test.ts
Normal file
44
extensions/slack/src/message-tool-api.test.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { describeSlackMessageTool } from "./message-tool-api.js";
|
||||
|
||||
describe("Slack message tool public API", () => {
|
||||
it("describes configured Slack message actions without loading channel runtime", () => {
|
||||
expect(
|
||||
describeSlackMessageTool({
|
||||
cfg: {
|
||||
channels: {
|
||||
slack: {
|
||||
botToken: "xoxb-test",
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
).toMatchObject({
|
||||
actions: expect.arrayContaining(["send", "upload-file", "read"]),
|
||||
capabilities: expect.arrayContaining(["blocks"]),
|
||||
});
|
||||
});
|
||||
|
||||
it("honors account-scoped action gates", () => {
|
||||
expect(
|
||||
describeSlackMessageTool({
|
||||
cfg: {
|
||||
channels: {
|
||||
slack: {
|
||||
botToken: "xoxb-default",
|
||||
accounts: {
|
||||
ops: {
|
||||
botToken: "xoxb-ops",
|
||||
actions: {
|
||||
messages: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
accountId: "ops",
|
||||
}).actions,
|
||||
).not.toContain("upload-file");
|
||||
});
|
||||
});
|
||||
30
extensions/slack/src/message-tool-api.ts
Normal file
30
extensions/slack/src/message-tool-api.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Type } from "@sinclair/typebox";
|
||||
import type { ChannelMessageActionAdapter } from "openclaw/plugin-sdk/channel-contract";
|
||||
import { isSlackInteractiveRepliesEnabled } from "./interactive-replies.js";
|
||||
import { listSlackMessageActions } from "./message-actions.js";
|
||||
import { createSlackMessageToolBlocksSchema } from "./message-tool-schema.js";
|
||||
|
||||
export function describeSlackMessageTool({
|
||||
cfg,
|
||||
accountId,
|
||||
}: Parameters<NonNullable<ChannelMessageActionAdapter["describeMessageTool"]>>[0]) {
|
||||
const actions = listSlackMessageActions(cfg, accountId);
|
||||
const capabilities = new Set<"blocks" | "interactive">();
|
||||
if (actions.includes("send")) {
|
||||
capabilities.add("blocks");
|
||||
}
|
||||
if (isSlackInteractiveRepliesEnabled({ cfg, accountId })) {
|
||||
capabilities.add("interactive");
|
||||
}
|
||||
return {
|
||||
actions,
|
||||
capabilities: Array.from(capabilities),
|
||||
schema: actions.includes("send")
|
||||
? {
|
||||
properties: {
|
||||
blocks: Type.Optional(createSlackMessageToolBlocksSchema()),
|
||||
},
|
||||
}
|
||||
: null,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user