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
f51f4a58
Commit
f51f4a58
authored
Mar 08, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: tool inputs
parent
b5f3bbea
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
120 additions
and
12 deletions
+120
-12
field.tsx
web/app/components/workflow/nodes/_base/components/field.tsx
+1
-1
input-var-list.tsx
...ponents/workflow/nodes/tool/components/input-var-list.tsx
+86
-0
panel.tsx
web/app/components/workflow/nodes/tool/panel.tsx
+19
-6
use-config.ts
web/app/components/workflow/nodes/tool/use-config.ts
+14
-5
No files found.
web/app/components/workflow/nodes/_base/components/field.tsx
View file @
f51f4a58
...
...
@@ -31,7 +31,7 @@ const Filed: FC<Props> = ({
<
div
className=
{
cn
(
inline
&&
'flex justify-between items-center'
)
}
>
<
div
className=
'flex justify-between items-center'
>
<
div
className=
'flex items-center h-6'
>
<
div
className=
'text-
xs
font-medium text-gray-700 uppercase'
>
{
title
}
</
div
>
<
div
className=
'text-
[13px]
font-medium text-gray-700 uppercase'
>
{
title
}
</
div
>
{
tooltip
&&
(
<
TooltipPlus
popupContent=
{
<
div
className=
'w-[120px]'
>
...
...
web/app/components/workflow/nodes/tool/components/input-var-list.tsx
0 → 100644
View file @
f51f4a58
'use client'
import
type
{
FC
}
from
'react'
import
React
,
{
useCallback
}
from
'react'
import
produce
from
'immer'
import
type
{
ToolVarInput
}
from
'../types'
import
{
VarType
}
from
'../types'
import
type
{
CredentialFormSchema
}
from
'@/app/components/header/account-setting/model-provider-page/declarations'
import
{
FormTypeEnum
}
from
'@/app/components/header/account-setting/model-provider-page/declarations'
import
{
useLanguage
}
from
'@/app/components/header/account-setting/model-provider-page/hooks'
import
VarReferencePicker
from
'@/app/components/workflow/nodes/_base/components/variable/var-reference-picker'
type
Props
=
{
readOnly
:
boolean
schema
:
CredentialFormSchema
[]
value
:
ToolVarInput
[]
onChange
:
(
value
:
ToolVarInput
[])
=>
void
}
const
InputVarList
:
FC
<
Props
>
=
({
readOnly
,
schema
,
value
,
onChange
,
})
=>
{
const
language
=
useLanguage
()
const
keyValues
=
(()
=>
{
const
res
:
Record
<
string
,
ToolVarInput
>
=
{}
value
.
forEach
((
item
)
=>
{
res
[
item
.
variable
]
=
item
})
return
res
})()
const
handleChange
=
useCallback
((
variable
:
string
)
=>
{
return
(
varValue
:
any
)
=>
{
const
newValue
=
produce
(
value
,
(
draft
:
ToolVarInput
[])
=>
{
const
target
=
draft
.
find
(
item
=>
item
.
variable
===
variable
)
if
(
target
)
{
target
.
value_selector
=
varValue
// TODO: support constant value
}
else
{
draft
.
push
({
variable
,
variable_type
:
VarType
.
selector
,
// TODO: support constant value
value_selector
:
varValue
,
})
}
})
onChange
(
newValue
)
}
},
[
value
,
onChange
])
return
(
<
div
className=
'space-y-3'
>
{
schema
.
map
(({
variable
,
label
,
type
,
required
,
tooltip
,
})
=>
{
const
varInput
=
keyValues
[
variable
]
return
(
<
div
key=
{
variable
}
className=
'space-y-1'
>
<
div
className=
'flex items-center h-[18px] space-x-2'
>
<
span
className=
'text-[13px] font-medium text-gray-900'
>
{
label
[
language
]
||
label
.
en_US
}
</
span
>
<
span
className=
'text-xs font-normal text-gray-500'
>
{
type
===
FormTypeEnum
.
textNumber
?
'Number'
:
'String'
}
</
span
>
{
required
&&
<
span
className=
'leading-[18px] text-xs font-normal text-[#EC4A0A]'
>
Required
</
span
>
}
</
div
>
<
VarReferencePicker
readonly=
{
readOnly
}
isShowNodeName
value=
{
varInput
?.
value_selector
||
[]
}
// TODO: support constant value
onChange=
{
handleChange
(
variable
)
}
/>
{
tooltip
&&
<
div
className=
'leading-[18px] text-xs font-normal text-gray-600'
>
{
tooltip
[
language
]
||
tooltip
.
en_US
}
</
div
>
}
</
div
>
)
})
}
</
div
>
)
}
export
default
React
.
memo
(
InputVarList
)
web/app/components/workflow/nodes/tool/panel.tsx
View file @
f51f4a58
...
...
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next'
import
Split
from
'../_base/components/split'
import
type
{
ToolNodeType
}
from
'./types'
import
useConfig
from
'./use-config'
import
InputVarList
from
'./components/input-var-list'
import
Button
from
'@/app/components/base/button'
import
Field
from
'@/app/components/workflow/nodes/_base/components/field'
import
type
{
NodePanelProps
}
from
'@/app/components/workflow/types'
...
...
@@ -20,6 +21,8 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
const
{
inputs
,
toolInputVarSchema
,
setInputVar
,
toolSettingSchema
,
toolSettingValue
,
setToolSettingValue
,
...
...
@@ -41,12 +44,22 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
)
}
<
div
className=
'px-4 pb-4 space-y-4'
>
<
Field
title=
{
t
(
`${i18nPrefix}.inputVars`
)
}
>
inputVars
</
Field
>
<
Split
/>
{
toolInputVarSchema
.
length
>
0
&&
(
<>
<
Field
title=
{
t
(
`${i18nPrefix}.inputVars`
)
}
>
<
InputVarList
readOnly=
{
readOnly
}
schema=
{
toolInputVarSchema
as
any
}
value=
{
inputs
.
tool_inputs
}
onChange=
{
setInputVar
}
/>
</
Field
>
<
Split
/>
</>
)
}
<
Form
className=
'space-y-4'
itemClassName=
'!py-0'
...
...
web/app/components/workflow/nodes/tool/use-config.ts
View file @
f51f4a58
import
{
useCallback
,
useEffect
,
useState
}
from
'react'
import
type
{
ToolNodeType
}
from
'./types'
import
type
{
ToolNodeType
,
ToolVarInput
}
from
'./types'
import
useNodeCrud
from
'@/app/components/workflow/nodes/_base/hooks/use-node-crud'
import
{
fetchBuiltInToolList
,
fetchCustomToolList
}
from
'@/service/tools'
import
type
{
Tool
}
from
'@/app/components/tools/types'
...
...
@@ -9,7 +9,7 @@ import { CollectionType } from '@/app/components/tools/types'
const
useConfig
=
(
id
:
string
,
payload
:
ToolNodeType
)
=>
{
const
{
inputs
,
setInputs
}
=
useNodeCrud
<
ToolNodeType
>
(
id
,
payload
)
const
{
provider_id
,
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
[
currTool
,
setCurrTool
]
=
useState
<
Tool
|
null
>
(
null
)
const
formSchemas
=
currTool
?
toolParametersToFormSchemas
(
currTool
.
parameters
)
:
[]
...
...
@@ -26,21 +26,30 @@ const useConfig = (id: string, payload: ToolNodeType) => {
},
[
inputs
,
setInputs
])
// setting when call
const
toolInputSchema
=
formSchemas
.
filter
((
item
:
any
)
=>
item
.
form
===
'llm'
)
const
toolInputVarSchema
=
formSchemas
.
filter
((
item
:
any
)
=>
item
.
form
===
'llm'
)
const
setInputVar
=
useCallback
((
value
:
ToolVarInput
[])
=>
{
setInputs
({
...
inputs
,
tool_inputs
:
value
,
})
},
[
inputs
,
setInputs
])
useEffect
(()
=>
{
(
async
()
=>
{
const
list
=
isBuiltIn
?
await
fetchBuiltInToolList
(
provider_
id
)
:
await
fetchCustomToolList
(
provider_id
)
const
list
=
isBuiltIn
?
await
fetchBuiltInToolList
(
provider_
name
||
provider_id
)
:
await
fetchCustomToolList
(
provider_name
)
const
currTool
=
list
.
find
(
tool
=>
tool
.
name
===
tool_name
)
if
(
currTool
)
setCurrTool
(
currTool
)
})()
},
[
provider_
id
])
},
[
provider_
name
])
return
{
inputs
,
currTool
,
toolSettingSchema
,
toolSettingValue
,
setToolSettingValue
,
toolInputVarSchema
,
setInputVar
,
}
}
...
...
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