Skip to content

A platform for community discussion. Free, open, simple.

REFACTOR: convert AI feature settings to formkit (#36850)

Kris2d1a60d68c04
diff --git a/frontend/discourse/admin/templates/admin-plugins.gjs b/frontend/discourse/admin/templates/admin-plugins.gjs
index c4ae5c0c185..17f74619143 100644
--- a/frontend/discourse/admin/templates/admin-plugins.gjs
+++ b/frontend/discourse/admin/templates/admin-plugins.gjs
@@ -8,9 +8,14 @@ export default <template>
{{#if @controller.showTopNav}}
<div class="d-page-header">
<DBreadcrumbsContainer />
- <DBreadcrumbsItem @path="/admin" @label={{i18n "admin_title"}} />
+ <DBreadcrumbsItem
+ @path="/admin"
+ @route="admin"
+ @label={{i18n "admin_title"}}
+ />
<DBreadcrumbsItem
@path="/admin/plugins"
+ @route="adminPlugins"
@label={{i18n "admin.config.plugins.title"}}
/>
<div class="d-nav-submenu">
diff --git a/frontend/discourse/app/components/d-breadcrumbs-item.gjs b/frontend/discourse/app/components/d-breadcrumbs-item.gjs
index fa8338db297..99a483543cc 100644
--- a/frontend/discourse/app/components/d-breadcrumbs-item.gjs
+++ b/frontend/discourse/app/components/d-breadcrumbs-item.gjs
@@ -1,4 +1,5 @@
import Component from "@glimmer/component";
+import { LinkTo } from "@ember/routing";
import { service } from "@ember/service";
import icon from "discourse/helpers/d-icon";
import getURL from "discourse/lib/get-url";
@@ -19,13 +20,19 @@ export default class DBreadcrumbsItem extends Component {
// @cached
get templateForContainer() {
// Those are evaluated in a different context than the `@linkClass`
- const { label, path } = this.args;
+ const { label, path, route } = this.args;
return <template>
<li ...attributes>
- <a href={{getURL path}} class={{@linkClass}}>
- {{label}}
- </a>
+ {{#if route}}
+ <LinkTo @route={{route}} class={{@linkClass}}>
+ {{label}}
+ </LinkTo>
+ {{else}}
+ <a href={{getURL path}} class={{@linkClass}}>
+ {{label}}
+ </a>
+ {{/if}}
<span class="separator">
{{~icon "angle-right"~}}
</span>
diff --git a/frontend/discourse/app/form-kit/components/fk/form.gjs b/frontend/discourse/app/form-kit/components/fk/form.gjs
index df85a38cf24..a655f2850c7 100644
--- a/frontend/discourse/app/form-kit/components/fk/form.gjs
+++ b/frontend/discourse/app/form-kit/components/fk/form.gjs
@@ -50,6 +50,7 @@ class FKForm extends Component {
reset: this.onReset,
addError: this.addError,
removeError: this.removeError,
+ removeErrors: this.removeErrors,
});
this.router.on("routeWillChange", this.checkIsDirty);
@@ -65,10 +66,14 @@ class FKForm extends Component {
async checkIsDirty(transition) {
let triggerConfirm = false;
+ // In some cases (e.g., subroute -> parent),
+ // queryParamsOnly is true even though the route name changes
+ const routeChanging = transition.to?.name !== transition.from?.name;
+
const shouldCheck =
this.formData.isDirty &&
!transition.isAborted &&
- !transition.queryParamsOnly;
+ (!transition.queryParamsOnly || routeChanging);
if (this.args.onDirtyCheck) {
triggerConfirm = shouldCheck && this.args.onDirtyCheck(transition);
@@ -137,6 +142,11 @@ class FKForm extends Component {
this.formData.removeError(name);
}
+ @action
+ removeErrors() {
+ this.formData.removeErrors();
+ }
+
@action
registerFormElement(element) {
this.formElement = element;
diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/controllers/admin-plugins/show/discourse-ai-features/edit.js b/plugins/discourse-ai/admin/assets/javascripts/discourse/controllers/admin-plugins/show/discourse-ai-features/edit.js
new file mode 100644
index 00000000000..4d5f8762e6b
--- /dev/null
+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/controllers/admin-plugins/show/discourse-ai-features/edit.js
@@ -0,0 +1,113 @@
+import { tracked } from "@glimmer/tracking";
+import Controller from "@ember/controller";
+import { action } from "@ember/object";
+import { service } from "@ember/service";
+import SiteSetting from "discourse/admin/models/site-setting";
+import { i18n } from "discourse-i18n";
+
+export default class AdminPluginsShowDiscourseAiFeaturesEditController extends Controller {
+ @service toasts;
+ @service router;
+
+ @tracked settings = [];
+
+ @action
+ onRegisterFormApi(api) {
+ this.formApi = api;
+ }
+
+ @action
+ findSetting(settingName) {
+ return this.settings.find((s) => s.setting === settingName);
+ }
+
+ /**
+ * Generates a FormKit validation string for a site setting.
+ *
+ * @param {Object} setting - The site setting object
+ * @param {string} setting.type - The setting type (e.g., "integer", "bool", "string")
+ * @param {number} [setting.min] - Minimum value for integer settings
+ * @param {number} [setting.max] - Maximum value for integer settings
+ * @returns {string|undefined} Validation string in FormKit format (e.g., "number|between:0,100")
+ * or undefined if no validation is needed
+ */
+ @action
+ getValidationFor(setting) {
+ const validation = [];
+
+ if (setting.type === "integer") {
+ validation.push("number");
+
+ if (setting.min !== undefined || setting.max !== undefined) {
+ const min = setting.min ?? "";
+ const max = setting.max ?? "";
+ validation.push(`between:${min},${max}`);
+ }
+ }
+
+ return validation.length > 0 ? validation.join("|") : undefined;
+ }
+
+ @action
+ async save(data) {
+ if (this.formApi) {
+ this.formApi.removeErrors();
+ }
+
+ const errors = {};
+
+ for (const [key, value] of Object.entries(data)) {
+ const setting = this.findSetting(key);
+ if (!setting) {
+ continue;
+ }
+
+ const valuesEqual = this.valuesEqual(setting.value, value);
+
+ if (valuesEqual) {
+ continue;
+ }
+
+ try {
+ await SiteSetting.update(key, value);
+ setting.value = value;
+ } catch (e) {
+ const errorMsg = e.jqXHR?.responseJSON?.errors?.[0] || "Unknown error";
+ errors[key] = errorMsg;
+
+ if (this.formApi) {
+ this.formApi.addError(key, {
+ title: setting.humanized_name,
+ message: errorMsg,
+ });
+ }
+ }
+ }
+
+ if (Object.keys(errors).length === 0) {
+ this.toasts.success({
+ data: { message: i18n("saved") },
+ duration: 2000,
+ });
+
+ this.router.refresh("adminPlugins.show.discourse-ai-features");
+ } else {
+ this.toasts.error({
+ data: {
+ message: i18n("discourse_ai.features.settings_save_error"),
+ },
+ duration: 4000,
+ });
+ }
+ }
+
+ valuesEqual(a, b) {
+ if (a === b) {
+ return true;
+ }
+ if (a == null || b == null) {
+ return false;
+ }
+ return a.toString() === b.toString();
+ }
+}
diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-features/edit.js b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-features/edit.js
index 885853da6ad..d2ced40d880 100644
--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-features/edit.js
+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-features/edit.js
@@ -1,7 +1,7 @@
-import { action } from "@ember/object";
import SiteSetting from "discourse/admin/models/site-setting";
import { ajax } from "discourse/lib/ajax";
import DiscourseRoute from "discourse/routes/discourse";
+import { getSettingGroupsForFeature } from "discourse/plugins/discourse-ai/discourse/lib/ai-feature-setting-groups";
export default class AdminPluginsShowDiscourseAiFeaturesEdit extends DiscourseRoute {
async model(params) {
@@ -23,13 +23,34 @@ export default class AdminPluginsShowDiscourseAiFeaturesEdit extends DiscourseRo
SiteSetting.create(setting)
);
+ currentFeature.settingGroups = getSettingGroupsForFeature(
+ currentFeature.module_name
+ );
+
+ currentFeature.formData = {};
+ currentFeature.feature_settings.forEach((setting) => {
+ let value = setting.value;
+
+ if (setting.type === "bool") {
+ value = value === "true" || value === true;
+ }
+
+ if (setting.type === "enum" && typeof value === "string") {
+ const numValue = parseInt(value, 10);
+ if (!isNaN(numValue) && numValue.toString() === value) {
+ value = numValue;
+ }
+ }
+
+ currentFeature.formData[setting.setting] = value;
+ });
+
return currentFeature;
}
- @action
- willTransition() {
- // site settings may amend if a feature is enabled or disabled, so refresh the model
- // even on back button
- this.router.refresh("adminPlugins.show.discourse-ai-features");
+ setupController(controller, model) {
+ super.setupController(controller, model);
+
+ controller.set("settings", model.feature_settings);
}
}
diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-features/edit.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-features/edit.gjs
index d54a6933251..1685149b599 100644
--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-features/edit.gjs
+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-features/edit.gjs
@@ -1,21 +1,51 @@
-import SiteSettingComponent from "discourse/admin/components/site-setting";
import BackButton from "discourse/components/back-button";
+import Form from "discourse/components/form";
+import { eq } from "discourse/truth-helpers";
+import { i18n } from "discourse-i18n";
+import AiFeatureSettingField from "discourse/plugins/discourse-ai/discourse/components/ai-feature-setting-field";
export default <template>
- <BackButton
- @route="adminPlugins.show.discourse-ai-features"
- @label="discourse_ai.features.back"
- />
- <section class="ai-feature-editor__header">
- <h2>{{@model.name}}</h2>
- <p>{{@model.description}}</p>
- </section>
+ <BackButton @route="adminPlugins.show.discourse-ai-features" />
- <section class="ai-feature-editor">
- {{#each @model.feature_settings as |setting|}}
- <div>
- <SiteSettingComponent @setting={{setting}} />
- </div>
- {{/each}}
- </section>
+ {{#if @model.feature_settings.length}}
+ <Form
+ @data={{@model.formData}}
+ @onSubmit={{@controller.save}}
+ @onRegisterApi={{@controller.onRegisterFormApi}}
+ class="ai-feature-editor"
+ as |form|
+ >
+ {{#each @model.settingGroups as |group|}}
+ <form.Section @title={{i18n group.titleKey}}>
+ {{#each group.settings as |settingName|}}
+ {{#let (@controller.findSetting settingName) as |setting|}}
+ {{#if setting}}
+ <form.Field
+ @name={{setting.setting}}
+ @title={{setting.humanized_name}}
+ @description={{if
+ (eq setting.type "bool")
+ null
+ setting.description
+ }}
+ @format="large"
+ @validation={{@controller.getValidationFor setting}}
+ as |field|
+ >
+ <AiFeatureSettingField
+ @setting={{setting}}
+ @field={{field}}
+ />
+ </form.Field>
+ {{/if}}
+ {{/let}}
+ {{/each}}
+ </form.Section>
+ {{/each}}
+
+ <form.Actions>
+ <form.Submit />
+ </form.Actions>
+ </Form>
+ {{/if}}
</template>
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.gjs
new file mode 100644
index 00000000000..54765ba54b2
--- /dev/null
+++ b/plugins/discourse-ai/assets/javascripts/discourse/components/ai-feature-setting-field.gjs
@@ -0,0 +1,81 @@
+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 !== "");
+ };
+
+ serializeListValue = (callback) => {
+ return (values) => {
+ const serialized = Array.isArray(values) ? values.join("|") : values;
+ callback(serialized);
+ };
+ };
+
+ get groupChoices() {
+ return (this.site.groups || []).map((g) => {
+ return { name: g.name, id: g.id.toString() };
+ });
+ }
+
+ get controlType() {
+ const { type, list_type } = this.args.setting;
+
+ if (type === "list" && list_type) {
+ return `${list_type}_list`;
+ }
+ return type;
+ }
+
+ <template>
+ {{#if (eq this.controlType "bool")}}
+ <@field.Checkbox>
+ {{@setting.description}}
+ </@field.Checkbox>
+ {{else if (eq this.controlType "integer")}}
+ <@field.Input @type="number" />
+ {{else if (eq this.controlType "enum")}}
+ <@field.Select as |select|>
+ {{#each @setting.valid_values as |option|}}
+ <select.Option @value={{option.value}}>
+ {{option.name}}
+ </select.Option>
+ {{/each}}
+ </@field.Select>
+ {{else if (eq this.controlType "group_list")}}
+ <@field.Custom>
+ <ListSetting
+ @value={{this.parseGroupList @field.value}}
+ @choices={{this.groupChoices}}
+ @settingName={{@setting.setting}}
+ @nameProperty="name"
+ @valueProperty="id"
+ @onChange={{this.serializeListValue @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}}
+ />
+ </@field.Custom>
+ {{else}}
+ <@field.Input />
+ {{/if}}
+ </template>
+}
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/lib/ai-feature-setting-groups.js b/plugins/discourse-ai/assets/javascripts/discourse/lib/ai-feature-setting-groups.js
new file mode 100644
index 00000000000..b6dee15077c
--- /dev/null
+++ b/plugins/discourse-ai/assets/javascripts/discourse/lib/ai-feature-setting-groups.js
@@ -0,0 +1,239 @@
+export const AI_FEATURE_SETTING_GROUPS = {
+ ai_helper: [
+ {
+ key: "access_permissions",
+ titleKey:
+ "discourse_ai.features.ai_helper.setting_groups.access_permissions",
+ settings: [
+ "ai_helper_enabled",
+ "composer_ai_helper_allowed_groups",
+ "post_ai_helper_allowed_groups",
+ "ai_helper_allowed_in_pm",
+ ],
+ },
+ {
+ key: "enabled_features",
+ titleKey:
+ "discourse_ai.features.ai_helper.setting_groups.enabled_features",
+ settings: ["ai_helper_enabled_features"],
+ },
+ {
+ key: "automation",
+ titleKey: "discourse_ai.features.ai_helper.setting_groups.automation",
+ settings: [
+ "ai_helper_automatic_chat_thread_title",
+ "ai_helper_automatic_chat_thread_title_delay",
+ ],
+ },
+ {
+ key: "personas",
+ titleKey: "discourse_ai.features.ai_helper.setting_groups.personas",
+ settings: [
+ "ai_helper_proofreader_persona",
+ "ai_helper_title_suggestions_persona",
+ "ai_helper_explain_persona",
+ "ai_helper_post_illustrator_persona",
+ "ai_helper_smart_dates_persona",
+ "ai_helper_translator_persona",
+ "ai_helper_markdown_tables_persona",
+ "ai_helper_custom_prompt_persona",
+ "ai_helper_image_caption_persona",
+ ],
+ },
+ ],
+
+ embeddings: [
+ {
+ key: "model_settings",
+ titleKey:
+ "discourse_ai.features.embeddings.setting_groups.model_settings",
+ settings: [
+ "ai_embeddings_enabled",
+ "ai_embeddings_selected_model",
+ "ai_embeddings_generate_for_pms",
+ ],
+ },
+ {
+ key: "related_topics",
+ titleKey:
+ "discourse_ai.features.embeddings.setting_groups.related_topics",
+ settings: [
+ "ai_embeddings_semantic_related_topics_enabled",
+ "ai_embeddings_semantic_related_topics",
+ "ai_embeddings_semantic_related_include_closed_topics",
+ "ai_embeddings_semantic_related_age_penalty",
+ "ai_embeddings_semantic_related_age_time_scale",
+ ],
+ },
+ {
+ key: "semantic_search",
+ titleKey:
+ "discourse_ai.features.embeddings.setting_groups.semantic_search",
+ settings: [
+ "ai_embeddings_semantic_search_enabled",
+ "ai_embeddings_semantic_search_use_hyde",
+ "ai_embeddings_semantic_quick_search_enabled",
+ "ai_embeddings_semantic_search_hyde_persona",
+ ],
+ },
+ ],
+
+ bot: [
+ {
+ key: "settings",
+ titleKey: "discourse_ai.features.bot.setting_groups.settings",
+ settings: [
+ "ai_bot_enabled",
+ "ai_bot_enabled_llms",
+ "ai_bot_enable_chat_warning",
+ ],
+ },
+ {
+ key: "access_control",
+ titleKey: "discourse_ai.features.bot.setting_groups.access_control",
+ settings: [
+ "ai_bot_debugging_allowed_groups",
+ "ai_bot_allowed_groups",
+ "ai_bot_public_sharing_allowed_groups",
+ ],
+ },
+ {
+ key: "ui_settings",
+ titleKey: "discourse_ai.features.bot.setting_groups.ui_settings",
+ settings: ["ai_bot_add_to_header", "ai_bot_add_to_community_section"],
+ },
+ {
+ key: "integrations",
+ titleKey: "discourse_ai.features.bot.setting_groups.integrations",
+ settings: ["ai_bot_github_access_token"],
+ },
+ ],
+
+ summarization: [
+ {
+ key: "settings",
+ titleKey: "discourse_ai.features.summarization.setting_groups.settings",
+ settings: [
+ "ai_summarization_enabled",
+ "ai_summarization_persona",
+ "ai_pm_summarization_allowed_groups",
+ ],
+ },
+ {
+ key: "gists",
+ titleKey: "discourse_ai.features.summarization.setting_groups.gists",
+ settings: ["ai_summary_gists_enabled", "ai_summary_gists_persona"],
+ },
+ {
+ key: "backfill",
+ titleKey: "discourse_ai.features.summarization.setting_groups.backfill",
+ settings: [
+ "ai_summary_backfill_topic_max_age_days",
+ "ai_summary_backfill_maximum_topics_per_hour",
+ "ai_summary_backfill_minimum_word_count",
+ ],
+ },
+ ],
+
+ search: [
+ {
+ key: "settings",
+ titleKey: "discourse_ai.features.search.setting_groups.settings",
+ settings: ["ai_discover_enabled", "ai_discover_persona"],
+ },
+ ],
+
+ translation: [
+ {
+ key: "settings",
+ titleKey: "discourse_ai.features.translation.setting_groups.settings",
+ settings: ["ai_translation_enabled"],
+ },
+ {
+ key: "personas",
+ titleKey: "discourse_ai.features.translation.setting_groups.personas",
+ settings: [
+ "ai_translation_locale_detector_persona",
+ "ai_translation_post_raw_translator_persona",
+ "ai_translation_topic_title_translator_persona",
+ "ai_translation_short_text_translator_persona",
+ ],
+ },
+ {
+ key: "backfill_and_limits",
+ titleKey:
+ "discourse_ai.features.translation.setting_groups.backfill_and_limits",
+ settings: [
+ "ai_translation_backfill_hourly_rate",
+ "ai_translation_backfill_limit_to_public_content",
+ "ai_translation_max_post_length",
+ "ai_translation_backfill_max_age_days",
+ "ai_translation_max_tokens_multiplier",
+ "ai_translation_verbose_logs",
+ ],
+ },
+ ],
+
+ discord: [
+ {
+ key: "settings",
+ titleKey: "discourse_ai.features.discord.setting_groups.settings",
+ settings: [
+ "ai_discord_search_enabled",
+ "ai_discord_search_mode",
+ "ai_discord_search_persona",
+ ],
+ },
+ {
+ key: "discord_configuration",
+ titleKey:
+ "discourse_ai.features.discord.setting_groups.discord_configuration",
+ settings: [
+ "ai_discord_app_id",
+ "ai_discord_app_public_key",
+ "ai_discord_allowed_guilds",
+ ],
+ },
+ ],
+
+ inference: [
+ {
+ key: "settings",
+ titleKey: "discourse_ai.features.inference.setting_groups.settings",
+ settings: ["inferred_concepts_enabled"],
+ },
+ {
+ key: "topic_criteria",
+ titleKey: "discourse_ai.features.inference.setting_groups.topic_criteria",
+ settings: [
+ "inferred_concepts_background_match",
+ "inferred_concepts_daily_topics_limit",
+ "inferred_concepts_min_posts",
+ "inferred_concepts_min_likes",
+ "inferred_concepts_min_views",
+ "inferred_concepts_lookback_days",
+ ],
+ },
+ {
+ key: "post_criteria",
+ titleKey: "discourse_ai.features.inference.setting_groups.post_criteria",
+ settings: [
+ "inferred_concepts_daily_posts_limit",
+ "inferred_concepts_post_min_likes",
+ ],
+ },
+ {
+ key: "personas",
+ titleKey: "discourse_ai.features.inference.setting_groups.personas",
+ settings: [
+ "inferred_concepts_generate_persona",
+ "inferred_concepts_match_persona",
+ "inferred_concepts_deduplicate_persona",
+ ],
+ },
+ ],
+};
+
+export function getSettingGroupsForFeature(moduleName) {
+ return AI_FEATURE_SETTING_GROUPS[moduleName] || [];
+}
diff --git a/plugins/discourse-ai/assets/stylesheets/admin/ai-features-editor.scss b/plugins/discourse-ai/assets/stylesheets/admin/ai-features-editor.scss
new file mode 100644
index 00000000000..2e463c78fbc
--- /dev/null
+++ b/plugins/discourse-ai/assets/stylesheets/admin/ai-features-editor.scss
@@ -0,0 +1,6 @@
+.ai-feature-editor {
+ .form-kit__container-optional {
+ // ideally need to add this ability to formkit
+ display: none;
+ }
+}
diff --git a/plugins/discourse-ai/config/locales/client.en.yml b/plugins/discourse-ai/config/locales/client.en.yml
index 7b8261ee8dc..0d14c78aa07 100644
--- a/plugins/discourse-ai/config/locales/client.en.yml
+++ b/plugins/discourse-ai/config/locales/client.en.yml
@@ -230,6 +230,7 @@ en:
short_title: "Features"
description: "These are the AI features available to visitors on your site. These can be configured to use specific personas and LLMs, and can be access controlled by groups."
back: "Back"
+ settings_save_error: "Some settings could not be saved."
disabled: "(disabled)"
persona:
one: "Persona:"
@@ -250,6 +251,11 @@ en:
bot: "Chatbot"
name: "Bot"
description: "A chat bot that can answer questions and assist users in personal messages, forum and in chat"
+ setting_groups:
+ settings: "Basic Settings"
+ access_control: "Access Control"
+ ui_settings: "UI Settings"
+ integrations: "Integrations"
nav:
configured: "Configured"
unconfigured: "Unconfigured"
@@ -266,24 +272,42 @@ en:
description: "Makes a summarization button available that allows visitors to summarize topics"
topic_summaries: "Topic summaries"
gists: "Topic list's short summaries"
+ setting_groups:
+ settings: "Basic Settings"
+ gists: "Gists"
+ backfill: "Backfill"
search:
name: "Search"
description: "Enhances search experience by providing AI-generated answers to queries"
discoveries: "Discoveries"
+ setting_groups:
+ settings: "Basic Settings"
embeddings:
name: "Embeddings"
description: "Powers features like Related Topics and AI Search by generating semantic representations of text"
hyde: "HyDE"
+ setting_groups:
+ model_settings: "Model Settings"
+ related_topics: "Related Topics"
+ semantic_search: "Semantic Search"
discord:
name: "Discord integration"
description: "Adds the ability to search Discord channels"
search: "Discord search"
+ setting_groups:
+ settings: "Basic Settings"
+ discord_configuration: "Discord Configuration"
inference:
name: "Inferred concepts"
description: "Classifies topics and posts into areas of interest / labels."
generate_concepts: "Concepts inference"
match_concepts: "Concepts matching"
deduplicate_concepts: "Concepts deduplication"
+ setting_groups:
+ settings: "Basic Settings"
+ topic_criteria: "Topic Criteria"
+ post_criteria: "Post Criteria"
+ personas: "Personas"
ai_helper:
name: "Helper"
@@ -299,6 +323,11 @@ en:
image_caption: "Caption images"
translator: "Translator"
post_illustrator: "Post illustrator"
+ setting_groups:
+ access_permissions: "Access & Permissions"
+ enabled_features: "Enabled Features"
+ automation: "Automation"
+ personas: "Personas"
translation:
name: "Translation"
@@ -312,6 +341,10 @@ en:
one: "Scheduled translation for %{count} untranslated post."
other: "Scheduled translation for %{count} untranslated posts."
schedule_topic_error: "Failed to schedule translations. Please try again."
+ setting_groups:
+ settings: "Basic Settings"
+ personas: "Personas"
+ backfill_and_limits: "Backfill & Limits"
spam:
name: "Spam"
diff --git a/plugins/discourse-ai/plugin.rb b/plugins/discourse-ai/plugin.rb
index 3cf9ec0a7fc..25aa578fa21 100644
--- a/plugins/discourse-ai/plugin.rb
+++ b/plugins/discourse-ai/plugin.rb
@@ -19,6 +19,8 @@ register_asset "stylesheets/common/ai-blinking-animation.scss"
register_asset "stylesheets/common/ai-user-settings.scss"
register_asset "stylesheets/common/ai-features.scss"
+register_asset "stylesheets/admin/ai-features-editor.scss"
+
register_asset "stylesheets/modules/translation/common/admin-translations.scss"
register_asset "stylesheets/modules/ai-helper/common/ai-helper.scss"
diff --git a/plugins/discourse-ai/spec/system/admin_ai_features_spec.rb b/plugins/discourse-ai/spec/system/admin_ai_features_spec.rb
index 923175bf05b..163b8ef3008 100644
--- a/plugins/discourse-ai/spec/system/admin_ai_features_spec.rb
+++ b/plugins/discourse-ai/spec/system/admin_ai_features_spec.rb
@@ -48,13 +48,15 @@ RSpec.describe "Admin AI features configuration", type: :system do
expect(ai_features_page).to have_feature_groups("topic_summaries", [group_1.name, group_2.name])
end
- it "shows edit page with settings" do
+ it "shows edit page with grouped settings" do
ai_features_page.visit
ai_features_page.click_edit_module("summarization")
expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-features/1/edit")
- expect(page).to have_css(".setting")
+ expect(page).to have_css(".ai-feature-editor")
+ expect(page).to have_css(".form-kit__section")
+ expect(page).to have_css(".form-kit__field")
end
end
diff --git a/plugins/discourse-ai/test/javascripts/unit/controllers/admin-plugins-show-discourse-ai-features-edit-test.js b/plugins/discourse-ai/test/javascripts/unit/controllers/admin-plugins-show-discourse-ai-features-edit-test.js
new file mode 100644
index 00000000000..7938bdec3df
--- /dev/null
+++ b/plugins/discourse-ai/test/javascripts/unit/controllers/admin-plugins-show-discourse-ai-features-edit-test.js
@@ -0,0 +1,190 @@
+import { setupTest } from "ember-qunit";
+import { module, test } from "qunit";
+
+module(
+ "Unit | Controller | admin-plugins/show/discourse-ai-features/edit",
+ function (hooks) {
+ setupTest(hooks);
+
+ test("getValidationFor returns correct validation for integer with min/max", function (assert) {
+ const controller = this.owner.lookup(
+ "controller:admin-plugins/show/discourse-ai-features/edit"
+ );
+
+ const setting = {
+ type: "integer",
+ min: 0,
+ max: 100,
+ };
+
+ const validation = controller.getValidationFor(setting);
+
+ assert.strictEqual(
+ validation,
+ "number|between:0,100",
+ "should return number with between validator"
+ );
+ });
+
+ test("getValidationFor returns correct validation for integer with only min", function (assert) {
+ const controller = this.owner.lookup(
+ "controller:admin-plugins/show/discourse-ai-features/edit"
+ );
+
+ const setting = {
+ type: "integer",
+ min: 5,
+ };
+
+ const validation = controller.getValidationFor(setting);
+
+ assert.strictEqual(
+ validation,
+ "number|between:5,",
+ "should return number with between validator (min only)"
+ );
+ });
+
+ test("getValidationFor returns correct validation for integer with only max", function (assert) {
+ const controller = this.owner.lookup(
+ "controller:admin-plugins/show/discourse-ai-features/edit"
+ );
+
+ const setting = {
+ type: "integer",
+ max: 50,
+ };
+
+ const validation = controller.getValidationFor(setting);
+
+ assert.strictEqual(
+ validation,
+ "number|between:,50",
+ "should return number with between validator (max only)"
+ );
+ });
+
+ test("getValidationFor returns number for integer without constraints", function (assert) {
+ const controller = this.owner.lookup(
+ "controller:admin-plugins/show/discourse-ai-features/edit"
+ );
+
+ const setting = {
+ type: "integer",
+ };
+
+ const validation = controller.getValidationFor(setting);
+
+ assert.strictEqual(
+ validation,
+ "number",
+ "should return just number validator"
+ );
+ });
+
+ test("getValidationFor returns undefined for non-integer types", function (assert) {
+ const controller = this.owner.lookup(
+ "controller:admin-plugins/show/discourse-ai-features/edit"
+ );
+
+ const setting = {
+ type: "string",
+ };
+
+ const validation = controller.getValidationFor(setting);
+
+ assert.strictEqual(
+ validation,
+ undefined,
+ "should return undefined for non-integer types"
+ );
+ });
+
+ test("valuesEqual compares using toString", function (assert) {
+ const controller = this.owner.lookup(
+ "controller:admin-plugins/show/discourse-ai-features/edit"
+ );
+
+ assert.true(
+ controller.valuesEqual("123", 123),
+ "string '123' should equal number 123"
+ );
+ assert.true(
+ controller.valuesEqual(true, "true"),
+ "boolean true should equal string 'true'"
+ );
+ assert.true(
+ controller.valuesEqual(false, "false"),
+ "boolean false should equal string 'false'"
+ );
+ assert.true(
+ controller.valuesEqual("abc", "abc"),
+ "identical strings should be equal"
+ );
+ assert.false(
+ controller.valuesEqual("123", "456"),
+ "different values should not be equal"
+ );
+ });
+
+ test("valuesEqual handles null and undefined", function (assert) {
+ const controller = this.owner.lookup(
+ "controller:admin-plugins/show/discourse-ai-features/edit"
+ );
+
+ assert.false(
+ controller.valuesEqual(null, "null"),
+ "null should not equal string 'null'"
+ );
+ assert.false(
+ controller.valuesEqual(undefined, "undefined"),
+ "undefined should not equal string 'undefined'"
+ );
+ assert.true(controller.valuesEqual(null, null), "null should equal null");
+ assert.true(
+ controller.valuesEqual(undefined, undefined),
+ "undefined should equal undefined"
+ );
+ assert.false(
+ controller.valuesEqual(null, undefined),
+ "null should not equal undefined"
+ );
+ });
+
+ test("findSetting returns correct setting by name", function (assert) {
+ const controller = this.owner.lookup(
+ "controller:admin-plugins/show/discourse-ai-features/edit"
+ );
+
+ controller.settings = [
+ { setting: "setting_one", value: "value1" },
+ { setting: "setting_two", value: "value2" },
+ { setting: "setting_three", value: "value3" },
+ ];
+
+ const result = controller.findSetting("setting_two");
+
+ assert.deepEqual(
+ result,
+ { setting: "setting_two", value: "value2" },
+ "should return the correct setting"
+ );
+ });
+
+ test("findSetting returns undefined for non-existent setting", function (assert) {
+ const controller = this.owner.lookup(
+ "controller:admin-plugins/show/discourse-ai-features/edit"
+ );
+
+ controller.settings = [{ setting: "setting_one", value: "value1" }];
+
+ const result = controller.findSetting("nonexistent");
+
+ assert.strictEqual(
+ result,
+ undefined,
+ "should return undefined for non-existent setting"
+ );
+ });
+ }
+);
diff --git a/plugins/discourse-ai/test/javascripts/unit/lib/ai-feature-setting-groups-test.js b/plugins/discourse-ai/test/javascripts/unit/lib/ai-feature-setting-groups-test.js
new file mode 100644
index 00000000000..578123a7db0
--- /dev/null
+++ b/plugins/discourse-ai/test/javascripts/unit/lib/ai-feature-setting-groups-test.js
@@ -0,0 +1,82 @@
+import { module, test } from "qunit";
+import { getSettingGroupsForFeature } from "discourse/plugins/discourse-ai/discourse/lib/ai-feature-setting-groups";
+
+module("Unit | Lib | ai-feature-setting-groups", function () {
+ test("returns correct groups for ai_helper", function (assert) {
+ const groups = getSettingGroupsForFeature("ai_helper");
+
+ assert.strictEqual(groups.length, 4, "ai_helper should have 4 groups");
+ assert.strictEqual(
+ groups[0].key,
+ "access_permissions",
+ "first group should be access_permissions"
+ );
+
+ assert.true(
+ groups[0].settings.includes("ai_helper_enabled"),
+ "access_permissions should include ai_helper_enabled"
+ );
+ });
+
+ test("returns correct groups for embeddings", function (assert) {
+ const groups = getSettingGroupsForFeature("embeddings");
+
+ assert.strictEqual(groups.length, 3, "embeddings should have 3 groups");
+ assert.strictEqual(
+ groups[0].key,
+ "model_settings",
+ "first group should be model_settings"
+ );
+ });
+
+ test("returns correct groups for bot", function (assert) {
+ const groups = getSettingGroupsForFeature("bot");
+
+ assert.strictEqual(groups.length, 4, "bot should have 4 groups");
+ assert.strictEqual(
+ groups[0].key,
+ "settings",
+ "first group should be settings"
+ );
+ });
+
+ test("returns correct groups for summarization", function (assert) {
+ const groups = getSettingGroupsForFeature("summarization");
+
+ assert.strictEqual(groups.length, 3, "summarization should have 3 groups");
+ });
+
+ test("returns correct groups for search", function (assert) {
+ const groups = getSettingGroupsForFeature("search");
+
+ assert.strictEqual(groups.length, 1, "search should have 1 group");
+ });
+
+ test("returns correct groups for translation", function (assert) {
+ const groups = getSettingGroupsForFeature("translation");
+
+ assert.strictEqual(groups.length, 3, "translation should have 3 groups");
+ });
+
+ test("returns correct groups for discord", function (assert) {
+ const groups = getSettingGroupsForFeature("discord");
+
+ assert.strictEqual(groups.length, 2, "discord should have 2 groups");
+ });
+
+ test("returns correct groups for inference", function (assert) {
+ const groups = getSettingGroupsForFeature("inference");
+
+ assert.strictEqual(groups.length, 4, "inference should have 4 groups");
+ });
+
+ test("returns empty array for unknown feature", function (assert) {
+ const groups = getSettingGroupsForFeature("unknown_feature");
+
+ assert.strictEqual(
+ groups.length,
+ 0,
+ "unknown feature should return empty array"
+ );
+ });
+});