diff --git a/web/app/components/datasets/create/step-two/index.tsx b/web/app/components/datasets/create/step-two/index.tsx index cd0237ab6f..22b0860139 100644 --- a/web/app/components/datasets/create/step-two/index.tsx +++ b/web/app/components/datasets/create/step-two/index.tsx @@ -487,8 +487,10 @@ const StepTwo = ({ setMax(Number(e.target.value))} + placeholder={t('datasetCreation.stepTwo.separatorPlaceholder') || ''} + value={max} + min={1} + onChange={e => setMax(parseInt(e.target.value.replace(/^0+/, ''), 10))} /> @@ -497,7 +499,7 @@ const StepTwo = ({
{t('datasetCreation.stepTwo.rules')}
{rules.map(rule => (
- ruleChangeHandle(rule.id)} className="w-4 h-4 rounded border-gray-300 text-blue-700 focus:ring-blue-700" /> + ruleChangeHandle(rule.id)} className="w-4 h-4 rounded border-gray-300 text-blue-700 focus:ring-blue-700" />
))} diff --git a/web/hooks/use-breakpoints.ts b/web/hooks/use-breakpoints.ts index 1aab56a9fd..99c2b75d67 100644 --- a/web/hooks/use-breakpoints.ts +++ b/web/hooks/use-breakpoints.ts @@ -8,20 +8,22 @@ export enum MediaType { } const useBreakpoints = () => { - const [width, setWidth] = React.useState(globalThis.innerWidth); + const [width, setWidth] = React.useState(globalThis.innerWidth) const media = (() => { - if (width <= 640) return MediaType.mobile; - if (width <= 768) return MediaType.tablet; - return MediaType.pc; - })(); + if (width <= 640) + return MediaType.mobile + if (width <= 768) + return MediaType.tablet + return MediaType.pc + })() React.useEffect(() => { - const handleWindowResize = () => setWidth(window.innerWidth); - window.addEventListener("resize", handleWindowResize); - return () => window.removeEventListener("resize", handleWindowResize); - }, []); + const handleWindowResize = () => setWidth(window.innerWidth) + window.addEventListener('resize', handleWindowResize) + return () => window.removeEventListener('resize', handleWindowResize) + }, []) - return media; + return media } -export default useBreakpoints \ No newline at end of file +export default useBreakpoints diff --git a/web/service/apps.ts b/web/service/apps.ts index e881a1e78b..a7d9f9817b 100644 --- a/web/service/apps.ts +++ b/web/service/apps.ts @@ -5,91 +5,91 @@ import type { CommonResponse } from '@/models/common' import type { AppMode, ModelConfig } from '@/types/app' export const fetchAppList: Fetcher }> = ({ url, params }) => { - return get(url, { params }) as Promise + return get(url, { params }) } export const fetchAppDetail: Fetcher = ({ url, id }) => { - return get(`${url}/${id}`) as Promise + return get(`${url}/${id}`) } export const fetchAppTemplates: Fetcher = ({ url }) => { - return get(url) as Promise + return get(url) } export const createApp: Fetcher = ({ name, icon, icon_background, mode, config }) => { - return post('apps', { body: { name, icon, icon_background, mode, model_config: config } }) as Promise + return post('apps', { body: { name, icon, icon_background, mode, model_config: config } }) } export const deleteApp: Fetcher = (appID) => { - return del(`apps/${appID}`) as Promise + return del(`apps/${appID}`) } export const updateAppSiteStatus: Fetcher }> = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const updateAppApiStatus: Fetcher }> = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } // path: /apps/{appId}/rate-limit export const updateAppRateLimit: Fetcher }> = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const updateAppSiteAccessToken: Fetcher = ({ url }) => { - return post(url) as Promise + return post(url) } export const updateAppSiteConfig: Fetcher }> = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const getAppDailyConversations: Fetcher }> = ({ url, params }) => { - return get(url, { params }) as Promise + return get(url, { params }) } export const getAppStatistics: Fetcher }> = ({ url, params }) => { - return get(url, { params }) as Promise + return get(url, { params }) } export const getAppDailyEndUsers: Fetcher }> = ({ url, params }) => { - return get(url, { params }) as Promise + return get(url, { params }) } export const getAppTokenCosts: Fetcher }> = ({ url, params }) => { - return get(url, { params }) as Promise + return get(url, { params }) } export const updateAppModelConfig: Fetcher }> = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } // For temp testing export const fetchAppListNoMock: Fetcher }> = ({ url, params }) => { - return get(url, params) as Promise + return get(url, params) } export const fetchApiKeysList: Fetcher }> = ({ url, params }) => { - return get(url, params) as Promise + return get(url, params) } export const delApikey: Fetcher }> = ({ url, params }) => { - return del(url, params) as Promise + return del(url, params) } export const createApikey: Fetcher }> = ({ url, body }) => { - return post(url, body) as Promise + return post(url, body) } export const validateOpenAIKey: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const updateOpenAIKey: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const generationIntroduction: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } diff --git a/web/service/base.ts b/web/service/base.ts index 9f461dba1c..00ce140d69 100644 --- a/web/service/base.ts +++ b/web/service/base.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-new, prefer-promise-reject-errors */ import { API_PREFIX, IS_CE_EDITION, PUBLIC_API_PREFIX } from '@/config' import Toast from '@/app/components/base/toast' import type { MessageEnd, ThoughtItem } from '@/app/components/app/chat/type' @@ -50,6 +49,17 @@ type IOtherOptions = { getAbortController?: (abortController: AbortController) => void } +type ResponseError = { + code: string + message: string + status: number +} + +type FetchOptionType = Omit & { + params?: Record + body?: BodyInit | Record | null +} + function unicodeToChar(text: string) { if (!text) return '' @@ -146,17 +156,17 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted read() } -const baseFetch = ( +const baseFetch = ( url: string, - fetchOptions: any, + fetchOptions: FetchOptionType, { isPublicAPI = false, bodyStringify = true, needAllResponseContent, deleteContentType, }: IOtherOptions, -) => { - const options = Object.assign({}, baseOptions, fetchOptions) +): Promise => { + const options: typeof baseOptions & FetchOptionType = Object.assign({}, baseOptions, fetchOptions) if (isPublicAPI) { const sharedToken = globalThis.location.pathname.split('/').slice(-1)[0] const accessToken = localStorage.getItem('token') || JSON.stringify({ [sharedToken]: '' }) @@ -209,27 +219,27 @@ const baseFetch = ( }, TIME_OUT) }), new Promise((resolve, reject) => { - globalThis.fetch(urlWithPrefix, options) - .then((res: any) => { + globalThis.fetch(urlWithPrefix, options as RequestInit) + .then((res) => { const resClone = res.clone() // Error handler - if (!/^(2|3)\d{2}$/.test(res.status)) { + if (!/^(2|3)\d{2}$/.test(String(res.status))) { const bodyJson = res.json() switch (res.status) { case 401: { if (isPublicAPI) { Toast.notify({ type: 'error', message: 'Invalid token' }) - return bodyJson.then((data: any) => Promise.reject(data)) + return bodyJson.then((data: T) => Promise.reject(data)) } const loginUrl = `${globalThis.location.origin}/signin` if (IS_CE_EDITION) { - bodyJson.then((data: any) => { + bodyJson.then((data: ResponseError) => { if (data.code === 'not_setup') { globalThis.location.href = `${globalThis.location.origin}/install` } else { if (location.pathname === '/signin') { - bodyJson.then((data: any) => { + bodyJson.then((data: ResponseError) => { Toast.notify({ type: 'error', message: data.message }) }) } @@ -238,26 +248,22 @@ const baseFetch = ( } } }) - return Promise.reject() + return Promise.reject(Error('Unauthorized')) } globalThis.location.href = loginUrl break } case 403: - new Promise(() => { - bodyJson.then((data: any) => { - Toast.notify({ type: 'error', message: data.message }) - if (data.code === 'already_setup') - globalThis.location.href = `${globalThis.location.origin}/signin` - }) + bodyJson.then((data: ResponseError) => { + Toast.notify({ type: 'error', message: data.message }) + if (data.code === 'already_setup') + globalThis.location.href = `${globalThis.location.origin}/signin` }) break // fall through default: - new Promise(() => { - bodyJson.then((data: any) => { - Toast.notify({ type: 'error', message: data.message }) - }) + bodyJson.then((data: ResponseError) => { + Toast.notify({ type: 'error', message: data.message }) }) } return Promise.reject(resClone) @@ -270,7 +276,7 @@ const baseFetch = ( } // return data - const data = options.headers.get('Content-type') === ContentType.download ? res.blob() : res.json() + const data: Promise = options.headers.get('Content-type') === ContentType.download ? res.blob() : res.json() resolve(needAllResponseContent ? resClone : data) }) @@ -279,7 +285,7 @@ const baseFetch = ( reject(err) }) }), - ]) + ]) as Promise } export const upload = (options: any): Promise => { @@ -315,7 +321,7 @@ export const upload = (options: any): Promise => { }) } -export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, onData, onCompleted, onThought, onMessageEnd, onError, getAbortController }: IOtherOptions) => { +export const ssePost = (url: string, fetchOptions: FetchOptionType, { isPublicAPI = false, onData, onCompleted, onThought, onMessageEnd, onError, getAbortController }: IOtherOptions) => { const abortController = new AbortController() const options = Object.assign({}, baseOptions, { @@ -336,14 +342,11 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o if (body) options.body = JSON.stringify(body) - globalThis.fetch(urlWithPrefix, options) - .then((res: any) => { - // debugger - if (!/^(2|3)\d{2}$/.test(res.status)) { - new Promise(() => { - res.json().then((data: any) => { - Toast.notify({ type: 'error', message: data.message || 'Server Error' }) - }) + globalThis.fetch(urlWithPrefix, options as RequestInit) + .then((res) => { + if (!/^(2|3)\d{2}$/.test(String(res.status))) { + res.json().then((data: any) => { + Toast.notify({ type: 'error', message: data.message || 'Server Error' }) }) onError?.('Server Error') return @@ -365,47 +368,49 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o }) } -export const request = (url: string, options = {}, otherOptions?: IOtherOptions) => { - return baseFetch(url, options, otherOptions || {}) +// base request +export const request = (url: string, options = {}, otherOptions?: IOtherOptions) => { + return baseFetch(url, options, otherOptions || {}) } -export const get = (url: string, options = {}, otherOptions?: IOtherOptions) => { - return request(url, Object.assign({}, options, { method: 'GET' }), otherOptions) +// request methods +export const get = (url: string, options = {}, otherOptions?: IOtherOptions) => { + return request(url, Object.assign({}, options, { method: 'GET' }), otherOptions) } // For public API -export const getPublic = (url: string, options = {}, otherOptions?: IOtherOptions) => { - return get(url, options, { ...otherOptions, isPublicAPI: true }) +export const getPublic = (url: string, options = {}, otherOptions?: IOtherOptions) => { + return get(url, options, { ...otherOptions, isPublicAPI: true }) } -export const post = (url: string, options = {}, otherOptions?: IOtherOptions) => { - return request(url, Object.assign({}, options, { method: 'POST' }), otherOptions) +export const post = (url: string, options = {}, otherOptions?: IOtherOptions) => { + return request(url, Object.assign({}, options, { method: 'POST' }), otherOptions) } -export const postPublic = (url: string, options = {}, otherOptions?: IOtherOptions) => { - return post(url, options, { ...otherOptions, isPublicAPI: true }) +export const postPublic = (url: string, options = {}, otherOptions?: IOtherOptions) => { + return post(url, options, { ...otherOptions, isPublicAPI: true }) } -export const put = (url: string, options = {}, otherOptions?: IOtherOptions) => { - return request(url, Object.assign({}, options, { method: 'PUT' }), otherOptions) +export const put = (url: string, options = {}, otherOptions?: IOtherOptions) => { + return request(url, Object.assign({}, options, { method: 'PUT' }), otherOptions) } -export const putPublic = (url: string, options = {}, otherOptions?: IOtherOptions) => { - return put(url, options, { ...otherOptions, isPublicAPI: true }) +export const putPublic = (url: string, options = {}, otherOptions?: IOtherOptions) => { + return put(url, options, { ...otherOptions, isPublicAPI: true }) } -export const del = (url: string, options = {}, otherOptions?: IOtherOptions) => { - return request(url, Object.assign({}, options, { method: 'DELETE' }), otherOptions) +export const del = (url: string, options = {}, otherOptions?: IOtherOptions) => { + return request(url, Object.assign({}, options, { method: 'DELETE' }), otherOptions) } -export const delPublic = (url: string, options = {}, otherOptions?: IOtherOptions) => { - return del(url, options, { ...otherOptions, isPublicAPI: true }) +export const delPublic = (url: string, options = {}, otherOptions?: IOtherOptions) => { + return del(url, options, { ...otherOptions, isPublicAPI: true }) } -export const patch = (url: string, options = {}, otherOptions?: IOtherOptions) => { - return request(url, Object.assign({}, options, { method: 'PATCH' }), otherOptions) +export const patch = (url: string, options = {}, otherOptions?: IOtherOptions) => { + return request(url, Object.assign({}, options, { method: 'PATCH' }), otherOptions) } -export const patchPublic = (url: string, options = {}, otherOptions?: IOtherOptions) => { - return patch(url, options, { ...otherOptions, isPublicAPI: true }) +export const patchPublic = (url: string, options = {}, otherOptions?: IOtherOptions) => { + return patch(url, options, { ...otherOptions, isPublicAPI: true }) } diff --git a/web/service/common.ts b/web/service/common.ts index 18bbc99167..49609657c3 100644 --- a/web/service/common.ts +++ b/web/service/common.ts @@ -16,173 +16,173 @@ import type { import type { BackendModel, ProviderMap } from '@/app/components/header/account-setting/model-page/declarations' export const login: Fetcher }> = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const setup: Fetcher }> = ({ body }) => { - return post('/setup', { body }) as Promise + return post('/setup', { body }) } export const fetchSetupStatus = () => { - return get('/setup') as Promise + return get('/setup') } export const fetchUserProfile: Fetcher }> = ({ url, params }) => { - return get(url, params, { needAllResponseContent: true }) as Promise + return get(url, params, { needAllResponseContent: true }) } export const updateUserProfile: Fetcher }> = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const logout: Fetcher }> = ({ url, params }) => { - return get(url, params) as Promise + return get(url, params) } export const fetchLanggeniusVersion: Fetcher }> = ({ url, params }) => { - return get(url, { params }) as Promise + return get(url, { params }) } export const oauth: Fetcher }> = ({ url, params }) => { - return get(url, { params }) as Promise + return get(url, { params }) } export const oneMoreStep: Fetcher }> = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const fetchMembers: Fetcher<{ accounts: Member[] | null }, { url: string; params: Record }> = ({ url, params }) => { - return get(url, { params }) as Promise<{ accounts: Member[] | null }> + return get<{ accounts: Member[] | null }>(url, { params }) } export const fetchProviders: Fetcher }> = ({ url, params }) => { - return get(url, { params }) as Promise + return get(url, { params }) } export const validateProviderKey: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const updateProviderAIKey: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const fetchAccountIntegrates: Fetcher<{ data: AccountIntegrate[] | null }, { url: string; params: Record }> = ({ url, params }) => { - return get(url, { params }) as Promise<{ data: AccountIntegrate[] | null }> + return get<{ data: AccountIntegrate[] | null }>(url, { params }) } export const inviteMember: Fetcher }> = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const updateMemberRole: Fetcher }> = ({ url, body }) => { - return put(url, { body }) as Promise + return put(url, { body }) } export const deleteMemberOrCancelInvitation: Fetcher = ({ url }) => { - return del(url) as Promise + return del(url) } export const fetchFilePreview: Fetcher<{ content: string }, { fileID: string }> = ({ fileID }) => { - return get(`/files/${fileID}/preview`) as Promise<{ content: string }> + return get<{ content: string }>(`/files/${fileID}/preview`) } export const fetchCurrentWorkspace: Fetcher }> = ({ url, params }) => { - return get(url, { params }) as Promise + return get(url, { params }) } export const fetchWorkspaces: Fetcher<{ workspaces: IWorkspace[] }, { url: string; params: Record }> = ({ url, params }) => { - return get(url, { params }) as Promise<{ workspaces: IWorkspace[] }> + return get<{ workspaces: IWorkspace[] }>(url, { params }) } export const switchWorkspace: Fetcher }> = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const fetchDataSource: Fetcher<{ data: DataSourceNotion[] }, { url: string }> = ({ url }) => { - return get(url) as Promise<{ data: DataSourceNotion[] }> + return get<{ data: DataSourceNotion[] }>(url) } export const syncDataSourceNotion: Fetcher = ({ url }) => { - return get(url) as Promise + return get(url) } export const updateDataSourceNotionAction: Fetcher = ({ url }) => { - return patch(url) as Promise + return patch(url) } export const fetchPluginProviders: Fetcher = (url) => { - return get(url) as Promise + return get(url) } export const validatePluginProviderKey: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const updatePluginProviderAIKey: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const invitationCheck: Fetcher = ({ url, params }) => { - return get(url, { params }) as Promise + return get(url, { params }) } export const activateMember: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const fetchModelProviders: Fetcher = (url) => { - return get(url) as Promise + return get(url) } export const fetchModelList: Fetcher = (url) => { - return get(url) as Promise + return get(url) } export const validateModelProvider: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const setModelProvider: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const deleteModelProvider: Fetcher = ({ url }) => { - return del(url) as Promise + return del(url) } export const changeModelProviderPriority: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const setModelProviderModel: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const deleteModelProviderModel: Fetcher = ({ url }) => { - return del(url) as Promise + return del(url) } export const getPayUrl: Fetcher<{ url: string }, string> = (url) => { - return get(url) as Promise<{ url: string }> + return get<{ url: string }>(url) } export const fetchDefaultModal: Fetcher = (url) => { - return get(url) as Promise + return get(url) } export const updateDefaultModel: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const submitFreeQuota: Fetcher<{ type: string; redirect_url?: string; result?: string }, string> = (url) => { - return post(url) as Promise<{ type: string; redirect_url?: string; result?: string }> + return post<{ type: string; redirect_url?: string; result?: string }>(url) } export const fetchFileUploadConfig: Fetcher = ({ url }) => { - return get(url) as Promise + return get(url) } export const fetchDocumentsLimit: Fetcher = (url) => { - return get(url) as Promise + return get(url) } export const fetchSparkFreeQuotaVerify: Fetcher<{ result: string; flag: boolean; reason: string }, string> = (url) => { diff --git a/web/service/datasets.ts b/web/service/datasets.ts index d2178db0d5..5fd45c1daa 100644 --- a/web/service/datasets.ts +++ b/web/service/datasets.ts @@ -40,155 +40,155 @@ export type SortType = 'created_at' | 'hit_count' | '-created_at' | '-hit_count' export type MetadataType = 'all' | 'only' | 'without' export const fetchDataDetail: Fetcher = (datasetId: string) => { - return get(`/datasets/${datasetId}`) as Promise + return get(`/datasets/${datasetId}`) } export const updateDatasetSetting: Fetcher> }> = ({ datasetId, body }) => { - return patch(`/datasets/${datasetId}`, { body }) as Promise + return patch(`/datasets/${datasetId}`, { body }) } export const fetchDatasetRelatedApps: Fetcher = (datasetId: string) => { - return get(`/datasets/${datasetId}/related-apps`) as Promise + return get(`/datasets/${datasetId}/related-apps`) } export const fetchDatasets: Fetcher = ({ url, params }) => { const urlParams = qs.stringify(params, { indices: false }) - return get(`${url}?${urlParams}`) as Promise + return get(`${url}?${urlParams}`) } export const createEmptyDataset: Fetcher = ({ name }) => { - return post('/datasets', { body: { name } }) as Promise + return post('/datasets', { body: { name } }) } export const deleteDataset: Fetcher = (datasetID) => { - return del(`/datasets/${datasetID}`) as Promise + return del(`/datasets/${datasetID}`) } export const fetchDefaultProcessRule: Fetcher = ({ url }) => { - return get(url) as Promise + return get(url) } export const fetchProcessRule: Fetcher = ({ params: { documentId } }) => { - return get('/datasets/process-rule', { params: { document_id: documentId } }) as Promise + return get('/datasets/process-rule', { params: { document_id: documentId } }) } export const fetchDocuments: Fetcher = ({ datasetId, params }) => { - return get(`/datasets/${datasetId}/documents`, { params }) as Promise + return get(`/datasets/${datasetId}/documents`, { params }) } export const createFirstDocument: Fetcher = ({ body }) => { - return post('/datasets/init', { body }) as Promise + return post('/datasets/init', { body }) } export const createDocument: Fetcher = ({ datasetId, body }) => { - return post(`/datasets/${datasetId}/documents`, { body }) as Promise + return post(`/datasets/${datasetId}/documents`, { body }) } export const fetchIndexingEstimate: Fetcher = ({ datasetId, documentId }) => { - return get(`/datasets/${datasetId}/documents/${documentId}/indexing-estimate`, {}) as Promise + return get(`/datasets/${datasetId}/documents/${documentId}/indexing-estimate`, {}) } export const fetchIndexingEstimateBatch: Fetcher = ({ datasetId, batchId }) => { - return get(`/datasets/${datasetId}/batch/${batchId}/indexing-estimate`, {}) as Promise + return get(`/datasets/${datasetId}/batch/${batchId}/indexing-estimate`, {}) } export const fetchIndexingStatus: Fetcher = ({ datasetId, documentId }) => { - return get(`/datasets/${datasetId}/documents/${documentId}/indexing-status`, {}) as Promise + return get(`/datasets/${datasetId}/documents/${documentId}/indexing-status`, {}) } export const fetchIndexingStatusBatch: Fetcher = ({ datasetId, batchId }) => { - return get(`/datasets/${datasetId}/batch/${batchId}/indexing-status`, {}) as Promise + return get(`/datasets/${datasetId}/batch/${batchId}/indexing-status`, {}) } export const fetchDocumentDetail: Fetcher = ({ datasetId, documentId, params }) => { - return get(`/datasets/${datasetId}/documents/${documentId}`, { params }) as Promise + return get(`/datasets/${datasetId}/documents/${documentId}`, { params }) } export const pauseDocIndexing: Fetcher = ({ datasetId, documentId }) => { - return patch(`/datasets/${datasetId}/documents/${documentId}/processing/pause`) as Promise + return patch(`/datasets/${datasetId}/documents/${documentId}/processing/pause`) } export const resumeDocIndexing: Fetcher = ({ datasetId, documentId }) => { - return patch(`/datasets/${datasetId}/documents/${documentId}/processing/resume`) as Promise + return patch(`/datasets/${datasetId}/documents/${documentId}/processing/resume`) } export const deleteDocument: Fetcher = ({ datasetId, documentId }) => { - return del(`/datasets/${datasetId}/documents/${documentId}`) as Promise + return del(`/datasets/${datasetId}/documents/${documentId}`) } export const archiveDocument: Fetcher = ({ datasetId, documentId }) => { - return patch(`/datasets/${datasetId}/documents/${documentId}/status/archive`) as Promise + return patch(`/datasets/${datasetId}/documents/${documentId}/status/archive`) } export const unArchiveDocument: Fetcher = ({ datasetId, documentId }) => { - return patch(`/datasets/${datasetId}/documents/${documentId}/status/un_archive`) as Promise + return patch(`/datasets/${datasetId}/documents/${documentId}/status/un_archive`) } export const enableDocument: Fetcher = ({ datasetId, documentId }) => { - return patch(`/datasets/${datasetId}/documents/${documentId}/status/enable`) as Promise + return patch(`/datasets/${datasetId}/documents/${documentId}/status/enable`) } export const disableDocument: Fetcher = ({ datasetId, documentId }) => { - return patch(`/datasets/${datasetId}/documents/${documentId}/status/disable`) as Promise + return patch(`/datasets/${datasetId}/documents/${documentId}/status/disable`) } export const syncDocument: Fetcher = ({ datasetId, documentId }) => { - return get(`/datasets/${datasetId}/documents/${documentId}/notion/sync`) as Promise + return get(`/datasets/${datasetId}/documents/${documentId}/notion/sync`) } export const preImportNotionPages: Fetcher<{ notion_info: DataSourceNotionWorkspace[] }, { url: string; datasetId?: string }> = ({ url, datasetId }) => { - return get(url, { params: { dataset_id: datasetId } }) as Promise<{ notion_info: DataSourceNotionWorkspace[] }> + return get<{ notion_info: DataSourceNotionWorkspace[] }>(url, { params: { dataset_id: datasetId } }) } export const modifyDocMetadata: Fetcher } }> = ({ datasetId, documentId, body }) => { - return put(`/datasets/${datasetId}/documents/${documentId}/metadata`, { body }) as Promise + return put(`/datasets/${datasetId}/documents/${documentId}/metadata`, { body }) } // apis for segments in a document export const fetchSegments: Fetcher = ({ datasetId, documentId, params }) => { - return get(`/datasets/${datasetId}/documents/${documentId}/segments`, { params }) as Promise + return get(`/datasets/${datasetId}/documents/${documentId}/segments`, { params }) } export const enableSegment: Fetcher = ({ datasetId, segmentId }) => { - return patch(`/datasets/${datasetId}/segments/${segmentId}/enable`) as Promise + return patch(`/datasets/${datasetId}/segments/${segmentId}/enable`) } export const disableSegment: Fetcher = ({ datasetId, segmentId }) => { - return patch(`/datasets/${datasetId}/segments/${segmentId}/disable`) as Promise + return patch(`/datasets/${datasetId}/segments/${segmentId}/disable`) } export const updateSegment: Fetcher<{ data: SegmentDetailModel; doc_form: string }, { datasetId: string; documentId: string; segmentId: string; body: SegmentUpdator }> = ({ datasetId, documentId, segmentId, body }) => { - return patch(`/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}`, { body }) as Promise<{ data: SegmentDetailModel; doc_form: string }> + return patch<{ data: SegmentDetailModel; doc_form: string }>(`/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}`, { body }) } export const addSegment: Fetcher<{ data: SegmentDetailModel; doc_form: string }, { datasetId: string; documentId: string; body: SegmentUpdator }> = ({ datasetId, documentId, body }) => { - return post(`/datasets/${datasetId}/documents/${documentId}/segment`, { body }) as Promise<{ data: SegmentDetailModel; doc_form: string }> + return post<{ data: SegmentDetailModel; doc_form: string }>(`/datasets/${datasetId}/documents/${documentId}/segment`, { body }) } export const deleteSegment: Fetcher = ({ datasetId, documentId, segmentId }) => { - return del(`/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}`) as Promise + return del(`/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}`) } export const segmentBatchImport: Fetcher<{ job_id: string; job_status: string }, { url: string; body: FormData }> = ({ url, body }) => { - return post(url, { body }, { bodyStringify: false, deleteContentType: true }) as Promise<{ job_id: string; job_status: string }> + return post<{ job_id: string; job_status: string }>(url, { body }, { bodyStringify: false, deleteContentType: true }) } export const checkSegmentBatchImportProgress: Fetcher<{ job_id: string; job_status: string }, { jobID: string }> = ({ jobID }) => { - return get(`/datasets/batch_import_status/${jobID}`) as Promise<{ job_id: string; job_status: string }> + return get<{ job_id: string; job_status: string }>(`/datasets/batch_import_status/${jobID}`) } // hit testing export const hitTesting: Fetcher = ({ datasetId, queryText }) => { - return post(`/datasets/${datasetId}/hit-testing`, { body: { query: queryText } }) as Promise + return post(`/datasets/${datasetId}/hit-testing`, { body: { query: queryText } }) } export const fetchTestingRecords: Fetcher = ({ datasetId, params }) => { - return get(`/datasets/${datasetId}/queries`, { params }) as Promise + return get(`/datasets/${datasetId}/queries`, { params }) } export const fetchFileIndexingEstimate: Fetcher = (body: any) => { - return post('/datasets/indexing-estimate', { body }) as Promise + return post('/datasets/indexing-estimate', { body }) } export const fetchNotionPagePreview: Fetcher<{ content: string }, { workspaceID: string; pageID: string; pageType: string }> = ({ workspaceID, pageID, pageType }) => { - return get(`notion/workspaces/${workspaceID}/pages/${pageID}/${pageType}/preview`) as Promise<{ content: string }> + return get<{ content: string }>(`notion/workspaces/${workspaceID}/pages/${pageID}/${pageType}/preview`) } diff --git a/web/service/log.ts b/web/service/log.ts index 76ebd3adcd..0280874c67 100644 --- a/web/service/log.ts +++ b/web/service/log.ts @@ -18,42 +18,42 @@ import type { } from '@/models/log' export const fetchConversationList: Fetcher }> = ({ appId, params }) => { - return get(`/console/api/apps/${appId}/messages`, params) as Promise + return get(`/console/api/apps/${appId}/messages`, params) } // (Text Generation Application) Session List export const fetchCompletionConversations: Fetcher = ({ url, params }) => { - return get(url, { params }) as Promise + return get(url, { params }) } // (Text Generation Application) Session Detail export const fetchCompletionConversationDetail: Fetcher = ({ url }) => { - return get(url, {}) as Promise + return get(url, {}) } // (Chat Application) Session List export const fetchChatConversations: Fetcher = ({ url, params }) => { - return get(url, { params }) as Promise + return get(url, { params }) } // (Chat Application) Session Detail export const fetchChatConversationDetail: Fetcher = ({ url }) => { - return get(url, {}) as Promise + return get(url, {}) } // (Chat Application) Message list in one session export const fetchChatMessages: Fetcher = ({ url, params }) => { - return get(url, { params }) as Promise + return get(url, { params }) } export const updateLogMessageFeedbacks: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const updateLogMessageAnnotations: Fetcher = ({ url, body }) => { - return post(url, { body }) as Promise + return post(url, { body }) } export const fetchAnnotationsCount: Fetcher = ({ url }) => { - return get(url) as Promise + return get(url) }