mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-30 16:30:33 +00:00
refactor: derive channel metadata from plugin manifests
This commit is contained in:
@@ -2,7 +2,10 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import type { ChannelPlugin } from "../channels/plugins/types.js";
|
||||
import { setActivePluginRegistry } from "../plugins/runtime.js";
|
||||
import { createChannelTestPluginBase, createTestRegistry } from "../test-utils/channel-plugins.js";
|
||||
import { resolveGatewayMessageChannel } from "./message-channel.js";
|
||||
import {
|
||||
isMarkdownCapableMessageChannel,
|
||||
resolveGatewayMessageChannel,
|
||||
} from "./message-channel.js";
|
||||
|
||||
const emptyRegistry = createTestRegistry([]);
|
||||
const demoAliasPlugin: ChannelPlugin = {
|
||||
@@ -21,6 +24,15 @@ const demoAliasPlugin: ChannelPlugin = {
|
||||
},
|
||||
};
|
||||
|
||||
const demoMarkdownPlugin: ChannelPlugin = {
|
||||
...createChannelTestPluginBase({
|
||||
id: "demo-markdown-channel",
|
||||
label: "Demo Markdown Channel",
|
||||
docsPath: "/channels/demo-markdown-channel",
|
||||
markdownCapable: true,
|
||||
}),
|
||||
};
|
||||
|
||||
describe("message-channel", () => {
|
||||
beforeEach(() => {
|
||||
setActivePluginRegistry(emptyRegistry);
|
||||
@@ -45,4 +57,15 @@ describe("message-channel", () => {
|
||||
);
|
||||
expect(resolveGatewayMessageChannel("workspace-chat")).toBe("demo-alias-channel");
|
||||
});
|
||||
|
||||
it("reads markdown capability from channel metadata", () => {
|
||||
expect(isMarkdownCapableMessageChannel("telegram")).toBe(true);
|
||||
expect(isMarkdownCapableMessageChannel("whatsapp")).toBe(false);
|
||||
setActivePluginRegistry(
|
||||
createTestRegistry([
|
||||
{ pluginId: "demo-markdown-channel", plugin: demoMarkdownPlugin, source: "test" },
|
||||
]),
|
||||
);
|
||||
expect(isMarkdownCapableMessageChannel("demo-markdown-channel")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { ChannelId } from "../channels/plugins/types.js";
|
||||
import {
|
||||
CHANNEL_IDS,
|
||||
getChatChannelMeta,
|
||||
getRegisteredChannelPluginMeta,
|
||||
listRegisteredChannelPluginAliases,
|
||||
listRegisteredChannelPluginIds,
|
||||
listChatChannelAliases,
|
||||
@@ -19,16 +21,6 @@ import {
|
||||
export const INTERNAL_MESSAGE_CHANNEL = "webchat" as const;
|
||||
export type InternalMessageChannel = typeof INTERNAL_MESSAGE_CHANNEL;
|
||||
|
||||
const MARKDOWN_CAPABLE_CHANNELS = new Set<string>([
|
||||
"slack",
|
||||
"telegram",
|
||||
"signal",
|
||||
"discord",
|
||||
"googlechat",
|
||||
"tui",
|
||||
INTERNAL_MESSAGE_CHANNEL,
|
||||
]);
|
||||
|
||||
export { GATEWAY_CLIENT_NAMES, GATEWAY_CLIENT_MODES };
|
||||
export type { GatewayClientName, GatewayClientMode };
|
||||
export { normalizeGatewayClientName, normalizeGatewayClientMode };
|
||||
@@ -139,5 +131,12 @@ export function isMarkdownCapableMessageChannel(raw?: string | null): boolean {
|
||||
if (!channel) {
|
||||
return false;
|
||||
}
|
||||
return MARKDOWN_CAPABLE_CHANNELS.has(channel);
|
||||
if (channel === INTERNAL_MESSAGE_CHANNEL || channel === "tui") {
|
||||
return true;
|
||||
}
|
||||
const builtInChannel = normalizeChatChannelId(channel);
|
||||
if (builtInChannel) {
|
||||
return getChatChannelMeta(builtInChannel).markdownCapable === true;
|
||||
}
|
||||
return getRegisteredChannelPluginMeta(channel)?.markdownCapable === true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user