diff --git a/core/llm/constructMessages.ts b/core/llm/constructMessages.ts deleted file mode 100644 index dc9dbc8bf..000000000 --- a/core/llm/constructMessages.ts +++ /dev/null @@ -1,187 +0,0 @@ -import { - ChatHistoryItem, - ChatMessage, - ContextItemWithId, - RuleWithSource, - TextMessagePart, - ToolResultChatMessage, - UserChatMessage, -} from "../"; -import { findLast } from "../util/findLast"; -import { normalizeToMessageParts } from "../util/messageContent"; -import { isUserOrToolMsg } from "./messages"; -import { getSystemMessageWithRules } from "./rules/getSystemMessageWithRules"; -import { RulePolicies } from "./rules/types"; - -export const DEFAULT_CHAT_SYSTEM_MESSAGE_URL = - "https://github.com/continuedev/continue/blob/main/core/llm/constructMessages.ts"; - -export const DEFAULT_AGENT_SYSTEM_MESSAGE_URL = - "https://github.com/continuedev/continue/blob/main/core/llm/constructMessages.ts"; - -export const CODEBLOCK_FORMATTING_INSTRUCTIONS = `\ - Always include the language and file name in the info string when you write code blocks. - If you are editing "src/main.py" for example, your code block should start with '\`\`\`python src/main.py' -`; - -export const EDIT_CODE_INSTRUCTIONS = `\ - When addressing code modification requests, present a concise code snippet that - emphasizes only the necessary changes and uses abbreviated placeholders for - unmodified sections. For example: - - \`\`\`language /path/to/file - // ... existing code ... - - {{ modified code here }} - - // ... existing code ... - - {{ another modification }} - - // ... rest of code ... - \`\`\` - - In existing files, you should always restate the function or class that the snippet belongs to: - - \`\`\`language /path/to/file - // ... existing code ... - - function exampleFunction() { - // ... existing code ... - - {{ modified code here }} - - // ... rest of function ... - } - - // ... rest of code ... - \`\`\` - - Since users have access to their complete file, they prefer reading only the - relevant modifications. It's perfectly acceptable to omit unmodified portions - at the beginning, middle, or end of files using these "lazy" comments. Only - provide the complete file when explicitly requested. Include a concise explanation - of changes unless the user specifically asks for code only. -`; - -export const DEFAULT_CHAT_SYSTEM_MESSAGE = `\ - - You are in chat mode. - - If the user asks to make changes to files offer that they can use the Apply Button on the code block, or switch to Agent Mode to make the suggested updates automatically. - If needed consisely explain to the user they can switch to agent mode using the Mode Selector dropdown and provide no other details. - -${CODEBLOCK_FORMATTING_INSTRUCTIONS} -${EDIT_CODE_INSTRUCTIONS} -`; - -export const DEFAULT_AGENT_SYSTEM_MESSAGE = `\ - - You are in agent mode. - -${CODEBLOCK_FORMATTING_INSTRUCTIONS} -`; - -/** - * Helper function to get the context items for a user message - */ -function getUserContextItems( - userMsg: UserChatMessage | ToolResultChatMessage | undefined, - history: ChatHistoryItem[], -): ContextItemWithId[] { - if (!userMsg) return []; - - // Find the history item that contains the userMsg - const historyItem = history.find((item) => { - // Check if the message ID matches - if ("id" in userMsg && "id" in item.message) { - return (item.message as any).id === (userMsg as any).id; - } - // Fallback to content comparison - return ( - item.message.content === userMsg.content && - item.message.role === userMsg.role - ); - }); - - return historyItem?.contextItems || []; -} - -export function constructMessages( - messageMode: string, - history: ChatHistoryItem[], - baseChatOrAgentSystemMessage: string | undefined, - rules: RuleWithSource[], - rulePolicies?: RulePolicies, -): ChatMessage[] { - const filteredHistory = history.filter( - (item) => item.message.role !== "system", - ); - const msgs: ChatMessage[] = []; - - for (let i = 0; i < filteredHistory.length; i++) { - const historyItem = filteredHistory[i]; - - if (messageMode === "chat") { - const toolMessage: ToolResultChatMessage = - historyItem.message as ToolResultChatMessage; - if (historyItem.toolCallState?.toolCallId || toolMessage.toolCallId) { - // remove all tool calls from the history - continue; - } - } - - if (historyItem.message.role === "user") { - // Gather context items for user messages - let content = normalizeToMessageParts(historyItem.message); - - const ctxItems = historyItem.contextItems - .map((ctxItem) => { - return { - type: "text", - text: `${ctxItem.content}\n`, - } as TextMessagePart; - }) - .filter((part) => !!part.text.trim()); - - content = [...ctxItems, ...content]; - msgs.push({ - ...historyItem.message, - content, - }); - } else { - msgs.push(historyItem.message); - } - } - - const lastUserMsg = findLast(msgs, isUserOrToolMsg) as - | UserChatMessage - | ToolResultChatMessage - | undefined; - - // Get context items for the last user message - const lastUserContextItems = getUserContextItems( - lastUserMsg, - filteredHistory, - ); - const systemMessage = getSystemMessageWithRules({ - baseSystemMessage: baseChatOrAgentSystemMessage, - rules, - userMessage: lastUserMsg, - contextItems: lastUserContextItems, - rulePolicies, - }); - - if (systemMessage.trim()) { - msgs.unshift({ - role: "system", - content: systemMessage, - }); - } - - // Remove the "id" from all of the messages - return msgs.map((msg) => { - const { id, ...rest } = msg as any; - return rest; - }); -} diff --git a/core/llm/defaultSystemMessages.ts b/core/llm/defaultSystemMessages.ts index 64ea23dd0..c2f82bac4 100644 --- a/core/llm/defaultSystemMessages.ts +++ b/core/llm/defaultSystemMessages.ts @@ -4,10 +4,12 @@ export const DEFAULT_CHAT_SYSTEM_MESSAGE_URL = export const DEFAULT_AGENT_SYSTEM_MESSAGE_URL = "https://github.com/continuedev/continue/blob/main/core/llm/defaultSystemMessages.ts"; -const EDIT_MESSAGE = `\ +export const CODEBLOCK_FORMATTING_INSTRUCTIONS = `\ Always include the language and file name in the info string when you write code blocks. If you are editing "src/main.py" for example, your code block should start with '\`\`\`python src/main.py' +`; +export const EDIT_CODE_INSTRUCTIONS = `\ When addressing code modification requests, present a concise code snippet that emphasizes only the necessary changes and uses abbreviated placeholders for unmodified sections. For example: @@ -54,12 +56,13 @@ export const DEFAULT_CHAT_SYSTEM_MESSAGE = `\ If the user asks to make changes to files offer that they can use the Apply Button on the code block, or switch to Agent Mode to make the suggested updates automatically. If needed consisely explain to the user they can switch to agent mode using the Mode Selector dropdown and provide no other details. -${EDIT_MESSAGE} +${CODEBLOCK_FORMATTING_INSTRUCTIONS} +${EDIT_CODE_INSTRUCTIONS} `; export const DEFAULT_AGENT_SYSTEM_MESSAGE = `\ You are in agent mode. -${EDIT_MESSAGE} +${CODEBLOCK_FORMATTING_INSTRUCTIONS} `; diff --git a/gui/src/components/mainInput/belowMainInput/ContextItemsPeek.tsx b/gui/src/components/mainInput/belowMainInput/ContextItemsPeek.tsx index 14d44fadf..4b344ecea 100644 --- a/gui/src/components/mainInput/belowMainInput/ContextItemsPeek.tsx +++ b/gui/src/components/mainInput/belowMainInput/ContextItemsPeek.tsx @@ -122,13 +122,8 @@ export function ContextItemsPeekItem({ return (
openContextItem(contextItem, ideMessenger)} - className="group mr-2 flex cursor-pointer items-center overflow-hidden text-ellipsis whitespace-nowrap rounded px-1.5 py-1 text-xs hover:bg-white/10" ->>>>>>> d22ab74b15007ff7d84e3462bd344080305e1dc9 + className="mr-2 flex cursor-pointer flex-row items-center gap-1.5 whitespace-nowrap rounded px-1.5 py-1 text-xs hover:bg-white/10" data-testid="context-items-peek-item" > {getContextItemIcon()} diff --git a/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx b/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx index 059f6e20b..07c547468 100644 --- a/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx +++ b/gui/src/pages/gui/ToolCallDiv/SimpleToolCallUI.tsx @@ -1,17 +1,11 @@ import { ChevronRightIcon } from "@heroicons/react/24/outline"; -<<<<<<< HEAD import { Tool, ToolCallState } from "core"; -import { ComponentType, useMemo, useState } from "react"; -import { ContextItemsPeekItem } from "../../../components/mainInput/belowMainInput/ContextItemsPeek"; -======= -import { ContextItemWithId, Tool, ToolCallState } from "core"; import { ComponentType, useContext, useMemo, useState } from "react"; import { ContextItemsPeekItem, openContextItem, } from "../../../components/mainInput/belowMainInput/ContextItemsPeek"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; ->>>>>>> d22ab74b15007ff7d84e3462bd344080305e1dc9 import { ArgsItems, ArgsToggleIcon } from "./ToolCallArgs"; import { toolCallStateToContextItems } from "./toolCallStateToContextItem"; import { ToolCallStatusMessage } from "./ToolCallStatusMessage"; @@ -30,18 +24,11 @@ export function SimpleToolCallUI({ tool, historyIndex, }: SimpleToolCallUIProps) { -<<<<<<< HEAD + const ideMessenger = useContext(IdeMessengerContext); const shownContextItems = useMemo(() => { const contextItems = toolCallStateToContextItems(toolCallState); return contextItems.filter((item) => !item.hidden); }, [toolCallState]); -======= - const ideMessenger = useContext(IdeMessengerContext); - - const ctxItems = useMemo(() => { - return contextItems?.filter((ctxItem) => !ctxItem.hidden) ?? []; - }, [contextItems]); ->>>>>>> d22ab74b15007ff7d84e3462bd344080305e1dc9 const [open, setOpen] = useState(false); const [isHovered, setIsHovered] = useState(false); @@ -51,8 +38,8 @@ export function SimpleToolCallUI({ return Object.entries(toolCallState.parsedArgs); }, [toolCallState.parsedArgs]); - const isToggleable = ctxItems.length > 1; - const isSingleItem = ctxItems.length === 1; + const isToggleable = shownContextItems.length > 1; + const isSingleItem = shownContextItems.length === 1; const shouldShowContent = isToggleable ? open : false; const isClickable = isToggleable || isSingleItem; @@ -60,7 +47,7 @@ export function SimpleToolCallUI({ if (isToggleable) { setOpen((prev) => !prev); } else if (isSingleItem) { - openContextItem(ctxItems[0], ideMessenger); + openContextItem(shownContextItems[0], ideMessenger); } } @@ -102,7 +89,6 @@ export function SimpleToolCallUI({
-<<<<<<< HEAD
{!!toolCallState.output?.length && ( @@ -116,31 +102,6 @@ export function SimpleToolCallUI({ ) : null}
- -
- {shownContextItems.length ? ( - shownContextItems.map((contextItem, idx) => ( - - )) - ) : ( -
- No tool call output -
-======= - {args.length > 0 && ( - ->>>>>>> d22ab74b15007ff7d84e3462bd344080305e1dc9 - )} -
- {isToggleable && ( @@ -149,8 +110,8 @@ export function SimpleToolCallUI({ shouldShowContent ? "max-h-[50vh] opacity-100" : "max-h-0 opacity-0" }`} > - {ctxItems.length > 0 ? ( - ctxItems.map((contextItem, idx) => ( + {shownContextItems.length > 0 ? ( + shownContextItems.map((contextItem, idx) => ( )) ) : (