2024-06-05 14:27:06 +08:00
|
|
|
import { Accordion } from "@/components/bs-ui/accordion";
|
|
|
|
|
import { SearchInput } from "@/components/bs-ui/input";
|
|
|
|
|
import { Sheet, SheetContent, SheetTitle, SheetTrigger } from "@/components/bs-ui/sheet";
|
|
|
|
|
import { getAssistantToolsApi } from "@/controllers/API/assistant";
|
|
|
|
|
import ToolItem from "@/pages/SkillPage/components/ToolItem";
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
import { PersonIcon, StarFilledIcon } from "@radix-ui/react-icons";
|
|
|
|
|
import { useEffect, useMemo, useState } from "react";
|
|
|
|
|
import { Button } from "@/components/bs-ui/button";
|
2024-06-13 15:11:41 +08:00
|
|
|
import sousuo from "../../../assets/npc/sousuo.png";
|
|
|
|
|
import gongjuAdd from "../../../assets/npc/gongjuAdd.png";
|
|
|
|
|
import gongjuIcon from "../../../assets/npc/gongjuIcon.png";
|
|
|
|
|
import gongjuIcon1 from "../../../assets/npc/gongjuIcon1.png";
|
2024-06-22 18:34:39 +08:00
|
|
|
import borderR from "../../../assets/npc/border-r.png";
|
2024-06-05 14:27:06 +08:00
|
|
|
|
|
|
|
|
export default function ToolsSheet({ select, onSelect, children }) {
|
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
const [type, setType] = useState('default') // default custom
|
|
|
|
|
|
|
|
|
|
const [keyword, setKeyword] = useState('')
|
|
|
|
|
const [allData, setAllData] = useState([])
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
getAssistantToolsApi(type).then(res => {
|
|
|
|
|
setAllData(res)
|
|
|
|
|
setKeyword('')
|
|
|
|
|
})
|
|
|
|
|
}, [type])
|
|
|
|
|
|
|
|
|
|
const options = useMemo(() => {
|
|
|
|
|
return allData.filter(el =>
|
|
|
|
|
el.name.toLowerCase().includes(keyword.toLowerCase())
|
|
|
|
|
|| el.description.toLowerCase().includes(keyword.toLowerCase())
|
|
|
|
|
)
|
|
|
|
|
}, [keyword, allData])
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Sheet onOpenChange={open => !open && setKeyword('')}>
|
|
|
|
|
<SheetTrigger asChild>
|
|
|
|
|
{children}
|
|
|
|
|
</SheetTrigger>
|
2024-06-22 18:34:39 +08:00
|
|
|
<SheetContent className="w-[1000px] sm:max-w-[1000px] bg-[#1a1a1a]">
|
2024-06-05 14:27:06 +08:00
|
|
|
<div className="flex h-full" onClick={e => e.stopPropagation()}>
|
2024-06-22 18:34:39 +08:00
|
|
|
<div className="xinDuiHua-boxR">
|
|
|
|
|
{/* <img src={borderR} className="w-[30px] h-[100%]" alt="" /> */}
|
|
|
|
|
</div>
|
2024-06-25 14:55:48 +08:00
|
|
|
<div className="w-[280px] p-6">
|
2024-06-05 14:27:06 +08:00
|
|
|
<SheetTitle>{t('build.addTool')}</SheetTitle>
|
2024-06-13 15:11:41 +08:00
|
|
|
<div className="relative mt-[14px]">
|
|
|
|
|
<img src={sousuo} className="absolute w-[14px] left-[14px] top-[10px]" alt="" />
|
|
|
|
|
<input placeholder="搜索"
|
|
|
|
|
className="w-[237px] h-[34px] bg-[#1A1A1A] text-[#fff] pl-[40px]"
|
|
|
|
|
style={{borderRadius:"17px",outline:"none"}}
|
|
|
|
|
onChange={(e) => setKeyword(e.target.value)} type="text" />
|
|
|
|
|
</div>
|
|
|
|
|
{/* <SearchInput placeholder={t('build.search')} className="mt-6" onChange={(e) => setKeyword(e.target.value)} /> */}
|
|
|
|
|
{/* <Button
|
2024-06-05 14:27:06 +08:00
|
|
|
className="mt-4 w-full"
|
|
|
|
|
onClick={() => window.open("/build/tools")}
|
|
|
|
|
>
|
|
|
|
|
{t('create')}{t("tools.createCustomTool")}
|
2024-06-13 15:11:41 +08:00
|
|
|
</Button> */}
|
|
|
|
|
<div className="w-[237px] h-[27px] bg-[#FFD025] mt-[14px] flex justify-center items-center border-radius-14 cursor-pointer" onClick={() => window.open("/build/tools")}>
|
|
|
|
|
<img src={gongjuAdd} className="w-[14px]" alt="" />
|
|
|
|
|
<span className="text-[#333333] ml-[12px]">自定义工具</span>
|
|
|
|
|
</div>
|
2024-06-05 14:27:06 +08:00
|
|
|
<div className="mt-4">
|
|
|
|
|
<div
|
2024-06-13 15:11:41 +08:00
|
|
|
className={`flex items-center gap-2 px-4 py-2 rounded-md cursor-pointer hover:bg-muted-foreground/10 transition-all duration-200 ${type === 'default' && 'bg-[#2A271D] text-[#FFD54C]'}`}
|
2024-06-05 14:27:06 +08:00
|
|
|
onClick={() => setType('default')}
|
|
|
|
|
>
|
2024-06-13 15:11:41 +08:00
|
|
|
{/* <PersonIcon /> */}
|
|
|
|
|
{type === "default" ? <img src={gongjuIcon1} className="w-[14px]" alt="" /> : <img src={gongjuIcon} className="w-[14px]" alt="" />}
|
2024-06-22 18:34:39 +08:00
|
|
|
<span className={`ml-[8px] text-[#999999] ${type === "default" && "text-[#FFD025]"}`}>内置工具</span>
|
2024-06-05 14:27:06 +08:00
|
|
|
</div>
|
|
|
|
|
<div
|
2024-06-13 15:11:41 +08:00
|
|
|
className={`flex items-center gap-2 px-4 py-2 rounded-md cursor-pointer hover:bg-muted-foreground/10 transition-all duration-200 mt-1 ${type === 'custom' && 'bg-[#2A271D] text-[#FFD54C]'}`}
|
2024-06-05 14:27:06 +08:00
|
|
|
onClick={() => setType('custom')}
|
|
|
|
|
>
|
2024-06-13 15:11:41 +08:00
|
|
|
{type === "custom" ? <img src={gongjuIcon1} className="w-[14px]" alt="" /> : <img src={gongjuIcon} className="w-[14px]" alt="" />}
|
|
|
|
|
{/* <StarFilledIcon /> */}
|
2024-06-22 18:34:39 +08:00
|
|
|
<span className={`ml-[8px] text-[#999999] ${type === "custom" && "text-[#FFD025]"}`}>自定义工具</span>
|
2024-06-05 14:27:06 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-06-25 14:55:48 +08:00
|
|
|
<div className="w-[690px] flex-1 bg-[#121212] p-5 pt-12 h-full overflow-auto scrollbar-hide">
|
2024-06-05 14:27:06 +08:00
|
|
|
<Accordion type="single" collapsible className="w-full">
|
|
|
|
|
{
|
|
|
|
|
options.length ? options.map(el => (
|
|
|
|
|
<ToolItem
|
|
|
|
|
key={el.id}
|
|
|
|
|
type={'add'}
|
|
|
|
|
select={select}
|
|
|
|
|
data={el}
|
|
|
|
|
onSelect={onSelect}
|
|
|
|
|
></ToolItem>
|
|
|
|
|
)) : <div className="pt-40 text-center text-sm text-muted-foreground mt-2">
|
|
|
|
|
{t('build.empty')}
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
</Accordion>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</SheetContent>
|
|
|
|
|
</Sheet>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
};
|