index.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import type { FC } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import {
  4. RiAddLine,
  5. } from '@remixicon/react'
  6. import type {
  7. ModelProvider,
  8. } from '../declarations'
  9. import { ConfigurationMethodEnum } from '../declarations'
  10. import {
  11. DEFAULT_BACKGROUND_COLOR,
  12. modelTypeFormat,
  13. } from '../utils'
  14. import {
  15. useLanguage,
  16. } from '../hooks'
  17. import ModelBadge from '../model-badge'
  18. import ProviderIcon from '../provider-icon'
  19. import s from './index.module.css'
  20. import { Settings01 } from '@/app/components/base/icons/src/vender/line/general'
  21. import Button from '@/app/components/base/button'
  22. import { useAppContext } from '@/context/app-context'
  23. type ProviderCardProps = {
  24. provider: ModelProvider
  25. onOpenModal: (configurateMethod: ConfigurationMethodEnum) => void
  26. }
  27. const ProviderCard: FC<ProviderCardProps> = ({
  28. provider,
  29. onOpenModal,
  30. }) => {
  31. const { t } = useTranslation()
  32. const language = useLanguage()
  33. const { isCurrentWorkspaceManager } = useAppContext()
  34. const configurateMethods = provider.configurate_methods.filter(method => method !== ConfigurationMethodEnum.fetchFromRemote)
  35. return (
  36. <div
  37. className='group relative flex flex-col px-4 py-3 h-[148px] border-[0.5px] border-black/5 rounded-xl shadow-xs hover:shadow-lg'
  38. style={{ background: provider.background || DEFAULT_BACKGROUND_COLOR }}
  39. >
  40. <div className='grow h-0'>
  41. <div className='py-0.5'>
  42. <ProviderIcon provider={provider} />
  43. </div>
  44. {
  45. provider.description && (
  46. <div
  47. className='mt-1 leading-4 text-xs text-black/[48] line-clamp-4'
  48. title={provider.description[language] || provider.description.en_US}
  49. >
  50. {provider.description[language] || provider.description.en_US}
  51. </div>
  52. )
  53. }
  54. </div>
  55. <div className='shrink-0'>
  56. <div className={'flex flex-wrap group-hover:hidden gap-0.5'}>
  57. {
  58. provider.supported_model_types.map(modelType => (
  59. <ModelBadge key={modelType}>
  60. {modelTypeFormat(modelType)}
  61. </ModelBadge>
  62. ))
  63. }
  64. </div>
  65. <div className={`hidden group-hover:grid grid-cols-${configurateMethods.length} gap-1`}>
  66. {
  67. configurateMethods.map((method) => {
  68. if (method === ConfigurationMethodEnum.predefinedModel) {
  69. return (
  70. <Button
  71. key={method}
  72. className={'h-7 text-xs shrink-0'}
  73. onClick={() => onOpenModal(method)}
  74. disabled={!isCurrentWorkspaceManager}
  75. >
  76. <Settings01 className={`mr-[5px] w-3.5 h-3.5 ${s.icon}`} />
  77. <span className='text-xs inline-flex items-center justify-center overflow-ellipsis shrink-0'>{t('common.operation.setup')}</span>
  78. </Button>
  79. )
  80. }
  81. return (
  82. <Button
  83. key={method}
  84. className='px-0 h-7 text-xs'
  85. onClick={() => onOpenModal(method)}
  86. disabled={!isCurrentWorkspaceManager}
  87. >
  88. <RiAddLine className='mr-[5px] w-3.5 h-3.5' />
  89. {t('common.modelProvider.addModel')}
  90. </Button>
  91. )
  92. })
  93. }
  94. </div>
  95. </div>
  96. </div>
  97. )
  98. }
  99. export default ProviderCard