redux audit
This commit is contained in:
parent
2c597764ca
commit
3d5d4569a7
20 changed files with 454 additions and 426 deletions
6
extensions/vscode/package-lock.json
generated
6
extensions/vscode/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "0.9.232",
|
||||
"version": "0.9.233",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "0.9.232",
|
||||
"version": "0.9.233",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@electron/rebuild": "^3.2.10",
|
||||
|
|
@ -109,7 +109,7 @@
|
|||
"cheerio": "^1.0.0-rc.12",
|
||||
"commander": "^12.0.0",
|
||||
"comment-json": "^4.2.3",
|
||||
"dbinfoz": "^0.11.0",
|
||||
"dbinfoz": "^0.14.0",
|
||||
"diff": "^7.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"fastest-levenshtein": "^1.0.16",
|
||||
|
|
|
|||
8
gui/package-lock.json
generated
8
gui/package-lock.json
generated
|
|
@ -56,7 +56,6 @@
|
|||
"socket.io-client": "^4.7.2",
|
||||
"styled-components": "^5.3.6",
|
||||
"table": "^6.8.1",
|
||||
"tailwind-scrollbar-hide": "^1.1.7",
|
||||
"tippy.js": "^6.3.7",
|
||||
"unist-util-visit": "^5.0.0",
|
||||
"uuid": "^9.0.1",
|
||||
|
|
@ -112,7 +111,7 @@
|
|||
"cheerio": "^1.0.0-rc.12",
|
||||
"commander": "^12.0.0",
|
||||
"comment-json": "^4.2.3",
|
||||
"dbinfoz": "^0.11.0",
|
||||
"dbinfoz": "^0.14.0",
|
||||
"diff": "^7.0.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"fastest-levenshtein": "^1.0.16",
|
||||
|
|
@ -8984,11 +8983,6 @@
|
|||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tailwind-scrollbar-hide": {
|
||||
"version": "1.1.7",
|
||||
"resolved": "https://registry.npmjs.org/tailwind-scrollbar-hide/-/tailwind-scrollbar-hide-1.1.7.tgz",
|
||||
"integrity": "sha512-X324n9OtpTmOMqEgDUEA/RgLrNfBF/jwJdctaPZDzB3mppxJk7TLIDmOreEDm1Bq4R9LSPu4Epf8VSdovNU+iA=="
|
||||
},
|
||||
"node_modules/tailwindcss": {
|
||||
"version": "3.4.12",
|
||||
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.12.tgz",
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
import { useDispatch } from "react-redux";
|
||||
import { RouterProvider, createMemoryRouter } from "react-router-dom";
|
||||
import Layout from "./components/Layout";
|
||||
import { SubmenuContextProvidersContext } from "./context/SubmenuContextProviders";
|
||||
import { VscThemeContext } from "./context/VscTheme";
|
||||
import { VscThemeProvider } from "./context/VscTheme";
|
||||
import useSetup from "./hooks/useSetup";
|
||||
import useSubmenuContextProviders from "./hooks/useSubmenuContextProviders";
|
||||
import { useVscTheme } from "./hooks/useVscTheme";
|
||||
import { AddNewModel, ConfigureProvider } from "./pages/AddNewModel";
|
||||
import ConfigErrorPage from "./pages/config-error";
|
||||
import Edit from "./pages/Edit";
|
||||
|
|
@ -18,6 +15,7 @@ import MorePage from "./pages/More";
|
|||
import SettingsPage from "./pages/settings";
|
||||
import Stats from "./pages/stats";
|
||||
import { ROUTES } from "./util/navigation";
|
||||
import { SubmenuContextProvidersProvider } from "./context/SubmenuContextProviders";
|
||||
|
||||
const router = createMemoryRouter([
|
||||
{
|
||||
|
|
@ -77,22 +75,25 @@ const router = createMemoryRouter([
|
|||
},
|
||||
]);
|
||||
|
||||
function App() {
|
||||
/*
|
||||
Prevents entire app from rerendering continuously with useSetup in App
|
||||
TODO - look into a more redux-esque way to do this
|
||||
*/
|
||||
function SetupListeners() {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useSetup(dispatch);
|
||||
return <></>;
|
||||
}
|
||||
|
||||
const vscTheme = useVscTheme();
|
||||
const submenuContextProvidersMethods = useSubmenuContextProviders();
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<VscThemeContext.Provider value={vscTheme}>
|
||||
<SubmenuContextProvidersContext.Provider
|
||||
value={submenuContextProvidersMethods}
|
||||
>
|
||||
<VscThemeProvider>
|
||||
<SubmenuContextProvidersProvider>
|
||||
<RouterProvider router={router} />
|
||||
</SubmenuContextProvidersContext.Provider>
|
||||
</VscThemeContext.Provider>
|
||||
</SubmenuContextProvidersProvider>
|
||||
<SetupListeners />
|
||||
</VscThemeProvider>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,11 @@ import { useDispatch, useSelector } from "react-redux";
|
|||
import styled, { keyframes } from "styled-components";
|
||||
import { defaultBorderRadius, vscBackground } from "..";
|
||||
import { useWebviewListener } from "../../hooks/useWebviewListener";
|
||||
import { selectSlashCommands } from "../../redux/selectors";
|
||||
import { selectSlashCommandComboBoxInputs } from "../../redux/selectors";
|
||||
import { newSession, setMessageAtIndex } from "../../redux/slices/stateSlice";
|
||||
import { RootState } from "../../redux/store";
|
||||
import ContextItemsPeek from "./ContextItemsPeek";
|
||||
import TipTapEditor from "./TipTapEditor";
|
||||
|
||||
interface ContinueInputBoxProps {
|
||||
isLastUserInput: boolean;
|
||||
isMainInput?: boolean;
|
||||
|
|
@ -64,7 +63,7 @@ function ContinueInputBox(props: ContinueInputBoxProps) {
|
|||
const dispatch = useDispatch();
|
||||
|
||||
const active = useSelector((store: RootState) => store.state.active);
|
||||
const availableSlashCommands = useSelector(selectSlashCommands);
|
||||
const availableSlashCommands = useSelector(selectSlashCommandComboBoxInputs);
|
||||
const availableContextProviders = useSelector(
|
||||
(store: RootState) => store.state.config.contextProviders,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import {
|
|||
vscInputBorderFocus,
|
||||
} from "..";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { SubmenuContextProvidersContext } from "../../context/SubmenuContextProviders";
|
||||
import { useSubmenuContextProviders } from "../../context/SubmenuContextProviders";
|
||||
import useHistory from "../../hooks/useHistory";
|
||||
import { useInputHistory } from "../../hooks/useInputHistory";
|
||||
import useUpdatingRef from "../../hooks/useUpdatingRef";
|
||||
|
|
@ -168,7 +168,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
const dispatch = useDispatch();
|
||||
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const { getSubmenuContextItems } = useContext(SubmenuContextProvidersContext);
|
||||
const { getSubmenuContextItems } = useSubmenuContextProviders();
|
||||
|
||||
const historyLength = useSelector(
|
||||
(store: RootState) => store.state.history.length,
|
||||
|
|
@ -598,7 +598,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
|
||||
if (isOSREnabled) {
|
||||
handleJetBrainsOSRMetaKeyIssues(e, editor);
|
||||
} else if (!isJetBrains()){
|
||||
} else if (!isJetBrains()) {
|
||||
await handleVSCMetaKeyIssues(e, editor);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { ChevronDownIcon } from "@heroicons/react/24/outline";
|
||||
import { debounce } from "lodash";
|
||||
import { useContext, useEffect, useRef, useState } from "react";
|
||||
import { useContext, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import styled, { css, keyframes } from "styled-components";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
|
@ -80,11 +80,12 @@ export default function StepContainerPreToolbar(
|
|||
(state: RootState) => state.state.nextCodeBlockToApplyIndex,
|
||||
);
|
||||
|
||||
const applyState = useSelector((store: RootState) =>
|
||||
store.state.applyStates.find(
|
||||
(state) => state.streamId === streamIdRef.current,
|
||||
),
|
||||
const applyStates = useSelector(
|
||||
(store: RootState) => store.state.applyStates,
|
||||
);
|
||||
const applyState = useMemo(() => {
|
||||
return applyStates.find((state) => state.streamId === streamIdRef.current);
|
||||
}, [applyStates, streamIdRef]);
|
||||
|
||||
// This handles an edge case when the last node in the markdown syntax tree is a codeblock.
|
||||
// In this scenario, `isGeneratingCodeBlock` is never set to false since we determine if
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { RootState } from "../../redux/store";
|
|||
import { ContextItemWithId, SymbolWithRange } from "core";
|
||||
import SymbolLink from "./SymbolLink";
|
||||
import { useSelector } from "react-redux";
|
||||
import useUpdatingRef from "../../hooks/useUpdatingRef";
|
||||
|
||||
const StyledMarkdown = styled.div<{
|
||||
fontSize?: number;
|
||||
|
|
@ -155,21 +156,17 @@ function processCodeBlocks(tree: any) {
|
|||
const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
|
||||
props: StyledMarkdownPreviewProps,
|
||||
) {
|
||||
// The refs are a workaround because rehype options are stored on initiation
|
||||
// So they won't use the most up-to-date state values
|
||||
// So in this case we just put them in refs
|
||||
const contextItems = useSelector(
|
||||
(state: RootState) =>
|
||||
state.state.history[props.itemIndex - 1]?.contextItems,
|
||||
);
|
||||
const contextItemsRef = useUpdatingRef(contextItems);
|
||||
|
||||
const symbols = useSelector((state: RootState) => state.state.symbols);
|
||||
|
||||
// The refs are a workaround because rehype options are stored on initiation
|
||||
// So they won't use the most up-to-date state values
|
||||
// So in this case we just put them in refs
|
||||
const symbolsRef = useRef<SymbolWithRange[]>([]);
|
||||
const contextItemsRef = useRef<ContextItemWithId[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
contextItemsRef.current = contextItems || [];
|
||||
}, [contextItems]);
|
||||
useEffect(() => {
|
||||
// Note, before I was only looking for symbols that matched
|
||||
// Context item files on current history item
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
import { ContextSubmenuItem } from "core";
|
||||
import { createContext } from "react";
|
||||
|
||||
export const SubmenuContextProvidersContext = createContext<{
|
||||
getSubmenuContextItems: (
|
||||
providerTitle: string | undefined,
|
||||
query: string,
|
||||
) => (ContextSubmenuItem & { providerTitle: string })[];
|
||||
addItem: (providerTitle: string, item: ContextSubmenuItem) => void;
|
||||
}>({
|
||||
getSubmenuContextItems: () => [],
|
||||
addItem: () => {},
|
||||
});
|
||||
322
gui/src/context/SubmenuContextProviders.tsx
Normal file
322
gui/src/context/SubmenuContextProviders.tsx
Normal file
|
|
@ -0,0 +1,322 @@
|
|||
import { ContextSubmenuItem } from "core";
|
||||
import { createContext } from "react";
|
||||
import {
|
||||
deduplicateArray,
|
||||
getBasename,
|
||||
getUniqueFilePath,
|
||||
groupByLastNPathParts,
|
||||
} from "core/util";
|
||||
import MiniSearch, { SearchResult } from "minisearch";
|
||||
import { useCallback, useContext, useEffect, useMemo, useState } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { IdeMessengerContext } from "./IdeMessenger";
|
||||
import { selectContextProviderDescriptions } from "../redux/selectors";
|
||||
import { RootState } from "../redux/store";
|
||||
import { useWebviewListener } from "../hooks/useWebviewListener";
|
||||
|
||||
const MINISEARCH_OPTIONS = {
|
||||
prefix: true,
|
||||
fuzzy: 2,
|
||||
};
|
||||
|
||||
const MAX_LENGTH = 70;
|
||||
|
||||
interface SubtextContextProvidersContextType {
|
||||
getSubmenuContextItems: (
|
||||
providerTitle: string | undefined,
|
||||
query: string,
|
||||
) => (ContextSubmenuItem & { providerTitle: string })[];
|
||||
addItem: (providerTitle: string, item: ContextSubmenuItem) => void;
|
||||
}
|
||||
|
||||
const initialContextProviders: SubtextContextProvidersContextType = {
|
||||
getSubmenuContextItems: () => [],
|
||||
addItem: () => {},
|
||||
};
|
||||
|
||||
const SubmenuContextProvidersContext =
|
||||
createContext<SubtextContextProvidersContextType>(initialContextProviders);
|
||||
|
||||
export const SubmenuContextProvidersProvider = ({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) => {
|
||||
const [minisearches, setMinisearches] = useState<{
|
||||
[id: string]: MiniSearch;
|
||||
}>({});
|
||||
const [fallbackResults, setFallbackResults] = useState<{
|
||||
[id: string]: ContextSubmenuItem[];
|
||||
}>({});
|
||||
|
||||
const contextProviderDescriptions = useSelector(
|
||||
selectContextProviderDescriptions,
|
||||
);
|
||||
|
||||
const [initialLoadComplete, setInitialLoadComplete] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [autoLoadTriggered, setAutoLoadTriggered] = useState(false);
|
||||
|
||||
const config = useSelector((store: RootState) => store.state.config);
|
||||
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
const getOpenFilesItems = useCallback(async () => {
|
||||
const openFiles = await ideMessenger.ide.getOpenFiles();
|
||||
const openFileGroups = groupByLastNPathParts(openFiles, 2);
|
||||
|
||||
return openFiles.map((file) => ({
|
||||
id: file,
|
||||
title: getBasename(file),
|
||||
description: getUniqueFilePath(file, openFileGroups),
|
||||
providerTitle: "file",
|
||||
}));
|
||||
}, [ideMessenger]);
|
||||
|
||||
useWebviewListener("refreshSubmenuItems", async (data) => {
|
||||
if (!isLoading) {
|
||||
setInitialLoadComplete(false);
|
||||
setAutoLoadTriggered((prev) => !prev); // Toggle to trigger effect
|
||||
}
|
||||
});
|
||||
|
||||
useWebviewListener("updateSubmenuItems", async (data) => {
|
||||
const minisearch = new MiniSearch<ContextSubmenuItem>({
|
||||
fields: ["title", "description"],
|
||||
storeFields: ["id", "title", "description"],
|
||||
});
|
||||
|
||||
minisearch.addAll(data.submenuItems);
|
||||
|
||||
setMinisearches((prev) => ({ ...prev, [data.provider]: minisearch }));
|
||||
|
||||
if (data.provider === "file") {
|
||||
const openFiles = await getOpenFilesItems();
|
||||
setFallbackResults((prev) => ({
|
||||
...prev,
|
||||
file: [
|
||||
...openFiles,
|
||||
...data.submenuItems.slice(0, MAX_LENGTH - openFiles.length),
|
||||
],
|
||||
}));
|
||||
} else {
|
||||
setFallbackResults((prev) => ({
|
||||
...prev,
|
||||
[data.provider]: data.submenuItems.slice(0, MAX_LENGTH),
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
const addItem = useCallback(
|
||||
(providerTitle: string, item: ContextSubmenuItem) => {
|
||||
if (!minisearches[providerTitle]) {
|
||||
return;
|
||||
}
|
||||
minisearches[providerTitle].add(item);
|
||||
},
|
||||
[minisearches],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
const refreshOpenFiles = async () => {
|
||||
if (!isMounted) return;
|
||||
const openFiles = await getOpenFilesItems();
|
||||
setFallbackResults((prev) => ({
|
||||
...prev,
|
||||
file: deduplicateArray(
|
||||
[...openFiles, ...(Array.isArray(prev.file) ? prev.file : [])],
|
||||
(a, b) => a.id === b.id,
|
||||
),
|
||||
}));
|
||||
};
|
||||
|
||||
const interval = setInterval(refreshOpenFiles, 2000);
|
||||
|
||||
refreshOpenFiles(); // Initial call
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
clearInterval(interval);
|
||||
};
|
||||
}, [getOpenFilesItems]);
|
||||
|
||||
const getSubmenuSearchResults = useMemo(
|
||||
() =>
|
||||
(providerTitle: string | undefined, query: string): SearchResult[] => {
|
||||
if (providerTitle === undefined) {
|
||||
// Return search combined from all providers
|
||||
const results = Object.keys(minisearches).map((providerTitle) => {
|
||||
const results = minisearches[providerTitle].search(
|
||||
query,
|
||||
MINISEARCH_OPTIONS,
|
||||
);
|
||||
return results.map((result) => {
|
||||
return { ...result, providerTitle };
|
||||
});
|
||||
});
|
||||
|
||||
return results.flat().sort((a, b) => b.score - a.score);
|
||||
}
|
||||
if (!minisearches[providerTitle]) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const results = minisearches[providerTitle]
|
||||
.search(query, MINISEARCH_OPTIONS)
|
||||
.map((result) => {
|
||||
return { ...result, providerTitle };
|
||||
});
|
||||
|
||||
return results;
|
||||
},
|
||||
[minisearches],
|
||||
);
|
||||
|
||||
const getSubmenuContextItems = useMemo(
|
||||
() =>
|
||||
(
|
||||
providerTitle: string | undefined,
|
||||
query: string,
|
||||
limit: number = MAX_LENGTH,
|
||||
): (ContextSubmenuItem & { providerTitle: string })[] => {
|
||||
try {
|
||||
const results = getSubmenuSearchResults(providerTitle, query);
|
||||
if (results.length === 0) {
|
||||
const fallbackItems = (fallbackResults[providerTitle] ?? [])
|
||||
.slice(0, limit)
|
||||
.map((result) => {
|
||||
return {
|
||||
...result,
|
||||
providerTitle,
|
||||
};
|
||||
});
|
||||
|
||||
if (fallbackItems.length === 0 && !initialLoadComplete) {
|
||||
return [
|
||||
{
|
||||
id: "loading",
|
||||
title: "Loading...",
|
||||
description: "Please wait while items are being loaded",
|
||||
providerTitle: providerTitle || "unknown",
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
return fallbackItems;
|
||||
}
|
||||
const limitedResults = results.slice(0, limit).map((result) => {
|
||||
return {
|
||||
id: result.id,
|
||||
title: result.title,
|
||||
description: result.description,
|
||||
providerTitle: result.providerTitle,
|
||||
};
|
||||
});
|
||||
return limitedResults;
|
||||
} catch (error) {
|
||||
console.error("Error in getSubmenuContextItems:", error);
|
||||
return [];
|
||||
}
|
||||
},
|
||||
[fallbackResults, getSubmenuSearchResults, initialLoadComplete],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (contextProviderDescriptions.length === 0 || isLoading) {
|
||||
return;
|
||||
}
|
||||
setIsLoading(true);
|
||||
|
||||
const loadSubmenuItems = async () => {
|
||||
try {
|
||||
await Promise.all(
|
||||
contextProviderDescriptions.map(async (description) => {
|
||||
const shouldSkipProvider =
|
||||
description.dependsOnIndexing && config.disableIndexing;
|
||||
|
||||
if (shouldSkipProvider) {
|
||||
console.debug(
|
||||
`Skipping ${description.title} provider due to disabled indexing`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const minisearch = new MiniSearch<ContextSubmenuItem>({
|
||||
fields: ["title", "description"],
|
||||
storeFields: ["id", "title", "description"],
|
||||
});
|
||||
|
||||
const result = await ideMessenger.request(
|
||||
"context/loadSubmenuItems",
|
||||
{
|
||||
title: description.title,
|
||||
},
|
||||
);
|
||||
|
||||
if (result.status === "error") {
|
||||
console.error(
|
||||
`Error loading items for ${description.title}:`,
|
||||
result.error,
|
||||
);
|
||||
return;
|
||||
}
|
||||
const items = result.content;
|
||||
|
||||
minisearch.addAll(items);
|
||||
|
||||
setMinisearches((prev) => ({
|
||||
...prev,
|
||||
[description.title]: minisearch,
|
||||
}));
|
||||
|
||||
if (description.title === "file") {
|
||||
const openFiles = await getOpenFilesItems();
|
||||
setFallbackResults((prev) => ({
|
||||
...prev,
|
||||
file: [
|
||||
...openFiles,
|
||||
...items.slice(0, MAX_LENGTH - openFiles.length),
|
||||
],
|
||||
}));
|
||||
} else {
|
||||
setFallbackResults((prev) => ({
|
||||
...prev,
|
||||
[description.title]: items.slice(0, MAX_LENGTH),
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error processing ${description.title}:`, error);
|
||||
console.error(
|
||||
"Error details:",
|
||||
JSON.stringify(error, Object.getOwnPropertyNames(error)),
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error in loadSubmenuItems:", error);
|
||||
} finally {
|
||||
setInitialLoadComplete(true);
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
loadSubmenuItems();
|
||||
}, [contextProviderDescriptions, autoLoadTriggered]);
|
||||
|
||||
return (
|
||||
<SubmenuContextProvidersContext.Provider
|
||||
value={{
|
||||
getSubmenuContextItems,
|
||||
addItem,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</SubmenuContextProvidersContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useSubmenuContextProviders = () =>
|
||||
useContext(SubmenuContextProvidersContext);
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
import { createContext } from "react";
|
||||
|
||||
export const VscThemeContext = createContext<any>(undefined);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { useState } from "react";
|
||||
import { createContext, useContext, useState } from "react";
|
||||
import { parseHexColor } from "../components";
|
||||
import { useWebviewListener } from "./useWebviewListener";
|
||||
import { useWebviewListener } from "../hooks/useWebviewListener";
|
||||
|
||||
const hljsToTextMate: Record<string, string[]> = {
|
||||
".hljs-comment": ["comment"],
|
||||
|
|
@ -149,9 +149,24 @@ function fallbackTheme() {
|
|||
};
|
||||
}
|
||||
|
||||
export function useVscTheme() {
|
||||
const [theme, setTheme] = useState<any>(
|
||||
constructTheme(window.fullColorTheme || {}),
|
||||
interface VscThemeContextType {
|
||||
theme: Record<string, string>;
|
||||
}
|
||||
|
||||
const initialVscThemeContext: VscThemeContextType = {
|
||||
theme: constructTheme(window.fullColorTheme || {}),
|
||||
};
|
||||
export const VscThemeContext = createContext<VscThemeContextType>(
|
||||
initialVscThemeContext,
|
||||
);
|
||||
|
||||
export const VscThemeProvider = ({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) => {
|
||||
const [theme, setTheme] = useState<Record<string, string>>(
|
||||
initialVscThemeContext.theme,
|
||||
);
|
||||
|
||||
useWebviewListener("setTheme", async (data) => {
|
||||
|
|
@ -159,5 +174,11 @@ export function useVscTheme() {
|
|||
setTheme(constructTheme(data.theme));
|
||||
});
|
||||
|
||||
return theme;
|
||||
}
|
||||
return (
|
||||
<VscThemeContext.Provider value={{ theme }}>
|
||||
{children}
|
||||
</VscThemeContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useVscTheme = () => useContext(VscThemeContext);
|
||||
|
|
@ -5,7 +5,7 @@ import { defaultBorderRadius } from "../components";
|
|||
import TipTapEditor from "../components/mainInput/TipTapEditor";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import useSetup from "../hooks/useSetup";
|
||||
import { selectSlashCommands } from "../redux/selectors";
|
||||
import { selectSlashCommandComboBoxInputs } from "../redux/selectors";
|
||||
import { RootState } from "../redux/store";
|
||||
|
||||
const EditorInsetDiv = styled.div`
|
||||
|
|
@ -18,7 +18,7 @@ const EditorInsetDiv = styled.div`
|
|||
|
||||
function EditorInset() {
|
||||
const dispatch = useDispatch();
|
||||
const availableSlashCommands = useSelector(selectSlashCommands);
|
||||
const availableSlashCommands = useSelector(selectSlashCommandComboBoxInputs);
|
||||
const availableContextProviders = useSelector(
|
||||
(store: RootState) => store.state.config.contextProviders,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import { constructMessages } from "core/llm/constructMessages";
|
|||
import { stripImages } from "core/llm/images";
|
||||
import { getBasename, getRelativePath } from "core/util";
|
||||
import { usePostHog } from "posthog-js/react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import resolveEditorContent, {
|
||||
hasSlashCommandOrContextProvider,
|
||||
|
|
@ -38,18 +38,18 @@ import { resetNextCodeBlockToApplyIndex } from "../redux/slices/stateSlice";
|
|||
import { RootState } from "../redux/store";
|
||||
import useHistory from "./useHistory";
|
||||
import { updateFileSymbolsFromContextItems } from "../util/symbols";
|
||||
import {
|
||||
selectDefaultContextProviders,
|
||||
selectSlashCommands,
|
||||
} from "../redux/selectors";
|
||||
|
||||
function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) {
|
||||
const posthog = usePostHog();
|
||||
|
||||
const defaultModel = useSelector(defaultModelSelector);
|
||||
const defaultContextProviders = useSelector(
|
||||
(store: RootState) => store.state.config.experimental?.defaultContext ?? [],
|
||||
);
|
||||
const defaultContextProviders = useSelector(selectDefaultContextProviders);
|
||||
|
||||
const slashCommands = useSelector(
|
||||
(store: RootState) => store.state.config.slashCommands || [],
|
||||
);
|
||||
const slashCommands = useSelector(selectSlashCommands);
|
||||
|
||||
const history = useSelector((store: RootState) => store.state.history);
|
||||
const active = useSelector((store: RootState) => store.state.active);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Dispatch } from "@reduxjs/toolkit";
|
||||
import { useCallback, useContext, useEffect, useRef, useState } from "react";
|
||||
import { useCallback, useContext, useEffect, useRef } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { VSC_THEME_COLOR_VARS } from "../components";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
|
|
@ -15,9 +15,8 @@ import {
|
|||
} from "../redux/slices/stateSlice";
|
||||
import { RootState } from "../redux/store";
|
||||
|
||||
import { debounce } from "lodash";
|
||||
import { isJetBrains } from "../util";
|
||||
import { getLocalStorage, setLocalStorage } from "../util/localStorage";
|
||||
import { setLocalStorage } from "../util/localStorage";
|
||||
import useChatHandler from "./useChatHandler";
|
||||
import { useWebviewListener } from "./useWebviewListener";
|
||||
import { updateFileSymbolsFromContextItems } from "../util/symbols";
|
||||
|
|
@ -178,8 +177,6 @@ function useSetup(dispatch: Dispatch) {
|
|||
},
|
||||
[defaultModelTitle],
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
export default useSetup;
|
||||
|
|
|
|||
|
|
@ -1,311 +0,0 @@
|
|||
import { ContextSubmenuItem } from "core";
|
||||
import { WebviewMessengerResult } from "core/protocol/util";
|
||||
import {
|
||||
deduplicateArray,
|
||||
getBasename,
|
||||
getUniqueFilePath,
|
||||
groupByLastNPathParts,
|
||||
} from "core/util";
|
||||
import MiniSearch, { SearchResult } from "minisearch";
|
||||
import { useCallback, useContext, useEffect, useMemo, useState } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
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,
|
||||
fuzzy: 2,
|
||||
};
|
||||
|
||||
const MAX_LENGTH = 70;
|
||||
|
||||
function useSubmenuContextProviders() {
|
||||
const [minisearches, setMinisearches] = useState<{
|
||||
[id: string]: MiniSearch;
|
||||
}>({});
|
||||
const [fallbackResults, setFallbackResults] = useState<{
|
||||
[id: string]: ContextSubmenuItem[];
|
||||
}>({});
|
||||
|
||||
const contextProviderDescriptions = useSelector(
|
||||
selectContextProviderDescriptions,
|
||||
);
|
||||
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const [initialLoadComplete, setInitialLoadComplete] = useState(false);
|
||||
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(() => {
|
||||
return async () => {
|
||||
const openFiles = await ideMessenger.ide.getOpenFiles();
|
||||
const openFileGroups = groupByLastNPathParts(openFiles, 2);
|
||||
|
||||
return openFiles.map((file) => ({
|
||||
id: file,
|
||||
title: getBasename(file),
|
||||
description: getUniqueFilePath(file, openFileGroups),
|
||||
providerTitle: "file",
|
||||
}));
|
||||
};
|
||||
}, [ideMessenger]);
|
||||
|
||||
useWebviewListener("refreshSubmenuItems", async (data) => {
|
||||
if (!isLoading) {
|
||||
setLoaded(false);
|
||||
setInitialLoadComplete(false);
|
||||
setAutoLoadTriggered((prev) => !prev); // Toggle to trigger effect
|
||||
}
|
||||
});
|
||||
|
||||
useWebviewListener("updateSubmenuItems", async (data) => {
|
||||
const minisearch = new MiniSearch<ContextSubmenuItem>({
|
||||
fields: ["title", "description"],
|
||||
storeFields: ["id", "title", "description"],
|
||||
});
|
||||
|
||||
minisearch.addAll(data.submenuItems);
|
||||
|
||||
setMinisearches((prev) => ({ ...prev, [data.provider]: minisearch }));
|
||||
|
||||
if (data.provider === "file") {
|
||||
const openFiles = await memoizedGetOpenFileItems();
|
||||
setFallbackResults((prev) => ({
|
||||
...prev,
|
||||
file: [
|
||||
...openFiles,
|
||||
...data.submenuItems.slice(0, MAX_LENGTH - openFiles.length),
|
||||
],
|
||||
}));
|
||||
} else {
|
||||
setFallbackResults((prev) => ({
|
||||
...prev,
|
||||
[data.provider]: data.submenuItems.slice(0, MAX_LENGTH),
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
const addItem = useCallback(
|
||||
(providerTitle: string, item: ContextSubmenuItem) => {
|
||||
if (!minisearches[providerTitle]) {
|
||||
return;
|
||||
}
|
||||
minisearches[providerTitle].add(item);
|
||||
},
|
||||
[minisearches],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
const refreshOpenFiles = async () => {
|
||||
if (!isMounted) return;
|
||||
const openFiles = await memoizedGetOpenFileItems();
|
||||
setFallbackResults((prev) => ({
|
||||
...prev,
|
||||
file: deduplicateArray(
|
||||
[...openFiles, ...(Array.isArray(prev.file) ? prev.file : [])],
|
||||
(a, b) => a.id === b.id,
|
||||
),
|
||||
}));
|
||||
};
|
||||
|
||||
const interval = setInterval(refreshOpenFiles, 2000);
|
||||
|
||||
refreshOpenFiles(); // Initial call
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
clearInterval(interval);
|
||||
};
|
||||
}, [memoizedGetOpenFileItems]);
|
||||
|
||||
const getSubmenuSearchResults = useMemo(
|
||||
() =>
|
||||
(providerTitle: string | undefined, query: string): SearchResult[] => {
|
||||
if (providerTitle === undefined) {
|
||||
// Return search combined from all providers
|
||||
const results = Object.keys(minisearches).map((providerTitle) => {
|
||||
const results = minisearches[providerTitle].search(
|
||||
query,
|
||||
MINISEARCH_OPTIONS,
|
||||
);
|
||||
return results.map((result) => {
|
||||
return { ...result, providerTitle };
|
||||
});
|
||||
});
|
||||
|
||||
return results.flat().sort((a, b) => b.score - a.score);
|
||||
}
|
||||
if (!minisearches[providerTitle]) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const results = minisearches[providerTitle]
|
||||
.search(query, MINISEARCH_OPTIONS)
|
||||
.map((result) => {
|
||||
return { ...result, providerTitle };
|
||||
});
|
||||
|
||||
return results;
|
||||
},
|
||||
[minisearches],
|
||||
);
|
||||
|
||||
const getSubmenuContextItems = useMemo(
|
||||
() =>
|
||||
(
|
||||
providerTitle: string | undefined,
|
||||
query: string,
|
||||
limit: number = MAX_LENGTH,
|
||||
): (ContextSubmenuItem & { providerTitle: string })[] => {
|
||||
try {
|
||||
const results = getSubmenuSearchResults(providerTitle, query);
|
||||
if (results.length === 0) {
|
||||
const fallbackItems = (fallbackResults[providerTitle] ?? [])
|
||||
.slice(0, limit)
|
||||
.map((result) => {
|
||||
return {
|
||||
...result,
|
||||
providerTitle,
|
||||
};
|
||||
});
|
||||
|
||||
if (fallbackItems.length === 0 && !initialLoadComplete) {
|
||||
return [
|
||||
{
|
||||
id: "loading",
|
||||
title: "Loading...",
|
||||
description: "Please wait while items are being loaded",
|
||||
providerTitle: providerTitle || "unknown",
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
return fallbackItems;
|
||||
}
|
||||
const limitedResults = results.slice(0, limit).map((result) => {
|
||||
return {
|
||||
id: result.id,
|
||||
title: result.title,
|
||||
description: result.description,
|
||||
providerTitle: result.providerTitle,
|
||||
};
|
||||
});
|
||||
return limitedResults;
|
||||
} catch (error) {
|
||||
console.error("Error in getSubmenuContextItems:", error);
|
||||
return [];
|
||||
}
|
||||
},
|
||||
[fallbackResults, getSubmenuSearchResults, initialLoadComplete],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (contextProviderDescriptions.length === 0 || loaded || isLoading) {
|
||||
return;
|
||||
}
|
||||
setLoaded(true);
|
||||
setIsLoading(true);
|
||||
|
||||
const loadSubmenuItems = async () => {
|
||||
try {
|
||||
await Promise.all(
|
||||
contextProviderDescriptions.map(async (description) => {
|
||||
const shouldSkipProvider =
|
||||
description.dependsOnIndexing && config.disableIndexing;
|
||||
|
||||
if (shouldSkipProvider) {
|
||||
console.debug(
|
||||
`Skipping ${description.title} provider due to disabled indexing`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const minisearch = new MiniSearch<ContextSubmenuItem>({
|
||||
fields: ["title", "description"],
|
||||
storeFields: ["id", "title", "description"],
|
||||
});
|
||||
|
||||
const result = await ideMessenger.request(
|
||||
"context/loadSubmenuItems",
|
||||
{
|
||||
title: description.title,
|
||||
},
|
||||
)
|
||||
|
||||
if (result.status === "error") {
|
||||
console.error(
|
||||
`Error loading items for ${description.title}:`,
|
||||
result.error,
|
||||
);
|
||||
return;
|
||||
}
|
||||
const items = result.content;
|
||||
|
||||
minisearch.addAll(items);
|
||||
|
||||
setMinisearches((prev) => ({
|
||||
...prev,
|
||||
[description.title]: minisearch,
|
||||
}));
|
||||
|
||||
if (description.title === "file") {
|
||||
const openFiles = await memoizedGetOpenFileItems();
|
||||
setFallbackResults((prev) => ({
|
||||
...prev,
|
||||
file: [
|
||||
...openFiles,
|
||||
...items.slice(0, MAX_LENGTH - openFiles.length),
|
||||
],
|
||||
}));
|
||||
} else {
|
||||
setFallbackResults((prev) => ({
|
||||
...prev,
|
||||
[description.title]: items.slice(0, MAX_LENGTH),
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error processing ${description.title}:`, error);
|
||||
console.error(
|
||||
"Error details:",
|
||||
JSON.stringify(error, Object.getOwnPropertyNames(error)),
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error in loadSubmenuItems:", error);
|
||||
} finally {
|
||||
setInitialLoadComplete(true);
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
loadSubmenuItems().catch((error) => {
|
||||
console.error("Error in loadSubmenuItems:", error);
|
||||
setInitialLoadComplete(true);
|
||||
setIsLoading(false);
|
||||
});
|
||||
}, [contextProviderDescriptions, loaded, autoLoadTriggered]);
|
||||
|
||||
useWebviewListener("configUpdate", async () => {
|
||||
// When config is updated (for example switching to a different workspace)
|
||||
// we need to reload the context providers.
|
||||
setLoaded(false);
|
||||
});
|
||||
|
||||
return {
|
||||
getSubmenuContextItems,
|
||||
addItem,
|
||||
};
|
||||
}
|
||||
|
||||
export default useSubmenuContextProviders;
|
||||
|
|
@ -21,6 +21,7 @@ import AcceptRejectAllButtons from "../../components/StepContainer/AcceptRejectA
|
|||
import ContinueInputBox from "../../components/mainInput/ContinueInputBox";
|
||||
import StepContainer from "../../components/StepContainer";
|
||||
import getMultifileEditPrompt from "./getMultifileEditPrompt";
|
||||
import { selectApplyState } from "../../redux/selectors";
|
||||
|
||||
const EDIT_DISALLOWED_CONTEXT_PROVIDERS = [
|
||||
"codebase",
|
||||
|
|
@ -50,11 +51,7 @@ export default function Edit() {
|
|||
(state: RootState) => state.state.applyStates,
|
||||
);
|
||||
|
||||
const applyState = useSelector(
|
||||
(store: RootState) =>
|
||||
store.state.applyStates.find((state) => state.streamId === "edit")
|
||||
?.status ?? "closed",
|
||||
);
|
||||
const applyState = useSelector(selectApplyState);
|
||||
|
||||
const isSingleRangeEdit =
|
||||
editModeState.codeToEdit.length === 0 ||
|
||||
|
|
@ -74,8 +71,6 @@ export default function Edit() {
|
|||
}
|
||||
}, [applyState, editModeState.editStatus]);
|
||||
|
||||
// const active = useSelector((state: RootState) => state.state.active);
|
||||
|
||||
const pendingApplyStates = applyStates.filter(
|
||||
(state) => state.status === "done",
|
||||
);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
|
|
@ -131,10 +132,15 @@ export function Chat() {
|
|||
const mainTextInputRef = useRef<HTMLInputElement>(null);
|
||||
const stepsDivRef = useRef<HTMLDivElement>(null);
|
||||
const [isAtBottom, setIsAtBottom] = useState<boolean>(false);
|
||||
const state = useSelector((state: RootState) => state.state);
|
||||
const history = useSelector((store: RootState) => store.state.history);
|
||||
const showChatScrollbar = useSelector(
|
||||
(store: RootState) => store.state.config?.ui?.showChatScrollbar,
|
||||
);
|
||||
const { saveSession, getLastSessionId, loadLastSession } =
|
||||
useHistory(dispatch);
|
||||
|
||||
console.log("chat rendering");
|
||||
|
||||
const snapToBottom = useCallback(() => {
|
||||
if (!stepsDivRef.current) return;
|
||||
const elem = stepsDivRef.current;
|
||||
|
|
@ -289,7 +295,7 @@ export function Chat() {
|
|||
setLocalStorage("mainTextEntryCounter", 1);
|
||||
}
|
||||
},
|
||||
[state.history, defaultModel, state, streamResponse],
|
||||
[history, defaultModel, streamResponse],
|
||||
);
|
||||
|
||||
useWebviewListener(
|
||||
|
|
@ -303,26 +309,27 @@ export function Chat() {
|
|||
|
||||
const isLastUserInput = useCallback(
|
||||
(index: number): boolean => {
|
||||
return !state.history
|
||||
return !history
|
||||
.slice(index + 1)
|
||||
.some((entry) => entry.message.role === "user");
|
||||
},
|
||||
[state.history],
|
||||
[history],
|
||||
);
|
||||
|
||||
const showScrollbar =
|
||||
state.config.ui?.showChatScrollbar || window.innerHeight > 5000;
|
||||
const showScrollbar = useMemo(() => {
|
||||
return showChatScrollbar ?? window.innerHeight > 5000;
|
||||
}, [showChatScrollbar]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{widget}
|
||||
<StepsDiv
|
||||
ref={stepsDivRef}
|
||||
className={`overflow-y-scroll pt-[8px] ${showScrollbar ? "thin-scrollbar" : "no-scrollbar"} ${state.history.length > 0 ? "flex-1" : ""}`}
|
||||
className={`overflow-y-scroll pt-[8px] ${showScrollbar ? "thin-scrollbar" : "no-scrollbar"} ${history.length > 0 ? "flex-1" : ""}`}
|
||||
onScroll={handleScroll}
|
||||
>
|
||||
{highlights}
|
||||
{state.history.map((item, index: number) => (
|
||||
{history.map((item, index: number) => (
|
||||
<Fragment key={item.message.id}>
|
||||
<ErrorBoundary
|
||||
FallbackComponent={fallbackRender}
|
||||
|
|
@ -368,7 +375,7 @@ export function Chat() {
|
|||
>
|
||||
<StepContainer
|
||||
index={index}
|
||||
isLast={index === state.history.length - 1}
|
||||
isLast={index === history.length - 1}
|
||||
item={item}
|
||||
/>
|
||||
</TimelineItem>
|
||||
|
|
@ -421,7 +428,7 @@ export function Chat() {
|
|||
>
|
||||
<div className="flex flex-row items-center justify-between pb-1 pl-0.5 pr-2">
|
||||
<div className="xs:inline hidden">
|
||||
{state.history.length === 0 && getLastSessionId() ? (
|
||||
{history.length === 0 && getLastSessionId() ? (
|
||||
<div className="xs:inline hidden">
|
||||
<NewSessionButton
|
||||
onClick={async () => {
|
||||
|
|
@ -440,7 +447,7 @@ export function Chat() {
|
|||
<ConfigErrorIndicator />
|
||||
</div>
|
||||
|
||||
{state.history.length === 0 && (
|
||||
{history.length === 0 && (
|
||||
<>
|
||||
{onboardingCard.show && (
|
||||
<div className="mx-2 mt-10">
|
||||
|
|
@ -458,7 +465,7 @@ export function Chat() {
|
|||
</div>
|
||||
</div>
|
||||
<div
|
||||
className={`${state.history.length === 0 ? "h-full" : ""} flex flex-col justify-end`}
|
||||
className={`${history.length === 0 ? "h-full" : ""} flex flex-col justify-end`}
|
||||
>
|
||||
<ChatIndexingPeeks />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { createSelector } from "@reduxjs/toolkit";
|
|||
import { ComboBoxItemType } from "../../components/mainInput/types";
|
||||
import { RootState } from "../store";
|
||||
|
||||
export const selectSlashCommands = createSelector(
|
||||
export const selectSlashCommandComboBoxInputs = createSelector(
|
||||
[(store: RootState) => store.state.config.slashCommands],
|
||||
(slashCommands) => {
|
||||
return (
|
||||
|
|
@ -17,6 +17,13 @@ export const selectSlashCommands = createSelector(
|
|||
},
|
||||
);
|
||||
|
||||
export const selectSlashCommands = createSelector(
|
||||
[(store: RootState) => store.state.config.slashCommands],
|
||||
(slashCommands) => {
|
||||
return slashCommands || [];
|
||||
},
|
||||
);
|
||||
|
||||
export const selectContextProviderDescriptions = createSelector(
|
||||
[(store: RootState) => store.state.config.contextProviders],
|
||||
(providers) => {
|
||||
|
|
@ -24,7 +31,23 @@ export const selectContextProviderDescriptions = createSelector(
|
|||
},
|
||||
);
|
||||
|
||||
export const selectDefaultContextProviders = createSelector(
|
||||
[(store: RootState) => store.state.config.experimental?.defaultContext],
|
||||
(defaultProviders) => {
|
||||
return defaultProviders ?? [];
|
||||
},
|
||||
);
|
||||
|
||||
export const selectUseActiveFile = createSelector(
|
||||
[(store: RootState) => store.state.config.experimental?.defaultContext],
|
||||
(defaultContext) => defaultContext?.includes("activeFile" as any),
|
||||
);
|
||||
|
||||
export const selectApplyState = createSelector(
|
||||
[(store: RootState) => store.state.applyStates],
|
||||
(applyStates) => {
|
||||
return (
|
||||
applyStates.find((state) => state.streamId === "edit")?.status ?? "closed"
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { DEFAULT_MAX_TOKENS } from "core/llm/constants";
|
||||
import { RootState } from "../store";
|
||||
import { createSelector } from "@reduxjs/toolkit";
|
||||
|
||||
export const defaultModelSelector = (state: RootState) => {
|
||||
const title = state.state.defaultModelTitle;
|
||||
return state.state.config.models.find((model) => model.title === title);
|
||||
};
|
||||
|
||||
export const contextLengthSelector = (state: RootState) => {
|
||||
return defaultModelSelector(state)?.contextLength || DEFAULT_MAX_TOKENS;
|
||||
};
|
||||
export const defaultModelSelector = createSelector(
|
||||
[
|
||||
(store: RootState) => store.state.defaultModelTitle,
|
||||
(store: RootState) => store.state.config.models,
|
||||
],
|
||||
(defaultModelTitle, models) => {
|
||||
return models?.find((model) => model.title === defaultModelTitle);
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -341,7 +341,7 @@ export const stateSlice = createSlice({
|
|||
payload.rangeInFileWithContents.range.start.line + 1
|
||||
}-${payload.rangeInFileWithContents.range.end.line + 1})`;
|
||||
contextItems.push({
|
||||
name: `${base} ${lineNums}`,
|
||||
name: `${base} ${lineNums}s`,
|
||||
description: payload.rangeInFileWithContents.filepath,
|
||||
id: {
|
||||
providerTitle: "code",
|
||||
|
|
@ -367,10 +367,7 @@ export const stateSlice = createSlice({
|
|||
};
|
||||
},
|
||||
setSelectedProfileId: (state, { payload }: PayloadAction<string>) => {
|
||||
return {
|
||||
...state,
|
||||
selectedProfileId: payload,
|
||||
};
|
||||
state.selectedProfileId = payload;
|
||||
},
|
||||
setCurCheckpointIndex: (state, { payload }: PayloadAction<number>) => {
|
||||
state.curCheckpointIndex = payload;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue