index.tsx 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useCallback, useMemo } from 'react'
  4. // import { useTheme } from 'next-themes'
  5. import {
  6. RiArrowRightUpLine,
  7. RiBugLine,
  8. RiErrorWarningLine,
  9. RiHardDrive3Line,
  10. RiLoginCircleLine,
  11. RiVerifiedBadgeLine,
  12. } from '@remixicon/react'
  13. import { useTranslation } from 'react-i18next'
  14. import { usePluginPageContext } from '../plugin-page/context'
  15. import { Github } from '../../base/icons/src/public/common'
  16. import Badge from '../../base/badge'
  17. import { type PluginDetail, PluginSource, PluginType } from '../types'
  18. import CornerMark from '../card/base/corner-mark'
  19. import Description from '../card/base/description'
  20. import OrgInfo from '../card/base/org-info'
  21. import Title from '../card/base/title'
  22. import Action from './action'
  23. import cn from '@/utils/classnames'
  24. import { API_PREFIX } from '@/config'
  25. import { useSingleCategories } from '../hooks'
  26. import { useRenderI18nObject } from '@/hooks/use-i18n'
  27. import useRefreshPluginList from '@/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list'
  28. import { useAppContext } from '@/context/app-context'
  29. import { gte } from 'semver'
  30. import Tooltip from '@/app/components/base/tooltip'
  31. // import { getMarketplaceUrl } from '@/utils/var'
  32. import { useGlobalPublicStore } from '@/context/global-public-context'
  33. type Props = {
  34. className?: string
  35. plugin: PluginDetail
  36. }
  37. const PluginItem: FC<Props> = ({
  38. className,
  39. plugin,
  40. }) => {
  41. const { t } = useTranslation()
  42. // zlwu12 2025-09-18 注释
  43. // const { theme } = useTheme()
  44. const { categoriesMap } = useSingleCategories()
  45. const currentPluginID = usePluginPageContext(v => v.currentPluginID)
  46. const setCurrentPluginID = usePluginPageContext(v => v.setCurrentPluginID)
  47. const { refreshPluginList } = useRefreshPluginList()
  48. const {
  49. source,
  50. tenant_id,
  51. installation_id,
  52. plugin_unique_identifier,
  53. endpoints_active,
  54. meta,
  55. plugin_id,
  56. status,
  57. deprecated_reason,
  58. } = plugin
  59. const { category, author, name, label, description, icon, verified, meta: declarationMeta } = plugin.declaration
  60. const orgName = useMemo(() => {
  61. return [PluginSource.github, PluginSource.marketplace].includes(source) ? author : ''
  62. }, [source, author])
  63. const { langGeniusVersionInfo } = useAppContext()
  64. const isDifyVersionCompatible = useMemo(() => {
  65. if (!langGeniusVersionInfo.current_version)
  66. return true
  67. return gte(langGeniusVersionInfo.current_version, declarationMeta.minimum_dify_version ?? '0.0.0')
  68. }, [declarationMeta.minimum_dify_version, langGeniusVersionInfo.current_version])
  69. const isDeprecated = useMemo(() => {
  70. return status === 'deleted' && !!deprecated_reason
  71. }, [status, deprecated_reason])
  72. const handleDelete = useCallback(() => {
  73. refreshPluginList({ category } as any)
  74. }, [category, refreshPluginList])
  75. const getValueFromI18nObject = useRenderI18nObject()
  76. const title = getValueFromI18nObject(label)
  77. const descriptionText = getValueFromI18nObject(description)
  78. const { enable_marketplace } = useGlobalPublicStore(s => s.systemFeatures)
  79. return (
  80. <div
  81. className={cn(
  82. 'relative overflow-hidden rounded-xl border-[1.5px] border-background-section-burn p-1',
  83. currentPluginID === plugin_id && 'border-components-option-card-option-selected-border',
  84. source === PluginSource.debugging
  85. ? 'bg-[repeating-linear-gradient(-45deg,rgba(16,24,40,0.04),rgba(16,24,40,0.04)_5px,rgba(0,0,0,0.02)_5px,rgba(0,0,0,0.02)_10px)]'
  86. : 'bg-background-section-burn',
  87. )}
  88. onClick={() => {
  89. setCurrentPluginID(plugin.plugin_id)
  90. }}
  91. >
  92. <div className={cn('hover-bg-components-panel-on-panel-item-bg relative z-10 rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-on-panel-item-bg p-4 pb-3 shadow-xs', className)}>
  93. <CornerMark text={categoriesMap[category].label} />
  94. {/* Header */}
  95. <div className='flex'>
  96. <div className='flex h-10 w-10 items-center justify-center overflow-hidden rounded-xl border-[1px] border-components-panel-border-subtle'>
  97. <img
  98. className='h-full w-full'
  99. src={`${API_PREFIX}/workspaces/current/plugin/icon?tenant_id=${tenant_id}&filename=${icon}`}
  100. alt={`plugin-${plugin_unique_identifier}-logo`}
  101. />
  102. </div>
  103. <div className='ml-3 w-0 grow'>
  104. <div className='flex h-5 items-center'>
  105. <Title title={title} />
  106. {verified && <RiVerifiedBadgeLine className='ml-0.5 h-4 w-4 shrink-0 text-text-accent' />}
  107. {!isDifyVersionCompatible && <Tooltip popupContent={
  108. t('plugin.difyVersionNotCompatible', { minimalDifyVersion: declarationMeta.minimum_dify_version })
  109. }><RiErrorWarningLine color='red' className='ml-0.5 h-4 w-4 shrink-0 text-text-accent' /></Tooltip>}
  110. <Badge className='ml-1 shrink-0'
  111. text={source === PluginSource.github ? plugin.meta!.version : plugin.version}
  112. hasRedCornerMark={(source === PluginSource.marketplace) && !!plugin.latest_version && plugin.latest_version !== plugin.version}
  113. />
  114. </div>
  115. <div className='flex items-center justify-between'>
  116. <Description text={descriptionText} descriptionLineRows={1}></Description>
  117. <div onClick={e => e.stopPropagation()}>
  118. <Action
  119. pluginUniqueIdentifier={plugin_unique_identifier}
  120. installationId={installation_id}
  121. author={author}
  122. pluginName={name}
  123. usedInApps={5}
  124. isShowFetchNewVersion={source === PluginSource.github}
  125. isShowInfo={source === PluginSource.github}
  126. isShowDelete
  127. meta={meta}
  128. onDelete={handleDelete}
  129. category={category}
  130. />
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. </div>
  136. <div className='mb-1 mt-1.5 flex h-4 items-center gap-x-2 px-4'>
  137. {/* Organization & Name */}
  138. <div className='flex grow items-center overflow-hidden'>
  139. <OrgInfo
  140. className='mt-0.5'
  141. orgName={orgName}
  142. packageName={name}
  143. packageNameClassName='w-auto max-w-[150px]'
  144. />
  145. {category === PluginType.extension && (
  146. <>
  147. <div className='system-xs-regular mx-2 text-text-quaternary'>·</div>
  148. <div className='system-xs-regular flex space-x-1 overflow-hidden text-text-tertiary'>
  149. <RiLoginCircleLine className='h-4 w-4 shrink-0' />
  150. <span
  151. className='truncate'
  152. title={t('plugin.endpointsEnabled', { num: endpoints_active })}
  153. >
  154. {t('plugin.endpointsEnabled', { num: endpoints_active })}
  155. </span>
  156. </div>
  157. </>
  158. )}
  159. </div>
  160. {/* Source */}
  161. <div className='flex shrink-0 items-center'>
  162. {source === PluginSource.github
  163. && <>
  164. <a href={`https://github.com/${meta!.repo}`} target='_blank' className='flex items-center gap-1'>
  165. <div className='system-2xs-medium-uppercase text-text-tertiary'>{t('plugin.from')}</div>
  166. <div className='flex items-center space-x-0.5 text-text-secondary'>
  167. <Github className='h-3 w-3' />
  168. <div className='system-2xs-semibold-uppercase'>GitHub</div>
  169. <RiArrowRightUpLine className='h-3 w-3' />
  170. </div>
  171. </a>
  172. </>
  173. }
  174. {source === PluginSource.marketplace && enable_marketplace
  175. && <>
  176. {/* zlwu12 2025-09-18 注释 */}
  177. {/* <a href={getMarketplaceUrl(`/plugins/${author}/${name}`, { theme })} target='_blank' className='flex items-center gap-0.5'>
  178. <div className='system-2xs-medium-uppercase text-text-tertiary'>{t('plugin.from')} <span className='text-text-secondary'>marketplace</span></div>
  179. <RiArrowRightUpLine className='h-3 w-3 text-text-tertiary' />
  180. </a> */}
  181. </>
  182. }
  183. {source === PluginSource.local
  184. && <>
  185. <div className='flex items-center gap-1'>
  186. <RiHardDrive3Line className='h-3 w-3 text-text-tertiary' />
  187. <div className='system-2xs-medium-uppercase text-text-tertiary'>Local Plugin</div>
  188. </div>
  189. </>
  190. }
  191. {source === PluginSource.debugging
  192. && <>
  193. <div className='flex items-center gap-1'>
  194. <RiBugLine className='h-3 w-3 text-text-warning' />
  195. <div className='system-2xs-medium-uppercase text-text-warning'>Debugging Plugin</div>
  196. </div>
  197. </>
  198. }
  199. </div>
  200. {/* Deprecated */}
  201. {source === PluginSource.marketplace && enable_marketplace && isDeprecated && (
  202. <div className='system-2xs-medium-uppercase flex shrink-0 items-center gap-x-2'>
  203. <span className='text-text-tertiary'>·</span>
  204. <span className='text-text-warning'>
  205. {t('plugin.deprecated')}
  206. </span>
  207. </div>
  208. )}
  209. </div>
  210. {/* BG Effect for Deprecated Plugin */}
  211. {source === PluginSource.marketplace && enable_marketplace && isDeprecated && (
  212. <div className='absolute bottom-[-71px] right-[-45px] z-0 size-40 bg-components-badge-status-light-warning-halo opacity-60 blur-[120px]' />
  213. )}
  214. </div>
  215. )
  216. }
  217. export default React.memo(PluginItem)