fix: Tool-Results im Chat korrekt anzeigen
Result-Div wird nicht mehr leer erstellt bei tool_use – erst wenn tatsächlich ein Result vorliegt. Header wird nachträglich clickable gemacht wenn das Result später eintrifft. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
6d16d00290
commit
7d55e8e818
2 files changed
+29
-9
No files matched your search
+15
-3
@@ -286,16 +286,28 @@ function _renderMessagesIntoFragment(fragment, msgs, imageMessageIds, opts) {
|
||||
if (msg._choiceHandled) continue;
|
||||
const prevBoxes = fragment.querySelectorAll('.tool-box');
|
||||
const lastToolBox = prevBoxes[prevBoxes.length - 1];
|
||||
if (lastToolBox && !lastToolBox.querySelector('.tool-result') && !lastToolBox.querySelector('.todo-list')) {
|
||||
if (lastToolBox) {
|
||||
var existingResult = lastToolBox.querySelector('.tool-result');
|
||||
// todo_write: nachträglich die Todo-Liste rendern (sichtbar)
|
||||
if (lastToolBox.dataset.toolName === 'todo_write') {
|
||||
if (lastToolBox.dataset.toolName === 'todo_write' && !lastToolBox.querySelector('.todo-list')) {
|
||||
lastToolBox.appendChild(buildTodoList(msg.content || '', msg.isError));
|
||||
} else {
|
||||
} else if (existingResult && !existingResult.textContent) {
|
||||
// Leeres Result-Div updaten (von renderToolBoxContent mit result=null erstellt)
|
||||
existingResult.textContent = truncate(msg.content || '', 300);
|
||||
if (msg.isError) existingResult.classList.add('tool-error');
|
||||
} else if (!existingResult) {
|
||||
// Neues Result-Div erstellen
|
||||
const rd = document.createElement('div');
|
||||
rd.className = 'tool-result' + (msg.isError ? ' tool-error' : '');
|
||||
rd.textContent = truncate(msg.content || '', 300);
|
||||
rd.hidden = true;
|
||||
lastToolBox.appendChild(rd);
|
||||
// Header clickable machen
|
||||
var hdr = lastToolBox.querySelector('.tool-box-header');
|
||||
if (hdr && !hdr.classList.contains('clickable')) {
|
||||
hdr.classList.add('clickable');
|
||||
hdr.addEventListener('click', function() { rd.hidden = !rd.hidden; });
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
||||
+14
-6
@@ -198,12 +198,14 @@ function renderToolBoxContent(div, rawName, inputJson, result, isError, sources)
|
||||
header.appendChild(inputSpan);
|
||||
}
|
||||
|
||||
const resultDiv = document.createElement('div');
|
||||
resultDiv.className = 'tool-result' + (isError ? ' tool-error' : '');
|
||||
resultDiv.textContent = result || '';
|
||||
resultDiv.hidden = true;
|
||||
div.appendChild(resultDiv);
|
||||
foldTarget = resultDiv;
|
||||
if (result) {
|
||||
const resultDiv = document.createElement('div');
|
||||
resultDiv.className = 'tool-result' + (isError ? ' tool-error' : '');
|
||||
resultDiv.textContent = result;
|
||||
resultDiv.hidden = true;
|
||||
div.appendChild(resultDiv);
|
||||
foldTarget = resultDiv;
|
||||
}
|
||||
}
|
||||
|
||||
if (foldTarget && name !== 'todo_write') {
|
||||
@@ -324,6 +326,12 @@ function appendToolResult(div, result, isError) {
|
||||
rd.textContent = truncate(result, 300);
|
||||
rd.hidden = true;
|
||||
div.appendChild(rd);
|
||||
// Header clickable machen falls noch nicht
|
||||
var hdr = div.querySelector('.tool-box-header');
|
||||
if (hdr && !hdr.classList.contains('clickable')) {
|
||||
hdr.classList.add('clickable');
|
||||
hdr.addEventListener('click', function() { rd.hidden = !rd.hidden; });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user