Skip to content

Commit

Permalink
feat: tools vars limit
Browse files Browse the repository at this point in the history
  • Loading branch information
iamjoel committed Mar 15, 2024
1 parent 338dd1c commit 5ee7fc4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useCallback } from 'react'
import produce from 'immer'
import type { ToolVarInput } from '../types'
import { VarType as VarKindType } from '../types'
import { type ValueSelector } from '@/app/components/workflow/types'
import type { ValueSelector, Var } from '@/app/components/workflow/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'
Expand All @@ -17,6 +17,7 @@ type Props = {
value: ToolVarInput[]
onChange: (value: ToolVarInput[]) => void
isSupportConstantValue?: boolean
filterVar?: (payload: Var, valueSelector: ValueSelector) => boolean
}

const InputVarList: FC<Props> = ({
Expand All @@ -26,6 +27,7 @@ const InputVarList: FC<Props> = ({
value,
onChange,
isSupportConstantValue,
filterVar,
}) => {
const language = useLanguage()

Expand Down Expand Up @@ -92,6 +94,7 @@ const InputVarList: FC<Props> = ({
onChange={handleChange(variable)}
isSupportConstantValue={isSupportConstantValue}
defaultVarKindType={varInput?.variable_type}
filterVar={filterVar}
/>
{tooltip && <div className='leading-[18px] text-xs font-normal text-gray-600'>{tooltip[language] || tooltip.en_US}</div>}
</div>
Expand Down
2 changes: 2 additions & 0 deletions web/app/components/workflow/nodes/tool/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
inputs,
toolInputVarSchema,
setInputVar,
filterVar,
toolSettingSchema,
toolSettingValue,
setToolSettingValue,
Expand Down Expand Up @@ -80,6 +81,7 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
schema={toolInputVarSchema as any}
value={inputs.tool_parameters}
onChange={setInputVar}
filterVar={filterVar}
isSupportConstantValue
/>
</Field>
Expand Down
22 changes: 15 additions & 7 deletions web/app/components/workflow/nodes/tool/use-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import { fetchBuiltInToolList, fetchCollectionList, fetchCustomToolList, updateB
import { addDefaultValue, toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema'
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 { InputVarType, VarType as VarVarType } from '@/app/components/workflow/types'
import type { InputVar, Var } 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 { t } = useTranslation()
const language = useLanguage()
Expand All @@ -27,7 +26,7 @@ const useConfig = (id: string, payload: ToolNodeType) => {
* tool_configurations: tool setting, not dynamic setting
* tool_parameters: tool dynamic setting(by user)
*/
const { provider_id, provider_name, provider_type, tool_name, tool_configurations, tool_parameters: toolInputs } = inputs
const { provider_id, provider_name, provider_type, tool_name, tool_configurations } = inputs
const isBuiltIn = provider_type === CollectionType.builtIn
const [currCollection, setCurrCollection] = useState<Collection | null | undefined>(null)
const fetchCurrCollection = useCallback(async () => {
Expand All @@ -43,6 +42,7 @@ const useConfig = (id: string, payload: ToolNodeType) => {
return

fetchCurrCollection()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [provider_id])

// Auth
Expand All @@ -63,7 +63,7 @@ const useConfig = (id: string, payload: ToolNodeType) => {
})
await fetchCurrCollection()
hideSetAuthModal()
}, [currCollection])
}, [currCollection?.name, fetchCurrCollection, hideSetAuthModal, t])

const [currTool, setCurrTool] = useState<Tool | null>(null)
const formSchemas = currTool ? toolParametersToFormSchemas(currTool.parameters) : []
Expand Down Expand Up @@ -94,6 +94,7 @@ const useConfig = (id: string, payload: ToolNodeType) => {
})
})
setInputs(inputsWithDefaultValue)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currTool])

// setting when call
Expand All @@ -104,6 +105,11 @@ const useConfig = (id: string, payload: ToolNodeType) => {
})
}, [inputs, setInputs])

// TODO: dynamic setting as the current var type
const filterVar = useCallback((varPayload: Var) => {
return varPayload.type !== VarVarType.arrayFile
}, [])

const isLoading = currTool && (isBuiltIn ? !currCollection : false)

useEffect(() => {
Expand All @@ -123,6 +129,7 @@ const useConfig = (id: string, payload: ToolNodeType) => {
if (currTool)
setCurrTool(currTool)
})()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [provider_name])

// single run
Expand All @@ -149,13 +156,13 @@ const useConfig = (id: string, payload: ToolNodeType) => {
const singleRunForms = (() => {
const formInputs: InputVar[] = []
toolInputVarSchema.forEach((item: any) => {
const targetItem = toolInputs.find(input => input.variable === item.variable)
// 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,
type: InputVarType.textInput, // TODO: to form input
required: item.required,
})
// }
Expand All @@ -176,6 +183,7 @@ const useConfig = (id: string, payload: ToolNodeType) => {
setToolSettingValue,
toolInputVarSchema,
setInputVar,
filterVar,
currCollection,
isShowAuthBtn,
showSetAuth,
Expand Down

0 comments on commit 5ee7fc4

Please sign in to comment.