"use client"; import { useMemo, useState } from "react"; import { useRecommendedRoles } from "@/components/labels"; import { modelFilePaths, recommendFiles } from "@/lib/recommend"; /** * Companion files (template, MTP, mmproj, …) for the model weights in `picked`, per the * "Recommended files" setting. They count as selected unless the user unchecked them (`dismissed`), * and drop out by themselves when the model file they belong to is deselected. */ export function useRecommended( files: { path: string; size: number }[], picked: Iterable, options: { isExcluded?: (path: string) => boolean; have?: string[] } = {}, ) { const { isExcluded, have } = options; const roles = useRecommendedRoles(); const [dismissed, setDismissed] = useState>(new Set()); const pickedList = useMemo(() => [...picked], [picked]); const all = useMemo(() => { const already = new Set(pickedList); return recommendFiles(files, modelFilePaths(pickedList), roles, [...pickedList, ...(have ?? [])]).filter( (p) => !already.has(p) && !isExcluded?.(p), ); }, [files, pickedList, roles, isExcluded, have]); const active = useMemo(() => new Set(all.filter((p) => !dismissed.has(p))), [all, dismissed]); /** Check or uncheck recommended paths (unchecking remembers the choice). */ function setOn(paths: string[], on: boolean) { setDismissed((prev) => { const next = new Set(prev); for (const p of paths) { if (on) next.delete(p); else next.add(p); } return next; }); } return { all, active, setOn, reset: () => setDismissed(new Set()) }; }