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
b3b9e1da
Commit
b3b9e1da
authored
Mar 11, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: tools support run
parent
c0ccffa1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
1 deletion
+77
-1
use-one-step-run.ts
...components/workflow/nodes/_base/hooks/use-one-step-run.ts
+1
-0
panel.tsx
web/app/components/workflow/nodes/tool/panel.tsx
+18
-0
use-config.ts
web/app/components/workflow/nodes/tool/use-config.ts
+58
-1
No files found.
web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts
View file @
b3b9e1da
...
@@ -25,6 +25,7 @@ const useOneStepRun = <T>({ id, data, defaultRunInputData, isInvalid = () => tru
...
@@ -25,6 +25,7 @@ const useOneStepRun = <T>({ id, data, defaultRunInputData, isInvalid = () => tru
const
[
runningStatus
,
setRunningStatus
]
=
useState
(
'un started'
)
const
[
runningStatus
,
setRunningStatus
]
=
useState
(
'un started'
)
const
handleRun
=
()
=>
{
const
handleRun
=
()
=>
{
// console.log(runInputData)
if
(
isInvalid
())
if
(
isInvalid
())
return
return
...
...
web/app/components/workflow/nodes/tool/panel.tsx
View file @
b3b9e1da
...
@@ -11,6 +11,7 @@ import type { NodePanelProps } from '@/app/components/workflow/types'
...
@@ -11,6 +11,7 @@ import type { NodePanelProps } from '@/app/components/workflow/types'
import
Form
from
'@/app/components/header/account-setting/model-provider-page/model-modal/Form'
import
Form
from
'@/app/components/header/account-setting/model-provider-page/model-modal/Form'
import
ConfigCredential
from
'@/app/components/tools/setting/build-in/config-credentials'
import
ConfigCredential
from
'@/app/components/tools/setting/build-in/config-credentials'
import
Loading
from
'@/app/components/base/loading'
import
Loading
from
'@/app/components/base/loading'
import
BeforeRunForm
from
'@/app/components/workflow/nodes/_base/components/before-run-form'
const
i18nPrefix
=
'workflow.nodes.tool'
const
i18nPrefix
=
'workflow.nodes.tool'
...
@@ -35,6 +36,12 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
...
@@ -35,6 +36,12 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
hideSetAuthModal
,
hideSetAuthModal
,
handleSaveAuth
,
handleSaveAuth
,
isLoading
,
isLoading
,
isShowSingleRun
,
hideSingleRun
,
singleRunForms
,
runningStatus
,
handleRun
,
handleStop
,
}
=
useConfig
(
id
,
data
)
}
=
useConfig
(
id
,
data
)
if
(
isLoading
)
{
if
(
isLoading
)
{
...
@@ -101,6 +108,17 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
...
@@ -101,6 +108,17 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
isHideRemoveBtn
isHideRemoveBtn
/>
/>
)
}
)
}
{
isShowSingleRun
&&
(
<
BeforeRunForm
nodeName=
{
inputs
.
title
}
onHide=
{
hideSingleRun
}
forms=
{
singleRunForms
}
runningStatus=
{
runningStatus
}
onRun=
{
handleRun
}
onStop=
{
handleStop
}
/>
)
}
</
div
>
</
div
>
)
)
}
}
...
...
web/app/components/workflow/nodes/tool/use-config.ts
View file @
b3b9e1da
...
@@ -3,20 +3,27 @@ import { useTranslation } from 'react-i18next'
...
@@ -3,20 +3,27 @@ import { useTranslation } from 'react-i18next'
import
produce
from
'immer'
import
produce
from
'immer'
import
{
useBoolean
}
from
'ahooks'
import
{
useBoolean
}
from
'ahooks'
import
{
useStore
}
from
'../../store'
import
{
useStore
}
from
'../../store'
import
type
{
ToolNodeType
,
ToolVarInput
}
from
'./types'
import
{
type
ToolNodeType
,
type
ToolVarInput
}
from
'./types'
import
{
useLanguage
}
from
'@/app/components/header/account-setting/model-provider-page/hooks'
import
useNodeCrud
from
'@/app/components/workflow/nodes/_base/hooks/use-node-crud'
import
useNodeCrud
from
'@/app/components/workflow/nodes/_base/hooks/use-node-crud'
import
{
CollectionType
}
from
'@/app/components/tools/types'
import
{
CollectionType
}
from
'@/app/components/tools/types'
import
type
{
Collection
,
Tool
}
from
'@/app/components/tools/types'
import
type
{
Collection
,
Tool
}
from
'@/app/components/tools/types'
import
{
fetchBuiltInToolList
,
fetchCollectionList
,
fetchCustomToolList
,
updateBuiltInToolCredential
}
from
'@/service/tools'
import
{
fetchBuiltInToolList
,
fetchCollectionList
,
fetchCustomToolList
,
updateBuiltInToolCredential
}
from
'@/service/tools'
import
{
addDefaultValue
,
toolParametersToFormSchemas
}
from
'@/app/components/tools/utils/to-form-schema'
import
{
addDefaultValue
,
toolParametersToFormSchemas
}
from
'@/app/components/tools/utils/to-form-schema'
import
Toast
from
'@/app/components/base/toast'
import
Toast
from
'@/app/components/base/toast'
import
type
{
Props
as
FormProps
}
from
'@/app/components/workflow/nodes/_base/components/before-run-form/form'
import
{
InputVarType
}
from
'@/app/components/workflow/types'
import
type
{
InputVar
}
from
'@/app/components/workflow/types'
import
useOneStepRun
from
'@/app/components/workflow/nodes/_base/hooks/use-one-step-run'
const
useConfig
=
(
id
:
string
,
payload
:
ToolNodeType
)
=>
{
const
useConfig
=
(
id
:
string
,
payload
:
ToolNodeType
)
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
language
=
useLanguage
()
const
toolsMap
=
useStore
(
s
=>
s
.
toolsMap
)
const
toolsMap
=
useStore
(
s
=>
s
.
toolsMap
)
const
setToolsMap
=
useStore
(
s
=>
s
.
setToolsMap
)
const
setToolsMap
=
useStore
(
s
=>
s
.
setToolsMap
)
const
{
inputs
,
setInputs
}
=
useNodeCrud
<
ToolNodeType
>
(
id
,
payload
)
const
{
inputs
,
setInputs
}
=
useNodeCrud
<
ToolNodeType
>
(
id
,
payload
)
const
toolInputs
=
inputs
.
tool_inputs
const
{
provider_id
,
provider_name
,
provider_type
,
tool_name
,
tool_parameters
}
=
inputs
const
{
provider_id
,
provider_name
,
provider_type
,
tool_name
,
tool_parameters
}
=
inputs
const
isBuiltIn
=
provider_type
===
CollectionType
.
builtIn
const
isBuiltIn
=
provider_type
===
CollectionType
.
builtIn
const
[
currCollection
,
setCurrCollection
]
=
useState
<
Collection
|
null
|
undefined
>
(
null
)
const
[
currCollection
,
setCurrCollection
]
=
useState
<
Collection
|
null
|
undefined
>
(
null
)
...
@@ -99,6 +106,48 @@ const useConfig = (id: string, payload: ToolNodeType) => {
...
@@ -99,6 +106,48 @@ const useConfig = (id: string, payload: ToolNodeType) => {
})()
})()
},
[
provider_name
])
},
[
provider_name
])
// single run
const
{
isShowSingleRun
,
hideSingleRun
,
runningStatus
,
setRunInputData
,
handleRun
,
handleStop
,
}
=
useOneStepRun
<
ToolNodeType
>
({
id
,
data
:
inputs
,
defaultRunInputData
:
{},
})
const
[
inputVarValues
,
doSetInputVarValues
]
=
useState
<
Record
<
string
,
any
>>
({})
const
setInputVarValues
=
(
value
:
Record
<
string
,
any
>
)
=>
{
doSetInputVarValues
(
value
)
setRunInputData
(
value
)
}
const
singleRunForms
=
(()
=>
{
const
formInputs
:
InputVar
[]
=
[]
toolInputVarSchema
.
forEach
((
item
:
any
)
=>
{
const
targetItem
=
toolInputs
.
find
(
input
=>
input
.
variable
===
item
.
variable
)
// TODO: support selector
// if (targetItem?.variable_type === VarType.selector) {
formInputs
.
push
({
label
:
item
.
label
[
language
]
||
item
.
label
.
en_US
,
variable
:
item
.
variable
,
type
:
InputVarType
.
textInput
,
required
:
item
.
required
,
})
// }
})
const
forms
:
FormProps
[]
=
[{
inputs
:
formInputs
,
values
:
inputVarValues
,
onChange
:
setInputVarValues
,
}]
return
forms
})()
return
{
return
{
inputs
,
inputs
,
currTool
,
currTool
,
...
@@ -114,6 +163,14 @@ const useConfig = (id: string, payload: ToolNodeType) => {
...
@@ -114,6 +163,14 @@ const useConfig = (id: string, payload: ToolNodeType) => {
hideSetAuthModal
,
hideSetAuthModal
,
handleSaveAuth
,
handleSaveAuth
,
isLoading
,
isLoading
,
isShowSingleRun
,
hideSingleRun
,
inputVarValues
,
setInputVarValues
,
singleRunForms
,
runningStatus
,
handleRun
,
handleStop
,
}
}
}
}
...
...
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