A platform for community discussion. Free, open, simple.
FIX: ensures ai_bot_enabled_llms works correctly (#37269)
Joffrey JAFFEUX8fe4b255e03e
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-feature-setting-field.gjs b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-feature-setting-field.gjsindex 54765ba54b2..1a8f4917e60 100644--- a/plugins/discourse-ai/assets/javascripts/discourse/components/ai-feature-setting-field.gjs+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-feature-setting-field.gjs@@ -1,33 +1,40 @@import Component from "@glimmer/component";import { service } from "@ember/service";-import ValueList from "discourse/admin/components/value-list";import ListSetting from "discourse/select-kit/components/list-setting";import { eq } from "discourse/truth-helpers";export default class AiFeatureSettingField extends Component {@service site;- parseGroupList = (value) => {- if (!value) {- return [];- }- return value- .toString()- .split("|")- .filter((id) => id !== "");+ parseList = (value) => {+ return value?.toString().split("|").filter(Boolean) || [];};- serializeListValue = (callback) => {+ serializeList = (callback) => {return (values) => {- const serialized = Array.isArray(values) ? values.join("|") : values;- callback(serialized);+ callback(Array.isArray(values) ? values.join("|") : values);};};get groupChoices() {- return (this.site.groups || []).map((g) => {- return { name: g.name, id: g.id.toString() };- });+ return (this.site.groups || []).map((g) => ({+ name: g.name,+ id: g.id.toString(),+ }));+ }++ get hasEnumChoices() {+ return this.args.setting.valid_values?.length > 0;+ }++ get compactListChoices() {+ if (this.hasEnumChoices) {+ return this.args.setting.valid_values.map((v) => ({+ name: v.name,+ value: String(v.value),+ }));+ }+ return this.args.setting.choices;}get controlType() {@@ -57,21 +64,23 @@ export default class AiFeatureSettingField extends Component {{{else if (eq this.controlType "group_list")}}<@field.Custom><ListSetting- @value={{this.parseGroupList @field.value}}+ @value={{this.parseList @field.value}}@choices={{this.groupChoices}}@settingName={{@setting.setting}}@nameProperty="name"@valueProperty="id"- @onChange={{this.serializeListValue @field.set}}+ @onChange={{this.serializeList @field.set}}/></@field.Custom>{{else if (eq this.controlType "compact_list")}}<@field.Custom>- <ValueList- @values={{@field.value}}- @choices={{@setting.choices}}- @inputDelimiter="|"- @onChange={{this.serializeListValue @field.set}}+ <ListSetting+ @value={{this.parseList @field.value}}+ @choices={{this.compactListChoices}}+ @settingName={{@setting.setting}}+ @nameProperty={{if this.hasEnumChoices "name"}}+ @valueProperty={{if this.hasEnumChoices "value"}}+ @onChange={{this.serializeList @field.set}}/></@field.Custom>{{else}}diff --git a/plugins/discourse-ai/spec/system/admin_ai_features_spec.rb b/plugins/discourse-ai/spec/system/admin_ai_features_spec.rbindex 163b8ef3008..377aee5e6ab 100644--- a/plugins/discourse-ai/spec/system/admin_ai_features_spec.rb+++ b/plugins/discourse-ai/spec/system/admin_ai_features_spec.rb@@ -59,4 +59,22 @@ RSpec.describe "Admin AI features configuration", type: :system doexpect(page).to have_css(".form-kit__section")expect(page).to have_css(".form-kit__field")end++ it "displays LLM names in compact_list settings" do+ llm1 = Fabricate(:llm_model, display_name: "Test LLM Alpha")+ llm2 = Fabricate(:llm_model, display_name: "Test LLM Beta")++ SiteSetting.ai_bot_enabled = true+ SiteSetting.ai_bot_enabled_llms = "#{llm1.id}|#{llm2.id}"++ page.visit(+ "/admin/plugins/discourse-ai/ai-features/#{DiscourseAi::Configuration::Module::BOT_ID}/edit",+ )++ expect(page).to have_css(".ai-feature-editor")++ field = form.field("ai_bot_enabled_llms")+ expect(field.component).to have_content("Test LLM Alpha")+ expect(field.component).to have_content("Test LLM Beta")+ endend