Merge branch 'main' into pe/tsc-fix-find-widget
This commit is contained in:
commit
a9060131da
18 changed files with 167 additions and 282 deletions
|
|
@ -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.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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", {
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ Prompt files provide a convenient way to standardize common patterns and share a
|
|||
|
||||
## Quick start
|
||||
|
||||
:::tip[Prompt library]
|
||||
<!-- :::tip[Prompt library]
|
||||
To assist you in getting started, [we've curated a small library of `.prompt` files](https://github.com/continuedev/prompt-file-examples). We encourage community contributions to this repository, so please consider opening up a pull request with your own prompts!
|
||||
:::
|
||||
::: -->
|
||||
|
||||
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
|
||||
---
|
||||
<system>
|
||||
You are an expert programmer
|
||||
</system>
|
||||
|
||||
{{{ 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 <kbd>cmd/ctrl</kbd> + <kbd>L</kbd> 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 `<system></system>` 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
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<NodeViewWrapper className="code-block-with-content" as="p">
|
||||
<CodeSnippetPreview
|
||||
borderColor={
|
||||
item.id === contextItems[0]?.id
|
||||
isFirstContextItem
|
||||
? "#d0d"
|
||||
: selected
|
||||
? vscBadgeBackground
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import FileIcon from "../FileIcon";
|
|||
import SafeImg from "../SafeImg";
|
||||
import { INSTRUCTIONS_BASE_ITEM } from "core/context/providers/utils";
|
||||
import { getIconFromDropdownItem } from "./MentionList";
|
||||
import styled from "styled-components";
|
||||
import { getBasename } from "core/util";
|
||||
|
||||
interface ContextItemsPeekProps {
|
||||
|
|
|
|||
|
|
@ -225,10 +225,6 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
inDropdownRef.current = true;
|
||||
};
|
||||
|
||||
const contextItems = useSelector(
|
||||
(store: RootState) => 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,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<TopDiv>
|
||||
<TopDiv active={active}>
|
||||
<ToolbarDiv isExpanded={isExpanded} className="find-widget-skip">
|
||||
<div className="flex min-w-0 max-w-[45%] items-center">
|
||||
<ChevronDownIcon
|
||||
|
|
|
|||
|
|
@ -14,13 +14,12 @@ import {
|
|||
import { getFontSize, isJetBrains } from "../../util";
|
||||
import "./katex.css";
|
||||
import "./markdown.css";
|
||||
import { useSelector } from "react-redux";
|
||||
import { memoizedContextItemsSelector } from "../../redux/slices/stateSlice";
|
||||
import { ctxItemToRifWithContents } from "core/commands/util";
|
||||
import FilenameLink from "./FilenameLink";
|
||||
import StepContainerPreToolbar from "./StepContainerPreToolbar";
|
||||
import { SyntaxHighlightedPre } from "./SyntaxHighlightedPre";
|
||||
import StepContainerPreActionButtons from "./StepContainerPreActionButtons";
|
||||
import { ContextItemWithId } from "core";
|
||||
|
||||
const StyledMarkdown = styled.div<{
|
||||
fontSize?: number;
|
||||
|
|
@ -93,6 +92,7 @@ interface StyledMarkdownPreviewProps {
|
|||
className?: string;
|
||||
isRenderingInStepContainer?: boolean; // Currently only used to control the rendering of codeblocks
|
||||
scrollLocked?: boolean;
|
||||
contextItems?: ContextItemWithId[];
|
||||
}
|
||||
|
||||
const HLJS_LANGUAGE_CLASSNAME_PREFIX = "language-";
|
||||
|
|
@ -153,8 +153,6 @@ function processCodeBlocks(tree: any) {
|
|||
const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
|
||||
props: StyledMarkdownPreviewProps,
|
||||
) {
|
||||
const contextItems = useSelector(memoizedContextItemsSelector);
|
||||
|
||||
const [reactContent, setMarkdownSource] = useRemark({
|
||||
remarkPlugins: [remarkMath, () => 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 <FilenameLink rif={rif} />;
|
||||
if (props.contextItems) {
|
||||
const ctxItem = props.contextItems.find((ctxItem) =>
|
||||
ctxItem.uri?.value.includes(content),
|
||||
);
|
||||
if (ctxItem) {
|
||||
const rif = ctxItemToRifWithContents(ctxItem);
|
||||
return <FilenameLink rif={rif} />;
|
||||
}
|
||||
}
|
||||
|
||||
return <code {...codeProps}>{codeProps.children}</code>;
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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<any>) {
|
||||
const [configLoaded, setConfigLoaded] = useState<boolean>(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<any>) {
|
|||
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<any>) {
|
|||
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<any>) {
|
|||
}, 2_000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [configLoaded]);
|
||||
}, [initialConfigLoad, loadConfig]);
|
||||
|
||||
useEffect(() => {
|
||||
// Override persisted state
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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<ContextItemWithId[]>((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<ContextItemWithId[]>) => {
|
||||
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<number>) => {
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -39,12 +39,7 @@ const windowIDTransform = (windowID: string) =>
|
|||
);
|
||||
|
||||
const saveSubsetFilters = [
|
||||
createFilter("state", [
|
||||
"history",
|
||||
"contextItems",
|
||||
"sessionId",
|
||||
"defaultModelTitle",
|
||||
]),
|
||||
createFilter("state", ["history", "sessionId", "defaultModelTitle"]),
|
||||
];
|
||||
|
||||
const persistConfig = {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue