2025-05-09 16:35:09 +08:00
|
|
|
import type { RAGPipelineVariables } from '@/models/pipeline'
|
2025-04-18 15:46:54 +08:00
|
|
|
import type { StateCreator } from 'zustand'
|
2025-05-23 14:25:38 +08:00
|
|
|
import type {
|
|
|
|
ToolWithProvider,
|
|
|
|
} from '@/app/components/workflow/types'
|
2025-05-26 14:13:28 +08:00
|
|
|
import type { DataSourceItem } from '@/app/components/workflow/block-selector/types'
|
|
|
|
import { transformDataSourceToTool } from '@/app/components/workflow/block-selector/utils'
|
2025-04-18 15:46:54 +08:00
|
|
|
|
|
|
|
export type RagPipelineSliceShape = {
|
2025-05-07 16:30:24 +08:00
|
|
|
pipelineId: string
|
2025-04-22 11:29:03 +08:00
|
|
|
showInputFieldDialog: boolean
|
|
|
|
setShowInputFieldDialog: (showInputFieldPanel: boolean) => void
|
2025-04-21 17:49:26 +08:00
|
|
|
nodesDefaultConfigs: Record<string, any>
|
|
|
|
setNodesDefaultConfigs: (nodesDefaultConfigs: Record<string, any>) => void
|
2025-05-09 16:35:09 +08:00
|
|
|
ragPipelineVariables: RAGPipelineVariables
|
|
|
|
setRagPipelineVariables: (ragPipelineVariables: RAGPipelineVariables) => void
|
2025-05-23 14:25:38 +08:00
|
|
|
dataSourceList: ToolWithProvider[]
|
2025-05-26 14:13:28 +08:00
|
|
|
setDataSourceList: (dataSourceList: DataSourceItem[]) => void
|
2025-04-18 15:46:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export type CreateRagPipelineSliceSlice = StateCreator<RagPipelineSliceShape>
|
|
|
|
export const createRagPipelineSliceSlice: StateCreator<RagPipelineSliceShape> = set => ({
|
2025-05-07 16:30:24 +08:00
|
|
|
pipelineId: '',
|
2025-04-22 11:29:03 +08:00
|
|
|
showInputFieldDialog: false,
|
|
|
|
setShowInputFieldDialog: showInputFieldDialog => set(() => ({ showInputFieldDialog })),
|
2025-04-21 17:49:26 +08:00
|
|
|
nodesDefaultConfigs: {},
|
|
|
|
setNodesDefaultConfigs: nodesDefaultConfigs => set(() => ({ nodesDefaultConfigs })),
|
2025-05-19 16:26:13 +08:00
|
|
|
ragPipelineVariables: [],
|
2025-05-09 16:35:09 +08:00
|
|
|
setRagPipelineVariables: (ragPipelineVariables: RAGPipelineVariables) => set(() => ({ ragPipelineVariables })),
|
2025-05-23 14:25:38 +08:00
|
|
|
dataSourceList: [],
|
2025-05-26 14:13:28 +08:00
|
|
|
setDataSourceList: (dataSourceList: DataSourceItem[]) => {
|
2025-06-03 10:14:48 +08:00
|
|
|
const formattedDataSourceList = dataSourceList.map(item => transformDataSourceToTool(item))
|
|
|
|
set(() => ({ dataSourceList: formattedDataSourceList }))
|
2025-05-26 14:13:28 +08:00
|
|
|
},
|
2025-04-18 15:46:54 +08:00
|
|
|
})
|