2025-05-07 14:29:01 +08:00
|
|
|
import type { MutationOptions } from '@tanstack/react-query'
|
2025-05-07 11:30:13 +08:00
|
|
|
import { useMutation, useQuery } from '@tanstack/react-query'
|
2025-05-07 18:09:38 +08:00
|
|
|
import { del, get, patch, post } from './base'
|
2025-05-07 11:30:13 +08:00
|
|
|
import type {
|
2025-05-16 15:14:50 +08:00
|
|
|
DeleteTemplateResponse,
|
|
|
|
ExportTemplateDSLResponse,
|
2025-05-14 14:49:01 +08:00
|
|
|
ImportPipelineDSLConfirmResponse,
|
2025-05-07 18:09:38 +08:00
|
|
|
ImportPipelineDSLRequest,
|
|
|
|
ImportPipelineDSLResponse,
|
2025-05-14 14:49:01 +08:00
|
|
|
PipelineCheckDependenciesResponse,
|
2025-05-20 11:42:22 +08:00
|
|
|
PipelineDatasourceNodeRunRequest,
|
2025-05-21 10:53:18 +08:00
|
|
|
PipelineDatasourceNodeRunResponse,
|
2025-05-20 11:42:22 +08:00
|
|
|
PipelineProcessingParamsRequest,
|
2025-05-08 18:29:49 +08:00
|
|
|
PipelineProcessingParamsResponse,
|
2025-05-07 11:30:13 +08:00
|
|
|
PipelineTemplateByIdResponse,
|
|
|
|
PipelineTemplateListParams,
|
|
|
|
PipelineTemplateListResponse,
|
2025-05-21 16:37:02 +08:00
|
|
|
PublishedPipelineInfoResponse,
|
2025-05-16 15:14:50 +08:00
|
|
|
UpdateTemplateInfoRequest,
|
|
|
|
UpdateTemplateInfoResponse,
|
2025-05-07 11:30:13 +08:00
|
|
|
} from '@/models/pipeline'
|
2025-05-16 14:53:39 +08:00
|
|
|
import type { ToolWithProvider } from '@/app/components/workflow/types'
|
2025-05-07 11:30:13 +08:00
|
|
|
|
|
|
|
const NAME_SPACE = 'pipeline'
|
|
|
|
|
|
|
|
export const usePipelineTemplateList = (params: PipelineTemplateListParams) => {
|
|
|
|
return useQuery<PipelineTemplateListResponse>({
|
|
|
|
queryKey: [NAME_SPACE, 'template', 'list'],
|
|
|
|
queryFn: () => {
|
2025-05-16 15:14:50 +08:00
|
|
|
return get<PipelineTemplateListResponse>('/rag/pipeline/templates', { params })
|
2025-05-07 11:30:13 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2025-05-07 18:09:38 +08:00
|
|
|
export const usePipelineTemplateById = (templateId: string, enabled: boolean) => {
|
2025-05-07 11:30:13 +08:00
|
|
|
return useQuery<PipelineTemplateByIdResponse>({
|
|
|
|
queryKey: [NAME_SPACE, 'template', templateId],
|
|
|
|
queryFn: () => {
|
2025-05-16 15:14:50 +08:00
|
|
|
return get<PipelineTemplateByIdResponse>(`/rag/pipeline/templates/${templateId}`)
|
2025-05-07 11:30:13 +08:00
|
|
|
},
|
2025-05-07 18:09:38 +08:00
|
|
|
enabled,
|
2025-05-07 11:30:13 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2025-05-16 15:14:50 +08:00
|
|
|
export const useUpdateTemplateInfo = (
|
|
|
|
mutationOptions: MutationOptions<UpdateTemplateInfoResponse, Error, UpdateTemplateInfoRequest> = {},
|
2025-05-07 14:29:01 +08:00
|
|
|
) => {
|
2025-05-07 11:30:13 +08:00
|
|
|
return useMutation({
|
|
|
|
mutationKey: [NAME_SPACE, 'template', 'update'],
|
2025-05-16 15:14:50 +08:00
|
|
|
mutationFn: (request: UpdateTemplateInfoRequest) => {
|
|
|
|
const { template_id, ...rest } = request
|
|
|
|
return patch<UpdateTemplateInfoResponse>(`/rag/customized/templates/${template_id}`, {
|
2025-05-07 11:30:13 +08:00
|
|
|
body: rest,
|
|
|
|
})
|
|
|
|
},
|
2025-05-07 14:29:01 +08:00
|
|
|
...mutationOptions,
|
2025-05-07 11:30:13 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2025-05-16 15:14:50 +08:00
|
|
|
export const useDeleteTemplate = (
|
|
|
|
mutationOptions: MutationOptions<DeleteTemplateResponse, Error, string> = {},
|
2025-05-07 14:29:01 +08:00
|
|
|
) => {
|
2025-05-07 11:30:13 +08:00
|
|
|
return useMutation({
|
|
|
|
mutationKey: [NAME_SPACE, 'template', 'delete'],
|
2025-05-16 15:14:50 +08:00
|
|
|
mutationFn: (templateId: string) => {
|
|
|
|
return del<DeleteTemplateResponse>(`/rag/customized/templates/${templateId}`)
|
2025-05-07 11:30:13 +08:00
|
|
|
},
|
2025-05-07 14:29:01 +08:00
|
|
|
...mutationOptions,
|
2025-05-07 11:30:13 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2025-05-16 15:14:50 +08:00
|
|
|
export const useExportTemplateDSL = (
|
2025-05-16 16:32:25 +08:00
|
|
|
mutationOptions: MutationOptions<ExportTemplateDSLResponse, Error, string> = {},
|
2025-05-07 14:29:01 +08:00
|
|
|
) => {
|
|
|
|
return useMutation({
|
2025-05-14 14:49:01 +08:00
|
|
|
mutationKey: [NAME_SPACE, 'dsl-export'],
|
2025-05-16 15:14:50 +08:00
|
|
|
mutationFn: (templateId: string) => {
|
|
|
|
return get<ExportTemplateDSLResponse>(`/rag/customized/templates/${templateId}`)
|
2025-05-07 11:30:13 +08:00
|
|
|
},
|
2025-05-07 14:29:01 +08:00
|
|
|
...mutationOptions,
|
2025-05-07 11:30:13 +08:00
|
|
|
})
|
|
|
|
}
|
2025-05-07 18:09:38 +08:00
|
|
|
|
|
|
|
export const useImportPipelineDSL = (
|
|
|
|
mutationOptions: MutationOptions<ImportPipelineDSLResponse, Error, ImportPipelineDSLRequest> = {},
|
|
|
|
) => {
|
|
|
|
return useMutation({
|
2025-05-14 14:49:01 +08:00
|
|
|
mutationKey: [NAME_SPACE, 'dsl-import'],
|
2025-05-07 18:09:38 +08:00
|
|
|
mutationFn: (request: ImportPipelineDSLRequest) => {
|
2025-05-16 16:32:25 +08:00
|
|
|
return post<ImportPipelineDSLResponse>('/rag/pipelines/imports', { body: request })
|
2025-05-14 14:49:01 +08:00
|
|
|
},
|
|
|
|
...mutationOptions,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useImportPipelineDSLConfirm = (
|
2025-05-14 16:27:59 +08:00
|
|
|
mutationOptions: MutationOptions<ImportPipelineDSLConfirmResponse, Error, string> = {},
|
2025-05-14 14:49:01 +08:00
|
|
|
) => {
|
|
|
|
return useMutation({
|
|
|
|
mutationKey: [NAME_SPACE, 'dsl-import-confirm'],
|
2025-05-14 16:27:59 +08:00
|
|
|
mutationFn: (importId: string) => {
|
2025-05-20 11:42:22 +08:00
|
|
|
return post<ImportPipelineDSLConfirmResponse>(`/rag/pipelines/imports/${importId}/confirm`)
|
2025-05-14 14:49:01 +08:00
|
|
|
},
|
|
|
|
...mutationOptions,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useCheckPipelineDependencies = (
|
|
|
|
mutationOptions: MutationOptions<PipelineCheckDependenciesResponse, Error, string> = {},
|
|
|
|
) => {
|
|
|
|
return useMutation({
|
|
|
|
mutationKey: [NAME_SPACE, 'check-dependencies'],
|
|
|
|
mutationFn: (pipelineId: string) => {
|
|
|
|
return post<PipelineCheckDependenciesResponse>(`/rag/pipelines/imports/${pipelineId}/check-dependencies`)
|
2025-05-07 18:09:38 +08:00
|
|
|
},
|
|
|
|
...mutationOptions,
|
|
|
|
})
|
|
|
|
}
|
2025-05-08 18:29:49 +08:00
|
|
|
|
2025-05-21 10:53:18 +08:00
|
|
|
export const useDatasourceNodeRun = (
|
|
|
|
mutationOptions: MutationOptions<PipelineDatasourceNodeRunResponse, Error, PipelineDatasourceNodeRunRequest> = {},
|
|
|
|
) => {
|
2025-05-20 11:42:22 +08:00
|
|
|
return useMutation({
|
|
|
|
mutationKey: [NAME_SPACE, 'datasource-node-run'],
|
|
|
|
mutationFn: (request: PipelineDatasourceNodeRunRequest) => {
|
|
|
|
const { pipeline_id, node_id, ...rest } = request
|
2025-05-21 10:53:18 +08:00
|
|
|
return post<PipelineDatasourceNodeRunResponse>(`/rag/pipelines/${pipeline_id}/workflows/published/nodes/${node_id}/run`, {
|
2025-05-20 11:42:22 +08:00
|
|
|
body: rest,
|
|
|
|
})
|
|
|
|
},
|
2025-05-21 10:53:18 +08:00
|
|
|
...mutationOptions,
|
2025-05-20 11:42:22 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2025-05-14 14:49:01 +08:00
|
|
|
// Get the config of shared input fields
|
2025-05-20 11:42:22 +08:00
|
|
|
export const usePipelineProcessingParams = (params: PipelineProcessingParamsRequest) => {
|
|
|
|
const { pipeline_id, node_id } = params
|
2025-05-08 18:29:49 +08:00
|
|
|
return useQuery<PipelineProcessingParamsResponse>({
|
2025-05-20 11:42:22 +08:00
|
|
|
queryKey: [NAME_SPACE, 'pipeline-processing-params', pipeline_id],
|
2025-05-08 18:29:49 +08:00
|
|
|
queryFn: () => {
|
2025-05-20 11:42:22 +08:00
|
|
|
return get<PipelineProcessingParamsResponse>(`/rag/pipelines/${pipeline_id}/workflows/processing/parameters`, {
|
|
|
|
params: {
|
|
|
|
node_id,
|
|
|
|
},
|
|
|
|
})
|
2025-05-08 18:29:49 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2025-05-16 14:53:39 +08:00
|
|
|
|
|
|
|
export const useDataSourceList = (enabled?: boolean) => {
|
|
|
|
return useQuery<ToolWithProvider[]>({
|
|
|
|
enabled,
|
|
|
|
queryKey: [NAME_SPACE, 'data-source'],
|
|
|
|
queryFn: () => {
|
|
|
|
return get('/rag/pipelines/datasource-plugins')
|
|
|
|
},
|
|
|
|
retry: false,
|
|
|
|
})
|
|
|
|
}
|
2025-05-21 16:37:02 +08:00
|
|
|
|
|
|
|
export const usePublishedPipelineInfo = (pipelineId: string) => {
|
|
|
|
return useQuery<PublishedPipelineInfoResponse>({
|
|
|
|
queryKey: [NAME_SPACE, 'published-pipeline', pipelineId],
|
|
|
|
queryFn: () => {
|
|
|
|
return get<PublishedPipelineInfoResponse>(`/rag/pipelines/${pipelineId}/workflows/publish`)
|
|
|
|
},
|
2025-05-22 14:49:40 +08:00
|
|
|
enabled: !!pipelineId,
|
2025-05-21 16:37:02 +08:00
|
|
|
})
|
|
|
|
}
|