diff --git a/core/config/ProfileLifecycleManager.ts b/core/config/ProfileLifecycleManager.ts index 85116f213..8d44c8bac 100644 --- a/core/config/ProfileLifecycleManager.ts +++ b/core/config/ProfileLifecycleManager.ts @@ -1,5 +1,3 @@ -import { config } from "dotenv"; - import { BrowserSerializedContinueConfig, ContinueConfig, diff --git a/core/config/load.ts b/core/config/load.ts index b692b36bf..9911c840f 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -527,6 +527,7 @@ function finalToBrowserConfig( embeddingsProvider: final.embeddingsProvider?.id, ui: final.ui, experimental: final.experimental, + docs: final.docs, }; } diff --git a/core/core.ts b/core/core.ts index b2be3478c..331ffbe85 100644 --- a/core/core.ts +++ b/core/core.ts @@ -735,6 +735,10 @@ export class Core { return this.docsService.initStatuses(); }); on("docs/getSuggestedDocs", async (msg) => { + if (hasRequestedDocs) { + return; + } // TODO, remove, hack because of rerendering + hasRequestedDocs = true; const suggestedDocs = await getAllSuggestedDocs(this.ide); this.messenger.send("docs/suggestions", suggestedDocs); }); @@ -842,3 +846,5 @@ export class Core { // private } + +let hasRequestedDocs = false; diff --git a/core/index.d.ts b/core/index.d.ts index 5541584eb..35c072bdb 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1189,6 +1189,7 @@ export interface BrowserSerializedContinueConfig { reranker?: RerankerDescription; experimental?: ExperimentalConfig; analytics?: AnalyticsConfig; + docs?: SiteIndexingConfig[]; } // DOCS SUGGESTIONS AND PACKAGE INFO @@ -1210,6 +1211,7 @@ export type ParsedPackageInfo = { export type PackageDetails = { docsLink?: string; + docsLinkWarning?: string; title?: string; description?: string; repo?: string; diff --git a/core/indexing/docs/suggestions/index.ts b/core/indexing/docs/suggestions/index.ts index 4e0c2104a..db192489a 100644 --- a/core/indexing/docs/suggestions/index.ts +++ b/core/indexing/docs/suggestions/index.ts @@ -63,9 +63,10 @@ export async function getAllSuggestedDocs(ide: IDE) { ); // Parse package files and build map of language -> packages - const packagesByRegistry: Record = {}; + const packagesByCrawler: Record = {}; PACKAGE_CRAWLERS.forEach((Crawler) => { const crawler = new Crawler(); + packagesByCrawler[crawler.packageRegistry] = []; const packageFiles = packageFilesByRegistry[crawler.packageRegistry]; packageFiles.forEach((file) => { const contents = fileContents.get(file.path); @@ -73,10 +74,7 @@ export async function getAllSuggestedDocs(ide: IDE) { return; } const packages = crawler.parsePackageFile(file, contents); - if (!packagesByRegistry[crawler.packageRegistry]) { - packagesByRegistry[crawler.packageRegistry] = []; - } - packagesByRegistry[crawler.packageRegistry].push(...packages); + packagesByCrawler[crawler.packageRegistry].push(...packages); }); }); @@ -84,13 +82,13 @@ export async function getAllSuggestedDocs(ide: IDE) { // TODO - this is where you would allow docs for different versions // by e.g. using "name-version" as the map key instead of just name // For now have not allowed - const languages = Object.keys(packagesByRegistry); - languages.forEach((language) => { - const packages = packagesByRegistry[language]; + const registries = Object.keys(packagesByCrawler); + registries.forEach((registry) => { + const packages = packagesByCrawler[registry]; const uniquePackages = Array.from( new Map(packages.map((pkg) => [pkg.name, pkg])).values(), ); - packagesByRegistry[language] = uniquePackages; + packagesByCrawler[registry] = uniquePackages; }); // Get documentation links for all packages @@ -98,7 +96,7 @@ export async function getAllSuggestedDocs(ide: IDE) { await Promise.all( PACKAGE_CRAWLERS.map(async (Crawler) => { const crawler = new Crawler(); - const packages = packagesByRegistry[crawler.packageRegistry]; + const packages = packagesByCrawler[crawler.packageRegistry]; const docsByRegistry = await Promise.all( packages.map(async (packageInfo) => { try { @@ -114,6 +112,11 @@ export async function getAllSuggestedDocs(ide: IDE) { details: { ...details, docsLink: details.docsLink, + docsLinkWarning: details.docsLink.includes("github.com") + ? "Github docs not supported, find the docs site" + : details.docsLink.includes("docs") + ? undefined + : "May not be a docs site, check the URL", }, }; } catch (error) { @@ -129,19 +132,3 @@ export async function getAllSuggestedDocs(ide: IDE) { ); return allDocsResults; } - -// write me an interface PackageCrawler that contains: -// 1. property `language` to store a given language like "python" or "typescript" -// 2. has a method `getPackageFiles` which takes a list of file names and decides which ones match package/dependency files (e.g. package.json for typescript, requirements.txt for python, etc) -// 3. has a method `parsePackageFile` which returns a list of package name and version from a relevant package file, in a standardized format like semver -// 4. has a method `getDocumentationLink` to check for documentation link for a given package (e.g. GET `https://registry.npmjs.org/` and find docs field for typescript, documentation link in the package metadata for PyPi, etc.) -// Then, write typescript classes to implement this typescript interface for the languages "python" and "typescript" - -// I want to present the user with a list of dependencies and allow them to select which ones to index (embed) documentation for. -// In order to prevent duplicate file reads, the process will be like this: -// 1. take in a list of filepaths called `filepaths` -// 2. loop an array of PackageCrawler classes to build a map of `language` (string) to `packageFilePaths` (string[]) -// 3. Get unique filepaths from `packageFilePaths` and build a map ` of filepath to file contents using an existing `readFile` function, and skipping file reads of already in the map -// Finally, -// Add a `` method to the interface and classes that returns -// Then, assemble the classes in an array, and write a function getAllSuggestedDocs that returns a map of `language` to an ar diff --git a/core/indexing/docs/suggestions/packageCrawlers/Python.ts b/core/indexing/docs/suggestions/packageCrawlers/Python.ts index d00045f97..6a486c984 100644 --- a/core/indexing/docs/suggestions/packageCrawlers/Python.ts +++ b/core/indexing/docs/suggestions/packageCrawlers/Python.ts @@ -30,7 +30,7 @@ export class PythonPackageCrawler implements PackageCrawler { .split("\n") .map((line) => { const [name, version] = line.split("=="); - return { name, version, packageFile: file, language: "python" }; + return { name, version, packageFile: file, language: "py" }; }) .filter((pkg) => pkg.name && pkg.version); } diff --git a/core/protocol/core.ts b/core/protocol/core.ts index 069f9e297..f5b04c9cf 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -9,7 +9,6 @@ import type { DiffLine, FileSymbolMap, IdeSettings, - IndexingStatusMap, LLMFullCompletionOptions, MessageContent, ModelDescription, diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index bf90497c8..fb6a8837c 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -2,9 +2,9 @@ import { ConfigValidationError } from "../config/validation.js"; import type { ContextItemWithId, - DocsSuggestions, IndexingProgressUpdate, IndexingStatus, + PackageDocsResult, } from "../index.js"; export type ToWebviewFromIdeOrCoreProtocol = { @@ -26,5 +26,5 @@ export type ToWebviewFromIdeOrCoreProtocol = { getWebviewHistoryLength: [undefined, number]; signInToControlPlane: [undefined, void]; openDialogMessage: ["account", void]; - "docs/suggestions": [DocsSuggestions, void]; + "docs/suggestions": [PackageDocsResult[], void]; }; diff --git a/gui/src/components/dialogs/AddDocsDialog.tsx b/gui/src/components/dialogs/AddDocsDialog.tsx index ca6a8bceb..0a90a60d2 100644 --- a/gui/src/components/dialogs/AddDocsDialog.tsx +++ b/gui/src/components/dialogs/AddDocsDialog.tsx @@ -1,12 +1,15 @@ import { CheckCircleIcon, + CheckIcon, ChevronDownIcon, ChevronUpIcon, CodeBracketIcon, + ExclamationTriangleIcon, InformationCircleIcon, LinkIcon, + PlusCircleIcon, } from "@heroicons/react/24/outline"; -import { PackageDocsResult, SiteIndexingConfig } from "core"; +import { IndexingStatus, PackageDocsResult, SiteIndexingConfig } from "core"; import { usePostHog } from "posthog-js/react"; import { useContext, useLayoutEffect, useMemo, useRef, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; @@ -20,39 +23,79 @@ import { RootState } from "../../redux/store"; import IndexingStatusViewer from "../indexing/IndexingStatus"; import { ToolTip } from "../gui/Tooltip"; +import FileIcon from "../FileIcon"; +import DocsIndexingPeeks from "../indexing/DocsIndexingPeeks"; +import { updateIndexingStatus } from "../../redux/slices/stateSlice"; +import preIndexedDocs from "core/indexing/docs/preIndexedDocs"; function AddDocsDialog() { const posthog = usePostHog(); const dispatch = useDispatch(); - const ref = useRef(null); + const titleRef = useRef(null); + const urlRef = useRef(null); const [title, setTitle] = useState(""); const [startUrl, setStartUrl] = useState(""); const [faviconUrl, setFaviconUrl] = useState(""); - const [isOpen, setIsOpen] = useState(false); - - const [submittedConfig, setSubmittedConfig] = useState(); const ideMessenger = useContext(IdeMessengerContext); const indexingStatuses = useSelector( (store: RootState) => store.state.indexing.statuses, ); + const docsIndexingStatuses: IndexingStatus[] = useMemo(() => { + return Object.values(indexingStatuses).filter( + (status) => status.type === "docs" && status.status === "indexing", + ); + }, [indexingStatuses]); + const docsSuggestions = useSelector( (store: RootState) => store.state.docsSuggestions, ); + const configDocs = useSelector((store: RootState) => store.state.config.docs); + + const sortedDocsSuggestions = useMemo(() => { + const docsFromConfig = configDocs ?? []; + const filtered = docsSuggestions.filter((sug) => { + const startUrl = sug.details?.docsLink; + return ( + !docsFromConfig.find((d) => d.startUrl === startUrl) && + !docsIndexingStatuses.find((s) => s.id === startUrl) && + (startUrl ? !preIndexedDocs[startUrl] : true) + ); + }); + + filtered.sort((a, b) => { + const rank = (result: PackageDocsResult) => { + if (result.error) { + return 2; + } else if (result.details?.docsLinkWarning) { + return 1; + } else { + return 0; + } + }; + return rank(a) - rank(b); + }); + return filtered; + }, [docsSuggestions, configDocs, docsIndexingStatuses]); + const isFormValid = startUrl && title; useLayoutEffect(() => { setTimeout(() => { - if (ref.current) { - ref.current.focus(); + if (titleRef.current) { + titleRef.current.focus(); } }, 100); - }, [ref]); + }, [titleRef]); + const closeDialog = () => { + dispatch(setShowDialog(false)); + dispatch(setDialogMessage(undefined)); + }; function onSubmit(e: any) { e.preventDefault(); @@ -64,220 +107,236 @@ function AddDocsDialog() { ideMessenger.post("context/addDocs", siteIndexingConfig); - setSubmittedConfig(siteIndexingConfig); setTitle(""); setStartUrl(""); setFaviconUrl(""); posthog.capture("add_docs_gui", { url: startUrl }); + + // Optimistic status update + dispatch( + updateIndexingStatus({ + type: "docs", + description: "Initializing", + id: startUrl, + embeddingsProviderId: "mock-embeddings-provider-id", + progress: 0, + status: "indexing", + title, + url: startUrl, + }), + ); } - const handleSelectSuggestion = (docsResult: PackageDocsResult) => {}; + const handleSelectSuggestion = (docsResult: PackageDocsResult) => { + if (docsResult.error) { + setTitle(docsResult.packageInfo.name); + setStartUrl(""); + urlRef.current?.focus(); + return; + } + if (docsResult.details?.docsLinkWarning) { + setTitle(docsResult.packageInfo.name); + setStartUrl(docsResult.details.docsLink); + urlRef.current?.focus(); + return; + } + const siteIndexingConfig: SiteIndexingConfig = { + startUrl: docsResult.details.docsLink, + title: docsResult.details.title, + faviconUrl: undefined, + }; - // if (submittedConfig) { - // const status = indexingStatuses[submittedConfig.startUrl]; - // return ( - //
- //
- // - //

{`Docs added`}

- //
- //
- //

Title: {submittedConfig.title}

- //

Start URL: {submittedConfig.startUrl}

- // {submittedConfig.rootUrl && ( - //

Root URL: {submittedConfig.rootUrl}

- // )} - // {submittedConfig.maxDepth && ( - //

Max depth: {submittedConfig.maxDepth}

- // )} - // {submittedConfig.faviconUrl && ( - //

Favicon URL: {submittedConfig.faviconUrl}

- // )} - //
- // {!!status && ( - //
- //

{`Type "@docs" and select ${submittedConfig.title} to reference these docs once indexing is complete. Check indexing status from the "More" page.`}

- //
- // - //
- //
- // )} - //
- // { - // setSubmittedConfig(undefined); - // }} - // > - // Add another - // - // - //
- //
- // ); - // } + ideMessenger.post("context/addDocs", siteIndexingConfig); + + posthog.capture("add_docs_gui", { url: startUrl }); + + // Optimistic status update + dispatch( + updateIndexingStatus({ + type: "docs", + description: "Initializing", + id: docsResult.details.docsLink, + embeddingsProviderId: "mock-embeddings-provider-id", + progress: 0, + status: "indexing", + title: docsResult.details.title ?? docsResult.packageInfo.name, + url: docsResult.details.docsLink, + }), + ); + }; return ( -
-
-

Add documentation

- {docsSuggestions.length ? ( -
- - - - - - {/* */} - - - - - - Add docs - {docsSuggestions.map((docsResult) => { - const { error, details } = docsResult; - const { language, name, version } = docsResult.packageInfo; - const id = `${language}-${name}-${version}`; - return ( - - - - {/* */} - - - - ); - })} - -
- - TitleVersionStart Link
- - {name}{version} - {error ? ( - - No docs link found - - ) : ( - -
- -
-

- {details.docsLink} -

-
- )} -
- - - -

{`Version: ${version}`}

-

{`Found in ${docsResult.packageInfo.packageFile.path}`}

-
-
-
- ) : null} -

- Continue pre-indexes many common documentation sites, but if there's - one you don't see in the dropdown, enter the URL here. -

- -

- Continue's indexing engine will crawl the site and generate embeddings - so that you can ask questions. -

-
- {/* -
- - - - -
setIsOpen((prev) => !prev)} - > - {isOpen ? ( - - ) : ( - - )} - Advanced -
- - {isOpen && ( -
- -
+
+
+

Add documentation

+

Add docs

+ {sortedDocsSuggestions.length && ( +

Suggestions

)} - -
- +
+ {sortedDocsSuggestions.map((docsResult) => { + const { error, details } = docsResult; + const { language, name, version } = docsResult.packageInfo; + const id = `${language}-${name}-${version}`; + return ( + <> +
{ + handleSelectSuggestion(docsResult); + }} + > +
+ {error ? ( +
+ + + Docs URL not found + +
+ ) : details.docsLinkWarning ? ( +
+ + + Start URL might not lead to docs + +
+ ) : ( + + )} +
+
+
+ +
+ {name} +
+
+ {error ? ( + + No docs link found + + ) : ( +
+ {/*
+ +
*/} +

+ {details.docsLink} +

+
+ )} +
+
+ + +

{`Version: ${version}`}

+

{`Found in ${docsResult.packageInfo.packageFile.path}`}

+
+
+
+ + {error ? "Add to form" : "Index these docs"} + + + ); + })}
- */} +
+
+
+ + + +
+
+ + Done + + +
+
+
+
+ + +
+
+ {docsIndexingStatuses.length ? ( +

+ It is safe to close this form while indexing +

+ ) : null} +
+
); } diff --git a/gui/src/components/dialogs/index.tsx b/gui/src/components/dialogs/index.tsx index 7685109ba..8a3a67fe8 100644 --- a/gui/src/components/dialogs/index.tsx +++ b/gui/src/components/dialogs/index.tsx @@ -71,7 +71,7 @@ const TextDialog = (props: TextDialogProps) => { return (