refactor(term): add mutableRow to terminal api, use it for thinking_tokens

This commit is contained in:
damocles 2026-07-05 12:39:26 +02:00
commit 788673341c
2 changed files with 19 additions and 5 deletions

View file

@ -1933,9 +1933,7 @@ window.marked = marked;
&& thinkingTokensRow.nextElementSibling === null) {
thinkingTokensText.nodeValue = text;
} else {
thinkingTokensRow = api.row('note', '', '🧠');
thinkingTokensText = document.createTextNode(text);
thinkingTokensRow.appendChild(thinkingTokensText);
[thinkingTokensRow, thinkingTokensText] = api.mutableRow('note', text, '🧠');
}
return;
}

View file

@ -215,6 +215,22 @@ export function create(opts) {
afterAppend(wasNearBottom);
return e;
}
// Like row(), but returns [element, textNode] so the caller can update
// the text in place via textNode.nodeValue. Use for rows whose content
// changes after initial render (e.g. live-updating counters).
// Text is stored as a plain text node — no linkify, no innerHTML.
function mutableRow(cls, text, icon) {
clearPlaceholder();
const wasNearBottom = isNearBottom();
const e = document.createElement('div');
e.className = 'row ' + (cls || '') + (currentNoAnim ? ' no-anim' : '');
if (icon != null && icon !== '') e.appendChild(glyphSpan(icon));
const tn = document.createTextNode(text == null ? '' : String(text));
e.appendChild(tn);
log.appendChild(e);
afterAppend(wasNearBottom);
return [e, tn];
}
function details(cls, summary, body, icon) {
clearPlaceholder();
const wasNearBottom = isNearBottom();
@ -253,7 +269,7 @@ export function create(opts) {
function api(extra) {
return Object.assign({
row, details, detailsDiff, placeholder, linkify,
row, mutableRow, details, detailsDiff, placeholder, linkify,
fromHistory: false,
}, extra || {});
}
@ -486,7 +502,7 @@ export function create(opts) {
}
const ready = start();
return { row, details, detailsDiff, placeholder, ready };
return { row, mutableRow, details, detailsDiff, placeholder, ready };
}
// Build a DocumentFragment from `text`, turning bare http(s) URLs into