feat: 模型配置提交格式改为JSON数组字符串

- handleSave中将model字段转换为JSON字符串格式:[{id, name}]
- 更新parseModelSelections支持解析JSON格式和旧逗号分隔格式
- 移除normalize函数,由handleSave统一处理格式转换
main
sp mac bookpro 2605 2026-06-03 01:54:10 +08:00
parent d00ef10e9f
commit 40c5396a80
3 changed files with 29 additions and 12 deletions

View File

@ -152,9 +152,6 @@ export default function CapabilitySettings({
label="模型"
className="mb-0"
getValueProps={(value) => ({ value: parseModelSelections(value) })}
normalize={(value) =>
Array.isArray(value) ? value.map((item) => String(item).trim()).filter(Boolean).join(',') : ''
}
>
<ModelCheckboxDropdown models={models} />
</Form.Item>

View File

@ -32,10 +32,26 @@ export const TYPE_TAG: Record<SkillType, { color: string; icon: string; label: s
export const isImageUrl = (url: string | undefined) => url?.startsWith('http') || url?.startsWith('/');
export const parseModelSelections = (value?: string | string[]) =>
Array.isArray(value)
? value
: String(value || '')
.split(',')
.map((item) => item.trim())
.filter(Boolean);
export const parseModelSelections = (value?: string | string[]) => {
if (Array.isArray(value)) {
return value;
}
// 尝试解析 JSON 格式
try {
const parsed = JSON.parse(String(value || '[]'));
if (Array.isArray(parsed)) {
return parsed.map((item: any) => {
if (typeof item === 'object' && item.id) {
return item.id;
}
return String(item);
}).filter(Boolean);
}
} catch {
// 兼容旧格式:逗号分隔的字符串
}
return String(value || '')
.split(',')
.map((item) => item.trim())
.filter(Boolean);
};

View File

@ -163,9 +163,13 @@ export function useAgentEditor({ id, isNew, form, message, navigate }: UseAgentE
Object.keys(values).forEach((key) => {
const formValue = (values as any)[key];
const originalValue = (agent as any)?.[key];
// 特殊处理 model 字段:如果是数组,用逗号拼接成字符串
// 特殊处理 model 字段:将 id 和 name 组合成 JSON 数组字符串
if (key === 'model' && Array.isArray(formValue)) {
changedFields[key] = formValue.join(',');
const modelObjects = formValue.map((modelId: string) => {
const model = models.find((m) => m.id === modelId);
return { id: modelId, name: model?.model_name || '' };
});
changedFields[key] = JSON.stringify(modelObjects);
} else if (formValue !== originalValue) {
changedFields[key] = formValue;
}