{"repo": "chadananda/site2rag", "files": {"src/slp-context.js": {"4e012e5efbf018ec6e17a12e31d1cb3e1ae898d7": {"t": 1786068266.847429, "n": 4794, "h": "67c249fe1abb0488", "c": "// Builds the free-text `context` block sent with an SLP job. Distills the document's hosting\n// page(s) — title, link text, description, author, language, subject, likely proper nouns — via a\n// cheap DeepSeek call. SLP feeds this into OCR synthesis + metadata extraction (better proper-noun\n// and archaic-spelling resolution). Cache-optimized: the system prompt is byte-stable across calls\n// (cached prefix), only the page signals vary. Deps: DEEPSEEK_API_KEY. See db.js (hosts, pdf_quality).\nimport { readFileSync, existsSync } from 'fs';\n\nconst DEEPSEEK_URL = 'https://api.deepseek.com/chat/completions';\n\n// Stable system prompt — keep byte-identical across calls so DeepSeek caches it as the shared prefix.\nconst SYS = [\n 'You write a short, factual CONTEXT note about a document to help an OCR + metadata service process it accurately.',\n 'You are given text gathered from the library web page(s) that link to the document.',\n 'Output 2–5 plain-text sentences (no markdown, no JSON, no preamble) stating ONLY what the input supports:',\n \"the document's title, author or editor, publication/date, source collection or journal, primary language,\",\n 'subject, and any proper nouns, names, or archaic/transliterated spellings likely to appear in the text.',\n 'Omit anything not supported by the input. Never invent. Keep under 200 words.',\n].join(' ');\n\nconst decodeEntities = (s) => s\n .replace(/&/g, '&').replace(/'/g, \"'\").replace(/"/g, '\"')\n .replace(/á/g, 'á').replace(/í/g, 'í').replace(/é/g, 'é')\n .replace(/&[a-z]+;/gi, ' ');\n\nconst metaTags = (html) => {\n const out = {};\n const t = html.match(/