/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React, { useMemo } from 'react'; import { Modal, Button, Empty, Divider, Typography, } from '@douyinfe/semi-ui'; import { IconCopy } from '@douyinfe/semi-icons'; import { copy, showError, showSuccess } from '../../../../helpers'; const { Text } = Typography; const parseAuditLine = (line) => { if (typeof line !== 'string') { return null; } const firstSpaceIndex = line.indexOf(' '); if (firstSpaceIndex <= 0) { return { action: line, content: line }; } return { action: line.slice(0, firstSpaceIndex), content: line.slice(firstSpaceIndex + 1), }; }; const getActionLabel = (action, t) => { switch ((action || '').toLowerCase()) { case 'set': return t('设置'); case 'delete': return t('删除'); case 'copy': return t('复制'); case 'move': return t('移动'); case 'append': return t('追加'); case 'prepend': return t('前置'); case 'trim_prefix': return t('去前缀'); case 'trim_suffix': return t('去后缀'); case 'ensure_prefix': return t('保前缀'); case 'ensure_suffix': return t('保后缀'); case 'trim_space': return t('去空格'); case 'to_lower': return t('转小写'); case 'to_upper': return t('转大写'); case 'replace': return t('替换'); case 'regex_replace': return t('正则替换'); case 'set_header': return t('设请求头'); case 'delete_header': return t('删请求头'); case 'copy_header': return t('复制请求头'); case 'move_header': return t('移动请求头'); case 'pass_headers': return t('透传请求头'); case 'sync_fields': return t('同步字段'); case 'return_error': return t('返回错误'); default: return action; } }; const ParamOverrideModal = ({ showParamOverrideModal, setShowParamOverrideModal, paramOverrideTarget, t, }) => { const lines = Array.isArray(paramOverrideTarget?.lines) ? paramOverrideTarget.lines : []; const parsedLines = useMemo(() => { return lines.map(parseAuditLine); }, [lines]); const copyAll = async () => { const content = lines.join('\n'); if (!content) { return; } if (await copy(content)) { showSuccess(t('参数覆盖已复制')); return; } showError(t('无法复制到剪贴板,请手动复制')); }; return ( setShowParamOverrideModal(false)} footer={null} centered closable maskClosable width={640} >
{t('{{count}} 项操作', { count: lines.length })}
{paramOverrideTarget?.modelName ? ( {paramOverrideTarget.modelName} ) : null} {paramOverrideTarget?.requestId ? ( {t('Request ID')}: {paramOverrideTarget.requestId} ) : null} {paramOverrideTarget?.requestPath ? ( {t('请求路径')}: {paramOverrideTarget.requestPath} ) : null}
{lines.length === 0 ? ( ) : (
{parsedLines.map((item, index) => { if (!item) { return null; } return (
{getActionLabel(item.action, t)}
{item.content}
); })}
)}
); }; export default ParamOverrideModal;