chore: types

This commit is contained in:
Joel 2024-04-02 11:49:53 +08:00
parent c5e58c713c
commit 56a1d5330a
3 changed files with 16 additions and 23 deletions

View File

@ -50,7 +50,7 @@ const VarReferencePicker: FC<Props> = ({
onOpen = () => { },
onChange,
isSupportConstantValue,
defaultVarKindType = VarKindType.static,
defaultVarKindType = VarKindType.constant,
onlyLeafNodeVar,
filterVar = () => true,
}) => {
@ -65,7 +65,7 @@ const VarReferencePicker: FC<Props> = ({
const isChatMode = useIsChatMode()
const [varKindType, setVarKindType] = useState<VarKindType>(defaultVarKindType)
const isConstant = isSupportConstantValue && varKindType === VarKindType.static
const isConstant = isSupportConstantValue && varKindType === VarKindType.constant
const { getTreeLeafNodes, getBeforeNodesInSameBranch } = useWorkflow()
const availableNodes = onlyLeafNodeVar ? getTreeLeafNodes(nodeId) : getBeforeNodesInSameBranch(nodeId)
const allOutputVars = toNodeOutputVars(availableNodes, isChatMode)
@ -124,17 +124,17 @@ const VarReferencePicker: FC<Props> = ({
const varKindTypes = [
{
label: 'Variable',
value: VarKindType.selector,
value: VarKindType.variable,
},
{
label: 'Constant',
value: VarKindType.static,
value: VarKindType.constant,
},
]
const handleVarKindTypeChange = useCallback((value: VarKindType) => {
setVarKindType(value)
if (value === VarKindType.static)
if (value === VarKindType.constant)
onChange('', value)
else
onChange([], value)
@ -170,7 +170,7 @@ const VarReferencePicker: FC<Props> = ({
}, [onChange, varKindType])
const handleClearVar = useCallback(() => {
if (varKindType === VarKindType.static)
if (varKindType === VarKindType.constant)
onChange('', varKindType)
else
onChange([], varKindType)

View File

@ -28,7 +28,6 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
inputs,
toolInputVarSchema,
setInputVar,
handleOnVarOpen,
filterVar,
toolSettingSchema,
toolSettingValue,
@ -84,7 +83,6 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
onChange={setInputVar}
filterVar={filterVar}
isSupportConstantValue
onOpen={handleOnVarOpen}
/>
</Field>
)}

View File

@ -12,7 +12,7 @@ import { addDefaultValue, toolParametersToFormSchemas } from '@/app/components/t
import Toast from '@/app/components/base/toast'
import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form'
import { VarType as VarVarType } from '@/app/components/workflow/types'
import type { InputVar, Var } from '@/app/components/workflow/types'
import type { InputVar, ValueSelector, Var } from '@/app/components/workflow/types'
import useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run'
import {
useFetchToolsData,
@ -94,18 +94,9 @@ const useConfig = (id: string, payload: ToolNodeType) => {
})
}, [inputs, setInputs])
const [currVarIndex, setCurrVarIndex] = useState(-1)
const currVarType = toolInputVarSchema[currVarIndex]?._type
const handleOnVarOpen = useCallback((index: number) => {
setCurrVarIndex(index)
}, [])
const filterVar = useCallback((varPayload: Var) => {
if (currVarType)
return varPayload.type === currVarType
return varPayload.type !== VarVarType.arrayFile
}, [currVarType])
return [VarVarType.string, VarVarType.number].includes(varPayload.type)
}, [])
const isLoading = currTool && (isBuiltIn ? !currCollection : false)
@ -148,10 +139,15 @@ const useConfig = (id: string, payload: ToolNodeType) => {
},
})
const hadVarParams = Object.keys(inputs.tool_parameters)
.filter(key => inputs.tool_parameters[key].type === VarType.mixed)
.filter(key => inputs.tool_parameters[key].type !== VarType.constant)
.map(k => inputs.tool_parameters[k])
const varInputs = getInputVars(hadVarParams.map(p => p.value as string))
const varInputs = getInputVars(hadVarParams.map((p) => {
if (p.type === VarType.variable)
return `#${[p.value as ValueSelector].join('.')}#`
return p.value as string
}))
const singleRunForms = (() => {
const formInputs: InputVar[] = []
@ -180,7 +176,6 @@ const useConfig = (id: string, payload: ToolNodeType) => {
setToolSettingValue,
toolInputVarSchema,
setInputVar,
handleOnVarOpen,
filterVar,
currCollection,
isShowAuthBtn,