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
89fc90ac
Commit
89fc90ac
authored
Mar 08, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: code support debug
parent
072f5caa
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
2 deletions
+71
-2
page.tsx
web/app/(commonLayout)/workflow/nodes/page.tsx
+2
-2
panel.tsx
web/app/components/workflow/nodes/code/panel.tsx
+26
-0
use-config.ts
web/app/components/workflow/nodes/code/use-config.ts
+43
-0
No files found.
web/app/(commonLayout)/workflow/nodes/page.tsx
View file @
89fc90ac
...
...
@@ -32,8 +32,8 @@ const allMockData = {
[
BlockEnum
.
End
]:
EndNodeMock
,
}
const
nodes
=
[
BlockEnum
.
KnowledgeRetrieval
/* 4 */
,
BlockEnum
.
Start
/* 1 */
,
BlockEnum
.
DirectAnswer
/* 2 */
,
BlockEnum
.
LLM
/* 3 */
,
BlockEnum
.
QuestionClassifier
/* 5 */
,
BlockEnum
.
IfElse
/* 6 */
,
BlockEnum
.
Code
/* 7 */
,
BlockEnum
.
TemplateTransform
/* 8 */
,
BlockEnum
.
HttpRequest
/* 9 */
,
BlockEnum
.
Tool
/* 10 */
,
BlockEnum
.
Code
/* 7 */
,
BlockEnum
.
KnowledgeRetrieval
/* 4 */
,
BlockEnum
.
Start
/* 1 */
,
BlockEnum
.
DirectAnswer
/* 2 */
,
BlockEnum
.
LLM
/* 3 */
,
BlockEnum
.
QuestionClassifier
/* 5 */
,
BlockEnum
.
IfElse
/* 6 */
,
BlockEnum
.
TemplateTransform
/* 8 */
,
BlockEnum
.
HttpRequest
/* 9 */
,
BlockEnum
.
Tool
/* 10 */
,
BlockEnum
.
VariableAssigner
/* 11 */
,
BlockEnum
.
End
/* 12 */
,
].
map
((
item
,
i
)
=>
{
const
payload
=
allMockData
[
item
]
...
...
web/app/components/workflow/nodes/code/panel.tsx
View file @
89fc90ac
...
...
@@ -12,6 +12,7 @@ import Split from '@/app/components/workflow/nodes/_base/components/split'
import
CodeEditor
from
'@/app/components/workflow/nodes/_base/components/editor/code-editor'
import
TypeSelector
from
'@/app/components/workflow/nodes/_base/components/selector'
import
type
{
NodePanelProps
}
from
'@/app/components/workflow/types'
import
BeforeRunForm
from
'@/app/components/workflow/nodes/_base/components/before-run-form'
const
i18nPrefix
=
'workflow.nodes.code'
...
...
@@ -40,6 +41,15 @@ const Panel: FC<NodePanelProps<CodeNodeType>> = ({
handleCodeLanguageChange
,
handleOutputVarListChange
,
handleAddOutputVariable
,
// single run
isShowSingleRun
,
hideSingleRun
,
runningStatus
,
handleRun
,
handleStop
,
varInputs
,
inputVarValues
,
setInputVarValues
,
}
=
useConfig
(
id
,
data
)
return
(
<
div
className=
'mt-2'
>
...
...
@@ -86,6 +96,22 @@ const Panel: FC<NodePanelProps<CodeNodeType>> = ({
/>
</
Field
>
</
div
>
{
isShowSingleRun
&&
(
<
BeforeRunForm
nodeName=
{
inputs
.
title
}
onHide=
{
hideSingleRun
}
forms=
{
[
{
inputs
:
varInputs
,
values
:
inputVarValues
,
onChange
:
setInputVarValues
,
},
]
}
runningStatus=
{
runningStatus
}
onRun=
{
handleRun
}
onStop=
{
handleStop
}
/>
)
}
</
div
>
)
}
...
...
web/app/components/workflow/nodes/code/use-config.ts
View file @
89fc90ac
...
...
@@ -4,6 +4,7 @@ import useVarList from '../_base/hooks/use-var-list'
import
useOutputVarList
from
'../_base/hooks/use-output-var-list'
import
type
{
CodeLanguage
,
CodeNodeType
}
from
'./types'
import
useNodeCrud
from
'@/app/components/workflow/nodes/_base/hooks/use-node-crud'
import
useOneStepRun
from
'@/app/components/workflow/nodes/_base/hooks/use-one-step-run'
const
useConfig
=
(
id
:
string
,
payload
:
CodeNodeType
)
=>
{
const
{
inputs
,
setInputs
}
=
useNodeCrud
<
CodeNodeType
>
(
id
,
payload
)
...
...
@@ -31,6 +32,39 @@ const useConfig = (id: string, payload: CodeNodeType) => {
setInputs
,
})
// single run
const
{
isShowSingleRun
,
hideSingleRun
,
toVarInputs
,
runningStatus
,
handleRun
,
handleStop
,
runInputData
,
setRunInputData
,
}
=
useOneStepRun
<
CodeNodeType
>
({
id
,
data
:
inputs
,
defaultRunInputData
:
{
name
:
'Joel'
,
age
:
'18'
,
},
})
const
varInputs
=
toVarInputs
(
inputs
.
variables
)
const
inputVarValues
=
(()
=>
{
const
vars
:
Record
<
string
,
any
>
=
{}
Object
.
keys
(
runInputData
)
.
forEach
((
key
)
=>
{
vars
[
key
]
=
runInputData
[
key
]
})
return
vars
})()
const
setInputVarValues
=
useCallback
((
newPayload
:
Record
<
string
,
any
>
)
=>
{
setRunInputData
(
newPayload
)
},
[
runInputData
,
setRunInputData
])
return
{
inputs
,
handleVarListChange
,
...
...
@@ -39,6 +73,15 @@ const useConfig = (id: string, payload: CodeNodeType) => {
handleCodeLanguageChange
,
handleOutputVarListChange
,
handleAddOutputVariable
,
// single run
isShowSingleRun
,
hideSingleRun
,
runningStatus
,
handleRun
,
handleStop
,
varInputs
,
inputVarValues
,
setInputVarValues
,
}
}
...
...
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