This commit is contained in:
StyleZhang 2024-03-07 19:42:46 +08:00
parent 783f7a9b13
commit 072f5caa06
6 changed files with 44 additions and 26 deletions

View File

@ -26,7 +26,7 @@ const CustomConnectionLine = ({ fromX, fromY, toX, toY }: ConnectionLineComponen
d={edgePath} d={edgePath}
/> />
<rect <rect
x={toX - 2} x={toX}
y={toY - 4} y={toY - 4}
width={2} width={2}
height={8} height={8}

View File

@ -138,15 +138,17 @@ const WorkflowWrap: FC<WorkflowProps> = ({
useStore.setState({ draftUpdatedAt: data.updated_at }) useStore.setState({ draftUpdatedAt: data.updated_at })
}, [data]) }, [data])
const startNode = { const startNode = useMemo(() => {
id: `${Date.now()}`, return {
type: 'custom', id: `${Date.now()}`,
data: nodesInitialData.start, type: 'custom',
position: { data: nodesInitialData.start,
x: 100, position: {
y: 100, x: 100,
}, y: 100,
} },
}
}, [nodesInitialData])
const nodesData = useMemo(() => { const nodesData = useMemo(() => {
if (nodes) if (nodes)
@ -156,7 +158,7 @@ const WorkflowWrap: FC<WorkflowProps> = ({
return data.graph.nodes return data.graph.nodes
return [startNode] return [startNode]
}, [data, nodes]) }, [data, nodes, startNode])
const edgesData = useMemo(() => { const edgesData = useMemo(() => {
if (edges) if (edges)
return edges return edges
@ -165,7 +167,7 @@ const WorkflowWrap: FC<WorkflowProps> = ({
return data.graph.edges return data.graph.edges
return [] return []
}, [data, nodes]) }, [data, edges])
const handleFetchCollectionList = async () => { const handleFetchCollectionList = async () => {
const toolsets = await fetchCollectionList() const toolsets = await fetchCollectionList()
@ -183,16 +185,22 @@ const WorkflowWrap: FC<WorkflowProps> = ({
handleFetchCollectionList() handleFetchCollectionList()
}, []) }, [])
if (error && appDetail) { if (error && !error.bodyUsed && appDetail) {
syncWorkflowDraft({ error.json().then((err: any) => {
url: `/apps/${appDetail.id}/workflows/draft`, if (err.code === 'draft_workflow_not_exist') {
params: { syncWorkflowDraft({
graph: { url: `/apps/${appDetail.id}/workflows/draft`,
nodes: [startNode], params: {
edges: [], graph: {
}, nodes: [startNode],
features: {}, edges: [],
}, },
features: {},
},
}).then((res) => {
useStore.setState({ draftUpdatedAt: res.updated_at })
})
}
}) })
} }
@ -204,6 +212,9 @@ const WorkflowWrap: FC<WorkflowProps> = ({
) )
} }
if (!data)
return null
const features = data?.features || {} const features = data?.features || {}
const initialFeatures: FeaturesData = { const initialFeatures: FeaturesData = {
opening: { opening: {

View File

@ -2,6 +2,7 @@ import {
memo, memo,
useCallback, useCallback,
} from 'react' } from 'react'
import { useTranslation } from 'react-i18next'
import type { import type {
CommonNodeType, CommonNodeType,
OnSelectBlock, OnSelectBlock,
@ -23,6 +24,7 @@ const Item = ({
branchName, branchName,
data, data,
}: ItemProps) => { }: ItemProps) => {
const { t } = useTranslation()
const { handleNodeChange } = useWorkflow() const { handleNodeChange } = useWorkflow()
const handleSelect = useCallback<OnSelectBlock>((type, toolDefaultValue) => { const handleSelect = useCallback<OnSelectBlock>((type, toolDefaultValue) => {
handleNodeChange(nodeId, type, sourceHandle, toolDefaultValue) handleNodeChange(nodeId, type, sourceHandle, toolDefaultValue)
@ -35,10 +37,10 @@ const Item = ({
${open && '!bg-gray-100 !flex'} ${open && '!bg-gray-100 !flex'}
`} `}
> >
Change {t('workflow.panel.change')}
</Button> </Button>
) )
}, []) }, [t])
return ( return (
<div <div

View File

@ -144,10 +144,13 @@ export const getLayoutByDagre = (nodes: Node[], edges: Edge[]) => {
export const canRunBySingle = (nodeType: BlockEnum) => { export const canRunBySingle = (nodeType: BlockEnum) => {
return nodeType === BlockEnum.LLM return nodeType === BlockEnum.LLM
|| nodeType === BlockEnum.KnowledgeRetrieval || nodeType === BlockEnum.KnowledgeRetrieval
|| nodeType === BlockEnum.IfElse
|| nodeType === BlockEnum.Code || nodeType === BlockEnum.Code
|| nodeType === BlockEnum.TemplateTransform || nodeType === BlockEnum.TemplateTransform
|| nodeType === BlockEnum.QuestionClassifier || nodeType === BlockEnum.QuestionClassifier
|| nodeType === BlockEnum.HttpRequest || nodeType === BlockEnum.HttpRequest
|| nodeType === BlockEnum.Tool || nodeType === BlockEnum.Tool
} }
export const getVariables = () => {
}

View File

@ -70,6 +70,7 @@ const translation = {
checklist: 'Checklist', checklist: 'Checklist',
checklistTip: 'Make sure all issues are resolved before publishing', checklistTip: 'Make sure all issues are resolved before publishing',
organizeBlocks: 'Organize blocks', organizeBlocks: 'Organize blocks',
change: 'Change',
}, },
nodes: { nodes: {
common: { common: {

View File

@ -40,7 +40,7 @@ const translation = {
blocks: { blocks: {
'start': '开始', 'start': '开始',
'end': '结束', 'end': '结束',
'direct-answer': '直接回', 'direct-answer': '直接回',
'llm': 'LLM', 'llm': 'LLM',
'knowledge-retrieval': '知识检索', 'knowledge-retrieval': '知识检索',
'question-classifier': '问题分类器', 'question-classifier': '问题分类器',
@ -70,6 +70,7 @@ const translation = {
checklist: '检查清单', checklist: '检查清单',
checklistTip: '发布前确保所有问题均已解决', checklistTip: '发布前确保所有问题均已解决',
organizeBlocks: '整理节点', organizeBlocks: '整理节点',
change: '更改',
}, },
nodes: { nodes: {
common: { common: {