Skip to content

A platform for community discussion. Free, open, simple.

UX: Refine AI bot conversation page and composer (#40457)

Keegan George1f42822a370f
diff --git a/frontend/discourse/app/controllers/topic.js b/frontend/discourse/app/controllers/topic.js
index 906e7dffc13..3d61e2ed71b 100644
--- a/frontend/discourse/app/controllers/topic.js
+++ b/frontend/discourse/app/controllers/topic.js
@@ -37,7 +37,10 @@ import QuoteState from "discourse/lib/quote-state";
import { extractLinkMeta } from "discourse/lib/render-topic-featured-link";
import { fancyTitle } from "discourse/lib/topic-fancy-title";
import { autoTrackedArray } from "discourse/lib/tracked-tools";
-import { applyBehaviorTransformer } from "discourse/lib/transformer";
+import {
+ applyBehaviorTransformer,
+ applyValueTransformer,
+} from "discourse/lib/transformer";
import DiscourseURL, { userPath } from "discourse/lib/url";
import { escapeExpression } from "discourse/lib/utilities";
import Bookmark, { AUTO_DELETE_PREFERENCES } from "discourse/models/bookmark";
@@ -321,6 +324,12 @@ export default class TopicController extends Controller {
"model.word_count",
"model.postStream.loadingFilter"
)
+ get showTopicFooterButtons() {
+ return applyValueTransformer("topic-show-footer-buttons", true, {
+ topic: this.model,
+ });
+ }
+
get showBottomTopicMap() {
// filter out small posts, because they're short
const postsCount =
diff --git a/frontend/discourse/app/lib/registry/transformers.js b/frontend/discourse/app/lib/registry/transformers.js
index 0b02e60e007..a455ab53612 100644
--- a/frontend/discourse/app/lib/registry/transformers.js
+++ b/frontend/discourse/app/lib/registry/transformers.js
@@ -118,6 +118,7 @@ export const VALUE_TRANSFORMERS = Object.freeze([
"topic-list-item-expand-pinned",
"topic-list-item-mobile-layout",
"topic-list-item-style",
+ "topic-show-footer-buttons",
"user-field-components",
"user-menu-notification-item-acting-user-avatar",
"user-notes-modal-subtitle",
diff --git a/frontend/discourse/app/templates/topic.gjs b/frontend/discourse/app/templates/topic.gjs
index e03c1b6dec4..31d95ac60c5 100644
--- a/frontend/discourse/app/templates/topic.gjs
+++ b/frontend/discourse/app/templates/topic.gjs
@@ -586,28 +586,32 @@ export default <template>
/>
</span>
- <TopicFooterButtons
- @topic={{@controller.model}}
- @toggleMultiSelect={{@controller.toggleMultiSelect}}
- @showTopicSlowModeUpdate={{routeAction "showTopicSlowModeUpdate"}}
- @deleteTopic={{@controller.deleteTopic}}
- @recoverTopic={{@controller.recoverTopic}}
- @toggleClosed={{@controller.toggleClosed}}
- @toggleArchived={{@controller.toggleArchived}}
- @toggleVisibility={{@controller.toggleVisibility}}
- @showTopicTimerModal={{routeAction "showTopicTimerModal"}}
- @showFeatureTopic={{routeAction "showFeatureTopic"}}
- @showChangeTimestamp={{routeAction "showChangeTimestamp"}}
- @resetBumpDate={{@controller.resetBumpDate}}
- @convertToPublicTopic={{@controller.convertToPublicTopic}}
- @convertToPrivateMessage={{@controller.convertToPrivateMessage}}
- @toggleBookmark={{@controller.toggleBookmark}}
- @showFlagTopic={{routeAction "showFlagTopic"}}
- @toggleArchiveMessage={{@controller.toggleArchiveMessage}}
- @editFirstPost={{@controller.editFirstPost}}
- @deferTopic={{@controller.deferTopic}}
- @replyToPost={{@controller.replyToPost}}
- />
+ {{#if @controller.showTopicFooterButtons}}
+ <TopicFooterButtons
+ @topic={{@controller.model}}
+ @toggleMultiSelect={{@controller.toggleMultiSelect}}
+ @showTopicSlowModeUpdate={{routeAction
+ "showTopicSlowModeUpdate"
+ }}
+ @deleteTopic={{@controller.deleteTopic}}
+ @recoverTopic={{@controller.recoverTopic}}
+ @toggleClosed={{@controller.toggleClosed}}
+ @toggleArchived={{@controller.toggleArchived}}
+ @toggleVisibility={{@controller.toggleVisibility}}
+ @showTopicTimerModal={{routeAction "showTopicTimerModal"}}
+ @showFeatureTopic={{routeAction "showFeatureTopic"}}
+ @showChangeTimestamp={{routeAction "showChangeTimestamp"}}
+ @resetBumpDate={{@controller.resetBumpDate}}
+ @convertToPublicTopic={{@controller.convertToPublicTopic}}
+ @convertToPrivateMessage={{@controller.convertToPrivateMessage}}
+ @toggleBookmark={{@controller.toggleBookmark}}
+ @showFlagTopic={{routeAction "showFlagTopic"}}
+ @toggleArchiveMessage={{@controller.toggleArchiveMessage}}
+ @editFirstPost={{@controller.editFirstPost}}
+ @deferTopic={{@controller.deferTopic}}
+ @replyToPost={{@controller.replyToPost}}
+ />
+ {{/if}}
{{else}}
<AnonymousTopicFooterButtons @topic={{@controller.model}} />
{{/if}}
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-bot-docked-composer.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-bot-docked-composer.gjs
index ca3c2f1d5c8..7026152805c 100644
--- a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-bot-docked-composer.gjs
+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-bot-docked-composer.gjs
@@ -37,7 +37,6 @@ export default class AiBotDockedComposer extends Component {
@tracked showToolbar = false;
@tracked hasContentBelow = false;
- @tracked atAbsoluteBottom = false;
@tracked editingPost = null;
@tracked pendingBotReply = false;
@@ -66,9 +65,6 @@ export default class AiBotDockedComposer extends Component {
if (this.hasContentBelow) {
this.hasContentBelow = false;
}
- if (!this.atAbsoluteBottom) {
- this.atAbsoluteBottom = true;
- }
return;
}
@@ -77,16 +73,6 @@ export default class AiBotDockedComposer extends Component {
if (hasContentBelow !== this.hasContentBelow) {
this.hasContentBelow = hasContentBelow;
}
-
- // Two thresholds (show at 60px, hide at 140px) prevent the disclaimer
- // from toggling itself: appearing adds height, which shifts the scroll
- // position and would immediately hide it again in a loop on Firefox.
- const nearBottom = this.atAbsoluteBottom
- ? distFromBottom <= 140
- : distFromBottom <= 60;
- if (nearBottom !== this.atAbsoluteBottom) {
- this.atAbsoluteBottom = nearBottom;
- }
};
#alignWithPost = () => {
@@ -588,11 +574,6 @@ export default class AiBotDockedComposer extends Component {
{{/if}}
</button>
{{/if}}
- {{#if this.atAbsoluteBottom}}
- <p class="ai-bot-docked-composer__disclaimer">
- {{i18n "discourse_ai.ai_bot.conversations.disclaimer"}}
- </p>
- {{/if}}
</:default>
</DockedComposer>
</template>
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-conversation-sidebar-context-menu.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-conversation-sidebar-context-menu.gjs
index a510ecf8068..606a146b5c8 100644
--- a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-conversation-sidebar-context-menu.gjs
+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-conversation-sidebar-context-menu.gjs
@@ -1,10 +1,15 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
+import { service } from "@ember/service";
import DButton from "discourse/ui-kit/d-button";
import DDropdownMenu from "discourse/ui-kit/d-dropdown-menu";
+import { showShareConversationModal } from "../lib/ai-bot-helper";
export default class AiConversationSidebarContextMenu extends Component {
+ @service currentUser;
+ @service modal;
+
@tracked isTogglingStarred = false;
get topic() {
@@ -19,6 +24,10 @@ export default class AiConversationSidebarContextMenu extends Component {
return this.manager.siteSettings.enable_ai_bot_starred_conversations;
}
+ get canShare() {
+ return this.currentUser?.can_share_ai_bot_conversations;
+ }
+
get isStarred() {
return !!this.topic?.ai_conversation_starred;
}
@@ -49,6 +58,16 @@ export default class AiConversationSidebarContextMenu extends Component {
}
}
+ @action
+ share() {
+ if (!this.canShare || !this.topic) {
+ return;
+ }
+
+ showShareConversationModal(this.modal, this.topic.id);
+ this.args.close();
+ }
+
<template>
<DDropdownMenu class="ai-conversation-sidebar-link-menu" as |dropdown|>
{{#if this.canStarConversations}}
@@ -63,6 +82,17 @@ export default class AiConversationSidebarContextMenu extends Component {
/>
</dropdown.item>
{{/if}}
+ {{#if this.canShare}}
+ <dropdown.item>
+ <DButton
+ @action={{this.share}}
+ @icon="share-nodes"
+ @label="discourse_ai.ai_bot.share_ai_conversation.name"
+ @title="discourse_ai.ai_bot.share_ai_conversation.title"
+ class="ai-conversation-sidebar-link-menu__share-conversation"
+ />
+ </dropdown.item>
+ {{/if}}
</DDropdownMenu>
</template>
}
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/initializers/ai-bot-replies.js b/plugins/discourse-ai/assets/javascripts/discourse/initializers/ai-bot-replies.js
index c1c311f770f..f8a14655f9c 100644
--- a/plugins/discourse-ai/assets/javascripts/discourse/initializers/ai-bot-replies.js
+++ b/plugins/discourse-ai/assets/javascripts/discourse/initializers/ai-bot-replies.js
@@ -7,7 +7,7 @@ import AiCancelStreamingButton from "../components/post-menu/ai-cancel-streaming
import AiDebugButton from "../components/post-menu/ai-debug-button";
import AiRetryStreamingButton from "../components/post-menu/ai-retry-streaming-button";
import AiShareButton from "../components/post-menu/ai-share-button";
-import { isGPTBot, showShareConversationModal } from "../lib/ai-bot-helper";
+import { isGPTBot } from "../lib/ai-bot-helper";
import {
cleanupStreamingData,
streamPostText,
@@ -264,26 +264,20 @@ function initializeShareButton(api) {
);
}
-function initializeShareTopicButton(api) {
- const modal = api.container.lookup("service:modal");
- const currentUser = api.container.lookup("service:current-user");
-
- api.registerTopicFooterButton({
- id: "share-ai-conversation",
- icon: "share-nodes",
- label: "discourse_ai.ai_bot.share_ai_conversation.name",
- title: "discourse_ai.ai_bot.share_ai_conversation.title",
- action() {
- showShareConversationModal(modal, this.topic.id);
- },
- classNames: ["share-ai-conversation-button"],
- dependentKeys: ["topic.ai_agent_name"],
- displayed() {
- return (
- currentUser?.can_share_ai_bot_conversations && this.topic.ai_agent_name
- );
- },
- });
+function initializeFooterButtonsVisibility(api) {
+ const siteSettings = api.container.lookup("service:site-settings");
+
+ api.registerValueTransformer(
+ "topic-show-footer-buttons",
+ ({ value, context: { topic } }) => {
+ // On AI bot PMs the docked composer replaces the topic footer, so its
+ // buttons (reply, admin wrench, etc.) are redundant — skip rendering it.
+ if (siteSettings.ai_bot_enable_docked_composer && topic?.is_bot_pm) {
+ return false;
+ }
+ return value;
+ }
+ );
}
export default {
@@ -301,7 +295,7 @@ export default {
initializeAgentDecorator(api);
initializeDebugButton(api, container);
initializeShareButton(api, container);
- initializeShareTopicButton(api, container);
+ initializeFooterButtonsVisibility(api);
initializeRetryButton(api);
});
}
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js b/plugins/discourse-ai/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js
index 479dcc532db..3014043b07b 100644
--- a/plugins/discourse-ai/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js
+++ b/plugins/discourse-ai/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js
@@ -26,6 +26,7 @@ export default class AiConversationsSidebarManager extends Service {
@service router;
@service menu;
@service capabilities;
+ @service currentUser;
@service siteSettings;
@tracked topics = [];
@@ -486,7 +487,8 @@ export default class AiConversationsSidebarManager extends Service {
_conversationLink(topic) {
const isStarred = !!topic.ai_conversation_starred;
const canShowConversationMenu =
- this.siteSettings.enable_ai_bot_starred_conversations &&
+ (this.siteSettings.enable_ai_bot_starred_conversations ||
+ this.currentUser?.can_share_ai_bot_conversations) &&
!this.capabilities.isIpadOS;
return {
diff --git a/plugins/discourse-ai/assets/stylesheets/modules/ai-bot-conversations/common.scss b/plugins/discourse-ai/assets/stylesheets/modules/ai-bot-conversations/common.scss
index 9e272ec6f32..b77d0d2f443 100644
--- a/plugins/discourse-ai/assets/stylesheets/modules/ai-bot-conversations/common.scss
+++ b/plugins/discourse-ai/assets/stylesheets/modules/ai-bot-conversations/common.scss
@@ -52,6 +52,11 @@ body.has-ai-conversations-sidebar {
display: none;
}
+ // "Powered by Discourse" is redundant chrome on the AI conversations surface
+ .powered-by-discourse {
+ display: none;
+ }
+
// topic elements
#topic-footer-button-share-and-invite,
body:not(.staff) #topic-footer-button-archive,
@@ -375,10 +380,6 @@ body.has-ai-conversations-sidebar {
.sidebar-footer-wrapper {
display: flex;
- .powered-by-discourse {
- display: block;
- }
-
button {
display: none;
}
@@ -422,18 +423,6 @@ body.has-ai-conversations-sidebar {
}
}
- @include viewport.until(sm) {
- .share-ai-conversation-button {
- .d-icon {
- margin: 0;
- }
-
- .d-button-label {
- display: none;
- }
- }
- }
-
// custom user card link
.user-card-meta__profile-link {
display: block;
@@ -450,16 +439,6 @@ body.has-ai-conversations-sidebar {
display: none;
}
- .topic-footer-main-buttons {
- button:not(
- .create,
- .share-ai-conversation-button,
- .topic-admin-menu-trigger
- ) {
- display: none;
- }
- }
-
.topic-map {
box-sizing: border-box;
width: 100%;
@@ -474,8 +453,10 @@ body.has-ai-conversations-sidebar {
display: none;
}
+ // The bottom topic map (participants + invite) is redundant on the AI
+ // conversation page — the docked composer sits where it would render.
&.--bottom {
- padding-top: 0;
+ display: none;
}
section {
diff --git a/plugins/discourse-ai/assets/stylesheets/modules/ai-bot-conversations/docked-composer.scss b/plugins/discourse-ai/assets/stylesheets/modules/ai-bot-conversations/docked-composer.scss
index 36817fe4935..9876fa56687 100644
--- a/plugins/discourse-ai/assets/stylesheets/modules/ai-bot-conversations/docked-composer.scss
+++ b/plugins/discourse-ai/assets/stylesheets/modules/ai-bot-conversations/docked-composer.scss
@@ -108,7 +108,15 @@ body.has-ai-bot-docked-composer {
border: var(--d-input-border);
border-color: var(--content-border-color);
border-radius: var(--d-input-border-radius);
- background: var(--d-input-bg-color);
+
+ // Match the chat input's light grey, but composited over an opaque base so
+ // topic content doesn't show through the input while scrolling (the docked
+ // composer's container is transparent, unlike chat's opaque pane).
+ background-color: var(--secondary);
+ background-image: linear-gradient(
+ rgb(var(--primary-very-low-rgb), 0.5),
+ rgb(var(--primary-very-low-rgb), 0.5)
+ );
transition: border-color 0.15s ease-in-out;
position: relative;
@@ -345,14 +353,3 @@ body.has-ai-bot-docked-composer [data-user-id^="-"] .cooked {
transform: translateY(0);
}
}
-
-.ai-bot-docked-composer__disclaimer {
- margin: var(--space-2) 0 var(--space-4);
- text-align: center;
- font-size: var(--font-down-2);
- color: var(--primary-medium);
-
- @include viewport.until(sm) {
- display: none;
- }
-}
diff --git a/plugins/discourse-ai/spec/system/ai_bot/ai_conversation_sidebar_share_spec.rb b/plugins/discourse-ai/spec/system/ai_bot/ai_conversation_sidebar_share_spec.rb
new file mode 100644
index 00000000000..0929f27c918
--- /dev/null
+++ b/plugins/discourse-ai/spec/system/ai_bot/ai_conversation_sidebar_share_spec.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+RSpec.describe "AI Bot conversation sidebar share" do
+ fab!(:admin) { Fabricate(:admin, username: "ai_sharer") }
+ fab!(:gpt_4) { Fabricate(:llm_model, name: "gpt-4") }
+ let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model("gpt-4") }
+
+ let(:pm) do
+ Fabricate(
+ :private_message_topic,
+ title: "Shareable AI conversation",
+ user: admin,
+ last_posted_at: 1.minute.ago,
+ topic_allowed_users: [
+ Fabricate.build(:topic_allowed_user, user: admin),
+ Fabricate.build(:topic_allowed_user, user: bot_user),
+ ],
+ )
+ end
+
+ let(:ai_pm_homepage) { PageObjects::Components::AiPmHomepage.new }
+
+ before do
+ enable_current_plugin
+ SiteSetting.ai_bot_enabled = true
+ # Starring is intentionally disabled to prove the conversation menu still
+ # appears (and exposes Share) purely on the strength of sharing access.
+ SiteSetting.enable_ai_bot_starred_conversations = false
+ SiteSetting.ai_bot_public_sharing_allowed_groups = "1" # admins
+ SiteSetting.navigation_menu = "sidebar"
+ toggle_enabled_bots(bots: [gpt_4])
+ Group.refresh_automatic_groups!
+
+ pm.custom_fields[DiscourseAi::AiBot::TOPIC_AI_BOT_PM_FIELD] = "t"
+ pm.save!
+ Fabricate(:post, topic: pm, user: admin, raw: "How do I do stuff?")
+ Fabricate(:post, topic: pm, user: bot_user, raw: "Here is how you do stuff")
+
+ sign_in(admin)
+ end
+
+ it "shows Share in the conversation menu when starring is disabled" do
+ page.visit(Topic.relative_url(pm.id, pm.slug))
+
+ ai_pm_homepage.open_conversation_menu(pm)
+
+ expect(ai_pm_homepage).to have_share_conversation_menu_item
+ expect(ai_pm_homepage).to have_no_star_conversation_menu_item
+ end
+
+ it "opens the share modal from the conversation menu" do
+ page.visit(Topic.relative_url(pm.id, pm.slug))
+
+ ai_pm_homepage.share_conversation(pm)
+
+ expect(page).to have_css(".ai-share-full-topic-modal")
+ end
+end
diff --git a/plugins/discourse-ai/spec/system/ai_bot/docked_composer_spec.rb b/plugins/discourse-ai/spec/system/ai_bot/docked_composer_spec.rb
index bf495354313..c8e42592cd4 100644
--- a/plugins/discourse-ai/spec/system/ai_bot/docked_composer_spec.rb
+++ b/plugins/discourse-ai/spec/system/ai_bot/docked_composer_spec.rb
@@ -58,7 +58,9 @@ RSpec.describe "AI Bot docked composer" do
expect(page).to have_css(".ai-bot-docked-composer")
expect(page).to have_css(".ai-bot-docked-composer .d-editor-input")
- expect(page).to have_no_css("#topic-footer-buttons .create")
+ # The docked composer replaces the topic footer entirely, so it is not
+ # rendered (rather than hidden via CSS).
+ expect(page).to have_no_css("#topic-footer-buttons")
end
it "sends a reply via the docked composer when pressing Enter" do
diff --git a/plugins/discourse-ai/spec/system/page_objects/components/ai_pm_homepage.rb b/plugins/discourse-ai/spec/system/page_objects/components/ai_pm_homepage.rb
index 494ce550303..9fad8c32392 100644
--- a/plugins/discourse-ai/spec/system/page_objects/components/ai_pm_homepage.rb
+++ b/plugins/discourse-ai/spec/system/page_objects/components/ai_pm_homepage.rb
@@ -88,12 +88,29 @@ module PageObjects
page.has_no_css?("#sidebar-section-content-starred-conversations")
end
- def toggle_star_for_conversation(topic)
+ def open_conversation_menu(topic)
conversation_link(topic).hover
conversation_link(topic).find(".sidebar-section-hover-button").click
+ end
+
+ def toggle_star_for_conversation(topic)
+ open_conversation_menu(topic)
page.find(".ai-conversation-sidebar-link-menu__star-conversation").click
end
+ def share_conversation(topic)
+ open_conversation_menu(topic)
+ page.find(".ai-conversation-sidebar-link-menu__share-conversation").click
+ end
+
+ def has_share_conversation_menu_item?
+ page.has_css?(".ai-conversation-sidebar-link-menu__share-conversation")
+ end
+
+ def has_no_star_conversation_menu_item?
+ page.has_no_css?(".ai-conversation-sidebar-link-menu__star-conversation")
+ end
+
def has_no_sidebar_back_link?
page.has_no_css?(".sidebar-sections__back-to-forum")
end