You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rag-tool-suggestions.tsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import type { Dispatch, SetStateAction } from 'react'
  2. import React, { useCallback, useMemo } from 'react'
  3. import { Trans, useTranslation } from 'react-i18next'
  4. import type { OnSelectBlock } from '../types'
  5. import Tools from './tools'
  6. import { ToolTypeEnum } from './types'
  7. import type { ViewType } from './view-type-select'
  8. import { RiMoreLine } from '@remixicon/react'
  9. import Loading from '@/app/components/base/loading'
  10. import Link from 'next/link'
  11. import { getMarketplaceUrl } from '@/utils/var'
  12. import { useRAGRecommendedPlugins } from '@/service/use-tools'
  13. type RAGToolSuggestionsProps = {
  14. viewType: ViewType
  15. onSelect: OnSelectBlock
  16. onTagsChange: Dispatch<SetStateAction<string[]>>
  17. }
  18. const RAGToolSuggestions: React.FC<RAGToolSuggestionsProps> = ({
  19. viewType,
  20. onSelect,
  21. onTagsChange,
  22. }) => {
  23. const { t } = useTranslation()
  24. const {
  25. data: ragRecommendedPlugins,
  26. isFetching: isFetchingRAGRecommendedPlugins,
  27. } = useRAGRecommendedPlugins()
  28. const recommendedPlugins = useMemo(() => {
  29. if (ragRecommendedPlugins)
  30. return [...ragRecommendedPlugins.installed_recommended_plugins]
  31. return []
  32. }, [ragRecommendedPlugins])
  33. const loadMore = useCallback(() => {
  34. onTagsChange((prev) => {
  35. if (prev.includes('rag'))
  36. return prev
  37. return [...prev, 'rag']
  38. })
  39. }, [onTagsChange])
  40. return (
  41. <div className='flex flex-col p-1'>
  42. <div className='system-xs-medium px-3 pb-0.5 pt-1 text-text-tertiary'>
  43. {t('pipeline.ragToolSuggestions.title')}
  44. </div>
  45. {isFetchingRAGRecommendedPlugins && (
  46. <div className='py-2'>
  47. <Loading type='app' />
  48. </div>
  49. )}
  50. {!isFetchingRAGRecommendedPlugins && recommendedPlugins.length === 0 && (
  51. <p className='system-xs-regular px-3 py-1 text-text-tertiary'>
  52. <Trans
  53. i18nKey='pipeline.ragToolSuggestions.noRecommendationPluginsInstalled'
  54. components={{
  55. CustomLink: (
  56. <Link
  57. className='text-text-accent'
  58. target='_blank'
  59. rel='noopener noreferrer'
  60. href={getMarketplaceUrl('', { tags: 'rag' })}
  61. />
  62. ),
  63. }}
  64. />
  65. </p>
  66. )}
  67. {!isFetchingRAGRecommendedPlugins && recommendedPlugins.length > 0 && (
  68. <>
  69. <Tools
  70. className='p-0'
  71. tools={recommendedPlugins}
  72. onSelect={onSelect}
  73. canNotSelectMultiple
  74. toolType={ToolTypeEnum.All}
  75. viewType={viewType}
  76. hasSearchText={false}
  77. />
  78. <div
  79. className='flex cursor-pointer items-center gap-x-2 py-1 pl-3 pr-2'
  80. onClick={loadMore}
  81. >
  82. <div className='px-1'>
  83. <RiMoreLine className='size-4 text-text-tertiary' />
  84. </div>
  85. <div className='system-xs-regular text-text-tertiary'>
  86. {t('common.operation.more')}
  87. </div>
  88. </div>
  89. </>
  90. )}
  91. </div>
  92. )
  93. }
  94. export default React.memo(RAGToolSuggestions)