File size: 645 Bytes
eb1a39a
 
 
 
 
 
 
db9635c
eb1a39a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { readFile } from "fs/promises";
import { join } from "path";

export class DocumentationService {
  private cache: string | null = null;
  private readonly docsPath: string;

  constructor(filename: string = "llms.txt") {
    this.docsPath = join(process.cwd(), filename);
  }

  async load(): Promise<string | null> {
    if (this.cache !== null) {
      return this.cache;
    }

    try {
      this.cache = await readFile(this.docsPath, "utf-8");
      return this.cache;
    } catch {
      return null;
    }
  }

  clearCache(): void {
    this.cache = null;
  }
}

export const documentationService = new DocumentationService();