autodetect docs v1
This commit is contained in:
parent
48806f3f08
commit
504c0c3843
13 changed files with 396 additions and 261 deletions
|
|
@ -1,5 +1,3 @@
|
|||
import { config } from "dotenv";
|
||||
|
||||
import {
|
||||
BrowserSerializedContinueConfig,
|
||||
ContinueConfig,
|
||||
|
|
|
|||
|
|
@ -527,6 +527,7 @@ function finalToBrowserConfig(
|
|||
embeddingsProvider: final.embeddingsProvider?.id,
|
||||
ui: final.ui,
|
||||
experimental: final.experimental,
|
||||
docs: final.docs,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
2
core/index.d.ts
vendored
2
core/index.d.ts
vendored
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -63,9 +63,10 @@ export async function getAllSuggestedDocs(ide: IDE) {
|
|||
);
|
||||
|
||||
// Parse package files and build map of language -> packages
|
||||
const packagesByRegistry: Record<string, ParsedPackageInfo[]> = {};
|
||||
const packagesByCrawler: Record<string, ParsedPackageInfo[]> = {};
|
||||
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/<package>` 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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import type {
|
|||
DiffLine,
|
||||
FileSymbolMap,
|
||||
IdeSettings,
|
||||
IndexingStatusMap,
|
||||
LLMFullCompletionOptions,
|
||||
MessageContent,
|
||||
ModelDescription,
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<HTMLInputElement>(null);
|
||||
const titleRef = useRef<HTMLInputElement>(null);
|
||||
const urlRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const [title, setTitle] = useState("");
|
||||
const [startUrl, setStartUrl] = useState("");
|
||||
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 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 (
|
||||
// <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>
|
||||
// );
|
||||
// }
|
||||
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 (
|
||||
<div className="p-4">
|
||||
<div className="mb-8">
|
||||
<h1>Add documentation</h1>
|
||||
{docsSuggestions.length ? (
|
||||
<div className="no-scrollbar max-h-[300px] overflow-y-auto">
|
||||
<table className="border-collapse p-0">
|
||||
<thead className="bg-vsc-background sticky -top-1 font-bold">
|
||||
<tr className="">
|
||||
<td className="pr-1">
|
||||
<CodeBracketIcon className="h-3.5 w-3.5" />
|
||||
</td>
|
||||
<td className="pr-1">Title</td>
|
||||
{/* <td className="pr-1">Version</td> */}
|
||||
<td className="pr-1">Start Link</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="p-0">
|
||||
<tr className="whitespace-nowrap">Add docs</tr>
|
||||
{docsSuggestions.map((docsResult) => {
|
||||
const { error, details } = docsResult;
|
||||
const { language, name, version } = docsResult.packageInfo;
|
||||
const id = `${language}-${name}-${version}`;
|
||||
return (
|
||||
<tr key={id} className="p-0">
|
||||
<td>
|
||||
<input type="checkbox"></input>
|
||||
</td>
|
||||
<td>{name}</td>
|
||||
{/* <td>{version}</td> */}
|
||||
<td className="">
|
||||
{error ? (
|
||||
<span className="text-vsc-input-border italic">
|
||||
No docs link found
|
||||
</span>
|
||||
) : (
|
||||
<span className="flex flex-row items-center gap-2">
|
||||
<div>
|
||||
<LinkIcon className="h-2 w-2" />
|
||||
</div>
|
||||
<p className="lines lines-1 m-0 p-0">
|
||||
{details.docsLink}
|
||||
</p>
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
<InformationCircleIcon
|
||||
data-tooltip-id={id}
|
||||
className="text-vsc-foreground-muted h-3.5 w-3.5 cursor-help"
|
||||
/>
|
||||
|
||||
<ToolTip id={id} place="bottom">
|
||||
<p className="m-0 p-0">{`Version: ${version}`}</p>
|
||||
<p className="m-0 p-0">{`Found in ${docsResult.packageInfo.packageFile.path}`}</p>
|
||||
</ToolTip>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : null}
|
||||
<p>
|
||||
Continue pre-indexes many common documentation sites, but if there's
|
||||
one you don't see in the dropdown, enter the URL here.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Continue's indexing engine will crawl the site and generate embeddings
|
||||
so that you can ask questions.
|
||||
</p>
|
||||
</div>
|
||||
{/*
|
||||
<form onSubmit={onSubmit} className="flex flex-col space-y-4">
|
||||
<label>
|
||||
Title
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="Title"
|
||||
value={title}
|
||||
ref={ref}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
/>
|
||||
<HelperText>
|
||||
The title that will be displayed to users in the `@docs` submenu
|
||||
</HelperText>
|
||||
</label>
|
||||
|
||||
<label>
|
||||
Start URL
|
||||
<Input
|
||||
type="url"
|
||||
placeholder="Start URL"
|
||||
value={startUrl}
|
||||
onChange={(e) => {
|
||||
setStartUrl(e.target.value);
|
||||
}}
|
||||
/>
|
||||
<HelperText>
|
||||
The starting location to begin crawling the documentation site
|
||||
</HelperText>
|
||||
</label>
|
||||
|
||||
<div
|
||||
className="cursor-pointer"
|
||||
onClick={() => setIsOpen((prev) => !prev)}
|
||||
>
|
||||
{isOpen ? (
|
||||
<ChevronUpIcon
|
||||
width="1.0em"
|
||||
height="1.0em"
|
||||
style={{ color: lightGray }}
|
||||
></ChevronUpIcon>
|
||||
) : (
|
||||
<ChevronDownIcon
|
||||
width="1.0em"
|
||||
height="1.0em"
|
||||
style={{ color: lightGray }}
|
||||
></ChevronDownIcon>
|
||||
)}
|
||||
<span className="ms-1">Advanced</span>
|
||||
</div>
|
||||
|
||||
{isOpen && (
|
||||
<div className="pt-2">
|
||||
<label>
|
||||
Favicon URL [Optional]
|
||||
<Input
|
||||
type="url"
|
||||
placeholder={`${startUrl}/favicon.ico`}
|
||||
value={faviconUrl}
|
||||
onChange={(e) => {
|
||||
setFaviconUrl(e.target.value);
|
||||
}}
|
||||
/>
|
||||
<HelperText>
|
||||
The URL path to a favicon for the site - by default, it will be
|
||||
`/favicon.ico` path from the Start URL
|
||||
</HelperText>
|
||||
</label>
|
||||
</div>
|
||||
<div className="px-2 py-4 sm:px-4">
|
||||
<div className="">
|
||||
<h1 className="mb-0 hidden sm:block">Add documentation</h1>
|
||||
<h1 className="sm:hidden">Add docs</h1>
|
||||
{sortedDocsSuggestions.length && (
|
||||
<p className="m-0 mb-1 mt-4 p-0 font-semibold">Suggestions</p>
|
||||
)}
|
||||
|
||||
<div className="flex justify-end">
|
||||
<Button disabled={!isFormValid} type="submit">
|
||||
Submit
|
||||
</Button>
|
||||
<div className="border-vsc-foreground-muted max-h-[175px] overflow-y-scroll rounded-sm py-1 pr-2">
|
||||
{sortedDocsSuggestions.map((docsResult) => {
|
||||
const { error, details } = docsResult;
|
||||
const { language, name, version } = docsResult.packageInfo;
|
||||
const id = `${language}-${name}-${version}`;
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
key={id}
|
||||
className="grid cursor-pointer grid-cols-[auto_minmax(0,1fr)_minmax(0,1fr)_auto] items-center px-1 py-1 hover:bg-gray-200/10"
|
||||
onClick={() => {
|
||||
handleSelectSuggestion(docsResult);
|
||||
}}
|
||||
>
|
||||
<div className="pr-1">
|
||||
{error ? (
|
||||
<div>
|
||||
<ExclamationTriangleIcon
|
||||
data-tooltip-id={id + "-error"}
|
||||
className="h-4 w-4 text-red-500"
|
||||
/>
|
||||
<ToolTip id={id + "-error"} place="bottom">
|
||||
Docs URL not found
|
||||
</ToolTip>
|
||||
</div>
|
||||
) : details.docsLinkWarning ? (
|
||||
<div>
|
||||
<ExclamationTriangleIcon
|
||||
data-tooltip-id={id + "-warning"}
|
||||
className="h-4 w-4 text-yellow-600"
|
||||
/>
|
||||
<ToolTip id={id + "-warning"} place="bottom">
|
||||
Start URL might not lead to docs
|
||||
</ToolTip>
|
||||
</div>
|
||||
) : (
|
||||
<PlusCircleIcon className="h-4 w-4 text-green-600" />
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-0.5">
|
||||
<div className="hidden sm:block">
|
||||
<FileIcon
|
||||
filename={`x.${language}`}
|
||||
height="1rem"
|
||||
width="1rem"
|
||||
/>
|
||||
</div>
|
||||
<span className="lines lines-1">{name}</span>
|
||||
</div>
|
||||
<div>
|
||||
{error ? (
|
||||
<span className="text-vsc-input-border italic">
|
||||
No docs link found
|
||||
</span>
|
||||
) : (
|
||||
<div className="flex items-center gap-2">
|
||||
{/* <div>
|
||||
<LinkIcon className="h-2 w-2" />
|
||||
</div> */}
|
||||
<p className="lines lines-1 m-0 p-0">
|
||||
{details.docsLink}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<InformationCircleIcon
|
||||
data-tooltip-id={id + "-info"}
|
||||
className="text-vsc-foreground-muted h-3.5 w-3.5 select-none"
|
||||
/>
|
||||
<ToolTip id={id + "-info"} place="bottom">
|
||||
<p className="m-0 p-0">{`Version: ${version}`}</p>
|
||||
<p className="m-0 p-0">{`Found in ${docsResult.packageInfo.packageFile.path}`}</p>
|
||||
</ToolTip>
|
||||
</div>
|
||||
</div>
|
||||
<ToolTip id={id} place="bottom">
|
||||
{error ? "Add to form" : "Index these docs"}
|
||||
</ToolTip>
|
||||
</>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</form> */}
|
||||
<div className="mt-3">
|
||||
<form onSubmit={onSubmit} className="flex flex-col gap-1">
|
||||
<div className="flex flex-row gap-2">
|
||||
<label className="flex min-w-16 basis-1/4 flex-col gap-1">
|
||||
<div className="flex flex-row items-center gap-1">
|
||||
<span>Title</span>
|
||||
<div>
|
||||
<InformationCircleIcon
|
||||
data-tooltip-id={"add-docs-form-title"}
|
||||
className="text-vsc-foreground-muted h-3.5 w-3.5 select-none"
|
||||
/>
|
||||
<ToolTip id={"add-docs-form-title"} place="top">
|
||||
The title that will be displayed to users in the `@docs`
|
||||
submenu
|
||||
</ToolTip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="Title"
|
||||
value={title}
|
||||
ref={titleRef}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="flex basis-3/4 flex-col gap-1">
|
||||
<div className="flex flex-row items-center gap-1">
|
||||
<span className="lines lines-1 whitespace-nowrap">
|
||||
Start URL
|
||||
</span>
|
||||
<div>
|
||||
<InformationCircleIcon
|
||||
data-tooltip-id={"add-docs-form-url"}
|
||||
className="text-vsc-foreground-muted h-3.5 w-3.5 select-none"
|
||||
/>
|
||||
<ToolTip id={"add-docs-form-url"} place="top">
|
||||
The starting location to begin crawling the documentation
|
||||
site
|
||||
</ToolTip>
|
||||
</div>
|
||||
</div>
|
||||
<Input
|
||||
ref={urlRef}
|
||||
type="url"
|
||||
placeholder="Start URL"
|
||||
value={startUrl}
|
||||
onChange={(e) => {
|
||||
setStartUrl(e.target.value);
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div className="flex flex-row justify-end gap-2">
|
||||
<SecondaryButton className="min-w-16" onClick={closeDialog}>
|
||||
Done
|
||||
</SecondaryButton>
|
||||
<Button
|
||||
className="min-w-16"
|
||||
disabled={!isFormValid}
|
||||
type="submit"
|
||||
>
|
||||
Go
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DocsIndexingPeeks statuses={docsIndexingStatuses} />
|
||||
<div className="flex flex-row items-end justify-between gap-2">
|
||||
<div>
|
||||
{docsIndexingStatuses.length ? (
|
||||
<p className="mt-2 p-0 text-xs text-stone-500">
|
||||
It is safe to close this form while indexing
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ const TextDialog = (props: TextDialogProps) => {
|
|||
return (
|
||||
<ScreenCover onClick={props.onClose} hidden={!props.showDialog}>
|
||||
<DialogContainer
|
||||
className="xs:w-[85%] w-[92%] sm:w-[75%]"
|
||||
className="xs:w-[90%] no-scrollbar max-h-full w-[92%] max-w-[600px] overflow-auto sm:w-[88%] md:w-[80%]"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ function ChatIndexingPeeks() {
|
|||
return (
|
||||
<div className="flex flex-col gap-1">
|
||||
{mergedIndexingStates.map((state) => {
|
||||
return <ChatIndexingPeek state={state} />;
|
||||
return <ChatIndexingPeek key={state.type} state={state} />;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
76
gui/src/components/indexing/DocsIndexingPeeks.tsx
Normal file
76
gui/src/components/indexing/DocsIndexingPeeks.tsx
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { RootState } from "../../redux/store";
|
||||
|
||||
import { IndexingStatus } from "core";
|
||||
import { useMemo } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { ArrowPathIcon, EyeSlashIcon } from "@heroicons/react/24/outline";
|
||||
import {
|
||||
setDialogMessage,
|
||||
setShowDialog,
|
||||
} from "../../redux/slices/uiStateSlice";
|
||||
|
||||
export interface DocsIndexingPeekProps {
|
||||
status: IndexingStatus;
|
||||
}
|
||||
|
||||
function DocsIndexingPeek({ status }: DocsIndexingPeekProps) {
|
||||
const navigate = useNavigate();
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const progressPercentage = useMemo(() => {
|
||||
return Math.min(100, Math.max(0, status.progress * 100));
|
||||
}, [status.progress]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="flex cursor-pointer flex-row items-center gap-2 rounded-md px-1 text-stone-500 hover:bg-gray-700/10"
|
||||
onClick={() => {
|
||||
navigate("/more");
|
||||
dispatch(setShowDialog(false));
|
||||
dispatch(setDialogMessage(undefined));
|
||||
}}
|
||||
>
|
||||
<p className="m-0 p-0 text-stone-500 group-hover:underline">
|
||||
{status.title}
|
||||
</p>
|
||||
<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: `${progressPercentage}%`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="xs:flex hidden flex-row items-center gap-1 text-stone-500">
|
||||
<span className="text-xs no-underline">
|
||||
{progressPercentage.toFixed(0)}%
|
||||
</span>
|
||||
<ArrowPathIcon
|
||||
className={`animate-spin-slow inline-block h-4 w-4 text-stone-500`}
|
||||
></ArrowPathIcon>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface DocsIndexingPeeksProps {
|
||||
statuses: IndexingStatus[];
|
||||
}
|
||||
|
||||
function DocsIndexingPeekList({ statuses }: DocsIndexingPeeksProps) {
|
||||
if (!statuses.length) return null;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col">
|
||||
<p className="mx-0 my-1.5 p-0 text-stone-500">Currently Indexing</p>
|
||||
<div className="max-h-[100px] overflow-y-auto pr-2">
|
||||
{statuses.map((status) => {
|
||||
return <DocsIndexingPeek key={status.id} status={status} />;
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default DocsIndexingPeekList;
|
||||
|
|
@ -8,6 +8,8 @@ import {
|
|||
setShowDialog,
|
||||
} from "../../redux/slices/uiStateSlice";
|
||||
import AddDocsDialog from "../dialogs/AddDocsDialog";
|
||||
import { PlusCircleIcon } from "@heroicons/react/24/outline";
|
||||
import { ToolTip } from "../gui/Tooltip";
|
||||
|
||||
function IndexingStatuses() {
|
||||
const indexingStatuses = useSelector(
|
||||
|
|
@ -25,30 +27,35 @@ function IndexingStatuses() {
|
|||
<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. */}
|
||||
{docsStatuses.length ? (
|
||||
<>
|
||||
<PlusCircleIcon
|
||||
data-tooltip-id={"more-add-docs-button"}
|
||||
className="text-vsc-foreground-muted h-5 w-5 cursor-pointer focus:ring-0"
|
||||
onClick={() => {
|
||||
dispatch(setShowDialog(true));
|
||||
dispatch(setDialogMessage(<AddDocsDialog />));
|
||||
}}
|
||||
/>
|
||||
<ToolTip id={"more-add-docs-button"} place="top">
|
||||
Add Docs
|
||||
</ToolTip>
|
||||
</>
|
||||
) : null}
|
||||
</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) => {
|
||||
<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} />;
|
||||
})
|
||||
: null}
|
||||
<SecondaryButton
|
||||
onClick={() => {
|
||||
dispatch(setShowDialog(true));
|
||||
dispatch(setDialogMessage(<AddDocsDialog />));
|
||||
}}
|
||||
>
|
||||
Add Docs
|
||||
</SecondaryButton>
|
||||
) : (
|
||||
<SecondaryButton>Add Docs</SecondaryButton>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
// </div>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue