import { LEARNED_CAP, activeLearned, learnedCite, namesOf, suggestRemoving } from "yt-dlp-transcript-common/lib/report/draft/triage/learned"; import { readLearned } from "yt-dlp-transcript-common/lib/report/draft/triage/learnedStore"; import type { Schedule } from "yt-dlp-transcript-common/lib/report/schedule/types"; import { sitesPaths } from "../articles/sites"; import type { LearnedView } from "./learned-types"; // --------------------------------------------------------------------------- // LEARNED SPELLINGS, umtool's side (plans/umtool-redesign.md, R6.3). The // editor proposes, confirms and keeps a watch's spellings in learned.json // beside the schedule (its one writer). umtool READS it here for the series // page; Remove and Promote go through `report-schedule` (POST /api/schedules). // // SERVER ONLY. // --------------------------------------------------------------------------- /** A schedule's learned spellings for its page: each with its state (suggest removing, idle) and cite. */ export async function readScheduleLearned(s: Pick): Promise { const f = await readLearned(sitesPaths(), s).catch(() => null); const names = namesOf(s.scope.terms ?? null, s.scope.regex === true); const active = new Set(activeLearned(f, names).map((l) => l.spelling)); return { schedule: s.id, rows: (f?.learned ?? []).map((l) => ({ ...l, suggestRemoving: suggestRemoving(l), idle: !active.has(l.spelling), cite: learnedCite(l) })), blocked: f?.blocked ?? [], dropped: [...(f?.dropped ?? [])].reverse().slice(0, 12), lastPass: f?.passes.at(-1) ?? null, proposedAt: f?.proposedAt ?? null, names, cap: LEARNED_CAP, }; }