diff --git a/core/context/providers/DocsContextProvider.ts b/core/context/providers/DocsContextProvider.ts index 00e193354..4c92a68ed 100644 --- a/core/context/providers/DocsContextProvider.ts +++ b/core/context/providers/DocsContextProvider.ts @@ -89,6 +89,7 @@ class DocsContextProvider extends BaseContextProvider { return []; } await docsService.isInitialized; + docsService.setGithubToken(this.options?.githubToken); // Get chunks let chunks = await docsService.retrieveChunksFromQuery( diff --git a/core/indexing/docs/DocsCrawler.ts b/core/indexing/docs/DocsCrawler.ts index 31c117620..35ea41247 100644 --- a/core/indexing/docs/DocsCrawler.ts +++ b/core/indexing/docs/DocsCrawler.ts @@ -25,6 +25,7 @@ class DocsCrawler { private readonly maxDepth: number = 4, private readonly maxRequestsPerCrawl: number = 1000, private readonly useLocalCrawling: boolean = false, + private readonly githubToken: string | undefined = undefined, ) { this.chromiumInstaller = new ChromiumInstaller(this.ide, this.config); } @@ -47,7 +48,7 @@ class DocsCrawler { undefined > { if (startUrl.host === this.GITHUB_HOST) { - yield* new GitHubCrawler(startUrl).crawl(); + yield* new GitHubCrawler(startUrl, this.githubToken).crawl(); return "github"; } diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 5fa93cc0a..1ad38b7a1 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -93,6 +93,7 @@ export default class DocsService { private sqliteDb?: Database; private ideInfoPromise: Promise; + private githubToken?: string; constructor( configHandler: ConfigHandler, @@ -103,6 +104,10 @@ export default class DocsService { this.isInitialized = this.init(configHandler); } + setGithubToken(token: string) { + this.githubToken = token; + } + // Singleton pattern: only one service globally private static instance?: DocsService; static createSingleton( @@ -437,6 +442,7 @@ export default class DocsService { maxDepth, undefined, useLocalCrawling, + this.githubToken, ); for await (const page of docsCrawler.crawl(new URL(startUrl))) { estimatedProgress += 1 / 2 ** (processedPages + 1); @@ -588,10 +594,19 @@ export default class DocsService { providers: ["docs"], }); } catch (e) { + let description = `Error getting docs from: ${siteIndexingConfig.startUrl}`; + if (e instanceof Error) { + if ( + e.message.includes("github.com") && + e.message.includes("rate limit") + ) { + description = "Github rate limit exceeded"; + } + } console.error("Error indexing docs", e); this.handleStatusUpdate({ ...fixedStatus, - description: `Error getting docs from: ${siteIndexingConfig.startUrl}`, + description, status: "failed", progress: 1, }); @@ -810,9 +825,7 @@ export default class DocsService { if ( // currentStatus?.status === "complete" && oldConfigDoc && - (oldConfigDoc.maxDepth !== doc.maxDepth || - oldConfigDoc.title !== doc.title || - oldConfigDoc.faviconUrl !== doc.faviconUrl) + !this.siteIndexingConfigsAreEqual(oldConfigDoc, doc) ) { changedDocs.push(doc); } else { @@ -982,16 +995,24 @@ export default class DocsService { ); } + private siteIndexingConfigsAreEqual( + config1: SiteIndexingConfig, + config2: SiteIndexingConfig, + ) { + return ( + config1.startUrl === config2.startUrl && + config1.faviconUrl === config2.faviconUrl && + config1.title === config2.title && + config1.maxDepth === config2.maxDepth && + config1.useLocalCrawling === config2.useLocalCrawling + ); + } + private addToConfig(siteIndexingConfig: SiteIndexingConfig) { // Handles the case where a user has manually added the doc to config.json // so it already exists in the file - const doesEquivalentDocExist = this.config.docs?.some( - (doc) => - doc.startUrl === siteIndexingConfig.startUrl && - doc.faviconUrl === siteIndexingConfig.faviconUrl && - siteIndexingConfig.title === doc.title && - siteIndexingConfig.maxDepth === doc.maxDepth && - siteIndexingConfig.useLocalCrawling === doc.useLocalCrawling, + const doesEquivalentDocExist = this.config.docs?.some((doc) => + this.siteIndexingConfigsAreEqual(doc, siteIndexingConfig), ); if (!doesEquivalentDocExist) { diff --git a/core/indexing/docs/crawlers/GitHubCrawler.ts b/core/indexing/docs/crawlers/GitHubCrawler.ts index ebad52fc3..521cbaa89 100644 --- a/core/indexing/docs/crawlers/GitHubCrawler.ts +++ b/core/indexing/docs/crawlers/GitHubCrawler.ts @@ -6,11 +6,17 @@ import { PageData } from "../DocsCrawler"; class GitHubCrawler { private readonly markdownRegex = new RegExp(/\.(md|mdx)$/); - private octokit = new Octokit({ auth: undefined }); + private octokit: Octokit; - constructor(private readonly startUrl: URL) {} + constructor( + private readonly startUrl: URL, + private readonly githubToken: string | undefined, + ) { + this.octokit = new Octokit({ auth: this.githubToken }); + } async *crawl(): AsyncGenerator { + console.log("CRAWLING", this.startUrl); console.debug( `[${ (this.constructor as any).name @@ -19,6 +25,7 @@ class GitHubCrawler { const urlStr = this.startUrl.toString(); const [_, owner, repo] = this.startUrl.pathname.split("/"); const branch = await this.getGithubRepoDefaultBranch(owner, repo); + const paths = await this.getGitHubRepoPaths(owner, repo, branch); for await (const path of paths) { diff --git a/gui/src/components/indexing/DocsIndexingStatus.tsx b/gui/src/components/indexing/DocsIndexingStatus.tsx index f595b42cf..df2bc11f2 100644 --- a/gui/src/components/indexing/DocsIndexingStatus.tsx +++ b/gui/src/components/indexing/DocsIndexingStatus.tsx @@ -176,9 +176,23 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) { }[status?.status]} - - {status?.description} - + {status?.description === "Github rate limit exceeded" ? ( + + ideMessenger.post( + "openUrl", + "https://docs.continue.dev/customize/deep-dives/docs#github", + ) + } + > + {status.description} + + ) : ( + + {status?.description} + + )} );