Skip to content

Commit

Permalink
Merge branch 'feat/workflow' into deploy/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
zxhlyh committed Mar 21, 2024
2 parents 5eca84d + e366e12 commit 8648cf0
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 15 deletions.
11 changes: 8 additions & 3 deletions web/app/components/workflow/hooks/use-workflow-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export const useWorkflowRun = () => {
params: any,
callback?: IOtherOptions,
) => {
handleLoadBackupDraft()
const {
onWorkflowStarted,
onWorkflowFinished,
Expand All @@ -154,6 +153,8 @@ export const useWorkflowRun = () => {
if (appDetail?.mode === 'workflow')
url = `/apps/${appDetail.id}/workflows/draft/run`

let prevNodeId = ''

ssePost(
url,
{
Expand Down Expand Up @@ -203,6 +204,8 @@ export const useWorkflowRun = () => {
}
}))

prevNodeId = ''

if (onWorkflowFinished)
onWorkflowFinished(params)
},
Expand Down Expand Up @@ -244,7 +247,7 @@ export const useWorkflowRun = () => {
})
setNodes(newNodes)
const newEdges = produce(edges, (draft) => {
const edge = draft.find(edge => edge.target === data.node_id)
const edge = draft.find(edge => edge.target === data.node_id && edge.source === prevNodeId)

if (edge)
edge.data = { ...edge.data, _runned: true } as any
Expand Down Expand Up @@ -279,13 +282,15 @@ export const useWorkflowRun = () => {
})
setNodes(newNodes)

prevNodeId = data.node_id

if (onNodeFinished)
onNodeFinished(params)
},
...restCallback,
},
)
}, [store, reactflow, workflowStore, handleLoadBackupDraft])
}, [store, reactflow, workflowStore])

const handleStopRun = useCallback((taskId: string) => {
const appId = useAppStore.getState().appDetail?.id
Expand Down
2 changes: 1 addition & 1 deletion web/app/components/workflow/hooks/use-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export const useWorkflow = () => {
const { getNodes, setNodes } = store.getState()
const afterNodes = getAfterNodesInSameBranch(nodeId)
const effectNodes = findUsedVarNodes(oldValeSelector, afterNodes)
console.log(effectNodes)
// console.log(effectNodes)
if (effectNodes.length > 0) {
// debugger
const newNodes = getNodes().map((node) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,84 @@ export const updateNodeVars = (oldNode: Node, oldVarSelector: ValueSelector, new

break
}
case BlockEnum.KnowledgeRetrieval: {
const payload = data as KnowledgeRetrievalNodeType
if (payload.query_variable_selector.join('.') === oldVarSelector.join('.'))
payload.query_variable_selector = newVarSelector
break
}
case BlockEnum.IfElse: {
const payload = data as IfElseNodeType
if (payload.conditions) {
payload.conditions = payload.conditions.map((c) => {
if (c.variable_selector.join('.') === oldVarSelector.join('.'))
c.variable_selector = newVarSelector
return c
})
}
break
}
case BlockEnum.Code: {
const payload = data as CodeNodeType
if (payload.variables) {
payload.variables = payload.variables.map((v) => {
if (v.value_selector.join('.') === oldVarSelector.join('.'))
v.value_selector = newVarSelector
return v
})
}
break
}
case BlockEnum.TemplateTransform: {
const payload = data as TemplateTransformNodeType
if (payload.variables) {
payload.variables = payload.variables.map((v: any) => {
if (v.value_selector.join('.') === oldVarSelector.join('.'))
v.value_selector = newVarSelector
return v
})
}
break
}
case BlockEnum.QuestionClassifier: {
const payload = data as QuestionClassifierNodeType
if (payload.query_variable_selector.join('.') === oldVarSelector.join('.'))
payload.query_variable_selector = newVarSelector
break
}
case BlockEnum.HttpRequest: {
const payload = data as HttpNodeType
if (payload.variables) {
payload.variables = payload.variables.map((v) => {
if (v.value_selector.join('.') === oldVarSelector.join('.'))
v.value_selector = newVarSelector
return v
})
}
break
}
case BlockEnum.Tool: {
const payload = data as ToolNodeType
if (payload.tool_parameters) {
payload.tool_parameters = payload.tool_parameters.map((v) => {
if (v.value_selector?.join('.') === oldVarSelector.join('.'))
v.value_selector = newVarSelector
return v
})
}
break
}
case BlockEnum.VariableAssigner: {
const payload = data as VariableAssignerNodeType
if (payload.variables) {
payload.variables = payload.variables.map((v) => {
if (v.join('.') === oldVarSelector.join('.'))
v = newVarSelector
return v
})
}
break
}
}
})
return newNode
Expand Down
2 changes: 1 addition & 1 deletion web/app/components/workflow/nodes/answer/node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Node: FC<NodeProps<AnswerNodeType>> = ({
const { t } = useTranslation()

return (
<div className='px-3'>
<div className='mb-1 px-3 py-1'>
<InfoPanel title={t('workflow.nodes.answer.answer')} content={data.answer} />
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => {
const [selectedDatasets, setSelectedDatasets] = useState<DataSet[]>([])
useEffect(() => {
(async () => {
const inputs = inputRef.current
const datasetIds = inputs.dataset_ids
if (datasetIds?.length > 0) {
const { data: dataSetsWithDetail } = await fetchDatasets({ url: '/datasets', params: { page: 1, ids: datasetIds } })
Expand All @@ -196,7 +197,7 @@ const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => {
}, [])

useEffect(() => {
let query_variable_selector: ValueSelector = []
let query_variable_selector: ValueSelector = inputs.query_variable_selector
if (isChatMode && inputs.query_variable_selector.length === 0 && startNodeId)
query_variable_selector = [startNodeId, 'sys.query']

Expand Down
21 changes: 12 additions & 9 deletions web/app/components/workflow/panel/record.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import { memo, useCallback } from 'react'
import {
memo,
// useCallback,
} from 'react'
import {
useIsChatMode,
useWorkflow,
// useWorkflow,
} from '../hooks'
import Run from '../run'
import { useStore } from '../store'
import ChatRecord from './chat-record'
import type { WorkflowRunDetailResponse } from '@/models/log'
// import type { WorkflowRunDetailResponse } from '@/models/log'

const Record = () => {
const isChatMode = useIsChatMode()
const { renderTreeFromRecord } = useWorkflow()
// const { renderTreeFromRecord } = useWorkflow()
const historyWorkflowData = useStore(s => s.historyWorkflowData)

const getResultCallback = useCallback((res: WorkflowRunDetailResponse) => {
const { graph } = res
// const getResultCallback = useCallback((res: WorkflowRunDetailResponse) => {
// const { graph } = res

renderTreeFromRecord(graph.nodes, graph.edges, graph.viewport)
}, [renderTreeFromRecord])
// renderTreeFromRecord(graph.nodes, graph.edges, graph.viewport)
// }, [renderTreeFromRecord])

return (
<div className={`
Expand All @@ -33,7 +36,7 @@ const Record = () => {
: (
<Run
runID={historyWorkflowData?.id || ''}
getResultCallback={getResultCallback}
// getResultCallback={getResultCallback}
/>
)
}
Expand Down

0 comments on commit 8648cf0

Please sign in to comment.