mirror of
https://github.com/langgenius/dify.git
synced 2026-03-02 06:16:39 +08:00
Co-authored-by: AkaraChen <akarachen@outlook.com> Co-authored-by: Yi <yxiaoisme@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: JzoNg <jzongcode@gmail.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: kurokobo <kuro664@gmail.com> Co-authored-by: Hiroshi Fujita <fujita-h@users.noreply.github.com>
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import type { StrategyDetail, StrategyPluginDetail } from '@/app/components/plugins/types'
|
|
import { ALL_CHAT_AVAILABLE_BLOCKS, ALL_COMPLETION_AVAILABLE_BLOCKS } from '../../constants'
|
|
import type { NodeDefault } from '../../types'
|
|
import type { AgentNodeType } from './types'
|
|
import { renderI18nObject } from '@/hooks/use-i18n'
|
|
|
|
const nodeDefault: NodeDefault<AgentNodeType> = {
|
|
defaultValue: {
|
|
},
|
|
getAvailablePrevNodes(isChatMode) {
|
|
return isChatMode
|
|
? ALL_CHAT_AVAILABLE_BLOCKS
|
|
: ALL_COMPLETION_AVAILABLE_BLOCKS
|
|
},
|
|
getAvailableNextNodes(isChatMode) {
|
|
return isChatMode
|
|
? ALL_CHAT_AVAILABLE_BLOCKS
|
|
: ALL_COMPLETION_AVAILABLE_BLOCKS
|
|
},
|
|
checkValid(payload, t, moreDataForCheckValid: {
|
|
strategyProvider?: StrategyPluginDetail,
|
|
strategy?: StrategyDetail
|
|
language: string
|
|
isReadyForCheckValid: boolean
|
|
}) {
|
|
const { strategy, language, isReadyForCheckValid } = moreDataForCheckValid
|
|
if (!isReadyForCheckValid) {
|
|
return {
|
|
isValid: true,
|
|
errorMessage: '',
|
|
}
|
|
}
|
|
if (!strategy) {
|
|
return {
|
|
isValid: false,
|
|
errorMessage: t('workflow.nodes.agent.checkList.strategyNotSelected'),
|
|
}
|
|
}
|
|
for (const param of strategy.parameters) {
|
|
if (param.required && !payload.agent_parameters?.[param.name]?.value) {
|
|
return {
|
|
isValid: false,
|
|
errorMessage: t('workflow.errorMsg.fieldRequired', { field: renderI18nObject(param.label, language) }),
|
|
}
|
|
}
|
|
}
|
|
return {
|
|
isValid: true,
|
|
errorMessage: '',
|
|
}
|
|
},
|
|
}
|
|
|
|
export default nodeDefault
|