mirror of https://github.com/langgenius/dify.git
feat: output var
This commit is contained in:
parent
ae42edb8d7
commit
0d2a74b8cb
|
|
@ -127,6 +127,7 @@ export const AgentStrategySelector = (props: AgentStrategySelectorProps) => {
|
|||
agent_strategy_provider_name: tool!.provider_name,
|
||||
agent_parameters: tool!.params,
|
||||
agent_strategy_label: tool!.tool_label,
|
||||
agent_output_schema: tool!.output_schema,
|
||||
})
|
||||
setOpen(false)
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ export type Strategy = {
|
|||
agent_strategy_name: string
|
||||
agent_strategy_label: string
|
||||
agent_parameters?: ToolVarInputs
|
||||
agent_output_schema: Record<string, any>
|
||||
}
|
||||
|
||||
export type AgentStrategyProps = {
|
||||
|
|
@ -37,44 +38,6 @@ type MultipleToolSelectorSchema = CustomSchema<'array[tools]'>
|
|||
type CustomField = ToolSelectorSchema | MultipleToolSelectorSchema
|
||||
|
||||
const devMockForm = [{
|
||||
name: 'model',
|
||||
label: {
|
||||
en_US: 'Model',
|
||||
zh_Hans: '模型',
|
||||
pt_BR: 'Model',
|
||||
ja_JP: 'Model',
|
||||
},
|
||||
placeholder: null,
|
||||
scope: 'tool-call&llm',
|
||||
auto_generate: null,
|
||||
template: null,
|
||||
required: true,
|
||||
default: null,
|
||||
min: null,
|
||||
max: null,
|
||||
options: [],
|
||||
type: 'model-selector',
|
||||
},
|
||||
{
|
||||
name: 'tools',
|
||||
label: {
|
||||
en_US: 'Tools list',
|
||||
zh_Hans: '工具列表',
|
||||
pt_BR: 'Tools list',
|
||||
ja_JP: 'Tools list',
|
||||
},
|
||||
placeholder: null,
|
||||
scope: null,
|
||||
auto_generate: null,
|
||||
template: null,
|
||||
required: true,
|
||||
default: null,
|
||||
min: null,
|
||||
max: null,
|
||||
options: [],
|
||||
type: 'array[tools]',
|
||||
},
|
||||
{
|
||||
name: 'instruction',
|
||||
label: {
|
||||
en_US: 'Instruction',
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import type { ReactNode } from 'react'
|
||||
import Collapse from '.'
|
||||
|
||||
type FieldCollapseProps = {
|
||||
title: string
|
||||
children: JSX.Element
|
||||
children: ReactNode
|
||||
}
|
||||
const FieldCollapse = ({
|
||||
title,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
'use client'
|
||||
import type { FC } from 'react'
|
||||
import type { FC, ReactNode } from 'react'
|
||||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { FieldCollapse } from '@/app/components/workflow/nodes/_base/components/collapse'
|
||||
|
|
@ -7,7 +7,7 @@ import { FieldCollapse } from '@/app/components/workflow/nodes/_base/components/
|
|||
type Props = {
|
||||
className?: string
|
||||
title?: string
|
||||
children: JSX.Element
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
const OutputVars: FC<Props> = ({
|
||||
|
|
|
|||
|
|
@ -318,17 +318,23 @@ const formatItem = (
|
|||
|
||||
case BlockEnum.Agent: {
|
||||
const payload = data as AgentNodeType
|
||||
if (!payload.agent_parameters) {
|
||||
res.vars = []
|
||||
break
|
||||
}
|
||||
res.vars = Object.keys(payload.agent_parameters).map((key) => {
|
||||
return {
|
||||
variable: key,
|
||||
// TODO: is this correct?
|
||||
type: payload.agent_parameters![key].type as unknown as VarType,
|
||||
}
|
||||
const outputs: Var[] = []
|
||||
Object.keys(payload.output_schema.properties).forEach((outputKey) => {
|
||||
const output = payload.output_schema.properties[outputKey]
|
||||
outputs.push({
|
||||
variable: outputKey,
|
||||
type: output.type === 'array'
|
||||
? `Array[${output.items?.type.slice(0, 1).toLocaleUpperCase()}${output.items?.type.slice(1)}]` as VarType
|
||||
: `${output.type.slice(0, 1).toLocaleUpperCase()}${output.type.slice(1)}` as VarType,
|
||||
// TODO: is this required?
|
||||
// @ts-expect-error todo added
|
||||
description: output.description,
|
||||
})
|
||||
})
|
||||
res.vars = [
|
||||
...outputs,
|
||||
...TOOL_OUTPUT_STRUCT,
|
||||
]
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,14 @@ import Field from '../_base/components/field'
|
|||
import { AgentStrategy } from '../_base/components/agent-strategy'
|
||||
import useConfig from './use-config'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import OutputVars, { VarItem } from '../_base/components/output-vars'
|
||||
|
||||
const i18nPrefix = 'workflow.nodes.agent'
|
||||
|
||||
const AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
|
||||
const { inputs, setInputs, currentStrategy } = useConfig(props.id, props.data)
|
||||
const { t } = useTranslation()
|
||||
return <div className='space-y-2 my-2'>
|
||||
return <div className='my-2'>
|
||||
<Field title={t('workflow.nodes.agent.strategy.label')} className='px-4' >
|
||||
<AgentStrategy
|
||||
strategy={inputs.agent_strategy_name ? {
|
||||
|
|
@ -17,6 +20,7 @@ const AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
|
|||
agent_strategy_name: inputs.agent_strategy_name!,
|
||||
agent_parameters: inputs.agent_parameters,
|
||||
agent_strategy_label: inputs.agent_strategy_label!,
|
||||
agent_output_schema: inputs.output_schema,
|
||||
} : undefined}
|
||||
onStrategyChange={(strategy) => {
|
||||
setInputs({
|
||||
|
|
@ -25,6 +29,7 @@ const AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
|
|||
agent_strategy_name: strategy?.agent_strategy_name,
|
||||
agent_parameters: strategy?.agent_parameters,
|
||||
agent_strategy_label: strategy?.agent_strategy_label,
|
||||
output_schema: strategy!.agent_output_schema,
|
||||
})
|
||||
}}
|
||||
formSchema={currentStrategy?.parameters as any || []}
|
||||
|
|
@ -35,6 +40,33 @@ const AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
|
|||
})}
|
||||
/>
|
||||
</Field>
|
||||
<div>
|
||||
<OutputVars>
|
||||
<VarItem
|
||||
name='text'
|
||||
type='String'
|
||||
description={t(`${i18nPrefix}.outputVars.text`)}
|
||||
/>
|
||||
<VarItem
|
||||
name='files'
|
||||
type='Array[File]'
|
||||
description={t(`${i18nPrefix}.outputVars.files.title`)}
|
||||
/>
|
||||
<VarItem
|
||||
name='json'
|
||||
type='Array[Object]'
|
||||
description={t(`${i18nPrefix}.outputVars.json`)}
|
||||
/>
|
||||
{inputs.output_schema && Object.entries(inputs.output_schema).map(([name, schema]) => (
|
||||
<VarItem
|
||||
key={name}
|
||||
name={name}
|
||||
type={schema.type}
|
||||
description={schema.description}
|
||||
/>
|
||||
))}
|
||||
</OutputVars>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,4 +7,5 @@ export type AgentNodeType = CommonNodeType & {
|
|||
agent_strategy_label?: string
|
||||
agent_parameters?: ToolVarInputs,
|
||||
agent_configurations?: Record<string, ToolVarInputs>
|
||||
output_schema: Record<string, any>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -728,6 +728,17 @@ const translation = {
|
|||
modelSelectorTooltips: {
|
||||
deprecated: 'This model is deprecated',
|
||||
},
|
||||
outputVars: {
|
||||
text: 'agent generated content',
|
||||
files: {
|
||||
title: 'agent generated files',
|
||||
type: 'Support type. Now only support image',
|
||||
transfer_method: 'Transfer method.Value is remote_url or local_file',
|
||||
url: 'Image url',
|
||||
upload_file_id: 'Upload file id',
|
||||
},
|
||||
json: 'agent generated json',
|
||||
},
|
||||
},
|
||||
},
|
||||
tracing: {
|
||||
|
|
|
|||
|
|
@ -728,6 +728,17 @@ const translation = {
|
|||
modelSelectorTooltips: {
|
||||
deprecated: '此模型已弃用',
|
||||
},
|
||||
outputVars: {
|
||||
text: 'agent 生成的内容',
|
||||
files: {
|
||||
title: 'agent 生成的文件',
|
||||
type: '支持类型。现在只支持图片',
|
||||
transfer_method: '传输方式。值为 remote_url 或 local_file',
|
||||
url: '图片链接',
|
||||
upload_file_id: '上传文件ID',
|
||||
},
|
||||
json: 'agent 生成的json',
|
||||
},
|
||||
},
|
||||
},
|
||||
tracing: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue