fix: no icon in tool select

pull/12372/head
AkaraChen 1 year ago
parent cd08f98bff
commit 244517e6e7

@ -35,7 +35,7 @@ const ExternalNotInstallWarn = () => {
</Tooltip> </Tooltip>
} }
function formatStrategy(input: StrategyPluginDetail[]): ToolWithProvider[] { function formatStrategy(input: StrategyPluginDetail[], getIcon: (i: string) => string): ToolWithProvider[] {
return input.map((item) => { return input.map((item) => {
const res: ToolWithProvider = { const res: ToolWithProvider = {
id: item.provider, id: item.provider,
@ -44,7 +44,7 @@ function formatStrategy(input: StrategyPluginDetail[]): ToolWithProvider[] {
name: item.declaration.identity.name, name: item.declaration.identity.name,
description: item.declaration.identity.description as any, description: item.declaration.identity.description as any,
plugin_id: item.plugin_id, plugin_id: item.plugin_id,
icon: item.declaration.identity.icon, icon: getIcon(item.declaration.identity.icon),
label: item.declaration.identity.label as any, label: item.declaration.identity.label as any,
type: CollectionType.all, type: CollectionType.all,
tools: item.declaration.strategies.map(strategy => ({ tools: item.declaration.strategies.map(strategy => ({
@ -76,19 +76,18 @@ export const AgentStrategySelector = (props: AgentStrategySelectorProps) => {
const [viewType, setViewType] = useState<ViewType>(ViewType.flat) const [viewType, setViewType] = useState<ViewType>(ViewType.flat)
const [query, setQuery] = useState('') const [query, setQuery] = useState('')
const stra = useStrategyProviders() const stra = useStrategyProviders()
const list = stra.data ? formatStrategy(stra.data) : undefined const { getIconUrl } = useGetIcon()
const list = stra.data ? formatStrategy(stra.data, getIconUrl) : undefined
const filteredTools = useMemo(() => { const filteredTools = useMemo(() => {
if (!list) return [] if (!list) return []
return list.filter(tool => tool.name.toLowerCase().includes(query.toLowerCase())) return list.filter(tool => tool.name.toLowerCase().includes(query.toLowerCase()))
}, [query, list]) }, [query, list])
// TODO: should be replaced by real data // TODO: should be replaced by real data
const isExternalInstalled = true const isExternalInstalled = true
const { getIconUrl } = useGetIcon()
// TODO: 验证这玩意写对了没 // TODO: 验证这玩意写对了没
const iconFilename = list?.find( const icon = list?.find(
coll => coll.tools?.find(tool => tool.name === value?.agent_strategy_name), coll => coll.tools?.find(tool => tool.name === value?.agent_strategy_name),
)?.icon )?.icon as string | undefined
const icon = iconFilename ? getIconUrl(iconFilename as string) : undefined
const { t } = useTranslation() const { t } = useTranslation()
return <PortalToFollowElem open={open} onOpenChange={setOpen} placement='bottom'> return <PortalToFollowElem open={open} onOpenChange={setOpen} placement='bottom'>
<PortalToFollowElemTrigger className='w-full'> <PortalToFollowElemTrigger className='w-full'>

Loading…
Cancel
Save