diff --git a/src/channels/official-channels-ids.ts b/src/channels/official-channels-ids.ts new file mode 100644 index 00000000..d99a11b4 --- /dev/null +++ b/src/channels/official-channels-ids.ts @@ -0,0 +1,48 @@ +/** + * Official Channels IDs (leaf module, no runtime dependencies) + * + * Pure helpers extracted from `official-channels-runtime` so that + * config-loader code can use them without transitively pulling in + * `claude-detector` / `shell-executor` / `websearch-manager`. + * + * The full channel definitions (with display names, plugin specs, env keys, + * etc.) live in `official-channels-runtime`. This module only owns: + * - the canonical ordered list of channel IDs + * - the type-narrowing predicate + * - the order-preserving normalizer + * - the legacy-discord shim + */ + +import type { OfficialChannelId } from '../config/unified-config-types'; + +/** Canonical, ordered list of official channel IDs. */ +export const OFFICIAL_CHANNEL_IDS: readonly OfficialChannelId[] = [ + 'telegram', + 'discord', + 'imessage', +] as const; + +const OFFICIAL_CHANNEL_ID_SET = new Set(OFFICIAL_CHANNEL_IDS); + +export function isOfficialChannelId(value: string): value is OfficialChannelId { + return OFFICIAL_CHANNEL_ID_SET.has(value); +} + +export function normalizeOfficialChannelIds(values: readonly string[]): OfficialChannelId[] { + const seen = new Set(); + const normalized: OfficialChannelId[] = []; + + for (const channelId of OFFICIAL_CHANNEL_IDS) { + if (!values.includes(channelId) || seen.has(channelId)) { + continue; + } + seen.add(channelId); + normalized.push(channelId); + } + + return normalized; +} + +export function resolveLegacyDiscordSelection(enabled: boolean | undefined): OfficialChannelId[] { + return enabled ? ['discord'] : []; +} diff --git a/src/channels/official-channels-runtime.ts b/src/channels/official-channels-runtime.ts index df5c97b1..7b95e19b 100644 --- a/src/channels/official-channels-runtime.ts +++ b/src/channels/official-channels-runtime.ts @@ -64,7 +64,20 @@ export const OFFICIAL_CHANNELS: Record(); - const normalized: OfficialChannelId[] = []; - - for (const channelId of OFFICIAL_CHANNEL_IDS) { - if (!values.includes(channelId) || seen.has(channelId)) { - continue; - } - - seen.add(channelId); - normalized.push(channelId); - } - - return normalized; -} - export function hasExplicitChannelsFlag(args: string[]): boolean { return args.some((arg) => arg === '--channels' || arg.startsWith('--channels=')); } @@ -757,10 +750,6 @@ export function isOfficialChannelSelectionValid(selection: string): boolean { ); } -export function resolveLegacyDiscordSelection(enabled: boolean | undefined): OfficialChannelId[] { - return enabled ? ['discord'] : []; -} - export function getOfficialChannelsSupportedProfiles(): string[] { return ['default', 'account']; } diff --git a/src/config/loader/config-getters.ts b/src/config/loader/config-getters.ts index 4d0a21d1..28d87436 100644 --- a/src/config/loader/config-getters.ts +++ b/src/config/loader/config-getters.ts @@ -32,7 +32,7 @@ import type { } from '../unified-config-types'; import { canonicalizeBrowserConfig } from './normalizers'; import { canonicalizeImageAnalysisConfig } from '../../utils/hooks/image-analysis-backend-resolver'; -import { normalizeOfficialChannelIds } from '../../channels/official-channels-runtime'; +import { normalizeOfficialChannelIds } from '../../channels/official-channels-ids'; import { normalizeSearxngBaseUrl } from '../../utils/websearch/types'; // --------------------------------------------------------------------------- diff --git a/src/config/loader/normalizers.ts b/src/config/loader/normalizers.ts index d317b9e5..093ae434 100644 --- a/src/config/loader/normalizers.ts +++ b/src/config/loader/normalizers.ts @@ -24,7 +24,7 @@ import { isOfficialChannelId, normalizeOfficialChannelIds, resolveLegacyDiscordSelection, -} from '../../channels/official-channels-runtime'; +} from '../../channels/official-channels-ids'; import { getRecommendedBrowserUserDataDir } from '../../utils/browser/browser-settings'; import { GO_DURATION_PATTERN, GO_DURATION_SEGMENT } from './io-locks'; diff --git a/src/utils/config-manager.ts b/src/utils/config-manager.ts index e6d183a0..5bb7d79c 100644 --- a/src/utils/config-manager.ts +++ b/src/utils/config-manager.ts @@ -6,7 +6,7 @@ import { isConfig, isSettings } from '../types'; import type { Config, Settings, CLIProxyVariantsConfig, CLIProxyVariantConfig } from '../types'; import { expandPath, error } from './helpers'; import { info } from './ui'; -import { isUnifiedMode, loadOrCreateUnifiedConfig } from '../config/config-loader-facade'; +import { isUnifiedMode, loadOrCreateUnifiedConfig } from '../config/unified-config-loader'; // TODO: Replace with proper imports after converting these files // const { ErrorManager } = require('./error-manager');