feat: doc extract single run

This commit is contained in:
Joel 2025-05-06 10:34:05 +08:00
parent 7242d7bf83
commit a00e45b257
4 changed files with 56 additions and 82 deletions

View File

@ -11,6 +11,7 @@ import useTemplateTransformSingleRunFormParams from '../../../../template-transf
import useQuestionClassifierSingleRunFormParams from '../../../../question-classifier/use-single-run-form-params' import useQuestionClassifierSingleRunFormParams from '../../../../question-classifier/use-single-run-form-params'
import useHttpRequestSingleRunFormParams from '../../../../http/use-single-run-form-params' import useHttpRequestSingleRunFormParams from '../../../../http/use-single-run-form-params'
import useIterationSingleRunFormParams from '../../../../iteration/use-single-run-form-params' import useIterationSingleRunFormParams from '../../../../iteration/use-single-run-form-params'
import useDocExtractorSingleRunFormParams from '../../../../document-extractor/use-single-run-form-params'
import { BlockEnum } from '@/app/components/workflow/types' import { BlockEnum } from '@/app/components/workflow/types'
import { import {
useNodesSyncDraft, useNodesSyncDraft,
@ -27,7 +28,7 @@ const singleRunFormParamsHooks: Record<BlockEnum, any> = {
[BlockEnum.ParameterExtractor]: undefined, [BlockEnum.ParameterExtractor]: undefined,
[BlockEnum.Iteration]: useIterationSingleRunFormParams, [BlockEnum.Iteration]: useIterationSingleRunFormParams,
[BlockEnum.Agent]: undefined, [BlockEnum.Agent]: undefined,
[BlockEnum.DocExtractor]: undefined, [BlockEnum.DocExtractor]: useDocExtractorSingleRunFormParams,
[BlockEnum.Loop]: undefined, [BlockEnum.Loop]: undefined,
[BlockEnum.Start]: undefined, [BlockEnum.Start]: undefined,
[BlockEnum.End]: undefined, [BlockEnum.End]: undefined,

View File

@ -11,11 +11,9 @@ import useConfig from './use-config'
import type { DocExtractorNodeType } from './types' import type { DocExtractorNodeType } from './types'
import { fetchSupportFileTypes } from '@/service/datasets' import { fetchSupportFileTypes } from '@/service/datasets'
import Field from '@/app/components/workflow/nodes/_base/components/field' import Field from '@/app/components/workflow/nodes/_base/components/field'
import { BlockEnum, InputVarType, type NodePanelProps } from '@/app/components/workflow/types' import { BlockEnum, type NodePanelProps } from '@/app/components/workflow/types'
import I18n from '@/context/i18n' import I18n from '@/context/i18n'
import { LanguagesSupported } from '@/i18n/language' import { LanguagesSupported } from '@/i18n/language'
import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/before-run-form'
import ResultPanel from '@/app/components/workflow/run/result-panel'
const i18nPrefix = 'workflow.nodes.docExtractor' const i18nPrefix = 'workflow.nodes.docExtractor'
@ -48,15 +46,6 @@ const Panel: FC<NodePanelProps<DocExtractorNodeType>> = ({
inputs, inputs,
handleVarChanges, handleVarChanges,
filterVar, filterVar,
// single run
isShowSingleRun,
hideSingleRun,
runningStatus,
handleRun,
handleStop,
runResult,
files,
setFiles,
} = useConfig(id, data) } = useConfig(id, data)
return ( return (
@ -92,30 +81,6 @@ const Panel: FC<NodePanelProps<DocExtractorNodeType>> = ({
/> />
</OutputVars> </OutputVars>
</div> </div>
{
isShowSingleRun && (
<BeforeRunForm
nodeName={inputs.title}
onHide={hideSingleRun}
forms={[
{
inputs: [{
label: t(`${i18nPrefix}.inputVar`)!,
variable: 'files',
type: InputVarType.multiFiles,
required: true,
}],
values: { files },
onChange: keyValue => setFiles(keyValue.files),
},
]}
runningStatus={runningStatus}
onRun={handleRun}
onStop={handleStop}
result={<ResultPanel {...runResult} showSteps={false} />}
/>
)
}
</div> </div>
) )
} }

View File

@ -1,12 +1,10 @@
import { useCallback, useMemo } from 'react' import { useCallback, useMemo } from 'react'
import produce from 'immer' import produce from 'immer'
import { useStoreApi } from 'reactflow' import { useStoreApi } from 'reactflow'
import type { ValueSelector, Var } from '../../types' import type { ValueSelector, Var } from '../../types'
import { InputVarType, VarType } from '../../types' import { VarType } from '../../types'
import type { DocExtractorNodeType } from './types' import type { DocExtractorNodeType } from './types'
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 useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run'
import { import {
useIsChatMode, useIsChatMode,
useNodesReadOnly, useNodesReadOnly,
@ -58,53 +56,11 @@ const useConfig = (id: string, payload: DocExtractorNodeType) => {
setInputs(newInputs) setInputs(newInputs)
}, [getType, inputs, setInputs]) }, [getType, inputs, setInputs])
// single run
const {
isShowSingleRun,
hideSingleRun,
runningStatus,
isCompleted,
handleRun,
handleStop,
runInputData,
setRunInputData,
runResult,
} = useOneStepRun<DocExtractorNodeType>({
id,
data: inputs,
defaultRunInputData: { files: [] },
})
const varInputs = [{
label: inputs.title,
variable: 'files',
type: InputVarType.multiFiles,
required: true,
}]
const files = runInputData.files
const setFiles = useCallback((newFiles: []) => {
setRunInputData({
...runInputData,
files: newFiles,
})
}, [runInputData, setRunInputData])
return { return {
readOnly, readOnly,
inputs, inputs,
filterVar, filterVar,
handleVarChanges, handleVarChanges,
// single run
isShowSingleRun,
hideSingleRun,
runningStatus,
isCompleted,
handleRun,
handleStop,
varInputs,
files,
setFiles,
runResult,
} }
} }

View File

@ -0,0 +1,52 @@
import type { MutableRefObject } from 'react'
import type { InputVar, Variable } from '@/app/components/workflow/types'
import { useCallback, useMemo } from 'react'
import type { DocExtractorNodeType } from './types'
import { useTranslation } from 'react-i18next'
import { InputVarType } from '@/app/components/workflow/types'
const i18nPrefix = 'workflow.nodes.docExtractor'
type Params = {
id: string,
payload: DocExtractorNodeType,
runInputData: Record<string, any>
runInputDataRef: MutableRefObject<Record<string, any>>
getInputVars: (textList: string[]) => InputVar[]
setRunInputData: (data: Record<string, any>) => void
toVarInputs: (variables: Variable[]) => InputVar[]
}
const useSingleRunFormParams = ({
runInputData,
setRunInputData,
}: Params) => {
const { t } = useTranslation()
const files = runInputData.files
const setFiles = useCallback((newFiles: []) => {
setRunInputData({
...runInputData,
files: newFiles,
})
}, [runInputData, setRunInputData])
const forms = useMemo(() => {
return [
{
inputs: [{
label: t(`${i18nPrefix}.inputVar`)!,
variable: 'files',
type: InputVarType.multiFiles,
required: true,
}],
values: { files },
onChange: (keyValue: Record<string, any>) => setFiles(keyValue.files),
},
]
}, [files, setFiles, t])
return {
forms,
}
}
export default useSingleRunFormParams