feat(rag): pass credentialId to online document preview and wire to data source store

This commit is contained in:
twwu
2025-08-08 14:26:38 +08:00
parent df5a4e5c08
commit b21d991fdb
3 changed files with 7 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ import { useDatasetDetailContextWithSelector } from '@/context/dataset-detail'
import { usePreviewOnlineDocument } from '@/service/use-pipeline'
import Toast from '@/app/components/base/toast'
import { Markdown } from '@/app/components/base/markdown'
import { useDataSourceStore } from '../data-source/store'
type OnlineDocumentPreviewProps = {
currentPage: NotionPage
@@ -26,14 +27,17 @@ const OnlineDocumentPreview = ({
const [content, setContent] = useState('')
const pipelineId = useDatasetDetailContextWithSelector(state => state.dataset?.pipeline_id)
const { mutateAsync: getOnlineDocumentContent, isPending } = usePreviewOnlineDocument()
const dataSourceStore = useDataSourceStore()
useEffect(() => {
const { currentCredentialId } = dataSourceStore.getState()
getOnlineDocumentContent({
workspaceID: currentPage.workspace_id,
pageID: currentPage.page_id,
pageType: currentPage.type,
pipelineId: pipelineId || '',
datasourceNodeId,
credentialId: currentCredentialId,
}, {
onSuccess(data) {
setContent(data.content)
@@ -45,7 +49,6 @@ const OnlineDocumentPreview = ({
})
},
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentPage.page_id])
return (

View File

@@ -262,6 +262,7 @@ export type OnlineDocumentPreviewRequest = {
pageType: string
pipelineId: string
datasourceNodeId: string
credentialId: string
}
export type OnlineDocumentPreviewResponse = {

View File

@@ -340,12 +340,13 @@ export const usePreviewOnlineDocument = () => {
return useMutation({
mutationKey: [NAME_SPACE, 'preview-online-document'],
mutationFn: (params: OnlineDocumentPreviewRequest) => {
const { pipelineId, datasourceNodeId, workspaceID, pageID, pageType } = params
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,