🚧
This commit is contained in:
parent
dbab612c81
commit
95c0a59ce7
13 changed files with 293 additions and 306 deletions
|
|
@ -1,4 +1,6 @@
|
|||
import * as fs from "fs";
|
||||
import {
|
||||
BaseCompletionOptions,
|
||||
Config,
|
||||
ContextProviderWithParams,
|
||||
ContinueConfig,
|
||||
|
|
@ -9,7 +11,9 @@ import {
|
|||
ModelDescription,
|
||||
SerializedContinueConfig,
|
||||
SlashCommand,
|
||||
SlashCommandDescription,
|
||||
} from "..";
|
||||
|
||||
import {
|
||||
slashCommandFromDescription,
|
||||
slashFromCustomCommand,
|
||||
|
|
@ -22,6 +26,99 @@ import TransformersJsEmbeddingsProvider from "../indexing/embeddings/Transformer
|
|||
import { BaseLLM } from "../llm";
|
||||
import { llmFromDescription } from "../llm/llms";
|
||||
import CustomLLMClass from "../llm/llms/CustomLLM";
|
||||
import {
|
||||
getConfigJsPath,
|
||||
getConfigJsonPath,
|
||||
getConfigTsPath,
|
||||
migrate,
|
||||
} from "../util/paths";
|
||||
|
||||
function loadSerializedConfig(
|
||||
workspaceConfigs: Partial<SerializedContinueConfig>[]
|
||||
): SerializedContinueConfig {
|
||||
const configPath = getConfigJsonPath();
|
||||
let contents = fs.readFileSync(configPath, "utf8");
|
||||
let config = JSON.parse(contents) as SerializedContinueConfig;
|
||||
if (config.allowAnonymousTelemetry === undefined) {
|
||||
config.allowAnonymousTelemetry = true;
|
||||
}
|
||||
|
||||
// Migrate to camelCase - replace all instances of "snake_case" with "camelCase"
|
||||
migrate("camelCaseConfig", () => {
|
||||
contents = contents
|
||||
.replace(/(_\w)/g, function (m) {
|
||||
return m[1].toUpperCase();
|
||||
})
|
||||
.replace("openai-aiohttp", "openai");
|
||||
|
||||
fs.writeFileSync(configPath, contents, "utf8");
|
||||
});
|
||||
|
||||
migrate("codebaseContextProvider", () => {
|
||||
if (
|
||||
!config.contextProviders?.filter((cp) => cp.name === "codebase")?.length
|
||||
) {
|
||||
config.contextProviders = [
|
||||
...(config.contextProviders || []),
|
||||
{
|
||||
name: "codebase",
|
||||
params: {},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (!config.embeddingsProvider) {
|
||||
config.embeddingsProvider = {
|
||||
provider: "transformers.js",
|
||||
};
|
||||
}
|
||||
|
||||
fs.writeFileSync(configPath, JSON.stringify(config, undefined, 2), "utf8");
|
||||
});
|
||||
|
||||
migrate("problemsContextProvider", () => {
|
||||
if (
|
||||
!config.contextProviders?.filter((cp) => cp.name === "problems")?.length
|
||||
) {
|
||||
config.contextProviders = [
|
||||
...(config.contextProviders || []),
|
||||
{
|
||||
name: "problems",
|
||||
params: {},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
fs.writeFileSync(configPath, JSON.stringify(config, undefined, 2), "utf8");
|
||||
});
|
||||
|
||||
migrate("foldersContextProvider", () => {
|
||||
if (
|
||||
!config.contextProviders?.filter((cp) => cp.name === "folder")?.length
|
||||
) {
|
||||
config.contextProviders = [
|
||||
...(config.contextProviders || []),
|
||||
{
|
||||
name: "folder",
|
||||
params: {},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
fs.writeFileSync(configPath, JSON.stringify(config, undefined, 2), "utf8");
|
||||
});
|
||||
|
||||
migrate("renameFreeTrialProvider", () => {
|
||||
contents = contents.replace(/openai-free-trial/g, "free-trial");
|
||||
fs.writeFileSync(configPath, contents, "utf8");
|
||||
});
|
||||
|
||||
for (const workspaceConfig of workspaceConfigs) {
|
||||
config = mergeJson(config, workspaceConfig);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
function serializedToIntermediateConfig(
|
||||
initial: SerializedContinueConfig
|
||||
|
|
@ -115,4 +212,109 @@ async function intermediateToFinalConfig(
|
|||
};
|
||||
}
|
||||
|
||||
export { intermediateToFinalConfig, serializedToIntermediateConfig };
|
||||
interface BrowserSerializedContinueConfig {
|
||||
allowAnonymousTelemetry?: boolean;
|
||||
models: ModelDescription[];
|
||||
systemMessage?: string;
|
||||
completionOptions?: BaseCompletionOptions;
|
||||
slashCommands?: SlashCommandDescription[];
|
||||
contextProviders?: ContextProviderWithParams[];
|
||||
disableIndexing?: boolean;
|
||||
disableSessionTitles?: boolean;
|
||||
userToken?: string;
|
||||
embeddingsProvider?: string;
|
||||
}
|
||||
|
||||
function finalToBrowserConfig(
|
||||
final: ContinueConfig
|
||||
): BrowserSerializedContinueConfig {
|
||||
return {
|
||||
allowAnonymousTelemetry: final.allowAnonymousTelemetry,
|
||||
models: final.models.map((m) => ({
|
||||
provider: m.providerName,
|
||||
model: m.model,
|
||||
title: m.title || m.model,
|
||||
apiKey: m.apiKey,
|
||||
apiBase: m.apiBase,
|
||||
contextLength: m.contextLength,
|
||||
template: m.template,
|
||||
completionOptions: m.completionOptions,
|
||||
systemMessage: m.systemMessage,
|
||||
requestOptions: m.requestOptions,
|
||||
promptTemplates: m.promptTemplates,
|
||||
})),
|
||||
systemMessage: final.systemMessage,
|
||||
completionOptions: final.completionOptions,
|
||||
slashCommands: final.slashCommands?.map((m) => m.description),
|
||||
contextProviders: final.contextProviders?.map((c) => c.description),
|
||||
disableIndexing: final.disableIndexing,
|
||||
disableSessionTitles: final.disableSessionTitles,
|
||||
userToken: final.userToken,
|
||||
embeddingsProvider: final.embeddingsProvider?.id,
|
||||
};
|
||||
}
|
||||
|
||||
async function buildConfigTs(browser: boolean) {
|
||||
if (!fs.existsSync(getConfigTsPath())) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
// Dynamic import esbuild so potentially disastrous errors can be caught
|
||||
const esbuild = require("esbuild");
|
||||
|
||||
await esbuild.build({
|
||||
entryPoints: [getConfigTsPath()],
|
||||
bundle: true,
|
||||
platform: browser ? "browser" : "node",
|
||||
format: browser ? "esm" : "cjs",
|
||||
outfile: getConfigJsPath(!browser),
|
||||
external: ["fetch", "fs", "path", "os", "child_process"],
|
||||
sourcemap: true,
|
||||
});
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
"Build error. Please check your ~/.continue/config.ts file: " + e
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!fs.existsSync(getConfigJsPath(!browser))) {
|
||||
return undefined;
|
||||
}
|
||||
return fs.readFileSync(getConfigJsPath(!browser), "utf8");
|
||||
}
|
||||
|
||||
async function loadFullConfigNode(
|
||||
readFile: (filepath: string) => Promise<string>,
|
||||
workspaceConfigs: Partial<SerializedContinueConfig>[]
|
||||
): Promise<ContinueConfig> {
|
||||
let serialized = loadSerializedConfig(workspaceConfigs);
|
||||
let intermediate = serializedToIntermediateConfig(serialized);
|
||||
|
||||
const configJsContents = await buildConfigTs(false);
|
||||
if (configJsContents) {
|
||||
try {
|
||||
// Try config.ts first
|
||||
const configJsPath = getConfigJsPath(true);
|
||||
const module = await require(configJsPath);
|
||||
delete require.cache[require.resolve(configJsPath)];
|
||||
if (!module.modifyConfig) {
|
||||
throw new Error("config.ts does not export a modifyConfig function.");
|
||||
}
|
||||
intermediate = module.modifyConfig(intermediate);
|
||||
} catch (e) {
|
||||
console.log("Error loading config.ts: ", e);
|
||||
}
|
||||
}
|
||||
const finalConfig = await intermediateToFinalConfig(intermediate, readFile);
|
||||
return finalConfig;
|
||||
}
|
||||
|
||||
export {
|
||||
finalToBrowserConfig,
|
||||
intermediateToFinalConfig,
|
||||
loadFullConfigNode,
|
||||
serializedToIntermediateConfig,
|
||||
type BrowserSerializedContinueConfig,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -533,7 +533,6 @@ declare global {
|
|||
}
|
||||
|
||||
export interface SerializedContinueConfig {
|
||||
disallowedSteps?: string[];
|
||||
allowAnonymousTelemetry?: boolean;
|
||||
models: ModelDescription[];
|
||||
systemMessage?: string;
|
||||
|
|
|
|||
|
|
@ -1,24 +1,11 @@
|
|||
import * as fs from "fs";
|
||||
import { DiffLine, IDE, Problem, SerializedContinueConfig } from "..";
|
||||
import { DiffLine, IDE, Problem } from "..";
|
||||
import { BrowserSerializedContinueConfig } from "../config/load";
|
||||
import { Chunk } from "../index";
|
||||
import {
|
||||
getConfigJsonPath,
|
||||
getConfigTsPath,
|
||||
getContinueGlobalPath,
|
||||
} from "../util/paths";
|
||||
import { getContinueGlobalPath } from "../util/paths";
|
||||
|
||||
class FileSystemIde implements IDE {
|
||||
async getSerializedConfig(): Promise<SerializedContinueConfig> {
|
||||
const configPath = getConfigJsonPath();
|
||||
let contents = fs.readFileSync(configPath, "utf8");
|
||||
return JSON.parse(contents) as SerializedContinueConfig;
|
||||
}
|
||||
|
||||
async getConfigJsUrl(): Promise<string | undefined> {
|
||||
if (!fs.existsSync(getConfigTsPath())) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async getSerializedConfig(): Promise<BrowserSerializedContinueConfig> {
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,16 @@
|
|||
import { Chunk, DiffLine, Problem } from "..";
|
||||
import { IDE, SerializedContinueConfig } from "../index";
|
||||
import { BrowserSerializedContinueConfig } from "../config/load";
|
||||
import { IDE } from "../index";
|
||||
|
||||
import { ideRequest } from "./messaging";
|
||||
async function r(messageType: string, options: any = {}) {
|
||||
return await ideRequest(messageType, options);
|
||||
}
|
||||
export class ExtensionIde implements IDE {
|
||||
async getSerializedConfig(): Promise<SerializedContinueConfig> {
|
||||
async getSerializedConfig(): Promise<BrowserSerializedContinueConfig> {
|
||||
return await r("getSerializedConfig");
|
||||
}
|
||||
|
||||
async getConfigJsUrl(): Promise<string | undefined> {
|
||||
return await r("getConfigJsUrl");
|
||||
}
|
||||
|
||||
async getDiff() {
|
||||
return await r("getDiff");
|
||||
}
|
||||
|
|
|
|||
6
core/index.d.ts
vendored
6
core/index.d.ts
vendored
|
|
@ -1,3 +1,5 @@
|
|||
import { BrowserSerializedContinueConfig } from "./config/load";
|
||||
|
||||
export interface ChunkWithoutID {
|
||||
content: string;
|
||||
startLine: number;
|
||||
|
|
@ -286,8 +288,7 @@ export class Problem {
|
|||
}
|
||||
|
||||
export interface IDE {
|
||||
getSerializedConfig(): Promise<SerializedContinueConfig>;
|
||||
getConfigJsUrl(): Promise<string | undefined>;
|
||||
getSerializedConfig(): Promise<BrowserSerializedContinueConfig>;
|
||||
getDiff(): Promise<string>;
|
||||
getTerminalContents(): Promise<string>;
|
||||
listWorkspaceContents(directory?: string): Promise<string[]>;
|
||||
|
|
@ -541,7 +542,6 @@ export interface EmbeddingsProvider {
|
|||
}
|
||||
|
||||
export interface SerializedContinueConfig {
|
||||
disallowedSteps?: string[];
|
||||
allowAnonymousTelemetry?: boolean;
|
||||
models: ModelDescription[];
|
||||
systemMessage?: string;
|
||||
|
|
|
|||
|
|
@ -19,12 +19,14 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@octokit/rest": "^20.0.2",
|
||||
"@types/node-fetch": "^2.6.11",
|
||||
"@xenova/transformers": "^2.14.0",
|
||||
"cheerio": "^1.0.0-rc.12",
|
||||
"dotenv": "^16.3.1",
|
||||
"fastest-levenshtein": "^1.0.16",
|
||||
"handlebars": "^4.7.8",
|
||||
"js-tiktoken": "^1.0.8",
|
||||
"node-fetch": "^3.3.2",
|
||||
"node-html-markdown": "^1.3.0",
|
||||
"openai": "^4.20.1",
|
||||
"replicate": "^0.23.0",
|
||||
|
|
|
|||
|
|
@ -880,7 +880,7 @@
|
|||
resolved "https://registry.npmjs.org/@types/mustache/-/mustache-4.2.5.tgz"
|
||||
integrity sha512-PLwiVvTBg59tGFL/8VpcGvqOu3L4OuveNvPi0EYbWchRdEVP++yRUXJPFl+CApKEq13017/4Nf7aQ5lTtHUNsA==
|
||||
|
||||
"@types/node-fetch@^2.6.4":
|
||||
"@types/node-fetch@^2.6.11", "@types/node-fetch@^2.6.4":
|
||||
version "2.6.11"
|
||||
resolved "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz"
|
||||
integrity sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==
|
||||
|
|
@ -1518,6 +1518,11 @@ css-what@^6.1.0:
|
|||
resolved "https://registry.npmjs.org/css-what/-/css-what-6.1.0.tgz"
|
||||
integrity sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==
|
||||
|
||||
data-uri-to-buffer@^4.0.0:
|
||||
version "4.0.1"
|
||||
resolved "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz"
|
||||
integrity sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==
|
||||
|
||||
debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.3, debug@~4.3.1, debug@~4.3.2, debug@4:
|
||||
version "4.3.4"
|
||||
resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz"
|
||||
|
|
@ -1799,6 +1804,14 @@ fb-watchman@^2.0.0:
|
|||
dependencies:
|
||||
bser "2.1.1"
|
||||
|
||||
fetch-blob@^3.1.2, fetch-blob@^3.1.4:
|
||||
version "3.2.0"
|
||||
resolved "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz"
|
||||
integrity sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==
|
||||
dependencies:
|
||||
node-domexception "^1.0.0"
|
||||
web-streams-polyfill "^3.0.3"
|
||||
|
||||
file-uri-to-path@1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz"
|
||||
|
|
@ -1863,6 +1876,13 @@ formdata-node@^4.3.2:
|
|||
node-domexception "1.0.0"
|
||||
web-streams-polyfill "4.0.0-beta.3"
|
||||
|
||||
formdata-polyfill@^4.0.10:
|
||||
version "4.0.10"
|
||||
resolved "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz"
|
||||
integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==
|
||||
dependencies:
|
||||
fetch-blob "^3.1.2"
|
||||
|
||||
fs-constants@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz"
|
||||
|
|
@ -2869,7 +2889,7 @@ node-addon-api@^7.0.0:
|
|||
resolved "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.0.tgz"
|
||||
integrity sha512-mNcltoe1R8o7STTegSOHdnJNN7s5EUvhoS7ShnTHDyOSd+8H+UdWODq6qSv67PjC8Zc5JRT8+oLAMCr0SIXw7g==
|
||||
|
||||
node-domexception@1.0.0:
|
||||
node-domexception@^1.0.0, node-domexception@1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz"
|
||||
integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==
|
||||
|
|
@ -2881,6 +2901,15 @@ node-fetch@^2.6.7:
|
|||
dependencies:
|
||||
whatwg-url "^5.0.0"
|
||||
|
||||
node-fetch@^3.3.2:
|
||||
version "3.3.2"
|
||||
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz"
|
||||
integrity sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==
|
||||
dependencies:
|
||||
data-uri-to-buffer "^4.0.0"
|
||||
fetch-blob "^3.1.4"
|
||||
formdata-polyfill "^4.0.10"
|
||||
|
||||
node-gyp@8.x:
|
||||
version "8.4.1"
|
||||
resolved "https://registry.npmjs.org/node-gyp/-/node-gyp-8.4.1.tgz"
|
||||
|
|
@ -3809,7 +3838,7 @@ walker@^1.0.8:
|
|||
dependencies:
|
||||
makeerror "1.0.12"
|
||||
|
||||
web-streams-polyfill@^3.2.1:
|
||||
web-streams-polyfill@^3.0.3, web-streams-polyfill@^3.2.1:
|
||||
version "3.3.2"
|
||||
resolved "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.2.tgz"
|
||||
integrity sha512-3pRGuxRF5gpuZc0W+EpwQRmCD7gRqcDOMt688KmdlDAgAyaB1XlN0zq2njfDNm44XVdIouE7pZ6GzbdyH47uIQ==
|
||||
|
|
|
|||
|
|
@ -283,10 +283,6 @@ export function getSidebarContent(
|
|||
respond(await ide.getSerializedConfig());
|
||||
break;
|
||||
}
|
||||
case "getConfigJsUrl": {
|
||||
respond(await ide.getConfigJsUrl());
|
||||
break;
|
||||
}
|
||||
case "getTerminalContents": {
|
||||
respond(await ide.getTerminalContents());
|
||||
break;
|
||||
|
|
@ -588,7 +584,7 @@ export function getSidebarContent(
|
|||
params,
|
||||
} = data.message;
|
||||
|
||||
const config = await configHandler.loadConfig(ide);
|
||||
const config = await configHandler.loadConfig();
|
||||
const llm = await llmFromTitle(modelTitle);
|
||||
const slashCommand = config.slashCommands?.find(
|
||||
(sc) => sc.name === slashCommandName
|
||||
|
|
@ -613,7 +609,7 @@ export function getSidebarContent(
|
|||
}
|
||||
case "loadSubmenuItems": {
|
||||
const { title } = data.message;
|
||||
const config = await configHandler.loadConfig(ide);
|
||||
const config = await configHandler.loadConfig();
|
||||
const provider = config.contextProviders?.find(
|
||||
(p) => p.description.title === title
|
||||
);
|
||||
|
|
@ -640,7 +636,7 @@ export function getSidebarContent(
|
|||
}
|
||||
case "getContextItems": {
|
||||
const { name, query, fullInput, selectedCode } = data.message;
|
||||
const config = await configHandler.loadConfig(ide);
|
||||
const config = await configHandler.loadConfig();
|
||||
const llm = await llmFromTitle();
|
||||
const provider = config.contextProviders?.find(
|
||||
(p) => p.description.title === name
|
||||
|
|
|
|||
|
|
@ -1,29 +1,14 @@
|
|||
import { exec } from "child_process";
|
||||
import defaultConfig from "core/config/default";
|
||||
import {
|
||||
getConfigJsPath,
|
||||
getConfigJsonPath,
|
||||
getConfigTsPath,
|
||||
getContinueGlobalPath,
|
||||
migrate,
|
||||
} from "core/util/paths";
|
||||
import * as fs from "fs";
|
||||
import { getContinueGlobalPath } from "core/util/paths";
|
||||
import * as path from "path";
|
||||
import * as vscode from "vscode";
|
||||
import { ideProtocolClient } from "./activation/activate";
|
||||
|
||||
import * as child_process from "child_process";
|
||||
import { Chunk, DiffLine, IDE, Problem } from "core";
|
||||
import {
|
||||
Chunk,
|
||||
ContinueConfig,
|
||||
DiffLine,
|
||||
IDE,
|
||||
Problem,
|
||||
SerializedContinueConfig,
|
||||
} from "core";
|
||||
import {
|
||||
intermediateToFinalConfig,
|
||||
serializedToIntermediateConfig,
|
||||
BrowserSerializedContinueConfig,
|
||||
finalToBrowserConfig,
|
||||
} from "core/config/load";
|
||||
import { LanceDbIndex } from "core/indexing/LanceDbIndex";
|
||||
import { IndexTag } from "core/indexing/types";
|
||||
|
|
@ -33,209 +18,10 @@ import { configHandler } from "./loadConfig";
|
|||
import { traverseDirectory } from "./util/traverseDirectory";
|
||||
import { getExtensionUri, openEditorAndRevealRange } from "./util/vscode";
|
||||
|
||||
async function buildConfigTs(browser: boolean) {
|
||||
if (!fs.existsSync(getConfigTsPath())) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
// Dynamic import esbuild so potentially disastrous errors can be caught
|
||||
const esbuild = require("esbuild");
|
||||
|
||||
await esbuild.build({
|
||||
entryPoints: [getConfigTsPath()],
|
||||
bundle: true,
|
||||
platform: browser ? "browser" : "node",
|
||||
format: browser ? "esm" : "cjs",
|
||||
outfile: getConfigJsPath(!browser),
|
||||
external: ["fetch", "fs", "path", "os", "child_process"],
|
||||
sourcemap: true,
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
vscode.window.showErrorMessage(
|
||||
"Build error. Please check your ~/.continue/config.ts file: " + e
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!fs.existsSync(getConfigJsPath(!browser))) {
|
||||
return undefined;
|
||||
}
|
||||
return fs.readFileSync(getConfigJsPath(!browser), "utf8");
|
||||
}
|
||||
|
||||
class VsCodeIde implements IDE {
|
||||
async getSerializedConfig(): Promise<SerializedContinueConfig> {
|
||||
try {
|
||||
const configPath = getConfigJsonPath();
|
||||
let contents = fs.readFileSync(configPath, "utf8");
|
||||
let config = JSON.parse(contents) as SerializedContinueConfig;
|
||||
if (config.allowAnonymousTelemetry === undefined) {
|
||||
config.allowAnonymousTelemetry = true;
|
||||
}
|
||||
config.allowAnonymousTelemetry =
|
||||
config.allowAnonymousTelemetry &&
|
||||
vscode.workspace.getConfiguration("continue").get("telemetryEnabled");
|
||||
|
||||
// Migrate to camelCase - replace all instances of "snake_case" with "camelCase"
|
||||
migrate("camelCaseConfig", () => {
|
||||
contents = contents
|
||||
.replace(/(_\w)/g, function (m) {
|
||||
return m[1].toUpperCase();
|
||||
})
|
||||
.replace("openai-aiohttp", "openai");
|
||||
|
||||
fs.writeFileSync(configPath, contents, "utf8");
|
||||
});
|
||||
|
||||
migrate("codebaseContextProvider", () => {
|
||||
if (
|
||||
!config.contextProviders?.filter((cp) => cp.name === "codebase")
|
||||
?.length
|
||||
) {
|
||||
config.contextProviders = [
|
||||
...(config.contextProviders || []),
|
||||
{
|
||||
name: "codebase",
|
||||
params: {},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (!config.embeddingsProvider) {
|
||||
config.embeddingsProvider = {
|
||||
provider: "transformers.js",
|
||||
};
|
||||
}
|
||||
|
||||
fs.writeFileSync(
|
||||
configPath,
|
||||
JSON.stringify(config, undefined, 2),
|
||||
"utf8"
|
||||
);
|
||||
});
|
||||
|
||||
migrate("problemsContextProvider", () => {
|
||||
if (
|
||||
!config.contextProviders?.filter((cp) => cp.name === "problems")
|
||||
?.length
|
||||
) {
|
||||
config.contextProviders = [
|
||||
...(config.contextProviders || []),
|
||||
{
|
||||
name: "problems",
|
||||
params: {},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
fs.writeFileSync(
|
||||
configPath,
|
||||
JSON.stringify(config, undefined, 2),
|
||||
"utf8"
|
||||
);
|
||||
});
|
||||
|
||||
migrate("foldersContextProvider", () => {
|
||||
if (
|
||||
!config.contextProviders?.filter((cp) => cp.name === "folder")?.length
|
||||
) {
|
||||
config.contextProviders = [
|
||||
...(config.contextProviders || []),
|
||||
{
|
||||
name: "folder",
|
||||
params: {},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
fs.writeFileSync(
|
||||
configPath,
|
||||
JSON.stringify(config, undefined, 2),
|
||||
"utf8"
|
||||
);
|
||||
});
|
||||
|
||||
migrate("renameFreeTrialProvider", () => {
|
||||
contents = contents.replace(/openai-free-trial/g, "free-trial");
|
||||
fs.writeFileSync(configPath, contents, "utf8");
|
||||
});
|
||||
|
||||
for (const workspacePath of await this.getWorkspaceDirs()) {
|
||||
const continueRcPath = path.join(workspacePath, ".continuerc.json");
|
||||
if (fs.existsSync(continueRcPath)) {
|
||||
const continueRc = JSON.parse(
|
||||
fs.readFileSync(continueRcPath, "utf8")
|
||||
) as Partial<SerializedContinueConfig>;
|
||||
config = mergeJson(config, continueRc);
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
} catch (e) {
|
||||
vscode.window
|
||||
.showErrorMessage(
|
||||
"Error loading config.json. Please check your config.json file: " + e,
|
||||
"Open config.json"
|
||||
)
|
||||
.then((selection) => {
|
||||
if (selection === "Open config.json") {
|
||||
vscode.workspace
|
||||
.openTextDocument(getConfigJsonPath())
|
||||
.then((doc) => {
|
||||
vscode.window.showTextDocument(doc);
|
||||
});
|
||||
}
|
||||
});
|
||||
return defaultConfig;
|
||||
}
|
||||
}
|
||||
|
||||
async getConfigJsUrl(): Promise<string | undefined> {
|
||||
const configJsString = await buildConfigTs(true);
|
||||
|
||||
if (!configJsString) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var dataUrl = "data:text/javascript;base64," + btoa(configJsString);
|
||||
return dataUrl;
|
||||
|
||||
// try {
|
||||
// // Use tsc to compile config.ts to config.js. Spawn a child process to do this
|
||||
// // But we've packaged a file tsc.js in this folder, so just call that
|
||||
// const { spawn } = require("child_process");
|
||||
// const child = spawn(process.execPath, [
|
||||
// __dirname + "/tsc.js",
|
||||
// "--project",
|
||||
// getTsConfigPath(),
|
||||
// ]);
|
||||
|
||||
// await new Promise((resolve, reject) => {
|
||||
// child.stdout.on("data", (data: any) => {
|
||||
// console.log(`stdout: ${data}`);
|
||||
// });
|
||||
// child.stderr.on("data", (data: any) => {
|
||||
// reject(data);
|
||||
// });
|
||||
// child.on("close", (code: any) => {
|
||||
// console.log(`child process exited with code ${code}`);
|
||||
// resolve(null);
|
||||
// });
|
||||
// });
|
||||
|
||||
// const configJsString = fs.readFileSync(getConfigJsPath(), "utf8");
|
||||
// var dataUrl = "data:text/javascript;base64," + btoa(configJsString);
|
||||
|
||||
// return dataUrl;
|
||||
// } catch (e) {
|
||||
// console.log(e);
|
||||
// vscode.window.showErrorMessage(
|
||||
// "Error loading config.js. Please check your config.ts file: " + e
|
||||
// );
|
||||
// return undefined;
|
||||
// }
|
||||
async getSerializedConfig(): Promise<BrowserSerializedContinueConfig> {
|
||||
const config = await configHandler.loadConfig();
|
||||
return finalToBrowserConfig(config);
|
||||
}
|
||||
|
||||
async getDiff(): Promise<string> {
|
||||
|
|
@ -457,7 +243,7 @@ class VsCodeIde implements IDE {
|
|||
n: number,
|
||||
directory: string | undefined
|
||||
): Promise<Chunk[]> {
|
||||
const embeddingsProvider = (await configHandler.loadConfig(new VsCodeIde()))
|
||||
const embeddingsProvider = (await configHandler.loadConfig())
|
||||
.embeddingsProvider;
|
||||
if (!embeddingsProvider) {
|
||||
return [];
|
||||
|
|
@ -482,32 +268,4 @@ class VsCodeIde implements IDE {
|
|||
}
|
||||
}
|
||||
|
||||
async function loadFullConfigNode(ide: IDE): Promise<ContinueConfig> {
|
||||
let serialized = await ide.getSerializedConfig();
|
||||
let intermediate = serializedToIntermediateConfig(serialized);
|
||||
|
||||
const configJsContents = await buildConfigTs(false);
|
||||
if (configJsContents) {
|
||||
try {
|
||||
// Try config.ts first
|
||||
const configJsPath = getConfigJsPath(true);
|
||||
const module = await require(configJsPath);
|
||||
delete require.cache[require.resolve(configJsPath)];
|
||||
if (!module.modifyConfig) {
|
||||
throw new Error("config.ts does not export a modifyConfig function.");
|
||||
}
|
||||
intermediate = module.modifyConfig(intermediate);
|
||||
} catch (e) {
|
||||
console.log("Error loading config.ts: ", e);
|
||||
}
|
||||
}
|
||||
const finalConfig = await intermediateToFinalConfig(
|
||||
intermediate,
|
||||
async (filepath) => {
|
||||
return ideProtocolClient.readFile(filepath);
|
||||
}
|
||||
);
|
||||
return finalConfig;
|
||||
}
|
||||
|
||||
export { VsCodeIde, buildConfigTs, loadFullConfigNode };
|
||||
export { VsCodeIde };
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import { ContinueConfig, IDE, ILLM } from "core";
|
||||
import { ContinueConfig, ILLM } from "core";
|
||||
import defaultConfig from "core/config/default";
|
||||
import { loadFullConfigNode } from "core/config/load";
|
||||
import { getConfigJsonPath } from "core/util/paths";
|
||||
import { https } from "follow-redirects";
|
||||
import * as fs from "fs";
|
||||
import fetch from "node-fetch";
|
||||
import * as vscode from "vscode";
|
||||
import { webviewRequest } from "./debugPanel";
|
||||
import { VsCodeIde, loadFullConfigNode } from "./ideProtocol";
|
||||
const tls = require("tls");
|
||||
|
||||
const outputChannel = vscode.window.createOutputChannel(
|
||||
|
|
@ -18,12 +20,33 @@ class VsCodeConfigHandler {
|
|||
this.savedConfig = undefined;
|
||||
}
|
||||
|
||||
async loadConfig(ide: IDE): Promise<ContinueConfig> {
|
||||
if (this.savedConfig) {
|
||||
async loadConfig(): Promise<ContinueConfig> {
|
||||
try {
|
||||
if (this.savedConfig) {
|
||||
return this.savedConfig;
|
||||
}
|
||||
this.savedConfig = await loadFullConfigNode(ideProtocolClient.readFile);
|
||||
this.savedConfig.allowAnonymousTelemetry =
|
||||
this.savedConfig.allowAnonymousTelemetry &&
|
||||
vscode.workspace.getConfiguration("continue").get("telemetryEnabled");
|
||||
return this.savedConfig;
|
||||
} catch (e) {
|
||||
vscode.window
|
||||
.showErrorMessage(
|
||||
"Error loading config.json. Please check your config.json file: " + e,
|
||||
"Open config.json"
|
||||
)
|
||||
.then((selection) => {
|
||||
if (selection === "Open config.json") {
|
||||
vscode.workspace
|
||||
.openTextDocument(getConfigJsonPath())
|
||||
.then((doc) => {
|
||||
vscode.window.showTextDocument(doc);
|
||||
});
|
||||
}
|
||||
});
|
||||
return defaultConfig;
|
||||
}
|
||||
this.savedConfig = await loadFullConfigNode(ide);
|
||||
return this.savedConfig;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -32,7 +55,7 @@ export const configHandler = new VsCodeConfigHandler();
|
|||
const TIMEOUT = 7200; // 7200 seconds = 2 hours
|
||||
|
||||
export async function llmFromTitle(title?: string): Promise<ILLM> {
|
||||
let config = await configHandler.loadConfig(new VsCodeIde());
|
||||
let config = await configHandler.loadConfig();
|
||||
|
||||
if (title === undefined) {
|
||||
const resp = await webviewRequest("getDefaultModelTitle");
|
||||
|
|
@ -47,7 +70,7 @@ export async function llmFromTitle(title?: string): Promise<ILLM> {
|
|||
if (!llm) {
|
||||
// Try to reload config
|
||||
configHandler.reloadConfig();
|
||||
config = await configHandler.loadConfig(new VsCodeIde());
|
||||
config = await configHandler.loadConfig();
|
||||
llm = config.models.find((llm) => llm.title === title);
|
||||
if (!llm) {
|
||||
throw new Error(`Unknown model ${title}`);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ const vscodeGetStats = async (
|
|||
|
||||
async function getIndexesToBuild(): Promise<CodebaseIndex[]> {
|
||||
const ide = new VsCodeIde();
|
||||
const config = await configHandler.loadConfig(ide);
|
||||
const config = await configHandler.loadConfig();
|
||||
|
||||
const indexes = [
|
||||
new ChunkCodebaseIndex(ide.readFile), // Chunking must come first
|
||||
|
|
@ -42,7 +42,7 @@ export async function vsCodeIndexCodebase(workspaceDirs: string[]) {
|
|||
debugPanelWebview?.postMessage({ type: "indexProgress", progress, desc });
|
||||
};
|
||||
|
||||
const config = await configHandler.loadConfig(new VsCodeIde());
|
||||
const config = await configHandler.loadConfig();
|
||||
if (config.disableIndexing) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,10 +47,7 @@ function useSetup(dispatch: Dispatch<any>) {
|
|||
|
||||
// Fall back to config.json
|
||||
dispatch(setConfig(finalConfig));
|
||||
} catch (e) {
|
||||
console.log("Error loading config.json: ", e);
|
||||
errorPopup(e.message);
|
||||
}
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
// Load config from the IDE
|
||||
|
|
|
|||
|
|
@ -146,9 +146,6 @@ function GUI(props: GUIProps) {
|
|||
const defaultModel = useSelector(defaultModelSelector);
|
||||
|
||||
const active = useSelector((state: RootStore) => state.state.active);
|
||||
const contextProviders = useSelector(
|
||||
(state: RootStore) => state.state.config.contextProviders || []
|
||||
);
|
||||
|
||||
// #endregion
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue