FIX: enum selection not working for persona tools

This commit is contained in:
Sam Saffron 2025-06-12 12:57:41 +10:00
parent 2f845d1efe
commit 96e6357841
No known key found for this signature in database
GPG Key ID: B9606168D2FFD9F5
2 changed files with 29 additions and 4 deletions

View File

@ -16,16 +16,16 @@ export default class AiPersonaToolOptions extends Component {
} }
get toolsMetadata() { get toolsMetadata() {
const metatada = {}; const metadata = {};
this.args.allTools.map((t) => { this.args.allTools.map((t) => {
metatada[t.id] = { metadata[t.id] = {
name: t.name, name: t.name,
...t?.options, ...t?.options,
}; };
}); });
return metatada; return metadata;
} }
@action @action
@ -76,7 +76,7 @@ export default class AiPersonaToolOptions extends Component {
> >
{{#if (eq optionMeta.type "enum")}} {{#if (eq optionMeta.type "enum")}}
<field.Select @includeNone={{false}} as |select|> <field.Select @includeNone={{false}} as |select|>
{{#each optionsObj.values as |v|}} {{#each optionMeta.values as |v|}}
<select.Option @value={{v}}>{{v}}</select.Option> <select.Option @value={{v}}>{{v}}</select.Option>
{{/each}} {{/each}}
</field.Select> </field.Select>

View File

@ -10,6 +10,31 @@ RSpec.describe "AI personas", type: :system, js: true do
sign_in(admin) sign_in(admin)
end 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 it "remembers the last selected persona" do
visit "/" visit "/"
find(".d-header .ai-bot-button").click() find(".d-header .ai-bot-button").click()