commit
fbcc5a46b9
21 changed files with 312 additions and 132 deletions
|
|
@ -643,6 +643,7 @@ function llmToSerializedModelDescription(llm: ILLM): ModelDescription {
|
|||
template: llm.template,
|
||||
completionOptions: llm.completionOptions,
|
||||
baseAgentSystemMessage: llm.baseAgentSystemMessage,
|
||||
basePlanSystemMessage: llm.basePlanSystemMessage,
|
||||
baseChatSystemMessage: llm.baseChatSystemMessage,
|
||||
requestOptions: llm.requestOptions,
|
||||
promptTemplates: serializePromptTemplates(llm.promptTemplates),
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ async function modelConfigToBaseLLM({
|
|||
template: model.promptTemplates?.chat,
|
||||
promptTemplates: model.promptTemplates,
|
||||
baseAgentSystemMessage: model.chatOptions?.baseAgentSystemMessage,
|
||||
basePlanSystemMessage: model.chatOptions?.basePlanSystemMessage,
|
||||
baseChatSystemMessage: model.chatOptions?.baseSystemMessage,
|
||||
capabilities: {
|
||||
tools: model.capabilities?.includes("tool_use"),
|
||||
|
|
|
|||
10
core/index.d.ts
vendored
10
core/index.d.ts
vendored
|
|
@ -428,7 +428,7 @@ export interface PromptLog {
|
|||
completion: string;
|
||||
}
|
||||
|
||||
export type MessageModes = "chat" | "agent";
|
||||
export type MessageModes = "chat" | "agent" | "plan";
|
||||
|
||||
export type ToolStatus =
|
||||
| "generating"
|
||||
|
|
@ -568,6 +568,7 @@ export interface LLMOptions {
|
|||
title?: string;
|
||||
uniqueId?: string;
|
||||
baseAgentSystemMessage?: string;
|
||||
basePlanSystemMessage?: string;
|
||||
baseChatSystemMessage?: string;
|
||||
autocompleteOptions?: Partial<TabAutocompleteOptions>;
|
||||
contextLength?: number;
|
||||
|
|
@ -1091,6 +1092,7 @@ export interface ModelDescription {
|
|||
template?: TemplateType;
|
||||
completionOptions?: BaseCompletionOptions;
|
||||
baseAgentSystemMessage?: string;
|
||||
basePlanSystemMessage?: string;
|
||||
baseChatSystemMessage?: string;
|
||||
requestOptions?: RequestOptions;
|
||||
promptTemplates?: { [key: string]: string };
|
||||
|
|
@ -1637,9 +1639,11 @@ export interface TerminalOptions {
|
|||
|
||||
export type RuleSource =
|
||||
| "default-chat"
|
||||
| "default-plan"
|
||||
| "default-agent"
|
||||
| "model-chat-options"
|
||||
| "model-agent-options"
|
||||
| "model-options-chat"
|
||||
| "model-options-plan"
|
||||
| "model-options-agent"
|
||||
| "rules-block"
|
||||
| "json-systemMessage"
|
||||
| ".continuerules";
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
export const DEFAULT_CHAT_SYSTEM_MESSAGE_URL =
|
||||
"https://github.com/continuedev/continue/blob/main/core/llm/defaultSystemMessages.ts";
|
||||
|
||||
export const DEFAULT_AGENT_SYSTEM_MESSAGE_URL =
|
||||
export const DEFAULT_SYSTEM_MESSAGES_URL =
|
||||
"https://github.com/continuedev/continue/blob/main/core/llm/defaultSystemMessages.ts";
|
||||
|
||||
export const CODEBLOCK_FORMATTING_INSTRUCTIONS = `\
|
||||
|
|
@ -66,3 +63,17 @@ export const DEFAULT_AGENT_SYSTEM_MESSAGE = `\
|
|||
|
||||
${CODEBLOCK_FORMATTING_INSTRUCTIONS}
|
||||
</important_rules>`;
|
||||
|
||||
// The note about read-only tools is for MCP servers
|
||||
// For now, all MCP tools are included so model can decide if they are read-only
|
||||
export const DEFAULT_PLAN_SYSTEM_MESSAGE = `\
|
||||
<important_rules>
|
||||
You are in plan mode, in which you help the user understand and construct a plan.
|
||||
Only use read-only tools. Do not use any tools that would write to non-temporary files.
|
||||
If the user wants to make changes, offer that they can switch to Agent mode to give you access to write tools to make the suggested updates.
|
||||
|
||||
${CODEBLOCK_FORMATTING_INSTRUCTIONS}
|
||||
${EDIT_CODE_INSTRUCTIONS}
|
||||
|
||||
In plan mode, only write code when directly suggesting changes. Prioritize understanding and developing a plan.
|
||||
</important_rules>`;
|
||||
|
|
|
|||
|
|
@ -141,6 +141,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
|
||||
title?: string;
|
||||
baseChatSystemMessage?: string;
|
||||
basePlanSystemMessage?: string;
|
||||
baseAgentSystemMessage?: string;
|
||||
contextLength: number;
|
||||
maxStopWords?: number | undefined;
|
||||
|
|
@ -209,6 +210,7 @@ export abstract class BaseLLM implements ILLM {
|
|||
this.title = options.title;
|
||||
this.uniqueId = options.uniqueId ?? "None";
|
||||
this.baseAgentSystemMessage = options.baseAgentSystemMessage;
|
||||
this.basePlanSystemMessage = options.basePlanSystemMessage;
|
||||
this.baseChatSystemMessage = options.baseChatSystemMessage;
|
||||
this.contextLength =
|
||||
options.contextLength ?? llmInfo?.contextLength ?? DEFAULT_CONTEXT_LENGTH;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import {
|
|||
LLMOptions,
|
||||
} from "../..";
|
||||
import { renderTemplatedString } from "../../util/handlebars/renderTemplatedString";
|
||||
import { DEFAULT_CHAT_SYSTEM_MESSAGE } from "../defaultSystemMessages";
|
||||
import { BaseLLM } from "../index";
|
||||
import Anthropic from "./Anthropic";
|
||||
import Asksage from "./Asksage";
|
||||
|
|
@ -141,9 +140,9 @@ export async function llmFromDescription(
|
|||
|
||||
let baseChatSystemMessage: string | undefined = undefined;
|
||||
if (desc.systemMessage !== undefined) {
|
||||
baseChatSystemMessage = DEFAULT_CHAT_SYSTEM_MESSAGE;
|
||||
baseChatSystemMessage += "\n\n";
|
||||
baseChatSystemMessage += await renderTemplatedString(
|
||||
// baseChatSystemMessage = DEFAULT_CHAT_SYSTEM_MESSAGE;
|
||||
// baseChatSystemMessage += "\n\n";
|
||||
baseChatSystemMessage = await renderTemplatedString(
|
||||
Handlebars,
|
||||
desc.systemMessage,
|
||||
{},
|
||||
|
|
@ -163,6 +162,7 @@ export async function llmFromDescription(
|
|||
cls.defaultOptions?.completionOptions?.maxTokens,
|
||||
},
|
||||
baseChatSystemMessage,
|
||||
basePlanSystemMessage: baseChatSystemMessage,
|
||||
baseAgentSystemMessage: baseChatSystemMessage,
|
||||
logger: llmLogger,
|
||||
uniqueId,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
import { ChatBubbleLeftIcon, SparklesIcon } from "@heroicons/react/24/outline";
|
||||
import {
|
||||
ChatBubbleLeftIcon,
|
||||
SparklesIcon,
|
||||
SwatchIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { MessageModes } from "core";
|
||||
|
||||
interface ModeIconProps {
|
||||
|
|
@ -13,6 +17,8 @@ export function ModeIcon({
|
|||
switch (mode) {
|
||||
case "agent":
|
||||
return <SparklesIcon className={className} />;
|
||||
case "plan":
|
||||
return <SwatchIcon className={className} />;
|
||||
case "chat":
|
||||
return <ChatBubbleLeftIcon className={className} />;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
import { CheckIcon, ChevronDownIcon } from "@heroicons/react/24/outline";
|
||||
import {
|
||||
CheckIcon,
|
||||
ChevronDownIcon,
|
||||
InformationCircleIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { MessageModes } from "core";
|
||||
import { modelSupportsTools } from "core/llm/autodetect";
|
||||
import { useCallback, useEffect, useMemo } from "react";
|
||||
|
|
@ -6,6 +10,7 @@ import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
|||
import { selectSelectedChatModel } from "../../redux/slices/configSlice";
|
||||
import { setMode } from "../../redux/slices/sessionSlice";
|
||||
import { getFontSize, getMetaKeyLabel } from "../../util";
|
||||
import { ToolTip } from "../gui/Tooltip";
|
||||
import { useMainEditor } from "../mainInput/TipTapEditor";
|
||||
import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from "../ui";
|
||||
import { ModeIcon } from "./ModeIcon";
|
||||
|
|
@ -27,13 +32,19 @@ export function ModeSelect() {
|
|||
if (!selectedModel) {
|
||||
return;
|
||||
}
|
||||
if (mode === "agent" && !agentModeSupported) {
|
||||
if (mode !== "chat" && !agentModeSupported) {
|
||||
dispatch(setMode("chat"));
|
||||
}
|
||||
}, [mode, agentModeSupported, dispatch, selectedModel]);
|
||||
|
||||
const cycleMode = useCallback(() => {
|
||||
dispatch(setMode(mode === "chat" ? "agent" : "chat"));
|
||||
if (mode === "chat") {
|
||||
dispatch(setMode("plan"));
|
||||
} else if (mode === "plan") {
|
||||
dispatch(setMode("agent"));
|
||||
} else {
|
||||
dispatch(setMode("chat"));
|
||||
}
|
||||
// Only focus main editor if another one doesn't already have focus
|
||||
if (!document.activeElement?.classList?.contains("ProseMirror")) {
|
||||
mainEditor?.commands.focus();
|
||||
|
|
@ -74,7 +85,7 @@ export function ModeSelect() {
|
|||
>
|
||||
<ModeIcon mode={mode} />
|
||||
<span className="hidden sm:block">
|
||||
{mode.charAt(0).toUpperCase() + mode.slice(1)}
|
||||
{mode === "chat" ? "Chat" : mode === "agent" ? "Agent" : "Plan"}
|
||||
</span>
|
||||
<ChevronDownIcon
|
||||
className="h-2 w-2 flex-shrink-0"
|
||||
|
|
@ -94,7 +105,35 @@ export function ModeSelect() {
|
|||
</div>
|
||||
{mode === "chat" && <CheckIcon className="ml-auto h-3 w-3" />}
|
||||
</ListboxOption>
|
||||
|
||||
<ListboxOption
|
||||
value="plan"
|
||||
disabled={!agentModeSupported}
|
||||
className={"gap-1"}
|
||||
>
|
||||
<div className="flex flex-row items-center gap-1.5">
|
||||
<ModeIcon mode="plan" />
|
||||
<span className="">Plan</span>
|
||||
<InformationCircleIcon
|
||||
data-tooltip-id="plan-tip"
|
||||
className="h-2.5 w-2.5 flex-shrink-0"
|
||||
/>
|
||||
<ToolTip
|
||||
id="plan-tip"
|
||||
style={{
|
||||
zIndex: 200001,
|
||||
}}
|
||||
>
|
||||
In Plan mode, only read-only and MCP tools are enabled
|
||||
</ToolTip>
|
||||
</div>
|
||||
{agentModeSupported ? (
|
||||
<CheckIcon
|
||||
className={`ml-auto h-3 w-3 ${mode === "plan" ? "" : "opacity-0"}`}
|
||||
/>
|
||||
) : (
|
||||
<span>(Not supported)</span>
|
||||
)}
|
||||
</ListboxOption>
|
||||
<ListboxOption
|
||||
value="agent"
|
||||
disabled={!agentModeSupported}
|
||||
|
|
@ -103,9 +142,23 @@ export function ModeSelect() {
|
|||
<div className="flex flex-row items-center gap-1.5">
|
||||
<ModeIcon mode="agent" />
|
||||
<span className="">Agent</span>
|
||||
<InformationCircleIcon
|
||||
data-tooltip-id="agent-tip"
|
||||
className="h-2.5 w-2.5 flex-shrink-0"
|
||||
/>
|
||||
<ToolTip
|
||||
id="agent-tip"
|
||||
style={{
|
||||
zIndex: 200001,
|
||||
}}
|
||||
>
|
||||
All tools are enabled based on policies
|
||||
</ToolTip>
|
||||
</div>
|
||||
{agentModeSupported ? (
|
||||
mode === "agent" && <CheckIcon className="ml-auto h-3 w-3" />
|
||||
<CheckIcon
|
||||
className={`ml-auto h-3 w-3 ${mode === "agent" ? "" : "opacity-0"}`}
|
||||
/>
|
||||
) : (
|
||||
<span>(Not supported)</span>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ type ToggleSwitchProps = {
|
|||
text: string;
|
||||
size?: number;
|
||||
showIfToggled?: ReactNode;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
const ToggleSwitch: React.FC<ToggleSwitchProps> = ({
|
||||
|
|
@ -15,15 +16,18 @@ const ToggleSwitch: React.FC<ToggleSwitchProps> = ({
|
|||
text,
|
||||
size = 16,
|
||||
showIfToggled,
|
||||
disabled = false,
|
||||
}) => {
|
||||
return (
|
||||
<div className="flex cursor-pointer select-none items-center justify-between gap-3">
|
||||
<div
|
||||
className={`flex select-none items-center justify-between gap-3 ${disabled ? "cursor-not-allowed" : "cursor-pointer"}`}
|
||||
>
|
||||
<span className="truncate-right">{text}</span>
|
||||
<div className="flex flex-row items-center gap-1">
|
||||
{isToggled && !!showIfToggled && showIfToggled}
|
||||
<div
|
||||
className={`border-vsc-input-border bg-vsc-input-background flex items-center rounded-full border border-solid`}
|
||||
onClick={onToggle}
|
||||
onClick={disabled ? undefined : onToggle}
|
||||
style={{
|
||||
height: size,
|
||||
width: size * 2,
|
||||
|
|
|
|||
|
|
@ -7,9 +7,8 @@ import {
|
|||
import { RuleWithSource } from "core";
|
||||
import {
|
||||
DEFAULT_AGENT_SYSTEM_MESSAGE,
|
||||
DEFAULT_AGENT_SYSTEM_MESSAGE_URL,
|
||||
DEFAULT_CHAT_SYSTEM_MESSAGE,
|
||||
DEFAULT_CHAT_SYSTEM_MESSAGE_URL,
|
||||
DEFAULT_SYSTEM_MESSAGES_URL,
|
||||
} from "core/llm/defaultSystemMessages";
|
||||
import { useContext, useMemo } from "react";
|
||||
import { useAuth } from "../../../../context/Auth";
|
||||
|
|
@ -52,10 +51,12 @@ const RuleCard: React.FC<RuleCardProps> = ({ rule }) => {
|
|||
ideMessenger.post("openFile", {
|
||||
path: rule.ruleFile,
|
||||
});
|
||||
} else if (rule.source === "default-chat" && mode === "chat") {
|
||||
ideMessenger.post("openUrl", DEFAULT_CHAT_SYSTEM_MESSAGE_URL);
|
||||
} else if (rule.source === "default-agent" && mode === "agent") {
|
||||
ideMessenger.post("openUrl", DEFAULT_AGENT_SYSTEM_MESSAGE_URL);
|
||||
} else if (
|
||||
rule.source === "default-chat" ||
|
||||
rule.source === "default-plan" ||
|
||||
rule.source === "default-agent"
|
||||
) {
|
||||
ideMessenger.post("openUrl", DEFAULT_SYSTEM_MESSAGES_URL);
|
||||
} else {
|
||||
ideMessenger.post("config/openProfile", {
|
||||
profileId: undefined,
|
||||
|
|
@ -81,9 +82,11 @@ const RuleCard: React.FC<RuleCardProps> = ({ rule }) => {
|
|||
return "Default agent system message";
|
||||
} else if (rule.source === "json-systemMessage") {
|
||||
return "JSON systemMessage)";
|
||||
} else if (rule.source === "model-agent-options") {
|
||||
} else if (rule.source === "model-options-agent") {
|
||||
return "Base System Agent Message";
|
||||
} else if (rule.source === "model-chat-options") {
|
||||
} else if (rule.source === "model-options-plan") {
|
||||
return "Base System Plan Message";
|
||||
} else if (rule.source === "model-options-chat") {
|
||||
return "Base System Chat Message";
|
||||
} else {
|
||||
return "Assistant rule";
|
||||
|
|
@ -215,11 +218,24 @@ export function RulesSection() {
|
|||
}
|
||||
}
|
||||
|
||||
if (mode === "agent") {
|
||||
if (mode === "chat") {
|
||||
if (config.selectedModelByRole.chat?.baseChatSystemMessage) {
|
||||
rules.unshift({
|
||||
rule: config.selectedModelByRole.chat?.baseChatSystemMessage,
|
||||
source: "model-options-chat",
|
||||
});
|
||||
} else {
|
||||
rules.unshift({
|
||||
rule: DEFAULT_CHAT_SYSTEM_MESSAGE,
|
||||
source: "default-chat",
|
||||
});
|
||||
}
|
||||
} else if (mode === "agent") {
|
||||
// agent
|
||||
if (config.selectedModelByRole.chat?.baseAgentSystemMessage) {
|
||||
rules.unshift({
|
||||
rule: config.selectedModelByRole.chat?.baseAgentSystemMessage,
|
||||
source: "model-agent-options",
|
||||
source: "model-options-agent",
|
||||
});
|
||||
} else {
|
||||
rules.unshift({
|
||||
|
|
@ -228,15 +244,16 @@ export function RulesSection() {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
if (config.selectedModelByRole.chat?.baseChatSystemMessage) {
|
||||
// plan
|
||||
if (config.selectedModelByRole.chat?.basePlanSystemMessage) {
|
||||
rules.unshift({
|
||||
rule: config.selectedModelByRole.chat?.baseChatSystemMessage,
|
||||
source: "model-chat-options",
|
||||
rule: config.selectedModelByRole.chat?.basePlanSystemMessage,
|
||||
source: "model-options-plan",
|
||||
});
|
||||
} else {
|
||||
rules.unshift({
|
||||
rule: DEFAULT_CHAT_SYSTEM_MESSAGE,
|
||||
source: "default-chat",
|
||||
rule: DEFAULT_AGENT_SYSTEM_MESSAGE,
|
||||
source: "default-agent",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { InformationCircleIcon } from "@heroicons/react/24/outline";
|
||||
import { Tool } from "core";
|
||||
import { useMemo } from "react";
|
||||
import { useAppDispatch, useAppSelector } from "../../../../../redux/hooks";
|
||||
|
|
@ -6,7 +7,26 @@ import { fontSize } from "../../../../../util";
|
|||
import ToggleSwitch from "../../../../gui/Switch";
|
||||
import ToolPolicyItem from "./ToolPolicyItem";
|
||||
|
||||
interface ModeBadgeProps {
|
||||
text: string;
|
||||
icon: React.ReactNode;
|
||||
onClick: () => void;
|
||||
isSelected: boolean;
|
||||
}
|
||||
const ModeBadge = ({ text, onClick, isSelected, icon }: ModeBadgeProps) => {
|
||||
return (
|
||||
<div
|
||||
className="flex flex-1 items-center justify-center gap-1.5 text-sm"
|
||||
onClick={isSelected ? undefined : onClick}
|
||||
>
|
||||
{icon}
|
||||
{text}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const ToolPoliciesSection = () => {
|
||||
const mode = useAppSelector((state) => state.session.mode);
|
||||
const availableTools = useAppSelector((state) => state.config.config.tools);
|
||||
const toolGroupSettings = useAppSelector(
|
||||
(store) => store.ui.toolGroupSettings,
|
||||
|
|
@ -39,38 +59,56 @@ export const ToolPoliciesSection = () => {
|
|||
);
|
||||
}, [availableTools]);
|
||||
|
||||
const allToolsOff = mode === "chat";
|
||||
|
||||
const message =
|
||||
mode === "chat"
|
||||
? "All tools are disabled in Chat mode"
|
||||
: mode === "plan"
|
||||
? "Plan mode: only read-only and MCP tools"
|
||||
: "Agent mode: all tool policies apply";
|
||||
|
||||
return (
|
||||
<>
|
||||
{toolsByGroup.map(([groupName, tools]) => (
|
||||
<div key={groupName} className="mt-2 flex flex-col pr-1">
|
||||
<div className="flex flex-row items-center justify-between px-1">
|
||||
<h3
|
||||
className="m-0 p-0 font-bold"
|
||||
style={{
|
||||
fontSize: fontSize(-2),
|
||||
}}
|
||||
>
|
||||
{groupName}
|
||||
</h3>
|
||||
<ToggleSwitch
|
||||
isToggled={toolGroupSettings[groupName] !== "exclude"}
|
||||
onToggle={() => dispatch(toggleToolGroupSetting(groupName))}
|
||||
text=""
|
||||
size={10}
|
||||
/>
|
||||
</div>
|
||||
<div className={`relative flex flex-col p-1`}>
|
||||
{tools.map((tool) => (
|
||||
<ToolPolicyItem
|
||||
key={tool.uri + tool.function.name}
|
||||
tool={tool}
|
||||
duplicatesDetected={duplicateDetection[tool.function.name]}
|
||||
excluded={toolGroupSettings[groupName] === "exclude"}
|
||||
<div className="mb-3 px-1">
|
||||
<InformationCircleIcon className="text-description-muted mr-1.5 inline-block h-2.5 w-2.5 flex-shrink-0" />
|
||||
<span className="text-description text-xs italic">{message}</span>
|
||||
</div>
|
||||
{toolsByGroup.map(([groupName, tools]) => {
|
||||
const isGroupEnabled =
|
||||
!allToolsOff && toolGroupSettings[groupName] !== "exclude";
|
||||
return (
|
||||
<div key={groupName} className="mt-2 flex flex-col pr-1">
|
||||
<div className="flex flex-row items-center justify-between px-1">
|
||||
<h3
|
||||
className="m-0 p-0 font-bold"
|
||||
style={{
|
||||
fontSize: fontSize(-2),
|
||||
}}
|
||||
>
|
||||
{groupName}
|
||||
</h3>
|
||||
<ToggleSwitch
|
||||
isToggled={isGroupEnabled}
|
||||
onToggle={() => dispatch(toggleToolGroupSetting(groupName))}
|
||||
text=""
|
||||
size={10}
|
||||
disabled={allToolsOff}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className={`relative flex flex-col p-1`}>
|
||||
{tools.map((tool) => (
|
||||
<ToolPolicyItem
|
||||
key={tool.uri + tool.function.name}
|
||||
tool={tool}
|
||||
duplicatesDetected={duplicateDetection[tool.function.name]}
|
||||
isGroupEnabled={isGroupEnabled}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {
|
|||
InformationCircleIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { Tool } from "core";
|
||||
import { BUILT_IN_GROUP_NAME } from "core/tools/builtIn";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { useAppSelector } from "../../../../../redux/hooks";
|
||||
|
|
@ -16,7 +17,7 @@ import { useFontSize } from "../../../../ui/font";
|
|||
interface ToolDropdownItemProps {
|
||||
tool: Tool;
|
||||
duplicatesDetected: boolean;
|
||||
excluded: boolean;
|
||||
isGroupEnabled: boolean;
|
||||
}
|
||||
|
||||
function ToolPolicyItem(props: ToolDropdownItemProps) {
|
||||
|
|
@ -25,6 +26,7 @@ function ToolPolicyItem(props: ToolDropdownItemProps) {
|
|||
(state) => state.ui.toolSettings[props.tool.function.name],
|
||||
);
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
const mode = useAppSelector((state) => state.session.mode);
|
||||
|
||||
useEffect(() => {
|
||||
if (!policy) {
|
||||
|
|
@ -44,6 +46,12 @@ function ToolPolicyItem(props: ToolDropdownItemProps) {
|
|||
|
||||
const fontSize = useFontSize(-2);
|
||||
|
||||
const disabled =
|
||||
!props.isGroupEnabled ||
|
||||
(mode === "plan" &&
|
||||
props.tool.group === BUILT_IN_GROUP_NAME &&
|
||||
!props.tool.readonly);
|
||||
|
||||
if (!policy) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -106,16 +114,21 @@ function ToolPolicyItem(props: ToolDropdownItemProps) {
|
|||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={`flex w-8 flex-row items-center justify-end gap-2 px-2 py-0.5 sm:w-16 ${props.excluded ? "cursor-not-allowed" : "hover:bg-list-active hover:text-list-active-foreground cursor-pointer"}`}
|
||||
className={`flex w-8 flex-row items-center justify-end gap-2 px-2 py-0.5 sm:w-16 ${disabled ? "cursor-not-allowed" : "hover:bg-list-active hover:text-list-active-foreground cursor-pointer"}`}
|
||||
data-testid={`tool-policy-item-${props.tool.function.name}`}
|
||||
onClick={(e) => {
|
||||
dispatch(toggleToolSetting(props.tool.function.name));
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}}
|
||||
onClick={
|
||||
disabled
|
||||
? undefined
|
||||
: (e) => {
|
||||
dispatch(toggleToolSetting(props.tool.function.name));
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
>
|
||||
{props.excluded || policy === "disabled" ? (
|
||||
{disabled || policy === "disabled" ? (
|
||||
<>
|
||||
<span className="text-lightgray sm:hidden">Off</span>
|
||||
<span className="text-lightgray hidden sm:inline-block">
|
||||
|
|
|
|||
|
|
@ -19,9 +19,11 @@ const getSourceLabel = (source: RuleSource): string => {
|
|||
return "Default Chat";
|
||||
case "default-agent":
|
||||
return "Default Agent";
|
||||
case "model-chat-options":
|
||||
case "model-options-chat":
|
||||
return "Model Chat Options";
|
||||
case "model-agent-options":
|
||||
case "model-options-plan":
|
||||
return "Model Plan Options";
|
||||
case "model-options-agent":
|
||||
return "Model Agent Options";
|
||||
case "rules-block":
|
||||
return "Rules Block";
|
||||
|
|
|
|||
|
|
@ -27,6 +27,18 @@ test("should be able to toggle modes", async () => {
|
|||
);
|
||||
});
|
||||
|
||||
// Check that it switched to Plan mode
|
||||
await getElementByText("Plan");
|
||||
|
||||
act(() => {
|
||||
document.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: ".",
|
||||
metaKey: true, // cmd key on Mac
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
// Check that it switched to Agent mode
|
||||
await getElementByText("Agent");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { createSelector } from "@reduxjs/toolkit";
|
||||
import { Tool } from "core";
|
||||
import { BUILT_IN_GROUP_NAME } from "core/tools/builtIn";
|
||||
import { RootState } from "../store";
|
||||
|
||||
export const selectActiveTools = createSelector(
|
||||
|
|
@ -12,14 +13,18 @@ export const selectActiveTools = createSelector(
|
|||
(mode, tools, policies, groupPolicies): Tool[] => {
|
||||
if (mode === "chat") {
|
||||
return [];
|
||||
} else if (mode === "agent") {
|
||||
return tools.filter(
|
||||
} else {
|
||||
const enabledTools = tools.filter(
|
||||
(tool) =>
|
||||
policies[tool.function.name] !== "disabled" &&
|
||||
groupPolicies[tool.group] !== "exclude",
|
||||
);
|
||||
} else {
|
||||
return [];
|
||||
if (mode === "plan") {
|
||||
return enabledTools.filter(
|
||||
(t) => t.group !== BUILT_IN_GROUP_NAME || t.readonly,
|
||||
);
|
||||
}
|
||||
return enabledTools;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -75,52 +75,49 @@ export const streamEditThunk = createAsyncThunk<
|
|||
|
||||
export const exitEdit = createAsyncThunk<
|
||||
void,
|
||||
{ goToMode?: MessageModes; openNewSession?: boolean },
|
||||
{ openNewSession?: boolean },
|
||||
ThunkApiType
|
||||
>(
|
||||
"edit/exit",
|
||||
async ({ goToMode, openNewSession }, { dispatch, extra, getState }) => {
|
||||
const state = getState();
|
||||
const codeToEdit = state.editModeState.codeToEdit;
|
||||
const isInEdit = state.session.isInEdit;
|
||||
const previousModeEditorContent =
|
||||
state.editModeState.previousModeEditorContent;
|
||||
>("edit/exit", async ({ openNewSession }, { dispatch, extra, getState }) => {
|
||||
const state = getState();
|
||||
const codeToEdit = state.editModeState.codeToEdit;
|
||||
const isInEdit = state.session.isInEdit;
|
||||
const previousModeEditorContent =
|
||||
state.editModeState.previousModeEditorContent;
|
||||
|
||||
if (!isInEdit) {
|
||||
return;
|
||||
}
|
||||
if (!isInEdit) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (codeToEdit[0] && state.editModeState.applyState.numDiffs) {
|
||||
extra.ideMessenger.post("rejectDiff", {
|
||||
filepath: codeToEdit[0].filepath,
|
||||
});
|
||||
}
|
||||
if (codeToEdit[0] && state.editModeState.applyState.numDiffs) {
|
||||
extra.ideMessenger.post("rejectDiff", {
|
||||
filepath: codeToEdit[0].filepath,
|
||||
});
|
||||
}
|
||||
|
||||
extra.ideMessenger.post("edit/clearDecorations", undefined);
|
||||
extra.ideMessenger.post("edit/clearDecorations", undefined);
|
||||
|
||||
dispatch(clearCodeToEdit());
|
||||
dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE));
|
||||
dispatch(setIsInEdit(false));
|
||||
dispatch(clearCodeToEdit());
|
||||
dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE));
|
||||
dispatch(setIsInEdit(false));
|
||||
|
||||
// Restore the previous editor content if available
|
||||
if (previousModeEditorContent) {
|
||||
dispatch(setMainEditorContentTrigger(previousModeEditorContent));
|
||||
dispatch(setPreviousModeEditorContent(undefined));
|
||||
}
|
||||
// Restore the previous editor content if available
|
||||
if (previousModeEditorContent) {
|
||||
dispatch(setMainEditorContentTrigger(previousModeEditorContent));
|
||||
dispatch(setPreviousModeEditorContent(undefined));
|
||||
}
|
||||
|
||||
if (openNewSession || state.editModeState.lastNonEditSessionWasEmpty) {
|
||||
dispatch(newSession());
|
||||
} else {
|
||||
await dispatch(
|
||||
loadLastSession({
|
||||
saveCurrentSession: false,
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (openNewSession || state.editModeState.lastNonEditSessionWasEmpty) {
|
||||
dispatch(newSession());
|
||||
} else {
|
||||
await dispatch(
|
||||
loadLastSession({
|
||||
saveCurrentSession: false,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
dispatch(setMode(goToMode ?? state.editModeState.returnToMode));
|
||||
},
|
||||
);
|
||||
dispatch(setMode(state.editModeState.returnToMode));
|
||||
});
|
||||
|
||||
export const enterEdit = createAsyncThunk<
|
||||
void,
|
||||
|
|
|
|||
|
|
@ -115,21 +115,19 @@ export const streamNormalInput = createAsyncThunk<
|
|||
dispatch(addPromptCompletionPair([next.value]));
|
||||
|
||||
try {
|
||||
if (state.session.mode === "chat" || state.session.mode === "agent") {
|
||||
extra.ideMessenger.post("devdata/log", {
|
||||
name: "chatInteraction",
|
||||
data: {
|
||||
prompt: next.value.prompt,
|
||||
completion: next.value.completion,
|
||||
modelProvider: selectedChatModel.underlyingProviderName,
|
||||
modelTitle: selectedChatModel.title,
|
||||
sessionId: state.session.id,
|
||||
...(state.session.mode === "agent" && {
|
||||
tools: activeTools.map((tool) => tool.function.name),
|
||||
}),
|
||||
},
|
||||
});
|
||||
}
|
||||
extra.ideMessenger.post("devdata/log", {
|
||||
name: "chatInteraction",
|
||||
data: {
|
||||
prompt: next.value.prompt,
|
||||
completion: next.value.completion,
|
||||
modelProvider: selectedChatModel.underlyingProviderName,
|
||||
modelTitle: selectedChatModel.title,
|
||||
sessionId: state.session.id,
|
||||
...(!!activeTools.length && {
|
||||
tools: activeTools.map((tool) => tool.function.name),
|
||||
}),
|
||||
},
|
||||
});
|
||||
// else if (state.session.mode === "edit") {
|
||||
// extra.ideMessenger.post("devdata/log", {
|
||||
// name: "editInteraction",
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export const streamThunkWrapper = createAsyncThunk<
|
|||
try {
|
||||
await runStream();
|
||||
const state = getState();
|
||||
if (state.session.mode === "chat" || state.session.mode === "agent") {
|
||||
if (!state.session.isInEdit) {
|
||||
await dispatch(
|
||||
saveCurrentSession({
|
||||
openNewSession: false,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
import {
|
||||
DEFAULT_AGENT_SYSTEM_MESSAGE,
|
||||
DEFAULT_CHAT_SYSTEM_MESSAGE,
|
||||
DEFAULT_PLAN_SYSTEM_MESSAGE,
|
||||
} from "core/llm/defaultSystemMessages";
|
||||
import { renderChatMessage } from "core/util/messageContent";
|
||||
import { beforeEach, describe, expect, test, vi } from "vitest";
|
||||
|
|
@ -90,8 +91,9 @@ vi.mock("core/llm/rules/getSystemMessageWithRules", async (importOriginal) => {
|
|||
|
||||
test("getBaseSystemMessage should return the correct system message based on mode", () => {
|
||||
const mockModel = {
|
||||
baseAgentSystemMessage: "Custom Agent System Message",
|
||||
baseChatSystemMessage: "Custom Chat System Message",
|
||||
basePlanSystemMessage: "Custom Plan System Message",
|
||||
baseAgentSystemMessage: "Custom Agent System Message",
|
||||
} as ModelDescription;
|
||||
|
||||
// Test agent mode with custom message
|
||||
|
|
@ -99,6 +101,11 @@ test("getBaseSystemMessage should return the correct system message based on mod
|
|||
"Custom Agent System Message",
|
||||
);
|
||||
|
||||
// Test plan mode with custom message
|
||||
expect(getBaseSystemMessage("plan", mockModel)).toBe(
|
||||
"Custom Plan System Message",
|
||||
);
|
||||
|
||||
// Test chat mode with custom message
|
||||
expect(getBaseSystemMessage("chat", mockModel)).toBe(
|
||||
"Custom Chat System Message",
|
||||
|
|
@ -109,6 +116,11 @@ test("getBaseSystemMessage should return the correct system message based on mod
|
|||
DEFAULT_AGENT_SYSTEM_MESSAGE,
|
||||
);
|
||||
|
||||
// Test agent mode with default message
|
||||
expect(getBaseSystemMessage("plan", {} as ModelDescription)).toBe(
|
||||
DEFAULT_PLAN_SYSTEM_MESSAGE,
|
||||
);
|
||||
|
||||
// Test chat mode with default message
|
||||
expect(getBaseSystemMessage("chat", {} as ModelDescription)).toBe(
|
||||
DEFAULT_CHAT_SYSTEM_MESSAGE,
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import {
|
|||
import {
|
||||
DEFAULT_AGENT_SYSTEM_MESSAGE,
|
||||
DEFAULT_CHAT_SYSTEM_MESSAGE,
|
||||
DEFAULT_PLAN_SYSTEM_MESSAGE,
|
||||
} from "core/llm/defaultSystemMessages";
|
||||
import { chatMessageIsEmpty } from "core/llm/messages";
|
||||
import { getSystemMessageWithRules } from "core/llm/rules/getSystemMessageWithRules";
|
||||
|
|
@ -167,6 +168,8 @@ export function getBaseSystemMessage(
|
|||
): string {
|
||||
if (messageMode === "agent") {
|
||||
return model.baseAgentSystemMessage ?? DEFAULT_AGENT_SYSTEM_MESSAGE;
|
||||
} else if (messageMode === "plan") {
|
||||
return model.basePlanSystemMessage ?? DEFAULT_PLAN_SYSTEM_MESSAGE;
|
||||
} else {
|
||||
return model.baseChatSystemMessage ?? DEFAULT_CHAT_SYSTEM_MESSAGE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ export type EmbedOptions = z.infer<typeof embedOptionsSchema>;
|
|||
export const chatOptionsSchema = z.object({
|
||||
baseSystemMessage: z.string().optional(),
|
||||
baseAgentSystemMessage: z.string().optional(),
|
||||
basePlanSystemMessage: z.string().optional(),
|
||||
});
|
||||
export type ChatOptions = z.infer<typeof chatOptionsSchema>;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue