From b30443387b7ff7f9ce2a4846e2af480ee4152ad8 Mon Sep 17 00:00:00 2001
From: Sycun <165354365+Sycun@users.noreply.github.com>
Date: Wed, 11 Nov 2026 17:20:35 +0800
Subject: [PATCH] fix(chat): hide missing tool call batch positions
---
web/static/i18n/ar-SA.json | 1 +
web/static/i18n/en-US.json | 1 +
web/static/i18n/ru-RU.json | 1 +
web/static/i18n/zh-CN.json | 1 +
web/static/js/chat.js | 7 +-----
web/static/js/monitor.js | 23 +++++++-----------
web/static/js/tool-blocked-display.test.cjs | 27 ++++++++++++++++++++-
web/static/js/webshell.js | 14 ++---------
web/templates/index.html | 6 ++---
9 files changed, 45 insertions(+), 36 deletions(-)
diff --git a/web/static/i18n/ar-SA.json b/web/static/i18n/ar-SA.json
index aefb460a..45810186 100644
--- a/web/static/i18n/ar-SA.json
+++ b/web/static/i18n/ar-SA.json
@@ -885,6 +885,7 @@
"assistantStreamPhase": "مخرجات المساعد",
"toolCallsDetected": "تم رصد {{count}} استدعاء أداة",
"callTool": "استدعاء الأداة: {{name}} ({{index}}/{{total}})",
+ "callToolWithoutPosition": "استدعاء الأداة: {{name}}",
"toolExecComplete": "اكتملت الأداة {{name}}",
"toolExecFailed": "فشلت الأداة {{name}}",
"knowledgeRetrieval": "استرجاع المعرفة",
diff --git a/web/static/i18n/en-US.json b/web/static/i18n/en-US.json
index 606c46e2..2dccf611 100644
--- a/web/static/i18n/en-US.json
+++ b/web/static/i18n/en-US.json
@@ -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",
diff --git a/web/static/i18n/ru-RU.json b/web/static/i18n/ru-RU.json
index d1e6e6c3..d52098d5 100644
--- a/web/static/i18n/ru-RU.json
+++ b/web/static/i18n/ru-RU.json
@@ -898,6 +898,7 @@
"assistantStreamPhase": "Ответ ассистента",
"toolCallsDetected": "Обнаружено вызовов инструментов: {{count}}",
"callTool": "Вызов инструмента: {{name}} ({{index}}/{{total}})",
+ "callToolWithoutPosition": "Вызов инструмента: {{name}}",
"toolExecComplete": "Инструмент {{name}} выполнен",
"toolExecFailed": "Сбой инструмента {{name}}",
"knowledgeRetrieval": "Поиск в базе знаний",
diff --git a/web/static/i18n/zh-CN.json b/web/static/i18n/zh-CN.json
index 0f140f40..996b5ec2 100644
--- a/web/static/i18n/zh-CN.json
+++ b/web/static/i18n/zh-CN.json
@@ -874,6 +874,7 @@
"assistantStreamPhase": "助手输出",
"toolCallsDetected": "检测到 {{count}} 个工具调用",
"callTool": "调用工具: {{name}} ({{index}}/{{total}})",
+ "callToolWithoutPosition": "调用工具: {{name}}",
"toolExecComplete": "工具 {{name}} 执行完成",
"toolExecFailed": "工具 {{name}} 执行失败",
"knowledgeRetrieval": "知识检索",
diff --git a/web/static/js/chat.js b/web/static/js/chat.js
index 388d7a51..f4e3f0bb 100644
--- a/web/static/js/chat.js
+++ b/web/static/js/chat.js
@@ -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') : '未知工具');
diff --git a/web/static/js/monitor.js b/web/static/js/monitor.js
index 602bd3c6..4b816cde 100644
--- a/web/static/js/monitor.js
+++ b/web/static/js/monitor.js
@@ -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);
diff --git a/web/static/js/tool-blocked-display.test.cjs b/web/static/js/tool-blocked-display.test.cjs
index 6a61d0ec..afa47d28 100644
--- a/web/static/js/tool-blocked-display.test.cjs
+++ b/web/static/js/tool-blocked-display.test.cjs
@@ -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('&', '&').replaceAll('<', '<'),
};
- 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 [
diff --git a/web/static/js/webshell.js b/web/static/js/webshell.js
index d056f318..97ca9366 100644
--- a/web/static/js/webshell.js
+++ b/web/static/js/webshell.js
@@ -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);
diff --git a/web/templates/index.html b/web/templates/index.html
index 3dbf7c63..fde6b61b 100644
--- a/web/templates/index.html
+++ b/web/templates/index.html
@@ -7069,9 +7069,9 @@
-
+
-
+
@@ -7091,7 +7091,7 @@
-
+