@thanh01.pmt/research-kit 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +27 -14
  2. package/dist/academic/index.d.cts +3 -3
  3. package/dist/academic/index.d.ts +3 -3
  4. package/dist/catalogBuilder-2i5KASUF.d.ts +82 -0
  5. package/dist/catalogBuilder-nrGYEY4b.d.cts +82 -0
  6. package/dist/chunk-LSMSIPTZ.js +3 -0
  7. package/dist/{chunk-2JEVBCIF.js.map → chunk-LSMSIPTZ.js.map} +1 -1
  8. package/dist/{chunk-KAFQVI2R.js → chunk-ON6VFCJO.js} +3 -3
  9. package/dist/{chunk-KAFQVI2R.js.map → chunk-ON6VFCJO.js.map} +1 -1
  10. package/dist/{chunk-GKF3NDEX.js → chunk-QFYM2NV4.js} +3 -3
  11. package/dist/{chunk-GKF3NDEX.js.map → chunk-QFYM2NV4.js.map} +1 -1
  12. package/dist/{chunk-XIF5YNI7.js → chunk-QK3LVGI7.js} +244 -8
  13. package/dist/chunk-QK3LVGI7.js.map +1 -0
  14. package/dist/{chunk-J7XKDMGL.js → chunk-X3X26W2I.js} +2 -2
  15. package/dist/{chunk-J7XKDMGL.js.map → chunk-X3X26W2I.js.map} +1 -1
  16. package/dist/{chunk-AUGVVZTL.js → chunk-XDDTHWJW.js} +173 -6
  17. package/dist/chunk-XDDTHWJW.js.map +1 -0
  18. package/dist/config/index.cjs.map +1 -1
  19. package/dist/config/index.d.cts +1 -1
  20. package/dist/config/index.d.ts +1 -1
  21. package/dist/config/index.js +1 -1
  22. package/dist/evidence/index.cjs.map +1 -1
  23. package/dist/evidence/index.d.cts +2 -2
  24. package/dist/evidence/index.d.ts +2 -2
  25. package/dist/evidence/index.js +2 -2
  26. package/dist/harvester/index.cjs +248 -6
  27. package/dist/harvester/index.cjs.map +1 -1
  28. package/dist/harvester/index.d.cts +63 -49
  29. package/dist/harvester/index.d.ts +63 -49
  30. package/dist/harvester/index.js +3 -3
  31. package/dist/{index-t8pahlJ4.d.ts → index-DlngvZBr.d.cts} +15 -1
  32. package/dist/{index-t8pahlJ4.d.cts → index-DlngvZBr.d.ts} +15 -1
  33. package/dist/index.cjs +443 -6
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +28 -13
  36. package/dist/index.d.ts +28 -13
  37. package/dist/index.js +37 -11
  38. package/dist/index.js.map +1 -1
  39. package/dist/{literatureReview-BTPFe7eb.d.cts → literatureReview-C7hsjrn4.d.cts} +1 -1
  40. package/dist/{literatureReview-hGbfrBmw.d.ts → literatureReview-DWl13r_3.d.ts} +1 -1
  41. package/dist/pipeline/index.cjs +361 -6
  42. package/dist/pipeline/index.cjs.map +1 -1
  43. package/dist/pipeline/index.d.cts +49 -5
  44. package/dist/pipeline/index.d.ts +49 -5
  45. package/dist/pipeline/index.js +4 -4
  46. package/dist/{webScraper-BhiQ8s9x.d.ts → webScraper-DBFUIqoO.d.ts} +1 -1
  47. package/dist/{webScraper-D9Ldus9p.d.cts → webScraper-yO9P-oLb.d.cts} +1 -1
  48. package/package.json +9 -8
  49. package/LICENSE +0 -21
  50. package/dist/catalogBuilder-CmmQzUnf.d.ts +0 -38
  51. package/dist/catalogBuilder-DgXYxL2F.d.cts +0 -38
  52. package/dist/chunk-2JEVBCIF.js +0 -3
  53. package/dist/chunk-AUGVVZTL.js.map +0 -1
  54. package/dist/chunk-XIF5YNI7.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/harvester/webScraper.ts","../../src/evidence/evidenceScorer.ts","../../src/evidence/claimVerifier.ts","../../src/evidence/provenanceTracker.ts"],"names":[],"mappings":";;;AAgCO,SAAS,0BAAA,CAA2B,QAAA,EAAkB,WAAA,GAAc,CAAA,EAAa;AACtF,EAAA,MAAM,WAAA,GAAc,QAAA,CAAS,OAAA,CAAQ,iBAAA,EAAmB,IAAI,CAAA;AAC5D,EAAA,MAAM,SAAS,WAAA,CACZ,KAAA,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AAA,EAAG,CAAC,CAAA,CAAE,aAAa,CAAA,CAAA;AACnF,IAAA,MAAM,WAAA,GAAA,iBAAc,IAAI,IAAA,EAAK,EAAE,WAAA,EAAY;AAE3C,IAAA,MAAM,OAAA,GAAU;AAAA,MACd,yCAAkC,KAAK,CAAA,CAAA;AAAA,MACvC,wBAAwB,UAAU,CAAA,yBAAA,EAA4B,WAAW,CAAA,mCAAA,EAAsC,QAAQ,MAAM,CAAA,EAAA,CAAA;AAAA,MAC7H;AAAA,oBAAA,CAAA;AAAA,MACA,CAAA,4EAAA,CAAA;AAAA,MACA,CAAA,yBAAA,CAAA;AAAA,MACA,GAAG,OAAA,CAAQ,GAAA,CAAI,CAAA,CAAA,KAAK,CAAA,IAAA,EAAO,CAAA,CAAE,UAAU,CAAA,OAAA,EAAU,CAAA,CAAE,MAAM,CAAA,cAAA,EAAY,CAAA,CAAE,cAAc,aAAa,CAAA,CAAE,QAAQ,CAAA,qBAAA,EAAwB,CAAA,CAAE,SAAS,CAAA,MAAA,EAAS,CAAA,CAAE,UAAA,CAAW,KAAA,CAAM,CAAA,EAAG,EAAE,CAAC,CAAA,IAAA,CAAM,CAAA;AAAA,MACvL;AAAA,sBAAA,CAAA;AAAA,MACA,CAAA,mHAAA,CAAA;AAAA,MACA,CAAA,sGAAA;AAAA,KACF;AAEA,IAAA,OAAO;AAAA,MACL,KAAA;AAAA,MACA,UAAA;AAAA,MACA,WAAA;AAAA,MACA,cAAc,OAAA,CAAQ,MAAA;AAAA,MACtB,OAAA;AAAA,MACA,YAAA,EAAc,OAAA,CAAQ,IAAA,CAAK,IAAI;AAAA,KACjC;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import { CustomCrawlerAdapter } from '../config/researchConfig';\nimport { isYouTubeUrl, YouTubeIngestionService } from './youtubeTranscript';\n\nexport interface ExtractedCodeBlock {\n language: string;\n code: string;\n}\n\nexport interface ScrapedDocument {\n url: string;\n title: string;\n markdownContent: string;\n byteSize: number;\n extractedCodeSnippets: string[];\n extractedCodeBlocks?: ExtractedCodeBlock[];\n extractedTables?: string[];\n extractedHeadings?: string[];\n keyExcerpts?: string[];\n tablesCount: number;\n fetchProvider: 'jina' | 'crawl4ai' | 'youtube' | 'direct' | 'custom';\n}\n\nexport interface WebScraperOptions {\n crawl4aiHost?: string;\n jinaKey?: string;\n allowEnvFallback?: boolean;\n customAdapter?: CustomCrawlerAdapter;\n}\n\n/**\n * Extracts top substantive paragraphs from Markdown (stripping navigation, links-only lines, and cookie banners).\n */\nexport function extractSubstantiveExcerpts(markdown: string, maxExcerpts = 6): string[] {\n const withoutCode = markdown.replace(/```[\\s\\S]*?```/g, '\\n');\n const blocks = withoutCode\n .split(/\\n{2,}/)\n .map((b) => b.replace(/\\s+/g, ' ').trim())\n .filter((b) => {\n if (b.length < 60 || b.length > 900) return false;\n if (b.startsWith('#') || b.startsWith('|')) return false;\n const linkRatio = (b.match(/\\[[^\\]]+\\]\\([^)]+\\)/g) || []).join('').length / b.length;\n if (linkRatio > 0.45) return false;\n if (/\\b(cookie policy|privacy policy|all rights reserved|terms of service|sign in|log in|subscribe to our newsletter)\\b/i.test(b)) {\n return false;\n }\n return true;\n });\n\n return blocks.slice(0, maxExcerpts);\n}\n\n/**\n * High-fidelity web content & YouTube transcript extractor with Custom Crawler & Jina Auth support\n */\nexport class WebScraper {\n private crawl4aiHost?: string;\n private jinaKey?: string;\n private allowEnvFallback: boolean;\n private customAdapter?: CustomCrawlerAdapter;\n private youtubeService: YouTubeIngestionService;\n\n constructor(options: WebScraperOptions = {}) {\n this.allowEnvFallback = options.allowEnvFallback ?? true;\n this.crawl4aiHost =\n options.crawl4aiHost || (this.allowEnvFallback ? process.env.CRAWL4AI_HOST : undefined) || 'http://localhost:11235';\n this.jinaKey = options.jinaKey || (this.allowEnvFallback ? process.env.JINA_API_KEY : undefined);\n this.customAdapter = options.customAdapter;\n this.youtubeService = new YouTubeIngestionService();\n }\n\n setCustomAdapter(adapter: CustomCrawlerAdapter) {\n this.customAdapter = adapter;\n }\n\n setJinaKey(key?: string) {\n this.jinaKey = key;\n }\n\n async scrapeUrl(\n targetUrl: string,\n options: { customAdapter?: CustomCrawlerAdapter; jinaKey?: string; preferredLanguages?: string[] } = {}\n ): Promise<ScrapedDocument> {\n const adapter = options.customAdapter || this.customAdapter;\n\n // 0. Custom Crawler Adapter (e.g. MCP bridge, Playwright, Headless Chrome)\n if (adapter) {\n try {\n const result = await adapter.crawl(targetUrl);\n if (result && result.markdownContent) {\n return this.packageDocument(targetUrl, result.markdownContent, 'custom', result.title);\n }\n } catch (e: any) {\n console.warn(`[WebScraper] Custom crawler adapter failed for ${targetUrl}:`, e?.message || e);\n }\n }\n\n // 0.5. YouTube Video URL -> Route to YouTubeIngestionService (Idea §3.1)\n if (isYouTubeUrl(targetUrl)) {\n try {\n const yt = await this.youtubeService.fetchTranscript(targetUrl, options.preferredLanguages);\n if (yt.stitchedMarkdown && yt.stitchedMarkdown.length > 80) {\n return this.packageDocument(yt.url, yt.stitchedMarkdown, 'youtube', yt.title);\n }\n } catch (e: any) {\n console.warn(`[WebScraper] YouTube transcript extraction failed for ${targetUrl}:`, e?.message || e);\n }\n }\n\n // 1. Try Jina Reader API (with optional Bearer auth from host app or env)\n try {\n const jinaUrl = `https://r.jina.ai/${targetUrl}`;\n const jinaKey = options.jinaKey || this.jinaKey;\n const headers: Record<string, string> = {\n 'User-Agent': 'OrchableComposer/1.0',\n 'X-Return-Format': 'markdown',\n };\n if (jinaKey) {\n headers['Authorization'] = `Bearer ${jinaKey}`;\n }\n\n const res = await fetch(jinaUrl, {\n headers,\n signal: AbortSignal.timeout(15000),\n });\n\n if (res.ok) {\n const markdown = await res.text();\n if (markdown && markdown.length > 100) {\n return this.packageDocument(targetUrl, markdown, 'jina');\n }\n }\n } catch (e: any) {\n console.warn(`[WebScraper] Jina Reader failed for ${targetUrl}:`, e?.message || e);\n }\n\n // 2. Try Crawl4AI Local Server if reachable\n if (this.crawl4aiHost) {\n try {\n const res = await fetch(`${this.crawl4aiHost}/crawl`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n urls: targetUrl,\n priority: 10,\n }),\n signal: AbortSignal.timeout(15000),\n });\n\n if (res.ok) {\n const data = await res.json();\n const markdown = data?.results?.[0]?.markdown || data?.markdown;\n if (markdown) {\n return this.packageDocument(targetUrl, markdown, 'crawl4ai');\n }\n }\n } catch {\n // ignore if local crawl4ai is not running\n }\n }\n\n // 3. Fallback: Direct Fetch & Structured HTML-to-Markdown Conversion\n try {\n const res = await fetch(targetUrl, {\n headers: { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)' },\n signal: AbortSignal.timeout(10000),\n });\n if (res.ok) {\n const rawHtml = await res.text();\n const titleTag = rawHtml.match(/<title[^>]*>([\\s\\S]*?)<\\/title>/i)?.[1]?.trim();\n const clean = rawHtml\n .replace(/<script\\b[^<]*(?:(?!<\\/script>)<[^<]*)*<\\/script>/gi, '')\n .replace(/<style\\b[^<]*(?:(?!<\\/style>)<[^<]*)*<\\/style>/gi, '')\n .replace(/<nav\\b[^<]*(?:(?!<\\/nav>)<[^<]*)*<\\/nav>/gi, '')\n .replace(/<footer\\b[^<]*(?:(?!<\\/footer>)<[^<]*)*<\\/footer>/gi, '')\n .replace(/<h([1-3])[^>]*>([\\s\\S]*?)<\\/h\\1>/gi, (_, lvl, txt) => `\\n${'#'.repeat(Number(lvl))} ${txt.replace(/<[^>]+>/g, '').trim()}\\n`)\n .replace(/<pre[^>]*><code[^>]*>([\\s\\S]*?)<\\/code><\\/pre>/gi, (_, code) => `\\n\\`\\`\\`\\n${code.replace(/<[^>]+>/g, '').trim()}\\n\\`\\`\\`\\n`)\n .replace(/<p[^>]*>([\\s\\S]*?)<\\/p>/gi, (_, p) => `\\n${p.replace(/<[^>]+>/g, ' ').trim()}\\n`)\n .replace(/<[^>]+>/g, ' ')\n .replace(/[ \\t]+/g, ' ')\n .replace(/\\n{3,}/g, '\\n\\n')\n .trim();\n\n return this.packageDocument(targetUrl, clean, 'direct', titleTag);\n }\n } catch (e: any) {\n console.warn(`[WebScraper] Direct fetch failed for ${targetUrl}:`, e?.message || e);\n }\n\n throw new Error(`Unable to fetch content from URL: ${targetUrl}`);\n }\n\n private packageDocument(\n url: string,\n markdown: string,\n provider: 'jina' | 'crawl4ai' | 'youtube' | 'direct' | 'custom',\n explicitTitle?: string\n ): ScrapedDocument {\n const titleMatch = markdown.match(/^#\\s+(.+)$/m) || markdown.match(/^Title:\\s*(.+)$/im);\n const title = (explicitTitle || (titleMatch ? titleMatch[1]!.trim() : url.split('/').filter(Boolean).pop() || 'Document')).slice(0, 180);\n\n // Extract code blocks with language tags\n const codeBlockMatches = [...markdown.matchAll(/```([a-zA-Z0-9_+-]*)\\n([\\s\\S]*?)```/g)];\n const extractedCodeBlocks: ExtractedCodeBlock[] = codeBlockMatches\n .map((m) => ({\n language: (m[1] || '').trim().toLowerCase(),\n code: (m[2] || '').trim(),\n }))\n .filter((b) => b.code.length > 0);\n const extractedCodeSnippets = extractedCodeBlocks.map((b) => b.code);\n\n // Extract markdown tables (contiguous pipe lines with separator row)\n const tableBlocks =\n markdown.match(/(?:^\\|.+\\|\\s*\\n)+^\\|[-:| ]+\\|\\s*\\n(?:^\\|.+\\|\\s*\\n?)+/gm) ||\n markdown.match(/\\|[\\s\\S]*?\\|[\\s\\S]*?\\|/g) ||\n [];\n const extractedTables = tableBlocks.map((t) => t.trim()).filter((t) => t.length > 15);\n\n // Extract section headings\n const extractedHeadings = [...markdown.matchAll(/^#{1,3}\\s+(.+)$/gm)]\n .map((m) => m[1]!.trim())\n .filter((h) => h.length > 2 && h.length < 120);\n\n const keyExcerpts = extractSubstantiveExcerpts(markdown, 6);\n\n return {\n url,\n title,\n markdownContent: markdown,\n byteSize: Buffer.byteLength(markdown, 'utf-8'),\n extractedCodeSnippets,\n extractedCodeBlocks,\n extractedTables,\n extractedHeadings,\n keyExcerpts,\n tablesCount: extractedTables.length,\n fetchProvider: provider,\n };\n }\n}\n","import { ScrapedDocument, extractSubstantiveExcerpts } from '../harvester/webScraper';\nimport { TechnicalDomain } from '../harvester/domainClassifier';\nimport { CourseResearchContext, LlmTextFn } from '../config/researchConfig';\n\nexport interface ScoredEvidence {\n doc: ScrapedDocument;\n score: number; // 1 to 10\n isApproved: boolean; // >= 6 is approved\n isLlmEvaluated?: boolean;\n breakdown: {\n technicalDepth?: number; // legacy alias for backwards compatibility\n structuralRichness: number; // 1-10: format hygiene, byte size, headings, tables\n codeSnippetQuality: number; // 1-10\n noiseFactor: number; // 1-10 (lower is better)\n pedagogicalRelevance?: number; // 1-10 (when evaluated by LLM)\n };\n summary: string;\n keyTakeaways: string[];\n}\n\nfunction tokenizeBilingualKeywords(text: string): string[] {\n return text\n .normalize('NFC')\n .toLowerCase()\n .replace(/[.,;:!?()[\\]{}\"“”‘’/\\\\|`*_~#-]+/g, ' ')\n .split(/\\s+/)\n .filter((w) => w.length >= 2 && !/^(and|the|for|with|from|into|của|trong|được|những|các|cho|với|khi|và|hoặc|để|từ|đến|về)$/.test(w));\n}\n\n/**\n * Extracts top key sentences from a document ranked by keyword overlap and structural salience (TextRank-inspired).\n */\nexport function extractTopSentences(markdown: string, targetTopic: string, maxSentences = 3): string[] {\n const keywords = tokenizeBilingualKeywords(targetTopic);\n const withoutCode = markdown.replace(/```[\\s\\S]*?```/g, ' ');\n const rawSentences = withoutCode\n .split(/(?<=[.!?。\\n])\\s+/)\n .map((s) => s.replace(/^[-*•#>\\s]+/, '').replace(/\\s+/g, ' ').trim())\n .filter((s) => {\n if (s.length < 45 || s.length > 320) return false;\n if (s.startsWith('|') || s.startsWith('http')) return false;\n if (/\\b(cookie|privacy policy|sign in|subscribe|all rights reserved)\\b/i.test(s)) return false;\n return true;\n });\n\n if (rawSentences.length === 0) return [];\n\n const scored = rawSentences.map((sentence, idx) => {\n const lower = sentence.normalize('NFC').toLowerCase();\n const matchedCount = keywords.filter((k) => lower.includes(k)).length;\n const positionBonus = idx < 8 ? 1.5 : idx < 20 ? 0.5 : 0;\n const technicalBonus = /(`[^`]+`|\\b(?:api|function|class|actor|async|sensor|pin|loop|state|biến|hàm|cảm biến|vòng lặp|mạch)\\b)/i.test(\n sentence\n )\n ? 1.5\n : 0;\n return {\n sentence,\n idx,\n score: matchedCount * 2 + positionBonus + technicalBonus,\n };\n });\n\n return scored\n .sort((a, b) => b.score - a.score || a.idx - b.idx)\n .slice(0, maxSentences)\n .sort((a, b) => a.idx - b.idx)\n .map((s) => s.sentence);\n}\n\n/**\n * Evaluates and scores evidence on a 1-10 scale and extracts real substantive takeaways\n */\nexport class EvidenceScorer {\n scoreDocument(doc: ScrapedDocument, domain: TechnicalDomain, targetTopic: string): ScoredEvidence {\n let depthScore = 5;\n const hasCode = doc.extractedCodeSnippets.length > 0;\n let codeScore = hasCode ? Math.min(10, 7 + Math.min(3, doc.extractedCodeSnippets.length)) : 5;\n let noiseScore = 2;\n\n const lowerContent = doc.markdownContent.normalize('NFC').toLowerCase();\n const targetKeywords = tokenizeBilingualKeywords(targetTopic);\n const keywordMatches = targetKeywords.filter((k) => lowerContent.includes(k)).length;\n const matchRatio = targetKeywords.length > 0 ? keywordMatches / targetKeywords.length : 1;\n\n if (matchRatio >= 0.75) depthScore += 3;\n else if (matchRatio >= 0.4) depthScore += 2;\n else if (keywordMatches >= 1) depthScore += 1;\n\n if (doc.tablesCount > 0) depthScore += 1;\n if (doc.byteSize > 1500) depthScore += 1;\n if ((doc.extractedHeadings?.length || 0) >= 2) depthScore += 1;\n depthScore = Math.min(10, depthScore);\n\n // Conceptual, academic, or official overview pages without code fences shouldn't be rejected if rich in structure\n if (!hasCode && doc.byteSize > 1200 && matchRatio >= 0.5) {\n codeScore = 6;\n }\n\n if (lowerContent.includes('subscribe') && lowerContent.includes('advertisement')) {\n noiseScore += 3;\n }\n\n const rawTotal = depthScore * 0.55 + codeScore * 0.35 - noiseScore * 0.1 + 0.5;\n const score = Math.max(1, Math.min(10, Math.round(rawTotal)));\n const isApproved = score >= 6;\n\n const topSentences = extractTopSentences(doc.markdownContent, targetTopic, 3);\n const excerpts = doc.keyExcerpts?.length ? doc.keyExcerpts : extractSubstantiveExcerpts(doc.markdownContent, 3);\n const keyTakeaways = topSentences.length > 0 ? topSentences : excerpts.slice(0, 2);\n\n const summary =\n keyTakeaways.length > 0\n ? `${keyTakeaways[0]} [Evidence ${score}/10 · ${doc.extractedCodeSnippets.length} code blocks · ${doc.tablesCount} tables]`\n : `Evidence scored ${score}/10 (${isApproved ? 'APPROVED' : 'REJECTED'}) for ${domain} (${doc.byteSize} bytes).`;\n\n return {\n doc,\n score,\n isApproved,\n isLlmEvaluated: false,\n breakdown: {\n technicalDepth: depthScore,\n structuralRichness: depthScore,\n codeSnippetQuality: codeScore,\n noiseFactor: noiseScore,\n },\n summary,\n keyTakeaways,\n };\n }\n\n /**\n * Evaluates evidence with host LLM for genuine pedagogical relevance, conceptual depth,\n * and accuracy for the target learner age band.\n */\n async scoreDocumentWithLlm(\n doc: ScrapedDocument,\n domain: TechnicalDomain,\n targetTopic: string,\n options: { llm?: LlmTextFn; context?: CourseResearchContext } = {}\n ): Promise<ScoredEvidence> {\n const baseline = this.scoreDocument(doc, domain, targetTopic);\n if (!options.llm) {\n return baseline;\n }\n\n try {\n const prompt = [\n `You are a Senior Curriculum Researcher. Evaluate this harvested web document for the course topic \"${targetTopic}\" (Domain: ${domain}).`,\n options.context?.ageBand ? `Target Learner Age Band: ${options.context.ageBand[0]}-${options.context.ageBand[1]}` : '',\n options.context?.hardwarePlatform ? `Hardware Platform: ${options.context.hardwarePlatform}` : '',\n options.context?.softwareEnv ? `Software / Tools: ${options.context.softwareEnv}` : '',\n `\\nDocument Title: ${doc.title}`,\n `Document URL: ${doc.url}`,\n `Sample Excerpts:\\n${(doc.keyExcerpts || []).slice(0, 3).join('\\n')}`,\n `Code Blocks Found: ${doc.extractedCodeSnippets.length}`,\n `\\nReturn ONLY a JSON object:`,\n `{\"score\": 8, \"isApproved\": true, \"pedagogicalRelevance\": 9, \"summary\": \"1-sentence evaluative summary\", \"keyTakeaways\": [\"Takeaway 1 grounded in text\", \"Takeaway 2\"]}`,\n ]\n .filter(Boolean)\n .join('\\n');\n\n const raw = await options.llm(prompt, {\n system: 'You are an educational curriculum auditor. Output strictly valid JSON.',\n temperature: 0.2,\n jsonMode: true,\n });\n\n const match = raw.match(/\\{[\\s\\S]*\\}/);\n if (match) {\n const parsed = JSON.parse(match[0]);\n const score = Math.max(1, Math.min(10, Number(parsed.score) || baseline.score));\n return {\n doc,\n score,\n isApproved: score >= 6,\n isLlmEvaluated: true,\n breakdown: {\n ...baseline.breakdown,\n pedagogicalRelevance: Number(parsed.pedagogicalRelevance) || score,\n },\n summary: String(parsed.summary || baseline.summary),\n keyTakeaways: Array.isArray(parsed.keyTakeaways) && parsed.keyTakeaways.length > 0\n ? parsed.keyTakeaways.map(String)\n : baseline.keyTakeaways,\n };\n }\n } catch (e: any) {\n console.warn('[EvidenceScorer] LLM evidence evaluation failed, using structural baseline:', e?.message || e);\n }\n\n return baseline;\n }\n}\n","import { LlmTextFn } from '../config/researchConfig';\n\nexport type ClaimVerdict = 'supported' | 'refuted' | 'not_enough_evidence' | 'lexical_match_only';\n\nexport interface VerifiedClaim {\n claimText: string;\n sourceUrl?: string;\n verdict: ClaimVerdict;\n isSupported: boolean;\n isLlmVerified: boolean;\n confidenceScore: number;\n extractedQuote?: string;\n explanation?: string;\n}\n\nexport interface ClaimSweepReport {\n totalClaimsChecked: number;\n supportedClaimsCount: number;\n refutedClaimsCount: number;\n unverifiedClaimsCount: number;\n hallucinationRisk: 'low' | 'medium' | 'high';\n isLlmVerified: boolean;\n claims: VerifiedClaim[];\n reportMd: string;\n}\n\n/**\n * Non-semantic grammatical fillers ONLY.\n * NEVER include negation words ('không', 'chưa', 'not', 'never') or causal markers ('khi', 'nếu', 'thì', 'if', 'then')\n * because stripping them inverts semantic polarity and destroys conditional assertions.\n */\nconst CLAIM_STOPWORDS = new Set([\n 'the', 'and', 'for', 'with', 'that', 'this', 'from', 'into', 'are', 'was', 'were', 'have', 'has',\n 'will', 'would', 'through', 'their', 'these', 'those', 'which', 'while',\n 'của', 'trong', 'được', 'những', 'các', 'cho', 'với', 'và', 'hoặc', 'để',\n 'từ', 'đến', 'về', 'này', 'đó', 'một', 'như', 'sẽ', 'đang', 'đã', 'ra', 'vào', 'là',\n]);\n\nfunction extractSignificantTokens(text: string): string[] {\n return text\n .normalize('NFC')\n .toLowerCase()\n .replace(/[.,;:!?()[\\]{}\"“”‘’/\\\\|`*_~#-]+/g, ' ')\n .split(/\\s+/)\n .filter((w) => w.length >= 3 && !CLAIM_STOPWORDS.has(w));\n}\n\nfunction tokenMatchesCorpus(token: string, lowerCorpus: string): boolean {\n if (lowerCorpus.includes(token)) return true;\n // Basic morphological stem check (e.g., eliminate -> eliminat, isolation -> isolat, races -> race)\n if (token.length >= 6) {\n const stem = token.replace(/(?:ing|tion|ions|ment|ments|ed|es|s)$/, '');\n if (stem.length >= 4 && lowerCorpus.includes(stem)) return true;\n }\n return false;\n}\n\n/**\n * Claim-Support Sweep & Fact Checker\n * Combines Deterministic Passage Retrieval (Passage Candidate Slicing)\n * with LLM Semantic Entailment (Natural Language Inference).\n */\nexport class ClaimVerifier {\n /**\n * Deterministic lexical match baseline.\n * Explicitly marks verdict as 'lexical_match_only' to prevent false sense of semantic verification.\n */\n verifyClaimsDeterministic(claims: string[], sourceCorpus: string): ClaimSweepReport {\n const verifiedList: VerifiedClaim[] = [];\n const normCorpus = sourceCorpus.normalize('NFC');\n const lowerCorpus = normCorpus.toLowerCase();\n const corpusSentences = normCorpus\n .split(/(?<=[.!?。\\n])\\s+/)\n .map((s) => s.replace(/^[-*•#>\\s]+/, '').replace(/\\s+/g, ' ').trim())\n .filter((s) => {\n if (s.length < 25) return false;\n if (/^(title:|url source:|final url:|http|!\\[)/i.test(s)) return false;\n return true;\n });\n\n for (const claim of claims) {\n const claimTokens = extractSignificantTokens(claim);\n const matchCount = claimTokens.filter((t) => tokenMatchesCorpus(t, lowerCorpus)).length;\n const matchRatio = claimTokens.length > 0 ? matchCount / claimTokens.length : 0;\n\n // Find best candidate supporting quote from corpus sentences via lexical overlap\n let bestQuote: string | undefined;\n let bestSentenceRatio = 0;\n for (const sent of corpusSentences) {\n const lowerSent = sent.toLowerCase();\n const sentMatches = claimTokens.filter((t) => tokenMatchesCorpus(t, lowerSent)).length;\n const sentRatio = claimTokens.length > 0 ? sentMatches / claimTokens.length : 0;\n if (sentRatio > bestSentenceRatio) {\n bestSentenceRatio = sentRatio;\n bestQuote = sent.slice(0, 240);\n }\n }\n\n const effectiveRatio = Math.max(matchRatio, bestSentenceRatio);\n const hasLexicalEvidence = effectiveRatio >= 0.55;\n\n verifiedList.push({\n claimText: claim,\n verdict: 'lexical_match_only',\n isSupported: hasLexicalEvidence,\n isLlmVerified: false,\n confidenceScore: Math.round(effectiveRatio * 100),\n extractedQuote: hasLexicalEvidence ? bestQuote : undefined,\n explanation: hasLexicalEvidence\n ? `Lexical token match found (${Math.round(effectiveRatio * 100)}% token overlap). Semantic entailment requires LLM verification.`\n : `Insufficient lexical overlap in harvest corpus (${Math.round(effectiveRatio * 100)}%).`,\n });\n }\n\n const supportedCount = verifiedList.filter((c) => c.isSupported).length;\n const supportPct = claims.length > 0 ? (supportedCount / claims.length) * 100 : 100;\n const hallucinationRisk = supportPct >= 80 ? 'low' : supportPct >= 50 ? 'medium' : 'high';\n\n const mdLines = [\n `# 🔍 Claim-Support Sweep & Verification Report (Lexical Scan Mode)`,\n `> **Notice:** *Scored via deterministic lexical token matching. True semantic entailment requires an LLM call.*`,\n `> **Lexical Coverage:** \\`${supportPct.toFixed(1)}%\\` (${supportedCount}/${claims.length} claims with token matches) | **Hallucination Risk (Lexical):** \\`${hallucinationRisk.toUpperCase()}\\``,\n `\\n| Pedagogical / Technical Claim | Evidence Status | Token Match | Supporting Quote | Semantic Status |`,\n `|---|---|---|---|---|`,\n ...verifiedList.map(\n (c) =>\n `| ${c.claimText.replace(/\\|/g, '/')} | ${c.isSupported ? '🟡 **LEXICAL MATCH**' : '⚠️ *UNVERIFIED / GAP*'} | \\`${c.confidenceScore}%\\` | ${(c.extractedQuote || '—').replace(/\\|/g, '/')} | *Awaiting LLM Entailment* |`\n ),\n ];\n\n return {\n totalClaimsChecked: claims.length,\n supportedClaimsCount: supportedCount,\n refutedClaimsCount: 0,\n unverifiedClaimsCount: claims.length - supportedCount,\n hallucinationRisk,\n isLlmVerified: false,\n claims: verifiedList,\n reportMd: mdLines.join('\\n'),\n };\n }\n\n /**\n * Primary verification interface.\n * If an LLM callback is provided, performs genuine Semantic Entailment (NLI).\n * Otherwise falls back to deterministic lexical retrieval with honest labeling.\n */\n async verifyClaims(\n claims: string[],\n sourceCorpus: string,\n options: { llm?: LlmTextFn } = {}\n ): Promise<ClaimSweepReport> {\n const detReport = this.verifyClaimsDeterministic(claims, sourceCorpus);\n if (!options.llm || claims.length === 0) {\n return detReport;\n }\n\n try {\n const normCorpus = sourceCorpus.normalize('NFC');\n const cleanSubstantiveText = normCorpus\n .replace(/```[\\s\\S]*?```/g, '\\n')\n .split('\\n')\n .filter((l) => !/^(title:|url source:|final url:|http|!\\[|#)/i.test(l.trim()))\n .join('\\n')\n .trim();\n\n const corpusSentences = cleanSubstantiveText\n .split(/(?<=[.!?。\\n])\\s+/)\n .map((s) => s.replace(/^[-*•#>\\s]+/, '').replace(/\\s+/g, ' ').trim())\n .filter((s) => s.length >= 25 && !/^(cookie|privacy|sign in|all rights reserved)/i.test(s));\n\n // Collect candidate passages for each claim.\n // If cross-lingual (e.g. Vietnamese claim vs English corpus), lexical overlap alone might miss translated synonyms,\n // so we include top lexical matches AND the first substantive paragraphs of the reference document.\n const fallbackExcerpts = corpusSentences.slice(0, 8).join('\\n');\n\n const claimContexts = claims.map((claim, idx) => {\n const tokens = extractSignificantTokens(claim);\n const topSentences = corpusSentences\n .map((sent) => ({\n sent,\n overlap: tokens.filter((t) => tokenMatchesCorpus(t, sent.toLowerCase())).length,\n }))\n .filter((item) => item.overlap > 0)\n .sort((a, b) => b.overlap - a.overlap)\n .slice(0, 5)\n .map((item) => item.sent);\n\n const candidates = topSentences.length > 0\n ? `${topSentences.join('\\n')}\\n\\n[General Reference Excerpts]:\\n${fallbackExcerpts}`\n : fallbackExcerpts || 'No substantive text found.';\n\n return {\n idx,\n claim,\n candidatePassages: candidates,\n };\n });\n\n const prompt = [\n `You are a Rigorous Scientific & Pedagogical Fact-Checking System (Natural Language Inference).`,\n `Evaluate whether each technical/pedagogical claim is strictly SUPPORTED, directly REFUTED, or has NOT_ENOUGH_EVIDENCE in the harvested technical reference text.`,\n `Pay careful attention to NEGATION words (\"không\", \"never\", \"tránh\", \"do not\"), causal relationships, hardware pin constraints, and edge cases. Do not assume truth without textual evidence.`,\n `\\nHarvested Reference Excerpts for Claims:\\n`,\n claimContexts.map((c) => `[Claim ${c.idx + 1}]: \"${c.claim}\"\\n[Passage Candidates]: ${c.candidatePassages}`).join('\\n\\n'),\n `\\nReturn ONLY a valid JSON array of objects with the exact structure:`,\n `[{\"claimIndex\": 1, \"verdict\": \"supported\"|\"refuted\"|\"not_enough_evidence\", \"confidenceScore\": 95, \"extractedQuote\": \"exact quote from passage\", \"explanation\": \"1-sentence semantic reason\"}]`,\n ].join('\\n');\n\n const raw = await options.llm(prompt, {\n system: 'You are an exacting academic fact-checker. Output strictly valid JSON array without commentary.',\n temperature: 0.1,\n jsonMode: true,\n });\n\n let parsed: any[] = [];\n const arrayMatch = raw.match(/\\[[\\s\\S]*\\]/);\n if (arrayMatch) {\n try {\n const res = JSON.parse(arrayMatch[0]);\n if (Array.isArray(res)) parsed = res;\n } catch {}\n }\n if (parsed.length === 0) {\n const objMatch = raw.match(/\\{[\\s\\S]*\\}/);\n if (objMatch) {\n try {\n const obj = JSON.parse(objMatch[0]);\n const candidateList = obj.claims || obj.results || obj.verifications || Object.values(obj).find(Array.isArray);\n if (Array.isArray(candidateList)) parsed = candidateList;\n } catch {}\n }\n }\n\n if (parsed.length > 0) {\n const verifiedList: VerifiedClaim[] = claims.map((claim, idx) => {\n const item = parsed.find((p: any) => p.claimIndex === idx + 1) || parsed[idx];\n const verdict: ClaimVerdict =\n item && ['supported', 'refuted', 'not_enough_evidence'].includes(item.verdict)\n ? item.verdict\n : detReport.claims[idx]?.isSupported\n ? 'supported'\n : 'not_enough_evidence';\n\n const isSupported = verdict === 'supported';\n return {\n claimText: claim,\n verdict,\n isSupported,\n isLlmVerified: true,\n confidenceScore: Number(item?.confidenceScore) || (isSupported ? 90 : 30),\n extractedQuote: item?.extractedQuote || detReport.claims[idx]?.extractedQuote,\n explanation: item?.explanation || (isSupported ? 'Semantically entailed by reference corpus.' : 'Not verified.'),\n };\n });\n\n const supportedCount = verifiedList.filter((c) => c.verdict === 'supported').length;\n const refutedCount = verifiedList.filter((c) => c.verdict === 'refuted').length;\n const unverifiedCount = claims.length - supportedCount;\n const supportPct = claims.length > 0 ? (supportedCount / claims.length) * 100 : 100;\n const hallucinationRisk = refutedCount > 0 ? 'high' : supportPct >= 75 ? 'low' : 'medium';\n\n const mdLines = [\n `# 🔍 Claim-Support Sweep & Semantic Verification Report (LLM NLI Evaluated)`,\n `> **Semantic Verification Rate:** \\`${supportPct.toFixed(1)}%\\` (${supportedCount}/${claims.length} claims supported) | **Refuted / Contradictions:** \\`${refutedCount}\\` | **Hallucination Risk:** \\`${hallucinationRisk.toUpperCase()}\\``,\n `\\n| Pedagogical / Technical Claim | Semantic Verdict | Confidence | Supporting Quote / Evidence | Explanation |`,\n `|---|---|---|---|---|`,\n ...verifiedList.map(\n (c) =>\n `| ${c.claimText.replace(/\\|/g, '/')} | ${\n c.verdict === 'supported'\n ? '✅ **SUPPORTED**'\n : c.verdict === 'refuted'\n ? '❌ **REFUTED**'\n : '⚠️ *NOT ENOUGH EVIDENCE*'\n } | \\`${c.confidenceScore}%\\` | ${(c.extractedQuote || '—').replace(/\\|/g, '/')} | ${(c.explanation || '').replace(/\\|/g, '/')} |`\n ),\n ];\n\n return {\n totalClaimsChecked: claims.length,\n supportedClaimsCount: supportedCount,\n refutedClaimsCount: refutedCount,\n unverifiedClaimsCount: unverifiedCount,\n hallucinationRisk,\n isLlmVerified: true,\n claims: verifiedList,\n reportMd: mdLines.join('\\n'),\n };\n }\n } catch (e: any) {\n console.warn('[ClaimVerifier] LLM semantic verification failed, falling back to deterministic lexical report:', e?.message || e);\n }\n\n return detReport;\n }\n}\n","export interface ProvenanceRecord {\n resourceId: string;\n sourceUrl: string;\n accessedAt: string;\n domain: string;\n relevanceScore: number;\n byteSize: number;\n}\n\nexport interface ProvenanceSidecar {\n topic: string;\n campaignId: string;\n generatedAt: string;\n totalRecords: number;\n records: ProvenanceRecord[];\n provenanceMd: string;\n}\n\n/**\n * Generates the mandatory *.provenance.md sidecar document (English Canonical)\n */\nexport class ProvenanceTracker {\n generateSidecar(topic: string, records: ProvenanceRecord[]): ProvenanceSidecar {\n const campaignId = `CAMP-${Math.random().toString(36).substring(2, 9).toUpperCase()}`;\n const generatedAt = new Date().toISOString();\n\n const mdLines = [\n `# 📜 Provenance & Audit Trail: ${topic}`,\n `> **Campaign ID:** \\`${campaignId}\\` | **Generated At:** \\`${generatedAt}\\` | **Total Verified Sources:** \\`${records.length}\\``,\n `\\n## Audit Trail Table`,\n `| Resource ID | Domain | Relevancy | Size (Bytes) | Source URL | Timestamp |`,\n `|---|---|---|---|---|---|`,\n ...records.map(r => `| **${r.resourceId}** | \\`${r.domain}\\` | ⭐ \\`${r.relevanceScore}/10\\` | \\`${r.byteSize}\\` | [Access Source](${r.sourceUrl}) | \\`${r.accessedAt.slice(0, 19)}\\` |`),\n `\\n## Integrity Guarantee`,\n `- Every pedagogical claim and technical snippet in the curriculum maps 1-to-1 to the physical sources listed above.`,\n `- Unverified citations or hallucinated sources are strictly prohibited under Curriculum OS Rule §5.`\n ];\n\n return {\n topic,\n campaignId,\n generatedAt,\n totalRecords: records.length,\n records,\n provenanceMd: mdLines.join('\\n'),\n };\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/harvester/webScraper.ts","../../src/evidence/evidenceScorer.ts","../../src/evidence/claimVerifier.ts","../../src/evidence/provenanceTracker.ts"],"names":[],"mappings":";;;AAgCO,SAAS,0BAAA,CAA2B,QAAA,EAAkB,WAAA,GAAc,CAAA,EAAa;AACtF,EAAA,MAAM,WAAA,GAAc,QAAA,CAAS,OAAA,CAAQ,iBAAA,EAAmB,IAAI,CAAA;AAC5D,EAAA,MAAM,SAAS,WAAA,CACZ,KAAA,CAAM,QAAQ,CAAA,CACd,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,OAAA,CAAQ,MAAA,EAAQ,GAAG,CAAA,CAAE,IAAA,EAAM,CAAA,CACxC,MAAA,CAAO,CAAC,CAAA,KAAM;AACb,IAAA,IAAI,EAAE,MAAA,GAAS,EAAA,IAAM,CAAA,CAAE,MAAA,GAAS,KAAK,OAAO,KAAA;AAC5C,IAAA,IAAI,CAAA,CAAE,WAAW,GAAG,CAAA,IAAK,EAAE,UAAA,CAAW,GAAG,GAAG,OAAO,KAAA;AACnD,IAAA,MAAM,SAAA,GAAA,CAAa,CAAA,CAAE,KAAA,CAAM,sBAAsB,CAAA,IAAK,EAAC,EAAG,IAAA,CAAK,EAAE,CAAA,CAAE,MAAA,GAAS,CAAA,CAAE,MAAA;AAC9E,IAAA,IAAI,SAAA,GAAY,MAAM,OAAO,KAAA;AAC7B,IAAA,IAAI,qHAAA,CAAsH,IAAA,CAAK,CAAC,CAAA,EAAG;AACjI,MAAA,OAAO,KAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAA;AAAA,EACT,CAAC,CAAA;AAEH,EAAA,OAAO,MAAA,CAAO,KAAA,CAAM,CAAA,EAAG,WAAW,CAAA;AACpC;;;AC7BA,SAAS,0BAA0B,IAAA,EAAwB;AACzD,EAAA,OAAO,IAAA,CACJ,UAAU,KAAK,CAAA,CACf,aAAY,CACZ,OAAA,CAAQ,kCAAA,EAAoC,GAAG,CAAA,CAC/C,KAAA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AA,MACtB,OAAA;AAAA,MACA,YAAA,EAAc,OAAA,CAAQ,IAAA,CAAK,IAAI;AAAA,KACjC;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import { CustomCrawlerAdapter } from '../config/researchConfig';\nimport { isYouTubeUrl, YouTubeIngestionService } from './youtubeTranscript';\n\nexport interface ExtractedCodeBlock {\n language: string;\n code: string;\n}\n\nexport interface ScrapedDocument {\n url: string;\n title: string;\n markdownContent: string;\n byteSize: number;\n extractedCodeSnippets: string[];\n extractedCodeBlocks?: ExtractedCodeBlock[];\n extractedTables?: string[];\n extractedHeadings?: string[];\n keyExcerpts?: string[];\n tablesCount: number;\n fetchProvider: 'jina' | 'crawl4ai' | 'youtube' | 'direct' | 'custom';\n}\n\nexport interface WebScraperOptions {\n crawl4aiHost?: string;\n jinaKey?: string;\n allowEnvFallback?: boolean;\n customAdapter?: CustomCrawlerAdapter;\n}\n\n/**\n * Extracts top substantive paragraphs from Markdown (stripping navigation, links-only lines, and cookie banners).\n */\nexport function extractSubstantiveExcerpts(markdown: string, maxExcerpts = 6): string[] {\n const withoutCode = markdown.replace(/```[\\s\\S]*?```/g, '\\n');\n const blocks = withoutCode\n .split(/\\n{2,}/)\n .map((b) => b.replace(/\\s+/g, ' ').trim())\n .filter((b) => {\n if (b.length < 60 || b.length > 900) return false;\n if (b.startsWith('#') || b.startsWith('|')) return false;\n const linkRatio = (b.match(/\\[[^\\]]+\\]\\([^)]+\\)/g) || []).join('').length / b.length;\n if (linkRatio > 0.45) return false;\n if (/\\b(cookie policy|privacy policy|all rights reserved|terms of service|sign in|log in|subscribe to our newsletter)\\b/i.test(b)) {\n return false;\n }\n return true;\n });\n\n return blocks.slice(0, maxExcerpts);\n}\n\n/**\n * High-fidelity web content & YouTube transcript extractor with Custom Crawler & Jina Auth support\n */\nexport class WebScraper {\n private crawl4aiHost?: string;\n private jinaKey?: string;\n private allowEnvFallback: boolean;\n private customAdapter?: CustomCrawlerAdapter;\n private youtubeService: YouTubeIngestionService;\n\n constructor(options: WebScraperOptions = {}) {\n this.allowEnvFallback = options.allowEnvFallback ?? true;\n this.crawl4aiHost =\n options.crawl4aiHost || (this.allowEnvFallback ? process.env.CRAWL4AI_HOST : undefined) || 'http://localhost:11235';\n this.jinaKey = options.jinaKey || (this.allowEnvFallback ? process.env.JINA_API_KEY : undefined);\n this.customAdapter = options.customAdapter;\n this.youtubeService = new YouTubeIngestionService();\n }\n\n setCustomAdapter(adapter: CustomCrawlerAdapter) {\n this.customAdapter = adapter;\n }\n\n setJinaKey(key?: string) {\n this.jinaKey = key;\n }\n\n async scrapeUrl(\n targetUrl: string,\n options: { customAdapter?: CustomCrawlerAdapter; jinaKey?: string; preferredLanguages?: string[] } = {}\n ): Promise<ScrapedDocument> {\n const adapter = options.customAdapter || this.customAdapter;\n\n // 0. Custom Crawler Adapter (e.g. MCP bridge, Playwright, Headless Chrome)\n if (adapter) {\n try {\n const result = await adapter.crawl(targetUrl);\n if (result && result.markdownContent) {\n return this.packageDocument(targetUrl, result.markdownContent, 'custom', result.title);\n }\n } catch (e: any) {\n console.warn(`[WebScraper] Custom crawler adapter failed for ${targetUrl}:`, e?.message || e);\n }\n }\n\n // 0.5. YouTube Video URL -> Route to YouTubeIngestionService (Idea §3.1)\n if (isYouTubeUrl(targetUrl)) {\n try {\n const yt = await this.youtubeService.fetchTranscript(targetUrl, options.preferredLanguages);\n if (yt.stitchedMarkdown && yt.stitchedMarkdown.length > 80) {\n return this.packageDocument(yt.url, yt.stitchedMarkdown, 'youtube', yt.title);\n }\n } catch (e: any) {\n console.warn(`[WebScraper] YouTube transcript extraction failed for ${targetUrl}:`, e?.message || e);\n }\n }\n\n // 1. Try Jina Reader API (with optional Bearer auth from host app or env)\n try {\n const jinaUrl = `https://r.jina.ai/${targetUrl}`;\n const jinaKey = options.jinaKey || this.jinaKey;\n const headers: Record<string, string> = {\n 'User-Agent': 'OrchableComposer/1.0',\n 'X-Return-Format': 'markdown',\n };\n if (jinaKey) {\n headers['Authorization'] = `Bearer ${jinaKey}`;\n }\n\n const res = await fetch(jinaUrl, {\n headers,\n signal: AbortSignal.timeout(8000),\n });\n\n if (res.ok) {\n const markdown = await res.text();\n if (markdown && markdown.length > 100) {\n return this.packageDocument(targetUrl, markdown, 'jina');\n }\n }\n } catch (e: any) {\n console.warn(`[WebScraper] Jina Reader failed for ${targetUrl}:`, e?.message || e);\n }\n\n // 2. Try Crawl4AI Local Server if reachable\n if (this.crawl4aiHost) {\n try {\n const res = await fetch(`${this.crawl4aiHost}/crawl`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n urls: targetUrl,\n priority: 10,\n }),\n signal: AbortSignal.timeout(15000),\n });\n\n if (res.ok) {\n const data = await res.json();\n const markdown = data?.results?.[0]?.markdown || data?.markdown;\n if (markdown) {\n return this.packageDocument(targetUrl, markdown, 'crawl4ai');\n }\n }\n } catch {\n // ignore if local crawl4ai is not running\n }\n }\n\n // 3. Fallback: Direct Fetch & Structured HTML-to-Markdown Conversion\n try {\n const res = await fetch(targetUrl, {\n headers: { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)' },\n signal: AbortSignal.timeout(10000),\n });\n if (res.ok) {\n const rawHtml = await res.text();\n const titleTag = rawHtml.match(/<title[^>]*>([\\s\\S]*?)<\\/title>/i)?.[1]?.trim();\n const clean = rawHtml\n .replace(/<script\\b[^<]*(?:(?!<\\/script>)<[^<]*)*<\\/script>/gi, '')\n .replace(/<style\\b[^<]*(?:(?!<\\/style>)<[^<]*)*<\\/style>/gi, '')\n .replace(/<nav\\b[^<]*(?:(?!<\\/nav>)<[^<]*)*<\\/nav>/gi, '')\n .replace(/<footer\\b[^<]*(?:(?!<\\/footer>)<[^<]*)*<\\/footer>/gi, '')\n .replace(/<h([1-3])[^>]*>([\\s\\S]*?)<\\/h\\1>/gi, (_, lvl, txt) => `\\n${'#'.repeat(Number(lvl))} ${txt.replace(/<[^>]+>/g, '').trim()}\\n`)\n .replace(/<pre[^>]*><code[^>]*>([\\s\\S]*?)<\\/code><\\/pre>/gi, (_, code) => `\\n\\`\\`\\`\\n${code.replace(/<[^>]+>/g, '').trim()}\\n\\`\\`\\`\\n`)\n .replace(/<p[^>]*>([\\s\\S]*?)<\\/p>/gi, (_, p) => `\\n${p.replace(/<[^>]+>/g, ' ').trim()}\\n`)\n .replace(/<[^>]+>/g, ' ')\n .replace(/[ \\t]+/g, ' ')\n .replace(/\\n{3,}/g, '\\n\\n')\n .trim();\n\n return this.packageDocument(targetUrl, clean, 'direct', titleTag);\n }\n } catch (e: any) {\n console.warn(`[WebScraper] Direct fetch failed for ${targetUrl}:`, e?.message || e);\n }\n\n throw new Error(`Unable to fetch content from URL: ${targetUrl}`);\n }\n\n private packageDocument(\n url: string,\n markdown: string,\n provider: 'jina' | 'crawl4ai' | 'youtube' | 'direct' | 'custom',\n explicitTitle?: string\n ): ScrapedDocument {\n const titleMatch = markdown.match(/^#\\s+(.+)$/m) || markdown.match(/^Title:\\s*(.+)$/im);\n const title = (explicitTitle || (titleMatch ? titleMatch[1]!.trim() : url.split('/').filter(Boolean).pop() || 'Document')).slice(0, 180);\n\n // Extract code blocks with language tags\n const codeBlockMatches = [...markdown.matchAll(/```([a-zA-Z0-9_+-]*)\\n([\\s\\S]*?)```/g)];\n const extractedCodeBlocks: ExtractedCodeBlock[] = codeBlockMatches\n .map((m) => ({\n language: (m[1] || '').trim().toLowerCase(),\n code: (m[2] || '').trim(),\n }))\n .filter((b) => b.code.length > 0);\n const extractedCodeSnippets = extractedCodeBlocks.map((b) => b.code);\n\n // Extract markdown tables (contiguous pipe lines with separator row)\n const tableBlocks =\n markdown.match(/(?:^\\|.+\\|\\s*\\n)+^\\|[-:| ]+\\|\\s*\\n(?:^\\|.+\\|\\s*\\n?)+/gm) ||\n markdown.match(/\\|[\\s\\S]*?\\|[\\s\\S]*?\\|/g) ||\n [];\n const extractedTables = tableBlocks.map((t) => t.trim()).filter((t) => t.length > 15);\n\n // Extract section headings\n const extractedHeadings = [...markdown.matchAll(/^#{1,3}\\s+(.+)$/gm)]\n .map((m) => m[1]!.trim())\n .filter((h) => h.length > 2 && h.length < 120);\n\n const keyExcerpts = extractSubstantiveExcerpts(markdown, 6);\n\n return {\n url,\n title,\n markdownContent: markdown,\n byteSize: Buffer.byteLength(markdown, 'utf-8'),\n extractedCodeSnippets,\n extractedCodeBlocks,\n extractedTables,\n extractedHeadings,\n keyExcerpts,\n tablesCount: extractedTables.length,\n fetchProvider: provider,\n };\n }\n}\n","import { ScrapedDocument, extractSubstantiveExcerpts } from '../harvester/webScraper';\nimport { TechnicalDomain } from '../harvester/domainClassifier';\nimport { CourseResearchContext, LlmTextFn } from '../config/researchConfig';\n\nexport interface ScoredEvidence {\n doc: ScrapedDocument;\n score: number; // 1 to 10\n isApproved: boolean; // >= 6 is approved\n isLlmEvaluated?: boolean;\n breakdown: {\n technicalDepth?: number; // legacy alias for backwards compatibility\n structuralRichness: number; // 1-10: format hygiene, byte size, headings, tables\n codeSnippetQuality: number; // 1-10\n noiseFactor: number; // 1-10 (lower is better)\n pedagogicalRelevance?: number; // 1-10 (when evaluated by LLM)\n };\n summary: string;\n keyTakeaways: string[];\n}\n\nfunction tokenizeBilingualKeywords(text: string): string[] {\n return text\n .normalize('NFC')\n .toLowerCase()\n .replace(/[.,;:!?()[\\]{}\"“”‘’/\\\\|`*_~#-]+/g, ' ')\n .split(/\\s+/)\n .filter((w) => w.length >= 2 && !/^(and|the|for|with|from|into|của|trong|được|những|các|cho|với|khi|và|hoặc|để|từ|đến|về)$/.test(w));\n}\n\n/**\n * Extracts top key sentences from a document ranked by keyword overlap and structural salience (TextRank-inspired).\n */\nexport function extractTopSentences(markdown: string, targetTopic: string, maxSentences = 3): string[] {\n const keywords = tokenizeBilingualKeywords(targetTopic);\n const withoutCode = markdown.replace(/```[\\s\\S]*?```/g, ' ');\n const rawSentences = withoutCode\n .split(/(?<=[.!?。\\n])\\s+/)\n .map((s) => s.replace(/^[-*•#>\\s]+/, '').replace(/\\s+/g, ' ').trim())\n .filter((s) => {\n if (s.length < 45 || s.length > 320) return false;\n if (s.startsWith('|') || s.startsWith('http')) return false;\n if (/\\b(cookie|privacy policy|sign in|subscribe|all rights reserved)\\b/i.test(s)) return false;\n return true;\n });\n\n if (rawSentences.length === 0) return [];\n\n const scored = rawSentences.map((sentence, idx) => {\n const lower = sentence.normalize('NFC').toLowerCase();\n const matchedCount = keywords.filter((k) => lower.includes(k)).length;\n const positionBonus = idx < 8 ? 1.5 : idx < 20 ? 0.5 : 0;\n const technicalBonus = /(`[^`]+`|\\b(?:api|function|class|actor|async|sensor|pin|loop|state|biến|hàm|cảm biến|vòng lặp|mạch)\\b)/i.test(\n sentence\n )\n ? 1.5\n : 0;\n return {\n sentence,\n idx,\n score: matchedCount * 2 + positionBonus + technicalBonus,\n };\n });\n\n return scored\n .sort((a, b) => b.score - a.score || a.idx - b.idx)\n .slice(0, maxSentences)\n .sort((a, b) => a.idx - b.idx)\n .map((s) => s.sentence);\n}\n\n/**\n * Evaluates and scores evidence on a 1-10 scale and extracts real substantive takeaways\n */\nexport class EvidenceScorer {\n scoreDocument(doc: ScrapedDocument, domain: TechnicalDomain, targetTopic: string): ScoredEvidence {\n let depthScore = 5;\n const hasCode = doc.extractedCodeSnippets.length > 0;\n let codeScore = hasCode ? Math.min(10, 7 + Math.min(3, doc.extractedCodeSnippets.length)) : 5;\n let noiseScore = 2;\n\n const lowerContent = doc.markdownContent.normalize('NFC').toLowerCase();\n const targetKeywords = tokenizeBilingualKeywords(targetTopic);\n const keywordMatches = targetKeywords.filter((k) => lowerContent.includes(k)).length;\n const matchRatio = targetKeywords.length > 0 ? keywordMatches / targetKeywords.length : 1;\n\n if (matchRatio >= 0.75) depthScore += 3;\n else if (matchRatio >= 0.4) depthScore += 2;\n else if (keywordMatches >= 1) depthScore += 1;\n\n if (doc.tablesCount > 0) depthScore += 1;\n if (doc.byteSize > 1500) depthScore += 1;\n if ((doc.extractedHeadings?.length || 0) >= 2) depthScore += 1;\n depthScore = Math.min(10, depthScore);\n\n // Conceptual, academic, or official overview pages without code fences shouldn't be rejected if rich in structure\n if (!hasCode && doc.byteSize > 1200 && matchRatio >= 0.5) {\n codeScore = 6;\n }\n\n if (lowerContent.includes('subscribe') && lowerContent.includes('advertisement')) {\n noiseScore += 3;\n }\n\n const rawTotal = depthScore * 0.55 + codeScore * 0.35 - noiseScore * 0.1 + 0.5;\n const score = Math.max(1, Math.min(10, Math.round(rawTotal)));\n const isApproved = score >= 6;\n\n const topSentences = extractTopSentences(doc.markdownContent, targetTopic, 3);\n const excerpts = doc.keyExcerpts?.length ? doc.keyExcerpts : extractSubstantiveExcerpts(doc.markdownContent, 3);\n const keyTakeaways = topSentences.length > 0 ? topSentences : excerpts.slice(0, 2);\n\n const summary =\n keyTakeaways.length > 0\n ? `${keyTakeaways[0]} [Evidence ${score}/10 · ${doc.extractedCodeSnippets.length} code blocks · ${doc.tablesCount} tables]`\n : `Evidence scored ${score}/10 (${isApproved ? 'APPROVED' : 'REJECTED'}) for ${domain} (${doc.byteSize} bytes).`;\n\n return {\n doc,\n score,\n isApproved,\n isLlmEvaluated: false,\n breakdown: {\n technicalDepth: depthScore,\n structuralRichness: depthScore,\n codeSnippetQuality: codeScore,\n noiseFactor: noiseScore,\n },\n summary,\n keyTakeaways,\n };\n }\n\n /**\n * Evaluates evidence with host LLM for genuine pedagogical relevance, conceptual depth,\n * and accuracy for the target learner age band.\n */\n async scoreDocumentWithLlm(\n doc: ScrapedDocument,\n domain: TechnicalDomain,\n targetTopic: string,\n options: { llm?: LlmTextFn; context?: CourseResearchContext } = {}\n ): Promise<ScoredEvidence> {\n const baseline = this.scoreDocument(doc, domain, targetTopic);\n if (!options.llm) {\n return baseline;\n }\n\n try {\n const prompt = [\n `You are a Senior Curriculum Researcher. Evaluate this harvested web document for the course topic \"${targetTopic}\" (Domain: ${domain}).`,\n options.context?.ageBand ? `Target Learner Age Band: ${options.context.ageBand[0]}-${options.context.ageBand[1]}` : '',\n options.context?.hardwarePlatform ? `Hardware Platform: ${options.context.hardwarePlatform}` : '',\n options.context?.softwareEnv ? `Software / Tools: ${options.context.softwareEnv}` : '',\n `\\nDocument Title: ${doc.title}`,\n `Document URL: ${doc.url}`,\n `Sample Excerpts:\\n${(doc.keyExcerpts || []).slice(0, 3).join('\\n')}`,\n `Code Blocks Found: ${doc.extractedCodeSnippets.length}`,\n `\\nReturn ONLY a JSON object:`,\n `{\"score\": 8, \"isApproved\": true, \"pedagogicalRelevance\": 9, \"summary\": \"1-sentence evaluative summary\", \"keyTakeaways\": [\"Takeaway 1 grounded in text\", \"Takeaway 2\"]}`,\n ]\n .filter(Boolean)\n .join('\\n');\n\n const raw = await options.llm(prompt, {\n system: 'You are an educational curriculum auditor. Output strictly valid JSON.',\n temperature: 0.2,\n jsonMode: true,\n });\n\n const match = raw.match(/\\{[\\s\\S]*\\}/);\n if (match) {\n const parsed = JSON.parse(match[0]);\n const score = Math.max(1, Math.min(10, Number(parsed.score) || baseline.score));\n return {\n doc,\n score,\n isApproved: score >= 6,\n isLlmEvaluated: true,\n breakdown: {\n ...baseline.breakdown,\n pedagogicalRelevance: Number(parsed.pedagogicalRelevance) || score,\n },\n summary: String(parsed.summary || baseline.summary),\n keyTakeaways: Array.isArray(parsed.keyTakeaways) && parsed.keyTakeaways.length > 0\n ? parsed.keyTakeaways.map(String)\n : baseline.keyTakeaways,\n };\n }\n } catch (e: any) {\n console.warn('[EvidenceScorer] LLM evidence evaluation failed, using structural baseline:', e?.message || e);\n }\n\n return baseline;\n }\n}\n","import { LlmTextFn } from '../config/researchConfig';\n\nexport type ClaimVerdict = 'supported' | 'refuted' | 'not_enough_evidence' | 'lexical_match_only';\n\nexport interface VerifiedClaim {\n claimText: string;\n sourceUrl?: string;\n verdict: ClaimVerdict;\n isSupported: boolean;\n isLlmVerified: boolean;\n confidenceScore: number;\n extractedQuote?: string;\n explanation?: string;\n}\n\nexport interface ClaimSweepReport {\n totalClaimsChecked: number;\n supportedClaimsCount: number;\n refutedClaimsCount: number;\n unverifiedClaimsCount: number;\n hallucinationRisk: 'low' | 'medium' | 'high';\n isLlmVerified: boolean;\n claims: VerifiedClaim[];\n reportMd: string;\n}\n\n/**\n * Non-semantic grammatical fillers ONLY.\n * NEVER include negation words ('không', 'chưa', 'not', 'never') or causal markers ('khi', 'nếu', 'thì', 'if', 'then')\n * because stripping them inverts semantic polarity and destroys conditional assertions.\n */\nconst CLAIM_STOPWORDS = new Set([\n 'the', 'and', 'for', 'with', 'that', 'this', 'from', 'into', 'are', 'was', 'were', 'have', 'has',\n 'will', 'would', 'through', 'their', 'these', 'those', 'which', 'while',\n 'của', 'trong', 'được', 'những', 'các', 'cho', 'với', 'và', 'hoặc', 'để',\n 'từ', 'đến', 'về', 'này', 'đó', 'một', 'như', 'sẽ', 'đang', 'đã', 'ra', 'vào', 'là',\n]);\n\nfunction extractSignificantTokens(text: string): string[] {\n return text\n .normalize('NFC')\n .toLowerCase()\n .replace(/[.,;:!?()[\\]{}\"“”‘’/\\\\|`*_~#-]+/g, ' ')\n .split(/\\s+/)\n .filter((w) => w.length >= 3 && !CLAIM_STOPWORDS.has(w));\n}\n\nfunction tokenMatchesCorpus(token: string, lowerCorpus: string): boolean {\n if (lowerCorpus.includes(token)) return true;\n // Basic morphological stem check (e.g., eliminate -> eliminat, isolation -> isolat, races -> race)\n if (token.length >= 6) {\n const stem = token.replace(/(?:ing|tion|ions|ment|ments|ed|es|s)$/, '');\n if (stem.length >= 4 && lowerCorpus.includes(stem)) return true;\n }\n return false;\n}\n\n/**\n * Claim-Support Sweep & Fact Checker\n * Combines Deterministic Passage Retrieval (Passage Candidate Slicing)\n * with LLM Semantic Entailment (Natural Language Inference).\n */\nexport class ClaimVerifier {\n /**\n * Deterministic lexical match baseline.\n * Explicitly marks verdict as 'lexical_match_only' to prevent false sense of semantic verification.\n */\n verifyClaimsDeterministic(claims: string[], sourceCorpus: string): ClaimSweepReport {\n const verifiedList: VerifiedClaim[] = [];\n const normCorpus = sourceCorpus.normalize('NFC');\n const lowerCorpus = normCorpus.toLowerCase();\n const corpusSentences = normCorpus\n .split(/(?<=[.!?。\\n])\\s+/)\n .map((s) => s.replace(/^[-*•#>\\s]+/, '').replace(/\\s+/g, ' ').trim())\n .filter((s) => {\n if (s.length < 25) return false;\n if (/^(title:|url source:|final url:|http|!\\[)/i.test(s)) return false;\n return true;\n });\n\n for (const claim of claims) {\n const claimTokens = extractSignificantTokens(claim);\n const matchCount = claimTokens.filter((t) => tokenMatchesCorpus(t, lowerCorpus)).length;\n const matchRatio = claimTokens.length > 0 ? matchCount / claimTokens.length : 0;\n\n // Find best candidate supporting quote from corpus sentences via lexical overlap\n let bestQuote: string | undefined;\n let bestSentenceRatio = 0;\n for (const sent of corpusSentences) {\n const lowerSent = sent.toLowerCase();\n const sentMatches = claimTokens.filter((t) => tokenMatchesCorpus(t, lowerSent)).length;\n const sentRatio = claimTokens.length > 0 ? sentMatches / claimTokens.length : 0;\n if (sentRatio > bestSentenceRatio) {\n bestSentenceRatio = sentRatio;\n bestQuote = sent.slice(0, 240);\n }\n }\n\n const effectiveRatio = Math.max(matchRatio, bestSentenceRatio);\n const hasLexicalEvidence = effectiveRatio >= 0.55;\n\n verifiedList.push({\n claimText: claim,\n verdict: 'lexical_match_only',\n isSupported: hasLexicalEvidence,\n isLlmVerified: false,\n confidenceScore: Math.round(effectiveRatio * 100),\n extractedQuote: hasLexicalEvidence ? bestQuote : undefined,\n explanation: hasLexicalEvidence\n ? `Lexical token match found (${Math.round(effectiveRatio * 100)}% token overlap). Semantic entailment requires LLM verification.`\n : `Insufficient lexical overlap in harvest corpus (${Math.round(effectiveRatio * 100)}%).`,\n });\n }\n\n const supportedCount = verifiedList.filter((c) => c.isSupported).length;\n const supportPct = claims.length > 0 ? (supportedCount / claims.length) * 100 : 100;\n const hallucinationRisk = supportPct >= 80 ? 'low' : supportPct >= 50 ? 'medium' : 'high';\n\n const mdLines = [\n `# 🔍 Claim-Support Sweep & Verification Report (Lexical Scan Mode)`,\n `> **Notice:** *Scored via deterministic lexical token matching. True semantic entailment requires an LLM call.*`,\n `> **Lexical Coverage:** \\`${supportPct.toFixed(1)}%\\` (${supportedCount}/${claims.length} claims with token matches) | **Hallucination Risk (Lexical):** \\`${hallucinationRisk.toUpperCase()}\\``,\n `\\n| Pedagogical / Technical Claim | Evidence Status | Token Match | Supporting Quote | Semantic Status |`,\n `|---|---|---|---|---|`,\n ...verifiedList.map(\n (c) =>\n `| ${c.claimText.replace(/\\|/g, '/')} | ${c.isSupported ? '🟡 **LEXICAL MATCH**' : '⚠️ *UNVERIFIED / GAP*'} | \\`${c.confidenceScore}%\\` | ${(c.extractedQuote || '—').replace(/\\|/g, '/')} | *Awaiting LLM Entailment* |`\n ),\n ];\n\n return {\n totalClaimsChecked: claims.length,\n supportedClaimsCount: supportedCount,\n refutedClaimsCount: 0,\n unverifiedClaimsCount: claims.length - supportedCount,\n hallucinationRisk,\n isLlmVerified: false,\n claims: verifiedList,\n reportMd: mdLines.join('\\n'),\n };\n }\n\n /**\n * Primary verification interface.\n * If an LLM callback is provided, performs genuine Semantic Entailment (NLI).\n * Otherwise falls back to deterministic lexical retrieval with honest labeling.\n */\n async verifyClaims(\n claims: string[],\n sourceCorpus: string,\n options: { llm?: LlmTextFn } = {}\n ): Promise<ClaimSweepReport> {\n const detReport = this.verifyClaimsDeterministic(claims, sourceCorpus);\n if (!options.llm || claims.length === 0) {\n return detReport;\n }\n\n try {\n const normCorpus = sourceCorpus.normalize('NFC');\n const cleanSubstantiveText = normCorpus\n .replace(/```[\\s\\S]*?```/g, '\\n')\n .split('\\n')\n .filter((l) => !/^(title:|url source:|final url:|http|!\\[|#)/i.test(l.trim()))\n .join('\\n')\n .trim();\n\n const corpusSentences = cleanSubstantiveText\n .split(/(?<=[.!?。\\n])\\s+/)\n .map((s) => s.replace(/^[-*•#>\\s]+/, '').replace(/\\s+/g, ' ').trim())\n .filter((s) => s.length >= 25 && !/^(cookie|privacy|sign in|all rights reserved)/i.test(s));\n\n // Collect candidate passages for each claim.\n // If cross-lingual (e.g. Vietnamese claim vs English corpus), lexical overlap alone might miss translated synonyms,\n // so we include top lexical matches AND the first substantive paragraphs of the reference document.\n const fallbackExcerpts = corpusSentences.slice(0, 8).join('\\n');\n\n const claimContexts = claims.map((claim, idx) => {\n const tokens = extractSignificantTokens(claim);\n const topSentences = corpusSentences\n .map((sent) => ({\n sent,\n overlap: tokens.filter((t) => tokenMatchesCorpus(t, sent.toLowerCase())).length,\n }))\n .filter((item) => item.overlap > 0)\n .sort((a, b) => b.overlap - a.overlap)\n .slice(0, 5)\n .map((item) => item.sent);\n\n const candidates = topSentences.length > 0\n ? `${topSentences.join('\\n')}\\n\\n[General Reference Excerpts]:\\n${fallbackExcerpts}`\n : fallbackExcerpts || 'No substantive text found.';\n\n return {\n idx,\n claim,\n candidatePassages: candidates,\n };\n });\n\n const prompt = [\n `You are a Rigorous Scientific & Pedagogical Fact-Checking System (Natural Language Inference).`,\n `Evaluate whether each technical/pedagogical claim is strictly SUPPORTED, directly REFUTED, or has NOT_ENOUGH_EVIDENCE in the harvested technical reference text.`,\n `Pay careful attention to NEGATION words (\"không\", \"never\", \"tránh\", \"do not\"), causal relationships, hardware pin constraints, and edge cases. Do not assume truth without textual evidence.`,\n `\\nHarvested Reference Excerpts for Claims:\\n`,\n claimContexts.map((c) => `[Claim ${c.idx + 1}]: \"${c.claim}\"\\n[Passage Candidates]: ${c.candidatePassages}`).join('\\n\\n'),\n `\\nReturn ONLY a valid JSON array of objects with the exact structure:`,\n `[{\"claimIndex\": 1, \"verdict\": \"supported\"|\"refuted\"|\"not_enough_evidence\", \"confidenceScore\": 95, \"extractedQuote\": \"exact quote from passage\", \"explanation\": \"1-sentence semantic reason\"}]`,\n ].join('\\n');\n\n const raw = await options.llm(prompt, {\n system: 'You are an exacting academic fact-checker. Output strictly valid JSON array without commentary.',\n temperature: 0.1,\n jsonMode: true,\n });\n\n let parsed: any[] = [];\n const arrayMatch = raw.match(/\\[[\\s\\S]*\\]/);\n if (arrayMatch) {\n try {\n const res = JSON.parse(arrayMatch[0]);\n if (Array.isArray(res)) parsed = res;\n } catch {}\n }\n if (parsed.length === 0) {\n const objMatch = raw.match(/\\{[\\s\\S]*\\}/);\n if (objMatch) {\n try {\n const obj = JSON.parse(objMatch[0]);\n const candidateList = obj.claims || obj.results || obj.verifications || Object.values(obj).find(Array.isArray);\n if (Array.isArray(candidateList)) parsed = candidateList;\n } catch {}\n }\n }\n\n if (parsed.length > 0) {\n const verifiedList: VerifiedClaim[] = claims.map((claim, idx) => {\n const item = parsed.find((p: any) => p.claimIndex === idx + 1) || parsed[idx];\n const verdict: ClaimVerdict =\n item && ['supported', 'refuted', 'not_enough_evidence'].includes(item.verdict)\n ? item.verdict\n : detReport.claims[idx]?.isSupported\n ? 'supported'\n : 'not_enough_evidence';\n\n const isSupported = verdict === 'supported';\n return {\n claimText: claim,\n verdict,\n isSupported,\n isLlmVerified: true,\n confidenceScore: Number(item?.confidenceScore) || (isSupported ? 90 : 30),\n extractedQuote: item?.extractedQuote || detReport.claims[idx]?.extractedQuote,\n explanation: item?.explanation || (isSupported ? 'Semantically entailed by reference corpus.' : 'Not verified.'),\n };\n });\n\n const supportedCount = verifiedList.filter((c) => c.verdict === 'supported').length;\n const refutedCount = verifiedList.filter((c) => c.verdict === 'refuted').length;\n const unverifiedCount = claims.length - supportedCount;\n const supportPct = claims.length > 0 ? (supportedCount / claims.length) * 100 : 100;\n const hallucinationRisk = refutedCount > 0 ? 'high' : supportPct >= 75 ? 'low' : 'medium';\n\n const mdLines = [\n `# 🔍 Claim-Support Sweep & Semantic Verification Report (LLM NLI Evaluated)`,\n `> **Semantic Verification Rate:** \\`${supportPct.toFixed(1)}%\\` (${supportedCount}/${claims.length} claims supported) | **Refuted / Contradictions:** \\`${refutedCount}\\` | **Hallucination Risk:** \\`${hallucinationRisk.toUpperCase()}\\``,\n `\\n| Pedagogical / Technical Claim | Semantic Verdict | Confidence | Supporting Quote / Evidence | Explanation |`,\n `|---|---|---|---|---|`,\n ...verifiedList.map(\n (c) =>\n `| ${c.claimText.replace(/\\|/g, '/')} | ${\n c.verdict === 'supported'\n ? '✅ **SUPPORTED**'\n : c.verdict === 'refuted'\n ? '❌ **REFUTED**'\n : '⚠️ *NOT ENOUGH EVIDENCE*'\n } | \\`${c.confidenceScore}%\\` | ${(c.extractedQuote || '—').replace(/\\|/g, '/')} | ${(c.explanation || '').replace(/\\|/g, '/')} |`\n ),\n ];\n\n return {\n totalClaimsChecked: claims.length,\n supportedClaimsCount: supportedCount,\n refutedClaimsCount: refutedCount,\n unverifiedClaimsCount: unverifiedCount,\n hallucinationRisk,\n isLlmVerified: true,\n claims: verifiedList,\n reportMd: mdLines.join('\\n'),\n };\n }\n } catch (e: any) {\n console.warn('[ClaimVerifier] LLM semantic verification failed, falling back to deterministic lexical report:', e?.message || e);\n }\n\n return detReport;\n }\n}\n","export interface ProvenanceRecord {\n resourceId: string;\n sourceUrl: string;\n accessedAt: string;\n domain: string;\n relevanceScore: number;\n byteSize: number;\n}\n\nexport interface ProvenanceSidecar {\n topic: string;\n campaignId: string;\n generatedAt: string;\n totalRecords: number;\n records: ProvenanceRecord[];\n provenanceMd: string;\n}\n\n/**\n * Generates the mandatory *.provenance.md sidecar document (English Canonical)\n */\nexport class ProvenanceTracker {\n generateSidecar(topic: string, records: ProvenanceRecord[]): ProvenanceSidecar {\n const campaignId = `CAMP-${Math.random().toString(36).substring(2, 9).toUpperCase()}`;\n const generatedAt = new Date().toISOString();\n\n const mdLines = [\n `# 📜 Provenance & Audit Trail: ${topic}`,\n `> **Campaign ID:** \\`${campaignId}\\` | **Generated At:** \\`${generatedAt}\\` | **Total Verified Sources:** \\`${records.length}\\``,\n `\\n## Audit Trail Table`,\n `| Resource ID | Domain | Relevancy | Size (Bytes) | Source URL | Timestamp |`,\n `|---|---|---|---|---|---|`,\n ...records.map(r => `| **${r.resourceId}** | \\`${r.domain}\\` | ⭐ \\`${r.relevanceScore}/10\\` | \\`${r.byteSize}\\` | [Access Source](${r.sourceUrl}) | \\`${r.accessedAt.slice(0, 19)}\\` |`),\n `\\n## Integrity Guarantee`,\n `- Every pedagogical claim and technical snippet in the curriculum maps 1-to-1 to the physical sources listed above.`,\n `- Unverified citations or hallucinated sources are strictly prohibited under Curriculum OS Rule §5.`\n ];\n\n return {\n topic,\n campaignId,\n generatedAt,\n totalRecords: records.length,\n records,\n provenanceMd: mdLines.join('\\n'),\n };\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { S as ScrapedDocument, T as TechnicalDomain } from '../webScraper-D9Ldus9p.cjs';
2
- import { L as LlmTextFn, C as CourseResearchContext } from '../index-t8pahlJ4.cjs';
1
+ import { S as ScrapedDocument, T as TechnicalDomain } from '../webScraper-yO9P-oLb.cjs';
2
+ import { L as LlmTextFn, C as CourseResearchContext } from '../index-DlngvZBr.cjs';
3
3
  export { P as ProvenanceRecord, a as ProvenanceSidecar, b as ProvenanceTracker } from '../provenanceTracker-ct4s5lJV.cjs';
4
4
  import 'zod';
5
5
 
@@ -1,5 +1,5 @@
1
- import { S as ScrapedDocument, T as TechnicalDomain } from '../webScraper-BhiQ8s9x.js';
2
- import { L as LlmTextFn, C as CourseResearchContext } from '../index-t8pahlJ4.js';
1
+ import { S as ScrapedDocument, T as TechnicalDomain } from '../webScraper-DBFUIqoO.js';
2
+ import { L as LlmTextFn, C as CourseResearchContext } from '../index-DlngvZBr.js';
3
3
  export { P as ProvenanceRecord, a as ProvenanceSidecar, b as ProvenanceTracker } from '../provenanceTracker-ct4s5lJV.js';
4
4
  import 'zod';
5
5
 
@@ -1,5 +1,5 @@
1
1
  export { ClaimVerifier } from '../chunk-2XIEWCUE.js';
2
- export { EvidenceScorer, ProvenanceTracker, extractTopSentences } from '../chunk-GKF3NDEX.js';
3
- import '../chunk-KAFQVI2R.js';
2
+ export { EvidenceScorer, ProvenanceTracker, extractTopSentences } from '../chunk-QFYM2NV4.js';
3
+ import '../chunk-ON6VFCJO.js';
4
4
  //# sourceMappingURL=index.js.map
5
5
  //# sourceMappingURL=index.js.map
@@ -552,7 +552,7 @@ var WebScraper = class {
552
552
  }
553
553
  const res = await fetch(jinaUrl, {
554
554
  headers,
555
- signal: AbortSignal.timeout(15e3)
555
+ signal: AbortSignal.timeout(8e3)
556
556
  });
557
557
  if (res.ok) {
558
558
  const markdown = await res.text();
@@ -637,6 +637,214 @@ ${p.replace(/<[^>]+>/g, " ").trim()}
637
637
  }
638
638
  };
639
639
 
640
+ // src/harvester/noiseFilter.ts
641
+ var ECOMMERCE_DOMAINS = /* @__PURE__ */ new Set([
642
+ "shopee.vn",
643
+ "shopee.com",
644
+ "lazada.vn",
645
+ "lazada.com",
646
+ "tiki.vn",
647
+ "sendo.vn",
648
+ "aliexpress.com",
649
+ "taobao.com",
650
+ "amazon.com",
651
+ "ebay.com",
652
+ "banggood.com"
653
+ ]);
654
+ var ECOMMERCE_AND_COMMERCIAL_PATTERNS = [
655
+ /\b(shopee|lazada|tiki|sendo|taobao|aliexpress)\b/i,
656
+ /\b(mua ngay|giá tốt|khuyến mãi|freeship|bán chạy|nhập khẩu chính hãng|cửa hàng|bảng giá|đặt hàng)\b/i,
657
+ /\b(buy now|add to cart|free shipping|discount|best price|on sale|shop now|in stock|order now)\b/i,
658
+ /\b(\d+[kKđ]|₫|\$\d+|\d+\s*(?:VNĐ|VND|usd))\b/i
659
+ ];
660
+ function isCommercialOrNoise(input) {
661
+ if (input.url) {
662
+ try {
663
+ const hostname = new URL(input.url).hostname.toLowerCase().replace(/^www\./, "");
664
+ if (ECOMMERCE_DOMAINS.has(hostname) || [...ECOMMERCE_DOMAINS].some((d) => hostname.endsWith(`.${d}`))) {
665
+ return true;
666
+ }
667
+ } catch {
668
+ }
669
+ }
670
+ const combined = `${input.title || ""} ${input.snippet || ""}`;
671
+ if (!combined.trim()) return false;
672
+ for (const pattern of ECOMMERCE_AND_COMMERCIAL_PATTERNS) {
673
+ if (pattern.test(combined)) {
674
+ return true;
675
+ }
676
+ }
677
+ return false;
678
+ }
679
+ function evaluateTechnicalDensity(markdown) {
680
+ if (!markdown || markdown.trim().length < 80) {
681
+ return {
682
+ score: 1,
683
+ isSufficientQuality: false,
684
+ codeDensity: 0,
685
+ technicalTermDensity: 0,
686
+ hasStructure: false,
687
+ reasons: ["Content is too short or empty."]
688
+ };
689
+ }
690
+ const reasons = [];
691
+ const totalLength = markdown.length;
692
+ const codeBlocks = markdown.match(/```[\s\S]*?```/g) || [];
693
+ const inlineCode = markdown.match(/`[^`\n]+`/g) || [];
694
+ const totalCodeChars = codeBlocks.reduce((sum, b) => sum + b.length, 0) + inlineCode.reduce((sum, c) => sum + c.length, 0);
695
+ const codeDensity = Math.min(1, totalCodeChars / Math.max(1, totalLength));
696
+ const headings = markdown.match(/^#{1,4}\s+.+$/gm) || [];
697
+ const hasStructure = headings.length >= 2;
698
+ const techKeywords = markdown.match(
699
+ /\b(function|class|method|struct|interface|api|hardware|sensor|pin|circuit|logic|loop|state|algorithm|test|debug|schema|protocol|variable)\b/gi
700
+ ) || [];
701
+ const technicalTermDensity = Math.min(1, techKeywords.length * 10 / Math.max(100, markdown.split(/\s+/).length));
702
+ let score = 5;
703
+ if (codeDensity > 0.15) {
704
+ score += 2;
705
+ } else if (codeDensity > 0.05) {
706
+ score += 1;
707
+ } else {
708
+ reasons.push("Low code or API snippet density.");
709
+ }
710
+ if (hasStructure) {
711
+ score += 1.5;
712
+ } else {
713
+ reasons.push("Lacks clear hierarchical markdown headings.");
714
+ }
715
+ if (technicalTermDensity > 0.08) {
716
+ score += 1.5;
717
+ }
718
+ const finalScore = Math.min(10, Math.max(1, Math.round(score * 10) / 10));
719
+ return {
720
+ score: finalScore,
721
+ isSufficientQuality: finalScore >= 6,
722
+ codeDensity,
723
+ technicalTermDensity,
724
+ hasStructure,
725
+ reasons
726
+ };
727
+ }
728
+
729
+ // src/harvester/graphUtils.ts
730
+ function transitiveReduction(edges) {
731
+ const uniqueEdges = [];
732
+ const edgeSet = /* @__PURE__ */ new Set();
733
+ for (const e of edges) {
734
+ if (!e.source || !e.target || e.source === e.target) continue;
735
+ const key = `${e.source}-->${e.target}`;
736
+ if (!edgeSet.has(key)) {
737
+ edgeSet.add(key);
738
+ uniqueEdges.push(e);
739
+ }
740
+ }
741
+ const adj = /* @__PURE__ */ new Map();
742
+ for (const e of uniqueEdges) {
743
+ if (!adj.has(e.source)) adj.set(e.source, /* @__PURE__ */ new Set());
744
+ adj.get(e.source).add(e.target);
745
+ }
746
+ const reducedEdges = [];
747
+ const removedTransitiveEdges = [];
748
+ const hasAlternatePath = (start, target) => {
749
+ const directNeighbors = adj.get(start);
750
+ if (!directNeighbors) return false;
751
+ const queue = [];
752
+ const visited = /* @__PURE__ */ new Set([start]);
753
+ for (const nxt of directNeighbors) {
754
+ if (nxt !== target) {
755
+ queue.push(nxt);
756
+ visited.add(nxt);
757
+ }
758
+ }
759
+ while (queue.length > 0) {
760
+ const curr = queue.shift();
761
+ if (curr === target) return true;
762
+ const nextSet = adj.get(curr);
763
+ if (!nextSet) continue;
764
+ for (const nxt of nextSet) {
765
+ if (nxt === target) return true;
766
+ if (!visited.has(nxt)) {
767
+ visited.add(nxt);
768
+ queue.push(nxt);
769
+ }
770
+ }
771
+ }
772
+ return false;
773
+ };
774
+ for (const e of uniqueEdges) {
775
+ if (hasAlternatePath(e.source, e.target) && !hasAlternatePath(e.target, e.source)) {
776
+ removedTransitiveEdges.push(e);
777
+ } else {
778
+ reducedEdges.push(e);
779
+ }
780
+ }
781
+ return { reducedEdges, removedTransitiveEdges };
782
+ }
783
+ function kahnTopologicalSort(nodes, edges) {
784
+ const nodeSet = new Set(nodes);
785
+ const validEdges = edges.filter((e) => nodeSet.has(e.source) && nodeSet.has(e.target) && e.source !== e.target);
786
+ const inDegree = /* @__PURE__ */ new Map();
787
+ const adj = /* @__PURE__ */ new Map();
788
+ for (const n of nodes) {
789
+ inDegree.set(n, 0);
790
+ adj.set(n, /* @__PURE__ */ new Set());
791
+ }
792
+ for (const e of validEdges) {
793
+ adj.get(e.source).add(e.target);
794
+ inDegree.set(e.target, (inDegree.get(e.target) ?? 0) + 1);
795
+ }
796
+ const queue = [];
797
+ for (const [node, deg] of inDegree.entries()) {
798
+ if (deg === 0) queue.push(node);
799
+ }
800
+ const order = [];
801
+ const cyclesBroken = [];
802
+ const droppedEdges = [];
803
+ while (order.length < nodes.length) {
804
+ if (queue.length > 0) {
805
+ queue.sort((a, b) => a.localeCompare(b));
806
+ const curr = queue.shift();
807
+ order.push(curr);
808
+ const neighbors = adj.get(curr);
809
+ if (neighbors) {
810
+ for (const nxt of neighbors) {
811
+ const nextDeg = (inDegree.get(nxt) ?? 1) - 1;
812
+ inDegree.set(nxt, nextDeg);
813
+ if (nextDeg === 0) queue.push(nxt);
814
+ }
815
+ }
816
+ } else {
817
+ const remaining = nodes.filter((n) => !order.includes(n));
818
+ if (remaining.length === 0) break;
819
+ remaining.sort((a, b) => (inDegree.get(a) ?? 0) - (inDegree.get(b) ?? 0) || a.localeCompare(b));
820
+ const candidate = remaining[0];
821
+ let dropped = false;
822
+ for (const [src, targets] of adj.entries()) {
823
+ if (remaining.includes(src) && targets.has(candidate)) {
824
+ targets.delete(candidate);
825
+ droppedEdges.push({ source: src, target: candidate });
826
+ cyclesBroken.push(`${src} -> ${candidate}`);
827
+ inDegree.set(candidate, Math.max(0, (inDegree.get(candidate) ?? 1) - 1));
828
+ if (inDegree.get(candidate) === 0) {
829
+ queue.push(candidate);
830
+ }
831
+ dropped = true;
832
+ break;
833
+ }
834
+ }
835
+ if (!dropped) {
836
+ order.push(candidate);
837
+ }
838
+ }
839
+ }
840
+ return {
841
+ isDag: cyclesBroken.length === 0,
842
+ order,
843
+ cyclesBroken,
844
+ droppedEdges
845
+ };
846
+ }
847
+
640
848
  // src/harvester/termExtractor.ts
641
849
  var VIETNAMESE_STOPWORDS = /* @__PURE__ */ new Set([
642
850
  "l\xE0",
@@ -850,6 +1058,7 @@ var PedagogicalTermExtractor = class {
850
1058
  }
851
1059
  };
852
1060
  for (const { resourceId, doc } of docs) {
1061
+ if (isCommercialOrNoise({ url: doc.url, title: doc.title })) continue;
853
1062
  const md = doc.markdownContent || "";
854
1063
  const mdWithoutCode = md.replace(/```[\s\S]*?```/g, "\n");
855
1064
  const bilingualMatches = mdWithoutCode.matchAll(
@@ -953,7 +1162,7 @@ ${corpusPreview}`,
953
1162
  `
954
1163
  Return ONLY a valid JSON array of 6 to 12 atomic pedagogical concepts ordered from foundational to advanced.`,
955
1164
  `IMPORTANT FOR VIETNAMESE TERMS: Keep multi-syllable Vietnamese compound terms intact (e.g. "Bi\u1EBFn tr\u1EA1ng th\xE1i", "C\u1EA3m bi\u1EBFn \xE1nh s\xE1ng", "V\xF2ng l\u1EB7p s\u1EF1 ki\u1EC7n") and pair them with accurate English canonical terms.`,
956
- `Each item in the JSON array must have: {"id": "C_01", "term": "Display Name", "termVi": "Thu\u1EADt ng\u1EEF Ti\u1EBFng Vi\u1EC7t chu\u1EA9n", "termEn": "Canonical English Term", "category": "core_concept"|"api_syntax"|"hardware_component"|"pedagogical_pattern", "marrLayer": "ULO"|"CIO"|"SIO", "bloomLevel": "understand"|"apply"|"analyze", "salienceScore": 9.0, "definition": "1-sentence clear definition grounded in sources", "prerequisites": ["C_01"], "sourceIds": ["RES-01"]}`
1165
+ `Each item in the JSON array must have: {"id": "C_01", "term": "Display Name", "termVi": "Thu\u1EADt ng\u1EEF Ti\u1EBFng Vi\u1EC7t chu\u1EA9n", "termEn": "Canonical English Term", "category": "core_concept"|"api_syntax"|"hardware_component"|"pedagogical_pattern", "marrLayer": "ULO"|"CIO"|"SIO", "bloomLevel": "understand"|"apply"|"analyze", "salienceScore": 9.0, "definition": "1-sentence clear definition grounded in sources", "prerequisites": ["C_01"], "sourceIds": ["RES-01"], "facets": {"computationalPrinciple": "...", "mentalModel": "...", "syntaxAndTools": ["..."]}, "commonMisconceptions": ["..."]}`
957
1166
  ].filter(Boolean).join("\n");
958
1167
  const rawResponse = await options.llm(prompt, {
959
1168
  system: "You are a Principal Computer Science Curriculum Architect & Bilingual Terminology Specialist (Vietnamese-English). Output strictly valid JSON array without markdown commentary.",
@@ -965,9 +1174,26 @@ Return ONLY a valid JSON array of 6 to 12 atomic pedagogical concepts ordered fr
965
1174
  const parsed = JSON.parse(jsonMatch[0]);
966
1175
  if (Array.isArray(parsed) && parsed.length > 0) {
967
1176
  const validIds = new Set(parsed.map((item, idx) => String(item.id || `C_${String(idx + 1).padStart(2, "0")}`)));
1177
+ const rawEdges = [];
1178
+ for (const item of parsed) {
1179
+ const targetId = String(item.id || "");
1180
+ if (!validIds.has(targetId)) continue;
1181
+ for (const p of item.prerequisites || []) {
1182
+ const srcId = String(p);
1183
+ if (validIds.has(srcId) && srcId !== targetId) {
1184
+ rawEdges.push({ source: srcId, target: targetId });
1185
+ }
1186
+ }
1187
+ }
1188
+ const { reducedEdges } = transitiveReduction(rawEdges);
1189
+ const reducedPrereqMap = /* @__PURE__ */ new Map();
1190
+ for (const e of reducedEdges) {
1191
+ if (!reducedPrereqMap.has(e.target)) reducedPrereqMap.set(e.target, []);
1192
+ reducedPrereqMap.get(e.target).push(e.source);
1193
+ }
968
1194
  const concepts = parsed.map((item, idx) => {
969
1195
  const id = String(item.id || `C_${String(idx + 1).padStart(2, "0")}`);
970
- const prereqs = Array.isArray(item.prerequisites) ? item.prerequisites.map(String).filter((p) => p !== id && validIds.has(p)) : [];
1196
+ const prereqs = reducedPrereqMap.get(id) || [];
971
1197
  return {
972
1198
  id,
973
1199
  term: String(item.term || item.termVi || item.termEn || `Concept ${idx + 1}`),
@@ -979,12 +1205,22 @@ Return ONLY a valid JSON array of 6 to 12 atomic pedagogical concepts ordered fr
979
1205
  salienceScore: Number(item.salienceScore) || 8,
980
1206
  definition: String(item.definition || ""),
981
1207
  prerequisites: prereqs,
982
- sourceIds: Array.isArray(item.sourceIds) && item.sourceIds.length > 0 ? item.sourceIds.map(String) : ["RES-01"]
1208
+ sourceIds: Array.isArray(item.sourceIds) && item.sourceIds.length > 0 ? item.sourceIds.map(String) : ["RES-01"],
1209
+ facets: item.facets && typeof item.facets === "object" ? {
1210
+ computationalPrinciple: item.facets.computationalPrinciple ? String(item.facets.computationalPrinciple) : void 0,
1211
+ mentalModel: item.facets.mentalModel ? String(item.facets.mentalModel) : void 0,
1212
+ syntaxAndTools: Array.isArray(item.facets.syntaxAndTools) ? item.facets.syntaxAndTools.map(String) : void 0
1213
+ } : void 0,
1214
+ commonMisconceptions: Array.isArray(item.commonMisconceptions) ? item.commonMisconceptions.map(String) : void 0,
1215
+ troubleshootingHints: Array.isArray(item.troubleshootingHints) ? item.troubleshootingHints.map(String) : void 0
983
1216
  };
984
1217
  });
1218
+ const topoResult = kahnTopologicalSort(concepts.map((c) => c.id), reducedEdges);
1219
+ const conceptMap = new Map(concepts.map((c) => [c.id, c]));
1220
+ const sortedConcepts = topoResult.order.map((id) => conceptMap.get(id)).filter(Boolean);
985
1221
  return {
986
- concepts,
987
- conceptDagTsv: this.formatConceptDagTsv(concepts),
1222
+ concepts: sortedConcepts.length > 0 ? sortedConcepts : concepts,
1223
+ conceptDagTsv: this.formatConceptDagTsv(sortedConcepts.length > 0 ? sortedConcepts : concepts),
988
1224
  isLlmRefined: true,
989
1225
  unrefinedCandidatesCount: detBundle.unrefinedCandidatesCount
990
1226
  };
@@ -1127,17 +1363,23 @@ var HealthAuditor = class {
1127
1363
  };
1128
1364
 
1129
1365
  exports.CatalogBuilder = CatalogBuilder;
1366
+ exports.ECOMMERCE_AND_COMMERCIAL_PATTERNS = ECOMMERCE_AND_COMMERCIAL_PATTERNS;
1367
+ exports.ECOMMERCE_DOMAINS = ECOMMERCE_DOMAINS;
1130
1368
  exports.HealthAuditor = HealthAuditor;
1131
1369
  exports.MultiSourceSearchEngine = MultiSourceSearchEngine;
1132
1370
  exports.PedagogicalTermExtractor = PedagogicalTermExtractor;
1133
1371
  exports.WebScraper = WebScraper;
1134
1372
  exports.YouTubeIngestionService = YouTubeIngestionService;
1135
1373
  exports.classifyTechnicalDomain = classifyTechnicalDomain;
1374
+ exports.evaluateTechnicalDensity = evaluateTechnicalDensity;
1136
1375
  exports.extractSubstantiveExcerpts = extractSubstantiveExcerpts;
1137
1376
  exports.extractYouTubeVideoId = extractYouTubeVideoId;
1138
1377
  exports.formatTimestamp = formatTimestamp;
1139
1378
  exports.inferPrimaryCodeLanguage = inferPrimaryCodeLanguage;
1379
+ exports.isCommercialOrNoise = isCommercialOrNoise;
1140
1380
  exports.isYouTubeUrl = isYouTubeUrl;
1381
+ exports.kahnTopologicalSort = kahnTopologicalSort;
1141
1382
  exports.stitchCaptionSegments = stitchCaptionSegments;
1383
+ exports.transitiveReduction = transitiveReduction;
1142
1384
  //# sourceMappingURL=index.cjs.map
1143
1385
  //# sourceMappingURL=index.cjs.map