feat: Add Citations and Attributions to Agent Node

pull/18558/head
oneness0 1 year ago committed by chiehw
parent 59dc7c880e
commit 0f2d06f181

@ -19,6 +19,7 @@ export enum FormTypeEnum {
toolSelector = 'tool-selector', toolSelector = 'tool-selector',
multiToolSelector = 'array[tools]', multiToolSelector = 'array[tools]',
appSelector = 'app-selector', appSelector = 'app-selector',
varSelector = 'var-selector',
} }
export type FormOption = { export type FormOption = {

@ -21,6 +21,7 @@ import ModelParameterModal from '@/app/components/plugins/plugin-detail-panel/mo
import ToolSelector from '@/app/components/plugins/plugin-detail-panel/tool-selector' import ToolSelector from '@/app/components/plugins/plugin-detail-panel/tool-selector'
import MultipleToolSelector from '@/app/components/plugins/plugin-detail-panel/multiple-tool-selector' import MultipleToolSelector from '@/app/components/plugins/plugin-detail-panel/multiple-tool-selector'
import AppSelector from '@/app/components/plugins/plugin-detail-panel/app-selector' import AppSelector from '@/app/components/plugins/plugin-detail-panel/app-selector'
import VarReferencePicker from '@/app/components/workflow/nodes/_base/components/variable/var-reference-picker'
import RadioE from '@/app/components/base/radio/ui' import RadioE from '@/app/components/base/radio/ui'
import type { import type {
NodeOutPutVar, NodeOutPutVar,
@ -409,6 +410,38 @@ function Form<
) )
} }
if (formSchema.type === FormTypeEnum.varSelector) {
const {
variable, label, required, scope,
} = formSchema as (CredentialFormSchemaTextInput | CredentialFormSchemaSecretInput)
return (
<div key={variable} className={cn(itemClassName, 'py-3')}>
<div className={cn(fieldLabelClassName, 'system-sm-semibold flex items-center py-2 text-text-secondary')}>
{label[language] || label.en_US}
{required && (
<span className='ml-1 text-red-500'>*</span>
)}
{tooltipContent}
</div>
<VarReferencePicker
zIndex={1001}
readonly={false}
isShowNodeName
nodeId={nodeId || ''}
value={value[variable] || []}
onChange={item => handleFormChange(variable, item as any)}
filterVar={(varPayload) => {
if (!scope) return true
return scope.split('&').includes(varPayload.type)
}}
/>
{fieldMoreInfo?.(formSchema)}
{validating && changeKey === variable && <ValidatingTip />}
</div>
)
}
// @ts-expect-error it work // @ts-expect-error it work
if (!Object.values(FormTypeEnum).includes(formSchema.type)) if (!Object.values(FormTypeEnum).includes(formSchema.type))
return customRenderField?.(formSchema as CustomFormSchema, filteredProps) return customRenderField?.(formSchema as CustomFormSchema, filteredProps)

@ -14,6 +14,7 @@ import type { Memory, Var } from '../../types'
import { VarType as VarKindType } from '../../types' import { VarType as VarKindType } from '../../types'
import useAvailableVarList from '../_base/hooks/use-available-var-list' import useAvailableVarList from '../_base/hooks/use-available-var-list'
import produce from 'immer' import produce from 'immer'
import { FormTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
export type StrategyStatus = { export type StrategyStatus = {
plugin: { plugin: {
@ -92,11 +93,20 @@ const useConfig = (id: string, payload: AgentNodeType) => {
}), }),
) )
}, [inputs.agent_parameters, currentStrategy?.parameters]) }, [inputs.agent_parameters, currentStrategy?.parameters])
const getParamVarType = useCallback((paramName: string) => {
const isVariable = currentStrategy?.parameters.some(
param => param.name === paramName && param.type === FormTypeEnum.varSelector,
)
if (isVariable) return VarType.variable
return VarType.constant
}, [currentStrategy?.parameters])
const onFormChange = (value: Record<string, any>) => { const onFormChange = (value: Record<string, any>) => {
const res: ToolVarInputs = {} const res: ToolVarInputs = {}
Object.entries(value).forEach(([key, val]) => { Object.entries(value).forEach(([key, val]) => {
res[key] = { res[key] = {
type: VarType.constant, type: getParamVarType(key),
value: val, value: val,
} }
}) })

Loading…
Cancel
Save