import { C as getActivePluginRegistry, S as normalizeChatChannelId, p as CHANNEL_IDS } from "./subsystem-_lp1q2Mi.js";

//#region ../../src/gateway/protocol/client-info.ts
const GATEWAY_CLIENT_IDS = {
	WEBCHAT_UI: "webchat-ui",
	CONTROL_UI: "edwinpai-control-ui",
	WEBCHAT: "webchat",
	CLI: "cli",
	GATEWAY_CLIENT: "gateway-client",
	MACOS_APP: "edwinpai-macos",
	IOS_APP: "edwinpai-ios",
	ANDROID_APP: "edwinpai-android",
	NODE_HOST: "node-host",
	TEST: "test",
	FINGERPRINT: "fingerprint",
	PROBE: "edwinpai-probe"
};
const LEGACY_GATEWAY_CLIENT_IDS = {
	CONTROL_UI: "edwin-control-ui",
	MACOS_APP: "edwin-macos",
	IOS_APP: "edwin-ios",
	ANDROID_APP: "edwin-android",
	PROBE: "edwin-probe"
};
const LEGACY_TO_CURRENT = {
	"edwin-control-ui": "edwinpai-control-ui",
	"edwin-macos": "edwinpai-macos",
	"edwin-ios": "edwinpai-ios",
	"edwin-android": "edwinpai-android",
	"edwin-probe": "edwinpai-probe"
};
const GATEWAY_INTERFACE_IDS = GATEWAY_CLIENT_IDS;
const GATEWAY_CLIENT_NAMES = GATEWAY_CLIENT_IDS;
const GATEWAY_CLIENT_MODES = {
	WEBCHAT: "webchat",
	CLI: "cli",
	UI: "ui",
	BACKEND: "backend",
	NODE: "node",
	PROBE: "probe",
	TEST: "test"
};
const GATEWAY_INTERFACE_MODES = GATEWAY_CLIENT_MODES;
const GATEWAY_CLIENT_ID_SET = new Set(Object.values(GATEWAY_CLIENT_IDS));
const GATEWAY_CLIENT_MODE_SET = new Set(Object.values(GATEWAY_CLIENT_MODES));
function normalizeGatewayClientId(raw) {
	const normalized = raw?.trim().toLowerCase();
	if (!normalized) return;
	const mapped = LEGACY_TO_CURRENT[normalized];
	if (mapped) return mapped;
	return GATEWAY_CLIENT_ID_SET.has(normalized) ? normalized : void 0;
}
function normalizeGatewayInterfaceId(raw) {
	return normalizeGatewayClientId(raw);
}
function normalizeGatewayClientMode(raw) {
	const normalized = raw?.trim().toLowerCase();
	if (!normalized) return;
	return GATEWAY_CLIENT_MODE_SET.has(normalized) ? normalized : void 0;
}
function normalizeGatewayInterfaceMode(raw) {
	return normalizeGatewayClientMode(raw);
}

//#endregion
//#region ../../src/utils/message-channel.ts
const INTERNAL_MESSAGE_CHANNEL = "webchat";
const MARKDOWN_CAPABLE_CHANNELS = new Set([
	"slack",
	"telegram",
	"signal",
	"discord",
	"googlechat",
	"tui",
	INTERNAL_MESSAGE_CHANNEL
]);
function isGatewayCliInterface(client) {
	return normalizeGatewayInterfaceMode(client?.mode) === GATEWAY_INTERFACE_MODES.CLI;
}
function isInternalMessageChannel(raw) {
	return normalizeMessageChannel(raw) === INTERNAL_MESSAGE_CHANNEL;
}
function isWebchatInterface(client) {
	if (normalizeGatewayInterfaceMode(client?.mode) === GATEWAY_INTERFACE_MODES.WEBCHAT) return true;
	return normalizeGatewayInterfaceId(client?.id) === GATEWAY_INTERFACE_IDS.WEBCHAT_UI;
}
function isWebchatClient(client) {
	return isWebchatInterface(client);
}
function normalizeMessageChannel(raw) {
	const normalized = raw?.trim().toLowerCase();
	if (!normalized) return;
	if (normalized === INTERNAL_MESSAGE_CHANNEL) return INTERNAL_MESSAGE_CHANNEL;
	const builtIn = normalizeChatChannelId(normalized);
	if (builtIn) return builtIn;
	return (getActivePluginRegistry()?.channels.find((entry) => {
		if (entry.plugin.id.toLowerCase() === normalized) return true;
		return (entry.plugin.meta.aliases ?? []).some((alias) => alias.trim().toLowerCase() === normalized);
	}))?.plugin.id ?? normalized;
}
const listPluginChannelIds = () => {
	const registry = getActivePluginRegistry();
	if (!registry) return [];
	return registry.channels.map((entry) => entry.plugin.id);
};
const listDeliverableMessageChannels = () => Array.from(new Set([...CHANNEL_IDS, ...listPluginChannelIds()]));
const listGatewayMessageChannels = () => [...listDeliverableMessageChannels(), INTERNAL_MESSAGE_CHANNEL];
function isGatewayMessageChannel(value) {
	return listGatewayMessageChannels().includes(value);
}
function isDeliverableMessageChannel(value) {
	return listDeliverableMessageChannels().includes(value);
}
function resolveGatewayMessageChannel(raw) {
	const normalized = normalizeMessageChannel(raw);
	if (!normalized) return;
	return isGatewayMessageChannel(normalized) ? normalized : void 0;
}
function resolveMessageChannel(primary, fallback) {
	return normalizeMessageChannel(primary) ?? normalizeMessageChannel(fallback);
}
function isMarkdownCapableMessageChannel(raw) {
	const channel = normalizeMessageChannel(raw);
	if (!channel) return false;
	return MARKDOWN_CAPABLE_CHANNELS.has(channel);
}

//#endregion
export { GATEWAY_INTERFACE_MODES as _, isInternalMessageChannel as a, isWebchatInterface as c, resolveGatewayMessageChannel as d, resolveMessageChannel as f, GATEWAY_INTERFACE_IDS as g, GATEWAY_CLIENT_NAMES as h, isGatewayMessageChannel as i, listDeliverableMessageChannels as l, GATEWAY_CLIENT_MODES as m, isDeliverableMessageChannel as n, isMarkdownCapableMessageChannel as o, GATEWAY_CLIENT_IDS as p, isGatewayCliInterface as r, isWebchatClient as s, INTERNAL_MESSAGE_CHANNEL as t, normalizeMessageChannel as u, LEGACY_GATEWAY_CLIENT_IDS as v, normalizeGatewayInterfaceId as y };