/** * 模型配置类型注册表 * 定义支持的配置类型及其字段元数据 */ export const MODEL_CONFIG_TYPES = { basic: { key: 'basic', label: 'OpenAI 兼容接口', description: '支持标准的 OpenAI API 格式', fields: [ { key: 'apiUrl', label: 'API 地址', type: 'url', required: true }, { key: 'apiKey', label: 'API 密钥', type: 'password', required: true }, { key: 'modelName', label: '模型名称', type: 'text', required: true }, { key: 'temperature', label: 'Temperature', type: 'number', min: 0, max: 2, step: 0.1, default: 0.7 }, { key: 'maxTokens', label: 'Max Tokens', type: 'number', min: 1, max: 128000, step: 1, default: 4096 }, { key: 'topP', label: 'Top P', type: 'number', min: 0, max: 1, step: 0.1, default: 0.9 }, ] }, zhisuan: { key: 'zhisuan', label: '智算管理平台', description: '内部智算平台接入', fields: [ { key: 'apiUrl', label: 'API 地址', type: 'url', required: true }, { key: 'appId', label: 'App ID', type: 'text', required: true }, { key: 'appSecret', label: 'App Secret', type: 'password', required: true }, ] } }; /** * 获取所有配置类型列表 * @returns {Array} 配置类型列表 */ export const getConfigTypeList = () => { return Object.values(MODEL_CONFIG_TYPES).map(type => ({ key: type.key, label: type.label, description: type.description })); }; /** * 根据 key 获取配置类型定义 * @param {string} key - 配置类型 key * @returns {Object|undefined} 配置类型定义 */ export const getConfigTypeByKey = (key) => { return MODEL_CONFIG_TYPES[key]; }; /** * 获取配置类型的字段定义 * @param {string} key - 配置类型 key * @returns {Array} 字段定义数组 */ export const getConfigFields = (key) => { const configType = MODEL_CONFIG_TYPES[key]; return configType ? configType.fields : []; }; /** * 生成配置摘要信息 * @param {Object} config - 配置对象 * @returns {string} 摘要字符串 */ export const getConfigSummary = (config) => { if (!config) return '-'; const type = MODEL_CONFIG_TYPES[config.type]; if (!type) return '-'; if (config.type === 'basic') { return config.basic?.modelName || '-'; } if (config.type === 'zhisuan') { return '智算平台接入'; } return '-'; }; /** * 掩码显示敏感信息 * @param {string} value - 原始值 * @returns {string} 掩码后的值 */ export const maskSensitiveValue = (value) => { if (!value || value.length < 8) return '****'; return value.substring(0, 4) + '****' + value.substring(value.length - 4); };