Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 44 additions & 32 deletions assets/javascripts/discourse/components/modal/diff-modal.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import willDestroy from "@ember/render-modifiers/modifiers/will-destroy";
import { service } from "@ember/service";
import { htmlSafe } from "@ember/template";
import { or } from "truth-helpers";
import CookText from "discourse/components/cook-text";
import DButton from "discourse/components/d-button";
import DModal from "discourse/components/d-modal";
Expand Down Expand Up @@ -41,6 +42,10 @@ export default class ModalDiffModal extends Component {
}

get diffResult() {
if (this.loading) {
return this.escapedSelectedText;
}

if (this.diffStreamer.diff?.length > 0) {
return this.diffStreamer.diff;
}
Expand All @@ -50,10 +55,22 @@ export default class ModalDiffModal extends Component {
return this.escapedSelectedText;
}

get smoothStreamerResult() {
if (this.loading) {
return this.escapedSelectedText;
}

return this.smoothStreamer.renderedText;
}

get isStreaming() {
// diffStreamer stops Streaming when it is finished with a chunk, looking at isDone is safe
// it starts off not done
return !this.diffStreamer.isDone || this.smoothStreamer.isStreaming;
if (this.args.model.showResultAsDiff) {
return !this.diffStreamer.isDone;
}

return this.smoothStreamer.isStreaming;
}

get primaryBtnLabel() {
Expand Down Expand Up @@ -154,42 +171,37 @@ export default class ModalDiffModal extends Component {
{{willDestroy this.cleanup}}
class="text-preview"
>
{{#if this.loading}}
<div class="composer-ai-helper-modal__loading">
{{[email protected]~}}
</div>
{{else}}
<div
class={{concatClass
"composer-ai-helper-modal__suggestion"
"streamable-content"
(if this.isStreaming "streaming")
(if @model.showResultAsDiff "inline-diff")
(if this.diffStreamer.isThinking "thinking")
}}
>
{{~#if @model.showResultAsDiff~}}
<span class="diff-inner">{{htmlSafe this.diffResult}}</span>
<div
class={{concatClass
"composer-ai-helper-modal__suggestion"
"streamable-content"
(if this.isStreaming "streaming")
(if @model.showResultAsDiff "inline-diff")
(if this.diffStreamer.isThinking "thinking")
(if this.loading "composer-ai-helper-modal__loading")
}}
>
{{~#if @model.showResultAsDiff~}}
<span class="diff-inner">{{htmlSafe this.diffResult}}</span>
{{else}}
{{#if (or this.loading this.smoothStreamer.isStreaming)}}
<CookText
@rawText={{this.smoothStreamerResult}}
class="cooked"
/>
{{else}}
{{#if this.smoothStreamer.isStreaming}}
<div class="composer-ai-helper-modal__old-value">
{{~this.escapedSelectedText~}}
</div>
<div class="composer-ai-helper-modal__new-value">
<CookText
@rawText={{this.smoothStreamer.renderedText}}
@rawText={{this.smoothStreamerResult}}
class="cooked"
/>
{{else}}
<div class="composer-ai-helper-modal__old-value">
{{@model.selectedText}}
</div>
<div class="composer-ai-helper-modal__new-value">
<CookText
@rawText={{this.smoothStreamer.renderedText}}
class="cooked"
/>
</div>
{{/if}}
</div>
{{/if}}
</div>
{{/if}}
{{/if}}
</div>
</div>
</:body>

Expand Down
2 changes: 1 addition & 1 deletion assets/stylesheets/common/streaming.scss
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ mark.highlight {
animation-name: mark-blink;
}

.composer-ai-helper-modal__loading {
.composer-ai-helper-modal__loading.inline-diff {
white-space: pre-wrap;
}

Expand Down
14 changes: 9 additions & 5 deletions assets/stylesheets/modules/ai-helper/common/ai-helper.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
@use "lib/viewport";

.composer-ai-helper-modal {
.text-preview,
.inline-diff {
font-family: var(--d-font-family--monospace);
font-variant-ligatures: none;
}

.text-preview,
.inline-diff {
ins {
background-color: var(--success-low);
text-decoration: none;
Expand Down Expand Up @@ -55,13 +57,16 @@
}

&__old-value {
background-color: var(--danger-low);
white-space: pre-wrap;
border-left: 2px solid var(--danger);
padding-left: 1rem;
color: var(--danger);
margin-bottom: 1rem;
}

&__new-value {
background-color: var(--success-low);
border-left: 2px solid var(--success);
padding-left: 1rem;
color: var(--success);
}

Expand All @@ -77,7 +82,6 @@
}

.ai-composer-helper-menu {
padding: 0.25rem;
max-width: 25rem;
list-style: none;

Expand Down Expand Up @@ -701,7 +705,7 @@
width: 100%;
border-radius: 0;
margin: 0;
padding: 0.5em 1rem;
padding: 0.7rem 1rem;

&:focus,
&:hover {
Expand Down
Loading