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.

преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
Introduce Plugins (#13836) Signed-off-by: yihong0618 <zouzou0208@gmail.com> Signed-off-by: -LAN- <laipz8200@outlook.com> Signed-off-by: xhe <xw897002528@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: takatost <takatost@gmail.com> Co-authored-by: kurokobo <kuro664@gmail.com> Co-authored-by: Novice Lee <novicelee@NoviPro.local> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: AkaraChen <akarachen@outlook.com> Co-authored-by: Yi <yxiaoisme@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: JzoNg <jzongcode@gmail.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: Hiroshi Fujita <fujita-h@users.noreply.github.com> Co-authored-by: AkaraChen <85140972+AkaraChen@users.noreply.github.com> Co-authored-by: NFish <douxc512@gmail.com> Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: Novice <857526207@qq.com> Co-authored-by: Hiroki Nagai <82458324+nagaihiroki-git@users.noreply.github.com> Co-authored-by: Gen Sato <52241300+halogen22@users.noreply.github.com> Co-authored-by: eux <euxuuu@gmail.com> Co-authored-by: huangzhuo1949 <167434202+huangzhuo1949@users.noreply.github.com> Co-authored-by: huangzhuo <huangzhuo1@xiaomi.com> Co-authored-by: lotsik <lotsik@mail.ru> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: nite-knite <nkCoding@gmail.com> Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: gakkiyomi <gakkiyomi@aliyun.com> Co-authored-by: CN-P5 <heibai2006@gmail.com> Co-authored-by: CN-P5 <heibai2006@qq.com> Co-authored-by: Chuehnone <1897025+chuehnone@users.noreply.github.com> Co-authored-by: yihong <zouzou0208@gmail.com> Co-authored-by: Kevin9703 <51311316+Kevin9703@users.noreply.github.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: Boris Feld <lothiraldan@gmail.com> Co-authored-by: mbo <himabo@gmail.com> Co-authored-by: mabo <mabo@aeyes.ai> Co-authored-by: Warren Chen <warren.chen830@gmail.com> Co-authored-by: JzoNgKVO <27049666+JzoNgKVO@users.noreply.github.com> Co-authored-by: jiandanfeng <chenjh3@wangsu.com> Co-authored-by: zhu-an <70234959+xhdd123321@users.noreply.github.com> Co-authored-by: zhaoqingyu.1075 <zhaoqingyu.1075@bytedance.com> Co-authored-by: 海狸大師 <86974027+yenslife@users.noreply.github.com> Co-authored-by: Xu Song <xusong.vip@gmail.com> Co-authored-by: rayshaw001 <396301947@163.com> Co-authored-by: Ding Jiatong <dingjiatong@gmail.com> Co-authored-by: Bowen Liang <liangbowen@gf.com.cn> Co-authored-by: JasonVV <jasonwangiii@outlook.com> Co-authored-by: le0zh <newlight@qq.com> Co-authored-by: zhuxinliang <zhuxinliang@didiglobal.com> Co-authored-by: k-zaku <zaku99@outlook.jp> Co-authored-by: luckylhb90 <luckylhb90@gmail.com> Co-authored-by: hobo.l <hobo.l@binance.com> Co-authored-by: jiangbo721 <365065261@qq.com> Co-authored-by: 刘江波 <jiangbo721@163.com> Co-authored-by: Shun Miyazawa <34241526+miya@users.noreply.github.com> Co-authored-by: EricPan <30651140+Egfly@users.noreply.github.com> Co-authored-by: crazywoola <427733928@qq.com> Co-authored-by: sino <sino2322@gmail.com> Co-authored-by: Jhvcc <37662342+Jhvcc@users.noreply.github.com> Co-authored-by: lowell <lowell.hu@zkteco.in> Co-authored-by: Boris Polonsky <BorisPolonsky@users.noreply.github.com> Co-authored-by: Ademílson Tonato <ademilsonft@outlook.com> Co-authored-by: Ademílson Tonato <ademilson.tonato@refurbed.com> Co-authored-by: IWAI, Masaharu <iwaim.sub@gmail.com> Co-authored-by: Yueh-Po Peng (Yabi) <94939112+y10ab1@users.noreply.github.com> Co-authored-by: Jason <ggbbddjm@gmail.com> Co-authored-by: Xin Zhang <sjhpzx@gmail.com> Co-authored-by: yjc980121 <3898524+yjc980121@users.noreply.github.com> Co-authored-by: heyszt <36215648+hieheihei@users.noreply.github.com> Co-authored-by: Abdullah AlOsaimi <osaimiacc@gmail.com> Co-authored-by: Abdullah AlOsaimi <189027247+osaimi@users.noreply.github.com> Co-authored-by: Yingchun Lai <laiyingchun@apache.org> Co-authored-by: Hash Brown <hi@xzd.me> Co-authored-by: zuodongxu <192560071+zuodongxu@users.noreply.github.com> Co-authored-by: Masashi Tomooka <tmokmss@users.noreply.github.com> Co-authored-by: aplio <ryo.091219@gmail.com> Co-authored-by: Obada Khalili <54270856+obadakhalili@users.noreply.github.com> Co-authored-by: Nam Vu <zuzoovn@gmail.com> Co-authored-by: Kei YAMAZAKI <1715090+kei-yamazaki@users.noreply.github.com> Co-authored-by: TechnoHouse <13776377+deephbz@users.noreply.github.com> Co-authored-by: Riddhimaan-Senapati <114703025+Riddhimaan-Senapati@users.noreply.github.com> Co-authored-by: MaFee921 <31881301+2284730142@users.noreply.github.com> Co-authored-by: te-chan <t-nakanome@sakura-is.co.jp> Co-authored-by: HQidea <HQidea@users.noreply.github.com> Co-authored-by: Joshbly <36315710+Joshbly@users.noreply.github.com> Co-authored-by: xhe <xw897002528@gmail.com> Co-authored-by: weiwenyan-dev <154779315+weiwenyan-dev@users.noreply.github.com> Co-authored-by: ex_wenyan.wei <ex_wenyan.wei@tcl.com> Co-authored-by: engchina <12236799+engchina@users.noreply.github.com> Co-authored-by: engchina <atjapan2015@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: 呆萌闷油瓶 <253605712@qq.com> Co-authored-by: Kemal <kemalmeler@outlook.com> Co-authored-by: Lazy_Frog <4590648+lazyFrogLOL@users.noreply.github.com> Co-authored-by: Yi Xiao <54782454+YIXIAO0@users.noreply.github.com> Co-authored-by: Steven sun <98230804+Tuyohai@users.noreply.github.com> Co-authored-by: steven <sunzwj@digitalchina.com> Co-authored-by: Kalo Chin <91766386+fdb02983rhy@users.noreply.github.com> Co-authored-by: Katy Tao <34019945+KatyTao@users.noreply.github.com> Co-authored-by: depy <42985524+h4ckdepy@users.noreply.github.com> Co-authored-by: 胡春东 <gycm520@gmail.com> Co-authored-by: Junjie.M <118170653@qq.com> Co-authored-by: MuYu <mr.muzea@gmail.com> Co-authored-by: Naoki Takashima <39912547+takatea@users.noreply.github.com> Co-authored-by: Summer-Gu <37869445+gubinjie@users.noreply.github.com> Co-authored-by: Fei He <droxer.he@gmail.com> Co-authored-by: ybalbert001 <120714773+ybalbert001@users.noreply.github.com> Co-authored-by: Yuanbo Li <ybalbert@amazon.com> Co-authored-by: douxc <7553076+douxc@users.noreply.github.com> Co-authored-by: liuzhenghua <1090179900@qq.com> Co-authored-by: Wu Jiayang <62842862+Wu-Jiayang@users.noreply.github.com> Co-authored-by: Your Name <you@example.com> Co-authored-by: kimjion <45935338+kimjion@users.noreply.github.com> Co-authored-by: AugNSo <song.tiankai@icloud.com> Co-authored-by: llinvokerl <38915183+llinvokerl@users.noreply.github.com> Co-authored-by: liusurong.lsr <liusurong.lsr@alibaba-inc.com> Co-authored-by: Vasu Negi <vasu-negi@users.noreply.github.com> Co-authored-by: Hundredwz <1808096180@qq.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com>
преди 8 месеца
преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
преди 2 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. 'use client'
  2. import React, { useMemo, useState } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import { RiArrowRightLine, RiFolder6Line } from '@remixicon/react'
  5. import FilePreview from '../file-preview'
  6. import FileUploader from '../file-uploader'
  7. import NotionPagePreview from '../notion-page-preview'
  8. import EmptyDatasetCreationModal from '../empty-dataset-creation-modal'
  9. import Website from '../website'
  10. import WebsitePreview from '../website/preview'
  11. import s from './index.module.css'
  12. import cn from '@/utils/classnames'
  13. import type { CrawlOptions, CrawlResultItem, FileItem } from '@/models/datasets'
  14. import type { DataSourceProvider, NotionPage } from '@/models/common'
  15. import { DataSourceType } from '@/models/datasets'
  16. import Button from '@/app/components/base/button'
  17. import { NotionPageSelector } from '@/app/components/base/notion-page-selector'
  18. import { useDatasetDetailContext } from '@/context/dataset-detail'
  19. import { useProviderContext } from '@/context/provider-context'
  20. import VectorSpaceFull from '@/app/components/billing/vector-space-full'
  21. import classNames from '@/utils/classnames'
  22. type IStepOneProps = {
  23. datasetId?: string
  24. dataSourceType?: DataSourceType
  25. dataSourceTypeDisable: boolean
  26. hasConnection: boolean
  27. onSetting: () => void
  28. files: FileItem[]
  29. updateFileList: (files: FileItem[]) => void
  30. updateFile: (fileItem: FileItem, progress: number, list: FileItem[]) => void
  31. notionPages?: NotionPage[]
  32. updateNotionPages: (value: NotionPage[]) => void
  33. onStepChange: () => void
  34. changeType: (type: DataSourceType) => void
  35. websitePages?: CrawlResultItem[]
  36. updateWebsitePages: (value: CrawlResultItem[]) => void
  37. onWebsiteCrawlProviderChange: (provider: DataSourceProvider) => void
  38. onWebsiteCrawlJobIdChange: (jobId: string) => void
  39. crawlOptions: CrawlOptions
  40. onCrawlOptionsChange: (payload: CrawlOptions) => void
  41. }
  42. type NotionConnectorProps = {
  43. onSetting: () => void
  44. }
  45. export const NotionConnector = ({ onSetting }: NotionConnectorProps) => {
  46. const { t } = useTranslation()
  47. return (
  48. <div className={s.notionConnectionTip}>
  49. <span className={s.notionIcon} />
  50. <div className={s.title}>{t('datasetCreation.stepOne.notionSyncTitle')}</div>
  51. <div className={s.tip}>{t('datasetCreation.stepOne.notionSyncTip')}</div>
  52. <Button className='h-8' variant='primary' onClick={onSetting}>{t('datasetCreation.stepOne.connect')}</Button>
  53. </div>
  54. )
  55. }
  56. const StepOne = ({
  57. datasetId,
  58. dataSourceType: inCreatePageDataSourceType,
  59. dataSourceTypeDisable,
  60. changeType,
  61. hasConnection,
  62. onSetting,
  63. onStepChange,
  64. files,
  65. updateFileList,
  66. updateFile,
  67. notionPages = [],
  68. updateNotionPages,
  69. websitePages = [],
  70. updateWebsitePages,
  71. onWebsiteCrawlProviderChange,
  72. onWebsiteCrawlJobIdChange,
  73. crawlOptions,
  74. onCrawlOptionsChange,
  75. }: IStepOneProps) => {
  76. const { dataset } = useDatasetDetailContext()
  77. const [showModal, setShowModal] = useState(false)
  78. const [currentFile, setCurrentFile] = useState<File | undefined>()
  79. const [currentNotionPage, setCurrentNotionPage] = useState<NotionPage | undefined>()
  80. const [currentWebsite, setCurrentWebsite] = useState<CrawlResultItem | undefined>()
  81. const { t } = useTranslation()
  82. const modalShowHandle = () => setShowModal(true)
  83. const modalCloseHandle = () => setShowModal(false)
  84. const updateCurrentFile = (file: File) => {
  85. setCurrentFile(file)
  86. }
  87. const hideFilePreview = () => {
  88. setCurrentFile(undefined)
  89. }
  90. const updateCurrentPage = (page: NotionPage) => {
  91. setCurrentNotionPage(page)
  92. }
  93. const hideNotionPagePreview = () => {
  94. setCurrentNotionPage(undefined)
  95. }
  96. const hideWebsitePreview = () => {
  97. setCurrentWebsite(undefined)
  98. }
  99. const shouldShowDataSourceTypeList = !datasetId || (datasetId && !dataset?.data_source_type)
  100. const isInCreatePage = shouldShowDataSourceTypeList
  101. const dataSourceType = isInCreatePage ? inCreatePageDataSourceType : dataset?.data_source_type
  102. const { plan, enableBilling } = useProviderContext()
  103. const allFileLoaded = (files.length > 0 && files.every(file => file.file.id))
  104. const hasNotin = notionPages.length > 0
  105. const isVectorSpaceFull = plan.usage.vectorSpace >= plan.total.vectorSpace
  106. const isShowVectorSpaceFull = (allFileLoaded || hasNotin) && isVectorSpaceFull && enableBilling
  107. const notSupportBatchUpload = enableBilling && plan.type === 'sandbox'
  108. const nextDisabled = useMemo(() => {
  109. if (!files.length)
  110. return true
  111. if (files.some(file => !file.file.id))
  112. return true
  113. if (isShowVectorSpaceFull)
  114. return true
  115. return false
  116. }, [files, isShowVectorSpaceFull])
  117. return (
  118. <div className='flex w-full h-full'>
  119. <div className='w-1/2 h-full overflow-y-auto relative'>
  120. <div className='flex justify-end'>
  121. <div className={classNames(s.form)}>
  122. {
  123. shouldShowDataSourceTypeList && (
  124. <div className={classNames(s.stepHeader, 'z-10 text-text-secondary bg-components-panel-bg-blur')}>{t('datasetCreation.steps.one')}</div>
  125. )
  126. }
  127. {
  128. shouldShowDataSourceTypeList && (
  129. <div className='grid grid-cols-3 mb-8 gap-4'>
  130. <div
  131. className={cn(
  132. s.dataSourceItem,
  133. dataSourceType === DataSourceType.FILE && s.active,
  134. dataSourceTypeDisable && dataSourceType !== DataSourceType.FILE && s.disabled,
  135. )}
  136. onClick={() => {
  137. if (dataSourceTypeDisable)
  138. return
  139. changeType(DataSourceType.FILE)
  140. hideFilePreview()
  141. hideNotionPagePreview()
  142. }}
  143. >
  144. <span className={cn(s.datasetIcon)} />
  145. <span
  146. title={t('datasetCreation.stepOne.dataSourceType.file')}
  147. className='truncate'
  148. >
  149. {t('datasetCreation.stepOne.dataSourceType.file')}
  150. </span>
  151. </div>
  152. <div
  153. className={cn(
  154. s.dataSourceItem,
  155. dataSourceType === DataSourceType.NOTION && s.active,
  156. dataSourceTypeDisable && dataSourceType !== DataSourceType.NOTION && s.disabled,
  157. )}
  158. onClick={() => {
  159. if (dataSourceTypeDisable)
  160. return
  161. changeType(DataSourceType.NOTION)
  162. hideFilePreview()
  163. hideNotionPagePreview()
  164. }}
  165. >
  166. <span className={cn(s.datasetIcon, s.notion)} />
  167. <span
  168. title={t('datasetCreation.stepOne.dataSourceType.notion')}
  169. className='truncate'
  170. >
  171. {t('datasetCreation.stepOne.dataSourceType.notion')}
  172. </span>
  173. </div>
  174. <div
  175. className={cn(
  176. s.dataSourceItem,
  177. dataSourceType === DataSourceType.WEB && s.active,
  178. dataSourceTypeDisable && dataSourceType !== DataSourceType.WEB && s.disabled,
  179. )}
  180. onClick={() => changeType(DataSourceType.WEB)}
  181. >
  182. <span className={cn(s.datasetIcon, s.web)} />
  183. <span
  184. title={t('datasetCreation.stepOne.dataSourceType.web')}
  185. className='truncate'
  186. >
  187. {t('datasetCreation.stepOne.dataSourceType.web')}
  188. </span>
  189. </div>
  190. </div>
  191. )
  192. }
  193. {dataSourceType === DataSourceType.FILE && (
  194. <>
  195. <FileUploader
  196. fileList={files}
  197. titleClassName={!shouldShowDataSourceTypeList ? 'mt-[30px] !mb-[44px] !text-lg !font-semibold !text-gray-900' : undefined}
  198. prepareFileList={updateFileList}
  199. onFileListUpdate={updateFileList}
  200. onFileUpdate={updateFile}
  201. onPreview={updateCurrentFile}
  202. notSupportBatchUpload={notSupportBatchUpload}
  203. />
  204. {isShowVectorSpaceFull && (
  205. <div className='max-w-[640px] mb-4'>
  206. <VectorSpaceFull />
  207. </div>
  208. )}
  209. <div className="flex justify-end gap-2 max-w-[640px]">
  210. {/* <Button>{t('datasetCreation.stepOne.cancel')}</Button> */}
  211. <Button disabled={nextDisabled} variant='primary' onClick={onStepChange}>
  212. <span className="flex gap-0.5 px-[10px]">
  213. <span className="px-0.5">{t('datasetCreation.stepOne.button')}</span>
  214. <RiArrowRightLine className="size-4" />
  215. </span>
  216. </Button>
  217. </div>
  218. </>
  219. )}
  220. {dataSourceType === DataSourceType.NOTION && (
  221. <>
  222. {!hasConnection && <NotionConnector onSetting={onSetting} />}
  223. {hasConnection && (
  224. <>
  225. <div className='mb-8 w-[640px]'>
  226. <NotionPageSelector
  227. value={notionPages.map(page => page.page_id)}
  228. onSelect={updateNotionPages}
  229. onPreview={updateCurrentPage}
  230. />
  231. </div>
  232. {isShowVectorSpaceFull && (
  233. <div className='max-w-[640px] mb-4'>
  234. <VectorSpaceFull />
  235. </div>
  236. )}
  237. <div className="flex justify-end gap-2 max-w-[640px]">
  238. {/* <Button>{t('datasetCreation.stepOne.cancel')}</Button> */}
  239. <Button disabled={isShowVectorSpaceFull || !notionPages.length} variant='primary' onClick={onStepChange}>
  240. <span className="flex gap-0.5 px-[10px]">
  241. <span className="px-0.5">{t('datasetCreation.stepOne.button')}</span>
  242. <RiArrowRightLine className="size-4" />
  243. </span>
  244. </Button>
  245. </div>
  246. </>
  247. )}
  248. </>
  249. )}
  250. {dataSourceType === DataSourceType.WEB && (
  251. <>
  252. <div className={cn('mb-8 w-[640px]', !shouldShowDataSourceTypeList && 'mt-12')}>
  253. <Website
  254. onPreview={setCurrentWebsite}
  255. checkedCrawlResult={websitePages}
  256. onCheckedCrawlResultChange={updateWebsitePages}
  257. onCrawlProviderChange={onWebsiteCrawlProviderChange}
  258. onJobIdChange={onWebsiteCrawlJobIdChange}
  259. crawlOptions={crawlOptions}
  260. onCrawlOptionsChange={onCrawlOptionsChange}
  261. />
  262. </div>
  263. {isShowVectorSpaceFull && (
  264. <div className='max-w-[640px] mb-4'>
  265. <VectorSpaceFull />
  266. </div>
  267. )}
  268. <div className="flex justify-end gap-2 max-w-[640px]">
  269. {/* <Button>{t('datasetCreation.stepOne.cancel')}</Button> */}
  270. <Button disabled={isShowVectorSpaceFull || !websitePages.length} variant='primary' onClick={onStepChange}>
  271. <span className="flex gap-0.5 px-[10px]">
  272. <span className="px-0.5">{t('datasetCreation.stepOne.button')}</span>
  273. <RiArrowRightLine className="size-4" />
  274. </span>
  275. </Button>
  276. </div>
  277. </>
  278. )}
  279. {!datasetId && (
  280. <>
  281. <div className={s.dividerLine} />
  282. <span className="inline-flex items-center cursor-pointer text-[13px] leading-4 text-text-accent" onClick={modalShowHandle}>
  283. <RiFolder6Line className="size-4 mr-1" />
  284. {t('datasetCreation.stepOne.emptyDatasetCreation')}
  285. </span>
  286. </>
  287. )}
  288. </div>
  289. <EmptyDatasetCreationModal show={showModal} onHide={modalCloseHandle} />
  290. </div>
  291. </div>
  292. <div className='w-1/2 h-full overflow-y-auto'>
  293. {currentFile && <FilePreview file={currentFile} hidePreview={hideFilePreview} />}
  294. {currentNotionPage && <NotionPagePreview currentPage={currentNotionPage} hidePreview={hideNotionPagePreview} />}
  295. {currentWebsite && <WebsitePreview payload={currentWebsite} hidePreview={hideWebsitePreview} />}
  296. </div>
  297. </div>
  298. )
  299. }
  300. export default StepOne