github token link in docs UI

This commit is contained in:
Dallin Romney 2025-01-16 00:04:44 -08:00
parent b6bbc5169f
commit 9d707188af
5 changed files with 61 additions and 17 deletions

View file

@ -89,6 +89,7 @@ class DocsContextProvider extends BaseContextProvider {
return [];
}
await docsService.isInitialized;
docsService.setGithubToken(this.options?.githubToken);
// Get chunks
let chunks = await docsService.retrieveChunksFromQuery(

View file

@ -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";
}

View file

@ -93,6 +93,7 @@ export default class DocsService {
private sqliteDb?: Database;
private ideInfoPromise: Promise<IdeInfo>;
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) {

View file

@ -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<PageData> {
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) {

View file

@ -176,9 +176,23 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) {
}[status?.status]}
</span>
<span className="lines lines-1 text-right text-xs text-stone-500">
{status?.description}
</span>
{status?.description === "Github rate limit exceeded" ? (
<span
className="lines lines-1 cursor-pointer text-right text-xs text-stone-500 underline"
onClick={() =>
ideMessenger.post(
"openUrl",
"https://docs.continue.dev/customize/deep-dives/docs#github",
)
}
>
{status.description}
</span>
) : (
<span className="lines lines-1 text-right text-xs text-stone-500">
{status?.description}
</span>
)}
</div>
</div>
);