From f613b438da136abc75b77d9175286b200d9ea7a6 Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 21 Mar 2025 11:27:58 -0700 Subject: [PATCH] tool lump section --- gui/src/components/mainInput/InputToolbar.tsx | 3 - .../InputToolbar/ToggleToolsButton.tsx | 178 ------------------ .../InputToolbar/ToolDropdownItem.tsx | 2 +- .../mainInput/Lump/TopInputToolbar.tsx | 11 ++ gui/src/components/mainInput/Lump/index.tsx | 4 +- .../Lump/sections/SelectedSection.tsx | 3 + .../mainInput/Lump/sections/ToolsSection.tsx | 25 +++ 7 files changed, 43 insertions(+), 183 deletions(-) delete mode 100644 gui/src/components/mainInput/InputToolbar/ToggleToolsButton.tsx create mode 100644 gui/src/components/mainInput/Lump/sections/ToolsSection.tsx diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 2642fc089..9c1bdb15e 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -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) { )} - - diff --git a/gui/src/components/mainInput/InputToolbar/ToggleToolsButton.tsx b/gui/src/components/mainInput/InputToolbar/ToggleToolsButton.tsx deleted file mode 100644 index 20dae9160..000000000 --- a/gui/src/components/mainInput/InputToolbar/ToggleToolsButton.tsx +++ /dev/null @@ -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(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 ( - !isDisabled && dispatch(toggleUseTools())}> -
- !isDisabled && setIsHovered(true)} - onMouseLeave={() => !isDisabled && setIsHovered(false)} - /> - {isDisabled && ( - - {isInEditMode - ? "Tool use not supported in edit mode" - : "This model does not support tool use"} - - )} - {!useTools && !isDisabled && ( - - Enable tool usage - - )} - - {useTools && !isDisabled && ( - <> - Tools - -
- {}} - as="div" - onClick={(e) => e.stopPropagation()} - disabled={isDisabled} - > - {({ open }) => ( - <> - { - e.stopPropagation(); - setDropdownOpen(!isDropdownOpen); - }} - className="text-lightgray flex cursor-pointer items-center border-none bg-transparent px-0 outline-none" - aria-disabled={isDisabled} - > - - - setDropdownOpen(false)} - > - -
-
- Tool policies{" "} - -

- - Automatic: - {" "} - Can be used without asking -

-

- - Allowed: - {" "} - Will ask before using -

-

- - Disabled: - {" "} - Cannot be used -

-
- } - /> -
-
-
- {availableTools.map((tool: any) => ( - - - - ))} -
- - - - )} - -
- - )} - -
- ); -} diff --git a/gui/src/components/mainInput/InputToolbar/ToolDropdownItem.tsx b/gui/src/components/mainInput/InputToolbar/ToolDropdownItem.tsx index 5df66f147..adea1943b 100644 --- a/gui/src/components/mainInput/InputToolbar/ToolDropdownItem.tsx +++ b/gui/src/components/mainInput/InputToolbar/ToolDropdownItem.tsx @@ -26,7 +26,7 @@ function ToolDropdownItem(props: ToolDropdownItemProps) { return (
{ dispatch(toggleToolSetting(props.tool.function.name)); e.stopPropagation(); diff --git a/gui/src/components/mainInput/Lump/TopInputToolbar.tsx b/gui/src/components/mainInput/Lump/TopInputToolbar.tsx index b6a6633fc..ab51c8bfa 100644 --- a/gui/src/components/mainInput/Lump/TopInputToolbar.tsx +++ b/gui/src/components/mainInput/Lump/TopInputToolbar.tsx @@ -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) { ) } /> + + props.setSelectedSection( + props.selectedSection === "tools" ? null : "tools", + ) + } + />
diff --git a/gui/src/components/mainInput/Lump/index.tsx b/gui/src/components/mainInput/Lump/index.tsx index 3c50eef32..bd54b5015 100644 --- a/gui/src/components/mainInput/Lump/index.tsx +++ b/gui/src/components/mainInput/Lump/index.tsx @@ -39,7 +39,9 @@ export function Lump(props: LumpProps) { setSelectedSection={setSelectedSection} /> - +
+ +
); diff --git a/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx b/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx index 18e5f93c6..0e0da16d9 100644 --- a/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/SelectedSection.tsx @@ -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 ; case "context": return ; + case "tools": + return ; default: return null; } diff --git a/gui/src/components/mainInput/Lump/sections/ToolsSection.tsx b/gui/src/components/mainInput/Lump/sections/ToolsSection.tsx new file mode 100644 index 000000000..34106b701 --- /dev/null +++ b/gui/src/components/mainInput/Lump/sections/ToolsSection.tsx @@ -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 ( +
+ {availableTools.map((tool: any) => ( +
+ +
+ ))} +
+ ); +}