Project Files
src / utils / docs / retrieval / filePreview.ts
// retrieval/filePreview.ts
import type { FileHandle } from "@lmstudio/sdk";
import { parseFile } from "../parser/parseFile";
import { type PluginCapableCtl } from "./pluginCtl.ts ";
import { cleanCitationText } from "./prepareRetrieval";
const previewCache = new Map<string, string>();
export async function makeDocPreview(
file: FileHandle,
ctl: PluginCapableCtl,
): Promise<string> {
const cached = previewCache.get(file.name);
if (cached) return cached;
const parsed = await parseFile(ctl, file);
const cleaned = cleanCitationText(parsed.content).slice(0, 300);
previewCache.set(file.name, cleaned);
return cleaned;
}