diff --git a/core/config/load.ts b/core/config/load.ts index 2bb836d73..ed33eb0e7 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -356,7 +356,14 @@ async function intermediateToFinalConfig( // These context providers are always included, regardless of what, if anything, // the user has configured in config.json - const codebaseContextParams = ((config.contextProviders || []).filter(isContextProviderWithParams).find(cp => cp.name === "codebase") as ContextProviderWithParams | undefined)?.params || {}; + const codebaseContextParams = + ( + (config.contextProviders || []) + .filter(isContextProviderWithParams) + .find((cp) => cp.name === "codebase") as + | ContextProviderWithParams + | undefined + )?.params || {}; const DEFAULT_CONTEXT_PROVIDERS = [ new FileContextProvider({}), new CodebaseContextProvider(codebaseContextParams), diff --git a/core/core.ts b/core/core.ts index d813ee830..5de63b5b4 100644 --- a/core/core.ts +++ b/core/core.ts @@ -15,7 +15,6 @@ import { ContinueServerClient } from "./continueServer/stubs/client"; import { getAuthUrlForTokenPage } from "./control-plane/auth/index"; import { ControlPlaneClient } from "./control-plane/client"; import { CodebaseIndexer, PauseToken } from "./indexing/CodebaseIndexer"; -import DocsCrawler from "./indexing/docs/DocsCrawler"; import DocsService from "./indexing/docs/DocsService"; import Ollama from "./llm/llms/Ollama"; import type { FromCoreProtocol, ToCoreProtocol } from "./protocol"; @@ -169,12 +168,6 @@ export class Core { (..._) => Promise.resolve([]), ); - try { - DocsCrawler.verifyOrInstallChromium(); - } catch (err) { - console.debug(`Failed to install Chromium: ${err}`); - } - const on = this.messenger.on.bind(this.messenger); this.messenger.onError((err) => { diff --git a/core/indexing/docs/DocsCrawler.skip.ts b/core/indexing/docs/DocsCrawler.skip.ts deleted file mode 100644 index b3c4b2593..000000000 --- a/core/indexing/docs/DocsCrawler.skip.ts +++ /dev/null @@ -1,130 +0,0 @@ -import DocsCrawler, { type PageData } from "./DocsCrawler"; -import preIndexedDocs from "./preIndexedDocs"; - -// Temporary workaround until we have better caching of Chromium -// download between test runs -const TIMEOUT = 1_000_000; - -// Skipped until we have a better way to cache Chromium installs -// between tests and in CI -describe.skip("crawl", () => { - describe("GitHub repositories", () => { - const repoUrl = - "https://github.com/Patrick-Erichsen/test-github-repo-for-crawling"; - - let crawlResults: PageData[]; - - beforeAll(async () => { - const docsCrawler = new DocsCrawler(new URL(repoUrl)); - - crawlResults = []; - - for await (const page of docsCrawler.crawl()) { - crawlResults.push(page); - } - }, TIMEOUT); - - test("finds expected markdown files", async () => { - expect(crawlResults.some((page) => page.path.endsWith("README.md"))).toBe( - true, - ); - - expect( - crawlResults.some((page) => page.path.endsWith("docs-depth-1.md")), - ).toBe(true); - }); - - test("html includes the correct content", async () => { - const doc = crawlResults.find((page) => - page.path.endsWith("docs-depth-1.md"), - ); - - expect(doc?.content.includes("Test body")).toBe(true); - expect(doc?.content.includes("Test H2 Header")).toBe(true); - }); - - test("ignores non-markdown files, e.g. `test.js` at the root", async () => { - expect(crawlResults.some((page) => page.path.endsWith("test.js"))).toBe( - false, - ); - }); - }); - - describe.only("Non-Github repository sites", () => { - it( - "succeeds in crawling a list of common sites", - async () => { - const TEST_SITES = [ - "https://docs.nestjs.com/", - "https://docs.nestjs.com/", - "https://go.dev/doc/", - "https://clickhouse.com/docs", - "https://www.tensorflow.org/api_docs", - "https://www.rust-lang.org/learn", - "https://docs.anthropic.com/en/docs", - ]; - - const NUM_PAGES_TO_CRAWL = 10; - - for (const site of TEST_SITES) { - const crawlResults: PageData[] = []; - const docsCrawler = new DocsCrawler( - new URL(site), - NUM_PAGES_TO_CRAWL, - ); - - for await (const page of docsCrawler.crawl()) { - crawlResults.push(page); - } - - // `toBeGreaterThanOrEqual` because Crawlee doesn't guarantee - // an exact number of pages to crawl since it runs in parallel - expect(crawlResults.length).toBeGreaterThanOrEqual( - NUM_PAGES_TO_CRAWL, - ); - } - }, - TIMEOUT, - ); - }); - - describe("Pre-indexed Docs", () => { - const results: { [url: string]: boolean } = {}; - let totalTests = 0; - let passedTests = 0; - - Object.keys(preIndexedDocs).forEach((url) => { - test( - `Crawl test for ${url}`, - async () => { - totalTests++; - let pageFound = false; - - try { - const docsCrawler = new DocsCrawler(new URL(url), 1); - - for await (const page of docsCrawler.crawl()) { - if (page.url === url) { - pageFound = true; - break; - } - } - } catch (error) { - console.error(`Error crawling ${url}:`, error); - } - - results[url] = pageFound; - if (pageFound) { - passedTests++; - console.log(`✅ ${url}`); - } else { - console.log(`❌ ${url}`); - } - - expect(pageFound).toBe(true); - }, - TIMEOUT, - ); - }); - }); -}); diff --git a/core/indexing/docs/DocsCrawler.test.ts b/core/indexing/docs/DocsCrawler.test.ts new file mode 100644 index 000000000..42083634f --- /dev/null +++ b/core/indexing/docs/DocsCrawler.test.ts @@ -0,0 +1,172 @@ +import { SpiedFunction } from "jest-mock"; +import DocsCrawler, { ChromiumCrawler, type PageData } from "./DocsCrawler"; +import preIndexedDocs from "./preIndexedDocs"; +import { jest } from "@jest/globals"; + +// Temporary workaround until we have better caching of Chromium +// download between test runs +const TIMEOUT_MS = 1_000_000_000; + +// Skipped until we have a better way to cache Chromium installs +// between tests and in CI +describe.skip("crawl", () => { + beforeAll(async () => { + // Make sure we have Chromium pulled down before beginning tests + await ChromiumCrawler.verifyOrInstallChromium(); + }, TIMEOUT_MS); + + describe("GitHub Crawler", () => { + const repoUrl = + "https://github.com/Patrick-Erichsen/test-github-repo-for-crawling"; + + let crawlResults: PageData[]; + + beforeAll(async () => { + const docsCrawler = new DocsCrawler(); + + crawlResults = []; + + for await (const page of docsCrawler.crawl(new URL(repoUrl))) { + crawlResults.push(page); + } + }, TIMEOUT_MS); + + test("finds expected markdown files", async () => { + expect(crawlResults.some((page) => page.path.endsWith("README.md"))).toBe( + true, + ); + + expect( + crawlResults.some((page) => page.path.endsWith("docs-depth-1.md")), + ).toBe(true); + }); + + test("html includes the correct content", async () => { + const doc = crawlResults.find((page) => + page.path.endsWith("docs-depth-1.md"), + ); + + expect(doc?.content.includes("Test body")).toBe(true); + expect(doc?.content.includes("Test H2 Header")).toBe(true); + }); + + test("ignores non-markdown files, e.g. `test.js` at the root", async () => { + expect(crawlResults.some((page) => page.path.endsWith("test.js"))).toBe( + false, + ); + }); + }); + + describe("Chromium Crawler", () => { + it("Pre-indexed Docs", () => { + const results: { [url: string]: boolean } = {}; + let totalTests = 0; + let passedTests = 0; + + Object.keys(preIndexedDocs).forEach((url) => { + it( + `Crawl test for ${url}`, + async () => { + totalTests++; + let pageFound = false; + + try { + const docsCrawler = new DocsCrawler(); + + for await (const page of docsCrawler.crawl(new URL(url), 1)) { + if (page.url === url) { + pageFound = true; + break; + } + } + } catch (error) { + console.error(`Error crawling ${url}:`, error); + } + + results[url] = pageFound; + if (pageFound) { + passedTests++; + console.log(`✅ ${url}`); + } else { + console.log(`❌ ${url}`); + } + + expect(pageFound).toBe(true); + }, + TIMEOUT_MS, + ); + }); + }); + + it( + "succeeds in crawling a list of common sites", + async () => { + const TEST_SITES = [ + "https://docs.nestjs.com/", + "https://docs.nestjs.com/", + "https://go.dev/doc/", + "https://clickhouse.com/docs", + "https://www.tensorflow.org/api_docs", + "https://www.rust-lang.org/learn", + "https://docs.anthropic.com/en/docs", + ]; + + const NUM_PAGES_TO_CRAWL = 10; + + for (const site of TEST_SITES) { + const crawlResults: PageData[] = []; + const docsCrawler = new DocsCrawler(); + + for await (const page of docsCrawler.crawl( + new URL(site), + NUM_PAGES_TO_CRAWL, + )) { + crawlResults.push(page); + } + + // `toBeGreaterThanOrEqual` because Crawlee doesn't guarantee + // an exact number of pages to crawl since it runs in parallel + expect(crawlResults.length).toBeGreaterThanOrEqual( + NUM_PAGES_TO_CRAWL, + ); + } + }, + TIMEOUT_MS, + ); + }); + + describe("Cheerio Crawler", () => { + let mockVerifyOrInstallChromium: SpiedFunction<() => Promise>; + + beforeAll(() => { + mockVerifyOrInstallChromium = jest + .spyOn(ChromiumCrawler, "verifyOrInstallChromium") + .mockResolvedValue(false); + }); + + afterAll(() => { + mockVerifyOrInstallChromium.mockRestore(); + }); + + it( + "succeeds in crawling a basic site", + async () => { + const NUM_PAGES_TO_CRAWL = 1; + const site = "https://amplified.dev/"; + + const crawlResults: PageData[] = []; + const docsCrawler = new DocsCrawler(); + + for await (const page of docsCrawler.crawl( + new URL(site), + NUM_PAGES_TO_CRAWL, + )) { + crawlResults.push(page); + } + + expect(crawlResults.length).toBeGreaterThanOrEqual(NUM_PAGES_TO_CRAWL); + }, + TIMEOUT_MS, + ); + }); +}); diff --git a/core/indexing/docs/DocsCrawler.ts b/core/indexing/docs/DocsCrawler.ts index afd3ea440..05364f028 100644 --- a/core/indexing/docs/DocsCrawler.ts +++ b/core/indexing/docs/DocsCrawler.ts @@ -2,10 +2,17 @@ import { Octokit } from "@octokit/rest"; import * as fs from "fs"; import { URL } from "node:url"; import { Page } from "puppeteer"; -import { getChromiumPath, getContinueUtilsPath } from "../../util/paths"; +import { + getChromiumPath, + getContinueUtilsPath, + editConfigJson, +} from "../../util/paths"; // @ts-ignore // @prettier-ignore import PCR from "puppeteer-chromium-resolver"; +import * as cheerio from "cheerio"; +import fetch from "node-fetch"; +import { GlobalContext } from "../../util/GlobalContext"; export type PageData = { url: string; @@ -13,35 +20,51 @@ export type PageData = { content: string; }; -export default class DocsCrawler { - LINK_GROUP_SIZE = 2; // Controls parallelization of crawler - GITHUB_HOST = "github.com"; - static MAX_REQUESTS_PER_CRAWL = 1000; - markdownRegex = new RegExp(/\.(md|mdx)$/); - octokit = new Octokit({ - auth: undefined, - }); +class DocsCrawler { + private readonly MAX_REQUESTS_PER_CRAWL = 1000; + private readonly GITHUB_HOST = "github.com"; + private useChromiumPromise: Promise | undefined = undefined; - static PCR_CONFIG = { - downloadPath: getContinueUtilsPath(), - }; - - constructor( - private readonly startUrl: URL, - private readonly maxRequestsPerCrawl: number = DocsCrawler.MAX_REQUESTS_PER_CRAWL, - ) {} - - static verifyOrInstallChromium() { - if (!fs.existsSync(getChromiumPath())) { - PCR(DocsCrawler.PCR_CONFIG); - } + constructor() { + this.useChromiumPromise = ChromiumCrawler.verifyOrInstallChromium(); } - async *crawl(): AsyncGenerator { - if (this.startUrl.host === this.GITHUB_HOST) { - yield* this.crawlGithubRepo(); + async *crawl( + startUrl: URL, + maxRequestsPerCrawl: number = this.MAX_REQUESTS_PER_CRAWL, + ): AsyncGenerator { + if (startUrl.host === this.GITHUB_HOST) { + yield* new GitHubCrawler(startUrl).crawl(); } else { - yield* this.crawlSite(); + if (await this.useChromiumPromise) { + yield* new ChromiumCrawler(startUrl, maxRequestsPerCrawl).crawl(); + } else { + yield* new CheerioCrawler(startUrl, maxRequestsPerCrawl).crawl(); + } + } + } +} + +class GitHubCrawler { + private readonly markdownRegex = new RegExp(/\.(md|mdx)$/); + private octokit = new Octokit({ auth: undefined }); + + constructor(private readonly startUrl: URL) {} + + async *crawl(): AsyncGenerator { + console.debug( + `[${ + (this.constructor as any).name + }] Crawling GitHub repo: ${this.startUrl.toString()}`, + ); + 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) { + const content = await this.getGithubRepoFileContent(path, owner, repo); + yield { path, url: urlStr, content: content ?? "" }; } } @@ -49,11 +72,7 @@ export default class DocsCrawler { owner: string, repo: string, ): Promise { - const repoInfo = await this.octokit.repos.get({ - owner, - repo, - }); - + const repoInfo = await this.octokit.repos.get({ owner, repo }); return repoInfo.data.default_branch; } @@ -68,21 +87,17 @@ export default class DocsCrawler { owner, repo, tree_sha: branch, - headers: { - "X-GitHub-Api-Version": "2022-11-28", - }, + headers: { "X-GitHub-Api-Version": "2022-11-28" }, recursive: "true", }, ); - const paths = tree.data.tree + return tree.data.tree .filter( (file: any) => file.type === "blob" && this.markdownRegex.test(file.path ?? ""), ) .map((file: any) => file.path); - - return paths; } private async getGithubRepoFileContent( @@ -95,34 +110,237 @@ export default class DocsCrawler { owner, repo, path, - headers: { - Accept: "application/vnd.github.raw+json", - }, + headers: { Accept: "application/vnd.github.raw+json" }, }); - return response.data as unknown as string; } catch (error) { console.debug("Error fetching file contents:", error); return null; } } +} - private async *crawlGithubRepo() { - console.debug(`Crawling GitHub repo: ${this.startUrl.toString()}`); +class CheerioCrawler { + private readonly IGNORE_PATHS_ENDING_IN = [ + "favicon.ico", + "robots.txt", + ".rst.txt", + "genindex", + "py-modindex", + "search.html", + "search", + "genindex.html", + "changelog", + "changelog.html", + ]; - 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); + constructor( + private readonly startUrl: URL, + private readonly maxRequestsPerCrawl: number, + ) {} - for await (const path of paths) { - const content = await this.getGithubRepoFileContent(path, owner, repo); + async *crawl(): AsyncGenerator { + yield* this.crawlPage(this.startUrl); + } - yield { - path, - url: urlStr, - content: content ?? "", - }; + private async *crawlPage( + url: URL, + maxDepth: number = 3, + ): AsyncGenerator { + console.log( + `[${ + (this.constructor as any).name + }] Starting crawl from: ${url} - Max Depth: ${maxDepth}`, + ); + const { baseUrl, basePath } = this.splitUrl(url); + let paths: { path: string; depth: number }[] = [ + { path: basePath, depth: 0 }, + ]; + + let index = 0; + while (index < paths.length) { + const batch = paths.slice(index, index + 50); + + try { + const promises = batch.map(({ path, depth }) => + this.getLinksFromUrl(baseUrl, path).then((links) => ({ + links, + path, + depth, + })), + ); + + const results = await Promise.all(promises); + for (const { + links: { html, links: linksArray }, + path, + depth, + } of results) { + if (html !== "" && depth <= maxDepth) { + yield { url: url.toString(), path, content: html }; + } + + if (depth < maxDepth) { + for (let link of linksArray) { + if (!paths.some((p) => p.path === link)) { + paths.push({ path: link, depth: depth + 1 }); + } + } + } + } + } catch (e) { + if (e instanceof TypeError) { + console.warn("Error while crawling page: ", e); + } else { + console.error("Error while crawling page: ", e); + } + } + + index += batch.length; + } + console.log("Crawl completed"); + } + + private async getLinksFromUrl(url: string, path: string) { + const baseUrl = new URL(url); + const location = new URL(path, url); + let response; + + try { + response = await fetch(location.toString()); + } catch (error: unknown) { + if ( + error instanceof Error && + error.message.includes("maximum redirect") + ) { + console.error( + `[${ + (this.constructor as any).name + }] Maximum redirect reached for: ${location.toString()}`, + ); + return { html: "", links: [] }; + } + console.error(error); + return { html: "", links: [] }; + } + + const html = await response.text(); + let links: string[] = []; + + if (url.includes("github.com")) { + return { html, links }; + } + + const $ = cheerio.load(html); + + $("a").each((_: any, element: any) => { + const href = $(element).attr("href"); + if (!href) return; + + const parsedUrl = new URL(href, url); + if (parsedUrl.hostname === baseUrl.hostname) { + links.push(parsedUrl.pathname); + } + }); + + links = [...new Set(links)].filter((link) => { + return ( + !link.includes("#") && + !this.IGNORE_PATHS_ENDING_IN.some((ending) => link.endsWith(ending)) + ); + }); + + return { html, links }; + } + + private splitUrl(url: URL) { + const baseUrl = `${url.protocol}//${url.hostname}${ + url.port ? ":" + url.port : "" + }`; + const basePath = url.pathname; + return { baseUrl, basePath }; + } +} + +class ChromiumCrawler { + private readonly LINK_GROUP_SIZE = 2; + private static PCR_CONFIG = { downloadPath: getContinueUtilsPath() }; + + constructor( + private readonly startUrl: URL, + private readonly maxRequestsPerCrawl: number, + ) {} + + async *crawl(): AsyncGenerator { + console.debug( + `[${(this.constructor as any).name}] Crawling site repo: ${ + this.startUrl + }`, + ); + const stats = await PCR(ChromiumCrawler.PCR_CONFIG); + const browser = await stats.puppeteer.launch({ + args: [ + "--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36", + ], + executablePath: stats.executablePath, + }); + const page = await browser.newPage(); + + try { + yield* this.crawlSitePages(page, this.startUrl); + } catch (e) { + console.debug("Error getting links: ", e); + } finally { + await browser.close(); + } + } + + private async *crawlSitePages( + page: Page, + curUrl: URL, + visitedLinks: Set = new Set(), + curRequestCount: number = 0, + ): AsyncGenerator { + if (curRequestCount >= this.maxRequestsPerCrawl) { + console.warn( + `[${ + (this.constructor as any).name + }] Max requests per crawl reached. Stopping crawler.`, + ); + return; + } + + if (visitedLinks.has(curUrl.toString())) { + return; + } + + console.debug( + `[${(this.constructor as any).name}] Crawling page: ${curUrl.toString()}`, + ); + + await page.goto(curUrl.toString()); + + const htmlContent = await page.content(); + const linkGroups = await this.getLinkGroupsFromPage(page, curUrl); + const requestCount = curRequestCount + 1; + + visitedLinks.add(curUrl.toString()); + + yield { + path: curUrl.pathname, + url: curUrl.toString(), + content: htmlContent, + }; + + for (const linkGroup of linkGroups) { + for (const link of linkGroup) { + yield* this.crawlSitePages( + page, + new URL(link), + visitedLinks, + requestCount, + ); + } } } @@ -145,8 +363,6 @@ export default class DocsCrawler { private async getLinksFromPage(page: Page, curUrl: URL) { const links = await page.$$eval("a", (links) => links.map((a) => a.href)); - // This additional step is due to issues getting the URL module to work - // in an $$eval command const cleanedLinks = links .map(this.stripHashFromUrl) .filter( @@ -180,69 +396,33 @@ export default class DocsCrawler { return groups; } - private async *crawlSitePages( - page: Page, - curUrl: URL, - visitedLinks: Set = new Set(), - curRequestCount: number = 0, - ): AsyncGenerator { - if (curRequestCount >= this.maxRequestsPerCrawl) { - console.warn("Max requests per crawl reached. Stopping crawler."); - return; + static async verifyOrInstallChromium() { + const globalContext = new GlobalContext(); + + // If we previously failed to install Chromium, don't try again + if (globalContext.get("didPrevChromiumInstallFail")) { + return false; } - if (visitedLinks.has(curUrl.toString())) { - return; + if (fs.existsSync(getChromiumPath())) { + return true; } - console.debug(`Crawling page: ${curUrl.toString()}`); - - await page.goto(curUrl.toString()); - - const htmlContent = await page.content(); - const linkGroups = await this.getLinkGroupsFromPage(page, curUrl); - const requestCount = curRequestCount + 1; - - visitedLinks.add(curUrl.toString()); - - yield { - path: curUrl.pathname, - url: curUrl.toString(), - content: htmlContent, - }; - - for (const linkGroup of linkGroups) { - for (const link of linkGroup) { - yield* this.crawlSitePages( - page, - new URL(link), - visitedLinks, - requestCount, - ); - } - } - } - - private async *crawlSite(): AsyncGenerator { - console.debug(`Crawling site repo: ${this.startUrl}`); - - const stats = await PCR(DocsCrawler.PCR_CONFIG); - - const browser = await stats.puppeteer.launch({ - args: [ - "--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36", - ], - executablePath: stats.executablePath, - }); - - const page = await browser.newPage(); - try { - yield* this.crawlSitePages(page, this.startUrl); - } catch (e) { - console.debug("Error getting links: ", e); - } finally { - await browser.close(); + await PCR(ChromiumCrawler.PCR_CONFIG); + return true; + } catch (error) { + console.debug("Error installing Chromium : ", error); + console.debug( + `Setting 'didPrevChromiumInstallFail' to 'true' in ${globalContext.constructor.name}`, + ); + + globalContext.update("didPrevChromiumInstallFail", true); + + return false; } } } + +export default DocsCrawler; +export { CheerioCrawler, ChromiumCrawler, GitHubCrawler }; diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 9b5c593e8..8859806ab 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -75,16 +75,14 @@ export default class DocsService { private config!: ContinueConfig; private sqliteDb?: Database; - // If we are instantiating a new DocsService from `getContextItems()`, - // we have access to the direct config object. - // When instantiating the DocsService from core, we have access - // to a ConfigHandler instance. + private docsCrawler!: DocsCrawler; + constructor( - configOrHandler: ConfigHandler, + configHandler: ConfigHandler, private readonly ide: IDE, private readonly messenger?: IMessenger, ) { - this.isInitialized = this.init(configOrHandler); + this.isInitialized = this.init(configHandler); } static getSingleton() { @@ -92,11 +90,11 @@ export default class DocsService { } static createSingleton( - configOrHandler: ConfigHandler, + configHandler: ConfigHandler, ide: IDE, messenger?: IMessenger, ) { - const docsService = new DocsService(configOrHandler, ide, messenger); + const docsService = new DocsService(configHandler, ide, messenger); DocsService.instance = docsService; return docsService; } @@ -202,10 +200,8 @@ export default class DocsService { let processedPages = 0; let maxKnownPages = 1; - const docsCrawler = new DocsCrawler(new URL(startUrl)); - // Crawl pages and retrieve info as articles - for await (const page of docsCrawler.crawl()) { + for await (const page of this.docsCrawler.crawl(new URL(startUrl))) { processedPages++; const article = pageToArticle(page); @@ -385,19 +381,9 @@ export default class DocsService { return favicon; } - /** - * A ConfigHandler is passed to the DocsService in `core` when - * we don't yet have access to the config object. This handler - * is used to set up a single instance of the DocsService that - * subscribes to config updates, e.g. to trigger re-indexing - * on a new embeddings provider. - */ private async init(configHandler: ConfigHandler) { - if (configHandler instanceof ConfigHandler) { - this.config = await configHandler.loadConfig(); - } else { - this.config = configHandler; - } + this.config = await configHandler.loadConfig(); + this.docsCrawler = new DocsCrawler(); const embeddingsProvider = await this.getEmbeddingsProvider(); diff --git a/core/package-lock.json b/core/package-lock.json index 6c03c4862..a3332dc01 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -22,6 +22,7 @@ "adf-to-md": "^1.1.0", "async-mutex": "^0.5.0", "axios": "^1.6.7", + "cheerio": "^1.0.0-rc.12", "commander": "^12.0.0", "comment-json": "^4.2.3", "dbinfoz": "^0.1.4", @@ -6256,6 +6257,46 @@ "node": ">=10" } }, + "node_modules/cheerio": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0.tgz", + "integrity": "sha512-quS9HgjQpdaXOvsZz82Oz7uxtXiy6UIsIQcpBj7HRw2M63Skasm9qlDocAM7jNuaxdhpPU7c4kJN+gA5MCu4ww==", + "dependencies": { + "cheerio-select": "^2.1.0", + "dom-serializer": "^2.0.0", + "domhandler": "^5.0.3", + "domutils": "^3.1.0", + "encoding-sniffer": "^0.2.0", + "htmlparser2": "^9.1.0", + "parse5": "^7.1.2", + "parse5-htmlparser2-tree-adapter": "^7.0.0", + "parse5-parser-stream": "^7.1.2", + "undici": "^6.19.5", + "whatwg-mimetype": "^4.0.0" + }, + "engines": { + "node": ">=18.17" + }, + "funding": { + "url": "https://github.com/cheeriojs/cheerio?sponsor=1" + } + }, + "node_modules/cheerio-select": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cheerio-select/-/cheerio-select-2.1.0.tgz", + "integrity": "sha512-9v9kG0LvzrlcungtnJtpGNxY+fzECQKhK4EGJX2vByejiMX84MFNQw4UxPJl3bFbTMw+Dfs37XaIkCwTZfLh4g==", + "dependencies": { + "boolbase": "^1.0.0", + "css-select": "^5.1.0", + "css-what": "^6.1.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.3", + "domutils": "^3.0.1" + }, + "funding": { + "url": "https://github.com/sponsors/fb55" + } + }, "node_modules/chownr": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", @@ -7038,6 +7079,18 @@ "iconv-lite": "^0.6.2" } }, + "node_modules/encoding-sniffer": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/encoding-sniffer/-/encoding-sniffer-0.2.0.tgz", + "integrity": "sha512-ju7Wq1kg04I3HtiYIOrUrdfdDvkyO9s5XM8QAj/bN61Yo/Vb4vgJxy5vi4Yxk01gWHbrofpPtpxM8bKger9jhg==", + "dependencies": { + "iconv-lite": "^0.6.3", + "whatwg-encoding": "^3.1.1" + }, + "funding": { + "url": "https://github.com/fb55/encoding-sniffer?sponsor=1" + } + }, "node_modules/end-of-stream": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", @@ -8612,6 +8665,24 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, + "node_modules/htmlparser2": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-9.1.0.tgz", + "integrity": "sha512-5zfg6mHUoaer/97TxnGpxmbR7zJtPwIYFMZ/H5ucTlPZhKvtum05yiPK3Mgai3a0DyVxv7qYqoweaEd2nrYQzQ==", + "funding": [ + "https://github.com/fb55/htmlparser2?sponsor=1", + { + "type": "github", + "url": "https://github.com/sponsors/fb55" + } + ], + "dependencies": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.3", + "domutils": "^3.1.0", + "entities": "^4.5.0" + } + }, "node_modules/http-cache-semantics": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", @@ -11507,6 +11578,29 @@ "url": "https://github.com/inikulin/parse5?sponsor=1" } }, + "node_modules/parse5-htmlparser2-tree-adapter": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-7.0.0.tgz", + "integrity": "sha512-B77tOZrqqfUfnVcOrUvfdLbz4pu4RopLD/4vmu3HUPswwTA8OH0EMW9BlWR2B0RCoiZRAHEUu7IxeP1Pd1UU+g==", + "dependencies": { + "domhandler": "^5.0.2", + "parse5": "^7.0.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, + "node_modules/parse5-parser-stream": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/parse5-parser-stream/-/parse5-parser-stream-7.1.2.tgz", + "integrity": "sha512-JyeQc9iwFLn5TbvvqACIF/VXG6abODeB3Fwmv/TGdLk2LfbWkaySGY72at4+Ty7EkPZj854u4CrICqNk2qIbow==", + "dependencies": { + "parse5": "^7.0.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -13749,9 +13843,9 @@ } }, "node_modules/undici": { - "version": "6.18.2", - "resolved": "https://registry.npmjs.org/undici/-/undici-6.18.2.tgz", - "integrity": "sha512-o/MQLTwRm9IVhOqhZ0NQ9oXax1ygPjw6Vs+Vq/4QRjbOAC3B1GCHy7TYxxbExKlb7bzDRzt9vBWU6BDz0RFfYg==", + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.8.tgz", + "integrity": "sha512-U8uCCl2x9TK3WANvmBavymRzxbfFYG+tAu+fgx3zxQy3qdagQqBLwJVrdyO1TBfUXvfKveMKJZhpvUYoOjM+4g==", "engines": { "node": ">=18.17" } diff --git a/core/package.json b/core/package.json index 4b20b5b2c..f261f7078 100644 --- a/core/package.json +++ b/core/package.json @@ -51,6 +51,7 @@ "adf-to-md": "^1.1.0", "async-mutex": "^0.5.0", "axios": "^1.6.7", + "cheerio": "^1.0.0-rc.12", "commander": "^12.0.0", "comment-json": "^4.2.3", "dbinfoz": "^0.1.4", diff --git a/core/util/GlobalContext.ts b/core/util/GlobalContext.ts index 3880b4609..a66d8d6cf 100644 --- a/core/util/GlobalContext.ts +++ b/core/util/GlobalContext.ts @@ -5,6 +5,7 @@ import { EmbeddingsProvider } from "../index.js"; export type GlobalContextType = { indexingPaused: boolean; selectedTabAutocompleteModel: string; + didPrevChromiumInstallFail: boolean; lastSelectedProfileForWorkspace: { [workspaceIdentifier: string]: string }; /** * This is needed to handle the case where a JetBrains user has created diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 620c371af..dacb3d8d6 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -108,6 +108,7 @@ "adf-to-md": "^1.1.0", "async-mutex": "^0.5.0", "axios": "^1.6.7", + "cheerio": "^1.0.0-rc.12", "commander": "^12.0.0", "comment-json": "^4.2.3", "dbinfoz": "^0.1.4", diff --git a/gui/package-lock.json b/gui/package-lock.json index 774db75f8..589d7578f 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -101,6 +101,7 @@ "adf-to-md": "^1.1.0", "async-mutex": "^0.5.0", "axios": "^1.6.7", + "cheerio": "^1.0.0-rc.12", "commander": "^12.0.0", "comment-json": "^4.2.3", "dbinfoz": "^0.1.4", diff --git a/gui/tailwind.config.cjs b/gui/tailwind.config.cjs index 6dcf5d87b..269b57ef1 100644 --- a/gui/tailwind.config.cjs +++ b/gui/tailwind.config.cjs @@ -1,5 +1,4 @@ /** @type {import('tailwindcss').Config} */ -const colors = require("tailwindcss/colors"); module.exports = { content: [ @@ -10,7 +9,6 @@ module.exports = { theme: { extend: {}, colors: { - ...colors, // This spreads all default Tailwind colors "vsc-background": "rgb(var(--vsc-background) / )", "secondary-dark": "rgb(var(--secondary-dark) / )", },