diff --git a/core/config/validation.ts b/core/config/validation.ts
index ebcbb623d..062c0eaed 100644
--- a/core/config/validation.ts
+++ b/core/config/validation.ts
@@ -34,6 +34,18 @@ export function validateConfig(config: SerializedContinueConfig) {
message: `Model at index ${index} has an invalid 'provider'.`,
});
}
+
+ if (model.contextLength && model.completionOptions?.maxTokens) {
+ const difference =
+ model.contextLength - model.completionOptions.maxTokens;
+
+ if (difference < 1000) {
+ errors.push({
+ fatal: false,
+ message: `Model "${model.title}" has a contextLength of ${model.contextLength} and a maxTokens of ${model.completionOptions.maxTokens}. This leaves only ${difference} tokens for input context and will likely result in your inputs being truncated.`,
+ });
+ }
+ }
});
}
diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts
index 46fedf9d0..d97b92974 100644
--- a/core/indexing/docs/DocsService.ts
+++ b/core/indexing/docs/DocsService.ts
@@ -254,6 +254,8 @@ export default class DocsService {
if (processedPages === maxKnownPages) {
maxKnownPages *= 2;
}
+
+ await new Promise((resolve) => setTimeout(resolve, 50));
}
void Telemetry.capture("docs_pages_crawled", {
diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts
index 17f104a52..bebb8ead1 100644
--- a/core/llm/autodetect.ts
+++ b/core/llm/autodetect.ts
@@ -49,7 +49,7 @@ const PROVIDER_HANDLES_TEMPLATING: ModelProvider[] = [
"mistral",
"sambanova",
"vertexai",
- "watsonx"
+ "watsonx",
];
const PROVIDER_SUPPORTS_IMAGES: ModelProvider[] = [
@@ -63,7 +63,8 @@ const PROVIDER_SUPPORTS_IMAGES: ModelProvider[] = [
"sagemaker",
"continue-proxy",
"openrouter",
- "vertexai"
+ "vertexai",
+ "azure",
];
const MODEL_SUPPORTS_IMAGES: string[] = [
@@ -121,7 +122,7 @@ const PARALLEL_PROVIDERS: ModelProvider[] = [
"together",
"sambanova",
"nebius",
- "vertexai"
+ "vertexai",
];
function llmCanGenerateInParallel(
diff --git a/core/llm/countTokens.ts b/core/llm/countTokens.ts
index 7ae3da1b7..9b30ad4bc 100644
--- a/core/llm/countTokens.ts
+++ b/core/llm/countTokens.ts
@@ -323,6 +323,27 @@ function pruneChatHistory(
return chatHistory;
}
+function messageIsEmpty(message: ChatMessage): boolean {
+ if (typeof message.content === "string") {
+ return message.content.trim() === "";
+ }
+ if (Array.isArray(message.content)) {
+ return message.content.every(
+ (item) => !item.imageUrl && item.text?.trim() === "",
+ );
+ }
+ return false;
+}
+
+function addSpaceToAnyEmptyMessages(messages: ChatMessage[]): ChatMessage[] {
+ return messages.map((message) => {
+ if (messageIsEmpty(message)) {
+ message.content = " ";
+ }
+ return message;
+ });
+}
+
function compileChatMessages(
modelName: string,
msgs: ChatMessage[] | undefined,
@@ -333,12 +354,14 @@ function compileChatMessages(
functions: any[] | undefined = undefined,
systemMessage: string | undefined = undefined,
): ChatMessage[] {
- const msgsCopy = msgs
+ let msgsCopy = msgs
? msgs
.map((msg) => ({ ...msg }))
.filter((msg) => msg.content !== "" && msg.role !== "system")
: [];
+ msgsCopy = addSpaceToAnyEmptyMessages(msgsCopy);
+
if (prompt) {
const promptMsg: ChatMessage = {
role: "user",
diff --git a/docs/docs/customize/deep-dives/prompt-files.md b/docs/docs/customize/deep-dives/prompt-files.md
index 928e01543..91f3557ea 100644
--- a/docs/docs/customize/deep-dives/prompt-files.md
+++ b/docs/docs/customize/deep-dives/prompt-files.md
@@ -6,9 +6,9 @@ Prompt files provide a convenient way to standardize common patterns and share a
## Quick start
-:::tip[Prompt library]
+
Below is a quick example of setting up a prompt file to write unit tests using Jest.
@@ -17,31 +17,19 @@ Below is a quick example of setting up a prompt file to write unit tests using J
3. Write the following contents to `test.prompt` and save.
```
-temperature: 0.5
-maxTokens: 4096
+name: Rails Project
+description: Information about this project
---
-
-You are an expert programmer
-
-
-{{{ input }}}
-
-Write unit tests for the above selected code, following each of these instructions:
-- Use `jest`
-- Properly set up and tear down
-- Include important edge cases
-- The tests should be complete and sophisticated
-- Give the tests just as chat output, don't edit any file
-- Don't explain how to set up `jest`
+Attached is a summary of the current Ruby on Rails application, including the @Gemfile and database schema in @db/schema.rb
```
Now to use this prompt, you can highlight code and use cmd/ctrl + L to select it in the Continue sidebar.
-Then, type "/" to see the list of slash commands and choose the one called "test". Press enter and the LLM will respond given the instructions from your prompt file.
+Then, type "@", select "Prompt files", and choose the one called "Rails Project". You can now ask any question as usual and the LLM will have the information from your .prompt file.
## Format
-The format is inspired by [HumanLoops's .prompt file](https://docs.humanloop.com/docs/prompt-file-format), with additional templating to use context providers and built-in variables using [Handlebars syntax](https://handlebarsjs.com/guide/).
+The format is inspired by [HumanLoops's .prompt file](https://docs.humanloop.com/docs/prompt-file-format), with additional templating to reference files, URLs, and context providers.
:::info
The current state of this format is experimental and subject to change
@@ -51,38 +39,19 @@ The current state of this format is experimental and subject to change
The "preamble" is everything above the `---` separator, and lets you specify model parameters. It uses YAML syntax and currently supports the following parameters:
-- `name`
-- `temperature`
-- `topP`
-- `topK`
-- `minP`
-- `presencePenalty`
-- `frequencyPenalty`
-- `mirostat`
-- `stop`
-- `maxTokens`
-- `description`
+- `name` - The display title
+- `description` - The description you will see in the dropdown
+- `version` - Can be either "1" (for legacy prompt files) or "2" (this is the default and does not need to be set)
If you don't need any of these parameters, you can leave out the preamble and do not need to include the `---` separator.
-### System message
+### Context
-To add a system message, start the body with `` tags like in the example above and place your system message inside.
+Many [context provider](../context-providers.md) can be referenced by typing "@" followed by the name of the context provider.
-### Built-in variables
-
-The following built-in variables are currently available:
-
-- `{{{ input }}}` - The full text from the input box in the sidebar that is sent along with the slash command
-- `{{{ currentFile }}}` - The currently open file in your IDE
-- `{{{ ./path/to/file.js }}}` - Any file can be directly referenced
-
-### Context providers
-
-Any [context provider](../context-providers.md) that you have added to your config can be referenced using the name of the context provider. Context providers that receive an input are also supported.
-
-- `{{{ terminal }}}` - The contents of the terminal
-- `{{{ url "https://github.com/continuedev/continue" }}}` - The contents of a URL
+- `@terminal` - The contents of the terminal
+- `@https://github.com/continuedev/continue` - The contents of a URL
+- `@src/index.ts` - The contents of a file
## Feedback
diff --git a/extensions/vscode/src/diff/vertical/handler.ts b/extensions/vscode/src/diff/vertical/handler.ts
index 323c8caaf..3286749a6 100644
--- a/extensions/vscode/src/diff/vertical/handler.ts
+++ b/extensions/vscode/src/diff/vertical/handler.ts
@@ -26,9 +26,12 @@ export class VerticalDiffHandler implements vscode.Disposable {
private currentLineIndex: number;
private cancelled = false;
private newLinesAdded = 0;
- private get diffBlocks() {
- return this.editorToVerticalDiffCodeLens.get(this.filepath) || [];
+ private deletionBuffer: string[] = [];
+ private redDecorationManager: DecorationTypeRangeManager;
+ private get filepath() {
+ return this.editor.document.uri.fsPath;
}
+ public insertedInCurrentBlock = 0;
public get range(): vscode.Range {
const startLine = Math.min(this.startLine, this.endLine);
const endLine = Math.max(this.startLine, this.endLine);
@@ -78,14 +81,6 @@ export class VerticalDiffHandler implements vscode.Disposable {
this.disposables.push(disposable);
}
- private get filepath() {
- return this.editor.document.uri.fsPath;
- }
-
- private deletionBuffer: string[] = [];
- private redDecorationManager: DecorationTypeRangeManager;
- insertedInCurrentBlock = 0;
-
private async insertDeletionBuffer() {
// Don't remove trailing whitespace line
const totalDeletedContent = this.deletionBuffer.join("\n");
@@ -99,13 +94,15 @@ export class VerticalDiffHandler implements vscode.Disposable {
}
if (this.deletionBuffer.length || this.insertedInCurrentBlock > 0) {
- this.diffBlocks.push({
+ const blocks = this.editorToVerticalDiffCodeLens.get(this.filepath) || [];
+
+ blocks.push({
start: this.currentLineIndex - this.insertedInCurrentBlock,
numRed: this.deletionBuffer.length,
numGreen: this.insertedInCurrentBlock,
});
- this.editorToVerticalDiffCodeLens.set(this.filepath, this.diffBlocks);
+ this.editorToVerticalDiffCodeLens.set(this.filepath, blocks);
}
if (this.deletionBuffer.length === 0) {
@@ -274,7 +271,7 @@ export class VerticalDiffHandler implements vscode.Disposable {
this.options.onStatusUpdate(
"closed",
- this.diffBlocks.length,
+ this.editorToVerticalDiffCodeLens.get(this.filepath)?.length ?? 0,
this.editor.document.getText(),
);
@@ -366,7 +363,7 @@ export class VerticalDiffHandler implements vscode.Disposable {
this.options.onStatusUpdate(
"done",
- this.diffBlocks.length,
+ this.editorToVerticalDiffCodeLens.get(this.filepath)?.length ?? 0,
this.editor.document.getText(),
);
@@ -418,10 +415,13 @@ export class VerticalDiffHandler implements vscode.Disposable {
// Shift the codelens objects
this.shiftCodeLensObjects(startLine, offset);
- const status = this.diffBlocks.length === 0 ? "closed" : undefined;
+ const numDiffs =
+ this.editorToVerticalDiffCodeLens.get(this.filepath)?.length ?? 0;
+
+ const status = numDiffs === 0 ? "closed" : undefined;
this.options.onStatusUpdate(
status,
- this.diffBlocks.length,
+ numDiffs,
this.editor.document.getText(),
);
}
@@ -463,6 +463,7 @@ export class VerticalDiffHandler implements vscode.Disposable {
}
public hasDiffForCurrentFile(): boolean {
- return this.diffBlocks.length > 0;
+ const diffBlocks = this.editorToVerticalDiffCodeLens.get(this.filepath);
+ return diffBlocks !== undefined && diffBlocks.length > 0;
}
}
diff --git a/gui/src/components/History/index.tsx b/gui/src/components/History/index.tsx
index 7ed525626..4aee636bd 100644
--- a/gui/src/components/History/index.tsx
+++ b/gui/src/components/History/index.tsx
@@ -46,13 +46,20 @@ export function History() {
const fetchSessions = async () => {
const sessions = await getHistory();
setSessions(sessions);
- minisearch.addAll(
- sessions.map((session) => ({
- title: session.title,
- sessionId: session.sessionId,
- id: session.sessionId,
- })),
- );
+
+ try {
+ // Consider adding just last session to existing instead of clearing/adding all
+ minisearch.removeAll();
+ minisearch.addAll(
+ sessions.map((session) => ({
+ title: session.title,
+ sessionId: session.sessionId,
+ id: session.sessionId,
+ })),
+ );
+ } catch (e) {
+ console.log("error adding sessions to minisearch", e);
+ }
};
fetchSessions();
}, [lastSessionId]);
diff --git a/gui/src/components/mainInput/CodeBlockComponent.tsx b/gui/src/components/mainInput/CodeBlockComponent.tsx
index 217fcc293..20d700c63 100644
--- a/gui/src/components/mainInput/CodeBlockComponent.tsx
+++ b/gui/src/components/mainInput/CodeBlockComponent.tsx
@@ -1,28 +1,25 @@
import { NodeViewWrapper } from "@tiptap/react";
import { ContextItemWithId } from "core";
-import { useDispatch, useSelector } from "react-redux";
import { vscBadgeBackground } from "..";
-import { RootState } from "../../redux/store";
import CodeSnippetPreview from "../markdown/CodeSnippetPreview";
+import { useSelector } from "react-redux";
+import { RootState } from "../../redux/store";
-export const CodeBlockComponent = ({
- node,
- deleteNode,
- selected,
- editor,
- updateAttributes,
-}: any) => {
- const dispatch = useDispatch();
+export const CodeBlockComponent = (props: any) => {
+ const { node, deleteNode, selected, editor, updateAttributes } = props;
const item: ContextItemWithId = node.attrs.item;
+ // const contextItems = useSelector(
+ // (store: RootState) =>
+ // store.state.history[store.state.history.length - 1].contextItems,
+ // );
+ // const isFirstContextItem = item.id === contextItems[0]?.id;
+ const isFirstContextItem = false;
- const contextItems = useSelector(
- (state: RootState) => state.state.contextItems,
- );
return (
store.state.contextItems,
- );
-
const defaultModel = useSelector(defaultModelSelector);
const defaultModelRef = useUpdatingRef(defaultModel);
@@ -498,19 +494,7 @@ function TipTapEditor(props: TipTapEditorProps) {
content: props.editorState || mainEditorContent || "",
onFocus: () => setIsEditorFocused(true),
onBlur: () => setIsEditorFocused(false),
- onUpdate: ({ editor, transaction }) => {
- // If /edit is typed and no context items are selected, select the first
-
- if (contextItems.length > 0) {
- return;
- }
-
- const json = editor.getJSON();
- let codeBlock = json.content?.find((el) => el.type === "codeBlock");
- if (!codeBlock) {
- return;
- }
- },
+ // onUpdate
editable: !active || props.isMainInput,
});
diff --git a/gui/src/components/markdown/CodeSnippetPreview.tsx b/gui/src/components/markdown/CodeSnippetPreview.tsx
index 639e14cc8..39c09cfb6 100644
--- a/gui/src/components/markdown/CodeSnippetPreview.tsx
+++ b/gui/src/components/markdown/CodeSnippetPreview.tsx
@@ -124,6 +124,7 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) {
source={`${fence}${getMarkdownLanguageTagForFile(
props.item.description.split(" ")[0],
)} ${props.item.description}\n${content}\n${fence}`}
+ contextItems={[props.item]}
/>
diff --git a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx
index 340a37f17..fbc43e5d2 100644
--- a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx
+++ b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx
@@ -1,17 +1,15 @@
import { ChevronDownIcon } from "@heroicons/react/24/outline";
import { debounce } from "lodash";
import { useContext, useEffect, useRef, useState } from "react";
-import { useDispatch, useSelector } from "react-redux";
-import styled, { keyframes } from "styled-components";
+import { useSelector } from "react-redux";
+import styled, { css, keyframes } from "styled-components";
import { v4 as uuidv4 } from "uuid";
import { defaultBorderRadius, lightGray, vscEditorBackground } from "../..";
import { IdeMessengerContext } from "../../../context/IdeMessenger";
import { useWebviewListener } from "../../../hooks/useWebviewListener";
-import { updateApplyState } from "../../../redux/slices/stateSlice";
import { RootState } from "../../../redux/store";
import { getFontSize } from "../../../util";
import { childrenToText } from "../utils";
-import { useApplyCodeBlock } from "../../../hooks/useApplyCodeBlock";
import ApplyActions from "./ApplyActions";
import CopyButton from "./CopyButton";
import FileInfo from "./FileInfo";
@@ -27,14 +25,19 @@ const fadeInAnimation = keyframes`
}
`;
-const TopDiv = styled.div`
+const TopDiv = styled.div<{ active?: boolean }>`
outline: 1px solid rgba(153, 153, 152);
outline-offset: -0.5px;
border-radius: ${defaultBorderRadius};
margin-bottom: 8px !important;
background-color: ${vscEditorBackground};
min-width: 0;
- animation: ${fadeInAnimation} 300ms ease-out forwards;
+ ${(props) =>
+ props.active
+ ? "animation: none;"
+ : css`
+ animation: ${fadeInAnimation} 300ms ease-out forwards;
+ `}
`;
const ToolbarDiv = styled.div<{ isExpanded: boolean }>`
@@ -68,6 +71,7 @@ export default function StepContainerPreToolbar(
const isMultifileEdit = useSelector(
(state: RootState) => state.state.isMultifileEdit,
);
+ const active = useSelector((state: RootState) => state.state.active);
const [isExpanded, setIsExpanded] = useState(isMultifileEdit ? false : true);
const [codeBlockContent, setCodeBlockContent] = useState("");
const isChatActive = useSelector((state: RootState) => state.state.active);
@@ -165,7 +169,7 @@ export default function StepContainerPreToolbar(
}
return (
-
+
processCodeBlocks],
rehypePlugins: [
@@ -237,13 +235,14 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
code: ({ node, ...codeProps }) => {
const content = getCodeChildrenContent(codeProps.children);
- const ctxItem = contextItems.find((ctxItem) =>
- ctxItem.uri?.value.includes(content),
- );
-
- if (ctxItem) {
- const rif = ctxItemToRifWithContents(ctxItem);
- return ;
+ if (props.contextItems) {
+ const ctxItem = props.contextItems.find((ctxItem) =>
+ ctxItem.uri?.value.includes(content),
+ );
+ if (ctxItem) {
+ const rif = ctxItemToRifWithContents(ctxItem);
+ return ;
+ }
}
return {codeProps.children};
diff --git a/gui/src/hooks/useChatHandler.ts b/gui/src/hooks/useChatHandler.ts
index c805c94db..ce599454d 100644
--- a/gui/src/hooks/useChatHandler.ts
+++ b/gui/src/hooks/useChatHandler.ts
@@ -23,7 +23,6 @@ import resolveEditorContent, {
import { IIdeMessenger } from "../context/IdeMessenger";
import { defaultModelSelector } from "../redux/selectors/modelSelectors";
import {
- addContextItems,
addPromptCompletionPair,
clearLastResponse,
initNewActiveMessage,
@@ -51,10 +50,6 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) {
(store: RootState) => store.state.config.slashCommands || [],
);
- const contextItems = useSelector(
- (state: RootState) => state.state.contextItems,
- );
-
const history = useSelector((store: RootState) => store.state.history);
const active = useSelector((store: RootState) => store.state.active);
const activeRef = useRef(active);
@@ -231,26 +226,33 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) {
.slice(0, 1000)
.join("\n");
}
- selectedContextItems.unshift({
- content: `The following file is currently open. Don't reference it if it's not relevant to the user's message.\n\n\`\`\`${getRelativePath(
- currentFile.path,
- await ideMessenger.ide.getWorkspaceDirs(),
- )}\n${currentFileContents}\n\`\`\``,
- name: `Active file: ${getBasename(currentFile.path)}`,
- description: currentFile.path,
- id: {
- itemId: currentFile.path,
- providerTitle: "file",
- },
- uri: {
- type: "file",
- value: currentFile.path,
- },
- });
+ if (
+ !selectedContextItems.find(
+ (item) => item.uri?.value === currentFile.path,
+ )
+ ) {
+ // don't add the file if it's already in the context items
+ selectedContextItems.unshift({
+ content: `The following file is currently open. Don't reference it if it's not relevant to the user's message.\n\n\`\`\`${getRelativePath(
+ currentFile.path,
+ await ideMessenger.ide.getWorkspaceDirs(),
+ )}\n${currentFileContents}\n\`\`\``,
+ name: `Active file: ${getBasename(currentFile.path)}`,
+ description: currentFile.path,
+ id: {
+ itemId: currentFile.path,
+ providerTitle: "file",
+ },
+ uri: {
+ type: "file",
+ value: currentFile.path,
+ },
+ });
+ }
}
}
- dispatch(addContextItems(contextItems));
+ // dispatch(addContextItems(contextItems));
const message: ChatMessage = {
role: "user",
diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts
index 2fed805da..b96c48ed2 100644
--- a/gui/src/hooks/useSetup.ts
+++ b/gui/src/hooks/useSetup.ts
@@ -1,5 +1,5 @@
import { Dispatch } from "@reduxjs/toolkit";
-import { useContext, useEffect, useState } from "react";
+import { useCallback, useContext, useEffect, useRef, useState } from "react";
import { useSelector } from "react-redux";
import { VSC_THEME_COLOR_VARS } from "../components";
import { IdeMessengerContext } from "../context/IdeMessenger";
@@ -21,11 +21,10 @@ import useChatHandler from "./useChatHandler";
import { useWebviewListener } from "./useWebviewListener";
function useSetup(dispatch: Dispatch) {
- const [configLoaded, setConfigLoaded] = useState(false);
-
const ideMessenger = useContext(IdeMessengerContext);
- const loadConfig = async () => {
+ const initialConfigLoad = useRef(false);
+ const loadConfig = useCallback(async () => {
const result = await ideMessenger.request(
"config/getSerializedProfileInfo",
undefined,
@@ -36,7 +35,7 @@ function useSetup(dispatch: Dispatch) {
const { config, profileId } = result.content;
dispatch(setConfig(config));
dispatch(setSelectedProfileId(profileId));
- setConfigLoaded(true);
+ initialConfigLoad.current = true;
setLocalStorage("disableIndexing", config.disableIndexing || false);
// Perform any actions needed with the config
@@ -44,13 +43,13 @@ function useSetup(dispatch: Dispatch) {
setLocalStorage("fontSize", config.ui.fontSize);
document.body.style.fontSize = `${config.ui.fontSize}px`;
}
- };
+ }, [dispatch, ideMessenger, initialConfigLoad]);
// Load config from the IDE
useEffect(() => {
loadConfig();
const interval = setInterval(() => {
- if (configLoaded) {
+ if (initialConfigLoad.current) {
clearInterval(interval);
return;
}
@@ -58,7 +57,7 @@ function useSetup(dispatch: Dispatch) {
}, 2_000);
return () => clearInterval(interval);
- }, [configLoaded]);
+ }, [initialConfigLoad, loadConfig]);
useEffect(() => {
// Override persisted state
diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx
index 21ed79f04..345fe6f37 100644
--- a/gui/src/pages/gui/Chat.tsx
+++ b/gui/src/pages/gui/Chat.tsx
@@ -157,11 +157,11 @@ export function Chat() {
if (active) snapToBottom();
}, [active, snapToBottom]);
- useEffect(() => {
- setTimeout(() => {
- smoothScrollToBottom();
- }, 400);
- }, [smoothScrollToBottom, state.sessionId]);
+ // useEffect(() => {
+ // setTimeout(() => {
+ // smoothScrollToBottom();
+ // }, 400);
+ // }, [smoothScrollToBottom, state.sessionId]);
useEffect(() => {
// Cmd + Backspace to delete current step
@@ -288,7 +288,7 @@ export function Chat() {
setLocalStorage("mainTextEntryCounter", 1);
}
},
- [state.history, state.contextItems, defaultModel, state, streamResponse],
+ [state.history, defaultModel, state, streamResponse],
);
useWebviewListener(
diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts
index 34f844908..2d5cb1267 100644
--- a/gui/src/redux/slices/stateSlice.ts
+++ b/gui/src/redux/slices/stateSlice.ts
@@ -17,16 +17,6 @@ import { v4 as uuidv4, v4 } from "uuid";
import { RootState } from "../store";
import { ApplyState } from "core/protocol/ideWebview";
-export const memoizedContextItemsSelector = createSelector(
- [(state: RootState) => state.state.history],
- (history) => {
- return history.reduce((acc, item) => {
- acc.push(...item.contextItems);
- return acc;
- }, []);
- },
-);
-
// 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 & {
@@ -34,7 +24,6 @@ type ChatHistoryItemWithMessageId = ChatHistoryItem & {
};
type State = {
history: ChatHistoryItemWithMessageId[];
- contextItems: ContextItemWithId[];
ttsActive: boolean;
active: boolean;
isGatheringContext: boolean;
@@ -54,7 +43,6 @@ type State = {
const initialState: State = {
history: [],
- contextItems: [],
ttsActive: false,
active: false,
isGatheringContext: false,
@@ -152,9 +140,6 @@ export const stateSlice = createSlice({
state.history[index].contextItems = contextItems;
}
},
- addContextItems: (state, action: PayloadAction) => {
- state.contextItems = state.contextItems.concat(action.payload);
- },
resubmitAtIndex: (
state,
{
@@ -182,7 +167,6 @@ export const stateSlice = createSlice({
});
// https://github.com/continuedev/continue/pull/1021
- // state.contextItems = [];
state.active = true;
},
deleteMessage: (state, action: PayloadAction) => {
@@ -199,7 +183,7 @@ export const stateSlice = createSlice({
) => {
state.history.push({
message: { role: "user", content: "", id: uuidv4() },
- contextItems: state.contextItems,
+ contextItems: [],
editorState: payload.editorState,
});
state.history.push({
@@ -210,8 +194,7 @@ export const stateSlice = createSlice({
},
contextItems: [],
});
- // https://github.com/continuedev/continue/pull/1021
- // state.contextItems = [];
+
state.active = true;
state.curCheckpointIndex = state.curCheckpointIndex + 1;
},
@@ -284,7 +267,6 @@ export const stateSlice = createSlice({
state.curCheckpointIndex = 0;
} else {
state.history = [];
- state.contextItems = [];
state.active = false;
state.title = "New Session";
state.sessionId = v4();
@@ -292,71 +274,21 @@ export const stateSlice = createSlice({
state.curCheckpointIndex = 0;
}
},
- deleteContextWithIds: (
- state,
- {
- payload,
- }: PayloadAction<{ ids: ContextItemId[]; index: number | undefined }>,
- ) => {
- const getKey = (id: ContextItemId) => `${id.providerTitle}-${id.itemId}`;
- const ids = new Set(payload.ids.map(getKey));
-
- if (payload.index === undefined) {
- state.contextItems = state.contextItems.filter(
- (item) => !ids.has(getKey(item.id)),
- );
- } else {
- state.history[payload.index].contextItems = state.history[
- payload.index
- ].contextItems.filter((item) => !ids.has(getKey(item.id)));
- }
- },
addHighlightedCode: (
state,
{
payload,
}: PayloadAction<{ rangeInFileWithContents: any; edit: boolean }>,
) => {
- let contextItems = [...state.contextItems].map((item) => {
+ let contextItems =
+ state.history[state.history.length - 1].contextItems ?? [];
+ contextItems = contextItems.map((item) => {
return { ...item, editing: false };
});
const base = payload.rangeInFileWithContents.filepath
.split(/[\\/]/)
.pop();
- // Merge if there is overlap
- for (let i = 0; i < contextItems.length; i++) {
- const item = contextItems[i];
- if (item.description === payload.rangeInFileWithContents.filepath) {
- let newStart = payload.rangeInFileWithContents.range.start.line;
- let newEnd = payload.rangeInFileWithContents.range.end.line;
- let [oldStart, oldEnd] = item.name
- .split("(")[1]
- .split(")")[0]
- .split("-")
- .map((x: string) => parseInt(x) - 1);
- if (newStart > oldEnd || newEnd < oldStart) {
- continue;
- }
- const startLine = Math.min(newStart, oldStart);
- const endLine = Math.max(newEnd, oldEnd);
-
- // const oldContents = item.content.split("\n");
- // const newContents =
- // payload.rangeInFileWithContents.contents.split("\n");
- // const finalContents = [];
-
- contextItems[i] = {
- ...item,
- name: `${base} (${startLine + 1}-${endLine + 1})`,
- content: payload.rangeInFileWithContents.contents,
- editing: true,
- editable: true,
- };
- return { ...state, contextItems };
- }
- }
-
const lineNums = `(${
payload.rangeInFileWithContents.range.start.line + 1
}-${payload.rangeInFileWithContents.range.end.line + 1})`;
@@ -371,46 +303,7 @@ export const stateSlice = createSlice({
editing: true,
editable: true,
});
-
- return { ...state, contextItems };
- },
- setEditingAtIds: (
- state,
- {
- payload,
- }: PayloadAction<{ ids: ContextItemId[]; index: number | undefined }>,
- ) => {
- const ids = payload.ids.map((id) => id.itemId);
-
- if (typeof payload.index === "undefined") {
- return {
- ...state,
- contextItems: state.contextItems.map((item) => {
- return {
- ...item,
- editing: ids.includes(item.id.itemId),
- };
- }),
- };
- } else {
- return {
- ...state,
- history: state.history.map((step, i) => {
- if (i === payload.index) {
- return {
- ...step,
- contextItems: step.contextItems.map((item) => {
- return {
- ...item,
- editing: ids.includes(item.id.itemId),
- };
- }),
- };
- }
- return step;
- }),
- };
- }
+ state.history[state.history.length - 1].contextItems = contextItems;
},
setDefaultModel: (
state,
@@ -473,15 +366,12 @@ export const stateSlice = createSlice({
export const {
setContextItemsAtIndex,
- addContextItems,
addContextItemsAtIndex,
setInactive,
streamUpdate,
newSession,
- deleteContextWithIds,
resubmitAtIndex,
addHighlightedCode,
- setEditingAtIds,
setDefaultModel,
setConfig,
setConfigError,
diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts
index 5a6bc51f5..725d88c01 100644
--- a/gui/src/redux/store.ts
+++ b/gui/src/redux/store.ts
@@ -39,12 +39,7 @@ const windowIDTransform = (windowID: string) =>
);
const saveSubsetFilters = [
- createFilter("state", [
- "history",
- "contextItems",
- "sessionId",
- "defaultModelTitle",
- ]),
+ createFilter("state", ["history", "sessionId", "defaultModelTitle"]),
];
const persistConfig = {