Merge pull request #3661 from continuedev/dallin/docsapalooza

Get Docs Details
This commit is contained in:
Nate Sesti 2025-01-27 17:21:53 -08:00 • committed by GitHub
commit ce2bfeda26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 328 additions and 52 deletions

View file

@ -20,6 +20,10 @@ class DocsContextProvider extends BaseContextProvider {
displayTitle: "Docs",
description: "Type to search docs",
type: "submenu",
// Todo: consider a different renderInline so that when multiple docs are referenced in one message,
// Or the doc has an odd name unrelated to the content
// The name of the doc itself doesn't skew the embedding results
// renderInlineAs: "<docs-context-provider>",
};
constructor(options: any) {
@ -82,6 +86,7 @@ class DocsContextProvider extends BaseContextProvider {
query: string,
extras: ContextProviderExtras,
): Promise<ContextItem[]> {
const nRetrieve = this.options?.nRetrieve ?? DocsContextProvider.nRetrieve;
const useReranking = this.options?.useReranking ?? true;
// Get docs service
@ -96,7 +101,7 @@ class DocsContextProvider extends BaseContextProvider {
let chunks = await docsService.retrieveChunksFromQuery(
extras.fullInput, // confusing: fullInput = the query, query = startUrl in this case
query,
this.options?.nRetrieve ?? DocsContextProvider.nRetrieve,
nRetrieve,
);
if (!chunks?.length) {
return [];

View file

@ -863,6 +863,9 @@ export class Core {
on("docs/initStatuses", async (msg) => {
void this.docsService.initStatuses();
});
on("docs/getDetails", async (msg) => {
return await this.docsService.getDetails(msg.data.startUrl);
});
//
on("didChangeSelectedProfile", (msg) => {

8
core/index.d.ts vendored
View file

@ -229,6 +229,14 @@ export interface SiteIndexingConfig {
rootUrl?: string; // Currently only used by preindexed docs
}
export interface DocsIndexingDetails {
startUrl: string;
config: SiteIndexingConfig;
indexingStatus: IndexingStatus | undefined;
chunks: Chunk[];
isPreIndexedDoc: boolean;
}
export interface IContextProvider {
get description(): ContextProviderDescription;

View file

@ -5,6 +5,7 @@ import lancedb, { Connection } from "vectordb";
import {
Chunk,
ContinueConfig,
DocsIndexingDetails,
IDE,
IdeInfo,
ILLM,
@ -31,7 +32,6 @@ import {
markdownPageToArticleWithChunks,
} from "./article";
import DocsCrawler, { DocsCrawlerType, PageData } from "./crawlers/DocsCrawler";
import { ConfigResult } from "@continuedev/config-yaml";
import { runLanceMigrations, runSqliteMigrations } from "./migrations";
import {
downloadFromS3,
@ -40,6 +40,7 @@ import {
SiteIndexingResults,
} from "./preIndexed";
import preIndexedDocs from "./preIndexedDocs";
import { ConfigResult } from "@continuedev/config-yaml";
// Purposefully lowercase because lancedb converts
export interface LanceDbDocsRow {
@ -327,7 +328,7 @@ export default class DocsService {
}
// Returns true if startUrl has been indexed with current embeddingsProvider
async hasMetadata(startUrl: string): Promise<Promise<boolean>> {
async hasMetadata(startUrl: string): Promise<boolean> {
const db = await this.getOrCreateSqliteDb();
const title = await db.get(
`SELECT title FROM ${DocsService.sqlitebTableName} WHERE startUrl = ? AND embeddingsProviderId = ?`,
@ -695,6 +696,64 @@ export default class DocsService {
return await this.retrieveChunks(startUrl, vector, nRetrieve, isPreindexed);
}
private lanceDBRowToChunk(row: LanceDbDocsRow): Chunk {
return {
digest: row.path,
filepath: row.path,
startLine: row.startline,
endLine: row.endline,
index: 0,
content: row.content,
otherMetadata: {
title: row.title,
},
};
}
async getDetails(startUrl: string): Promise<DocsIndexingDetails> {
const db = await this.getOrCreateSqliteDb();
try {
const { isPreindexed, provider } =
await this.getEmbeddingsProvider(startUrl);
const preIndexedDoc = preIndexedDocs[startUrl];
const isPreIndexedDoc = !!preIndexedDoc;
const result = await db.get(
`SELECT startUrl, title, favicon FROM ${DocsService.sqlitebTableName} WHERE startUrl = ? AND embeddingsProviderId = ?`,
startUrl,
provider.embeddingId,
);
if (!result) {
throw new Error(`${startUrl} not found in sqlite`);
}
const siteIndexingConfig: SiteIndexingConfig = {
startUrl,
faviconUrl: result.favicon,
title: result.title,
};
const table = await this.getOrCreateLanceTable({
initializationVector: [],
startUrl,
});
const rows = (await table
.filter(`starturl = '${startUrl}'`)
.limit(1000)
.execute()) as LanceDbDocsRow[];
return {
startUrl,
config: siteIndexingConfig,
indexingStatus: this.statuses.get(startUrl),
chunks: rows.map(this.lanceDBRowToChunk),
isPreIndexedDoc,
};
} catch (e) {
console.warn("Error getting details", e);
throw e;
}
}
// This is split into its own function so that it can be recursive
// in the case of fetching preindexed docs from s3
async retrieveChunks(
@ -732,17 +791,7 @@ export default class DocsService {
return await this.retrieveChunks(startUrl, vector, nRetrieve, true, true);
}
return docs.map((doc) => ({
digest: doc.path,
filepath: doc.path,
startLine: doc.startline,
endLine: doc.endline,
index: 0,
content: doc.content,
otherMetadata: {
title: doc.title,
},
}));
return docs.map(this.lanceDBRowToChunk);
}
// SQLITE DB
@ -798,7 +847,7 @@ export default class DocsService {
private async syncDocs(
oldConfig: ContinueConfig | undefined,
newConfig: ContinueConfig,
reindex: boolean,
forceReindex: boolean,
) {
try {
this.isSyncing = true;
@ -838,20 +887,25 @@ export default class DocsService {
) {
changedDocs.push(doc);
} else {
// if get's here, not changed, no update needed, mark as complete
this.handleStatusUpdate({
type: "docs",
id: doc.startUrl,
embeddingsProviderId: this.config.embeddingsProvider.embeddingId,
isReindexing: false,
title: doc.title,
debugInfo: "Config sync: not changed",
icon: doc.faviconUrl,
url: doc.startUrl,
progress: 1,
description: "Complete",
status: "complete",
});
if (forceReindex) {
changedDocs.push(doc);
} else {
// if get's here, not changed, no update needed, mark as complete
this.handleStatusUpdate({
type: "docs",
id: doc.startUrl,
embeddingsProviderId:
this.config.embeddingsProvider.embeddingId,
isReindexing: false,
title: doc.title,
debugInfo: "Config sync: not changed",
icon: doc.faviconUrl,
url: doc.startUrl,
progress: 1,
description: "Complete",
status: "complete",
});
}
}
} else {
const currentStatus = this.statuses.get(doc.startUrl);

View file

@ -7,6 +7,7 @@ import type {
ContextProviderWithParams,
ContextSubmenuItem,
DiffLine,
DocsIndexingDetails,
FileSymbolMap,
IdeSettings,
LLMFullCompletionOptions,
@ -180,7 +181,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
"indexing/setPaused": [{ type: string; id: string; paused: boolean }, void];
"docs/getSuggestedDocs": [undefined, void];
"docs/initStatuses": [undefined, void];
"docs/getDetails": [{ startUrl: string }, DocsIndexingDetails];
addAutocompleteModel: [{ model: ModelDescription }, void];
"profiles/switch": [{ id: string }, undefined];

View file

@ -52,6 +52,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
"indexing/setPaused",
"docs/getSuggestedDocs",
"docs/initStatuses",
"docs/getDetails",
//
"completeOnboarding",
"addAutocompleteModel",

View file

@ -0,0 +1,176 @@
import {
CheckIcon,
InformationCircleIcon,
PencilIcon,
PlusIcon,
} from "@heroicons/react/24/outline";
import {
DocsIndexingDetails,
IndexingStatus,
PackageDocsResult,
SiteIndexingConfig,
} from "core";
import preIndexedDocs from "core/indexing/docs/preIndexedDocs";
import { usePostHog } from "posthog-js/react";
import {
useCallback,
useContext,
useEffect,
useLayoutEffect,
useMemo,
useRef,
useState,
} from "react";
import { useDispatch } from "react-redux";
import { Input, SecondaryButton } from "..";
import { IdeMessengerContext } from "../../context/IdeMessenger";
import { useAppSelector } from "../../redux/hooks";
import { updateConfig } from "../../redux/slices/configSlice";
import { updateIndexingStatus } from "../../redux/slices/indexingSlice";
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
import FileIcon from "../FileIcon";
import { ToolTip } from "../gui/Tooltip";
import DocsIndexingPeeks from "../indexing/DocsIndexingPeeks";
import { Tooltip } from "react-tooltip";
interface DocsDetailsDialogProps {
startUrl: string;
}
function DocsDetailsDialog({ startUrl }: DocsDetailsDialogProps) {
const config = useAppSelector((store) => store.config.config);
const posthog = usePostHog();
const dispatch = useDispatch();
const ideMessenger = useContext(IdeMessengerContext);
const closeDialog = () => {
dispatch(setShowDialog(false));
dispatch(setDialogMessage(undefined));
};
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(false);
const [data, setData] = useState<DocsIndexingDetails | undefined>(undefined);
const fetchData = useCallback(async () => {
setIsLoading(true);
setIsError(false);
try {
const response = await ideMessenger.request("docs/getDetails", {
startUrl,
});
if (response.status === "error") {
throw new Error(response.error);
}
setData(response.content);
} catch (error) {
setIsError(true);
} finally {
setIsLoading(false);
}
}, []);
useEffect(() => {
fetchData();
}, []);
let comp = <div>Loading...</div>;
if (!isLoading) {
if (isError) {
comp = (
<div>
<div>Error fetching docs details</div>
<SecondaryButton onClick={fetchData}>Try again</SecondaryButton>
</div>
);
}
if (data) {
comp = (
<div className="flex flex-col gap-0.5">
<p className="m-0 mt-2 p-0 text-stone-500">{`Title: ${data.config.title}`}</p>
<p className="m-0 p-0 text-stone-500">{`Pre-indexed doc: ${data.isPreIndexedDoc}`}</p>
{!data.chunks?.length ? (
<div>No article chunks</div>
) : (
<div className="relative mt-2 h-[300px] overflow-auto">
<table className="w-full border-collapse">
<thead className="bg-vsc-background sticky top-0 text-left">
<tr>
<th className="py-1">Filepath</th>
<th>Content</th>
</tr>
</thead>
<tbody className="h-20 overflow-y-scroll">
{data.chunks.map((chunk, i) => {
const contentToolTipId = `docs-content-peek-${i}`;
const urlToolTipId = `docs-url-peek-${i}`;
return (
<>
<tr key={i} className="">
<td
className="cursor-pointer px-1"
data-tooltip-id={urlToolTipId}
data-tooltip-delay-show={500}
>
<span className="truncate-start max-w-[200px]">
{chunk.filepath}
</span>
</td>
<td
className="cursor-pointer px-1"
data-tooltip-id={contentToolTipId}
data-tooltip-delay-show={500}
>
<span className="lines lines-1">
{chunk.content}
</span>
</td>
</tr>
<Tooltip
id={urlToolTipId}
place="top"
className="max-w-full"
>
{chunk.filepath}
</Tooltip>
<Tooltip
id={contentToolTipId}
place="top"
className="max-h-[300px] max-w-[170px] overflow-y-auto"
>
{chunk.content}
</Tooltip>
</>
);
})}
</tbody>
</table>
</div>
)}
</div>
);
}
}
return (
<div className="px-2 py-4 sm:px-4">
<h3>Docs index</h3>
<p
className="m-0 mt-1 cursor-pointer p-0 text-stone-500 hover:underline"
onClick={(e) => {
e.stopPropagation();
ideMessenger.post("openUrl", startUrl);
}}
>
{startUrl}
</p>
{comp}
<div className="flex flex-row justify-end">
<SecondaryButton onClick={closeDialog}>Close</SecondaryButton>
</div>
</div>
);
}
export default DocsDetailsDialog;

View file

@ -6,6 +6,7 @@ import {
ArrowTopRightOnSquareIcon,
CheckCircleIcon,
ExclamationTriangleIcon,
EyeIcon,
PauseCircleIcon,
TrashIcon,
} from "@heroicons/react/24/outline";
@ -13,6 +14,7 @@ import { useAppDispatch, useAppSelector } from "../../redux/hooks";
import { updateIndexingStatus } from "../../redux/slices/indexingSlice";
import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
import ConfirmationDialog from "../dialogs/ConfirmationDialog";
import DocsDetailsDialog from "./DocsDetailsDialog";
interface IndexingStatusViewerProps {
docConfig: SiteIndexingConfig;
@ -175,24 +177,40 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) {
pending: "",
}[status?.status]}
</span>
{status?.description === "Github rate limit exceeded" ? (
<span
className="lines lines-1 cursor-pointer text-right text-xs text-stone-500 underline"
onClick={() =>
ideMessenger.post(
"openUrl",
"https://docs.continue.dev/customize/deep-dives/docs#github",
)
}
>
{status.description}
</span>
) : (
<span className="lines lines-1 text-right text-xs text-stone-500">
{status?.description}
</span>
)}
<div className="flex flex-row items-center gap-1">
{status?.description === "Github rate limit exceeded" ? (
<span
className="lines lines-1 cursor-pointer text-right text-xs text-stone-500 underline"
onClick={() =>
ideMessenger.post(
"openUrl",
"https://docs.continue.dev/customize/deep-dives/docs#github",
)
}
>
{status.description}
</span>
) : (
<span className="lines lines-1 text-right text-xs text-stone-500">
{status?.description}
</span>
)}
{status?.status === "complete" ? (
<EyeIcon
className="h-4 w-4 cursor-pointer text-stone-500"
onClick={() => {
dispatch(setShowDialog(true));
dispatch(
setDialogMessage(
<DocsDetailsDialog startUrl={docConfig.startUrl} />,
),
);
}}
>
Add Docs
</EyeIcon>
) : null}
</div>
</div>
</div>
);

View file

@ -89,7 +89,7 @@ export const AddCodeToEdit = Node.create<MentionOptions>({
default: null,
parseHTML: (element) => element.getAttribute("data-renderInlineAs"),
renderHTML: (attributes) => {
if (!attributes.renderInlineAs) {
if (typeof attributes.renderInlineAs !== "string") {
return {};
}

View file

@ -116,7 +116,7 @@ export const Mention = Node.create<MentionOptions>({
default: null,
parseHTML: (element) => element.getAttribute("data-renderInlineAs"),
renderHTML: (attributes) => {
if (!attributes.renderInlineAs) {
if (typeof attributes.renderInlineAs !== "string") {
return {};
}

View file

@ -53,7 +53,6 @@ async function resolveEditorContent({
for (const p of editorState.content) {
if (p.type === "paragraph") {
const [text, ctxItems, foundSlashCommand] = resolveParagraph(p);
// Only take the first slash command\
if (foundSlashCommand && typeof slashCommand === "undefined") {
slashCommand = foundSlashCommand;
@ -240,7 +239,7 @@ function resolveParagraph(
export function hasSlashCommandOrContextProvider(
editorState: JSONContent,
): boolean {
if (!editorState.content) {
if (!editorState?.content) {
return false;
}

View file

@ -92,3 +92,13 @@ body {
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
}
.truncate-start {
display: inline-block;
vertical-align: middle;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
direction: rtl;
width: 100%;
}

View file

@ -36,6 +36,7 @@ const saveSubsetFilters = [
createFilter("editModeState", []),
createFilter("config", ["defaultModelTitle"]),
createFilter("ui", ["toolSettings", "useTools"]),
createFilter("indexing", []),
];
const migrations: MigrationManifest = {