move config into globalcontext
This commit is contained in:
parent
fd7bbce79b
commit
d331b5c191
10 changed files with 32 additions and 47 deletions
|
|
@ -485,7 +485,6 @@ function finalToBrowserConfig(
|
|||
contextProviders: final.contextProviders?.map((c) => c.description),
|
||||
disableIndexing: final.disableIndexing,
|
||||
disableSessionTitles: final.disableSessionTitles,
|
||||
disableHeadlessCrawling: final.disableHeadlessCrawling,
|
||||
userToken: final.userToken,
|
||||
embeddingsProvider: final.embeddingsProvider?.id,
|
||||
ui: final.ui,
|
||||
|
|
|
|||
5
core/index.d.ts
vendored
5
core/index.d.ts
vendored
|
|
@ -933,7 +933,6 @@ export interface SerializedContinueConfig {
|
|||
contextProviders?: ContextProviderWithParams[];
|
||||
disableIndexing?: boolean;
|
||||
disableSessionTitles?: boolean;
|
||||
disableHeadlessCrawling?: boolean;
|
||||
userToken?: string;
|
||||
embeddingsProvider?: EmbeddingsProviderDescription;
|
||||
tabAutocompleteModel?: ModelDescription | ModelDescription[];
|
||||
|
|
@ -976,8 +975,6 @@ export interface Config {
|
|||
disableIndexing?: boolean;
|
||||
/** If set to true, Continue will not make extra requests to the LLM to generate a summary title of each session. */
|
||||
disableSessionTitles?: boolean;
|
||||
/** Disable headless crawling. This is useful if you're running into issues with Chromium or Playwright, or do not want to install Chromium. */
|
||||
disableHeadlessCrawling?: boolean;
|
||||
/** An optional token to identify a user. Not used by Continue unless you write custom coniguration that requires such a token */
|
||||
userToken?: string;
|
||||
/** The provider used to calculate embeddings. If left empty, Continue will use transformers.js to calculate the embeddings with all-MiniLM-L6-v2 */
|
||||
|
|
@ -1009,7 +1006,6 @@ export interface ContinueConfig {
|
|||
slashCommands?: SlashCommand[];
|
||||
contextProviders?: IContextProvider[];
|
||||
disableSessionTitles?: boolean;
|
||||
disableHeadlessCrawling?: boolean;
|
||||
disableIndexing?: boolean;
|
||||
userToken?: string;
|
||||
embeddingsProvider: EmbeddingsProvider;
|
||||
|
|
@ -1032,7 +1028,6 @@ export interface BrowserSerializedContinueConfig {
|
|||
contextProviders?: ContextProviderDescription[];
|
||||
disableIndexing?: boolean;
|
||||
disableSessionTitles?: boolean;
|
||||
disableHeadlessCrawling?: boolean;
|
||||
userToken?: string;
|
||||
embeddingsProvider?: string;
|
||||
ui?: ContinueUIConfig;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
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
|
||||
|
|
@ -20,7 +22,7 @@ describe.skip("crawl", () => {
|
|||
let crawlResults: PageData[];
|
||||
|
||||
beforeAll(async () => {
|
||||
const docsCrawler = new DocsCrawler(false);
|
||||
const docsCrawler = new DocsCrawler();
|
||||
|
||||
crawlResults = [];
|
||||
|
||||
|
|
@ -69,7 +71,7 @@ describe.skip("crawl", () => {
|
|||
let pageFound = false;
|
||||
|
||||
try {
|
||||
const docsCrawler = new DocsCrawler(false);
|
||||
const docsCrawler = new DocsCrawler();
|
||||
|
||||
for await (const page of docsCrawler.crawl(new URL(url), 1)) {
|
||||
if (page.url === url) {
|
||||
|
|
@ -113,7 +115,7 @@ describe.skip("crawl", () => {
|
|||
|
||||
for (const site of TEST_SITES) {
|
||||
const crawlResults: PageData[] = [];
|
||||
const docsCrawler = new DocsCrawler(false);
|
||||
const docsCrawler = new DocsCrawler();
|
||||
|
||||
for await (const page of docsCrawler.crawl(
|
||||
new URL(site),
|
||||
|
|
@ -134,6 +136,18 @@ describe.skip("crawl", () => {
|
|||
});
|
||||
|
||||
describe("Cheerio Crawler", () => {
|
||||
let mockVerifyOrInstallChromium: SpiedFunction<() => Promise<boolean>>;
|
||||
|
||||
beforeAll(() => {
|
||||
mockVerifyOrInstallChromium = jest
|
||||
.spyOn(ChromiumCrawler, "verifyOrInstallChromium")
|
||||
.mockResolvedValue(false);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mockVerifyOrInstallChromium.mockRestore();
|
||||
});
|
||||
|
||||
it(
|
||||
"succeeds in crawling a basic site",
|
||||
async () => {
|
||||
|
|
@ -141,7 +155,7 @@ describe.skip("crawl", () => {
|
|||
const site = "https://amplified.dev/";
|
||||
|
||||
const crawlResults: PageData[] = [];
|
||||
const docsCrawler = new DocsCrawler(false);
|
||||
const docsCrawler = new DocsCrawler();
|
||||
|
||||
for await (const page of docsCrawler.crawl(
|
||||
new URL(site),
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import {
|
|||
import PCR from "puppeteer-chromium-resolver";
|
||||
import * as cheerio from "cheerio";
|
||||
import fetch from "node-fetch";
|
||||
import { ContinueConfig } from "../..";
|
||||
import { GlobalContext } from "../../util/GlobalContext";
|
||||
|
||||
export type PageData = {
|
||||
url: string;
|
||||
|
|
@ -25,12 +25,8 @@ class DocsCrawler {
|
|||
private readonly GITHUB_HOST = "github.com";
|
||||
private useChromiumPromise: Promise<boolean> | undefined = undefined;
|
||||
|
||||
constructor(
|
||||
private readonly disableHeadlessCrawling: ContinueConfig["disableHeadlessCrawling"],
|
||||
) {
|
||||
if (!disableHeadlessCrawling) {
|
||||
this.useChromiumPromise = ChromiumCrawler.verifyOrInstallChromium();
|
||||
}
|
||||
constructor() {
|
||||
this.useChromiumPromise = ChromiumCrawler.verifyOrInstallChromium();
|
||||
}
|
||||
|
||||
async *crawl(
|
||||
|
|
@ -401,6 +397,13 @@ class ChromiumCrawler {
|
|||
}
|
||||
|
||||
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 (fs.existsSync(getChromiumPath())) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -411,13 +414,10 @@ class ChromiumCrawler {
|
|||
} catch (error) {
|
||||
console.debug("Error installing Chromium : ", error);
|
||||
console.debug(
|
||||
"Setting `disableHeadlessCrawling` to `true` in config.json",
|
||||
`Setting 'didPrevChromiumInstallFail' to 'true' in ${globalContext.constructor.name}`,
|
||||
);
|
||||
|
||||
editConfigJson((config) => ({
|
||||
...config,
|
||||
disableHeadlessCrawling: true,
|
||||
}));
|
||||
globalContext.update("didPrevChromiumInstallFail", true);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -383,7 +383,7 @@ export default class DocsService {
|
|||
|
||||
private async init(configHandler: ConfigHandler) {
|
||||
this.config = await configHandler.loadConfig();
|
||||
this.docsCrawler = new DocsCrawler(this.config.disableHeadlessCrawling);
|
||||
this.docsCrawler = new DocsCrawler();
|
||||
|
||||
const embeddingsProvider = await this.getEmbeddingsProvider();
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
6
docs/static/schemas/config.json
vendored
6
docs/static/schemas/config.json
vendored
|
|
@ -1881,12 +1881,6 @@
|
|||
"title": "config.json",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"disableHeadlessCrawling": {
|
||||
"title": "Disable Headless Crawling",
|
||||
"description": "Disable headless crawling. This is useful if you're running into issues with Chromium or Playwright, or do not want to install Chromium.",
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"docs": {
|
||||
"title": "Docs",
|
||||
"description": "A list of documentation sites to be indexed",
|
||||
|
|
|
|||
|
|
@ -1881,12 +1881,6 @@
|
|||
"title": "config.json",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"disableHeadlessCrawling": {
|
||||
"title": "Disable Headless Crawling",
|
||||
"description": "Disable headless crawling. This is useful if you're running into issues with Chromium or Playwright, or do not want to install Chromium.",
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"docs": {
|
||||
"title": "Docs",
|
||||
"description": "A list of documentation sites to be indexed",
|
||||
|
|
|
|||
|
|
@ -1881,12 +1881,6 @@
|
|||
"title": "config.json",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"disableHeadlessCrawling": {
|
||||
"title": "Disable Headless Crawling",
|
||||
"description": "Disable headless crawling. This is useful if you're running into issues with Chromium or Playwright, or do not want to install Chromium.",
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"docs": {
|
||||
"title": "Docs",
|
||||
"description": "A list of documentation sites to be indexed",
|
||||
|
|
|
|||
|
|
@ -2105,12 +2105,6 @@
|
|||
"title": "config.json",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"disableHeadlessCrawling": {
|
||||
"title": "Disable Headless Crawling",
|
||||
"description": "Disable headless crawling. This is useful if you're running into issues with Chromium or Playwright, or do not want to install Chromium.",
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"docs": {
|
||||
"title": "Docs",
|
||||
"description": "A list of documentation sites to be indexed",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue