47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
export function unwrapListData(value) {
|
|
if (Array.isArray(value)) return value
|
|
if (Array.isArray(value?.data)) return value.data
|
|
return []
|
|
}
|
|
|
|
export function pickAvatarId(currentAvatarId, avatars) {
|
|
return currentAvatarId || avatars?.[0]?.id || null
|
|
}
|
|
|
|
export function normalizeAvatarEditForm(avatar = {}) {
|
|
const config = avatar.config || {}
|
|
return {
|
|
name: avatar.name || '',
|
|
displayName: avatar.displayName || '',
|
|
description: avatar.description || '',
|
|
status: avatar.status || 'active',
|
|
photoUrl: avatar.photoUrl || '',
|
|
replyStyle: config.replyStyle || 'professional',
|
|
creativity: Number.isFinite(config.creativity) ? config.creativity : 50,
|
|
rigor: Number.isFinite(config.rigor) ? config.rigor : 50,
|
|
humor: Number.isFinite(config.humor) ? config.humor : 30,
|
|
responseLength: config.responseLength || 'medium',
|
|
systemPrompt: config.systemPrompt || '',
|
|
autoReply: config.autoReply !== false,
|
|
}
|
|
}
|
|
|
|
export function buildAvatarUpdatePayload(form) {
|
|
return {
|
|
name: form.name.trim(),
|
|
displayName: form.displayName.trim() || form.name.trim(),
|
|
description: form.description.trim(),
|
|
status: form.status,
|
|
photoUrl: form.photoUrl.trim(),
|
|
config: {
|
|
replyStyle: form.replyStyle,
|
|
creativity: Number(form.creativity),
|
|
rigor: Number(form.rigor),
|
|
humor: Number(form.humor),
|
|
responseLength: form.responseLength,
|
|
systemPrompt: form.systemPrompt.trim(),
|
|
autoReply: !!form.autoReply,
|
|
},
|
|
}
|
|
}
|