Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
a55a7603
Commit
a55a7603
authored
Mar 13, 2024
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
split hooks
parent
64fa343d
Changes
25
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
586 additions
and
491 deletions
+586
-491
features.tsx
web/app/components/workflow/features.tsx
+2
-2
index.tsx
web/app/components/workflow/header/index.tsx
+4
-4
run-and-history.tsx
web/app/components/workflow/header/run-and-history.tsx
+3
-3
index.ts
web/app/components/workflow/hooks/index.ts
+7
-0
use-edges-interactions.ts
web/app/components/workflow/hooks/use-edges-interactions.ts
+118
-0
use-node-data-update.ts
web/app/components/workflow/hooks/use-node-data-update.ts
+43
-0
use-nodes-data.ts
web/app/components/workflow/hooks/use-nodes-data.ts
+27
-0
use-nodes-interactions.ts
web/app/components/workflow/hooks/use-nodes-interactions.ts
+15
-435
use-nodes-sync-draft.ts
web/app/components/workflow/hooks/use-nodes-sync-draft.ts
+85
-0
use-workflow-run.ts
web/app/components/workflow/hooks/use-workflow-run.ts
+103
-0
use-workflow.ts
web/app/components/workflow/hooks/use-workflow.ts
+126
-0
index.tsx
web/app/components/workflow/index.tsx
+7
-5
add.tsx
...ponents/workflow/nodes/_base/components/next-step/add.tsx
+2
-2
item.tsx
...onents/workflow/nodes/_base/components/next-step/item.tsx
+2
-2
node-control.tsx
...mponents/workflow/nodes/_base/components/node-control.tsx
+2
-2
node-handle.tsx
...omponents/workflow/nodes/_base/components/node-handle.tsx
+3
-3
change-block.tsx
...ow/nodes/_base/components/panel-operator/change-block.tsx
+2
-2
index.tsx
.../workflow/nodes/_base/components/panel-operator/index.tsx
+2
-2
use-node-crud.ts
...pp/components/workflow/nodes/_base/hooks/use-node-crud.ts
+3
-3
use-one-step-run.ts
...components/workflow/nodes/_base/hooks/use-one-step-run.ts
+2
-2
panel.tsx
web/app/components/workflow/nodes/_base/panel.tsx
+12
-7
class-list.tsx
...kflow/nodes/question-classifier/components/class-list.tsx
+2
-2
zoom-in-out.tsx
web/app/components/workflow/operator/zoom-in-out.tsx
+2
-2
hooks.ts
web/app/components/workflow/panel/debug-and-preview/hooks.ts
+3
-3
inputs-panel.tsx
web/app/components/workflow/panel/inputs-panel.tsx
+9
-10
No files found.
web/app/components/workflow/features.tsx
View file @
a55a7603
...
@@ -4,7 +4,7 @@ import {
...
@@ -4,7 +4,7 @@ import {
}
from
'react'
}
from
'react'
import
{
useTranslation
}
from
'react-i18next'
import
{
useTranslation
}
from
'react-i18next'
import
{
useStore
}
from
'./store'
import
{
useStore
}
from
'./store'
import
{
use
Workflow
}
from
'./hooks'
import
{
use
NodesSyncDraft
}
from
'./hooks'
import
{
XClose
}
from
'@/app/components/base/icons/src/vender/line/general'
import
{
XClose
}
from
'@/app/components/base/icons/src/vender/line/general'
import
{
import
{
FeaturesChoose
,
FeaturesChoose
,
...
@@ -14,7 +14,7 @@ import {
...
@@ -14,7 +14,7 @@ import {
const
Features
=
()
=>
{
const
Features
=
()
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
setShowFeaturesPanel
=
useStore
(
state
=>
state
.
setShowFeaturesPanel
)
const
setShowFeaturesPanel
=
useStore
(
state
=>
state
.
setShowFeaturesPanel
)
const
{
handleSyncWorkflowDraft
}
=
use
Workflow
()
const
{
handleSyncWorkflowDraft
}
=
use
NodesSyncDraft
()
const
handleFeaturesChange
=
useCallback
(()
=>
{
const
handleFeaturesChange
=
useCallback
(()
=>
{
handleSyncWorkflowDraft
()
handleSyncWorkflowDraft
()
...
...
web/app/components/workflow/header/index.tsx
View file @
a55a7603
...
@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next'
...
@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next'
import
{
useStore
}
from
'../store'
import
{
useStore
}
from
'../store'
import
{
import
{
useIsChatMode
,
useIsChatMode
,
useWorkflow
,
useWorkflow
Run
,
}
from
'../hooks'
}
from
'../hooks'
import
RunAndHistory
from
'./run-and-history'
import
RunAndHistory
from
'./run-and-history'
import
EditingTitle
from
'./editing-title'
import
EditingTitle
from
'./editing-title'
...
@@ -24,15 +24,15 @@ const Header: FC = () => {
...
@@ -24,15 +24,15 @@ const Header: FC = () => {
const
appSidebarExpand
=
useAppStore
(
s
=>
s
.
appSidebarExpand
)
const
appSidebarExpand
=
useAppStore
(
s
=>
s
.
appSidebarExpand
)
const
isChatMode
=
useIsChatMode
()
const
isChatMode
=
useIsChatMode
()
const
runningStatus
=
useStore
(
s
=>
s
.
runningStatus
)
const
runningStatus
=
useStore
(
s
=>
s
.
runningStatus
)
const
{
handleRun
Init
}
=
useWorkflow
()
const
{
handleRun
Setting
}
=
useWorkflowRun
()
const
handleShowFeatures
=
useCallback
(()
=>
{
const
handleShowFeatures
=
useCallback
(()
=>
{
useStore
.
setState
({
showFeaturesPanel
:
true
})
useStore
.
setState
({
showFeaturesPanel
:
true
})
},
[])
},
[])
const
handleGoBackToEdit
=
useCallback
(()
=>
{
const
handleGoBackToEdit
=
useCallback
(()
=>
{
handleRun
Init
(
true
)
handleRun
Setting
(
true
)
},
[
handleRun
Init
])
},
[
handleRun
Setting
])
return
(
return
(
<
div
<
div
...
...
web/app/components/workflow/header/run-and-history.tsx
View file @
a55a7603
...
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next'
...
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next'
import
{
useStore
}
from
'../store'
import
{
useStore
}
from
'../store'
import
{
import
{
useIsChatMode
,
useIsChatMode
,
useWorkflow
,
useWorkflow
Run
,
}
from
'../hooks'
}
from
'../hooks'
import
{
WorkflowRunningStatus
}
from
'../types'
import
{
WorkflowRunningStatus
}
from
'../types'
import
{
Play
}
from
'@/app/components/base/icons/src/vender/line/mediaAndDevices'
import
{
Play
}
from
'@/app/components/base/icons/src/vender/line/mediaAndDevices'
...
@@ -54,11 +54,11 @@ RunMode.displayName = 'RunMode'
...
@@ -54,11 +54,11 @@ RunMode.displayName = 'RunMode'
const
PreviewMode
=
memo
(()
=>
{
const
PreviewMode
=
memo
(()
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
{
handleRun
Init
}
=
useWorkflow
()
const
{
handleRun
Setting
}
=
useWorkflowRun
()
const
runningStatus
=
useStore
(
s
=>
s
.
runningStatus
)
const
runningStatus
=
useStore
(
s
=>
s
.
runningStatus
)
const
handleClick
=
()
=>
{
const
handleClick
=
()
=>
{
handleRun
Init
()
handleRun
Setting
()
}
}
return
(
return
(
...
...
web/app/components/workflow/hooks/index.ts
0 → 100644
View file @
a55a7603
export
*
from
'./use-edges-interactions'
export
*
from
'./use-node-data-update'
export
*
from
'./use-nodes-interactions'
export
*
from
'./use-nodes-data'
export
*
from
'./use-nodes-sync-draft'
export
*
from
'./use-workflow'
export
*
from
'./use-workflow-run'
web/app/components/workflow/hooks/use-edges-interactions.ts
0 → 100644
View file @
a55a7603
import
{
useCallback
}
from
'react'
import
produce
from
'immer'
import
type
{
EdgeMouseHandler
,
OnEdgesChange
,
}
from
'reactflow'
import
{
useStoreApi
}
from
'reactflow'
import
{
useStore
}
from
'../store'
import
{
useNodesSyncDraft
}
from
'./use-nodes-sync-draft'
export
const
useEdgesInteractions
=
()
=>
{
const
store
=
useStoreApi
()
const
{
handleSyncWorkflowDraft
}
=
useNodesSyncDraft
()
const
handleEdgeEnter
=
useCallback
<
EdgeMouseHandler
>
((
_
,
edge
)
=>
{
const
{
runningStatus
}
=
useStore
.
getState
()
if
(
runningStatus
)
return
const
{
edges
,
setEdges
,
}
=
store
.
getState
()
const
newEdges
=
produce
(
edges
,
(
draft
)
=>
{
const
currentEdge
=
draft
.
find
(
e
=>
e
.
id
===
edge
.
id
)
!
currentEdge
.
data
=
{
...
currentEdge
.
data
,
_hovering
:
true
}
})
setEdges
(
newEdges
)
},
[
store
])
const
handleEdgeLeave
=
useCallback
<
EdgeMouseHandler
>
((
_
,
edge
)
=>
{
const
{
runningStatus
}
=
useStore
.
getState
()
if
(
runningStatus
)
return
const
{
edges
,
setEdges
,
}
=
store
.
getState
()
const
newEdges
=
produce
(
edges
,
(
draft
)
=>
{
const
currentEdge
=
draft
.
find
(
e
=>
e
.
id
===
edge
.
id
)
!
currentEdge
.
data
=
{
...
currentEdge
.
data
,
_hovering
:
false
}
})
setEdges
(
newEdges
)
},
[
store
])
const
handleEdgeDeleteByDeleteBranch
=
useCallback
((
nodeId
:
string
,
branchId
:
string
)
=>
{
const
{
runningStatus
}
=
useStore
.
getState
()
if
(
runningStatus
)
return
const
{
edges
,
setEdges
,
}
=
store
.
getState
()
const
newEdges
=
produce
(
edges
,
(
draft
)
=>
{
const
index
=
draft
.
findIndex
(
edge
=>
edge
.
source
===
nodeId
&&
edge
.
sourceHandle
===
branchId
)
if
(
index
>
-
1
)
draft
.
splice
(
index
,
1
)
})
setEdges
(
newEdges
)
handleSyncWorkflowDraft
()
},
[
store
,
handleSyncWorkflowDraft
])
const
handleEdgeDelete
=
useCallback
(()
=>
{
const
{
runningStatus
}
=
useStore
.
getState
()
if
(
runningStatus
)
return
const
{
edges
,
setEdges
,
}
=
store
.
getState
()
const
newEdges
=
produce
(
edges
,
(
draft
)
=>
{
const
index
=
draft
.
findIndex
(
edge
=>
edge
.
selected
)
if
(
index
>
-
1
)
draft
.
splice
(
index
,
1
)
})
setEdges
(
newEdges
)
handleSyncWorkflowDraft
()
},
[
store
,
handleSyncWorkflowDraft
])
const
handleEdgesChange
=
useCallback
<
OnEdgesChange
>
((
changes
)
=>
{
const
{
runningStatus
}
=
useStore
.
getState
()
if
(
runningStatus
)
return
const
{
edges
,
setEdges
,
}
=
store
.
getState
()
const
newEdges
=
produce
(
edges
,
(
draft
)
=>
{
changes
.
forEach
((
change
)
=>
{
if
(
change
.
type
===
'select'
)
draft
.
find
(
edge
=>
edge
.
id
===
change
.
id
)
!
.
selected
=
change
.
selected
})
})
setEdges
(
newEdges
)
},
[
store
])
return
{
handleEdgeEnter
,
handleEdgeLeave
,
handleEdgeDeleteByDeleteBranch
,
handleEdgeDelete
,
handleEdgesChange
,
}
}
web/app/components/workflow/hooks/use-node-data-update.ts
0 → 100644
View file @
a55a7603
import
{
useCallback
}
from
'react'
import
produce
from
'immer'
import
{
useStoreApi
}
from
'reactflow'
import
{
useStore
}
from
'../store'
import
{
useNodesSyncDraft
}
from
'./use-nodes-sync-draft'
type
NodeDataUpdatePayload
=
{
id
:
string
data
:
Record
<
string
,
any
>
}
export
const
useNodeDataUpdate
=
()
=>
{
const
store
=
useStoreApi
()
const
{
handleSyncWorkflowDraft
}
=
useNodesSyncDraft
()
const
handleNodeDataUpdate
=
useCallback
(({
id
,
data
}:
NodeDataUpdatePayload
)
=>
{
const
{
getNodes
,
setNodes
,
}
=
store
.
getState
()
const
newNodes
=
produce
(
getNodes
(),
(
draft
)
=>
{
const
currentNode
=
draft
.
find
(
node
=>
node
.
id
===
id
)
!
currentNode
.
data
=
{
...
currentNode
.
data
,
...
data
}
})
setNodes
(
newNodes
)
},
[
store
])
const
handleNodeDataUpdateWithSyncDraft
=
useCallback
((
payload
:
NodeDataUpdatePayload
)
=>
{
const
{
runningStatus
}
=
useStore
.
getState
()
if
(
runningStatus
)
return
handleNodeDataUpdate
(
payload
)
handleSyncWorkflowDraft
(
true
)
},
[
handleSyncWorkflowDraft
,
handleNodeDataUpdate
])
return
{
handleNodeDataUpdate
,
handleNodeDataUpdateWithSyncDraft
,
}
}
web/app/components/workflow/hooks/use-nodes-data.ts
0 → 100644
View file @
a55a7603
import
{
useTranslation
}
from
'react-i18next'
import
produce
from
'immer'
import
type
{
BlockEnum
}
from
'../types'
import
{
NODES_EXTRA_DATA
,
NODES_INITIAL_DATA
,
}
from
'../constants'
export
const
useNodesInitialData
=
()
=>
{
const
{
t
}
=
useTranslation
()
return
produce
(
NODES_INITIAL_DATA
,
(
draft
)
=>
{
Object
.
keys
(
draft
).
forEach
((
key
)
=>
{
draft
[
key
as
BlockEnum
].
title
=
t
(
`workflow.blocks.
${
key
}
`
)
})
})
}
export
const
useNodesExtraData
=
()
=>
{
const
{
t
}
=
useTranslation
()
return
produce
(
NODES_EXTRA_DATA
,
(
draft
)
=>
{
Object
.
keys
(
draft
).
forEach
((
key
)
=>
{
draft
[
key
as
BlockEnum
].
about
=
t
(
`workflow.blocksAbout.
${
key
}
`
)
})
})
}
web/app/components/workflow/hooks.ts
→
web/app/components/workflow/hooks
/use-nodes-interactions
.ts
View file @
a55a7603
import
{
useCallback
}
from
'react'
import
{
useCallback
}
from
'react'
import
{
useTranslation
}
from
'react-i18next'
import
produce
from
'immer'
import
produce
from
'immer'
import
{
useDebounceFn
}
from
'ahooks'
import
type
{
import
type
{
EdgeMouseHandler
,
NodeDragHandler
,
NodeDragHandler
,
NodeMouseHandler
,
NodeMouseHandler
,
OnConnect
,
OnConnect
,
OnEdgesChange
,
Viewport
,
}
from
'reactflow'
}
from
'reactflow'
import
{
import
{
Position
,
Position
,
getConnectedEdges
,
getConnectedEdges
,
getIncomers
,
getIncomers
,
getOutgoers
,
getOutgoers
,
useReactFlow
,
useStoreApi
,
useStoreApi
,
}
from
'reactflow'
}
from
'reactflow'
import
type
{
Node
}
from
'.
/types'
import
type
{
ToolDefaultValue
}
from
'../block-selector
/types'
import
{
import
type
{
BlockEnum
,
Node
,
NodeRunningStatus
,
}
from
'../types'
WorkflowRunningStatus
,
import
{
BlockEnum
}
from
'../types'
}
from
'./types
'
import
{
useStore
}
from
'../store
'
import
{
import
{
NODES_EXTRA_DATA
,
NODES_INITIAL_DATA
,
NODE_WIDTH_X_OFFSET
,
NODE_WIDTH_X_OFFSET
,
Y_OFFSET
,
Y_OFFSET
,
}
from
'./constants'
}
from
'../constants'
import
{
import
{
useNodesInitialData
}
from
'./use-nodes-data'
getLayoutByDagre
,
import
{
useNodesSyncDraft
}
from
'./use-nodes-sync-draft'
}
from
'./utils'
import
{
useStore
}
from
'./store'
import
type
{
ToolDefaultValue
}
from
'./block-selector/types'
import
{
syncWorkflowDraft
}
from
'@/service/workflow'
import
{
useFeaturesStore
}
from
'@/app/components/base/features/hooks'
import
{
useStore
as
useAppStore
}
from
'@/app/components/app/store'
import
{
ssePost
}
from
'@/service/base'
import
type
{
IOtherOptions
}
from
'@/service/base'
export
const
useIsChatMode
=
()
=>
{
const
appDetail
=
useAppStore
(
s
=>
s
.
appDetail
)
return
appDetail
?.
mode
===
'advanced-chat'
}
export
const
useNodesInitialData
=
()
=>
{
export
const
useNodesInteractions
=
()
=>
{
const
{
t
}
=
useTranslation
()
return
produce
(
NODES_INITIAL_DATA
,
(
draft
)
=>
{
Object
.
keys
(
draft
).
forEach
((
key
)
=>
{
draft
[
key
as
BlockEnum
].
title
=
t
(
`workflow.blocks.
${
key
}
`
)
})
})
}
export
const
useNodesExtraData
=
()
=>
{
const
{
t
}
=
useTranslation
()
return
produce
(
NODES_EXTRA_DATA
,
(
draft
)
=>
{
Object
.
keys
(
draft
).
forEach
((
key
)
=>
{
draft
[
key
as
BlockEnum
].
about
=
t
(
`workflow.blocksAbout.
${
key
}
`
)
})
})
}
export
const
useWorkflow
=
()
=>
{
const
store
=
useStoreApi
()
const
store
=
useStoreApi
()
const
reactFlow
=
useReactFlow
()
const
nodesInitialData
=
useNodesInitialData
()
const
nodesInitialData
=
useNodesInitialData
()
const
featuresStore
=
useFeaturesStore
()
const
{
handleSyncWorkflowDraft
}
=
useNodesSyncDraft
()
const
shouldDebouncedSyncWorkflowDraft
=
useCallback
(()
=>
{
const
{
getNodes
,
edges
,
}
=
store
.
getState
()
const
{
getViewport
}
=
reactFlow
const
appId
=
useAppStore
.
getState
().
appDetail
?.
id
if
(
appId
)
{
const
features
=
featuresStore
!
.
getState
().
features
const
producedNodes
=
produce
(
getNodes
(),
(
draft
)
=>
{
draft
.
forEach
((
node
)
=>
{
Object
.
keys
(
node
.
data
).
forEach
((
key
)
=>
{
if
(
key
.
startsWith
(
'_'
))
delete
node
.
data
[
key
]
})
})
})
const
producedEdges
=
produce
(
edges
,
(
draft
)
=>
{
draft
.
forEach
((
edge
)
=>
{
delete
edge
.
data
})
})
syncWorkflowDraft
({
url
:
`/apps/
${
appId
}
/workflows/draft`
,
params
:
{
graph
:
{
nodes
:
producedNodes
,
edges
:
producedEdges
,
viewport
:
getViewport
(),
},
features
:
{
opening_statement
:
features
.
opening
.
opening_statement
,
suggested_questions
:
features
.
opening
.
suggested_questions
,
suggested_questions_after_answer
:
features
.
suggested
,
text_to_speech
:
features
.
text2speech
,
speech_to_text
:
features
.
speech2text
,
retriever_resource
:
features
.
citation
,
sensitive_word_avoidance
:
features
.
moderation
,
},
},
}).
then
((
res
)
=>
{
useStore
.
setState
({
draftUpdatedAt
:
res
.
updated_at
})
})
}
},
[
store
,
reactFlow
,
featuresStore
])
const
{
run
:
debouncedSyncWorkflowDraft
}
=
useDebounceFn
(
shouldDebouncedSyncWorkflowDraft
,
{
wait
:
2000
,
trailing
:
true
,
})
const
handleSyncWorkflowDraft
=
useCallback
((
shouldDelay
?:
boolean
)
=>
{
if
(
shouldDelay
)
debouncedSyncWorkflowDraft
()
else
shouldDebouncedSyncWorkflowDraft
()
},
[
debouncedSyncWorkflowDraft
,
shouldDebouncedSyncWorkflowDraft
])
const
handleLayout
=
useCallback
(
async
()
=>
{
const
{
getNodes
,
edges
,
setNodes
,
}
=
store
.
getState
()
const
layout
=
getLayoutByDagre
(
getNodes
(),
edges
)
const
newNodes
=
produce
(
getNodes
(),
(
draft
)
=>
{
draft
.
forEach
((
node
)
=>
{
const
nodeWithPosition
=
layout
.
node
(
node
.
id
)
node
.
position
=
{
x
:
nodeWithPosition
.
x
,
y
:
nodeWithPosition
.
y
,
}
})
})
setNodes
(
newNodes
)
},
[
store
])
const
handleSetViewport
=
useCallback
((
viewPort
:
Viewport
)
=>
{
reactFlow
.
setViewport
(
viewPort
)
handleSyncWorkflowDraft
()
},
[
reactFlow
,
handleSyncWorkflowDraft
])
const
handleNodeDragStart
=
useCallback
<
NodeDragHandler
>
(()
=>
{
const
handleNodeDragStart
=
useCallback
<
NodeDragHandler
>
(()
=>
{
const
{
const
{
...
@@ -164,8 +36,10 @@ export const useWorkflow = () => {
...
@@ -164,8 +36,10 @@ export const useWorkflow = () => {
setIsDragging
,
setIsDragging
,
}
=
useStore
.
getState
()
}
=
useStore
.
getState
()
if
(
!
runningStatus
)
if
(
runningStatus
)
setIsDragging
(
true
)
return
setIsDragging
(
true
)
},
[])
},
[])
const
handleNodeDrag
=
useCallback
<
NodeDragHandler
>
((
e
,
node
:
Node
)
=>
{
const
handleNodeDrag
=
useCallback
<
NodeDragHandler
>
((
e
,
node
:
Node
)
=>
{
...
@@ -433,25 +307,6 @@ export const useWorkflow = () => {
...
@@ -433,25 +307,6 @@ export const useWorkflow = () => {
handleSyncWorkflowDraft
()
handleSyncWorkflowDraft
()
},
[
store
,
handleSyncWorkflowDraft
])
},
[
store
,
handleSyncWorkflowDraft
])
const
handleNodeDataUpdate
=
useCallback
(({
id
,
data
}:
{
id
:
string
;
data
:
Record
<
string
,
any
>
})
=>
{
const
{
runningStatus
}
=
useStore
.
getState
()
if
(
runningStatus
)
return
const
{
getNodes
,
setNodes
,
}
=
store
.
getState
()
const
newNodes
=
produce
(
getNodes
(),
(
draft
)
=>
{
const
currentNode
=
draft
.
find
(
node
=>
node
.
id
===
id
)
!
currentNode
.
data
=
{
...
currentNode
.
data
,
...
data
}
})
setNodes
(
newNodes
)
handleSyncWorkflowDraft
(
true
)
},
[
store
,
handleSyncWorkflowDraft
])
const
handleNodeAddNext
=
useCallback
((
const
handleNodeAddNext
=
useCallback
((
currentNodeId
:
string
,
currentNodeId
:
string
,
nodeType
:
BlockEnum
,
nodeType
:
BlockEnum
,
...
@@ -636,196 +491,7 @@ export const useWorkflow = () => {
...
@@ -636,196 +491,7 @@ export const useWorkflow = () => {
}
}
},
[
store
,
nodesInitialData
,
handleSyncWorkflowDraft
])
},
[
store
,
nodesInitialData
,
handleSyncWorkflowDraft
])
const
handleEdgeEnter
=
useCallback
<
EdgeMouseHandler
>
((
_
,
edge
)
=>
{
const
{
runningStatus
}
=
useStore
.
getState
()
if
(
runningStatus
)
return
const
{
edges
,
setEdges
,
}
=
store
.
getState
()
const
newEdges
=
produce
(
edges
,
(
draft
)
=>
{
const
currentEdge
=
draft
.
find
(
e
=>
e
.
id
===
edge
.
id
)
!
currentEdge
.
data
=
{
...
currentEdge
.
data
,
_hovering
:
true
}
})
setEdges
(
newEdges
)
},
[
store
])
const
handleEdgeLeave
=
useCallback
<
EdgeMouseHandler
>
((
_
,
edge
)
=>
{
const
{
runningStatus
}
=
useStore
.
getState
()
if
(
runningStatus
)
return
const
{
edges
,
setEdges
,
}
=
store
.
getState
()
const
newEdges
=
produce
(
edges
,
(
draft
)
=>
{
const
currentEdge
=
draft
.
find
(
e
=>
e
.
id
===
edge
.
id
)
!
currentEdge
.
data
=
{
...
currentEdge
.
data
,
_hovering
:
false
}
})
setEdges
(
newEdges
)
},
[
store
])
const
handleEdgeDeleteByDeleteBranch
=
useCallback
((
nodeId
:
string
,
branchId
:
string
)
=>
{
const
{
runningStatus
}
=
useStore
.
getState
()
if
(
runningStatus
)
return
const
{
edges
,
setEdges
,
}
=
store
.
getState
()
const
newEdges
=
produce
(
edges
,
(
draft
)
=>
{
const
index
=
draft
.
findIndex
(
edge
=>
edge
.
source
===
nodeId
&&
edge
.
sourceHandle
===
branchId
)
if
(
index
>
-
1
)
draft
.
splice
(
index
,
1
)
})
setEdges
(
newEdges
)
handleSyncWorkflowDraft
()
},
[
store
,
handleSyncWorkflowDraft
])
const
handleEdgeDelete
=
useCallback
(()
=>
{
const
{
runningStatus
}
=
useStore
.
getState
()
if
(
runningStatus
)
return
const
{
edges
,
setEdges
,
}
=
store
.
getState
()
const
newEdges
=
produce
(
edges
,
(
draft
)
=>
{
const
index
=
draft
.
findIndex
(
edge
=>
edge
.
selected
)
if
(
index
>
-
1
)
draft
.
splice
(
index
,
1
)
})
setEdges
(
newEdges
)
handleSyncWorkflowDraft
()
},
[
store
,
handleSyncWorkflowDraft
])
const
handleEdgesChange
=
useCallback
<
OnEdgesChange
>
((
changes
)
=>
{
const
{
runningStatus
}
=
useStore
.
getState
()
if
(
runningStatus
)
return
const
{
edges
,
setEdges
,
}
=
store
.
getState
()
const
newEdges
=
produce
(
edges
,
(
draft
)
=>
{
changes
.
forEach
((
change
)
=>
{
if
(
change
.
type
===
'select'
)
draft
.
find
(
edge
=>
edge
.
id
===
change
.
id
)
!
.
selected
=
change
.
selected
})
})
setEdges
(
newEdges
)
},
[
store
])
const
handleRunInit
=
useCallback
((
shouldClear
?:
boolean
)
=>
{
useStore
.
setState
({
runningStatus
:
shouldClear
?
undefined
:
WorkflowRunningStatus
.
Waiting
})
const
{
setNodes
,
getNodes
}
=
store
.
getState
()
const
newNodes
=
produce
(
getNodes
(),
(
draft
)
=>
{
draft
.
forEach
((
node
)
=>
{
node
.
data
.
_runningStatus
=
shouldClear
?
undefined
:
NodeRunningStatus
.
Waiting
})
})
setNodes
(
newNodes
)
},
[
store
])
const
getTreeLeafNodes
=
useCallback
(()
=>
{
const
{
getNodes
,
edges
,
}
=
store
.
getState
()
const
nodes
=
getNodes
()
const
startNode
=
nodes
.
find
(
node
=>
node
.
data
.
type
===
BlockEnum
.
Start
)
if
(
!
startNode
)
return
[]
const
list
:
Node
[]
=
[]
const
preOrder
=
(
root
:
Node
,
callback
:
(
node
:
Node
)
=>
void
)
=>
{
const
outgoers
=
getOutgoers
(
root
,
nodes
,
edges
)
if
(
outgoers
.
length
)
{
outgoers
.
forEach
((
outgoer
)
=>
{
preOrder
(
outgoer
,
callback
)
})
}
else
{
callback
(
root
)
}
}
preOrder
(
startNode
,
(
node
)
=>
{
list
.
push
(
node
)
})
return
list
.
filter
((
item
)
=>
{
if
(
item
.
data
.
type
===
BlockEnum
.
IfElse
)
return
false
if
(
item
.
data
.
type
===
BlockEnum
.
QuestionClassifier
)
return
false
return
true
})
},
[
store
])
const
getBeforeNodesInSameBranch
=
useCallback
((
nodeId
:
string
)
=>
{
const
{
getNodes
,
edges
,
}
=
store
.
getState
()
const
nodes
=
getNodes
()
const
currentNode
=
nodes
.
find
(
node
=>
node
.
id
===
nodeId
)
!
const
list
:
Node
[]
=
[]
const
traverse
=
(
root
:
Node
,
callback
:
(
node
:
Node
)
=>
void
)
=>
{
const
incomers
=
getIncomers
(
root
,
nodes
,
edges
)
if
(
incomers
.
length
)
{
incomers
.
forEach
((
node
)
=>
{
callback
(
node
)
traverse
(
node
,
callback
)
})
}
}
traverse
(
currentNode
,
(
node
)
=>
{
list
.
push
(
node
)
})
const
length
=
list
.
length
if
(
length
&&
list
.
some
(
item
=>
item
.
data
.
type
===
BlockEnum
.
Start
))
{
return
list
.
reverse
().
filter
((
item
)
=>
{
if
(
item
.
data
.
type
===
BlockEnum
.
IfElse
)
return
false
if
(
item
.
data
.
type
===
BlockEnum
.
QuestionClassifier
)
return
false
return
true
})
}
return
[]
},
[
store
])
return
{
return
{
handleSyncWorkflowDraft
,
handleLayout
,
handleSetViewport
,
handleNodeDragStart
,
handleNodeDragStart
,
handleNodeDrag
,
handleNodeDrag
,
handleNodeDragStop
,
handleNodeDragStop
,
...
@@ -835,94 +501,8 @@ export const useWorkflow = () => {
...
@@ -835,94 +501,8 @@ export const useWorkflow = () => {
handleNodeClick
,
handleNodeClick
,
handleNodeConnect
,
handleNodeConnect
,
handleNodeDelete
,
handleNodeDelete
,
handleNodeDataUpdate
,
handleNodeAddNext
,
handleNodeAddNext
,
handleNodeAddPrev
,
handleNodeAddPrev
,
handleNodeChange
,
handleNodeChange
,
handleEdgeEnter
,
handleEdgeLeave
,
handleEdgeDeleteByDeleteBranch
,
handleEdgeDelete
,
handleEdgesChange
,
handleRunInit
,
getTreeLeafNodes
,
getBeforeNodesInSameBranch
,
}
}
}
}
export
const
useWorkflowRun
=
()
=>
{
const
store
=
useStoreApi
()
const
reactflow
=
useReactFlow
()
const
run
=
useCallback
((
params
:
any
,
callback
?:
IOtherOptions
)
=>
{
const
{
getNodes
,
setNodes
,
}
=
store
.
getState
()
const
appDetail
=
useAppStore
.
getState
().
appDetail
let
url
=
''
if
(
appDetail
?.
mode
===
'advanced-chat'
)
url
=
`/apps/
${
appDetail
.
id
}
/advanced-chat/workflows/draft/run`
if
(
appDetail
?.
mode
===
'workflow'
)
url
=
`/apps/
${
appDetail
.
id
}
/workflows/draft/run`
ssePost
(
url
,
{
body
:
params
,
},
{
onWorkflowStarted
:
({
task_id
,
workflow_run_id
,
sequence_number
})
=>
{
useStore
.
setState
({
runningStatus
:
WorkflowRunningStatus
.
Running
})
useStore
.
setState
({
taskId
:
task_id
})
useStore
.
setState
({
currentSequenceNumber
:
sequence_number
})
useStore
.
setState
({
workflowRunId
:
workflow_run_id
})
const
newNodes
=
produce
(
getNodes
(),
(
draft
)
=>
{
draft
.
forEach
((
node
)
=>
{
node
.
data
.
_runningStatus
=
NodeRunningStatus
.
Waiting
})
})
setNodes
(
newNodes
)
},
onWorkflowFinished
:
({
data
})
=>
{
useStore
.
setState
({
runningStatus
:
data
.
status
as
WorkflowRunningStatus
})
},
onNodeStarted
:
({
data
})
=>
{
const
nodes
=
getNodes
()
const
{
getViewport
,
setViewport
,
}
=
reactflow
const
viewport
=
getViewport
()
const
currentNodeIndex
=
nodes
.
findIndex
(
node
=>
node
.
id
===
data
.
node_id
)
const
position
=
nodes
[
currentNodeIndex
].
position
const
zoom
=
1
setViewport
({
zoom
,
x
:
200
/
viewport
.
zoom
-
position
.
x
,
y
:
200
/
viewport
.
zoom
-
position
.
y
,
})
const
newNodes
=
produce
(
nodes
,
(
draft
)
=>
{
draft
[
currentNodeIndex
].
data
.
_runningStatus
=
NodeRunningStatus
.
Running
})
setNodes
(
newNodes
)
},
onNodeFinished
:
({
data
})
=>
{
const
newNodes
=
produce
(
getNodes
(),
(
draft
)
=>
{
const
currentNode
=
draft
.
find
(
node
=>
node
.
id
===
data
.
node_id
)
!
currentNode
.
data
.
_runningStatus
=
data
.
status
})
setNodes
(
newNodes
)
},
...
callback
,
},
)
},
[
store
,
reactflow
])
return
run
}
web/app/components/workflow/hooks/use-nodes-sync-draft.ts
0 → 100644
View file @
a55a7603
import
{
useCallback
}
from
'react'
import
produce
from
'immer'
import
{
useDebounceFn
}
from
'ahooks'
import
{
useReactFlow
,
useStoreApi
,
}
from
'reactflow'
import
{
useStore
}
from
'../store'
import
{
syncWorkflowDraft
}
from
'@/service/workflow'
import
{
useFeaturesStore
}
from
'@/app/components/base/features/hooks'
import
{
useStore
as
useAppStore
}
from
'@/app/components/app/store'
export
const
useNodesSyncDraft
=
()
=>
{
const
store
=
useStoreApi
()
const
reactFlow
=
useReactFlow
()
const
featuresStore
=
useFeaturesStore
()
const
shouldDebouncedSyncWorkflowDraft
=
useCallback
(()
=>
{
const
{
getNodes
,
edges
,
}
=
store
.
getState
()
const
{
getViewport
}
=
reactFlow
const
appId
=
useAppStore
.
getState
().
appDetail
?.
id
if
(
appId
)
{
const
features
=
featuresStore
!
.
getState
().
features
const
producedNodes
=
produce
(
getNodes
(),
(
draft
)
=>
{
draft
.
forEach
((
node
)
=>
{
Object
.
keys
(
node
.
data
).
forEach
((
key
)
=>
{
if
(
key
.
startsWith
(
'_'
))
delete
node
.
data
[
key
]
})
})
})
const
producedEdges
=
produce
(
edges
,
(
draft
)
=>
{
draft
.
forEach
((
edge
)
=>
{
delete
edge
.
data
})
})
syncWorkflowDraft
({
url
:
`/apps/
${
appId
}
/workflows/draft`
,
params
:
{
graph
:
{
nodes
:
producedNodes
,
edges
:
producedEdges
,
viewport
:
getViewport
(),
},
features
:
{
opening_statement
:
features
.
opening
.
opening_statement
,
suggested_questions
:
features
.
opening
.
suggested_questions
,
suggested_questions_after_answer
:
features
.
suggested
,
text_to_speech
:
features
.
text2speech
,
speech_to_text
:
features
.
speech2text
,
retriever_resource
:
features
.
citation
,
sensitive_word_avoidance
:
features
.
moderation
,
},
},
}).
then
((
res
)
=>
{
useStore
.
setState
({
draftUpdatedAt
:
res
.
updated_at
})
})
}
},
[
store
,
reactFlow
,
featuresStore
])
const
{
run
:
debouncedSyncWorkflowDraft
}
=
useDebounceFn
(
shouldDebouncedSyncWorkflowDraft
,
{
wait
:
2000
,
trailing
:
true
,
})
const
handleSyncWorkflowDraft
=
useCallback
((
shouldDelay
?:
boolean
)
=>
{
const
{
runningStatus
}
=
useStore
.
getState
()
if
(
runningStatus
)
return
if
(
shouldDelay
)
debouncedSyncWorkflowDraft
()
else
shouldDebouncedSyncWorkflowDraft
()
},
[
debouncedSyncWorkflowDraft
,
shouldDebouncedSyncWorkflowDraft
])
return
{
handleSyncWorkflowDraft
,
}
}
web/app/components/workflow/hooks/use-workflow-run.ts
0 → 100644
View file @
a55a7603
import
{
useCallback
}
from
'react'
import
{
useReactFlow
,
useStoreApi
,
}
from
'reactflow'
import
produce
from
'immer'
import
{
useStore
}
from
'../store'
import
{
NodeRunningStatus
,
WorkflowRunningStatus
,
}
from
'../types'
import
{
useStore
as
useAppStore
}
from
'@/app/components/app/store'
import
type
{
IOtherOptions
}
from
'@/service/base'
import
{
ssePost
}
from
'@/service/base'
export
const
useWorkflowRun
=
()
=>
{
const
store
=
useStoreApi
()
const
reactflow
=
useReactFlow
()
const
handleRunSetting
=
useCallback
((
shouldClear
?:
boolean
)
=>
{
useStore
.
setState
({
runningStatus
:
shouldClear
?
undefined
:
WorkflowRunningStatus
.
Waiting
})
const
{
setNodes
,
getNodes
}
=
store
.
getState
()
const
newNodes
=
produce
(
getNodes
(),
(
draft
)
=>
{
draft
.
forEach
((
node
)
=>
{
node
.
data
.
_runningStatus
=
shouldClear
?
undefined
:
NodeRunningStatus
.
Waiting
})
})
setNodes
(
newNodes
)
},
[
store
])
const
handleRun
=
useCallback
((
params
:
any
,
callback
?:
IOtherOptions
)
=>
{
const
{
getNodes
,
setNodes
,
}
=
store
.
getState
()
const
appDetail
=
useAppStore
.
getState
().
appDetail
let
url
=
''
if
(
appDetail
?.
mode
===
'advanced-chat'
)
url
=
`/apps/
${
appDetail
.
id
}
/advanced-chat/workflows/draft/run`
if
(
appDetail
?.
mode
===
'workflow'
)
url
=
`/apps/
${
appDetail
.
id
}
/workflows/draft/run`
ssePost
(
url
,
{
body
:
params
,
},
{
onWorkflowStarted
:
({
task_id
,
workflow_run_id
,
sequence_number
})
=>
{
useStore
.
setState
({
runningStatus
:
WorkflowRunningStatus
.
Running
})
useStore
.
setState
({
taskId
:
task_id
})
useStore
.
setState
({
currentSequenceNumber
:
sequence_number
})
useStore
.
setState
({
workflowRunId
:
workflow_run_id
})
const
newNodes
=
produce
(
getNodes
(),
(
draft
)
=>
{
draft
.
forEach
((
node
)
=>
{
node
.
data
.
_runningStatus
=
NodeRunningStatus
.
Waiting
})
})
setNodes
(
newNodes
)
},
onWorkflowFinished
:
({
data
})
=>
{
useStore
.
setState
({
runningStatus
:
data
.
status
as
WorkflowRunningStatus
})
},
onNodeStarted
:
({
data
})
=>
{
const
nodes
=
getNodes
()
const
{
getViewport
,
setViewport
,
}
=
reactflow
const
viewport
=
getViewport
()
const
currentNodeIndex
=
nodes
.
findIndex
(
node
=>
node
.
id
===
data
.
node_id
)
const
position
=
nodes
[
currentNodeIndex
].
position
const
zoom
=
1
setViewport
({
zoom
,
x
:
200
/
viewport
.
zoom
-
position
.
x
,
y
:
200
/
viewport
.
zoom
-
position
.
y
,
})
const
newNodes
=
produce
(
nodes
,
(
draft
)
=>
{
draft
[
currentNodeIndex
].
data
.
_runningStatus
=
NodeRunningStatus
.
Running
})
setNodes
(
newNodes
)
},
onNodeFinished
:
({
data
})
=>
{
const
newNodes
=
produce
(
getNodes
(),
(
draft
)
=>
{
const
currentNode
=
draft
.
find
(
node
=>
node
.
id
===
data
.
node_id
)
!
currentNode
.
data
.
_runningStatus
=
data
.
status
})
setNodes
(
newNodes
)
},
...
callback
,
},
)
},
[
store
,
reactflow
])
return
{
handleRunSetting
,
handleRun
,
}
}
web/app/components/workflow/hooks/use-workflow.ts
0 → 100644
View file @
a55a7603
import
{
useCallback
}
from
'react'
import
produce
from
'immer'
import
{
getIncomers
,
getOutgoers
,
useStoreApi
,
}
from
'reactflow'
import
{
getLayoutByDagre
}
from
'../utils'
import
type
{
Node
}
from
'../types'
import
{
BlockEnum
}
from
'../types'
import
{
useStore
as
useAppStore
}
from
'@/app/components/app/store'
export
const
useIsChatMode
=
()
=>
{
const
appDetail
=
useAppStore
(
s
=>
s
.
appDetail
)
return
appDetail
?.
mode
===
'advanced-chat'
}
export
const
useWorkflow
=
()
=>
{
const
store
=
useStoreApi
()
const
handleLayout
=
useCallback
(
async
()
=>
{
const
{
getNodes
,
edges
,
setNodes
,
}
=
store
.
getState
()
const
layout
=
getLayoutByDagre
(
getNodes
(),
edges
)
const
newNodes
=
produce
(
getNodes
(),
(
draft
)
=>
{
draft
.
forEach
((
node
)
=>
{
const
nodeWithPosition
=
layout
.
node
(
node
.
id
)
node
.
position
=
{
x
:
nodeWithPosition
.
x
,
y
:
nodeWithPosition
.
y
,
}
})
})
setNodes
(
newNodes
)
},
[
store
])
const
getTreeLeafNodes
=
useCallback
(()
=>
{
const
{
getNodes
,
edges
,
}
=
store
.
getState
()
const
nodes
=
getNodes
()
const
startNode
=
nodes
.
find
(
node
=>
node
.
data
.
type
===
BlockEnum
.
Start
)
if
(
!
startNode
)
return
[]
const
list
:
Node
[]
=
[]
const
preOrder
=
(
root
:
Node
,
callback
:
(
node
:
Node
)
=>
void
)
=>
{
const
outgoers
=
getOutgoers
(
root
,
nodes
,
edges
)
if
(
outgoers
.
length
)
{
outgoers
.
forEach
((
outgoer
)
=>
{
preOrder
(
outgoer
,
callback
)
})
}
else
{
callback
(
root
)
}
}
preOrder
(
startNode
,
(
node
)
=>
{
list
.
push
(
node
)
})
return
list
.
filter
((
item
)
=>
{
if
(
item
.
data
.
type
===
BlockEnum
.
IfElse
)
return
false
if
(
item
.
data
.
type
===
BlockEnum
.
QuestionClassifier
)
return
false
return
true
})
},
[
store
])
const
getBeforeNodesInSameBranch
=
useCallback
((
nodeId
:
string
)
=>
{
const
{
getNodes
,
edges
,
}
=
store
.
getState
()
const
nodes
=
getNodes
()
const
currentNode
=
nodes
.
find
(
node
=>
node
.
id
===
nodeId
)
!
const
list
:
Node
[]
=
[]
const
traverse
=
(
root
:
Node
,
callback
:
(
node
:
Node
)
=>
void
)
=>
{
const
incomers
=
getIncomers
(
root
,
nodes
,
edges
)
if
(
incomers
.
length
)
{
incomers
.
forEach
((
node
)
=>
{
callback
(
node
)
traverse
(
node
,
callback
)
})
}
}
traverse
(
currentNode
,
(
node
)
=>
{
list
.
push
(
node
)
})
const
length
=
list
.
length
if
(
length
&&
list
.
some
(
item
=>
item
.
data
.
type
===
BlockEnum
.
Start
))
{
return
list
.
reverse
().
filter
((
item
)
=>
{
if
(
item
.
data
.
type
===
BlockEnum
.
IfElse
)
return
false
if
(
item
.
data
.
type
===
BlockEnum
.
QuestionClassifier
)
return
false
return
true
})
}
return
[]
},
[
store
])
return
{
handleLayout
,
getTreeLeafNodes
,
getBeforeNodesInSameBranch
,
}
}
web/app/components/workflow/index.tsx
View file @
a55a7603
...
@@ -20,8 +20,10 @@ import type {
...
@@ -20,8 +20,10 @@ import type {
Node
,
Node
,
}
from
'./types'
}
from
'./types'
import
{
import
{
useEdgesInteractions
,
useNodesInitialData
,
useNodesInitialData
,
useWorkflow
,
useNodesInteractions
,
useNodesSyncDraft
,
}
from
'./hooks'
}
from
'./hooks'
import
Header
from
'./header'
import
Header
from
'./header'
import
CustomNode
from
'./nodes'
import
CustomNode
from
'./nodes'
...
@@ -65,6 +67,7 @@ const Workflow: FC<WorkflowProps> = memo(({
...
@@ -65,6 +67,7 @@ const Workflow: FC<WorkflowProps> = memo(({
})
=>
{
})
=>
{
const
showFeaturesPanel
=
useStore
(
state
=>
state
.
showFeaturesPanel
)
const
showFeaturesPanel
=
useStore
(
state
=>
state
.
showFeaturesPanel
)
const
runningStatus
=
useStore
(
s
=>
s
.
runningStatus
)
const
runningStatus
=
useStore
(
s
=>
s
.
runningStatus
)
const
{
handleSyncWorkflowDraft
}
=
useNodesSyncDraft
()
useEffect
(()
=>
{
useEffect
(()
=>
{
setAutoFreeze
(
false
)
setAutoFreeze
(
false
)
...
@@ -75,8 +78,6 @@ const Workflow: FC<WorkflowProps> = memo(({
...
@@ -75,8 +78,6 @@ const Workflow: FC<WorkflowProps> = memo(({
},
[])
},
[])
const
{
const
{
handleSyncWorkflowDraft
,
handleNodeDragStart
,
handleNodeDragStart
,
handleNodeDrag
,
handleNodeDrag
,
handleNodeDragStop
,
handleNodeDragStop
,
...
@@ -84,12 +85,13 @@ const Workflow: FC<WorkflowProps> = memo(({
...
@@ -84,12 +85,13 @@ const Workflow: FC<WorkflowProps> = memo(({
handleNodeLeave
,
handleNodeLeave
,
handleNodeClick
,
handleNodeClick
,
handleNodeConnect
,
handleNodeConnect
,
}
=
useNodesInteractions
()
const
{
handleEdgeEnter
,
handleEdgeEnter
,
handleEdgeLeave
,
handleEdgeLeave
,
handleEdgeDelete
,
handleEdgeDelete
,
handleEdgesChange
,
handleEdgesChange
,
}
=
use
Workflow
()
}
=
use
EdgesInteractions
()
useOnViewportChange
({
useOnViewportChange
({
onEnd
:
()
=>
handleSyncWorkflowDraft
(),
onEnd
:
()
=>
handleSyncWorkflowDraft
(),
...
...
web/app/components/workflow/nodes/_base/components/next-step/add.tsx
View file @
a55a7603
...
@@ -3,7 +3,7 @@ import {
...
@@ -3,7 +3,7 @@ import {
useCallback
,
useCallback
,
}
from
'react'
}
from
'react'
import
{
useTranslation
}
from
'react-i18next'
import
{
useTranslation
}
from
'react-i18next'
import
{
use
Workflow
}
from
'@/app/components/workflow/hooks'
import
{
use
NodesInteractions
}
from
'@/app/components/workflow/hooks'
import
BlockSelector
from
'@/app/components/workflow/block-selector'
import
BlockSelector
from
'@/app/components/workflow/block-selector'
import
{
Plus
}
from
'@/app/components/base/icons/src/vender/line/general'
import
{
Plus
}
from
'@/app/components/base/icons/src/vender/line/general'
import
type
{
OnSelectBlock
}
from
'@/app/components/workflow/types'
import
type
{
OnSelectBlock
}
from
'@/app/components/workflow/types'
...
@@ -19,7 +19,7 @@ const Add = ({
...
@@ -19,7 +19,7 @@ const Add = ({
branchName
,
branchName
,
}:
AddProps
)
=>
{
}:
AddProps
)
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
{
handleNodeAddNext
}
=
use
Workflow
()
const
{
handleNodeAddNext
}
=
use
NodesInteractions
()
const
handleSelect
=
useCallback
<
OnSelectBlock
>
((
type
,
toolDefaultValue
)
=>
{
const
handleSelect
=
useCallback
<
OnSelectBlock
>
((
type
,
toolDefaultValue
)
=>
{
handleNodeAddNext
(
nodeId
,
type
,
sourceHandle
,
toolDefaultValue
)
handleNodeAddNext
(
nodeId
,
type
,
sourceHandle
,
toolDefaultValue
)
...
...
web/app/components/workflow/nodes/_base/components/next-step/item.tsx
View file @
a55a7603
...
@@ -9,7 +9,7 @@ import type {
...
@@ -9,7 +9,7 @@ import type {
}
from
'@/app/components/workflow/types'
}
from
'@/app/components/workflow/types'
import
BlockIcon
from
'@/app/components/workflow/block-icon'
import
BlockIcon
from
'@/app/components/workflow/block-icon'
import
BlockSelector
from
'@/app/components/workflow/block-selector'
import
BlockSelector
from
'@/app/components/workflow/block-selector'
import
{
use
Workflow
}
from
'@/app/components/workflow/hooks'
import
{
use
NodesInteractions
}
from
'@/app/components/workflow/hooks'
import
Button
from
'@/app/components/base/button'
import
Button
from
'@/app/components/base/button'
type
ItemProps
=
{
type
ItemProps
=
{
...
@@ -25,7 +25,7 @@ const Item = ({
...
@@ -25,7 +25,7 @@ const Item = ({
data
,
data
,
}:
ItemProps
)
=>
{
}:
ItemProps
)
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
{
handleNodeChange
}
=
use
Workflow
()
const
{
handleNodeChange
}
=
use
NodesInteractions
()
const
handleSelect
=
useCallback
<
OnSelectBlock
>
((
type
,
toolDefaultValue
)
=>
{
const
handleSelect
=
useCallback
<
OnSelectBlock
>
((
type
,
toolDefaultValue
)
=>
{
handleNodeChange
(
nodeId
,
type
,
sourceHandle
,
toolDefaultValue
)
handleNodeChange
(
nodeId
,
type
,
sourceHandle
,
toolDefaultValue
)
},
[
nodeId
,
sourceHandle
,
handleNodeChange
])
},
[
nodeId
,
sourceHandle
,
handleNodeChange
])
...
...
web/app/components/workflow/nodes/_base/components/node-control.tsx
View file @
a55a7603
...
@@ -5,7 +5,7 @@ import {
...
@@ -5,7 +5,7 @@ import {
useState
,
useState
,
}
from
'react'
}
from
'react'
import
{
useTranslation
}
from
'react-i18next'
import
{
useTranslation
}
from
'react-i18next'
import
{
use
Workflow
}
from
'../../../hooks'
import
{
use
NodeDataUpdate
}
from
'../../../hooks'
import
type
{
Node
}
from
'../../../types'
import
type
{
Node
}
from
'../../../types'
import
{
canRunBySingle
}
from
'../../../utils'
import
{
canRunBySingle
}
from
'../../../utils'
import
PanelOperator
from
'./panel-operator'
import
PanelOperator
from
'./panel-operator'
...
@@ -22,7 +22,7 @@ const NodeControl: FC<NodeControlProps> = ({
...
@@ -22,7 +22,7 @@ const NodeControl: FC<NodeControlProps> = ({
})
=>
{
})
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
[
open
,
setOpen
]
=
useState
(
false
)
const
[
open
,
setOpen
]
=
useState
(
false
)
const
{
handleNodeDataUpdate
}
=
use
Workflow
()
const
{
handleNodeDataUpdate
}
=
use
NodeDataUpdate
()
const
handleOpenChange
=
useCallback
((
newOpen
:
boolean
)
=>
{
const
handleOpenChange
=
useCallback
((
newOpen
:
boolean
)
=>
{
setOpen
(
newOpen
)
setOpen
(
newOpen
)
...
...
web/app/components/workflow/nodes/_base/components/node-handle.tsx
View file @
a55a7603
...
@@ -14,7 +14,7 @@ import { BlockEnum } from '../../../types'
...
@@ -14,7 +14,7 @@ import { BlockEnum } from '../../../types'
import
type
{
Node
}
from
'../../../types'
import
type
{
Node
}
from
'../../../types'
import
BlockSelector
from
'../../../block-selector'
import
BlockSelector
from
'../../../block-selector'
import
type
{
ToolDefaultValue
}
from
'../../../block-selector/types'
import
type
{
ToolDefaultValue
}
from
'../../../block-selector/types'
import
{
use
Workflow
}
from
'../../../hooks'
import
{
use
NodesInteractions
}
from
'../../../hooks'
type
NodeHandleProps
=
{
type
NodeHandleProps
=
{
handleId
:
string
handleId
:
string
...
@@ -30,7 +30,7 @@ export const NodeTargetHandle = ({
...
@@ -30,7 +30,7 @@ export const NodeTargetHandle = ({
nodeSelectorClassName
,
nodeSelectorClassName
,
}:
NodeHandleProps
)
=>
{
}:
NodeHandleProps
)
=>
{
const
[
open
,
setOpen
]
=
useState
(
false
)
const
[
open
,
setOpen
]
=
useState
(
false
)
const
{
handleNodeAddPrev
}
=
use
Workflow
()
const
{
handleNodeAddPrev
}
=
use
NodesInteractions
()
const
edges
=
useEdges
()
const
edges
=
useEdges
()
const
connectedEdges
=
getConnectedEdges
([{
id
}
as
Node
],
edges
)
const
connectedEdges
=
getConnectedEdges
([{
id
}
as
Node
],
edges
)
const
connected
=
connectedEdges
.
find
(
edge
=>
edge
.
targetHandle
===
handleId
&&
edge
.
target
===
id
)
const
connected
=
connectedEdges
.
find
(
edge
=>
edge
.
targetHandle
===
handleId
&&
edge
.
target
===
id
)
...
@@ -92,7 +92,7 @@ export const NodeSourceHandle = ({
...
@@ -92,7 +92,7 @@ export const NodeSourceHandle = ({
nodeSelectorClassName
,
nodeSelectorClassName
,
}:
NodeHandleProps
)
=>
{
}:
NodeHandleProps
)
=>
{
const
[
open
,
setOpen
]
=
useState
(
false
)
const
[
open
,
setOpen
]
=
useState
(
false
)
const
{
handleNodeAddNext
}
=
use
Workflow
()
const
{
handleNodeAddNext
}
=
use
NodesInteractions
()
const
edges
=
useEdges
()
const
edges
=
useEdges
()
const
connectedEdges
=
getConnectedEdges
([{
id
}
as
Node
],
edges
)
const
connectedEdges
=
getConnectedEdges
([{
id
}
as
Node
],
edges
)
const
connected
=
connectedEdges
.
find
(
edge
=>
edge
.
sourceHandle
===
handleId
&&
edge
.
source
===
id
)
const
connected
=
connectedEdges
.
find
(
edge
=>
edge
.
sourceHandle
===
handleId
&&
edge
.
source
===
id
)
...
...
web/app/components/workflow/nodes/_base/components/panel-operator/change-block.tsx
View file @
a55a7603
...
@@ -4,7 +4,7 @@ import {
...
@@ -4,7 +4,7 @@ import {
}
from
'react'
}
from
'react'
import
{
useTranslation
}
from
'react-i18next'
import
{
useTranslation
}
from
'react-i18next'
import
BlockSelector
from
'@/app/components/workflow/block-selector'
import
BlockSelector
from
'@/app/components/workflow/block-selector'
import
{
use
Workflow
}
from
'@/app/components/workflow/hooks'
import
{
use
NodesInteractions
}
from
'@/app/components/workflow/hooks'
import
type
{
OnSelectBlock
}
from
'@/app/components/workflow/types'
import
type
{
OnSelectBlock
}
from
'@/app/components/workflow/types'
type
ChangeBlockProps
=
{
type
ChangeBlockProps
=
{
...
@@ -16,7 +16,7 @@ const ChangeBlock = ({
...
@@ -16,7 +16,7 @@ const ChangeBlock = ({
sourceHandle
,
sourceHandle
,
}:
ChangeBlockProps
)
=>
{
}:
ChangeBlockProps
)
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
{
handleNodeChange
}
=
use
Workflow
()
const
{
handleNodeChange
}
=
use
NodesInteractions
()
const
handleSelect
=
useCallback
<
OnSelectBlock
>
((
type
,
toolDefaultValue
)
=>
{
const
handleSelect
=
useCallback
<
OnSelectBlock
>
((
type
,
toolDefaultValue
)
=>
{
handleNodeChange
(
nodeId
,
type
,
sourceHandle
,
toolDefaultValue
)
handleNodeChange
(
nodeId
,
type
,
sourceHandle
,
toolDefaultValue
)
...
...
web/app/components/workflow/nodes/_base/components/panel-operator/index.tsx
View file @
a55a7603
...
@@ -14,7 +14,7 @@ import ChangeBlock from './change-block'
...
@@ -14,7 +14,7 @@ import ChangeBlock from './change-block'
import
{
useStore
}
from
'@/app/components/workflow/store'
import
{
useStore
}
from
'@/app/components/workflow/store'
import
{
import
{
useNodesExtraData
,
useNodesExtraData
,
use
Workflow
,
use
NodesInteractions
,
}
from
'@/app/components/workflow/hooks'
}
from
'@/app/components/workflow/hooks'
import
{
DotsHorizontal
}
from
'@/app/components/base/icons/src/vender/line/general'
import
{
DotsHorizontal
}
from
'@/app/components/base/icons/src/vender/line/general'
import
{
import
{
...
@@ -52,7 +52,7 @@ const PanelOperator = ({
...
@@ -52,7 +52,7 @@ const PanelOperator = ({
const
{
locale
}
=
useContext
(
I18n
)
const
{
locale
}
=
useContext
(
I18n
)
const
language
=
getLanguage
(
locale
)
const
language
=
getLanguage
(
locale
)
const
edges
=
useEdges
()
const
edges
=
useEdges
()
const
{
handleNodeDelete
}
=
use
Workflow
()
const
{
handleNodeDelete
}
=
use
NodesInteractions
()
const
nodesExtraData
=
useNodesExtraData
()
const
nodesExtraData
=
useNodesExtraData
()
const
toolsets
=
useStore
(
s
=>
s
.
toolsets
)
const
toolsets
=
useStore
(
s
=>
s
.
toolsets
)
const
toolsMap
=
useStore
(
s
=>
s
.
toolsMap
)
const
toolsMap
=
useStore
(
s
=>
s
.
toolsMap
)
...
...
web/app/components/workflow/nodes/_base/hooks/use-node-crud.ts
View file @
a55a7603
import
{
use
Workflow
}
from
'@/app/components/workflow/hooks'
import
{
use
NodeDataUpdate
}
from
'@/app/components/workflow/hooks'
import
type
{
CommonNodeType
}
from
'@/app/components/workflow/types'
import
type
{
CommonNodeType
}
from
'@/app/components/workflow/types'
const
useNodeCrud
=
<
T
>
(
id
:
string
,
data
:
CommonNodeType
<
T
>
)
=>
{
const
useNodeCrud
=
<
T
>
(
id
:
string
,
data
:
CommonNodeType
<
T
>
)
=>
{
const
{
handleNodeDataUpdate
}
=
useWorkflow
()
const
{
handleNodeDataUpdate
WithSyncDraft
}
=
useNodeDataUpdate
()
const
setInputs
=
(
newInputs
:
CommonNodeType
<
T
>
)
=>
{
const
setInputs
=
(
newInputs
:
CommonNodeType
<
T
>
)
=>
{
handleNodeDataUpdate
({
handleNodeDataUpdate
WithSyncDraft
({
id
,
id
,
data
:
newInputs
,
data
:
newInputs
,
})
})
...
...
web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts
View file @
a55a7603
import
{
useState
}
from
'react'
import
{
useState
}
from
'react'
import
{
useTranslation
}
from
'react-i18next'
import
{
useTranslation
}
from
'react-i18next'
import
{
use
Workflow
}
from
'@/app/components/workflow/hooks'
import
{
use
NodeDataUpdate
}
from
'@/app/components/workflow/hooks'
import
type
{
CommonNodeType
,
InputVar
,
Variable
}
from
'@/app/components/workflow/types'
import
type
{
CommonNodeType
,
InputVar
,
Variable
}
from
'@/app/components/workflow/types'
import
{
InputVarType
,
NodeRunningStatus
}
from
'@/app/components/workflow/types'
import
{
InputVarType
,
NodeRunningStatus
}
from
'@/app/components/workflow/types'
import
{
useStore
as
useAppStore
}
from
'@/app/components/app/store'
import
{
useStore
as
useAppStore
}
from
'@/app/components/app/store'
...
@@ -21,7 +21,7 @@ const useOneStepRun = <T>({ id, data, defaultRunInputData, isInvalid = () => tru
...
@@ -21,7 +21,7 @@ const useOneStepRun = <T>({ id, data, defaultRunInputData, isInvalid = () => tru
const
[
runInputData
,
setRunInputData
]
=
useState
<
Record
<
string
,
any
>>
(
defaultRunInputData
||
{})
const
[
runInputData
,
setRunInputData
]
=
useState
<
Record
<
string
,
any
>>
(
defaultRunInputData
||
{})
const
[
runResult
,
setRunResult
]
=
useState
<
any
>
(
null
)
const
[
runResult
,
setRunResult
]
=
useState
<
any
>
(
null
)
const
{
handleNodeDataUpdate
}:
{
handleNodeDataUpdate
:
(
data
:
any
)
=>
void
}
=
use
Workflow
()
const
{
handleNodeDataUpdate
}:
{
handleNodeDataUpdate
:
(
data
:
any
)
=>
void
}
=
use
NodeDataUpdate
()
const
isShowSingleRun
=
data
.
_isSingleRun
const
isShowSingleRun
=
data
.
_isSingleRun
const
hideSingleRun
=
()
=>
{
const
hideSingleRun
=
()
=>
{
handleNodeDataUpdate
({
handleNodeDataUpdate
({
...
...
web/app/components/workflow/nodes/_base/panel.tsx
View file @
a55a7603
...
@@ -18,7 +18,10 @@ import {
...
@@ -18,7 +18,10 @@ import {
XClose
,
XClose
,
}
from
'@/app/components/base/icons/src/vender/line/general'
}
from
'@/app/components/base/icons/src/vender/line/general'
import
BlockIcon
from
'@/app/components/workflow/block-icon'
import
BlockIcon
from
'@/app/components/workflow/block-icon'
import
{
useWorkflow
}
from
'@/app/components/workflow/hooks'
import
{
useNodeDataUpdate
,
useNodesInteractions
,
}
from
'@/app/components/workflow/hooks'
import
{
canRunBySingle
}
from
'@/app/components/workflow/utils'
import
{
canRunBySingle
}
from
'@/app/components/workflow/utils'
import
{
GitBranch01
}
from
'@/app/components/base/icons/src/vender/line/development'
import
{
GitBranch01
}
from
'@/app/components/base/icons/src/vender/line/development'
import
{
Play
}
from
'@/app/components/base/icons/src/vender/line/mediaAndDevices'
import
{
Play
}
from
'@/app/components/base/icons/src/vender/line/mediaAndDevices'
...
@@ -36,18 +39,20 @@ const BasePanel: FC<BasePanelProps> = ({
...
@@ -36,18 +39,20 @@ const BasePanel: FC<BasePanelProps> = ({
children
,
children
,
})
=>
{
})
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
{
handleNodeSelect
}
=
useNodesInteractions
()
const
{
const
{
handleNodeSelect
,
handleNodeDataUpdate
,
handleNodeDataUpdate
,
}
=
useWorkflow
()
handleNodeDataUpdateWithSyncDraft
,
}
=
useNodeDataUpdate
()
const
handleTitleChange
=
useCallback
((
title
:
string
)
=>
{
const
handleTitleChange
=
useCallback
((
title
:
string
)
=>
{
if
(
!
title
)
if
(
!
title
)
return
return
handleNodeDataUpdate
({
id
,
data
:
{
...
data
,
title
}
})
handleNodeDataUpdate
WithSyncDraft
({
id
,
data
:
{
...
data
,
title
}
})
},
[
handleNodeDataUpdate
,
id
,
data
])
},
[
handleNodeDataUpdate
WithSyncDraft
,
id
,
data
])
const
handleDescriptionChange
=
useCallback
((
desc
:
string
)
=>
{
const
handleDescriptionChange
=
useCallback
((
desc
:
string
)
=>
{
handleNodeDataUpdate
({
id
,
data
:
{
...
data
,
desc
}
})
handleNodeDataUpdate
WithSyncDraft
({
id
,
data
:
{
...
data
,
desc
}
})
},
[
handleNodeDataUpdate
,
id
,
data
])
},
[
handleNodeDataUpdate
WithSyncDraft
,
id
,
data
])
return
(
return
(
<
div
className=
'w-[420px] h-full bg-white shadow-lg border-[0.5px] border-gray-200 rounded-2xl overflow-y-auto'
>
<
div
className=
'w-[420px] h-full bg-white shadow-lg border-[0.5px] border-gray-200 rounded-2xl overflow-y-auto'
>
...
...
web/app/components/workflow/nodes/question-classifier/components/class-list.tsx
View file @
a55a7603
...
@@ -3,7 +3,7 @@ import type { FC } from 'react'
...
@@ -3,7 +3,7 @@ import type { FC } from 'react'
import
React
,
{
useCallback
}
from
'react'
import
React
,
{
useCallback
}
from
'react'
import
produce
from
'immer'
import
produce
from
'immer'
import
{
useTranslation
}
from
'react-i18next'
import
{
useTranslation
}
from
'react-i18next'
import
{
use
Workflow
}
from
'../../../hooks'
import
{
use
EdgesInteractions
}
from
'../../../hooks'
import
AddButton
from
'../../_base/components/add-button'
import
AddButton
from
'../../_base/components/add-button'
import
Item
from
'./class-item'
import
Item
from
'./class-item'
import
type
{
Topic
}
from
'@/app/components/workflow/nodes/question-classifier/types'
import
type
{
Topic
}
from
'@/app/components/workflow/nodes/question-classifier/types'
...
@@ -22,7 +22,7 @@ const ClassList: FC<Props> = ({
...
@@ -22,7 +22,7 @@ const ClassList: FC<Props> = ({
onChange
,
onChange
,
})
=>
{
})
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
{
handleEdgeDeleteByDeleteBranch
}
=
use
Workflow
()
const
{
handleEdgeDeleteByDeleteBranch
}
=
use
EdgesInteractions
()
const
handleClassChange
=
useCallback
((
index
:
number
)
=>
{
const
handleClassChange
=
useCallback
((
index
:
number
)
=>
{
return
(
value
:
Topic
)
=>
{
return
(
value
:
Topic
)
=>
{
...
...
web/app/components/workflow/operator/zoom-in-out.tsx
View file @
a55a7603
...
@@ -10,7 +10,7 @@ import {
...
@@ -10,7 +10,7 @@ import {
useReactFlow
,
useReactFlow
,
useViewport
,
useViewport
,
}
from
'reactflow'
}
from
'reactflow'
import
{
use
Workflow
}
from
'../hooks'
import
{
use
NodesSyncDraft
}
from
'../hooks'
import
{
useStore
}
from
'../store'
import
{
useStore
}
from
'../store'
import
{
import
{
PortalToFollowElem
,
PortalToFollowElem
,
...
@@ -29,7 +29,7 @@ const ZoomInOut: FC = () => {
...
@@ -29,7 +29,7 @@ const ZoomInOut: FC = () => {
fitView
,
fitView
,
}
=
useReactFlow
()
}
=
useReactFlow
()
const
{
zoom
}
=
useViewport
()
const
{
zoom
}
=
useViewport
()
const
{
handleSyncWorkflowDraft
}
=
use
Workflow
()
const
{
handleSyncWorkflowDraft
}
=
use
NodesSyncDraft
()
const
[
open
,
setOpen
]
=
useState
(
false
)
const
[
open
,
setOpen
]
=
useState
(
false
)
const
runningStatus
=
useStore
(
s
=>
s
.
runningStatus
)
const
runningStatus
=
useStore
(
s
=>
s
.
runningStatus
)
...
...
web/app/components/workflow/panel/debug-and-preview/hooks.ts
View file @
a55a7603
...
@@ -17,7 +17,7 @@ export const useChat = (
...
@@ -17,7 +17,7 @@ export const useChat = (
)
=>
{
)
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
{
notify
}
=
useToastContext
()
const
{
notify
}
=
useToastContext
()
const
run
=
useWorkflowRun
()
const
{
handleRun
}
=
useWorkflowRun
()
const
hasStopResponded
=
useRef
(
false
)
const
hasStopResponded
=
useRef
(
false
)
const
connversationId
=
useRef
(
''
)
const
connversationId
=
useRef
(
''
)
const
taskIdRef
=
useRef
(
''
)
const
taskIdRef
=
useRef
(
''
)
...
@@ -126,7 +126,7 @@ export const useChat = (
...
@@ -126,7 +126,7 @@ export const useChat = (
let
hasSetResponseId
=
false
let
hasSetResponseId
=
false
r
un
(
handleR
un
(
params
,
params
,
{
{
onData
:
(
message
:
string
,
isFirstMessage
:
boolean
,
{
conversationId
:
newConversationId
,
messageId
,
taskId
}:
any
)
=>
{
onData
:
(
message
:
string
,
isFirstMessage
:
boolean
,
{
conversationId
:
newConversationId
,
messageId
,
taskId
}:
any
)
=>
{
...
@@ -179,7 +179,7 @@ export const useChat = (
...
@@ -179,7 +179,7 @@ export const useChat = (
},
},
},
},
)
)
},
[
r
un
,
handleResponding
,
handleUpdateChatList
,
notify
,
t
,
updateCurrentQA
])
},
[
handleR
un
,
handleResponding
,
handleUpdateChatList
,
notify
,
t
,
updateCurrentQA
])
return
{
return
{
conversationId
:
connversationId
.
current
,
conversationId
:
connversationId
.
current
,
...
...
web/app/components/workflow/panel/inputs-panel.tsx
View file @
a55a7603
...
@@ -7,10 +7,7 @@ import { useNodes } from 'reactflow'
...
@@ -7,10 +7,7 @@ import { useNodes } from 'reactflow'
import
FormItem
from
'../nodes/_base/components/before-run-form/form-item'
import
FormItem
from
'../nodes/_base/components/before-run-form/form-item'
import
{
BlockEnum
}
from
'../types'
import
{
BlockEnum
}
from
'../types'
import
{
useStore
}
from
'../store'
import
{
useStore
}
from
'../store'
import
{
import
{
useWorkflowRun
}
from
'../hooks'
useWorkflow
,
useWorkflowRun
,
}
from
'../hooks'
import
type
{
StartNodeType
}
from
'../nodes/start/types'
import
type
{
StartNodeType
}
from
'../nodes/start/types'
import
Button
from
'@/app/components/base/button'
import
Button
from
'@/app/components/base/button'
...
@@ -18,8 +15,10 @@ const InputsPanel = () => {
...
@@ -18,8 +15,10 @@ const InputsPanel = () => {
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
nodes
=
useNodes
<
StartNodeType
>
()
const
nodes
=
useNodes
<
StartNodeType
>
()
const
inputs
=
useStore
(
s
=>
s
.
inputs
)
const
inputs
=
useStore
(
s
=>
s
.
inputs
)
const
run
=
useWorkflowRun
()
const
{
const
{
handleRunInit
}
=
useWorkflow
()
handleRun
,
handleRunSetting
,
}
=
useWorkflowRun
()
const
startNode
=
nodes
.
find
(
node
=>
node
.
data
.
type
===
BlockEnum
.
Start
)
const
startNode
=
nodes
.
find
(
node
=>
node
.
data
.
type
===
BlockEnum
.
Start
)
const
variables
=
startNode
?.
data
.
variables
||
[]
const
variables
=
startNode
?.
data
.
variables
||
[]
...
@@ -34,10 +33,10 @@ const InputsPanel = () => {
...
@@ -34,10 +33,10 @@ const InputsPanel = () => {
useStore
.
setState
({
showInputsPanel
:
false
})
useStore
.
setState
({
showInputsPanel
:
false
})
},
[])
},
[])
const
handle
Run
=
()
=>
{
const
do
Run
=
()
=>
{
handleCancel
()
handleCancel
()
handleRun
Init
()
handleRun
Setting
()
r
un
({
inputs
})
handleR
un
({
inputs
})
}
}
return
(
return
(
...
@@ -72,7 +71,7 @@ const InputsPanel = () => {
...
@@ -72,7 +71,7 @@ const InputsPanel = () => {
<
Button
<
Button
type=
'primary'
type=
'primary'
className=
'py-0 w-[190px] h-8 rounded-lg text-[13px] font-medium'
className=
'py-0 w-[190px] h-8 rounded-lg text-[13px] font-medium'
onClick=
{
handle
Run
}
onClick=
{
do
Run
}
>
>
{
t
(
'workflow.singleRun.startRun'
)
}
{
t
(
'workflow.singleRun.startRun'
)
}
</
Button
>
</
Button
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment