| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import type { Fetcher } from 'swr' | 
					
						
							|  |  |  | import qs from 'qs' | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | import { del, get, patch, post, put } from './base' | 
					
						
							| 
									
										
										
										
											2023-07-28 20:47:15 +08:00
										 |  |  | import type { | 
					
						
							|  |  |  |   CreateDocumentReq, | 
					
						
							|  |  |  |   DataSet, | 
					
						
							|  |  |  |   DataSetListResponse, | 
					
						
							| 
									
										
										
										
											2024-04-24 15:02:29 +08:00
										 |  |  |   ErrorDocsResponse, | 
					
						
							| 
									
										
										
										
											2024-09-30 15:38:43 +08:00
										 |  |  |   ExternalAPIDeleteResponse, | 
					
						
							|  |  |  |   ExternalAPIItem, | 
					
						
							|  |  |  |   ExternalAPIListResponse, | 
					
						
							|  |  |  |   ExternalAPIUsage, | 
					
						
							|  |  |  |   ExternalKnowledgeBaseHitTestingResponse, | 
					
						
							|  |  |  |   ExternalKnowledgeItem, | 
					
						
							| 
									
										
										
										
											2025-01-09 17:44:11 +08:00
										 |  |  |   FetchDatasetsParams, | 
					
						
							| 
									
										
										
										
											2023-07-28 20:47:15 +08:00
										 |  |  |   FileIndexingEstimateResponse, | 
					
						
							|  |  |  |   HitTestingRecordsResponse, | 
					
						
							|  |  |  |   HitTestingResponse, | 
					
						
							| 
									
										
										
										
											2023-10-07 17:42:16 +08:00
										 |  |  |   IndexingEstimateParams, | 
					
						
							| 
									
										
										
										
											2023-07-28 20:47:15 +08:00
										 |  |  |   IndexingEstimateResponse, | 
					
						
							|  |  |  |   IndexingStatusBatchResponse, | 
					
						
							|  |  |  |   IndexingStatusResponse, | 
					
						
							|  |  |  |   ProcessRuleResponse, | 
					
						
							|  |  |  |   RelatedAppResponse, | 
					
						
							|  |  |  |   createDocumentResponse, | 
					
						
							|  |  |  | } from '@/models/datasets' | 
					
						
							| 
									
										
										
										
											2024-09-30 15:38:43 +08:00
										 |  |  | import type { CreateKnowledgeBaseReq } from '@/app/components/datasets/external-knowledge-base/create/declarations' | 
					
						
							| 
									
										
										
										
											2024-09-30 21:27:11 +08:00
										 |  |  | import type { CreateExternalAPIReq } from '@/app/components/datasets/external-api/declarations' | 
					
						
							| 
									
										
										
										
											2024-09-30 15:38:43 +08:00
										 |  |  | import type { CommonResponse, DataSourceNotionWorkspace } from '@/models/common' | 
					
						
							| 
									
										
										
										
											2024-09-30 21:27:11 +08:00
										 |  |  | import { DataSourceProvider } from '@/models/common' | 
					
						
							| 
									
										
										
										
											2023-09-27 16:06:49 +08:00
										 |  |  | import type { | 
					
						
							| 
									
										
										
										
											2024-09-08 12:14:11 +07:00
										 |  |  |   ApiKeysListResponse, | 
					
						
							| 
									
										
										
										
											2023-09-27 16:06:49 +08:00
										 |  |  |   CreateApiKeyResponse, | 
					
						
							|  |  |  | } from '@/models/app' | 
					
						
							| 
									
										
										
										
											2023-11-18 11:53:35 +08:00
										 |  |  | import type { RetrievalConfig } from '@/types/app' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // apis for documents in a dataset
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type CommonDocReq = { | 
					
						
							|  |  |  |   datasetId: string | 
					
						
							|  |  |  |   documentId: string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | type BatchReq = { | 
					
						
							|  |  |  |   datasetId: string | 
					
						
							|  |  |  |   batchId: string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | export type SortType = 'created_at' | 'hit_count' | '-created_at' | '-hit_count' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export type MetadataType = 'all' | 'only' | 'without' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-27 10:31:46 +08:00
										 |  |  | export const fetchDatasetDetail: Fetcher<DataSet, string> = (datasetId: string) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return get<DataSet>(`/datasets/${datasetId}`) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-24 15:02:29 +08:00
										 |  |  | export const updateDatasetSetting: Fetcher<DataSet, { | 
					
						
							|  |  |  |   datasetId: string | 
					
						
							|  |  |  |   body: Partial<Pick<DataSet, | 
					
						
							| 
									
										
										
										
											2024-07-09 17:47:54 +08:00
										 |  |  |     'name' | 'description' | 'permission' | 'partial_member_list' | 'indexing_technique' | 'retrieval_model' | 'embedding_model' | 'embedding_model_provider' | 
					
						
							| 
									
										
										
										
											2024-04-24 15:02:29 +08:00
										 |  |  |   >> | 
					
						
							|  |  |  | }> = ({ datasetId, body }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return patch<DataSet>(`/datasets/${datasetId}`, { body }) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const fetchDatasetRelatedApps: Fetcher<RelatedAppResponse, string> = (datasetId: string) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return get<RelatedAppResponse>(`/datasets/${datasetId}/related-apps`) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 17:44:11 +08:00
										 |  |  | export const fetchDatasets: Fetcher<DataSetListResponse, FetchDatasetsParams> = ({ url, params }) => { | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   const urlParams = qs.stringify(params, { indices: false }) | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return get<DataSetListResponse>(`${url}?${urlParams}`) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const createEmptyDataset: Fetcher<DataSet, { name: string }> = ({ name }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return post<DataSet>('/datasets', { body: { name } }) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-01 16:14:49 +08:00
										 |  |  | export const checkIsUsedInApp: Fetcher<{ is_using: boolean }, string> = (id) => { | 
					
						
							|  |  |  |   return get<{ is_using: boolean }>(`/datasets/${id}/use-check`, {}, { | 
					
						
							|  |  |  |     silent: true, | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | export const deleteDataset: Fetcher<DataSet, string> = (datasetID) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return del<DataSet>(`/datasets/${datasetID}`) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 15:38:43 +08:00
										 |  |  | export const fetchExternalAPIList: Fetcher<ExternalAPIListResponse, { url: string }> = ({ url }) => { | 
					
						
							|  |  |  |   return get<ExternalAPIListResponse>(url) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const fetchExternalAPI: Fetcher<ExternalAPIItem, { apiTemplateId: string }> = ({ apiTemplateId }) => { | 
					
						
							|  |  |  |   return get<ExternalAPIItem>(`/datasets/external-knowledge-api/${apiTemplateId}`) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const updateExternalAPI: Fetcher<ExternalAPIItem, { apiTemplateId: string; body: ExternalAPIItem }> = ({ apiTemplateId, body }) => { | 
					
						
							|  |  |  |   return patch<ExternalAPIItem>(`/datasets/external-knowledge-api/${apiTemplateId}`, { body }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const deleteExternalAPI: Fetcher<ExternalAPIDeleteResponse, { apiTemplateId: string }> = ({ apiTemplateId }) => { | 
					
						
							|  |  |  |   return del<ExternalAPIDeleteResponse>(`/datasets/external-knowledge-api/${apiTemplateId}`) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const checkUsageExternalAPI: Fetcher<ExternalAPIUsage, { apiTemplateId: string }> = ({ apiTemplateId }) => { | 
					
						
							|  |  |  |   return get<ExternalAPIUsage>(`/datasets/external-knowledge-api/${apiTemplateId}/use-check`) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const createExternalAPI: Fetcher<ExternalAPIItem, { body: CreateExternalAPIReq }> = ({ body }) => { | 
					
						
							|  |  |  |   return post<ExternalAPIItem>('/datasets/external-knowledge-api', { body }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const createExternalKnowledgeBase: Fetcher<ExternalKnowledgeItem, { body: CreateKnowledgeBaseReq }> = ({ body }) => { | 
					
						
							|  |  |  |   return post<ExternalKnowledgeItem>('/datasets/external', { body }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | export const fetchDefaultProcessRule: Fetcher<ProcessRuleResponse, { url: string }> = ({ url }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return get<ProcessRuleResponse>(url) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | export const fetchProcessRule: Fetcher<ProcessRuleResponse, { params: { documentId: string } }> = ({ params: { documentId } }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return get<ProcessRuleResponse>('/datasets/process-rule', { params: { document_id: documentId } }) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const createFirstDocument: Fetcher<createDocumentResponse, { body: CreateDocumentReq }> = ({ body }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return post<createDocumentResponse>('/datasets/init', { body }) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | export const createDocument: Fetcher<createDocumentResponse, { datasetId: string; body: CreateDocumentReq }> = ({ datasetId, body }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return post<createDocumentResponse>(`/datasets/${datasetId}/documents`, { body }) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const fetchIndexingEstimate: Fetcher<IndexingEstimateResponse, CommonDocReq> = ({ datasetId, documentId }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return get<IndexingEstimateResponse>(`/datasets/${datasetId}/documents/${documentId}/indexing-estimate`, {}) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | export const fetchIndexingEstimateBatch: Fetcher<IndexingEstimateResponse, BatchReq> = ({ datasetId, batchId }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return get<IndexingEstimateResponse>(`/datasets/${datasetId}/batch/${batchId}/indexing-estimate`, {}) | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const fetchIndexingStatus: Fetcher<IndexingStatusResponse, CommonDocReq> = ({ datasetId, documentId }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return get<IndexingStatusResponse>(`/datasets/${datasetId}/documents/${documentId}/indexing-status`, {}) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | export const fetchIndexingStatusBatch: Fetcher<IndexingStatusBatchResponse, BatchReq> = ({ datasetId, batchId }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return get<IndexingStatusBatchResponse>(`/datasets/${datasetId}/batch/${batchId}/indexing-status`, {}) | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-04 15:10:34 +08:00
										 |  |  | export const renameDocumentName: Fetcher<CommonResponse, CommonDocReq & { name: string }> = ({ datasetId, documentId, name }) => { | 
					
						
							|  |  |  |   return post<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/rename`, { | 
					
						
							|  |  |  |     body: { name }, | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | export const pauseDocIndexing: Fetcher<CommonResponse, CommonDocReq> = ({ datasetId, documentId }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return patch<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/processing/pause`) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const resumeDocIndexing: Fetcher<CommonResponse, CommonDocReq> = ({ datasetId, documentId }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return patch<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/processing/resume`) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | export const preImportNotionPages: Fetcher<{ notion_info: DataSourceNotionWorkspace[] }, { url: string; datasetId?: string }> = ({ url, datasetId }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return get<{ notion_info: DataSourceNotionWorkspace[] }>(url, { params: { dataset_id: datasetId } }) | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | export const modifyDocMetadata: Fetcher<CommonResponse, CommonDocReq & { body: { doc_type: string; doc_metadata: Record<string, any> } }> = ({ datasetId, documentId, body }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return put<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/metadata`, { body }) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // hit testing
 | 
					
						
							| 
									
										
										
										
											2023-11-18 11:53:35 +08:00
										 |  |  | export const hitTesting: Fetcher<HitTestingResponse, { datasetId: string; queryText: string; retrieval_model: RetrievalConfig }> = ({ datasetId, queryText, retrieval_model }) => { | 
					
						
							|  |  |  |   return post<HitTestingResponse>(`/datasets/${datasetId}/hit-testing`, { body: { query: queryText, retrieval_model } }) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-30 15:38:43 +08:00
										 |  |  | export const externalKnowledgeBaseHitTesting: Fetcher<ExternalKnowledgeBaseHitTestingResponse, { datasetId: string; query: string; external_retrieval_model: { top_k: number; score_threshold: number; score_threshold_enabled: boolean } }> = ({ datasetId, query, external_retrieval_model }) => { | 
					
						
							|  |  |  |   return post<ExternalKnowledgeBaseHitTestingResponse>(`/datasets/${datasetId}/external-hit-testing`, { body: { query, external_retrieval_model } }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | export const fetchTestingRecords: Fetcher<HitTestingRecordsResponse, { datasetId: string; params: { page: number; limit: number } }> = ({ datasetId, params }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return get<HitTestingRecordsResponse>(`/datasets/${datasetId}/queries`, { params }) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-07 17:42:16 +08:00
										 |  |  | export const fetchFileIndexingEstimate: Fetcher<FileIndexingEstimateResponse, IndexingEstimateParams> = (body: IndexingEstimateParams) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return post<FileIndexingEstimateResponse>('/datasets/indexing-estimate', { body }) | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const fetchNotionPagePreview: Fetcher<{ content: string }, { workspaceID: string; pageID: string; pageType: string }> = ({ workspaceID, pageID, pageType }) => { | 
					
						
							| 
									
										
										
										
											2023-09-15 20:54:20 +08:00
										 |  |  |   return get<{ content: string }>(`notion/workspaces/${workspaceID}/pages/${pageID}/${pageType}/preview`) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-09-27 16:06:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-08 12:14:11 +07:00
										 |  |  | export const fetchApiKeysList: Fetcher<ApiKeysListResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => { | 
					
						
							|  |  |  |   return get<ApiKeysListResponse>(url, params) | 
					
						
							| 
									
										
										
										
											2023-09-27 16:06:49 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const delApikey: Fetcher<CommonResponse, { url: string; params: Record<string, any> }> = ({ url, params }) => { | 
					
						
							|  |  |  |   return del<CommonResponse>(url, params) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const createApikey: Fetcher<CreateApiKeyResponse, { url: string; body: Record<string, any> }> = ({ url, body }) => { | 
					
						
							|  |  |  |   return post<CreateApiKeyResponse>(url, body) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const fetchDatasetApiBaseUrl: Fetcher<{ api_base_url: string }, string> = (url) => { | 
					
						
							|  |  |  |   return get<{ api_base_url: string }>(url) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-12-18 23:28:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-17 03:06:32 -05:00
										 |  |  | export const fetchDataSources = () => { | 
					
						
							| 
									
										
										
										
											2024-06-14 22:02:41 +08:00
										 |  |  |   return get<CommonResponse>('api-key-auth/data-source') | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-17 03:06:32 -05:00
										 |  |  | export const createDataSourceApiKeyBinding: Fetcher<CommonResponse, Record<string, any>> = (body) => { | 
					
						
							| 
									
										
										
										
											2024-06-14 22:02:41 +08:00
										 |  |  |   return post<CommonResponse>('api-key-auth/data-source/binding', { body }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-17 03:06:32 -05:00
										 |  |  | export const removeDataSourceApiKeyBinding: Fetcher<CommonResponse, string> = (id: string) => { | 
					
						
							| 
									
										
										
										
											2024-06-14 22:02:41 +08:00
										 |  |  |   return del<CommonResponse>(`api-key-auth/data-source/${id}`) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const createFirecrawlTask: Fetcher<CommonResponse, Record<string, any>> = (body) => { | 
					
						
							|  |  |  |   return post<CommonResponse>('website/crawl', { | 
					
						
							|  |  |  |     body: { | 
					
						
							|  |  |  |       ...body, | 
					
						
							| 
									
										
										
										
											2024-09-30 09:57:19 +08:00
										 |  |  |       provider: DataSourceProvider.fireCrawl, | 
					
						
							| 
									
										
										
										
											2024-06-14 22:02:41 +08:00
										 |  |  |     }, | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const checkFirecrawlTaskStatus: Fetcher<CommonResponse, string> = (jobId: string) => { | 
					
						
							|  |  |  |   return get<CommonResponse>(`website/crawl/status/${jobId}`, { | 
					
						
							|  |  |  |     params: { | 
					
						
							| 
									
										
										
										
											2024-09-30 09:57:19 +08:00
										 |  |  |       provider: DataSourceProvider.fireCrawl, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, { | 
					
						
							|  |  |  |     silent: true, | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const createJinaReaderTask: Fetcher<CommonResponse, Record<string, any>> = (body) => { | 
					
						
							|  |  |  |   return post<CommonResponse>('website/crawl', { | 
					
						
							|  |  |  |     body: { | 
					
						
							|  |  |  |       ...body, | 
					
						
							|  |  |  |       provider: DataSourceProvider.jinaReader, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const checkJinaReaderTaskStatus: Fetcher<CommonResponse, string> = (jobId: string) => { | 
					
						
							|  |  |  |   return get<CommonResponse>(`website/crawl/status/${jobId}`, { | 
					
						
							|  |  |  |     params: { | 
					
						
							|  |  |  |       provider: 'jinareader', | 
					
						
							| 
									
										
										
										
											2024-06-14 22:02:41 +08:00
										 |  |  |     }, | 
					
						
							|  |  |  |   }, { | 
					
						
							|  |  |  |     silent: true, | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-07 06:43:23 +02:00
										 |  |  | export const createWatercrawlTask: Fetcher<CommonResponse, Record<string, any>> = (body) => { | 
					
						
							|  |  |  |   return post<CommonResponse>('website/crawl', { | 
					
						
							|  |  |  |     body: { | 
					
						
							|  |  |  |       ...body, | 
					
						
							|  |  |  |       provider: DataSourceProvider.waterCrawl, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const checkWatercrawlTaskStatus: Fetcher<CommonResponse, string> = (jobId: string) => { | 
					
						
							|  |  |  |   return get<CommonResponse>(`website/crawl/status/${jobId}`, { | 
					
						
							|  |  |  |     params: { | 
					
						
							|  |  |  |       provider: DataSourceProvider.waterCrawl, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, { | 
					
						
							|  |  |  |     silent: true, | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-18 23:28:25 +08:00
										 |  |  | type FileTypesRes = { | 
					
						
							|  |  |  |   allowed_extensions: string[] | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const fetchSupportFileTypes: Fetcher<FileTypesRes, { url: string }> = ({ url }) => { | 
					
						
							|  |  |  |   return get<FileTypesRes>(url) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-04-24 15:02:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const getErrorDocs: Fetcher<ErrorDocsResponse, { datasetId: string }> = ({ datasetId }) => { | 
					
						
							|  |  |  |   return get<ErrorDocsResponse>(`/datasets/${datasetId}/error-docs`) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const retryErrorDocs: Fetcher<CommonResponse, { datasetId: string; document_ids: string[] }> = ({ datasetId, document_ids }) => { | 
					
						
							|  |  |  |   return post<CommonResponse>(`/datasets/${datasetId}/retry`, { body: { document_ids } }) | 
					
						
							|  |  |  | } |