|
|
|
|
@ -27,10 +27,9 @@ import {
|
|
|
|
|
getProcessedFilesFromResponse,
|
|
|
|
|
} from '@/app/components/base/file-uploader/utils'
|
|
|
|
|
import type { FileEntity } from '@/app/components/base/file-uploader/types'
|
|
|
|
|
import type { NodeTracing } from '@/types/workflow'
|
|
|
|
|
|
|
|
|
|
type GetAbortController = (abortController: AbortController) => void
|
|
|
|
|
interface SendCallback {
|
|
|
|
|
type SendCallback = {
|
|
|
|
|
onGetSuggestedQuestions?: (responseItemId: string, getAbortController: GetAbortController) => Promise<any>
|
|
|
|
|
}
|
|
|
|
|
export const useChat = (
|
|
|
|
|
@ -276,6 +275,7 @@ export const useChat = (
|
|
|
|
|
)
|
|
|
|
|
setSuggestQuestions(data)
|
|
|
|
|
}
|
|
|
|
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
|
|
|
catch (error) {
|
|
|
|
|
setSuggestQuestions([])
|
|
|
|
|
}
|
|
|
|
|
@ -331,8 +331,7 @@ export const useChat = (
|
|
|
|
|
responseItem.workflowProcess!.tracing!.push({
|
|
|
|
|
...data,
|
|
|
|
|
status: NodeRunningStatus.Running,
|
|
|
|
|
details: [],
|
|
|
|
|
} as any)
|
|
|
|
|
})
|
|
|
|
|
handleUpdateChatList(produce(chatListRef.current, (draft) => {
|
|
|
|
|
const currentIndex = draft.findIndex(item => item.id === responseItem.id)
|
|
|
|
|
draft[currentIndex] = {
|
|
|
|
|
@ -341,30 +340,21 @@ export const useChat = (
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
},
|
|
|
|
|
onIterationNext: ({ data }) => {
|
|
|
|
|
const tracing = responseItem.workflowProcess!.tracing!
|
|
|
|
|
const iterations = tracing.find(item => item.node_id === data.node_id
|
|
|
|
|
&& (item.execution_metadata?.parallel_id === data.execution_metadata?.parallel_id || item.parallel_id === data.execution_metadata?.parallel_id))!
|
|
|
|
|
iterations.details!.push([])
|
|
|
|
|
|
|
|
|
|
handleUpdateChatList(produce(chatListRef.current, (draft) => {
|
|
|
|
|
const currentIndex = draft.length - 1
|
|
|
|
|
draft[currentIndex] = responseItem
|
|
|
|
|
}))
|
|
|
|
|
},
|
|
|
|
|
onIterationFinish: ({ data }) => {
|
|
|
|
|
const tracing = responseItem.workflowProcess!.tracing!
|
|
|
|
|
const iterationsIndex = tracing.findIndex(item => item.node_id === data.node_id
|
|
|
|
|
&& (item.execution_metadata?.parallel_id === data.execution_metadata?.parallel_id || item.parallel_id === data.execution_metadata?.parallel_id))!
|
|
|
|
|
tracing[iterationsIndex] = {
|
|
|
|
|
...tracing[iterationsIndex],
|
|
|
|
|
...data,
|
|
|
|
|
status: NodeRunningStatus.Succeeded,
|
|
|
|
|
} as any
|
|
|
|
|
handleUpdateChatList(produce(chatListRef.current, (draft) => {
|
|
|
|
|
const currentIndex = draft.length - 1
|
|
|
|
|
draft[currentIndex] = responseItem
|
|
|
|
|
}))
|
|
|
|
|
const currentTracingIndex = responseItem.workflowProcess!.tracing!.findIndex(item => item.id === data.id)
|
|
|
|
|
if (currentTracingIndex > -1) {
|
|
|
|
|
responseItem.workflowProcess!.tracing[currentTracingIndex] = {
|
|
|
|
|
...responseItem.workflowProcess!.tracing[currentTracingIndex],
|
|
|
|
|
...data,
|
|
|
|
|
}
|
|
|
|
|
handleUpdateChatList(produce(chatListRef.current, (draft) => {
|
|
|
|
|
const currentIndex = draft.findIndex(item => item.id === responseItem.id)
|
|
|
|
|
draft[currentIndex] = {
|
|
|
|
|
...draft[currentIndex],
|
|
|
|
|
...responseItem,
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onNodeStarted: ({ data }) => {
|
|
|
|
|
if (data.iteration_id)
|
|
|
|
|
@ -386,16 +376,7 @@ export const useChat = (
|
|
|
|
|
if (data.iteration_id)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
const currentIndex = responseItem.workflowProcess!.tracing!.findIndex((item) => {
|
|
|
|
|
if (!item.execution_metadata?.parallel_id)
|
|
|
|
|
return item.node_id === data.node_id
|
|
|
|
|
return item.node_id === data.node_id && (item.execution_metadata?.parallel_id === data.execution_metadata?.parallel_id || item.parallel_id === data.execution_metadata?.parallel_id)
|
|
|
|
|
})
|
|
|
|
|
if (responseItem.workflowProcess!.tracing[currentIndex].retryDetail)
|
|
|
|
|
responseItem.workflowProcess!.tracing[currentIndex].retryDetail?.push(data as NodeTracing)
|
|
|
|
|
else
|
|
|
|
|
responseItem.workflowProcess!.tracing[currentIndex].retryDetail = [data as NodeTracing]
|
|
|
|
|
|
|
|
|
|
responseItem.workflowProcess!.tracing!.push(data)
|
|
|
|
|
handleUpdateChatList(produce(chatListRef.current, (draft) => {
|
|
|
|
|
const currentIndex = draft.findIndex(item => item.id === responseItem.id)
|
|
|
|
|
draft[currentIndex] = {
|
|
|
|
|
@ -408,27 +389,20 @@ export const useChat = (
|
|
|
|
|
if (data.iteration_id)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
const currentIndex = responseItem.workflowProcess!.tracing!.findIndex((item) => {
|
|
|
|
|
if (!item.execution_metadata?.parallel_id)
|
|
|
|
|
return item.node_id === data.node_id
|
|
|
|
|
return item.node_id === data.node_id && (item.execution_metadata?.parallel_id === data.execution_metadata?.parallel_id || item.parallel_id === data.execution_metadata?.parallel_id)
|
|
|
|
|
})
|
|
|
|
|
responseItem.workflowProcess!.tracing[currentIndex] = {
|
|
|
|
|
...(responseItem.workflowProcess!.tracing[currentIndex]?.extras
|
|
|
|
|
? { extras: responseItem.workflowProcess!.tracing[currentIndex].extras }
|
|
|
|
|
: {}),
|
|
|
|
|
...(responseItem.workflowProcess!.tracing[currentIndex]?.retryDetail
|
|
|
|
|
? { retryDetail: responseItem.workflowProcess!.tracing[currentIndex].retryDetail }
|
|
|
|
|
: {}),
|
|
|
|
|
...data,
|
|
|
|
|
} as any
|
|
|
|
|
handleUpdateChatList(produce(chatListRef.current, (draft) => {
|
|
|
|
|
const currentIndex = draft.findIndex(item => item.id === responseItem.id)
|
|
|
|
|
draft[currentIndex] = {
|
|
|
|
|
...draft[currentIndex],
|
|
|
|
|
...responseItem,
|
|
|
|
|
const currentTracingIndex = responseItem.workflowProcess!.tracing!.findIndex(item => item.id === data.id)
|
|
|
|
|
if (currentTracingIndex > -1) {
|
|
|
|
|
responseItem.workflowProcess!.tracing[currentTracingIndex] = {
|
|
|
|
|
...responseItem.workflowProcess!.tracing[currentTracingIndex],
|
|
|
|
|
...data,
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
handleUpdateChatList(produce(chatListRef.current, (draft) => {
|
|
|
|
|
const currentIndex = draft.findIndex(item => item.id === responseItem.id)
|
|
|
|
|
draft[currentIndex] = {
|
|
|
|
|
...draft[currentIndex],
|
|
|
|
|
...responseItem,
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|