feat(web): llm node add memory config

This commit is contained in:
zhaoying
2026-01-14 16:50:20 +08:00
parent a6e7565919
commit 617ff706bc
8 changed files with 142 additions and 41 deletions

View File

@@ -1,6 +1,5 @@
import React, { useState, useImperativeHandle, forwardRef, useRef } from 'react';
import { Button, Input, Space, Typography, Tooltip, message, List } from 'antd';
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons';
import { useState, useImperativeHandle, forwardRef, useRef } from 'react';
import { Button, Space, List } from 'antd';
import { useTranslation } from 'react-i18next';
import type { ChatVariable, AddChatVariableRef } from '../../types';
import type { ChatVariableModalRef } from './types'

View File

@@ -131,7 +131,7 @@ const EditableTable: React.FC<EditableTableProps> = ({
const AddButton = ({ block = false }: { block?: boolean }) => (
<Button
type={block ? "dashed" : "text"}
icon={<PlusOutlined />}
icon={block ? undefined : <PlusOutlined />}
onClick={() => add(createNewRow())}
size="small"
block={block}

View File

@@ -0,0 +1,69 @@
import { type FC } from "react";
import { useTranslation } from 'react-i18next'
import { Form, Row, Col, Divider, Switch, Slider } from 'antd'
import type { Suggestion } from '../../Editor/plugin/AutocompletePlugin'
import MessageEditor from '../MessageEditor'
const MemoryConfig: FC<{ options: Suggestion[]; parentName: string; }> = ({
options,
parentName
}) => {
const { t } = useTranslation()
const form = Form.useFormInstance();
const values = Form.useWatch([], form) || {}
console.log('MemoryConfig', values)
const handleChangeEnable = (value: boolean) => {
if (value) {
form.setFieldsValue({
memory: {
...form.getFieldValue(parentName),
enable_window: false,
window_size: 20,
messages: "{{sys.message}}"
}
})
}
}
return (
<>
{values?.memory?.enable && <>
<div className="rb:flex rb:items-center rb:justify-between rb:py-1.5 rb:px-2 rb:bg-[#F6F8FC] rb:rounded-md rb:mb-2">
{t('workflow.config.llm.memory')}
<span>{t('workflow.config.llm.inner')}</span>
</div>
<Form.Item layout="horizontal" name={[parentName, 'messages']}>
<MessageEditor
title="USER"
isArray={false}
parentName={[parentName, 'messages']}
options={options}
/>
</Form.Item>
<Divider />
</>}
<Form.Item layout="horizontal" name={[parentName, 'enable']} label={t('workflow.config.llm.memory')}>
<Switch onChange={handleChangeEnable} />
</Form.Item>
{values?.memory?.enable && <>
<Row className="rb:mb-3">
<Col span={10}>
<Form.Item layout="horizontal" name={[parentName, 'enable_window']} noStyle>
<Switch />
</Form.Item>
<span className="rb:ml-2">{t('workflow.config.llm.enable_window')}</span>
</Col>
<Col span={14}>
<Form.Item layout="horizontal" name={[parentName, 'window_size']} noStyle>
<Slider min={1} max={100} step={1} className="rb:my-0!" disabled={!values?.memory?.enable_window} />
</Form.Item>
</Col>
</Row>
</>}
</>
);
};
export default MemoryConfig;

View File

@@ -127,7 +127,7 @@ const MessageEditor: FC<MessageEditor> = ({
</Space>
);
})}
<Form.Item>
<Form.Item noStyle>
<Button type="dashed" onClick={() => handleAdd(add)} block>
+{t('workflow.addMessage')}
</Button>

View File

@@ -22,6 +22,7 @@ import ConditionList from './ConditionList'
import CycleVarsList from './CycleVarsList'
import AssignmentList from './AssignmentList'
import ToolConfig from './ToolConfig'
import MemoryConfig from './MemoryConfig'
// import { calculateVariableList } from './utils/variableListCalculator'
interface PropertiesProps {
@@ -1230,6 +1231,20 @@ const Properties: FC<PropertiesProps> = ({
</Form.Item>
)
}
if (config.type === 'memoryConfig') {
return (
<Form.Item
key={key}
name={key}
noStyle
>
<MemoryConfig
parentName={key}
options={getFilteredVariableList('llm')}
/>
</Form.Item>
)
}
return (
<Form.Item