fix: simplify enhanced display for personalization updates
This commit is contained in:
parent
8991ed5084
commit
1b27b3ffa2
@ -778,42 +778,18 @@ function renderManagePersonalization(result: any, args: any): string {
|
||||
|
||||
if (action === 'update') {
|
||||
const field = String(result.updated_field || args.field || '');
|
||||
const oldValue = result.old_value ?? args.old_value;
|
||||
const newValue = result.updated_value ?? args.value;
|
||||
|
||||
if (field) {
|
||||
html += `<div><strong>字段:</strong>${escapeHtml(formatPersonalizationFieldLabel(field))}</div>`;
|
||||
html += `<div><strong>新值:</strong>${escapeHtml(formatPersonalizationFieldValue(field, newValue))}</div>`;
|
||||
if (oldValue !== undefined) {
|
||||
html += `<div><strong>旧值:</strong>${escapeHtml(formatPersonalizationFieldValue(field, oldValue))}</div>`;
|
||||
}
|
||||
}
|
||||
if (result?.theme_changed && result?.new_theme) {
|
||||
html += `<div><strong>主题刷新:</strong>${escapeHtml(formatPersonalizationFieldValue('theme', result.new_theme))}</div>`;
|
||||
html += `<div><strong>修改项:</strong>${escapeHtml(formatPersonalizationFieldLabel(field))}</div>`;
|
||||
html += `<div><strong>修改后:</strong>${escapeHtml(formatPersonalizationFieldValue(field, newValue))}</div>`;
|
||||
}
|
||||
html += '</div>';
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
const data = result?.data && typeof result.data === 'object' ? result.data : {};
|
||||
const entries = Object.entries(data);
|
||||
html += `<div><strong>配置项:</strong>${entries.length} 项</div>`;
|
||||
html += '</div>';
|
||||
|
||||
if (entries.length > 0) {
|
||||
html += '<div class="tool-result-content">';
|
||||
html += '<div class="personalization-config-title">当前个性化配置</div>';
|
||||
html += '<div class="personalization-config-list">';
|
||||
entries.forEach(([field, value]) => {
|
||||
html += '<div class="config-item">';
|
||||
html += `<span class="config-label">${escapeHtml(formatPersonalizationFieldLabel(field))}</span>`;
|
||||
html += `<span class="config-value">${escapeHtml(formatPersonalizationFieldValue(field, value))}</span>`;
|
||||
html += '</div>';
|
||||
});
|
||||
html += '</div></div>';
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
@ -98,6 +98,10 @@ export function renderEnhancedToolResult(
|
||||
else if (name === 'update_memory') {
|
||||
return renderUpdateMemory(result, args);
|
||||
}
|
||||
// 个性化管理类
|
||||
else if (name === 'manage_personalization') {
|
||||
return renderManagePersonalization(result, args);
|
||||
}
|
||||
|
||||
// 待办事项类
|
||||
else if (name === 'todo_create') {
|
||||
@ -626,6 +630,66 @@ function renderUpdateMemory(result: any, args: any): string {
|
||||
return html;
|
||||
}
|
||||
|
||||
function formatPersonalizationFieldLabel(field: string): string {
|
||||
const labelMap: Record<string, string> = {
|
||||
self_identify: 'AI 自称',
|
||||
user_name: '用户称呼',
|
||||
profession: '用户职业',
|
||||
tone: '交流语气',
|
||||
considerations: '注意事项',
|
||||
theme: '主题',
|
||||
communication_style: '交流风格',
|
||||
enabled: '个性化开关'
|
||||
};
|
||||
return labelMap[field] || field;
|
||||
}
|
||||
|
||||
function formatPersonalizationFieldValue(field: string, value: any): string {
|
||||
if (value === null || value === undefined || value === '') {
|
||||
return '未设置';
|
||||
}
|
||||
if (field === 'enabled') {
|
||||
return value ? '开启' : '关闭';
|
||||
}
|
||||
if (field === 'considerations') {
|
||||
if (!Array.isArray(value) || value.length === 0) {
|
||||
return '未设置';
|
||||
}
|
||||
return value.map((item) => String(item)).join('、');
|
||||
}
|
||||
return String(value);
|
||||
}
|
||||
|
||||
function renderManagePersonalization(result: any, args: any): string {
|
||||
const action = String(args.action || result.action || 'read');
|
||||
const status = formatToolStatusLabel(result, action === 'update' ? '✓ 已更新' : '✓ 已读取');
|
||||
const field = String(result.updated_field || args.field || '');
|
||||
const newValue = result.updated_value ?? args.value;
|
||||
|
||||
let html = '<div class="tool-result-meta">';
|
||||
html += `<div><strong>操作:</strong>${escapeHtml(action === 'update' ? '更新配置' : '读取配置')}</div>`;
|
||||
html += `<div><strong>状态:</strong>${status}</div>`;
|
||||
|
||||
if (!result?.success) {
|
||||
if (result?.error) {
|
||||
html += `<div><strong>错误:</strong>${escapeHtml(String(result.error))}</div>`;
|
||||
}
|
||||
if (Array.isArray(result?.validation_errors) && result.validation_errors.length > 0) {
|
||||
html += `<div><strong>校验:</strong>${escapeHtml(result.validation_errors.join(';'))}</div>`;
|
||||
}
|
||||
html += '</div>';
|
||||
return html;
|
||||
}
|
||||
|
||||
if (action === 'update' && field) {
|
||||
html += `<div><strong>修改项:</strong>${escapeHtml(formatPersonalizationFieldLabel(field))}</div>`;
|
||||
html += `<div><strong>修改后:</strong>${escapeHtml(formatPersonalizationFieldValue(field, newValue))}</div>`;
|
||||
}
|
||||
|
||||
html += '</div>';
|
||||
return html;
|
||||
}
|
||||
|
||||
// 待办事项类渲染函数
|
||||
function renderTodoCreate(result: any, args: any): string {
|
||||
const status = formatToolStatusLabel(result, '✓ 已创建');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user