From 8f6bf11320ba24af3ebd924480968d776621e5c0 Mon Sep 17 00:00:00 2001 From: Neal_Tan <425088158@qq.com> Date: Sun, 30 Mar 2025 00:51:48 +0000 Subject: [PATCH] =?UTF-8?q?feat(Assistant):=20=E5=A2=9E=E5=8A=A0=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=8D=E5=8F=98=E9=87=8F=E8=BE=93=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在编辑助手处添加了变量 - 保存智能体时可以保存变量 Fixed #4049 --- src/renderer/src/components/VariableList.tsx | 103 ++++++++++++++++ src/renderer/src/config/models.ts | 18 ++- .../src/pages/home/Tabs/AssistantItem.tsx | 3 + .../AssistantPromptSettings.tsx | 116 ++++++++++++++++-- src/renderer/src/services/ApiService.ts | 9 ++ src/renderer/src/types/index.ts | 7 ++ src/renderer/src/utils/index.ts | 19 +++ 7 files changed, 266 insertions(+), 9 deletions(-) create mode 100644 src/renderer/src/components/VariableList.tsx diff --git a/src/renderer/src/components/VariableList.tsx b/src/renderer/src/components/VariableList.tsx new file mode 100644 index 0000000000..324cf301a6 --- /dev/null +++ b/src/renderer/src/components/VariableList.tsx @@ -0,0 +1,103 @@ +import { DeleteOutlined, ImportOutlined } from '@ant-design/icons' +import { VStack } from '@renderer/components/Layout' +import { Variable } from '@renderer/types' +import { Button, Input, Tooltip } from 'antd' +import { useTranslation } from 'react-i18next' +import styled from 'styled-components' + +interface VariableListProps { + variables: Variable[] + setVariables: (variables: Variable[]) => void + onUpdate?: (variables: Variable[]) => void + onInsertVariable?: (name: string) => void +} + +const VariableList: React.FC = ({ variables, setVariables, onUpdate, onInsertVariable }) => { + const { t } = useTranslation() + + const deleteVariable = (id: string) => { + const updatedVariables = variables.filter((v) => v.id !== id) + setVariables(updatedVariables) + + if (onUpdate) { + onUpdate(updatedVariables) + } + } + + const updateVariable = (id: string, field: 'name' | 'value', value: string) => { + // Only update the local state when typing, don't call the parent's onUpdate + const updatedVariables = variables.map((v) => (v.id === id ? { ...v, [field]: value } : v)) + setVariables(updatedVariables) + } + + // This function will be called when input loses focus + const handleInputBlur = () => { + if (onUpdate) { + onUpdate(variables) + } + } + + return ( + + {variables.length === 0 ? ( + {t('common.no_variables_added')} + ) : ( + + {variables.map((variable) => ( + + updateVariable(variable.id, 'name', e.target.value)} + onBlur={handleInputBlur} + style={{ width: '30%' }} + /> + updateVariable(variable.id, 'value', e.target.value)} + onBlur={handleInputBlur} + style={{ flex: 1 }} + /> + {onInsertVariable && ( + + + + )} + + +