mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 17:20:43 +00:00
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import { CHANNEL_IDS } from "../channels/ids.js";
|
|
import { listRegisteredChannelPluginIds } from "../channels/registry.js";
|
|
import {
|
|
INTERNAL_MESSAGE_CHANNEL,
|
|
type InternalMessageChannel,
|
|
} from "./message-channel-constants.js";
|
|
import { normalizeMessageChannel as normalizeMessageChannelCore } from "./message-channel-core.js";
|
|
|
|
type ChannelId = string & { readonly __openclawChannelIdBrand?: never };
|
|
|
|
export type DeliverableMessageChannel = ChannelId;
|
|
|
|
export type GatewayMessageChannel = DeliverableMessageChannel;
|
|
|
|
export function normalizeMessageChannel(raw?: string | null): string | undefined {
|
|
return normalizeMessageChannelCore(raw);
|
|
}
|
|
|
|
const listPluginChannelIds = (): string[] => {
|
|
return listRegisteredChannelPluginIds();
|
|
};
|
|
|
|
export const listDeliverableMessageChannels = (): ChannelId[] =>
|
|
Array.from(new Set([...CHANNEL_IDS, ...listPluginChannelIds()]));
|
|
|
|
const listGatewayMessageChannels = (): GatewayMessageChannel[] => [
|
|
...listDeliverableMessageChannels(),
|
|
INTERNAL_MESSAGE_CHANNEL,
|
|
];
|
|
|
|
export function isGatewayMessageChannel(value: string): value is GatewayMessageChannel {
|
|
return listGatewayMessageChannels().includes(value as GatewayMessageChannel);
|
|
}
|
|
|
|
export function isDeliverableMessageChannel(value: string): value is DeliverableMessageChannel {
|
|
return listDeliverableMessageChannels().includes(value as DeliverableMessageChannel);
|
|
}
|
|
|
|
export function resolveGatewayMessageChannel(
|
|
raw?: string | null,
|
|
): GatewayMessageChannel | undefined {
|
|
const normalized = normalizeMessageChannel(raw);
|
|
if (!normalized) {
|
|
return undefined;
|
|
}
|
|
return isGatewayMessageChannel(normalized) ? normalized : undefined;
|
|
}
|
|
|
|
export function resolveMessageChannel(
|
|
primary?: string | null,
|
|
fallback?: string | null,
|
|
): string | undefined {
|
|
return normalizeMessageChannel(primary) ?? normalizeMessageChannel(fallback);
|
|
}
|
|
|
|
export type { InternalMessageChannel };
|