docs suggestions: packages in GUI
This commit is contained in:
parent
954bd5f563
commit
abd46dfb4f
8 changed files with 61 additions and 6 deletions
|
|
@ -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);
|
||||
});
|
||||
//
|
||||
|
||||
|
|
|
|||
3
core/index.d.ts
vendored
3
core/index.d.ts
vendored
|
|
@ -1219,3 +1219,6 @@ export type PackageDocsResult = {
|
|||
| { error: string; details?: never }
|
||||
| { details: PackageDetailsSuccess; error?: never }
|
||||
);
|
||||
|
||||
// language -> package -> package info
|
||||
export type DocsSuggestions = Record<string, PackageDocsResult[]>;
|
||||
|
|
|
|||
|
|
@ -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<string, PackageDocsResult[]> = {};
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,4 +75,5 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] =
|
|||
"getWebviewHistoryLength",
|
||||
"signInToControlPlane",
|
||||
"openDialogMessage",
|
||||
"docs/suggestions",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<div className="p-4">
|
||||
<div className="mb-8">
|
||||
<h1>Add a documentation site</h1>
|
||||
|
||||
<h1>Add documentation</h1>
|
||||
{docsByLanguage.map(({ language, packages }) => {
|
||||
return (
|
||||
<div key={language}>
|
||||
<h1>{language}</h1>
|
||||
<div>
|
||||
{packages.map((pkg) => {
|
||||
return (
|
||||
<div>
|
||||
<p>{pkg.packageInfo.name}</p>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
<p>
|
||||
Continue pre-indexes many common documentation sites, but if there's
|
||||
one you don't see in the dropdown, enter the URL here.
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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<DocsSuggestions>,
|
||||
) => {
|
||||
console.log("FROM REDUX", payload);
|
||||
state.docsSuggestions = payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -480,6 +490,7 @@ export const {
|
|||
updateIndexingStatus,
|
||||
setIndexingChatPeekHidden,
|
||||
abortStream,
|
||||
updateDocsSuggestions,
|
||||
} = stateSlice.actions;
|
||||
|
||||
export default stateSlice.reducer;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue