You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

panel.tsx 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import type { FC } from 'react'
  2. import { memo } from 'react'
  3. import type { NodePanelProps } from '../../types'
  4. import { AgentFeature, type AgentNodeType } from './types'
  5. import Field from '../_base/components/field'
  6. import { AgentStrategy } from '../_base/components/agent-strategy'
  7. import useConfig from './use-config'
  8. import { useTranslation } from 'react-i18next'
  9. import OutputVars, { VarItem } from '../_base/components/output-vars'
  10. import type { StrategyParamItem } from '@/app/components/plugins/types'
  11. import type { CredentialFormSchema } from '@/app/components/header/account-setting/model-provider-page/declarations'
  12. import { toType } from '@/app/components/tools/utils/to-form-schema'
  13. import { useStore } from '../../store'
  14. import Split from '../_base/components/split'
  15. import MemoryConfig from '../_base/components/memory-config'
  16. const i18nPrefix = 'workflow.nodes.agent'
  17. export function strategyParamToCredientialForm(param: StrategyParamItem): CredentialFormSchema {
  18. return {
  19. ...param as any,
  20. variable: param.name,
  21. show_on: [],
  22. type: toType(param.type),
  23. tooltip: param.help,
  24. }
  25. }
  26. const AgentPanel: FC<NodePanelProps<AgentNodeType>> = (props) => {
  27. const {
  28. inputs,
  29. setInputs,
  30. currentStrategy,
  31. formData,
  32. onFormChange,
  33. isChatMode,
  34. availableNodesWithParent,
  35. availableVars,
  36. readOnly,
  37. outputSchema,
  38. handleMemoryChange,
  39. canChooseMCPTool,
  40. } = useConfig(props.id, props.data)
  41. const { t } = useTranslation()
  42. const resetEditor = useStore(s => s.setControlPromptEditorRerenderKey)
  43. return <div className='my-2'>
  44. <Field
  45. required
  46. title={t('workflow.nodes.agent.strategy.label')}
  47. className='px-4 py-2'
  48. tooltip={t('workflow.nodes.agent.strategy.tooltip')} >
  49. <AgentStrategy
  50. strategy={inputs.agent_strategy_name ? {
  51. agent_strategy_provider_name: inputs.agent_strategy_provider_name!,
  52. agent_strategy_name: inputs.agent_strategy_name!,
  53. agent_strategy_label: inputs.agent_strategy_label!,
  54. agent_output_schema: inputs.output_schema,
  55. plugin_unique_identifier: inputs.plugin_unique_identifier!,
  56. meta: inputs.meta,
  57. } : undefined}
  58. onStrategyChange={(strategy) => {
  59. setInputs({
  60. ...inputs,
  61. agent_strategy_provider_name: strategy?.agent_strategy_provider_name,
  62. agent_strategy_name: strategy?.agent_strategy_name,
  63. agent_strategy_label: strategy?.agent_strategy_label,
  64. output_schema: strategy!.agent_output_schema,
  65. plugin_unique_identifier: strategy!.plugin_unique_identifier,
  66. meta: strategy?.meta,
  67. })
  68. resetEditor(Date.now())
  69. }}
  70. formSchema={currentStrategy?.parameters?.map(strategyParamToCredientialForm) || []}
  71. formValue={formData}
  72. onFormValueChange={onFormChange}
  73. nodeOutputVars={availableVars}
  74. availableNodes={availableNodesWithParent}
  75. nodeId={props.id}
  76. canChooseMCPTool={canChooseMCPTool}
  77. />
  78. </Field>
  79. <div className='px-4 py-2'>
  80. {isChatMode && currentStrategy?.features?.includes(AgentFeature.HISTORY_MESSAGES) && (
  81. <>
  82. <Split />
  83. <MemoryConfig
  84. className='mt-4'
  85. readonly={readOnly}
  86. config={{ data: inputs.memory }}
  87. onChange={handleMemoryChange}
  88. canSetRoleName={false}
  89. />
  90. </>
  91. )}
  92. </div>
  93. <div>
  94. <OutputVars>
  95. <VarItem
  96. name='text'
  97. type='String'
  98. description={t(`${i18nPrefix}.outputVars.text`)}
  99. />
  100. <VarItem
  101. name='files'
  102. type='Array[File]'
  103. description={t(`${i18nPrefix}.outputVars.files.title`)}
  104. />
  105. <VarItem
  106. name='json'
  107. type='Array[Object]'
  108. description={t(`${i18nPrefix}.outputVars.json`)}
  109. />
  110. {outputSchema.map(({ name, type, description }) => (
  111. <VarItem
  112. key={name}
  113. name={name}
  114. type={type}
  115. description={description}
  116. />
  117. ))}
  118. </OutputVars>
  119. </div>
  120. </div>
  121. }
  122. AgentPanel.displayName = 'AgentPanel'
  123. export default memo(AgentPanel)