// A channel's `mirror` config key (release 31, lane D): the channel MIRRORS // another creator's streams, and `of` names the creator's channels in this // corpus (their slugs). The mirror scan (controller/mirrorScan.ts) pairs the // two (lib/mirrors/match.ts). // // Pure, client-safe (channelConfig.ts imports the coercion). import { isSafeChannelSegment } from "../citations/moments"; export type MirrorConfig = { of: string[]; }; export const MIRROR_CONFIG_FIELD_DOCS: Record = { of: "The slugs of the creator's channels in this corpus that this channel copies (every platform the creator uploads to), e.g. `[\"creator-youtube\", \"creator-rumble\"]`. Trimmed and de-duplicated; a value that is not a channel slug is dropped, and a list left empty drops the whole key.", }; // The slugs of a list (an array, or text separated by commas or whitespace), // trimmed, valid and de-duplicated, in order. export function mirrorSlugs(v: unknown): string[] { const raw = Array.isArray(v) ? v : typeof v === "string" ? v.split(/[\s,]+/) : []; const out: string[] = []; for (const x of raw) { if (typeof x !== "string") continue; const s = x.trim(); if (s && isSafeChannelSegment(s) && !out.includes(s)) out.push(s); } return out; } export function coerceMirrorConfig(v: unknown): MirrorConfig | undefined { if (!v || typeof v !== "object" || Array.isArray(v)) return undefined; const of = mirrorSlugs((v as Record).of); return of.length > 0 ? { of } : undefined; }