feat: output var

pull/12372/head
AkaraChen 1 year ago
parent ae42edb8d7
commit 0d2a74b8cb

@ -127,6 +127,7 @@ export const AgentStrategySelector = (props: AgentStrategySelectorProps) => {
agent_strategy_provider_name: tool!.provider_name, agent_strategy_provider_name: tool!.provider_name,
agent_parameters: tool!.params, agent_parameters: tool!.params,
agent_strategy_label: tool!.tool_label, agent_strategy_label: tool!.tool_label,
agent_output_schema: tool!.output_schema,
}) })
setOpen(false) setOpen(false)
}} }}

@ -19,6 +19,7 @@ export type Strategy = {
agent_strategy_name: string agent_strategy_name: string
agent_strategy_label: string agent_strategy_label: string
agent_parameters?: ToolVarInputs agent_parameters?: ToolVarInputs
agent_output_schema: Record<string, any>
} }
export type AgentStrategyProps = { export type AgentStrategyProps = {
@ -37,44 +38,6 @@ type MultipleToolSelectorSchema = CustomSchema<'array[tools]'>
type CustomField = ToolSelectorSchema | MultipleToolSelectorSchema type CustomField = ToolSelectorSchema | MultipleToolSelectorSchema
const devMockForm = [{ 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', name: 'instruction',
label: { label: {
en_US: 'Instruction', en_US: 'Instruction',

@ -1,8 +1,9 @@
import type { ReactNode } from 'react'
import Collapse from '.' import Collapse from '.'
type FieldCollapseProps = { type FieldCollapseProps = {
title: string title: string
children: JSX.Element children: ReactNode
} }
const FieldCollapse = ({ const FieldCollapse = ({
title, title,

@ -1,5 +1,5 @@
'use client' 'use client'
import type { FC } from 'react' import type { FC, ReactNode } from 'react'
import React from 'react' import React from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { FieldCollapse } from '@/app/components/workflow/nodes/_base/components/collapse' 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 = { type Props = {
className?: string className?: string
title?: string title?: string
children: JSX.Element children: ReactNode
} }
const OutputVars: FC<Props> = ({ const OutputVars: FC<Props> = ({

@ -318,17 +318,23 @@ const formatItem = (
case BlockEnum.Agent: { case BlockEnum.Agent: {
const payload = data as AgentNodeType const payload = data as AgentNodeType
if (!payload.agent_parameters) { const outputs: Var[] = []
res.vars = [] Object.keys(payload.output_schema.properties).forEach((outputKey) => {
break const output = payload.output_schema.properties[outputKey]
} outputs.push({
res.vars = Object.keys(payload.agent_parameters).map((key) => { variable: outputKey,
return { type: output.type === 'array'
variable: key, ? `Array[${output.items?.type.slice(0, 1).toLocaleUpperCase()}${output.items?.type.slice(1)}]` as VarType
// TODO: is this correct? : `${output.type.slice(0, 1).toLocaleUpperCase()}${output.type.slice(1)}` as VarType,
type: payload.agent_parameters![key].type as unknown as VarType, // TODO: is this required?
} // @ts-expect-error todo added
description: output.description,
})
}) })
res.vars = [
...outputs,
...TOOL_OUTPUT_STRUCT,
]
break break
} }

@ -5,11 +5,14 @@ import Field from '../_base/components/field'
import { AgentStrategy } from '../_base/components/agent-strategy' import { AgentStrategy } from '../_base/components/agent-strategy'
import useConfig from './use-config' import useConfig from './use-config'
import { useTranslation } from 'react-i18next' 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 AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
const { inputs, setInputs, currentStrategy } = useConfig(props.id, props.data) const { inputs, setInputs, currentStrategy } = useConfig(props.id, props.data)
const { t } = useTranslation() 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' > <Field title={t('workflow.nodes.agent.strategy.label')} className='px-4' >
<AgentStrategy <AgentStrategy
strategy={inputs.agent_strategy_name ? { strategy={inputs.agent_strategy_name ? {
@ -17,6 +20,7 @@ const AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
agent_strategy_name: inputs.agent_strategy_name!, agent_strategy_name: inputs.agent_strategy_name!,
agent_parameters: inputs.agent_parameters, agent_parameters: inputs.agent_parameters,
agent_strategy_label: inputs.agent_strategy_label!, agent_strategy_label: inputs.agent_strategy_label!,
agent_output_schema: inputs.output_schema,
} : undefined} } : undefined}
onStrategyChange={(strategy) => { onStrategyChange={(strategy) => {
setInputs({ setInputs({
@ -25,6 +29,7 @@ const AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
agent_strategy_name: strategy?.agent_strategy_name, agent_strategy_name: strategy?.agent_strategy_name,
agent_parameters: strategy?.agent_parameters, agent_parameters: strategy?.agent_parameters,
agent_strategy_label: strategy?.agent_strategy_label, agent_strategy_label: strategy?.agent_strategy_label,
output_schema: strategy!.agent_output_schema,
}) })
}} }}
formSchema={currentStrategy?.parameters as any || []} formSchema={currentStrategy?.parameters as any || []}
@ -35,6 +40,33 @@ const AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
})} })}
/> />
</Field> </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> </div>
} }

@ -7,4 +7,5 @@ export type AgentNodeType = CommonNodeType & {
agent_strategy_label?: string agent_strategy_label?: string
agent_parameters?: ToolVarInputs, agent_parameters?: ToolVarInputs,
agent_configurations?: Record<string, ToolVarInputs> agent_configurations?: Record<string, ToolVarInputs>
output_schema: Record<string, any>
} }

@ -728,6 +728,17 @@ const translation = {
modelSelectorTooltips: { modelSelectorTooltips: {
deprecated: 'This model is deprecated', 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: { tracing: {

@ -728,6 +728,17 @@ const translation = {
modelSelectorTooltips: { modelSelectorTooltips: {
deprecated: '此模型已弃用', deprecated: '此模型已弃用',
}, },
outputVars: {
text: 'agent 生成的内容',
files: {
title: 'agent 生成的文件',
type: '支持类型。现在只支持图片',
transfer_method: '传输方式。值为 remote_url 或 local_file',
url: '图片链接',
upload_file_id: '上传文件ID',
},
json: 'agent 生成的json',
},
}, },
}, },
tracing: { tracing: {

Loading…
Cancel
Save