show above

This commit is contained in:
Nate 2024-11-29 08:52:46 -08:00
parent 5d4e6e9494
commit e8550b0af6
3 changed files with 73 additions and 45 deletions

View file

@ -5,6 +5,7 @@ export const createNewFileTool: Tool = {
type: "function",
displayTitle: "Create New File",
wouldLikeTo: "create a new file",
readonly: false,
function: {
name: BuiltInToolNames.CreateNewFile,
description: "Create a new file",

View file

@ -5,6 +5,7 @@ export const exactSearchTool: Tool = {
type: "function",
displayTitle: "Exact Search",
wouldLikeTo: "search for a specific term within the repository",
readonly: true,
function: {
name: BuiltInToolNames.ExactSearch,
description: "Perform an exact search over the repository using ripgrep",

View file

@ -1,4 +1,4 @@
import { Listbox } from "@headlessui/react";
import { Listbox, Transition } from "@headlessui/react";
import {
ChevronDownIcon,
ChevronUpIcon,
@ -6,7 +6,7 @@ import {
} from "@heroicons/react/24/outline";
import { modelSupportsTools } from "core/llm/autodetect";
import { allTools } from "core/tools/index";
import { useRef, useState } from "react";
import { useEffect, useRef, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import styled from "styled-components";
import { defaultBorderRadius, lightGray, vscForeground } from "../..";
@ -34,13 +34,35 @@ const BackgroundDiv = styled.div<{ useTools: boolean }>`
transition: background-color 200ms;
`;
export default function ToolDropdown() {
export default function ToolDropdown({
}: {
}) {
const buttonRef = useRef<HTMLButtonElement>(null);
const dispatch = useDispatch();
const [isDropdownOpen, setDropdownOpen] = useState(false);
const useTools = useSelector((store: RootState) => store.uiState.useTools);
const defaultModel = useSelector(defaultModelSelector);
const [showAbove, setShowAbove] = useState(false);
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]);
if (!modelSupportsTools(defaultModel.model)) {
return null;
@ -77,49 +99,53 @@ export default function ToolDropdown() {
<ChevronDownIcon className="h-3 w-3" />
)}
</Listbox.Button>
<Listbox.Options className="bg-vsc-editor-background border-lightgray/50 absolute right-0 top-full z-50 mt-1 min-w-fit whitespace-nowrap rounded-md border border-solid px-1 py-0 shadow-lg">
<div
className="mb-1 flex items-center gap-2 px-2 py-1"
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>
{allTools.map((tool) => (
<Listbox.Option
key={tool.function.name}
value="addAllFiles"
className="text-vsc-foreground block w-full cursor-pointer text-left text-[10px] brightness-75 hover:brightness-125"
<Transition
show={isDropdownOpen}
>
<Listbox.Options className={`bg-vsc-editor-background border-lightgray/50 absolute right-0 z-50 mb-1 min-w-fit whitespace-nowrap rounded-md border border-solid px-1 py-0 shadow-lg ${showAbove ? "bottom-full" : ""}`}>
<div
className="mb-1 flex items-center gap-2 px-2 py-1"
style={{
color: vscForeground,
borderBottom: `1px solid ${lightGray}`,
}}
>
<ToolDropdownItem tool={tool} />
</Listbox.Option>
))}
</Listbox.Options>
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>
{allTools.map((tool) => (
<Listbox.Option
key={tool.function.name}
value="addAllFiles"
className="text-vsc-foreground block w-full cursor-pointer text-left text-[10px] brightness-75 hover:brightness-125"
>
<ToolDropdownItem tool={tool} />
</Listbox.Option>
))}
</Listbox.Options>
</Transition>
</Listbox>
</div>
</>