Skip to content

DEV: Temporarily suppress diff animation as we fix issues #1341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2025
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
22 changes: 16 additions & 6 deletions assets/javascripts/discourse/components/modal/diff-modal.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,21 @@ export default class ModalDiffModal extends Component {

@tracked loading = false;
@tracked finalResult = "";
@tracked showcasedDiff = "";
@tracked diffStreamer = new DiffStreamer(this.args.model.selectedText);
@tracked suggestion = "";
@tracked
smoothStreamer = new SmoothStreamer(
() => this.suggestion,
(newValue) => (this.suggestion = newValue)
);
@tracked isStreaming = false;

constructor() {
super(...arguments);
this.suggestChanges();
}

get isStreaming() {
return this.diffStreamer.isStreaming || this.smoothStreamer.isStreaming;
}

get primaryBtnLabel() {
return this.loading
? i18n("discourse_ai.ai_helper.context_menu.loading")
Expand All @@ -64,12 +62,25 @@ export default class ModalDiffModal extends Component {

@action
async updateResult(result) {
// TODO(@keegan)
// Temporarily we are removing the animation using the diff streamer
// and simply showing the diff streamed without a proper animation
// while we figure things out
// so that things are not too janky in the meantime.
this.loading = false;
this.isStreaming = true;

if (result.done) {
this.finalResult = result.result;
}

this.showcasedDiff = result.diff;

if (result.done) {
this.loading = false;
this.isStreaming = false;
}

if (this.args.model.showResultAsDiff) {
this.diffStreamer.updateResult(result, "result");
} else {
Expand Down Expand Up @@ -140,12 +151,11 @@ export default class ModalDiffModal extends Component {
"composer-ai-helper-modal__suggestion"
"streamable-content"
(if this.isStreaming "streaming")
(if this.diffStreamer.isThinking "thinking")
(if @model.showResultAsDiff "inline-diff")
}}
>
{{#if @model.showResultAsDiff}}
{{htmlSafe this.diffStreamer.diff}}
{{htmlSafe this.showcasedDiff}}
{{else}}
{{#if this.smoothStreamer.isStreaming}}
<CookText
Expand Down
8 changes: 3 additions & 5 deletions lib/ai_helper/assistant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,9 @@ def stream_prompt(completion_prompt, input, user, channel, force_default_locale:
if (streamed_result.length > 10 && (Time.now - start > 0.3)) || Rails.env.test?
sanitized = sanitize_result(streamed_result)

if DiscourseAi::Utils::DiffUtils::SafetyChecker.safe_to_stream?(sanitized)
payload = { result: sanitized, diff: streamed_diff, done: false }
publish_update(channel, payload, user)
start = Time.now
end
payload = { result: sanitized, diff: streamed_diff, done: false }
publish_update(channel, payload, user)
start = Time.now
end
end

Expand Down
Loading