mirror of https://github.com/langgenius/dify.git
chore: code support debug
This commit is contained in:
parent
072f5caa06
commit
89fc90ac80
|
|
@ -32,8 +32,8 @@ const allMockData = {
|
|||
[BlockEnum.End]: EndNodeMock,
|
||||
}
|
||||
const nodes = [
|
||||
BlockEnum.KnowledgeRetrieval/* 4 */, BlockEnum.Start/* 1 */, BlockEnum.DirectAnswer/* 2 */, BlockEnum.LLM/* 3 */, BlockEnum.QuestionClassifier/* 5 */,
|
||||
BlockEnum.IfElse/* 6 */, BlockEnum.Code/* 7 */, BlockEnum.TemplateTransform/* 8 */, BlockEnum.HttpRequest/* 9 */, BlockEnum.Tool/* 10 */,
|
||||
BlockEnum.Code/* 7 */, BlockEnum.KnowledgeRetrieval/* 4 */, BlockEnum.Start/* 1 */, BlockEnum.DirectAnswer/* 2 */, BlockEnum.LLM/* 3 */, BlockEnum.QuestionClassifier/* 5 */,
|
||||
BlockEnum.IfElse/* 6 */, BlockEnum.TemplateTransform/* 8 */, BlockEnum.HttpRequest/* 9 */, BlockEnum.Tool/* 10 */,
|
||||
BlockEnum.VariableAssigner/* 11 */, BlockEnum.End/* 12 */,
|
||||
].map((item, i) => {
|
||||
const payload = allMockData[item]
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import Split from '@/app/components/workflow/nodes/_base/components/split'
|
|||
import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
|
||||
import TypeSelector from '@/app/components/workflow/nodes/_base/components/selector'
|
||||
import type { NodePanelProps } from '@/app/components/workflow/types'
|
||||
import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/before-run-form'
|
||||
|
||||
const i18nPrefix = 'workflow.nodes.code'
|
||||
|
||||
|
|
@ -40,6 +41,15 @@ const Panel: FC<NodePanelProps<CodeNodeType>> = ({
|
|||
handleCodeLanguageChange,
|
||||
handleOutputVarListChange,
|
||||
handleAddOutputVariable,
|
||||
// single run
|
||||
isShowSingleRun,
|
||||
hideSingleRun,
|
||||
runningStatus,
|
||||
handleRun,
|
||||
handleStop,
|
||||
varInputs,
|
||||
inputVarValues,
|
||||
setInputVarValues,
|
||||
} = useConfig(id, data)
|
||||
return (
|
||||
<div className='mt-2'>
|
||||
|
|
@ -86,6 +96,22 @@ const Panel: FC<NodePanelProps<CodeNodeType>> = ({
|
|||
/>
|
||||
</Field>
|
||||
</div>
|
||||
{isShowSingleRun && (
|
||||
<BeforeRunForm
|
||||
nodeName={inputs.title}
|
||||
onHide={hideSingleRun}
|
||||
forms={[
|
||||
{
|
||||
inputs: varInputs,
|
||||
values: inputVarValues,
|
||||
onChange: setInputVarValues,
|
||||
},
|
||||
]}
|
||||
runningStatus={runningStatus}
|
||||
onRun={handleRun}
|
||||
onStop={handleStop}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import useVarList from '../_base/hooks/use-var-list'
|
|||
import useOutputVarList from '../_base/hooks/use-output-var-list'
|
||||
import type { CodeLanguage, CodeNodeType } from './types'
|
||||
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'
|
||||
|
||||
const useConfig = (id: string, payload: CodeNodeType) => {
|
||||
const { inputs, setInputs } = useNodeCrud<CodeNodeType>(id, payload)
|
||||
|
|
@ -31,6 +32,39 @@ const useConfig = (id: string, payload: CodeNodeType) => {
|
|||
setInputs,
|
||||
})
|
||||
|
||||
// single run
|
||||
const {
|
||||
isShowSingleRun,
|
||||
hideSingleRun,
|
||||
toVarInputs,
|
||||
runningStatus,
|
||||
handleRun,
|
||||
handleStop,
|
||||
runInputData,
|
||||
setRunInputData,
|
||||
} = useOneStepRun<CodeNodeType>({
|
||||
id,
|
||||
data: inputs,
|
||||
defaultRunInputData: {
|
||||
name: 'Joel',
|
||||
age: '18',
|
||||
},
|
||||
})
|
||||
const varInputs = toVarInputs(inputs.variables)
|
||||
|
||||
const inputVarValues = (() => {
|
||||
const vars: Record<string, any> = {}
|
||||
Object.keys(runInputData)
|
||||
.forEach((key) => {
|
||||
vars[key] = runInputData[key]
|
||||
})
|
||||
return vars
|
||||
})()
|
||||
|
||||
const setInputVarValues = useCallback((newPayload: Record<string, any>) => {
|
||||
setRunInputData(newPayload)
|
||||
}, [runInputData, setRunInputData])
|
||||
|
||||
return {
|
||||
inputs,
|
||||
handleVarListChange,
|
||||
|
|
@ -39,6 +73,15 @@ const useConfig = (id: string, payload: CodeNodeType) => {
|
|||
handleCodeLanguageChange,
|
||||
handleOutputVarListChange,
|
||||
handleAddOutputVariable,
|
||||
// single run
|
||||
isShowSingleRun,
|
||||
hideSingleRun,
|
||||
runningStatus,
|
||||
handleRun,
|
||||
handleStop,
|
||||
varInputs,
|
||||
inputVarValues,
|
||||
setInputVarValues,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue