diff --git a/app/controllers/discourse_ai/ai_bot/conversations_controller.rb b/app/controllers/discourse_ai/ai_bot/conversations_controller.rb deleted file mode 100644 index ee569b8a..00000000 --- a/app/controllers/discourse_ai/ai_bot/conversations_controller.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -module DiscourseAi - module AiBot - class ConversationsController < ::ApplicationController - requires_plugin ::DiscourseAi::PLUGIN_NAME - requires_login - - def index - page = params[:page].to_i - per_page = params[:per_page]&.to_i || 40 - - bot_user_ids = EntryPoint.all_bot_ids - base_query = - Topic - .private_messages_for_user(current_user) - .joins(:topic_users) - .where(topic_users: { user_id: bot_user_ids }) - .distinct - total = base_query.count - pms = base_query.order(last_posted_at: :desc).offset(page * per_page).limit(per_page) - - render json: { - conversations: serialize_data(pms, BasicTopicSerializer), - meta: { - total: total, - page: page, - per_page: per_page, - has_more: total > (page + 1) * per_page, - }, - } - end - end - end -end diff --git a/assets/javascripts/discourse/components/ai-bot-header-icon.gjs b/assets/javascripts/discourse/components/ai-bot-header-icon.gjs index 3cbda25c..1907f517 100644 --- a/assets/javascripts/discourse/components/ai-bot-header-icon.gjs +++ b/assets/javascripts/discourse/components/ai-bot-header-icon.gjs @@ -9,7 +9,6 @@ export default class AiBotHeaderIcon extends Component { @service currentUser; @service siteSettings; @service composer; - @service router; get bots() { const availableBots = this.currentUser.ai_enabled_chat_bots @@ -25,9 +24,6 @@ export default class AiBotHeaderIcon extends Component { @action compose() { - if (this.siteSettings.ai_enable_experimental_bot_ux) { - return this.router.transitionTo("discourse-ai-bot-conversations"); - } composeAiBotMessage(this.bots[0], this.composer); } diff --git a/assets/javascripts/discourse/components/ai-bot-sidebar-new-conversation.gjs b/assets/javascripts/discourse/components/ai-bot-sidebar-new-conversation.gjs deleted file mode 100644 index 915b8283..00000000 --- a/assets/javascripts/discourse/components/ai-bot-sidebar-new-conversation.gjs +++ /dev/null @@ -1,27 +0,0 @@ -import Component from "@glimmer/component"; -import { service } from "@ember/service"; -import DButton from "discourse/components/d-button"; -import { AI_CONVERSATIONS_PANEL } from "../services/ai-conversations-sidebar-manager"; - -export default class AiBotSidebarNewConversation extends Component { - @service router; - @service sidebarState; - - get shouldRender() { - return ( - this.router.currentRouteName !== "discourse-ai-bot-conversations" && - this.sidebarState.isCurrentPanel(AI_CONVERSATIONS_PANEL) - ); - } - - -} diff --git a/assets/javascripts/discourse/controllers/discourse-ai-bot-conversations.js b/assets/javascripts/discourse/controllers/discourse-ai-bot-conversations.js deleted file mode 100644 index c23923a3..00000000 --- a/assets/javascripts/discourse/controllers/discourse-ai-bot-conversations.js +++ /dev/null @@ -1,70 +0,0 @@ -import Controller from "@ember/controller"; -import { action } from "@ember/object"; -import { service } from "@ember/service"; -import { tracked } from "@ember-compat/tracked-built-ins"; - -export default class DiscourseAiBotConversations extends Controller { - @service aiBotConversationsHiddenSubmit; - @service currentUser; - - @tracked selectedPersona = this.personaOptions[0].username; - - textarea = null; - - init() { - super.init(...arguments); - this.selectedPersonaChanged(this.selectedPersona); - } - - get personaOptions() { - if (this.currentUser.ai_enabled_personas) { - return this.currentUser.ai_enabled_personas - .filter((persona) => persona.username) - .map((persona) => { - return { - id: persona.id, - username: persona.username, - name: persona.name, - description: persona.description, - }; - }); - } - } - - get displayPersonaSelector() { - return this.personaOptions.length > 1; - } - - get filterable() { - return this.personaOptions.length > 4; - } - - @action - selectedPersonaChanged(username) { - this.selectedPersona = username; - this.aiBotConversationsHiddenSubmit.personaUsername = username; - } - - @action - updateInputValue(event) { - this._autoExpandTextarea(); - this.aiBotConversationsHiddenSubmit.inputValue = event.target.value; - } - - @action - handleKeyDown(event) { - if (event.key === "Enter" && !event.shiftKey) { - this.aiBotConversationsHiddenSubmit.submitToBot(); - } - } - - @action - setTextArea(element) { - this.textarea = element; - } - - _autoExpandTextarea() { - this.textarea.style.height = "auto"; - this.textarea.style.height = this.textarea.scrollHeight + "px"; - } -} diff --git a/assets/javascripts/discourse/discourse-ai-bot-dashboard-route-map.js b/assets/javascripts/discourse/discourse-ai-bot-dashboard-route-map.js deleted file mode 100644 index 0c5b9213..00000000 --- a/assets/javascripts/discourse/discourse-ai-bot-dashboard-route-map.js +++ /dev/null @@ -1,5 +0,0 @@ -export default function () { - this.route("discourse-ai-bot-conversations", { - path: "/discourse-ai/ai-bot/conversations", - }); -} diff --git a/assets/javascripts/discourse/lib/ai-bot-helper.js b/assets/javascripts/discourse/lib/ai-bot-helper.js index d7fb0132..69832586 100644 --- a/assets/javascripts/discourse/lib/ai-bot-helper.js +++ b/assets/javascripts/discourse/lib/ai-bot-helper.js @@ -23,43 +23,24 @@ export function showShareConversationModal(modal, topicId) { .catch(popupAjaxError); } -export async function composeAiBotMessage( - targetBot, - composer, - options = { - skipFocus: false, - topicBody: "", - personaUsername: null, - } -) { +export function composeAiBotMessage(targetBot, composer) { const currentUser = composer.currentUser; const draftKey = "new_private_message_ai_" + new Date().getTime(); - let botUsername; - if (targetBot) { - botUsername = currentUser.ai_enabled_chat_bots.find( - (bot) => bot.model_name === targetBot - )?.username; - } else if (options.personaUsername) { - botUsername = options.personaUsername; - } else { - botUsername = currentUser.ai_enabled_chat_bots[0].username; - } + let botUsername = currentUser.ai_enabled_chat_bots.find( + (bot) => bot.model_name === targetBot + ).username; - const data = { - action: Composer.PRIVATE_MESSAGE, - recipients: botUsername, - topicTitle: i18n("discourse_ai.ai_bot.default_pm_prefix"), - archetypeId: "private_message", - draftKey, - hasGroups: false, - warningsDisabled: true, - }; - - if (options.skipFocus) { - data.topicBody = options.topicBody; - await composer.open(data); - } else { - composer.focusComposer({ fallbackToNewTopic: true, openOpts: data }); - } + composer.focusComposer({ + fallbackToNewTopic: true, + openOpts: { + action: Composer.PRIVATE_MESSAGE, + recipients: botUsername, + topicTitle: i18n("discourse_ai.ai_bot.default_pm_prefix"), + archetypeId: "private_message", + draftKey, + hasGroups: false, + warningsDisabled: true, + }, + }); } diff --git a/assets/javascripts/discourse/services/ai-bot-conversations-hidden-submit.js b/assets/javascripts/discourse/services/ai-bot-conversations-hidden-submit.js deleted file mode 100644 index 7796007d..00000000 --- a/assets/javascripts/discourse/services/ai-bot-conversations-hidden-submit.js +++ /dev/null @@ -1,62 +0,0 @@ -import { action } from "@ember/object"; -import { next } from "@ember/runloop"; -import Service, { service } from "@ember/service"; -import { popupAjaxError } from "discourse/lib/ajax-error"; -import { i18n } from "discourse-i18n"; -import { composeAiBotMessage } from "../lib/ai-bot-helper"; - -export default class AiBotConversationsHiddenSubmit extends Service { - @service composer; - @service aiConversationsSidebarManager; - @service dialog; - - personaUsername; - - inputValue = ""; - - @action - focusInput() { - this.composer.destroyDraft(); - this.composer.close(); - next(() => { - document.getElementById("custom-homepage-input").focus(); - }); - } - - @action - async submitToBot() { - this.composer.destroyDraft(); - this.composer.close(); - - if (this.inputValue.length < 10) { - return this.dialog.alert({ - message: i18n( - "discourse_ai.ai_bot.conversations.min_input_length_message" - ), - didConfirm: () => this.focusInput(), - didCancel: () => this.focusInput(), - }); - } - - // we are intentionally passing null as the targetBot to allow for the - // function to select the first available bot. This will be refactored in the - // future to allow for selecting a specific bot. - await composeAiBotMessage(null, this.composer, { - skipFocus: true, - topicBody: this.inputValue, - personaUsername: this.personaUsername, - }); - - try { - await this.composer.save(); - this.aiConversationsSidebarManager.newTopicForceSidebar = true; - if (this.inputValue.length > 10) { - // prevents submitting same message again when returning home - // but avoids deleting too-short message on submit - this.inputValue = ""; - } - } catch (e) { - popupAjaxError(e); - } - } -} diff --git a/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js b/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js deleted file mode 100644 index ce41d0f1..00000000 --- a/assets/javascripts/discourse/services/ai-conversations-sidebar-manager.js +++ /dev/null @@ -1,40 +0,0 @@ -import { tracked } from "@glimmer/tracking"; -import Service, { service } from "@ember/service"; -import { ADMIN_PANEL, MAIN_PANEL } from "discourse/lib/sidebar/panels"; - -export const AI_CONVERSATIONS_PANEL = "ai-conversations"; - -export default class AiConversationsSidebarManager extends Service { - @service sidebarState; - - @tracked newTopicForceSidebar = false; - - forceCustomSidebar() { - // Set the panel to your custom panel - this.sidebarState.setPanel(AI_CONVERSATIONS_PANEL); - - // Use separated mode to ensure independence from hamburger menu - this.sidebarState.setSeparatedMode(); - - // Hide panel switching buttons to keep UI clean - this.sidebarState.hideSwitchPanelButtons(); - - this.sidebarState.isForcingSidebar = true; - document.body.classList.add("has-ai-conversations-sidebar"); - return true; - } - - stopForcingCustomSidebar() { - // This method is called when leaving your route - // Only restore main panel if we previously forced ours - document.body.classList.remove("has-ai-conversations-sidebar"); - const isAdminSidebarActive = - this.sidebarState.currentPanel?.key === ADMIN_PANEL; - // only restore main panel if we previously forced our sidebar - // and not if we are in admin sidebar - if (this.sidebarState.isForcingSidebar && !isAdminSidebarActive) { - this.sidebarState.setPanel(MAIN_PANEL); // Return to main sidebar panel - this.sidebarState.isForcingSidebar = false; - } - } -} diff --git a/assets/javascripts/discourse/templates/discourse-ai-bot-conversations.gjs b/assets/javascripts/discourse/templates/discourse-ai-bot-conversations.gjs deleted file mode 100644 index 0085e06b..00000000 --- a/assets/javascripts/discourse/templates/discourse-ai-bot-conversations.gjs +++ /dev/null @@ -1,51 +0,0 @@ -import { hash } from "@ember/helper"; -import { on } from "@ember/modifier"; -import didInsert from "@ember/render-modifiers/modifiers/did-insert"; -import RouteTemplate from "ember-route-template"; -import DButton from "discourse/components/d-button"; -import { i18n } from "discourse-i18n"; -import DropdownSelectBox from "select-kit/components/dropdown-select-box"; - -export default RouteTemplate( -