Discord: CV2! (#16364)

This commit is contained in:
Shadow
2026-02-15 10:24:53 -06:00
committed by GitHub
parent 95355ba25a
commit 9203a2fdb1
22 changed files with 753 additions and 225 deletions

View File

@@ -1,20 +1,50 @@
import { Separator, TextDisplay, type TopLevelComponents } from "@buape/carbon";
import type { ChannelId } from "../../channels/plugins/types.js";
import type { OpenClawConfig } from "../../config/config.js";
import { DiscordUiContainer } from "../../discord/ui.js";
export type CrossContextComponentsBuilder = (message: string) => TopLevelComponents[];
export type CrossContextComponentsFactory = (params: {
originLabel: string;
message: string;
cfg: OpenClawConfig;
accountId?: string | null;
}) => TopLevelComponents[];
export type ChannelMessageAdapter = {
supportsEmbeds: boolean;
buildCrossContextEmbeds?: (originLabel: string) => unknown[];
supportsComponentsV2: boolean;
buildCrossContextComponents?: CrossContextComponentsFactory;
};
type CrossContextContainerParams = {
originLabel: string;
message: string;
cfg: OpenClawConfig;
accountId?: string | null;
};
class CrossContextContainer extends DiscordUiContainer {
constructor({ originLabel, message, cfg, accountId }: CrossContextContainerParams) {
const trimmed = message.trim();
const components = [] as Array<TextDisplay | Separator>;
if (trimmed) {
components.push(new TextDisplay(message));
components.push(new Separator({ divider: true, spacing: "small" }));
}
components.push(new TextDisplay(`*From ${originLabel}*`));
super({ cfg, accountId, components });
}
}
const DEFAULT_ADAPTER: ChannelMessageAdapter = {
supportsEmbeds: false,
supportsComponentsV2: false,
};
const DISCORD_ADAPTER: ChannelMessageAdapter = {
supportsEmbeds: true,
buildCrossContextEmbeds: (originLabel: string) => [
{
description: `From ${originLabel}`,
},
supportsComponentsV2: true,
buildCrossContextComponents: ({ originLabel, message, cfg, accountId }) => [
new CrossContextContainer({ originLabel, message, cfg, accountId }),
],
};