fix(chat): hide missing tool call batch positions

This commit is contained in:
Sycun committed 2026-11-11 17:20:35 +08:00
1 parent ecedd32c97
commit b30443387b
9 files changed
+45 -36

No files matched your search

+1
View File
@@ -885,6 +885,7 @@
"assistantStreamPhase": "مخرجات المساعد",
"toolCallsDetected": "تم رصد {{count}} استدعاء أداة",
"callTool": "استدعاء الأداة: {{name}} ({{index}}/{{total}})",
"callToolWithoutPosition": "استدعاء الأداة: {{name}}",
"toolExecComplete": "اكتملت الأداة {{name}}",
"toolExecFailed": "فشلت الأداة {{name}}",
"knowledgeRetrieval": "استرجاع المعرفة",
+1
View File
@@ -886,6 +886,7 @@
"assistantStreamPhase": "Assistant output",
"toolCallsDetected": "Detected {{count}} tool call(s)",
"callTool": "Call tool: {{name}} ({{index}}/{{total}})",
"callToolWithoutPosition": "Call tool: {{name}}",
"toolExecComplete": "Tool {{name}} completed",
"toolExecFailed": "Tool {{name}} failed",
"knowledgeRetrieval": "Knowledge retrieval",
+1
View File
@@ -898,6 +898,7 @@
"assistantStreamPhase": "Ответ ассистента",
"toolCallsDetected": "Обнаружено вызовов инструментов: {{count}}",
"callTool": "Вызов инструмента: {{name}} ({{index}}/{{total}})",
"callToolWithoutPosition": "Вызов инструмента: {{name}}",
"toolExecComplete": "Инструмент {{name}} выполнен",
"toolExecFailed": "Сбой инструмента {{name}}",
"knowledgeRetrieval": "Поиск в базе знаний",
+1
View File
@@ -874,6 +874,7 @@
"assistantStreamPhase": "助手输出",
"toolCallsDetected": "检测到 {{count}} 个工具调用",
"callTool": "调用工具: {{name}} ({{index}}/{{total}})",
"callToolWithoutPosition": "调用工具: {{name}}",
"toolExecComplete": "工具 {{name}} 执行完成",
"toolExecFailed": "工具 {{name}} 执行失败",
"knowledgeRetrieval": "知识检索",
+1 -6
View File
@@ -4376,12 +4376,7 @@ function renderProcessDetails(messageId, processDetails, options) {
} else if (eventType === 'tool_calls_detected') {
itemTitle = agPx + '🔧 ' + (typeof window.t === 'function' ? window.t('chat.toolCallsDetected', { count: data.count || 0 }) : '检测到 ' + (data.count || 0) + ' 个工具调用');
} else if (eventType === 'tool_call') {
const toolName = data.toolName || (typeof window.t === 'function' ? window.t('chat.unknownTool') : '未知工具');
const index = data.index || 0;
const total = data.total || 0;
const callTitle = typeof window.formatToolCallTimelineTitle === 'function'
? window.formatToolCallTimelineTitle(toolName, index, total)
: (typeof window.t === 'function' ? window.t('chat.callTool', { name: escapeHtml(toolName), index: index, total: total }) : '调用工具: ' + escapeHtml(toolName) + ' (' + index + '/' + total + ')');
const callTitle = window.formatToolCallTimelineTitle(data.toolName, data.index, data.total);
itemTitle = agPx + '🔧 ' + callTitle;
} else if (eventType === 'tool_result') {
const toolName = data.toolName || (typeof window.t === 'function' ? window.t('chat.unknownTool') : '未知工具');
+9 -14
View File
@@ -3608,9 +3608,6 @@ function handleStreamEvent(event, progressElement, progressId,
case 'tool_call':
const toolInfo = event.data || {};
const toolName = toolInfo.toolName || (typeof window.t === 'function' ? window.t('chat.unknownTool') : '未知工具');
const index = toolInfo.index || 0;
const total = toolInfo.total || 0;
const toolCallId = toolInfo.toolCallId || null;
if (toolCallId) {
const existing = getToolCallMapping(progressId, toolCallId);
@@ -3625,7 +3622,7 @@ function handleStreamEvent(event, progressElement, progressId,
}
}
}
const toolCallTitle = formatToolCallTimelineTitle(toolName, index, total);
const toolCallTitle = formatToolCallTimelineTitle(toolInfo.toolName, toolInfo.index, toolInfo.total);
const toolCallItemId = addTimelineItem(timeline, 'tool_call', {
title: timelineAgentBracketPrefix(toolInfo) + '🔧 ' + toolCallTitle,
message: event.message,
@@ -5883,12 +5880,15 @@ function toolCallArgsEmpty(args) {
function formatToolCallTimelineTitle(toolName, index, total) {
const name = toolName || (typeof window.t === 'function' ? window.t('chat.unknownTool') : '未知工具');
const idx = index || 0;
const tot = total || 0;
const idx = Number(index);
const tot = Number(total);
const hasBatchPosition = Number.isInteger(idx) && Number.isInteger(tot) && idx > 0 && idx <= tot;
if (typeof window.t === 'function') {
return window.t('chat.callTool', { name: name, index: idx, total: tot });
const key = hasBatchPosition ? 'chat.callTool' : 'chat.callToolWithoutPosition';
const title = window.t(key, { name: name, index: idx, total: tot });
if (title && title !== key) return title;
}
return '调用工具: ' + name + (tot ? ' (' + idx + '/' + tot + ')' : '');
return '调用工具: ' + name + (hasBatchPosition ? ' (' + idx + '/' + tot + ')' : '');
}
function collectToolResultTextParts(value, parts, depth) {
@@ -9629,12 +9629,7 @@ function refreshProgressAndTimelineI18n() {
const count = parseInt(item.dataset.toolCallsCount, 10) || 0;
titleSpan.textContent = ap + '\uD83D\uDD27 ' + _t('chat.toolCallsDetected', { count: count });
} else if (type === 'tool_call' && (item.dataset.toolName !== undefined || item.dataset.toolIndex !== undefined)) {
const name = (item.dataset.toolName != null && item.dataset.toolName !== '') ? item.dataset.toolName : _t('chat.unknownTool');
const index = parseInt(item.dataset.toolIndex, 10) || 0;
const total = parseInt(item.dataset.toolTotal, 10) || 0;
const callTitle = typeof formatToolCallTimelineTitle === 'function'
? formatToolCallTimelineTitle(name, index, total)
: _t('chat.callTool', { name: name, index: index, total: total });
const callTitle = formatToolCallTimelineTitle(item.dataset.toolName, item.dataset.toolIndex, item.dataset.toolTotal);
titleSpan.textContent = ap + '\uD83D\uDD27 ' + callTitle;
if (item.dataset.toolDisplayStatus) {
applyToolCallStatus(item, item.dataset.toolDisplayStatus);
+26 -1
View File
@@ -2,6 +2,7 @@ const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const vm = require('node:vm');
const i18next = require('../vendor/i18next.min.js');
const monitor = fs.readFileSync('web/static/js/monitor.js', 'utf8');
const chat = fs.readFileSync('web/static/js/chat.js', 'utf8');
const reason = '工具调用已被安全规则拦截:识别到 example.gov,禁止访问。\n规则: 政府网站保护';
@@ -48,7 +49,7 @@ function runtime() {
getCurrentTimeLocale: () => 'en-US', getTimeFormatOptions: () => ({}),
escapeHtml: (value) => String(value).replaceAll('&', '&amp;').replaceAll('<', '&lt;'),
};
const funcs = ['collectToolResultTextParts', 'isToolGuardBlockedResult', 'getToolExecutionDisplayStatus',
const funcs = ['formatToolCallTimelineTitle', 'collectToolResultTextParts', 'isToolGuardBlockedResult', 'getToolExecutionDisplayStatus',
'getToolResultDisplayState', 'toolDisplayStatusFromState', 'getBackgroundRunningToolLabel',
'getToolCallStatusPresentation', 'applyToolCallStatus', 'parseToolCallArgsFromData', 'toolCallArgsEmpty',
'setToolCallDetailState', 'mergeToolResultIntoCallItem', 'coalesceProcessDetailsToolPairs',
@@ -60,6 +61,30 @@ function runtime() {
return ctx;
}
test('tool call titles show a batch position only when the event has a valid one', async () => {
const ctx = runtime();
const titles = {
'zh-CN': '调用工具: exec',
'en-US': 'Call tool: exec',
'ru-RU': 'Вызов инструмента: exec',
'ar-SA': 'استدعاء الأداة: exec'
};
for (const [locale, title] of Object.entries(titles)) {
const translation = JSON.parse(fs.readFileSync(`web/static/i18n/${locale}.json`, 'utf8'));
const instance = i18next.createInstance();
await instance.init({ lng: locale, resources: { [locale]: { translation } } });
ctx.window.t = instance.t.bind(instance);
assert.equal(ctx.formatToolCallTimelineTitle('exec'), title);
assert.equal(ctx.formatToolCallTimelineTitle('exec', 0, 0), title);
assert.equal(ctx.formatToolCallTimelineTitle('exec', 1), title);
assert.equal(ctx.formatToolCallTimelineTitle('exec', 3, 2), title);
assert.equal(ctx.formatToolCallTimelineTitle('exec', 1, 2), title + ' (1/2)');
assert.equal(ctx.formatToolCallTimelineTitle('exec', '2', '2'), title + ' (2/2)');
}
delete ctx.window.t;
assert.equal(ctx.formatToolCallTimelineTitle('exec'), titles['zh-CN']);
});
test('structured block markers have priority over generic failure and running states', () => {
const ctx = runtime();
for (const payload of [
+2 -12
View File
@@ -2231,12 +2231,7 @@ function buildWebshellTimelineItemFromDetail(detail) {
} else if (eventType === 'tool_calls_detected') {
title = ap + '🔧 ' + ((typeof window.t === 'function') ? window.t('chat.toolCallsDetected', { count: data.count || 0 }) : ('检测到 ' + (data.count || 0) + ' 个工具调用'));
} else if (eventType === 'tool_call') {
var tn = data.toolName || ((typeof window.t === 'function') ? window.t('chat.unknownTool') : '未知工具');
var idx = data.index || 0;
var total = data.total || 0;
var wsCallTitle = typeof window.formatToolCallTimelineTitle === 'function'
? window.formatToolCallTimelineTitle(tn, idx, total)
: ((typeof window.t === 'function') ? window.t('chat.callTool', { name: tn, index: idx, total: total }) : ('调用: ' + tn + (total ? ' (' + idx + '/' + total + ')' : '')));
var wsCallTitle = window.formatToolCallTimelineTitle(data.toolName, data.index, data.total);
title = ap + '🔧 ' + wsCallTitle;
} else if (eventType === 'tool_result') {
var tname = data.toolName || '工具';
@@ -3754,12 +3749,7 @@ function runWebshellAiSend(conn, inputEl, sendBtn, messagesContainer) {
appendTimelineItem('tool_calls_detected', webshellAgentPx(_ed) + '🔧 ' + detectedLabel, _em || '', _ed);
if (!streamingTarget) assistantDiv.textContent = '…';
} else if (_et === 'tool_call' && _ed) {
var tn = _ed.toolName || '未知工具';
var idx = _ed.index || 0;
var total = _ed.total || 0;
var callTitle = typeof window.formatToolCallTimelineTitle === 'function'
? window.formatToolCallTimelineTitle(tn, idx, total)
: (wsTOr('chat.callTool', '') || ('调用工具: ' + tn + (total ? ' (' + idx + '/' + total + ')' : '')));
var callTitle = window.formatToolCallTimelineTitle(_ed.toolName, _ed.index, _ed.total);
var callItem = appendTimelineItem('tool_call', webshellAgentPx(_ed) + '🔧 ' + callTitle, _em || '', _ed);
if (_ed.toolCallId && callItem) {
wsToolCallItems.set(_ed.toolCallId, callItem);
+3 -3
View File
@@ -7069,9 +7069,9 @@
<script src="/static/js/agents.js"></script>
<script src="/static/js/dashboard.js?v=20261011-token-settings-cache-only"></script>
<script src="/static/js/chat-scroll.js?v=20260815-1"></script>
<script src="/static/js/monitor.js?v=20261011-token-usage-pagination-20261027"></script>
<script src="/static/js/monitor.js?v=20261011-token-usage-pagination-20261027-tool-title"></script>
<script src="/static/js/attack-chain-context.js?v=20261012-summary-2"></script>
<script src="/static/js/chat.js?v=20261016-context-memory-token-usage-pagination-20261027"></script>
<script src="/static/js/chat.js?v=20261016-context-memory-token-usage-pagination-20261027-tool-title"></script>
<script src="/static/js/chat-plan-progress.js?v=20260815-1"></script>
<script src="/static/js/hitl.js?v=20260819-1-pagination-20261027"></script>
<script src="/static/js/tool-guard.js?v=20261010-conflict"></script>
@@ -7091,7 +7091,7 @@
<script src="/static/js/projects.js?v=20260819-1-pagination-20261027"></script>
<script src="/static/js/vulnerability.js?v=20261030-format-download"></script>
<script src="/static/js/vulnerability-download.js?v=20261030-2"></script>
<script src="/static/js/webshell.js?v=20261011-token-usage"></script>
<script src="/static/js/webshell.js?v=20261011-token-usage-tool-title"></script>
<script src="/static/js/chat-files.js?v=20261103-personal-integration"></script>
<script src="/static/js/assessments.js"></script>
<script src="/static/js/tasks.js?v=20261103-personal-integration"></script>