Files
openclaw/src/utils/message-channel-normalize.ts
Peter Steinberger 00d8d7ead0 refactor: extract normalization core package
Extract shared normalization/coercion helpers into private @openclaw/normalization-core workspace package while preserving existing plugin SDK helper subpaths.\n\nAlso keeps direct normalization-core imports internal, wires UI/build/loader resolution, and replaces the slow PR network CodeQL lane with a fast added-line boundary scan while retaining full CodeQL for scheduled/manual runs.\n\nVerification: local moved tests, plugin SDK boundary tests, extension loader tests, agents-support shard, UI build/test, build artifacts, lint, workflow guards, autoreview, and GitHub CI passed on PR head 963d893715.
2026-05-31 01:33:00 +01:00

58 lines
1.9 KiB
TypeScript

import { uniqueStrings } from "@openclaw/normalization-core/string-normalization";
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[] =>
uniqueStrings([...CHANNEL_IDS, ...listPluginChannelIds()]) as ChannelId[];
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 };