From abd46dfb4ff1aea84e94922fdda5d6fce23c6edf Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 21 Nov 2024 12:52:25 -0800 Subject: [PATCH] docs suggestions: packages in GUI --- core/core.ts | 3 +- core/index.d.ts | 3 ++ core/indexing/docs/suggestions/index.ts | 4 +-- core/protocol/passThrough.ts | 1 + core/protocol/webview.ts | 2 ++ gui/src/components/dialogs/AddDocsDialog.tsx | 37 ++++++++++++++++++-- gui/src/hooks/useSetup.ts | 6 ++++ gui/src/redux/slices/stateSlice.ts | 11 ++++++ 8 files changed, 61 insertions(+), 6 deletions(-) diff --git a/core/core.ts b/core/core.ts index d080ec34b..d81df8a37 100644 --- a/core/core.ts +++ b/core/core.ts @@ -739,7 +739,8 @@ export class Core { return this.docsService.initStatuses(); }); on("docs/getSuggestedDocs", async (msg) => { - getAllSuggestedDocs(this.ide); + const suggestedDocs = await getAllSuggestedDocs(this.ide); + this.messenger.send("docs/suggestions", suggestedDocs); }); // diff --git a/core/index.d.ts b/core/index.d.ts index de1adb893..d6b2c1970 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1219,3 +1219,6 @@ export type PackageDocsResult = { | { error: string; details?: never } | { details: PackageDetailsSuccess; error?: never } ); + +// language -> package -> package info +export type DocsSuggestions = Record; diff --git a/core/indexing/docs/suggestions/index.ts b/core/indexing/docs/suggestions/index.ts index 5699cd761..3ee4fb642 100644 --- a/core/indexing/docs/suggestions/index.ts +++ b/core/indexing/docs/suggestions/index.ts @@ -1,4 +1,5 @@ import { + DocsSuggestions, FilePathAndName, IDE, PackageDetails, @@ -80,7 +81,7 @@ export async function getAllSuggestedDocs(ide: IDE) { }); // Get documentation links for all packages - const docsByLanguage: Record = {}; + const docsByLanguage: DocsSuggestions = {}; await Promise.all( PACKAGE_CRAWLERS.map(async (Crawler) => { const crawler = new Crawler(); @@ -112,7 +113,6 @@ export async function getAllSuggestedDocs(ide: IDE) { ); }), ); - return docsByLanguage; } diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index ebe2a8697..2bd8de2c1 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -75,4 +75,5 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] = "getWebviewHistoryLength", "signInToControlPlane", "openDialogMessage", + "docs/suggestions", ]; diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index 0dcdb047f..bf90497c8 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -2,6 +2,7 @@ import { ConfigValidationError } from "../config/validation.js"; import type { ContextItemWithId, + DocsSuggestions, IndexingProgressUpdate, IndexingStatus, } from "../index.js"; @@ -25,4 +26,5 @@ export type ToWebviewFromIdeOrCoreProtocol = { getWebviewHistoryLength: [undefined, number]; signInToControlPlane: [undefined, void]; openDialogMessage: ["account", void]; + "docs/suggestions": [DocsSuggestions, void]; }; diff --git a/gui/src/components/dialogs/AddDocsDialog.tsx b/gui/src/components/dialogs/AddDocsDialog.tsx index 098194886..c21aca5a6 100644 --- a/gui/src/components/dialogs/AddDocsDialog.tsx +++ b/gui/src/components/dialogs/AddDocsDialog.tsx @@ -5,7 +5,7 @@ import { } from "@heroicons/react/24/outline"; import { SiteIndexingConfig } from "core"; import { usePostHog } from "posthog-js/react"; -import { useContext, useLayoutEffect, useRef, useState } from "react"; +import { useContext, useLayoutEffect, useMemo, useRef, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import { Button, HelperText, Input, lightGray, SecondaryButton } from ".."; import { IdeMessengerContext } from "../../context/IdeMessenger"; @@ -15,6 +15,7 @@ import { } from "../../redux/slices/uiStateSlice"; import { RootState } from "../../redux/store"; import IndexingStatusViewer from "../indexing/IndexingStatus"; +import { C } from "core/autocomplete/constants/AutocompleteLanguageInfo"; function AddDocsDialog() { const posthog = usePostHog(); @@ -34,6 +35,21 @@ function AddDocsDialog() { (store: RootState) => store.state.indexing.statuses, ); + const docsSuggestions = useSelector( + (store: RootState) => store.state.docsSuggestions, + ); + + const docsByLanguage = useMemo(() => { + console.log(docsSuggestions); + const languages = Object.keys(docsSuggestions); + return languages.map((language) => { + return { + language, + packages: docsSuggestions[language], + }; + }); + }, [docsSuggestions]); + const isFormValid = startUrl && title; useLayoutEffect(() => { @@ -118,8 +134,23 @@ function AddDocsDialog() { return (
-

Add a documentation site

- +

Add documentation

+ {docsByLanguage.map(({ language, packages }) => { + return ( +
+

{language}

+
+ {packages.map((pkg) => { + return ( +
+

{pkg.packageInfo.name}

+
+ ); + })} +
+
+ ); + })}

Continue pre-indexes many common documentation sites, but if there's one you don't see in the dropdown, enter the URL here. diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index f18379889..ecc7a7ac9 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -11,6 +11,7 @@ import { setInactive, setSelectedProfileId, setTTSActive, + updateDocsSuggestions, updateIndexingStatus, } from "../redux/slices/stateSlice"; import { RootState } from "../redux/store"; @@ -85,6 +86,7 @@ function useSetup(dispatch: Dispatch) { // ON LOAD useEffect(() => { ideMessenger.post("docs/getSuggestedDocs", undefined); + // Override persisted state dispatch(setInactive()); @@ -116,6 +118,10 @@ function useSetup(dispatch: Dispatch) { } }, []); + useWebviewListener("docs/suggestions", async (data) => { + dispatch(updateDocsSuggestions(data)); + }); + const { streamResponse } = useChatHandler(dispatch, ideMessenger); const defaultModelTitle = useSelector( diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index 770e9ce69..e965455c4 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -5,6 +5,7 @@ import { ChatMessage, Checkpoint, ContextItemWithId, + DocsSuggestions, FileSymbolMap, IndexingStatus, PersistedSessionInfo, @@ -47,6 +48,7 @@ type State = { }; streamAborter: AbortController; isMultifileEdit: boolean; + docsSuggestions: DocsSuggestions; }; const initialState: State = { @@ -89,6 +91,7 @@ const initialState: State = { }, }, streamAborter: new AbortController(), + docsSuggestions: {}, }; export const stateSlice = createSlice({ @@ -447,6 +450,13 @@ export const stateSlice = createSlice({ [payload.type]: payload.hidden, }; }, + updateDocsSuggestions: ( + state, + { payload }: PayloadAction, + ) => { + console.log("FROM REDUX", payload); + state.docsSuggestions = payload; + }, }, }); @@ -480,6 +490,7 @@ export const { updateIndexingStatus, setIndexingChatPeekHidden, abortStream, + updateDocsSuggestions, } = stateSlice.actions; export default stateSlice.reducer;