mirror of
https://github.com/langgenius/dify.git
synced 2026-02-19 17:34:41 +08:00
feat: command node output variables
This commit is contained in:
parent
3902929d9f
commit
888be71639
@ -25,6 +25,7 @@ import {
|
||||
TemplatingTransform,
|
||||
VariableX,
|
||||
WebhookLine,
|
||||
WindowCursor,
|
||||
} from '@/app/components/base/icons/src/vender/workflow'
|
||||
import { cn } from '@/utils/classnames'
|
||||
import { BlockEnum } from './types'
|
||||
@ -45,7 +46,7 @@ const DEFAULT_ICON_MAP: Record<BlockEnum, React.ComponentType<{ className: strin
|
||||
[BlockEnum.Start]: Home,
|
||||
[BlockEnum.LLM]: Llm,
|
||||
[BlockEnum.Code]: Code,
|
||||
[BlockEnum.Command]: Code,
|
||||
[BlockEnum.Command]: WindowCursor,
|
||||
[BlockEnum.End]: End,
|
||||
[BlockEnum.IfElse]: IfElse,
|
||||
[BlockEnum.HttpRequest]: Http,
|
||||
|
||||
@ -116,6 +116,7 @@ export const SUPPORT_OUTPUT_VARS_NODE = [
|
||||
BlockEnum.KnowledgeRetrieval,
|
||||
BlockEnum.Code,
|
||||
BlockEnum.TemplateTransform,
|
||||
BlockEnum.Command,
|
||||
BlockEnum.HttpRequest,
|
||||
BlockEnum.Tool,
|
||||
BlockEnum.VariableAssigner,
|
||||
@ -166,6 +167,25 @@ export const TEMPLATE_TRANSFORM_OUTPUT_STRUCT: Var[] = [
|
||||
},
|
||||
]
|
||||
|
||||
export const COMMAND_OUTPUT_STRUCT: Var[] = [
|
||||
{
|
||||
variable: 'stdout',
|
||||
type: VarType.string,
|
||||
},
|
||||
{
|
||||
variable: 'stderr',
|
||||
type: VarType.string,
|
||||
},
|
||||
{
|
||||
variable: 'exit_code',
|
||||
type: VarType.number,
|
||||
},
|
||||
{
|
||||
variable: 'pid',
|
||||
type: VarType.string,
|
||||
},
|
||||
]
|
||||
|
||||
export const QUESTION_CLASSIFIER_OUTPUT_STRUCT = [
|
||||
{
|
||||
variable: 'class_name',
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import type { AgentNodeType } from '../../../agent/types'
|
||||
import type { AnswerNodeType } from '../../../answer/types'
|
||||
import type { CodeNodeType } from '../../../code/types'
|
||||
import type { CommandNodeType } from '../../../command/types'
|
||||
import type { DocExtractorNodeType } from '../../../document-extractor/types'
|
||||
import type { EndNodeType } from '../../../end/types'
|
||||
import type { HttpNodeType } from '../../../http/types'
|
||||
@ -38,6 +39,7 @@ import { isArray } from 'es-toolkit/compat'
|
||||
import { produce } from 'immer'
|
||||
import {
|
||||
AGENT_OUTPUT_STRUCT,
|
||||
COMMAND_OUTPUT_STRUCT,
|
||||
FILE_STRUCT,
|
||||
getGlobalVars,
|
||||
HTTP_REQUEST_OUTPUT_STRUCT,
|
||||
@ -435,6 +437,11 @@ const formatItem = (
|
||||
break
|
||||
}
|
||||
|
||||
case BlockEnum.Command: {
|
||||
res.vars = COMMAND_OUTPUT_STRUCT
|
||||
break
|
||||
}
|
||||
|
||||
case BlockEnum.QuestionClassifier: {
|
||||
res.vars = QUESTION_CLASSIFIER_OUTPUT_STRUCT
|
||||
break
|
||||
@ -1744,6 +1751,20 @@ export const updateNodeVars = (
|
||||
}
|
||||
break
|
||||
}
|
||||
case BlockEnum.Command: {
|
||||
const payload = data as CommandNodeType
|
||||
payload.command = replaceOldVarInText(
|
||||
payload.command,
|
||||
oldVarSelector,
|
||||
newVarSelector,
|
||||
)
|
||||
payload.working_directory = replaceOldVarInText(
|
||||
payload.working_directory,
|
||||
oldVarSelector,
|
||||
newVarSelector,
|
||||
)
|
||||
break
|
||||
}
|
||||
case BlockEnum.QuestionClassifier: {
|
||||
const payload = data as QuestionClassifierNodeType
|
||||
if (
|
||||
@ -2035,6 +2056,11 @@ export const getNodeOutputVars = (
|
||||
break
|
||||
}
|
||||
|
||||
case BlockEnum.Command: {
|
||||
varsToValueSelectorList(COMMAND_OUTPUT_STRUCT, [id], res)
|
||||
break
|
||||
}
|
||||
|
||||
case BlockEnum.QuestionClassifier: {
|
||||
varsToValueSelectorList(QUESTION_CLASSIFIER_OUTPUT_STRUCT, [id], res)
|
||||
break
|
||||
|
||||
@ -5,6 +5,7 @@ import * as React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import Field from '@/app/components/workflow/nodes/_base/components/field'
|
||||
import Input from '@/app/components/workflow/nodes/_base/components/input-support-select-var'
|
||||
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
|
||||
import Split from '@/app/components/workflow/nodes/_base/components/split'
|
||||
import useAvailableVarList from '@/app/components/workflow/nodes/_base/hooks/use-available-var-list'
|
||||
import useConfig from './use-config'
|
||||
@ -64,6 +65,33 @@ const Panel: FC<NodePanelProps<CommandNodeType>> = ({
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
<Split />
|
||||
<div>
|
||||
<OutputVars>
|
||||
<>
|
||||
<VarItem
|
||||
name="stdout"
|
||||
type="string"
|
||||
description={t(`${i18nPrefix}.outputVars.stdout`, { ns: 'workflow' })}
|
||||
/>
|
||||
<VarItem
|
||||
name="stderr"
|
||||
type="string"
|
||||
description={t(`${i18nPrefix}.outputVars.stderr`, { ns: 'workflow' })}
|
||||
/>
|
||||
<VarItem
|
||||
name="exit_code"
|
||||
type="number"
|
||||
description={t(`${i18nPrefix}.outputVars.exitCode`, { ns: 'workflow' })}
|
||||
/>
|
||||
<VarItem
|
||||
name="pid"
|
||||
type="number"
|
||||
description={t(`${i18nPrefix}.outputVars.pid`, { ns: 'workflow' })}
|
||||
/>
|
||||
</>
|
||||
</OutputVars>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@ -410,6 +410,10 @@
|
||||
"nodes.code.syncFunctionSignature": "Sync function signature to code",
|
||||
"nodes.command.command": "Command",
|
||||
"nodes.command.commandPlaceholder": "Enter the command to execute, e.g., ls -la",
|
||||
"nodes.command.outputVars.exitCode": "Exit code of the command",
|
||||
"nodes.command.outputVars.pid": "Process ID of the command",
|
||||
"nodes.command.outputVars.stderr": "Standard error from command execution",
|
||||
"nodes.command.outputVars.stdout": "Standard output from command execution",
|
||||
"nodes.command.seconds": "seconds",
|
||||
"nodes.command.timeout": "Timeout",
|
||||
"nodes.command.workingDirectory": "Working Directory",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user