Merge pull request #2972 from continuedev/dallin/docs-ui

Docs Indexing UI
This commit is contained in:
Nate Sesti 2024-11-20 10:25:37 -08:00 • committed by GitHub
commit 45af97608e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 1210 additions and 481 deletions

View file

@ -9,7 +9,6 @@ import {
} from "../..";
import DocsService from "../../indexing/docs/DocsService";
import preIndexedDocs from "../../indexing/docs/preIndexedDocs";
import { Telemetry } from "../../util/posthog";
import { INSTRUCTIONS_BASE_ITEM } from "./utils";
@ -88,38 +87,10 @@ class DocsContextProvider extends BaseContextProvider {
return [];
}
const isJetBrainsAndPreIndexedDocsProvider =
await docsService.isJetBrainsAndPreIndexedDocsProvider();
if (isJetBrainsAndPreIndexedDocsProvider) {
void extras.ide.showToast(
"error",
`${DocsService.preIndexedDocsEmbeddingsProvider.id} is configured as ` +
"the embeddings provider, but it cannot be used with JetBrains. " +
"Please select a different embeddings provider to use the '@docs' " +
"context provider.",
);
return [];
}
const preIndexedDoc = preIndexedDocs[query];
if (!!preIndexedDoc) {
void Telemetry.capture("docs_pre_indexed_doc_used", {
doc: preIndexedDoc["title"],
});
}
const embeddingsProvider = await docsService.getEmbeddingsProvider(
!!preIndexedDoc,
);
const [vector] = await embeddingsProvider.embed([extras.fullInput]);
let chunks = await docsService.retrieveChunks(
await docsService.isInitialized;
let chunks = await docsService.retrieveChunksFromQuery(
extras.fullInput, // confusing: fullInput = the query, query = startUrl in this case
query,
vector,
this.options?.nRetrieve ?? DocsContextProvider.nRetrieve,
);
@ -175,7 +146,7 @@ class DocsContextProvider extends BaseContextProvider {
return [];
}
const docs = (await docsService.list()) ?? [];
const docs = (await docsService.listMetadata()) ?? [];
const canUsePreindexedDocs = await docsService.canUsePreindexedDocs();
const submenuItemsMap = new Map<string, ContextSubmenuItem>();

View file

@ -42,7 +42,7 @@ export class Core {
codebaseIndexerPromise: Promise<CodebaseIndexer>;
completionProvider: CompletionProvider;
continueServerClientPromise: Promise<ContinueServerClient>;
indexingState: IndexingProgressUpdate;
codebaseIndexingState: IndexingProgressUpdate;
controlPlaneClient: ControlPlaneClient;
private docsService: DocsService;
private globalContext = new GlobalContext();
@ -88,7 +88,11 @@ export class Core {
// Ensure .continue directory is created
setupInitialDotContinueDirectory();
this.indexingState = { status: "loading", desc: "loading", progress: 0 };
this.codebaseIndexingState = {
status: "loading",
desc: "loading",
progress: 0,
};
const ideSettingsPromise = messenger.request("getIdeSettings", undefined);
const sessionInfoPromise = messenger.request("getControlPlaneSessionInfo", {
@ -148,6 +152,7 @@ export class Core {
// Index on initialization
void this.ide.getWorkspaceDirs().then(async (dirs) => {
// Respect pauseCodebaseIndexOnStart user settings
this.indexingPauseToken.paused = true;
if (ideSettings.pauseCodebaseIndexOnStart) {
void this.messenger.request("indexProgress", {
progress: 1,
@ -272,34 +277,15 @@ export class Core {
// Context providers
on("context/addDocs", async (msg) => {
let hasFailed = false;
for await (const result of this.docsService.indexAndAdd(msg.data)) {
if (result.status === "failed") {
hasFailed = true;
break;
}
}
if (hasFailed) {
void this.ide.showToast("info", `Failed to index ${msg.data.startUrl}`);
} else {
void this.ide.showToast(
"info",
`Successfully indexed ${msg.data.startUrl}`,
);
this.messenger.send("refreshSubmenuItems", undefined);
}
void this.docsService.indexAndAdd(msg.data);
});
on("context/removeDocs", async (msg) => {
await this.docsService.delete(msg.data.startUrl);
this.messenger.send("refreshSubmenuItems", undefined);
});
on("context/indexDocs", async (msg) => {
await this.docsService.indexAllDocs(msg.data.reIndex);
this.messenger.send("refreshSubmenuItems", undefined);
await this.docsService.syncOrReindexAllDocsWithPrompt(msg.data.reIndex);
});
on("context/loadSubmenuItems", async (msg) => {
@ -681,6 +667,8 @@ export class Core {
const rows = await DevDataSqliteDb.getTokensPerModel();
return rows;
});
// Codebase indexing
on("index/forceReIndex", async ({ data }) => {
if (data?.shouldClearIndexes) {
const codebaseIndexer = await this.codebaseIndexerPromise;
@ -696,17 +684,41 @@ export class Core {
}
});
on("index/setPaused", (msg) => {
new GlobalContext().update("indexingPaused", msg.data);
this.globalContext.update("indexingPaused", msg.data);
this.indexingPauseToken.paused = msg.data;
});
on("index/indexingProgressBarInitialized", async (msg) => {
// Triggered when progress bar is initialized.
// If a non-default state has been stored, update the indexing display to that state
if (this.indexingState.status !== "loading") {
void this.messenger.request("indexProgress", this.indexingState);
if (this.codebaseIndexingState.status !== "loading") {
void this.messenger.request(
"indexProgress",
this.codebaseIndexingState,
);
}
});
// Docs, etc. indexing
on("indexing/reindex", async (msg) => {
if (msg.data.type === "docs") {
void this.docsService.reindexDoc(msg.data.id);
}
});
on("indexing/abort", async (msg) => {
if (msg.data.type === "docs") {
this.docsService.abort(msg.data.id);
}
});
on("indexing/setPaused", async (msg) => {
if (msg.data.type === "docs") {
this.docsService.setPaused(msg.data.id, msg.data.paused);
}
});
on("indexing/initStatuses", async (msg) => {
return this.docsService.initStatuses();
});
//
on("didChangeSelectedProfile", (msg) => {
void this.configHandler.setSelectedProfile(msg.data.id);
void this.configHandler.reloadConfig();
@ -763,7 +775,7 @@ export class Core {
}
void this.messenger.request("indexProgress", updateToSend);
this.indexingState = updateToSend;
this.codebaseIndexingState = updateToSend;
if (update.status === "failed") {
void this.sendIndexingErrorTelemetry(update);
@ -797,7 +809,7 @@ export class Core {
}
void this.messenger.request("indexProgress", updateToSend);
this.indexingState = updateToSend;
this.codebaseIndexingState = updateToSend;
if (update.status === "failed") {
void this.sendIndexingErrorTelemetry(update);
@ -806,4 +818,6 @@ export class Core {
this.messenger.send("refreshSubmenuItems", undefined);
}
// private
}

24
core/index.d.ts vendored
View file

@ -45,6 +45,30 @@ export interface IndexingProgressUpdate {
debugInfo?: string;
}
// This is more or less a V2 of IndexingProgressUpdate
export interface IndexingStatus {
id: string;
type: "docs";
progress: number;
description: string;
status:
| "indexing"
| "complete"
| "paused"
| "failed"
| "aborted"
| "deleted"
| "pending";
embeddingsProviderId: string;
isReindexing?: boolean;
debugInfo?: string;
title: string;
icon?: string;
url?: string;
}
export type IndexingStatusMap = Map<string, IndexingStatus>;
export type PromptTemplateFunction = (
history: ChatMessage[],
otherData: Record<string, string>,

View file

@ -95,6 +95,6 @@ export default DocsCrawler;
export {
CheerioCrawler,
ChromiumCrawler,
ChromiumInstaller as ChromiumInstaller,
ChromiumInstaller,
GitHubCrawler,
};

View file

@ -66,23 +66,20 @@ describe.skip("DocsService Integration Tests", () => {
});
test("Indexing, retrieval, and deletion of a new documentation site", async () => {
const generator = docsService.indexAndAdd(mockSiteConfig);
while (!(await generator.next()).done) {}
await docsService.indexAndAdd(mockSiteConfig);
let latestConfig = await getReloadedConfig();
// Sqlite check
expect(await docsService.has(mockSiteConfig.startUrl)).toBe(true);
expect(await docsService.hasMetadata(mockSiteConfig.startUrl)).toBe(true);
// config.json check
expect(latestConfig.docs).toContainEqual(mockSiteConfig);
// Lance DB check
const embeddingsProvider = await docsService.getEmbeddingsProvider();
const [mockVector] = await embeddingsProvider.embed(["test"]);
let retrievedChunks = await docsService.retrieveChunks(
let retrievedChunks = await docsService.retrieveChunksFromQuery(
"test",
mockSiteConfig.startUrl,
mockVector,
5,
);
@ -91,7 +88,7 @@ describe.skip("DocsService Integration Tests", () => {
await docsService.delete(mockSiteConfig.startUrl);
// Sqlite check
expect(await docsService.has(mockSiteConfig.startUrl)).toBe(false);
expect(await docsService.hasMetadata(mockSiteConfig.startUrl)).toBe(false);
// config.json check
latestConfig = await getReloadedConfig();
@ -100,9 +97,9 @@ describe.skip("DocsService Integration Tests", () => {
);
// LanceDB check
retrievedChunks = await docsService.retrieveChunks(
retrievedChunks = await docsService.retrieveChunksFromQuery(
"test",
mockSiteConfig.startUrl,
mockVector,
5,
);
expect(retrievedChunks.length).toBe(0);
@ -133,17 +130,15 @@ describe.skip("DocsService Integration Tests", () => {
test("Handles pulling down and adding pre-indexed docs", async () => {
const preIndexedDoc = Object.values(preIndexedDocs)[0];
const generator = docsService.indexAndAdd(preIndexedDoc);
while (!(await generator.next()).done) {}
await docsService.indexAndAdd(preIndexedDoc);
});
test("Config synchronization with SQLite", async () => {
const generator = docsService.indexAndAdd(mockSiteConfig);
while (!(await generator.next()).done) {}
await docsService.indexAndAdd(mockSiteConfig);
await getReloadedConfig();
expect(await docsService.has(mockSiteConfig.startUrl)).toBe(true);
expect(await docsService.hasMetadata(mockSiteConfig.startUrl)).toBe(true);
editConfigJson((config) => {
const { docs, ...restConfig } = config;
@ -164,6 +159,6 @@ describe.skip("DocsService Integration Tests", () => {
await new Promise((resolve) => setTimeout(resolve, 100));
}
expect(await docsService.has(mockSiteConfig.startUrl)).toBe(false);
expect(await docsService.hasMetadata(mockSiteConfig.startUrl)).toBe(false);
});
});

File diff suppressed because it is too large Load diff

View file

@ -8,6 +8,7 @@ import type {
ContextSubmenuItem,
DiffLine,
IdeSettings,
IndexingStatusMap,
LLMFullCompletionOptions,
MessageContent,
ModelDescription,
@ -142,6 +143,8 @@ export type ToCoreFromIdeOrWebviewProtocol = {
{ model: string; promptTokens: number; generatedTokens: number }[],
];
"tts/kill": [undefined, void];
// Codebase indexing
"index/setPaused": [boolean, void];
"index/forceReIndex": [
undefined | { dirs?: string[]; shouldClearIndexes?: boolean },
@ -155,6 +158,13 @@ export type ToCoreFromIdeOrWebviewProtocol = {
},
void,
];
// Docs etc. Indexing. TODO move codebase to this
"indexing/reindex": [{ type: string; id: string }, void];
"indexing/abort": [{ type: string; id: string }, void];
"indexing/setPaused": [{ type: string; id: string; paused: boolean }, void];
"indexing/initStatuses": [undefined, void];
addAutocompleteModel: [{ model: ModelDescription }, void];
"profiles/switch": [{ id: string }, undefined];

View file

@ -39,10 +39,17 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
"chatDescriber/describe",
"stats/getTokensPerDay",
"stats/getTokensPerModel",
// Codebase
"index/setPaused",
"index/forceReIndex",
"index/forceReIndexFiles",
"index/indexingProgressBarInitialized",
// Docs, etc.
"indexing/initStatuses",
"indexing/reindex",
"indexing/abort",
"indexing/setPaused",
//
"completeOnboarding",
"addAutocompleteModel",
"config/listProfiles",
@ -55,7 +62,8 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] =
[
"configUpdate",
"getDefaultModelTitle",
"indexProgress",
"indexProgress", // Codebase
"indexing/statusUpdate", // Docs, etc.
"addContextItem",
"refreshSubmenuItems",
"isContinueInputFocused",

View file

@ -1,12 +1,17 @@
import { ConfigValidationError } from "../config/validation.js";
import type { ContextItemWithId, IndexingProgressUpdate } from "../index.js";
import type {
ContextItemWithId,
IndexingProgressUpdate,
IndexingStatus,
} from "../index.js";
export type ToWebviewFromIdeOrCoreProtocol = {
configUpdate: [undefined, void];
configError: [ConfigValidationError[] | undefined, void];
getDefaultModelTitle: [undefined, string];
indexProgress: [IndexingProgressUpdate, void];
indexProgress: [IndexingProgressUpdate, void]; // Codebase
"indexing/statusUpdate": [IndexingStatus, void]; // Docs, etc.
refreshSubmenuItems: [undefined, void];
isContinueInputFocused: [undefined, boolean];
addContextItem: [

View file

@ -2356,7 +2356,7 @@
"type": "integer",
"description": "The maximum depth to crawl the documentation site"
},
"favicon": {
"faviconUrl": {
"type": "string",
"description": "The URL path to a favicon for the site - by default, it will be `/favicon.ico` path from the Start URL"
}

View file

@ -1,11 +1,20 @@
import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline";
import {
CheckCircleIcon,
ChevronDownIcon,
ChevronUpIcon,
} from "@heroicons/react/24/outline";
import { SiteIndexingConfig } from "core";
import { usePostHog } from "posthog-js/react";
import { useContext, useLayoutEffect, useRef, useState } from "react";
import { useDispatch } from "react-redux";
import { Button, HelperText, Input, lightGray } from "..";
import { useDispatch, useSelector } from "react-redux";
import { Button, HelperText, Input, lightGray, SecondaryButton } from "..";
import { IdeMessengerContext } from "../../context/IdeMessenger";
import { setShowDialog } from "../../redux/slices/uiStateSlice";
import {
setDialogMessage,
setShowDialog,
} from "../../redux/slices/uiStateSlice";
import { RootState } from "../../redux/store";
import IndexingStatusViewer from "../indexing/IndexingStatus";
function AddDocsDialog() {
const posthog = usePostHog();
@ -18,7 +27,12 @@ function AddDocsDialog() {
const [faviconUrl, setFaviconUrl] = useState("");
const [isOpen, setIsOpen] = useState(false);
const [submittedConfig, setSubmittedConfig] = useState<SiteIndexingConfig>();
const ideMessenger = useContext(IdeMessengerContext);
const indexingStatuses = useSelector(
(store: RootState) => store.state.indexing.statuses,
);
const isFormValid = startUrl && title;
@ -41,15 +55,66 @@ function AddDocsDialog() {
ideMessenger.post("context/addDocs", siteIndexingConfig);
setSubmittedConfig(siteIndexingConfig);
setTitle("");
setStartUrl("");
setFaviconUrl("");
dispatch(setShowDialog(false));
posthog.capture("add_docs_gui", { url: startUrl });
}
if (submittedConfig) {
const status = indexingStatuses[submittedConfig.startUrl];
return (
<div className="flex flex-col p-4">
<div className="flex flex-row items-center gap-2">
<CheckCircleIcon className="h-8 w-8" />
<h1>{`Docs added`}</h1>
</div>
<div className="flex flex-col gap-1 text-stone-500">
<p className="m-0 p-0">Title: {submittedConfig.title}</p>
<p className="m-0 p-0">Start URL: {submittedConfig.startUrl}</p>
{submittedConfig.rootUrl && (
<p className="m-0 p-0">Root URL: {submittedConfig.rootUrl}</p>
)}
{submittedConfig.maxDepth && (
<p className="m-0 p-0">Max depth: {submittedConfig.maxDepth}</p>
)}
{submittedConfig.faviconUrl && (
<p className="m-0 p-0">Favicon URL: {submittedConfig.faviconUrl}</p>
)}
</div>
{!!status && (
<div className="mt-4 flex flex-col divide-x-0 divide-y-2 divide-solid divide-zinc-700">
<p className="m-0 mb-5 p-0 leading-snug">{`Type "@docs" and select ${submittedConfig.title} to reference these docs once indexing is complete. Check indexing status from the "More" page.`}</p>
<div className="pt-1">
<IndexingStatusViewer status={status} />
</div>
</div>
)}
<div className="mt-4 flex flex-row items-center justify-end gap-4">
<SecondaryButton
className=""
onClick={() => {
setSubmittedConfig(undefined);
}}
>
Add another
</SecondaryButton>
<Button
className=""
onClick={() => {
dispatch(setDialogMessage(undefined));
dispatch(setShowDialog(false));
}}
>
Done
</Button>
</div>
</div>
);
}
return (
<div className="p-4">
<div className="mb-8">

View file

@ -34,7 +34,6 @@ const DialogContainer = styled.div`
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 75%;
`;
const Dialog = styled.div`
@ -72,6 +71,7 @@ const TextDialog = (props: TextDialogProps) => {
return (
<ScreenCover onClick={props.onClose} hidden={!props.showDialog}>
<DialogContainer
className="xs:w-[85%] w-[92%] sm:w-[75%]"
onClick={(e) => {
e.stopPropagation();
}}

View file

@ -154,7 +154,6 @@ export const Button = styled.button`
export const SecondaryButton = styled.button`
padding: 10px 12px;
margin: 8px 0;
height: 2.5rem;
border-radius: ${defaultBorderRadius};
border: 1px solid ${vscForeground};

View file

@ -0,0 +1,113 @@
import { useDispatch, useSelector } from "react-redux";
import { RootState } from "../../redux/store";
import { IndexingStatus } from "core";
import { useMemo, useState } from "react";
import { useNavigate } from "react-router-dom";
import { ArrowPathIcon, EyeSlashIcon } from "@heroicons/react/24/outline";
import { setIndexingChatPeekHidden } from "../../redux/slices/stateSlice";
interface MergedIndexingState {
displayName: string;
type: IndexingStatus["type"];
titles: IndexingStatus["title"][];
progressPercentage: number;
}
const mergeProgress = (states: IndexingStatus[]): number => {
const progress =
states.reduce((acc, state) => acc + state.progress, 0) / states.length;
return Math.min(100, Math.max(0, progress * 100));
};
export interface ChatIndexingPeekProps {
state: MergedIndexingState;
}
function ChatIndexingPeek({ state }: ChatIndexingPeekProps) {
const navigate = useNavigate();
const dispatch = useDispatch();
const hiddenPeeks = useSelector(
(store: RootState) => store.state.indexing.hiddenChatPeekTypes,
);
if (hiddenPeeks[state.type]) return null;
return (
<div
className="flex flex-row items-center border-0 border-t border-solid border-t-zinc-700 px-3 py-0.5"
onClick={() => {
navigate("/more");
}}
>
<div className="group flex flex-1 cursor-pointer flex-row items-center gap-2">
<div className={`flex flex-row items-center gap-2`}>
<p className="m-0 p-0 text-stone-500 group-hover:underline">
{state.displayName}
</p>
{/* <p className="no-underline lines lines-1 m-0 max-w-20 p-0 text-xs text-stone-500">
{state.titles.join(", ")}
</p> */}
</div>
<div className="my-2 h-1.5 flex-1 rounded-md border border-solid border-gray-400">
<div
className={`h-full rounded-lg bg-stone-500 transition-all duration-200 ease-in-out`}
style={{
width: `${state.progressPercentage}%`,
}}
/>
</div>
<div className="xs:flex hidden flex-row items-center gap-1 text-stone-500">
<span className="text-xs no-underline">
{state.progressPercentage.toFixed(0)}%
</span>
<ArrowPathIcon
className={`animate-spin-slow inline-block h-4 w-4 text-stone-500`}
></ArrowPathIcon>
</div>
</div>
<EyeSlashIcon
className="ml-2 h-4 w-4 cursor-pointer text-stone-500 hover:opacity-80"
onClick={(e) => {
dispatch(
setIndexingChatPeekHidden({ type: state.type, hidden: true }),
);
e.stopPropagation();
}}
/>
</div>
);
}
function ChatIndexingPeeks() {
const indexingStatuses = useSelector(
(store: RootState) => store.state.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) {
mergedStates.push({
displayName: "Docs indexing",
type: "docs",
titles: docsStates.map((state) => state.title),
progressPercentage: mergeProgress(docsStates),
});
}
return mergedStates;
}, [indexingStatuses]);
if (!mergedIndexingStates.length) return null;
return (
<div className="flex flex-col gap-1">
{mergedIndexingStates.map((state) => {
return <ChatIndexingPeek state={state} />;
})}
</div>
);
}
export default ChatIndexingPeeks;

View file

@ -0,0 +1,147 @@
import { IndexingStatus } from "core";
import { PropsWithChildren, useContext, useMemo } from "react";
import { useDispatch } from "react-redux";
import { usePostHog } from "posthog-js/react";
import { IdeMessengerContext } from "../../context/IdeMessenger";
import {
ArrowPathIcon,
ArrowRightStartOnRectangleIcon,
ArrowTopRightOnSquareIcon,
CheckCircleIcon,
PauseCircleIcon,
XMarkIcon,
} from "@heroicons/react/24/outline";
import { updateIndexingStatus } from "../../redux/slices/stateSlice";
interface IndexingStatusViewerProps {
status: IndexingStatus;
}
const STATUS_TO_ICON: Record<IndexingStatus["status"], any> = {
indexing: ArrowPathIcon,
paused: PauseCircleIcon,
complete: CheckCircleIcon,
aborted: null,
deleted: null,
pending: null,
failed: XMarkIcon, // Since we show an erorr message below
};
function IndexingStatusViewer({ status }: IndexingStatusViewerProps) {
const ideMessenger = useContext(IdeMessengerContext);
const posthog = usePostHog();
const dispatch = useDispatch();
const reIndex = () =>
ideMessenger.post("indexing/reindex", {
type: status.type,
id: status.id,
});
const abort = () => {
ideMessenger.post("indexing/abort", {
type: status.type,
id: status.id,
});
// Optimistic abort status
dispatch(
updateIndexingStatus({ ...status, status: "aborted", progress: 0 }),
);
};
const progressPercentage = useMemo(() => {
return Math.min(100, Math.max(0, status.progress * 100));
}, [status.progress]);
const Icon = STATUS_TO_ICON[status.status];
return (
<div className="mt-2 flex w-full flex-col">
{/* {`${status.type} - ${status.id} - ${status.status} - ${status.progress} - ${status.description} - ${status.icon}`} */}
<div
className={`flex flex-row items-center justify-between gap-2 text-sm`}
>
<div
className={`flex flex-row items-center gap-2 ${status.url ? "cursor-pointer hover:underline" : ""}`}
onClick={() => {
if (status.url) {
ideMessenger.post("openUrl", status.url);
}
}}
>
{status.icon ? (
<img src={status.icon} alt="doc icon" className="h-4 w-4" />
) : null}
<p className="lines lines-1 m-0 p-0 text-left">
{status.title ?? status.id}
</p>
{!!status.url && (
<ArrowTopRightOnSquareIcon className="mb-0.5 h-3 w-3 text-stone-500" />
)}
</div>
{status.status === "pending" ? (
<div className="text-xs text-stone-500">Pending...</div>
) : (
<div className="flex flex-row items-center gap-1 text-stone-500">
<span className="text-xs">{progressPercentage.toFixed(0)}%</span>
{Icon ? (
<Icon
className={`inline-block h-4 w-4 text-stone-500 ${
status.status === "indexing" ? "animate-spin-slow" : ""
}`}
></Icon>
) : null}
</div>
)}
</div>
<div className="my-2 h-1.5 w-full rounded-md border border-solid border-gray-400">
<div
className={`h-full rounded-lg transition-all duration-200 ease-in-out ${
status.status === "failed" ? "bg-red-600" : "bg-stone-500"
}`}
style={{
width: `${progressPercentage}%`,
}}
/>
</div>
<div className="flex flex-row items-center justify-between gap-4">
<span
className={`cursor-pointer whitespace-nowrap text-xs text-stone-500 underline`}
onClick={
{
complete: reIndex,
indexing: abort,
failed: reIndex,
aborted: reIndex,
paused: () => {},
deleted: () => {},
pending: () => {},
}[status.status]
}
>
{
{
complete: "Click to re-index",
indexing: "Cancel indexing",
failed: "Click to retry",
aborted: "Click to index",
paused: "",
deleted: "",
pending: "",
}[status.status]
}
</span>
{/* {status.status === "indexing" && ( */}
<span className="lines lines-1 text-right text-xs text-stone-500">
{status.description}
</span>
{/* )} */}
</div>
</div>
);
}
export default IndexingStatusViewer;

View file

@ -0,0 +1,56 @@
import { useMemo } from "react";
import { useDispatch, useSelector } from "react-redux";
import { RootState } from "../../redux/store";
import IndexingStatusViewer from "./IndexingStatus";
import { Button, SecondaryButton } from "..";
import {
setDialogMessage,
setShowDialog,
} from "../../redux/slices/uiStateSlice";
import AddDocsDialog from "../dialogs/AddDocsDialog";
function IndexingStatuses() {
const indexingStatuses = useSelector(
(store: RootState) => store.state.indexing.statuses,
);
const docsStatuses = useMemo(() => {
const docs = Object.values(indexingStatuses).filter(
(status) => status.type === "docs" && status.status !== "deleted",
);
return docs;
}, [indexingStatuses]);
const dispatch = useDispatch();
return (
<div className="flex flex-col gap-1">
<div className="flex flex-row items-center justify-between">
<h3 className="mb-1 mt-0 text-xl">@docs indexes</h3>
{/* <div className="border-1 rounded-full border">
<ChevronUpIcon className="h-8 w-8" />
</div> */}
{/* TODO add some way to hide, scroll, etc. */}
</div>
<span className="text-xs text-stone-500">
Manage your documentation sources
</span>
{/* <div className="flex max-h-[170px] flex-col gap-1 overflow-x-hidden overflow-y-scroll pr-2"> */}
{docsStatuses.length ? (
docsStatuses.map((status) => {
return <IndexingStatusViewer key={status.id} status={status} />;
})
) : (
<SecondaryButton
onClick={() => {
dispatch(setShowDialog(true));
dispatch(setDialogMessage(<AddDocsDialog />));
}}
>
Add Docs
</SecondaryButton>
)}
</div>
// </div>
);
}
export default IndexingStatuses;

View file

@ -0,0 +1,16 @@
import {
ArrowPathIcon,
CheckCircleIcon,
PauseCircleIcon,
} from "@heroicons/react/24/outline";
import { IndexingStatus } from "core";
export const STATUS_TO_ICON: Record<IndexingStatus["status"], any> = {
indexing: ArrowPathIcon,
paused: PauseCircleIcon,
complete: CheckCircleIcon,
aborted: null,
deleted: null,
pending: null,
failed: null, // XMarkIcon, // Since we show an error message below
};

View file

@ -11,6 +11,7 @@ import {
setInactive,
setSelectedProfileId,
setTTSActive,
updateIndexingStatus,
} from "../redux/slices/stateSlice";
import { RootState } from "../redux/store";
@ -50,14 +51,20 @@ function useSetup(dispatch: Dispatch<any>) {
loadConfig();
const interval = setInterval(() => {
if (initialConfigLoad.current) {
// This triggers sending pending status to the GUI for relevant docs indexes
clearInterval(interval);
ideMessenger.post("indexing/initStatuses", undefined);
return;
}
loadConfig();
}, 2_000);
return () => clearInterval(interval);
}, [initialConfigLoad, loadConfig]);
}, [initialConfigLoad, loadConfig, ideMessenger]);
useWebviewListener("configUpdate", async () => {
await loadConfig();
});
useEffect(() => {
// Override persisted state
@ -110,18 +117,6 @@ function useSetup(dispatch: Dispatch<any>) {
});
});
const debouncedIndexDocs = debounce(() => {
ideMessenger.post("context/indexDocs", { reIndex: false });
}, 1000);
useWebviewListener("configUpdate", async () => {
await loadConfig();
if (!isJetBrains && !getLocalStorage("disableIndexing")) {
debouncedIndexDocs();
}
});
useWebviewListener("configError", async (error) => {
dispatch(setConfigError(error));
});
@ -144,6 +139,10 @@ function useSetup(dispatch: Dispatch<any>) {
);
});
useWebviewListener("indexing/statusUpdate", async (data) => {
dispatch(updateIndexingStatus(data));
});
useWebviewListener(
"getDefaultModelTitle",
async () => {

View file

@ -13,6 +13,7 @@ import { IdeMessengerContext } from "../context/IdeMessenger";
import { selectContextProviderDescriptions } from "../redux/selectors";
import { getLocalStorage } from "../util/localStorage";
import { useWebviewListener } from "./useWebviewListener";
import { RootState } from "../redux/store";
const MINISEARCH_OPTIONS = {
prefix: true,
@ -38,6 +39,8 @@ function useSubmenuContextProviders() {
const [isLoading, setIsLoading] = useState(false);
const [autoLoadTriggered, setAutoLoadTriggered] = useState(false);
const config = useSelector((store: RootState) => store.state.config);
const ideMessenger = useContext(IdeMessengerContext);
const memoizedGetOpenFileItems = useMemo(() => {
@ -213,12 +216,10 @@ function useSubmenuContextProviders() {
const loadSubmenuItems = async () => {
try {
const disableIndexing = getLocalStorage("disableIndexing") ?? false;
await Promise.all(
contextProviderDescriptions.map(async (description) => {
const shouldSkipProvider =
description.dependsOnIndexing && disableIndexing;
description.dependsOnIndexing && config.disableIndexing;
if (shouldSkipProvider) {
console.debug(

View file

@ -72,3 +72,22 @@ a:focus {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
.lines {
/* white-space: pre-wrap; */
word-break: break-word;
overflow: hidden;
line-height: 1.375;
}
.lines-3 {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
.lines-1 {
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}

View file

@ -15,6 +15,7 @@ import { setOnboardingCard } from "../../redux/slices/uiStateSlice";
import useHistory from "../../hooks/useHistory";
import MoreHelpRow from "./MoreHelpRow";
import IndexingProgress from "./IndexingProgress";
import IndexingStatuses from "../../components/indexing/IndexingStatuses";
function MorePage() {
useNavigationListener();
@ -50,6 +51,9 @@ function MorePage() {
</div>
<IndexingProgress />
</div>
<div className="flex flex-col py-5">
<IndexingStatuses />
</div>
<div className="py-5">
<h3 className="mb-4 mt-0 text-xl">Help center</h3>

View file

@ -59,6 +59,7 @@ import {
} from "../../util";
import { FREE_TRIAL_LIMIT_REQUESTS } from "../../util/freeTrial";
import { getLocalStorage, setLocalStorage } from "../../util/localStorage";
import ChatIndexingPeeks from "../../components/indexing/ChatIndexingPeeks";
import { useFindWidget } from "../../components/find/FindWidget";
const StopButton = styled.div`
@ -317,7 +318,7 @@ export function Chat() {
{widget}
<StepsDiv
ref={stepsDivRef}
className={`overflow-y-scroll pt-[8px] ${showScrollbar ? "thin-scrollbar" : "no-scrollbar"} ${state.history.length > 0 ? "h-full" : ""}`}
className={`overflow-y-scroll pt-[8px] ${showScrollbar ? "thin-scrollbar" : "no-scrollbar"} ${state.history.length > 0 ? "flex-1" : ""}`}
onScroll={handleScroll}
>
{highlights}
@ -469,6 +470,11 @@ export function Chat() {
)}
</div>
</div>
<div
className={`${state.history.length === 0 ? "h-full" : ""} flex flex-col justify-end`}
>
<ChatIndexingPeeks />
</div>
</>
);
}

View file

@ -5,6 +5,7 @@ import {
ChatMessage,
Checkpoint,
ContextItemWithId,
IndexingStatus,
PersistedSessionInfo,
PromptLog,
} from "core";
@ -35,6 +36,10 @@ type State = {
curCheckpointIndex: number;
applyStates: ApplyState[];
nextCodeBlockToApplyIndex: number;
indexing: {
hiddenChatPeekTypes: Record<IndexingStatus["type"], boolean>;
statuses: Record<string, IndexingStatus>;
};
streamAborter: AbortController;
isMultifileEdit: boolean;
};
@ -68,6 +73,12 @@ const initialState: State = {
curCheckpointIndex: 0,
nextCodeBlockToApplyIndex: 0,
applyStates: [],
indexing: {
statuses: {},
hiddenChatPeekTypes: {
docs: false,
},
},
streamAborter: new AbortController(),
};
@ -369,6 +380,42 @@ export const stateSlice = createSlice({
resetNextCodeBlockToApplyIndex: (state) => {
state.nextCodeBlockToApplyIndex = 0;
},
updateIndexingStatus: (
state,
{ payload }: PayloadAction<IndexingStatus>,
) => {
state.indexing.statuses = {
...state.indexing.statuses,
[payload.id]: payload,
};
// This check is so that if all indexing is stopped for e.g. docs
// The next time docs indexing starts the peek will show again
const indexingThisType = Object.values(state.indexing.statuses).filter(
(status) =>
status.type === payload.type && status.status === "indexing",
);
if (indexingThisType.length === 0) {
state.indexing.hiddenChatPeekTypes = {
...state.indexing.hiddenChatPeekTypes,
[payload.type]: false,
};
}
},
setIndexingChatPeekHidden: (
state,
{
payload,
}: PayloadAction<{
type: IndexingStatus["type"];
hidden: boolean;
}>,
) => {
state.indexing.hiddenChatPeekTypes = {
...state.indexing.hiddenChatPeekTypes,
[payload.type]: payload.hidden,
};
},
},
});
@ -398,6 +445,8 @@ export const {
setCurCheckpointIndex,
resetNextCodeBlockToApplyIndex,
updateApplyState,
updateIndexingStatus,
setIndexingChatPeekHidden,
abortStream,
} = stateSlice.actions;