Merge branch 'main' into nate/fixes123
This commit is contained in:
commit
23a0d0e3e2
15 changed files with 302 additions and 217 deletions
|
|
@ -80,22 +80,28 @@ class DocsContextProvider extends BaseContextProvider {
|
|||
query: string,
|
||||
extras: ContextProviderExtras,
|
||||
): Promise<ContextItem[]> {
|
||||
// Get docs service
|
||||
const docsService = DocsService.getSingleton();
|
||||
|
||||
if (!docsService) {
|
||||
console.error(`${DocsService.name} has not been initialized`);
|
||||
return [];
|
||||
}
|
||||
|
||||
await docsService.isInitialized;
|
||||
|
||||
// Get chunks
|
||||
let chunks = await docsService.retrieveChunksFromQuery(
|
||||
extras.fullInput, // confusing: fullInput = the query, query = startUrl in this case
|
||||
query,
|
||||
this.options?.nRetrieve ?? DocsContextProvider.nRetrieve,
|
||||
);
|
||||
if (!chunks?.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// We found chunks, so check if there's a favicon for the docs page
|
||||
const favicon = await docsService.getFavicon(query);
|
||||
|
||||
// Rerank if there's a rerankder
|
||||
if (extras.reranker) {
|
||||
chunks = await this._rerankChunks(
|
||||
chunks,
|
||||
|
|
@ -139,18 +145,30 @@ class DocsContextProvider extends BaseContextProvider {
|
|||
async loadSubmenuItems(
|
||||
args: LoadSubmenuItemsArgs,
|
||||
): Promise<ContextSubmenuItem[]> {
|
||||
// Get docs service
|
||||
const docsService = DocsService.getSingleton();
|
||||
|
||||
if (!docsService) {
|
||||
console.error(`${DocsService.name} has not been initialized`);
|
||||
return [];
|
||||
}
|
||||
await docsService.isInitialized;
|
||||
|
||||
const docs = (await docsService.listMetadata()) ?? [];
|
||||
const canUsePreindexedDocs = await docsService.canUsePreindexedDocs();
|
||||
|
||||
// Create map of docs url -> submenu item
|
||||
const submenuItemsMap = new Map<string, ContextSubmenuItem>();
|
||||
|
||||
// Add custom docs from config
|
||||
const docs = (await docsService.listMetadata()) ?? [];
|
||||
for (const { startUrl, title, favicon } of docs) {
|
||||
submenuItemsMap.set(startUrl, {
|
||||
title,
|
||||
id: startUrl,
|
||||
description: new URL(startUrl).hostname,
|
||||
icon: favicon,
|
||||
});
|
||||
}
|
||||
|
||||
// Add pre-indexed docs if supported
|
||||
const canUsePreindexedDocs = await docsService.canUsePreindexedDocs();
|
||||
if (canUsePreindexedDocs) {
|
||||
for (const { startUrl, title } of Object.values(preIndexedDocs)) {
|
||||
submenuItemsMap.set(startUrl, {
|
||||
|
|
@ -164,17 +182,8 @@ class DocsContextProvider extends BaseContextProvider {
|
|||
}
|
||||
}
|
||||
|
||||
for (const { startUrl, title, favicon } of docs) {
|
||||
submenuItemsMap.set(startUrl, {
|
||||
title,
|
||||
id: startUrl,
|
||||
description: new URL(startUrl).hostname,
|
||||
icon: favicon,
|
||||
});
|
||||
}
|
||||
|
||||
// Create array and sort if pre-indexed is supported
|
||||
const submenuItems = Array.from(submenuItemsMap.values());
|
||||
|
||||
if (canUsePreindexedDocs) {
|
||||
return this._sortByPreIndexedDocs(submenuItems);
|
||||
}
|
||||
|
|
|
|||
10
core/core.ts
10
core/core.ts
|
|
@ -12,7 +12,7 @@ import {
|
|||
setupLocalConfigAfterFreeTrial,
|
||||
setupQuickstartConfig,
|
||||
} from "./config/onboarding";
|
||||
import { addModel, deleteModel } from "./config/util";
|
||||
import { addContextProvider, addModel, deleteModel } from "./config/util";
|
||||
import { recentlyEditedFilesCache } from "./context/retrieval/recentlyEditedFilesCache";
|
||||
import { ContinueServerClient } from "./continueServer/stubs/client";
|
||||
import { getAuthUrlForTokenPage } from "./control-plane/auth/index";
|
||||
|
|
@ -280,6 +280,10 @@ export class Core {
|
|||
return this.configHandler.listProfiles();
|
||||
});
|
||||
|
||||
on("config/addContextProvider", async (msg) => {
|
||||
addContextProvider(msg.data);
|
||||
});
|
||||
|
||||
// Context providers
|
||||
on("context/addDocs", async (msg) => {
|
||||
void this.docsService.indexAndAdd(msg.data);
|
||||
|
|
@ -290,7 +294,7 @@ export class Core {
|
|||
});
|
||||
|
||||
on("context/indexDocs", async (msg) => {
|
||||
await this.docsService.syncOrReindexAllDocsWithPrompt(msg.data.reIndex);
|
||||
await this.docsService.syncDocsWithPrompt(msg.data.reIndex);
|
||||
});
|
||||
|
||||
on("context/loadSubmenuItems", async (msg) => {
|
||||
|
|
@ -818,7 +822,7 @@ export class Core {
|
|||
});
|
||||
on("indexing/setPaused", async (msg) => {
|
||||
if (msg.data.type === "docs") {
|
||||
// this.docsService.setPaused(msg.data.id, msg.data.paused);
|
||||
// this.docsService.setPaused(msg.data.id, msg.data.paused); // not supported yet
|
||||
}
|
||||
});
|
||||
on("docs/getSuggestedDocs", async (msg) => {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import TransformersJsEmbeddingsProvider from "../../llm/llms/TransformersJsEmbed
|
|||
import { FromCoreProtocol, ToCoreProtocol } from "../../protocol";
|
||||
import { IMessenger } from "../../protocol/messenger";
|
||||
import { fetchFavicon, getFaviconBase64 } from "../../util/fetchFavicon";
|
||||
import { IMessenger } from "../../protocol/messenger";
|
||||
import { GlobalContext } from "../../util/GlobalContext";
|
||||
import {
|
||||
editConfigJson,
|
||||
|
|
@ -88,7 +89,6 @@ export default class DocsService {
|
|||
public isSyncing: boolean = false;
|
||||
|
||||
private docsIndexingQueue = new Set<string>();
|
||||
private globalContext = new GlobalContext();
|
||||
private lanceTableNamesSet = new Set<string>();
|
||||
|
||||
private config!: ContinueConfig;
|
||||
|
|
@ -145,7 +145,7 @@ export default class DocsService {
|
|||
|
||||
this.config.docs?.forEach((doc) => {
|
||||
if (!doc.startUrl) {
|
||||
console.error("Invalid config docs entry, no start");
|
||||
console.error("Invalid config docs entry, no start url", doc.title);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -184,20 +184,37 @@ export default class DocsService {
|
|||
}
|
||||
|
||||
abort(startUrl: string) {
|
||||
const status = this.statuses.get(startUrl);
|
||||
if (status) {
|
||||
if (this.docsIndexingQueue.has(startUrl)) {
|
||||
const status = this.statuses.get(startUrl);
|
||||
if (status) {
|
||||
this.handleStatusUpdate({
|
||||
...status,
|
||||
status: "aborted",
|
||||
progress: 0,
|
||||
description: "Canceled",
|
||||
});
|
||||
}
|
||||
this.docsIndexingQueue.delete(startUrl);
|
||||
this.handleStatusUpdate({
|
||||
...status,
|
||||
status: "aborted",
|
||||
progress: 0,
|
||||
description: "Canceled",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isAborted(startUrl: string) {
|
||||
return this.statuses.get(startUrl)?.status === "aborted";
|
||||
shouldCancel(startUrl: string, startedWithEmbedder: string) {
|
||||
// Check if aborted
|
||||
const isAborted = this.statuses.get(startUrl)?.status === "aborted";
|
||||
if (isAborted) {
|
||||
return true;
|
||||
}
|
||||
// Handle indexing disabled change mid-indexing
|
||||
if (this.config.disableIndexing) {
|
||||
this.abort(startUrl);
|
||||
return true;
|
||||
}
|
||||
// Handle embeddings provider change mid-indexing
|
||||
if (this.config.embeddingsProvider.embeddingId !== startedWithEmbedder) {
|
||||
this.abort(startUrl);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// NOTE Pausing not supported for docs yet
|
||||
|
|
@ -255,93 +272,79 @@ export default class DocsService {
|
|||
|
||||
this.docsCrawler = new DocsCrawler(this.ide, newConfig);
|
||||
|
||||
if (this.config.disableIndexing) {
|
||||
return;
|
||||
}
|
||||
|
||||
// No point in indexing if no docs context provider
|
||||
const hasDocsContextProvider = this.hasDocsContextProvider();
|
||||
if (!hasDocsContextProvider) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip docs indexing if not supported
|
||||
// No warning message here because would show on ANY config update
|
||||
const unsupported =
|
||||
await this.isUsingUnsupportedPreIndexedEmbeddingsProvider();
|
||||
if (unsupported) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.syncOrReindexAllDocs(newConfig, oldConfig);
|
||||
await this.syncDocs(oldConfig, newConfig, false);
|
||||
}
|
||||
}
|
||||
|
||||
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.embeddingId
|
||||
) {
|
||||
// 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) {
|
||||
async syncDocsWithPrompt(reIndex: boolean = false) {
|
||||
if (!this.hasDocsContextProvider()) {
|
||||
const didAddDocsContextProvider =
|
||||
await this.showAddDocsContextProviderToast();
|
||||
const actionMsg = "Add 'docs' context provider";
|
||||
const res = await this.ide.showToast(
|
||||
"info",
|
||||
"Starting docs indexing",
|
||||
actionMsg,
|
||||
);
|
||||
|
||||
if (!didAddDocsContextProvider) {
|
||||
if (res === actionMsg) {
|
||||
addContextProvider({
|
||||
name: DocsContextProvider.description.title,
|
||||
params: {},
|
||||
});
|
||||
|
||||
void this.ide.showToast(
|
||||
"info",
|
||||
"Successfuly added docs context provider",
|
||||
);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await this.syncOrReindexAllDocs(this.config);
|
||||
await this.syncDocs(undefined, this.config, reIndex);
|
||||
|
||||
void this.ide.showToast("info", "Docs indexing completed");
|
||||
}
|
||||
|
||||
// Returns true if startUrl has been indexed with current embeddingsProvider
|
||||
async hasMetadata(startUrl: string): Promise<Promise<boolean>> {
|
||||
const db = await this.getOrCreateSqliteDb();
|
||||
const title = await db.get(
|
||||
`SELECT title FROM ${DocsService.sqlitebTableName} WHERE startUrl = ?`,
|
||||
`SELECT title FROM ${DocsService.sqlitebTableName} WHERE startUrl = ? AND embeddingsProviderId = ?`,
|
||||
startUrl,
|
||||
this.config.embeddingsProvider.embeddingId,
|
||||
);
|
||||
|
||||
return !!title;
|
||||
}
|
||||
|
||||
async showAddDocsContextProviderToast() {
|
||||
const actionMsg = "Add 'docs' context provider";
|
||||
const res = await this.ide.showToast(
|
||||
"info",
|
||||
"Starting docs indexing",
|
||||
actionMsg,
|
||||
);
|
||||
|
||||
if (res === actionMsg) {
|
||||
addContextProvider({
|
||||
name: DocsContextProvider.description.title,
|
||||
params: {},
|
||||
});
|
||||
|
||||
void this.ide.showToast(
|
||||
"info",
|
||||
"Successfuly added docs context provider",
|
||||
);
|
||||
}
|
||||
|
||||
return res === actionMsg;
|
||||
}
|
||||
|
||||
async listMetadata() {
|
||||
const embeddingsProvider = this.config.embeddingsProvider;
|
||||
if (!embeddingsProvider) {
|
||||
return [];
|
||||
}
|
||||
const db = await this.getOrCreateSqliteDb();
|
||||
const docs = await db.all<SqliteDocsRow[]>(
|
||||
`SELECT title, startUrl, favicon FROM ${DocsService.sqlitebTableName}`,
|
||||
`SELECT title, startUrl, favicon FROM ${DocsService.sqlitebTableName}
|
||||
WHERE embeddingsProviderId = ?`,
|
||||
embeddingsProvider.embeddingId,
|
||||
);
|
||||
|
||||
return docs;
|
||||
|
|
@ -360,17 +363,29 @@ export default class DocsService {
|
|||
siteIndexingConfig: SiteIndexingConfig,
|
||||
reIndex: boolean = false,
|
||||
): Promise<void> {
|
||||
if (this.config.disableIndexing) {
|
||||
console.warn("Attempting to add/index docs when indexing is disabled");
|
||||
return;
|
||||
}
|
||||
const { startUrl } = siteIndexingConfig;
|
||||
|
||||
const canUsePreindexedDocs = await this.canUsePreindexedDocs();
|
||||
if (canUsePreindexedDocs) {
|
||||
const preIndexedDoc = preIndexedDocs[startUrl];
|
||||
const isPreIndexedDoc = !!preIndexedDoc;
|
||||
if (isPreIndexedDoc) {
|
||||
console.warn("Can not override pre-indexed start urls");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Queue - indexAndAdd is invoked circularly by config edits. This prevents duplicate runs
|
||||
if (this.docsIndexingQueue.has(startUrl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const embeddingsProvider = await this.getEmbeddingsProvider();
|
||||
|
||||
this.docsIndexingQueue.add(startUrl);
|
||||
|
||||
const startedWithEmbedder = this.config.embeddingsProvider.embeddingId;
|
||||
const indexExists = await this.hasMetadata(startUrl);
|
||||
|
||||
// Build status update - most of it is fixed values
|
||||
|
|
@ -404,13 +419,11 @@ export default class DocsService {
|
|||
}
|
||||
}
|
||||
|
||||
// If not preindexed
|
||||
const isPreIndexedDoc = !!preIndexedDocs[siteIndexingConfig.startUrl];
|
||||
if (!isPreIndexedDoc) {
|
||||
this.addToConfig(siteIndexingConfig);
|
||||
}
|
||||
|
||||
try {
|
||||
this.docsIndexingQueue.add(startUrl);
|
||||
|
||||
this.addToConfig(siteIndexingConfig);
|
||||
|
||||
this.handleStatusUpdate({
|
||||
...fixedStatus,
|
||||
status: "indexing",
|
||||
|
|
@ -427,7 +440,7 @@ export default class DocsService {
|
|||
estimatedProgress += 1 / 2 ** (processedPages + 1);
|
||||
|
||||
// NOTE - during "indexing" phase, check if aborted before each status update
|
||||
if (this.isAborted(startUrl)) {
|
||||
if (this.shouldCancel(startUrl, startedWithEmbedder)) {
|
||||
return;
|
||||
}
|
||||
this.handleStatusUpdate({
|
||||
|
|
@ -465,7 +478,7 @@ export default class DocsService {
|
|||
for (let i = 0; i < articles.length; i++) {
|
||||
const article = articles[i];
|
||||
|
||||
if (this.isAborted(startUrl)) {
|
||||
if (this.shouldCancel(startUrl, startedWithEmbedder)) {
|
||||
return;
|
||||
}
|
||||
this.handleStatusUpdate({
|
||||
|
|
@ -502,7 +515,7 @@ export default class DocsService {
|
|||
`No embeddings were created for site: ${siteIndexingConfig.startUrl}\n Num chunks: ${chunks.length}`,
|
||||
);
|
||||
|
||||
if (this.isAborted(startUrl)) {
|
||||
if (this.shouldCancel(startUrl, startedWithEmbedder)) {
|
||||
return;
|
||||
}
|
||||
this.handleStatusUpdate({
|
||||
|
|
@ -520,7 +533,7 @@ export default class DocsService {
|
|||
// Add docs to databases
|
||||
console.log(`Adding ${embeddings.length} embeddings to db`);
|
||||
|
||||
if (this.isAborted(startUrl)) {
|
||||
if (this.shouldCancel(startUrl, startedWithEmbedder)) {
|
||||
return;
|
||||
}
|
||||
this.handleStatusUpdate({
|
||||
|
|
@ -538,7 +551,7 @@ export default class DocsService {
|
|||
|
||||
const favicon = await fetchFavicon(new URL(siteIndexingConfig.startUrl));
|
||||
|
||||
if (this.isAborted(startUrl)) {
|
||||
if (this.shouldCancel(startUrl, startedWithEmbedder)) {
|
||||
return;
|
||||
}
|
||||
this.handleStatusUpdate({
|
||||
|
|
@ -557,7 +570,7 @@ export default class DocsService {
|
|||
|
||||
this.docsIndexingQueue.delete(startUrl);
|
||||
|
||||
if (this.isAborted(startUrl)) {
|
||||
if (this.shouldCancel(startUrl, startedWithEmbedder)) {
|
||||
return;
|
||||
}
|
||||
this.handleStatusUpdate({
|
||||
|
|
@ -576,7 +589,7 @@ export default class DocsService {
|
|||
console.error("Error indexing docs", e);
|
||||
this.handleStatusUpdate({
|
||||
...fixedStatus,
|
||||
description: `No embeddings were created for site: ${siteIndexingConfig.startUrl}`,
|
||||
description: `Error getting docs from: ${siteIndexingConfig.startUrl}`,
|
||||
status: "failed",
|
||||
progress: 1,
|
||||
});
|
||||
|
|
@ -649,13 +662,18 @@ export default class DocsService {
|
|||
return await this.retrieveChunks(startUrl, vector, nRetrieve);
|
||||
}
|
||||
|
||||
// This is split into its own function so that it can be recursive
|
||||
// in the case of fetching preindexed docs from s3
|
||||
async retrieveChunks(
|
||||
startUrl: string,
|
||||
vector: number[],
|
||||
nRetrieve: number,
|
||||
isRetry: boolean = false,
|
||||
): Promise<Chunk[]> {
|
||||
const isPreIndexedDoc = !!preIndexedDocs[startUrl];
|
||||
const preIndexedDoc = preIndexedDocs[startUrl];
|
||||
const isPreIndexedDoc = !!preIndexedDoc;
|
||||
|
||||
// Lance doesn't have an embeddingsprovider column, instead it includes it in the table name
|
||||
const table = await this.getOrCreateLanceTable({
|
||||
initializationVector: vector,
|
||||
isPreIndexedDoc,
|
||||
|
|
@ -672,19 +690,21 @@ export default class DocsService {
|
|||
console.warn("Error retrieving chunks from LanceDB", e);
|
||||
}
|
||||
|
||||
const hasIndexedDoc = await this.hasMetadata(startUrl);
|
||||
|
||||
if (!hasIndexedDoc && docs.length === 0) {
|
||||
const preIndexedDoc = preIndexedDocs[startUrl];
|
||||
|
||||
if (isRetry || !preIndexedDoc) {
|
||||
// No docs are found for preindexed? try fetching once
|
||||
if (docs.length === 0 && isPreIndexedDoc) {
|
||||
if (isRetry) {
|
||||
return [];
|
||||
}
|
||||
|
||||
await this.fetchAndAddPreIndexedDocEmbeddings(preIndexedDoc.title);
|
||||
return await this.retrieveChunks(startUrl, vector, nRetrieve, true);
|
||||
}
|
||||
|
||||
if (isPreIndexedDoc) {
|
||||
void Telemetry.capture("docs_pre_indexed_doc_used", {
|
||||
doc: preIndexedDoc["title"],
|
||||
});
|
||||
}
|
||||
|
||||
return docs.map((doc) => ({
|
||||
digest: doc.path,
|
||||
filepath: doc.path,
|
||||
|
|
@ -709,12 +729,13 @@ export default class DocsService {
|
|||
await db.exec("PRAGMA busy_timeout = 3000;");
|
||||
|
||||
await runSqliteMigrations(db);
|
||||
|
||||
// First create the table if it doesn't exist
|
||||
await db.exec(`CREATE TABLE IF NOT EXISTS ${DocsService.sqlitebTableName} (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title STRING NOT NULL,
|
||||
startUrl STRING NOT NULL UNIQUE,
|
||||
favicon STRING
|
||||
startUrl STRING NOT NULL,
|
||||
favicon STRING,
|
||||
embeddingsProviderId STRING
|
||||
)`);
|
||||
|
||||
this.sqliteDb = db;
|
||||
|
|
@ -740,9 +761,10 @@ export default class DocsService {
|
|||
Sync with no embeddings provider change
|
||||
Ignores pre-indexed docs
|
||||
*/
|
||||
private async syncDocsOnConfigUpdate(
|
||||
private async syncDocs(
|
||||
oldConfig: ContinueConfig | undefined,
|
||||
newConfig: ContinueConfig,
|
||||
reindex: boolean,
|
||||
) {
|
||||
try {
|
||||
this.isSyncing = true;
|
||||
|
|
@ -752,6 +774,7 @@ export default class DocsService {
|
|||
const newConfigDocs = newConfig.docs || [];
|
||||
const newConfigStartUrls = newConfigDocs.map((doc) => doc.startUrl);
|
||||
|
||||
// NOTE since listMetadata filters by embeddings provider id embedding model changes are accounted for here
|
||||
const currentlyIndexedDocs = await this.listMetadata();
|
||||
const currentStartUrls = currentlyIndexedDocs.map((doc) => doc.startUrl);
|
||||
|
||||
|
|
@ -774,7 +797,9 @@ export default class DocsService {
|
|||
const oldConfigDoc = oldConfigDocs.find(
|
||||
(d) => d.startUrl === doc.startUrl,
|
||||
);
|
||||
// const currentStatus = this.statuses.get(doc.startUrl);
|
||||
if (
|
||||
// currentStatus?.status === "complete" &&
|
||||
oldConfigDoc &&
|
||||
(oldConfigDoc.maxDepth !== doc.maxDepth ||
|
||||
oldConfigDoc.title !== doc.title ||
|
||||
|
|
@ -862,9 +887,7 @@ export default class DocsService {
|
|||
return name.replace(/[^a-zA-Z0-9_.-]/g, "_");
|
||||
}
|
||||
|
||||
private async getLanceTableNameFromEmbeddingsProvider(
|
||||
isPreIndexedDoc: boolean,
|
||||
) {
|
||||
private async getLanceTableName(isPreIndexedDoc: boolean) {
|
||||
const embeddingsProvider =
|
||||
await this.getEmbeddingsProvider(isPreIndexedDoc);
|
||||
|
||||
|
|
@ -885,7 +908,7 @@ export default class DocsService {
|
|||
const conn = await lancedb.connect(getLanceDbPath());
|
||||
const tableNames = await conn.tableNames();
|
||||
const tableNameFromEmbeddingsProvider =
|
||||
await this.getLanceTableNameFromEmbeddingsProvider(!!isPreIndexedDoc);
|
||||
await this.getLanceTableName(!!isPreIndexedDoc);
|
||||
|
||||
if (!tableNames.includes(tableNameFromEmbeddingsProvider)) {
|
||||
if (initializationVector) {
|
||||
|
|
@ -942,24 +965,35 @@ export default class DocsService {
|
|||
}: AddParams) {
|
||||
const db = await this.getOrCreateSqliteDb();
|
||||
await db.run(
|
||||
`INSERT INTO ${DocsService.sqlitebTableName} (title, startUrl, favicon) VALUES (?, ?, ?)`,
|
||||
`INSERT INTO ${DocsService.sqlitebTableName} (title, startUrl, favicon, embeddingsProviderId) VALUES (?, ?, ?, ?)`,
|
||||
title,
|
||||
startUrl,
|
||||
favicon,
|
||||
this.config.embeddingsProvider.embeddingId,
|
||||
);
|
||||
}
|
||||
|
||||
private addToConfig(siteIndexingConfig: SiteIndexingConfig) {
|
||||
// Handles the case where a user has manually added the doc to config.json
|
||||
// so it already exists in the file
|
||||
const doesDocExist = this.config.docs?.some(
|
||||
(doc) => doc.startUrl === siteIndexingConfig.startUrl,
|
||||
const doesEquivalentDocExist = this.config.docs?.some(
|
||||
(doc) =>
|
||||
doc.startUrl === siteIndexingConfig.startUrl &&
|
||||
doc.faviconUrl === siteIndexingConfig.faviconUrl &&
|
||||
siteIndexingConfig.title === doc.title,
|
||||
// siteIndexingConfig.maxDepth === doc.maxDepth &&
|
||||
// doc.rootUrl === siteIndexingConfig.rootUrl,
|
||||
);
|
||||
|
||||
if (!doesDocExist) {
|
||||
if (!doesEquivalentDocExist) {
|
||||
editConfigJson((config) => ({
|
||||
...config,
|
||||
docs: [...(config.docs ?? []), siteIndexingConfig],
|
||||
docs: [
|
||||
...(config.docs?.filter(
|
||||
(doc) => doc.startUrl !== siteIndexingConfig.startUrl,
|
||||
) ?? []),
|
||||
siteIndexingConfig,
|
||||
],
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
@ -1010,34 +1044,4 @@ export default class DocsService {
|
|||
this.deleteFromConfig(startUrl);
|
||||
this.messenger?.send("refreshSubmenuItems", undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently this deletes re-crawls + re-indexes all docs.
|
||||
* A more optimal solution in the future will be to create
|
||||
* a per-embeddings-provider table for docs.
|
||||
*/
|
||||
private async reindexDocsOnNewEmbeddingsProvider() {
|
||||
// We use config as our source of truth here since it contains additional information
|
||||
// needed for re-crawling such as `faviconUrl` and `maxDepth`.
|
||||
const { docs, embeddingsProvider } = this.config;
|
||||
|
||||
if (!docs || docs.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(
|
||||
`Reindexing non-preindexed docs with new embeddings provider: ${embeddingsProvider.embeddingId}`,
|
||||
);
|
||||
await Promise.allSettled(docs.map((doc) => this.indexAndAdd(doc)));
|
||||
|
||||
// Important that this only is invoked after we have successfully
|
||||
// cleared and reindex the docs so that the table cannot end up in an
|
||||
// invalid state.
|
||||
this.globalContext.update(
|
||||
"curEmbeddingsProviderId",
|
||||
embeddingsProvider.embeddingId,
|
||||
);
|
||||
|
||||
console.log("Completed reindexing of all non-preindexed docs");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,41 +27,50 @@ export async function runLanceMigrations(table: Table) {
|
|||
|
||||
export async function runSqliteMigrations(db: Database) {
|
||||
await new Promise((resolve) => {
|
||||
migrate(
|
||||
void migrate(
|
||||
"sqlite_modify_docs_columns_and_copy_to_config",
|
||||
async () => {
|
||||
try {
|
||||
const pragma = await db.all(
|
||||
`PRAGMA table_info(${DocsService.sqlitebTableName})`,
|
||||
`PRAGMA table_info(${DocsService.sqlitebTableName});`,
|
||||
);
|
||||
|
||||
const hasFaviconCol = pragma.some(
|
||||
(pragma) => pragma.name === "favicon",
|
||||
);
|
||||
if (!hasFaviconCol) {
|
||||
await db.exec(
|
||||
`ALTER TABLE ${DocsService.sqlitebTableName} ADD COLUMN favicon BLOB;`,
|
||||
);
|
||||
}
|
||||
|
||||
const hasBaseUrlCol = pragma.some(
|
||||
(pragma) => pragma.name === "baseUrl",
|
||||
);
|
||||
|
||||
if (!hasFaviconCol) {
|
||||
await db.exec(
|
||||
`ALTER TABLE ${DocsService.sqlitebTableName} ADD COLUMN favicon BLOB`,
|
||||
);
|
||||
}
|
||||
|
||||
if (hasBaseUrlCol) {
|
||||
await db.exec(
|
||||
`ALTER TABLE ${DocsService.sqlitebTableName} RENAME COLUMN baseUrl TO startUrl`,
|
||||
`ALTER TABLE ${DocsService.sqlitebTableName} RENAME COLUMN baseUrl TO startUrl;`,
|
||||
);
|
||||
}
|
||||
|
||||
const sqliteDocs = await db.all<
|
||||
Array<Pick<SqliteDocsRow, "title" | "startUrl">>
|
||||
>(`SELECT title, startUrl FROM ${DocsService.sqlitebTableName}`);
|
||||
const hasEmbeddingsProviderColumn = pragma.some(
|
||||
(pragma) => pragma.name === "embeddingsProviderId",
|
||||
);
|
||||
if (!hasEmbeddingsProviderColumn) {
|
||||
// gotta just delete in this case since old docs will be unusable anyway
|
||||
await db.exec(`DROP TABLE ${DocsService.sqlitebTableName};`);
|
||||
}
|
||||
|
||||
editConfigJson((config) => ({
|
||||
...config,
|
||||
docs: [...(config.docs || []), ...sqliteDocs],
|
||||
}));
|
||||
const needsToUpdateConfig = !hasFaviconCol || hasBaseUrlCol;
|
||||
if (needsToUpdateConfig) {
|
||||
const sqliteDocs = await db.all<
|
||||
Array<Pick<SqliteDocsRow, "title" | "startUrl">>
|
||||
>(`SELECT title, startUrl FROM ${DocsService.sqlitebTableName}`);
|
||||
editConfigJson((config) => ({
|
||||
...config,
|
||||
docs: [...(config.docs || []), ...sqliteDocs],
|
||||
}));
|
||||
}
|
||||
} finally {
|
||||
resolve(undefined);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import type {
|
|||
ChatMessage,
|
||||
ContextItem,
|
||||
ContextItemWithId,
|
||||
ContextProviderWithParams,
|
||||
ContextSubmenuItem,
|
||||
DiffLine,
|
||||
FileSymbolMap,
|
||||
|
|
@ -70,6 +71,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
},
|
||||
];
|
||||
"config/deleteModel": [{ title: string }, void];
|
||||
"config/addContextProvider": [ContextProviderWithParams, void];
|
||||
"config/reload": [undefined, ConfigResult<BrowserSerializedContinueConfig>];
|
||||
"config/listProfiles": [undefined, ProfileDescription[]];
|
||||
"config/openProfile": [{ profileId: string | undefined }, void];
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
|||
"history/save",
|
||||
"devdata/log",
|
||||
"config/addModel",
|
||||
"config/addContextProvider",
|
||||
"config/newPromptFile",
|
||||
"config/ideSettingsUpdate",
|
||||
"config/getSerializedProfileInfo",
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ describe("GlobalContext", () => {
|
|||
const value = globalContext.get("indexingPaused");
|
||||
expect(value).toBeUndefined();
|
||||
expect(consoleWarnMock).toHaveBeenCalledWith(
|
||||
expect.stringContaining("Error parsing global context")
|
||||
expect.stringContaining("Error parsing global context"),
|
||||
);
|
||||
|
||||
// Clean up
|
||||
|
|
@ -99,7 +99,7 @@ describe("GlobalContext", () => {
|
|||
expect(value).toBeUndefined();
|
||||
|
||||
expect(consoleWarnMock).toHaveBeenCalledWith(
|
||||
expect.stringContaining("Error updating global context")
|
||||
expect.stringContaining("Error updating global context"),
|
||||
);
|
||||
|
||||
// Clean up
|
||||
|
|
@ -113,10 +113,10 @@ describe("GlobalContext", () => {
|
|||
|
||||
expect(globalContext.get("indexingPaused")).toBe(true);
|
||||
expect(globalContext.get("selectedTabAutocompleteModel")).toBe(
|
||||
"test-model"
|
||||
"test-model",
|
||||
);
|
||||
expect(globalContext.get("hasDismissedConfigTsNoticeJetBrains")).toBe(
|
||||
false
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -125,16 +125,7 @@ describe("GlobalContext", () => {
|
|||
expect(globalContext.get("hasAlreadyCreatedAPromptFile")).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle curEmbeddingsProviderId correctly", () => {
|
||||
globalContext.update("curEmbeddingsProviderId", "test-provider-id");
|
||||
expect(globalContext.get("curEmbeddingsProviderId")).toBe(
|
||||
"test-provider-id"
|
||||
);
|
||||
});
|
||||
|
||||
it("should not crash or throw when getting a key that hasn't been set", () => {
|
||||
expect(
|
||||
globalContext.get("hasAlreadyCreatedAPromptFile")
|
||||
).toBeUndefined();
|
||||
expect(globalContext.get("hasAlreadyCreatedAPromptFile")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ export type GlobalContextType = {
|
|||
*
|
||||
* For VS Code users, it is unnecessary since we use transformers.js by default.
|
||||
*/
|
||||
curEmbeddingsProviderId: string;
|
||||
hasDismissedConfigTsNoticeJetBrains: boolean;
|
||||
hasAlreadyCreatedAPromptFile: boolean;
|
||||
showConfigUpdateToast: boolean;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ class ContinueBrowser(val project: Project, url: String) {
|
|||
"history/save",
|
||||
"devdata/log",
|
||||
"config/addModel",
|
||||
"config/addContextProvider",
|
||||
"config/newPromptFile",
|
||||
"config/ideSettingsUpdate",
|
||||
"config/getSerializedProfileInfo",
|
||||
|
|
|
|||
|
|
@ -17,8 +17,10 @@ import DocsIndexingPeeks from "../indexing/DocsIndexingPeeks";
|
|||
import preIndexedDocs from "core/indexing/docs/preIndexedDocs";
|
||||
import { updateIndexingStatus } from "../../redux/slices/indexingSlice";
|
||||
import { useAppSelector } from "../../redux/hooks";
|
||||
import { setConfig } from "../../redux/slices/configSlice";
|
||||
|
||||
function AddDocsDialog() {
|
||||
const config = useAppSelector((store) => store.config.config);
|
||||
const posthog = usePostHog();
|
||||
const dispatch = useDispatch();
|
||||
|
||||
|
|
@ -125,6 +127,7 @@ function AddDocsDialog() {
|
|||
}
|
||||
const suggestedTitle =
|
||||
docsResult.details.title ?? docsResult.packageInfo.name;
|
||||
|
||||
if (docsResult.details?.docsLinkWarning) {
|
||||
setTitle(suggestedTitle);
|
||||
setStartUrl(docsResult.details.docsLink);
|
||||
|
|
@ -143,6 +146,19 @@ function AddDocsDialog() {
|
|||
|
||||
// Optimistic status update
|
||||
dispatch(
|
||||
setConfig({
|
||||
...config,
|
||||
docs: [
|
||||
...(config.docs?.filter(
|
||||
(doc) => doc.startUrl !== docsResult.details.docsLink,
|
||||
) ?? []),
|
||||
{
|
||||
startUrl: docsResult.details.docsLink,
|
||||
title: suggestedTitle,
|
||||
faviconUrl: undefined,
|
||||
},
|
||||
],
|
||||
}),
|
||||
updateIndexingStatus({
|
||||
type: "docs",
|
||||
description: "Initializing",
|
||||
|
|
|
|||
|
|
@ -75,25 +75,31 @@ function ChatIndexingPeek({ state }: ChatIndexingPeekProps) {
|
|||
}
|
||||
|
||||
function ChatIndexingPeeks() {
|
||||
const config = useAppSelector((store) => store.config.config);
|
||||
const indexingStatuses = useAppSelector(
|
||||
(store) => store.indexing.indexing.statuses,
|
||||
);
|
||||
const mergedIndexingStates: MergedIndexingState[] = useMemo(() => {
|
||||
const mergedStates: MergedIndexingState[] = [];
|
||||
|
||||
const docsStates = Object.values(indexingStatuses).filter(
|
||||
(status) => status.type === "docs" && status.status === "indexing",
|
||||
);
|
||||
if (docsStates.length > 0) {
|
||||
const configDocs = config?.docs ?? [];
|
||||
const docsIndexing: IndexingStatus[] = [];
|
||||
configDocs.forEach((doc) => {
|
||||
const status = indexingStatuses[doc.startUrl];
|
||||
if (status && status.status === "indexing") {
|
||||
docsIndexing.push(status);
|
||||
}
|
||||
});
|
||||
if (docsIndexing.length > 0) {
|
||||
mergedStates.push({
|
||||
displayName: "Docs indexing",
|
||||
type: "docs",
|
||||
titles: docsStates.map((state) => state.title),
|
||||
progressPercentage: mergeProgress(docsStates),
|
||||
titles: docsIndexing.map((doc) => doc.title),
|
||||
progressPercentage: mergeProgress(docsIndexing),
|
||||
});
|
||||
}
|
||||
return mergedStates;
|
||||
}, [indexingStatuses]);
|
||||
}, [config, indexingStatuses]);
|
||||
|
||||
if (!mergedIndexingStates.length) return null;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { IndexingStatus } from "core";
|
|||
import { useMemo } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
|
||||
import { useAppSelector } from "../../redux/hooks";
|
||||
|
||||
export interface DocsIndexingPeekProps {
|
||||
status: IndexingStatus;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ const STATUS_TO_ICON: Record<IndexingStatus["status"], any> = {
|
|||
};
|
||||
|
||||
function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) {
|
||||
const config = useAppSelector((store) => store.config.config);
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
|
|
@ -146,28 +147,30 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) {
|
|||
|
||||
<div className="flex flex-row items-center justify-between gap-4">
|
||||
<span
|
||||
className={`cursor-pointer whitespace-nowrap text-xs text-stone-500 underline`}
|
||||
className={`cursor-pointer whitespace-nowrap text-xs text-stone-500 ${config.disableIndexing ? "" : "underline"}`}
|
||||
onClick={
|
||||
{
|
||||
complete: reIndex,
|
||||
indexing: abort,
|
||||
failed: reIndex,
|
||||
aborted: reIndex,
|
||||
paused: () => {},
|
||||
pending: () => {},
|
||||
}[status?.status]
|
||||
config.disableIndexing
|
||||
? undefined
|
||||
: {
|
||||
complete: reIndex,
|
||||
indexing: abort,
|
||||
failed: reIndex,
|
||||
aborted: reIndex,
|
||||
paused: () => {},
|
||||
pending: () => {},
|
||||
}[status?.status]
|
||||
}
|
||||
>
|
||||
{
|
||||
{
|
||||
complete: "Click to re-index",
|
||||
indexing: "Cancel indexing",
|
||||
failed: "Click to retry",
|
||||
aborted: "Click to index",
|
||||
paused: "",
|
||||
pending: "",
|
||||
}[status?.status]
|
||||
}
|
||||
{config.disableIndexing
|
||||
? "Indexing disabled"
|
||||
: {
|
||||
complete: "Click to re-index",
|
||||
indexing: "Cancel indexing",
|
||||
failed: "Click to retry",
|
||||
aborted: "Click to index",
|
||||
paused: "",
|
||||
pending: "",
|
||||
}[status?.status]}
|
||||
</span>
|
||||
|
||||
<span className="lines lines-1 text-right text-xs text-stone-500">
|
||||
|
|
|
|||
|
|
@ -4,11 +4,24 @@ import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
|
|||
import AddDocsDialog from "../dialogs/AddDocsDialog";
|
||||
import DocsIndexingStatus from "./DocsIndexingStatus";
|
||||
import { useAppSelector } from "../../redux/hooks";
|
||||
import { useContext, useMemo } from "react";
|
||||
import { ExclamationTriangleIcon } from "@heroicons/react/24/outline";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
|
||||
function DocsIndexingStatuses() {
|
||||
const dispatch = useDispatch();
|
||||
const config = useAppSelector((store) => store.config.config);
|
||||
const configDocs = config.docs ?? [];
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
const hasDocsProvider = useMemo(() => {
|
||||
return !!config.contextProviders?.some(
|
||||
(provider) => provider.title === "docs",
|
||||
);
|
||||
}, [config]);
|
||||
|
||||
const configDocs = useMemo(() => {
|
||||
return config.docs ?? [];
|
||||
}, [config]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-1">
|
||||
|
|
@ -27,9 +40,35 @@ function DocsIndexingStatuses() {
|
|||
) : null}
|
||||
</div>
|
||||
<span className="text-xs text-stone-500">
|
||||
{configDocs.length
|
||||
? "Manage your documentation sources"
|
||||
: "No docs yet"}
|
||||
{hasDocsProvider ? (
|
||||
configDocs.length ? (
|
||||
"Manage your documentation sources"
|
||||
) : (
|
||||
"No docs yet"
|
||||
)
|
||||
) : (
|
||||
<div className="flex flex-col gap-1 text-xs">
|
||||
<div className="flex flex-row gap-1">
|
||||
<div>
|
||||
<ExclamationTriangleIcon className="h-4 w-4 text-stone-500" />
|
||||
</div>
|
||||
<span className="text-stone-500">
|
||||
@docs is not in your config
|
||||
</span>
|
||||
</div>
|
||||
<span
|
||||
className="cursor-pointer text-stone-500 underline"
|
||||
onClick={() => {
|
||||
ideMessenger.post("config/addContextProvider", {
|
||||
name: "docs",
|
||||
params: {},
|
||||
});
|
||||
}}
|
||||
>
|
||||
Add @docs to my config
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</span>
|
||||
<div className="flex max-h-[170px] flex-col gap-1 overflow-y-auto overflow-x-hidden pr-2">
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ const STATUS_TO_SUBTITLE_TEXT: Record<
|
|||
indexing: "Click to pause",
|
||||
paused: "Click to resume",
|
||||
failed: "Click to retry",
|
||||
disabled: "Click to open config.json and enable indexing (requires reload)",
|
||||
disabled: "Click to open config",
|
||||
cancelled: "Click to restart",
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue