docs indexing on more
This commit is contained in:
parent
f71b074a77
commit
f52fbca1d5
17 changed files with 620 additions and 304 deletions
47
core/core.ts
47
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<ToCoreProtocol, FromCoreProtocol>
|
||||
|
|
@ -45,7 +44,6 @@ export class Core {
|
|||
continueServerClientPromise: Promise<ContinueServerClient>;
|
||||
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);
|
||||
|
|
|
|||
24
core/index.d.ts
vendored
24
core/index.d.ts
vendored
|
|
@ -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<IndexingStatusUpdate["id"], IndexingStatusUpdate>
|
||||
>;
|
||||
export type IndexingStatusMap = Map<string, IndexingStatus>;
|
||||
|
||||
export type PromptTemplateFunction = (
|
||||
history: ChatMessage[],
|
||||
|
|
|
|||
|
|
@ -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<ToCoreProtocol, FromCoreProtocol>;
|
||||
readonly statuses: IndexingStatusMap = new Map();
|
||||
private readonly reindexTypeFunctions: Map<
|
||||
string,
|
||||
(id: string) => Promise<void>
|
||||
> = new Map();
|
||||
|
||||
constructor(messenger: IMessenger<ToCoreProtocol, FromCoreProtocol>) {
|
||||
this.messenger = messenger;
|
||||
}
|
||||
|
||||
private static instance?: IndexingStatusManager;
|
||||
static createSingleton(
|
||||
messenger: IMessenger<ToCoreProtocol, FromCoreProtocol>,
|
||||
) {
|
||||
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<void>) {
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<ToCoreProtocol, FromCoreProtocol>,
|
||||
private readonly indexingManager?: IndexingStatusManager,
|
||||
) {
|
||||
this.isInitialized = this.init(configHandler);
|
||||
}
|
||||
|
|
@ -111,14 +110,8 @@ export default class DocsService {
|
|||
configHandler: ConfigHandler,
|
||||
ide: IDE,
|
||||
messenger?: IMessenger<ToCoreProtocol, FromCoreProtocol>,
|
||||
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<Promise<boolean>> {
|
||||
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<SqliteDocsRow[]>(
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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: [
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<footer className="flex h-7 items-center justify-between overflow-hidden border-0 border-t border-solid border-t-zinc-700 p-2">
|
||||
<div className="flex max-w-[40vw] gap-2">
|
||||
<ProfileSwitcher />
|
||||
{defaultModel?.provider === "free-trial" && (
|
||||
<FreeTrialProgressBar
|
||||
completed={parseInt(localStorage.getItem("ftc") || "0")}
|
||||
total={FREE_TRIAL_LIMIT_REQUESTS}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<>
|
||||
<FooterIndexingPeeks />
|
||||
|
||||
<footer className="flex h-7 items-center justify-between overflow-hidden border-0 border-t border-solid border-t-zinc-700 p-2">
|
||||
<div className="flex max-w-[40vw] gap-2">
|
||||
<ProfileSwitcher />
|
||||
{defaultModel?.provider === "free-trial" && (
|
||||
<FreeTrialProgressBar
|
||||
completed={parseInt(localStorage.getItem("ftc") || "0")}
|
||||
total={FREE_TRIAL_LIMIT_REQUESTS}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex gap-1">
|
||||
{configError && (
|
||||
<HeaderButtonWithToolTip
|
||||
tooltipPlacement="top-end"
|
||||
text="Config error"
|
||||
onClick={onClickError}
|
||||
>
|
||||
<ExclamationTriangleIcon className="h-4 w-4" />
|
||||
</HeaderButtonWithToolTip>
|
||||
)}
|
||||
|
||||
<div className="flex gap-1">
|
||||
{configError && (
|
||||
<HeaderButtonWithToolTip
|
||||
tooltipPlacement="top-end"
|
||||
text="Config error"
|
||||
onClick={onClickError}
|
||||
text="More"
|
||||
onClick={onClickMore}
|
||||
>
|
||||
<ExclamationTriangleIcon className="h-4 w-4" />
|
||||
<EllipsisHorizontalCircleIcon className="h-4 w-4" />
|
||||
</HeaderButtonWithToolTip>
|
||||
)}
|
||||
|
||||
<HeaderButtonWithToolTip
|
||||
tooltipPlacement="top-end"
|
||||
text="More"
|
||||
onClick={onClickMore}
|
||||
>
|
||||
<EllipsisHorizontalCircleIcon className="h-4 w-4" />
|
||||
</HeaderButtonWithToolTip>
|
||||
|
||||
<HeaderButtonWithToolTip
|
||||
tooltipPlacement="top-end"
|
||||
onClick={onClickSettings}
|
||||
text="Configure Continue"
|
||||
>
|
||||
<Cog6ToothIcon className="h-4 w-4" />
|
||||
</HeaderButtonWithToolTip>
|
||||
</div>
|
||||
</footer>
|
||||
<HeaderButtonWithToolTip
|
||||
tooltipPlacement="top-end"
|
||||
onClick={onClickSettings}
|
||||
text="Configure Continue"
|
||||
>
|
||||
<Cog6ToothIcon className="h-4 w-4" />
|
||||
</HeaderButtonWithToolTip>
|
||||
</div>
|
||||
</footer>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
80
gui/src/components/indexing/FooterIndexingPeeks.tsx
Normal file
80
gui/src/components/indexing/FooterIndexingPeeks.tsx
Normal file
|
|
@ -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 (
|
||||
<div className="border-t-1 flex flex-row items-center gap-2 border border-0 border-gray-400 px-2 py-1">
|
||||
<div
|
||||
className={`flex flex-row items-center gap-2 ${status.url ? "hover:cursor-pointer hover:underline" : ""}`}
|
||||
onClick={() => {
|
||||
if (status.url) {
|
||||
ideMessenger.post("openUrl", status.url);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{status.icon ? (
|
||||
<img src={status.icon} alt="doc icon" className="h-4 w-4" />
|
||||
) : null}
|
||||
<p className="lines lines-1 m-0 p-0 text-left">
|
||||
{status.title ?? status.id}
|
||||
</p>
|
||||
</div>
|
||||
<div className="my-2 h-1.5 w-full rounded-md border border-solid border-gray-400">
|
||||
<div
|
||||
className={`h-full rounded-lg bg-stone-500 transition-all duration-200 ease-in-out`}
|
||||
style={{
|
||||
width: `${progressPercentage}%`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-row items-center gap-1 text-stone-500">
|
||||
<span className="text-xs">{progressPercentage.toFixed(0)}%</span>
|
||||
{Icon ? (
|
||||
<Icon
|
||||
className={`inline-block h-4 w-4 text-stone-500 ${
|
||||
status.status === "indexing" ? "animate-spin-slow" : ""
|
||||
}`}
|
||||
></Icon>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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 <FooterIndexingPeek status={status} />;
|
||||
})}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default FooterIndexingPeeks;
|
||||
135
gui/src/components/indexing/IndexingStatus.tsx
Normal file
135
gui/src/components/indexing/IndexingStatus.tsx
Normal file
|
|
@ -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<IndexingStatus["status"], any> = {
|
||||
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 (
|
||||
<div className="mt-2 flex w-full flex-col">
|
||||
{/* {`${status.type} - ${status.id} - ${status.status} - ${status.progress} - ${status.description} - ${status.icon}`} */}
|
||||
<div
|
||||
className={`flex flex-row items-center justify-between gap-2 text-sm`}
|
||||
>
|
||||
<div
|
||||
className={`flex flex-row items-center gap-2 ${status.url ? "hover:cursor-pointer hover:underline" : ""}`}
|
||||
onClick={() => {
|
||||
if (status.url) {
|
||||
ideMessenger.post("openUrl", status.url);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{status.icon ? (
|
||||
<img src={status.icon} alt="doc icon" className="h-4 w-4" />
|
||||
) : null}
|
||||
<p className="lines lines-1 m-0 p-0 text-left">
|
||||
{status.title ?? status.id}
|
||||
</p>
|
||||
</div>
|
||||
{status.status === "pending" ? (
|
||||
<div className="text-xs text-stone-500">Pending...</div>
|
||||
) : (
|
||||
<div className="flex flex-row items-center gap-1 text-stone-500">
|
||||
<span className="text-xs">{progressPercentage.toFixed(0)}%</span>
|
||||
{Icon ? (
|
||||
<Icon
|
||||
className={`inline-block h-4 w-4 text-stone-500 ${
|
||||
status.status === "indexing" ? "animate-spin-slow" : ""
|
||||
}`}
|
||||
></Icon>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="my-2 h-1.5 w-full rounded-md border border-solid border-gray-400">
|
||||
<div
|
||||
className={`h-full rounded-lg transition-all duration-200 ease-in-out ${
|
||||
status.status === "failed" ? "bg-red-600" : "bg-stone-500"
|
||||
}`}
|
||||
style={{
|
||||
width: `${progressPercentage}%`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-row items-center justify-between gap-4">
|
||||
<span
|
||||
className={`cursor-pointer whitespace-nowrap text-xs text-stone-500 underline`}
|
||||
onClick={
|
||||
{
|
||||
complete: reIndex,
|
||||
indexing: abort,
|
||||
failed: reIndex,
|
||||
aborted: reIndex,
|
||||
paused: () => {},
|
||||
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]
|
||||
}
|
||||
</span>
|
||||
|
||||
{status.status === "indexing" && (
|
||||
<span className="lines lines-1 text-right text-xs text-stone-500">
|
||||
{status.description}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default IndexingStatusViewer;
|
||||
50
gui/src/components/indexing/IndexingStatuses.tsx
Normal file
50
gui/src/components/indexing/IndexingStatuses.tsx
Normal file
|
|
@ -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 (
|
||||
<div className="flex flex-col gap-1">
|
||||
<h3 className="mb-1 mt-0 text-xl">@docs indexes</h3>
|
||||
<span className="text-xs text-stone-500">
|
||||
Manage your documentation sources
|
||||
</span>
|
||||
{docsStatuses.length ? (
|
||||
docsStatuses.map((status) => {
|
||||
return <IndexingStatusViewer key={status.id} status={status} />;
|
||||
})
|
||||
) : (
|
||||
<Button
|
||||
onClick={() => {
|
||||
dispatch(setShowDialog(true));
|
||||
dispatch(setDialogMessage(<AddDocsDialog />));
|
||||
}}
|
||||
>
|
||||
Add Docs
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default IndexingStatuses;
|
||||
17
gui/src/components/indexing/utils.ts
Normal file
17
gui/src/components/indexing/utils.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import {
|
||||
ArrowPathIcon,
|
||||
CheckCircleIcon,
|
||||
PauseCircleIcon,
|
||||
XMarkIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { IndexingStatus } from "core";
|
||||
|
||||
export const STATUS_TO_ICON: Record<IndexingStatus["status"], any> = {
|
||||
indexing: ArrowPathIcon,
|
||||
paused: PauseCircleIcon,
|
||||
complete: CheckCircleIcon,
|
||||
aborted: null,
|
||||
deleted: null,
|
||||
pending: null,
|
||||
failed: null, // XMarkIcon, // Since we show an error message below
|
||||
};
|
||||
|
|
@ -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<any>) {
|
|||
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<any>) {
|
|||
});
|
||||
});
|
||||
|
||||
useWebviewListener("configUpdate", async () => {
|
||||
await loadConfig();
|
||||
});
|
||||
|
||||
useWebviewListener("configError", async (error) => {
|
||||
dispatch(setConfigError(error));
|
||||
});
|
||||
|
|
@ -136,13 +139,7 @@ function useSetup(dispatch: Dispatch<any>) {
|
|||
});
|
||||
|
||||
useWebviewListener("indexing/statusUpdate", async (data) => {
|
||||
console.log("Indexing status update", data);
|
||||
// dispatch(
|
||||
// addContextItemsAtIndex({
|
||||
// index: data.historyIndex,
|
||||
// contextItems: [data.item],
|
||||
// }),
|
||||
// );
|
||||
dispatch(updateIndexingStatus(data));
|
||||
});
|
||||
|
||||
useWebviewListener(
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() {
|
|||
</div>
|
||||
<IndexingProgress />
|
||||
</div>
|
||||
<div className="flex flex-col py-5">
|
||||
<IndexingStatuses />
|
||||
</div>
|
||||
|
||||
<div className="py-5">
|
||||
<h3 className="mb-4 mt-0 text-xl">Help center</h3>
|
||||
|
|
|
|||
|
|
@ -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<boolean>) => {
|
||||
state.isInMultifileEdit = action.payload;
|
||||
},
|
||||
updateIndexingStatus: (state, action: PayloadAction<IndexingStatus>) => {
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue