// Pure helpers for the video-SELECTION grounding target (the AI-grounding // inclusion set), split out of SearchSessionContext so they're unit-testable // without pulling in the whole client component. // Drop selected slugs that are no longer among the current (settled) result set, // so a selection carried across a new/narrower search self-cleans. export function pruneSelection( selected: ReadonlySet, present: ReadonlySet, ): Set { const next = new Set(); for (const slug of selected) if (present.has(slug)) next.add(slug); return next; } // Filter result groups to the selection, preserving result order. Generic over // any object carrying a `slug` so the search-session's ResultGroup fits without // a dependency here. export function selectGroups( groups: ReadonlyArray, selected: ReadonlySet, ): G[] { if (selected.size === 0) return []; return groups.filter((g) => selected.has(g.slug)); }