Add files via upload

This commit is contained in:
公明
2026-08-15 11:03:13 +08:00
committed by GitHub
parent 9c0621819f
commit 7823fb6b0c
2 changed files with 36 additions and 0 deletions
+18
View File
@@ -5819,6 +5819,13 @@ function parseToolCallArgsFromData(data) {
return args;
}
function toolCallArgsEmpty(args) {
if (args == null) return true;
if (typeof args !== 'object') return false;
if (Array.isArray(args)) return args.length === 0;
return Object.keys(args).length === 0;
}
function formatToolCallTimelineTitle(toolName, index, total) {
const name = toolName || (typeof window.t === 'function' ? window.t('chat.unknownTool') : '未知工具');
const idx = index || 0;
@@ -6110,6 +6117,10 @@ function mergeToolResultIntoCallItem(item, data, options) {
if (item.classList.contains('tool-call-collapsible')) {
const state = toolCallDetailStateByItemId.get(item.id) || {};
const resultArgs = parseToolCallArgsFromData(data);
if (toolCallArgsEmpty(state.args) && !toolCallArgsEmpty(resultArgs)) {
state.args = resultArgs;
}
state.resultData = data;
state.rawText = text;
state.resultDetailId = data.processDetailId || state.resultDetailId || '';
@@ -6214,6 +6225,13 @@ function coalesceProcessDetailsToolPairs(details) {
function absorbResult(targetDetail, resultDetail) {
const rd = resultDetail.data || {};
targetDetail.data = targetDetail.data || {};
if (toolCallArgsEmpty(parseToolCallArgsFromData(targetDetail.data))) {
const resultArgs = parseToolCallArgsFromData(rd);
if (!toolCallArgsEmpty(resultArgs)) {
targetDetail.data.argumentsObj = resultArgs;
targetDetail.data.arguments = JSON.stringify(resultArgs);
}
}
targetDetail.data._mergedResult = Object.assign({}, rd);
if (resultDetail.id) {
targetDetail.data._mergedResultDetailId = resultDetail.id;
@@ -0,0 +1,18 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
test('tool_result 合并回工具调用卡时会回填空参数', () => {
const source = fs.readFileSync('web/static/js/monitor.js', 'utf8');
assert.match(source, /function toolCallArgsEmpty\(args\)/);
assert.match(source, /const resultArgs = parseToolCallArgsFromData\(data\);/);
assert.match(source, /toolCallArgsEmpty\(state\.args\) && !toolCallArgsEmpty\(resultArgs\)/);
assert.match(source, /state\.args = resultArgs;/);
});
test('历史 process_details 合并时也会从 tool_result 补齐 tool_call 参数', () => {
const source = fs.readFileSync('web/static/js/monitor.js', 'utf8');
assert.match(source, /function absorbResult\(targetDetail, resultDetail\)/);
assert.match(source, /targetDetail\.data\.argumentsObj = resultArgs;/);
assert.match(source, /targetDetail\.data\.arguments = JSON\.stringify\(resultArgs\);/);
});