mirror of https://github.com/langgenius/dify.git
feat: add single run api
This commit is contained in:
parent
547df0b5fe
commit
74bf6cd186
|
|
@ -9,6 +9,7 @@ import Button from '@/app/components/base/button'
|
|||
import { StopCircle } from '@/app/components/base/icons/src/vender/solid/mediaAndDevices'
|
||||
import { Loading02, XClose } from '@/app/components/base/icons/src/vender/line/general'
|
||||
import Split from '@/app/components/workflow/nodes/_base/components/split'
|
||||
import { NodeRunningStatus } from '@/app/components/workflow/types'
|
||||
|
||||
const i18nPrefix = 'workflow.singleRun'
|
||||
|
||||
|
|
@ -17,7 +18,7 @@ type BeforeRunFormProps = {
|
|||
onHide: () => void
|
||||
onRun: () => void
|
||||
onStop: () => void
|
||||
runningStatus: string // todo: wait for enum
|
||||
runningStatus: NodeRunningStatus
|
||||
result?: JSX.Element
|
||||
forms: FormProps[]
|
||||
}
|
||||
|
|
@ -32,8 +33,8 @@ const BeforeRunForm: FC<BeforeRunFormProps> = ({
|
|||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const isFinished = runningStatus === 'finished'
|
||||
const isRunning = runningStatus === 'running'
|
||||
const isFinished = runningStatus === NodeRunningStatus.Succeeded || runningStatus === NodeRunningStatus.Failed
|
||||
const isRunning = runningStatus === NodeRunningStatus.Running
|
||||
return (
|
||||
<div className='absolute inset-0 z-10 rounded-2xl pt-10' style={{
|
||||
backgroundColor: 'rgba(16, 24, 40, 0.20)',
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import { useState } from 'react'
|
||||
import { useWorkflow } from '@/app/components/workflow/hooks'
|
||||
import type { CommonNodeType, InputVar, Variable } from '@/app/components/workflow/types'
|
||||
import { InputVarType } from '@/app/components/workflow/types'
|
||||
import { InputVarType, NodeRunningStatus } from '@/app/components/workflow/types'
|
||||
import { useStore as useAppStore } from '@/app/components/app/store'
|
||||
import { singleNodeRun } from '@/service/workflow'
|
||||
|
||||
type Params<T> = {
|
||||
id: string
|
||||
|
|
@ -11,6 +13,9 @@ type Params<T> = {
|
|||
}
|
||||
|
||||
const useOneStepRun = <T>({ id, data, defaultRunInputData, isInvalid = () => true }: Params<T>) => {
|
||||
const appId = useAppStore.getState().appDetail?.id
|
||||
const [runInputData, setRunInputData] = useState<Record<string, any>>(defaultRunInputData || {})
|
||||
|
||||
const { handleNodeDataUpdate }: { handleNodeDataUpdate: (data: any) => void } = useWorkflow()
|
||||
const isShowSingleRun = data._isSingleRun
|
||||
const hideSingleRun = () => {
|
||||
|
|
@ -22,23 +27,32 @@ const useOneStepRun = <T>({ id, data, defaultRunInputData, isInvalid = () => tru
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
const [runningStatus, setRunningStatus] = useState('un started')
|
||||
const handleRun = () => {
|
||||
// console.log(runInputData)
|
||||
if (isInvalid())
|
||||
const runningStatus = data._singleRunningStatus || NodeRunningStatus.NotStart
|
||||
const handleRun = async () => {
|
||||
if (!isInvalid())
|
||||
return
|
||||
handleNodeDataUpdate({
|
||||
id,
|
||||
data: {
|
||||
...data,
|
||||
_singleRunningStatus: NodeRunningStatus.Running,
|
||||
},
|
||||
})
|
||||
|
||||
setRunningStatus('running')
|
||||
const res = await singleNodeRun(appId!, id, { inputs: runInputData })
|
||||
console.log(res)
|
||||
}
|
||||
|
||||
const handleStop = () => {
|
||||
setRunningStatus('not started')
|
||||
handleNodeDataUpdate({
|
||||
id,
|
||||
data: {
|
||||
...data,
|
||||
_singleRunningStatus: NodeRunningStatus.NotStart,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// TODO: store to node
|
||||
const [runInputData, setRunInputData] = useState<Record<string, any>>(defaultRunInputData || {})
|
||||
|
||||
const toVarInputs = (variables: Variable[]): InputVar[] => {
|
||||
if (!variables)
|
||||
return []
|
||||
|
|
@ -64,7 +78,6 @@ const useOneStepRun = <T>({ id, data, defaultRunInputData, isInvalid = () => tru
|
|||
runningStatus,
|
||||
handleRun,
|
||||
handleStop,
|
||||
setRunningStatus,
|
||||
runInputData,
|
||||
setRunInputData,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ const BaseNode: FC<BaseNodeProps> = ({
|
|||
{data.title}
|
||||
</div>
|
||||
{
|
||||
data._runningStatus === NodeRunningStatus.Running && (
|
||||
(data._runningStatus === NodeRunningStatus.Running || data._singleRunningStatus === NodeRunningStatus.Running) && (
|
||||
<Loading02 className='w-3.5 h-3.5 text-primary-600 animate-spin' />
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ const Panel: FC<NodePanelProps<CodeNodeType>> = ({
|
|||
onStop={handleStop}
|
||||
/>
|
||||
)}
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ const Panel: FC<NodePanelProps<DirectAnswerNodeType>> = ({
|
|||
</Field>
|
||||
<Split />
|
||||
<Editor
|
||||
title={t(`${i18nPrefix}.answer`)}
|
||||
title={t(`${i18nPrefix}.answer`)!}
|
||||
value={inputs.answer}
|
||||
onChange={handleAnswerChange}
|
||||
variables={inputs.variables.map(item => item.variable)}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ export type CommonNodeType<T = {}> = {
|
|||
_targetBranches?: Branch[]
|
||||
_isSingleRun?: boolean
|
||||
_runningStatus?: NodeRunningStatus
|
||||
_singleRunningStatus?: NodeRunningStatus
|
||||
selected?: boolean
|
||||
title: string
|
||||
desc: string
|
||||
|
|
@ -158,6 +159,7 @@ export enum WorkflowRunningStatus {
|
|||
}
|
||||
|
||||
export enum NodeRunningStatus {
|
||||
NotStart = 'not-start',
|
||||
Waiting = 'waiting',
|
||||
Running = 'running',
|
||||
Succeeded = 'succeeded',
|
||||
|
|
|
|||
|
|
@ -21,3 +21,7 @@ export const fetchNodesDefaultConfigs: Fetcher<any, string> = (url) => {
|
|||
export const fetchWorkflowRunHistory: Fetcher<WorkflowRunHistoryResponse, string> = (url) => {
|
||||
return get<WorkflowRunHistoryResponse>(url)
|
||||
}
|
||||
|
||||
export const singleNodeRun = (appId: string, nodeId: string, params: object) => {
|
||||
return post(`apps/${appId}/workflows/draft/nodes/${nodeId}/run`, { body: params })
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue