fix: 工具卡片错误信息显示、清理死代码
1. 工具调用失败时显示错误原因(之前只有状态标签没有具体错误) 2. 删除 formatFileSize 死代码(仅在已移除的结果渲染中使用) 3. 清理 updateLastAssistantMessage 未使用的 stats 参数
This commit is contained in:
@@ -241,6 +241,14 @@ function renderToolCallCard(tc: ToolCallRecord): string {
|
|||||||
if (args.selector) paramsHtml += `<div class="tool-param">选择器: <code>${escapeHtml(String(args.selector))}</code></div>`;
|
if (args.selector) paramsHtml += `<div class="tool-param">选择器: <code>${escapeHtml(String(args.selector))}</code></div>`;
|
||||||
if (args.action) paramsHtml += `<div class="tool-param">操作: <code>${escapeHtml(String(args.action))}</code></div>`;
|
if (args.action) paramsHtml += `<div class="tool-param">操作: <code>${escapeHtml(String(args.action))}</code></div>`;
|
||||||
|
|
||||||
|
// 失败/取消时显示错误信息(成功结果在工作空间工具页签查看)
|
||||||
|
let errorHtml = '';
|
||||||
|
if (tc.status === 'error' && tc.result?.error) {
|
||||||
|
errorHtml = `<div class="tool-call-error">❌ ${escapeHtml(String(tc.result.error))}</div>`;
|
||||||
|
} else if (tc.status === 'cancelled') {
|
||||||
|
errorHtml = `<div class="tool-call-error">🚫 用户取消了操作</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
return `<div class="tool-call-card tool-call-${tc.status}">
|
return `<div class="tool-call-card tool-call-${tc.status}">
|
||||||
<div class="tool-call-header">
|
<div class="tool-call-header">
|
||||||
<span class="tool-call-icon">${icon}</span>
|
<span class="tool-call-icon">${icon}</span>
|
||||||
@@ -248,19 +256,11 @@ function renderToolCallCard(tc: ToolCallRecord): string {
|
|||||||
<span class="tool-call-status">${status}</span>
|
<span class="tool-call-status">${status}</span>
|
||||||
</div>
|
</div>
|
||||||
${paramsHtml ? `<div class="tool-call-params">${paramsHtml}</div>` : ''}
|
${paramsHtml ? `<div class="tool-call-params">${paramsHtml}</div>` : ''}
|
||||||
|
${errorHtml}
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatFileSize(bytes: number): string {
|
export function updateLastAssistantMessage(content: string, think: string | null, _stats: unknown, model?: string): void {
|
||||||
if (!bytes) return '0 B';
|
|
||||||
const units = ['B', 'KB', 'MB', 'GB'];
|
|
||||||
let i = 0;
|
|
||||||
let size = bytes;
|
|
||||||
while (size >= 1024 && i < units.length - 1) { size /= 1024; i++; }
|
|
||||||
return `${size.toFixed(1)} ${units[i]}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function updateLastAssistantMessage(content: string, think: string | null, stats: { eval_count?: number; total_duration?: number } | null, model?: string): void {
|
|
||||||
const lastMsg = currentPlaceholder;
|
const lastMsg = currentPlaceholder;
|
||||||
if (!lastMsg) return;
|
if (!lastMsg) return;
|
||||||
|
|
||||||
|
|||||||
@@ -2062,6 +2062,15 @@ html, body {
|
|||||||
color: var(--critical);
|
color: var(--critical);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tool-call-error {
|
||||||
|
padding: 6px 14px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--critical);
|
||||||
|
border-top: 1px solid var(--border-subtle);
|
||||||
|
background: rgba(220, 53, 69, 0.04);
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
/* ── 聊天区域工具调用历史(可折叠)── */
|
/* ── 聊天区域工具调用历史(可折叠)── */
|
||||||
.tool-calls-history {
|
.tool-calls-history {
|
||||||
margin: 8px 0;
|
margin: 8px 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user