| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  | import type { FC } from 'react' | 
					
						
							| 
									
										
										
										
											2024-04-12 16:02:56 +08:00
										 |  |  | import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import useSWR from 'swr' | 
					
						
							|  |  |  | import { useContext } from 'use-context-selector' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							|  |  |  | import { omit } from 'lodash-es' | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  | import { RiLoader2Line, RiPauseCircleLine, RiPlayCircleLine } from '@remixicon/react' | 
					
						
							|  |  |  | import Image from 'next/image' | 
					
						
							| 
									
										
										
										
											2023-05-30 15:26:26 +08:00
										 |  |  | import { FieldInfo } from '../metadata' | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  | import { useDocumentContext } from '../index' | 
					
						
							|  |  |  | import { IndexingType } from '../../../create/step-two' | 
					
						
							|  |  |  | import { indexMethodIcon, retrievalIcon } from '../../../create/icons' | 
					
						
							|  |  |  | import EmbeddingSkeleton from './skeleton' | 
					
						
							|  |  |  | import { RETRIEVE_METHOD } from '@/types/app' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import Divider from '@/app/components/base/divider' | 
					
						
							|  |  |  | import { ToastContext } from '@/app/components/base/toast' | 
					
						
							| 
									
										
										
										
											2025-04-14 16:06:10 +08:00
										 |  |  | import type { IndexingStatusResponse } from '@/models/datasets' | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  | import { ProcessMode, type ProcessRuleResponse } from '@/models/datasets' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import type { CommonResponse } from '@/models/common' | 
					
						
							| 
									
										
										
										
											2024-04-12 16:02:56 +08:00
										 |  |  | import { asyncRunSafe, sleep } from '@/utils' | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   fetchIndexingStatus as doFetchIndexingStatus, | 
					
						
							|  |  |  |   fetchProcessRule, | 
					
						
							|  |  |  |   pauseDocIndexing, | 
					
						
							|  |  |  |   resumeDocIndexing, | 
					
						
							|  |  |  | } from '@/service/datasets' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  | type IEmbeddingDetailProps = { | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   datasetId?: string | 
					
						
							|  |  |  |   documentId?: string | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |   indexingType?: IndexingType | 
					
						
							|  |  |  |   retrievalMethod?: RETRIEVE_METHOD | 
					
						
							| 
									
										
										
										
											2023-07-28 20:47:15 +08:00
										 |  |  |   detailUpdate: VoidFunction | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  | type IRuleDetailProps = { | 
					
						
							|  |  |  |   sourceData?: ProcessRuleResponse | 
					
						
							|  |  |  |   indexingType?: IndexingType | 
					
						
							|  |  |  |   retrievalMethod?: RETRIEVE_METHOD | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  | const RuleDetail: FC<IRuleDetailProps> = React.memo(({ | 
					
						
							|  |  |  |   sourceData, | 
					
						
							|  |  |  |   indexingType, | 
					
						
							|  |  |  |   retrievalMethod, | 
					
						
							|  |  |  | }) => { | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const segmentationRuleMap = { | 
					
						
							|  |  |  |     mode: t('datasetDocuments.embedding.mode'), | 
					
						
							|  |  |  |     segmentLength: t('datasetDocuments.embedding.segmentLength'), | 
					
						
							|  |  |  |     textCleaning: t('datasetDocuments.embedding.textCleaning'), | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-05-30 15:26:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const getRuleName = (key: string) => { | 
					
						
							|  |  |  |     if (key === 'remove_extra_spaces') | 
					
						
							|  |  |  |       return t('datasetCreation.stepTwo.removeExtraSpaces') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (key === 'remove_urls_emails') | 
					
						
							|  |  |  |       return t('datasetCreation.stepTwo.removeUrlEmails') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (key === 'remove_stopwords') | 
					
						
							|  |  |  |       return t('datasetCreation.stepTwo.removeStopwords') | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |   const isNumber = (value: unknown) => { | 
					
						
							|  |  |  |     return typeof value === 'number' | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   const getValue = useCallback((field: string) => { | 
					
						
							| 
									
										
										
										
											2023-05-30 15:26:26 +08:00
										 |  |  |     let value: string | number | undefined = '-' | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |     const maxTokens = isNumber(sourceData?.rules?.segmentation?.max_tokens) | 
					
						
							|  |  |  |       ? sourceData.rules.segmentation.max_tokens | 
					
						
							|  |  |  |       : value | 
					
						
							|  |  |  |     const childMaxTokens = isNumber(sourceData?.rules?.subchunk_segmentation?.max_tokens) | 
					
						
							|  |  |  |       ? sourceData.rules.subchunk_segmentation.max_tokens | 
					
						
							|  |  |  |       : value | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     switch (field) { | 
					
						
							|  |  |  |       case 'mode': | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |         value = !sourceData?.mode | 
					
						
							|  |  |  |           ? value | 
					
						
							|  |  |  |           : sourceData.mode === ProcessMode.general | 
					
						
							|  |  |  |             ? (t('datasetDocuments.embedding.custom') as string) | 
					
						
							|  |  |  |             : `${t('datasetDocuments.embedding.hierarchical')} · ${sourceData?.rules?.parent_mode === 'paragraph' | 
					
						
							|  |  |  |               ? t('dataset.parentMode.paragraph') | 
					
						
							|  |  |  |               : t('dataset.parentMode.fullDoc')}`
 | 
					
						
							| 
									
										
										
										
											2023-05-30 15:26:26 +08:00
										 |  |  |         break | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |       case 'segmentLength': | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |         value = !sourceData?.mode | 
					
						
							|  |  |  |           ? value | 
					
						
							|  |  |  |           : sourceData.mode === ProcessMode.general | 
					
						
							|  |  |  |             ? maxTokens | 
					
						
							|  |  |  |             : `${t('datasetDocuments.embedding.parentMaxTokens')} ${maxTokens}; ${t('datasetDocuments.embedding.childMaxTokens')} ${childMaxTokens}` | 
					
						
							| 
									
										
										
										
											2023-05-30 15:26:26 +08:00
										 |  |  |         break | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |       default: | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |         value = !sourceData?.mode | 
					
						
							|  |  |  |           ? value | 
					
						
							|  |  |  |           : sourceData?.rules?.pre_processing_rules?.filter(rule => | 
					
						
							|  |  |  |             rule.enabled).map(rule => getRuleName(rule.id)).join(',') | 
					
						
							| 
									
										
										
										
											2023-05-30 15:26:26 +08:00
										 |  |  |         break | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     return value | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |     // eslint-disable-next-line react-hooks/exhaustive-deps
 | 
					
						
							|  |  |  |   }, [sourceData]) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |   return <div className='py-3'> | 
					
						
							|  |  |  |     <div className='flex flex-col gap-y-1'> | 
					
						
							|  |  |  |       {Object.keys(segmentationRuleMap).map((field) => { | 
					
						
							|  |  |  |         return <FieldInfo | 
					
						
							|  |  |  |           key={field} | 
					
						
							|  |  |  |           label={segmentationRuleMap[field as keyof typeof segmentationRuleMap]} | 
					
						
							|  |  |  |           displayedValue={String(getValue(field))} | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       })} | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |     <Divider type='horizontal' className='bg-divider-subtle' /> | 
					
						
							|  |  |  |     <FieldInfo | 
					
						
							|  |  |  |       label={t('datasetCreation.stepTwo.indexMode')} | 
					
						
							|  |  |  |       displayedValue={t(`datasetCreation.stepTwo.${indexingType === IndexingType.ECONOMICAL ? 'economical' : 'qualified'}`) as string} | 
					
						
							|  |  |  |       valueIcon={ | 
					
						
							|  |  |  |         <Image | 
					
						
							|  |  |  |           className='size-4' | 
					
						
							|  |  |  |           src={ | 
					
						
							|  |  |  |             indexingType === IndexingType.ECONOMICAL | 
					
						
							|  |  |  |               ? indexMethodIcon.economical | 
					
						
							|  |  |  |               : indexMethodIcon.high_quality | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           alt='' | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     /> | 
					
						
							|  |  |  |     <FieldInfo | 
					
						
							|  |  |  |       label={t('datasetSettings.form.retrievalSetting.title')} | 
					
						
							|  |  |  |       displayedValue={t(`dataset.retrieval.${indexingType === IndexingType.ECONOMICAL ? 'invertedIndex' : retrievalMethod}.title`) as string} | 
					
						
							|  |  |  |       valueIcon={ | 
					
						
							|  |  |  |         <Image | 
					
						
							|  |  |  |           className='size-4' | 
					
						
							|  |  |  |           src={ | 
					
						
							|  |  |  |             retrievalMethod === RETRIEVE_METHOD.fullText | 
					
						
							|  |  |  |               ? retrievalIcon.fullText | 
					
						
							|  |  |  |               : retrievalMethod === RETRIEVE_METHOD.hybrid | 
					
						
							|  |  |  |                 ? retrievalIcon.hybrid | 
					
						
							|  |  |  |                 : retrievalIcon.vector | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           alt='' | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     /> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   </div> | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RuleDetail.displayName = 'RuleDetail' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  | const EmbeddingDetail: FC<IEmbeddingDetailProps> = ({ | 
					
						
							|  |  |  |   datasetId: dstId, | 
					
						
							|  |  |  |   documentId: docId, | 
					
						
							|  |  |  |   detailUpdate, | 
					
						
							|  |  |  |   indexingType, | 
					
						
							|  |  |  |   retrievalMethod, | 
					
						
							|  |  |  | }) => { | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  |   const { notify } = useContext(ToastContext) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |   const datasetId = useDocumentContext(s => s.datasetId) | 
					
						
							|  |  |  |   const documentId = useDocumentContext(s => s.documentId) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   const localDatasetId = dstId ?? datasetId | 
					
						
							|  |  |  |   const localDocumentId = docId ?? documentId | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-14 16:06:10 +08:00
										 |  |  |   const [indexingStatusDetail, setIndexingStatusDetail] = useState<IndexingStatusResponse | null>(null) | 
					
						
							| 
									
										
										
										
											2023-06-01 23:19:36 +08:00
										 |  |  |   const fetchIndexingStatus = async () => { | 
					
						
							| 
									
										
										
										
											2024-04-12 16:02:56 +08:00
										 |  |  |     const status = await doFetchIndexingStatus({ datasetId: localDatasetId, documentId: localDocumentId }) | 
					
						
							|  |  |  |     setIndexingStatusDetail(status) | 
					
						
							|  |  |  |     return status | 
					
						
							| 
									
										
										
										
											2023-06-01 23:19:36 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-31 08:07:48 +00:00
										 |  |  |   const isStopQuery = useRef(false) | 
					
						
							|  |  |  |   const stopQueryStatus = useCallback(() => { | 
					
						
							|  |  |  |     isStopQuery.current = true | 
					
						
							|  |  |  |   }, []) | 
					
						
							| 
									
										
										
										
											2023-06-01 23:40:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-31 08:07:48 +00:00
										 |  |  |   const startQueryStatus = useCallback(async () => { | 
					
						
							|  |  |  |     if (isStopQuery.current) | 
					
						
							| 
									
										
										
										
											2024-04-12 16:02:56 +08:00
										 |  |  |       return | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       const indexingStatusDetail = await fetchIndexingStatus() | 
					
						
							|  |  |  |       if (['completed', 'error', 'paused'].includes(indexingStatusDetail?.indexing_status)) { | 
					
						
							| 
									
										
										
										
											2023-06-01 23:19:36 +08:00
										 |  |  |         stopQueryStatus() | 
					
						
							| 
									
										
										
										
											2023-07-28 20:47:15 +08:00
										 |  |  |         detailUpdate() | 
					
						
							| 
									
										
										
										
											2023-06-01 23:19:36 +08:00
										 |  |  |         return | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-05-31 08:07:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-12 16:02:56 +08:00
										 |  |  |       await sleep(2500) | 
					
						
							|  |  |  |       await startQueryStatus() | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-04-14 11:27:14 +08:00
										 |  |  |     catch { | 
					
						
							| 
									
										
										
										
											2024-04-12 16:02:56 +08:00
										 |  |  |       await sleep(2500) | 
					
						
							|  |  |  |       await startQueryStatus() | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |     // eslint-disable-next-line react-hooks/exhaustive-deps
 | 
					
						
							| 
									
										
										
										
											2024-05-31 08:07:48 +00:00
										 |  |  |   }, [stopQueryStatus]) | 
					
						
							| 
									
										
										
										
											2023-06-01 23:19:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   useEffect(() => { | 
					
						
							| 
									
										
										
										
											2024-05-31 08:07:48 +00:00
										 |  |  |     isStopQuery.current = false | 
					
						
							| 
									
										
										
										
											2024-04-12 16:02:56 +08:00
										 |  |  |     startQueryStatus() | 
					
						
							| 
									
										
										
										
											2023-06-01 23:19:36 +08:00
										 |  |  |     return () => { | 
					
						
							|  |  |  |       stopQueryStatus() | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-05-31 08:07:48 +00:00
										 |  |  |   }, [startQueryStatus, stopQueryStatus]) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |   const { data: ruleDetail } = useSWR({ | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     action: 'fetchProcessRule', | 
					
						
							| 
									
										
										
										
											2023-05-30 15:26:26 +08:00
										 |  |  |     params: { documentId: localDocumentId }, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   }, apiParams => fetchProcessRule(omit(apiParams, 'action')), { | 
					
						
							|  |  |  |     revalidateOnFocus: false, | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const isEmbedding = useMemo(() => ['indexing', 'splitting', 'parsing', 'cleaning'].includes(indexingStatusDetail?.indexing_status || ''), [indexingStatusDetail]) | 
					
						
							|  |  |  |   const isEmbeddingCompleted = useMemo(() => ['completed'].includes(indexingStatusDetail?.indexing_status || ''), [indexingStatusDetail]) | 
					
						
							|  |  |  |   const isEmbeddingPaused = useMemo(() => ['paused'].includes(indexingStatusDetail?.indexing_status || ''), [indexingStatusDetail]) | 
					
						
							|  |  |  |   const isEmbeddingError = useMemo(() => ['error'].includes(indexingStatusDetail?.indexing_status || ''), [indexingStatusDetail]) | 
					
						
							|  |  |  |   const percent = useMemo(() => { | 
					
						
							|  |  |  |     const completedCount = indexingStatusDetail?.completed_segments || 0 | 
					
						
							|  |  |  |     const totalCount = indexingStatusDetail?.total_segments || 0 | 
					
						
							| 
									
										
										
										
											2023-05-30 15:26:26 +08:00
										 |  |  |     if (totalCount === 0) | 
					
						
							|  |  |  |       return 0 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     const percent = Math.round(completedCount * 100 / totalCount) | 
					
						
							|  |  |  |     return percent > 100 ? 100 : percent | 
					
						
							|  |  |  |   }, [indexingStatusDetail]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const handleSwitch = async () => { | 
					
						
							|  |  |  |     const opApi = isEmbedding ? pauseDocIndexing : resumeDocIndexing | 
					
						
							|  |  |  |     const [e] = await asyncRunSafe<CommonResponse>(opApi({ datasetId: localDatasetId, documentId: localDocumentId }) as Promise<CommonResponse>) | 
					
						
							|  |  |  |     if (!e) { | 
					
						
							|  |  |  |       notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |       // if the embedding is resumed from paused, we need to start the query status
 | 
					
						
							|  |  |  |       if (isEmbeddingPaused) { | 
					
						
							|  |  |  |         isStopQuery.current = false | 
					
						
							|  |  |  |         startQueryStatus() | 
					
						
							|  |  |  |         detailUpdate() | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2023-06-01 23:19:36 +08:00
										 |  |  |       setIndexingStatusDetail(null) | 
					
						
							| 
									
										
										
										
											2023-05-30 15:26:26 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2023-09-05 09:13:59 +08:00
										 |  |  |       notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |       <div className='flex flex-col gap-y-2 px-16 py-12'> | 
					
						
							|  |  |  |         <div className='flex h-6 items-center gap-x-1'> | 
					
						
							|  |  |  |           {isEmbedding && <RiLoader2Line className='h-4 w-4 animate-spin text-text-secondary' />} | 
					
						
							|  |  |  |           <span className='system-md-semibold-uppercase grow text-text-secondary'> | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |             {isEmbedding && t('datasetDocuments.embedding.processing')} | 
					
						
							|  |  |  |             {isEmbeddingCompleted && t('datasetDocuments.embedding.completed')} | 
					
						
							|  |  |  |             {isEmbeddingPaused && t('datasetDocuments.embedding.paused')} | 
					
						
							|  |  |  |             {isEmbeddingError && t('datasetDocuments.embedding.error')} | 
					
						
							|  |  |  |           </span> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |           {isEmbedding && ( | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |             <button | 
					
						
							|  |  |  |               type='button' | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |               className={`flex items-center gap-x-1 rounded-md border-[0.5px]
 | 
					
						
							|  |  |  |               border-components-button-secondary-border bg-components-button-secondary-bg px-1.5 py-1 shadow-xs shadow-shadow-shadow-3 backdrop-blur-[5px]`}
 | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |               onClick={handleSwitch} | 
					
						
							|  |  |  |             > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |               <RiPauseCircleLine className='h-3.5 w-3.5 text-components-button-secondary-text' /> | 
					
						
							|  |  |  |               <span className='system-xs-medium pr-[3px] text-components-button-secondary-text'> | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |                 {t('datasetDocuments.embedding.pause')} | 
					
						
							|  |  |  |               </span> | 
					
						
							|  |  |  |             </button> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |           )} | 
					
						
							|  |  |  |           {isEmbeddingPaused && ( | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |             <button | 
					
						
							|  |  |  |               type='button' | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |               className={`flex items-center gap-x-1 rounded-md border-[0.5px]
 | 
					
						
							|  |  |  |               border-components-button-secondary-border bg-components-button-secondary-bg px-1.5 py-1 shadow-xs shadow-shadow-shadow-3 backdrop-blur-[5px]`}
 | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |               onClick={handleSwitch} | 
					
						
							|  |  |  |             > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |               <RiPlayCircleLine className='h-3.5 w-3.5 text-components-button-secondary-text' /> | 
					
						
							|  |  |  |               <span className='system-xs-medium pr-[3px] text-components-button-secondary-text'> | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |                 {t('datasetDocuments.embedding.resume')} | 
					
						
							|  |  |  |               </span> | 
					
						
							|  |  |  |             </button> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |           )} | 
					
						
							|  |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |         {/* progress bar */} | 
					
						
							|  |  |  |         <div className={cn( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           'flex h-2 w-full items-center overflow-hidden rounded-md border border-components-progress-bar-border', | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |           isEmbedding ? 'bg-components-progress-bar-bg bg-opacity-50' : 'bg-components-progress-bar-bg', | 
					
						
							|  |  |  |         )}> | 
					
						
							|  |  |  |           <div | 
					
						
							|  |  |  |             className={cn( | 
					
						
							|  |  |  |               'h-full', | 
					
						
							|  |  |  |               (isEmbedding || isEmbeddingCompleted) && 'bg-components-progress-bar-progress-solid', | 
					
						
							|  |  |  |               (isEmbeddingPaused || isEmbeddingError) && 'bg-components-progress-bar-progress-highlight', | 
					
						
							|  |  |  |             )} | 
					
						
							|  |  |  |             style={{ width: `${percent}%` }} | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |         <div className={'flex w-full items-center'}> | 
					
						
							|  |  |  |           <span className='system-xs-medium text-text-secondary'> | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |             {`${t('datasetDocuments.embedding.segments')} ${indexingStatusDetail?.completed_segments || '--'}/${indexingStatusDetail?.total_segments || '--'} · ${percent}%`} | 
					
						
							|  |  |  |           </span> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2024-12-26 12:01:51 +08:00
										 |  |  |         <RuleDetail sourceData={ruleDetail} indexingType={indexingType} retrievalMethod={retrievalMethod} /> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       <EmbeddingSkeleton /> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |     </> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-12 16:02:56 +08:00
										 |  |  | export default React.memo(EmbeddingDetail) |