Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit b3bd933

Browse files
committed
DEV: Add thinking state
1 parent 672dc53 commit b3bd933

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

assets/javascripts/discourse/components/modal/diff-modal.gjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export default class ModalDiffModal extends Component {
140140
"composer-ai-helper-modal__suggestion"
141141
"streamable-content"
142142
(if this.isStreaming "streaming")
143+
(if this.diffStreamer.isThinking "thinking")
143144
(if @model.showResultAsDiff "inline-diff")
144145
}}
145146
>

assets/javascripts/discourse/lib/diff-streamer.gjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export default class DiffStreamer {
1212
@tracked lastResultText = "";
1313
@tracked diff = "";
1414
@tracked suggestion = "";
15+
@tracked isDone = false;
16+
@tracked isThinking = false;
1517
typingTimer = null;
1618
currentWordIndex = 0;
1719

@@ -35,6 +37,7 @@ export default class DiffStreamer {
3537
const newText = result[newTextKey];
3638
const diffText = newText.slice(this.lastResultText.length).trim();
3739
const newWords = diffText.split(/\s+/).filter(Boolean);
40+
this.isDone = result?.done;
3841

3942
if (newWords.length > 0) {
4043
this.isStreaming = true;
@@ -64,14 +67,20 @@ export default class DiffStreamer {
6467
* Highlights the current word if streaming is ongoing.
6568
*/
6669
#streamNextWord() {
67-
if (this.currentWordIndex === this.words.length) {
70+
if (this.currentWordIndex === this.words.length && !this.isDone) {
71+
this.isThinking = true;
72+
}
73+
74+
if (this.currentWordIndex === this.words.length && this.isDone) {
75+
this.isThinking = false;
6876
this.diff = this.#compareText(this.selectedText, this.suggestion, {
6977
markLastWord: false,
7078
});
7179
this.isStreaming = false;
7280
}
7381

7482
if (this.currentWordIndex < this.words.length) {
83+
this.isThinking = false;
7584
this.suggestion += this.words[this.currentWordIndex] + " ";
7685
this.diff = this.#compareText(this.selectedText, this.suggestion, {
7786
markLastWord: true,

assets/stylesheets/common/streaming.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,18 @@ article.streaming .cooked {
7979
}
8080
}
8181
}
82+
83+
@keyframes mark-blink {
84+
0%,
85+
100% {
86+
border-color: var(--highlight-high);
87+
}
88+
89+
50% {
90+
border-color: transparent;
91+
}
92+
}
93+
94+
.composer-ai-helper-modal__suggestion.thinking mark.highlight {
95+
animation: mark-blink 1s step-start 0s infinite;
96+
}

0 commit comments

Comments
 (0)