mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 12:37:20 +08:00
fix: Enhance data source handling by adding error response type and updating local file and online document slices
This commit is contained in:
parent
76c418c0b7
commit
cf4f652105
@ -1,11 +1,12 @@
|
|||||||
import type { StateCreator } from 'zustand'
|
import type { StateCreator } from 'zustand'
|
||||||
import type { FileItem } from '@/models/datasets'
|
import type { DocumentItem, FileItem } from '@/models/datasets'
|
||||||
|
|
||||||
export type LocalFileSliceShape = {
|
export type LocalFileSliceShape = {
|
||||||
localFileList: FileItem[]
|
localFileList: FileItem[]
|
||||||
setLocalFileList: (fileList: FileItem[]) => void
|
setLocalFileList: (fileList: FileItem[]) => void
|
||||||
currentLocalFile: File | undefined
|
currentLocalFile: File | undefined
|
||||||
setCurrentLocalFile: (file: File | undefined) => void
|
setCurrentLocalFile: (file: File | undefined) => void
|
||||||
|
previewLocalFileRef: React.MutableRefObject<DocumentItem | undefined>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createLocalFileSlice: StateCreator<LocalFileSliceShape> = (set) => {
|
export const createLocalFileSlice: StateCreator<LocalFileSliceShape> = (set) => {
|
||||||
@ -18,5 +19,6 @@ export const createLocalFileSlice: StateCreator<LocalFileSliceShape> = (set) =>
|
|||||||
setCurrentLocalFile: (file: File | undefined) => set(() => ({
|
setCurrentLocalFile: (file: File | undefined) => set(() => ({
|
||||||
currentLocalFile: file,
|
currentLocalFile: file,
|
||||||
})),
|
})),
|
||||||
|
previewLocalFileRef: { current: undefined },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ export type OnlineDocumentSliceShape = {
|
|||||||
setSelectedPagesId: (selectedPagesId: Set<string>) => void
|
setSelectedPagesId: (selectedPagesId: Set<string>) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createOnlineDocumentSlice: StateCreator<OnlineDocumentSliceShape> = (set, get) => {
|
export const createOnlineDocumentSlice: StateCreator<OnlineDocumentSliceShape> = (set) => {
|
||||||
return ({
|
return ({
|
||||||
documentData: [],
|
documentData: [],
|
||||||
setDocumentData: (documentData: DataSourceNotionWorkspace[]) => set(() => ({
|
setDocumentData: (documentData: DataSourceNotionWorkspace[]) => set(() => ({
|
||||||
@ -38,7 +38,7 @@ export const createOnlineDocumentSlice: StateCreator<OnlineDocumentSliceShape> =
|
|||||||
setCurrentDocument: (document: NotionPage | undefined) => set(() => ({
|
setCurrentDocument: (document: NotionPage | undefined) => set(() => ({
|
||||||
currentDocument: document,
|
currentDocument: document,
|
||||||
})),
|
})),
|
||||||
selectedPagesId: new Set([...get().onlineDocuments.map(doc => doc.page_id)]),
|
selectedPagesId: new Set(),
|
||||||
setSelectedPagesId: (selectedPagesId: Set<string>) => set(() => ({
|
setSelectedPagesId: (selectedPagesId: Set<string>) => set(() => ({
|
||||||
selectedPagesId,
|
selectedPagesId,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { StateCreator } from 'zustand'
|
import type { StateCreator } from 'zustand'
|
||||||
import { type OnlineDriveFile, OnlineDriveFileType } from '@/models/pipeline'
|
import type { OnlineDriveFile } from '@/models/pipeline'
|
||||||
|
|
||||||
export type OnlineDriveSliceShape = {
|
export type OnlineDriveSliceShape = {
|
||||||
prefix: string[]
|
prefix: string[]
|
||||||
@ -32,11 +32,7 @@ export const createOnlineDriveSlice: StateCreator<OnlineDriveSliceShape> = (set)
|
|||||||
setSelectedFileList: (selectedFileList: string[]) => set(() => ({
|
setSelectedFileList: (selectedFileList: string[]) => set(() => ({
|
||||||
selectedFileList,
|
selectedFileList,
|
||||||
})),
|
})),
|
||||||
fileList: [{
|
fileList: [],
|
||||||
key: 'Bucket_1',
|
|
||||||
size: 1024, // unit bytes
|
|
||||||
type: OnlineDriveFileType.bucket,
|
|
||||||
}],
|
|
||||||
setFileList: (fileList: OnlineDriveFile[]) => set(() => ({
|
setFileList: (fileList: OnlineDriveFile[]) => set(() => ({
|
||||||
fileList,
|
fileList,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import { ContentType, base, baseOptions, getAccessToken } from './fetch'
|
|||||||
import { asyncRunSafe } from '@/utils'
|
import { asyncRunSafe } from '@/utils'
|
||||||
import type {
|
import type {
|
||||||
DataSourceNodeCompletedResponse,
|
DataSourceNodeCompletedResponse,
|
||||||
|
DataSourceNodeErrorResponse,
|
||||||
DataSourceNodeProcessingResponse,
|
DataSourceNodeProcessingResponse,
|
||||||
} from '@/types/pipeline'
|
} from '@/types/pipeline'
|
||||||
const TIME_OUT = 100000
|
const TIME_OUT = 100000
|
||||||
@ -69,6 +70,7 @@ export type IOnAgentLog = (agentLog: AgentLogResponse) => void
|
|||||||
|
|
||||||
export type IOnDataSourceNodeProcessing = (dataSourceNodeProcessing: DataSourceNodeProcessingResponse) => void
|
export type IOnDataSourceNodeProcessing = (dataSourceNodeProcessing: DataSourceNodeProcessingResponse) => void
|
||||||
export type IOnDataSourceNodeCompleted = (dataSourceNodeCompleted: DataSourceNodeCompletedResponse) => void
|
export type IOnDataSourceNodeCompleted = (dataSourceNodeCompleted: DataSourceNodeCompletedResponse) => void
|
||||||
|
export type IOnDataSourceNodeError = (dataSourceNodeError: DataSourceNodeErrorResponse) => void
|
||||||
|
|
||||||
export type IOtherOptions = {
|
export type IOtherOptions = {
|
||||||
isPublicAPI?: boolean
|
isPublicAPI?: boolean
|
||||||
@ -108,6 +110,7 @@ export type IOtherOptions = {
|
|||||||
// Pipeline data source node run
|
// Pipeline data source node run
|
||||||
onDataSourceNodeProcessing?: IOnDataSourceNodeProcessing
|
onDataSourceNodeProcessing?: IOnDataSourceNodeProcessing
|
||||||
onDataSourceNodeCompleted?: IOnDataSourceNodeCompleted
|
onDataSourceNodeCompleted?: IOnDataSourceNodeCompleted
|
||||||
|
onDataSourceNodeError?: IOnDataSourceNodeError
|
||||||
}
|
}
|
||||||
|
|
||||||
function unicodeToChar(text: string) {
|
function unicodeToChar(text: string) {
|
||||||
@ -165,6 +168,7 @@ const handleStream = (
|
|||||||
onAgentLog?: IOnAgentLog,
|
onAgentLog?: IOnAgentLog,
|
||||||
onDataSourceNodeProcessing?: IOnDataSourceNodeProcessing,
|
onDataSourceNodeProcessing?: IOnDataSourceNodeProcessing,
|
||||||
onDataSourceNodeCompleted?: IOnDataSourceNodeCompleted,
|
onDataSourceNodeCompleted?: IOnDataSourceNodeCompleted,
|
||||||
|
onDataSourceNodeError?: IOnDataSourceNodeError,
|
||||||
) => {
|
) => {
|
||||||
if (!response.ok)
|
if (!response.ok)
|
||||||
throw new Error('Network response was not ok')
|
throw new Error('Network response was not ok')
|
||||||
@ -289,6 +293,9 @@ const handleStream = (
|
|||||||
else if (bufferObj.event === 'datasource_completed') {
|
else if (bufferObj.event === 'datasource_completed') {
|
||||||
onDataSourceNodeCompleted?.(bufferObj as DataSourceNodeCompletedResponse)
|
onDataSourceNodeCompleted?.(bufferObj as DataSourceNodeCompletedResponse)
|
||||||
}
|
}
|
||||||
|
else if (bufferObj.event === 'datasource_error') {
|
||||||
|
onDataSourceNodeError?.(bufferObj as DataSourceNodeErrorResponse)
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
console.warn(`Unknown event: ${bufferObj.event}`, bufferObj)
|
console.warn(`Unknown event: ${bufferObj.event}`, bufferObj)
|
||||||
}
|
}
|
||||||
@ -387,6 +394,7 @@ export const ssePost = async (
|
|||||||
onLoopFinish,
|
onLoopFinish,
|
||||||
onDataSourceNodeProcessing,
|
onDataSourceNodeProcessing,
|
||||||
onDataSourceNodeCompleted,
|
onDataSourceNodeCompleted,
|
||||||
|
onDataSourceNodeError,
|
||||||
} = otherOptions
|
} = otherOptions
|
||||||
const abortController = new AbortController()
|
const abortController = new AbortController()
|
||||||
|
|
||||||
@ -486,6 +494,7 @@ export const ssePost = async (
|
|||||||
onAgentLog,
|
onAgentLog,
|
||||||
onDataSourceNodeProcessing,
|
onDataSourceNodeProcessing,
|
||||||
onDataSourceNodeCompleted,
|
onDataSourceNodeCompleted,
|
||||||
|
onDataSourceNodeError,
|
||||||
)
|
)
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
if (e.toString() !== 'AbortError: The user aborted a request.' && !e.toString().errorMessage.includes('TypeError: Cannot assign to read only property'))
|
if (e.toString() !== 'AbortError: The user aborted a request.' && !e.toString().errorMessage.includes('TypeError: Cannot assign to read only property'))
|
||||||
|
|||||||
@ -15,3 +15,8 @@ export type DataSourceNodeCompletedResponse = {
|
|||||||
data: any
|
data: any
|
||||||
time_consuming?: number
|
time_consuming?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DataSourceNodeErrorResponse = {
|
||||||
|
event: 'datasource_error'
|
||||||
|
error: string
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user