unified indexing peeks
This commit is contained in:
parent
906ce64045
commit
416fdbb69f
7 changed files with 178 additions and 197 deletions
|
|
@ -10,6 +10,7 @@ import {
|
|||
IndexingStatusMap,
|
||||
IndexingStatus,
|
||||
SiteIndexingConfig,
|
||||
IdeInfo,
|
||||
} from "../..";
|
||||
import { ConfigHandler } from "../../config/ConfigHandler";
|
||||
import { addContextProvider } from "../../config/util";
|
||||
|
|
@ -101,12 +102,14 @@ export default class DocsService {
|
|||
private sqliteDb?: Database;
|
||||
|
||||
private docsCrawler!: DocsCrawler;
|
||||
private ideInfoPromise: Promise<IdeInfo>;
|
||||
|
||||
constructor(
|
||||
configHandler: ConfigHandler,
|
||||
private readonly ide: IDE,
|
||||
private readonly messenger?: IMessenger<ToCoreProtocol, FromCoreProtocol>,
|
||||
) {
|
||||
this.ideInfoPromise = this.ide.getIdeInfo();
|
||||
this.isInitialized = this.init(configHandler);
|
||||
}
|
||||
|
||||
|
|
@ -135,6 +138,31 @@ export default class DocsService {
|
|||
|
||||
readonly statuses: IndexingStatusMap = new Map();
|
||||
|
||||
// Function for GUI to retrieve initial pending statuses
|
||||
// And kickoff indexing where needed
|
||||
async initStatuses() {
|
||||
this.config?.docs?.forEach(async (doc) => {
|
||||
const currentStatus = this.statuses.get(doc.startUrl);
|
||||
if (currentStatus) {
|
||||
this.handleStatusUpdate(currentStatus);
|
||||
} else {
|
||||
this.handleStatusUpdate({
|
||||
type: "docs",
|
||||
id: doc.startUrl,
|
||||
embeddingsProviderId: this.config.embeddingsProvider.id,
|
||||
isReindexing: false,
|
||||
progress: 0,
|
||||
description: "Pending",
|
||||
status: "pending",
|
||||
title: doc.title,
|
||||
debugInfo: `max depth: ${doc.maxDepth}`,
|
||||
icon: doc.faviconUrl,
|
||||
url: doc.startUrl,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
handleStatusUpdate(update: IndexingStatus) {
|
||||
this.statuses.set(update.id, update);
|
||||
this.messenger?.send("indexing/statusUpdate", update);
|
||||
|
|
@ -143,6 +171,7 @@ export default class DocsService {
|
|||
abort(startUrl: string) {
|
||||
const status = this.statuses.get(startUrl);
|
||||
if (status) {
|
||||
this.docsIndexingQueue.delete(startUrl);
|
||||
this.handleStatusUpdate({
|
||||
...status,
|
||||
status: "aborted",
|
||||
|
|
@ -177,7 +206,7 @@ export default class DocsService {
|
|||
* So, we only include pre-indexed docs in the submenu for non-JetBrains IDEs.
|
||||
*/
|
||||
async canUsePreindexedDocs() {
|
||||
const ideInfo = await this.ide.getIdeInfo();
|
||||
const ideInfo = await this.ideInfoPromise;
|
||||
if (ideInfo.ideType === "jetbrains") {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -322,12 +351,15 @@ export default class DocsService {
|
|||
): Promise<void> {
|
||||
const { startUrl } = siteIndexingConfig;
|
||||
|
||||
// Queue - indexAndAdd is invoked circularly by config edits. This prevents duplicate runs
|
||||
if (this.docsIndexingQueue.has(startUrl)) {
|
||||
console.debug("Already in queue");
|
||||
return;
|
||||
}
|
||||
|
||||
const embeddingsProvider = await this.getEmbeddingsProvider();
|
||||
|
||||
this.docsIndexingQueue.add(startUrl);
|
||||
|
||||
const indexExists = await this.hasMetadata(startUrl);
|
||||
|
||||
const fixedStatus: Pick<
|
||||
|
|
@ -366,8 +398,6 @@ export default class DocsService {
|
|||
}
|
||||
}
|
||||
|
||||
// Mark the site as currently being indexed
|
||||
this.docsIndexingQueue.add(startUrl);
|
||||
try {
|
||||
this.handleStatusUpdate({
|
||||
...fixedStatus,
|
||||
|
|
@ -378,7 +408,7 @@ export default class DocsService {
|
|||
|
||||
const articles: Article[] = [];
|
||||
let processedPages = 0;
|
||||
let estimatedProgress = 0; // progress heuristic = sum series 1/(2^n) from n=1 to pages + 1. Alternative e.g. sum 1/(2^n)
|
||||
let estimatedProgress = 0;
|
||||
|
||||
// Crawl pages and retrieve info as articles
|
||||
for await (const page of this.docsCrawler.crawl(new URL(startUrl))) {
|
||||
|
|
@ -392,7 +422,10 @@ export default class DocsService {
|
|||
...fixedStatus,
|
||||
description: `Finding subpages (${page.path})`,
|
||||
status: "indexing",
|
||||
progress: 0.4 * estimatedProgress, // 0% -> 40%, a heuristic approach for progress calculation
|
||||
progress:
|
||||
0.3 * estimatedProgress +
|
||||
Math.min(0.2, (0.2 * processedPages) / 500),
|
||||
// For the first 50%, 30% is sum of series 1/(2^n) and the other 20% is based on number of files/ 500 max
|
||||
});
|
||||
|
||||
const article = pageToArticle(page);
|
||||
|
|
@ -425,7 +458,7 @@ export default class DocsService {
|
|||
...fixedStatus,
|
||||
status: "indexing",
|
||||
description: `Creating Embeddings: ${article.subpath}`,
|
||||
progress: 0.4 + 0.4 * (i / articles.length), // 40% -> 80%
|
||||
progress: 0.5 + 0.3 * (i / articles.length), // 50% -> 80%
|
||||
});
|
||||
|
||||
try {
|
||||
|
|
@ -466,9 +499,7 @@ export default class DocsService {
|
|||
});
|
||||
|
||||
void this.ide.showToast("info", `Failed to index ${startUrl}`);
|
||||
|
||||
this.docsIndexingQueue.delete(startUrl);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -540,28 +571,34 @@ export default class DocsService {
|
|||
}
|
||||
}
|
||||
|
||||
// Function for GUI to retrieve initial pending statuses
|
||||
// And kickoff indexing where needed
|
||||
async initStatuses() {
|
||||
this.config?.docs?.forEach(async (doc) => {
|
||||
const currentStatus = this.statuses.get(doc.startUrl);
|
||||
if (currentStatus) {
|
||||
this.handleStatusUpdate(currentStatus);
|
||||
} else {
|
||||
this.handleStatusUpdate({
|
||||
type: "docs",
|
||||
id: doc.startUrl,
|
||||
embeddingsProviderId: this.config.embeddingsProvider.id,
|
||||
isReindexing: false,
|
||||
progress: 0,
|
||||
description: "Pending",
|
||||
status: "pending",
|
||||
title: doc.title,
|
||||
debugInfo: `max depth: ${doc.maxDepth}`,
|
||||
icon: doc.faviconUrl,
|
||||
url: doc.startUrl,
|
||||
});
|
||||
}
|
||||
// When user requests a pre-indexed doc for the first time
|
||||
// And pre-indexed embeddings are supported
|
||||
// Fetch pre-indexed embeddings from S3, add to Lance, and then search those
|
||||
private async fetchAndAddPreIndexedDocEmbeddings(title: string) {
|
||||
const embeddingsProvider = await this.getEmbeddingsProvider(true);
|
||||
|
||||
const data = await downloadFromS3(
|
||||
S3Buckets.continueIndexedDocs,
|
||||
getS3Filename(embeddingsProvider.id, title),
|
||||
);
|
||||
|
||||
const siteEmbeddings = JSON.parse(data) as SiteIndexingResults;
|
||||
const startUrl = new URL(siteEmbeddings.url).toString();
|
||||
|
||||
const faviconUrl = preIndexedDocs[startUrl].faviconUrl;
|
||||
const favicon =
|
||||
typeof faviconUrl === "string"
|
||||
? await getFaviconBase64(faviconUrl)
|
||||
: undefined;
|
||||
|
||||
await this.add({
|
||||
favicon,
|
||||
siteIndexingConfig: {
|
||||
startUrl,
|
||||
title: siteEmbeddings.title,
|
||||
},
|
||||
chunks: siteEmbeddings.chunks,
|
||||
embeddings: siteEmbeddings.chunks.map((c) => c.embedding),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -704,7 +741,7 @@ export default class DocsService {
|
|||
const currentlyIndexedDocs = await this.listMetadata();
|
||||
const currentStartUrls = currentlyIndexedDocs.map((doc) => doc.startUrl);
|
||||
|
||||
// Anything found in sqlite but not in new config should be deleted
|
||||
// Anything found in sqlite but not in new config should be deleted if not preindexed
|
||||
const deletedDocs = currentlyIndexedDocs.filter(
|
||||
(doc) =>
|
||||
!preIndexedDocs[doc.startUrl] &&
|
||||
|
|
@ -717,12 +754,12 @@ export default class DocsService {
|
|||
const newDocs: SiteIndexingConfig[] = [];
|
||||
const changedDocs: SiteIndexingConfig[] = [];
|
||||
for (const doc of newConfigDocs) {
|
||||
const oldConfigDoc = oldConfigDocs.find(
|
||||
(d) => d.startUrl === doc.startUrl,
|
||||
);
|
||||
const currentIndexedDoc = currentStartUrls.includes(doc.startUrl);
|
||||
|
||||
if (currentIndexedDoc) {
|
||||
const oldConfigDoc = oldConfigDocs.find(
|
||||
(d) => d.startUrl === doc.startUrl,
|
||||
);
|
||||
if (
|
||||
oldConfigDoc &&
|
||||
(oldConfigDoc.maxDepth !== doc.maxDepth ||
|
||||
|
|
@ -976,37 +1013,6 @@ export default class DocsService {
|
|||
this.messenger?.send("refreshSubmenuItems", undefined);
|
||||
}
|
||||
|
||||
// When user requests a pre-indexed doc for the first time
|
||||
// And pre-indexed embeddings are supported
|
||||
// Fetch pre-indexed embeddings from S3, add to Lance, and then search those
|
||||
private async fetchAndAddPreIndexedDocEmbeddings(title: string) {
|
||||
const embeddingsProvider = await this.getEmbeddingsProvider(true);
|
||||
|
||||
const data = await downloadFromS3(
|
||||
S3Buckets.continueIndexedDocs,
|
||||
getS3Filename(embeddingsProvider.id, title),
|
||||
);
|
||||
|
||||
const siteEmbeddings = JSON.parse(data) as SiteIndexingResults;
|
||||
const startUrl = new URL(siteEmbeddings.url).toString();
|
||||
|
||||
const faviconUrl = preIndexedDocs[startUrl].faviconUrl;
|
||||
const favicon =
|
||||
typeof faviconUrl === "string"
|
||||
? await getFaviconBase64(faviconUrl)
|
||||
: undefined;
|
||||
|
||||
await this.add({
|
||||
favicon,
|
||||
siteIndexingConfig: {
|
||||
startUrl,
|
||||
title: siteEmbeddings.title,
|
||||
},
|
||||
chunks: siteEmbeddings.chunks,
|
||||
embeddings: siteEmbeddings.chunks.map((c) => c.embedding),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently this deletes re-crawls + re-indexes all docs.
|
||||
* A more optimal solution in the future will be to create
|
||||
|
|
|
|||
|
|
@ -9,7 +9,10 @@ import { useContext, useLayoutEffect, useRef, useState } from "react";
|
|||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { Button, HelperText, Input, lightGray } 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";
|
||||
|
||||
|
|
@ -57,8 +60,6 @@ function AddDocsDialog() {
|
|||
setStartUrl("");
|
||||
setFaviconUrl("");
|
||||
|
||||
// dispatch(setShowDialog(false));
|
||||
|
||||
posthog.capture("add_docs_gui", { url: startUrl });
|
||||
}
|
||||
|
||||
|
|
@ -103,6 +104,7 @@ function AddDocsDialog() {
|
|||
<Button
|
||||
className="flex-1"
|
||||
onClick={() => {
|
||||
dispatch(setDialogMessage(undefined));
|
||||
dispatch(setShowDialog(false));
|
||||
}}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -1,74 +1,74 @@
|
|||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { useSelector } from "react-redux";
|
||||
import { RootState } from "../../redux/store";
|
||||
|
||||
import { IndexingStatus } from "core";
|
||||
import { useContext, useMemo, useState } from "react";
|
||||
import { STATUS_TO_ICON } from "./utils";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { XMarkIcon } from "@heroicons/react/24/outline";
|
||||
import { current } from "@reduxjs/toolkit";
|
||||
import { ArrowPathIcon, EyeSlashIcon } from "@heroicons/react/24/outline";
|
||||
|
||||
interface IndexingStatusViewerProps {
|
||||
status: IndexingStatus;
|
||||
interface MergedIndexingState {
|
||||
displayName: string;
|
||||
type: string;
|
||||
titles: IndexingStatus["title"][];
|
||||
progressPercentage: number;
|
||||
}
|
||||
|
||||
function ChatIndexingPeek({ status }: IndexingStatusViewerProps) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
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;
|
||||
hidden: boolean;
|
||||
setHidden: (hidden: boolean) => void;
|
||||
}
|
||||
|
||||
function ChatIndexingPeek({ state, hidden, setHidden }: ChatIndexingPeekProps) {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const progressPercentage = useMemo(() => {
|
||||
return Math.min(100, Math.max(0, status.progress * 100));
|
||||
}, [status.progress]);
|
||||
|
||||
const Icon = STATUS_TO_ICON[status.status];
|
||||
|
||||
if (hidden) return null;
|
||||
return (
|
||||
<div
|
||||
className="flex cursor-pointer flex-row items-center gap-2 hover:opacity-80"
|
||||
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={`flex flex-row items-center gap-2 ${status.url ? "hover:cursor-pointer hover:underline" : ""}`}
|
||||
onClick={(e) => {
|
||||
if (status.url) {
|
||||
ideMessenger.post("openUrl", status.url);
|
||||
e.stopPropagation();
|
||||
}
|
||||
}}
|
||||
>
|
||||
{status.icon ? (
|
||||
<img
|
||||
src={status.icon}
|
||||
alt="icon"
|
||||
className="2xs:block hidden h-4 w-4"
|
||||
<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}%`,
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
<p className="lines lines-1 m-0 max-w-20 p-0 text-left">
|
||||
{status.title ?? status.id}
|
||||
</p>
|
||||
</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>
|
||||
<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">{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>
|
||||
{/* <XMarkIcon className="h-4 w-4 text-stone-500" /> */}
|
||||
<EyeSlashIcon
|
||||
className="ml-2 h-4 w-4 cursor-pointer text-stone-500 hover:opacity-80"
|
||||
onClick={(e) => {
|
||||
setHidden(true);
|
||||
e.stopPropagation();
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -77,23 +77,52 @@ function ChatIndexingPeeks() {
|
|||
const indexingStatuses = useSelector(
|
||||
(store: RootState) => store.state.indexingStatuses,
|
||||
);
|
||||
const [hidden, setHidden] = useState(false);
|
||||
const currentlyIndexingDocs = useMemo(() => {
|
||||
return Object.values(indexingStatuses).filter(
|
||||
(status) => status.status === "indexing",
|
||||
|
||||
const [hidden, setHidden] = useState<{
|
||||
[key: string]: boolean;
|
||||
}>({});
|
||||
|
||||
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),
|
||||
});
|
||||
} else {
|
||||
// So that next indexing will show again if hidden
|
||||
setHidden({
|
||||
...hidden,
|
||||
docs: false,
|
||||
});
|
||||
}
|
||||
return mergedStates;
|
||||
}, [indexingStatuses]);
|
||||
|
||||
if (!currentlyIndexingDocs.length) return null;
|
||||
if (!mergedIndexingStates.length) return null;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-1 px-3 pb-1">
|
||||
{/* <p className="m-0 p-0 text-xs text-stone-500">Indexing in progress</p> */}
|
||||
{hidden
|
||||
? null
|
||||
: currentlyIndexingDocs.map((status) => {
|
||||
return <ChatIndexingPeek status={status} />;
|
||||
})}
|
||||
<div className="flex flex-col gap-1">
|
||||
{mergedIndexingStates.map((state) => {
|
||||
return (
|
||||
<ChatIndexingPeek
|
||||
state={state}
|
||||
hidden={hidden[state.type]}
|
||||
setHidden={() =>
|
||||
setHidden({
|
||||
...hidden,
|
||||
[state.type]: true,
|
||||
})
|
||||
}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import {
|
|||
setShowDialog,
|
||||
} from "../../redux/slices/uiStateSlice";
|
||||
import AddDocsDialog from "../dialogs/AddDocsDialog";
|
||||
import { ChevronUpIcon } from "@heroicons/react/24/outline";
|
||||
|
||||
function IndexingStatuses() {
|
||||
const indexingStatuses = useSelector(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import {
|
|||
ArrowPathIcon,
|
||||
CheckCircleIcon,
|
||||
PauseCircleIcon,
|
||||
XMarkIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { IndexingStatus } from "core";
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ import { getLocalStorage, setLocalStorage } from "../../util/localStorage";
|
|||
import ChatIndexingPeeks from "../../components/indexing/ChatIndexingPeeks";
|
||||
import { useFindWidget } from "../../components/find/FindWidget";
|
||||
|
||||
|
||||
const StopButton = styled.div`
|
||||
background-color: ${vscBackground};
|
||||
width: fit-content;
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ import { JSONContent } from "@tiptap/react";
|
|||
import {
|
||||
ChatHistoryItem,
|
||||
ChatMessage,
|
||||
Checkpoint,
|
||||
ContextItemId,
|
||||
ContextItemWithId,
|
||||
IndexingStatus,
|
||||
PersistedSessionInfo,
|
||||
|
|
@ -14,14 +12,13 @@ import { BrowserSerializedContinueConfig } from "core/config/load";
|
|||
import { ConfigValidationError } from "core/config/validation";
|
||||
import { stripImages } from "core/llm/images";
|
||||
import { v4 as uuidv4, v4 } from "uuid";
|
||||
import { RootState } from "../store";
|
||||
import { ApplyState } from "core/protocol/ideWebview";
|
||||
|
||||
// We need this to handle reorderings (e.g. a mid-array deletion) of the messages array.
|
||||
// The proper fix is adding a UUID to all chat messages, but this is the temp workaround.
|
||||
type ChatHistoryItemWithMessageId = ChatHistoryItem & {
|
||||
message: ChatMessage & { id: string };
|
||||
};
|
||||
|
||||
type State = {
|
||||
history: ChatHistoryItemWithMessageId[];
|
||||
ttsActive: boolean;
|
||||
|
|
@ -34,12 +31,8 @@ type State = {
|
|||
mainEditorContent?: JSONContent;
|
||||
selectedProfileId: string;
|
||||
configError: ConfigValidationError[] | undefined;
|
||||
isInMultifileEdit: boolean;
|
||||
indexingStatuses: { [id: string]: IndexingStatus };
|
||||
checkpoints: Checkpoint[];
|
||||
curCheckpointIndex: number;
|
||||
isMultifileEdit: boolean;
|
||||
applyStates: ApplyState[];
|
||||
nextCodeBlockToApplyIndex: number;
|
||||
};
|
||||
|
||||
const initialState: State = {
|
||||
|
|
@ -66,12 +59,8 @@ const initialState: State = {
|
|||
sessionId: v4(),
|
||||
defaultModelTitle: "GPT-4",
|
||||
selectedProfileId: "local",
|
||||
isInMultifileEdit: false,
|
||||
indexingStatuses: {},
|
||||
checkpoints: [],
|
||||
isMultifileEdit: false,
|
||||
curCheckpointIndex: 0,
|
||||
nextCodeBlockToApplyIndex: 0,
|
||||
applyStates: [],
|
||||
};
|
||||
|
||||
export const stateSlice = createSlice({
|
||||
|
|
@ -198,7 +187,6 @@ export const stateSlice = createSlice({
|
|||
});
|
||||
|
||||
state.active = true;
|
||||
state.curCheckpointIndex = state.curCheckpointIndex + 1;
|
||||
},
|
||||
setMessageAtIndex: (
|
||||
state,
|
||||
|
|
@ -265,15 +253,12 @@ export const stateSlice = createSlice({
|
|||
state.history = payload.history as any;
|
||||
state.title = payload.title;
|
||||
state.sessionId = payload.sessionId;
|
||||
state.checkpoints = payload.checkpoints;
|
||||
state.curCheckpointIndex = 0;
|
||||
} else {
|
||||
state.history = [];
|
||||
state.active = false;
|
||||
state.title = "New Session";
|
||||
state.sessionId = v4();
|
||||
state.checkpoints = [];
|
||||
state.curCheckpointIndex = 0;
|
||||
state.isInMultifileEdit = false;
|
||||
}
|
||||
},
|
||||
addHighlightedCode: (
|
||||
|
|
@ -326,42 +311,8 @@ export const stateSlice = createSlice({
|
|||
selectedProfileId: payload,
|
||||
};
|
||||
},
|
||||
|
||||
setIsInMultifileEdit: (state, { payload }: PayloadAction<boolean>) => {
|
||||
state.isMultifileEdit = payload;
|
||||
},
|
||||
setCurCheckpointIndex: (state, { payload }: PayloadAction<number>) => {
|
||||
state.curCheckpointIndex = payload;
|
||||
},
|
||||
updateCurCheckpoint: (
|
||||
state,
|
||||
{ payload }: PayloadAction<{ filepath: string; content: string }>,
|
||||
) => {
|
||||
state.checkpoints[state.curCheckpointIndex] = {
|
||||
...state.checkpoints[state.curCheckpointIndex],
|
||||
[payload.filepath]: payload.content,
|
||||
};
|
||||
},
|
||||
updateApplyState: (state, { payload }: PayloadAction<ApplyState>) => {
|
||||
const index = state.applyStates.findIndex(
|
||||
(applyState) => applyState.streamId === payload.streamId,
|
||||
);
|
||||
|
||||
const curApplyState = state.applyStates[index];
|
||||
|
||||
if (index === -1) {
|
||||
state.applyStates.push(payload);
|
||||
} else {
|
||||
curApplyState.status = payload.status ?? curApplyState.status;
|
||||
curApplyState.numDiffs = payload.numDiffs ?? curApplyState.numDiffs;
|
||||
curApplyState.filepath = payload.filepath ?? curApplyState.filepath;
|
||||
}
|
||||
if(payload.status === "done"){
|
||||
state.nextCodeBlockToApplyIndex++;
|
||||
}
|
||||
},
|
||||
resetNextCodeBlockToApplyIndex: (state) => {
|
||||
state.nextCodeBlockToApplyIndex = 0;
|
||||
setIsInMultifileEdit: (state, action: PayloadAction<boolean>) => {
|
||||
state.isInMultifileEdit = action.payload;
|
||||
},
|
||||
updateIndexingStatus: (state, action: PayloadAction<IndexingStatus>) => {
|
||||
console.log("update indexing status");
|
||||
|
|
@ -398,10 +349,6 @@ export const {
|
|||
setIsGatheringContext,
|
||||
setIsInMultifileEdit,
|
||||
updateIndexingStatus,
|
||||
updateCurCheckpoint,
|
||||
setCurCheckpointIndex,
|
||||
resetNextCodeBlockToApplyIndex,
|
||||
updateApplyState,
|
||||
} = stateSlice.actions;
|
||||
|
||||
export default stateSlice.reducer;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue