Changesets · Branches · Tags · Compare
| Changeset | 402bc38c172a41880dc0d70d00109adcab05f5fda6f2943be8b6c09bac880cc6 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-07-09 17:10 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-09 17:10 -07:00 |
| Parents | 81ce8cce6ac5, c081a032c656 |
2 files changed
modified core/context/providers/DocsContextProvider.ts +13 −6
| @@ -145,6 +145,11 @@ | ||
| 145 | 145 | async loadSubmenuItems( |
| 146 | 146 | args: LoadSubmenuItemsArgs, |
| 147 | 147 | ): Promise<ContextSubmenuItem[]> { |
| 148 | + const { config } = args; | |
| 149 | + // This set is used to filter out the docs that is not in docs config but exist in sqlite metadata | |
| 150 | + const configDocsSet = new Set( | |
| 151 | + config.docs?.map((doc) => doc.startUrl) || [], | |
| 152 | + ); | |
| 148 | 153 | // Get docs service |
| 149 | 154 | const docsService = DocsService.getSingleton(); |
| 150 | 155 | if (!docsService) { |
| @@ -159,12 +164,14 @@ | ||
| 159 | 164 | // Get all indexed docs from the database |
| 160 | 165 | const docs = (await docsService.listMetadata()) ?? []; |
| 161 | 166 | for (const { startUrl, title, favicon } of docs) { |
| 162 | - submenuItems.push({ | |
| 163 | - title, | |
| 164 | - id: startUrl, | |
| 165 | - description: new URL(startUrl).hostname, | |
| 166 | - icon: favicon, | |
| 167 | - }); | |
| 167 | + if (configDocsSet.has(startUrl)) { | |
| 168 | + submenuItems.push({ | |
| 169 | + title, | |
| 170 | + id: startUrl, | |
| 171 | + description: new URL(startUrl).hostname, | |
| 172 | + icon: favicon, | |
| 173 | + }); | |
| 174 | + } | |
| 168 | 175 | } |
| 169 | 176 | |
| 170 | 177 | // Sort alphabetically |
modified core/indexing/docs/DocsService.ts +87 −11
| @@ -107,6 +107,17 @@ | ||
| 107 | 107 | ); |
| 108 | 108 | }; |
| 109 | 109 | |
| 110 | +const siteIndexingConfigsAreEqualExceptTitleAndFavicon = ( | |
| 111 | + config1: SiteIndexingConfig, | |
| 112 | + config2: SiteIndexingConfig, | |
| 113 | +) => { | |
| 114 | + return ( | |
| 115 | + config1.startUrl === config2.startUrl && | |
| 116 | + config1.maxDepth === config2.maxDepth && | |
| 117 | + config1.useLocalCrawling === config2.useLocalCrawling | |
| 118 | + ); | |
| 119 | +}; | |
| 120 | + | |
| 110 | 121 | /* |
| 111 | 122 | General process: |
| 112 | 123 | - On config update: |
| @@ -395,6 +406,21 @@ | ||
| 395 | 406 | siteIndexingConfig: SiteIndexingConfig, |
| 396 | 407 | ): Promise<boolean> { |
| 397 | 408 | try { |
| 409 | + // Set a initial status when retrieving cache | |
| 410 | + this.handleStatusUpdate({ | |
| 411 | + type: "docs", | |
| 412 | + id: startUrl, | |
| 413 | + embeddingsProviderId: embeddingId, | |
| 414 | + isReindexing: false, | |
| 415 | + title: siteIndexingConfig.title, | |
| 416 | + debugInfo: "Loaded from cache", | |
| 417 | + icon: siteIndexingConfig.faviconUrl, | |
| 418 | + url: startUrl, | |
| 419 | + progress: 0, | |
| 420 | + description: "Try to retrieve cache", | |
| 421 | + status: "indexing", | |
| 422 | + }); | |
| 423 | + | |
| 398 | 424 | const cacheHit = await this.tryFetchFromCache(startUrl, embeddingId); |
| 399 | 425 | |
| 400 | 426 | if (cacheHit) { |
| @@ -429,7 +455,8 @@ | ||
| 429 | 455 | siteIndexingConfig: SiteIndexingConfig, |
| 430 | 456 | forceReindex: boolean = false, |
| 431 | 457 | ): Promise<void> { |
| 432 | - const { startUrl, useLocalCrawling, maxDepth } = siteIndexingConfig; | |
| 458 | + const { startUrl, useLocalCrawling, maxDepth, faviconUrl } = | |
| 459 | + siteIndexingConfig; | |
| 433 | 460 | |
| 434 | 461 | // First, if indexing is already in process, don't attempt |
| 435 | 462 | // This queue is necessary because indexAndAdd is invoked circularly by config edits |
| @@ -685,7 +712,9 @@ | ||
| 685 | 712 | await this.deleteIndexes(startUrl); |
| 686 | 713 | } |
| 687 | 714 | |
| 688 | - const favicon = await fetchFavicon(new URL(siteIndexingConfig.startUrl)); | |
| 715 | + const favicon = | |
| 716 | + faviconUrl || | |
| 717 | + (await fetchFavicon(new URL(siteIndexingConfig.startUrl))); | |
| 689 | 718 | |
| 690 | 719 | if (this.shouldCancel(startUrl, startedWithEmbedder)) { |
| 691 | 720 | return; |
| @@ -718,10 +747,6 @@ | ||
| 718 | 747 | void this.ide.showToast("info", `Successfully indexed ${startUrl}`); |
| 719 | 748 | } |
| 720 | 749 | |
| 721 | - this.messenger?.send("refreshSubmenuItems", { | |
| 722 | - providers: ["docs"], | |
| 723 | - }); | |
| 724 | - | |
| 725 | 750 | removeFromFailedGlobalContext(siteIndexingConfig); |
| 726 | 751 | } catch (e) { |
| 727 | 752 | console.error( |
| @@ -766,14 +791,22 @@ | ||
| 766 | 791 | const siteEmbeddings = JSON.parse(data) as SiteIndexingResults; |
| 767 | 792 | |
| 768 | 793 | // Try to get a favicon for the site |
| 769 | - const favicon = await fetchFavicon(new URL(startUrl)); | |
| 794 | + const favicon = | |
| 795 | + this.statuses.get(startUrl)?.icon || | |
| 796 | + (await fetchFavicon(new URL(startUrl))); | |
| 797 | + | |
| 798 | + // Always try to make the title match what users set in the config | |
| 799 | + const title = | |
| 800 | + this.statuses.get(startUrl)?.title || | |
| 801 | + siteEmbeddings.title || | |
| 802 | + new URL(startUrl).hostname; | |
| 770 | 803 | |
| 771 | 804 | // Add the cached embeddings to our database |
| 772 | 805 | await this.add({ |
| 773 | 806 | favicon, |
| 774 | 807 | siteIndexingConfig: { |
| 775 | 808 | startUrl, |
| 776 | - title: siteEmbeddings.title || new URL(startUrl).hostname, | |
| 809 | + title, | |
| 777 | 810 | }, |
| 778 | 811 | chunks: siteEmbeddings.chunks, |
| 779 | 812 | embeddings: siteEmbeddings.chunks.map((c) => c.embedding), |
| @@ -910,6 +943,10 @@ | ||
| 910 | 943 | ); |
| 911 | 944 | |
| 912 | 945 | if (cacheHit) { |
| 946 | + // If cache hit, refresh the submenu items for docs | |
| 947 | + this.messenger?.send("refreshSubmenuItems", { | |
| 948 | + providers: ["docs"], | |
| 949 | + }); | |
| 913 | 950 | // If cache hit, retry the search once |
| 914 | 951 | return await this.retrieveChunks(startUrl, vector, nRetrieve, true); |
| 915 | 952 | } |
| @@ -987,8 +1024,7 @@ | ||
| 987 | 1024 | const currentStartUrls = currentlyIndexedDocs.map((doc) => doc.startUrl); |
| 988 | 1025 | |
| 989 | 1026 | // Anything found in old config, new config, AND sqlite that doesn't match should be reindexed |
| 990 | - // TODO if only favicon and title change, only update, don't embed | |
| 991 | - // Otherwise anything found in new config that isn't in sqlite should be added/indexed | |
| 1027 | + // Anything found in new config that isn't in sqlite should be added/indexed | |
| 992 | 1028 | const addedDocs: SiteIndexingConfig[] = []; |
| 993 | 1029 | const changedDocs: SiteIndexingConfig[] = []; |
| 994 | 1030 | for (const doc of newConfigDocs) { |
| @@ -999,12 +1035,26 @@ | ||
| 999 | 1035 | (d) => d.startUrl === doc.startUrl, |
| 1000 | 1036 | ); |
| 1001 | 1037 | |
| 1038 | + // TODO: Changes to the docs config made while Continue isn't running won't be caught | |
| 1002 | 1039 | if (oldConfigDoc && !siteIndexingConfigsAreEqual(oldConfigDoc, doc)) { |
| 1003 | - changedDocs.push(doc); | |
| 1040 | + // When only the title or faviconUrl changed, Update the sqlite metadate instead of reindexing | |
| 1041 | + if ( | |
| 1042 | + siteIndexingConfigsAreEqualExceptTitleAndFavicon( | |
| 1043 | + oldConfigDoc, | |
| 1044 | + doc, | |
| 1045 | + ) | |
| 1046 | + ) { | |
| 1047 | + await this.updateMetadataInSqlite(doc); | |
| 1048 | + } else { | |
| 1049 | + changedDocs.push(doc); | |
| 1050 | + } | |
| 1004 | 1051 | } else { |
| 1005 | 1052 | if (forceReindex) { |
| 1006 | 1053 | changedDocs.push(doc); |
| 1007 | 1054 | } else { |
| 1055 | + // This is a temperary fix to catch the changes to the docs config that were made when Continue isn't running | |
| 1056 | + // We only update title and faviconUrl here | |
| 1057 | + await this.updateMetadataInSqlite(doc); | |
| 1008 | 1058 | // if get's here, not changed, no update needed, mark as complete |
| 1009 | 1059 | this.handleStatusUpdate({ |
| 1010 | 1060 | type: "docs", |
| @@ -1036,6 +1086,10 @@ | ||
| 1036 | 1086 | console.error("Error syncing docs index on config update", e); |
| 1037 | 1087 | } finally { |
| 1038 | 1088 | this.isSyncing = false; |
| 1089 | + // Refresh the submenu items for docs | |
| 1090 | + this.messenger?.send("refreshSubmenuItems", { | |
| 1091 | + providers: ["docs"], | |
| 1092 | + }); | |
| 1039 | 1093 | } |
| 1040 | 1094 | } |
| 1041 | 1095 | |
| @@ -1182,6 +1236,27 @@ | ||
| 1182 | 1236 | ); |
| 1183 | 1237 | } |
| 1184 | 1238 | |
| 1239 | + private async updateMetadataInSqlite(siteIndexingConfig: SiteIndexingConfig) { | |
| 1240 | + const { startUrl, title, faviconUrl } = siteIndexingConfig; | |
| 1241 | + const favicon = faviconUrl || (await fetchFavicon(new URL(startUrl))); | |
| 1242 | + if (!this.config.selectedModelByRole.embed) { | |
| 1243 | + console.warn( | |
| 1244 | + `Attempting to add metadata for ${startUrl} without embeddings provider specified`, | |
| 1245 | + ); | |
| 1246 | + return; | |
| 1247 | + } | |
| 1248 | + | |
| 1249 | + const db = await this.getOrCreateSqliteDb(); | |
| 1250 | + | |
| 1251 | + await db.run( | |
| 1252 | + `UPDATE ${DocsService.sqlitebTableName} SET title = ?, favicon = ? WHERE startUrl = ? AND embeddingsProviderId = ?`, | |
| 1253 | + title, | |
| 1254 | + favicon, | |
| 1255 | + startUrl, | |
| 1256 | + this.config.selectedModelByRole.embed.embeddingId, | |
| 1257 | + ); | |
| 1258 | + } | |
| 1259 | + | |
| 1185 | 1260 | private addToConfig(siteIndexingConfig: SiteIndexingConfig) { |
| 1186 | 1261 | // Handles the case where a user has manually added the doc to config.json |
| 1187 | 1262 | // so it already exists in the file |
| @@ -1286,5 +1361,6 @@ | ||
| 1286 | 1361 | this.messenger?.send("refreshSubmenuItems", { |
| 1287 | 1362 | providers: ["docs"], |
| 1288 | 1363 | }); |
| 1364 | + this.statuses.delete(startUrl); | |
| 1289 | 1365 | } |
| 1290 | 1366 | } |