| | import { useMemo } from 'react'; |
| | import { Constants } from 'librechat-data-provider'; |
| | import type { TPlugin } from 'librechat-data-provider'; |
| | import type { MCPServerInfo } from '~/common'; |
| |
|
| | interface VisibleToolsResult { |
| | toolIds: string[]; |
| | mcpServerNames: string[]; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | export function useVisibleTools( |
| | selectedToolIds: string[] | undefined, |
| | regularTools: TPlugin[] | undefined, |
| | mcpServersMap: Map<string, MCPServerInfo>, |
| | ): VisibleToolsResult { |
| | return useMemo(() => { |
| | const mcpServers = new Set<string>(); |
| | const regularToolIds: string[] = []; |
| |
|
| | for (const toolId of selectedToolIds ?? []) { |
| | |
| | if (toolId.includes(Constants.mcp_delimiter)) { |
| | const serverName = toolId.split(Constants.mcp_delimiter)[1]; |
| | if (serverName) { |
| | mcpServers.add(serverName); |
| | } |
| | } |
| | |
| | else if (mcpServersMap.has(toolId)) { |
| | mcpServers.add(toolId); |
| | } |
| | |
| | else if (regularTools?.some((t) => t.pluginKey === toolId)) { |
| | regularToolIds.push(toolId); |
| | } |
| | } |
| |
|
| | return { |
| | toolIds: regularToolIds.sort((a, b) => a.localeCompare(b)), |
| | mcpServerNames: Array.from(mcpServers).sort((a, b) => a.localeCompare(b)), |
| | }; |
| | }, [regularTools, mcpServersMap, selectedToolIds]); |
| | } |
| |
|