Skip to content

Commit 35c079d

Browse files
committed
fix: rotate activity text when tool stream preview goes stale
When a tool (e.g. Write) streams slowly, the "receiving N bytes..." preview would freeze. After 2s of no updates, rotate through "Working...", "Writing...", "Processing..." every 3s so the user sees the operation is still in progress. Timers are cleaned up when tool info arrives.
1 parent 0faccc5 commit 35c079d

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/core-ai/AIChatPanel.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ define(function (require, exports, module) {
4848
// --- AI event trace logging (compact, non-flooding) ---
4949
let _traceTextChunks = 0;
5050
let _traceToolStreamCounts = {}; // toolId → count
51+
let _toolStreamStaleTimer = null; // timer to start rotating activity text
52+
let _toolStreamRotateTimer = null; // interval for cycling activity phrases
5153

5254
// DOM references
5355
let $panel, $messages, $status, $statusText, $textarea, $sendBtn, $stopBtn;
@@ -420,6 +422,32 @@ define(function (require, exports, module) {
420422
$tool.find(".ai-tool-preview").text(preview);
421423
_scrollToBottom();
422424
}
425+
426+
// Reset staleness timer — if no new stream event arrives within 2s,
427+
// rotate through activity phrases so the user sees something is happening.
428+
clearTimeout(_toolStreamStaleTimer);
429+
clearInterval(_toolStreamRotateTimer);
430+
_toolStreamStaleTimer = setTimeout(function () {
431+
const phrases = [
432+
Strings.AI_CHAT_WORKING,
433+
Strings.AI_CHAT_WRITING,
434+
Strings.AI_CHAT_PROCESSING
435+
];
436+
let idx = 0;
437+
const $livePreview = $tool.find(".ai-tool-preview");
438+
if ($livePreview.length && !$tool.hasClass("ai-tool-done")) {
439+
$livePreview.text(phrases[idx]);
440+
}
441+
_toolStreamRotateTimer = setInterval(function () {
442+
idx = (idx + 1) % phrases.length;
443+
const $p = $tool.find(".ai-tool-preview");
444+
if ($p.length && !$tool.hasClass("ai-tool-done")) {
445+
$p.text(phrases[idx]);
446+
} else {
447+
clearInterval(_toolStreamRotateTimer);
448+
}
449+
}, 3000);
450+
}, 2000);
423451
}
424452

425453
/**
@@ -925,6 +953,10 @@ define(function (require, exports, module) {
925953
}).css("cursor", "pointer").addClass("ai-tool-label-clickable");
926954
}
927955

956+
// Clear any stale-preview timers now that tool info arrived
957+
clearTimeout(_toolStreamStaleTimer);
958+
clearInterval(_toolStreamRotateTimer);
959+
928960
// Delay marking as done so the streaming preview stays visible briefly.
929961
// The ai-tool-done class hides the preview via CSS; deferring it lets the
930962
// browser paint the preview before it disappears.

src/nls/root/strings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,9 @@ define({
18441844
"AI_CHAT_LABEL_CLAUDE": "Claude",
18451845
"AI_CHAT_SEND_ERROR": "Failed to send message: {0}",
18461846
"AI_CHAT_EDIT_NOT_FOUND": "Text not found in file \u2014 it may have changed",
1847+
"AI_CHAT_WORKING": "Working...",
1848+
"AI_CHAT_WRITING": "Writing...",
1849+
"AI_CHAT_PROCESSING": "Processing...",
18471850

18481851
// demo start - Phoenix Code Playground - Interactive Onboarding
18491852
"DEMO_SECTION1_TITLE": "Edit in Live Preview",

0 commit comments

Comments
 (0)