diff --git a/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-llms-show.js b/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-llms-edit.js similarity index 89% rename from admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-llms-show.js rename to admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-llms-edit.js index a72ce488..8230211c 100644 --- a/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-llms-show.js +++ b/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-llms-edit.js @@ -1,6 +1,6 @@ import DiscourseRoute from "discourse/routes/discourse"; -export default class AdminPluginsShowDiscourseAiLlmsShow extends DiscourseRoute { +export default class AdminPluginsShowDiscourseAiLlmsEdit extends DiscourseRoute { async model(params) { const allLlms = this.modelFor("adminPlugins.show.discourse-ai-llms"); const id = parseInt(params.id, 10); diff --git a/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas-show.js b/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas-edit.js similarity index 88% rename from admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas-show.js rename to admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas-edit.js index 16748ab6..8b5fdd02 100644 --- a/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas-show.js +++ b/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-personas-edit.js @@ -1,6 +1,6 @@ import DiscourseRoute from "discourse/routes/discourse"; -export default class AdminPluginsShowDiscourseAiPersonasShow extends DiscourseRoute { +export default class AdminPluginsShowDiscourseAiPersonasEdit extends DiscourseRoute { async model(params) { const allPersonas = this.modelFor( "adminPlugins.show.discourse-ai-personas" diff --git a/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-tools-show.js b/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-tools-edit.js similarity index 89% rename from admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-tools-show.js rename to admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-tools-edit.js index c76083b2..7ba40586 100644 --- a/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-tools-show.js +++ b/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-ai-tools-edit.js @@ -1,6 +1,6 @@ import DiscourseRoute from "discourse/routes/discourse"; -export default class DiscourseAiToolsShowRoute extends DiscourseRoute { +export default class DiscourseAiToolsEditRoute extends DiscourseRoute { async model(params) { const allTools = this.modelFor("adminPlugins.show.discourse-ai-tools"); const id = parseInt(params.id, 10); diff --git a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-llms/show.hbs b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-llms/edit.hbs similarity index 100% rename from admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-llms/show.hbs rename to admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-llms/edit.hbs diff --git a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-personas/show.hbs b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-personas/edit.hbs similarity index 100% rename from admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-personas/show.hbs rename to admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-personas/edit.hbs diff --git a/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-tools/show.hbs b/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-tools/edit.hbs similarity index 100% rename from admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-tools/show.hbs rename to admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-tools/edit.hbs diff --git a/app/controllers/discourse_ai/admin/ai_llms_controller.rb b/app/controllers/discourse_ai/admin/ai_llms_controller.rb index 3727a090..b7cc9234 100644 --- a/app/controllers/discourse_ai/admin/ai_llms_controller.rb +++ b/app/controllers/discourse_ai/admin/ai_llms_controller.rb @@ -30,7 +30,10 @@ module DiscourseAi } end - def show + def new + end + + def edit llm_model = LlmModel.find(params[:id]) render json: LlmModelSerializer.new(llm_model) end diff --git a/app/controllers/discourse_ai/admin/ai_personas_controller.rb b/app/controllers/discourse_ai/admin/ai_personas_controller.rb index cac72815..dd824735 100644 --- a/app/controllers/discourse_ai/admin/ai_personas_controller.rb +++ b/app/controllers/discourse_ai/admin/ai_personas_controller.rb @@ -5,7 +5,7 @@ module DiscourseAi class AiPersonasController < ::Admin::AdminController requires_plugin ::DiscourseAi::PLUGIN_NAME - before_action :find_ai_persona, only: %i[show update destroy create_user] + before_action :find_ai_persona, only: %i[edit update destroy create_user] def index ai_personas = @@ -33,7 +33,10 @@ module DiscourseAi render json: { ai_personas: ai_personas, meta: { tools: tools, llms: llms } } end - def show + def new + end + + def edit render json: LocalizedAiPersonaSerializer.new(@ai_persona) end diff --git a/app/controllers/discourse_ai/admin/ai_tools_controller.rb b/app/controllers/discourse_ai/admin/ai_tools_controller.rb index 92f5905c..c8a85c60 100644 --- a/app/controllers/discourse_ai/admin/ai_tools_controller.rb +++ b/app/controllers/discourse_ai/admin/ai_tools_controller.rb @@ -5,14 +5,17 @@ module DiscourseAi class AiToolsController < ::Admin::AdminController requires_plugin ::DiscourseAi::PLUGIN_NAME - before_action :find_ai_tool, only: %i[test show update destroy] + before_action :find_ai_tool, only: %i[test edit update destroy] def index ai_tools = AiTool.all render_serialized({ ai_tools: ai_tools }, AiCustomToolListSerializer, root: false) end - def show + def new + end + + def edit render_serialized(@ai_tool, AiCustomToolSerializer) end diff --git a/assets/javascripts/discourse/admin-discourse-ai-plugin-route-map.js b/assets/javascripts/discourse/admin-discourse-ai-plugin-route-map.js index 5e526247..e4c49570 100644 --- a/assets/javascripts/discourse/admin-discourse-ai-plugin-route-map.js +++ b/assets/javascripts/discourse/admin-discourse-ai-plugin-route-map.js @@ -6,17 +6,17 @@ export default { map() { this.route("discourse-ai-personas", { path: "ai-personas" }, function () { this.route("new"); - this.route("show", { path: "/:id" }); + this.route("edit", { path: "/:id/edit" }); }); this.route("discourse-ai-llms", { path: "ai-llms" }, function () { this.route("new"); - this.route("show", { path: "/:id" }); + this.route("edit", { path: "/:id/edit" }); }); this.route("discourse-ai-tools", { path: "ai-tools" }, function () { this.route("new"); - this.route("show", { path: "/:id" }); + this.route("edit", { path: "/:id/edit" }); }); this.route("discourse-ai-spam", { path: "ai-spam" }); this.route("discourse-ai-usage", { path: "ai-usage" }); diff --git a/assets/javascripts/discourse/components/ai-llms-list-editor.gjs b/assets/javascripts/discourse/components/ai-llms-list-editor.gjs index 483791ec..7f39a499 100644 --- a/assets/javascripts/discourse/components/ai-llms-list-editor.gjs +++ b/assets/javascripts/discourse/components/ai-llms-list-editor.gjs @@ -167,7 +167,7 @@ export default class AiLlmsListEditor extends Component { diff --git a/assets/javascripts/discourse/components/ai-persona-editor.gjs b/assets/javascripts/discourse/components/ai-persona-editor.gjs index 6c8dfaf8..d6dafa9f 100644 --- a/assets/javascripts/discourse/components/ai-persona-editor.gjs +++ b/assets/javascripts/discourse/components/ai-persona-editor.gjs @@ -135,7 +135,7 @@ export default class PersonaEditor extends Component { if (isNew && this.args.model.rag_uploads.length === 0) { this.args.personas.addObject(this.args.model); this.router.transitionTo( - "adminPlugins.show.discourse-ai-personas.show", + "adminPlugins.show.discourse-ai-personas.edit", this.args.model ); } else { diff --git a/assets/javascripts/discourse/components/ai-persona-list-editor.gjs b/assets/javascripts/discourse/components/ai-persona-list-editor.gjs index 1c06d3f3..28d6cd39 100644 --- a/assets/javascripts/discourse/components/ai-persona-list-editor.gjs +++ b/assets/javascripts/discourse/components/ai-persona-list-editor.gjs @@ -92,7 +92,7 @@ export default class AiPersonaListEditor extends Component { {{i18n "discourse_ai.ai_persona.edit"}} diff --git a/assets/javascripts/discourse/components/ai-tool-editor.gjs b/assets/javascripts/discourse/components/ai-tool-editor.gjs index 04f74a45..35447e25 100644 --- a/assets/javascripts/discourse/components/ai-tool-editor.gjs +++ b/assets/javascripts/discourse/components/ai-tool-editor.gjs @@ -103,7 +103,7 @@ export default class AiToolEditor extends Component { } this.router.transitionTo( - "adminPlugins.show.discourse-ai-tools.show", + "adminPlugins.show.discourse-ai-tools.edit", this.args.model ); } catch (e) { diff --git a/assets/javascripts/discourse/components/ai-tool-list-editor.gjs b/assets/javascripts/discourse/components/ai-tool-list-editor.gjs index 2725dc02..08422deb 100644 --- a/assets/javascripts/discourse/components/ai-tool-list-editor.gjs +++ b/assets/javascripts/discourse/components/ai-tool-list-editor.gjs @@ -57,7 +57,7 @@ export default class AiToolListEditor extends Component { {{I18n.t "discourse_ai.tools.edit"}} diff --git a/config/routes.rb b/config/routes.rb index f70b5a4b..b70e2edd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -53,7 +53,7 @@ Discourse::Application.routes.draw do scope "/admin/plugins/discourse-ai", constraints: AdminConstraint.new do resources :ai_personas, - only: %i[index create show update destroy], + only: %i[index new create edit update destroy], path: "ai-personas", controller: "discourse_ai/admin/ai_personas" @@ -61,7 +61,7 @@ Discourse::Application.routes.draw do resources( :ai_tools, - only: %i[index create show update destroy], + only: %i[index new create edit update destroy], path: "ai-tools", controller: "discourse_ai/admin/ai_tools", ) @@ -85,7 +85,7 @@ Discourse::Application.routes.draw do post "/ai-spam/test", to: "discourse_ai/admin/ai_spam#test" resources :ai_llms, - only: %i[index create show update destroy], + only: %i[index new create edit update destroy], path: "ai-llms", controller: "discourse_ai/admin/ai_llms" do collection { get :test } diff --git a/spec/requests/admin/ai_personas_controller_spec.rb b/spec/requests/admin/ai_personas_controller_spec.rb index 16e0001b..96677212 100644 --- a/spec/requests/admin/ai_personas_controller_spec.rb +++ b/spec/requests/admin/ai_personas_controller_spec.rb @@ -141,9 +141,9 @@ RSpec.describe DiscourseAi::Admin::AiPersonasController do end end - describe "GET #show" do + describe "GET #edit" do it "returns a success response" do - get "/admin/plugins/discourse-ai/ai-personas/#{ai_persona.id}.json" + get "/admin/plugins/discourse-ai/ai-personas/#{ai_persona.id}/edit.json" expect(response).to be_successful expect(response.parsed_body["ai_persona"]["name"]).to eq(ai_persona.name) end @@ -152,7 +152,7 @@ RSpec.describe DiscourseAi::Admin::AiPersonasController do upload = Fabricate(:upload) RagDocumentFragment.link_target_and_uploads(ai_persona, [upload.id]) - get "/admin/plugins/discourse-ai/ai-personas/#{ai_persona.id}.json" + get "/admin/plugins/discourse-ai/ai-personas/#{ai_persona.id}/edit.json" expect(response).to be_successful serialized_persona = response.parsed_body["ai_persona"] diff --git a/spec/requests/admin/ai_tools_controller_spec.rb b/spec/requests/admin/ai_tools_controller_spec.rb index 3ba96ac4..6a8ce92e 100644 --- a/spec/requests/admin/ai_tools_controller_spec.rb +++ b/spec/requests/admin/ai_tools_controller_spec.rb @@ -35,9 +35,9 @@ RSpec.describe DiscourseAi::Admin::AiToolsController do end end - describe "GET #show" do + describe "GET #edit" do it "returns a success response" do - get "/admin/plugins/discourse-ai/ai-tools/#{ai_tool.id}.json" + get "/admin/plugins/discourse-ai/ai-tools/#{ai_tool.id}/edit.json" expect(response).to be_successful expect(response.parsed_body["ai_tool"]["name"]).to eq(ai_tool.name) end diff --git a/spec/system/admin_ai_persona_spec.rb b/spec/system/admin_ai_persona_spec.rb index 4864d54a..510f0189 100644 --- a/spec/system/admin_ai_persona_spec.rb +++ b/spec/system/admin_ai_persona_spec.rb @@ -2,6 +2,7 @@ RSpec.describe "Admin AI persona configuration", type: :system, js: true do fab!(:admin) + let(:admin_header) { PageObjects::Components::AdminHeader.new } before do SiteSetting.ai_bot_enabled = true @@ -11,7 +12,13 @@ RSpec.describe "Admin AI persona configuration", type: :system, js: true do it "allows creation of a persona" do visit "/admin/plugins/discourse-ai/ai-personas" + + expect(admin_header).to be_visible + find(".ai-persona-list-editor__new-button").click() + + expect(admin_header).to be_hidden + find(".ai-persona-editor__name").set("Test Persona") find(".ai-persona-editor__description").fill_in(with: "I am a test persona") find(".ai-persona-editor__system_prompt").fill_in(with: "You are a helpful bot") @@ -35,7 +42,7 @@ RSpec.describe "Admin AI persona configuration", type: :system, js: true do expect(page).not_to have_current_path("/admin/plugins/discourse-ai/ai-personas/new") - persona_id = page.current_path.split("/").last.to_i + persona_id = page.current_path.split("/")[-2].to_i persona = AiPersona.find(persona_id) expect(persona.name).to eq("Test Persona") @@ -46,7 +53,7 @@ RSpec.describe "Admin AI persona configuration", type: :system, js: true do end it "will not allow deletion or editing of system personas" do - visit "/admin/plugins/discourse-ai/ai-personas/#{DiscourseAi::AiBot::Personas::Persona.system_personas.values.first}" + visit "/admin/plugins/discourse-ai/ai-personas/#{DiscourseAi::AiBot::Personas::Persona.system_personas.values.first}/edit" expect(page).not_to have_selector(".ai-persona-editor__delete") expect(find(".ai-persona-editor__system_prompt")).to be_disabled end @@ -54,7 +61,7 @@ RSpec.describe "Admin AI persona configuration", type: :system, js: true do it "will enable persona right away when you click on enable but does not save side effects" do persona = Fabricate(:ai_persona, enabled: false) - visit "/admin/plugins/discourse-ai/ai-personas/#{persona.id}" + visit "/admin/plugins/discourse-ai/ai-personas/#{persona.id}/edit" find(".ai-persona-editor__name").set("Test Persona 1") PageObjects::Components::DToggleSwitch.new(".ai-persona-editor__enabled").toggle diff --git a/spec/system/ai_bot/tool_spec.rb b/spec/system/ai_bot/tool_spec.rb index ec52ca16..70526254 100644 --- a/spec/system/ai_bot/tool_spec.rb +++ b/spec/system/ai_bot/tool_spec.rb @@ -4,6 +4,7 @@ require "rails_helper" describe "AI Tool Management", type: :system do fab!(:admin) + let(:admin_header) { PageObjects::Components::AdminHeader.new } before do SiteSetting.ai_embeddings_enabled = true @@ -36,9 +37,11 @@ describe "AI Tool Management", type: :system do it "allows admin to create a new AI tool from preset" do visit "/admin/plugins/discourse-ai/ai-tools" + expect(admin_header).to be_visible expect(page).to have_content("Tools") find(".ai-tool-list-editor__new-button").click + expect(admin_header).to be_hidden select_kit = PageObjects::Components::SelectKit.new(".ai-tool-editor__presets") select_kit.expand @@ -58,7 +61,7 @@ describe "AI Tool Management", type: :system do expect(page).to have_content("Tool saved") last_tool = AiTool.order("id desc").limit(1).first - visit "/admin/plugins/discourse-ai/ai-tools/#{last_tool.id}" + visit "/admin/plugins/discourse-ai/ai-tools/#{last_tool.id}/edit" ensure_can_run_test diff --git a/spec/system/llms/ai_llm_spec.rb b/spec/system/llms/ai_llm_spec.rb index 852cc784..548c0c82 100644 --- a/spec/system/llms/ai_llm_spec.rb +++ b/spec/system/llms/ai_llm_spec.rb @@ -2,6 +2,7 @@ RSpec.describe "Managing LLM configurations", type: :system, js: true do fab!(:admin) + let(:admin_header) { PageObjects::Components::AdminHeader.new } before do SiteSetting.ai_bot_enabled = true @@ -36,8 +37,10 @@ RSpec.describe "Managing LLM configurations", type: :system, js: true do it "manually configures an LLM" do visit "/admin/plugins/discourse-ai/ai-llms" + expect(admin_header).to be_visible find("[data-llm-id='none'] button").click() + expect(admin_header).to be_hidden find("input.ai-llm-editor__display-name").fill_in(with: "Self-hosted LLM") find("input.ai-llm-editor__name").fill_in(with: "llava-hf/llava-v1.6-mistral-7b-hf")