From 34627a94d473a16ffdc6c185ac695bd1ebfc7043 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Sun, 17 Nov 2024 02:25:32 -0800 Subject: [PATCH] indexing manager p2 --- core/core.ts | 11 ++-- core/index.d.ts | 5 ++ core/indexing/IndexingStatusManager.ts | 89 +++++++++++--------------- core/indexing/docs/DocsService.ts | 24 ++++--- core/protocol/core.ts | 11 ++-- core/protocol/webview.ts | 4 +- extensions/vscode/package-lock.json | 4 +- gui/src/hooks/useSetup.ts | 10 +++ 8 files changed, 85 insertions(+), 73 deletions(-) diff --git a/core/core.ts b/core/core.ts index fe07ecbce..8a27fedc3 100644 --- a/core/core.ts +++ b/core/core.ts @@ -110,12 +110,15 @@ export class Core { this.controlPlaneClient, ); - this.indexingManager = new IndexingStatusManager(this.messenger); + this.indexingManager = IndexingStatusManager.createSingleton( + this.messenger, + ); this.docsService = DocsService.createSingleton( this.configHandler, this.ide, this.messenger, + this.indexingManager, ); this.configHandler.onConfigUpdate( @@ -714,13 +717,13 @@ export class Core { }); on("indexing/reindex", async (msg) => { - this.indexingManager.reindex(msg.data.id); + this.indexingManager.reindex(msg.data.identifier); }); on("indexing/abort", async (msg) => { - this.indexingManager.abort(msg.data.id); + this.indexingManager.abort(msg.data.identifier); }); on("indexing/setPaused", async (msg) => { - this.indexingManager.setPaused(msg.data.id, msg.data.pause); + this.indexingManager.setPaused(msg.data.identifier, msg.data.pause); }); on("indexing/getStatuses", async (msg) => { return this.indexingManager.statuses; diff --git a/core/index.d.ts b/core/index.d.ts index f1c7263eb..53ca6ae42 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -57,6 +57,11 @@ export interface IndexingStatusUpdate { debugInfo?: string; } +interface IndexIdentifier { + type: string; + id: string; +} + export type IndexingStatusMap = Map< string, Map diff --git a/core/indexing/IndexingStatusManager.ts b/core/indexing/IndexingStatusManager.ts index 1ba177493..785f14b95 100644 --- a/core/indexing/IndexingStatusManager.ts +++ b/core/indexing/IndexingStatusManager.ts @@ -1,4 +1,4 @@ -import { IndexingStatusMap, IndexingStatusUpdate } from ".."; +import { IndexIdentifier, IndexingStatusMap, IndexingStatusUpdate } from ".."; import { FromCoreProtocol, ToCoreProtocol } from "../protocol"; import { IMessenger } from "../util/messenger"; @@ -7,7 +7,8 @@ import { IMessenger } from "../util/messenger"; 1. Pass indexingManager to the service 2. Register the service with the manager using `registerService` E.g. docs uses startUrl as id - 3. + 3. Rules of engagement: + - service is responsible for checking corrupted indexes - don't check paused or deleted */ export class IndexingStatusManager { private readonly messenger: IMessenger; @@ -21,26 +22,29 @@ export class IndexingStatusManager { this.messenger = messenger; } + private static instance?: IndexingStatusManager; + static createSingleton( + messenger: IMessenger, + ) { + const instance = new IndexingStatusManager(messenger); + IndexingStatusManager.instance = instance; + return instance; + } + + static getSingleton() { + return IndexingStatusManager.instance; + } + // Services that use an instance of this class should add their reindex functions here registerService(type: string, fn: (id: string) => Promise) { this.reindexTypeFunctions.set(type, fn); this.statuses.set(type, new Map()); } - reindex(type: string, id: string) { - const byType = this.statuses.get(type); + reindex({ type, id }: IndexIdentifier) { const reindexFn = this.reindexTypeFunctions.get(type); - - if (byType && reindexFn) { - const status = byType.get(id); - if (status) { - if (status.status === "deleted") { - throw new Error( - "Cannot reindex a deleted item, shouldn't ever happen", - ); - } - void reindexFn(id); - } + if (reindexFn) { + void reindexFn(id); } } @@ -52,53 +56,38 @@ export class IndexingStatusManager { } } - delete(type: string, id: string) { - const byType = this.statuses.get(type); - if (byType) { - const status = byType.get(id); - if (status) { - this.handleUpdate({ ...status, status: "deleted" }); - } + delete({ type, id }: IndexIdentifier) { + const status = this.statuses.get(type)?.get(id); + if (status) { + this.handleUpdate({ ...status, status: "deleted" }); } } - abort(type: string, id: string) { - const byType = this.statuses.get(type); - if (byType) { - const status = byType.get(id); - if (status) { - this.handleUpdate({ ...status, status: "aborted" }); - } + abort({ type, id }: IndexIdentifier) { + const status = this.statuses.get(type)?.get(id); + if (status) { + this.handleUpdate({ ...status, status: "aborted" }); } } - isAborted(type: string, id: string) { - const byType = this.statuses.get(type); - if (byType) { - const status = byType.get(id); - if (status) { - return status.status === "aborted"; - } + isAborted({ type, id }: IndexIdentifier) { + const status = this.statuses.get(type)?.get(id); + if (status) { + return status.status === "aborted"; } } - setPaused(type: string, id: string, pause: boolean) { - const byType = this.statuses.get(type); - if (byType) { - const status = byType.get(id); - if (status) { - this.handleUpdate({ ...status, status: pause ? "paused" : "indexing" }); - } + setPaused({ type, id }: IndexIdentifier, pause: boolean) { + const status = this.statuses.get(type)?.get(id); + if (status) { + this.handleUpdate({ ...status, status: pause ? "paused" : "indexing" }); } } - isPaused(type: string, id: string) { - const byType = this.statuses.get(type); - if (byType) { - const status = byType.get(id); - if (status) { - return status.status === "paused"; - } + isPaused({ type, id }: IndexIdentifier) { + const status = this.statuses.get(type)?.get(id); + if (status) { + return status.status === "paused"; } } } diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 9450cca6b..cb6e12bee 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -111,8 +111,14 @@ export default class DocsService { configHandler: ConfigHandler, ide: IDE, messenger?: IMessenger, + indexingManager?: IndexingStatusManager, ) { - const docsService = new DocsService(configHandler, ide, messenger); + const docsService = new DocsService( + configHandler, + ide, + messenger, + indexingManager, + ); DocsService.instance = docsService; return docsService; } @@ -127,9 +133,9 @@ export default class DocsService { DocsService.indexingType, this.reindexDoc, ); - this.config = await configHandler.loadConfig(); - await this.handleConfigUpdate({ config: this.config }); - configHandler.onConfigUpdate(this.handleConfigUpdate); + const config = await configHandler.loadConfig(); + await this.handleConfigUpdate({ config }); + configHandler.onConfigUpdate(this.handleConfigUpdate.bind(this)); } // Config @@ -502,7 +508,7 @@ export default class DocsService { const [vector] = await embeddingsProvider.embed([query]); - return await this.retrieveChunks(query, vector, nRetrieve); + return await this.retrieveChunks(startUrl, vector, nRetrieve); } async retrieveChunks( @@ -525,7 +531,7 @@ export default class DocsService { .where(`starturl = '${startUrl}'`) .execute(); } catch (e: any) { - console.error("Error retrieving chunks from LanceDB", e); + console.warn("Error retrieving chunks from LanceDB", e); } const hasIndexedDoc = await this.hasMetadata(startUrl); @@ -597,14 +603,14 @@ export default class DocsService { Ignores pre-indexed docs */ private async syncDocsOnConfigUpdate( - oldConfig: ContinueConfig, + oldConfig: ContinueConfig | undefined, newConfig: ContinueConfig, ) { try { this.isSyncing = true; // Otherwise sync the index based on config changes - const oldConfigDocs = oldConfig.docs || []; + const oldConfigDocs = oldConfig?.docs || []; const newConfigDocs = newConfig.docs || []; const newConfigStartUrls = newConfigDocs.map((doc) => doc.startUrl); @@ -664,7 +670,7 @@ export default class DocsService { await this.delete(doc.startUrl); } } catch (e) { - console.error("Error syncing config and sqlite", e); + console.error("Error syncing docs index on config update", e); } finally { this.isSyncing = false; } diff --git a/core/protocol/core.ts b/core/protocol/core.ts index fec158eac..2e5a660d4 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -8,6 +8,7 @@ import type { ContextSubmenuItem, DiffLine, IdeSettings, + IndexIdentifier, IndexingStatusMap, LLMFullCompletionOptions, MessageContent, @@ -159,13 +160,11 @@ export type ToCoreFromIdeOrWebviewProtocol = { ]; // Docs Indexing. TODO move codebase to this - "indexing/reindex": [ - { id: string; shouldClearAllOfIndexType?: boolean }, - void, - ]; - "indexing/abort": [{ id: string }, void]; - "indexing/setPaused": [{ id: string; pause: boolean }, void]; + "indexing/reindex": [{ identifier: IndexIdentifier }, void]; + "indexing/abort": [{ identifier: IndexIdentifier }, void]; + "indexing/setPaused": [{ identifier: IndexIdentifier; pause: boolean }, void]; "indexing/getStatuses": [undefined, IndexingStatusMap]; + addAutocompleteModel: [{ model: ModelDescription }, void]; "profiles/switch": [{ id: string }, undefined]; diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index 4fd2f7094..e5330d81f 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -10,8 +10,8 @@ export type ToWebviewFromIdeOrCoreProtocol = { configUpdate: [undefined, void]; configError: [ConfigValidationError[] | undefined, void]; getDefaultModelTitle: [undefined, string]; - indexProgress: [IndexingProgressUpdate, void]; - "indexing/statusUpdate": [IndexingStatusUpdate, void]; + indexProgress: [IndexingProgressUpdate, void]; // Codebase + "indexing/statusUpdate": [IndexingStatusUpdate, void]; // Docs, etc. refreshSubmenuItems: [undefined, void]; isContinueInputFocused: [undefined, boolean]; addContextItem: [ diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 24930d980..29ac4731f 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.229", + "version": "0.9.230", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.229", + "version": "0.9.230", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 5329abdda..07bcec0eb 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -135,6 +135,16 @@ function useSetup(dispatch: Dispatch) { ); }); + useWebviewListener("indexing/statusUpdate", async (data) => { + console.log("Indexing status update", data); + // dispatch( + // addContextItemsAtIndex({ + // index: data.historyIndex, + // contextItems: [data.item], + // }), + // ); + }); + useWebviewListener( "getDefaultModelTitle", async () => {