From 1d289383c60ef110239e756d71434f8bd093ba5f Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Sun, 28 Jan 2024 17:47:01 -0800 Subject: [PATCH 01/31] =?UTF-8?q?=F0=9F=9A=A7=20ChunkCodebaseIndex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .continueignore | 3 +- core/indexing/LanceDbIndex.ts | 6 +- core/indexing/chunk/ChunkCodebaseIndex.ts | 127 ++++++++++++++++++++ core/indexing/refreshIndex.ts | 4 + extensions/vscode/src/util/indexCodebase.ts | 11 +- 5 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 core/indexing/chunk/ChunkCodebaseIndex.ts diff --git a/.continueignore b/.continueignore index 4f17aba35..1086d8297 100644 --- a/.continueignore +++ b/.continueignore @@ -1,2 +1,3 @@ **/*.run.xml -archive/**/* \ No newline at end of file +archive/**/* +extensions/vscode/models/**/* \ No newline at end of file diff --git a/core/indexing/LanceDbIndex.ts b/core/indexing/LanceDbIndex.ts index fbeecc25f..792c01fd4 100644 --- a/core/indexing/LanceDbIndex.ts +++ b/core/indexing/LanceDbIndex.ts @@ -6,7 +6,7 @@ import { MAX_CHUNK_SIZE } from "../llm/constants"; import { getBasename } from "../util"; import { getLanceDbPath } from "../util/paths"; import { chunkDocument } from "./chunk/chunk"; -import { DatabaseConnection, SqliteDb } from "./refreshIndex"; +import { DatabaseConnection, SqliteDb, tagToString } from "./refreshIndex"; import { CodebaseIndex, IndexResultType, @@ -15,10 +15,6 @@ import { RefreshIndexResults, } from "./types"; -export function tagToString(tag: IndexTag): string { - return `${tag.directory}::${tag.branch}::${tag.artifactId}`; -} - // LanceDB converts to lowercase, so names must all be lowercase interface LanceDbRow { uuid: string; diff --git a/core/indexing/chunk/ChunkCodebaseIndex.ts b/core/indexing/chunk/ChunkCodebaseIndex.ts new file mode 100644 index 000000000..98d8e25c3 --- /dev/null +++ b/core/indexing/chunk/ChunkCodebaseIndex.ts @@ -0,0 +1,127 @@ +import { IndexingProgressUpdate } from "../.."; +import { MAX_CHUNK_SIZE } from "../../llm/constants"; +import { getBasename } from "../../util"; +import { DatabaseConnection, SqliteDb, tagToString } from "../refreshIndex"; +import { + CodebaseIndex, + IndexResultType, + IndexTag, + MarkCompleteCallback, + RefreshIndexResults, +} from "../types"; +import { chunkDocument } from "./chunk"; + +export class ChunkCodebaseIndex implements CodebaseIndex { + artifactId: string = "chunks"; + + readFile: (filepath: string) => Promise; + constructor(readFile: (filepath: string) => Promise) { + this.readFile = readFile; + } + + private async _createTables(db: DatabaseConnection) { + await db.exec(`CREATE TABLE IF NOT EXISTS chunks ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + cacheKey TEXT NOT NULL, + path TEXT NOT NULL, + idx INTEGER NOT NULL, + startLine INTEGER NOT NULL, + endLine INTEGER NOT NULL, + content TEXT NOT NULL + )`); + + await db.exec(`CREATE TABLE IF NOT EXISTS chunk_tags ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + tag TEXT NOT NULL, + chunkId INTEGER NOT NULL, + FOREIGN KEY (chunkId) REFERENCES chunks (id) + )`); + } + + async *update( + tag: IndexTag, + results: RefreshIndexResults, + markComplete: MarkCompleteCallback + ): AsyncGenerator { + const db = await SqliteDb.get(); + await this._createTables(db); + const tagString = tagToString(tag); + + // Compute chunks for new files + const contents = await Promise.all( + results.compute.map(({ path }) => this.readFile(path)) + ); + for (let i = 0; i < results.compute.length; i++) { + const item = results.compute[i]; + + // Insert chunks + for await (let chunk of chunkDocument( + item.path, + contents[i], + MAX_CHUNK_SIZE, + item.cacheKey + )) { + const { lastID } = await db.run( + `INSERT INTO chunks (cacheKey, path, idx, startLine, endLine, content) VALUES (?, ?, ?, ?, ?, ?)`, + [ + chunk.digest, + chunk.filepath, + chunk.index, + chunk.startLine, + chunk.endLine, + chunk.content, + ] + ); + + await db.run(`INSERT INTO chunk_tags (chunkId, tag) VALUES (?, ?)`, [ + lastID, + tagString, + ]); + } + + yield { + progress: i / results.compute.length, + desc: `Chunking ${getBasename(item.path)}`, + }; + markComplete([item], IndexResultType.Compute); + i++; + } + + // Add tag + for (const item of results.addTag) { + const chunksWithPath = await db.all( + `SELECT * FROM chunks WHERE cacheKey = ?`, + [item.cacheKey] + ); + + for (const chunk of chunksWithPath) { + await db.run(`INSERT INTO chunk_tags (chunkId, tag) VALUES (?, ?)`, [ + chunk.id, + tagString, + ]); + } + + markComplete([item], IndexResultType.AddTag); + } + + // Remove tag + for (const item of results.removeTag) { + await db.run(`DELETE FROM chunk_tags WHERE tag = ?`, [tagString]); + markComplete([item], IndexResultType.RemoveTag); + } + + // Delete + for (const item of results.del) { + const deleted = await db.run(`DELETE FROM chunks WHERE cacheKey = ?`, [ + item.cacheKey, + ]); + + // Delete from chunk_tags + await db.run(`DELETE FROM chunk_tags WHERE chunkId = ?`, [ + deleted.lastID, + ]); + + markComplete([item], IndexResultType.Delete); + } + } +} diff --git a/core/indexing/refreshIndex.ts b/core/indexing/refreshIndex.ts index 94ee72a9f..a37ae0077 100644 --- a/core/indexing/refreshIndex.ts +++ b/core/indexing/refreshIndex.ts @@ -15,6 +15,10 @@ import { export type DatabaseConnection = Database; +export function tagToString(tag: IndexTag): string { + return `${tag.directory}::${tag.branch}::${tag.artifactId}`; +} + export class SqliteDb { static db: DatabaseConnection | null = null; diff --git a/extensions/vscode/src/util/indexCodebase.ts b/extensions/vscode/src/util/indexCodebase.ts index b99899bd9..9a45b6e9e 100644 --- a/extensions/vscode/src/util/indexCodebase.ts +++ b/extensions/vscode/src/util/indexCodebase.ts @@ -1,4 +1,5 @@ import { LanceDbIndex } from "core/indexing/LanceDbIndex"; +import { ChunkCodebaseIndex } from "core/indexing/chunk/ChunkCodebaseIndex"; import { getComputeDeleteAddRemove } from "core/indexing/refreshIndex"; import { CodebaseIndex, IndexTag, LastModifiedMap } from "core/indexing/types"; import * as vscode from "vscode"; @@ -23,11 +24,13 @@ const vscodeGetStats = async ( }; async function getIndexesToBuild(): Promise { - const indexes = []; - const ide = new VsCodeIde(); const config = await configHandler.loadConfig(ide); - indexes.push(new LanceDbIndex(config.embeddingsProvider, ide.readFile)); + + const indexes = [ + new LanceDbIndex(config.embeddingsProvider, ide.readFile), + new ChunkCodebaseIndex(ide.readFile), + ]; return indexes; } @@ -66,7 +69,7 @@ export async function vsCodeIndexCodebase(workspaceDirs: string[]) { (filepath) => ideProtocolClient.readFile(filepath) ); - // console.log("RESULTS: ", results); + console.log("RESULTS: ", codebaseIndex.artifactId, results); for await (let { progress, desc } of codebaseIndex.update( tag, From 539993c456a0f0926091b7b704e59b50e3a94698 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Sun, 28 Jan 2024 18:39:47 -0800 Subject: [PATCH 02/31] =?UTF-8?q?=F0=9F=90=9B=20indexing=20bug=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/indexing/chunk/ChunkCodebaseIndex.ts | 1 - extensions/vscode/src/extension.ts | 1 - extensions/vscode/src/util/indexCodebase.ts | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/core/indexing/chunk/ChunkCodebaseIndex.ts b/core/indexing/chunk/ChunkCodebaseIndex.ts index 98d8e25c3..4ebe5e018 100644 --- a/core/indexing/chunk/ChunkCodebaseIndex.ts +++ b/core/indexing/chunk/ChunkCodebaseIndex.ts @@ -84,7 +84,6 @@ export class ChunkCodebaseIndex implements CodebaseIndex { desc: `Chunking ${getBasename(item.path)}`, }; markComplete([item], IndexResultType.Compute); - i++; } // Add tag diff --git a/extensions/vscode/src/extension.ts b/extensions/vscode/src/extension.ts index 421b6c169..725d09480 100644 --- a/extensions/vscode/src/extension.ts +++ b/extensions/vscode/src/extension.ts @@ -8,7 +8,6 @@ import { getUniqueId } from "./util/vscode"; let client: any = undefined; export async function capture(args: any) { - console.log("Capturing posthog event: ", args); if (!client) { const { PostHog } = await import("posthog-node"); client = new PostHog("phc_JS6XFROuNbhJtVCEdTSYk6gl5ArRrTNMpCcguAXlSPs", { diff --git a/extensions/vscode/src/util/indexCodebase.ts b/extensions/vscode/src/util/indexCodebase.ts index 9a45b6e9e..b43e9a30b 100644 --- a/extensions/vscode/src/util/indexCodebase.ts +++ b/extensions/vscode/src/util/indexCodebase.ts @@ -65,7 +65,7 @@ export async function vsCodeIndexCodebase(workspaceDirs: string[]) { }; const [results, markComplete] = await getComputeDeleteAddRemove( tag, - stats, + { ...stats }, (filepath) => ideProtocolClient.readFile(filepath) ); From aae4c0c5e0ea1bae0e0fdff9eb25fdf14db06b55 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Sun, 28 Jan 2024 20:08:04 -0800 Subject: [PATCH 03/31] =?UTF-8?q?=E2=9C=A8=20FullTextSearchCodebaseIndex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/indexing/FullTextSearch.ts | 125 ++++++++++++++++++++ extensions/vscode/src/util/indexCodebase.ts | 4 +- 2 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 core/indexing/FullTextSearch.ts diff --git a/core/indexing/FullTextSearch.ts b/core/indexing/FullTextSearch.ts new file mode 100644 index 000000000..63dc54178 --- /dev/null +++ b/core/indexing/FullTextSearch.ts @@ -0,0 +1,125 @@ +import { Chunk, IndexingProgressUpdate } from ".."; +import { DatabaseConnection, SqliteDb, tagToString } from "./refreshIndex"; +import { + CodebaseIndex, + IndexResultType, + IndexTag, + MarkCompleteCallback, + RefreshIndexResults, +} from "./types"; + +export class FullTextSearchCodebaseIndex implements CodebaseIndex { + artifactId: string = "sqliteFts"; + + private async _createTables(db: DatabaseConnection) { + await db.exec(`CREATE VIRTUAL TABLE IF NOT EXISTS fts USING fts5( + path, + content + )`); + + await db.exec(`CREATE TABLE IF NOT EXISTS fts_metadata ( + id INTEGER PRIMARY KEY, + path TEXT NOT NULL, + cacheKey TEXT NOT NULL, + chunkId INTEGER NOT NULL, + FOREIGN KEY (chunkId) REFERENCES chunks (id), + FOREIGN KEY (id) REFERENCES fts (rowid) + )`); + } + + async *update( + tag: IndexTag, + results: RefreshIndexResults, + markComplete: MarkCompleteCallback + ): AsyncGenerator { + const db = await SqliteDb.get(); + await this._createTables(db); + + for (let i = 0; i < results.compute.length; i++) { + const item = results.compute[i]; + + // Insert chunks + const chunks = await db.all( + `SELECT * FROM chunks WHERE path = ? AND cacheKey = ?`, + [item.path, item.cacheKey] + ); + + for (let chunk of chunks) { + const { lastID } = await db.run( + `INSERT INTO fts (path, content) VALUES (?, ?)`, + [item.path, chunk.content] + ); + await db.run( + `INSERT INTO fts_metadata (id, path, cacheKey, chunkId) VALUES (?, ?, ?)`, + [lastID, item.path, item.cacheKey, chunk.id] + ); + } + + yield { + progress: i / results.compute.length, + desc: `Indexing ${item.path}`, + }; + markComplete([item], IndexResultType.Compute); + } + + // Add tag + for (const item of results.addTag) { + markComplete([item], IndexResultType.AddTag); + } + + // Remove tag + for (const item of results.removeTag) { + markComplete([item], IndexResultType.RemoveTag); + } + + // Delete + for (const item of results.del) { + const { lastID } = await db.run( + `DELETE FROM fts_metadata WHERE path = ? AND cacheKey = ?`, + [item.path, item.cacheKey] + ); + await db.run(`DELETE FROM fts WHERE rowid = ?`, [lastID]); + + markComplete([item], IndexResultType.Delete); + } + } + + async retrieve( + tags: IndexTag[], + text: string, + n: number, + directory: string | undefined + ): Promise { + const db = await SqliteDb.get(); + const tagStrings = tags.map(tagToString); + + const results = await db.all( + `SELECT fts_metadata.chunkId + FROM fts + JOIN fts_metadata ON fts.rowid = fts_metadata.id + JOIN chunk_tags ON fts_metadata.chunkId = chunk_tags.chunkId + WHERE fts MATCH ? AND filtered_chunk_tags.tag IN (${tagStrings + .map(() => "?") + .join(",")}) + ORDER BY rank + LIMIT ?`, + [text, ...tagStrings, n] + ); + + const chunks = await db.all( + `SELECT * FROM chunks WHERE id IN (${results.map(() => "?").join(",")})`, + results.map((result) => result.chunkId) + ); + + return chunks.map((chunk) => { + return { + filepath: chunk.path, + index: chunk.index, + startLine: chunk.startLine, + endLine: chunk.endLine, + content: chunk.content, + digest: chunk.cacheKey, + }; + }); + } +} diff --git a/extensions/vscode/src/util/indexCodebase.ts b/extensions/vscode/src/util/indexCodebase.ts index b43e9a30b..8b21cbcd1 100644 --- a/extensions/vscode/src/util/indexCodebase.ts +++ b/extensions/vscode/src/util/indexCodebase.ts @@ -1,3 +1,4 @@ +import { FullTextSearchCodebaseIndex } from "core/indexing/FullTextSearch"; import { LanceDbIndex } from "core/indexing/LanceDbIndex"; import { ChunkCodebaseIndex } from "core/indexing/chunk/ChunkCodebaseIndex"; import { getComputeDeleteAddRemove } from "core/indexing/refreshIndex"; @@ -28,8 +29,9 @@ async function getIndexesToBuild(): Promise { const config = await configHandler.loadConfig(ide); const indexes = [ + new ChunkCodebaseIndex(ide.readFile), // Chunking must come first new LanceDbIndex(config.embeddingsProvider, ide.readFile), - new ChunkCodebaseIndex(ide.readFile), + new FullTextSearchCodebaseIndex(), ]; return indexes; From b71b2b05aa70b9cde24ab5e0acfb6758f52fdeb3 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Sun, 28 Jan 2024 22:39:49 -0800 Subject: [PATCH 04/31] =?UTF-8?q?=F0=9F=9A=A7=20constructing=20query=20for?= =?UTF-8?q?=20fts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../providers/CodebaseContextProvider.ts | 2 +- .../providers/FolderContextProvider.ts | 2 +- core/context/retrieval.ts | 23 +++++++++++++++++ core/ide/filesystem.ts | 4 +++ core/ide/index.ts | 4 +++ core/index.d.ts | 1 + core/indexing/FullTextSearch.ts | 25 ++++++++++--------- core/indexing/chunk/ChunkCodebaseIndex.ts | 3 ++- extensions/vscode/src/debugPanel.ts | 5 ++++ extensions/vscode/src/ideProtocol.ts | 4 +++ 10 files changed, 58 insertions(+), 15 deletions(-) diff --git a/core/context/providers/CodebaseContextProvider.ts b/core/context/providers/CodebaseContextProvider.ts index c79d8cc60..5c31fcc67 100644 --- a/core/context/providers/CodebaseContextProvider.ts +++ b/core/context/providers/CodebaseContextProvider.ts @@ -4,7 +4,6 @@ import { ContextProviderDescription, ContextProviderExtras, } from "../.."; -import { retrieveContextItemsFromEmbeddings } from "../retrieval"; class CodebaseContextProvider extends BaseContextProvider { static description: ContextProviderDescription = { @@ -18,6 +17,7 @@ class CodebaseContextProvider extends BaseContextProvider { query: string, extras: ContextProviderExtras ): Promise { + const { retrieveContextItemsFromEmbeddings } = await import("../retrieval"); return retrieveContextItemsFromEmbeddings(extras, this.options, undefined); } async load(): Promise {} diff --git a/core/context/providers/FolderContextProvider.ts b/core/context/providers/FolderContextProvider.ts index 10ad971d5..81955cb1e 100644 --- a/core/context/providers/FolderContextProvider.ts +++ b/core/context/providers/FolderContextProvider.ts @@ -7,7 +7,6 @@ import { LoadSubmenuItemsArgs, } from "../.."; import { getBasename, getLastNPathParts } from "../../util"; -import { retrieveContextItemsFromEmbeddings } from "../retrieval"; class FolderContextProvider extends BaseContextProvider { static description: ContextProviderDescription = { @@ -21,6 +20,7 @@ class FolderContextProvider extends BaseContextProvider { query: string, extras: ContextProviderExtras ): Promise { + const { retrieveContextItemsFromEmbeddings } = await import("../retrieval"); return retrieveContextItemsFromEmbeddings(extras, this.options, query); } async loadSubmenuItems( diff --git a/core/context/retrieval.ts b/core/context/retrieval.ts index 3a405691f..26bdc4e6b 100644 --- a/core/context/retrieval.ts +++ b/core/context/retrieval.ts @@ -5,6 +5,9 @@ import { ILLM, ModelProvider, } from ".."; +import { FullTextSearchCodebaseIndex } from "../indexing/FullTextSearch"; +import { ChunkCodebaseIndex } from "../indexing/chunk/ChunkCodebaseIndex"; +import { IndexTag } from "../indexing/types"; import { getBasename } from "../util"; const RERANK_PROMPT = ( @@ -146,6 +149,26 @@ export async function retrieveContextItemsFromEmbeddings( filterDirectory ); + const ftsIndex = new FullTextSearchCodebaseIndex(); + const workspaceDirs = await extras.ide.getWorkspaceDirs(); + const branches = await Promise.all( + workspaceDirs.map((dir) => extras.ide.getBranch(dir)) + ); + const tags: IndexTag[] = workspaceDirs.map((directory, i) => ({ + directory, + branch: branches[i], + artifactId: ChunkCodebaseIndex.artifactId, + })); + let ftsResults = await ftsIndex.retrieve( + tags, + extras.fullInput.trim().split(" ").join(" OR "), + nRetrieve, + filterDirectory + ); + + console.log("SIM RESULTS: ", results); + console.log("FTS RESULTS: ", ftsResults); + // Re-ranking if (useReranking) { results = await rerank(results, extras.llm, extras.fullInput, nFinal); diff --git a/core/ide/filesystem.ts b/core/ide/filesystem.ts index 2635a05cb..06d4e8c76 100644 --- a/core/ide/filesystem.ts +++ b/core/ide/filesystem.ts @@ -94,6 +94,10 @@ class FileSystemIde implements IDE { return Promise.resolve(); } + getBranch(dir: string): Promise { + return Promise.resolve(""); + } + async verticalDiffUpdate( filepath: string, startLine: number, diff --git a/core/ide/index.ts b/core/ide/index.ts index 66e865775..58647bfbf 100644 --- a/core/ide/index.ts +++ b/core/ide/index.ts @@ -112,6 +112,10 @@ export class ExtensionIde implements IDE { return r("sendChunkForFile", { chunk, embedding, tags }); } + async getBranch(dir: string): Promise { + return r("getBranch", { dir }); + } + retrieveChunks( text: string, n: number, diff --git a/core/index.d.ts b/core/index.d.ts index ffa22973e..d22a3c9a5 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -316,6 +316,7 @@ export interface IDE { getSearchResults(query: string): Promise; subprocess(command: string): Promise<[string, string]>; getProblems(filepath?: string | undefined): Promise; + getBranch(dir: string): Promise; // Embeddings /** diff --git a/core/indexing/FullTextSearch.ts b/core/indexing/FullTextSearch.ts index 63dc54178..6688174ac 100644 --- a/core/indexing/FullTextSearch.ts +++ b/core/indexing/FullTextSearch.ts @@ -14,7 +14,8 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex { private async _createTables(db: DatabaseConnection) { await db.exec(`CREATE VIRTUAL TABLE IF NOT EXISTS fts USING fts5( path, - content + content, + tokenize = 'trigram' )`); await db.exec(`CREATE TABLE IF NOT EXISTS fts_metadata ( @@ -50,7 +51,7 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex { [item.path, chunk.content] ); await db.run( - `INSERT INTO fts_metadata (id, path, cacheKey, chunkId) VALUES (?, ?, ?)`, + `INSERT INTO fts_metadata (id, path, cacheKey, chunkId) VALUES (?, ?, ?, ?)`, [lastID, item.path, item.cacheKey, chunk.id] ); } @@ -94,16 +95,16 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex { const tagStrings = tags.map(tagToString); const results = await db.all( - `SELECT fts_metadata.chunkId - FROM fts - JOIN fts_metadata ON fts.rowid = fts_metadata.id - JOIN chunk_tags ON fts_metadata.chunkId = chunk_tags.chunkId - WHERE fts MATCH ? AND filtered_chunk_tags.tag IN (${tagStrings - .map(() => "?") - .join(",")}) - ORDER BY rank - LIMIT ?`, - [text, ...tagStrings, n] + `SELECT fts_metadata.chunkId, fts_metadata.path, fts.content, rank + FROM fts + JOIN fts_metadata ON fts.rowid = fts_metadata.id + JOIN chunk_tags ON fts_metadata.chunkId = chunk_tags.chunkId + WHERE fts MATCH '${text}' AND chunk_tags.tag IN (${tagStrings + .map(() => "?") + .join(",")}) + ORDER BY rank + LIMIT ?`, + [...tagStrings, n] ); const chunks = await db.all( diff --git a/core/indexing/chunk/ChunkCodebaseIndex.ts b/core/indexing/chunk/ChunkCodebaseIndex.ts index 4ebe5e018..477328365 100644 --- a/core/indexing/chunk/ChunkCodebaseIndex.ts +++ b/core/indexing/chunk/ChunkCodebaseIndex.ts @@ -12,7 +12,8 @@ import { import { chunkDocument } from "./chunk"; export class ChunkCodebaseIndex implements CodebaseIndex { - artifactId: string = "chunks"; + static artifactId: string = "chunks"; + artifactId: string = ChunkCodebaseIndex.artifactId; readFile: (filepath: string) => Promise; constructor(readFile: (filepath: string) => Promise) { diff --git a/extensions/vscode/src/debugPanel.ts b/extensions/vscode/src/debugPanel.ts index bb00e42ed..71fb09053 100644 --- a/extensions/vscode/src/debugPanel.ts +++ b/extensions/vscode/src/debugPanel.ts @@ -428,6 +428,11 @@ export function getSidebarContent( respond(await ide.getProblems(data.message.filepath)); break; } + case "getBranch": { + const { dir } = data.message; + respond(await ide.getBranch(dir)); + break; + } case "getOpenFiles": { respond(await ide.getOpenFiles()); break; diff --git a/extensions/vscode/src/ideProtocol.ts b/extensions/vscode/src/ideProtocol.ts index 955a7dd04..83c63f6b7 100644 --- a/extensions/vscode/src/ideProtocol.ts +++ b/extensions/vscode/src/ideProtocol.ts @@ -416,6 +416,10 @@ class VsCodeIde implements IDE { }); } + async getBranch(dir: string): Promise { + return ideProtocolClient.getBranch(vscode.Uri.file(dir)); + } + async getFilesToEmbed( providerId: string ): Promise<[string, string, string][]> { From 5aa1ec0fe6819df5722e05a57f51edb94c889be9 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 29 Jan 2024 17:53:11 -0800 Subject: [PATCH 05/31] =?UTF-8?q?=F0=9F=A9=B9=20don't=20show=20inline=20ti?= =?UTF-8?q?ps=20in=20output=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/src/activation/inlineTips.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/extensions/vscode/src/activation/inlineTips.ts b/extensions/vscode/src/activation/inlineTips.ts index 9f78b8c3e..ffd4c663d 100644 --- a/extensions/vscode/src/activation/inlineTips.ts +++ b/extensions/vscode/src/activation/inlineTips.ts @@ -13,6 +13,11 @@ const inlineTipDecoration = vscode.window.createTextEditorDecorationType({ function handleSelectionChange(e: vscode.TextEditorSelectionChangeEvent) { const selection = e.selections[0]; const editor = e.textEditor; + + if (editor.document.uri.toString() === "output:tasks") { + return; + } + if ( selection.isEmpty || vscode.workspace @@ -69,6 +74,10 @@ export function setupInlineTips(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.window.onDidChangeActiveTextEditor((editor) => { if (editor?.document.getText() === "") { + if (editor.document.uri.toString() === "output:tasks") { + return; + } + editor.setDecorations(emptyFileTooltipDecoration, [ { range: new vscode.Range( From 75fbdd97412da99f317ad705a4dcff8c1abb439d Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 29 Jan 2024 18:18:39 -0800 Subject: [PATCH 06/31] =?UTF-8?q?=F0=9F=94=A7=20small=20improvements=20to?= =?UTF-8?q?=20context=20menus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/package-lock.json | 4 +- extensions/vscode/package.json | 78 ++++++++++++++----- .../vscode/src/activation/inlineTips.ts | 4 +- 3 files changed, 63 insertions(+), 23 deletions(-) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index f8d3d738c..599e8b606 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.8.7", + "version": "0.9.36", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.8.7", + "version": "0.9.36", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 5b7b64262..5b63435a6 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -1,7 +1,7 @@ { "name": "continue", "icon": "media/icon.png", - "version": "0.8.7", + "version": "0.9.36", "repository": { "type": "git", "url": "https://github.com/continuedev/continue" @@ -73,90 +73,107 @@ { "command": "continue.acceptDiff", "category": "Continue", - "title": "Accept Diff" + "title": "Accept Diff", + "group": "Continue" }, { "command": "continue.rejectDiff", "category": "Continue", - "title": "Reject Diff" + "title": "Reject Diff", + "group": "Continue" }, { "command": "continue.quickEdit", "category": "Continue", - "title": "Quick Edit" + "title": "Quick Edit", + "group": "Continue" }, { "command": "continue.toggleAuxiliaryBar", "category": "Continue", - "title": "Toggle Right Sidebar" + "title": "Toggle Right Sidebar", + "group": "Continue" }, { "command": "continue.focusContinueInput", "category": "Continue", - "title": "Add Highlighted Code to Context" + "title": "Add Highlighted Code to Context", + "group": "Continue" }, { "command": "continue.focusContinueInputWithoutClear", "category": "Continue", - "title": "Add Highlighted Code to Context" + "title": "Add Highlighted Code to Context", + "group": "Continue" }, { "command": "continue.debugTerminal", "category": "Continue", - "title": "Debug Terminal" + "title": "Debug Terminal", + "group": "Continue" }, { "command": "continue.toggleFullScreen", "category": "Continue", "title": "Toggle Full Screen", - "icon": "$(fullscreen)" + "icon": "$(fullscreen)", + "group": "Continue" }, { "command": "continue.shareSession", "category": "Continue", - "title": "Share Session" + "title": "Share Session", + "group": "Continue" }, { "command": "continue.selectFilesAsContext", "category": "Continue", - "title": "Continue: Select Files as Context" + "title": "Continue: Select Files as Context", + "group": "Continue" }, { "command": "continue.newSession", "category": "Continue", "title": "New Session", - "icon": "$(add)" + "icon": "$(add)", + "group": "Continue" }, { "command": "continue.viewHistory", "category": "Continue", "title": "View History", - "icon": "$(history)" + "icon": "$(history)", + "group": "Continue" }, { "command": "continue.writeCommentsForCode", "category": "Continue", - "title": "Write Comments for this Code" + "title": "Write Comments for this Code", + "group": "Continue" }, { "command": "continue.writeDocstringForCode", "category": "Continue", - "title": "Write a Docstring for this Code" + "title": "Write a Docstring for this Code", + "group": "Continue" }, { "command": "continue.fixCode", "category": "Continue", - "title": "Fix this Code" + "title": "Fix this Code", + "group": "Continue" }, { "command": "continue.optimizeCode", "category": "Continue", - "title": "Optimize this Code" + "title": "Optimize this Code", + "group": "Continue" }, { "command": "continue.fixGrammar", "category": "Continue", - "title": "Fix Grammar / Spelling" + "title": "Fix Grammar / Spelling", + "group": "Continue" } ], "keybindings": [ @@ -209,6 +226,29 @@ } ], "menus": { + "commandPalette": [ + { + "command": "continue.quickEdit" + }, + { + "command": "continue.toggleAuxiliaryBar" + }, + { + "command": "continue.focusContinueInput" + }, + { + "command": "continue.focusContinueInputWithoutClear" + }, + { + "command": "continue.debugTerminal" + }, + { + "command": "continue.toggleFullScreen" + }, + { + "command": "continue.newSession" + } + ], "webview/context": [ { "command": "continue.shareSession", @@ -218,7 +258,7 @@ "editor/context": [ { "submenu": "continue.continueSubMenu", - "group": "1_debug@1" + "group": "0_acontinue" } ], "continue.continueSubMenu": [ diff --git a/extensions/vscode/src/activation/inlineTips.ts b/extensions/vscode/src/activation/inlineTips.ts index ffd4c663d..fa7c33576 100644 --- a/extensions/vscode/src/activation/inlineTips.ts +++ b/extensions/vscode/src/activation/inlineTips.ts @@ -14,7 +14,7 @@ function handleSelectionChange(e: vscode.TextEditorSelectionChangeEvent) { const selection = e.selections[0]; const editor = e.textEditor; - if (editor.document.uri.toString() === "output:tasks") { + if (editor.document.uri.toString().startsWith("output:")) { return; } @@ -74,7 +74,7 @@ export function setupInlineTips(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.window.onDidChangeActiveTextEditor((editor) => { if (editor?.document.getText() === "") { - if (editor.document.uri.toString() === "output:tasks") { + if (editor.document.uri.toString().startsWith("output:")) { return; } From a5d37bacdb17ecc82c30ffac195489767b40a7cc Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 29 Jan 2024 20:04:39 -0800 Subject: [PATCH 07/31] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20improvements=20to=20?= =?UTF-8?q?codebase=20retrieval=20with=20FTS5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/commands/util.ts | 4 +- core/context/retrieval.ts | 38 +++++++++++++------ core/ide/filesystem.ts | 7 ++++ core/ide/index.ts | 8 ++++ core/index.d.ts | 5 +++ core/indexing/FullTextSearch.ts | 19 +++++++--- extensions/vscode/src/continueIdeClient.ts | 4 +- extensions/vscode/src/debugPanel.ts | 24 +++--------- extensions/vscode/src/ideProtocol.ts | 22 ++++++++++- .../components/mainInput/ContextItemsPeek.tsx | 8 +++- .../markdown/CodeSnippetPreview.tsx | 11 +++--- .../markdown/StyledMarkdownPreview.tsx | 5 ++- 12 files changed, 107 insertions(+), 48 deletions(-) diff --git a/core/commands/util.ts b/core/commands/util.ts index 17e0151f0..e9ec5943d 100644 --- a/core/commands/util.ts +++ b/core/commands/util.ts @@ -15,10 +15,10 @@ export function contextItemToRangeInFileWithContents( const lines = item.name.split("(")[1].split(")")[0].split("-"); const rif: RangeInFileWithContents = { - filepath: item.description, + filepath: item.description.split(" (")[0], range: { start: { - line: parseInt(lines[0]) - 1, + line: parseInt(lines[0]), character: 0, }, end: { diff --git a/core/context/retrieval.ts b/core/context/retrieval.ts index 26bdc4e6b..53efd5579 100644 --- a/core/context/retrieval.ts +++ b/core/context/retrieval.ts @@ -136,18 +136,11 @@ export async function retrieveContextItemsFromEmbeddings( return []; } - const nRetrieve = options?.nRetrieve || 20; - const nFinal = options?.nFinal || 8; + const nFinal = options?.nFinal || 10; const useReranking = llmCanGenerateInParallel(extras.llm) && (options?.useReranking === undefined ? false : options?.useReranking); - - // Similarity search - let results = await extras.ide.retrieveChunks( - extras.fullInput, - useReranking === false ? nFinal : nRetrieve, - filterDirectory - ); + const nRetrieve = useReranking === false ? nFinal : options?.nRetrieve || 20; const ftsIndex = new FullTextSearchCodebaseIndex(); const workspaceDirs = await extras.ide.getWorkspaceDirs(); @@ -159,15 +152,38 @@ export async function retrieveContextItemsFromEmbeddings( branch: branches[i], artifactId: ChunkCodebaseIndex.artifactId, })); + let ftsResults = await ftsIndex.retrieve( tags, extras.fullInput.trim().split(" ").join(" OR "), + nRetrieve / 2, + filterDirectory, + undefined + ); + + let vecResults = await extras.ide.retrieveChunks( + extras.fullInput, nRetrieve, filterDirectory ); - console.log("SIM RESULTS: ", results); - console.log("FTS RESULTS: ", ftsResults); + // Now combine these (de-duplicate) and re-rank + let results = [...ftsResults]; + for (const vecResult of vecResults) { + if (results.length >= nRetrieve) { + break; + } + if ( + !ftsResults.find( + (r) => + r.filepath === vecResult.filepath && + r.startLine === vecResult.startLine && + r.endLine === vecResult.endLine + ) + ) { + results.push(vecResult); + } + } // Re-ranking if (useReranking) { diff --git a/core/ide/filesystem.ts b/core/ide/filesystem.ts index 06d4e8c76..ad79c7e1f 100644 --- a/core/ide/filesystem.ts +++ b/core/ide/filesystem.ts @@ -28,6 +28,13 @@ class FileSystemIde implements IDE { getTerminalContents(): Promise { return Promise.resolve(""); } + showLines( + filepath: string, + startLine: number, + endLine: number + ): Promise { + return Promise.resolve(); + } listWorkspaceContents(): Promise { return new Promise((resolve, reject) => { fs.readdir("/tmp/continue", (err, files) => { diff --git a/core/ide/index.ts b/core/ide/index.ts index 58647bfbf..02c808634 100644 --- a/core/ide/index.ts +++ b/core/ide/index.ts @@ -30,6 +30,14 @@ export class ExtensionIde implements IDE { return await r("getWorkspaceDirs"); } + async showLines( + filepath: string, + startLine: number, + endLine: number + ): Promise { + return await r("showLines", { filepath, startLine, endLine }); + } + async listFolders(): Promise { return await r("listFolders"); } diff --git a/core/index.d.ts b/core/index.d.ts index d22a3c9a5..40a577a04 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -300,6 +300,11 @@ export interface IDE { runCommand(command: string): Promise; saveFile(filepath: string): Promise; readFile(filepath: string): Promise; + showLines( + filepath: string, + startLine: number, + endLine: number + ): Promise; showDiff( filepath: string, newContents: string, diff --git a/core/indexing/FullTextSearch.ts b/core/indexing/FullTextSearch.ts index 6688174ac..c7720bbf5 100644 --- a/core/indexing/FullTextSearch.ts +++ b/core/indexing/FullTextSearch.ts @@ -89,7 +89,8 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex { tags: IndexTag[], text: string, n: number, - directory: string | undefined + directory: string | undefined, + filterPaths: string[] | undefined ): Promise { const db = await SqliteDb.get(); const tagStrings = tags.map(tagToString); @@ -99,12 +100,20 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex { FROM fts JOIN fts_metadata ON fts.rowid = fts_metadata.id JOIN chunk_tags ON fts_metadata.chunkId = chunk_tags.chunkId - WHERE fts MATCH '${text}' AND chunk_tags.tag IN (${tagStrings - .map(() => "?") - .join(",")}) + WHERE fts MATCH '${text.replace( + /\?/g, + "" + )}' AND chunk_tags.tag IN (${tagStrings.map(() => "?").join(",")}) + ${ + filterPaths + ? `AND fts_metadata.path IN (${filterPaths + .map(() => "?") + .join(",")})` + : "" + } ORDER BY rank LIMIT ?`, - [...tagStrings, n] + [...tagStrings, ...(filterPaths || []), n] ); const chunks = await db.all( diff --git a/extensions/vscode/src/continueIdeClient.ts b/extensions/vscode/src/continueIdeClient.ts index 2f083f3bd..38cb966cc 100644 --- a/extensions/vscode/src/continueIdeClient.ts +++ b/extensions/vscode/src/continueIdeClient.ts @@ -233,9 +233,9 @@ class IdeProtocolClient { panel.webview.html = getSidebarContent(panel, "/monaco", edits); } - openFile(filepath: string) { + openFile(filepath: string, range?: vscode.Range) { // vscode has a builtin open/get open files - openEditorAndRevealRange(filepath, undefined, vscode.ViewColumn.One); + return openEditorAndRevealRange(filepath, range, vscode.ViewColumn.One); } async fileExists(filepath: string): Promise { diff --git a/extensions/vscode/src/debugPanel.ts b/extensions/vscode/src/debugPanel.ts index 71fb09053..ccb28c435 100644 --- a/extensions/vscode/src/debugPanel.ts +++ b/extensions/vscode/src/debugPanel.ts @@ -211,25 +211,6 @@ export function getSidebarContent( }); break; } - case "showLines": { - ideProtocolClient.highlightCode( - { - filepath: data.filepath, - range: { - start: { - line: data.start, - character: 0, - }, - end: { - line: data.end, - character: 0, - }, - }, - }, - "#00ff0022" - ); - break; - } case "toggleDevTools": { vscode.commands.executeCommand("workbench.action.toggleDevTools"); vscode.commands.executeCommand("continue.viewLogs"); @@ -441,6 +422,11 @@ export function getSidebarContent( respond(await ide.getPinnedFiles()); break; } + case "showLines": { + const { filepath, startLine, endLine } = data.message; + respond(await ide.showLines(filepath, startLine, endLine)); + break; + } // Other case "errorPopup": { vscode.window diff --git a/extensions/vscode/src/ideProtocol.ts b/extensions/vscode/src/ideProtocol.ts index 83c63f6b7..7c6f38916 100644 --- a/extensions/vscode/src/ideProtocol.ts +++ b/extensions/vscode/src/ideProtocol.ts @@ -31,7 +31,7 @@ import { verticalPerLineDiffManager } from "./diff/verticalPerLine/manager"; import { configHandler } from "./loadConfig"; import mergeJson from "./util/merge"; import { traverseDirectory } from "./util/traverseDirectory"; -import { getExtensionUri } from "./util/vscode"; +import { getExtensionUri, openEditorAndRevealRange } from "./util/vscode"; async function buildConfigTs(browser: boolean) { if (!fs.existsSync(getConfigTsPath())) { @@ -295,6 +295,26 @@ class VsCodeIde implements IDE { ideProtocolClient.openFile(path); } + async showLines( + filepath: string, + startLine: number, + endLine: number + ): Promise { + const range = new vscode.Range( + new vscode.Position(startLine, 0), + new vscode.Position(endLine, 0) + ); + openEditorAndRevealRange(filepath, range).then(() => { + ideProtocolClient.highlightCode( + { + filepath, + range, + }, + "#fff1" + ); + }); + } + async runCommand(command: string): Promise { await ideProtocolClient.runCommand(command); } diff --git a/gui/src/components/mainInput/ContextItemsPeek.tsx b/gui/src/components/mainInput/ContextItemsPeek.tsx index bdf99d708..466700495 100644 --- a/gui/src/components/mainInput/ContextItemsPeek.tsx +++ b/gui/src/components/mainInput/ContextItemsPeek.tsx @@ -1,5 +1,6 @@ import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline"; import { ContextItemWithId } from "core"; +import { contextItemToRangeInFileWithContents } from "core/commands/util"; import { ExtensionIde } from "core/ide"; import React from "react"; import styled from "styled-components"; @@ -46,8 +47,11 @@ const ContextItemsPeek = (props: ContextItemsPeekProps) => { contextItem.description.startsWith("/") || contextItem.description.startsWith("\\") ) { - new ExtensionIde().openFile( - contextItem.description.split(" ").shift() || "" + const rif = contextItemToRangeInFileWithContents(contextItem); + new ExtensionIde().showLines( + rif.filepath, + rif.range.start.line, + rif.range.end.line ); } else { new ExtensionIde().showVirtualFile(contextItem.name, contextItem.content); diff --git a/gui/src/components/markdown/CodeSnippetPreview.tsx b/gui/src/components/markdown/CodeSnippetPreview.tsx index 646764b5e..3f2a2adfa 100644 --- a/gui/src/components/markdown/CodeSnippetPreview.tsx +++ b/gui/src/components/markdown/CodeSnippetPreview.tsx @@ -5,6 +5,7 @@ import { XMarkIcon, } from "@heroicons/react/24/outline"; import { ContextItemWithId } from "core"; +import { ExtensionIde } from "core/ide"; import { getMarkdownLanguageTagForFile } from "core/util"; import React from "react"; import { useDispatch } from "react-redux"; @@ -97,11 +98,11 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) { .split("(")[1] .split(")")[0] .split("-"); - postToIde("showLines", { - filepath: props.item.description, - start: parseInt(lines[0]) - 1, - end: parseInt(lines[1]) - 1, - }); + new ExtensionIde().showLines( + props.item.description, + parseInt(lines[0]) - 1, + parseInt(lines[1]) - 1 + ); } else { postToIde("showVirtualFile", { name: props.item.name, diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index 6e7b3333d..ec26ba2ed 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -74,7 +74,10 @@ const StyledMarkdown = styled.div<{ padding-right: 8px; color: ${vscForeground}; - p { + p, + li, + ol, + ul { line-height: 1.5; } `; From 76da2714e6128a75c9c30990ef2fb33ea7e72a94 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 29 Jan 2024 21:05:02 -0800 Subject: [PATCH 08/31] =?UTF-8?q?=F0=9F=A9=B9=20fix=20inline=20tips=20show?= =?UTF-8?q?ing=20up=20when=20inline=20chat=20closed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/src/activation/inlineTips.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extensions/vscode/src/activation/inlineTips.ts b/extensions/vscode/src/activation/inlineTips.ts index 9f78b8c3e..de5412002 100644 --- a/extensions/vscode/src/activation/inlineTips.ts +++ b/extensions/vscode/src/activation/inlineTips.ts @@ -83,6 +83,9 @@ export function setupInlineTips(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.workspace.onDidChangeTextDocument((e) => { + if (e.document.uri.toString().startsWith("vscode://inline-chat")) { + return; + } if (e.document.getText() === "") { vscode.window.visibleTextEditors.forEach((editor) => { editor.setDecorations(emptyFileTooltipDecoration, [ From 39e52ed984a66ec80b6a30ac68c7d5bf5ecf4971 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 29 Jan 2024 21:06:08 -0800 Subject: [PATCH 09/31] =?UTF-8?q?=F0=9F=93=9D=20changelog=20for=20fts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changes/unreleased/Added-20240129-210550.yaml | 4 ++++ extensions/vscode/CHANGELOG.md | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Added-20240129-210550.yaml diff --git a/.changes/unreleased/Added-20240129-210550.yaml b/.changes/unreleased/Added-20240129-210550.yaml new file mode 100644 index 000000000..bcadeee63 --- /dev/null +++ b/.changes/unreleased/Added-20240129-210550.yaml @@ -0,0 +1,4 @@ +project: extensions/vscode +kind: Added +body: Full-text search index for retrieval +time: 2024-01-29T21:05:50.216548-08:00 diff --git a/extensions/vscode/CHANGELOG.md b/extensions/vscode/CHANGELOG.md index 884e51a08..e994fbb99 100644 --- a/extensions/vscode/CHANGELOG.md +++ b/extensions/vscode/CHANGELOG.md @@ -6,6 +6,11 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html), and is generated by [Changie](https://github.com/miniscruff/changie). +Pre-release Changes +### Added +* Image support +* Full-text search index for retrieval + ## v0.8.2 - 2024-01-23 ### Added * Add codellama and gemini to free trial, using new server @@ -14,7 +19,6 @@ and is generated by [Changie](https://github.com/miniscruff/changie). ### Changed * Updates to packaging to download native modules for current platform (lancedb, sqlite, onnxruntime, tree-sitter wasms) * Context providers now run from the extension side (in Node.js instead of browser javascript) -* Image support ## v0.8.1 - 2024-01-08 From 94ed7cad40bc9740736a2e392349784e8e707e83 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 30 Jan 2024 11:35:53 -0800 Subject: [PATCH 10/31] =?UTF-8?q?=F0=9F=90=9B=20create=20ProxyAgent=20if?= =?UTF-8?q?=20'proxy'=20set=20on=20requestOptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/src/loadConfig.ts | 35 ++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/extensions/vscode/src/loadConfig.ts b/extensions/vscode/src/loadConfig.ts index 8b34d0eb7..f430d339d 100644 --- a/extensions/vscode/src/loadConfig.ts +++ b/extensions/vscode/src/loadConfig.ts @@ -1,6 +1,6 @@ import { ContinueConfig, IDE, ILLM } from "core"; import * as fs from "fs"; -import { Agent, fetch } from "undici"; +import { Agent, ProxyAgent, fetch } from "undici"; import { webviewRequest } from "./debugPanel"; import { VsCodeIde, loadFullConfigNode } from "./ideProtocol"; const tls = require("tls"); @@ -62,16 +62,29 @@ export async function llmFromTitle(title?: string): Promise { let timeout = (llm.requestOptions?.timeout || TIMEOUT) * 1000; // measured in ms - const agent = new Agent({ - connect: { - ca, - rejectUnauthorized: llm.requestOptions?.verifySsl, - timeout, - }, - bodyTimeout: timeout, - connectTimeout: timeout, - headersTimeout: timeout, - }); + const agent = + llm.requestOptions?.proxy !== undefined + ? new ProxyAgent({ + connect: { + ca, + rejectUnauthorized: llm.requestOptions?.verifySsl, + timeout, + }, + uri: llm.requestOptions?.proxy, + bodyTimeout: timeout, + connectTimeout: timeout, + headersTimeout: timeout, + }) + : new Agent({ + connect: { + ca, + rejectUnauthorized: llm.requestOptions?.verifySsl, + timeout, + }, + bodyTimeout: timeout, + connectTimeout: timeout, + headersTimeout: timeout, + }); llm._fetch = (input, init) => { const headers: { [key: string]: string } = From ec7f7b6b6a6f8f351004d23a286e75f32d2e8e36 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 30 Jan 2024 19:46:47 +0000 Subject: [PATCH 11/31] =?UTF-8?q?=F0=9F=92=9A=20Update=20package.json=20ve?= =?UTF-8?q?rsion=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/package-lock.json | 4 ++-- extensions/vscode/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 599e8b606..e8d0d6b70 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.36", + "version": "0.9.37", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.36", + "version": "0.9.37", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 5b63435a6..136baa224 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -1,7 +1,7 @@ { "name": "continue", "icon": "media/icon.png", - "version": "0.9.36", + "version": "0.9.37", "repository": { "type": "git", "url": "https://github.com/continuedev/continue" From 2fab0e2cdaf6e1314c7da270ce69a0f4a473e8d7 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 30 Jan 2024 11:51:05 -0800 Subject: [PATCH 12/31] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Ollama=20keep=5Faliv?= =?UTF-8?q?e=20default=20to=2030min?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/llm/llms/Ollama.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/core/llm/llms/Ollama.ts b/core/llm/llms/Ollama.ts index 91103e175..0d454fb59 100644 --- a/core/llm/llms/Ollama.ts +++ b/core/llm/llms/Ollama.ts @@ -104,6 +104,7 @@ class Ollama extends BaseLLM { const finalOptions: any = { model: this._getModel(), raw: true, + keep_alive: 60 * 30, // 30 minutes options: { temperature: options.temperature, top_p: options.topP, From f1ab9bf936dc08f71831e353780fce6feea6505f Mon Sep 17 00:00:00 2001 From: Nate Sesti <33237525+sestinj@users.noreply.github.com> Date: Tue, 30 Jan 2024 13:01:50 -0800 Subject: [PATCH 13/31] =?UTF-8?q?=F0=9F=92=AB=20Documentation=20context=20?= =?UTF-8?q?provider=20(#786)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 💄 image drag and drop improvements * 💄 further improvement to drag/drop hints * 🐛 fix image selector insertion * 🐛 fix dropdown width being larger than window width * 🐛 respect disableIndexing * 🐛 fix context items not refreshing when editing past message * ✨ llava chat template * 🩹 multiple small fixes * 🐛 a few docs crawling fixes * 🔊 log docs url * 🐛 small fixes to DocsContextProvider * 📝 update changelog and docs for DocsContextProvider * 🐛 show new docs in submenu after it is loaded --- .../unreleased/Added-20240130-123143.yaml | 4 ++ "Icon\r" | 0 core/context/providers/DocsContextProvider.ts | 16 +++--- core/indexing/chunk/markdown.ts | 17 +++++- core/indexing/docs/crawl.ts | 52 ++++++++++++++----- core/indexing/docs/db.ts | 2 +- core/indexing/docs/index.ts | 24 +++++++-- docs/docs/customization/context-providers.md | 8 +++ docs/static/schemas/config.json | 2 + extensions/vscode/config_schema.json | 2 + extensions/vscode/src/debugPanel.ts | 6 ++- extensions/vscode/src/util/indexCodebase.ts | 2 - gui/src/App.tsx | 19 +++++-- gui/src/components/dialogs/AddDocsDialog.tsx | 17 +++--- gui/src/components/mainInput/TipTapEditor.tsx | 2 +- gui/src/hooks/useSubmenuContextProviders.tsx | 13 +++++ 16 files changed, 146 insertions(+), 40 deletions(-) create mode 100644 .changes/unreleased/Added-20240130-123143.yaml create mode 100644 "Icon\r" diff --git a/.changes/unreleased/Added-20240130-123143.yaml b/.changes/unreleased/Added-20240130-123143.yaml new file mode 100644 index 000000000..419c65e6b --- /dev/null +++ b/.changes/unreleased/Added-20240130-123143.yaml @@ -0,0 +1,4 @@ +project: extensions/vscode +kind: Added +body: Docs context provider +time: 2024-01-30T12:31:43.521306-08:00 diff --git "a/Icon\r" "b/Icon\r" new file mode 100644 index 000000000..e69de29bb diff --git a/core/context/providers/DocsContextProvider.ts b/core/context/providers/DocsContextProvider.ts index 3875dd3a0..803628f0c 100644 --- a/core/context/providers/DocsContextProvider.ts +++ b/core/context/providers/DocsContextProvider.ts @@ -36,13 +36,15 @@ class DocsContextProvider extends BaseContextProvider { return [ ...chunks .map((chunk) => ({ - name: chunk.filepath - .split("/") - .slice(1) - .join("/") - .split("/tree/main/") - .slice(1) - .join("/"), // chunk.otherMetadata?.title || chunk.filepath, + name: chunk.filepath.includes("/tree/main") // For display of GitHub files + ? chunk.filepath + .split("/") + .slice(1) + .join("/") + .split("/tree/main/") + .slice(1) + .join("/") + : chunk.otherMetadata?.title || chunk.filepath, description: new URL(chunk.filepath, query).toString(), content: chunk.content, })) diff --git a/core/indexing/chunk/markdown.ts b/core/indexing/chunk/markdown.ts index 0ca92158c..0e0901cf0 100644 --- a/core/indexing/chunk/markdown.ts +++ b/core/indexing/chunk/markdown.ts @@ -58,14 +58,29 @@ export async function* markdownChunker( hLevel: number ): AsyncGenerator { if (countTokens(content, "gpt-4") <= maxChunkSize) { + const header = findHeader(content.split("\n")); yield { content, startLine: 0, endLine: content.split("\n").length, + otherMetadata: { + fragment: cleanFragment(header), + title: cleanHeader(header), + }, }; return; } else if (hLevel > 4) { - yield* basicChunker(content, maxChunkSize); + const header = findHeader(content.split("\n")); + + for (const chunk of basicChunker(content, maxChunkSize)) { + yield { + ...chunk, + otherMetadata: { + fragment: cleanFragment(header), + title: cleanHeader(header), + }, + }; + } return; } diff --git a/core/indexing/docs/crawl.ts b/core/indexing/docs/crawl.ts index 13b86c807..0152005f2 100644 --- a/core/indexing/docs/crawl.ts +++ b/core/indexing/docs/crawl.ts @@ -43,11 +43,16 @@ function shouldFilterPath(pathname: string, baseUrl: URL): boolean { return false; } -async function crawlLinks(path: string, baseUrl: URL, visited: Set) { +async function* crawlLinks( + path: string, + baseUrl: URL, + visited: Set +): AsyncGenerator { if (visited.has(path) || shouldFilterPath(path, baseUrl)) { return; } visited.add(path); + yield visited.size; const response = await fetch(new URL(path, baseUrl)); const text = await response.text(); @@ -71,8 +76,12 @@ async function crawlLinks(path: string, baseUrl: URL, visited: Set) { }); await Promise.all( - children.map((child) => crawlLinks(child, baseUrl, visited)) + children.map(async (child) => { + for await (const _ of crawlLinks(child, baseUrl, visited)) { + } + }) ); + yield visited.size; } async function crawlGithubRepo(baseUrl: URL) { @@ -116,25 +125,44 @@ async function crawlGithubRepo(baseUrl: URL) { return paths; } -export async function crawlSubpages(baseUrl: URL) { +export async function* crawlSubpages( + baseUrl: URL +): AsyncGenerator { // Special case for GitHub repos if (baseUrl.hostname === "github.com") { return crawlGithubRepo(baseUrl); } // First, check if the parent of the path redirects to the same page - const parentUrl = new URL(baseUrl); - parentUrl.pathname = parentUrl.pathname.split("/").slice(0, -1).join("/"); - const response = await fetch(parentUrl); - - let useParent = response.url === baseUrl.toString(); + if (baseUrl.pathname.endsWith("/")) { + baseUrl.pathname = baseUrl.pathname.slice(0, -1); + } + let realBaseUrl = new URL(baseUrl); + while (true) { + let parentUrl = new URL(realBaseUrl); + parentUrl.pathname = parentUrl.pathname.split("/").slice(0, -1).join("/"); + if ( + parentUrl.pathname === realBaseUrl.pathname || + parentUrl.pathname === "" + ) { + break; + } + const response = await fetch(parentUrl); + const redirected = response.url.toString() === baseUrl.toString() + "/"; + if (!redirected) { + break; + } + realBaseUrl = parentUrl; + } const visited = new Set(); - await crawlLinks( - (useParent ? parentUrl.pathname : baseUrl.pathname) || "/", - baseUrl, + for await (const count of crawlLinks( + realBaseUrl.pathname || "/", + realBaseUrl, visited - ); + )) { + yield count; + } return [...visited]; } diff --git a/core/indexing/docs/db.ts b/core/indexing/docs/db.ts index 760fc0f87..21a23d827 100644 --- a/core/indexing/docs/db.ts +++ b/core/indexing/docs/db.ts @@ -22,7 +22,7 @@ async function createDocsTable(db: Database) { db.exec(`CREATE TABLE IF NOT EXISTS docs ( id INTEGER PRIMARY KEY AUTOINCREMENT, title STRING NOT NULL, - baseUrl STRING NOT NULL + baseUrl STRING NOT NULL UNIQUE )`); } diff --git a/core/indexing/docs/index.ts b/core/indexing/docs/index.ts index 7b147dcdd..5c2ade9ac 100644 --- a/core/indexing/docs/index.ts +++ b/core/indexing/docs/index.ts @@ -16,7 +16,7 @@ export async function* indexDocs( embeddingsProvider: EmbeddingsProvider ): AsyncGenerator { const existingDocs = await listDocs(); - if (existingDocs.find((doc) => doc.title === title)) { + if (existingDocs.find((doc) => doc.baseUrl === baseUrl.toString())) { yield { progress: 1, desc: "Already indexed", @@ -29,8 +29,23 @@ export async function* indexDocs( desc: "Finding subpages", }; - let subpaths = await crawlSubpages(baseUrl); - console.log("Found subpaths", subpaths); + const subpathGenerator = crawlSubpages(baseUrl); + let { value, done } = await subpathGenerator.next(); + while (true) { + if (done) { + break; + } + yield { + progress: 0, + desc: `Finding subpages (${value})`, + }; + const next = await subpathGenerator.next(); + value = next.value; + done = next.done; + } + + let subpaths = value as string[]; + const chunks: Chunk[] = []; const embeddings: number[][] = []; @@ -53,7 +68,7 @@ export async function* indexDocs( for (let i = 0; i < subpaths.length; i++) { const subpath = subpaths[i]; yield { - progress: 1 / (subpaths.length + 1), + progress: Math.max(1, Math.floor(100 / (subpaths.length + 1))), desc: `${subpath}`, }; @@ -75,6 +90,7 @@ export async function* indexDocs( (chunk.otherMetadata?.fragment ? `#${chunk.otherMetadata.fragment}` : ""), + otherMetadata: chunk.otherMetadata, index, digest: subpath, }); diff --git a/docs/docs/customization/context-providers.md b/docs/docs/customization/context-providers.md index a8c0d5ea2..692035656 100644 --- a/docs/docs/customization/context-providers.md +++ b/docs/docs/customization/context-providers.md @@ -32,6 +32,14 @@ Type '@terminal' to reference the contents of your IDE's terminal. { "name": "terminal" } ``` +### Documentation + +Type `@docs` to index and retrieve snippets from any documentation site. You can add any site by selecting "Add Docs" in the dropdown, then entering the root URL of the documentation site and a title to remember it by. After the site has been indexed, you can type `@docs`, select your documentation from the dropdown, and Continue will use similarity search to automatically find important sections when answering your question. + +```json +{ "name": "docs" } +``` + ### Open Files Type '@open' to reference the contents of all of your open files. Set `onlyPinned` to `true` to only reference pinned files. diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index 9976e7abd..86aadd082 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -968,6 +968,7 @@ "problems", "folder", "issue", + "docs", "tree" ], "markdownEnumDescriptions": [ @@ -982,6 +983,7 @@ "Include important files from a folder in the prompt, as determined by similarity search", "Reference GitHub issues from a repository", "Retrieve important pages from a documentation website, as determined by similarity search", + "Index and retrieve the contents of any documentation site, using embeddings to find important snippets", "Display a file tree of the current workspace" ], "type": "string" diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 9976e7abd..86aadd082 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -968,6 +968,7 @@ "problems", "folder", "issue", + "docs", "tree" ], "markdownEnumDescriptions": [ @@ -982,6 +983,7 @@ "Include important files from a folder in the prompt, as determined by similarity search", "Reference GitHub issues from a repository", "Retrieve important pages from a documentation website, as determined by similarity search", + "Index and retrieve the contents of any documentation site, using embeddings to find important snippets", "Display a file tree of the current workspace" ], "type": "string" diff --git a/extensions/vscode/src/debugPanel.ts b/extensions/vscode/src/debugPanel.ts index 90276bafb..9e8c80bbd 100644 --- a/extensions/vscode/src/debugPanel.ts +++ b/extensions/vscode/src/debugPanel.ts @@ -674,7 +674,7 @@ export function getSidebarContent( embeddingsProvider )) { progress.report({ - increment: update.progress * 100, + increment: update.progress, message: update.desc, }); } @@ -682,6 +682,10 @@ export function getSidebarContent( vscode.window.showInformationMessage( `🎉 Successfully indexed ${title}` ); + + debugPanelWebview?.postMessage({ + type: "refreshSubmenuItems", + }); } ); break; diff --git a/extensions/vscode/src/util/indexCodebase.ts b/extensions/vscode/src/util/indexCodebase.ts index 8b21cbcd1..90d1697ee 100644 --- a/extensions/vscode/src/util/indexCodebase.ts +++ b/extensions/vscode/src/util/indexCodebase.ts @@ -71,8 +71,6 @@ export async function vsCodeIndexCodebase(workspaceDirs: string[]) { (filepath) => ideProtocolClient.readFile(filepath) ); - console.log("RESULTS: ", codebaseIndex.artifactId, results); - for await (let { progress, desc } of codebaseIndex.update( tag, results, diff --git a/gui/src/App.tsx b/gui/src/App.tsx index d57d17642..0ad8260cc 100644 --- a/gui/src/App.tsx +++ b/gui/src/App.tsx @@ -66,19 +66,28 @@ const router = createMemoryRouter([ }, ]); -export const SubmenuContextProvidersContext = createContext< - (providerTitle: string | undefined, query: string) => ContextSubmenuItem[] ->(() => []); +export const SubmenuContextProvidersContext = createContext<{ + getSubmenuContextItems: ( + providerTitle: string | undefined, + query: string + ) => ContextSubmenuItem[]; + addItem: (providerTitle: string, item: ContextSubmenuItem) => void; +}>({ + getSubmenuContextItems: () => [], + addItem: () => {}, +}); function App() { const dispatch = useDispatch(); useSetup(dispatch); - const { getSubmenuContextItems } = useSubmenuContextProviders(); + const submenuContextProvidersMethods = useSubmenuContextProviders(); return ( - + ); diff --git a/gui/src/components/dialogs/AddDocsDialog.tsx b/gui/src/components/dialogs/AddDocsDialog.tsx index 3b342de2c..54a158078 100644 --- a/gui/src/components/dialogs/AddDocsDialog.tsx +++ b/gui/src/components/dialogs/AddDocsDialog.tsx @@ -1,9 +1,10 @@ import { postToIde } from "core/ide/messaging"; -import React, { useLayoutEffect } from "react"; +import { usePostHog } from "posthog-js/react"; +import React, { useContext, useLayoutEffect } from "react"; import { useDispatch } from "react-redux"; import styled from "styled-components"; import { Button, Input } from ".."; -import useSubmenuContextProviders from "../../hooks/useSubmenuContextProviders"; +import { SubmenuContextProvidersContext } from "../../App"; import { setShowDialog } from "../../redux/slices/uiStateSlice"; const GridDiv = styled.div` @@ -19,14 +20,17 @@ function AddDocsDialog() { const [urlValid, setUrlValid] = React.useState(false); const dispatch = useDispatch(); - const { addItem } = useSubmenuContextProviders(); + const { addItem } = useContext(SubmenuContextProvidersContext); const ref = React.useRef(null); + const posthog = usePostHog(); useLayoutEffect(() => { - if (ref.current) { - ref.current.focus(); - } + setTimeout(() => { + if (ref.current) { + ref.current.focus(); + } + }, 100); }, [ref]); return ( @@ -63,6 +67,7 @@ function AddDocsDialog() { title: docsTitle, description: new URL(docsUrl).hostname, }); + posthog.capture("add_docs", { url: docsUrl }); }} > Done diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index deb8fa03c..4827b8960 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -123,7 +123,7 @@ interface TipTapEditorProps { function TipTapEditor(props: TipTapEditorProps) { const dispatch = useDispatch(); - const getSubmenuContextItems = useContext(SubmenuContextProvidersContext); + const { getSubmenuContextItems } = useContext(SubmenuContextProvidersContext); const historyLength = useSelector( (store: RootStore) => store.state.history.length diff --git a/gui/src/hooks/useSubmenuContextProviders.tsx b/gui/src/hooks/useSubmenuContextProviders.tsx index c059f6ee2..1896379e4 100644 --- a/gui/src/hooks/useSubmenuContextProviders.tsx +++ b/gui/src/hooks/useSubmenuContextProviders.tsx @@ -43,6 +43,19 @@ function useSubmenuContextProviders() { }); } + useEffect(() => { + const handler = (e) => { + if (e.data.type !== "refreshSubmenuItems") { + return; + } + setLoaded(false); + }; + window.addEventListener("message", handler); + return () => { + window.removeEventListener("message", handler); + }; + }, []); + function addItem(providerTitle: string, item: ContextSubmenuItem) { console.log("Adding item", item, providerTitle, Object.keys(minisearches)); if (!minisearches[providerTitle]) { From 050c87a7546f69065410d2873cd465d47cd543db Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 30 Jan 2024 13:03:48 -0800 Subject: [PATCH 14/31] =?UTF-8?q?=F0=9F=93=9D=20update=20changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changes/unreleased/Added-20240130-130332.yaml | 4 ++++ .changes/unreleased/Fixed-20240130-130315.yaml | 4 ++++ extensions/vscode/CHANGELOG.md | 4 ++++ 3 files changed, 12 insertions(+) create mode 100644 .changes/unreleased/Added-20240130-130332.yaml create mode 100644 .changes/unreleased/Fixed-20240130-130315.yaml diff --git a/.changes/unreleased/Added-20240130-130332.yaml b/.changes/unreleased/Added-20240130-130332.yaml new file mode 100644 index 000000000..75bd1ca2e --- /dev/null +++ b/.changes/unreleased/Added-20240130-130332.yaml @@ -0,0 +1,4 @@ +project: extensions/vscode +kind: Added +body: CodeLlama-70b support +time: 2024-01-30T13:03:32.287428-08:00 diff --git a/.changes/unreleased/Fixed-20240130-130315.yaml b/.changes/unreleased/Fixed-20240130-130315.yaml new file mode 100644 index 000000000..ddc4186b8 --- /dev/null +++ b/.changes/unreleased/Fixed-20240130-130315.yaml @@ -0,0 +1,4 @@ +project: extensions/vscode +kind: Fixed +body: Fixed proxy setting in config.json +time: 2024-01-30T13:03:15.8294-08:00 diff --git a/extensions/vscode/CHANGELOG.md b/extensions/vscode/CHANGELOG.md index e994fbb99..fabc24168 100644 --- a/extensions/vscode/CHANGELOG.md +++ b/extensions/vscode/CHANGELOG.md @@ -10,6 +10,10 @@ Pre-release Changes ### Added * Image support * Full-text search index for retrieval +* Docs context provider +* CodeLlama-70b support +### Fixed +* Fixed proxy setting in config.json ## v0.8.2 - 2024-01-23 ### Added From d080c8ed30f15a4acca98bbb70e5989e6dbf7d60 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 30 Jan 2024 15:02:05 -0800 Subject: [PATCH 15/31] =?UTF-8?q?=F0=9F=9A=B8=20Show=20all=20prompts=20and?= =?UTF-8?q?=20completions=20in=20VS=20Code=20output=20panel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/llm/index.ts | 18 +++++++++++++++--- extensions/vscode/src/loadConfig.ts | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/core/llm/index.ts b/core/llm/index.ts index b60f0f240..b883bf196 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -380,11 +380,11 @@ export abstract class BaseLLM implements ILLM { .map(([key, value]) => `${key}: ${value}`) .join("\n"); return `Settings: - ${settings} +${settings} - ############################################ +############################################ - ${prompt}`; +${prompt}`; } private _logTokensGenerated(model: string, completion: string) { @@ -499,6 +499,10 @@ export abstract class BaseLLM implements ILLM { this._logTokensGenerated(completionOptions.model, completion); + if (log && this.writeLog) { + await this.writeLog(`Completion:\n\n${completion}\n\n`); + } + return { prompt, completion }; } @@ -539,6 +543,10 @@ export abstract class BaseLLM implements ILLM { const completion = await this._complete(prompt, completionOptions); this._logTokensGenerated(completionOptions.model, completion); + if (log && this.writeLog) { + await this.writeLog(`Completion:\n\n${completion}\n\n`); + } + return completion; } @@ -611,6 +619,10 @@ export abstract class BaseLLM implements ILLM { } this._logTokensGenerated(completionOptions.model, completion); + if (log && this.writeLog) { + await this.writeLog(`Completion:\n\n${completion}\n\n`); + } + return { prompt, completion }; } diff --git a/extensions/vscode/src/loadConfig.ts b/extensions/vscode/src/loadConfig.ts index f430d339d..3b469379d 100644 --- a/extensions/vscode/src/loadConfig.ts +++ b/extensions/vscode/src/loadConfig.ts @@ -1,10 +1,15 @@ import { ContinueConfig, IDE, ILLM } from "core"; import * as fs from "fs"; import { Agent, ProxyAgent, fetch } from "undici"; +import * as vscode from "vscode"; import { webviewRequest } from "./debugPanel"; import { VsCodeIde, loadFullConfigNode } from "./ideProtocol"; const tls = require("tls"); +const outputChannel = vscode.window.createOutputChannel( + "Continue - LLM Prompt/Completion" +); + class VsCodeConfigHandler { savedConfig: ContinueConfig | undefined; @@ -100,5 +105,16 @@ export async function llmFromTitle(title?: string): Promise { }); }; + llm.writeLog = async (log: string) => { + outputChannel.appendLine( + "==========================================================================" + ); + outputChannel.appendLine( + "==========================================================================" + ); + + outputChannel.append(log); + }; + return llm; } From dd52cac4aa2d33c62905833966b8658af6ca7a0d Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 30 Jan 2024 18:28:31 -0800 Subject: [PATCH 16/31] =?UTF-8?q?=F0=9F=A5=85=20give=20useful=20tips=20in?= =?UTF-8?q?=20error=20messages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/src/debugPanel.ts | 21 ++++++++++++--------- extensions/vscode/src/loadConfig.ts | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/extensions/vscode/src/debugPanel.ts b/extensions/vscode/src/debugPanel.ts index 9e8c80bbd..113bc8b4e 100644 --- a/extensions/vscode/src/debugPanel.ts +++ b/extensions/vscode/src/debugPanel.ts @@ -714,16 +714,19 @@ export function getSidebarContent( } } } catch (e: any) { + let message = `Continue error: ${e.message}`; + if (e.cause) { + if (e.cause.name === "ConnectTimeoutError") { + message = `Connection timed out. If you expect it to take a long time to connect, you can increase the timeout in config.json by setting "requestOptions": { "timeout": 10000 }. You can find the full config reference here: https://continue.dev/docs/reference/config`; + } else if (e.cause.code === "ECONNREFUSED") { + message = `Connection was refused. This likely means that there is no server running at the specified URL. If you are running your own server you may need to set the "apiBase" parameter in config.json. For example, you can set up an OpenAI-compatible server like here: https://continue.dev/docs/reference/Model%20Providers/openai#openai-compatible-servers--apis`; + } else { + message = `The request failed with "${e.cause.name}": ${e.cause.message}. If you're having trouble setting up Continue, please see the troubleshooting guide for help.`; + } + } + vscode.window - .showErrorMessage( - `Continue error: ${e.message}${ - e.message.includes("fetch failed") - ? ". It is possible that this error is due to certificates not being configured. See the troubleshooting page to learn more." - : "" - }`, - "Show Logs", - "Troubleshooting" - ) + .showErrorMessage(message, "Show Logs", "Troubleshooting") .then((selection) => { if (selection === "Show Logs") { vscode.commands.executeCommand("workbench.action.toggleDevTools"); diff --git a/extensions/vscode/src/loadConfig.ts b/extensions/vscode/src/loadConfig.ts index 3b469379d..5036a3f84 100644 --- a/extensions/vscode/src/loadConfig.ts +++ b/extensions/vscode/src/loadConfig.ts @@ -91,18 +91,28 @@ export async function llmFromTitle(title?: string): Promise { headersTimeout: timeout, }); - llm._fetch = (input, init) => { + llm._fetch = async (input, init) => { const headers: { [key: string]: string } = llm!.requestOptions?.headers || {}; for (const [key, value] of Object.entries(init?.headers || {})) { headers[key] = value as string; } - return fetch(input, { + const resp = await fetch(input, { ...init, dispatcher: agent, headers, }); + + if (!resp.ok) { + throw new Error( + `HTTP ${resp.status} ${resp.statusText} from ${ + resp.url + }\n\n${await resp.text()}` + ); + } + + return resp; }; llm.writeLog = async (log: string) => { From 057111ceb980290abe2ca1a2af87e3a5b7b54af0 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 30 Jan 2024 18:53:50 -0800 Subject: [PATCH 17/31] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20don't=20generate=20s?= =?UTF-8?q?ession=20titles=20ever=20if=20parallel=20generation=20not=20sup?= =?UTF-8?q?ported?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/context/retrieval.ts | 31 ++----------------------------- core/llm/index.ts | 21 +++++++++++++++++++++ gui/src/hooks/useHistory.tsx | 3 ++- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/core/context/retrieval.ts b/core/context/retrieval.ts index 57be93ac2..4ffc583cc 100644 --- a/core/context/retrieval.ts +++ b/core/context/retrieval.ts @@ -1,13 +1,8 @@ -import { - Chunk, - ContextItem, - ContextProviderExtras, - ILLM, - ModelProvider, -} from ".."; +import { Chunk, ContextItem, ContextProviderExtras, ILLM } from ".."; import { FullTextSearchCodebaseIndex } from "../indexing/FullTextSearch"; import { ChunkCodebaseIndex } from "../indexing/chunk/ChunkCodebaseIndex"; import { IndexTag } from "../indexing/types"; +import { llmCanGenerateInParallel } from "../llm"; import { getBasename } from "../util"; const RERANK_PROMPT = ( @@ -50,28 +45,6 @@ ${document} Relevant: `; -const PARALLEL_PROVIDERS: ModelProvider[] = [ - "anthropic", - "bedrock", - "deepinfra", - "gemini", - "google-palm", - "huggingface-inference-api", - "huggingface-tgi", - "mistral", - "free-trial", - "replicate", - "together", -]; - -function llmCanGenerateInParallel(llm: ILLM): boolean { - if (llm.providerName === "openai") { - return llm.model.includes("gpt"); - } - - return PARALLEL_PROVIDERS.includes(llm.providerName); -} - async function scoreChunk( chunk: Chunk, llm: ILLM, diff --git a/core/llm/index.ts b/core/llm/index.ts index b883bf196..3dcb6a2d5 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -88,6 +88,27 @@ export function modelSupportsImages( return false; } +const PARALLEL_PROVIDERS: ModelProvider[] = [ + "anthropic", + "bedrock", + "deepinfra", + "gemini", + "google-palm", + "huggingface-inference-api", + "huggingface-tgi", + "mistral", + "free-trial", + "replicate", + "together", +]; + +export function llmCanGenerateInParallel(llm: ILLM): boolean { + if (llm.providerName === "openai") { + return llm.model.includes("gpt"); + } + + return PARALLEL_PROVIDERS.includes(llm.providerName); +} function autodetectTemplateType(model: string): TemplateType | undefined { const lower = model.toLowerCase(); diff --git a/gui/src/hooks/useHistory.tsx b/gui/src/hooks/useHistory.tsx index f19f4b736..a6b9edfca 100644 --- a/gui/src/hooks/useHistory.tsx +++ b/gui/src/hooks/useHistory.tsx @@ -1,6 +1,7 @@ import { Dispatch } from "@reduxjs/toolkit"; import { PersistedSessionInfo, SessionInfo } from "core"; import { ideRequest } from "core/ide/messaging"; +import { llmCanGenerateInParallel } from "core/llm"; import { stripImages } from "core/llm/countTokens"; import { useSelector } from "react-redux"; import { defaultModelSelector } from "../redux/selectors/modelSelectors"; @@ -36,7 +37,7 @@ function useHistory(dispatch: Dispatch) { stripImages(stateCopy.history[0].message.content), 50 ); - if (!disableSessionTitles) { + if (!disableSessionTitles && llmCanGenerateInParallel(defaultModel)) { let { content } = await defaultModel.chat( [ ...stateCopy.history.map((item) => item.message), From bb582f86b0fa4a3b98008b5295883c8b3dd1b20b Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 30 Jan 2024 19:36:37 -0800 Subject: [PATCH 18/31] =?UTF-8?q?=F0=9F=9A=B8=20stop=20button=20for=20stre?= =?UTF-8?q?aming=20diffs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/package.json | 10 ++++++- extensions/vscode/src/diff/horizontal.ts | 10 +++++-- .../src/diff/verticalPerLine/manager.ts | 28 ++++++++++++++----- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 136baa224..6e4eb007a 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -80,7 +80,8 @@ "command": "continue.rejectDiff", "category": "Continue", "title": "Reject Diff", - "group": "Continue" + "group": "Continue", + "icon": "$(stop)" }, { "command": "continue.quickEdit", @@ -261,6 +262,13 @@ "group": "0_acontinue" } ], + "editor/title/run": [ + { + "command": "continue.rejectDiff", + "group": "Continue", + "when": "continue.streamingDiff" + } + ], "continue.continueSubMenu": [ { "command": "continue.focusContinueInputWithoutClear", diff --git a/extensions/vscode/src/diff/horizontal.ts b/extensions/vscode/src/diff/horizontal.ts index 462778c73..d9c89bdd8 100644 --- a/extensions/vscode/src/diff/horizontal.ts +++ b/extensions/vscode/src/diff/horizontal.ts @@ -342,12 +342,18 @@ async function recordAcceptReject(accepted: boolean, diffInfo: DiffInfo) { ); } -export async function acceptDiffCommand(newFilepath?: string) { +export async function acceptDiffCommand(newFilepath?: string | vscode.Uri) { + if (newFilepath instanceof vscode.Uri) { + newFilepath = newFilepath.fsPath; + } verticalPerLineDiffManager.clearForFilepath(newFilepath, true); await diffManager.acceptDiff(newFilepath); } -export async function rejectDiffCommand(newFilepath?: string) { +export async function rejectDiffCommand(newFilepath?: string | vscode.Uri) { + if (newFilepath instanceof vscode.Uri) { + newFilepath = newFilepath.fsPath; + } verticalPerLineDiffManager.clearForFilepath(newFilepath, false); await diffManager.rejectDiff(newFilepath); } diff --git a/extensions/vscode/src/diff/verticalPerLine/manager.ts b/extensions/vscode/src/diff/verticalPerLine/manager.ts index 12c9cd7cb..a85b58100 100644 --- a/extensions/vscode/src/diff/verticalPerLine/manager.ts +++ b/extensions/vscode/src/diff/verticalPerLine/manager.ts @@ -108,14 +108,28 @@ export async function streamEdit(input: string) { editor.selection.active ); - await diffHandler.run( - streamDiffLines( - rangeContent, - llm, - input, - getMarkdownLanguageTagForFile(filepath) - ) + vscode.commands.executeCommand( + "setContext", + "continue.streamingDiff", + true ); + + try { + await diffHandler.run( + streamDiffLines( + rangeContent, + llm, + input, + getMarkdownLanguageTagForFile(filepath) + ) + ); + } finally { + vscode.commands.executeCommand( + "setContext", + "continue.streamingDiff", + false + ); + } } } From 1f0ecdf49877fd3b577e5e8b02b4ad0e94a4ab7f Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 30 Jan 2024 20:03:41 -0800 Subject: [PATCH 19/31] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20butto?= =?UTF-8?q?n=20to=20re-open=20tutorial?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/src/activation/activate.ts | 37 +++++++++++--------- extensions/vscode/src/debugPanel.ts | 10 +++++- gui/src/pages/help.tsx | 22 +++++++++++- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/extensions/vscode/src/activation/activate.ts b/extensions/vscode/src/activation/activate.ts index ee270a0d5..9760426bf 100644 --- a/extensions/vscode/src/activation/activate.ts +++ b/extensions/vscode/src/activation/activate.ts @@ -17,24 +17,27 @@ export let extensionContext: vscode.ExtensionContext | undefined = undefined; export let ideProtocolClient: IdeProtocolClient; export let windowId: string = v4(); -async function openTutorial(context: vscode.ExtensionContext) { - if (context.globalState.get("continue.tutorialShown") !== true) { - const tutorialPath = path.join( - getExtensionUri().fsPath, - "continue_tutorial.py" - ); - // Ensure keyboard shortcuts match OS - const os = process.platform; +export async function showTutorial() { + const tutorialPath = path.join( + getExtensionUri().fsPath, + "continue_tutorial.py" + ); + // Ensure keyboard shortcuts match OS + if (process.platform !== "darwin") { let tutorialContent = fs.readFileSync(tutorialPath, "utf8"); - if (os !== "darwin") { - tutorialContent = tutorialContent.replace("⌘", "^"); - fs.writeFileSync(tutorialPath, tutorialContent); - } + tutorialContent = tutorialContent.replace("⌘", "^"); + fs.writeFileSync(tutorialPath, tutorialContent); + } - const doc = await vscode.workspace.openTextDocument( - vscode.Uri.file(tutorialPath) - ); - await vscode.window.showTextDocument(doc); + const doc = await vscode.workspace.openTextDocument( + vscode.Uri.file(tutorialPath) + ); + await vscode.window.showTextDocument(doc); +} + +async function openTutorialFirstTime(context: vscode.ExtensionContext) { + if (context.globalState.get("continue.tutorialShown") !== true) { + await showTutorial(); context.globalState.update("continue.tutorialShown", true); } } @@ -79,7 +82,7 @@ export async function activateExtension(context: vscode.ExtensionContext) { registerAllCodeLensProviders(context); registerAllCommands(context); registerQuickFixProvider(); - await openTutorial(context); + await openTutorialFirstTime(context); setupInlineTips(context); showRefactorMigrationMessage(); diff --git a/extensions/vscode/src/debugPanel.ts b/extensions/vscode/src/debugPanel.ts index 113bc8b4e..8e813d1b1 100644 --- a/extensions/vscode/src/debugPanel.ts +++ b/extensions/vscode/src/debugPanel.ts @@ -8,7 +8,11 @@ import * as path from "path"; import * as io from "socket.io-client"; import { v4 as uuidv4 } from "uuid"; import * as vscode from "vscode"; -import { ideProtocolClient, windowId } from "./activation/activate"; +import { + ideProtocolClient, + showTutorial, + windowId, +} from "./activation/activate"; import { getContinueServerUrl } from "./bridge"; import { streamEdit } from "./diff/verticalPerLine/manager"; import historyManager from "./history"; @@ -712,6 +716,10 @@ export function getSidebarContent( ); break; } + case "showTutorial": { + showTutorial(); + break; + } } } catch (e: any) { let message = `Continue error: ${e.message}`; diff --git a/gui/src/pages/help.tsx b/gui/src/pages/help.tsx index 1b36afe5a..3beb2c715 100644 --- a/gui/src/pages/help.tsx +++ b/gui/src/pages/help.tsx @@ -1,7 +1,8 @@ import { ArrowLeftIcon } from "@heroicons/react/24/outline"; +import { postToIde } from "core/ide/messaging"; import { useNavigate } from "react-router-dom"; import styled from "styled-components"; -import { lightGray, vscBackground, vscForeground } from "../components"; +import { Button, lightGray, vscBackground, vscForeground } from "../components"; import KeyboardShortcutsDialog from "../components/dialogs/KeyboardShortcuts"; const IconDiv = styled.div<{ backgroundColor?: string }>` @@ -18,6 +19,18 @@ const IconDiv = styled.div<{ backgroundColor?: string }>` } `; +const TutorialButton = styled(Button)` + padding: 2px 4px; + margin-left: auto; + margin-right: 12px; + background-color: transparent; + color: ${vscForeground}; + border: 1px solid ${lightGray}; + &:hover { + background-color: ${lightGray}; + } +`; + function HelpPage() { const navigate = useNavigate(); @@ -37,6 +50,13 @@ function HelpPage() { className="inline-block ml-4 cursor-pointer" />

Help Center

+ { + postToIde("showTutorial", {}); + }} + > + Open tutorial +
From d2c53736f67d1d17bb67ee3d3d3141553d200dc1 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 30 Jan 2024 20:11:48 -0800 Subject: [PATCH 20/31] =?UTF-8?q?=F0=9F=93=9D=20mention=20.continuerc.json?= =?UTF-8?q?=20in=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docs/reference/config.mdx | 2 +- extensions/vscode/src/activation/activate.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/docs/reference/config.mdx b/docs/docs/reference/config.mdx index 8bad8f814..608072369 100644 --- a/docs/docs/reference/config.mdx +++ b/docs/docs/reference/config.mdx @@ -3,7 +3,7 @@ import JSONSchemaViewer from "@theme/JSONSchemaViewer"; # Configuration Options -The following shows the JSON Schema definition for `config.json`: +The following shows the JSON Schema definition for `config.json`. You can also define a partial `config.json` object in a file called `.continuerc.json` at the root of your workspace. This will be [applied on top of](https://github.com/continuedev/continue/blob/74c1eb5e25c517c575f72d26227d31d5d2ea18ed/extensions/vscode/src/ideProtocol.ts#L165-L173) any configuration from `config.json`. Date: Tue, 30 Jan 2024 20:26:09 -0800 Subject: [PATCH 21/31] =?UTF-8?q?=F0=9F=94=A5=20gitignore=20Icon=3F=20and?= =?UTF-8?q?=20mention=20.continuerc.json=20in=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- "Icon\r" | 0 docs/docs/reference/config.mdx | 2 +- extensions/vscode/src/activation/activate.ts | 2 ++ 4 files changed, 5 insertions(+), 2 deletions(-) delete mode 100644 "Icon\r" diff --git a/.gitignore b/.gitignore index db987eda8..f8d2c8a18 100644 --- a/.gitignore +++ b/.gitignore @@ -151,4 +151,5 @@ codeql continue_server.build continue_server.dist -Icon \ No newline at end of file +Icon +Icon? \ No newline at end of file diff --git "a/Icon\r" "b/Icon\r" deleted file mode 100644 index e69de29bb..000000000 diff --git a/docs/docs/reference/config.mdx b/docs/docs/reference/config.mdx index 8bad8f814..608072369 100644 --- a/docs/docs/reference/config.mdx +++ b/docs/docs/reference/config.mdx @@ -3,7 +3,7 @@ import JSONSchemaViewer from "@theme/JSONSchemaViewer"; # Configuration Options -The following shows the JSON Schema definition for `config.json`: +The following shows the JSON Schema definition for `config.json`. You can also define a partial `config.json` object in a file called `.continuerc.json` at the root of your workspace. This will be [applied on top of](https://github.com/continuedev/continue/blob/74c1eb5e25c517c575f72d26227d31d5d2ea18ed/extensions/vscode/src/ideProtocol.ts#L165-L173) any configuration from `config.json`. Date: Wed, 31 Jan 2024 04:34:36 +0000 Subject: [PATCH 22/31] =?UTF-8?q?=F0=9F=92=9A=20Update=20package.json=20ve?= =?UTF-8?q?rsion=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/package-lock.json | 4 ++-- extensions/vscode/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index e8d0d6b70..e056b37f5 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.37", + "version": "0.9.38", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.37", + "version": "0.9.38", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 6e4eb007a..51da0d9b6 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -1,7 +1,7 @@ { "name": "continue", "icon": "media/icon.png", - "version": "0.9.37", + "version": "0.9.38", "repository": { "type": "git", "url": "https://github.com/continuedev/continue" From c09e84a0c64a2fc136c7fdb724986155e322c14d Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 30 Jan 2024 22:10:19 -0800 Subject: [PATCH 23/31] =?UTF-8?q?=F0=9F=90=9B=20fix=20sdk.addContextItem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gui/src/hooks/useChatHandler.ts | 25 +++++++++++++++++++------ gui/src/redux/slices/stateSlice.ts | 17 +++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/gui/src/hooks/useChatHandler.ts b/gui/src/hooks/useChatHandler.ts index 90ec92fb9..25cf28970 100644 --- a/gui/src/hooks/useChatHandler.ts +++ b/gui/src/hooks/useChatHandler.ts @@ -5,6 +5,7 @@ import { ChatHistory, ChatHistoryItem, ChatMessage, + ContinueSDK, LLMReturnValue, MessageContent, SlashCommand, @@ -19,7 +20,7 @@ import { useSelector } from "react-redux"; import resolveEditorContent from "../components/mainInput/resolveInput"; import { defaultModelSelector } from "../redux/selectors/modelSelectors"; import { - addContextItems, + addContextItemsAtIndex, addLogs, initNewActiveMessage, resubmitAtIndex, @@ -120,19 +121,25 @@ function useChatHandler(dispatch: Dispatch) { async function _streamSlashCommand( messages: ChatMessage[], slashCommand: SlashCommand, - input: string + input: string, + historyIndex: number ) { let generator: AsyncGenerator; if (slashCommand.runInNodeJs) { generator = _streamSlashCommandFromVsCode(messages, slashCommand, input); } else { - const sdk = { + const sdk: ContinueSDK = { input, history: messages, ide: new ExtensionIde(), llm: defaultModel, addContextItem: (item) => { - dispatch(addContextItems([item])); + dispatch( + addContextItemsAtIndex({ + index: historyIndex, + contextItems: [item], + }) + ); }, contextItems, params: slashCommand.params, @@ -181,10 +188,11 @@ function useChatHandler(dispatch: Dispatch) { }; let newHistory: ChatHistory = [...history.slice(0, index), historyItem]; + const historyIndex = index || newHistory.length - 1; dispatch( setMessageAtIndex({ message, - index: index || newHistory.length - 1, + index: historyIndex, contextItems, }) ); @@ -217,7 +225,12 @@ function useChatHandler(dispatch: Dispatch) { user_input: commandInput, }, }); - await _streamSlashCommand(messages, slashCommand, commandInput); + await _streamSlashCommand( + messages, + slashCommand, + commandInput, + historyIndex + ); } } catch (e) { console.log("Continue: error streaming response: ", e); diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index 9d881ceea..df0a792e5 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -264,6 +264,22 @@ export const stateSlice = createSlice({ state.history[payload.index].message = payload.message; state.history[payload.index].contextItems = payload.contextItems || []; }, + addContextItemsAtIndex: ( + state, + { + payload, + }: { + payload: { + index: number; + contextItems: ContextItemWithId[]; + }; + } + ) => { + console.log("addContextItemsAtIndex", payload, state.history); + if (payload.index < state.history.length) { + state.history[payload.index].contextItems.push(...payload.contextItems); + } + }, setInactive: (state) => { return { ...state, @@ -450,6 +466,7 @@ export const stateSlice = createSlice({ export const { setContextItemsAtIndex, addContextItems, + addContextItemsAtIndex, setInactive, streamUpdate, newSession, From ca30daf5a93a76f490b4764d209bcf077538417a Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 31 Jan 2024 11:32:18 -0800 Subject: [PATCH 24/31] =?UTF-8?q?=F0=9F=90=9B=20fix=20bug=20where=20fortra?= =?UTF-8?q?n=20code=20wasn't=20displayed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gui/package-lock.json | 552 +++++------------- gui/package.json | 2 + gui/src/components/index.ts | 1 - .../markdown/StyledMarkdownPreview.tsx | 120 +++- gui/src/hooks/useSubmenuContextProviders.tsx | 1 - gui/src/redux/slices/stateSlice.ts | 1 - 6 files changed, 254 insertions(+), 423 deletions(-) diff --git a/gui/package-lock.json b/gui/package-lock.json index 10049de81..967d5dbc0 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -46,9 +46,11 @@ "rehype-wrap-all": "^1.1.0", "remark-shiki-twoslash": "^3.1.3", "seti-file-icons": "^0.0.8", + "shikiji": "^0.10.2", "socket.io-client": "^4.7.2", "styled-components": "^5.3.6", "tippy.js": "^6.3.7", + "unist-util-visit": "^5.0.0", "uuid": "^9.0.1", "vscode-webview": "^1.0.1-beta.1" }, @@ -923,6 +925,27 @@ "node": ">=12" } }, + "node_modules/@mapbox/hast-util-table-cell-style/node_modules/unist-util-is": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-3.0.0.tgz", + "integrity": "sha512-sVZZX3+kspVNmLWBPAB6r+7D9ZgAFPNWm66f7YNb420RlQSbn+n8rG8dGZSkrER7ZIXGQYNm5pqC3v3HopH24A==" + }, + "node_modules/@mapbox/hast-util-table-cell-style/node_modules/unist-util-visit": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-1.4.1.tgz", + "integrity": "sha512-AvGNk7Bb//EmJZyhtRUnNMEpId/AZ5Ph/KUpTI09WHQuDZHKovQ1oEv3mfmKpWKtoMzyMC4GLBm1Zy5k12fjIw==", + "dependencies": { + "unist-util-visit-parents": "^2.0.0" + } + }, + "node_modules/@mapbox/hast-util-table-cell-style/node_modules/unist-util-visit-parents": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-2.1.2.tgz", + "integrity": "sha512-DyN5vD4NE3aSeB+PXYNKxzGsfocxp6asDc2XXE3b0ekO2BaRUpBicbbUygfSvYfUz1IkmjFR1YF7dPklraMZ2g==", + "dependencies": { + "unist-util-is": "^3.0.0" + } + }, "node_modules/@monaco-editor/loader": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/@monaco-editor/loader/-/loader-1.4.0.tgz", @@ -1104,18 +1127,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/@shikijs/rehype/node_modules/unist-util-is": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", - "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", - "dependencies": { - "@types/unist": "^3.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/@shikijs/rehype/node_modules/unist-util-stringify-position": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz", @@ -1128,33 +1139,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/@shikijs/rehype/node_modules/unist-util-visit": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", - "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0", - "unist-util-visit-parents": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/@shikijs/rehype/node_modules/unist-util-visit-parents": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz", - "integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/@shikijs/rehype/node_modules/vfile": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.1.tgz", @@ -4240,18 +4224,6 @@ "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==" }, - "node_modules/mdast-util-to-hast/node_modules/unist-util-is": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", - "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", - "dependencies": { - "@types/unist": "^3.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/mdast-util-to-hast/node_modules/unist-util-position": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/unist-util-position/-/unist-util-position-5.0.0.tgz", @@ -4276,33 +4248,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/mdast-util-to-hast/node_modules/unist-util-visit": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", - "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0", - "unist-util-visit-parents": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/mdast-util-to-hast/node_modules/unist-util-visit-parents": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz", - "integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/mdast-util-to-hast/node_modules/vfile": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.1.tgz", @@ -4374,45 +4319,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/mdast-util-to-markdown/node_modules/unist-util-is": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", - "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", - "dependencies": { - "@types/unist": "^3.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/mdast-util-to-markdown/node_modules/unist-util-visit": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", - "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0", - "unist-util-visit-parents": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/mdast-util-to-markdown/node_modules/unist-util-visit-parents": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz", - "integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/mdast-util-to-string": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/mdast-util-to-string/-/mdast-util-to-string-2.0.0.tgz", @@ -5587,18 +5493,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/react-markdown/node_modules/unist-util-is": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", - "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", - "dependencies": { - "@types/unist": "^3.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/react-markdown/node_modules/unist-util-stringify-position": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz", @@ -5611,33 +5505,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/react-markdown/node_modules/unist-util-visit": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", - "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0", - "unist-util-visit-parents": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/react-markdown/node_modules/unist-util-visit-parents": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz", - "integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/react-markdown/node_modules/vfile": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.1.tgz", @@ -6010,18 +5877,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/rehype-shikiji/node_modules/unist-util-is": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", - "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", - "dependencies": { - "@types/unist": "^3.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/rehype-shikiji/node_modules/unist-util-stringify-position": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz", @@ -6034,33 +5889,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/rehype-shikiji/node_modules/unist-util-visit": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", - "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0", - "unist-util-visit-parents": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/rehype-shikiji/node_modules/unist-util-visit-parents": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz", - "integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/rehype-shikiji/node_modules/vfile": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.1.tgz", @@ -7000,45 +6828,6 @@ "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==" }, - "node_modules/unist-util-remove-position/node_modules/unist-util-is": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", - "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", - "dependencies": { - "@types/unist": "^3.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/unist-util-remove-position/node_modules/unist-util-visit": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", - "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0", - "unist-util-visit-parents": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/unist-util-remove-position/node_modules/unist-util-visit-parents": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz", - "integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==", - "dependencies": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/unist-util-stringify-position": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-2.0.3.tgz", @@ -7052,25 +6841,65 @@ } }, "node_modules/unist-util-visit": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-1.4.1.tgz", - "integrity": "sha512-AvGNk7Bb//EmJZyhtRUnNMEpId/AZ5Ph/KUpTI09WHQuDZHKovQ1oEv3mfmKpWKtoMzyMC4GLBm1Zy5k12fjIw==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", + "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", "dependencies": { - "unist-util-visit-parents": "^2.0.0" + "@types/unist": "^3.0.0", + "unist-util-is": "^6.0.0", + "unist-util-visit-parents": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" } }, "node_modules/unist-util-visit-parents": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-2.1.2.tgz", - "integrity": "sha512-DyN5vD4NE3aSeB+PXYNKxzGsfocxp6asDc2XXE3b0ekO2BaRUpBicbbUygfSvYfUz1IkmjFR1YF7dPklraMZ2g==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz", + "integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==", "dependencies": { - "unist-util-is": "^3.0.0" + "@types/unist": "^3.0.0", + "unist-util-is": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" } }, + "node_modules/unist-util-visit-parents/node_modules/@types/unist": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", + "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==" + }, "node_modules/unist-util-visit-parents/node_modules/unist-util-is": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-3.0.0.tgz", - "integrity": "sha512-sVZZX3+kspVNmLWBPAB6r+7D9ZgAFPNWm66f7YNb420RlQSbn+n8rG8dGZSkrER7ZIXGQYNm5pqC3v3HopH24A==" + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", + "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", + "dependencies": { + "@types/unist": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unist-util-visit/node_modules/@types/unist": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", + "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==" + }, + "node_modules/unist-util-visit/node_modules/unist-util-is": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", + "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", + "dependencies": { + "@types/unist": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } }, "node_modules/universalify": { "version": "2.0.0", @@ -7824,6 +7653,29 @@ "integrity": "sha512-LyQz4XJIdCdY/+temIhD/Ed0x/p4GAOUycpFSEK2Ads1CPKZy6b7V/2ROEtQiLLQ8soIs0xe/QAoR6kwpyW/yw==", "requires": { "unist-util-visit": "^1.4.1" + }, + "dependencies": { + "unist-util-is": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-3.0.0.tgz", + "integrity": "sha512-sVZZX3+kspVNmLWBPAB6r+7D9ZgAFPNWm66f7YNb420RlQSbn+n8rG8dGZSkrER7ZIXGQYNm5pqC3v3HopH24A==" + }, + "unist-util-visit": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-1.4.1.tgz", + "integrity": "sha512-AvGNk7Bb//EmJZyhtRUnNMEpId/AZ5Ph/KUpTI09WHQuDZHKovQ1oEv3mfmKpWKtoMzyMC4GLBm1Zy5k12fjIw==", + "requires": { + "unist-util-visit-parents": "^2.0.0" + } + }, + "unist-util-visit-parents": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-2.1.2.tgz", + "integrity": "sha512-DyN5vD4NE3aSeB+PXYNKxzGsfocxp6asDc2XXE3b0ekO2BaRUpBicbbUygfSvYfUz1IkmjFR1YF7dPklraMZ2g==", + "requires": { + "unist-util-is": "^3.0.0" + } + } } }, "@monaco-editor/loader": { @@ -7967,14 +7819,6 @@ "vfile": "^6.0.0" } }, - "unist-util-is": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", - "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", - "requires": { - "@types/unist": "^3.0.0" - } - }, "unist-util-stringify-position": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz", @@ -7983,25 +7827,6 @@ "@types/unist": "^3.0.0" } }, - "unist-util-visit": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", - "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", - "requires": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0", - "unist-util-visit-parents": "^6.0.0" - } - }, - "unist-util-visit-parents": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz", - "integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==", - "requires": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0" - } - }, "vfile": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.1.tgz", @@ -10229,14 +10054,6 @@ "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==" }, - "unist-util-is": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", - "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", - "requires": { - "@types/unist": "^3.0.0" - } - }, "unist-util-position": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/unist-util-position/-/unist-util-position-5.0.0.tgz", @@ -10253,25 +10070,6 @@ "@types/unist": "^3.0.0" } }, - "unist-util-visit": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", - "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", - "requires": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0", - "unist-util-visit-parents": "^6.0.0" - } - }, - "unist-util-visit-parents": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz", - "integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==", - "requires": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0" - } - }, "vfile": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.1.tgz", @@ -10328,33 +10126,6 @@ "requires": { "@types/mdast": "^4.0.0" } - }, - "unist-util-is": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", - "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", - "requires": { - "@types/unist": "^3.0.0" - } - }, - "unist-util-visit": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", - "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", - "requires": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0", - "unist-util-visit-parents": "^6.0.0" - } - }, - "unist-util-visit-parents": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz", - "integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==", - "requires": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0" - } } } }, @@ -11125,14 +10896,6 @@ "vfile": "^6.0.0" } }, - "unist-util-is": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", - "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", - "requires": { - "@types/unist": "^3.0.0" - } - }, "unist-util-stringify-position": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz", @@ -11141,25 +10904,6 @@ "@types/unist": "^3.0.0" } }, - "unist-util-visit": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", - "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", - "requires": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0", - "unist-util-visit-parents": "^6.0.0" - } - }, - "unist-util-visit-parents": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz", - "integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==", - "requires": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0" - } - }, "vfile": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.1.tgz", @@ -11425,14 +11169,6 @@ "vfile": "^6.0.0" } }, - "unist-util-is": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", - "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", - "requires": { - "@types/unist": "^3.0.0" - } - }, "unist-util-stringify-position": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz", @@ -11441,25 +11177,6 @@ "@types/unist": "^3.0.0" } }, - "unist-util-visit": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", - "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", - "requires": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0", - "unist-util-visit-parents": "^6.0.0" - } - }, - "unist-util-visit-parents": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz", - "integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==", - "requires": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0" - } - }, "vfile": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.1.tgz", @@ -12165,33 +11882,6 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==" - }, - "unist-util-is": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", - "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", - "requires": { - "@types/unist": "^3.0.0" - } - }, - "unist-util-visit": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", - "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", - "requires": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0", - "unist-util-visit-parents": "^6.0.0" - } - }, - "unist-util-visit-parents": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz", - "integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==", - "requires": { - "@types/unist": "^3.0.0", - "unist-util-is": "^6.0.0" - } } } }, @@ -12204,25 +11894,51 @@ } }, "unist-util-visit": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-1.4.1.tgz", - "integrity": "sha512-AvGNk7Bb//EmJZyhtRUnNMEpId/AZ5Ph/KUpTI09WHQuDZHKovQ1oEv3mfmKpWKtoMzyMC4GLBm1Zy5k12fjIw==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", + "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", "requires": { - "unist-util-visit-parents": "^2.0.0" + "@types/unist": "^3.0.0", + "unist-util-is": "^6.0.0", + "unist-util-visit-parents": "^6.0.0" + }, + "dependencies": { + "@types/unist": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", + "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==" + }, + "unist-util-is": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", + "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", + "requires": { + "@types/unist": "^3.0.0" + } + } } }, "unist-util-visit-parents": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-2.1.2.tgz", - "integrity": "sha512-DyN5vD4NE3aSeB+PXYNKxzGsfocxp6asDc2XXE3b0ekO2BaRUpBicbbUygfSvYfUz1IkmjFR1YF7dPklraMZ2g==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz", + "integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==", "requires": { - "unist-util-is": "^3.0.0" + "@types/unist": "^3.0.0", + "unist-util-is": "^6.0.0" }, "dependencies": { + "@types/unist": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", + "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==" + }, "unist-util-is": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-3.0.0.tgz", - "integrity": "sha512-sVZZX3+kspVNmLWBPAB6r+7D9ZgAFPNWm66f7YNb420RlQSbn+n8rG8dGZSkrER7ZIXGQYNm5pqC3v3HopH24A==" + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", + "integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==", + "requires": { + "@types/unist": "^3.0.0" + } } } }, diff --git a/gui/package.json b/gui/package.json index 44da6d41c..efb7fb888 100644 --- a/gui/package.json +++ b/gui/package.json @@ -47,9 +47,11 @@ "rehype-wrap-all": "^1.1.0", "remark-shiki-twoslash": "^3.1.3", "seti-file-icons": "^0.0.8", + "shikiji": "^0.10.2", "socket.io-client": "^4.7.2", "styled-components": "^5.3.6", "tippy.js": "^6.3.7", + "unist-util-visit": "^5.0.0", "uuid": "^9.0.1", "vscode-webview": "^1.0.1-beta.1" }, diff --git a/gui/src/components/index.ts b/gui/src/components/index.ts index 911407755..b9d2b5176 100644 --- a/gui/src/components/index.ts +++ b/gui/src/components/index.ts @@ -94,7 +94,6 @@ export function parseColorForHex(colorVar: string): string { .map((x) => x.toString(16)) .map((x) => (x.length === 1 ? "0" + x : x)) .join(""); - console.log(hex, value); return hex; } diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index ec26ba2ed..3dcc0fb1d 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -1,7 +1,8 @@ -import { memo, useEffect } from "react"; +import React, { memo, useEffect } from "react"; import { useRemark } from "react-remark"; import rehypeShikiji from "rehype-shikiji"; import styled from "styled-components"; +import { visit } from "unist-util-visit"; import { defaultBorderRadius, vscBackground, @@ -50,6 +51,7 @@ const StyledMarkdown = styled.div<{ border-radius: ${defaultBorderRadius}; background-color: ${vscEditorBackground}; font-size: 12px; + font-family: var(--vscode-editor-font-family); } code:not(pre > code) { @@ -110,10 +112,124 @@ const FadeInWords: React.FC = (props: any) => { return

{words}

; }; +const supportedLanguages = [ + "abap", + "actionscript-3", + "ada", + "apex", + "applescript", + "asm", + "awk", + "bat", + "c", + "clojure", + "cobol", + "coffee", + "cpp", + "crystal", + "csharp", + "css", + "d", + "dart", + "diff", + "dockerfile", + "elixir", + "elm", + "erlang", + // "fortran", + "fsharp", + "git-commit", + "git-rebase", + "go", + "graphql", + "groovy", + "hack", + "haml", + "handlebars", + "haskell", + "hcl", + "hlsl", + "html", + "ini", + "java", + "javascript", + "jinja-html", + "json", + "jsonc", + "jsonnet", + "jsx", + "julia", + "kotlin", + "latex", + "less", + "lisp", + "log", + "logo", + "lua", + "makefile", + "markdown", + "matlab", + "nix", + "objective-c", + "ocaml", + "pascal", + "perl", + "perl6", + "php", + "pls", + "postcss", + "powershell", + "prolog", + "pug", + "puppet", + "purescript", + "python", + "r", + "razor", + "ruby", + "rust", + "sas", + "sass", + "scala", + "scheme", + "scss", + "shaderlab", + "shellscript", + "smalltalk", + "sql", + "stylus", + "svelte", + "swift", + "tcl", + "toml", + "ts", + "tsx", + "typescript", + "vb", + "viml", + "vue", + "wasm", + "xml", + "xsl", + "yaml", + "文言", +]; + const StyledMarkdownPreview = memo(function StyledMarkdownPreview( props: StyledMarkdownPreviewProps ) { const [reactContent, setMarkdownSource] = useRemark({ + remarkPlugins: [ + () => { + return (tree) => { + visit(tree, "code", (node: any) => { + if (!supportedLanguages.includes(node.lang)) { + node.lang = "python"; // Default to python to get some highlighting + } + }); + }; + }, + ], rehypePlugins: [ [ rehypeShikiji as any, @@ -122,6 +238,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( (window as any).fullColorTheme || (window as any).colorThemeName || "dark-plus", + addLanguageClass: true, }, ], // [ @@ -142,7 +259,6 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( ); }, pre: ({ node, ...preProps }) => { - console.log(node, preProps); return props.showCodeBorder ? ( ) : ( diff --git a/gui/src/hooks/useSubmenuContextProviders.tsx b/gui/src/hooks/useSubmenuContextProviders.tsx index 1896379e4..b51cd7ca7 100644 --- a/gui/src/hooks/useSubmenuContextProviders.tsx +++ b/gui/src/hooks/useSubmenuContextProviders.tsx @@ -57,7 +57,6 @@ function useSubmenuContextProviders() { }, []); function addItem(providerTitle: string, item: ContextSubmenuItem) { - console.log("Adding item", item, providerTitle, Object.keys(minisearches)); if (!minisearches[providerTitle]) { return; } diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index df0a792e5..b7ea70808 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -275,7 +275,6 @@ export const stateSlice = createSlice({ }; } ) => { - console.log("addContextItemsAtIndex", payload, state.history); if (payload.index < state.history.length) { state.history[payload.index].contextItems.push(...payload.contextItems); } From 65e420b359c733ae777a276a80c324d638c7e561 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 31 Jan 2024 11:35:36 -0800 Subject: [PATCH 25/31] =?UTF-8?q?=F0=9F=92=84=20default=20to=20javascript?= =?UTF-8?q?=20instead=20of=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gui/src/components/markdown/StyledMarkdownPreview.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index 3dcc0fb1d..ab1eb384c 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -224,7 +224,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview( return (tree) => { visit(tree, "code", (node: any) => { if (!supportedLanguages.includes(node.lang)) { - node.lang = "python"; // Default to python to get some highlighting + node.lang = "javascript"; // Default to javascript to get some highlighting } }); }; From 6d96bd9e9df477272973b8456165ca0f42765425 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 31 Jan 2024 19:43:34 +0000 Subject: [PATCH 26/31] =?UTF-8?q?=F0=9F=92=9A=20Update=20package.json=20ve?= =?UTF-8?q?rsion=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/package-lock.json | 4 ++-- extensions/vscode/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index e056b37f5..0bc92b4cf 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.38", + "version": "0.9.39", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.38", + "version": "0.9.39", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 51da0d9b6..7ef35120b 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -1,7 +1,7 @@ { "name": "continue", "icon": "media/icon.png", - "version": "0.9.38", + "version": "0.9.39", "repository": { "type": "git", "url": "https://github.com/continuedev/continue" From 00ce0255b145fb7171535633e74bc989a5d7c760 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 31 Jan 2024 14:38:52 -0800 Subject: [PATCH 27/31] =?UTF-8?q?=F0=9F=90=9B=20chat=20template=20for=20co?= =?UTF-8?q?dellama-70b?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/index.d.ts | 1 + core/llm/index.ts | 27 +++++++--- core/llm/llms/OpenAI.ts | 15 ++---- core/llm/llms/Together.ts | 49 ++++++------------- core/llm/templates/chat.ts | 17 +++++++ core/llm/templates/edit.ts | 9 +++- core/llm/templates/options.ts | 11 +++++ core/util/merge.ts | 36 ++++++++++++++ extensions/vscode/config_schema.json | 3 +- extensions/vscode/src/ideProtocol.ts | 2 +- extensions/vscode/src/util/merge.ts | 27 ---------- .../markdown/StyledMarkdownPreview.tsx | 2 +- 12 files changed, 119 insertions(+), 80 deletions(-) create mode 100644 core/llm/templates/options.ts create mode 100644 core/util/merge.ts delete mode 100644 extensions/vscode/src/util/merge.ts diff --git a/core/index.d.ts b/core/index.d.ts index 39aa51e01..20763fc93 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -404,6 +404,7 @@ type TemplateType = | "deepseek" | "xwin-coder" | "neural-chat" + | "codellama-70b" | "llava"; type ModelProvider = diff --git a/core/llm/index.ts b/core/llm/index.ts index 3dcb6a2d5..8b2d06765 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -6,11 +6,13 @@ import { LLMFullCompletionOptions, LLMOptions, LLMReturnValue, + ModelName, ModelProvider, RequestOptions, TemplateType, } from ".."; import { ideRequest, ideStreamRequest } from "../ide/messaging"; +import mergeJson from "../util/merge"; import { CONTEXT_LENGTH_FOR_MODEL, DEFAULT_ARGS, @@ -25,6 +27,7 @@ import { import { anthropicTemplateMessages, chatmlTemplateMessages, + codeLlama70bTemplateMessages, deepseekTemplateMessages, llama2TemplateMessages, llavaTemplateMessages, @@ -38,6 +41,7 @@ import { } from "./templates/chat"; import { alpacaEditPrompt, + codeLlama70bEditPrompt, codellamaEditPrompt, deepseekEditPrompt, mistralEditPrompt, @@ -49,11 +53,13 @@ import { xWinCoderEditPrompt, zephyrEditPrompt, } from "./templates/edit"; +import CompletionOptionsForModels from "./templates/options"; const PROVIDER_HANDLES_TEMPLATING: ModelProvider[] = [ "lmstudio", "openai", "ollama", + "together", ]; const PROVIDER_SUPPORTS_IMAGES: ModelProvider[] = [ @@ -113,8 +119,8 @@ export function llmCanGenerateInParallel(llm: ILLM): boolean { function autodetectTemplateType(model: string): TemplateType | undefined { const lower = model.toLowerCase(); - if (lower === "codellama-70b") { - return "none"; + if (lower.includes("codellama") && lower.includes("70b")) { + return "codellama-70b"; } if ( @@ -209,6 +215,7 @@ function autodetectTemplateFunction( "xwin-coder": xWinCoderTemplateMessages, "neural-chat": neuralChatTemplateMessages, llava: llavaTemplateMessages, + "codellama-70b": codeLlama70bTemplateMessages, none: null, }; @@ -249,6 +256,8 @@ function autodetectPromptTemplates( editTemplate = xWinCoderEditPrompt; } else if (templateType === "neural-chat") { editTemplate = neuralChatEditPrompt; + } else if (templateType === "codellama-70b") { + editTemplate = codeLlama70bEditPrompt; } else if (templateType) { editTemplate = simplestEditPrompt; } @@ -319,6 +328,12 @@ export abstract class BaseLLM implements ILLM { model: options.model || "gpt-4", maxTokens: options.completionOptions?.maxTokens || DEFAULT_MAX_TOKENS, }; + if (CompletionOptionsForModels[options.model as ModelName]) { + this.completionOptions = mergeJson( + this.completionOptions, + CompletionOptionsForModels[options.model as ModelName] || {} + ); + } this.requestOptions = options.requestOptions; this.promptTemplates = { ...autodetectPromptTemplates(options.model, templateType), @@ -450,10 +465,10 @@ ${prompt}`; delete options.log; delete options.raw; - const completionOptions: CompletionOptions = { - ...this.completionOptions, - ...options, - }; + const completionOptions: CompletionOptions = mergeJson( + this.completionOptions, + options + ); return { completionOptions, log, raw }; } diff --git a/core/llm/llms/OpenAI.ts b/core/llm/llms/OpenAI.ts index 7c79ea515..8ce374414 100644 --- a/core/llm/llms/OpenAI.ts +++ b/core/llm/llms/OpenAI.ts @@ -110,6 +110,10 @@ class OpenAI extends BaseLLM { prompt: string, options: CompletionOptions ): AsyncGenerator { + const args: any = this._convertArgs(options, []); + args.prompt = prompt; + delete args.messages; + const response = await this.fetch(this._getCompletionUrl(), { method: "POST", headers: { @@ -118,16 +122,7 @@ class OpenAI extends BaseLLM { "api-key": this.apiKey || "", // For Azure }, body: JSON.stringify({ - ...{ - prompt, - model: options.model, - max_tokens: options.maxTokens, - temperature: options.temperature, - top_p: options.topP, - frequency_penalty: options.frequencyPenalty, - presence_penalty: options.presencePenalty, - stop: options.stop, - }, + ...args, stream: true, }), }); diff --git a/core/llm/llms/Together.ts b/core/llm/llms/Together.ts index 4ac82c880..d93be974c 100644 --- a/core/llm/llms/Together.ts +++ b/core/llm/llms/Together.ts @@ -1,18 +1,23 @@ -import { BaseLLM } from ".."; -import { CompletionOptions, LLMOptions, ModelProvider } from "../.."; -import { streamSse } from "../stream"; +import { + ChatMessage, + CompletionOptions, + LLMOptions, + ModelProvider, +} from "../.."; -class Together extends BaseLLM { +import OpenAI from "./OpenAI"; + +class Together extends OpenAI { static providerName: ModelProvider = "together"; static defaultOptions: Partial = { - apiBase: "https://api.together.xyz", + apiBase: "https://api.together.xyz/v1", }; private static MODEL_IDS: { [name: string]: string } = { "codellama-7b": "togethercomputer/CodeLlama-7b-Instruct", "codellama-13b": "togethercomputer/CodeLlama-13b-Instruct", "codellama-34b": "togethercomputer/CodeLlama-34b-Instruct", - "codellama-70b": "codellama/CodeLlama-70b-Python-hf", + "codellama-70b": "codellama/CodeLlama-70b-Instruct-hf", "llama2-7b": "togethercomputer/llama-2-7b-chat", "llama2-13b": "togethercomputer/llama-2-13b-chat", "llama2-70b": "togethercomputer/llama-2-70b-chat", @@ -25,17 +30,9 @@ class Together extends BaseLLM { return Together.MODEL_IDS[model] || this.model; } - private _convertArgs(options: CompletionOptions, prompt: string) { - const finalOptions = { - prompt, - model: this._getModelName(options.model), - temperature: options.temperature, - top_p: options.topP, - top_k: options.topK, - max_tokens: options.maxTokens, - repetition_penalty: options.frequencyPenalty, - }; - + protected _convertArgs(options: any, messages: ChatMessage[]) { + const finalOptions = super._convertArgs(options, messages); + finalOptions.model = this._getModelName(options.model); return finalOptions; } @@ -43,22 +40,8 @@ class Together extends BaseLLM { prompt: string, options: CompletionOptions ): AsyncGenerator { - const response = await this.fetch(`${this.apiBase}/inference`, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${this.apiKey}`, - }, - body: JSON.stringify({ - ...this._convertArgs(options, prompt), - stream_tokens: true, - }), - }); - - for await (const value of streamSse(response)) { - if (value.choices) { - yield value.choices[0].text; - } + for await (const chunk of this._legacystreamComplete(prompt, options)) { + yield chunk; } } } diff --git a/core/llm/templates/chat.ts b/core/llm/templates/chat.ts index 8128b9a6d..bb0945042 100644 --- a/core/llm/templates/chat.ts +++ b/core/llm/templates/chat.ts @@ -264,9 +264,26 @@ function neuralChatTemplateMessages(msgs: ChatMessage[]): string { return prompt; } +/** +'Source: system\n\n System prompt Source: user\n\n First user query Source: assistant\n\n Model response to first query Source: user\n\n Second user query Source: assistant\nDestination: user\n\n ' + */ +function codeLlama70bTemplateMessages(msgs: ChatMessage[]): string { + let prompt = ""; + + for (const msg of msgs) { + prompt += `Source: ${msg.role}\n\n ${stripImages(msg.content).trim()}`; + prompt += " "; + } + + prompt += "Source: assistant\nDestination: user\n\n"; + + return prompt; +} + export { anthropicTemplateMessages, chatmlTemplateMessages, + codeLlama70bTemplateMessages, deepseekTemplateMessages, llama2TemplateMessages, llavaTemplateMessages, diff --git a/core/llm/templates/edit.ts b/core/llm/templates/edit.ts index 5a49f3158..0471ba4d1 100644 --- a/core/llm/templates/edit.ts +++ b/core/llm/templates/edit.ts @@ -138,18 +138,25 @@ Sure! Here's the code you requested: \`\`\`{{{language}}} `; +const codeLlama70bEditPrompt = `Source: system\n\n You are an expert programmer and write code on the first attempt without any errors or fillers. Source: user\n\n Rewrite the code to satisfy this request: "{{{userInput}}}" + +\`\`\`{{{language}}} +{{{codeToEdit}}} +\`\`\` Source: assistant\nDestination: user\n\n `; + export { alpacaEditPrompt, + codeLlama70bEditPrompt, codellamaEditPrompt, codellamaInfillEditPrompt, deepseekEditPrompt, gptEditPrompt, mistralEditPrompt, + neuralChatEditPrompt, openchatEditPrompt, phindEditPrompt, simplestEditPrompt, simplifiedEditPrompt, xWinCoderEditPrompt, zephyrEditPrompt, - neuralChatEditPrompt, }; diff --git a/core/llm/templates/options.ts b/core/llm/templates/options.ts new file mode 100644 index 000000000..1ebb02ba2 --- /dev/null +++ b/core/llm/templates/options.ts @@ -0,0 +1,11 @@ +import { CompletionOptions, ModelName } from "../.."; + +const CompletionOptionsForModels: { + [key in ModelName]?: Partial; +} = { + "codellama-70b": { + stop: ["Source: assistant"], + }, +}; + +export default CompletionOptionsForModels; diff --git a/core/util/merge.ts b/core/util/merge.ts new file mode 100644 index 000000000..c5a0af85f --- /dev/null +++ b/core/util/merge.ts @@ -0,0 +1,36 @@ +type JsonObject = { [key: string]: any }; + +export function mergeJson(first: JsonObject, second: JsonObject): any { + try { + for (var key in second) { + let secondValue = second[key]; + + if (!(key in first)) { + // New value + first[key] = secondValue; + continue; + } + + const firstValue = first[key]; + if (Array.isArray(secondValue)) { + // Array + first[key] = [...firstValue, ...secondValue]; + } else if (typeof secondValue === "object") { + // Object + first[key] = mergeJson(firstValue, secondValue); + } else { + // Other (boolean, number, string) + first[key] = secondValue; + } + } + return first; + } catch (e) { + console.error("Error merging JSON", e, first, second); + return { + ...first, + ...second, + }; + } +} + +export default mergeJson; diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 86aadd082..fc893cb5f 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -172,7 +172,8 @@ "deepseek", "openchat", "xwin-coder", - "neural-chat" + "neural-chat", + "codellama-70b" ], "type": "string" }, diff --git a/extensions/vscode/src/ideProtocol.ts b/extensions/vscode/src/ideProtocol.ts index 7c6f38916..43264dfc9 100644 --- a/extensions/vscode/src/ideProtocol.ts +++ b/extensions/vscode/src/ideProtocol.ts @@ -27,9 +27,9 @@ import { } from "core/config/load"; import { LanceDbIndex } from "core/indexing/LanceDbIndex"; import { IndexTag } from "core/indexing/types"; +import mergeJson from "core/util/merge"; import { verticalPerLineDiffManager } from "./diff/verticalPerLine/manager"; import { configHandler } from "./loadConfig"; -import mergeJson from "./util/merge"; import { traverseDirectory } from "./util/traverseDirectory"; import { getExtensionUri, openEditorAndRevealRange } from "./util/vscode"; diff --git a/extensions/vscode/src/util/merge.ts b/extensions/vscode/src/util/merge.ts deleted file mode 100644 index 418b83511..000000000 --- a/extensions/vscode/src/util/merge.ts +++ /dev/null @@ -1,27 +0,0 @@ -type JsonObject = { [key: string]: any }; - -function mergeJson(first: JsonObject, second: JsonObject): any { - for (var key in second) { - let secondValue = second[key]; - - if (!(key in first)) { - // New value - first[key] = secondValue; - } - - const firstValue = first[key]; - if (Array.isArray(secondValue)) { - // Array - first[key] = [...firstValue, ...secondValue]; - } else if (typeof secondValue === "object") { - // Object - first[key] = mergeJson(firstValue, secondValue); - } else { - // Other (boolean, number, string) - first[key] = secondValue; - } - } - return first; -} - -export default mergeJson; diff --git a/gui/src/components/markdown/StyledMarkdownPreview.tsx b/gui/src/components/markdown/StyledMarkdownPreview.tsx index ab1eb384c..e6f0629bb 100644 --- a/gui/src/components/markdown/StyledMarkdownPreview.tsx +++ b/gui/src/components/markdown/StyledMarkdownPreview.tsx @@ -140,7 +140,7 @@ const supportedLanguages = [ "fsharp", "git-commit", "git-rebase", - "go", + // "go", "graphql", "groovy", "hack", From de8ccb0ac856bb2a0bf61ac863941c4bd638a09f Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 31 Jan 2024 15:03:26 -0800 Subject: [PATCH 28/31] =?UTF-8?q?=F0=9F=A9=B9=20don't=20automatically=20ap?= =?UTF-8?q?pend=20/v1=20to=20apiBase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/indexing/embeddings/OpenAIEmbeddingsProvider.ts | 5 +---- core/llm/llms/OpenAI.ts | 10 ++-------- docs/static/schemas/config.json | 3 ++- extensions/vscode/src/loadConfig.ts | 9 ++++++--- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts b/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts index 333459f81..0b6f4fb22 100644 --- a/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts +++ b/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts @@ -16,13 +16,10 @@ class OpenAIEmbeddingsProvider extends BaseEmbeddingsProvider { if (apiBase?.endsWith("/")) { apiBase = apiBase.slice(0, -1); } - if (apiBase?.endsWith("/v1")) { - apiBase = apiBase.slice(0, -3); - } return await Promise.all( chunks.map(async (chunk) => { - const resp = await fetch(`${apiBase}/v1/embeddings`, { + const resp = await fetch(`${apiBase}/embeddings`, { method: "POST", body: JSON.stringify({ input: chunk, diff --git a/core/llm/llms/OpenAI.ts b/core/llm/llms/OpenAI.ts index 8ce374414..b0c357765 100644 --- a/core/llm/llms/OpenAI.ts +++ b/core/llm/llms/OpenAI.ts @@ -24,7 +24,7 @@ const NON_CHAT_MODELS = [ class OpenAI extends BaseLLM { static providerName: ModelProvider = "openai"; static defaultOptions: Partial = { - apiBase: "https://api.openai.com", + apiBase: "https://api.openai.com/v1", }; protected _convertMessage(message: ChatMessage) { @@ -87,9 +87,7 @@ class OpenAI extends BaseLLM { if (url.endsWith("/")) { url = url.slice(0, -1); } - if (!url.endsWith("/v1") && !url.includes("api.perplexity.ai")) { - url += "/v1"; - } + return url + "/completions"; } } @@ -148,10 +146,6 @@ class OpenAI extends BaseLLM { url = url.slice(0, -1); } - if (!url.includes("/v1") && !url.includes("api.perplexity.ai")) { - // includes instead of endsWith becuase DeepInfra uses /v1/openai/chat/completions - url += "/v1"; - } return url + "/chat/completions"; } } diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index 86aadd082..fc893cb5f 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -172,7 +172,8 @@ "deepseek", "openchat", "xwin-coder", - "neural-chat" + "neural-chat", + "codellama-70b" ], "type": "string" }, diff --git a/extensions/vscode/src/loadConfig.ts b/extensions/vscode/src/loadConfig.ts index 5036a3f84..3f208eee6 100644 --- a/extensions/vscode/src/loadConfig.ts +++ b/extensions/vscode/src/loadConfig.ts @@ -105,10 +105,13 @@ export async function llmFromTitle(title?: string): Promise { }); if (!resp.ok) { + let text = await resp.text(); + if (resp.status === 404 && !resp.url.includes("/v1")) { + text = + "This may mean that you forgot to add '/v1' to the end of your 'apiBase' in config.json."; + } throw new Error( - `HTTP ${resp.status} ${resp.statusText} from ${ - resp.url - }\n\n${await resp.text()}` + `HTTP ${resp.status} ${resp.statusText} from ${resp.url}\n\n${text}` ); } From b1a42b63f4b58a819509edc428e279f4f42dc7a6 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 31 Jan 2024 23:11:54 +0000 Subject: [PATCH 29/31] =?UTF-8?q?=F0=9F=92=9A=20Update=20package.json=20ve?= =?UTF-8?q?rsion=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/package-lock.json | 4 ++-- extensions/vscode/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 0bc92b4cf..3b5402e8a 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.39", + "version": "0.9.40", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.39", + "version": "0.9.40", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 7ef35120b..3de79d1af 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -1,7 +1,7 @@ { "name": "continue", "icon": "media/icon.png", - "version": "0.9.39", + "version": "0.9.40", "repository": { "type": "git", "url": "https://github.com/continuedev/continue" From 57573705dfb020bc2ed0908160fd3f31d454fe20 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 31 Jan 2024 15:40:24 -0800 Subject: [PATCH 30/31] =?UTF-8?q?=F0=9F=94=A5=20remove=20phind=20codellama?= =?UTF-8?q?=20from=20free=20trial=20defaults?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/config/default.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/config/default.ts b/core/config/default.ts index fc52f24c3..037c7d15b 100644 --- a/core/config/default.ts +++ b/core/config/default.ts @@ -12,11 +12,6 @@ const defaultConfig: SerializedContinueConfig = { provider: "free-trial", model: "gpt-4-vision-preview", }, - { - title: "Phind CodeLlama (Free Trial)", - provider: "free-trial", - model: "phind-codellama-34b", - }, { title: "Gemini Pro (Free Trial)", provider: "free-trial", From 2b3f7db3981d56ccd05f653f4526021d92a6be49 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 31 Jan 2024 17:22:14 -0800 Subject: [PATCH 31/31] =?UTF-8?q?=F0=9F=94=96=20update=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 3de79d1af..1e636c012 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -1,7 +1,7 @@ { "name": "continue", "icon": "media/icon.png", - "version": "0.9.40", + "version": "0.9.41", "repository": { "type": "git", "url": "https://github.com/continuedev/continue"