From 96e63578419af2339b9e96091eaf712415c1e97e Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Thu, 12 Jun 2025 12:57:41 +1000 Subject: [PATCH] FIX: enum selection not working for persona tools --- .../components/ai-persona-tool-options.gjs | 8 +++--- spec/system/ai_bot/persona_spec.rb | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/assets/javascripts/discourse/components/ai-persona-tool-options.gjs b/assets/javascripts/discourse/components/ai-persona-tool-options.gjs index c4895adf..9d93f457 100644 --- a/assets/javascripts/discourse/components/ai-persona-tool-options.gjs +++ b/assets/javascripts/discourse/components/ai-persona-tool-options.gjs @@ -16,16 +16,16 @@ export default class AiPersonaToolOptions extends Component { } get toolsMetadata() { - const metatada = {}; + const metadata = {}; this.args.allTools.map((t) => { - metatada[t.id] = { + metadata[t.id] = { name: t.name, ...t?.options, }; }); - return metatada; + return metadata; } @action @@ -76,7 +76,7 @@ export default class AiPersonaToolOptions extends Component { > {{#if (eq optionMeta.type "enum")}} - {{#each optionsObj.values as |v|}} + {{#each optionMeta.values as |v|}} {{v}} {{/each}} diff --git a/spec/system/ai_bot/persona_spec.rb b/spec/system/ai_bot/persona_spec.rb index 1cf5e231..5c3883e6 100644 --- a/spec/system/ai_bot/persona_spec.rb +++ b/spec/system/ai_bot/persona_spec.rb @@ -10,6 +10,31 @@ RSpec.describe "AI personas", type: :system, js: true do sign_in(admin) end + it "can select and save persona tool options" do + visit "/admin/plugins/discourse-ai/ai-personas" + find(".ai-persona-list-editor__new-button").click + + expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-personas/new") + + form = PageObjects::Components::FormKit.new("form") + form.field("name").fill_in("Test Persona") + form.field("description").fill_in("This is a test persona.") + form.field("system_prompt").fill_in("You are a helpful assistant.") + form.field("tools").select("Update Artifact") + form.field("toolOptions.UpdateArtifact.update_algorithm").select("full") + form.submit + + expect(page).to have_current_path(%r{/admin/plugins/discourse-ai/ai-personas/\d+/edit}) + + persona = AiPersona.order("id desc").first + + expect(persona.name).to eq("Test Persona") + expect(persona.description).to eq("This is a test persona.") + expect(persona.tools.count).to eq(1) + expect(persona.tools.first[0]).to eq("UpdateArtifact") + expect(persona.tools.first[1]["update_algorithm"]).to eq("full") + end + it "remembers the last selected persona" do visit "/" find(".d-header .ai-bot-button").click()