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
74bf6cd1
Commit
74bf6cd1
authored
Mar 12, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add single run api
parent
547df0b5
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
38 additions
and
17 deletions
+38
-17
index.tsx
...workflow/nodes/_base/components/before-run-form/index.tsx
+4
-3
use-one-step-run.ts
...components/workflow/nodes/_base/hooks/use-one-step-run.ts
+25
-12
node.tsx
web/app/components/workflow/nodes/_base/node.tsx
+1
-1
panel.tsx
web/app/components/workflow/nodes/code/panel.tsx
+1
-0
panel.tsx
web/app/components/workflow/nodes/direct-answer/panel.tsx
+1
-1
types.ts
web/app/components/workflow/types.ts
+2
-0
workflow.ts
web/service/workflow.ts
+4
-0
No files found.
web/app/components/workflow/nodes/_base/components/before-run-form/index.tsx
View file @
74bf6cd1
...
@@ -9,6 +9,7 @@ import Button from '@/app/components/base/button'
...
@@ -9,6 +9,7 @@ import Button from '@/app/components/base/button'
import
{
StopCircle
}
from
'@/app/components/base/icons/src/vender/solid/mediaAndDevices'
import
{
StopCircle
}
from
'@/app/components/base/icons/src/vender/solid/mediaAndDevices'
import
{
Loading02
,
XClose
}
from
'@/app/components/base/icons/src/vender/line/general'
import
{
Loading02
,
XClose
}
from
'@/app/components/base/icons/src/vender/line/general'
import
Split
from
'@/app/components/workflow/nodes/_base/components/split'
import
Split
from
'@/app/components/workflow/nodes/_base/components/split'
import
{
NodeRunningStatus
}
from
'@/app/components/workflow/types'
const
i18nPrefix
=
'workflow.singleRun'
const
i18nPrefix
=
'workflow.singleRun'
...
@@ -17,7 +18,7 @@ type BeforeRunFormProps = {
...
@@ -17,7 +18,7 @@ type BeforeRunFormProps = {
onHide
:
()
=>
void
onHide
:
()
=>
void
onRun
:
()
=>
void
onRun
:
()
=>
void
onStop
:
()
=>
void
onStop
:
()
=>
void
runningStatus
:
string
// todo: wait for enum
runningStatus
:
NodeRunningStatus
result
?:
JSX
.
Element
result
?:
JSX
.
Element
forms
:
FormProps
[]
forms
:
FormProps
[]
}
}
...
@@ -32,8 +33,8 @@ const BeforeRunForm: FC<BeforeRunFormProps> = ({
...
@@ -32,8 +33,8 @@ const BeforeRunForm: FC<BeforeRunFormProps> = ({
})
=>
{
})
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
isFinished
=
runningStatus
===
'finished'
const
isFinished
=
runningStatus
===
NodeRunningStatus
.
Succeeded
||
runningStatus
===
NodeRunningStatus
.
Failed
const
isRunning
=
runningStatus
===
'running'
const
isRunning
=
runningStatus
===
NodeRunningStatus
.
Running
return
(
return
(
<
div
className=
'absolute inset-0 z-10 rounded-2xl pt-10'
style=
{
{
<
div
className=
'absolute inset-0 z-10 rounded-2xl pt-10'
style=
{
{
backgroundColor
:
'rgba(16, 24, 40, 0.20)'
,
backgroundColor
:
'rgba(16, 24, 40, 0.20)'
,
...
...
web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts
View file @
74bf6cd1
import
{
useState
}
from
'react'
import
{
useState
}
from
'react'
import
{
useWorkflow
}
from
'@/app/components/workflow/hooks'
import
{
useWorkflow
}
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
}
from
'@/app/components/workflow/types'
import
{
InputVarType
,
NodeRunningStatus
}
from
'@/app/components/workflow/types'
import
{
useStore
as
useAppStore
}
from
'@/app/components/app/store'
import
{
singleNodeRun
}
from
'@/service/workflow'
type
Params
<
T
>
=
{
type
Params
<
T
>
=
{
id
:
string
id
:
string
...
@@ -11,6 +13,9 @@ type Params<T> = {
...
@@ -11,6 +13,9 @@ type Params<T> = {
}
}
const
useOneStepRun
=
<
T
>
({
id
,
data
,
defaultRunInputData
,
isInvalid
=
()
=>
true
}:
Params
<
T
>
)
=>
{
const
useOneStepRun
=
<
T
>
({
id
,
data
,
defaultRunInputData
,
isInvalid
=
()
=>
true
}:
Params
<
T
>
)
=>
{
const
appId
=
useAppStore
.
getState
().
appDetail
?.
id
const
[
runInputData
,
setRunInputData
]
=
useState
<
Record
<
string
,
any
>>
(
defaultRunInputData
||
{})
const
{
handleNodeDataUpdate
}:
{
handleNodeDataUpdate
:
(
data
:
any
)
=>
void
}
=
useWorkflow
()
const
{
handleNodeDataUpdate
}:
{
handleNodeDataUpdate
:
(
data
:
any
)
=>
void
}
=
useWorkflow
()
const
isShowSingleRun
=
data
.
_isSingleRun
const
isShowSingleRun
=
data
.
_isSingleRun
const
hideSingleRun
=
()
=>
{
const
hideSingleRun
=
()
=>
{
...
@@ -22,23 +27,32 @@ const useOneStepRun = <T>({ id, data, defaultRunInputData, isInvalid = () => tru
...
@@ -22,23 +27,32 @@ const useOneStepRun = <T>({ id, data, defaultRunInputData, isInvalid = () => tru
},
},
})
})
}
}
const
runningStatus
=
data
.
_singleRunningStatus
||
NodeRunningStatus
.
NotStart
const
[
runningStatus
,
setRunningStatus
]
=
useState
(
'un started'
)
const
handleRun
=
async
()
=>
{
const
handleRun
=
()
=>
{
if
(
!
isInvalid
())
// console.log(runInputData)
if
(
isInvalid
())
return
return
handleNodeDataUpdate
({
id
,
data
:
{
...
data
,
_singleRunningStatus
:
NodeRunningStatus
.
Running
,
},
})
setRunningStatus
(
'running'
)
const
res
=
await
singleNodeRun
(
appId
!
,
id
,
{
inputs
:
runInputData
})
console
.
log
(
res
)
}
}
const
handleStop
=
()
=>
{
const
handleStop
=
()
=>
{
setRunningStatus
(
'not started'
)
handleNodeDataUpdate
({
id
,
data
:
{
...
data
,
_singleRunningStatus
:
NodeRunningStatus
.
NotStart
,
},
})
}
}
// TODO: store to node
const
[
runInputData
,
setRunInputData
]
=
useState
<
Record
<
string
,
any
>>
(
defaultRunInputData
||
{})
const
toVarInputs
=
(
variables
:
Variable
[]):
InputVar
[]
=>
{
const
toVarInputs
=
(
variables
:
Variable
[]):
InputVar
[]
=>
{
if
(
!
variables
)
if
(
!
variables
)
return
[]
return
[]
...
@@ -64,7 +78,6 @@ const useOneStepRun = <T>({ id, data, defaultRunInputData, isInvalid = () => tru
...
@@ -64,7 +78,6 @@ const useOneStepRun = <T>({ id, data, defaultRunInputData, isInvalid = () => tru
runningStatus
,
runningStatus
,
handleRun
,
handleRun
,
handleStop
,
handleStop
,
setRunningStatus
,
runInputData
,
runInputData
,
setRunInputData
,
setRunInputData
,
}
}
...
...
web/app/components/workflow/nodes/_base/node.tsx
View file @
74bf6cd1
...
@@ -91,7 +91,7 @@ const BaseNode: FC<BaseNodeProps> = ({
...
@@ -91,7 +91,7 @@ const BaseNode: FC<BaseNodeProps> = ({
{
data
.
title
}
{
data
.
title
}
</
div
>
</
div
>
{
{
data
.
_runningStatus
===
NodeRunningStatus
.
Running
&&
(
(
data
.
_runningStatus
===
NodeRunningStatus
.
Running
||
data
.
_singleRunningStatus
===
NodeRunningStatus
.
Running
)
&&
(
<
Loading02
className=
'w-3.5 h-3.5 text-primary-600 animate-spin'
/>
<
Loading02
className=
'w-3.5 h-3.5 text-primary-600 animate-spin'
/>
)
)
}
}
...
...
web/app/components/workflow/nodes/code/panel.tsx
View file @
74bf6cd1
...
@@ -112,6 +112,7 @@ const Panel: FC<NodePanelProps<CodeNodeType>> = ({
...
@@ -112,6 +112,7 @@ const Panel: FC<NodePanelProps<CodeNodeType>> = ({
onStop=
{
handleStop
}
onStop=
{
handleStop
}
/>
/>
)
}
)
}
</
div
>
</
div
>
)
)
}
}
...
...
web/app/components/workflow/nodes/direct-answer/panel.tsx
View file @
74bf6cd1
...
@@ -42,7 +42,7 @@ const Panel: FC<NodePanelProps<DirectAnswerNodeType>> = ({
...
@@ -42,7 +42,7 @@ const Panel: FC<NodePanelProps<DirectAnswerNodeType>> = ({
</
Field
>
</
Field
>
<
Split
/>
<
Split
/>
<
Editor
<
Editor
title=
{
t
(
`${i18nPrefix}.answer`
)
}
title=
{
t
(
`${i18nPrefix}.answer`
)
!
}
value=
{
inputs
.
answer
}
value=
{
inputs
.
answer
}
onChange=
{
handleAnswerChange
}
onChange=
{
handleAnswerChange
}
variables=
{
inputs
.
variables
.
map
(
item
=>
item
.
variable
)
}
variables=
{
inputs
.
variables
.
map
(
item
=>
item
.
variable
)
}
...
...
web/app/components/workflow/types.ts
View file @
74bf6cd1
...
@@ -28,6 +28,7 @@ export type CommonNodeType<T = {}> = {
...
@@ -28,6 +28,7 @@ export type CommonNodeType<T = {}> = {
_targetBranches
?:
Branch
[]
_targetBranches
?:
Branch
[]
_isSingleRun
?:
boolean
_isSingleRun
?:
boolean
_runningStatus
?:
NodeRunningStatus
_runningStatus
?:
NodeRunningStatus
_singleRunningStatus
?:
NodeRunningStatus
selected
?:
boolean
selected
?:
boolean
title
:
string
title
:
string
desc
:
string
desc
:
string
...
@@ -158,6 +159,7 @@ export enum WorkflowRunningStatus {
...
@@ -158,6 +159,7 @@ export enum WorkflowRunningStatus {
}
}
export
enum
NodeRunningStatus
{
export
enum
NodeRunningStatus
{
NotStart
=
'not-start'
,
Waiting
=
'waiting'
,
Waiting
=
'waiting'
,
Running
=
'running'
,
Running
=
'running'
,
Succeeded
=
'succeeded'
,
Succeeded
=
'succeeded'
,
...
...
web/service/workflow.ts
View file @
74bf6cd1
...
@@ -21,3 +21,7 @@ export const fetchNodesDefaultConfigs: Fetcher<any, string> = (url) => {
...
@@ -21,3 +21,7 @@ export const fetchNodesDefaultConfigs: Fetcher<any, string> = (url) => {
export
const
fetchWorkflowRunHistory
:
Fetcher
<
WorkflowRunHistoryResponse
,
string
>
=
(
url
)
=>
{
export
const
fetchWorkflowRunHistory
:
Fetcher
<
WorkflowRunHistoryResponse
,
string
>
=
(
url
)
=>
{
return
get
<
WorkflowRunHistoryResponse
>
(
url
)
return
get
<
WorkflowRunHistoryResponse
>
(
url
)
}
}
export
const
singleNodeRun
=
(
appId
:
string
,
nodeId
:
string
,
params
:
object
)
=>
{
return
post
(
`apps/
${
appId
}
/workflows/draft/nodes/
${
nodeId
}
/run`
,
{
body
:
params
})
}
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