diff --git a/core/.eslintrc.json b/core/.eslintrc.json index 1c67b146c3..8ba241323d 100644 --- a/core/.eslintrc.json +++ b/core/.eslintrc.json @@ -8,7 +8,7 @@ "plugins": ["@typescript-eslint", "import"], "rules": { "quotes": ["warn", "double", {}], - "@typescript-eslint/naming-convention": "warn", + "@typescript-eslint/naming-convention": "off", "@typescript-eslint/semi": "warn", "curly": "warn", "eqeqeq": "warn", diff --git a/core/autocomplete/brackets.ts b/core/autocomplete/brackets.ts index 63afdfd10b..3734df2beb 100644 --- a/core/autocomplete/brackets.ts +++ b/core/autocomplete/brackets.ts @@ -84,9 +84,9 @@ export class BracketMatchingService { // Add corresponding open brackets from suffix to stack // because we overwrite them and the diff is displayed, and this allows something to be edited after that for (let i = 0; i < suffix.length; i++) { - if (suffix[i] === " ") continue; + if (suffix[i] === " ") {continue;} const openBracket = BracketMatchingService.BRACKETS_REVERSE[suffix[i]]; - if (!openBracket) break; + if (!openBracket) {break;} stack.unshift(openBracket); } diff --git a/core/autocomplete/languages.ts b/core/autocomplete/languages.ts index 19ab65f71e..f5b4cffb0d 100644 --- a/core/autocomplete/languages.ts +++ b/core/autocomplete/languages.ts @@ -26,7 +26,7 @@ export const Python = { name: "Python", // """"#" is for .ipynb files, where we add '"""' surrounding markdown blocks. // This stops the model from trying to complete the start of a new markdown block - topLevelKeywords: ["def", "class", '"""#'], + topLevelKeywords: ["def", "class", "\"\"\"#"], singleLineComment: "#", endOfLine: [], }; diff --git a/core/autocomplete/templates.ts b/core/autocomplete/templates.ts index 53aa034a93..c0e5c132a5 100644 --- a/core/autocomplete/templates.ts +++ b/core/autocomplete/templates.ts @@ -70,7 +70,9 @@ const codestralMultifileFimTemplate: AutocompleteTemplate = { .map((snippet, i) => `+++++ ${relativePaths[i]}\n${snippet.contents}`) .join("\n\n"); return [ - `${otherFiles}\n\n+++++ ${relativePaths[relativePaths.length - 1]}\n${prefix}`, + `${otherFiles}\n\n+++++ ${ + relativePaths[relativePaths.length - 1] + }\n${prefix}`, suffix, ]; }, @@ -172,8 +174,10 @@ const codegeexFimTemplate: AutocompleteTemplate = { ...snippets.map((snippet) => snippet.filepath), filepath, ]); - const baseTemplate = `###PATH:${relativePaths[relativePaths.length - 1]}\n###LANGUAGE:${language}\n###MODE:BLOCK\n<|code_suffix|>${suffix}<|code_prefix|>${prefix}<|code_middle|>`; - if (snippets.length == 0) { + const baseTemplate = `###PATH:${ + relativePaths[relativePaths.length - 1] + }\n###LANGUAGE:${language}\n###MODE:BLOCK\n<|code_suffix|>${suffix}<|code_prefix|>${prefix}<|code_middle|>`; + if (snippets.length === 0) { return `<|user|>\n${baseTemplate}<|assistant|>\n`; } const references = `###REFERENCE:\n${snippets diff --git a/core/context/providers/PostgresContextProvider.ts b/core/context/providers/PostgresContextProvider.ts index 494a3bc339..55c00ae3c3 100644 --- a/core/context/providers/PostgresContextProvider.ts +++ b/core/context/providers/PostgresContextProvider.ts @@ -37,7 +37,7 @@ class PostgresContextProvider extends BaseContextProvider { let tablesInfoQuery = ` SELECT table_schema, table_name FROM information_schema.tables`; - if (schema != null) { + if (schema !== null) { tablesInfoQuery += ` WHERE table_schema = '${schema}'`; } const { rows: tablesInfo } = await pool.query(tablesInfoQuery); diff --git a/core/context/rerankers/tei.ts b/core/context/rerankers/tei.ts index 667181ae3d..61f38b98ba 100644 --- a/core/context/rerankers/tei.ts +++ b/core/context/rerankers/tei.ts @@ -26,7 +26,7 @@ export class HuggingFaceTEIReranker implements Reranker { const resp = await fetch(new URL("rerank", apiBase), { method: "POST", - headers: { 'Content-Type': 'application/json' }, + headers: { "Content-Type": "application/json" }, body: JSON.stringify({ query: query, return_text: false, diff --git a/core/control-plane/client.ts b/core/control-plane/client.ts index 53e62d2477..bee6061b2a 100644 --- a/core/control-plane/client.ts +++ b/core/control-plane/client.ts @@ -74,7 +74,7 @@ export class ControlPlaneClient { } try { - const resp = await this.request(`/workspaces`, { + const resp = await this.request("/workspaces", { method: "GET", }); return (await resp.json()) as any; diff --git a/core/indexing/TestCodebaseIndex.ts b/core/indexing/TestCodebaseIndex.ts index 234bcbc3e6..7031fd992d 100644 --- a/core/indexing/TestCodebaseIndex.ts +++ b/core/indexing/TestCodebaseIndex.ts @@ -35,14 +35,14 @@ export class TestCodebaseIndex implements CodebaseIndex { for (const item of [...results.compute, ...results.addTag]) { await db.run( - `INSERT INTO test_index (path, branch, directory) VALUES (?, ?, ?)`, + "INSERT INTO test_index (path, branch, directory) VALUES (?, ?, ?)", [item.path, tag.branch, tag.directory], ); } for (const item of [...results.del, ...results.removeTag]) { await db.run( - `DELETE FROM test_index WHERE path = ? AND branch = ? AND directory = ?`, + "DELETE FROM test_index WHERE path = ? AND branch = ? AND directory = ?", [item.path, tag.branch, tag.directory], ); } diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts index e1d184b806..1696bd6747 100644 --- a/core/llm/autodetect.ts +++ b/core/llm/autodetect.ts @@ -80,7 +80,7 @@ function modelSupportsImages( title: string | undefined, capabilities: ModelCapability | undefined ): boolean { - if (capabilities?.uploadImage !== undefined) return capabilities.uploadImage + if (capabilities?.uploadImage !== undefined) {return capabilities.uploadImage;} if (!PROVIDER_SUPPORTS_IMAGES.includes(provider)) { return false; } diff --git a/core/llm/llms/FreeTrial.ts b/core/llm/llms/FreeTrial.ts index e4c1674e63..9fc59313b5 100644 --- a/core/llm/llms/FreeTrial.ts +++ b/core/llm/llms/FreeTrial.ts @@ -31,7 +31,7 @@ class FreeTrial extends BaseLLM { private async _countTokens(prompt: string, model: string, isPrompt: boolean) { if (!Telemetry.client) { throw new Error( - 'In order to use the free trial, telemetry must be enabled so that we can monitor abuse. To enable telemetry, set "allowAnonymousTelemetry": true in config.json and make sure the box is checked in IDE settings. If you use your own model (local or API key), telemetry will never be required.', + "In order to use the free trial, telemetry must be enabled so that we can monitor abuse. To enable telemetry, set \"allowAnonymousTelemetry\": true in config.json and make sure the box is checked in IDE settings. If you use your own model (local or API key), telemetry will never be required.", ); } const event = isPrompt diff --git a/core/llm/llms/Ollama.ts b/core/llm/llms/Ollama.ts index fcce902c84..f830b7f0fc 100644 --- a/core/llm/llms/Ollama.ts +++ b/core/llm/llms/Ollama.ts @@ -61,7 +61,7 @@ class Ollama extends BaseLLM { this.completionOptions.stop.push(JSON.parse(value)); } catch (e) { console.warn( - 'Error parsing stop parameter value "{value}: ${e}', + "Error parsing stop parameter value \"{value}: ${e}", ); } break; diff --git a/core/llm/llms/SageMaker.ts b/core/llm/llms/SageMaker.ts index 6a5890e670..a59de352ca 100644 --- a/core/llm/llms/SageMaker.ts +++ b/core/llm/llms/SageMaker.ts @@ -55,7 +55,7 @@ class SageMaker extends BaseLLM { let position; while ((position = buffer.indexOf("\n")) >= 0) { const line = buffer.slice(0, position); - const data = JSON.parse(line.replace(/^data:/, '')); + const data = JSON.parse(line.replace(/^data:/, "")); if ("choices" in data) { yield data.choices[0].delta.content; } @@ -94,7 +94,7 @@ class SageMaker extends BaseLLM { let position; while ((position = buffer.indexOf("\n")) >= 0) { const line = buffer.slice(0, position); - const data = JSON.parse(line.replace(/^data:/, '')); + const data = JSON.parse(line.replace(/^data:/, "")); if ("choices" in data) { yield { role: "assistant", content: data.choices[0].delta.content }; } @@ -143,7 +143,7 @@ class MessageAPIToolkit implements SageMakerModelToolkit { let prompt = jinja.compile(this.sagemaker.completionOptions.chat_template).render( { messages: messages, add_generation_prompt: true }, { autoEscape: false } - ) + ); const payload = { inputs: prompt, parameters: this.sagemaker.completionOptions, diff --git a/core/llm/llms/WatsonX.ts b/core/llm/llms/WatsonX.ts index 02e7c07993..edf1bd9fb2 100644 --- a/core/llm/llms/WatsonX.ts +++ b/core/llm/llms/WatsonX.ts @@ -19,7 +19,7 @@ class WatsonX extends BaseLLM { super(options); } async getBearerToken(): Promise<{ token: string; expiration: number }> { - if (this.watsonxUrl != null && this.watsonxUrl.includes("cloud.ibm.com")) { + if (this.watsonxUrl !== null && this.watsonxUrl.includes("cloud.ibm.com")) { // watsonx SaaS const wxToken = await ( await fetch( @@ -125,7 +125,9 @@ class WatsonX extends BaseLLM { protected _getHeaders() { return { "Content-Type": "application/json", - Authorization: `${watsonxConfig.accessToken.expiration === -1 ? "ZenApiKey" : "Bearer"} ${watsonxConfig.accessToken.token}`, + Authorization: `${ + watsonxConfig.accessToken.expiration === -1 ? "ZenApiKey" : "Bearer" + } ${watsonxConfig.accessToken.token}`, }; } @@ -169,11 +171,13 @@ class WatsonX extends BaseLLM { watsonxConfig.accessToken = await this.getBearerToken(); } else { console.log( - `Reusing token (expires in ${(watsonxConfig.accessToken.expiration - now) / 60} mins)`, + `Reusing token (expires in ${ + (watsonxConfig.accessToken.expiration - now) / 60 + } mins)`, ); } if (watsonxConfig.accessToken.token === undefined) { - throw new Error(`Something went wrong. Check your credentials, please.`); + throw new Error("Something went wrong. Check your credentials, please."); } const stopToken = @@ -185,7 +189,9 @@ class WatsonX extends BaseLLM { method: "POST", headers: { "Content-Type": "application/json", - Authorization: `${watsonxConfig.accessToken.expiration === -1 ? "ZenApiKey" : "Bearer"} ${watsonxConfig.accessToken.token}`, + Authorization: `${ + watsonxConfig.accessToken.expiration === -1 ? "ZenApiKey" : "Bearer" + } ${watsonxConfig.accessToken.token}`, }, body: JSON.stringify({ input: messages[messages.length - 1].content, diff --git a/core/llm/templates/edit.ts b/core/llm/templates/edit.ts index fd288a48ea..00a05ac72f 100644 --- a/core/llm/templates/edit.ts +++ b/core/llm/templates/edit.ts @@ -74,7 +74,7 @@ const osModelsEditPrompt: PromptTemplate = (history, otherData) => { !firstCharOfFirstLine; const suffixTag = isSuffix ? "" : ""; const suffixExplanation = isSuffix - ? ' When you get to "", end your response.' + ? " When you get to \"\", end your response." : ""; // If neither prefilling nor /v1/completions are supported, we have to use a chat prompt without putting words in the model's mouth diff --git a/core/test/indexing/chunk/code.test.ts b/core/test/indexing/chunk/code.test.ts index 00615d124e..92332dc283 100644 --- a/core/test/indexing/chunk/code.test.ts +++ b/core/test/indexing/chunk/code.test.ts @@ -29,7 +29,7 @@ describe.skip("codeChunker", () => { test("should capture small class and function from large python file", async () => { const extraLine = "# This is a comment"; const myClass = "class MyClass:\n def __init__(self):\n pass"; - const myFunction = 'def my_function():\n return "Hello, World!"'; + const myFunction = "def my_function():\n return \"Hello, World!\""; const file = Array(100).fill(extraLine).join("\n") + @@ -66,7 +66,7 @@ describe.skip("codeChunker", () => { chunks[0].startsWith("class MyClass:\n def method1():\n ..."), ).toBe(true); // The extra spaces seem to be a bug with tree-sitter-python - expect(chunks).toContain('def method1():\n return "Hello, 1!"'); - expect(chunks).toContain('def method20():\n return "Hello, 20!"'); + expect(chunks).toContain("def method1():\n return \"Hello, 1!\""); + expect(chunks).toContain("def method20():\n return \"Hello, 20!\""); }); }); diff --git a/core/test/util/merge.test.ts b/core/test/util/merge.test.ts index 3bd8309a80..8eb0546bd4 100644 --- a/core/test/util/merge.test.ts +++ b/core/test/util/merge.test.ts @@ -9,7 +9,7 @@ describe("mergeJson", () => { expect(result).toEqual({ a: 1, b: 3, c: 4 }); }); - it('should overwrite values when mergeBehavior is "overwrite"', () => { + it("should overwrite values when mergeBehavior is \"overwrite\"", () => { const first = { a: 1, b: 2 }; const second = { b: 3, c: 4 }; const result = mergeJson(first, second, "overwrite"); diff --git a/core/util/devdataSqlite.ts b/core/util/devdataSqlite.ts index 9724e9f213..4f86cb1a14 100644 --- a/core/util/devdataSqlite.ts +++ b/core/util/devdataSqlite.ts @@ -21,14 +21,14 @@ export class DevDataSqliteDb { // Add tokens_prompt column if it doesn't exist const columnCheckResult = await db.all( - `PRAGMA table_info(tokens_generated);`, + "PRAGMA table_info(tokens_generated);", ); const columnExists = columnCheckResult.some( (col: any) => col.name === "tokens_prompt", ); if (!columnExists) { await db.exec( - `ALTER TABLE tokens_generated ADD COLUMN tokens_prompt INTEGER NOT NULL DEFAULT 0;`, + "ALTER TABLE tokens_generated ADD COLUMN tokens_prompt INTEGER NOT NULL DEFAULT 0;", ); } } @@ -41,7 +41,7 @@ export class DevDataSqliteDb { ) { const db = await DevDataSqliteDb.get(); await db?.run( - `INSERT INTO tokens_generated (model, provider, tokens_prompt, tokens_generated) VALUES (?, ?, ?, ?)`, + "INSERT INTO tokens_generated (model, provider, tokens_prompt, tokens_generated) VALUES (?, ?, ?, ?)", [model, provider, promptTokens, generatedTokens], ); } diff --git a/core/util/extractMinimalStackTraceInfo.ts b/core/util/extractMinimalStackTraceInfo.ts index a2fa226de8..51fcde91a4 100644 --- a/core/util/extractMinimalStackTraceInfo.ts +++ b/core/util/extractMinimalStackTraceInfo.ts @@ -5,7 +5,7 @@ * @returns A string containing the minimal stack trace information. */ export function extractMinimalStackTraceInfo(stack: unknown): string { - if (typeof stack !== "string") return ""; + if (typeof stack !== "string") {return "";} const lines = stack.split("\n"); const minimalLines = lines.filter((line) => { return line.trimStart().startsWith("at ") && !line.includes("node_modules"); diff --git a/core/util/filesystem.ts b/core/util/filesystem.ts index 3307765183..06209a474c 100644 --- a/core/util/filesystem.ts +++ b/core/util/filesystem.ts @@ -84,12 +84,12 @@ class FileSystemIde implements IDE { } async getTags(artifactId: string): Promise { - const directory =(await this.getWorkspaceDirs())[0] + const directory =(await this.getWorkspaceDirs())[0]; return [{ artifactId, branch: await this.getBranch(directory), directory - }] + }]; } getIdeInfo(): Promise { diff --git a/core/util/index.ts b/core/util/index.ts index 0c7a063175..a628948c7b 100644 --- a/core/util/index.ts +++ b/core/util/index.ts @@ -2,19 +2,19 @@ export function removeQuotesAndEscapes(output: string): string { output = output.trim(); // Replace smart quotes - output = output.replace("“", '"'); - output = output.replace("”", '"'); + output = output.replace("“", "\""); + output = output.replace("”", "\""); output = output.replace("‘", "'"); output = output.replace("’", "'"); // Remove escapes - output = output.replace('\\"', '"'); + output = output.replace("\\\"", "\""); output = output.replace("\\'", "'"); output = output.replace("\\n", "\n"); output = output.replace("\\t", "\t"); output = output.replace("\\\\", "\\"); while ( - (output.startsWith('"') && output.endsWith('"')) || + (output.startsWith("\"") && output.endsWith("\"")) || (output.startsWith("'") && output.endsWith("'")) ) { output = output.slice(1, -1); @@ -120,7 +120,7 @@ export function getUniqueFilePath( } export function shortestRelativePaths(paths: string[]): string[] { - if (paths.length === 0) return []; + if (paths.length === 0) {return [];} const partsLengths = paths.map((x) => x.split(SEP_REGEX).length); const currentRelativePaths = paths.map(getBasename); @@ -135,7 +135,7 @@ export function shortestRelativePaths(paths: string[]): string[] { const firstDuplicatedPath = currentRelativePaths.find( (x, i) => isDuplicated[i], ); - if (!firstDuplicatedPath) break; + if (!firstDuplicatedPath) {break;} currentRelativePaths.forEach((x, i) => { if (x === firstDuplicatedPath) { diff --git a/core/util/messenger.ts b/core/util/messenger.ts index 416e4e8dab..2b0593ef38 100644 --- a/core/util/messenger.ts +++ b/core/util/messenger.ts @@ -75,7 +75,7 @@ export class InProcessMessenger< messageId?: string, ): ToProtocol[T][1] { const listener = this.myTypeListeners.get(messageType); - if (!listener) return; + if (!listener) {return;} const msg: Message = { messageType: messageType as string,