tool lump section

This commit is contained in:
Nate 2025-03-21 11:27:58 -07:00
parent b52794245e
commit f613b438da
7 changed files with 43 additions and 183 deletions

View file

@ -29,7 +29,6 @@ import {
import { ToolTip } from "../gui/Tooltip";
import ModelSelect from "../modelSelection/ModelSelect";
import HoverItem from "./InputToolbar/HoverItem";
import ToggleToolsButton from "./InputToolbar/ToggleToolsButton";
const StyledDiv = styled.div<{ isHidden?: boolean }>`
padding-top: 4px;
@ -158,8 +157,6 @@ function InputToolbar(props: InputToolbarProps) {
</ToolTip>
</HoverItem>
)}
<ToggleToolsButton disabled={!toolsSupported} />
</div>
</div>

View file

@ -1,178 +0,0 @@
import { Listbox } from "@headlessui/react";
import {
EllipsisHorizontalCircleIcon as EllipsisHorizontalIcon,
WrenchScrewdriverIcon as WrenchScrewdriverIconOutline,
} from "@heroicons/react/24/outline";
import { WrenchScrewdriverIcon as WrenchScrewdriverIconSolid } from "@heroicons/react/24/solid";
import { useEffect, useRef, useState } from "react";
import { useDispatch } from "react-redux";
import { lightGray, vscForeground } from "../..";
import { useAppSelector } from "../../../redux/hooks";
import { toggleUseTools } from "../../../redux/slices/uiSlice";
import { ToolTip } from "../../gui/Tooltip";
import InfoHover from "../../InfoHover";
import HoverItem from "./HoverItem";
import PopoverTransition from "./PopoverTransition";
import ToolDropdownItem from "./ToolDropdownItem";
import { selectIsInEditMode } from "../../../redux/slices/sessionSlice";
interface ToolDropdownProps {
disabled: boolean;
}
export default function ToolDropdown(props: ToolDropdownProps) {
const buttonRef = useRef<HTMLButtonElement>(null);
const dispatch = useDispatch();
const [isDropdownOpen, setDropdownOpen] = useState(false);
const [isHovered, setIsHovered] = useState(false);
const useTools = useAppSelector((state) => state.ui.useTools);
const availableTools = useAppSelector((state) => state.config.config.tools);
const [showAbove, setShowAbove] = useState(false);
const isInEditMode = useAppSelector(selectIsInEditMode);
const ToolsIcon = useTools
? WrenchScrewdriverIconSolid
: WrenchScrewdriverIconOutline;
useEffect(() => {
const checkPosition = () => {
if (buttonRef.current) {
const rect = buttonRef.current.getBoundingClientRect();
const windowHeight = window.innerHeight;
const spaceBelow = windowHeight - rect.bottom;
setShowAbove(spaceBelow < 250);
}
};
if (isDropdownOpen) {
checkPosition();
}
}, [isDropdownOpen]);
const isDisabled = props.disabled || isInEditMode;
return (
<HoverItem onClick={() => !isDisabled && dispatch(toggleUseTools())}>
<div
data-tooltip-id="tools-tooltip"
className={`-ml-1 -mt-1 flex flex-row items-center gap-1.5 rounded-md px-1 py-0.5 text-xs ${
(useTools || isHovered) && !isDisabled ? "bg-lightgray/30" : ""
} ${isDisabled ? "cursor-not-allowed opacity-50" : ""}`}
>
<ToolsIcon
className={`h-4 w-4 text-gray-400 ${
isDisabled ? "cursor-not-allowed" : ""
}`}
onMouseEnter={() => !isDisabled && setIsHovered(true)}
onMouseLeave={() => !isDisabled && setIsHovered(false)}
/>
{isDisabled && (
<ToolTip id="tools-tooltip" place="top-middle">
{isInEditMode
? "Tool use not supported in edit mode"
: "This model does not support tool use"}
</ToolTip>
)}
{!useTools && !isDisabled && (
<ToolTip id="tools-tooltip" place="top-middle">
Enable tool usage
</ToolTip>
)}
{useTools && !isDisabled && (
<>
<span className="hidden align-top sm:flex">Tools</span>
<div className="relative">
<Listbox
value={null}
onChange={() => {}}
as="div"
onClick={(e) => e.stopPropagation()}
disabled={isDisabled}
>
{({ open }) => (
<>
<Listbox.Button
ref={buttonRef}
onClick={(e) => {
e.stopPropagation();
setDropdownOpen(!isDropdownOpen);
}}
className="text-lightgray flex cursor-pointer items-center border-none bg-transparent px-0 outline-none"
aria-disabled={isDisabled}
>
<EllipsisHorizontalIcon className="h-3 w-3 cursor-pointer hover:brightness-125" />
</Listbox.Button>
<PopoverTransition
show={open}
afterLeave={() => setDropdownOpen(false)}
>
<Listbox.Options
className={`bg-vsc-editor-background border-lightgray/50 absolute -left-32 z-50 mb-1 min-w-fit whitespace-nowrap rounded-md border border-solid px-1 py-0 shadow-lg ${showAbove ? "bottom-full" : ""}`}
static
>
<div className="sticky">
<div
className="mb-1 flex items-center gap-2 px-2 py-1 text-xs"
style={{
color: vscForeground,
borderBottom: `1px solid ${lightGray}`,
}}
>
Tool policies{" "}
<InfoHover
id={"tool-policies"}
size={"3"}
msg={
<div
className="gap-0 *:m-1 *:text-left"
style={{ fontSize: "10px" }}
>
<p>
<span className="text-green-500">
Automatic:
</span>{" "}
Can be used without asking
</p>
<p>
<span className="text-yellow-500">
Allowed:
</span>{" "}
Will ask before using
</p>
<p>
<span className="text-red-500">
Disabled:
</span>{" "}
Cannot be used
</p>
</div>
}
/>
</div>
</div>
<div className="max-h-48 overflow-y-auto overflow-x-hidden pr-2">
{availableTools.map((tool: any) => (
<Listbox.Option
key={tool.function.name}
value="addAllFiles"
className="text-vsc-foreground block w-full cursor-pointer text-left text-xs brightness-75 hover:brightness-125"
>
<ToolDropdownItem tool={tool} />
</Listbox.Option>
))}
</div>
</Listbox.Options>
</PopoverTransition>
</>
)}
</Listbox>
</div>
</>
)}
</div>
</HoverItem>
);
}

View file

@ -26,7 +26,7 @@ function ToolDropdownItem(props: ToolDropdownItemProps) {
return (
<div
className="flex w-full items-center justify-between gap-2 px-2 py-1"
className="flex w-full items-center justify-between gap-2 px-2 py-0.5"
onClick={(e) => {
dispatch(toggleToolSetting(props.tool.function.name));
e.stopPropagation();

View file

@ -4,6 +4,7 @@ import {
CubeIcon,
FolderIcon,
PencilIcon,
WrenchScrewdriverIcon,
} from "@heroicons/react/24/outline";
import AssistantSelect from "../../modelSelection/platform/AssistantSelect";
import HoverItem from "../InputToolbar/HoverItem";
@ -90,6 +91,16 @@ export function TopInputToolbar(props: TopInputProps) {
)
}
/>
<TopToolbarIcon
icon={WrenchScrewdriverIcon}
tooltip="Tools"
isSelected={props.selectedSection === "tools"}
onClick={() =>
props.setSelectedSection(
props.selectedSection === "tools" ? null : "tools",
)
}
/>
</div>
<AssistantSelect />
</div>

View file

@ -39,7 +39,9 @@ export function Lump(props: LumpProps) {
setSelectedSection={setSelectedSection}
/>
<SelectedSection selectedSection={selectedSection} />
<div className="max-h-[200px] overflow-y-auto">
<SelectedSection selectedSection={selectedSection} />
</div>
</div>
</LumpDiv>
);

View file

@ -3,6 +3,7 @@ import { DocsSection } from "./DocsSection";
import { ModelsSection } from "./ModelsSection";
import { PromptsSection } from "./PromptsSection";
import { RulesSection } from "./RulesSection";
import { ToolsSection } from "./ToolsSection";
interface SelectedSectionProps {
selectedSection: string | null;
@ -20,6 +21,8 @@ export function SelectedSection(props: SelectedSectionProps) {
return <PromptsSection />;
case "context":
return <ContextSection />;
case "tools":
return <ToolsSection />;
default:
return null;
}

View file

@ -0,0 +1,25 @@
import { useAppSelector } from "../../../../redux/hooks";
import { getFontSize } from "../../../../util";
import ToolDropdownItem from "../../InputToolbar/ToolDropdownItem";
interface ToolsSectionProps {}
export function ToolsSection({}: ToolsSectionProps) {
const availableTools = useAppSelector((state) => state.config.config.tools);
return (
<div className="overflow-y-auto overflow-x-hidden pr-2">
{availableTools.map((tool: any) => (
<div
key={tool.function.name}
style={{
fontSize: `${getFontSize() - 3}px`,
}}
className="text-vsc-foreground block w-full text-left brightness-75 hover:brightness-125"
>
<ToolDropdownItem tool={tool} />
</div>
))}
</div>
);
}