mirror of
https://github.com/langgenius/dify.git
synced 2026-04-05 19:32:16 +08:00
chore: knip fix (#34481)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
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 { AppDetailResponse, AppListResponse, CreateApiKeyResponse, DSLImportMode, DSLImportResponse, TracingConfig, TracingStatus, UpdateAppModelConfigResponse, UpdateAppSiteCodeResponse, WebhookTriggerResponse } from '@/models/app'
|
||||
import type { CommonResponse } from '@/models/common'
|
||||
import type { AppIconType, AppModeEnum, ModelConfig } from '@/types/app'
|
||||
import { del, get, patch, post, put } from './base'
|
||||
@@ -16,10 +16,6 @@ export const fetchAppDetailDirect = async ({ url, id }: { url: string, id: strin
|
||||
return get<AppDetailResponse>(`${url}/${id}`)
|
||||
}
|
||||
|
||||
export const fetchAppTemplates = ({ url }: { url: string }): Promise<AppTemplatesResponse> => {
|
||||
return get<AppTemplatesResponse>(url)
|
||||
}
|
||||
|
||||
export const createApp = ({
|
||||
name,
|
||||
icon_type,
|
||||
@@ -112,15 +108,6 @@ export const updateAppSiteStatus = ({ url, body }: { url: string, body: Record<s
|
||||
return post<AppDetailResponse>(url, { body })
|
||||
}
|
||||
|
||||
export const updateAppApiStatus = ({ url, body }: { url: string, body: Record<string, any> }): Promise<AppDetailResponse> => {
|
||||
return post<AppDetailResponse>(url, { body })
|
||||
}
|
||||
|
||||
// path: /apps/{appId}/rate-limit
|
||||
export const updateAppRateLimit = ({ url, body }: { url: string, body: Record<string, any> }): Promise<AppDetailResponse> => {
|
||||
return post<AppDetailResponse>(url, { body })
|
||||
}
|
||||
|
||||
export const updateAppSiteAccessToken = ({ url }: { url: string }): Promise<UpdateAppSiteCodeResponse> => {
|
||||
return post<UpdateAppSiteCodeResponse>(url)
|
||||
}
|
||||
@@ -129,43 +116,10 @@ export const updateAppSiteConfig = ({ url, body }: { url: string, body: Record<s
|
||||
return post<AppDetailResponse>(url, { body })
|
||||
}
|
||||
|
||||
export const getAppDailyMessages = ({ url, params }: { url: string, params: Record<string, any> }): Promise<AppDailyMessagesResponse> => {
|
||||
return get<AppDailyMessagesResponse>(url, { params })
|
||||
}
|
||||
|
||||
export const getAppDailyConversations = ({ url, params }: { url: string, params: Record<string, any> }): Promise<AppDailyConversationsResponse> => {
|
||||
return get<AppDailyConversationsResponse>(url, { params })
|
||||
}
|
||||
|
||||
export const getWorkflowDailyConversations = ({ url, params }: { url: string, params: Record<string, any> }): Promise<WorkflowDailyConversationsResponse> => {
|
||||
return get<WorkflowDailyConversationsResponse>(url, { params })
|
||||
}
|
||||
|
||||
export const getAppStatistics = ({ url, params }: { url: string, params: Record<string, any> }): Promise<AppStatisticsResponse> => {
|
||||
return get<AppStatisticsResponse>(url, { params })
|
||||
}
|
||||
|
||||
export const getAppDailyEndUsers = ({ url, params }: { url: string, params: Record<string, any> }): Promise<AppDailyEndUsersResponse> => {
|
||||
return get<AppDailyEndUsersResponse>(url, { params })
|
||||
}
|
||||
|
||||
export const getAppTokenCosts = ({ url, params }: { url: string, params: Record<string, any> }): Promise<AppTokenCostsResponse> => {
|
||||
return get<AppTokenCostsResponse>(url, { params })
|
||||
}
|
||||
|
||||
export const updateAppModelConfig = ({ url, body }: { url: string, body: Record<string, any> }): Promise<UpdateAppModelConfigResponse> => {
|
||||
return post<UpdateAppModelConfigResponse>(url, { body })
|
||||
}
|
||||
|
||||
// For temp testing
|
||||
export const fetchAppListNoMock = ({ url, params }: { url: string, params: Record<string, any> }): Promise<AppListResponse> => {
|
||||
return get<AppListResponse>(url, params)
|
||||
}
|
||||
|
||||
export const fetchApiKeysList = ({ url, params }: { url: string, params: Record<string, any> }): Promise<ApiKeysListResponse> => {
|
||||
return get<ApiKeysListResponse>(url, params)
|
||||
}
|
||||
|
||||
export const delApikey = ({ url, params }: { url: string, params: Record<string, any> }): Promise<CommonResponse> => {
|
||||
return del<CommonResponse>(url, params)
|
||||
}
|
||||
@@ -174,23 +128,6 @@ export const createApikey = ({ url, body }: { url: string, body: Record<string,
|
||||
return post<CreateApiKeyResponse>(url, body)
|
||||
}
|
||||
|
||||
export const validateOpenAIKey = ({ url, body }: { url: string, body: { token: string } }): Promise<ValidateOpenAIKeyResponse> => {
|
||||
return post<ValidateOpenAIKeyResponse>(url, { body })
|
||||
}
|
||||
|
||||
export const updateOpenAIKey = ({ url, body }: { url: string, body: { token: string } }): Promise<UpdateOpenAIKeyResponse> => {
|
||||
return post<UpdateOpenAIKeyResponse>(url, { body })
|
||||
}
|
||||
|
||||
export const generationIntroduction = ({ url, body }: { url: string, body: { prompt_template: string } }): Promise<GenerationIntroductionResponse> => {
|
||||
return post<GenerationIntroductionResponse>(url, { body })
|
||||
}
|
||||
|
||||
export const fetchAppVoices = ({ appId, language }: { appId: string, language?: string }): Promise<AppVoicesListResponse> => {
|
||||
language = language || 'en-US'
|
||||
return get<AppVoicesListResponse>(`apps/${appId}/text-to-audio/voices?language=${language}`)
|
||||
}
|
||||
|
||||
// Tracing
|
||||
export const fetchTracingStatus = ({ appId }: { appId: string }): Promise<TracingStatus> => {
|
||||
return get<TracingStatus>(`/apps/${appId}/trace`)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { FetchOptionType, ResponseError } from './fetch'
|
||||
import type { AnnotationReply, MessageEnd, MessageReplace, ThoughtItem } from '@/app/components/base/chat/chat/type'
|
||||
import type { MessageEnd, MessageReplace, ThoughtItem } from '@/app/components/base/chat/chat/type'
|
||||
import type { VisionFile } from '@/types/app'
|
||||
import type {
|
||||
DataSourceNodeCompletedResponse,
|
||||
@@ -51,7 +51,6 @@ export type IOnThought = (though: ThoughtItem) => void
|
||||
export type IOnFile = (file: VisionFile) => void
|
||||
export type IOnMessageEnd = (messageEnd: MessageEnd) => void
|
||||
export type IOnMessageReplace = (messageReplace: MessageReplace) => void
|
||||
export type IOnAnnotationReply = (messageReplace: AnnotationReply) => void
|
||||
export type IOnCompleted = (hasError?: boolean, errorMessage?: string) => void
|
||||
export type IOnError = (msg: string, code?: string) => void
|
||||
|
||||
@@ -173,14 +172,6 @@ function formatURL(url: string, isPublicAPI: boolean) {
|
||||
return `${urlPrefix}${urlWithoutProtocol}`
|
||||
}
|
||||
|
||||
export function format(text: string) {
|
||||
let res = text.trim()
|
||||
if (res.startsWith('\n'))
|
||||
res = res.replace('\n', '')
|
||||
|
||||
return res.replaceAll('\n', '<br/>').replaceAll('```', '')
|
||||
}
|
||||
|
||||
export const handleStream = (
|
||||
response: Response,
|
||||
onData: IOnData,
|
||||
@@ -856,10 +847,6 @@ export const put = <T>(url: string, options = {}, otherOptions?: IOtherOptions)
|
||||
return request<T>(url, Object.assign({}, options, { method: 'PUT' }), otherOptions)
|
||||
}
|
||||
|
||||
export const putPublic = <T>(url: string, options = {}, otherOptions?: IOtherOptions) => {
|
||||
return put<T>(url, options, { ...otherOptions, isPublicAPI: true })
|
||||
}
|
||||
|
||||
export const del = <T>(url: string, options = {}, otherOptions?: IOtherOptions) => {
|
||||
return request<T>(url, Object.assign({}, options, { method: 'DELETE' }), otherOptions)
|
||||
}
|
||||
|
||||
@@ -1,34 +1,25 @@
|
||||
import type { CreateExternalAPIReq } from '@/app/components/datasets/external-api/declarations'
|
||||
import type { CreateKnowledgeBaseReq } from '@/app/components/datasets/external-knowledge-base/create/declarations'
|
||||
import type {
|
||||
ApiKeysListResponse,
|
||||
CreateApiKeyResponse,
|
||||
} from '@/models/app'
|
||||
import type { CommonResponse, DataSourceNotionWorkspace } from '@/models/common'
|
||||
import type { CommonResponse } from '@/models/common'
|
||||
import type {
|
||||
CreateDocumentReq,
|
||||
createDocumentResponse,
|
||||
DataSet,
|
||||
DataSetListResponse,
|
||||
ErrorDocsResponse,
|
||||
ExternalAPIDeleteResponse,
|
||||
ExternalAPIItem,
|
||||
ExternalAPIListResponse,
|
||||
ExternalAPIUsage,
|
||||
ExternalKnowledgeBaseHitTestingResponse,
|
||||
ExternalKnowledgeItem,
|
||||
FetchDatasetsParams,
|
||||
FileIndexingEstimateResponse,
|
||||
HitTestingRecordsResponse,
|
||||
HitTestingResponse,
|
||||
IndexingEstimateParams,
|
||||
IndexingEstimateResponse,
|
||||
IndexingStatusBatchResponse,
|
||||
IndexingStatusResponse,
|
||||
ProcessRuleResponse,
|
||||
RelatedAppResponse,
|
||||
} 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'
|
||||
@@ -58,10 +49,6 @@ export type SortType = 'created_at' | 'hit_count' | '-created_at' | '-hit_count'
|
||||
|
||||
export type MetadataType = 'all' | 'only' | 'without'
|
||||
|
||||
export const fetchDatasetDetail = (datasetId: string): Promise<DataSet> => {
|
||||
return get<DataSet>(`/datasets/${datasetId}`)
|
||||
}
|
||||
|
||||
export const updateDatasetSetting = ({
|
||||
datasetId,
|
||||
body,
|
||||
@@ -72,10 +59,6 @@ export const updateDatasetSetting = ({
|
||||
return patch<DataSet>(`/datasets/${datasetId}`, { body })
|
||||
}
|
||||
|
||||
export const fetchDatasetRelatedApps = (datasetId: string): Promise<RelatedAppResponse> => {
|
||||
return get<RelatedAppResponse>(`/datasets/${datasetId}/related-apps`)
|
||||
}
|
||||
|
||||
export const fetchDatasets = ({ url, params }: FetchDatasetsParams): Promise<DataSetListResponse> => {
|
||||
const urlParams = qs.stringify(params, { indices: false })
|
||||
return get<DataSetListResponse>(`${url}?${urlParams}`)
|
||||
@@ -95,10 +78,6 @@ export const deleteDataset = (datasetID: string): Promise<DataSet> => {
|
||||
return del<DataSet>(`/datasets/${datasetID}`)
|
||||
}
|
||||
|
||||
export const fetchExternalAPIList = ({ url }: { url: string }): Promise<ExternalAPIListResponse> => {
|
||||
return get<ExternalAPIListResponse>(url)
|
||||
}
|
||||
|
||||
export const fetchExternalAPI = ({ apiTemplateId }: { apiTemplateId: string }): Promise<ExternalAPIItem> => {
|
||||
return get<ExternalAPIItem>(`/datasets/external-knowledge-api/${apiTemplateId}`)
|
||||
}
|
||||
@@ -126,9 +105,6 @@ export const createExternalKnowledgeBase = ({ body }: { body: CreateKnowledgeBas
|
||||
export const fetchDefaultProcessRule = ({ url }: { url: string }): Promise<ProcessRuleResponse> => {
|
||||
return get<ProcessRuleResponse>(url)
|
||||
}
|
||||
export const fetchProcessRule = ({ params: { documentId } }: { params: { documentId: string } }): Promise<ProcessRuleResponse> => {
|
||||
return get<ProcessRuleResponse>('/datasets/process-rule', { params: { document_id: documentId } })
|
||||
}
|
||||
|
||||
export const createFirstDocument = ({ body }: { body: CreateDocumentReq }): Promise<createDocumentResponse> => {
|
||||
return post<createDocumentResponse>('/datasets/init', { body })
|
||||
@@ -138,13 +114,6 @@ export const createDocument = ({ datasetId, body }: { datasetId: string, body: C
|
||||
return post<createDocumentResponse>(`/datasets/${datasetId}/documents`, { body })
|
||||
}
|
||||
|
||||
export const fetchIndexingEstimate = ({ datasetId, documentId }: CommonDocReq): Promise<IndexingEstimateResponse> => {
|
||||
return get<IndexingEstimateResponse>(`/datasets/${datasetId}/documents/${documentId}/indexing-estimate`, {})
|
||||
}
|
||||
export const fetchIndexingEstimateBatch = ({ datasetId, batchId }: BatchReq): Promise<IndexingEstimateResponse> => {
|
||||
return get<IndexingEstimateResponse>(`/datasets/${datasetId}/batch/${batchId}/indexing-estimate`, {})
|
||||
}
|
||||
|
||||
export const fetchIndexingStatus = ({ datasetId, documentId }: CommonDocReq): Promise<IndexingStatusResponse> => {
|
||||
return get<IndexingStatusResponse>(`/datasets/${datasetId}/documents/${documentId}/indexing-status`, {})
|
||||
}
|
||||
@@ -179,27 +148,11 @@ export const downloadDocumentsZip = ({ datasetId, documentIds }: DocumentDownloa
|
||||
})
|
||||
}
|
||||
|
||||
export const preImportNotionPages = ({ url, datasetId }: { url: string, datasetId?: string }): Promise<{ notion_info: DataSourceNotionWorkspace[] }> => {
|
||||
return get<{ notion_info: DataSourceNotionWorkspace[] }>(url, { params: { dataset_id: datasetId } })
|
||||
}
|
||||
|
||||
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 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> => {
|
||||
return post<ExternalKnowledgeBaseHitTestingResponse>(`/datasets/${datasetId}/external-hit-testing`, { body: { query, external_retrieval_model } })
|
||||
}
|
||||
|
||||
export const fetchTestingRecords = ({ datasetId, params }: { datasetId: string, params: { page: number, limit: number } }): Promise<HitTestingRecordsResponse> => {
|
||||
return get<HitTestingRecordsResponse>(`/datasets/${datasetId}/queries`, { params })
|
||||
}
|
||||
|
||||
export const fetchFileIndexingEstimate = (body: IndexingEstimateParams): Promise<FileIndexingEstimateResponse> => {
|
||||
return post<FileIndexingEstimateResponse>('/datasets/indexing-estimate', { body })
|
||||
}
|
||||
@@ -212,10 +165,6 @@ export const fetchNotionPagePreview = ({ pageID, pageType, credentialID }: { pag
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchApiKeysList = ({ url, params }: { url: string, params: Record<string, any> }): Promise<ApiKeysListResponse> => {
|
||||
return get<ApiKeysListResponse>(url, params)
|
||||
}
|
||||
|
||||
export const delApikey = ({ url, params }: { url: string, params: Record<string, any> }): Promise<CommonResponse> => {
|
||||
return del<CommonResponse>(url, params)
|
||||
}
|
||||
@@ -224,18 +173,6 @@ export const createApikey = ({ url, body }: { url: string, body: Record<string,
|
||||
return post<CreateApiKeyResponse>(url, body)
|
||||
}
|
||||
|
||||
export const fetchDataSources = (): Promise<CommonResponse> => {
|
||||
return get<CommonResponse>('api-key-auth/data-source')
|
||||
}
|
||||
|
||||
export const createDataSourceApiKeyBinding = (body: Record<string, any>): Promise<CommonResponse> => {
|
||||
return post<CommonResponse>('api-key-auth/data-source/binding', { body })
|
||||
}
|
||||
|
||||
export const removeDataSourceApiKeyBinding = (id: string): Promise<CommonResponse> => {
|
||||
return del<CommonResponse>(`api-key-auth/data-source/${id}`)
|
||||
}
|
||||
|
||||
export const createFirecrawlTask = (body: Record<string, any>): Promise<CommonResponse> => {
|
||||
return post<CommonResponse>('website/crawl', {
|
||||
body: {
|
||||
@@ -297,14 +234,6 @@ export type FileTypesRes = {
|
||||
allowed_extensions: string[]
|
||||
}
|
||||
|
||||
export const fetchSupportFileTypes = ({ url }: { url: string }): Promise<FileTypesRes> => {
|
||||
return get<FileTypesRes>(url)
|
||||
}
|
||||
|
||||
export const getErrorDocs = ({ datasetId }: { datasetId: string }): Promise<ErrorDocsResponse> => {
|
||||
return get<ErrorDocsResponse>(`/datasets/${datasetId}/error-docs`)
|
||||
}
|
||||
|
||||
export const retryErrorDocs = ({ datasetId, document_ids }: { datasetId: string, document_ids: string[] }): Promise<CommonResponse> => {
|
||||
return post<CommonResponse>(`/datasets/${datasetId}/retry`, { body: { document_ids } })
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import type { IOnCompleted, IOnData, IOnError, IOnMessageReplace } from './base'
|
||||
import type { ModelParameterRule } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||
import type { ChatPromptConfig, CompletionPromptConfig } from '@/models/debug'
|
||||
import type { AppModeEnum, ModelModeType } from '@/types/app'
|
||||
import { get, post, ssePost } from './base'
|
||||
|
||||
export type BasicAppFirstRes = {
|
||||
type BasicAppFirstRes = {
|
||||
prompt: string
|
||||
variables: string[]
|
||||
opening_statement: string
|
||||
@@ -19,12 +18,6 @@ export type GenRes = {
|
||||
error?: string
|
||||
}
|
||||
|
||||
export type CodeGenRes = {
|
||||
code: string
|
||||
language: string[]
|
||||
error?: string
|
||||
}
|
||||
|
||||
export const stopChatMessageResponding = async (appId: string, taskId: string) => {
|
||||
return post(`apps/${appId}/chat-messages/${taskId}/stop`)
|
||||
}
|
||||
@@ -75,14 +68,6 @@ export const generateRule = (body: Record<string, any>) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchModelParams = (providerName: string, modelId: string) => {
|
||||
return get(`workspaces/current/model-providers/${providerName}/models/parameter-rules`, {
|
||||
params: {
|
||||
model: modelId,
|
||||
},
|
||||
}) as Promise<{ data: ModelParameterRule[] }>
|
||||
}
|
||||
|
||||
export const fetchPromptTemplate = ({
|
||||
appMode,
|
||||
mode,
|
||||
|
||||
@@ -188,15 +188,6 @@ export const useExternalKnowledgeApiList = (options?: { enabled?: boolean }) =>
|
||||
})
|
||||
}
|
||||
|
||||
export const useInvalidateExternalKnowledgeApiList = () => {
|
||||
const queryClient = useQueryClient()
|
||||
return () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [NAME_SPACE, 'external-knowledge-api'],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const useDatasetTestingRecords = (
|
||||
datasetId?: string,
|
||||
params?: { page: number, limit: number },
|
||||
|
||||
@@ -72,7 +72,7 @@ const toBatchDocumentsIdParams = (documentIds: string[] | string) => {
|
||||
return ids.map(id => `document_id=${id}`).join('&')
|
||||
}
|
||||
|
||||
export const useDocumentBatchAction = (action: DocumentActionType) => {
|
||||
const useDocumentBatchAction = (action: DocumentActionType) => {
|
||||
return useMutation({
|
||||
mutationFn: ({ datasetId, documentIds, documentId }: UpdateDocumentBatchParams) => {
|
||||
return patch<CommonResponse>(`/datasets/${datasetId}/documents/status/${action}/batch?${toBatchDocumentsIdParams(documentId || documentIds!)}`)
|
||||
|
||||
@@ -1,31 +1,14 @@
|
||||
import type {
|
||||
ExternalKnowledgeBaseHitTestingRequest,
|
||||
ExternalKnowledgeBaseHitTestingResponse,
|
||||
HitTestingRecordsRequest,
|
||||
HitTestingRecordsResponse,
|
||||
HitTestingRequest,
|
||||
HitTestingResponse,
|
||||
} from '@/models/datasets'
|
||||
import { useMutation, useQuery } from '@tanstack/react-query'
|
||||
import { get, post } from '../base'
|
||||
import { useInvalid } from '../use-base'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { post } from '../base'
|
||||
|
||||
const NAME_SPACE = 'hit-testing'
|
||||
|
||||
const HitTestingRecordsKey = [NAME_SPACE, 'records']
|
||||
|
||||
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 } }),
|
||||
})
|
||||
}
|
||||
|
||||
export const useInvalidateHitTestingRecords = (datasetId: string) => {
|
||||
return useInvalid([...HitTestingRecordsKey, datasetId])
|
||||
}
|
||||
|
||||
export const useHitTesting = (datasetId: string) => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'hit-testing', datasetId],
|
||||
|
||||
@@ -16,7 +16,7 @@ export const useDatasetMetaData = (datasetId: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const useInvalidDatasetMetaData = (datasetId: string) => {
|
||||
const useInvalidDatasetMetaData = (datasetId: string) => {
|
||||
return useInvalid([NAME_SPACE, 'dataset', datasetId])
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ export const useCreateMetaData = (datasetId: string) => {
|
||||
},
|
||||
})
|
||||
}
|
||||
export const useInvalidAllDocumentMetaData = (datasetId: string) => {
|
||||
const useInvalidAllDocumentMetaData = (datasetId: string) => {
|
||||
const queryClient = useQueryClient()
|
||||
return () => {
|
||||
queryClient.invalidateQueries({
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
import type {
|
||||
MarketplaceCollectionPluginsResponse,
|
||||
MarketplaceCollectionsResponse,
|
||||
} from '@/app/components/plugins/marketplace/types'
|
||||
import type {
|
||||
Dependency,
|
||||
InstallPackageResponse,
|
||||
Permissions,
|
||||
PluginDeclaration,
|
||||
PluginInfoFromMarketPlace,
|
||||
PluginManifestInMarket,
|
||||
PluginTasksResponse,
|
||||
TaskStatusResponse,
|
||||
UninstallPluginResponse,
|
||||
updatePackageResponse,
|
||||
@@ -54,14 +47,6 @@ export const uploadGitHub = async (repoUrl: string, selectedVersion: string, sel
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchIcon = (tenantId: string, fileName: string) => {
|
||||
return get(`workspaces/current/plugin/icon?tenant_id=${tenantId}&filename=${fileName}`)
|
||||
}
|
||||
|
||||
export const fetchManifest = async (uniqueIdentifier: string) => {
|
||||
return get<PluginDeclaration>(`/workspaces/current/plugin/fetch-manifest?plugin_unique_identifier=${uniqueIdentifier}`)
|
||||
}
|
||||
|
||||
export const fetchManifestFromMarketPlace = async (uniqueIdentifier: string) => {
|
||||
return getMarketplace<{ data: { plugin: PluginManifestInMarket, version: { version: string } } }>(`/plugins/identifier?unique_identifier=${uniqueIdentifier}`)
|
||||
}
|
||||
@@ -81,26 +66,10 @@ export const fetchPluginInfoFromMarketPlace = async ({
|
||||
return getMarketplace<{ data: { plugin: PluginInfoFromMarketPlace, version: { version: string } } }>(`/plugins/${org}/${name}`)
|
||||
}
|
||||
|
||||
export const fetchMarketplaceCollections = ({ url }: { url: string }): Promise<MarketplaceCollectionsResponse> => {
|
||||
return get<MarketplaceCollectionsResponse>(url)
|
||||
}
|
||||
|
||||
export const fetchMarketplaceCollectionPlugins = ({ url }: { url: string }): Promise<MarketplaceCollectionPluginsResponse> => {
|
||||
return get<MarketplaceCollectionPluginsResponse>(url)
|
||||
}
|
||||
|
||||
export const fetchPluginTasks = async () => {
|
||||
return get<PluginTasksResponse>('/workspaces/current/plugin/tasks?page=1&page_size=255')
|
||||
}
|
||||
|
||||
export const checkTaskStatus = async (taskId: string) => {
|
||||
return get<TaskStatusResponse>(`/workspaces/current/plugin/tasks/${taskId}`)
|
||||
}
|
||||
|
||||
export const updatePermission = async (permissions: Permissions) => {
|
||||
return post('/workspaces/current/plugin/permission/change', { body: permissions })
|
||||
}
|
||||
|
||||
export const uninstallPlugin = async (pluginId: string) => {
|
||||
return post<UninstallPluginResponse>('/workspaces/current/plugin/uninstall', { body: { plugin_installation_id: pluginId } })
|
||||
}
|
||||
|
||||
@@ -246,10 +246,6 @@ export const textToAudioStream = (url: string, appSourceType: AppSourceType, hea
|
||||
return (getAction('post', appSourceType))(url, { body, header }, { needAllResponseContent: true })
|
||||
}
|
||||
|
||||
export const textToAudio = (url: string, appSourceType: AppSourceType, body: FormData) => {
|
||||
return (getAction('post', appSourceType))(url, { body }, { bodyStringify: false, deleteContentType: true }) as Promise<{ data: string }>
|
||||
}
|
||||
|
||||
export const fetchAccessToken = async ({ userId, appCode }: { userId?: string, appCode: string }) => {
|
||||
const headers = new Headers()
|
||||
headers.append(WEB_APP_SHARE_CODE_HEADER_NAME, appCode)
|
||||
|
||||
@@ -15,10 +15,6 @@ export const fetchCollectionList = () => {
|
||||
return get<Collection[]>('/workspaces/current/tool-providers')
|
||||
}
|
||||
|
||||
export const fetchCollectionDetail = (collectionName: string) => {
|
||||
return get<Collection>(`/workspaces/current/tool-provider/${collectionName}/info`)
|
||||
}
|
||||
|
||||
export const fetchBuiltInToolList = (collectionName: string) => {
|
||||
return get<Tool[]>(`/workspaces/current/tool-provider/builtin/${collectionName}/tools`)
|
||||
}
|
||||
@@ -133,10 +129,6 @@ export const saveWorkflowToolProvider = (payload: WorkflowToolProviderRequest &
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchWorkflowToolDetailByAppID = (appID: string) => {
|
||||
return get<WorkflowToolProviderResponse>(`/workspaces/current/tool-provider/workflow/get?workflow_app_id=${appID}`)
|
||||
}
|
||||
|
||||
export const fetchWorkflowToolDetail = (toolID: string) => {
|
||||
return get<WorkflowToolProviderResponse>(`/workspaces/current/tool-provider/workflow/get?workflow_tool_id=${toolID}`)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
import { consoleClient, consoleQuery } from '@/service/client'
|
||||
import { AppModeEnum } from '@/types/app'
|
||||
import { get, post } from './base'
|
||||
import { useInvalid } from './use-base'
|
||||
|
||||
const NAME_SPACE = 'apps'
|
||||
|
||||
@@ -105,17 +104,6 @@ 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: '' } }),
|
||||
})
|
||||
}
|
||||
|
||||
export const useInvalidateAppFullList = () => {
|
||||
return useInvalid(useAppFullListKey)
|
||||
}
|
||||
|
||||
export const useInfiniteAppList = (params: AppListParams, options?: { enabled?: boolean }) => {
|
||||
const normalizedParams = normalizeAppListParams(params)
|
||||
return useInfiniteQuery<AppListResponse>({
|
||||
|
||||
@@ -10,7 +10,6 @@ import type {
|
||||
ApiBasedExtension,
|
||||
CodeBasedExtension,
|
||||
CommonResponse,
|
||||
DataSourceNotion,
|
||||
FileUploadConfigResponse,
|
||||
ICurrentWorkspace,
|
||||
IWorkspace,
|
||||
@@ -25,7 +24,6 @@ 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 { useInvalid } from './use-base'
|
||||
|
||||
const NAME_SPACE = 'common'
|
||||
|
||||
@@ -277,14 +275,6 @@ 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}`),
|
||||
enabled,
|
||||
})
|
||||
}
|
||||
|
||||
export const useSupportRetrievalMethods = () => {
|
||||
return useQuery<{ retrieval_method: RETRIEVE_METHOD[] }>({
|
||||
queryKey: commonQueryKeys.retrievalMethods,
|
||||
@@ -299,25 +289,6 @@ export const useAccountIntegrates = () => {
|
||||
})
|
||||
}
|
||||
|
||||
type DataSourceIntegratesOptions = {
|
||||
enabled?: boolean
|
||||
initialData?: { data: DataSourceNotion[] }
|
||||
}
|
||||
|
||||
export const useDataSourceIntegrates = (options: DataSourceIntegratesOptions = {}) => {
|
||||
const { enabled = true, initialData } = options
|
||||
return useQuery<{ data: DataSourceNotion[] }>({
|
||||
queryKey: commonQueryKeys.dataSourceIntegrates,
|
||||
queryFn: () => get<{ data: DataSourceNotion[] }>('/data-source/integrates'),
|
||||
enabled,
|
||||
initialData,
|
||||
})
|
||||
}
|
||||
|
||||
export const useInvalidDataSourceIntegrates = () => {
|
||||
return useInvalid(commonQueryKeys.dataSourceIntegrates)
|
||||
}
|
||||
|
||||
export const usePluginProviders = () => {
|
||||
return useQuery<PluginProvider[] | null>({
|
||||
queryKey: commonQueryKeys.pluginProviders,
|
||||
@@ -332,14 +303,6 @@ export const useCodeBasedExtensions = (module: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const useNotionConnection = (enabled: boolean) => {
|
||||
return useQuery<{ data: string }>({
|
||||
queryKey: commonQueryKeys.notionConnection,
|
||||
queryFn: () => get<{ data: string }>('/oauth/data-source/notion'),
|
||||
enabled,
|
||||
})
|
||||
}
|
||||
|
||||
export const useApiBasedExtensions = () => {
|
||||
return useQuery<ApiBasedExtension[]>({
|
||||
queryKey: commonQueryKeys.apiBasedExtensions,
|
||||
|
||||
@@ -3,13 +3,13 @@ import { post } from './base'
|
||||
|
||||
const NAME_SPACE = 'oauth-provider'
|
||||
|
||||
export type OAuthAppInfo = {
|
||||
type OAuthAppInfo = {
|
||||
app_icon: string
|
||||
app_label: Record<string, string>
|
||||
scope: string
|
||||
}
|
||||
|
||||
export type OAuthAuthorizeResponse = {
|
||||
type OAuthAuthorizeResponse = {
|
||||
code: string
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { MutationOptions } from '@tanstack/react-query'
|
||||
import type { ToolCredential } from '@/app/components/tools/types'
|
||||
import type { DataSourceItem } from '@/app/components/workflow/block-selector/types'
|
||||
import type { IconInfo } from '@/models/datasets'
|
||||
import type {
|
||||
@@ -31,14 +30,14 @@ import type {
|
||||
UpdateTemplateInfoRequest,
|
||||
UpdateTemplateInfoResponse,
|
||||
} from '@/models/pipeline'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { useMutation, useQuery } from '@tanstack/react-query'
|
||||
import { DatasourceType } from '@/models/pipeline'
|
||||
import { del, get, patch, post } from './base'
|
||||
import { useInvalid } from './use-base'
|
||||
|
||||
const NAME_SPACE = 'pipeline'
|
||||
|
||||
export const PipelineTemplateListQueryKeyPrefix = [NAME_SPACE, 'template-list']
|
||||
const PipelineTemplateListQueryKeyPrefix = [NAME_SPACE, 'template-list']
|
||||
export const usePipelineTemplateList = (params: PipelineTemplateListParams, enabled = true) => {
|
||||
return useQuery<PipelineTemplateListResponse>({
|
||||
queryKey: [...PipelineTemplateListQueryKeyPrefix, params],
|
||||
@@ -224,46 +223,6 @@ export const useRunPublishedPipeline = (
|
||||
})
|
||||
}
|
||||
|
||||
export const useDataSourceCredentials = (provider: string, pluginId: string, onSuccess: (value: ToolCredential[]) => void) => {
|
||||
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}`)
|
||||
onSuccess(result.result)
|
||||
return result.result
|
||||
},
|
||||
enabled: !!provider && !!pluginId,
|
||||
retry: 2,
|
||||
})
|
||||
}
|
||||
|
||||
export const useUpdateDataSourceCredentials = (
|
||||
) => {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'update-datasource-credentials'],
|
||||
mutationFn: ({
|
||||
provider,
|
||||
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(() => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [NAME_SPACE, 'datasource'],
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const useDraftPipelinePreProcessingParams = (params: PipelinePreProcessingParamsRequest, enabled = true) => {
|
||||
const { pipeline_id, node_id } = params
|
||||
return useQuery<PipelinePreProcessingParamsResponse>({
|
||||
|
||||
@@ -44,15 +44,6 @@ export const useSetPluginDefaultCredential = (
|
||||
})
|
||||
}
|
||||
|
||||
export const useGetPluginCredentialList = (
|
||||
url: string,
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'credential-list', url],
|
||||
queryFn: () => get(url),
|
||||
})
|
||||
}
|
||||
|
||||
export const useAddPluginCredential = (
|
||||
url: string,
|
||||
) => {
|
||||
|
||||
@@ -4,7 +4,6 @@ import type {
|
||||
ModelProvider,
|
||||
} from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||
import type {
|
||||
PluginsSearchParams,
|
||||
} from '@/app/components/plugins/marketplace/types'
|
||||
import type {
|
||||
DebugInfo as DebugInfoTypes,
|
||||
@@ -70,7 +69,7 @@ export const useInvalidateCheckInstalled = () => {
|
||||
}
|
||||
|
||||
const useRecommendedMarketplacePluginsKey = [NAME_SPACE, 'recommendedMarketplacePlugins']
|
||||
export const useRecommendedMarketplacePlugins = ({
|
||||
const useRecommendedMarketplacePlugins = ({
|
||||
collection = '__recommended-plugins-tools',
|
||||
enabled = true,
|
||||
limit = 15,
|
||||
@@ -231,12 +230,6 @@ export const useVersionListOfPlugin = (pluginID: string) => {
|
||||
queryFn: () => getMarketplace<{ data: VersionListResponse }>(`/plugins/${pluginID}/versions`, { params: { page: 1, page_size: 100 } }),
|
||||
})
|
||||
}
|
||||
export const useInvalidateVersionListOfPlugin = () => {
|
||||
const queryClient = useQueryClient()
|
||||
return (pluginID: string) => {
|
||||
queryClient.invalidateQueries({ queryKey: [NAME_SPACE, 'versions', pluginID] })
|
||||
}
|
||||
}
|
||||
|
||||
export const useInstallPackageFromLocal = () => {
|
||||
return useMutation({
|
||||
@@ -473,38 +466,6 @@ export const useRemoveAutoUpgrade = () => {
|
||||
})
|
||||
}
|
||||
|
||||
export const useMutationPluginsFromMarketplace = () => {
|
||||
return useMutation({
|
||||
mutationFn: (pluginsSearchParams: PluginsSearchParams) => {
|
||||
const {
|
||||
query,
|
||||
sort_by,
|
||||
sort_order,
|
||||
category,
|
||||
tags,
|
||||
exclude,
|
||||
type,
|
||||
page = 1,
|
||||
page_size = 40,
|
||||
} = pluginsSearchParams
|
||||
const pluginOrBundle = type === 'bundle' ? 'bundles' : 'plugins'
|
||||
return postMarketplace<{ data: PluginsFromMarketplaceResponse }>(`/${pluginOrBundle}/search/advanced`, {
|
||||
body: {
|
||||
page,
|
||||
page_size,
|
||||
query,
|
||||
sort_by,
|
||||
sort_order,
|
||||
category: category !== 'all' ? category : '',
|
||||
tags,
|
||||
exclude,
|
||||
type,
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const useFetchPluginsInMarketPlaceByIds = (unique_identifiers: string[], options?: QueryOptions<{ data: PluginsFromMarketplaceResponse }>) => {
|
||||
return useQuery({
|
||||
...options,
|
||||
@@ -519,39 +480,6 @@ export const useFetchPluginsInMarketPlaceByIds = (unique_identifiers: string[],
|
||||
})
|
||||
}
|
||||
|
||||
export const useFetchPluginListOrBundleList = (pluginsSearchParams: PluginsSearchParams) => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'fetchPluginListOrBundleList', pluginsSearchParams],
|
||||
queryFn: () => {
|
||||
const {
|
||||
query,
|
||||
sort_by,
|
||||
sort_order,
|
||||
category,
|
||||
tags,
|
||||
exclude,
|
||||
type,
|
||||
page = 1,
|
||||
page_size = 40,
|
||||
} = pluginsSearchParams
|
||||
const pluginOrBundle = type === 'bundle' ? 'bundles' : 'plugins'
|
||||
return postMarketplace<{ data: PluginsFromMarketplaceResponse }>(`/${pluginOrBundle}/search/advanced`, {
|
||||
body: {
|
||||
page,
|
||||
page_size,
|
||||
query,
|
||||
sort_by,
|
||||
sort_order,
|
||||
category: category !== 'all' ? category : '',
|
||||
tags,
|
||||
exclude,
|
||||
type,
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const useFetchPluginsInMarketPlaceByInfo = (infos: Record<string, any>[]) => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'fetchPluginsInMarketPlaceByInfo', infos],
|
||||
@@ -632,14 +560,6 @@ export const useMutationClearTaskPlugin = () => {
|
||||
})
|
||||
}
|
||||
|
||||
export const useMutationClearAllTaskPlugin = () => {
|
||||
return useMutation({
|
||||
mutationFn: () => {
|
||||
return post<{ success: boolean }>('/workspaces/current/plugin/tasks/delete_all')
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const usePluginManifestInfo = (pluginUID: string) => {
|
||||
return useQuery({
|
||||
enabled: !!pluginUID,
|
||||
|
||||
@@ -194,7 +194,7 @@ export const useGetHumanInputForm = (token: string, options: ShareQueryOptions =
|
||||
})
|
||||
}
|
||||
|
||||
export type SubmitHumanInputFormParams = {
|
||||
type SubmitHumanInputFormParams = {
|
||||
token: string
|
||||
data: {
|
||||
inputs: Record<string, string>
|
||||
|
||||
@@ -30,7 +30,3 @@ export const useStrategyProviderDetail = (agentProvider: string, options?: Query
|
||||
enabled: !!agentProvider,
|
||||
})
|
||||
}
|
||||
|
||||
export const useInvalidateStrategyProviderDetail = (agentProvider: string) => {
|
||||
return useInvalid([NAME_SPACE, 'detail', agentProvider])
|
||||
}
|
||||
|
||||
@@ -173,19 +173,6 @@ export const useAuthorizeMCP = () => {
|
||||
})
|
||||
}
|
||||
|
||||
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,
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const useMCPTools = (providerID: string) => {
|
||||
return useQuery({
|
||||
enabled: !!providerID,
|
||||
@@ -275,24 +262,6 @@ 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`),
|
||||
})
|
||||
}
|
||||
|
||||
export const useInvalidateBuiltinProviderInfo = () => {
|
||||
const queryClient = useQueryClient()
|
||||
return (providerName: string) => {
|
||||
queryClient.invalidateQueries(
|
||||
{
|
||||
queryKey: [NAME_SPACE, 'builtin-provider-info', providerName],
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export const useBuiltinTools = (providerName: string) => {
|
||||
return useQuery({
|
||||
enabled: !!providerName,
|
||||
@@ -301,41 +270,6 @@ export const useBuiltinTools = (providerName: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const useUpdateProviderCredentials = ({
|
||||
onSuccess,
|
||||
}: {
|
||||
onSuccess?: () => void
|
||||
}) => {
|
||||
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,
|
||||
},
|
||||
})
|
||||
},
|
||||
onSuccess,
|
||||
})
|
||||
}
|
||||
|
||||
export const useRemoveProviderCredentials = ({
|
||||
onSuccess,
|
||||
}: {
|
||||
onSuccess?: () => void
|
||||
}) => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'remove-provider-credentials'],
|
||||
mutationFn: (providerName: string) => {
|
||||
return post(`/workspaces/current/tool-provider/builtin/${providerName}/delete`, {
|
||||
body: {},
|
||||
})
|
||||
},
|
||||
onSuccess,
|
||||
})
|
||||
}
|
||||
|
||||
const useRAGRecommendedPluginListKey = [NAME_SPACE, 'rag-recommended-plugins']
|
||||
|
||||
export const useRAGRecommendedPlugins = (type: 'tool' | 'datasource' | 'all' = 'all') => {
|
||||
|
||||
@@ -8,7 +8,7 @@ import type {
|
||||
TriggerSubscriptionBuilder,
|
||||
TriggerWithProvider,
|
||||
} from '@/app/components/workflow/block-selector/types'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { useMutation, useQuery } from '@tanstack/react-query'
|
||||
import { CollectionType } from '@/app/components/tools/types'
|
||||
import { consoleClient, consoleQuery } from '@/service/client'
|
||||
import { get, post } from './base'
|
||||
@@ -75,17 +75,6 @@ export const useAllTriggerPlugins = (enabled = true) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const useTriggerPluginsByType = (triggerType: string, enabled = true) => {
|
||||
return useQuery<TriggerWithProvider[]>({
|
||||
queryKey: consoleQuery.triggers.list.queryKey({ input: { query: { type: triggerType } } }),
|
||||
queryFn: async () => {
|
||||
const response = await consoleClient.triggers.list({ query: { type: triggerType } })
|
||||
return response.map(convertToTriggerWithProvider)
|
||||
},
|
||||
enabled: enabled && !!triggerType,
|
||||
})
|
||||
}
|
||||
|
||||
export const useInvalidateAllTriggerPlugins = () => {
|
||||
return useInvalid(consoleQuery.triggers.list.queryKey({ input: {} }))
|
||||
}
|
||||
@@ -108,15 +97,6 @@ export const useTriggerSubscriptions = (provider: string, enabled = true) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const useInvalidateTriggerSubscriptions = () => {
|
||||
const queryClient = useQueryClient()
|
||||
return (provider: string) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: consoleQuery.triggers.subscriptions.queryKey({ input: { params: { provider } } }),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const useCreateTriggerSubscriptionBuilder = () => {
|
||||
return useMutation({
|
||||
mutationKey: consoleQuery.triggers.subscriptionBuilderCreate.mutationKey(),
|
||||
@@ -220,7 +200,7 @@ export const useDeleteTriggerSubscription = () => {
|
||||
})
|
||||
}
|
||||
|
||||
export type UpdateTriggerSubscriptionPayload = {
|
||||
type UpdateTriggerSubscriptionPayload = {
|
||||
subscriptionId: string
|
||||
name?: string
|
||||
properties?: Record<string, unknown>
|
||||
@@ -362,12 +342,3 @@ export const useTriggerPluginDynamicOptions = (payload: {
|
||||
}
|
||||
|
||||
// ===== Cache Invalidation Helpers =====
|
||||
|
||||
export const useInvalidateTriggerOAuthConfig = () => {
|
||||
const queryClient = useQueryClient()
|
||||
return (provider: string) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: consoleQuery.triggers.oauthConfig.queryKey({ input: { params: { provider } } }),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +188,6 @@ export const useResetToLastRunValue = (flowType: FlowType, flowId: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const useSysVarValuesKey = [NAME_SPACE, 'sys-variable']
|
||||
export const useSysVarValues = (flowType?: FlowType, flowId?: string) => {
|
||||
return useQuery({
|
||||
enabled: !!flowId,
|
||||
|
||||
@@ -17,11 +17,11 @@ export function getWebAppPassport(shareCode: string) {
|
||||
return localStorage.getItem(PASSPORT_LOCAL_STORAGE_NAME(shareCode)) || ''
|
||||
}
|
||||
|
||||
export function clearWebAppAccessToken() {
|
||||
function clearWebAppAccessToken() {
|
||||
localStorage.removeItem(ACCESS_TOKEN_LOCAL_STORAGE_NAME)
|
||||
}
|
||||
|
||||
export function clearWebAppPassport(shareCode: string) {
|
||||
function clearWebAppPassport(shareCode: string) {
|
||||
localStorage.removeItem(PASSPORT_LOCAL_STORAGE_NAME(shareCode))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,193 +0,0 @@
|
||||
import type { PluginTriggerNodeType } from '@/app/components/workflow/nodes/trigger-plugin/types'
|
||||
import type { Edge, Node } from '@/app/components/workflow/types'
|
||||
import type { FetchWorkflowDraftResponse } from '@/types/workflow'
|
||||
import { produce } from 'immer'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
|
||||
export type TriggerPluginNodePayload = {
|
||||
title: string
|
||||
desc: string
|
||||
plugin_id: string
|
||||
provider_id: string
|
||||
event_name: string
|
||||
subscription_id: string
|
||||
plugin_unique_identifier: string
|
||||
event_parameters: Record<string, unknown>
|
||||
}
|
||||
|
||||
export type WorkflowDraftSyncParams = Pick<
|
||||
FetchWorkflowDraftResponse,
|
||||
'graph' | 'features' | 'environment_variables' | 'conversation_variables'
|
||||
>
|
||||
|
||||
const removeTempProperties = (data: Record<string, unknown>): void => {
|
||||
Object.keys(data).forEach((key) => {
|
||||
if (key.startsWith('_'))
|
||||
delete data[key]
|
||||
})
|
||||
}
|
||||
|
||||
type TriggerParameterSchema = Record<string, unknown>
|
||||
|
||||
type TriggerPluginHydratePayload = (PluginTriggerNodeType & {
|
||||
paramSchemas?: TriggerParameterSchema[]
|
||||
parameters_schema?: TriggerParameterSchema[]
|
||||
})
|
||||
|
||||
const sanitizeTriggerPluginNode = (node: Node<TriggerPluginNodePayload>): Node<TriggerPluginNodePayload> => {
|
||||
const data = node.data
|
||||
|
||||
if (!data || data.type !== BlockEnum.TriggerPlugin)
|
||||
return node
|
||||
|
||||
const sanitizedData: TriggerPluginNodePayload & { type: BlockEnum.TriggerPlugin } = {
|
||||
type: BlockEnum.TriggerPlugin,
|
||||
title: data.title ?? '',
|
||||
desc: data.desc ?? '',
|
||||
plugin_id: data.plugin_id ?? '',
|
||||
provider_id: data.provider_id ?? '',
|
||||
event_name: data.event_name ?? '',
|
||||
subscription_id: data.subscription_id ?? '',
|
||||
plugin_unique_identifier: data.plugin_unique_identifier ?? '',
|
||||
event_parameters: (typeof data.event_parameters === 'object' && data.event_parameters !== null)
|
||||
? data.event_parameters as Record<string, unknown>
|
||||
: {},
|
||||
}
|
||||
|
||||
return {
|
||||
...node,
|
||||
data: sanitizedData,
|
||||
}
|
||||
}
|
||||
|
||||
export const sanitizeWorkflowDraftPayload = (params: WorkflowDraftSyncParams): WorkflowDraftSyncParams => {
|
||||
const { graph } = params
|
||||
|
||||
if (!graph?.nodes?.length)
|
||||
return params
|
||||
|
||||
const sanitizedNodes = graph.nodes.map((node) => {
|
||||
// First sanitize known node types (TriggerPlugin)
|
||||
const n = sanitizeTriggerPluginNode(node as Node<TriggerPluginNodePayload>) as Node<any>
|
||||
|
||||
// Normalize Start node variable json_schema: ensure dict, not string
|
||||
if ((n.data as any)?.type === BlockEnum.Start && Array.isArray((n.data as any).variables)) {
|
||||
const next = { ...n, data: { ...n.data } }
|
||||
next.data.variables = (n.data as any).variables.map((v: any) => {
|
||||
if (v && v.type === 'json_object' && typeof v.json_schema === 'string') {
|
||||
try {
|
||||
const obj = JSON.parse(v.json_schema)
|
||||
return { ...v, json_schema: obj }
|
||||
}
|
||||
catch {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return v
|
||||
})
|
||||
return next
|
||||
}
|
||||
|
||||
return n
|
||||
})
|
||||
|
||||
return {
|
||||
...params,
|
||||
graph: {
|
||||
...graph,
|
||||
nodes: sanitizedNodes,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const isTriggerPluginNode = (node: Node): node is Node<TriggerPluginHydratePayload> => {
|
||||
const data = node.data as unknown
|
||||
|
||||
if (!data || typeof data !== 'object')
|
||||
return false
|
||||
|
||||
const payload = data as Partial<TriggerPluginHydratePayload> & { type?: BlockEnum }
|
||||
|
||||
if (payload.type !== BlockEnum.TriggerPlugin)
|
||||
return false
|
||||
|
||||
return 'event_parameters' in payload
|
||||
}
|
||||
|
||||
const hydrateTriggerPluginNode = (node: Node): Node => {
|
||||
if (!isTriggerPluginNode(node))
|
||||
return node
|
||||
|
||||
const typedNode = node as Node<TriggerPluginHydratePayload>
|
||||
const data = typedNode.data
|
||||
const eventParameters = data.event_parameters ?? {}
|
||||
const parametersSchema = data.parameters_schema ?? data.paramSchemas ?? []
|
||||
const config = data.config ?? eventParameters ?? {}
|
||||
|
||||
const nextData: typeof data = {
|
||||
...data,
|
||||
config,
|
||||
paramSchemas: data.paramSchemas ?? parametersSchema,
|
||||
parameters_schema: parametersSchema,
|
||||
}
|
||||
|
||||
return {
|
||||
...typedNode,
|
||||
data: nextData,
|
||||
}
|
||||
}
|
||||
|
||||
export const hydrateWorkflowDraftResponse = (draft: FetchWorkflowDraftResponse): FetchWorkflowDraftResponse => {
|
||||
return produce(draft, (mutableDraft) => {
|
||||
if (!mutableDraft?.graph)
|
||||
return
|
||||
|
||||
if (mutableDraft.graph.nodes) {
|
||||
mutableDraft.graph.nodes = mutableDraft.graph.nodes
|
||||
.filter((node: Node) => !node.data?._isTempNode)
|
||||
.map((node: Node) => {
|
||||
if (node.data)
|
||||
removeTempProperties(node.data as Record<string, unknown>)
|
||||
|
||||
let n = hydrateTriggerPluginNode(node)
|
||||
// Normalize Start node variable json_schema to object when loading
|
||||
if ((n.data as any)?.type === BlockEnum.Start && Array.isArray((n.data as any).variables)) {
|
||||
const next = { ...n, data: { ...n.data } } as Node<any>
|
||||
next.data.variables = (n.data as any).variables.map((v: any) => {
|
||||
if (v && v.type === 'json_object' && typeof v.json_schema === 'string') {
|
||||
try {
|
||||
const obj = JSON.parse(v.json_schema)
|
||||
return { ...v, json_schema: obj }
|
||||
}
|
||||
catch {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return v
|
||||
})
|
||||
n = next
|
||||
}
|
||||
return n
|
||||
})
|
||||
}
|
||||
|
||||
if (mutableDraft.graph.edges) {
|
||||
mutableDraft.graph.edges = mutableDraft.graph.edges
|
||||
.filter((edge: Edge) => !edge.data?._isTemp)
|
||||
.map((edge: Edge) => {
|
||||
if (edge.data)
|
||||
removeTempProperties(edge.data as Record<string, unknown>)
|
||||
|
||||
return edge
|
||||
})
|
||||
}
|
||||
|
||||
if (mutableDraft.environment_variables) {
|
||||
mutableDraft.environment_variables = mutableDraft.environment_variables.map(env =>
|
||||
env.value_type === 'secret'
|
||||
? { ...env, value: '[__HIDDEN__]' }
|
||||
: env,
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user