mirror of
https://github.com/langgenius/dify.git
synced 2026-01-06 14:35:59 +00:00
Compare commits
5 Commits
feat/llm-n
...
refactor/w
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0ad6e04d9 | ||
|
|
8d9fbbe595 | ||
|
|
3da975c745 | ||
|
|
bde4b82695 | ||
|
|
6d7026255e |
@@ -1,7 +1,8 @@
|
||||
'use client'
|
||||
import type { FC } from 'react'
|
||||
import type { ResourceVarInputs } from '../types'
|
||||
import type { CredentialFormSchema, FormOption } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||
import type { FormOption } from '@/app/components/base/form/types'
|
||||
import type { CredentialFormSchema } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||
import type { Event, Tool } from '@/app/components/tools/types'
|
||||
import type { TriggerWithProvider } from '@/app/components/workflow/block-selector/types'
|
||||
import type { ToolWithProvider, ValueSelector, Var } from '@/app/components/workflow/types'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
import type { FC } from 'react'
|
||||
import type { CredentialFormSchema, CredentialFormSchemaSelect, FormOption } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||
import type { FormOption } from '@/app/components/base/form/types'
|
||||
import type { CredentialFormSchema, CredentialFormSchemaSelect } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||
import type { Tool } from '@/app/components/tools/types'
|
||||
import type { TriggerWithProvider } from '@/app/components/workflow/block-selector/types'
|
||||
import type { CommonNodeType, Node, NodeOutPutVar, ToolWithProvider, ValueSelector, Var } from '@/app/components/workflow/types'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { TracingProvider } from '@/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/tracing/type'
|
||||
import type { ApiKeysListResponse, AppDailyConversationsResponse, AppDailyEndUsersResponse, AppDailyMessagesResponse, AppDetailResponse, AppListResponse, AppStatisticsResponse, AppTemplatesResponse, AppTokenCostsResponse, AppVoicesListResponse, CreateApiKeyResponse, DSLImportMode, DSLImportResponse, GenerationIntroductionResponse, TracingConfig, TracingStatus, UpdateAppModelConfigResponse, UpdateAppSiteCodeResponse, UpdateOpenAIKeyResponse, ValidateOpenAIKeyResponse, WebhookTriggerResponse, WorkflowDailyConversationsResponse } from '@/models/app'
|
||||
import type { CommonResponse } from '@/models/common'
|
||||
import type { AppIconType, AppModeEnum, ModelConfig } from '@/types/app'
|
||||
import type { App, AppIconType, AppModeEnum, ModelConfig } from '@/types/app'
|
||||
import { del, get, patch, post, put } from './base'
|
||||
|
||||
export const fetchAppList = ({ url, params }: { url: string, params?: Record<string, any> }): Promise<AppListResponse> => {
|
||||
@@ -12,6 +12,22 @@ export const fetchAppDetail = ({ url, id }: { url: string, id: string }): Promis
|
||||
return get<AppDetailResponse>(`${url}/${id}`)
|
||||
}
|
||||
|
||||
export const fetchAppDetailById = (appID: string): Promise<App> => {
|
||||
return get<App>(`/apps/${appID}`)
|
||||
}
|
||||
|
||||
export const generateRuleTemplate = (type: string): Promise<{ data: string }> => {
|
||||
return post<{ data: string }>('instruction-generate/template', { body: { type } })
|
||||
}
|
||||
|
||||
export const fetchAppStatistics = <T>(appId: string, metric: string, params?: Record<string, any>): Promise<T> => {
|
||||
return get<T>(`/apps/${appId}/statistics/${metric}`, { params })
|
||||
}
|
||||
|
||||
export const fetchWorkflowStatistics = <T>(appId: string, metric: string, params?: Record<string, any>): Promise<T> => {
|
||||
return get<T>(`/apps/${appId}/workflow/statistics/${metric}`, { params })
|
||||
}
|
||||
|
||||
export const fetchAppDetailDirect = async ({ url, id }: { url: string, id: string }): Promise<AppDetailResponse> => {
|
||||
return get<AppDetailResponse>(`${url}/${id}`)
|
||||
}
|
||||
@@ -191,6 +207,10 @@ export const fetchAppVoices = ({ appId, language }: { appId: string, language?:
|
||||
return get<AppVoicesListResponse>(`apps/${appId}/text-to-audio/voices?language=${language}`)
|
||||
}
|
||||
|
||||
export const fetchAppApiKeys = (appId: string): Promise<ApiKeysListResponse> => {
|
||||
return get<ApiKeysListResponse>(`/apps/${appId}/api-keys`)
|
||||
}
|
||||
|
||||
// Tracing
|
||||
export const fetchTracingStatus = ({ appId }: { appId: string }): Promise<TracingStatus> => {
|
||||
return get<TracingStatus>(`/apps/${appId}/trace`)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { FileTypesRes } from './datasets'
|
||||
import type {
|
||||
DefaultModelResponse,
|
||||
Model,
|
||||
@@ -31,6 +32,8 @@ import type {
|
||||
ProviderAnthropicToken,
|
||||
ProviderAzureToken,
|
||||
SetupStatusResponse,
|
||||
StructuredOutputRulesRequestBody,
|
||||
StructuredOutputRulesResponse,
|
||||
UserProfileOriginResponse,
|
||||
} from '@/models/common'
|
||||
import type { RETRIEVE_METHOD } from '@/types/app'
|
||||
@@ -256,18 +259,6 @@ export const updateDefaultModel = ({ url, body }: { url: string, body: any }): P
|
||||
return post<CommonResponse>(url, { body })
|
||||
}
|
||||
|
||||
export const fetchModelParameterRules = (url: string): Promise<{ data: ModelParameterRule[] }> => {
|
||||
return get<{ data: ModelParameterRule[] }>(url)
|
||||
}
|
||||
|
||||
export const fetchFileUploadConfig = ({ url }: { url: string }): Promise<FileUploadConfigResponse> => {
|
||||
return get<FileUploadConfigResponse>(url)
|
||||
}
|
||||
|
||||
export const fetchNotionConnection = (url: string): Promise<{ data: string }> => {
|
||||
return get<{ data: string }>(url)
|
||||
}
|
||||
|
||||
export const fetchDataSourceNotionBinding = (url: string): Promise<{ result: string }> => {
|
||||
return get<{ result: string }>(url)
|
||||
}
|
||||
@@ -300,13 +291,6 @@ export const moderate = (url: string, body: { app_id: string, text: string }): P
|
||||
return post<ModerateResponse>(url, { body })
|
||||
}
|
||||
|
||||
type RetrievalMethodsRes = {
|
||||
retrieval_method: RETRIEVE_METHOD[]
|
||||
}
|
||||
export const fetchSupportRetrievalMethods = (url: string): Promise<RetrievalMethodsRes> => {
|
||||
return get<RetrievalMethodsRes>(url)
|
||||
}
|
||||
|
||||
export const getSystemFeatures = (): Promise<SystemFeatures> => {
|
||||
return get<SystemFeatures>('/system-features')
|
||||
}
|
||||
@@ -388,3 +372,111 @@ export const resetEmail = (body: { new_email: string, token: string }): Promise<
|
||||
|
||||
export const checkEmailExisted = (body: { email: string }): Promise<CommonResponse> =>
|
||||
post<CommonResponse>('/account/change-email/check-email-unique', { body }, { silent: true })
|
||||
|
||||
export const fetchFileUploadConfig = (): Promise<FileUploadConfigResponse> => {
|
||||
return get<FileUploadConfigResponse>('/files/upload')
|
||||
}
|
||||
|
||||
export const fetchUserProfileResponse = (): Promise<Response> => {
|
||||
return get<Response>('/account/profile', {}, { needAllResponseContent: true })
|
||||
}
|
||||
|
||||
export const fetchAccountProfile = (): Promise<void> => {
|
||||
return get('/account/profile', {}, { silent: true }) as Promise<void>
|
||||
}
|
||||
|
||||
export const fetchLangGeniusVersionInfo = (currentVersion?: string | null): Promise<LangGeniusVersionResponse> => {
|
||||
return get<LangGeniusVersionResponse>('/version', { params: { current_version: currentVersion } })
|
||||
}
|
||||
|
||||
export const fetchWorkspacesList = (): Promise<{ workspaces: IWorkspace[] }> => {
|
||||
return get<{ workspaces: IWorkspace[] }>('/workspaces')
|
||||
}
|
||||
|
||||
export const fetchCurrentWorkspaceInfo = (): Promise<ICurrentWorkspace> => {
|
||||
return post<ICurrentWorkspace>('/workspaces/current', { body: {} })
|
||||
}
|
||||
|
||||
export const generateStructuredOutputRules = (body: StructuredOutputRulesRequestBody): Promise<StructuredOutputRulesResponse> => {
|
||||
return post<StructuredOutputRulesResponse>('/rule-structured-output-generate', { body })
|
||||
}
|
||||
|
||||
export const sendRegisterEmail = (body: { email: string, language: string }): Promise<{ data: string, result: string }> => {
|
||||
return post<{ data: string, result: string }>('/email-register/send-email', { body })
|
||||
}
|
||||
|
||||
export const validateRegisterEmail = (body: { email: string, code: string, token: string }): Promise<{ is_valid: boolean, token: string }> => {
|
||||
return post<{ is_valid: boolean, token: string }>('/email-register/validity', { body })
|
||||
}
|
||||
|
||||
export const registerEmail = (body: { token: string, new_password: string, password_confirm: string }): Promise<{ result: string, data: {} }> => {
|
||||
return post<{ result: string, data: {} }>('/email-register', { body })
|
||||
}
|
||||
|
||||
export const fetchFileSupportTypes = (): Promise<FileTypesRes> => {
|
||||
return get<FileTypesRes>('/files/support-type')
|
||||
}
|
||||
|
||||
export const fetchWorkspaceMembers = (): Promise<{ accounts: Member[] | null }> => {
|
||||
return get<{ accounts: Member[] | null }>('/workspaces/current/members', { params: {} })
|
||||
}
|
||||
|
||||
export const fetchSchemaDefinitions = (): Promise<{ name: string, schema: { properties: Record<string, any> } }[]> => {
|
||||
return get<{ name: string, schema: { properties: Record<string, any> } }[]>('/spec/schema-definitions')
|
||||
}
|
||||
|
||||
export const logoutAccount = (): Promise<CommonResponse> => {
|
||||
return post<CommonResponse>('/logout')
|
||||
}
|
||||
|
||||
export const initAccount = (body: { invitation_code: string, interface_language: string, timezone: string }): Promise<CommonResponse> => {
|
||||
return post<CommonResponse>('/account/init', { body })
|
||||
}
|
||||
|
||||
export const fetchModelListByType = (type: ModelTypeEnum): Promise<{ data: Model[] }> => {
|
||||
return get<{ data: Model[] }>(`/workspaces/current/models/model-types/${type}`)
|
||||
}
|
||||
|
||||
export const fetchDefaultModelByType = (type: ModelTypeEnum): Promise<DefaultModelResponse> => {
|
||||
return get<DefaultModelResponse>(`/workspaces/current/default-model?model_type=${type}`)
|
||||
}
|
||||
|
||||
export const fetchSupportRetrievalMethods = (): Promise<{ retrieval_method: RETRIEVE_METHOD[] }> => {
|
||||
return get<{ retrieval_method: RETRIEVE_METHOD[] }>('/datasets/retrieval-setting')
|
||||
}
|
||||
|
||||
export const fetchAccountIntegratesList = (): Promise<{ data: AccountIntegrate[] | null }> => {
|
||||
return get<{ data: AccountIntegrate[] | null }>('/account/integrates')
|
||||
}
|
||||
|
||||
export const fetchDataSourceIntegrates = (): Promise<{ data: DataSourceNotion[] }> => {
|
||||
return get<{ data: DataSourceNotion[] }>('/data-source/integrates')
|
||||
}
|
||||
|
||||
export const fetchPluginProvidersList = (): Promise<PluginProvider[] | null> => {
|
||||
return get<PluginProvider[] | null>('/workspaces/current/tool-providers')
|
||||
}
|
||||
|
||||
export const fetchCodeBasedExtension = (module: string): Promise<CodeBasedExtension> => {
|
||||
return get<CodeBasedExtension>(`/code-based-extension?module=${module}`)
|
||||
}
|
||||
|
||||
export const fetchNotionConnection = (): Promise<{ data: string }> => {
|
||||
return get<{ data: string }>('/oauth/data-source/notion')
|
||||
}
|
||||
|
||||
export const fetchApiBasedExtensions = (): Promise<ApiBasedExtension[]> => {
|
||||
return get<ApiBasedExtension[]>('/api-based-extension')
|
||||
}
|
||||
|
||||
export const fetchInvitationCheck = (params?: { workspace_id?: string, email?: string, token?: string }) => {
|
||||
return get<CommonResponse & { is_valid: boolean, data: { workspace_name: string, email: string, workspace_id: string } }>('/activate/check', { params })
|
||||
}
|
||||
|
||||
export const fetchNotionBinding = (code?: string | null): Promise<{ result: string }> => {
|
||||
return get<{ result: string }>('/oauth/data-source/binding/notion', { params: { code } })
|
||||
}
|
||||
|
||||
export const fetchModelParameterRules = (provider?: string, model?: string): Promise<{ data: ModelParameterRule[] }> => {
|
||||
return get<{ data: ModelParameterRule[] }>(`/workspaces/current/model-providers/${provider}/models/parameter-rules`, { params: { model } })
|
||||
}
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
import type { CreateExternalAPIReq } from '@/app/components/datasets/external-api/declarations'
|
||||
import type { CreateKnowledgeBaseReq } from '@/app/components/datasets/external-knowledge-base/create/declarations'
|
||||
import type { BuiltInMetadataItem, MetadataBatchEditToServer, MetadataItemWithValueLength } from '@/app/components/datasets/metadata/types'
|
||||
import type {
|
||||
ApiKeysListResponse,
|
||||
CreateApiKeyResponse,
|
||||
} from '@/models/app'
|
||||
import type { CommonResponse, DataSourceNotionWorkspace } from '@/models/common'
|
||||
import type {
|
||||
BatchImportResponse,
|
||||
ChildChunkDetail,
|
||||
ChildSegmentsResponse,
|
||||
ChunkingMode,
|
||||
CreateDocumentReq,
|
||||
createDocumentResponse,
|
||||
DataSet,
|
||||
DataSetListResponse,
|
||||
DocumentActionType,
|
||||
DocumentDetailResponse,
|
||||
DocumentListResponse,
|
||||
ErrorDocsResponse,
|
||||
ExternalAPIDeleteResponse,
|
||||
ExternalAPIItem,
|
||||
@@ -20,6 +28,7 @@ import type {
|
||||
FetchDatasetsParams,
|
||||
FileIndexingEstimateResponse,
|
||||
HitTestingRecordsResponse,
|
||||
HitTestingRequest,
|
||||
HitTestingResponse,
|
||||
IndexingEstimateParams,
|
||||
IndexingEstimateResponse,
|
||||
@@ -27,8 +36,10 @@ import type {
|
||||
IndexingStatusResponse,
|
||||
ProcessRuleResponse,
|
||||
RelatedAppResponse,
|
||||
SegmentDetailModel,
|
||||
SegmentsResponse,
|
||||
SegmentUpdater,
|
||||
} from '@/models/datasets'
|
||||
import type { RetrievalConfig } from '@/types/app'
|
||||
import qs from 'qs'
|
||||
import { DataSourceProvider } from '@/models/common'
|
||||
import { del, get, patch, post, put } from './base'
|
||||
@@ -162,13 +173,22 @@ export const preImportNotionPages = ({ url, datasetId }: { url: string, datasetI
|
||||
return get<{ notion_info: DataSourceNotionWorkspace[] }>(url, { params: { dataset_id: datasetId } })
|
||||
}
|
||||
|
||||
export const fetchPreImportNotionPages = ({ datasetId, credentialId }: { datasetId: string, credentialId?: string }): Promise<{ notion_info: DataSourceNotionWorkspace[] }> => {
|
||||
return get<{ notion_info: DataSourceNotionWorkspace[] }>('/notion/pre-import/pages', {
|
||||
params: {
|
||||
dataset_id: datasetId,
|
||||
credential_id: credentialId,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const modifyDocMetadata = ({ datasetId, documentId, body }: CommonDocReq & { body: { doc_type: string, doc_metadata: Record<string, any> } }): Promise<CommonResponse> => {
|
||||
return put<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/metadata`, { body })
|
||||
}
|
||||
|
||||
// hit testing
|
||||
export const hitTesting = ({ datasetId, queryText, retrieval_model }: { datasetId: string, queryText: string, retrieval_model: RetrievalConfig }): Promise<HitTestingResponse> => {
|
||||
return post<HitTestingResponse>(`/datasets/${datasetId}/hit-testing`, { body: { query: queryText, retrieval_model } })
|
||||
export const hitTesting = ({ datasetId, query, retrieval_model, attachment_ids }: { datasetId: string } & HitTestingRequest): Promise<HitTestingResponse> => {
|
||||
return post<HitTestingResponse>(`/datasets/${datasetId}/hit-testing`, { body: { query, retrieval_model, attachment_ids } })
|
||||
}
|
||||
|
||||
export const externalKnowledgeBaseHitTesting = ({ datasetId, query, external_retrieval_model }: { datasetId: string, query: string, external_retrieval_model: { top_k: number, score_threshold: number, score_threshold_enabled: boolean } }): Promise<ExternalKnowledgeBaseHitTestingResponse> => {
|
||||
@@ -287,3 +307,165 @@ export const getErrorDocs = ({ datasetId }: { datasetId: string }): Promise<Erro
|
||||
export const retryErrorDocs = ({ datasetId, document_ids }: { datasetId: string, document_ids: string[] }): Promise<CommonResponse> => {
|
||||
return post<CommonResponse>(`/datasets/${datasetId}/retry`, { body: { document_ids } })
|
||||
}
|
||||
|
||||
export const fetchDatasetApiBaseInfo = (): Promise<{ api_base_url: string }> => {
|
||||
return get<{ api_base_url: string }>('/datasets/api-base-info')
|
||||
}
|
||||
|
||||
export const enableDatasetServiceApi = (datasetId: string): Promise<CommonResponse> => {
|
||||
return post<CommonResponse>(`/datasets/${datasetId}/api-keys/enable`)
|
||||
}
|
||||
|
||||
export const disableDatasetServiceApi = (datasetId: string): Promise<CommonResponse> => {
|
||||
return post<CommonResponse>(`/datasets/${datasetId}/api-keys/disable`)
|
||||
}
|
||||
|
||||
export const fetchDatasetApiKeys = (): Promise<ApiKeysListResponse> => {
|
||||
return get<ApiKeysListResponse>('/datasets/api-keys')
|
||||
}
|
||||
|
||||
export const fetchExternalKnowledgeApiList = (): Promise<ExternalAPIListResponse> => {
|
||||
return get<ExternalAPIListResponse>('/datasets/external-knowledge-api')
|
||||
}
|
||||
|
||||
export const fetchDatasetTestingRecords = (datasetId: string, params?: { page: number, limit: number }): Promise<HitTestingRecordsResponse> => {
|
||||
return get<HitTestingRecordsResponse>(`/datasets/${datasetId}/queries`, { params })
|
||||
}
|
||||
|
||||
export const fetchDatasetErrorDocs = (datasetId: string): Promise<ErrorDocsResponse> => {
|
||||
return get<ErrorDocsResponse>(`/datasets/${datasetId}/error-docs`)
|
||||
}
|
||||
|
||||
export const fetchDocumentList = (datasetId: string, params: { keyword: string, page: number, limit: number, sort?: string, status?: string }): Promise<DocumentListResponse> => {
|
||||
return get<DocumentListResponse>(`/datasets/${datasetId}/documents`, { params })
|
||||
}
|
||||
|
||||
export const fetchAutoDisabledDocuments = (datasetId: string): Promise<{ document_ids: string[] }> => {
|
||||
return get<{ document_ids: string[] }>(`/datasets/${datasetId}/auto-disable-logs`)
|
||||
}
|
||||
|
||||
const buildDocumentIdsQuery = (documentIds: string[] | string) => {
|
||||
const ids = Array.isArray(documentIds) ? documentIds : [documentIds]
|
||||
return ids.map(id => `document_id=${id}`).join('&')
|
||||
}
|
||||
|
||||
export const updateDocumentStatusBatch = (datasetId: string, action: DocumentActionType, documentIds: string[] | string): Promise<CommonResponse> => {
|
||||
return patch<CommonResponse>(`/datasets/${datasetId}/documents/status/${action}/batch?${buildDocumentIdsQuery(documentIds)}`)
|
||||
}
|
||||
|
||||
export const deleteDocumentBatch = (datasetId: string, documentIds: string[] | string): Promise<CommonResponse> => {
|
||||
return del<CommonResponse>(`/datasets/${datasetId}/documents?${buildDocumentIdsQuery(documentIds)}`)
|
||||
}
|
||||
|
||||
export const syncNotionDocument = (datasetId: string, documentId: string): Promise<CommonResponse> => {
|
||||
return get<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/notion/sync`)
|
||||
}
|
||||
|
||||
export const syncWebsiteDocument = (datasetId: string, documentId: string): Promise<CommonResponse> => {
|
||||
return get<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/website-sync`)
|
||||
}
|
||||
|
||||
export const fetchDocumentDetail = (datasetId: string, documentId: string, params?: { metadata?: string }): Promise<DocumentDetailResponse> => {
|
||||
return get<DocumentDetailResponse>(`/datasets/${datasetId}/documents/${documentId}`, { params })
|
||||
}
|
||||
|
||||
export const retryDocumentBatch = (datasetId: string, documentIds: string[]): Promise<CommonResponse> => {
|
||||
return post<CommonResponse>(`/datasets/${datasetId}/retry`, {
|
||||
body: {
|
||||
document_ids: documentIds,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchDatasetMetadata = (datasetId: string): Promise<{ doc_metadata: MetadataItemWithValueLength[], built_in_field_enabled: boolean }> => {
|
||||
return get<{ doc_metadata: MetadataItemWithValueLength[], built_in_field_enabled: boolean }>(`/datasets/${datasetId}/metadata`)
|
||||
}
|
||||
|
||||
export const createDatasetMetadata = (datasetId: string, payload: BuiltInMetadataItem): Promise<void> => {
|
||||
return post(`/datasets/${datasetId}/metadata`, {
|
||||
body: payload,
|
||||
}) as Promise<void>
|
||||
}
|
||||
|
||||
export const updateDatasetMetadataName = (datasetId: string, metaDataId: string, name: string): Promise<void> => {
|
||||
return patch(`/datasets/${datasetId}/metadata/${metaDataId}`, {
|
||||
body: {
|
||||
name,
|
||||
},
|
||||
}) as Promise<void>
|
||||
}
|
||||
|
||||
export const deleteDatasetMetadata = (datasetId: string, metaDataId: string): Promise<void> => {
|
||||
return del(`/datasets/${datasetId}/metadata/${metaDataId}`) as Promise<void>
|
||||
}
|
||||
|
||||
export const fetchBuiltInMetadataFields = (): Promise<{ fields: BuiltInMetadataItem[] }> => {
|
||||
return get<{ fields: BuiltInMetadataItem[] }>('/datasets/metadata/built-in')
|
||||
}
|
||||
|
||||
export const fetchDocumentMetadata = (datasetId: string, documentId: string): Promise<DocumentDetailResponse> => {
|
||||
return get<DocumentDetailResponse>(`/datasets/${datasetId}/documents/${documentId}`, { params: { metadata: 'only' } })
|
||||
}
|
||||
|
||||
export const batchUpdateDocumentMetadata = (datasetId: string, metadataList: MetadataBatchEditToServer): Promise<void> => {
|
||||
return post(`/datasets/${datasetId}/documents/metadata`, {
|
||||
body: {
|
||||
operation_data: metadataList,
|
||||
},
|
||||
}) as Promise<void>
|
||||
}
|
||||
|
||||
export const updateBuiltInMetadataStatus = (datasetId: string, enabled: boolean): Promise<void> => {
|
||||
return post(`/datasets/${datasetId}/metadata/built-in/${enabled ? 'enable' : 'disable'}`) as Promise<void>
|
||||
}
|
||||
|
||||
export const fetchSegmentList = (datasetId: string, documentId: string, params: { page: number, limit: number, keyword: string, enabled: boolean | 'all' | '' }): Promise<SegmentsResponse> => {
|
||||
return get<SegmentsResponse>(`/datasets/${datasetId}/documents/${documentId}/segments`, { params })
|
||||
}
|
||||
|
||||
export const updateSegment = (datasetId: string, documentId: string, segmentId: string, body: SegmentUpdater): Promise<{ data: SegmentDetailModel, doc_form: ChunkingMode }> => {
|
||||
return patch<{ data: SegmentDetailModel, doc_form: ChunkingMode }>(`/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}`, { body })
|
||||
}
|
||||
|
||||
export const addSegment = (datasetId: string, documentId: string, body: SegmentUpdater): Promise<{ data: SegmentDetailModel, doc_form: ChunkingMode }> => {
|
||||
return post<{ data: SegmentDetailModel, doc_form: ChunkingMode }>(`/datasets/${datasetId}/documents/${documentId}/segment`, { body })
|
||||
}
|
||||
|
||||
export const enableSegments = (datasetId: string, documentId: string, segmentIds: string[]): Promise<CommonResponse> => {
|
||||
const query = segmentIds.map(id => `segment_id=${id}`).join('&')
|
||||
return patch<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/segment/enable?${query}`)
|
||||
}
|
||||
|
||||
export const disableSegments = (datasetId: string, documentId: string, segmentIds: string[]): Promise<CommonResponse> => {
|
||||
const query = segmentIds.map(id => `segment_id=${id}`).join('&')
|
||||
return patch<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/segment/disable?${query}`)
|
||||
}
|
||||
|
||||
export const deleteSegments = (datasetId: string, documentId: string, segmentIds: string[]): Promise<CommonResponse> => {
|
||||
const query = segmentIds.map(id => `segment_id=${id}`).join('&')
|
||||
return del<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/segments?${query}`)
|
||||
}
|
||||
|
||||
export const fetchChildSegments = (datasetId: string, documentId: string, segmentId: string, params: { page: number, limit: number, keyword: string }): Promise<ChildSegmentsResponse> => {
|
||||
return get<ChildSegmentsResponse>(`/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}/child_chunks`, { params })
|
||||
}
|
||||
|
||||
export const deleteChildSegment = (datasetId: string, documentId: string, segmentId: string, childChunkId: string): Promise<CommonResponse> => {
|
||||
return del<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}/child_chunks/${childChunkId}`)
|
||||
}
|
||||
|
||||
export const addChildSegment = (datasetId: string, documentId: string, segmentId: string, body: { content: string }): Promise<{ data: ChildChunkDetail }> => {
|
||||
return post<{ data: ChildChunkDetail }>(`/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}/child_chunks`, { body })
|
||||
}
|
||||
|
||||
export const updateChildSegment = (datasetId: string, documentId: string, segmentId: string, childChunkId: string, body: { content: string }): Promise<{ data: ChildChunkDetail }> => {
|
||||
return patch<{ data: ChildChunkDetail }>(`/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}/child_chunks/${childChunkId}`, { body })
|
||||
}
|
||||
|
||||
export const batchImportSegments = (url: string, body: { upload_file_id: string }): Promise<BatchImportResponse> => {
|
||||
return post<BatchImportResponse>(url, { body })
|
||||
}
|
||||
|
||||
export const checkSegmentBatchImportStatus = (jobID: string): Promise<BatchImportResponse> => {
|
||||
return get<BatchImportResponse>(`/datasets/batch_import_status/${jobID}`)
|
||||
}
|
||||
|
||||
25
web/service/datasource.ts
Normal file
25
web/service/datasource.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import type {
|
||||
DataSourceAuth,
|
||||
DataSourceCredential,
|
||||
} from '@/app/components/header/account-setting/data-source-page-new/types'
|
||||
import { get } from './base'
|
||||
|
||||
export const fetchDataSourceListAuth = () => {
|
||||
return get<{ result: DataSourceAuth[] }>('/auth/plugin/datasource/list')
|
||||
}
|
||||
|
||||
export const fetchDefaultDataSourceListAuth = () => {
|
||||
return get<{ result: DataSourceAuth[] }>('/auth/plugin/datasource/default-list')
|
||||
}
|
||||
|
||||
export const fetchDataSourceOAuthUrl = (provider: string, credentialId?: string) => {
|
||||
return get<{
|
||||
authorization_url: string
|
||||
state: string
|
||||
context_id: string
|
||||
}>(`/oauth/plugin/${provider}/datasource/get-authorization-url?credential_id=${credentialId}`)
|
||||
}
|
||||
|
||||
export const fetchDataSourceAuth = (pluginId: string, provider: string) => {
|
||||
return get<{ result: DataSourceCredential[] }>(`/auth/plugin/datasource/${pluginId}/${provider}`)
|
||||
}
|
||||
24
web/service/education.ts
Normal file
24
web/service/education.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { EducationAddParams } from '@/app/education-apply/types'
|
||||
import { get, post } from './base'
|
||||
|
||||
export type EducationVerifyResponse = { token: string }
|
||||
export type EducationAddResponse = { message: string }
|
||||
export type EducationAutocompleteResponse = { data: string[], has_next: boolean, curr_page: number }
|
||||
export type EducationStatusResponse = { is_student: boolean, allow_refresh: boolean, expire_at: number | null }
|
||||
|
||||
export const verifyEducation = () => {
|
||||
return get<EducationVerifyResponse>('/account/education/verify', {}, { silent: true })
|
||||
}
|
||||
|
||||
export const addEducation = (params: EducationAddParams) => {
|
||||
return post<EducationAddResponse>('/account/education', { body: params })
|
||||
}
|
||||
|
||||
export const fetchEducationAutocomplete = (params: { keywords: string, page: number, limit: number }) => {
|
||||
const { keywords, page, limit } = params
|
||||
return get<EducationAutocompleteResponse>(`/account/education/autocomplete?keywords=${keywords}&page=${page}&limit=${limit}`)
|
||||
}
|
||||
|
||||
export const fetchEducationStatus = () => {
|
||||
return get<EducationStatusResponse>('/account/education')
|
||||
}
|
||||
62
web/service/endpoints.ts
Normal file
62
web/service/endpoints.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import type { EndpointsResponse } from '@/app/components/plugins/types'
|
||||
import { get, post } from './base'
|
||||
|
||||
export const fetchEndpointList = (pluginID: string) => {
|
||||
return get<EndpointsResponse>('/workspaces/current/endpoints/list/plugin', {
|
||||
params: {
|
||||
plugin_id: pluginID,
|
||||
page: 1,
|
||||
page_size: 100,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const createEndpoint = (payload: { pluginUniqueID: string, state: Record<string, any> }) => {
|
||||
const { pluginUniqueID, state } = payload
|
||||
const newName = state.name
|
||||
delete state.name
|
||||
return post('/workspaces/current/endpoints/create', {
|
||||
body: {
|
||||
plugin_unique_identifier: pluginUniqueID,
|
||||
settings: state,
|
||||
name: newName,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const updateEndpoint = (payload: { endpointID: string, state: Record<string, any> }) => {
|
||||
const { endpointID, state } = payload
|
||||
const newName = state.name
|
||||
delete state.name
|
||||
return post('/workspaces/current/endpoints/update', {
|
||||
body: {
|
||||
endpoint_id: endpointID,
|
||||
settings: state,
|
||||
name: newName,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteEndpoint = (endpointID: string) => {
|
||||
return post('/workspaces/current/endpoints/delete', {
|
||||
body: {
|
||||
endpoint_id: endpointID,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const enableEndpoint = (endpointID: string) => {
|
||||
return post('/workspaces/current/endpoints/enable', {
|
||||
body: {
|
||||
endpoint_id: endpointID,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const disableEndpoint = (endpointID: string) => {
|
||||
return post('/workspaces/current/endpoints/disable', {
|
||||
body: {
|
||||
endpoint_id: endpointID,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import type {
|
||||
ChunkingMode,
|
||||
CrawlOptions,
|
||||
CrawlResultItem,
|
||||
CreateDatasetReq,
|
||||
CreateDatasetResponse,
|
||||
CreateDocumentReq,
|
||||
createDocumentResponse,
|
||||
@@ -19,11 +18,13 @@ import type {
|
||||
} from '@/models/datasets'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { groupBy } from 'es-toolkit/compat'
|
||||
import { post } from '../base'
|
||||
import { createDocument, createFirstDocument, fetchDefaultProcessRule, fetchFileIndexingEstimate } from '../datasets'
|
||||
import { createDatasetForPipeline, createEmptyDatasetForPipeline } from '../pipeline'
|
||||
|
||||
const NAME_SPACE = 'knowledge/create-dataset'
|
||||
|
||||
type CreatePipelineDatasetRequest = Parameters<typeof createDatasetForPipeline>[0]
|
||||
|
||||
export const getNotionInfo = (
|
||||
notionPages: NotionPage[],
|
||||
credentialId: string,
|
||||
@@ -250,19 +251,19 @@ export const useCreatePipelineDataset = (
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'create-pipeline-empty-dataset'],
|
||||
mutationFn: () => {
|
||||
return post<CreateDatasetResponse>('/rag/pipeline/empty-dataset')
|
||||
return createEmptyDatasetForPipeline()
|
||||
},
|
||||
...mutationOptions,
|
||||
})
|
||||
}
|
||||
|
||||
export const useCreatePipelineDatasetFromCustomized = (
|
||||
mutationOptions: MutationOptions<CreateDatasetResponse, Error, CreateDatasetReq> = {},
|
||||
mutationOptions: MutationOptions<CreateDatasetResponse, Error, CreatePipelineDatasetRequest> = {},
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'create-pipeline-dataset'],
|
||||
mutationFn: (req: CreateDatasetReq) => {
|
||||
return post<CreateDatasetResponse>('/rag/pipeline/dataset', { body: req })
|
||||
mutationFn: (req: CreatePipelineDatasetRequest) => {
|
||||
return createDatasetForPipeline(req)
|
||||
},
|
||||
...mutationOptions,
|
||||
})
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import type { MutationOptions } from '@tanstack/react-query'
|
||||
import type { InfiniteData, MutationOptions, QueryKey } from '@tanstack/react-query'
|
||||
import type { ApiKeysListResponse } from '@/models/app'
|
||||
import type { CommonResponse } from '@/models/common'
|
||||
import type {
|
||||
DataSet,
|
||||
DatasetListRequest,
|
||||
DataSetListResponse,
|
||||
ErrorDocsResponse,
|
||||
@@ -12,7 +10,6 @@ import type {
|
||||
IndexingStatusBatchRequest,
|
||||
IndexingStatusBatchResponse,
|
||||
ProcessRuleResponse,
|
||||
RelatedAppResponse,
|
||||
} from '@/models/datasets'
|
||||
import {
|
||||
keepPreviousData,
|
||||
@@ -21,8 +18,20 @@ import {
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
} from '@tanstack/react-query'
|
||||
import qs from 'qs'
|
||||
import { get, post } from '../base'
|
||||
import {
|
||||
disableDatasetServiceApi,
|
||||
enableDatasetServiceApi,
|
||||
fetchDatasetApiBaseInfo,
|
||||
fetchDatasetApiKeys,
|
||||
fetchDatasetDetail,
|
||||
fetchDatasetErrorDocs,
|
||||
fetchDatasetRelatedApps,
|
||||
fetchDatasets,
|
||||
fetchDatasetTestingRecords,
|
||||
fetchExternalKnowledgeApiList,
|
||||
fetchIndexingStatusBatch,
|
||||
fetchProcessRule,
|
||||
} from '../datasets'
|
||||
import { useInvalid } from '../use-base'
|
||||
|
||||
const NAME_SPACE = 'dataset'
|
||||
@@ -62,17 +71,16 @@ export const useInfiniteDatasets = (
|
||||
options?: UseInfiniteDatasetsOptions,
|
||||
) => {
|
||||
const normalizedParams = normalizeDatasetsParams(params)
|
||||
const buildUrl = (pageParam: number | undefined) => {
|
||||
const queryString = qs.stringify({
|
||||
...normalizedParams,
|
||||
page: pageParam ?? normalizedParams.page,
|
||||
}, { indices: false })
|
||||
return `/datasets?${queryString}`
|
||||
}
|
||||
|
||||
return useInfiniteQuery<DataSetListResponse>({
|
||||
return useInfiniteQuery<DataSetListResponse, Error, InfiniteData<DataSetListResponse>, QueryKey, number>({
|
||||
queryKey: [...DatasetListKey, 'infinite', normalizedParams],
|
||||
queryFn: ({ pageParam = normalizedParams.page }) => get<DataSetListResponse>(buildUrl(pageParam as number | undefined)),
|
||||
queryFn: ({ pageParam = normalizedParams.page }) => fetchDatasets({
|
||||
url: '/datasets',
|
||||
params: {
|
||||
...normalizedParams,
|
||||
page: pageParam ?? normalizedParams.page,
|
||||
},
|
||||
}),
|
||||
getNextPageParam: lastPage => lastPage.has_more ? lastPage.page + 1 : undefined,
|
||||
initialPageParam: normalizedParams.page,
|
||||
staleTime: 0,
|
||||
@@ -86,14 +94,16 @@ export const useDatasetList = (params: DatasetListRequest) => {
|
||||
return useInfiniteQuery({
|
||||
queryKey: [...DatasetListKey, initialPage, tag_ids, limit, include_all, keyword],
|
||||
queryFn: ({ pageParam = 1 }) => {
|
||||
const urlParams = qs.stringify({
|
||||
tag_ids,
|
||||
limit,
|
||||
include_all,
|
||||
keyword,
|
||||
page: pageParam,
|
||||
}, { indices: false })
|
||||
return get<DataSetListResponse>(`/datasets?${urlParams}`)
|
||||
return fetchDatasets({
|
||||
url: '/datasets',
|
||||
params: {
|
||||
tag_ids,
|
||||
limit,
|
||||
include_all,
|
||||
keyword,
|
||||
page: pageParam,
|
||||
},
|
||||
})
|
||||
},
|
||||
getNextPageParam: lastPage => lastPage.has_more ? lastPage.page + 1 : null,
|
||||
initialPageParam: initialPage,
|
||||
@@ -109,7 +119,7 @@ export const datasetDetailQueryKeyPrefix = [NAME_SPACE, 'detail']
|
||||
export const useDatasetDetail = (datasetId: string) => {
|
||||
return useQuery({
|
||||
queryKey: [...datasetDetailQueryKeyPrefix, datasetId],
|
||||
queryFn: () => get<DataSet>(`/datasets/${datasetId}`),
|
||||
queryFn: () => fetchDatasetDetail(datasetId),
|
||||
enabled: !!datasetId,
|
||||
})
|
||||
}
|
||||
@@ -117,7 +127,7 @@ export const useDatasetDetail = (datasetId: string) => {
|
||||
export const useDatasetRelatedApps = (datasetId: string) => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'related-apps', datasetId],
|
||||
queryFn: () => get<RelatedAppResponse>(`/datasets/${datasetId}/related-apps`),
|
||||
queryFn: () => fetchDatasetRelatedApps(datasetId),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -128,7 +138,7 @@ export const useIndexingStatusBatch = (
|
||||
const { datasetId, batchId } = params
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'indexing-status-batch', datasetId, batchId],
|
||||
mutationFn: () => get<IndexingStatusBatchResponse>(`/datasets/${datasetId}/batch/${batchId}/indexing-status`),
|
||||
mutationFn: () => fetchIndexingStatusBatch({ datasetId, batchId }),
|
||||
...mutationOptions,
|
||||
})
|
||||
}
|
||||
@@ -136,7 +146,7 @@ export const useIndexingStatusBatch = (
|
||||
export const useProcessRule = (documentId?: string) => {
|
||||
return useQuery<ProcessRuleResponse>({
|
||||
queryKey: [NAME_SPACE, 'process-rule', documentId],
|
||||
queryFn: () => get<ProcessRuleResponse>('/datasets/process-rule', { params: { document_id: documentId } }),
|
||||
queryFn: () => fetchProcessRule({ params: { documentId: documentId || '' } }),
|
||||
enabled: !!documentId,
|
||||
refetchOnWindowFocus: false,
|
||||
})
|
||||
@@ -145,28 +155,28 @@ export const useProcessRule = (documentId?: string) => {
|
||||
export const useDatasetApiBaseUrl = () => {
|
||||
return useQuery<{ api_base_url: string }>({
|
||||
queryKey: [NAME_SPACE, 'api-base-info'],
|
||||
queryFn: () => get<{ api_base_url: string }>('/datasets/api-base-info'),
|
||||
queryFn: () => fetchDatasetApiBaseInfo(),
|
||||
})
|
||||
}
|
||||
|
||||
export const useEnableDatasetServiceApi = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'enable-api'],
|
||||
mutationFn: (datasetId: string) => post<CommonResponse>(`/datasets/${datasetId}/api-keys/enable`),
|
||||
mutationFn: (datasetId: string) => enableDatasetServiceApi(datasetId),
|
||||
})
|
||||
}
|
||||
|
||||
export const useDisableDatasetServiceApi = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'disable-api'],
|
||||
mutationFn: (datasetId: string) => post<CommonResponse>(`/datasets/${datasetId}/api-keys/disable`),
|
||||
mutationFn: (datasetId: string) => disableDatasetServiceApi(datasetId),
|
||||
})
|
||||
}
|
||||
|
||||
export const useDatasetApiKeys = (options?: { enabled?: boolean }) => {
|
||||
return useQuery<ApiKeysListResponse>({
|
||||
queryKey: [NAME_SPACE, 'api-keys'],
|
||||
queryFn: () => get<ApiKeysListResponse>('/datasets/api-keys'),
|
||||
queryFn: () => fetchDatasetApiKeys(),
|
||||
enabled: options?.enabled ?? true,
|
||||
})
|
||||
}
|
||||
@@ -183,7 +193,7 @@ export const useInvalidateDatasetApiKeys = () => {
|
||||
export const useExternalKnowledgeApiList = (options?: { enabled?: boolean }) => {
|
||||
return useQuery<ExternalAPIListResponse>({
|
||||
queryKey: [NAME_SPACE, 'external-knowledge-api'],
|
||||
queryFn: () => get<ExternalAPIListResponse>('/datasets/external-knowledge-api'),
|
||||
queryFn: () => fetchExternalKnowledgeApiList(),
|
||||
enabled: options?.enabled ?? true,
|
||||
})
|
||||
}
|
||||
@@ -203,7 +213,7 @@ export const useDatasetTestingRecords = (
|
||||
) => {
|
||||
return useQuery<HitTestingRecordsResponse>({
|
||||
queryKey: [NAME_SPACE, 'testing-records', datasetId, params],
|
||||
queryFn: () => get<HitTestingRecordsResponse>(`/datasets/${datasetId}/queries`, { params }),
|
||||
queryFn: () => fetchDatasetTestingRecords(datasetId || '', params),
|
||||
enabled: !!datasetId && !!params,
|
||||
placeholderData: keepPreviousData,
|
||||
})
|
||||
@@ -212,7 +222,7 @@ export const useDatasetTestingRecords = (
|
||||
export const useDatasetErrorDocs = (datasetId?: string) => {
|
||||
return useQuery<ErrorDocsResponse>({
|
||||
queryKey: [NAME_SPACE, 'error-docs', datasetId],
|
||||
queryFn: () => get<ErrorDocsResponse>(`/datasets/${datasetId}/error-docs`),
|
||||
queryFn: () => fetchDatasetErrorDocs(datasetId || ''),
|
||||
enabled: !!datasetId,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -7,8 +7,18 @@ import {
|
||||
} from '@tanstack/react-query'
|
||||
import { normalizeStatusForQuery } from '@/app/components/datasets/documents/status-filter'
|
||||
import { DocumentActionType } from '@/models/datasets'
|
||||
import { del, get, patch, post } from '../base'
|
||||
import { pauseDocIndexing, resumeDocIndexing } from '../datasets'
|
||||
import {
|
||||
deleteDocumentBatch,
|
||||
fetchAutoDisabledDocuments,
|
||||
fetchDocumentDetail,
|
||||
fetchDocumentList,
|
||||
pauseDocIndexing,
|
||||
resumeDocIndexing,
|
||||
retryDocumentBatch,
|
||||
syncNotionDocument,
|
||||
syncWebsiteDocument,
|
||||
updateDocumentStatusBatch,
|
||||
} from '../datasets'
|
||||
import { useInvalid } from '../use-base'
|
||||
|
||||
const NAME_SPACE = 'knowledge/document'
|
||||
@@ -28,7 +38,7 @@ export const useDocumentList = (payload: {
|
||||
const { query, datasetId, refetchInterval } = payload
|
||||
const { keyword, page, limit, sort, status } = query
|
||||
const normalizedStatus = normalizeStatusForQuery(status)
|
||||
const params: Record<string, number | string> = {
|
||||
const params: { keyword: string, page: number, limit: number, sort?: SortType, status?: string } = {
|
||||
keyword,
|
||||
page,
|
||||
limit,
|
||||
@@ -39,9 +49,7 @@ export const useDocumentList = (payload: {
|
||||
params.status = normalizedStatus
|
||||
return useQuery<DocumentListResponse>({
|
||||
queryKey: [...useDocumentListKey, datasetId, params],
|
||||
queryFn: () => get<DocumentListResponse>(`/datasets/${datasetId}/documents`, {
|
||||
params,
|
||||
}),
|
||||
queryFn: () => fetchDocumentList(datasetId, params),
|
||||
refetchInterval,
|
||||
})
|
||||
}
|
||||
@@ -54,7 +62,7 @@ const useAutoDisabledDocumentKey = [NAME_SPACE, 'autoDisabledDocument']
|
||||
export const useAutoDisabledDocuments = (datasetId: string) => {
|
||||
return useQuery({
|
||||
queryKey: [...useAutoDisabledDocumentKey, datasetId],
|
||||
queryFn: () => get<{ document_ids: string[] }>(`/datasets/${datasetId}/auto-disable-logs`),
|
||||
queryFn: () => fetchAutoDisabledDocuments(datasetId),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -62,15 +70,10 @@ export const useInvalidDisabledDocument = () => {
|
||||
return useInvalid(useAutoDisabledDocumentKey)
|
||||
}
|
||||
|
||||
const toBatchDocumentsIdParams = (documentIds: string[] | string) => {
|
||||
const ids = Array.isArray(documentIds) ? documentIds : [documentIds]
|
||||
return ids.map(id => `document_id=${id}`).join('&')
|
||||
}
|
||||
|
||||
export const useDocumentBatchAction = (action: DocumentActionType) => {
|
||||
return useMutation({
|
||||
mutationFn: ({ datasetId, documentIds, documentId }: UpdateDocumentBatchParams) => {
|
||||
return patch<CommonResponse>(`/datasets/${datasetId}/documents/status/${action}/batch?${toBatchDocumentsIdParams(documentId || documentIds!)}`)
|
||||
return updateDocumentStatusBatch(datasetId, action, documentId || documentIds!)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -94,7 +97,7 @@ export const useDocumentUnArchive = () => {
|
||||
export const useDocumentDelete = () => {
|
||||
return useMutation({
|
||||
mutationFn: ({ datasetId, documentIds, documentId }: UpdateDocumentBatchParams) => {
|
||||
return del<CommonResponse>(`/datasets/${datasetId}/documents?${toBatchDocumentsIdParams(documentId || documentIds!)}`)
|
||||
return deleteDocumentBatch(datasetId, documentId || documentIds!)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -102,7 +105,7 @@ export const useDocumentDelete = () => {
|
||||
export const useSyncDocument = () => {
|
||||
return useMutation({
|
||||
mutationFn: ({ datasetId, documentId }: UpdateDocumentBatchParams) => {
|
||||
return get<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/notion/sync`)
|
||||
return syncNotionDocument(datasetId, documentId as string)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -110,7 +113,7 @@ export const useSyncDocument = () => {
|
||||
export const useSyncWebsite = () => {
|
||||
return useMutation({
|
||||
mutationFn: ({ datasetId, documentId }: UpdateDocumentBatchParams) => {
|
||||
return get<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/website-sync`)
|
||||
return syncWebsiteDocument(datasetId, documentId as string)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -124,7 +127,7 @@ export const useDocumentDetail = (payload: {
|
||||
const { datasetId, documentId, params } = payload
|
||||
return useQuery<DocumentDetailResponse>({
|
||||
queryKey: [...useDocumentDetailKey, 'withoutMetaData', datasetId, documentId, params],
|
||||
queryFn: () => get<DocumentDetailResponse>(`/datasets/${datasetId}/documents/${documentId}`, { params }),
|
||||
queryFn: () => fetchDocumentDetail(datasetId, documentId, params),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -136,7 +139,7 @@ export const useDocumentMetadata = (payload: {
|
||||
const { datasetId, documentId, params } = payload
|
||||
return useQuery<DocumentDetailResponse>({
|
||||
queryKey: [...useDocumentDetailKey, 'onlyMetaData', datasetId, documentId, params],
|
||||
queryFn: () => get<DocumentDetailResponse>(`/datasets/${datasetId}/documents/${documentId}`, { params }),
|
||||
queryFn: () => fetchDocumentDetail(datasetId, documentId, params),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -167,11 +170,7 @@ export const useDocumentResume = () => {
|
||||
export const useDocumentBatchRetryIndex = () => {
|
||||
return useMutation({
|
||||
mutationFn: ({ datasetId, documentIds }: { datasetId: string, documentIds: string[] }) => {
|
||||
return post<CommonResponse>(`/datasets/${datasetId}/retry`, {
|
||||
body: {
|
||||
document_ids: documentIds,
|
||||
},
|
||||
})
|
||||
return retryDocumentBatch(datasetId, documentIds)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import type {
|
||||
ExternalKnowledgeBaseHitTestingRequest,
|
||||
ExternalKnowledgeBaseHitTestingResponse,
|
||||
HitTestingRecordsRequest,
|
||||
HitTestingRecordsResponse,
|
||||
HitTestingRequest,
|
||||
HitTestingResponse,
|
||||
} from '@/models/datasets'
|
||||
import { useMutation, useQuery } from '@tanstack/react-query'
|
||||
import { get, post } from '../base'
|
||||
import { externalKnowledgeBaseHitTesting, fetchTestingRecords, hitTesting } from '../datasets'
|
||||
import { useInvalid } from '../use-base'
|
||||
|
||||
const NAME_SPACE = 'hit-testing'
|
||||
@@ -18,7 +15,7 @@ export const useHitTestingRecords = (params: HitTestingRecordsRequest) => {
|
||||
const { datasetId, page, limit } = params
|
||||
return useQuery({
|
||||
queryKey: [...HitTestingRecordsKey, datasetId, page, limit],
|
||||
queryFn: () => get<HitTestingRecordsResponse>(`/datasets/${datasetId}/queries`, { params: { page, limit } }),
|
||||
queryFn: () => fetchTestingRecords({ datasetId, params: { page, limit } }),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -29,17 +26,13 @@ export const useInvalidateHitTestingRecords = (datasetId: string) => {
|
||||
export const useHitTesting = (datasetId: string) => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'hit-testing', datasetId],
|
||||
mutationFn: (params: HitTestingRequest) => post<HitTestingResponse>(`/datasets/${datasetId}/hit-testing`, {
|
||||
body: params,
|
||||
}),
|
||||
mutationFn: (params: HitTestingRequest) => hitTesting({ datasetId, ...params }),
|
||||
})
|
||||
}
|
||||
|
||||
export const useExternalKnowledgeBaseHitTesting = (datasetId: string) => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'external-knowledge-base-hit-testing', datasetId],
|
||||
mutationFn: (params: ExternalKnowledgeBaseHitTestingRequest) => post<ExternalKnowledgeBaseHitTestingResponse>(`/datasets/${datasetId}/external-hit-testing`, {
|
||||
body: params,
|
||||
}),
|
||||
mutationFn: (params: ExternalKnowledgeBaseHitTestingRequest) => externalKnowledgeBaseHitTesting({ datasetId, query: params.query, external_retrieval_model: params.external_retrieval_model }),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { DataSourceNotionWorkspace } from '@/models/common'
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { get } from '../base'
|
||||
import { fetchPreImportNotionPages } from '../datasets'
|
||||
|
||||
type PreImportNotionPagesParams = {
|
||||
datasetId: string
|
||||
@@ -16,12 +15,7 @@ export const usePreImportNotionPages = ({
|
||||
return useQuery({
|
||||
queryKey: [PRE_IMPORT_NOTION_PAGES_QUERY_KEY, datasetId, credentialId],
|
||||
queryFn: async () => {
|
||||
return get<{ notion_info: DataSourceNotionWorkspace[] }>('/notion/pre-import/pages', {
|
||||
params: {
|
||||
dataset_id: datasetId,
|
||||
credential_id: credentialId,
|
||||
},
|
||||
})
|
||||
return fetchPreImportNotionPages({ datasetId, credentialId })
|
||||
},
|
||||
retry: 0,
|
||||
})
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
import type { BuiltInMetadataItem, MetadataBatchEditToServer, MetadataItemWithValueLength } from '@/app/components/datasets/metadata/types'
|
||||
import type { DocumentDetailResponse } from '@/models/datasets'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { del, get, patch, post } from '../base'
|
||||
import {
|
||||
batchUpdateDocumentMetadata,
|
||||
createDatasetMetadata,
|
||||
deleteDatasetMetadata,
|
||||
fetchBuiltInMetadataFields,
|
||||
fetchDatasetMetadata,
|
||||
fetchDocumentMetadata,
|
||||
updateBuiltInMetadataStatus,
|
||||
updateDatasetMetadataName,
|
||||
} from '../datasets'
|
||||
import { useInvalid } from '../use-base'
|
||||
import { useDocumentListKey, useInvalidDocumentList } from './use-document'
|
||||
|
||||
@@ -11,7 +20,7 @@ export const useDatasetMetaData = (datasetId: string) => {
|
||||
return useQuery<{ doc_metadata: MetadataItemWithValueLength[], built_in_field_enabled: boolean }>({
|
||||
queryKey: [NAME_SPACE, 'dataset', datasetId],
|
||||
queryFn: () => {
|
||||
return get<{ doc_metadata: MetadataItemWithValueLength[], built_in_field_enabled: boolean }>(`/datasets/${datasetId}/metadata`)
|
||||
return fetchDatasetMetadata(datasetId)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -24,9 +33,7 @@ export const useCreateMetaData = (datasetId: string) => {
|
||||
const invalidDatasetMetaData = useInvalidDatasetMetaData(datasetId)
|
||||
return useMutation({
|
||||
mutationFn: async (payload: BuiltInMetadataItem) => {
|
||||
await post(`/datasets/${datasetId}/metadata`, {
|
||||
body: payload,
|
||||
})
|
||||
await createDatasetMetadata(datasetId, payload)
|
||||
await invalidDatasetMetaData()
|
||||
return Promise.resolve(true)
|
||||
},
|
||||
@@ -61,11 +68,7 @@ export const useRenameMeta = (datasetId: string) => {
|
||||
const invalidateAllMetaData = useInvalidAllMetaData(datasetId)
|
||||
return useMutation({
|
||||
mutationFn: async (payload: MetadataItemWithValueLength) => {
|
||||
await patch(`/datasets/${datasetId}/metadata/${payload.id}`, {
|
||||
body: {
|
||||
name: payload.name,
|
||||
},
|
||||
})
|
||||
await updateDatasetMetadataName(datasetId, payload.id, payload.name)
|
||||
await invalidateAllMetaData()
|
||||
},
|
||||
})
|
||||
@@ -76,7 +79,7 @@ export const useDeleteMetaData = (datasetId: string) => {
|
||||
return useMutation({
|
||||
mutationFn: async (metaDataId: string) => {
|
||||
// datasetMetaData = datasetMetaData.filter(item => item.id !== metaDataId)
|
||||
await del(`/datasets/${datasetId}/metadata/${metaDataId}`)
|
||||
await deleteDatasetMetadata(datasetId, metaDataId)
|
||||
await invalidateAllMetaData()
|
||||
},
|
||||
})
|
||||
@@ -86,7 +89,7 @@ export const useBuiltInMetaDataFields = () => {
|
||||
return useQuery<{ fields: BuiltInMetadataItem[] }>({
|
||||
queryKey: [NAME_SPACE, 'built-in'],
|
||||
queryFn: () => {
|
||||
return get('/datasets/metadata/built-in')
|
||||
return fetchBuiltInMetadataFields()
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -95,7 +98,7 @@ export const useDocumentMetaData = ({ datasetId, documentId }: { datasetId: stri
|
||||
return useQuery<DocumentDetailResponse>({
|
||||
queryKey: [NAME_SPACE, 'document', datasetId, documentId],
|
||||
queryFn: () => {
|
||||
return get<DocumentDetailResponse>(`/datasets/${datasetId}/documents/${documentId}`, { params: { metadata: 'only' } })
|
||||
return fetchDocumentMetadata(datasetId, documentId)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -108,11 +111,7 @@ export const useBatchUpdateDocMetadata = () => {
|
||||
metadata_list: MetadataBatchEditToServer
|
||||
}) => {
|
||||
const documentIds = payload.metadata_list.map(item => item.document_id)
|
||||
await post(`/datasets/${payload.dataset_id}/documents/metadata`, {
|
||||
body: {
|
||||
operation_data: payload.metadata_list,
|
||||
},
|
||||
})
|
||||
await batchUpdateDocumentMetadata(payload.dataset_id, payload.metadata_list)
|
||||
// meta data in dataset
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: [NAME_SPACE, 'dataset', payload.dataset_id],
|
||||
@@ -139,7 +138,7 @@ export const useUpdateBuiltInStatus = (datasetId: string) => {
|
||||
const invalidDatasetMetaData = useInvalidDatasetMetaData(datasetId)
|
||||
return useMutation({
|
||||
mutationFn: async (enabled: boolean) => {
|
||||
await post(`/datasets/${datasetId}/metadata/built-in/${enabled ? 'enable' : 'disable'}`)
|
||||
await updateBuiltInMetadataStatus(datasetId, enabled)
|
||||
invalidDatasetMetaData()
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
import type { CommonResponse } from '@/models/common'
|
||||
import type {
|
||||
BatchImportResponse,
|
||||
ChildChunkDetail,
|
||||
ChildSegmentsResponse,
|
||||
ChunkingMode,
|
||||
SegmentDetailModel,
|
||||
SegmentsResponse,
|
||||
SegmentUpdater,
|
||||
} from '@/models/datasets'
|
||||
import { useMutation, useQuery } from '@tanstack/react-query'
|
||||
import { del, get, patch, post } from '../base'
|
||||
import {
|
||||
addChildSegment,
|
||||
addSegment,
|
||||
batchImportSegments,
|
||||
checkSegmentBatchImportStatus,
|
||||
deleteChildSegment,
|
||||
deleteSegments,
|
||||
disableSegments,
|
||||
enableSegments,
|
||||
fetchChildSegments,
|
||||
fetchSegmentList,
|
||||
updateChildSegment,
|
||||
updateSegment,
|
||||
} from '../datasets'
|
||||
|
||||
const NAME_SPACE = 'segment'
|
||||
|
||||
@@ -36,7 +43,7 @@ export const useSegmentList = (
|
||||
return useQuery<SegmentsResponse>({
|
||||
queryKey: [...useSegmentListKey, datasetId, documentId, params],
|
||||
queryFn: () => {
|
||||
return get<SegmentsResponse>(`/datasets/${datasetId}/documents/${documentId}/segments`, { params })
|
||||
return fetchSegmentList(datasetId, documentId, params)
|
||||
},
|
||||
enabled: !disable,
|
||||
})
|
||||
@@ -47,7 +54,7 @@ export const useUpdateSegment = () => {
|
||||
mutationKey: [NAME_SPACE, 'update'],
|
||||
mutationFn: (payload: { datasetId: string, documentId: string, segmentId: string, body: SegmentUpdater }) => {
|
||||
const { datasetId, documentId, segmentId, body } = payload
|
||||
return patch<{ data: SegmentDetailModel, doc_form: ChunkingMode }>(`/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}`, { body })
|
||||
return updateSegment(datasetId, documentId, segmentId, body)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -57,7 +64,7 @@ export const useAddSegment = () => {
|
||||
mutationKey: [NAME_SPACE, 'add'],
|
||||
mutationFn: (payload: { datasetId: string, documentId: string, body: SegmentUpdater }) => {
|
||||
const { datasetId, documentId, body } = payload
|
||||
return post<{ data: SegmentDetailModel, doc_form: ChunkingMode }>(`/datasets/${datasetId}/documents/${documentId}/segment`, { body })
|
||||
return addSegment(datasetId, documentId, body)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -67,8 +74,7 @@ export const useEnableSegment = () => {
|
||||
mutationKey: [NAME_SPACE, 'enable'],
|
||||
mutationFn: (payload: { datasetId: string, documentId: string, segmentIds: string[] }) => {
|
||||
const { datasetId, documentId, segmentIds } = payload
|
||||
const query = segmentIds.map(id => `segment_id=${id}`).join('&')
|
||||
return patch<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/segment/enable?${query}`)
|
||||
return enableSegments(datasetId, documentId, segmentIds)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -78,8 +84,7 @@ export const useDisableSegment = () => {
|
||||
mutationKey: [NAME_SPACE, 'disable'],
|
||||
mutationFn: (payload: { datasetId: string, documentId: string, segmentIds: string[] }) => {
|
||||
const { datasetId, documentId, segmentIds } = payload
|
||||
const query = segmentIds.map(id => `segment_id=${id}`).join('&')
|
||||
return patch<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/segment/disable?${query}`)
|
||||
return disableSegments(datasetId, documentId, segmentIds)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -89,8 +94,7 @@ export const useDeleteSegment = () => {
|
||||
mutationKey: [NAME_SPACE, 'delete'],
|
||||
mutationFn: (payload: { datasetId: string, documentId: string, segmentIds: string[] }) => {
|
||||
const { datasetId, documentId, segmentIds } = payload
|
||||
const query = segmentIds.map(id => `segment_id=${id}`).join('&')
|
||||
return del<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/segments?${query}`)
|
||||
return deleteSegments(datasetId, documentId, segmentIds)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -115,7 +119,7 @@ export const useChildSegmentList = (
|
||||
return useQuery({
|
||||
queryKey: [...useChildSegmentListKey, datasetId, documentId, segmentId, params],
|
||||
queryFn: () => {
|
||||
return get<ChildSegmentsResponse>(`/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}/child_chunks`, { params })
|
||||
return fetchChildSegments(datasetId, documentId, segmentId, params)
|
||||
},
|
||||
enabled: !disable,
|
||||
})
|
||||
@@ -126,7 +130,7 @@ export const useDeleteChildSegment = () => {
|
||||
mutationKey: [NAME_SPACE, 'childChunk', 'delete'],
|
||||
mutationFn: (payload: { datasetId: string, documentId: string, segmentId: string, childChunkId: string }) => {
|
||||
const { datasetId, documentId, segmentId, childChunkId } = payload
|
||||
return del<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}/child_chunks/${childChunkId}`)
|
||||
return deleteChildSegment(datasetId, documentId, segmentId, childChunkId)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -136,7 +140,7 @@ export const useAddChildSegment = () => {
|
||||
mutationKey: [NAME_SPACE, 'childChunk', 'add'],
|
||||
mutationFn: (payload: { datasetId: string, documentId: string, segmentId: string, body: { content: string } }) => {
|
||||
const { datasetId, documentId, segmentId, body } = payload
|
||||
return post<{ data: ChildChunkDetail }>(`/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}/child_chunks`, { body })
|
||||
return addChildSegment(datasetId, documentId, segmentId, body)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -146,7 +150,7 @@ export const useUpdateChildSegment = () => {
|
||||
mutationKey: [NAME_SPACE, 'childChunk', 'update'],
|
||||
mutationFn: (payload: { datasetId: string, documentId: string, segmentId: string, childChunkId: string, body: { content: string } }) => {
|
||||
const { datasetId, documentId, segmentId, childChunkId, body } = payload
|
||||
return patch<{ data: ChildChunkDetail }>(`/datasets/${datasetId}/documents/${documentId}/segments/${segmentId}/child_chunks/${childChunkId}`, { body })
|
||||
return updateChildSegment(datasetId, documentId, segmentId, childChunkId, body)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -156,7 +160,7 @@ export const useSegmentBatchImport = () => {
|
||||
mutationKey: [NAME_SPACE, 'batchImport'],
|
||||
mutationFn: (payload: { url: string, body: { upload_file_id: string } }) => {
|
||||
const { url, body } = payload
|
||||
return post<BatchImportResponse>(url, { body })
|
||||
return batchImportSegments(url, body)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -166,7 +170,7 @@ export const useCheckSegmentBatchImportProgress = () => {
|
||||
mutationKey: [NAME_SPACE, 'batchImport', 'checkProgress'],
|
||||
mutationFn: (payload: { jobID: string }) => {
|
||||
const { jobID } = payload
|
||||
return get<BatchImportResponse>(`/datasets/batch_import_status/${jobID}`)
|
||||
return checkSegmentBatchImportStatus(jobID)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
import type {
|
||||
AgentLogDetailRequest,
|
||||
AgentLogDetailResponse,
|
||||
AnnotationsCountResponse,
|
||||
ChatConversationFullDetailResponse,
|
||||
ChatConversationsRequest,
|
||||
ChatConversationsResponse,
|
||||
ChatMessagesRequest,
|
||||
ChatMessagesResponse,
|
||||
CompletionConversationFullDetailResponse,
|
||||
CompletionConversationsRequest,
|
||||
CompletionConversationsResponse,
|
||||
LogMessageAnnotationsRequest,
|
||||
LogMessageAnnotationsResponse,
|
||||
LogMessageFeedbacksRequest,
|
||||
LogMessageFeedbacksResponse,
|
||||
WorkflowLogsResponse,
|
||||
WorkflowRunDetailResponse,
|
||||
} from '@/models/log'
|
||||
import type { NodeTracingListResponse } from '@/types/workflow'
|
||||
@@ -36,3 +44,27 @@ export const fetchTracingList = ({ url }: { url: string }): Promise<NodeTracingL
|
||||
export const fetchAgentLogDetail = ({ appID, params }: { appID: string, params: AgentLogDetailRequest }): Promise<AgentLogDetailResponse> => {
|
||||
return get<AgentLogDetailResponse>(`/apps/${appID}/agent/logs`, { params })
|
||||
}
|
||||
|
||||
export const fetchAnnotationsCount = (appId: string): Promise<AnnotationsCountResponse> => {
|
||||
return get<AnnotationsCountResponse>(`/apps/${appId}/annotations/count`)
|
||||
}
|
||||
|
||||
export const fetchChatConversations = (appId: string, params?: Partial<ChatConversationsRequest>): Promise<ChatConversationsResponse> => {
|
||||
return get<ChatConversationsResponse>(`/apps/${appId}/chat-conversations`, { params })
|
||||
}
|
||||
|
||||
export const fetchCompletionConversations = (appId: string, params?: Partial<CompletionConversationsRequest>): Promise<CompletionConversationsResponse> => {
|
||||
return get<CompletionConversationsResponse>(`/apps/${appId}/completion-conversations`, { params })
|
||||
}
|
||||
|
||||
export const fetchChatConversationDetail = (appId: string, conversationId: string): Promise<ChatConversationFullDetailResponse> => {
|
||||
return get<ChatConversationFullDetailResponse>(`/apps/${appId}/chat-conversations/${conversationId}`)
|
||||
}
|
||||
|
||||
export const fetchCompletionConversationDetail = (appId: string, conversationId: string): Promise<CompletionConversationFullDetailResponse> => {
|
||||
return get<CompletionConversationFullDetailResponse>(`/apps/${appId}/completion-conversations/${conversationId}`)
|
||||
}
|
||||
|
||||
export const fetchWorkflowLogs = (appId: string, params?: Record<string, string | number | boolean | undefined>): Promise<WorkflowLogsResponse> => {
|
||||
return get<WorkflowLogsResponse>(`/apps/${appId}/workflow-app-logs`, { params })
|
||||
}
|
||||
|
||||
92
web/service/models.ts
Normal file
92
web/service/models.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import type {
|
||||
ModelCredential,
|
||||
ModelItem,
|
||||
ModelLoadBalancingConfig,
|
||||
ModelTypeEnum,
|
||||
ProviderCredential,
|
||||
} from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||
import { del, get, post, put } from './base'
|
||||
|
||||
export const fetchModelProviderModelList = (provider: string) => {
|
||||
return get<{ data: ModelItem[] }>(`/workspaces/current/model-providers/${provider}/models`)
|
||||
}
|
||||
|
||||
export const fetchProviderCredential = (provider: string, credentialId?: string) => {
|
||||
return get<ProviderCredential>(`/workspaces/current/model-providers/${provider}/credentials${credentialId ? `?credential_id=${credentialId}` : ''}`)
|
||||
}
|
||||
|
||||
export const addProviderCredential = (provider: string, data: ProviderCredential) => {
|
||||
return post<{ result: string }>(`/workspaces/current/model-providers/${provider}/credentials`, {
|
||||
body: data,
|
||||
})
|
||||
}
|
||||
|
||||
export const editProviderCredential = (provider: string, data: ProviderCredential) => {
|
||||
return put<{ result: string }>(`/workspaces/current/model-providers/${provider}/credentials`, {
|
||||
body: data,
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteProviderCredential = (provider: string, data: { credential_id: string }) => {
|
||||
return del<{ result: string }>(`/workspaces/current/model-providers/${provider}/credentials`, {
|
||||
body: data,
|
||||
})
|
||||
}
|
||||
|
||||
export const activateProviderCredential = (provider: string, data: { credential_id: string, model?: string, model_type?: ModelTypeEnum }) => {
|
||||
return post<{ result: string }>(`/workspaces/current/model-providers/${provider}/credentials/switch`, {
|
||||
body: data,
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchModelCredential = (
|
||||
provider: string,
|
||||
model?: string,
|
||||
modelType?: string,
|
||||
configFrom?: string,
|
||||
credentialId?: string,
|
||||
) => {
|
||||
return get<ModelCredential>(`/workspaces/current/model-providers/${provider}/models/credentials?model=${model}&model_type=${modelType}&config_from=${configFrom}${credentialId ? `&credential_id=${credentialId}` : ''}`)
|
||||
}
|
||||
|
||||
export const addModelCredential = (provider: string, data: ModelCredential) => {
|
||||
return post<{ result: string }>(`/workspaces/current/model-providers/${provider}/models/credentials`, {
|
||||
body: data,
|
||||
})
|
||||
}
|
||||
|
||||
export const editModelCredential = (provider: string, data: ModelCredential) => {
|
||||
return put<{ result: string }>(`/workspaces/current/model-providers/${provider}/models/credentials`, {
|
||||
body: data,
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteModelCredential = (provider: string, data: { credential_id: string, model?: string, model_type?: ModelTypeEnum }) => {
|
||||
return del<{ result: string }>(`/workspaces/current/model-providers/${provider}/models/credentials`, {
|
||||
body: data,
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteModel = (provider: string, data: { model: string, model_type: ModelTypeEnum }) => {
|
||||
return del<{ result: string }>(`/workspaces/current/model-providers/${provider}/models`, {
|
||||
body: data,
|
||||
})
|
||||
}
|
||||
|
||||
export const activateModelCredential = (provider: string, data: { credential_id: string, model?: string, model_type?: ModelTypeEnum }) => {
|
||||
return post<{ result: string }>(`/workspaces/current/model-providers/${provider}/models/credentials/switch`, {
|
||||
body: data,
|
||||
})
|
||||
}
|
||||
|
||||
export const updateModelLoadBalancingConfig = (provider: string, data: {
|
||||
config_from: string
|
||||
model: string
|
||||
model_type: ModelTypeEnum
|
||||
load_balancing: ModelLoadBalancingConfig
|
||||
credential_id?: string
|
||||
}) => {
|
||||
return post<{ result: string }>(`/workspaces/current/model-providers/${provider}/models`, {
|
||||
body: data,
|
||||
})
|
||||
}
|
||||
19
web/service/oauth.ts
Normal file
19
web/service/oauth.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { post } from './base'
|
||||
|
||||
export type OAuthAppInfo = {
|
||||
app_icon: string
|
||||
app_label: Record<string, string>
|
||||
scope: string
|
||||
}
|
||||
|
||||
export type OAuthAuthorizeResponse = {
|
||||
code: string
|
||||
}
|
||||
|
||||
export const fetchOAuthAppInfo = (client_id: string, redirect_uri: string) => {
|
||||
return post<OAuthAppInfo>('/oauth/provider', { body: { client_id, redirect_uri } }, { silent: true })
|
||||
}
|
||||
|
||||
export const authorizeOAuthApp = (payload: { client_id: string }) => {
|
||||
return post<OAuthAuthorizeResponse>('/oauth/provider/authorize', { body: payload })
|
||||
}
|
||||
200
web/service/pipeline.ts
Normal file
200
web/service/pipeline.ts
Normal file
@@ -0,0 +1,200 @@
|
||||
import type { ToolCredential } from '@/app/components/tools/types'
|
||||
import type { DataSourceItem } from '@/app/components/workflow/block-selector/types'
|
||||
import type { CreateDatasetReq, CreateDatasetResponse, IconInfo } from '@/models/datasets'
|
||||
import type {
|
||||
ConversionResponse,
|
||||
DatasourceNodeSingleRunRequest,
|
||||
DatasourceNodeSingleRunResponse,
|
||||
DeleteTemplateResponse,
|
||||
ExportTemplateDSLResponse,
|
||||
ImportPipelineDSLConfirmResponse,
|
||||
ImportPipelineDSLRequest,
|
||||
ImportPipelineDSLResponse,
|
||||
OnlineDocumentPreviewRequest,
|
||||
OnlineDocumentPreviewResponse,
|
||||
PipelineCheckDependenciesResponse,
|
||||
PipelineExecutionLogRequest,
|
||||
PipelineExecutionLogResponse,
|
||||
PipelinePreProcessingParamsRequest,
|
||||
PipelinePreProcessingParamsResponse,
|
||||
PipelineProcessingParamsRequest,
|
||||
PipelineProcessingParamsResponse,
|
||||
PipelineTemplateByIdRequest,
|
||||
PipelineTemplateByIdResponse,
|
||||
PipelineTemplateListParams,
|
||||
PipelineTemplateListResponse,
|
||||
PublishedPipelineInfoResponse,
|
||||
PublishedPipelineRunPreviewResponse,
|
||||
PublishedPipelineRunRequest,
|
||||
PublishedPipelineRunResponse,
|
||||
UpdateTemplateInfoRequest,
|
||||
UpdateTemplateInfoResponse,
|
||||
} from '@/models/pipeline'
|
||||
import { DatasourceType } from '@/models/pipeline'
|
||||
import { del, get, patch, post } from './base'
|
||||
|
||||
export const fetchPipelineTemplateList = (params: PipelineTemplateListParams) => {
|
||||
return get<PipelineTemplateListResponse>('/rag/pipeline/templates', { params })
|
||||
}
|
||||
|
||||
export const fetchPipelineTemplateById = (params: PipelineTemplateByIdRequest) => {
|
||||
const { template_id, type } = params
|
||||
return get<PipelineTemplateByIdResponse>(`/rag/pipeline/templates/${template_id}`, {
|
||||
params: {
|
||||
type,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const updatePipelineTemplateInfo = (request: UpdateTemplateInfoRequest) => {
|
||||
const { template_id, ...rest } = request
|
||||
return patch<UpdateTemplateInfoResponse>(`/rag/pipeline/customized/templates/${template_id}`, {
|
||||
body: rest,
|
||||
})
|
||||
}
|
||||
|
||||
export const deletePipelineTemplate = (templateId: string) => {
|
||||
return del<DeleteTemplateResponse>(`/rag/pipeline/customized/templates/${templateId}`)
|
||||
}
|
||||
|
||||
export const exportPipelineTemplateDSL = (templateId: string) => {
|
||||
return post<ExportTemplateDSLResponse>(`/rag/pipeline/customized/templates/${templateId}`)
|
||||
}
|
||||
|
||||
export const importPipelineDSL = (request: ImportPipelineDSLRequest) => {
|
||||
return post<ImportPipelineDSLResponse>('/rag/pipelines/imports', { body: request })
|
||||
}
|
||||
|
||||
export const confirmImportPipelineDSL = (importId: string) => {
|
||||
return post<ImportPipelineDSLConfirmResponse>(`/rag/pipelines/imports/${importId}/confirm`)
|
||||
}
|
||||
|
||||
export const checkPipelineDependencies = (pipelineId: string) => {
|
||||
return get<PipelineCheckDependenciesResponse>(`/rag/pipelines/imports/${pipelineId}/check-dependencies`)
|
||||
}
|
||||
|
||||
export const fetchDraftPipelineProcessingParams = (params: PipelineProcessingParamsRequest) => {
|
||||
const { pipeline_id, node_id } = params
|
||||
return get<PipelineProcessingParamsResponse>(`/rag/pipelines/${pipeline_id}/workflows/draft/processing/parameters`, {
|
||||
params: {
|
||||
node_id,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchPublishedPipelineProcessingParams = (params: PipelineProcessingParamsRequest) => {
|
||||
const { pipeline_id, node_id } = params
|
||||
return get<PipelineProcessingParamsResponse>(`/rag/pipelines/${pipeline_id}/workflows/published/processing/parameters`, {
|
||||
params: {
|
||||
node_id,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchPipelineDataSourceList = () => {
|
||||
return get<DataSourceItem[]>('/rag/pipelines/datasource-plugins')
|
||||
}
|
||||
|
||||
export const fetchPublishedPipelineInfo = (pipelineId: string) => {
|
||||
return get<PublishedPipelineInfoResponse>(`/rag/pipelines/${pipelineId}/workflows/publish`)
|
||||
}
|
||||
|
||||
export const runPublishedPipeline = (request: PublishedPipelineRunRequest) => {
|
||||
const { pipeline_id: pipelineId, is_preview, ...rest } = request
|
||||
return post<PublishedPipelineRunPreviewResponse | PublishedPipelineRunResponse>(`/rag/pipelines/${pipelineId}/workflows/published/run`, {
|
||||
body: {
|
||||
...rest,
|
||||
is_preview,
|
||||
response_mode: 'blocking',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchDataSourceCredentials = (provider: string, pluginId: string) => {
|
||||
return get<{ result: ToolCredential[] }>(`/auth/plugin/datasource?provider=${provider}&plugin_id=${pluginId}`)
|
||||
}
|
||||
|
||||
export const updateDataSourceCredentials = (payload: { provider: string, pluginId: string, credentials: Record<string, any>, name: string }) => {
|
||||
const { provider, pluginId, credentials, name } = payload
|
||||
return post('/auth/plugin/datasource', {
|
||||
body: {
|
||||
provider,
|
||||
plugin_id: pluginId,
|
||||
credentials,
|
||||
name,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchDraftPipelinePreProcessingParams = (params: PipelinePreProcessingParamsRequest) => {
|
||||
const { pipeline_id, node_id } = params
|
||||
return get<PipelinePreProcessingParamsResponse>(`/rag/pipelines/${pipeline_id}/workflows/draft/pre-processing/parameters`, {
|
||||
params: {
|
||||
node_id,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchPublishedPipelinePreProcessingParams = (params: PipelinePreProcessingParamsRequest) => {
|
||||
const { pipeline_id, node_id } = params
|
||||
return get<PipelinePreProcessingParamsResponse>(`/rag/pipelines/${pipeline_id}/workflows/published/pre-processing/parameters`, {
|
||||
params: {
|
||||
node_id,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const exportPipelineDSL = (pipelineId: string, include = false) => {
|
||||
return get<ExportTemplateDSLResponse>(`/rag/pipelines/${pipelineId}/exports?include_secret=${include}`)
|
||||
}
|
||||
|
||||
export const publishAsCustomizedPipeline = (payload: { pipelineId: string, name: string, icon_info: IconInfo, description?: string }) => {
|
||||
const { pipelineId, ...rest } = payload
|
||||
return post(`/rag/pipelines/${pipelineId}/customized/publish`, {
|
||||
body: {
|
||||
...rest,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchPipelineExecutionLog = (params: PipelineExecutionLogRequest) => {
|
||||
const { dataset_id, document_id } = params
|
||||
return get<PipelineExecutionLogResponse>(`/datasets/${dataset_id}/documents/${document_id}/pipeline-execution-log`)
|
||||
}
|
||||
|
||||
export const previewOnlineDocument = (params: OnlineDocumentPreviewRequest) => {
|
||||
const { pipelineId, datasourceNodeId, workspaceID, pageID, pageType, credentialId } = params
|
||||
return post<OnlineDocumentPreviewResponse>(
|
||||
`/rag/pipelines/${pipelineId}/workflows/published/datasource/nodes/${datasourceNodeId}/preview`,
|
||||
{
|
||||
body: {
|
||||
datasource_type: DatasourceType.onlineDocument,
|
||||
credential_id: credentialId,
|
||||
inputs: {
|
||||
workspace_id: workspaceID,
|
||||
page_id: pageID,
|
||||
type: pageType,
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
export const convertDatasetToPipeline = (datasetId: string) => {
|
||||
return post<ConversionResponse>(`/rag/pipelines/transform/datasets/${datasetId}`)
|
||||
}
|
||||
|
||||
export const runDatasourceNodeSingle = (params: DatasourceNodeSingleRunRequest) => {
|
||||
const { pipeline_id: pipelineId, ...rest } = params
|
||||
return post<DatasourceNodeSingleRunResponse>(`/rag/pipelines/${pipelineId}/workflows/draft/datasource/variables-inspect`, {
|
||||
body: rest,
|
||||
})
|
||||
}
|
||||
|
||||
export const createEmptyDatasetForPipeline = () => {
|
||||
return post<CreateDatasetResponse>('/rag/pipeline/empty-dataset')
|
||||
}
|
||||
|
||||
export const createDatasetForPipeline = (request: CreateDatasetReq) => {
|
||||
return post<CreateDatasetResponse>('/rag/pipeline/dataset', { body: request })
|
||||
}
|
||||
62
web/service/plugins-auth.ts
Normal file
62
web/service/plugins-auth.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import type { FormSchema } from '@/app/components/base/form/types'
|
||||
import type { Credential, CredentialTypeEnum } from '@/app/components/plugins/plugin-auth/types'
|
||||
import { del, get, post } from './base'
|
||||
|
||||
export const fetchPluginCredentialInfo = (url: string) => {
|
||||
return get<{
|
||||
allow_custom_token?: boolean
|
||||
supported_credential_types: string[]
|
||||
credentials: Credential[]
|
||||
is_oauth_custom_client_enabled: boolean
|
||||
}>(url)
|
||||
}
|
||||
|
||||
export const setPluginDefaultCredential = (url: string, id: string) => {
|
||||
return post(url, { body: { id } })
|
||||
}
|
||||
|
||||
export const fetchPluginCredentialList = (url: string) => {
|
||||
return get(url)
|
||||
}
|
||||
|
||||
export const addPluginCredential = (url: string, params: { credentials: Record<string, any>, type: CredentialTypeEnum, name?: string }) => {
|
||||
return post(url, { body: params })
|
||||
}
|
||||
|
||||
export const updatePluginCredential = (url: string, params: { credential_id: string, credentials?: Record<string, any>, name?: string }) => {
|
||||
return post(url, { body: params })
|
||||
}
|
||||
|
||||
export const deletePluginCredential = (url: string, params: { credential_id: string }) => {
|
||||
return post(url, { body: params })
|
||||
}
|
||||
|
||||
export const fetchPluginCredentialSchema = (url: string) => {
|
||||
return get<FormSchema[]>(url)
|
||||
}
|
||||
|
||||
export const fetchPluginOAuthUrl = (url: string) => {
|
||||
return get<{
|
||||
authorization_url: string
|
||||
state: string
|
||||
context_id: string
|
||||
}>(url)
|
||||
}
|
||||
|
||||
export const fetchPluginOAuthClientSchema = (url: string) => {
|
||||
return get<{
|
||||
schema: FormSchema[]
|
||||
is_oauth_custom_client_enabled: boolean
|
||||
is_system_oauth_params_exists?: boolean
|
||||
client_params?: Record<string, any>
|
||||
redirect_uri?: string
|
||||
}>(url)
|
||||
}
|
||||
|
||||
export const setPluginOAuthCustomClient = (url: string, params: { client_params: Record<string, any>, enable_oauth_custom_client: boolean }) => {
|
||||
return post<{ result: string }>(url, { body: params })
|
||||
}
|
||||
|
||||
export const deletePluginOAuthCustomClient = (url: string) => {
|
||||
return del<{ result: string }>(url)
|
||||
}
|
||||
@@ -1,21 +1,33 @@
|
||||
import type { FormOption } from '@/app/components/base/form/types'
|
||||
import type {
|
||||
MarketplaceCollectionPluginsResponse,
|
||||
MarketplaceCollectionsResponse,
|
||||
PluginsSearchParams,
|
||||
} from '@/app/components/plugins/marketplace/types'
|
||||
import type {
|
||||
DebugInfo,
|
||||
Dependency,
|
||||
InstalledLatestVersionResponse,
|
||||
InstalledPluginListWithTotalResponse,
|
||||
InstallPackageResponse,
|
||||
Permissions,
|
||||
Plugin,
|
||||
PluginDeclaration,
|
||||
PluginDetail,
|
||||
PluginInfoFromMarketPlace,
|
||||
PluginManifestInMarket,
|
||||
PluginsFromMarketplaceByInfoResponse,
|
||||
PluginsFromMarketplaceResponse,
|
||||
PluginTask,
|
||||
PluginTasksResponse,
|
||||
ReferenceSetting,
|
||||
TaskStatusResponse,
|
||||
UninstallPluginResponse,
|
||||
updatePackageResponse,
|
||||
uploadGitHubResponse,
|
||||
VersionListResponse,
|
||||
} from '@/app/components/plugins/types'
|
||||
import { get, getMarketplace, post, upload } from './base'
|
||||
import { get, getMarketplace, post, postMarketplace, upload } from './base'
|
||||
|
||||
export const uploadFile = async (file: File, isBundle: boolean) => {
|
||||
const formData = new FormData()
|
||||
@@ -104,3 +116,188 @@ export const updatePermission = async (permissions: Permissions) => {
|
||||
export const uninstallPlugin = async (pluginId: string) => {
|
||||
return post<UninstallPluginResponse>('/workspaces/current/plugin/uninstall', { body: { plugin_installation_id: pluginId } })
|
||||
}
|
||||
|
||||
export const checkInstalledPlugins = (pluginIds: string[]) => {
|
||||
return post<{ plugins: PluginDetail[] }>('/workspaces/current/plugin/list/installations/ids', {
|
||||
body: {
|
||||
plugin_ids: pluginIds,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchRecommendedMarketplacePlugins = (collection: string, limit: number) => {
|
||||
return postMarketplace<{ data: { plugins: Plugin[] } }>(`/collections/${collection}/plugins`, {
|
||||
body: {
|
||||
limit,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchInstalledPluginList = (page: number, pageSize: number) => {
|
||||
return get<InstalledPluginListWithTotalResponse>(`/workspaces/current/plugin/list?page=${page}&page_size=${pageSize}`)
|
||||
}
|
||||
|
||||
export const fetchInstalledLatestVersion = (pluginIds: string[]) => {
|
||||
return post<InstalledLatestVersionResponse>('/workspaces/current/plugin/list/latest-versions', {
|
||||
body: {
|
||||
plugin_ids: pluginIds,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const installPackageFromMarketplace = (uniqueIdentifier: string) => {
|
||||
return post<InstallPackageResponse>('/workspaces/current/plugin/install/marketplace', {
|
||||
body: { plugin_unique_identifiers: [uniqueIdentifier] },
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchPluginDeclarationFromMarketplace = (pluginUniqueIdentifier: string) => {
|
||||
return get<{ manifest: PluginDeclaration }>('/workspaces/current/plugin/marketplace/pkg', {
|
||||
params: { plugin_unique_identifier: pluginUniqueIdentifier },
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchPluginVersionList = (pluginID: string) => {
|
||||
return getMarketplace<{ data: VersionListResponse }>(`/plugins/${pluginID}/versions`, { params: { page: 1, page_size: 100 } })
|
||||
}
|
||||
|
||||
export const installPackageFromLocal = (uniqueIdentifier: string) => {
|
||||
return post<InstallPackageResponse>('/workspaces/current/plugin/install/pkg', {
|
||||
body: { plugin_unique_identifiers: [uniqueIdentifier] },
|
||||
})
|
||||
}
|
||||
|
||||
export const installPackageFromGitHub = (payload: { repoUrl: string, selectedVersion: string, selectedPackage: string, uniqueIdentifier: string }) => {
|
||||
const { repoUrl, selectedVersion, selectedPackage, uniqueIdentifier } = payload
|
||||
return post<InstallPackageResponse>('/workspaces/current/plugin/install/github', {
|
||||
body: {
|
||||
repo: repoUrl,
|
||||
version: selectedVersion,
|
||||
package: selectedPackage,
|
||||
plugin_unique_identifier: uniqueIdentifier,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const uploadGitHubPackage = (payload: { repo: string, version: string, package: string }) => {
|
||||
return post<uploadGitHubResponse>('/workspaces/current/plugin/upload/github', {
|
||||
body: payload,
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchDebugKey = () => {
|
||||
return get<DebugInfo>('/workspaces/current/plugin/debugging-key')
|
||||
}
|
||||
|
||||
export const fetchReferenceSettings = () => {
|
||||
return get<ReferenceSetting>('/workspaces/current/plugin/preferences/fetch')
|
||||
}
|
||||
|
||||
export const updateReferenceSettings = (payload: ReferenceSetting) => {
|
||||
return post('/workspaces/current/plugin/preferences/change', { body: payload })
|
||||
}
|
||||
|
||||
export const excludeAutoUpgrade = (payload: { plugin_id: string }) => {
|
||||
return post('/workspaces/current/plugin/preferences/autoupgrade/exclude', { body: payload })
|
||||
}
|
||||
|
||||
export const searchMarketplacePlugins = (params: PluginsSearchParams) => {
|
||||
const {
|
||||
query,
|
||||
sortBy,
|
||||
sortOrder,
|
||||
category,
|
||||
tags,
|
||||
exclude,
|
||||
type,
|
||||
page = 1,
|
||||
pageSize = 40,
|
||||
} = params
|
||||
const pluginOrBundle = type === 'bundle' ? 'bundles' : 'plugins'
|
||||
return postMarketplace<{ data: PluginsFromMarketplaceResponse }>(`/${pluginOrBundle}/search/advanced`, {
|
||||
body: {
|
||||
page,
|
||||
page_size: pageSize,
|
||||
query,
|
||||
sort_by: sortBy,
|
||||
sort_order: sortOrder,
|
||||
category: category !== 'all' ? category : '',
|
||||
tags,
|
||||
exclude,
|
||||
type,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchMarketplacePluginsByIds = (unique_identifiers: string[]) => {
|
||||
return postMarketplace<{ data: PluginsFromMarketplaceResponse }>('/plugins/identifier/batch', {
|
||||
body: {
|
||||
unique_identifiers,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchMarketplacePluginsByInfo = (infos: Record<string, any>[]) => {
|
||||
return postMarketplace<{ data: PluginsFromMarketplaceByInfoResponse }>('/plugins/versions/batch', {
|
||||
body: {
|
||||
plugin_tuples: infos.map(info => ({
|
||||
org: info.organization,
|
||||
name: info.plugin,
|
||||
version: info.version,
|
||||
})),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchPluginTaskList = () => {
|
||||
return get<{ tasks: PluginTask[] }>('/workspaces/current/plugin/tasks?page=1&page_size=100')
|
||||
}
|
||||
|
||||
export const deletePluginTask = (taskId: string, pluginId: string) => {
|
||||
const encodedPluginId = encodeURIComponent(pluginId)
|
||||
return post<{ success: boolean }>(`/workspaces/current/plugin/tasks/${taskId}/delete/${encodedPluginId}`)
|
||||
}
|
||||
|
||||
export const deleteAllPluginTasks = () => {
|
||||
return post<{ success: boolean }>('/workspaces/current/plugin/tasks/delete_all')
|
||||
}
|
||||
|
||||
export const fetchPluginManifestInfo = (pluginUID: string) => {
|
||||
return getMarketplace<{ data: { plugin: PluginInfoFromMarketPlace, version: { version: string } } }>(`/plugins/${pluginUID}`)
|
||||
}
|
||||
|
||||
export const downloadPlugin = (info: { organization: string, pluginName: string, version: string }) => {
|
||||
return getMarketplace<Blob>(`/plugins/${info.organization}/${info.pluginName}/${info.version}/download`)
|
||||
}
|
||||
|
||||
export const checkImportDependencies = (appId: string) => {
|
||||
return get<{ leaked_dependencies: Dependency[] }>(`/apps/imports/${appId}/check-dependencies`)
|
||||
}
|
||||
|
||||
export const fetchPluginDynamicOptions = (params: {
|
||||
plugin_id: string
|
||||
provider: string
|
||||
action: string
|
||||
parameter: string
|
||||
provider_type?: string
|
||||
extra?: Record<string, any>
|
||||
}) => {
|
||||
return get<{ options: FormOption[] }>('/workspaces/current/plugin/parameters/dynamic-options', {
|
||||
params: {
|
||||
plugin_id: params.plugin_id,
|
||||
provider: params.provider,
|
||||
action: params.action,
|
||||
parameter: params.parameter,
|
||||
provider_type: params.provider_type,
|
||||
...params.extra,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchPluginReadme = (params: { plugin_unique_identifier: string, language?: string }) => {
|
||||
return get<{ readme: string }>('/workspaces/current/plugin/readme', { params }, { silent: true })
|
||||
}
|
||||
|
||||
export const fetchPluginAsset = (params: { plugin_unique_identifier: string, file_name: string }) => {
|
||||
return get<Blob>('/workspaces/current/plugin/asset', { params }, { silent: true })
|
||||
}
|
||||
|
||||
@@ -2,13 +2,16 @@ import type {
|
||||
Collection,
|
||||
CustomCollectionBackend,
|
||||
CustomParamSchema,
|
||||
MCPServerDetail,
|
||||
Tool,
|
||||
ToolCredential,
|
||||
WorkflowToolProviderRequest,
|
||||
WorkflowToolProviderResponse,
|
||||
} from '@/app/components/tools/types'
|
||||
import type { RAGRecommendedPlugins, ToolWithProvider } from '@/app/components/workflow/types'
|
||||
import type { AppIconType } from '@/types/app'
|
||||
import { buildProviderQuery } from './_tools_util'
|
||||
import { get, post } from './base'
|
||||
import { del, get, post, put } from './base'
|
||||
|
||||
export const fetchCollectionList = () => {
|
||||
return get<Collection[]>('/workspaces/current/tool-providers')
|
||||
@@ -140,3 +143,181 @@ export const deleteWorkflowTool = (toolID: string) => {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchAllBuiltInTools = () => {
|
||||
return get<ToolWithProvider[]>('/workspaces/current/tools/builtin')
|
||||
}
|
||||
|
||||
export const fetchAllCustomTools = () => {
|
||||
return get<ToolWithProvider[]>('/workspaces/current/tools/api')
|
||||
}
|
||||
|
||||
export const fetchAllWorkflowTools = () => {
|
||||
return get<ToolWithProvider[]>('/workspaces/current/tools/workflow')
|
||||
}
|
||||
|
||||
export const fetchAllMCPTools = () => {
|
||||
return get<ToolWithProvider[]>('/workspaces/current/tools/mcp')
|
||||
}
|
||||
|
||||
export const createMCPProvider = (payload: {
|
||||
name: string
|
||||
server_url: string
|
||||
icon_type: AppIconType
|
||||
icon: string
|
||||
icon_background?: string | null
|
||||
timeout?: number
|
||||
sse_read_timeout?: number
|
||||
headers?: Record<string, string>
|
||||
}) => {
|
||||
return post<ToolWithProvider>('workspaces/current/tool-provider/mcp', {
|
||||
body: {
|
||||
...payload,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const updateMCPProvider = (payload: {
|
||||
name: string
|
||||
server_url: string
|
||||
icon_type: AppIconType
|
||||
icon: string
|
||||
icon_background?: string | null
|
||||
provider_id: string
|
||||
timeout?: number
|
||||
sse_read_timeout?: number
|
||||
headers?: Record<string, string>
|
||||
}) => {
|
||||
return put('workspaces/current/tool-provider/mcp', {
|
||||
body: {
|
||||
...payload,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteMCPProvider = (id: string) => {
|
||||
return del('/workspaces/current/tool-provider/mcp', {
|
||||
body: {
|
||||
provider_id: id,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const authorizeMCPProvider = (payload: { provider_id: string }) => {
|
||||
return post<{ result?: string, authorization_url?: string }>('/workspaces/current/tool-provider/mcp/auth', {
|
||||
body: payload,
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchMCPProviderToken = (payload: { provider_id: string, authorization_code: string }) => {
|
||||
return get<MCPServerDetail>('/workspaces/current/tool-provider/mcp/token', {
|
||||
params: {
|
||||
...payload,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchMCPProviderTools = (providerID: string) => {
|
||||
return get<{ tools: Tool[] }>(`/workspaces/current/tool-provider/mcp/tools/${providerID}`)
|
||||
}
|
||||
|
||||
export const updateMCPProviderTools = (providerID: string) => {
|
||||
return get<{ tools: Tool[] }>(`/workspaces/current/tool-provider/mcp/update/${providerID}`)
|
||||
}
|
||||
|
||||
export const fetchMCPServerDetail = (appID: string) => {
|
||||
return get<MCPServerDetail>(`/apps/${appID}/server`)
|
||||
}
|
||||
|
||||
export const createMCPServer = (payload: {
|
||||
appID: string
|
||||
description?: string
|
||||
parameters?: Record<string, string>
|
||||
}) => {
|
||||
const { appID, ...rest } = payload
|
||||
return post(`apps/${appID}/server`, {
|
||||
body: {
|
||||
...rest,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const updateMCPServer = (payload: {
|
||||
appID: string
|
||||
id: string
|
||||
description?: string
|
||||
status?: string
|
||||
parameters?: Record<string, string>
|
||||
}) => {
|
||||
const { appID, ...rest } = payload
|
||||
return put(`apps/${appID}/server`, {
|
||||
body: {
|
||||
...rest,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const refreshMCPServerCode = (appID: string) => {
|
||||
return get<MCPServerDetail>(`apps/${appID}/server/refresh`)
|
||||
}
|
||||
|
||||
export const fetchBuiltinProviderInfo = (providerName: string) => {
|
||||
return get<Collection>(`/workspaces/current/tool-provider/builtin/${providerName}/info`)
|
||||
}
|
||||
|
||||
export const fetchBuiltinProviderTools = (providerName: string) => {
|
||||
return get<Tool[]>(`/workspaces/current/tool-provider/builtin/${providerName}/tools`)
|
||||
}
|
||||
|
||||
export const updateBuiltinProviderCredentials = (payload: { providerName: string, credentials: Record<string, any> }) => {
|
||||
const { providerName, credentials } = payload
|
||||
return post(`/workspaces/current/tool-provider/builtin/${providerName}/update`, {
|
||||
body: {
|
||||
credentials,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const removeBuiltinProviderCredentials = (providerName: string) => {
|
||||
return post(`/workspaces/current/tool-provider/builtin/${providerName}/delete`, {
|
||||
body: {},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchRAGRecommendedPlugins = (type: 'tool' | 'datasource' | 'all') => {
|
||||
return get<RAGRecommendedPlugins>('/rag/pipelines/recommended-plugins', {
|
||||
params: {
|
||||
type,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export type AppTrigger = {
|
||||
id: string
|
||||
trigger_type: 'trigger-webhook' | 'trigger-schedule' | 'trigger-plugin'
|
||||
title: string
|
||||
node_id: string
|
||||
provider_name: string
|
||||
icon: string
|
||||
status: 'enabled' | 'disabled' | 'unauthorized'
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export const fetchAppTriggers = (appId: string) => {
|
||||
return get<{ data: AppTrigger[] }>(`/apps/${appId}/triggers`)
|
||||
}
|
||||
|
||||
export const updateAppTriggerStatus = (payload: {
|
||||
appId: string
|
||||
triggerId: string
|
||||
enableTrigger: boolean
|
||||
}) => {
|
||||
const { appId, triggerId, enableTrigger } = payload
|
||||
return post<AppTrigger>(`/apps/${appId}/trigger-enable`, {
|
||||
body: {
|
||||
trigger_id: triggerId,
|
||||
enable_trigger: enableTrigger,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
187
web/service/triggers.ts
Normal file
187
web/service/triggers.ts
Normal file
@@ -0,0 +1,187 @@
|
||||
import type { FormOption } from '@/app/components/base/form/types'
|
||||
import type {
|
||||
TriggerLogEntity,
|
||||
TriggerOAuthClientParams,
|
||||
TriggerOAuthConfig,
|
||||
TriggerProviderApiEntity,
|
||||
TriggerSubscription,
|
||||
TriggerSubscriptionBuilder,
|
||||
} from '@/app/components/workflow/block-selector/types'
|
||||
import { del, get, post } from './base'
|
||||
|
||||
export const fetchTriggerProviders = () => {
|
||||
return get<TriggerProviderApiEntity[]>('/workspaces/current/triggers')
|
||||
}
|
||||
|
||||
export const fetchTriggerProvidersByType = (triggerType: string) => {
|
||||
return get<TriggerProviderApiEntity[]>(`/workspaces/current/triggers?type=${triggerType}`)
|
||||
}
|
||||
|
||||
export const fetchTriggerProviderInfo = (provider: string) => {
|
||||
return get<TriggerProviderApiEntity>(`/workspaces/current/trigger-provider/${provider}/info`)
|
||||
}
|
||||
|
||||
export const fetchTriggerSubscriptions = (provider: string) => {
|
||||
return get<TriggerSubscription[]>(`/workspaces/current/trigger-provider/${provider}/subscriptions/list`)
|
||||
}
|
||||
|
||||
export const createTriggerSubscriptionBuilder = (payload: { provider: string, credential_type?: string }) => {
|
||||
const { provider, ...body } = payload
|
||||
return post<{ subscription_builder: TriggerSubscriptionBuilder }>(
|
||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/builder/create`,
|
||||
{ body },
|
||||
)
|
||||
}
|
||||
|
||||
export const updateTriggerSubscriptionBuilder = (payload: {
|
||||
provider: string
|
||||
subscriptionBuilderId: string
|
||||
name?: string
|
||||
properties?: Record<string, unknown>
|
||||
parameters?: Record<string, unknown>
|
||||
credentials?: Record<string, unknown>
|
||||
}) => {
|
||||
const { provider, subscriptionBuilderId, ...body } = payload
|
||||
return post<TriggerSubscriptionBuilder>(
|
||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/builder/update/${subscriptionBuilderId}`,
|
||||
{ body },
|
||||
)
|
||||
}
|
||||
|
||||
export const verifyAndUpdateTriggerSubscriptionBuilder = (payload: {
|
||||
provider: string
|
||||
subscriptionBuilderId: string
|
||||
credentials?: Record<string, unknown>
|
||||
}) => {
|
||||
const { provider, subscriptionBuilderId, ...body } = payload
|
||||
return post<{ verified: boolean }>(
|
||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/builder/verify-and-update/${subscriptionBuilderId}`,
|
||||
{ body },
|
||||
{ silent: true },
|
||||
)
|
||||
}
|
||||
|
||||
export const verifyTriggerSubscription = (payload: {
|
||||
provider: string
|
||||
subscriptionId: string
|
||||
credentials?: Record<string, unknown>
|
||||
}) => {
|
||||
const { provider, subscriptionId, ...body } = payload
|
||||
return post<{ verified: boolean }>(
|
||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/verify/${subscriptionId}`,
|
||||
{ body },
|
||||
{ silent: true },
|
||||
)
|
||||
}
|
||||
|
||||
export const buildTriggerSubscription = (payload: {
|
||||
provider: string
|
||||
subscriptionBuilderId: string
|
||||
name?: string
|
||||
parameters?: Record<string, unknown>
|
||||
}) => {
|
||||
const { provider, subscriptionBuilderId, ...body } = payload
|
||||
return post(
|
||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/builder/build/${subscriptionBuilderId}`,
|
||||
{ body },
|
||||
)
|
||||
}
|
||||
|
||||
export const deleteTriggerSubscription = (subscriptionId: string) => {
|
||||
return post<{ result: string }>(
|
||||
`/workspaces/current/trigger-provider/${subscriptionId}/subscriptions/delete`,
|
||||
)
|
||||
}
|
||||
|
||||
export const updateTriggerSubscription = (payload: {
|
||||
subscriptionId: string
|
||||
name?: string
|
||||
properties?: Record<string, unknown>
|
||||
parameters?: Record<string, unknown>
|
||||
credentials?: Record<string, unknown>
|
||||
}) => {
|
||||
const { subscriptionId, ...body } = payload
|
||||
return post<{ result: string, id: string }>(
|
||||
`/workspaces/current/trigger-provider/${subscriptionId}/subscriptions/update`,
|
||||
{ body },
|
||||
)
|
||||
}
|
||||
|
||||
export const fetchTriggerSubscriptionBuilderLogs = (provider: string, subscriptionBuilderId: string) => {
|
||||
return get<{ logs: TriggerLogEntity[] }>(
|
||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/builder/logs/${subscriptionBuilderId}`,
|
||||
)
|
||||
}
|
||||
|
||||
export const fetchTriggerOAuthConfig = (provider: string) => {
|
||||
return get<TriggerOAuthConfig>(`/workspaces/current/trigger-provider/${provider}/oauth/client`)
|
||||
}
|
||||
|
||||
export const configureTriggerOAuth = (payload: { provider: string, client_params?: TriggerOAuthClientParams, enabled: boolean }) => {
|
||||
const { provider, ...body } = payload
|
||||
return post<{ result: string }>(
|
||||
`/workspaces/current/trigger-provider/${provider}/oauth/client`,
|
||||
{ body },
|
||||
)
|
||||
}
|
||||
|
||||
export const deleteTriggerOAuth = (provider: string) => {
|
||||
return del<{ result: string }>(`/workspaces/current/trigger-provider/${provider}/oauth/client`)
|
||||
}
|
||||
|
||||
export const initiateTriggerOAuth = (provider: string) => {
|
||||
return get<{ authorization_url: string, subscription_builder: TriggerSubscriptionBuilder }>(
|
||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/oauth/authorize`,
|
||||
{},
|
||||
{ silent: true },
|
||||
)
|
||||
}
|
||||
|
||||
export const fetchTriggerDynamicOptions = (payload: {
|
||||
plugin_id: string
|
||||
provider: string
|
||||
action: string
|
||||
parameter: string
|
||||
credential_id: string
|
||||
extra?: Record<string, unknown>
|
||||
}) => {
|
||||
return get<{ options: FormOption[] }>(
|
||||
'/workspaces/current/plugin/parameters/dynamic-options',
|
||||
{
|
||||
params: {
|
||||
plugin_id: payload.plugin_id,
|
||||
provider: payload.provider,
|
||||
action: payload.action,
|
||||
parameter: payload.parameter,
|
||||
credential_id: payload.credential_id,
|
||||
provider_type: 'trigger',
|
||||
...payload.extra,
|
||||
},
|
||||
},
|
||||
{ silent: true },
|
||||
)
|
||||
}
|
||||
|
||||
export const fetchTriggerDynamicOptionsWithCredentials = (payload: {
|
||||
plugin_id: string
|
||||
provider: string
|
||||
action: string
|
||||
parameter: string
|
||||
credential_id: string
|
||||
credentials: Record<string, unknown>
|
||||
}) => {
|
||||
return post<{ options: FormOption[] }>(
|
||||
'/workspaces/current/plugin/parameters/dynamic-options-with-credentials',
|
||||
{
|
||||
body: {
|
||||
plugin_id: payload.plugin_id,
|
||||
provider: payload.provider,
|
||||
action: payload.action,
|
||||
parameter: payload.parameter,
|
||||
credential_id: payload.credential_id,
|
||||
credentials: payload.credentials,
|
||||
},
|
||||
},
|
||||
{ silent: true },
|
||||
)
|
||||
}
|
||||
@@ -16,7 +16,15 @@ import {
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
} from '@tanstack/react-query'
|
||||
import { get, post } from './base'
|
||||
import {
|
||||
fetchAppApiKeys,
|
||||
fetchAppDetailById,
|
||||
fetchAppList,
|
||||
fetchAppStatistics,
|
||||
fetchAppVoices,
|
||||
fetchWorkflowStatistics,
|
||||
generateRuleTemplate,
|
||||
} from './apps'
|
||||
import { useInvalid } from './use-base'
|
||||
|
||||
const NAME_SPACE = 'apps'
|
||||
@@ -62,11 +70,7 @@ const useAppFullListKey = [NAME_SPACE, 'full-list']
|
||||
export const useGenerateRuleTemplate = (type: GeneratorType, disabled?: boolean) => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'generate-rule-template', type],
|
||||
queryFn: () => post<{ data: string }>('instruction-generate/template', {
|
||||
body: {
|
||||
type,
|
||||
},
|
||||
}),
|
||||
queryFn: () => generateRuleTemplate(type),
|
||||
enabled: !disabled,
|
||||
retry: 0,
|
||||
})
|
||||
@@ -75,7 +79,7 @@ export const useGenerateRuleTemplate = (type: GeneratorType, disabled?: boolean)
|
||||
export const useAppDetail = (appID: string) => {
|
||||
return useQuery<App>({
|
||||
queryKey: [NAME_SPACE, 'detail', appID],
|
||||
queryFn: () => get<App>(`/apps/${appID}`),
|
||||
queryFn: () => fetchAppDetailById(appID),
|
||||
enabled: !!appID,
|
||||
})
|
||||
}
|
||||
@@ -84,7 +88,7 @@ export const useAppList = (params: AppListParams, options?: { enabled?: boolean
|
||||
const normalizedParams = normalizeAppListParams(params)
|
||||
return useQuery<AppListResponse>({
|
||||
queryKey: appListKey(normalizedParams),
|
||||
queryFn: () => get<AppListResponse>('/apps', { params: normalizedParams }),
|
||||
queryFn: () => fetchAppList({ url: '/apps', params: normalizedParams }),
|
||||
...options,
|
||||
})
|
||||
}
|
||||
@@ -92,7 +96,7 @@ export const useAppList = (params: AppListParams, options?: { enabled?: boolean
|
||||
export const useAppFullList = () => {
|
||||
return useQuery<AppListResponse>({
|
||||
queryKey: useAppFullListKey,
|
||||
queryFn: () => get<AppListResponse>('/apps', { params: { page: 1, limit: 100, name: '' } }),
|
||||
queryFn: () => fetchAppList({ url: '/apps', params: { page: 1, limit: 100, name: '' } }),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -104,7 +108,7 @@ export const useInfiniteAppList = (params: AppListParams, options?: { enabled?:
|
||||
const normalizedParams = normalizeAppListParams(params)
|
||||
return useInfiniteQuery<AppListResponse>({
|
||||
queryKey: appListKey(normalizedParams),
|
||||
queryFn: ({ pageParam = normalizedParams.page }) => get<AppListResponse>('/apps', { params: { ...normalizedParams, page: pageParam } }),
|
||||
queryFn: ({ pageParam = normalizedParams.page }) => fetchAppList({ url: '/apps', params: { ...normalizedParams, page: pageParam } }),
|
||||
getNextPageParam: lastPage => lastPage.has_more ? lastPage.page + 1 : undefined,
|
||||
initialPageParam: normalizedParams.page,
|
||||
...options,
|
||||
@@ -123,7 +127,7 @@ export const useInvalidateAppList = () => {
|
||||
const useAppStatisticsQuery = <T>(metric: string, appId: string, params?: DateRangeParams) => {
|
||||
return useQuery<T>({
|
||||
queryKey: [NAME_SPACE, 'statistics', metric, appId, params],
|
||||
queryFn: () => get<T>(`/apps/${appId}/statistics/${metric}`, { params }),
|
||||
queryFn: () => fetchAppStatistics<T>(appId, metric, params),
|
||||
enabled: !!appId,
|
||||
})
|
||||
}
|
||||
@@ -131,7 +135,7 @@ const useAppStatisticsQuery = <T>(metric: string, appId: string, params?: DateRa
|
||||
const useWorkflowStatisticsQuery = <T>(metric: string, appId: string, params?: DateRangeParams) => {
|
||||
return useQuery<T>({
|
||||
queryKey: [NAME_SPACE, 'workflow-statistics', metric, appId, params],
|
||||
queryFn: () => get<T>(`/apps/${appId}/workflow/statistics/${metric}`, { params }),
|
||||
queryFn: () => fetchWorkflowStatistics<T>(appId, metric, params),
|
||||
enabled: !!appId,
|
||||
})
|
||||
}
|
||||
@@ -187,7 +191,7 @@ export const useWorkflowAverageInteractions = (appId: string, params?: DateRange
|
||||
export const useAppVoices = (appId?: string, language?: string) => {
|
||||
return useQuery<AppVoicesListResponse>({
|
||||
queryKey: [NAME_SPACE, 'voices', appId, language || 'en-US'],
|
||||
queryFn: () => get<AppVoicesListResponse>(`/apps/${appId}/text-to-audio/voices`, { params: { language: language || 'en-US' } }),
|
||||
queryFn: () => fetchAppVoices({ appId: appId || '', language }),
|
||||
enabled: !!appId,
|
||||
})
|
||||
}
|
||||
@@ -195,7 +199,7 @@ export const useAppVoices = (appId?: string, language?: string) => {
|
||||
export const useAppApiKeys = (appId?: string, options?: { enabled?: boolean }) => {
|
||||
return useQuery<ApiKeysListResponse>({
|
||||
queryKey: [NAME_SPACE, 'api-keys', appId],
|
||||
queryFn: () => get<ApiKeysListResponse>(`/apps/${appId}/api-keys`),
|
||||
queryFn: () => fetchAppApiKeys(appId || ''),
|
||||
enabled: !!appId && (options?.enabled ?? true),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -18,13 +18,43 @@ import type {
|
||||
Member,
|
||||
PluginProvider,
|
||||
StructuredOutputRulesRequestBody,
|
||||
StructuredOutputRulesResponse,
|
||||
UserProfileResponse,
|
||||
} from '@/models/common'
|
||||
import type { RETRIEVE_METHOD } from '@/types/app'
|
||||
import { useMutation, useQuery } from '@tanstack/react-query'
|
||||
import { IS_DEV } from '@/config'
|
||||
import { get, post } from './base'
|
||||
import {
|
||||
fetchAccountIntegratesList,
|
||||
fetchAccountProfile,
|
||||
fetchApiBasedExtensions,
|
||||
fetchCodeBasedExtension,
|
||||
fetchCurrentWorkspaceInfo,
|
||||
fetchDataSourceIntegrates,
|
||||
fetchDefaultModelByType,
|
||||
fetchFilePreview,
|
||||
fetchFileSupportTypes,
|
||||
fetchFileUploadConfig,
|
||||
fetchInvitationCheck,
|
||||
fetchLangGeniusVersionInfo,
|
||||
fetchModelListByType,
|
||||
fetchModelParameterRules,
|
||||
fetchModelProviders,
|
||||
fetchNotionBinding,
|
||||
fetchNotionConnection,
|
||||
fetchPluginProvidersList,
|
||||
fetchSchemaDefinitions,
|
||||
fetchSupportRetrievalMethods,
|
||||
fetchUserProfileResponse,
|
||||
fetchWorkspaceMembers,
|
||||
fetchWorkspacesList,
|
||||
generateStructuredOutputRules,
|
||||
initAccount,
|
||||
logoutAccount,
|
||||
registerEmail,
|
||||
sendRegisterEmail,
|
||||
validateRegisterEmail,
|
||||
verifyForgotPasswordToken,
|
||||
} from './common'
|
||||
import { useInvalid } from './use-base'
|
||||
|
||||
const NAME_SPACE = 'common'
|
||||
@@ -64,7 +94,7 @@ export const commonQueryKeys = {
|
||||
export const useFileUploadConfig = () => {
|
||||
return useQuery<FileUploadConfigResponse>({
|
||||
queryKey: commonQueryKeys.fileUploadConfig,
|
||||
queryFn: () => get<FileUploadConfigResponse>('/files/upload'),
|
||||
queryFn: () => fetchFileUploadConfig(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -80,7 +110,7 @@ export const useUserProfile = () => {
|
||||
return useQuery<UserProfileWithMeta>({
|
||||
queryKey: commonQueryKeys.userProfile,
|
||||
queryFn: async () => {
|
||||
const response = await get<Response>('/account/profile', {}, { needAllResponseContent: true }) as Response
|
||||
const response = await fetchUserProfileResponse()
|
||||
const profile = await response.clone().json() as UserProfileResponse
|
||||
return {
|
||||
profile,
|
||||
@@ -100,7 +130,7 @@ export const useUserProfile = () => {
|
||||
export const useLangGeniusVersion = (currentVersion?: string | null, enabled?: boolean) => {
|
||||
return useQuery<LangGeniusVersionResponse>({
|
||||
queryKey: commonQueryKeys.langGeniusVersion(currentVersion || undefined),
|
||||
queryFn: () => get<LangGeniusVersionResponse>('/version', { params: { current_version: currentVersion } }),
|
||||
queryFn: () => fetchLangGeniusVersionInfo(currentVersion),
|
||||
enabled: !!currentVersion && (enabled ?? true),
|
||||
})
|
||||
}
|
||||
@@ -108,14 +138,14 @@ export const useLangGeniusVersion = (currentVersion?: string | null, enabled?: b
|
||||
export const useCurrentWorkspace = () => {
|
||||
return useQuery<ICurrentWorkspace>({
|
||||
queryKey: commonQueryKeys.currentWorkspace,
|
||||
queryFn: () => post<ICurrentWorkspace>('/workspaces/current', { body: {} }),
|
||||
queryFn: () => fetchCurrentWorkspaceInfo(),
|
||||
})
|
||||
}
|
||||
|
||||
export const useWorkspaces = () => {
|
||||
return useQuery<{ workspaces: IWorkspace[] }>({
|
||||
queryKey: commonQueryKeys.workspaces,
|
||||
queryFn: () => get<{ workspaces: IWorkspace[] }>('/workspaces'),
|
||||
queryFn: () => fetchWorkspacesList(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -123,10 +153,7 @@ export const useGenerateStructuredOutputRules = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'generate-structured-output-rules'],
|
||||
mutationFn: (body: StructuredOutputRulesRequestBody) => {
|
||||
return post<StructuredOutputRulesResponse>(
|
||||
'/rule-structured-output-generate',
|
||||
{ body },
|
||||
)
|
||||
return generateStructuredOutputRules(body)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -136,7 +163,7 @@ export const useSendMail = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'mail-send'],
|
||||
mutationFn: (body: { email: string, language: string }) => {
|
||||
return post<MailSendResponse>('/email-register/send-email', { body })
|
||||
return sendRegisterEmail(body)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -147,7 +174,7 @@ export const useMailValidity = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'mail-validity'],
|
||||
mutationFn: (body: { email: string, code: string, token: string }) => {
|
||||
return post<MailValidityResponse>('/email-register/validity', { body })
|
||||
return validateRegisterEmail(body)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -158,7 +185,7 @@ export const useMailRegister = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'mail-register'],
|
||||
mutationFn: (body: { token: string, new_password: string, password_confirm: string }) => {
|
||||
return post<MailRegisterResponse>('/email-register', { body })
|
||||
return registerEmail(body)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -166,7 +193,7 @@ export const useMailRegister = () => {
|
||||
export const useFileSupportTypes = () => {
|
||||
return useQuery<FileTypesRes>({
|
||||
queryKey: [NAME_SPACE, 'file-types'],
|
||||
queryFn: () => get<FileTypesRes>('/files/support-type'),
|
||||
queryFn: () => fetchFileSupportTypes(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -177,7 +204,7 @@ type MemberResponse = {
|
||||
export const useMembers = () => {
|
||||
return useQuery<MemberResponse>({
|
||||
queryKey: commonQueryKeys.members,
|
||||
queryFn: () => get<MemberResponse>('/workspaces/current/members', { params: {} }),
|
||||
queryFn: () => fetchWorkspaceMembers(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -188,7 +215,7 @@ type FilePreviewResponse = {
|
||||
export const useFilePreview = (fileID: string) => {
|
||||
return useQuery<FilePreviewResponse>({
|
||||
queryKey: commonQueryKeys.filePreview(fileID),
|
||||
queryFn: () => get<FilePreviewResponse>(`/files/${fileID}/preview`),
|
||||
queryFn: () => fetchFilePreview({ fileID }),
|
||||
enabled: !!fileID,
|
||||
})
|
||||
}
|
||||
@@ -203,7 +230,7 @@ export type SchemaTypeDefinition = {
|
||||
export const useSchemaTypeDefinitions = () => {
|
||||
return useQuery<SchemaTypeDefinition[]>({
|
||||
queryKey: commonQueryKeys.schemaDefinitions,
|
||||
queryFn: () => get<SchemaTypeDefinition[]>('/spec/schema-definitions'),
|
||||
queryFn: () => fetchSchemaDefinitions(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -218,9 +245,7 @@ export const useIsLogin = () => {
|
||||
gcTime: 0,
|
||||
queryFn: async (): Promise<isLogin> => {
|
||||
try {
|
||||
await get('/account/profile', {}, {
|
||||
silent: true,
|
||||
})
|
||||
await fetchAccountProfile()
|
||||
}
|
||||
catch (e: any) {
|
||||
if (e.status === 401)
|
||||
@@ -235,7 +260,7 @@ export const useIsLogin = () => {
|
||||
export const useLogout = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'logout'],
|
||||
mutationFn: () => post('/logout'),
|
||||
mutationFn: () => logoutAccount(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -243,7 +268,7 @@ type ForgotPasswordValidity = CommonResponse & { is_valid: boolean, email: strin
|
||||
export const useVerifyForgotPasswordToken = (token?: string | null) => {
|
||||
return useQuery<ForgotPasswordValidity>({
|
||||
queryKey: commonQueryKeys.forgotPasswordValidity(token),
|
||||
queryFn: () => post<ForgotPasswordValidity>('/forgot-password/validity', { body: { token } }),
|
||||
queryFn: () => verifyForgotPasswordToken({ url: '/forgot-password/validity', body: { token: token || '' } }) as Promise<ForgotPasswordValidity>,
|
||||
enabled: !!token,
|
||||
staleTime: 0,
|
||||
gcTime: 0,
|
||||
@@ -259,21 +284,21 @@ type OneMoreStepPayload = {
|
||||
export const useOneMoreStep = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'one-more-step'],
|
||||
mutationFn: (body: OneMoreStepPayload) => post<CommonResponse>('/account/init', { body }),
|
||||
mutationFn: (body: OneMoreStepPayload) => initAccount(body),
|
||||
})
|
||||
}
|
||||
|
||||
export const useModelProviders = () => {
|
||||
return useQuery<{ data: ModelProvider[] }>({
|
||||
queryKey: commonQueryKeys.modelProviders,
|
||||
queryFn: () => get<{ data: ModelProvider[] }>('/workspaces/current/model-providers'),
|
||||
queryFn: () => fetchModelProviders('/workspaces/current/model-providers'),
|
||||
})
|
||||
}
|
||||
|
||||
export const useModelListByType = (type: ModelTypeEnum, enabled = true) => {
|
||||
return useQuery<{ data: Model[] }>({
|
||||
queryKey: commonQueryKeys.modelList(type),
|
||||
queryFn: () => get<{ data: Model[] }>(`/workspaces/current/models/model-types/${type}`),
|
||||
queryFn: () => fetchModelListByType(type),
|
||||
enabled,
|
||||
})
|
||||
}
|
||||
@@ -281,7 +306,7 @@ export const useModelListByType = (type: ModelTypeEnum, enabled = true) => {
|
||||
export const useDefaultModelByType = (type: ModelTypeEnum, enabled = true) => {
|
||||
return useQuery({
|
||||
queryKey: commonQueryKeys.defaultModel(type),
|
||||
queryFn: () => get(`/workspaces/current/default-model?model_type=${type}`),
|
||||
queryFn: () => fetchDefaultModelByType(type),
|
||||
enabled,
|
||||
})
|
||||
}
|
||||
@@ -289,14 +314,14 @@ export const useDefaultModelByType = (type: ModelTypeEnum, enabled = true) => {
|
||||
export const useSupportRetrievalMethods = () => {
|
||||
return useQuery<{ retrieval_method: RETRIEVE_METHOD[] }>({
|
||||
queryKey: commonQueryKeys.retrievalMethods,
|
||||
queryFn: () => get<{ retrieval_method: RETRIEVE_METHOD[] }>('/datasets/retrieval-setting'),
|
||||
queryFn: () => fetchSupportRetrievalMethods(),
|
||||
})
|
||||
}
|
||||
|
||||
export const useAccountIntegrates = () => {
|
||||
return useQuery<{ data: AccountIntegrate[] | null }>({
|
||||
queryKey: commonQueryKeys.accountIntegrates,
|
||||
queryFn: () => get<{ data: AccountIntegrate[] | null }>('/account/integrates'),
|
||||
queryFn: () => fetchAccountIntegratesList(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -309,7 +334,7 @@ export const useDataSourceIntegrates = (options: DataSourceIntegratesOptions = {
|
||||
const { enabled = true, initialData } = options
|
||||
return useQuery<{ data: DataSourceNotion[] }>({
|
||||
queryKey: commonQueryKeys.dataSourceIntegrates,
|
||||
queryFn: () => get<{ data: DataSourceNotion[] }>('/data-source/integrates'),
|
||||
queryFn: () => fetchDataSourceIntegrates(),
|
||||
enabled,
|
||||
initialData,
|
||||
})
|
||||
@@ -322,21 +347,21 @@ export const useInvalidDataSourceIntegrates = () => {
|
||||
export const usePluginProviders = () => {
|
||||
return useQuery<PluginProvider[] | null>({
|
||||
queryKey: commonQueryKeys.pluginProviders,
|
||||
queryFn: () => get<PluginProvider[] | null>('/workspaces/current/tool-providers'),
|
||||
queryFn: () => fetchPluginProvidersList(),
|
||||
})
|
||||
}
|
||||
|
||||
export const useCodeBasedExtensions = (module: string) => {
|
||||
return useQuery<CodeBasedExtension>({
|
||||
queryKey: commonQueryKeys.codeBasedExtensions(module),
|
||||
queryFn: () => get<CodeBasedExtension>(`/code-based-extension?module=${module}`),
|
||||
queryFn: () => fetchCodeBasedExtension(module),
|
||||
})
|
||||
}
|
||||
|
||||
export const useNotionConnection = (enabled: boolean) => {
|
||||
return useQuery<{ data: string }>({
|
||||
queryKey: commonQueryKeys.notionConnection,
|
||||
queryFn: () => get<{ data: string }>('/oauth/data-source/notion'),
|
||||
queryFn: () => fetchNotionConnection(),
|
||||
enabled,
|
||||
})
|
||||
}
|
||||
@@ -344,18 +369,14 @@ export const useNotionConnection = (enabled: boolean) => {
|
||||
export const useApiBasedExtensions = () => {
|
||||
return useQuery<ApiBasedExtension[]>({
|
||||
queryKey: commonQueryKeys.apiBasedExtensions,
|
||||
queryFn: () => get<ApiBasedExtension[]>('/api-based-extension'),
|
||||
queryFn: () => fetchApiBasedExtensions(),
|
||||
})
|
||||
}
|
||||
|
||||
export const useInvitationCheck = (params?: { workspace_id?: string, email?: string, token?: string }, enabled?: boolean) => {
|
||||
return useQuery({
|
||||
queryKey: commonQueryKeys.invitationCheck(params),
|
||||
queryFn: () => get<{
|
||||
is_valid: boolean
|
||||
data: { workspace_name: string, email: string, workspace_id: string }
|
||||
result: string
|
||||
}>('/activate/check', { params }),
|
||||
queryFn: () => fetchInvitationCheck(params),
|
||||
enabled: enabled ?? !!params?.token,
|
||||
retry: false,
|
||||
})
|
||||
@@ -364,7 +385,7 @@ export const useInvitationCheck = (params?: { workspace_id?: string, email?: str
|
||||
export const useNotionBinding = (code?: string | null, enabled?: boolean) => {
|
||||
return useQuery({
|
||||
queryKey: commonQueryKeys.notionBinding(code),
|
||||
queryFn: () => get<{ result: string }>('/oauth/data-source/binding/notion', { params: { code } }),
|
||||
queryFn: () => fetchNotionBinding(code),
|
||||
enabled: !!code && (enabled ?? true),
|
||||
})
|
||||
}
|
||||
@@ -372,7 +393,7 @@ export const useNotionBinding = (code?: string | null, enabled?: boolean) => {
|
||||
export const useModelParameterRules = (provider?: string, model?: string, enabled?: boolean) => {
|
||||
return useQuery<{ data: ModelParameterRule[] }>({
|
||||
queryKey: commonQueryKeys.modelParameterRules(provider, model),
|
||||
queryFn: () => get<{ data: ModelParameterRule[] }>(`/workspaces/current/model-providers/${provider}/models/parameter-rules`, { params: { model } }),
|
||||
queryFn: () => fetchModelParameterRules(provider, model),
|
||||
enabled: !!provider && !!model && (enabled ?? true),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import type {
|
||||
DataSourceAuth,
|
||||
DataSourceCredential,
|
||||
} from '@/app/components/header/account-setting/data-source-page-new/types'
|
||||
import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
} from '@tanstack/react-query'
|
||||
import { get } from './base'
|
||||
import {
|
||||
fetchDataSourceAuth,
|
||||
fetchDataSourceListAuth,
|
||||
fetchDataSourceOAuthUrl,
|
||||
fetchDefaultDataSourceListAuth,
|
||||
} from './datasource'
|
||||
import { useInvalid } from './use-base'
|
||||
|
||||
const NAME_SPACE = 'data-source-auth'
|
||||
@@ -14,7 +15,7 @@ const NAME_SPACE = 'data-source-auth'
|
||||
export const useGetDataSourceListAuth = () => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'list'],
|
||||
queryFn: () => get<{ result: DataSourceAuth[] }>('/auth/plugin/datasource/list'),
|
||||
queryFn: () => fetchDataSourceListAuth(),
|
||||
retry: 0,
|
||||
})
|
||||
}
|
||||
@@ -28,7 +29,7 @@ export const useInvalidDataSourceListAuth = (
|
||||
export const useGetDefaultDataSourceListAuth = () => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'default-list'],
|
||||
queryFn: () => get<{ result: DataSourceAuth[] }>('/auth/plugin/datasource/default-list'),
|
||||
queryFn: () => fetchDefaultDataSourceListAuth(),
|
||||
retry: 0,
|
||||
})
|
||||
}
|
||||
@@ -44,13 +45,7 @@ export const useGetDataSourceOAuthUrl = (
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'oauth-url', provider],
|
||||
mutationFn: (credentialId?: string) => {
|
||||
return get<
|
||||
{
|
||||
authorization_url: string
|
||||
state: string
|
||||
context_id: string
|
||||
}
|
||||
>(`/oauth/plugin/${provider}/datasource/get-authorization-url?credential_id=${credentialId}`)
|
||||
return fetchDataSourceOAuthUrl(provider, credentialId)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -64,7 +59,7 @@ export const useGetDataSourceAuth = ({
|
||||
}) => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'specific-data-source', pluginId, provider],
|
||||
queryFn: () => get<{ result: DataSourceCredential[] }>(`/auth/plugin/datasource/${pluginId}/${provider}`),
|
||||
queryFn: () => fetchDataSourceAuth(pluginId, provider),
|
||||
retry: 0,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,7 +3,12 @@ import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
} from '@tanstack/react-query'
|
||||
import { get, post } from './base'
|
||||
import {
|
||||
addEducation,
|
||||
fetchEducationAutocomplete,
|
||||
fetchEducationStatus,
|
||||
verifyEducation,
|
||||
} from './education'
|
||||
import { useInvalid } from './use-base'
|
||||
|
||||
const NAME_SPACE = 'education'
|
||||
@@ -12,7 +17,7 @@ export const useEducationVerify = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'education-verify'],
|
||||
mutationFn: () => {
|
||||
return get<{ token: string }>('/account/education/verify', {}, { silent: true })
|
||||
return verifyEducation()
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -25,9 +30,7 @@ export const useEducationAdd = ({
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'education-add'],
|
||||
mutationFn: (params: EducationAddParams) => {
|
||||
return post<{ message: string }>('/account/education', {
|
||||
body: params,
|
||||
})
|
||||
return addEducation(params)
|
||||
},
|
||||
onSuccess,
|
||||
})
|
||||
@@ -46,7 +49,7 @@ export const useEducationAutocomplete = () => {
|
||||
page = 0,
|
||||
limit = 40,
|
||||
} = searchParams
|
||||
return get<{ data: string[], has_next: boolean, curr_page: number }>(`/account/education/autocomplete?keywords=${keywords}&page=${page}&limit=${limit}`)
|
||||
return fetchEducationAutocomplete({ keywords, page, limit })
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -56,7 +59,7 @@ export const useEducationStatus = (disable?: boolean) => {
|
||||
enabled: !disable,
|
||||
queryKey: [NAME_SPACE, 'education-status'],
|
||||
queryFn: () => {
|
||||
return get<{ is_student: boolean, allow_refresh: boolean, expire_at: number | null }>('/account/education')
|
||||
return fetchEducationStatus()
|
||||
},
|
||||
retry: false,
|
||||
staleTime: 0, // Data expires immediately, ensuring fresh data on refetch
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
import type {
|
||||
EndpointsResponse,
|
||||
} from '@/app/components/plugins/types'
|
||||
import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
} from '@tanstack/react-query'
|
||||
import { get, post } from './base'
|
||||
import {
|
||||
createEndpoint,
|
||||
deleteEndpoint,
|
||||
disableEndpoint,
|
||||
enableEndpoint,
|
||||
fetchEndpointList,
|
||||
updateEndpoint,
|
||||
} from './endpoints'
|
||||
|
||||
const NAME_SPACE = 'endpoints'
|
||||
|
||||
export const useEndpointList = (pluginID: string) => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'list', pluginID],
|
||||
queryFn: () => get<EndpointsResponse>('/workspaces/current/endpoints/list/plugin', {
|
||||
params: {
|
||||
plugin_id: pluginID,
|
||||
page: 1,
|
||||
page_size: 100,
|
||||
},
|
||||
}),
|
||||
queryFn: () => fetchEndpointList(pluginID),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -44,16 +42,7 @@ export const useCreateEndpoint = ({
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'create'],
|
||||
mutationFn: (payload: { pluginUniqueID: string, state: Record<string, any> }) => {
|
||||
const { pluginUniqueID, state } = payload
|
||||
const newName = state.name
|
||||
delete state.name
|
||||
return post('/workspaces/current/endpoints/create', {
|
||||
body: {
|
||||
plugin_unique_identifier: pluginUniqueID,
|
||||
settings: state,
|
||||
name: newName,
|
||||
},
|
||||
})
|
||||
return createEndpoint(payload)
|
||||
},
|
||||
onSuccess,
|
||||
onError,
|
||||
@@ -70,16 +59,7 @@ export const useUpdateEndpoint = ({
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'update'],
|
||||
mutationFn: (payload: { endpointID: string, state: Record<string, any> }) => {
|
||||
const { endpointID, state } = payload
|
||||
const newName = state.name
|
||||
delete state.name
|
||||
return post('/workspaces/current/endpoints/update', {
|
||||
body: {
|
||||
endpoint_id: endpointID,
|
||||
settings: state,
|
||||
name: newName,
|
||||
},
|
||||
})
|
||||
return updateEndpoint(payload)
|
||||
},
|
||||
onSuccess,
|
||||
onError,
|
||||
@@ -96,11 +76,7 @@ export const useDeleteEndpoint = ({
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'delete'],
|
||||
mutationFn: (endpointID: string) => {
|
||||
return post('/workspaces/current/endpoints/delete', {
|
||||
body: {
|
||||
endpoint_id: endpointID,
|
||||
},
|
||||
})
|
||||
return deleteEndpoint(endpointID)
|
||||
},
|
||||
onSuccess,
|
||||
onError,
|
||||
@@ -117,11 +93,7 @@ export const useEnableEndpoint = ({
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'enable'],
|
||||
mutationFn: (endpointID: string) => {
|
||||
return post('/workspaces/current/endpoints/enable', {
|
||||
body: {
|
||||
endpoint_id: endpointID,
|
||||
},
|
||||
})
|
||||
return enableEndpoint(endpointID)
|
||||
},
|
||||
onSuccess,
|
||||
onError,
|
||||
@@ -138,11 +110,7 @@ export const useDisableEndpoint = ({
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'disable'],
|
||||
mutationFn: (endpointID: string) => {
|
||||
return post('/workspaces/current/endpoints/disable', {
|
||||
body: {
|
||||
endpoint_id: endpointID,
|
||||
},
|
||||
})
|
||||
return disableEndpoint(endpointID)
|
||||
},
|
||||
onSuccess,
|
||||
onError,
|
||||
|
||||
@@ -9,7 +9,14 @@ import type {
|
||||
WorkflowLogsResponse,
|
||||
} from '@/models/log'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { get } from './base'
|
||||
import {
|
||||
fetchAnnotationsCount,
|
||||
fetchChatConversationDetail,
|
||||
fetchChatConversations,
|
||||
fetchCompletionConversationDetail,
|
||||
fetchCompletionConversations,
|
||||
fetchWorkflowLogs,
|
||||
} from './log'
|
||||
|
||||
const NAME_SPACE = 'log'
|
||||
|
||||
@@ -18,7 +25,7 @@ const NAME_SPACE = 'log'
|
||||
export const useAnnotationsCount = (appId: string) => {
|
||||
return useQuery<AnnotationsCountResponse>({
|
||||
queryKey: [NAME_SPACE, 'annotations-count', appId],
|
||||
queryFn: () => get<AnnotationsCountResponse>(`/apps/${appId}/annotations/count`),
|
||||
queryFn: () => fetchAnnotationsCount(appId),
|
||||
enabled: !!appId,
|
||||
})
|
||||
}
|
||||
@@ -33,7 +40,7 @@ type ChatConversationsParams = {
|
||||
export const useChatConversations = ({ appId, params }: ChatConversationsParams) => {
|
||||
return useQuery<ChatConversationsResponse>({
|
||||
queryKey: [NAME_SPACE, 'chat-conversations', appId, params],
|
||||
queryFn: () => get<ChatConversationsResponse>(`/apps/${appId}/chat-conversations`, { params }),
|
||||
queryFn: () => fetchChatConversations(appId, params),
|
||||
enabled: !!appId,
|
||||
})
|
||||
}
|
||||
@@ -48,7 +55,7 @@ type CompletionConversationsParams = {
|
||||
export const useCompletionConversations = ({ appId, params }: CompletionConversationsParams) => {
|
||||
return useQuery<CompletionConversationsResponse>({
|
||||
queryKey: [NAME_SPACE, 'completion-conversations', appId, params],
|
||||
queryFn: () => get<CompletionConversationsResponse>(`/apps/${appId}/completion-conversations`, { params }),
|
||||
queryFn: () => fetchCompletionConversations(appId, params),
|
||||
enabled: !!appId,
|
||||
})
|
||||
}
|
||||
@@ -58,7 +65,7 @@ export const useCompletionConversations = ({ appId, params }: CompletionConversa
|
||||
export const useChatConversationDetail = (appId?: string, conversationId?: string) => {
|
||||
return useQuery<ChatConversationFullDetailResponse>({
|
||||
queryKey: [NAME_SPACE, 'chat-conversation-detail', appId, conversationId],
|
||||
queryFn: () => get<ChatConversationFullDetailResponse>(`/apps/${appId}/chat-conversations/${conversationId}`),
|
||||
queryFn: () => fetchChatConversationDetail(appId || '', conversationId || ''),
|
||||
enabled: !!appId && !!conversationId,
|
||||
})
|
||||
}
|
||||
@@ -68,7 +75,7 @@ export const useChatConversationDetail = (appId?: string, conversationId?: strin
|
||||
export const useCompletionConversationDetail = (appId?: string, conversationId?: string) => {
|
||||
return useQuery<CompletionConversationFullDetailResponse>({
|
||||
queryKey: [NAME_SPACE, 'completion-conversation-detail', appId, conversationId],
|
||||
queryFn: () => get<CompletionConversationFullDetailResponse>(`/apps/${appId}/completion-conversations/${conversationId}`),
|
||||
queryFn: () => fetchCompletionConversationDetail(appId || '', conversationId || ''),
|
||||
enabled: !!appId && !!conversationId,
|
||||
})
|
||||
}
|
||||
@@ -83,7 +90,7 @@ type WorkflowLogsParams = {
|
||||
export const useWorkflowLogs = ({ appId, params }: WorkflowLogsParams) => {
|
||||
return useQuery<WorkflowLogsResponse>({
|
||||
queryKey: [NAME_SPACE, 'workflow-logs', appId, params],
|
||||
queryFn: () => get<WorkflowLogsResponse>(`/apps/${appId}/workflow-app-logs`, { params }),
|
||||
queryFn: () => fetchWorkflowLogs(appId, params),
|
||||
enabled: !!appId,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type {
|
||||
ModelCredential,
|
||||
ModelItem,
|
||||
ModelLoadBalancingConfig,
|
||||
ModelTypeEnum,
|
||||
ProviderCredential,
|
||||
@@ -11,18 +10,27 @@ import {
|
||||
// useQueryClient,
|
||||
} from '@tanstack/react-query'
|
||||
import {
|
||||
del,
|
||||
get,
|
||||
post,
|
||||
put,
|
||||
} from './base'
|
||||
activateModelCredential,
|
||||
activateProviderCredential,
|
||||
addModelCredential,
|
||||
addProviderCredential,
|
||||
deleteModel,
|
||||
deleteModelCredential,
|
||||
deleteProviderCredential,
|
||||
editModelCredential,
|
||||
editProviderCredential,
|
||||
fetchModelCredential,
|
||||
fetchModelProviderModelList,
|
||||
fetchProviderCredential,
|
||||
updateModelLoadBalancingConfig,
|
||||
} from './models'
|
||||
|
||||
const NAME_SPACE = 'models'
|
||||
|
||||
export const useModelProviderModelList = (provider: string) => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'model-list', provider],
|
||||
queryFn: () => get<{ data: ModelItem[] }>(`/workspaces/current/model-providers/${provider}/models`),
|
||||
queryFn: () => fetchModelProviderModelList(provider),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -30,23 +38,19 @@ export const useGetProviderCredential = (enabled: boolean, provider: string, cre
|
||||
return useQuery({
|
||||
enabled,
|
||||
queryKey: [NAME_SPACE, 'model-list', provider, credentialId],
|
||||
queryFn: () => get<ProviderCredential>(`/workspaces/current/model-providers/${provider}/credentials${credentialId ? `?credential_id=${credentialId}` : ''}`),
|
||||
queryFn: () => fetchProviderCredential(provider, credentialId),
|
||||
})
|
||||
}
|
||||
|
||||
export const useAddProviderCredential = (provider: string) => {
|
||||
return useMutation({
|
||||
mutationFn: (data: ProviderCredential) => post<{ result: string }>(`/workspaces/current/model-providers/${provider}/credentials`, {
|
||||
body: data,
|
||||
}),
|
||||
mutationFn: (data: ProviderCredential) => addProviderCredential(provider, data),
|
||||
})
|
||||
}
|
||||
|
||||
export const useEditProviderCredential = (provider: string) => {
|
||||
return useMutation({
|
||||
mutationFn: (data: ProviderCredential) => put<{ result: string }>(`/workspaces/current/model-providers/${provider}/credentials`, {
|
||||
body: data,
|
||||
}),
|
||||
mutationFn: (data: ProviderCredential) => editProviderCredential(provider, data),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -54,9 +58,7 @@ export const useDeleteProviderCredential = (provider: string) => {
|
||||
return useMutation({
|
||||
mutationFn: (data: {
|
||||
credential_id: string
|
||||
}) => del<{ result: string }>(`/workspaces/current/model-providers/${provider}/credentials`, {
|
||||
body: data,
|
||||
}),
|
||||
}) => deleteProviderCredential(provider, data),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -66,9 +68,7 @@ export const useActiveProviderCredential = (provider: string) => {
|
||||
credential_id: string
|
||||
model?: string
|
||||
model_type?: ModelTypeEnum
|
||||
}) => post<{ result: string }>(`/workspaces/current/model-providers/${provider}/credentials/switch`, {
|
||||
body: data,
|
||||
}),
|
||||
}) => activateProviderCredential(provider, data),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ export const useGetModelCredential = (
|
||||
return useQuery({
|
||||
enabled,
|
||||
queryKey: [NAME_SPACE, 'model-list', provider, model, modelType, credentialId, configFrom],
|
||||
queryFn: () => get<ModelCredential>(`/workspaces/current/model-providers/${provider}/models/credentials?model=${model}&model_type=${modelType}&config_from=${configFrom}${credentialId ? `&credential_id=${credentialId}` : ''}`),
|
||||
queryFn: () => fetchModelCredential(provider, model, modelType, configFrom, credentialId),
|
||||
staleTime: 0,
|
||||
gcTime: 0,
|
||||
})
|
||||
@@ -91,17 +91,13 @@ export const useGetModelCredential = (
|
||||
|
||||
export const useAddModelCredential = (provider: string) => {
|
||||
return useMutation({
|
||||
mutationFn: (data: ModelCredential) => post<{ result: string }>(`/workspaces/current/model-providers/${provider}/models/credentials`, {
|
||||
body: data,
|
||||
}),
|
||||
mutationFn: (data: ModelCredential) => addModelCredential(provider, data),
|
||||
})
|
||||
}
|
||||
|
||||
export const useEditModelCredential = (provider: string) => {
|
||||
return useMutation({
|
||||
mutationFn: (data: ModelCredential) => put<{ result: string }>(`/workspaces/current/model-providers/${provider}/models/credentials`, {
|
||||
body: data,
|
||||
}),
|
||||
mutationFn: (data: ModelCredential) => editModelCredential(provider, data),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -111,9 +107,7 @@ export const useDeleteModelCredential = (provider: string) => {
|
||||
credential_id: string
|
||||
model?: string
|
||||
model_type?: ModelTypeEnum
|
||||
}) => del<{ result: string }>(`/workspaces/current/model-providers/${provider}/models/credentials`, {
|
||||
body: data,
|
||||
}),
|
||||
}) => deleteModelCredential(provider, data),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -122,9 +116,7 @@ export const useDeleteModel = (provider: string) => {
|
||||
mutationFn: (data: {
|
||||
model: string
|
||||
model_type: ModelTypeEnum
|
||||
}) => del<{ result: string }>(`/workspaces/current/model-providers/${provider}/models`, {
|
||||
body: data,
|
||||
}),
|
||||
}) => deleteModel(provider, data),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -134,9 +126,7 @@ export const useActiveModelCredential = (provider: string) => {
|
||||
credential_id: string
|
||||
model?: string
|
||||
model_type?: ModelTypeEnum
|
||||
}) => post<{ result: string }>(`/workspaces/current/model-providers/${provider}/models/credentials/switch`, {
|
||||
body: data,
|
||||
}),
|
||||
}) => activateModelCredential(provider, data),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -148,8 +138,6 @@ export const useUpdateModelLoadBalancingConfig = (provider: string) => {
|
||||
model_type: ModelTypeEnum
|
||||
load_balancing: ModelLoadBalancingConfig
|
||||
credential_id?: string
|
||||
}) => post<{ result: string }>(`/workspaces/current/model-providers/${provider}/models`, {
|
||||
body: data,
|
||||
}),
|
||||
}) => updateModelLoadBalancingConfig(provider, data),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,22 +1,13 @@
|
||||
import type { OAuthAppInfo } from './oauth'
|
||||
import { useMutation, useQuery } from '@tanstack/react-query'
|
||||
import { post } from './base'
|
||||
import { authorizeOAuthApp, fetchOAuthAppInfo } from './oauth'
|
||||
|
||||
const NAME_SPACE = 'oauth-provider'
|
||||
|
||||
export type OAuthAppInfo = {
|
||||
app_icon: string
|
||||
app_label: Record<string, string>
|
||||
scope: string
|
||||
}
|
||||
|
||||
export type OAuthAuthorizeResponse = {
|
||||
code: string
|
||||
}
|
||||
|
||||
export const useOAuthAppInfo = (client_id: string, redirect_uri: string) => {
|
||||
return useQuery<OAuthAppInfo>({
|
||||
queryKey: [NAME_SPACE, 'authAppInfo', client_id, redirect_uri],
|
||||
queryFn: () => post<OAuthAppInfo>('/oauth/provider', { body: { client_id, redirect_uri } }, { silent: true }),
|
||||
queryFn: () => fetchOAuthAppInfo(client_id, redirect_uri),
|
||||
enabled: Boolean(client_id && redirect_uri),
|
||||
})
|
||||
}
|
||||
@@ -24,6 +15,6 @@ export const useOAuthAppInfo = (client_id: string, redirect_uri: string) => {
|
||||
export const useAuthorizeOAuthApp = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'authorize'],
|
||||
mutationFn: (payload: { client_id: string }) => post<OAuthAuthorizeResponse>('/oauth/provider/authorize', { body: payload }),
|
||||
mutationFn: (payload: { client_id: string }) => authorizeOAuthApp(payload),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -32,8 +32,31 @@ import type {
|
||||
UpdateTemplateInfoResponse,
|
||||
} from '@/models/pipeline'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { DatasourceType } from '@/models/pipeline'
|
||||
import { del, get, patch, post } from './base'
|
||||
import {
|
||||
checkPipelineDependencies,
|
||||
confirmImportPipelineDSL,
|
||||
convertDatasetToPipeline,
|
||||
deletePipelineTemplate,
|
||||
exportPipelineDSL,
|
||||
exportPipelineTemplateDSL,
|
||||
fetchDataSourceCredentials,
|
||||
fetchDraftPipelinePreProcessingParams,
|
||||
fetchDraftPipelineProcessingParams,
|
||||
fetchPipelineDataSourceList,
|
||||
fetchPipelineExecutionLog,
|
||||
fetchPipelineTemplateById,
|
||||
fetchPipelineTemplateList,
|
||||
fetchPublishedPipelineInfo,
|
||||
fetchPublishedPipelinePreProcessingParams,
|
||||
fetchPublishedPipelineProcessingParams,
|
||||
importPipelineDSL,
|
||||
previewOnlineDocument,
|
||||
publishAsCustomizedPipeline,
|
||||
runDatasourceNodeSingle,
|
||||
runPublishedPipeline,
|
||||
updateDataSourceCredentials,
|
||||
updatePipelineTemplateInfo,
|
||||
} from './pipeline'
|
||||
import { useInvalid } from './use-base'
|
||||
|
||||
const NAME_SPACE = 'pipeline'
|
||||
@@ -43,7 +66,7 @@ export const usePipelineTemplateList = (params: PipelineTemplateListParams, enab
|
||||
return useQuery<PipelineTemplateListResponse>({
|
||||
queryKey: [...PipelineTemplateListQueryKeyPrefix, params],
|
||||
queryFn: () => {
|
||||
return get<PipelineTemplateListResponse>('/rag/pipeline/templates', { params })
|
||||
return fetchPipelineTemplateList(params)
|
||||
},
|
||||
enabled,
|
||||
})
|
||||
@@ -58,11 +81,7 @@ export const usePipelineTemplateById = (params: PipelineTemplateByIdRequest, ena
|
||||
return useQuery<PipelineTemplateByIdResponse>({
|
||||
queryKey: [NAME_SPACE, 'template', type, template_id],
|
||||
queryFn: () => {
|
||||
return get<PipelineTemplateByIdResponse>(`/rag/pipeline/templates/${template_id}`, {
|
||||
params: {
|
||||
type,
|
||||
},
|
||||
})
|
||||
return fetchPipelineTemplateById({ template_id, type })
|
||||
},
|
||||
enabled,
|
||||
staleTime: 0,
|
||||
@@ -75,10 +94,7 @@ export const useUpdateTemplateInfo = (
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'template-update'],
|
||||
mutationFn: (request: UpdateTemplateInfoRequest) => {
|
||||
const { template_id, ...rest } = request
|
||||
return patch<UpdateTemplateInfoResponse>(`/rag/pipeline/customized/templates/${template_id}`, {
|
||||
body: rest,
|
||||
})
|
||||
return updatePipelineTemplateInfo(request)
|
||||
},
|
||||
...mutationOptions,
|
||||
})
|
||||
@@ -90,7 +106,7 @@ export const useDeleteTemplate = (
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'template-delete'],
|
||||
mutationFn: (templateId: string) => {
|
||||
return del<DeleteTemplateResponse>(`/rag/pipeline/customized/templates/${templateId}`)
|
||||
return deletePipelineTemplate(templateId)
|
||||
},
|
||||
...mutationOptions,
|
||||
})
|
||||
@@ -102,7 +118,7 @@ export const useExportTemplateDSL = (
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'template-dsl-export'],
|
||||
mutationFn: (templateId: string) => {
|
||||
return post<ExportTemplateDSLResponse>(`/rag/pipeline/customized/templates/${templateId}`)
|
||||
return exportPipelineTemplateDSL(templateId)
|
||||
},
|
||||
...mutationOptions,
|
||||
})
|
||||
@@ -114,7 +130,7 @@ export const useImportPipelineDSL = (
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'dsl-import'],
|
||||
mutationFn: (request: ImportPipelineDSLRequest) => {
|
||||
return post<ImportPipelineDSLResponse>('/rag/pipelines/imports', { body: request })
|
||||
return importPipelineDSL(request)
|
||||
},
|
||||
...mutationOptions,
|
||||
})
|
||||
@@ -126,7 +142,7 @@ export const useImportPipelineDSLConfirm = (
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'dsl-import-confirm'],
|
||||
mutationFn: (importId: string) => {
|
||||
return post<ImportPipelineDSLConfirmResponse>(`/rag/pipelines/imports/${importId}/confirm`)
|
||||
return confirmImportPipelineDSL(importId)
|
||||
},
|
||||
...mutationOptions,
|
||||
})
|
||||
@@ -138,7 +154,7 @@ export const useCheckPipelineDependencies = (
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'check-dependencies'],
|
||||
mutationFn: (pipelineId: string) => {
|
||||
return get<PipelineCheckDependenciesResponse>(`/rag/pipelines/imports/${pipelineId}/check-dependencies`)
|
||||
return checkPipelineDependencies(pipelineId)
|
||||
},
|
||||
...mutationOptions,
|
||||
})
|
||||
@@ -149,11 +165,7 @@ export const useDraftPipelineProcessingParams = (params: PipelineProcessingParam
|
||||
return useQuery<PipelineProcessingParamsResponse>({
|
||||
queryKey: [NAME_SPACE, 'draft-pipeline-processing-params', pipeline_id, node_id],
|
||||
queryFn: () => {
|
||||
return get<PipelineProcessingParamsResponse>(`/rag/pipelines/${pipeline_id}/workflows/draft/processing/parameters`, {
|
||||
params: {
|
||||
node_id,
|
||||
},
|
||||
})
|
||||
return fetchDraftPipelineProcessingParams({ pipeline_id, node_id })
|
||||
},
|
||||
staleTime: 0,
|
||||
enabled,
|
||||
@@ -165,11 +177,7 @@ export const usePublishedPipelineProcessingParams = (params: PipelineProcessingP
|
||||
return useQuery<PipelineProcessingParamsResponse>({
|
||||
queryKey: [NAME_SPACE, 'published-pipeline-processing-params', pipeline_id, node_id],
|
||||
queryFn: () => {
|
||||
return get<PipelineProcessingParamsResponse>(`/rag/pipelines/${pipeline_id}/workflows/published/processing/parameters`, {
|
||||
params: {
|
||||
node_id,
|
||||
},
|
||||
})
|
||||
return fetchPublishedPipelineProcessingParams({ pipeline_id, node_id })
|
||||
},
|
||||
staleTime: 0,
|
||||
})
|
||||
@@ -181,7 +189,7 @@ export const useDataSourceList = (enabled: boolean, onSuccess?: (v: DataSourceIt
|
||||
queryKey: [NAME_SPACE, 'datasource'],
|
||||
staleTime: 0,
|
||||
queryFn: async () => {
|
||||
const data = await get<DataSourceItem[]>('/rag/pipelines/datasource-plugins')
|
||||
const data = await fetchPipelineDataSourceList()
|
||||
onSuccess?.(data)
|
||||
return data
|
||||
},
|
||||
@@ -199,7 +207,7 @@ export const usePublishedPipelineInfo = (pipelineId: string) => {
|
||||
return useQuery<PublishedPipelineInfoResponse>({
|
||||
queryKey: [...publishedPipelineInfoQueryKeyPrefix, pipelineId],
|
||||
queryFn: () => {
|
||||
return get<PublishedPipelineInfoResponse>(`/rag/pipelines/${pipelineId}/workflows/publish`)
|
||||
return fetchPublishedPipelineInfo(pipelineId)
|
||||
},
|
||||
enabled: !!pipelineId,
|
||||
})
|
||||
@@ -211,14 +219,7 @@ export const useRunPublishedPipeline = (
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'run-published-pipeline'],
|
||||
mutationFn: (request: PublishedPipelineRunRequest) => {
|
||||
const { pipeline_id: pipelineId, is_preview, ...rest } = request
|
||||
return post<PublishedPipelineRunPreviewResponse | PublishedPipelineRunResponse>(`/rag/pipelines/${pipelineId}/workflows/published/run`, {
|
||||
body: {
|
||||
...rest,
|
||||
is_preview,
|
||||
response_mode: 'blocking',
|
||||
},
|
||||
})
|
||||
return runPublishedPipeline(request)
|
||||
},
|
||||
...mutationOptions,
|
||||
})
|
||||
@@ -228,7 +229,7 @@ export const useDataSourceCredentials = (provider: string, pluginId: string, onS
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'datasource-credentials', provider, pluginId],
|
||||
queryFn: async () => {
|
||||
const result = await get<{ result: ToolCredential[] }>(`/auth/plugin/datasource?provider=${provider}&plugin_id=${pluginId}`)
|
||||
const result = await fetchDataSourceCredentials(provider, pluginId)
|
||||
onSuccess(result.result)
|
||||
return result.result
|
||||
},
|
||||
@@ -247,15 +248,8 @@ export const useUpdateDataSourceCredentials = (
|
||||
pluginId,
|
||||
credentials,
|
||||
name,
|
||||
}: { provider: string, pluginId: string, credentials: Record<string, any>, name: string }) => {
|
||||
return post('/auth/plugin/datasource', {
|
||||
body: {
|
||||
provider,
|
||||
plugin_id: pluginId,
|
||||
credentials,
|
||||
name,
|
||||
},
|
||||
}).then(() => {
|
||||
}: { provider: string, pluginId: string, credentials: Record<string, unknown>, name: string }) => {
|
||||
return updateDataSourceCredentials({ provider, pluginId, credentials, name }).then(() => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [NAME_SPACE, 'datasource'],
|
||||
})
|
||||
@@ -269,11 +263,7 @@ export const useDraftPipelinePreProcessingParams = (params: PipelinePreProcessin
|
||||
return useQuery<PipelinePreProcessingParamsResponse>({
|
||||
queryKey: [NAME_SPACE, 'draft-pipeline-pre-processing-params', pipeline_id, node_id],
|
||||
queryFn: () => {
|
||||
return get<PipelinePreProcessingParamsResponse>(`/rag/pipelines/${pipeline_id}/workflows/draft/pre-processing/parameters`, {
|
||||
params: {
|
||||
node_id,
|
||||
},
|
||||
})
|
||||
return fetchDraftPipelinePreProcessingParams({ pipeline_id, node_id })
|
||||
},
|
||||
staleTime: 0,
|
||||
enabled,
|
||||
@@ -285,11 +275,7 @@ export const usePublishedPipelinePreProcessingParams = (params: PipelinePreProce
|
||||
return useQuery<PipelinePreProcessingParamsResponse>({
|
||||
queryKey: [NAME_SPACE, 'published-pipeline-pre-processing-params', pipeline_id, node_id],
|
||||
queryFn: () => {
|
||||
return get<PipelinePreProcessingParamsResponse>(`/rag/pipelines/${pipeline_id}/workflows/published/pre-processing/parameters`, {
|
||||
params: {
|
||||
node_id,
|
||||
},
|
||||
})
|
||||
return fetchPublishedPipelinePreProcessingParams({ pipeline_id, node_id })
|
||||
},
|
||||
staleTime: 0,
|
||||
enabled,
|
||||
@@ -303,7 +289,7 @@ export const useExportPipelineDSL = () => {
|
||||
pipelineId,
|
||||
include = false,
|
||||
}: { pipelineId: string, include?: boolean }) => {
|
||||
return get<ExportTemplateDSLResponse>(`/rag/pipelines/${pipelineId}/exports?include_secret=${include}`)
|
||||
return exportPipelineDSL(pipelineId, include)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -322,13 +308,7 @@ export const usePublishAsCustomizedPipeline = () => {
|
||||
icon_info: IconInfo
|
||||
description?: string
|
||||
}) => {
|
||||
return post(`/rag/pipelines/${pipelineId}/customized/publish`, {
|
||||
body: {
|
||||
name,
|
||||
icon_info,
|
||||
description,
|
||||
},
|
||||
})
|
||||
return publishAsCustomizedPipeline({ pipelineId, name, icon_info, description })
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -338,40 +318,26 @@ export const usePipelineExecutionLog = (params: PipelineExecutionLogRequest) =>
|
||||
return useQuery<PipelineExecutionLogResponse>({
|
||||
queryKey: [NAME_SPACE, 'pipeline-execution-log', dataset_id, document_id],
|
||||
queryFn: () => {
|
||||
return get<PipelineExecutionLogResponse>(`/datasets/${dataset_id}/documents/${document_id}/pipeline-execution-log`)
|
||||
return fetchPipelineExecutionLog({ dataset_id, document_id })
|
||||
},
|
||||
staleTime: 0,
|
||||
})
|
||||
}
|
||||
|
||||
export const usePreviewOnlineDocument = () => {
|
||||
return useMutation({
|
||||
return useMutation<OnlineDocumentPreviewResponse, Error, OnlineDocumentPreviewRequest>({
|
||||
mutationKey: [NAME_SPACE, 'preview-online-document'],
|
||||
mutationFn: (params: OnlineDocumentPreviewRequest) => {
|
||||
const { pipelineId, datasourceNodeId, workspaceID, pageID, pageType, credentialId } = params
|
||||
return post<OnlineDocumentPreviewResponse>(
|
||||
`/rag/pipelines/${pipelineId}/workflows/published/datasource/nodes/${datasourceNodeId}/preview`,
|
||||
{
|
||||
body: {
|
||||
datasource_type: DatasourceType.onlineDocument,
|
||||
credential_id: credentialId,
|
||||
inputs: {
|
||||
workspace_id: workspaceID,
|
||||
page_id: pageID,
|
||||
type: pageType,
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
return previewOnlineDocument(params)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const useConvertDatasetToPipeline = () => {
|
||||
return useMutation({
|
||||
return useMutation<ConversionResponse, Error, string>({
|
||||
mutationKey: [NAME_SPACE, 'convert-dataset-to-pipeline'],
|
||||
mutationFn: (datasetId: string) => {
|
||||
return post<ConversionResponse>(`/rag/pipelines/transform/datasets/${datasetId}`)
|
||||
return convertDatasetToPipeline(datasetId)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -382,10 +348,7 @@ export const useDatasourceSingleRun = (
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'datasource-node-single-run'],
|
||||
mutationFn: (params: DatasourceNodeSingleRunRequest) => {
|
||||
const { pipeline_id: pipelineId, ...rest } = params
|
||||
return post<DatasourceNodeSingleRunResponse>(`/rag/pipelines/${pipelineId}/workflows/draft/datasource/variables-inspect`, {
|
||||
body: rest,
|
||||
})
|
||||
return runDatasourceNodeSingle(params)
|
||||
},
|
||||
...mutationOptions,
|
||||
})
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
import type { FormSchema } from '@/app/components/base/form/types'
|
||||
import type {
|
||||
Credential,
|
||||
CredentialTypeEnum,
|
||||
} from '@/app/components/plugins/plugin-auth/types'
|
||||
import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
} from '@tanstack/react-query'
|
||||
import { del, get, post } from './base'
|
||||
import {
|
||||
addPluginCredential,
|
||||
deletePluginCredential,
|
||||
deletePluginOAuthCustomClient,
|
||||
fetchPluginCredentialInfo,
|
||||
fetchPluginCredentialList,
|
||||
fetchPluginCredentialSchema,
|
||||
fetchPluginOAuthClientSchema,
|
||||
fetchPluginOAuthUrl,
|
||||
setPluginDefaultCredential,
|
||||
setPluginOAuthCustomClient,
|
||||
updatePluginCredential,
|
||||
} from './plugins-auth'
|
||||
import { useInvalid } from './use-base'
|
||||
|
||||
const NAME_SPACE = 'plugins-auth'
|
||||
@@ -18,12 +28,7 @@ export const useGetPluginCredentialInfo = (
|
||||
return useQuery({
|
||||
enabled: !!url,
|
||||
queryKey: [NAME_SPACE, 'credential-info', url],
|
||||
queryFn: () => get<{
|
||||
allow_custom_token?: boolean
|
||||
supported_credential_types: string[]
|
||||
credentials: Credential[]
|
||||
is_oauth_custom_client_enabled: boolean
|
||||
}>(url),
|
||||
queryFn: () => fetchPluginCredentialInfo(url),
|
||||
staleTime: 0,
|
||||
})
|
||||
}
|
||||
@@ -39,7 +44,7 @@ export const useSetPluginDefaultCredential = (
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => {
|
||||
return post(url, { body: { id } })
|
||||
return setPluginDefaultCredential(url, id)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -49,7 +54,7 @@ export const useGetPluginCredentialList = (
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'credential-list', url],
|
||||
queryFn: () => get(url),
|
||||
queryFn: () => fetchPluginCredentialList(url),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -62,7 +67,7 @@ export const useAddPluginCredential = (
|
||||
type: CredentialTypeEnum
|
||||
name?: string
|
||||
}) => {
|
||||
return post(url, { body: params })
|
||||
return addPluginCredential(url, params)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -76,7 +81,7 @@ export const useUpdatePluginCredential = (
|
||||
credentials?: Record<string, any>
|
||||
name?: string
|
||||
}) => {
|
||||
return post(url, { body: params })
|
||||
return updatePluginCredential(url, params)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -86,7 +91,7 @@ export const useDeletePluginCredential = (
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (params: { credential_id: string }) => {
|
||||
return post(url, { body: params })
|
||||
return deletePluginCredential(url, params)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -97,7 +102,7 @@ export const useGetPluginCredentialSchema = (
|
||||
return useQuery({
|
||||
enabled: !!url,
|
||||
queryKey: [NAME_SPACE, 'credential-schema', url],
|
||||
queryFn: () => get<FormSchema[]>(url),
|
||||
queryFn: () => fetchPluginCredentialSchema(url),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -107,13 +112,7 @@ export const useGetPluginOAuthUrl = (
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'oauth-url', url],
|
||||
mutationFn: () => {
|
||||
return get<
|
||||
{
|
||||
authorization_url: string
|
||||
state: string
|
||||
context_id: string
|
||||
}
|
||||
>(url)
|
||||
return fetchPluginOAuthUrl(url)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -124,13 +123,7 @@ export const useGetPluginOAuthClientSchema = (
|
||||
return useQuery({
|
||||
enabled: !!url,
|
||||
queryKey: [NAME_SPACE, 'oauth-client-schema', url],
|
||||
queryFn: () => get<{
|
||||
schema: FormSchema[]
|
||||
is_oauth_custom_client_enabled: boolean
|
||||
is_system_oauth_params_exists?: boolean
|
||||
client_params?: Record<string, any>
|
||||
redirect_uri?: string
|
||||
}>(url),
|
||||
queryFn: () => fetchPluginOAuthClientSchema(url),
|
||||
staleTime: 0,
|
||||
})
|
||||
}
|
||||
@@ -149,7 +142,7 @@ export const useSetPluginOAuthCustomClient = (
|
||||
client_params: Record<string, any>
|
||||
enable_oauth_custom_client: boolean
|
||||
}) => {
|
||||
return post<{ result: string }>(url, { body: params })
|
||||
return setPluginOAuthCustomClient(url, params)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -159,7 +152,7 @@ export const useDeletePluginOAuthCustomClient = (
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => {
|
||||
return del<{ result: string }>(url)
|
||||
return deletePluginOAuthCustomClient(url)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { MutateOptions, QueryOptions } from '@tanstack/react-query'
|
||||
import type {
|
||||
FormOption,
|
||||
ModelProvider,
|
||||
} from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||
import type {
|
||||
@@ -11,14 +10,12 @@ import type {
|
||||
Dependency,
|
||||
GitHubItemAndMarketPlaceDependency,
|
||||
InstalledLatestVersionResponse,
|
||||
InstalledPluginListWithTotalResponse,
|
||||
InstallPackageResponse,
|
||||
InstallStatusResponse,
|
||||
PackageDependency,
|
||||
Plugin,
|
||||
PluginDeclaration,
|
||||
PluginDetail,
|
||||
PluginInfoFromMarketPlace,
|
||||
PluginsFromMarketplaceByInfoResponse,
|
||||
PluginsFromMarketplaceResponse,
|
||||
PluginTask,
|
||||
@@ -40,8 +37,37 @@ import { getFormattedPlugin } from '@/app/components/plugins/marketplace/utils'
|
||||
import useReferenceSetting from '@/app/components/plugins/plugin-page/use-reference-setting'
|
||||
import { PluginCategoryEnum, TaskStatus } from '@/app/components/plugins/types'
|
||||
import { fetchModelProviderModelList } from '@/service/common'
|
||||
import { fetchPluginInfoFromMarketPlace, uninstallPlugin } from '@/service/plugins'
|
||||
import { get, getMarketplace, post, postMarketplace } from './base'
|
||||
import {
|
||||
checkImportDependencies,
|
||||
checkInstalledPlugins,
|
||||
deleteAllPluginTasks,
|
||||
deletePluginTask,
|
||||
downloadPlugin,
|
||||
excludeAutoUpgrade,
|
||||
fetchDebugKey,
|
||||
fetchInstalledLatestVersion,
|
||||
fetchInstalledPluginList,
|
||||
fetchMarketplacePluginsByIds,
|
||||
fetchMarketplacePluginsByInfo,
|
||||
fetchPluginAsset,
|
||||
fetchPluginDeclarationFromMarketplace,
|
||||
fetchPluginDynamicOptions,
|
||||
fetchPluginInfoFromMarketPlace,
|
||||
fetchPluginManifestInfo,
|
||||
fetchPluginReadme,
|
||||
fetchPluginTaskList,
|
||||
fetchPluginVersionList,
|
||||
fetchRecommendedMarketplacePlugins,
|
||||
fetchReferenceSettings,
|
||||
installPackageFromGitHub,
|
||||
installPackageFromLocal,
|
||||
installPackageFromMarketplace,
|
||||
searchMarketplacePlugins,
|
||||
uninstallPlugin,
|
||||
updateFromMarketPlace,
|
||||
updateReferenceSettings,
|
||||
uploadGitHubPackage,
|
||||
} from './plugins'
|
||||
import { useInvalidateAllBuiltInTools } from './use-tools'
|
||||
|
||||
const NAME_SPACE = 'plugins'
|
||||
@@ -56,11 +82,7 @@ export const useCheckInstalled = ({
|
||||
}) => {
|
||||
return useQuery<{ plugins: PluginDetail[] }>({
|
||||
queryKey: [NAME_SPACE, 'checkInstalled', pluginIds],
|
||||
queryFn: () => post<{ plugins: PluginDetail[] }>('/workspaces/current/plugin/list/installations/ids', {
|
||||
body: {
|
||||
plugin_ids: pluginIds,
|
||||
},
|
||||
}),
|
||||
queryFn: () => checkInstalledPlugins(pluginIds),
|
||||
enabled,
|
||||
staleTime: 0, // always fresh
|
||||
})
|
||||
@@ -79,14 +101,7 @@ export const useRecommendedMarketplacePlugins = ({
|
||||
return useQuery<Plugin[]>({
|
||||
queryKey: [...useRecommendedMarketplacePluginsKey, collection, limit],
|
||||
queryFn: async () => {
|
||||
const response = await postMarketplace<{ data: { plugins: Plugin[] } }>(
|
||||
`/collections/${collection}/plugins`,
|
||||
{
|
||||
body: {
|
||||
limit,
|
||||
},
|
||||
},
|
||||
)
|
||||
const response = await fetchRecommendedMarketplacePlugins(collection, limit)
|
||||
return response.data.plugins.map(plugin => getFormattedPlugin(plugin))
|
||||
},
|
||||
enabled,
|
||||
@@ -128,9 +143,7 @@ export const useFeaturedTriggersRecommendations = (enabled: boolean, limit = 15)
|
||||
|
||||
export const useInstalledPluginList = (disable?: boolean, pageSize = 100) => {
|
||||
const fetchPlugins = async ({ pageParam = 1 }) => {
|
||||
const response = await get<InstalledPluginListWithTotalResponse>(
|
||||
`/workspaces/current/plugin/list?page=${pageParam}&page_size=${pageSize}`,
|
||||
)
|
||||
const response = await fetchInstalledPluginList(pageParam as number, pageSize)
|
||||
return response
|
||||
}
|
||||
|
||||
@@ -183,11 +196,7 @@ export const useInstalledPluginList = (disable?: boolean, pageSize = 100) => {
|
||||
export const useInstalledLatestVersion = (pluginIds: string[]) => {
|
||||
return useQuery<InstalledLatestVersionResponse>({
|
||||
queryKey: [NAME_SPACE, 'installedLatestVersion', pluginIds],
|
||||
queryFn: () => post<InstalledLatestVersionResponse>('/workspaces/current/plugin/list/latest-versions', {
|
||||
body: {
|
||||
plugin_ids: pluginIds,
|
||||
},
|
||||
}),
|
||||
queryFn: () => fetchInstalledLatestVersion(pluginIds),
|
||||
enabled: !!pluginIds.length,
|
||||
initialData: pluginIds.length ? undefined : { versions: {} },
|
||||
})
|
||||
@@ -210,7 +219,7 @@ export const useInstallPackageFromMarketPlace = (options?: MutateOptions<Install
|
||||
return useMutation({
|
||||
...options,
|
||||
mutationFn: (uniqueIdentifier: string) => {
|
||||
return post<InstallPackageResponse>('/workspaces/current/plugin/install/marketplace', { body: { plugin_unique_identifiers: [uniqueIdentifier] } })
|
||||
return installPackageFromMarketplace(uniqueIdentifier)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -219,17 +228,15 @@ export const useUpdatePackageFromMarketPlace = (options?: MutateOptions<InstallP
|
||||
return useMutation({
|
||||
...options,
|
||||
mutationFn: (body: object) => {
|
||||
return post<InstallPackageResponse>('/workspaces/current/plugin/upgrade/marketplace', {
|
||||
body,
|
||||
})
|
||||
return updateFromMarketPlace(body as Record<string, string>)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const usePluginDeclarationFromMarketPlace = (pluginUniqueIdentifier: string) => {
|
||||
return useQuery({
|
||||
return useQuery<{ manifest: PluginDeclaration }>({
|
||||
queryKey: [NAME_SPACE, 'pluginDeclaration', pluginUniqueIdentifier],
|
||||
queryFn: () => get<{ manifest: PluginDeclaration }>('/workspaces/current/plugin/marketplace/pkg', { params: { plugin_unique_identifier: pluginUniqueIdentifier } }),
|
||||
queryFn: () => fetchPluginDeclarationFromMarketplace(pluginUniqueIdentifier),
|
||||
enabled: !!pluginUniqueIdentifier,
|
||||
})
|
||||
}
|
||||
@@ -238,7 +245,7 @@ export const useVersionListOfPlugin = (pluginID: string) => {
|
||||
return useQuery<{ data: VersionListResponse }>({
|
||||
enabled: !!pluginID,
|
||||
queryKey: [NAME_SPACE, 'versions', pluginID],
|
||||
queryFn: () => getMarketplace<{ data: VersionListResponse }>(`/plugins/${pluginID}/versions`, { params: { page: 1, page_size: 100 } }),
|
||||
queryFn: () => fetchPluginVersionList(pluginID),
|
||||
})
|
||||
}
|
||||
export const useInvalidateVersionListOfPlugin = () => {
|
||||
@@ -251,9 +258,7 @@ export const useInvalidateVersionListOfPlugin = () => {
|
||||
export const useInstallPackageFromLocal = () => {
|
||||
return useMutation({
|
||||
mutationFn: (uniqueIdentifier: string) => {
|
||||
return post<InstallPackageResponse>('/workspaces/current/plugin/install/pkg', {
|
||||
body: { plugin_unique_identifiers: [uniqueIdentifier] },
|
||||
})
|
||||
return installPackageFromLocal(uniqueIdentifier)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -266,14 +271,7 @@ export const useInstallPackageFromGitHub = () => {
|
||||
selectedPackage: string
|
||||
uniqueIdentifier: string
|
||||
}) => {
|
||||
return post<InstallPackageResponse>('/workspaces/current/plugin/install/github', {
|
||||
body: {
|
||||
repo: repoUrl,
|
||||
version: selectedVersion,
|
||||
package: selectedPackage,
|
||||
plugin_unique_identifier: uniqueIdentifier,
|
||||
},
|
||||
})
|
||||
return installPackageFromGitHub({ repoUrl, selectedVersion, selectedPackage, uniqueIdentifier })
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -283,11 +281,9 @@ export const useUploadGitHub = (payload: {
|
||||
version: string
|
||||
package: string
|
||||
}) => {
|
||||
return useQuery({
|
||||
return useQuery<uploadGitHubResponse>({
|
||||
queryKey: [NAME_SPACE, 'uploadGitHub', payload],
|
||||
queryFn: () => post<uploadGitHubResponse>('/workspaces/current/plugin/upload/github', {
|
||||
body: payload,
|
||||
}),
|
||||
queryFn: () => uploadGitHubPackage(payload),
|
||||
retry: 0,
|
||||
})
|
||||
}
|
||||
@@ -321,12 +317,10 @@ export const useInstallOrUpdate = ({
|
||||
// From local bundle don't have data.value.github_plugin_unique_identifier
|
||||
uniqueIdentifier = data.value.github_plugin_unique_identifier!
|
||||
if (!uniqueIdentifier) {
|
||||
const { unique_identifier } = await post<uploadGitHubResponse>('/workspaces/current/plugin/upload/github', {
|
||||
body: {
|
||||
repo: data.value.repo!,
|
||||
version: data.value.release! || data.value.version!,
|
||||
package: data.value.packages! || data.value.package!,
|
||||
},
|
||||
const { unique_identifier } = await uploadGitHubPackage({
|
||||
repo: data.value.repo!,
|
||||
version: data.value.release! || data.value.version!,
|
||||
package: data.value.packages! || data.value.package!,
|
||||
})
|
||||
uniqueIdentifier = data.value.github_plugin_unique_identifier! || unique_identifier
|
||||
// has the same version, but not installed
|
||||
@@ -339,13 +333,11 @@ export const useInstallOrUpdate = ({
|
||||
}
|
||||
}
|
||||
if (!isInstalled) {
|
||||
const { task_id, all_installed } = await post<InstallPackageResponse>('/workspaces/current/plugin/install/github', {
|
||||
body: {
|
||||
repo: data.value.repo!,
|
||||
version: data.value.release! || data.value.version!,
|
||||
package: data.value.packages! || data.value.package!,
|
||||
plugin_unique_identifier: uniqueIdentifier,
|
||||
},
|
||||
const { task_id, all_installed } = await installPackageFromGitHub({
|
||||
repoUrl: data.value.repo!,
|
||||
selectedVersion: data.value.release! || data.value.version!,
|
||||
selectedPackage: data.value.packages! || data.value.package!,
|
||||
uniqueIdentifier,
|
||||
})
|
||||
taskId = task_id
|
||||
isFinishedInstallation = all_installed
|
||||
@@ -362,11 +354,7 @@ export const useInstallOrUpdate = ({
|
||||
}
|
||||
}
|
||||
if (!isInstalled) {
|
||||
const { task_id, all_installed } = await post<InstallPackageResponse>('/workspaces/current/plugin/install/marketplace', {
|
||||
body: {
|
||||
plugin_unique_identifiers: [uniqueIdentifier],
|
||||
},
|
||||
})
|
||||
const { task_id, all_installed } = await installPackageFromMarketplace(uniqueIdentifier)
|
||||
taskId = task_id
|
||||
isFinishedInstallation = all_installed
|
||||
}
|
||||
@@ -382,11 +370,7 @@ export const useInstallOrUpdate = ({
|
||||
}
|
||||
}
|
||||
if (!isInstalled) {
|
||||
const { task_id, all_installed } = await post<InstallPackageResponse>('/workspaces/current/plugin/install/pkg', {
|
||||
body: {
|
||||
plugin_unique_identifiers: [uniqueIdentifier],
|
||||
},
|
||||
})
|
||||
const { task_id, all_installed } = await installPackageFromLocal(uniqueIdentifier)
|
||||
taskId = task_id
|
||||
isFinishedInstallation = all_installed
|
||||
}
|
||||
@@ -394,11 +378,7 @@ export const useInstallOrUpdate = ({
|
||||
if (isInstalled) {
|
||||
if (item.type === 'package') {
|
||||
await uninstallPlugin(installedPayload.installedId)
|
||||
const { task_id, all_installed } = await post<InstallPackageResponse>('/workspaces/current/plugin/install/pkg', {
|
||||
body: {
|
||||
plugin_unique_identifiers: [uniqueIdentifier],
|
||||
},
|
||||
})
|
||||
const { task_id, all_installed } = await installPackageFromLocal(uniqueIdentifier)
|
||||
taskId = task_id
|
||||
isFinishedInstallation = all_installed
|
||||
}
|
||||
@@ -437,9 +417,9 @@ export const useInstallOrUpdate = ({
|
||||
}
|
||||
|
||||
export const useDebugKey = () => {
|
||||
return useQuery({
|
||||
return useQuery<DebugInfoTypes>({
|
||||
queryKey: [NAME_SPACE, 'debugKey'],
|
||||
queryFn: () => get<DebugInfoTypes>('/workspaces/current/plugin/debugging-key'),
|
||||
queryFn: () => fetchDebugKey(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -447,7 +427,7 @@ const useReferenceSettingKey = [NAME_SPACE, 'referenceSettings']
|
||||
export const useReferenceSettings = () => {
|
||||
return useQuery({
|
||||
queryKey: useReferenceSettingKey,
|
||||
queryFn: () => get<ReferenceSetting>('/workspaces/current/plugin/preferences/fetch'),
|
||||
queryFn: () => fetchReferenceSettings(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -469,7 +449,7 @@ export const useMutationReferenceSettings = ({
|
||||
}) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: ReferenceSetting) => {
|
||||
return post('/workspaces/current/plugin/preferences/change', { body: payload })
|
||||
return updateReferenceSettings(payload)
|
||||
},
|
||||
onSuccess,
|
||||
})
|
||||
@@ -478,7 +458,7 @@ export const useMutationReferenceSettings = ({
|
||||
export const useRemoveAutoUpgrade = () => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: { plugin_id: string }) => {
|
||||
return post('/workspaces/current/plugin/preferences/autoupgrade/exclude', { body: payload })
|
||||
return excludeAutoUpgrade(payload)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -486,31 +466,7 @@ export const useRemoveAutoUpgrade = () => {
|
||||
export const useMutationPluginsFromMarketplace = () => {
|
||||
return useMutation({
|
||||
mutationFn: (pluginsSearchParams: PluginsSearchParams) => {
|
||||
const {
|
||||
query,
|
||||
sortBy,
|
||||
sortOrder,
|
||||
category,
|
||||
tags,
|
||||
exclude,
|
||||
type,
|
||||
page = 1,
|
||||
pageSize = 40,
|
||||
} = pluginsSearchParams
|
||||
const pluginOrBundle = type === 'bundle' ? 'bundles' : 'plugins'
|
||||
return postMarketplace<{ data: PluginsFromMarketplaceResponse }>(`/${pluginOrBundle}/search/advanced`, {
|
||||
body: {
|
||||
page,
|
||||
page_size: pageSize,
|
||||
query,
|
||||
sort_by: sortBy,
|
||||
sort_order: sortOrder,
|
||||
category: category !== 'all' ? category : '',
|
||||
tags,
|
||||
exclude,
|
||||
type,
|
||||
},
|
||||
})
|
||||
return searchMarketplacePlugins(pluginsSearchParams)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -519,11 +475,7 @@ export const useFetchPluginsInMarketPlaceByIds = (unique_identifiers: string[],
|
||||
return useQuery({
|
||||
...options,
|
||||
queryKey: [NAME_SPACE, 'fetchPluginsInMarketPlaceByIds', unique_identifiers],
|
||||
queryFn: () => postMarketplace<{ data: PluginsFromMarketplaceResponse }>('/plugins/identifier/batch', {
|
||||
body: {
|
||||
unique_identifiers,
|
||||
},
|
||||
}),
|
||||
queryFn: () => fetchMarketplacePluginsByIds(unique_identifiers),
|
||||
enabled: unique_identifiers?.filter(i => !!i).length > 0,
|
||||
retry: 0,
|
||||
})
|
||||
@@ -533,47 +485,15 @@ export const useFetchPluginListOrBundleList = (pluginsSearchParams: PluginsSearc
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'fetchPluginListOrBundleList', pluginsSearchParams],
|
||||
queryFn: () => {
|
||||
const {
|
||||
query,
|
||||
sortBy,
|
||||
sortOrder,
|
||||
category,
|
||||
tags,
|
||||
exclude,
|
||||
type,
|
||||
page = 1,
|
||||
pageSize = 40,
|
||||
} = pluginsSearchParams
|
||||
const pluginOrBundle = type === 'bundle' ? 'bundles' : 'plugins'
|
||||
return postMarketplace<{ data: PluginsFromMarketplaceResponse }>(`/${pluginOrBundle}/search/advanced`, {
|
||||
body: {
|
||||
page,
|
||||
page_size: pageSize,
|
||||
query,
|
||||
sort_by: sortBy,
|
||||
sort_order: sortOrder,
|
||||
category: category !== 'all' ? category : '',
|
||||
tags,
|
||||
exclude,
|
||||
type,
|
||||
},
|
||||
})
|
||||
return searchMarketplacePlugins(pluginsSearchParams)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const useFetchPluginsInMarketPlaceByInfo = (infos: Record<string, any>[]) => {
|
||||
return useQuery({
|
||||
return useQuery<{ data: PluginsFromMarketplaceByInfoResponse }>({
|
||||
queryKey: [NAME_SPACE, 'fetchPluginsInMarketPlaceByInfo', infos],
|
||||
queryFn: () => postMarketplace<{ data: PluginsFromMarketplaceByInfoResponse }>('/plugins/versions/batch', {
|
||||
body: {
|
||||
plugin_tuples: infos.map(info => ({
|
||||
org: info.organization,
|
||||
name: info.plugin,
|
||||
version: info.version,
|
||||
})),
|
||||
},
|
||||
}),
|
||||
queryFn: () => fetchMarketplacePluginsByInfo(infos),
|
||||
enabled: infos?.filter(i => !!i).length > 0,
|
||||
retry: 0,
|
||||
})
|
||||
@@ -592,10 +512,10 @@ export const usePluginTaskList = (category?: PluginCategoryEnum | string) => {
|
||||
isRefetching,
|
||||
refetch,
|
||||
...rest
|
||||
} = useQuery({
|
||||
} = useQuery<{ tasks: PluginTask[] }>({
|
||||
enabled: canManagement,
|
||||
queryKey: usePluginTaskListKey,
|
||||
queryFn: () => get<{ tasks: PluginTask[] }>('/workspaces/current/plugin/tasks?page=1&page_size=100'),
|
||||
queryFn: () => fetchPluginTaskList(),
|
||||
refetchInterval: (lastQuery) => {
|
||||
const lastData = lastQuery.state.data
|
||||
const taskDone = lastData?.tasks.every(task => task.status === TaskStatus.success || task.status === TaskStatus.failed)
|
||||
@@ -636,8 +556,7 @@ export const usePluginTaskList = (category?: PluginCategoryEnum | string) => {
|
||||
export const useMutationClearTaskPlugin = () => {
|
||||
return useMutation({
|
||||
mutationFn: ({ taskId, pluginId }: { taskId: string, pluginId: string }) => {
|
||||
const encodedPluginId = encodeURIComponent(pluginId)
|
||||
return post<{ success: boolean }>(`/workspaces/current/plugin/tasks/${taskId}/delete/${encodedPluginId}`)
|
||||
return deletePluginTask(taskId, pluginId)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -645,7 +564,7 @@ export const useMutationClearTaskPlugin = () => {
|
||||
export const useMutationClearAllTaskPlugin = () => {
|
||||
return useMutation({
|
||||
mutationFn: () => {
|
||||
return post<{ success: boolean }>('/workspaces/current/plugin/tasks/delete_all')
|
||||
return deleteAllPluginTasks()
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -654,7 +573,7 @@ export const usePluginManifestInfo = (pluginUID: string) => {
|
||||
return useQuery({
|
||||
enabled: !!pluginUID,
|
||||
queryKey: [[NAME_SPACE, 'manifest', pluginUID]],
|
||||
queryFn: () => getMarketplace<{ data: { plugin: PluginInfoFromMarketPlace, version: { version: string } } }>(`/plugins/${pluginUID}`),
|
||||
queryFn: () => fetchPluginManifestInfo(pluginUID),
|
||||
retry: 0,
|
||||
})
|
||||
}
|
||||
@@ -662,7 +581,7 @@ export const usePluginManifestInfo = (pluginUID: string) => {
|
||||
export const useDownloadPlugin = (info: { organization: string, pluginName: string, version: string }, needDownload: boolean) => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'downloadPlugin', info],
|
||||
queryFn: () => getMarketplace<Blob>(`/plugins/${info.organization}/${info.pluginName}/${info.version}/download`),
|
||||
queryFn: () => downloadPlugin(info),
|
||||
enabled: needDownload,
|
||||
retry: 0,
|
||||
})
|
||||
@@ -671,7 +590,7 @@ export const useDownloadPlugin = (info: { organization: string, pluginName: stri
|
||||
export const useMutationCheckDependencies = () => {
|
||||
return useMutation({
|
||||
mutationFn: (appId: string) => {
|
||||
return get<{ leaked_dependencies: Dependency[] }>(`/apps/imports/${appId}/check-dependencies`)
|
||||
return checkImportDependencies(appId)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -718,23 +637,14 @@ export const usePluginInfo = (providerName?: string) => {
|
||||
|
||||
export const useFetchDynamicOptions = (plugin_id: string, provider: string, action: string, parameter: string, provider_type?: string, extra?: Record<string, any>) => {
|
||||
return useMutation({
|
||||
mutationFn: () => get<{ options: FormOption[] }>('/workspaces/current/plugin/parameters/dynamic-options', {
|
||||
params: {
|
||||
plugin_id,
|
||||
provider,
|
||||
action,
|
||||
parameter,
|
||||
provider_type,
|
||||
...extra,
|
||||
},
|
||||
}),
|
||||
mutationFn: () => fetchPluginDynamicOptions({ plugin_id, provider, action, parameter, provider_type, extra }),
|
||||
})
|
||||
}
|
||||
|
||||
export const usePluginReadme = ({ plugin_unique_identifier, language }: { plugin_unique_identifier: string, language?: string }) => {
|
||||
return useQuery({
|
||||
queryKey: ['pluginReadme', plugin_unique_identifier, language],
|
||||
queryFn: () => get<{ readme: string }>('/workspaces/current/plugin/readme', { params: { plugin_unique_identifier, language } }, { silent: true }),
|
||||
queryFn: () => fetchPluginReadme({ plugin_unique_identifier, language }),
|
||||
enabled: !!plugin_unique_identifier,
|
||||
retry: 0,
|
||||
})
|
||||
@@ -744,7 +654,7 @@ export const usePluginReadmeAsset = ({ file_name, plugin_unique_identifier }: {
|
||||
const normalizedFileName = file_name?.replace(/(^\.\/_assets\/|^_assets\/)/, '')
|
||||
return useQuery({
|
||||
queryKey: ['pluginReadmeAsset', plugin_unique_identifier, normalizedFileName],
|
||||
queryFn: () => get<Blob>('/workspaces/current/plugin/asset', { params: { plugin_unique_identifier, file_name: normalizedFileName } }, { silent: true }),
|
||||
queryFn: () => fetchPluginAsset({ plugin_unique_identifier: plugin_unique_identifier || '', file_name: normalizedFileName || '' }),
|
||||
enabled: !!plugin_unique_identifier && !!file_name && /(^\.\/_assets|^_assets)/.test(file_name),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { QueryKey } from '@tanstack/react-query'
|
||||
import type { AppTrigger } from './tools'
|
||||
import type {
|
||||
Collection,
|
||||
MCPServerDetail,
|
||||
@@ -12,7 +13,31 @@ import {
|
||||
useQueryClient,
|
||||
} from '@tanstack/react-query'
|
||||
import { CollectionType } from '@/app/components/tools/types'
|
||||
import { del, get, post, put } from './base'
|
||||
import {
|
||||
authorizeMCPProvider,
|
||||
createMCPProvider,
|
||||
createMCPServer,
|
||||
deleteMCPProvider,
|
||||
fetchAllBuiltInTools,
|
||||
fetchAllCustomTools,
|
||||
fetchAllMCPTools,
|
||||
fetchAllWorkflowTools,
|
||||
fetchAppTriggers,
|
||||
fetchBuiltinProviderInfo,
|
||||
fetchBuiltinProviderTools,
|
||||
fetchCollectionList,
|
||||
fetchMCPProviderToken,
|
||||
fetchMCPProviderTools,
|
||||
fetchMCPServerDetail,
|
||||
fetchRAGRecommendedPlugins,
|
||||
refreshMCPServerCode,
|
||||
removeBuiltinProviderCredentials,
|
||||
updateAppTriggerStatus,
|
||||
updateBuiltinProviderCredentials,
|
||||
updateMCPProvider,
|
||||
updateMCPProviderTools,
|
||||
updateMCPServer,
|
||||
} from './tools'
|
||||
import { useInvalid } from './use-base'
|
||||
|
||||
const NAME_SPACE = 'tools'
|
||||
@@ -21,7 +46,7 @@ const useAllToolProvidersKey = [NAME_SPACE, 'allToolProviders']
|
||||
export const useAllToolProviders = (enabled = true) => {
|
||||
return useQuery<Collection[]>({
|
||||
queryKey: useAllToolProvidersKey,
|
||||
queryFn: () => get<Collection[]>('/workspaces/current/tool-providers'),
|
||||
queryFn: () => fetchCollectionList(),
|
||||
enabled,
|
||||
})
|
||||
}
|
||||
@@ -34,7 +59,7 @@ const useAllBuiltInToolsKey = [NAME_SPACE, 'builtIn']
|
||||
export const useAllBuiltInTools = () => {
|
||||
return useQuery<ToolWithProvider[]>({
|
||||
queryKey: useAllBuiltInToolsKey,
|
||||
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/builtin'),
|
||||
queryFn: () => fetchAllBuiltInTools(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -46,7 +71,7 @@ const useAllCustomToolsKey = [NAME_SPACE, 'customTools']
|
||||
export const useAllCustomTools = () => {
|
||||
return useQuery<ToolWithProvider[]>({
|
||||
queryKey: useAllCustomToolsKey,
|
||||
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/api'),
|
||||
queryFn: () => fetchAllCustomTools(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -58,7 +83,7 @@ const useAllWorkflowToolsKey = [NAME_SPACE, 'workflowTools']
|
||||
export const useAllWorkflowTools = () => {
|
||||
return useQuery<ToolWithProvider[]>({
|
||||
queryKey: useAllWorkflowToolsKey,
|
||||
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/workflow'),
|
||||
queryFn: () => fetchAllWorkflowTools(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -70,7 +95,7 @@ const useAllMCPToolsKey = [NAME_SPACE, 'MCPTools']
|
||||
export const useAllMCPTools = () => {
|
||||
return useQuery<ToolWithProvider[]>({
|
||||
queryKey: useAllMCPToolsKey,
|
||||
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/mcp'),
|
||||
queryFn: () => fetchAllMCPTools(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -102,11 +127,7 @@ export const useCreateMCP = () => {
|
||||
sse_read_timeout?: number
|
||||
headers?: Record<string, string>
|
||||
}) => {
|
||||
return post<ToolWithProvider>('workspaces/current/tool-provider/mcp', {
|
||||
body: {
|
||||
...payload,
|
||||
},
|
||||
})
|
||||
return createMCPProvider(payload)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -129,11 +150,7 @@ export const useUpdateMCP = ({
|
||||
sse_read_timeout?: number
|
||||
headers?: Record<string, string>
|
||||
}) => {
|
||||
return put('workspaces/current/tool-provider/mcp', {
|
||||
body: {
|
||||
...payload,
|
||||
},
|
||||
})
|
||||
return updateMCPProvider(payload)
|
||||
},
|
||||
onSuccess,
|
||||
})
|
||||
@@ -147,11 +164,7 @@ export const useDeleteMCP = ({
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'delete-mcp'],
|
||||
mutationFn: (id: string) => {
|
||||
return del('/workspaces/current/tool-provider/mcp', {
|
||||
body: {
|
||||
provider_id: id,
|
||||
},
|
||||
})
|
||||
return deleteMCPProvider(id)
|
||||
},
|
||||
onSuccess,
|
||||
})
|
||||
@@ -161,9 +174,7 @@ export const useAuthorizeMCP = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'authorize-mcp'],
|
||||
mutationFn: (payload: { provider_id: string }) => {
|
||||
return post<{ result?: string, authorization_url?: string }>('/workspaces/current/tool-provider/mcp/auth', {
|
||||
body: payload,
|
||||
})
|
||||
return authorizeMCPProvider(payload)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -172,20 +183,16 @@ export const useUpdateMCPAuthorizationToken = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'refresh-mcp-server-code'],
|
||||
mutationFn: (payload: { provider_id: string, authorization_code: string }) => {
|
||||
return get<MCPServerDetail>('/workspaces/current/tool-provider/mcp/token', {
|
||||
params: {
|
||||
...payload,
|
||||
},
|
||||
})
|
||||
return fetchMCPProviderToken(payload)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const useMCPTools = (providerID: string) => {
|
||||
return useQuery({
|
||||
return useQuery<{ tools: Tool[] }>({
|
||||
enabled: !!providerID,
|
||||
queryKey: [NAME_SPACE, 'get-MCP-provider-tool', providerID],
|
||||
queryFn: () => get<{ tools: Tool[] }>(`/workspaces/current/tool-provider/mcp/tools/${providerID}`),
|
||||
queryFn: () => fetchMCPProviderTools(providerID),
|
||||
})
|
||||
}
|
||||
export const useInvalidateMCPTools = () => {
|
||||
@@ -201,14 +208,14 @@ export const useInvalidateMCPTools = () => {
|
||||
|
||||
export const useUpdateMCPTools = () => {
|
||||
return useMutation({
|
||||
mutationFn: (providerID: string) => get<{ tools: Tool[] }>(`/workspaces/current/tool-provider/mcp/update/${providerID}`),
|
||||
mutationFn: (providerID: string) => updateMCPProviderTools(providerID),
|
||||
})
|
||||
}
|
||||
|
||||
export const useMCPServerDetail = (appID: string) => {
|
||||
return useQuery<MCPServerDetail>({
|
||||
queryKey: [NAME_SPACE, 'MCPServerDetail', appID],
|
||||
queryFn: () => get<MCPServerDetail>(`/apps/${appID}/server`),
|
||||
queryFn: () => fetchMCPServerDetail(appID),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -231,12 +238,7 @@ export const useCreateMCPServer = () => {
|
||||
description?: string
|
||||
parameters?: Record<string, string>
|
||||
}) => {
|
||||
const { appID, ...rest } = payload
|
||||
return post(`apps/${appID}/server`, {
|
||||
body: {
|
||||
...rest,
|
||||
},
|
||||
})
|
||||
return createMCPServer(payload)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -251,12 +253,7 @@ export const useUpdateMCPServer = () => {
|
||||
status?: string
|
||||
parameters?: Record<string, string>
|
||||
}) => {
|
||||
const { appID, ...rest } = payload
|
||||
return put(`apps/${appID}/server`, {
|
||||
body: {
|
||||
...rest,
|
||||
},
|
||||
})
|
||||
return updateMCPServer(payload)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -265,7 +262,7 @@ export const useRefreshMCPServerCode = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'refresh-mcp-server-code'],
|
||||
mutationFn: (appID: string) => {
|
||||
return get<MCPServerDetail>(`apps/${appID}/server/refresh`)
|
||||
return refreshMCPServerCode(appID)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -273,7 +270,7 @@ export const useRefreshMCPServerCode = () => {
|
||||
export const useBuiltinProviderInfo = (providerName: string) => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'builtin-provider-info', providerName],
|
||||
queryFn: () => get<Collection>(`/workspaces/current/tool-provider/builtin/${providerName}/info`),
|
||||
queryFn: () => fetchBuiltinProviderInfo(providerName),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -292,7 +289,7 @@ export const useBuiltinTools = (providerName: string) => {
|
||||
return useQuery({
|
||||
enabled: !!providerName,
|
||||
queryKey: [NAME_SPACE, 'builtin-provider-tools', providerName],
|
||||
queryFn: () => get<Tool[]>(`/workspaces/current/tool-provider/builtin/${providerName}/tools`),
|
||||
queryFn: () => fetchBuiltinProviderTools(providerName),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -304,12 +301,7 @@ export const useUpdateProviderCredentials = ({
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'update-provider-credentials'],
|
||||
mutationFn: (payload: { providerName: string, credentials: Record<string, any> }) => {
|
||||
const { providerName, credentials } = payload
|
||||
return post(`/workspaces/current/tool-provider/builtin/${providerName}/update`, {
|
||||
body: {
|
||||
credentials,
|
||||
},
|
||||
})
|
||||
return updateBuiltinProviderCredentials(payload)
|
||||
},
|
||||
onSuccess,
|
||||
})
|
||||
@@ -323,9 +315,7 @@ export const useRemoveProviderCredentials = ({
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'remove-provider-credentials'],
|
||||
mutationFn: (providerName: string) => {
|
||||
return post(`/workspaces/current/tool-provider/builtin/${providerName}/delete`, {
|
||||
body: {},
|
||||
})
|
||||
return removeBuiltinProviderCredentials(providerName)
|
||||
},
|
||||
onSuccess,
|
||||
})
|
||||
@@ -336,11 +326,7 @@ const useRAGRecommendedPluginListKey = [NAME_SPACE, 'rag-recommended-plugins']
|
||||
export const useRAGRecommendedPlugins = (type: 'tool' | 'datasource' | 'all' = 'all') => {
|
||||
return useQuery<RAGRecommendedPlugins>({
|
||||
queryKey: [...useRAGRecommendedPluginListKey, type],
|
||||
queryFn: () => get<RAGRecommendedPlugins>('/rag/pipelines/recommended-plugins', {
|
||||
params: {
|
||||
type,
|
||||
},
|
||||
}),
|
||||
queryFn: () => fetchRAGRecommendedPlugins(type),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -354,22 +340,10 @@ export const useInvalidateRAGRecommendedPlugins = () => {
|
||||
}
|
||||
|
||||
// App Triggers API hooks
|
||||
export type AppTrigger = {
|
||||
id: string
|
||||
trigger_type: 'trigger-webhook' | 'trigger-schedule' | 'trigger-plugin'
|
||||
title: string
|
||||
node_id: string
|
||||
provider_name: string
|
||||
icon: string
|
||||
status: 'enabled' | 'disabled' | 'unauthorized'
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export const useAppTriggers = (appId: string | undefined, options?: any) => {
|
||||
return useQuery<{ data: AppTrigger[] }>({
|
||||
queryKey: [NAME_SPACE, 'app-triggers', appId],
|
||||
queryFn: () => get<{ data: AppTrigger[] }>(`/apps/${appId}/triggers`),
|
||||
queryFn: () => fetchAppTriggers(appId || ''),
|
||||
enabled: !!appId,
|
||||
...options, // Merge additional options while maintaining backward compatibility
|
||||
})
|
||||
@@ -392,13 +366,9 @@ export const useUpdateTriggerStatus = () => {
|
||||
triggerId: string
|
||||
enableTrigger: boolean
|
||||
}) => {
|
||||
const { appId, triggerId, enableTrigger } = payload
|
||||
return post<AppTrigger>(`/apps/${appId}/trigger-enable`, {
|
||||
body: {
|
||||
trigger_id: triggerId,
|
||||
enable_trigger: enableTrigger,
|
||||
},
|
||||
})
|
||||
return updateAppTriggerStatus(payload)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export type { AppTrigger } from './tools'
|
||||
|
||||
@@ -5,12 +5,30 @@ import type {
|
||||
TriggerOAuthConfig,
|
||||
TriggerProviderApiEntity,
|
||||
TriggerSubscription,
|
||||
TriggerSubscriptionBuilder,
|
||||
TriggerWithProvider,
|
||||
} from '@/app/components/workflow/block-selector/types'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { CollectionType } from '@/app/components/tools/types'
|
||||
import { del, get, post } from './base'
|
||||
import {
|
||||
buildTriggerSubscription,
|
||||
configureTriggerOAuth,
|
||||
createTriggerSubscriptionBuilder,
|
||||
deleteTriggerOAuth,
|
||||
deleteTriggerSubscription,
|
||||
fetchTriggerDynamicOptions,
|
||||
fetchTriggerDynamicOptionsWithCredentials,
|
||||
fetchTriggerOAuthConfig,
|
||||
fetchTriggerProviderInfo,
|
||||
fetchTriggerProviders,
|
||||
fetchTriggerProvidersByType,
|
||||
fetchTriggerSubscriptionBuilderLogs,
|
||||
fetchTriggerSubscriptions,
|
||||
initiateTriggerOAuth,
|
||||
updateTriggerSubscription,
|
||||
updateTriggerSubscriptionBuilder,
|
||||
verifyAndUpdateTriggerSubscriptionBuilder,
|
||||
verifyTriggerSubscription,
|
||||
} from './triggers'
|
||||
import { useInvalid } from './use-base'
|
||||
|
||||
const NAME_SPACE = 'triggers'
|
||||
@@ -74,7 +92,7 @@ export const useAllTriggerPlugins = (enabled = true) => {
|
||||
return useQuery<TriggerWithProvider[]>({
|
||||
queryKey: [NAME_SPACE, 'all'],
|
||||
queryFn: async () => {
|
||||
const response = await get<TriggerProviderApiEntity[]>('/workspaces/current/triggers')
|
||||
const response = await fetchTriggerProviders()
|
||||
return response.map(convertToTriggerWithProvider)
|
||||
},
|
||||
enabled,
|
||||
@@ -87,7 +105,7 @@ export const useTriggerPluginsByType = (triggerType: string, enabled = true) =>
|
||||
return useQuery<TriggerWithProvider[]>({
|
||||
queryKey: [NAME_SPACE, 'byType', triggerType],
|
||||
queryFn: async () => {
|
||||
const response = await get<TriggerProviderApiEntity[]>(`/workspaces/current/triggers?type=${triggerType}`)
|
||||
const response = await fetchTriggerProvidersByType(triggerType)
|
||||
return response.map(convertToTriggerWithProvider)
|
||||
},
|
||||
enabled: enabled && !!triggerType,
|
||||
@@ -103,7 +121,7 @@ export const useInvalidateAllTriggerPlugins = () => {
|
||||
export const useTriggerProviderInfo = (provider: string, enabled = true) => {
|
||||
return useQuery<TriggerProviderApiEntity>({
|
||||
queryKey: [NAME_SPACE, 'provider-info', provider],
|
||||
queryFn: () => get<TriggerProviderApiEntity>(`/workspaces/current/trigger-provider/${provider}/info`),
|
||||
queryFn: () => fetchTriggerProviderInfo(provider),
|
||||
enabled: enabled && !!provider,
|
||||
staleTime: 0,
|
||||
gcTime: 0,
|
||||
@@ -113,7 +131,7 @@ export const useTriggerProviderInfo = (provider: string, enabled = true) => {
|
||||
export const useTriggerSubscriptions = (provider: string, enabled = true) => {
|
||||
return useQuery<TriggerSubscription[]>({
|
||||
queryKey: [NAME_SPACE, 'list-subscriptions', provider],
|
||||
queryFn: () => get<TriggerSubscription[]>(`/workspaces/current/trigger-provider/${provider}/subscriptions/list`),
|
||||
queryFn: () => fetchTriggerSubscriptions(provider),
|
||||
enabled: enabled && !!provider,
|
||||
})
|
||||
}
|
||||
@@ -134,11 +152,7 @@ export const useCreateTriggerSubscriptionBuilder = () => {
|
||||
provider: string
|
||||
credential_type?: string
|
||||
}) => {
|
||||
const { provider, ...body } = payload
|
||||
return post<{ subscription_builder: TriggerSubscriptionBuilder }>(
|
||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/builder/create`,
|
||||
{ body },
|
||||
)
|
||||
return createTriggerSubscriptionBuilder(payload)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -154,11 +168,7 @@ export const useUpdateTriggerSubscriptionBuilder = () => {
|
||||
parameters?: Record<string, unknown>
|
||||
credentials?: Record<string, unknown>
|
||||
}) => {
|
||||
const { provider, subscriptionBuilderId, ...body } = payload
|
||||
return post<TriggerSubscriptionBuilder>(
|
||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/builder/update/${subscriptionBuilderId}`,
|
||||
{ body },
|
||||
)
|
||||
return updateTriggerSubscriptionBuilder(payload)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -171,12 +181,7 @@ export const useVerifyAndUpdateTriggerSubscriptionBuilder = () => {
|
||||
subscriptionBuilderId: string
|
||||
credentials?: Record<string, unknown>
|
||||
}) => {
|
||||
const { provider, subscriptionBuilderId, ...body } = payload
|
||||
return post<{ verified: boolean }>(
|
||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/builder/verify-and-update/${subscriptionBuilderId}`,
|
||||
{ body },
|
||||
{ silent: true },
|
||||
)
|
||||
return verifyAndUpdateTriggerSubscriptionBuilder(payload)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -189,12 +194,7 @@ export const useVerifyTriggerSubscription = () => {
|
||||
subscriptionId: string
|
||||
credentials?: Record<string, unknown>
|
||||
}) => {
|
||||
const { provider, subscriptionId, ...body } = payload
|
||||
return post<{ verified: boolean }>(
|
||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/verify/${subscriptionId}`,
|
||||
{ body },
|
||||
{ silent: true },
|
||||
)
|
||||
return verifyTriggerSubscription(payload)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -210,11 +210,7 @@ export const useBuildTriggerSubscription = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'build-subscription'],
|
||||
mutationFn: (payload: BuildTriggerSubscriptionPayload) => {
|
||||
const { provider, subscriptionBuilderId, ...body } = payload
|
||||
return post(
|
||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/builder/build/${subscriptionBuilderId}`,
|
||||
{ body },
|
||||
)
|
||||
return buildTriggerSubscription(payload)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -223,9 +219,7 @@ export const useDeleteTriggerSubscription = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'delete-subscription'],
|
||||
mutationFn: (subscriptionId: string) => {
|
||||
return post<{ result: string }>(
|
||||
`/workspaces/current/trigger-provider/${subscriptionId}/subscriptions/delete`,
|
||||
)
|
||||
return deleteTriggerSubscription(subscriptionId)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -242,11 +236,7 @@ export const useUpdateTriggerSubscription = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'update-subscription'],
|
||||
mutationFn: (payload: UpdateTriggerSubscriptionPayload) => {
|
||||
const { subscriptionId, ...body } = payload
|
||||
return post<{ result: string, id: string }>(
|
||||
`/workspaces/current/trigger-provider/${subscriptionId}/subscriptions/update`,
|
||||
{ body },
|
||||
)
|
||||
return updateTriggerSubscription(payload)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -263,9 +253,7 @@ export const useTriggerSubscriptionBuilderLogs = (
|
||||
|
||||
return useQuery<{ logs: TriggerLogEntity[] }>({
|
||||
queryKey: [NAME_SPACE, 'subscription-builder-logs', provider, subscriptionBuilderId],
|
||||
queryFn: () => get(
|
||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/builder/logs/${subscriptionBuilderId}`,
|
||||
),
|
||||
queryFn: () => fetchTriggerSubscriptionBuilderLogs(provider, subscriptionBuilderId),
|
||||
enabled: enabled && !!provider && !!subscriptionBuilderId,
|
||||
refetchInterval,
|
||||
})
|
||||
@@ -275,7 +263,7 @@ export const useTriggerSubscriptionBuilderLogs = (
|
||||
export const useTriggerOAuthConfig = (provider: string, enabled = true) => {
|
||||
return useQuery<TriggerOAuthConfig>({
|
||||
queryKey: [NAME_SPACE, 'oauth-config', provider],
|
||||
queryFn: () => get<TriggerOAuthConfig>(`/workspaces/current/trigger-provider/${provider}/oauth/client`),
|
||||
queryFn: () => fetchTriggerOAuthConfig(provider),
|
||||
enabled: enabled && !!provider,
|
||||
})
|
||||
}
|
||||
@@ -290,11 +278,7 @@ export const useConfigureTriggerOAuth = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'configure-oauth'],
|
||||
mutationFn: (payload: ConfigureTriggerOAuthPayload) => {
|
||||
const { provider, ...body } = payload
|
||||
return post<{ result: string }>(
|
||||
`/workspaces/current/trigger-provider/${provider}/oauth/client`,
|
||||
{ body },
|
||||
)
|
||||
return configureTriggerOAuth(payload)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -303,9 +287,7 @@ export const useDeleteTriggerOAuth = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'delete-oauth'],
|
||||
mutationFn: (provider: string) => {
|
||||
return del<{ result: string }>(
|
||||
`/workspaces/current/trigger-provider/${provider}/oauth/client`,
|
||||
)
|
||||
return deleteTriggerOAuth(provider)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -314,11 +296,7 @@ export const useInitiateTriggerOAuth = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'initiate-oauth'],
|
||||
mutationFn: (provider: string) => {
|
||||
return get<{ authorization_url: string, subscription_builder: TriggerSubscriptionBuilder }>(
|
||||
`/workspaces/current/trigger-provider/${provider}/subscriptions/oauth/authorize`,
|
||||
{},
|
||||
{ silent: true },
|
||||
)
|
||||
return initiateTriggerOAuth(provider)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -338,36 +316,24 @@ export const useTriggerPluginDynamicOptions = (payload: {
|
||||
queryFn: () => {
|
||||
// Use new endpoint with POST when credentials provided (for edit mode)
|
||||
if (payload.credentials) {
|
||||
return post<{ options: FormOption[] }>(
|
||||
'/workspaces/current/plugin/parameters/dynamic-options-with-credentials',
|
||||
{
|
||||
body: {
|
||||
plugin_id: payload.plugin_id,
|
||||
provider: payload.provider,
|
||||
action: payload.action,
|
||||
parameter: payload.parameter,
|
||||
credential_id: payload.credential_id,
|
||||
credentials: payload.credentials,
|
||||
},
|
||||
},
|
||||
{ silent: true },
|
||||
)
|
||||
return fetchTriggerDynamicOptionsWithCredentials({
|
||||
plugin_id: payload.plugin_id,
|
||||
provider: payload.provider,
|
||||
action: payload.action,
|
||||
parameter: payload.parameter,
|
||||
credential_id: payload.credential_id,
|
||||
credentials: payload.credentials,
|
||||
})
|
||||
}
|
||||
// Use original GET endpoint for normal cases
|
||||
return get<{ options: FormOption[] }>(
|
||||
'/workspaces/current/plugin/parameters/dynamic-options',
|
||||
{
|
||||
params: {
|
||||
plugin_id: payload.plugin_id,
|
||||
provider: payload.provider,
|
||||
action: payload.action,
|
||||
parameter: payload.parameter,
|
||||
credential_id: payload.credential_id,
|
||||
provider_type: 'trigger',
|
||||
},
|
||||
},
|
||||
{ silent: true },
|
||||
)
|
||||
return fetchTriggerDynamicOptions({
|
||||
plugin_id: payload.plugin_id,
|
||||
provider: payload.provider,
|
||||
action: payload.action,
|
||||
parameter: payload.parameter,
|
||||
credential_id: payload.credential_id,
|
||||
extra: payload.extra,
|
||||
})
|
||||
},
|
||||
enabled: enabled && !!payload.plugin_id && !!payload.provider && !!payload.action && !!payload.parameter && !!payload.credential_id,
|
||||
retry: 0,
|
||||
|
||||
@@ -1,20 +1,32 @@
|
||||
import type { CommonResponse } from '@/models/common'
|
||||
import type { FlowType } from '@/types/common'
|
||||
import type {
|
||||
FetchWorkflowDraftPageParams,
|
||||
FetchWorkflowDraftPageResponse,
|
||||
FetchWorkflowDraftResponse,
|
||||
NodeTracing,
|
||||
PublishWorkflowParams,
|
||||
UpdateWorkflowParams,
|
||||
VarInInspect,
|
||||
WorkflowConfigResponse,
|
||||
WorkflowRunHistoryResponse,
|
||||
} from '@/types/workflow'
|
||||
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { del, get, patch, post, put } from './base'
|
||||
import { useInvalid, useReset } from './use-base'
|
||||
import { getFlowPrefix } from './utils'
|
||||
import {
|
||||
deleteAllInspectorVars,
|
||||
deleteInspectorVar,
|
||||
deleteNodeInspectorVars,
|
||||
deleteWorkflow,
|
||||
editInspectorVar,
|
||||
fetchAppWorkflow,
|
||||
fetchConversationVarValues,
|
||||
fetchLastRun,
|
||||
fetchSysVarValues,
|
||||
fetchWorkflowConfig,
|
||||
fetchWorkflowRunHistory,
|
||||
fetchWorkflowVersionHistory,
|
||||
publishWorkflow,
|
||||
resetConversationVar,
|
||||
updateWorkflow,
|
||||
} from './workflow'
|
||||
|
||||
const NAME_SPACE = 'workflow'
|
||||
|
||||
@@ -22,14 +34,14 @@ export const useAppWorkflow = (appID: string) => {
|
||||
return useQuery<FetchWorkflowDraftResponse>({
|
||||
enabled: !!appID,
|
||||
queryKey: [NAME_SPACE, 'publish', appID],
|
||||
queryFn: () => get<FetchWorkflowDraftResponse>(`/apps/${appID}/workflows/publish`),
|
||||
queryFn: () => fetchAppWorkflow(appID),
|
||||
})
|
||||
}
|
||||
|
||||
export const useWorkflowRunHistory = (url?: string, enabled = true) => {
|
||||
return useQuery<WorkflowRunHistoryResponse>({
|
||||
queryKey: [NAME_SPACE, 'runHistory', url],
|
||||
queryFn: () => get<WorkflowRunHistoryResponse>(url as string),
|
||||
queryFn: () => fetchWorkflowRunHistory(url as string),
|
||||
enabled: !!url && enabled,
|
||||
})
|
||||
}
|
||||
@@ -51,7 +63,7 @@ export const useWorkflowConfig = <T = WorkflowConfigResponse>(url: string, onSuc
|
||||
queryKey: [NAME_SPACE, 'config', url],
|
||||
staleTime: 0,
|
||||
queryFn: async () => {
|
||||
const data = await get<T>(url)
|
||||
const data = await fetchWorkflowConfig<T>(url)
|
||||
onSuccess(data)
|
||||
return data
|
||||
},
|
||||
@@ -65,13 +77,11 @@ export const useWorkflowVersionHistory = (params: FetchWorkflowDraftPageParams)
|
||||
return useInfiniteQuery({
|
||||
enabled: !!url,
|
||||
queryKey: [...WorkflowVersionHistoryKey, url, initialPage, limit, userId, namedOnly],
|
||||
queryFn: ({ pageParam = 1 }) => get<FetchWorkflowDraftPageResponse>(url, {
|
||||
params: {
|
||||
page: pageParam,
|
||||
limit,
|
||||
user_id: userId || '',
|
||||
named_only: !!namedOnly,
|
||||
},
|
||||
queryFn: ({ pageParam = 1 }) => fetchWorkflowVersionHistory(url, {
|
||||
page: pageParam,
|
||||
limit,
|
||||
user_id: userId || '',
|
||||
named_only: !!namedOnly,
|
||||
}),
|
||||
getNextPageParam: lastPage => lastPage.has_more ? lastPage.page + 1 : null,
|
||||
initialPageParam: initialPage,
|
||||
@@ -85,31 +95,21 @@ export const useResetWorkflowVersionHistory = () => {
|
||||
export const useUpdateWorkflow = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'update'],
|
||||
mutationFn: (params: UpdateWorkflowParams) => patch(params.url, {
|
||||
body: {
|
||||
marked_name: params.title,
|
||||
marked_comment: params.releaseNotes,
|
||||
},
|
||||
}),
|
||||
mutationFn: (params: UpdateWorkflowParams) => updateWorkflow(params),
|
||||
})
|
||||
}
|
||||
|
||||
export const useDeleteWorkflow = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'delete'],
|
||||
mutationFn: (url: string) => del(url),
|
||||
mutationFn: (url: string) => deleteWorkflow(url),
|
||||
})
|
||||
}
|
||||
|
||||
export const usePublishWorkflow = () => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'publish'],
|
||||
mutationFn: (params: PublishWorkflowParams) => post<CommonResponse & { created_at: number }>(params.url, {
|
||||
body: {
|
||||
marked_name: params.title,
|
||||
marked_comment: params.releaseNotes,
|
||||
},
|
||||
}),
|
||||
mutationFn: (params: PublishWorkflowParams) => publishWorkflow(params),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -119,9 +119,7 @@ export const useLastRun = (flowType: FlowType, flowId: string, nodeId: string, e
|
||||
enabled,
|
||||
queryKey: [...useLastRunKey, flowType, flowId, nodeId],
|
||||
queryFn: async () => {
|
||||
return get(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/nodes/${nodeId}/last-run`, {}, {
|
||||
silent: true,
|
||||
})
|
||||
return fetchLastRun(flowType, flowId, nodeId)
|
||||
},
|
||||
retry: 0,
|
||||
})
|
||||
@@ -141,8 +139,7 @@ export const useConversationVarValues = (flowType?: FlowType, flowId?: string) =
|
||||
enabled: !!flowId,
|
||||
queryKey: [NAME_SPACE, flowType, 'conversation var values', flowId],
|
||||
queryFn: async () => {
|
||||
const { items } = (await get(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/conversation-variables`)) as { items: VarInInspect[] }
|
||||
return items
|
||||
return fetchConversationVarValues(flowType as FlowType, flowId as string)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -155,7 +152,7 @@ export const useResetConversationVar = (flowType: FlowType, flowId: string) => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, flowType, 'reset conversation var', flowId],
|
||||
mutationFn: async (varId: string) => {
|
||||
return put(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables/${varId}/reset`)
|
||||
return resetConversationVar(flowType, flowId, varId)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -164,7 +161,7 @@ export const useResetToLastRunValue = (flowType: FlowType, flowId: string) => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, flowType, 'reset to last run value', flowId],
|
||||
mutationFn: async (varId: string): Promise<{ value: any }> => {
|
||||
return put(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables/${varId}/reset`)
|
||||
return resetConversationVar(flowType, flowId, varId) as Promise<{ value: any }>
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -175,8 +172,7 @@ export const useSysVarValues = (flowType?: FlowType, flowId?: string) => {
|
||||
enabled: !!flowId,
|
||||
queryKey: [NAME_SPACE, flowType, 'sys var values', flowId],
|
||||
queryFn: async () => {
|
||||
const { items } = (await get(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/system-variables`)) as { items: VarInInspect[] }
|
||||
return items
|
||||
return fetchSysVarValues(flowType as FlowType, flowId as string)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -189,7 +185,7 @@ export const useDeleteAllInspectorVars = (flowType: FlowType, flowId: string) =>
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, flowType, 'delete all inspector vars', flowId],
|
||||
mutationFn: async () => {
|
||||
return del(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables`)
|
||||
return deleteAllInspectorVars(flowType, flowId)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -198,7 +194,7 @@ export const useDeleteNodeInspectorVars = (flowType: FlowType, flowId: string) =
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, flowType, 'delete node inspector vars', flowId],
|
||||
mutationFn: async (nodeId: string) => {
|
||||
return del(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/nodes/${nodeId}/variables`)
|
||||
return deleteNodeInspectorVars(flowType, flowId, nodeId)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -207,7 +203,7 @@ export const useDeleteInspectVar = (flowType: FlowType, flowId: string) => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, flowType, 'delete inspector var', flowId],
|
||||
mutationFn: async (varId: string) => {
|
||||
return del(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables/${varId}`)
|
||||
return deleteInspectorVar(flowType, flowId, varId)
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -221,9 +217,7 @@ export const useEditInspectorVar = (flowType: FlowType, flowId: string) => {
|
||||
name?: string
|
||||
value?: any
|
||||
}) => {
|
||||
return patch(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables/${varId}`, {
|
||||
body: rest,
|
||||
})
|
||||
return editInspectorVar(flowType, flowId, { varId, ...rest })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,17 +3,99 @@ import type { CommonResponse } from '@/models/common'
|
||||
import type { FlowType } from '@/types/common'
|
||||
import type {
|
||||
ConversationVariableResponse,
|
||||
FetchWorkflowDraftPageResponse,
|
||||
FetchWorkflowDraftResponse,
|
||||
NodesDefaultConfigsResponse,
|
||||
NodeTracing,
|
||||
PublishWorkflowParams,
|
||||
UpdateWorkflowParams,
|
||||
VarInInspect,
|
||||
WorkflowRunHistoryResponse,
|
||||
} from '@/types/workflow'
|
||||
import { get, post } from './base'
|
||||
import { del, get, patch, post, put } from './base'
|
||||
import { getFlowPrefix } from './utils'
|
||||
|
||||
export const fetchWorkflowDraft = (url: string) => {
|
||||
return get(url, {}, { silent: true }) as Promise<FetchWorkflowDraftResponse>
|
||||
}
|
||||
|
||||
export const fetchAppWorkflow = (appID: string) => {
|
||||
return get<FetchWorkflowDraftResponse>(`/apps/${appID}/workflows/publish`)
|
||||
}
|
||||
|
||||
export const fetchWorkflowRunHistory = (url: string) => {
|
||||
return get<WorkflowRunHistoryResponse>(url)
|
||||
}
|
||||
|
||||
export const fetchWorkflowConfig = <T>(url: string) => {
|
||||
return get<T>(url)
|
||||
}
|
||||
|
||||
export const fetchWorkflowVersionHistory = (url: string, params: { page: number, limit: number, user_id?: string, named_only?: boolean }) => {
|
||||
return get<FetchWorkflowDraftPageResponse>(url, { params })
|
||||
}
|
||||
|
||||
export const updateWorkflow = (params: UpdateWorkflowParams) => {
|
||||
return patch(params.url, {
|
||||
body: {
|
||||
marked_name: params.title,
|
||||
marked_comment: params.releaseNotes,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteWorkflow = (url: string) => {
|
||||
return del(url)
|
||||
}
|
||||
|
||||
export const publishWorkflow = (params: PublishWorkflowParams) => {
|
||||
return post<CommonResponse & { created_at: number }>(params.url, {
|
||||
body: {
|
||||
marked_name: params.title,
|
||||
marked_comment: params.releaseNotes,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchLastRun = (flowType: FlowType, flowId: string, nodeId: string) => {
|
||||
return get<NodeTracing>(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/nodes/${nodeId}/last-run`, {}, {
|
||||
silent: true,
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchConversationVarValues = async (flowType: FlowType, flowId: string) => {
|
||||
const { items } = (await get(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/conversation-variables`)) as { items: VarInInspect[] }
|
||||
return items
|
||||
}
|
||||
|
||||
export const resetConversationVar = (flowType: FlowType, flowId: string, varId: string) => {
|
||||
return put(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables/${varId}/reset`)
|
||||
}
|
||||
|
||||
export const fetchSysVarValues = async (flowType: FlowType, flowId: string) => {
|
||||
const { items } = (await get(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/system-variables`)) as { items: VarInInspect[] }
|
||||
return items
|
||||
}
|
||||
|
||||
export const deleteAllInspectorVars = (flowType: FlowType, flowId: string) => {
|
||||
return del(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables`)
|
||||
}
|
||||
|
||||
export const deleteNodeInspectorVars = (flowType: FlowType, flowId: string, nodeId: string) => {
|
||||
return del(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/nodes/${nodeId}/variables`)
|
||||
}
|
||||
|
||||
export const deleteInspectorVar = (flowType: FlowType, flowId: string, varId: string) => {
|
||||
return del(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables/${varId}`)
|
||||
}
|
||||
|
||||
export const editInspectorVar = (flowType: FlowType, flowId: string, payload: { varId: string, name?: string, value?: any }) => {
|
||||
const { varId, ...rest } = payload
|
||||
return patch(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables/${varId}`, {
|
||||
body: rest,
|
||||
})
|
||||
}
|
||||
|
||||
export const syncWorkflowDraft = ({ url, params }: {
|
||||
url: string
|
||||
params: Pick<FetchWorkflowDraftResponse, 'graph' | 'features' | 'environment_variables' | 'conversation_variables'>
|
||||
|
||||
@@ -83,7 +83,6 @@ export const fetchAndMergeValidCompletionParams = async (
|
||||
isAdvancedMode: boolean = false,
|
||||
): Promise<{ params: FormValue, removedDetails: Record<string, string> }> => {
|
||||
const { fetchModelParameterRules } = await import('@/service/common')
|
||||
const url = `/workspaces/current/model-providers/${provider}/models/parameter-rules?model=${modelId}`
|
||||
const { data: parameterRules } = await fetchModelParameterRules(url)
|
||||
const { data: parameterRules } = await fetchModelParameterRules(provider, modelId)
|
||||
return mergeValidCompletionParams(oldParams, parameterRules ?? [], isAdvancedMode)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user