From f52fbca1d5e09982db1a5040ebd928af7730a92c Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Sun, 17 Nov 2024 20:29:19 -0800 Subject: [PATCH] docs indexing on more --- core/core.ts | 47 +-- core/index.d.ts | 24 +- core/indexing/IndexingStatusManager.ts | 93 ----- core/indexing/docs/DocsService.ts | 328 +++++++++++------- core/protocol/core.ts | 11 +- core/protocol/passThrough.ts | 2 +- core/protocol/webview.ts | 4 +- extensions/vscode/config_schema.json | 2 +- gui/src/components/Footer.tsx | 71 ++-- .../indexing/FooterIndexingPeeks.tsx | 80 +++++ .../components/indexing/IndexingStatus.tsx | 135 +++++++ .../components/indexing/IndexingStatuses.tsx | 50 +++ gui/src/components/indexing/utils.ts | 17 + gui/src/hooks/useSetup.ts | 21 +- gui/src/index.css | 19 + gui/src/pages/More/More.tsx | 4 + gui/src/redux/slices/stateSlice.ts | 16 +- 17 files changed, 620 insertions(+), 304 deletions(-) delete mode 100644 core/indexing/IndexingStatusManager.ts create mode 100644 gui/src/components/indexing/FooterIndexingPeeks.tsx create mode 100644 gui/src/components/indexing/IndexingStatus.tsx create mode 100644 gui/src/components/indexing/IndexingStatuses.tsx create mode 100644 gui/src/components/indexing/utils.ts diff --git a/core/core.ts b/core/core.ts index ab71ab4d7..823607814 100644 --- a/core/core.ts +++ b/core/core.ts @@ -35,7 +35,6 @@ import { TTS } from "./util/tts"; import type { ContextItemId, IDE, IndexingProgressUpdate } from "."; import type { FromCoreProtocol, ToCoreProtocol } from "./protocol"; import type { IMessenger, Message } from "./util/messenger"; -import { IndexingStatusManager } from "./indexing/IndexingStatusManager"; export class Core { // implements IMessenger @@ -45,7 +44,6 @@ export class Core { continueServerClientPromise: Promise; codebaseIndexingState: IndexingProgressUpdate; controlPlaneClient: ControlPlaneClient; - private indexingManager: IndexingStatusManager; private docsService: DocsService; private globalContext = new GlobalContext(); @@ -110,15 +108,10 @@ export class Core { this.controlPlaneClient, ); - this.indexingManager = IndexingStatusManager.createSingleton( - this.messenger, - ); - this.docsService = DocsService.createSingleton( this.configHandler, this.ide, this.messenger, - this.indexingManager, ); this.configHandler.onConfigUpdate( @@ -292,7 +285,7 @@ export class Core { }); on("context/indexDocs", async (msg) => { - await this.docsService.indexAllDocsWithPrompt(msg.data.reIndex); + await this.docsService.syncOrReindexAllDocsWithPrompt(msg.data.reIndex); }); on("context/loadSubmenuItems", async (msg) => { @@ -671,6 +664,8 @@ export class Core { const rows = await DevDataSqliteDb.getTokensPerModel(); return rows; }); + + // Codebase indexing on("index/forceReIndex", async ({ data }) => { if (data?.shouldClearIndexes) { const codebaseIndexer = await this.codebaseIndexerPromise; @@ -700,6 +695,27 @@ export class Core { } }); + // Docs, etc. indexing + on("indexing/reindex", async (msg) => { + if (msg.data.type === "docs") { + void this.docsService.reindexDoc(msg.data.id); + } + }); + on("indexing/abort", async (msg) => { + if (msg.data.type === "docs") { + this.docsService.abort(msg.data.id); + } + }); + on("indexing/setPaused", async (msg) => { + if (msg.data.type === "docs") { + this.docsService.setPaused(msg.data.id, msg.data.paused); + } + }); + on("indexing/initStatuses", async (msg) => { + return this.docsService.initStatuses(); + }); + // + on("didChangeSelectedProfile", (msg) => { void this.configHandler.setSelectedProfile(msg.data.id); void this.configHandler.reloadConfig(); @@ -720,19 +736,6 @@ export class Core { recentlyEditedFilesCache.set(filepath, filepath); } }); - - on("indexing/reindex", async (msg) => { - this.indexingManager.reindex(msg.data.identifier); - }); - on("indexing/abort", async (msg) => { - this.indexingManager.abort(msg.data.identifier); - }); - on("indexing/setPaused", async (msg) => { - this.indexingManager.setPaused(msg.data.identifier, msg.data.pause); - }); - on("indexing/getStatuses", async (msg) => { - return this.indexingManager.statuses; - }); } private indexingCancellationController: AbortController | undefined; @@ -803,7 +806,7 @@ export class Core { } void this.messenger.request("indexProgress", updateToSend); - this.indexingState = updateToSend; + this.codebaseIndexingState = updateToSend; if (update.status === "failed") { void this.sendIndexingErrorTelemetry(update); diff --git a/core/index.d.ts b/core/index.d.ts index 53ca6ae42..32685b79a 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -46,26 +46,28 @@ export interface IndexingProgressUpdate { } // This is more or less a V2 of IndexingProgressUpdate -export interface IndexingStatusUpdate { +export interface IndexingStatus { id: string; type: "docs"; progress: number; description: string; - status: "indexing" | "complete" | "paused" | "failed" | "aborted" | "deleted"; + status: + | "indexing" + | "complete" + | "paused" + | "failed" + | "aborted" + | "deleted" + | "pending"; embeddingsProviderId: string; isReindexing?: boolean; debugInfo?: string; + title: string; + icon?: string; + url?: string; } -interface IndexIdentifier { - type: string; - id: string; -} - -export type IndexingStatusMap = Map< - string, - Map ->; +export type IndexingStatusMap = Map; export type PromptTemplateFunction = ( history: ChatMessage[], diff --git a/core/indexing/IndexingStatusManager.ts b/core/indexing/IndexingStatusManager.ts deleted file mode 100644 index 785f14b95..000000000 --- a/core/indexing/IndexingStatusManager.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { IndexIdentifier, IndexingStatusMap, IndexingStatusUpdate } from ".."; -import { FromCoreProtocol, ToCoreProtocol } from "../protocol"; -import { IMessenger } from "../util/messenger"; - -/* - Any service that sends indexing updates can use an instance of this class - 1. Pass indexingManager to the service - 2. Register the service with the manager using `registerService` - E.g. docs uses startUrl as id - 3. Rules of engagement: - - service is responsible for checking corrupted indexes - don't check paused or deleted -*/ -export class IndexingStatusManager { - private readonly messenger: IMessenger; - readonly statuses: IndexingStatusMap = new Map(); - private readonly reindexTypeFunctions: Map< - string, - (id: string) => Promise - > = new Map(); - - constructor(messenger: IMessenger) { - 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, id }: IndexIdentifier) { - const reindexFn = this.reindexTypeFunctions.get(type); - if (reindexFn) { - void reindexFn(id); - } - } - - handleUpdate(status: IndexingStatusUpdate) { - const byType = this.statuses.get(status.type); - if (byType) { - byType.set(status.id, status); - this.messenger.send("indexing/statusUpdate", status); - } - } - - delete({ type, id }: IndexIdentifier) { - const status = this.statuses.get(type)?.get(id); - if (status) { - this.handleUpdate({ ...status, status: "deleted" }); - } - } - - abort({ type, id }: IndexIdentifier) { - const status = this.statuses.get(type)?.get(id); - if (status) { - this.handleUpdate({ ...status, status: "aborted" }); - } - } - - isAborted({ type, id }: IndexIdentifier) { - const status = this.statuses.get(type)?.get(id); - if (status) { - return status.status === "aborted"; - } - } - - 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, 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 25f465be4..7c163667b 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -7,7 +7,8 @@ import { ContinueConfig, EmbeddingsProvider, IDE, - IndexingStatusUpdate, + IndexingStatusMap, + IndexingStatus, SiteIndexingConfig, } from "../.."; import { ConfigHandler } from "../../config/ConfigHandler"; @@ -24,7 +25,6 @@ import { } from "../../util/paths"; import { Telemetry } from "../../util/posthog"; import TransformersJsEmbeddingsProvider from "../embeddings/TransformersJsEmbeddingsProvider"; -import { IndexingStatusManager } from "../IndexingStatusManager"; import { Article, chunkArticle, pageToArticle } from "./article"; import DocsCrawler from "./DocsCrawler"; @@ -100,7 +100,6 @@ export default class DocsService { configHandler: ConfigHandler, private readonly ide: IDE, private readonly messenger?: IMessenger, - private readonly indexingManager?: IndexingStatusManager, ) { this.isInitialized = this.init(configHandler); } @@ -111,14 +110,8 @@ export default class DocsService { configHandler: ConfigHandler, ide: IDE, messenger?: IMessenger, - indexingManager?: IndexingStatusManager, ) { - const docsService = new DocsService( - configHandler, - ide, - messenger, - indexingManager, - ); + const docsService = new DocsService(configHandler, ide, messenger); DocsService.instance = docsService; return docsService; } @@ -129,26 +122,46 @@ export default class DocsService { // Initialization - load config and attach config listener private async init(configHandler: ConfigHandler) { - this.indexingManager?.registerService( - DocsService.indexingType, - this.reindexDoc, - ); const config = await configHandler.loadConfig(); - this.config = config; - - // On first go we want to have an indexing status for all docs - // Since config handler will only trigger indexing status updates on changes - if (config.docs?.length) { - for (const doc of config.docs) { - await this.indexAndAdd(doc); - } - } - await this.handleConfigUpdate({ config }); configHandler.onConfigUpdate(this.handleConfigUpdate.bind(this)); } - // Config + readonly statuses: IndexingStatusMap = new Map(); + + handleStatusUpdate(update: IndexingStatus) { + this.statuses.set(update.id, update); + this.messenger?.send("indexing/statusUpdate", update); + } + + abort(startUrl: string) { + const status = this.statuses.get(startUrl); + if (status) { + this.handleStatusUpdate({ + ...status, + status: "aborted", + }); + } + } + + isAborted(startUrl: string) { + return this.statuses.get(startUrl)?.status === "aborted"; + } + + // Pausing not supported for docs yet + // setPaused(startUrl: string, pause: boolean) { + // const status = this.statuses.get(startUrl); + // if (status) { + // this.handleStatusUpdate({ + // ...status, + // status: pause ? "paused" : "indexing", + // }); + // } + // } + + // isPaused(startUrl: string) { + // return this.statuses.get(startUrl)?.status === "paused"; + // } /* * Currently, we generate and host embeddings for pre-indexed docs using transformers. @@ -183,8 +196,6 @@ export default class DocsService { return this.config.embeddingsProvider; } - // Expose this so that docs provider can check it - private async handleConfigUpdate({ config: newConfig, }: { @@ -203,27 +214,49 @@ export default class DocsService { return; } - // On embeddings provider change, reindex all non-preindexed docs - // change = doesn't match last successful embeddings provider - const curEmbeddingsProviderId = this.globalContext.get( - "curEmbeddingsProviderId", - ); - if ( - !curEmbeddingsProviderId || - curEmbeddingsProviderId !== newConfig.embeddingsProvider.id - ) { - // If not set, we're initializing - const currentDocs = await this.listMetadata(); - if (currentDocs.length > 0) { - await this.reindexDocsOnNewEmbeddingsProvider(); - return; - } - } - - await this.syncDocsOnConfigUpdate(oldConfig, newConfig); + await this.syncOrReindexAllDocs(newConfig, oldConfig); } } + private async syncOrReindexAllDocs( + newConfig: ContinueConfig, + oldConfig?: ContinueConfig, + ) { + // On embeddings provider change, reindex all non-preindexed docs + // change = doesn't match last successful embeddings provider + const curEmbeddingsProviderId = this.globalContext.get( + "curEmbeddingsProviderId", + ); + if ( + !curEmbeddingsProviderId || + curEmbeddingsProviderId !== newConfig.embeddingsProvider.id + ) { + // If not set, we're initializing + const currentDocs = await this.listMetadata(); + if (currentDocs.length > 0) { + await this.reindexDocsOnNewEmbeddingsProvider(); + return; + } + } + + await this.syncDocsOnConfigUpdate(oldConfig, newConfig); + } + + async syncOrReindexAllDocsWithPrompt(reIndex: boolean = false) { + if (!this.hasDocsContextProvider()) { + const didAddDocsContextProvider = + await this.showAddDocsContextProviderToast(); + + if (!didAddDocsContextProvider) { + return; + } + } + + await this.syncOrReindexAllDocs(this.config); + + void this.ide.showToast("info", "Docs indexing completed"); + } + async hasMetadata(startUrl: string): Promise> { const db = await this.getOrCreateSqliteDb(); const title = await db.get( @@ -234,16 +267,6 @@ export default class DocsService { return !!title; } - // private async hasIndexedDoc(startUrl: string) { - // const db = await this.getOrCreateSqliteDb(); - // const docs = await db.all( - // `SELECT startUrl FROM ${DocsService.sqlitebTableName} WHERE startUrl = ?`, - // startUrl, - // ); - - // return docs.length > 0; - // } - async showAddDocsContextProviderToast() { const actionMsg = "Add 'docs' context provider"; const res = await this.ide.showToast( @@ -267,25 +290,6 @@ export default class DocsService { return res === actionMsg; } - async indexAllDocsWithPrompt(reIndex: boolean = false) { - if (!this.hasDocsContextProvider()) { - const didAddDocsContextProvider = - await this.showAddDocsContextProviderToast(); - - if (!didAddDocsContextProvider) { - return; - } - } - - const docs = await this.listMetadata(); - - for (const doc of docs) { - await this.indexAndAdd(doc, reIndex); - } - - void this.ide.showToast("info", "Docs indexing completed"); - } - async listMetadata() { const db = await this.getOrCreateSqliteDb(); const docs = await db.all( @@ -295,10 +299,6 @@ export default class DocsService { return docs; } - updateIndexingStatus(update: IndexingStatusUpdate) { - this.indexingManager?.handleUpdate(update); - } - async reindexDoc(startUrl: string) { const docConfig = this.config.docs?.find( (doc) => doc.startUrl === startUrl, @@ -323,36 +323,53 @@ export default class DocsService { const indexExists = await this.hasMetadata(startUrl); const fixedStatus: Pick< - IndexingStatusUpdate, - "type" | "id" | "embeddingsProviderId" | "isReindexing" + IndexingStatus, + | "type" + | "id" + | "embeddingsProviderId" + | "isReindexing" + | "debugInfo" + | "icon" + | "url" + | "title" > = { type: "docs", id: siteIndexingConfig.startUrl, embeddingsProviderId: embeddingsProvider.id, isReindexing: reIndex && indexExists, + title: siteIndexingConfig.title, + debugInfo: `max depth: ${siteIndexingConfig.maxDepth}`, + icon: siteIndexingConfig.faviconUrl, + url: siteIndexingConfig.startUrl, }; - if (indexExists && !reIndex) { - this.updateIndexingStatus({ - ...fixedStatus, - progress: 1, - description: "Complete", - status: "complete", - debugInfo: "Already indexed", - }); - return; + if (indexExists) { + if (reIndex) { + await this.deleteIndexes(startUrl); + } else { + this.handleStatusUpdate({ + ...fixedStatus, + progress: 1, + description: "Complete", + status: "complete", + debugInfo: "Already indexed", + }); + return; + } } // Mark the site as currently being indexed this.docsIndexingQueue.add(startUrl); try { - this.updateIndexingStatus({ + this.handleStatusUpdate({ ...fixedStatus, status: "indexing", description: "Finding subpages", progress: 0, }); + // NOTE - during "indexing" phase, check if aborted before each status update + const articles: Article[] = []; let processedPages = 0; let maxKnownPages = 1; @@ -372,7 +389,10 @@ export default class DocsService { // Use a heuristic approach for progress calculation const progress = Math.min(processedPages / maxKnownPages, 1); - this.updateIndexingStatus({ + if (this.isAborted(startUrl)) { + return; + } + this.handleStatusUpdate({ ...fixedStatus, description: `Finding subpages (${page.path})`, status: "indexing", @@ -399,7 +419,11 @@ export default class DocsService { for (let i = 0; i < articles.length; i++) { const article = articles[i]; - this.updateIndexingStatus({ + + if (this.isAborted(startUrl)) { + return; + } + this.handleStatusUpdate({ ...fixedStatus, status: "indexing", description: `Creating Embeddings: ${article.subpath}`, @@ -433,7 +457,10 @@ export default class DocsService { `No embeddings were created for site: ${siteIndexingConfig.startUrl}\n Num chunks: ${chunks.length}`, ); - this.updateIndexingStatus({ + if (this.isAborted(startUrl)) { + return; + } + this.handleStatusUpdate({ ...fixedStatus, description: `No embeddings were created for site: ${siteIndexingConfig.startUrl}`, status: "failed", @@ -450,21 +477,34 @@ export default class DocsService { // Add docs to databases console.log(`Adding ${embeddings.length} embeddings to db`); - this.updateIndexingStatus({ + if (this.isAborted(startUrl)) { + return; + } + this.handleStatusUpdate({ ...fixedStatus, - description: `Adding ${embeddings.length} embeddings to db`, + description: "Deleting old embeddings from the db", status: "indexing", progress: 0.5, }); // Delete indexed docs if re-indexing - if (reIndex && (await this.hasMetadata(startUrl.toString()))) { + if (reIndex && indexExists) { console.log("Deleting old embeddings"); - await this.delete(startUrl); + await this.deleteIndexes(startUrl); } const favicon = await fetchFavicon(new URL(siteIndexingConfig.startUrl)); + if (this.isAborted(startUrl)) { + return; + } + this.handleStatusUpdate({ + ...fixedStatus, + description: `Adding ${embeddings.length} embeddings to db`, + status: "indexing", + progress: 0.5, + }); + await this.add({ siteIndexingConfig, chunks, @@ -474,7 +514,10 @@ export default class DocsService { this.docsIndexingQueue.delete(startUrl); - this.updateIndexingStatus({ + if (this.isAborted(startUrl)) { + return; + } + this.handleStatusUpdate({ ...fixedStatus, description: "Complete", status: "complete", @@ -488,7 +531,7 @@ export default class DocsService { } } catch (e) { console.error("Error indexing docs", e); - this.updateIndexingStatus({ + this.handleStatusUpdate({ ...fixedStatus, description: `No embeddings were created for site: ${siteIndexingConfig.startUrl}`, status: "failed", @@ -499,6 +542,31 @@ export default class DocsService { } } + // Function for GUI to retrieve initial pending statuses + // And kickoff indexing where needed + async initStatuses() { + this.config?.docs?.forEach(async (doc) => { + const currentStatus = this.statuses.get(doc.startUrl); + if (currentStatus) { + this.handleStatusUpdate(currentStatus); + } else { + this.handleStatusUpdate({ + type: "docs", + id: doc.startUrl, + embeddingsProviderId: this.config.embeddingsProvider.id, + isReindexing: false, + progress: 0, + description: "Pending", + status: "pending", + title: doc.title, + debugInfo: `max depth: ${doc.maxDepth}`, + icon: doc.faviconUrl, + url: doc.startUrl, + }); + } + }); + } + // Retrieve docs embeds based on user input async retrieveChunksFromQuery( query: string, @@ -638,10 +706,6 @@ export default class DocsService { const currentlyIndexedDocs = await this.listMetadata(); const currentStartUrls = currentlyIndexedDocs.map((doc) => doc.startUrl); - // const newDocs = newConfigDocs.filter( - // (doc) => !currentStartUrls.includes(doc.startUrl), - // ); - // Anything found in sqlite but not in new config should be deleted const deletedDocs = currentlyIndexedDocs.filter( (doc) => @@ -668,13 +732,30 @@ export default class DocsService { oldConfigDoc.faviconUrl !== doc.faviconUrl) ) { changedDocs.push(doc); + } else { + // if get's here, not changed, no update needed, mark as complete + this.handleStatusUpdate({ + type: "docs", + id: doc.startUrl, + embeddingsProviderId: this.config.embeddingsProvider.id, + isReindexing: false, + title: doc.title, + debugInfo: "Config sync: not changed", + icon: doc.faviconUrl, + url: doc.startUrl, + progress: 1, + description: "Complete", + status: "complete", + }); } - // if get's here, not changed, no update needed } else { newDocs.push(doc); } } + // Sends "Pending" or current status for each + await this.initStatuses(); + for (const doc of changedDocs) { console.log(`Updating indexed doc: ${doc.startUrl}`); await this.indexAndAdd(doc, true); @@ -688,7 +769,7 @@ export default class DocsService { } for (const doc of deletedDocs) { - await this.delete(doc.startUrl); + await this.deleteIndexes(doc.startUrl); } } catch (e) { console.error("Error syncing docs index on config update", e); @@ -852,7 +933,7 @@ export default class DocsService { } } - // Delete methods for individual docs + // Delete methods private async deleteEmbeddingsFromLance(startUrl: string) { for (const tableName of this.lanceTableNamesSet) { const conn = await lancedb.connect(getLanceDbPath()); @@ -870,20 +951,31 @@ export default class DocsService { } private deleteFromConfig(startUrl: string) { - editConfigJson((config) => ({ - ...config, - docs: config.docs?.filter((doc) => doc.startUrl !== startUrl) || [], - })); + const doesDocExist = this.config.docs?.some( + (doc) => doc.startUrl === startUrl, + ); + if (doesDocExist) { + editConfigJson((config) => ({ + ...config, + docs: config.docs?.filter((doc) => doc.startUrl !== startUrl) || [], + })); + } + } + + async deleteIndexes(startUrl: string) { + await this.deleteEmbeddingsFromLance(startUrl); + await this.deleteMetadataFromSqlite(startUrl); } async delete(startUrl: string) { - await this.deleteEmbeddingsFromLance(startUrl); - await this.deleteMetadataFromSqlite(startUrl); + await this.deleteIndexes(startUrl); this.deleteFromConfig(startUrl); - if (this.messenger) { - this.messenger.send("refreshSubmenuItems", undefined); + const status = this.statuses.get(startUrl); + if (status) { + this.handleStatusUpdate({ ...status, status: "deleted" }); } + this.messenger?.send("refreshSubmenuItems", undefined); } // When user requests a pre-indexed doc for the first time @@ -934,13 +1026,9 @@ export default class DocsService { console.log( `Reindexing non-preindexed docs with new embeddings provider: ${embeddingsProvider.id}`, ); - + await this.initStatuses(); for (const doc of docs) { - await this.delete(doc.startUrl); - } - - for (const doc of docs) { - await this.indexAndAdd(doc); + await this.indexAndAdd(doc, true); } // Important that this only is invoked after we have successfully diff --git a/core/protocol/core.ts b/core/protocol/core.ts index 65a798c55..f6c849963 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -8,7 +8,6 @@ import type { ContextSubmenuItem, DiffLine, IdeSettings, - IndexIdentifier, IndexingStatusMap, LLMFullCompletionOptions, MessageContent, @@ -160,11 +159,11 @@ export type ToCoreFromIdeOrWebviewProtocol = { void, ]; - // Docs Indexing. TODO move codebase to this - "indexing/reindex": [{ identifier: IndexIdentifier }, void]; - "indexing/abort": [{ identifier: IndexIdentifier }, void]; - "indexing/setPaused": [{ identifier: IndexIdentifier; pause: boolean }, void]; - "indexing/getStatuses": [undefined, IndexingStatusMap]; + // Docs etc. Indexing. TODO move codebase to this + "indexing/reindex": [{ type: string; id: string }, void]; + "indexing/abort": [{ type: string; id: string }, void]; + "indexing/setPaused": [{ type: string; id: string; paused: boolean }, void]; + "indexing/initStatuses": [undefined, void]; addAutocompleteModel: [{ model: ModelDescription }, void]; diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index 1997b8700..71e35fe65 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -45,7 +45,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] = "index/forceReIndexFiles", "index/indexingProgressBarInitialized", // Docs, etc. - "indexing/getStatuses", + "indexing/initStatuses", "indexing/reindex", "indexing/abort", "indexing/setPaused", diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index e5330d81f..d259fde9e 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -3,7 +3,7 @@ import { ConfigValidationError } from "../config/validation.js"; import type { ContextItemWithId, IndexingProgressUpdate, - IndexingStatusUpdate, + IndexingStatus, } from "../index.js"; export type ToWebviewFromIdeOrCoreProtocol = { @@ -11,7 +11,7 @@ export type ToWebviewFromIdeOrCoreProtocol = { configError: [ConfigValidationError[] | undefined, void]; getDefaultModelTitle: [undefined, string]; indexProgress: [IndexingProgressUpdate, void]; // Codebase - "indexing/statusUpdate": [IndexingStatusUpdate, void]; // Docs, etc. + "indexing/statusUpdate": [IndexingStatus, void]; // Docs, etc. refreshSubmenuItems: [undefined, void]; isContinueInputFocused: [undefined, boolean]; addContextItem: [ diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index eb75d1f90..76d27bec2 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -2325,7 +2325,7 @@ "type": "integer", "description": "The maximum depth to crawl the documentation site" }, - "favicon": { + "faviconUrl": { "type": "string", "description": "The URL path to a favicon for the site - by default, it will be `/favicon.ico` path from the Start URL" } diff --git a/gui/src/components/Footer.tsx b/gui/src/components/Footer.tsx index 0c094155c..bf51abc0f 100644 --- a/gui/src/components/Footer.tsx +++ b/gui/src/components/Footer.tsx @@ -14,6 +14,7 @@ import { ROUTES } from "../util/navigation"; import HeaderButtonWithToolTip from "./gui/HeaderButtonWithToolTip"; import FreeTrialProgressBar from "./loaders/FreeTrialProgressBar"; import ProfileSwitcher from "./ProfileSwitcher"; +import FooterIndexingPeeks from "./indexing/FooterIndexingPeeks"; function Footer() { const navigate = useNavigate(); @@ -47,45 +48,49 @@ function Footer() { } return ( -
-
- - {defaultModel?.provider === "free-trial" && ( - - )} -
+ <> + + +
+
+ + {defaultModel?.provider === "free-trial" && ( + + )} +
+ +
+ {configError && ( + + + + )} -
- {configError && ( - + - )} - - - - - - - -
-
+ + + + +
+ ); } diff --git a/gui/src/components/indexing/FooterIndexingPeeks.tsx b/gui/src/components/indexing/FooterIndexingPeeks.tsx new file mode 100644 index 000000000..c95e8db7d --- /dev/null +++ b/gui/src/components/indexing/FooterIndexingPeeks.tsx @@ -0,0 +1,80 @@ +import { useDispatch, useSelector } from "react-redux"; +import { RootState } from "../../redux/store"; + +import { IndexingStatus } from "core"; +import { useContext, useMemo } from "react"; +import { STATUS_TO_ICON } from "./utils"; +import { IdeMessengerContext } from "../../context/IdeMessenger"; + +interface IndexingStatusViewerProps { + status: IndexingStatus; +} + +function FooterIndexingPeek({ status }: IndexingStatusViewerProps) { + const ideMessenger = useContext(IdeMessengerContext); + + const progressPercentage = useMemo(() => { + return Math.min(100, Math.max(0, status.progress * 100)); + }, [status.progress]); + + const Icon = STATUS_TO_ICON[status.status]; + + return ( +
+
{ + if (status.url) { + ideMessenger.post("openUrl", status.url); + } + }} + > + {status.icon ? ( + doc icon + ) : null} +

+ {status.title ?? status.id} +

+
+
+
+
+
+ {progressPercentage.toFixed(0)}% + {Icon ? ( + + ) : null} +
+
+ ); +} + +function FooterIndexingPeeks() { + const indexingStatuses = useSelector( + (store: RootState) => store.state.indexingStatuses, + ); + const currentlyIndexingDocs = useMemo(() => { + return Object.values(indexingStatuses).filter( + (status) => status.status === "indexing", + ); + }, [indexingStatuses]); + + return ( + <> + {currentlyIndexingDocs.map((status) => { + return ; + })} + + ); +} + +export default FooterIndexingPeeks; diff --git a/gui/src/components/indexing/IndexingStatus.tsx b/gui/src/components/indexing/IndexingStatus.tsx new file mode 100644 index 000000000..eb53fd794 --- /dev/null +++ b/gui/src/components/indexing/IndexingStatus.tsx @@ -0,0 +1,135 @@ +import { IndexingStatus } from "core"; +import { PropsWithChildren, useContext, useMemo } from "react"; +import { useDispatch } from "react-redux"; +import { usePostHog } from "posthog-js/react"; +import { IdeMessengerContext } from "../../context/IdeMessenger"; +import { + ArrowPathIcon, + CheckCircleIcon, + PauseCircleIcon, + XMarkIcon, +} from "@heroicons/react/24/outline"; + +interface IndexingStatusViewerProps { + status: IndexingStatus; +} + +const STATUS_TO_ICON: Record = { + indexing: ArrowPathIcon, + paused: PauseCircleIcon, + complete: CheckCircleIcon, + aborted: null, + deleted: null, + pending: null, + failed: XMarkIcon, // Since we show an erorr message below +}; + +function IndexingStatusViewer({ status }: IndexingStatusViewerProps) { + const ideMessenger = useContext(IdeMessengerContext); + const posthog = usePostHog(); + + const reIndex = () => + ideMessenger.post("indexing/reindex", { + type: status.type, + id: status.id, + }); + + const abort = () => + ideMessenger.post("indexing/abort", { + type: status.type, + id: status.id, + }); + + const progressPercentage = useMemo(() => { + return Math.min(100, Math.max(0, status.progress * 100)); + }, [status.progress]); + + const Icon = STATUS_TO_ICON[status.status]; + + return ( +
+ {/* {`${status.type} - ${status.id} - ${status.status} - ${status.progress} - ${status.description} - ${status.icon}`} */} +
+
{ + if (status.url) { + ideMessenger.post("openUrl", status.url); + } + }} + > + {status.icon ? ( + doc icon + ) : null} +

+ {status.title ?? status.id} +

+
+ {status.status === "pending" ? ( +
Pending...
+ ) : ( +
+ {progressPercentage.toFixed(0)}% + {Icon ? ( + + ) : null} +
+ )} +
+ +
+
+
+ +
+ {}, + deleted: () => {}, + pending: () => {}, + }[status.status] + } + > + { + { + complete: "Click to re-index", + indexing: "Cancel indexing", + failed: "Click to retry", + aborted: "Click to index", + paused: "", + deleted: "", + pending: "", + }[status.status] + } + + + {status.status === "indexing" && ( + + {status.description} + + )} +
+
+ ); +} + +export default IndexingStatusViewer; diff --git a/gui/src/components/indexing/IndexingStatuses.tsx b/gui/src/components/indexing/IndexingStatuses.tsx new file mode 100644 index 000000000..bd7a61f44 --- /dev/null +++ b/gui/src/components/indexing/IndexingStatuses.tsx @@ -0,0 +1,50 @@ +import { useMemo } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import { RootState } from "../../redux/store"; +import IndexingStatusViewer from "./IndexingStatus"; +import { Button } from ".."; +import { + setDialogMessage, + setShowDialog, +} from "../../redux/slices/uiStateSlice"; +import AddDocsDialog from "../dialogs/AddDocsDialog"; + +function IndexingStatuses() { + const indexingStatuses = useSelector( + (store: RootState) => store.state.indexingStatuses, + ); + const docsStatuses = useMemo(() => { + const docs = Object.values(indexingStatuses).filter( + (status) => status.type === "docs" && status.status !== "deleted", + ); + + return []; + return docs; + }, [indexingStatuses]); + const dispatch = useDispatch(); + + return ( +
+

@docs indexes

+ + Manage your documentation sources + + {docsStatuses.length ? ( + docsStatuses.map((status) => { + return ; + }) + ) : ( + + )} +
+ ); +} + +export default IndexingStatuses; diff --git a/gui/src/components/indexing/utils.ts b/gui/src/components/indexing/utils.ts new file mode 100644 index 000000000..350f5008e --- /dev/null +++ b/gui/src/components/indexing/utils.ts @@ -0,0 +1,17 @@ +import { + ArrowPathIcon, + CheckCircleIcon, + PauseCircleIcon, + XMarkIcon, +} from "@heroicons/react/24/outline"; +import { IndexingStatus } from "core"; + +export const STATUS_TO_ICON: Record = { + indexing: ArrowPathIcon, + paused: PauseCircleIcon, + complete: CheckCircleIcon, + aborted: null, + deleted: null, + pending: null, + failed: null, // XMarkIcon, // Since we show an error message below +}; diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 49a6d429f..4bdfdd8bf 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -11,6 +11,7 @@ import { setInactive, setSelectedProfileId, setTTSActive, + updateIndexingStatus, } from "../redux/slices/stateSlice"; import { RootState } from "../redux/store"; @@ -50,14 +51,20 @@ function useSetup(dispatch: Dispatch) { loadConfig(); const interval = setInterval(() => { if (initialConfigLoad.current) { + // This triggers sending pending status to the GUI for relevant docs indexes clearInterval(interval); + ideMessenger.post("indexing/initStatuses", undefined); return; } loadConfig(); }, 2_000); return () => clearInterval(interval); - }, [initialConfigLoad, loadConfig]); + }, [initialConfigLoad, loadConfig, ideMessenger]); + + useWebviewListener("configUpdate", async () => { + await loadConfig(); + }); useEffect(() => { // Override persisted state @@ -110,10 +117,6 @@ function useSetup(dispatch: Dispatch) { }); }); - useWebviewListener("configUpdate", async () => { - await loadConfig(); - }); - useWebviewListener("configError", async (error) => { dispatch(setConfigError(error)); }); @@ -136,13 +139,7 @@ function useSetup(dispatch: Dispatch) { }); useWebviewListener("indexing/statusUpdate", async (data) => { - console.log("Indexing status update", data); - // dispatch( - // addContextItemsAtIndex({ - // index: data.historyIndex, - // contextItems: [data.item], - // }), - // ); + dispatch(updateIndexingStatus(data)); }); useWebviewListener( diff --git a/gui/src/index.css b/gui/src/index.css index b1cde096f..554ce2faa 100644 --- a/gui/src/index.css +++ b/gui/src/index.css @@ -72,3 +72,22 @@ a:focus { -ms-overflow-style: none; /* IE and Edge */ scrollbar-width: none; /* Firefox */ } + +.lines { + /* white-space: pre-wrap; */ + word-break: break-word; + overflow: hidden; + line-height: 1.375; +} + +.lines-3 { + display: -webkit-box; + -webkit-line-clamp: 3; + -webkit-box-orient: vertical; +} + +.lines-1 { + display: -webkit-box; + -webkit-line-clamp: 1; + -webkit-box-orient: vertical; +} diff --git a/gui/src/pages/More/More.tsx b/gui/src/pages/More/More.tsx index 4824c9535..e743a3834 100644 --- a/gui/src/pages/More/More.tsx +++ b/gui/src/pages/More/More.tsx @@ -15,6 +15,7 @@ import { setOnboardingCard } from "../../redux/slices/uiStateSlice"; import useHistory from "../../hooks/useHistory"; import MoreHelpRow from "./MoreHelpRow"; import IndexingProgress from "./IndexingProgress"; +import IndexingStatuses from "../../components/indexing/IndexingStatuses"; function MorePage() { useNavigationListener(); @@ -50,6 +51,9 @@ function MorePage() {
+
+ +

Help center

diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index 4222b4693..fa85427e5 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -3,17 +3,15 @@ import { JSONContent } from "@tiptap/react"; import { ChatHistoryItem, ChatMessage, - ContextItemId, ContextItemWithId, + IndexingStatus, PersistedSessionInfo, PromptLog, } from "core"; import { BrowserSerializedContinueConfig } from "core/config/load"; import { ConfigValidationError } from "core/config/validation"; import { stripImages } from "core/llm/images"; -import { createSelector } from "reselect"; import { v4 as uuidv4, v4 } from "uuid"; -import { RootState } from "../store"; // We need this to handle reorderings (e.g. a mid-array deletion) of the messages array. // The proper fix is adding a UUID to all chat messages, but this is the temp workaround. @@ -34,6 +32,7 @@ type State = { selectedProfileId: string; configError: ConfigValidationError[] | undefined; isInMultifileEdit: boolean; + indexingStatuses: { [id: string]: IndexingStatus }; }; const initialState: State = { @@ -61,6 +60,7 @@ const initialState: State = { defaultModelTitle: "GPT-4", selectedProfileId: "local", isInMultifileEdit: false, + indexingStatuses: {}, }; export const stateSlice = createSlice({ @@ -314,6 +314,15 @@ export const stateSlice = createSlice({ setIsInMultifileEdit: (state, action: PayloadAction) => { state.isInMultifileEdit = action.payload; }, + updateIndexingStatus: (state, action: PayloadAction) => { + console.log("update indexing status"); + state.indexingStatuses = { + ...state.indexingStatuses, + [action.payload.id]: action.payload, + }; + // consider only overwriting the one that changed + // depends on how watching + }, }, }); @@ -339,6 +348,7 @@ export const { deleteMessage, setIsGatheringContext, setIsInMultifileEdit, + updateIndexingStatus, } = stateSlice.actions; export default stateSlice.reducer;