Commit b3b9e1da authored by Joel's avatar Joel

feat: tools support run

parent c0ccffa1
...@@ -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
......
...@@ -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>
) )
} }
......
...@@ -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,
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment