A platform for community discussion. Free, open, simple.
FEATURE: merge llm, embeddings, and decisions under a single AI models tab (#44776)
Kris08a56b5b11e2
diff --git a/.skills/discourse-ai-llm-presets/SKILL.md b/.skills/discourse-ai-llm-presets/SKILL.mdindex 140bcad54f2..8faaf15e9b3 100644--- a/.skills/discourse-ai-llm-presets/SKILL.md+++ b/.skills/discourse-ai-llm-presets/SKILL.md@@ -91,7 +91,9 @@ Every preset model needs a one-line description in `config/locales/client.en.yml<provider_id>-<model_name>```-…with `.`, `/`, and `:` all replaced by `-` (handled in JS by `llm.id.replace(/[.:\/]/g, "-")` in `ai-llms-list-editor.gjs`).+…with `.`, `/`, and `:` all replaced by `-` (handled in JS by `id.replace(/[.:\/]/g, "-")` in `ai-model-new.gjs`).++Embedding and decision model presets (`EmbeddingDefinition.presets`, `DecisionModel.presets`) use the same pattern, keyed by `preset_id` under `discourse_ai.embeddings.preset_descriptions` and `discourse_ai.decision_models.preset_descriptions`. When any of those preset lists change, add/remove the matching keys too.Examples:| Provider | Model `name` | i18n key |diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-decision-model-editor-form.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-decision-model-editor-form.gjsindex cb84b741c6e..a0d94a6cde6 100644--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-decision-model-editor-form.gjs+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-decision-model-editor-form.gjs@@ -14,6 +14,19 @@ import { eq, gte, or } from "discourse/truth-helpers";import { i18n } from "discourse-i18n";import AiSecretSelector from "discourse/plugins/discourse-ai/discourse/components/ai-secret-selector";+function presetFields(preset) {+ return {+ display_name: preset.display_name,+ name: preset.name,+ provider: preset.provider,+ url: preset.url,+ vision_enabled: preset.vision_enabled,+ custom_headers: (preset.custom_headers ?? []).map((header) => ({+ ...header,+ })),+ };+}+export default class AiDecisionModelEditorForm extends Component {@service dialog;@service router;@@ -25,8 +38,7 @@ export default class AiDecisionModelEditorForm extends Component {@cachedget formData() {const { model } = this.args;-- return {+ const data = {display_name: model.display_name,name: model.name,provider: model.provider || this.providers[0],@@ -35,6 +47,17 @@ export default class AiDecisionModelEditorForm extends Component {vision_enabled: model.vision_enabled ?? false,custom_headers: model.custom_headers ?? [],};++ const preset =+ model.isNew &&+ this.presets.find((item) => item.preset_id === this.args.preset);+ if (preset) {+ Object.assign(data, presetFields(preset), {+ preset: preset.preset_id,+ });+ }++ return data;}get customHeaderLimits() {@@ -69,7 +92,7 @@ export default class AiDecisionModelEditorForm extends Component {this.args.model);this.router.transitionTo(- "adminPlugins.show.discourse-ai-decision-models.index"+ "adminPlugins.show.discourse-ai-models.index");} catch (e) {popupAjaxError(e);@@ -110,14 +133,12 @@ export default class AiDecisionModelEditorForm extends Component {await set("preset", value);const preset = this.presets.find((item) => item.preset_id === value);if (preset) {- for (const name of ["display_name", "name", "url", "vision_enabled"]) {- await set(name, preset[name]);+ const { provider, custom_headers, ...fields } = presetFields(preset);+ for (const [name, fieldValue] of Object.entries(fields)) {+ await set(name, fieldValue);}- await this.selectProvider(preset.provider, { set });- await set(- "custom_headers",- (preset.custom_headers ?? []).map((header) => ({ ...header }))- );+ await this.selectProvider(provider, { set });+ await set("custom_headers", custom_headers);}this.testResult = null;}@@ -146,8 +167,8 @@ export default class AiDecisionModelEditorForm extends Component {<template><BackButton- @label="discourse_ai.decision_models.back"- @route="adminPlugins.show.discourse-ai-decision-models"+ @label="discourse_ai.models.back"+ @route="adminPlugins.show.discourse-ai-models"/><Formclass="ai-decision-model-editor"diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-decision-model-editor.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-decision-model-editor.gjsnew file mode 100644index 00000000000..65dcc1d6758--- /dev/null+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-decision-model-editor.gjs@@ -0,0 +1,23 @@+import Component from "@glimmer/component";+import { service } from "@ember/service";+import DBreadcrumbsItem from "discourse/ui-kit/d-breadcrumbs-item";+import { i18n } from "discourse-i18n";+import AiDecisionModelEditorForm from "./ai-decision-model-editor-form.gjs";++export default class AiDecisionModelEditor extends Component {+ @service adminPluginNavManager;++ <template>+ <DBreadcrumbsItem+ @label={{i18n "discourse_ai.models.short_title"}}+ @path="/admin/plugins/{{this.adminPluginNavManager.currentPlugin.name}}/ai-models"+ />+ <section class="admin-detail">+ <AiDecisionModelEditorForm+ @decisionModels={{@decisionModels}}+ @model={{@model}}+ @preset={{@preset}}+ />+ </section>+ </template>+}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-decision-models-list-editor.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-decision-models-list-editor.gjsdeleted file mode 100644index d8e63cb6567..00000000000--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-decision-models-list-editor.gjs+++ /dev/null@@ -1,98 +0,0 @@-import { concat } from "@ember/helper";-import AdminConfigAreaEmptyList from "discourse/admin/components/admin-config-area-empty-list";-import DBreadcrumbsItem from "discourse/ui-kit/d-breadcrumbs-item";-import DButton from "discourse/ui-kit/d-button";-import DPageSubheader from "discourse/ui-kit/d-page-subheader";-import { i18n } from "discourse-i18n";-import AiCreditAllocationStatus from "discourse/plugins/discourse-ai/discourse/components/ai-credit-allocation-status";--export default <template>- <DBreadcrumbsItem- @label={{i18n "discourse_ai.decision_models.short_title"}}- @route="adminPlugins.show.discourse-ai-decision-models"- />- <section class="ai-decision-models-list-editor admin-detail">- <DPageSubheader- @descriptionLabel={{i18n "discourse_ai.decision_models.description"}}- @titleLabel={{i18n "discourse_ai.decision_models.short_title"}}- >- <:actions as |actions|>- <actions.Primary- class="ai-decision-models-list-editor__new-btn"- @icon="plus"- @label="discourse_ai.decision_models.create_new"- @route="adminPlugins.show.discourse-ai-decision-models.new"- />- </:actions>- </DPageSubheader>-- {{#if @decisionModels.content.length}}- <table class="d-table">- <thead class="d-table__header">- <tr>- <th>{{i18n "discourse_ai.decision_models.display_name"}}</th>- <th>{{i18n "discourse_ai.decision_models.model"}}</th>- <th>{{i18n "discourse_ai.decision_models.provider"}}</th>- <th></th>- </tr>- </thead>- <tbody>- {{#each @decisionModels.content as |decisionModel|}}- <tr- class="ai-decision-models-list-editor__row d-table__row"- data-decision-model-id={{decisionModel.id}}- >- <td class="d-table__cell --overview">- <strong>{{decisionModel.display_name}}</strong>- {{#if decisionModel.seeded}}- <div class="ai-decision-models-list-editor__seeded">- {{i18n "discourse_ai.decision_models.seeded_description"}}- </div>- {{/if}}- {{#if decisionModel.credit_allocation}}- <AiCreditAllocationStatus- @allocation={{decisionModel.credit_allocation}}- />- {{/if}}- </td>- <td class="d-table__cell --detail">- <div class="d-table__mobile-label">- {{i18n "discourse_ai.decision_models.model"}}- </div>- {{decisionModel.name}}- </td>- <td class="d-table__cell --detail">- <div class="d-table__mobile-label">- {{i18n "discourse_ai.decision_models.provider"}}- </div>- {{i18n- (concat- "discourse_ai.decision_models.providers."- decisionModel.provider- )- }}- </td>- <td class="d-table__cell --controls">- {{#unless decisionModel.seeded}}- <DButton- class="btn-default btn-small ai-decision-models-list-editor__edit-btn"- @label="discourse_ai.decision_models.edit"- @route="adminPlugins.show.discourse-ai-decision-models.edit"- @routeModels={{decisionModel.id}}- />- {{/unless}}- </td>- </tr>- {{/each}}- </tbody>- </table>- {{else}}- <AdminConfigAreaEmptyList- @ctaClass="ai-decision-models-list-editor__empty-new-btn"- @ctaLabel="discourse_ai.decision_models.create_new"- @ctaRoute="adminPlugins.show.discourse-ai-decision-models.new"- @emptyLabel="discourse_ai.decision_models.no_decision_models"- />- {{/if}}- </section>-</template>diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-embedding-editor.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-embedding-editor.gjsindex af92eb458fd..98841f01019 100644--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-embedding-editor.gjs+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-embedding-editor.gjs@@ -39,6 +39,9 @@ export default class AiEmbeddingEditor extends Component {if (this.args.model) {this.currentProvider = this.args.model.provider;}+ if (this.args.preset && this.args.model?.isNew) {+ this.configurePreset({ id: this.args.preset });+ }}@cached@@ -206,6 +209,13 @@ export default class AiEmbeddingEditor extends Component {@actionresetForm() {+ if (this.args.preset) {+ this.router.transitionTo("adminPlugins.show.discourse-ai-models.new", {+ queryParams: { type: "embedding" },+ });+ return;+ }+this.selectedPreset = null;this.currentProvider = null;}@@ -232,9 +242,7 @@ export default class AiEmbeddingEditor extends Component {}if (isNew) {- this.router.transitionTo(- "adminPlugins.show.discourse-ai-embeddings.index"- );+ this.router.transitionTo("adminPlugins.show.discourse-ai-models.index");} else {const savedProvider = this.currentProvider;@@ -300,7 +308,7 @@ export default class AiEmbeddingEditor extends Component {.then(() => {removeValueFromArray(this.args.embeddings, this.args.model);this.router.transitionTo(- "adminPlugins.show.discourse-ai-embeddings.index"+ "adminPlugins.show.discourse-ai-models.index");}).catch(popupAjaxError);@@ -316,8 +324,8 @@ export default class AiEmbeddingEditor extends Component {<template>{{#if this.showPresets}}<BackButton- @label="discourse_ai.embeddings.back"- @route="adminPlugins.show.discourse-ai-embeddings"+ @label="discourse_ai.models.back"+ @route="adminPlugins.show.discourse-ai-models"/><div class="control-group"><h2>{{i18n "discourse_ai.embeddings.presets"}}</h2>@@ -359,8 +367,8 @@ export default class AiEmbeddingEditor extends Component {/>{{else}}<BackButton- @label="discourse_ai.embeddings.back"- @route="adminPlugins.show.discourse-ai-embeddings"+ @label="discourse_ai.models.back"+ @route="adminPlugins.show.discourse-ai-models"/>{{/if}}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-embeddings-list-editor.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-embeddings-list-editor.gjsindex 7c5a292de2d..6918c11a034 100644--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-embeddings-list-editor.gjs+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-embeddings-list-editor.gjs@@ -1,114 +1,23 @@import Component from "@glimmer/component";-import { concat } from "@ember/helper";import { service } from "@ember/service";-import AdminConfigAreaEmptyList from "discourse/admin/components/admin-config-area-empty-list";-import DTooltip from "discourse/float-kit/components/d-tooltip";import DBreadcrumbsItem from "discourse/ui-kit/d-breadcrumbs-item";-import DButton from "discourse/ui-kit/d-button";-import DPageSubheader from "discourse/ui-kit/d-page-subheader";import { i18n } from "discourse-i18n";import AiEmbeddingEditor from "./ai-embedding-editor.gjs";export default class AiEmbeddingsListEditor extends Component {@service adminPluginNavManager;- get hasEmbeddingElements() {- return this.args.embeddings.content.length !== 0;- }-<template><DBreadcrumbsItem- @label={{i18n "discourse_ai.embeddings.short_title"}}- @path="/admin/plugins/{{this.adminPluginNavManager.currentPlugin.name}}/ai-embeddings"+ @label={{i18n "discourse_ai.models.short_title"}}+ @path="/admin/plugins/{{this.adminPluginNavManager.currentPlugin.name}}/ai-models"/><section class="ai-embeddings-list-editor admin-detail">- {{#if @currentEmbedding}}- <AiEmbeddingEditor- @embeddings={{@embeddings}}- @model={{@currentEmbedding}}- />- {{else}}- <DPageSubheader- @descriptionLabel={{i18n "discourse_ai.embeddings.description"}}- @learnMoreUrl="https://meta.discourse.org/t/discourse-ai-embeddings/259603"- @titleLabel={{i18n "discourse_ai.embeddings.short_title"}}- >- <:actions as |actions|>- <actions.Primary- class="ai-embeddings-list-editor__new-button"- @icon="plus"- @label="discourse_ai.embeddings.new"- @route="adminPlugins.show.discourse-ai-embeddings.new"- />- </:actions>- </DPageSubheader>-- {{#if this.hasEmbeddingElements}}- <table class="d-table">- <thead class="d-table__header">- <tr>- <th>{{i18n "discourse_ai.embeddings.display_name"}}</th>- <th>{{i18n "discourse_ai.embeddings.provider"}}</th>- <th></th>- </tr>- </thead>- <tbody>- {{#each @embeddings.content as |embedding|}}- <tr class="ai-embeddings-list__row d-table__row">- <td class="d-table__cell --overview">- <div class="ai-embeddings-list__name">- <strong>- {{embedding.display_name}}- </strong>- </div>- </td>- <td class="d-table__cell --detail">- <div class="d-table__mobile-label">- {{i18n "discourse_ai.embeddings.provider"}}- </div>- {{i18n- (concat- "discourse_ai.embeddings.providers." embedding.provider- )- }}- </td>- <td class="d-table__cell --controls">- {{#if embedding.seeded}}- <DTooltip- class="ai-embeddings-list__edit-disabled-tooltip"- >- <:trigger>- <DButton- class="btn btn-default btn-small disabled"- @label="discourse_ai.embeddings.edit"- />- </:trigger>- <:content>- {{i18n "discourse_ai.embeddings.seeded_warning"}}- </:content>- </DTooltip>- {{else}}- <DButton- class="btn btn-default btn-small ai-embeddings-list__edit-button"- @label="discourse_ai.embeddings.edit"- @route="adminPlugins.show.discourse-ai-embeddings.edit"- @routeModels={{embedding.id}}- />- {{/if}}- </td>- </tr>- {{/each}}- </tbody>- </table>- {{else}}- <AdminConfigAreaEmptyList- @ctaClass="ai-embeddings-list-editor__empty-new-button"- @ctaLabel="discourse_ai.embeddings.new"- @ctaRoute="adminPlugins.show.discourse-ai-embeddings.new"- @emptyLabel="discourse_ai.embeddings.empty"- />- {{/if}}- {{/if}}+ <AiEmbeddingEditor+ @embeddings={{@embeddings}}+ @model={{@currentEmbedding}}+ @preset={{@preset}}+ /></section></template>}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor-form.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor-form.gjsindex 220b09eb3a1..3da4b29721a 100644--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor-form.gjs+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor-form.gjs@@ -326,7 +326,7 @@ export default class AiLlmEditorForm extends Component {.then(() => {removeValueFromArray(this.args.llms.content, this.args.model);this.router.transitionTo(- "adminPlugins.show.discourse-ai-llms.index"+ "adminPlugins.show.discourse-ai-models.index");}).catch(popupAjaxError);diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor.gjsindex c90b580ed8f..540697c444d 100644--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor.gjs+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-editor.gjs@@ -3,8 +3,8 @@ import AiLlmEditorForm from "./ai-llm-editor-form.gjs";const AiLlmEditor = <template><BackButton- @label="discourse_ai.llms.back"- @route="adminPlugins.show.discourse-ai-llms"+ @label="discourse_ai.models.back"+ @route="adminPlugins.show.discourse-ai-models"/><AiLlmEditorForm@llms={{@llms}}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-usages.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-usages.gjsnew file mode 100644index 00000000000..084eeec6802--- /dev/null+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llm-usages.gjs@@ -0,0 +1,99 @@+import Component from "@glimmer/component";+import { LinkTo } from "@ember/routing";+import I18n, { i18n } from "discourse-i18n";++const FEATURE_USAGE_TYPES = new Set([+ "ai_bot",+ "ai_helper",+ "ai_image_caption",+ "ai_summarization",+ "ai_embeddings_semantic_search",+]);++const RECORD_USAGE_ROUTES = {+ ai_agent: { route: "adminPlugins.show.discourse-ai-agents.edit" },+ automation: {+ route: "adminPlugins.show.automation.edit",+ parentModel: "automation",+ },+ vision_delegate: { route: "adminPlugins.show.discourse-ai-llms.edit" },+};++export function usageRoute(usage) {+ if (!usage?.type) {+ return null;+ }++ if (FEATURE_USAGE_TYPES.has(usage.type)) {+ return usage.id === null || usage.id === undefined+ ? null+ : {+ route: "adminPlugins.show.discourse-ai-features.edit",+ models: [usage.id],+ };+ }++ if (usage.type === "ai_spam") {+ return { route: "adminPlugins.show.discourse-ai-spam" };+ }++ const target = RECORD_USAGE_ROUTES[usage.type];++ if (!target || usage.id === null || usage.id === undefined) {+ return null;+ }++ return {+ route: target.route,+ models: target.parentModel ? [target.parentModel, usage.id] : [usage.id],+ };+}++function localizeUsage(usage) {+ if (!usage?.type) {+ return usage?.name || "";+ }++ const key = `discourse_ai.llms.usage.${usage.type}`;+ if (I18n.lookup(key, { ignoreMissing: true })) {+ return i18n(key, { agent: usage.name });+ }++ return usage.name || usage.type;+}++class UsageItem extends Component {+ get target() {+ return usageRoute(this.args.usage);+ }++ get label() {+ return localizeUsage(this.args.usage);+ }++ <template>+ {{#if this.target}}+ {{#if this.target.models}}+ <LinkTo @models={{this.target.models}} @route={{this.target.route}}>+ {{this.label}}+ </LinkTo>+ {{else}}+ <LinkTo @route={{this.target.route}}>{{this.label}}</LinkTo>+ {{/if}}+ {{else}}+ {{this.label}}+ {{/if}}+ </template>+}++const AiLlmUsages = <template>+ {{#if @usages}}+ <ul class="ai-llm-list-editor__usages">+ {{#each @usages as |usage|}}+ <li><UsageItem @usage={{usage}} /></li>+ {{/each}}+ </ul>+ {{/if}}+</template>;++export default AiLlmUsages;diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llms-list-editor.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llms-list-editor.gjsindex da65f2c9f95..06be8ad1e33 100644--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llms-list-editor.gjs+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-llms-list-editor.gjs@@ -1,319 +1,23 @@import Component from "@glimmer/component";-import { concat, fn } from "@ember/helper";-import { action } from "@ember/object";-import { LinkTo } from "@ember/routing";import { service } from "@ember/service";-import AdminSectionLandingItem from "discourse/admin/components/admin-section-landing-item";-import AdminSectionLandingWrapper from "discourse/admin/components/admin-section-landing-wrapper";import DBreadcrumbsItem from "discourse/ui-kit/d-breadcrumbs-item";-import DButton from "discourse/ui-kit/d-button";-import DPageSubheader from "discourse/ui-kit/d-page-subheader";-import I18n, { i18n } from "discourse-i18n";-import AiCreditAllocationStatus from "discourse/plugins/discourse-ai/discourse/components/ai-credit-allocation-status";-import AiDefaultLlmSelector from "./ai-default-llm-selector.gjs";+import { i18n } from "discourse-i18n";import AiLlmEditor from "./ai-llm-editor.gjs";-function isPreseeded(llm) {- if (llm.id < 0) {- return true;- }-}--const FEATURE_USAGE_TYPES = new Set([- "ai_bot",- "ai_helper",- "ai_image_caption",- "ai_summarization",- "ai_embeddings_semantic_search",-]);--const RECORD_USAGE_ROUTES = {- ai_agent: { route: "adminPlugins.show.discourse-ai-agents.edit" },- automation: {- route: "adminPlugins.show.automation.edit",- parentModel: "automation",- },- vision_delegate: { route: "adminPlugins.show.discourse-ai-llms.edit" },-};--export function usageRoute(usage) {- if (!usage?.type) {- return null;- }-- if (FEATURE_USAGE_TYPES.has(usage.type)) {- return usage.id === null || usage.id === undefined- ? null- : {- route: "adminPlugins.show.discourse-ai-features.edit",- models: [usage.id],- };- }-- if (usage.type === "ai_spam") {- return { route: "adminPlugins.show.discourse-ai-spam" };- }-- const target = RECORD_USAGE_ROUTES[usage.type];-- if (!target || usage.id === null || usage.id === undefined) {- return null;- }-- return {- route: target.route,- models: target.parentModel ? [target.parentModel, usage.id] : [usage.id],- };-}--class UsageItem extends Component {- get target() {- return usageRoute(this.args.usage);- }-- <template>- {{#if this.target}}- {{#if this.target.models}}- <LinkTo @models={{this.target.models}} @route={{this.target.route}}>- {{@label}}- </LinkTo>- {{else}}- <LinkTo @route={{this.target.route}}>{{@label}}</LinkTo>- {{/if}}- {{else}}- {{@label}}- {{/if}}- </template>-}-export default class AiLlmsListEditor extends Component {@service adminPluginNavManager;- @service router;-- get hasLlmElements() {- return this.args.llms.content.length !== 0;- }-- get preconfiguredTitle() {- if (this.hasLlmElements) {- return "discourse_ai.llms.preconfigured.title";- } else {- return "discourse_ai.llms.preconfigured.title_no_llms";- }- }-- get preConfiguredLlms() {- const options = [- {- id: "none",- name: i18n("discourse_ai.llms.preconfigured.fake"),- provider: "fake",- },- ];-- const llmsContent = this.args.llms.content.map((llm) => ({- provider: llm.provider,- name: llm.name,- }));-- this.args.llms.resultSetMeta.presets.forEach((llm) => {- if (llm.models) {- llm.models.forEach((model) => {- const id = `${llm.id}-${model.name}`;- const isConfigured = llmsContent.some(- (content) =>- content.provider === llm.provider && content.name === model.name- );-- if (!isConfigured) {- options.push({- id,- name: model.display_name,- provider: llm.provider,- });- }- });- }- });-- return options;- }-- @action- modelDescription(llm) {- // this is a bit of an odd object, it can be an llm model or a preset model- // handle both flavors-- // in the case of model- let key;- if (typeof llm.id === "number") {- key = `${llm.provider}-${llm.name}`;- } else {- // case of preset- key = llm.id.replace(/[.:\/]/g, "-");- }-- key = `discourse_ai.llms.model_description.${key}`;- if (I18n.lookup(key, { ignoreMissing: true })) {- return i18n(key);- }- return "";- }-- @action- preseededDescription(llm) {- if (isPreseeded(llm)) {- return i18n("discourse_ai.llms.preseeded_model_description", {- model: llm.name,- });- }- }-- sanitizedTranslationKey(id) {- return id.replace(/\./g, "-");- }-- @action- transitionToLlmEditor(llmTemplate) {- this.router.transitionTo("adminPlugins.show.discourse-ai-llms.new", {- queryParams: { llmTemplate },- });- }-- localizeUsage(usage) {- if (!usage?.type) {- return usage?.name || "";- }-- const key = `discourse_ai.llms.usage.${usage.type}`;- if (I18n.lookup(key, { ignoreMissing: true })) {- return i18n(key, { agent: usage.name });- }-- return usage.name || usage.type;- }<template><DBreadcrumbsItem- @label={{i18n "discourse_ai.llms.short_title"}}- @path="/admin/plugins/{{this.adminPluginNavManager.currentPlugin.name}}/ai-llms"+ @label={{i18n "discourse_ai.models.short_title"}}+ @path="/admin/plugins/{{this.adminPluginNavManager.currentPlugin.name}}/ai-models"/><section class="ai-llm-list-editor admin-detail">- {{#if @currentLlm}}- <AiLlmEditor- @llms={{@llms}}- @llmTemplate={{@llmTemplate}}- @model={{@currentLlm}}- />- {{else}}- <DPageSubheader- @descriptionLabel={{i18n- "discourse_ai.llms.preconfigured.description"- }}- @learnMoreUrl="https://meta.discourse.org/t/discourse-ai-large-language-model-llm-settings-page/319903"- @titleLabel={{i18n "discourse_ai.llms.short_title"}}- />-- <AiDefaultLlmSelector />-- {{#if this.hasLlmElements}}- <section class="ai-llms-list-editor__configured">- <DPageSubheader- @titleLabel={{i18n "discourse_ai.llms.configured.title"}}- />- <table class="d-table">- <thead class="d-table__header">- <tr>- <th>{{i18n "discourse_ai.llms.display_name"}}</th>- <th>{{i18n "discourse_ai.llms.provider"}}</th>- <th></th>- </tr>- </thead>- <tbody>- {{#each @llms.content as |llm|}}- <tr- class="ai-llm-list__row d-table__row"- data-llm-id={{llm.name}}- >- <td class="d-table__cell --overview">-- <div class="ai-llm-list__name">- <strong>- {{llm.display_name}}- </strong>- </div>- <div class="ai-llm-list__description">- {{this.modelDescription llm}}- {{this.preseededDescription llm}}- </div>- {{#if llm.used_by}}- <ul class="ai-llm-list-editor__usages">- {{#each llm.used_by as |usage|}}- <li>- <UsageItem- @label={{this.localizeUsage usage}}- @usage={{usage}}- />- </li>- {{/each}}- </ul>- {{/if}}- {{#if llm.llm_credit_allocation}}- <AiCreditAllocationStatus- @allocation={{llm.llm_credit_allocation}}- />- {{/if}}- </td>- <td class="d-table__cell --detail">- <div class="d-table__mobile-label">- {{i18n "discourse_ai.llms.provider"}}- </div>- {{i18n- (concat "discourse_ai.llms.providers." llm.provider)- }}- </td>- <td class="d-table__cell --controls">- <DButton- class="btn btn-default btn-small ai-llm-list__edit-button"- @label="discourse_ai.llms.edit"- @route="adminPlugins.show.discourse-ai-llms.edit"- @routeModels={{llm.id}}- />- </td>- </tr>- {{/each}}- </tbody>- </table>- </section>- {{/if}}- <section class="ai-llms-list-editor__templates">- <DPageSubheader @titleLabel={{i18n this.preconfiguredTitle}} />- <AdminSectionLandingWrapper- class="ai-llms-list-editor__templates-list"- >- {{#each this.preConfiguredLlms as |llm|}}- <AdminSectionLandingItem- class="ai-llms-list-editor__templates-list-item"- data-llm-id={{llm.id}}- @descriptionLabelTranslated={{this.modelDescription llm}}- @taglineLabel={{concat- "discourse_ai.llms.providers."- llm.provider- }}- @titleLabelTranslated={{llm.name}}- >- <:buttons as |buttons|>- <buttons.Default- @action={{fn this.transitionToLlmEditor llm.id}}- @icon="gear"- @label="discourse_ai.llms.preconfigured.button"- />- </:buttons>- </AdminSectionLandingItem>- {{/each}}- </AdminSectionLandingWrapper>- </section>- {{/if}}+ <AiLlmEditor+ @llms={{@llms}}+ @llmTemplate={{@llmTemplate}}+ @model={{@currentLlm}}+ /></section></template>}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-model-new.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-model-new.gjsnew file mode 100644index 00000000000..86cbf39b260--- /dev/null+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-model-new.gjs@@ -0,0 +1,259 @@+import Component from "@glimmer/component";+import { concat, fn, hash } from "@ember/helper";+import { action } from "@ember/object";+import { service } from "@ember/service";+import { trustHTML } from "@ember/template";+import AdminSectionLandingItem from "discourse/admin/components/admin-section-landing-item";+import AdminSectionLandingWrapper from "discourse/admin/components/admin-section-landing-wrapper";+import BackButton from "discourse/components/back-button";+import { escapeExpression } from "discourse/lib/utilities";+import DBreadcrumbsItem from "discourse/ui-kit/d-breadcrumbs-item";+import DPageSubheader from "discourse/ui-kit/d-page-subheader";+import I18n, { i18n } from "discourse-i18n";+import { modelTypes } from "./ai-models-list.gjs";++const LEARN_MORE_URLS = {+ llm: "https://meta.discourse.org/t/discourse-ai-large-language-model-llm-settings-page/319903",+ embedding: "https://meta.discourse.org/t/discourse-ai-embeddings/259603",+ decision:+ "https://meta.discourse.org/t/typesafe-jev-and-other-system-one-decision-models/414738",+};++export default class AiModelNew extends Component {+ @service adminPluginNavManager;+ @service router;++ get types() {+ return modelTypes(this.args.decisionModels);+ }++ get selectedType() {+ return this.types.includes(this.args.type) ? this.args.type : null;+ }++ get typeOptions() {+ return this.types.map((type) => ({+ type,+ title: i18n(`discourse_ai.models.type_titles.${type}`),+ description: this.#typeDescription(type),+ }));+ }++ get templates() {+ switch (this.selectedType) {+ case "llm":+ return this.llmTemplates;+ case "embedding":+ return this.embeddingTemplates;+ case "decision":+ return this.decisionTemplates;+ default:+ return [];+ }+ }++ get llmTemplates() {+ const configured = this.args.llms.content;+ const templates = [+ {+ id: "none",+ name: i18n("discourse_ai.llms.preconfigured.fake"),+ tagline: i18n("discourse_ai.llms.providers.fake"),+ description: this.#llmPresetDescription("none"),+ },+ ];++ this.args.llms.resultSetMeta.presets.forEach((preset) => {+ preset.models?.forEach((model) => {+ const isConfigured = configured.some(+ (llm) => llm.provider === preset.provider && llm.name === model.name+ );+ if (isConfigured) {+ return;+ }++ const id = `${preset.id}-${model.name}`;+ templates.push({+ id,+ name: model.display_name,+ tagline: i18n(`discourse_ai.llms.providers.${preset.provider}`),+ description: this.#llmPresetDescription(id),+ });+ });+ });++ return templates;+ }++ get embeddingTemplates() {+ return [+ {+ id: "manual",+ name: i18n("discourse_ai.embeddings.configure_manually"),+ tagline: i18n("discourse_ai.embeddings.providers.fake"),+ description: this.#translatedPresetDescription("embeddings", "manual"),+ },+ ...this.args.embeddings.resultSetMeta.presets.map((preset) => ({+ id: preset.preset_id,+ name: preset.display_name,+ tagline: i18n(`discourse_ai.embeddings.providers.${preset.provider}`),+ description: this.#translatedPresetDescription(+ "embeddings",+ preset.preset_id+ ),+ })),+ ];+ }++ get decisionTemplates() {+ return [+ {+ id: "none",+ name: i18n("discourse_ai.llms.preconfigured.fake"),+ description: this.#translatedPresetDescription(+ "decision_models",+ "none"+ ),+ },+ ...this.args.decisionModels.resultSetMeta.presets.map((preset) => ({+ id: preset.preset_id,+ name: preset.display_name,+ tagline: i18n(+ `discourse_ai.decision_models.providers.${preset.provider}`+ ),+ description: this.#translatedPresetDescription(+ "decision_models",+ preset.preset_id+ ),+ })),+ ];+ }++ @action+ chooseType(type) {+ this.router.transitionTo("adminPlugins.show.discourse-ai-models.new", {+ queryParams: { type },+ });+ }++ @action+ chooseTemplate(template) {+ switch (this.selectedType) {+ case "llm":+ this.router.transitionTo("adminPlugins.show.discourse-ai-llms.new", {+ queryParams: { llmTemplate: template.id },+ });+ break;+ case "embedding":+ this.router.transitionTo(+ "adminPlugins.show.discourse-ai-embeddings.new",+ { queryParams: { preset: template.id } }+ );+ break;+ case "decision":+ this.router.transitionTo(+ "adminPlugins.show.discourse-ai-decision-models.new",+ {+ queryParams: {+ preset: template.id === "none" ? null : template.id,+ },+ }+ );+ break;+ }+ }++ #typeDescription(type) {+ const description = i18n(`discourse_ai.models.type_descriptions.${type}`);+ const url = LEARN_MORE_URLS[type];+ if (!url) {+ return description;+ }++ return trustHTML(+ `${escapeExpression(description)} ${i18n("learn_more_with_link", { url })}`+ );+ }++ #translatedPresetDescription(scope, id) {+ const key = `discourse_ai.${scope}.preset_descriptions.${id}`;+ return I18n.lookup(key, { ignoreMissing: true }) ? i18n(key) : "";+ }++ #llmPresetDescription(id) {+ const key = `discourse_ai.llms.model_description.${id.replace(+ /[.:\/]/g,+ "-"+ )}`;+ return I18n.lookup(key, { ignoreMissing: true }) ? i18n(key) : "";+ }++ <template>+ <DBreadcrumbsItem+ @label={{i18n "discourse_ai.models.short_title"}}+ @path="/admin/plugins/{{this.adminPluginNavManager.currentPlugin.name}}/ai-models"+ />+ <DBreadcrumbsItem+ @label={{i18n "discourse_ai.models.new"}}+ @path="/admin/plugins/{{this.adminPluginNavManager.currentPlugin.name}}/ai-models/new"+ />+ <section class="ai-model-new admin-detail">+ {{#if this.selectedType}}+ <BackButton+ @label="discourse_ai.models.back_to_types"+ @query={{hash type=null}}+ @route="adminPlugins.show.discourse-ai-models.new"+ />+ <DPageSubheader+ @titleLabel={{i18n+ (concat "discourse_ai.models.templates." this.selectedType)+ }}+ />+ <AdminSectionLandingWrapper class="ai-llms-list-editor__templates-list">+ {{#each this.templates as |template|}}+ <AdminSectionLandingItem+ class="ai-llms-list-editor__templates-list-item"+ data-template-id={{template.id}}+ @descriptionLabelTranslated={{template.description}}+ @taglineLabelTranslated={{template.tagline}}+ @titleLabelTranslated={{template.name}}+ >+ <:buttons as |buttons|>+ <buttons.Default+ @action={{fn this.chooseTemplate template}}+ @icon="gear"+ @label="discourse_ai.llms.preconfigured.button"+ />+ </:buttons>+ </AdminSectionLandingItem>+ {{/each}}+ </AdminSectionLandingWrapper>+ {{else}}+ <BackButton+ @label="discourse_ai.models.back"+ @route="adminPlugins.show.discourse-ai-models.index"+ />+ <DPageSubheader+ @titleLabel={{i18n "discourse_ai.models.choose_type"}}+ />+ <AdminSectionLandingWrapper class="ai-llms-list-editor__templates-list">+ {{#each this.typeOptions as |option|}}+ <AdminSectionLandingItem+ class="ai-llms-list-editor__templates-list-item ai-model-new__type"+ data-model-type={{option.type}}+ @descriptionLabelTranslated={{option.description}}+ @titleLabelTranslated={{option.title}}+ >+ <:buttons as |buttons|>+ <buttons.Default+ @action={{fn this.chooseType option.type}}+ @label="discourse_ai.models.select_type"+ />+ </:buttons>+ </AdminSectionLandingItem>+ {{/each}}+ </AdminSectionLandingWrapper>+ {{/if}}+ </section>+ </template>+}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-models-list.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-models-list.gjsnew file mode 100644index 00000000000..2282f4cd618--- /dev/null+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-models-list.gjs@@ -0,0 +1,300 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { concat, hash } from "@ember/helper";+import { action } from "@ember/object";+import { service } from "@ember/service";+import AdminConfigAreaEmptyList from "discourse/admin/components/admin-config-area-empty-list";+import DTooltip from "discourse/float-kit/components/d-tooltip";+import { eq } from "discourse/truth-helpers";+import DBreadcrumbsItem from "discourse/ui-kit/d-breadcrumbs-item";+import DButton from "discourse/ui-kit/d-button";+import DFilterInput from "discourse/ui-kit/d-filter-input";+import DNativeSelect from "discourse/ui-kit/d-native-select";+import DPageSubheader from "discourse/ui-kit/d-page-subheader";+import I18n, { i18n } from "discourse-i18n";+import AiCreditAllocationStatus from "discourse/plugins/discourse-ai/discourse/components/ai-credit-allocation-status";+import AiDefaultLlmSelector from "./ai-default-llm-selector.gjs";+import AiLlmUsages from "./ai-llm-usages.gjs";++const ALL = "all";++// Decision models only exist where workflows are enabled, so the route passes none otherwise.+export function modelTypes(decisionModels) {+ return decisionModels+ ? ["llm", "embedding", "decision"]+ : ["llm", "embedding"];+}++function llmDescription(llm) {+ const key = `discourse_ai.llms.model_description.${llm.provider}-${llm.name}`;+ const parts = [];++ if (I18n.lookup(key, { ignoreMissing: true })) {+ parts.push(i18n(key));+ }+ if (llm.id < 0) {+ parts.push(+ i18n("discourse_ai.llms.preseeded_model_description", {+ model: llm.name,+ })+ );+ }++ return parts.join(" ");+}++export default class AiModelsList extends Component {+ @service adminPluginNavManager;+ @service router;++ @tracked filterValue = "";++ get types() {+ return modelTypes(this.args.decisionModels);+ }++ get selectedType() {+ return this.types.includes(this.args.type) ? this.args.type : ALL;+ }++ get typeOptions() {+ return [+ { value: ALL, label: i18n("discourse_ai.models.filters.all") },+ ...this.types.map((type) => ({+ value: type,+ label: i18n(`discourse_ai.models.type_filters.${type}`),+ })),+ ];+ }++ get rows() {+ const llmRows = this.args.llms.content.map((llm) => ({+ key: `llm-${llm.id}`,+ type: "llm",+ dataId: llm.name,+ name: llm.display_name,+ provider: i18n(`discourse_ai.llms.providers.${llm.provider}`),+ description: llmDescription(llm),+ editRoute: "adminPlugins.show.discourse-ai-llms.edit",+ editModel: llm.id,+ creditAllocation: llm.llm_credit_allocation,+ llm,+ }));++ const embeddingRows = this.args.embeddings.content.map((embedding) => ({+ key: `embedding-${embedding.id}`,+ type: "embedding",+ dataId: embedding.id,+ name: embedding.display_name,+ provider: i18n(`discourse_ai.embeddings.providers.${embedding.provider}`),+ editRoute: "adminPlugins.show.discourse-ai-embeddings.edit",+ editModel: embedding.id,+ seeded: embedding.seeded,+ }));++ const decisionRows = (this.args.decisionModels?.content ?? []).map(+ (decisionModel) => ({+ key: `decision-${decisionModel.id}`,+ type: "decision",+ dataId: decisionModel.id,+ name: decisionModel.display_name,+ provider: i18n(+ `discourse_ai.decision_models.providers.${decisionModel.provider}`+ ),+ description: decisionModel.seeded+ ? i18n("discourse_ai.decision_models.seeded_description")+ : null,+ editRoute: decisionModel.seeded+ ? null+ : "adminPlugins.show.discourse-ai-decision-models.edit",+ editModel: decisionModel.id,+ creditAllocation: decisionModel.credit_allocation,+ })+ );++ return [...llmRows, ...embeddingRows, ...decisionRows];+ }++ get filteredRows() {+ let rows = this.rows;++ if (this.selectedType !== ALL) {+ rows = rows.filter((row) => row.type === this.selectedType);+ }++ const term = this.filterValue.trim().toLowerCase();+ if (term) {+ rows = rows.filter(+ (row) =>+ row.name?.toLowerCase().includes(term) ||+ row.provider?.toLowerCase().includes(term)+ );+ }++ return rows;+ }++ @action+ onFilterChange(event) {+ this.filterValue = event.target?.value || "";+ }++ @action+ onTypeChange(type) {+ this.router.transitionTo({+ queryParams: { type: type === ALL ? null : type },+ });+ }++ @action+ resetFilters() {+ this.filterValue = "";+ this.onTypeChange(ALL);+ }++ <template>+ <DBreadcrumbsItem+ @label={{i18n "discourse_ai.models.short_title"}}+ @path="/admin/plugins/{{this.adminPluginNavManager.currentPlugin.name}}/ai-models"+ />+ <section class="ai-models-list admin-detail">+ <DPageSubheader+ @descriptionLabel={{i18n "discourse_ai.models.description"}}+ @titleLabel={{i18n "discourse_ai.models.short_title"}}+ >+ <:actions as |actions|>+ <actions.Primary+ class="ai-models-list__new-button"+ @icon="plus"+ @label="discourse_ai.models.new"+ @route="adminPlugins.show.discourse-ai-models.new"+ />+ </:actions>+ </DPageSubheader>++ {{#if this.rows.length}}+ <div class="ai-models-list__controls">+ <DNativeSelect+ class="ai-models-list__type-filter"+ @includeNone={{false}}+ @onChange={{this.onTypeChange}}+ @value={{this.selectedType}}+ as |select|+ >+ {{#each this.typeOptions as |option|}}+ <select.Option @value={{option.value}}>+ {{option.label}}+ </select.Option>+ {{/each}}+ </DNativeSelect>++ <DFilterInput+ class="admin-filter__input"+ placeholder={{i18n "discourse_ai.models.filters.text"}}+ @filterAction={{this.onFilterChange}}+ @icons={{hash left="magnifying-glass"}}+ @value={{this.filterValue}}+ />+ </div>++ {{#if (eq this.selectedType "llm")}}+ <AiDefaultLlmSelector />+ {{/if}}++ {{#if this.filteredRows.length}}+ <table class="d-table ai-models-list__table">+ <thead class="d-table__header">+ <tr>+ <th>{{i18n "discourse_ai.models.name"}}</th>+ <th>{{i18n "discourse_ai.models.type"}}</th>+ <th>{{i18n "discourse_ai.models.provider"}}</th>+ <th></th>+ </tr>+ </thead>+ <tbody>+ {{#each this.filteredRows key="key" as |row|}}+ <tr+ class="ai-models-list__row d-table__row+ {{if (eq row.type 'llm') 'ai-llm-list__row'}}"+ data-llm-id={{if row.llm row.dataId}}+ data-model-id={{row.dataId}}+ data-model-type={{row.type}}+ >+ <td class="d-table__cell --overview">+ <div class="ai-models-list__name">+ <strong>{{row.name}}</strong>+ </div>+ {{#if row.description}}+ <div class="ai-models-list__description">+ {{row.description}}+ </div>+ {{/if}}+ {{#if row.llm}}+ <AiLlmUsages @usages={{row.llm.used_by}} />+ {{/if}}+ {{#if row.creditAllocation}}+ <AiCreditAllocationStatus+ @allocation={{row.creditAllocation}}+ />+ {{/if}}+ </td>+ <td class="d-table__cell --detail ai-models-list__type">+ <div class="d-table__mobile-label">+ {{i18n "discourse_ai.models.type"}}+ </div>+ {{i18n (concat "discourse_ai.models.types." row.type)}}+ </td>+ <td class="d-table__cell --detail">+ <div class="d-table__mobile-label">+ {{i18n "discourse_ai.models.provider"}}+ </div>+ {{row.provider}}+ </td>+ <td class="d-table__cell --controls">+ {{#if row.seeded}}+ <DTooltip>+ <:trigger>+ <DButton+ class="btn btn-default btn-small disabled"+ @label="discourse_ai.models.edit"+ />+ </:trigger>+ <:content>+ {{i18n "discourse_ai.embeddings.seeded_warning"}}+ </:content>+ </DTooltip>+ {{else if row.editRoute}}+ <DButton+ class="btn btn-default btn-small ai-models-list__edit-button"+ @label="discourse_ai.models.edit"+ @route={{row.editRoute}}+ @routeModels={{row.editModel}}+ />+ {{/if}}+ </td>+ </tr>+ {{/each}}+ </tbody>+ </table>+ {{else}}+ <div class="ai-models-list__no-results">+ <h3>{{i18n "discourse_ai.models.filters.no_results"}}</h3>+ <DButton+ class="btn-default"+ @action={{this.resetFilters}}+ @icon="arrow-rotate-left"+ @label="discourse_ai.models.filters.reset"+ />+ </div>+ {{/if}}+ {{else}}+ <AdminConfigAreaEmptyList+ @ctaClass="ai-models-list__empty-new-button"+ @ctaLabel="discourse_ai.models.new"+ @ctaRoute="adminPlugins.show.discourse-ai-models.new"+ @emptyLabel="discourse_ai.models.empty"+ />+ {{/if}}+ </section>+ </template>+}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-spam.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-spam.gjsindex 3780b50c0db..52414ff00f5 100644--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-spam.gjs+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/components/ai-spam.gjs@@ -277,7 +277,7 @@ export default class AiSpam extends Component {/>{{else}}<span class="ai-spam__llm-placeholder">- <LinkTo @route="adminPlugins.show.discourse-ai-llms.index">+ <LinkTo @route="adminPlugins.show.discourse-ai-models.new">{{i18n "discourse_ai.spam.no_llms"}}</LinkTo></span>diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-decision-models/index.js b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-decision-models/index.jsnew file mode 100644index 00000000000..838be0a9fe1--- /dev/null+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-decision-models/index.js@@ -0,0 +1,12 @@+import { service } from "@ember/service";+import DiscourseRoute from "discourse/routes/discourse";++export default class AdminPluginsShowDiscourseAiDecisionModelsIndex extends DiscourseRoute {+ @service router;++ beforeModel() {+ this.router.replaceWith("adminPlugins.show.discourse-ai-models.index", {+ queryParams: { type: "decision" },+ });+ }+}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-decision-models/new.js b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-decision-models/new.jsindex 48bfa954ae2..f99487fbe82 100644--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-decision-models/new.js+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-decision-models/new.js@@ -1,6 +1,10 @@import DiscourseRoute from "discourse/routes/discourse";export default class AdminPluginsShowDiscourseAiDecisionModelsNew extends DiscourseRoute {+ queryParams = {+ preset: { refreshModel: true },+ };+model() {return this.store.createRecord("ai-decision-model");}@@ -11,5 +15,6 @@ export default class AdminPluginsShowDiscourseAiDecisionModelsNew extends Discou"allDecisionModels",this.modelFor("adminPlugins.show.discourse-ai-decision-models"));+ controller.set("preset", this.paramsFor(this.routeName).preset || null);}}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-embeddings/index.js b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-embeddings/index.jsnew file mode 100644index 00000000000..6812c1aaae3--- /dev/null+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-embeddings/index.js@@ -0,0 +1,12 @@+import { service } from "@ember/service";+import DiscourseRoute from "discourse/routes/discourse";++export default class AdminPluginsShowDiscourseAiEmbeddingsIndex extends DiscourseRoute {+ @service router;++ beforeModel() {+ this.router.replaceWith("adminPlugins.show.discourse-ai-models.index", {+ queryParams: { type: "embedding" },+ });+ }+}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-embeddings/new.js b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-embeddings/new.jsindex ea8a9239251..14480fb2fb0 100644--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-embeddings/new.js+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-embeddings/new.js@@ -1,6 +1,10 @@import DiscourseRoute from "discourse/routes/discourse";export default class AdminPluginsShowDiscourseAiEmbeddingsNew extends DiscourseRoute {+ queryParams = {+ preset: { refreshModel: true },+ };+async model() {const record = this.store.createRecord("ai-embedding");record.provider_params = {};@@ -13,5 +17,6 @@ export default class AdminPluginsShowDiscourseAiEmbeddingsNew extends DiscourseR"allEmbeddings",this.modelFor("adminPlugins.show.discourse-ai-embeddings"));+ controller.set("preset", this.paramsFor(this.routeName).preset || null);}}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-llms/index.js b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-llms/index.jsnew file mode 100644index 00000000000..38a96e01fe6--- /dev/null+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-llms/index.js@@ -0,0 +1,12 @@+import { service } from "@ember/service";+import DiscourseRoute from "discourse/routes/discourse";++export default class AdminPluginsShowDiscourseAiLlmsIndex extends DiscourseRoute {+ @service router;++ beforeModel() {+ this.router.replaceWith("adminPlugins.show.discourse-ai-models.index", {+ queryParams: { type: "llm" },+ });+ }+}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-models.js b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-models.jsnew file mode 100644index 00000000000..fa7df65dc9a--- /dev/null+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-models.js@@ -0,0 +1,17 @@+import { service } from "@ember/service";+import DiscourseRoute from "discourse/routes/discourse";++export default class DiscourseAiModelsRoute extends DiscourseRoute {+ @service siteSettings;++ async model() {+ const [llms, embeddings, decisionModels] = await Promise.all([+ this.store.findAll("ai-llm"),+ this.store.findAll("ai-embedding"),+ this.siteSettings.enable_discourse_workflows+ ? this.store.findAll("ai-decision-model")+ : null,+ ]);+ return { llms, embeddings, decisionModels };+ }+}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-models/index.js b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-models/index.jsnew file mode 100644index 00000000000..6626807dbfe--- /dev/null+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-models/index.js@@ -0,0 +1,16 @@+import DiscourseRoute from "discourse/routes/discourse";++export default class AdminPluginsShowDiscourseAiModelsIndex extends DiscourseRoute {+ queryParams = {+ type: { refreshModel: true },+ };++ model() {+ return this.modelFor("adminPlugins.show.discourse-ai-models");+ }++ setupController(controller, model) {+ super.setupController(controller, model);+ controller.set("type", this.paramsFor(this.routeName).type || null);+ }+}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-models/new.js b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-models/new.jsnew file mode 100644index 00000000000..aaa1839e279--- /dev/null+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/routes/admin-plugins/show/discourse-ai-models/new.js@@ -0,0 +1,16 @@+import DiscourseRoute from "discourse/routes/discourse";++export default class AdminPluginsShowDiscourseAiModelsNew extends DiscourseRoute {+ queryParams = {+ type: { refreshModel: true },+ };++ model() {+ return this.modelFor("adminPlugins.show.discourse-ai-models");+ }++ setupController(controller, model) {+ super.setupController(controller, model);+ controller.set("type", this.paramsFor(this.routeName).type || null);+ }+}diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-decision-models/edit.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-decision-models/edit.gjsindex ee7aa998de7..66d50539b45 100644--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-decision-models/edit.gjs+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-decision-models/edit.gjs@@ -1,17 +1,8 @@-import AiDecisionModelEditorForm from "../../../../components/ai-decision-model-editor-form.gjs";-import AiDecisionModelsListEditor from "../../../../components/ai-decision-models-list-editor.gjs";+import AiDecisionModelEditor from "../../../../components/ai-decision-model-editor.gjs";export default <template>- {{#if @controller.model}}- <section class="admin-detail">- <AiDecisionModelEditorForm- @decisionModels={{@controller.allDecisionModels}}- @model={{@controller.model}}- />- </section>- {{else}}- <AiDecisionModelsListEditor- @decisionModels={{@controller.allDecisionModels}}- />- {{/if}}+ <AiDecisionModelEditor+ @decisionModels={{@controller.allDecisionModels}}+ @model={{@controller.model}}+ /></template>diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-decision-models/index.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-decision-models/index.gjsdeleted file mode 100644index 7b0199947e0..00000000000--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-decision-models/index.gjs+++ /dev/null@@ -1,5 +0,0 @@-import AiDecisionModelsListEditor from "../../../../components/ai-decision-models-list-editor.gjs";--export default <template>- <AiDecisionModelsListEditor @decisionModels={{@controller.model}} />-</template>diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-decision-models/new.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-decision-models/new.gjsindex 37e2dff0fc5..6bff575461e 100644--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-decision-models/new.gjs+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-decision-models/new.gjs@@ -1,10 +1,9 @@-import AiDecisionModelEditorForm from "../../../../components/ai-decision-model-editor-form.gjs";+import AiDecisionModelEditor from "../../../../components/ai-decision-model-editor.gjs";export default <template>- <section class="admin-detail">- <AiDecisionModelEditorForm- @decisionModels={{@controller.allDecisionModels}}- @model={{@controller.model}}- />- </section>+ <AiDecisionModelEditor+ @decisionModels={{@controller.allDecisionModels}}+ @model={{@controller.model}}+ @preset={{@controller.preset}}+ /></template>diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-embeddings/index.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-embeddings/index.gjsdeleted file mode 100644index 330ea68988f..00000000000--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-embeddings/index.gjs+++ /dev/null@@ -1,5 +0,0 @@-import AiEmbeddingsListEditor from "../../../../components/ai-embeddings-list-editor.gjs";--export default <template>- <AiEmbeddingsListEditor @embeddings={{@controller.model}} />-</template>diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-embeddings/new.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-embeddings/new.gjsindex ef129984e22..2164b5b0979 100644--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-embeddings/new.gjs+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-embeddings/new.gjs@@ -4,5 +4,6 @@ export default <template><AiEmbeddingsListEditor@currentEmbedding={{@controller.model}}@embeddings={{@controller.allEmbeddings}}+ @preset={{@controller.preset}}/></template>diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-llms/index.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-llms/index.gjsdeleted file mode 100644index 8fef0c67060..00000000000--- a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-llms/index.gjs+++ /dev/null@@ -1,5 +0,0 @@-import AiLlmsListEditor from "../../../../components/ai-llms-list-editor.gjs";--export default <template>- <AiLlmsListEditor @llms={{@controller.model}} />-</template>diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-models/index.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-models/index.gjsnew file mode 100644index 00000000000..a8abc3c2a93--- /dev/null+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-models/index.gjs@@ -0,0 +1,10 @@+import AiModelsList from "../../../../components/ai-models-list.gjs";++export default <template>+ <AiModelsList+ @decisionModels={{@controller.model.decisionModels}}+ @embeddings={{@controller.model.embeddings}}+ @llms={{@controller.model.llms}}+ @type={{@controller.type}}+ />+</template>diff --git a/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-models/new.gjs b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-models/new.gjsnew file mode 100644index 00000000000..ab6da59ca40--- /dev/null+++ b/plugins/discourse-ai/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-models/new.gjs@@ -0,0 +1,10 @@+import AiModelNew from "../../../../components/ai-model-new.gjs";++export default <template>+ <AiModelNew+ @decisionModels={{@controller.model.decisionModels}}+ @embeddings={{@controller.model.embeddings}}+ @llms={{@controller.model.llms}}+ @type={{@controller.type}}+ />+</template>diff --git a/plugins/discourse-ai/app/services/problem_check/ai_credit_hard_limit.rb b/plugins/discourse-ai/app/services/problem_check/ai_credit_hard_limit.rbindex f9cd6e893d3..5b67c79af83 100644--- a/plugins/discourse-ai/app/services/problem_check/ai_credit_hard_limit.rb+++ b/plugins/discourse-ai/app/services/problem_check/ai_credit_hard_limit.rb@@ -28,7 +28,7 @@ class ProblemCheck::AiCreditHardLimit < ProblemCheckmodel_id: model.id,model_name: model.display_name,reset_date: format_reset_date(allocation.next_reset_at),- url: "#{Discourse.base_path}/admin/plugins/discourse-ai/ai-llms",+ url: "#{Discourse.base_path}/admin/plugins/discourse-ai/ai-models?type=llm",}problem(model, override_data:)diff --git a/plugins/discourse-ai/app/services/problem_check/ai_credit_soft_limit.rb b/plugins/discourse-ai/app/services/problem_check/ai_credit_soft_limit.rbindex fdd5a6daf4f..18d357a8e92 100644--- a/plugins/discourse-ai/app/services/problem_check/ai_credit_soft_limit.rb+++ b/plugins/discourse-ai/app/services/problem_check/ai_credit_soft_limit.rb@@ -30,7 +30,7 @@ class ProblemCheck::AiCreditSoftLimit < ProblemCheckmodel_name: model.display_name,percentage_remaining: allocation.percentage_remaining.round,reset_date: format_reset_date(allocation.next_reset_at),- url: "#{Discourse.base_path}/admin/plugins/discourse-ai/ai-llms",+ url: "#{Discourse.base_path}/admin/plugins/discourse-ai/ai-models?type=llm",}problem(model, override_data:)diff --git a/plugins/discourse-ai/assets/javascripts/discourse/admin-discourse-ai-plugin-route-map.js b/plugins/discourse-ai/assets/javascripts/discourse/admin-discourse-ai-plugin-route-map.jsindex cf99aff2864..167fc87f65a 100644--- a/plugins/discourse-ai/assets/javascripts/discourse/admin-discourse-ai-plugin-route-map.js+++ b/plugins/discourse-ai/assets/javascripts/discourse/admin-discourse-ai-plugin-route-map.js@@ -10,6 +10,10 @@ export default {});this.route("discourse-ai-agents-legacy", { path: "ai-personas/*path" });+ this.route("discourse-ai-models", { path: "ai-models" }, function () {+ this.route("new");+ });+this.route("discourse-ai-llms", { path: "ai-llms" }, function () {this.route("new");this.route("edit", { path: "/:id/edit" });diff --git a/plugins/discourse-ai/assets/javascripts/discourse/initializers/admin-plugin-configuration-nav.js b/plugins/discourse-ai/assets/javascripts/discourse/initializers/admin-plugin-configuration-nav.jsindex e294763cfed..a7b73e12b8f 100644--- a/plugins/discourse-ai/assets/javascripts/discourse/initializers/admin-plugin-configuration-nav.js+++ b/plugins/discourse-ai/assets/javascripts/discourse/initializers/admin-plugin-configuration-nav.js@@ -11,8 +11,6 @@ export default {return;}- const siteSettings = container.lookup("service:site-settings");-withPluginApi((api) => {api.setAdminPluginIcon(PLUGIN_ID, "discourse-sparkles");api.addAdminPluginConfigurationNav(PLUGIN_ID, [@@ -27,19 +25,10 @@ export default {description: "discourse_ai.usage.subheader_description",},{- label: "discourse_ai.llms.short_title",- route: "adminPlugins.show.discourse-ai-llms",- description: "discourse_ai.llms.preconfigured.description",+ label: "discourse_ai.models.short_title",+ route: "adminPlugins.show.discourse-ai-models",+ description: "discourse_ai.models.description",},- ...(siteSettings.enable_discourse_workflows- ? [- {- label: "discourse_ai.decision_models.short_title",- route: "adminPlugins.show.discourse-ai-decision-models",- description: "discourse_ai.decision_models.description",- },- ]- : []),{label: "discourse_ai.secrets.short_title",route: "adminPlugins.show.discourse-ai-secrets",@@ -50,11 +39,6 @@ export default {route: "adminPlugins.show.discourse-ai-agents",description: "discourse_ai.ai_agent.agent_description",},- {- label: "discourse_ai.embeddings.short_title",- route: "adminPlugins.show.discourse-ai-embeddings",- description: "discourse_ai.embeddings.description",- },{label: "discourse_ai.tools.short_title",route: "adminPlugins.show.discourse-ai-tools",diff --git a/plugins/discourse-ai/assets/stylesheets/modules/llms/common/ai-llms-editor.scss b/plugins/discourse-ai/assets/stylesheets/modules/llms/common/ai-llms-editor.scssindex e36af2b57ff..2ecec850aa2 100644--- a/plugins/discourse-ai/assets/stylesheets/modules/llms/common/ai-llms-editor.scss+++ b/plugins/discourse-ai/assets/stylesheets/modules/llms/common/ai-llms-editor.scss@@ -8,7 +8,6 @@margin: 0 0 1em 0;}- &__configured,&__templates {margin-top: 2em;@@ -63,15 +62,8 @@}}-.ai-llms-list-editor__configured {- .d-toggle-switch {- justify-content: center;- }-}-.ai-tool-list-editor__current,-.ai-agent-list-editor__current,-.ai-llms-list-editor__configured {+.ai-agent-list-editor__current {.d-table {@include viewport.from(md) {th,@@ -162,11 +154,6 @@font-size: var(--font-down-1);}-.ai-decision-models-list-editor__seeded {- color: var(--primary-high);- font-size: var(--font-down-1);-}-@include viewport.until(md) {.ai-llm-list__description {max-width: 80%;@@ -177,3 +164,46 @@gap: var(--space-1);}}++.ai-models-list {+ &__controls {+ display: flex;+ gap: var(--space-2);+ margin-block: var(--space-4);++ .filter-input-container {+ flex: 6 1 auto;+ }++ .d-native-select {+ flex: 1 1 auto;+ max-width: 16em;+ }+ }++ &__type {+ white-space: nowrap;+ }++ &__no-results {+ display: flex;+ flex-direction: column;+ align-items: center;+ padding-block: var(--space-6);+ }++ .d-table {+ @include viewport.from(md) {+ th,+ td {+ &:first-child {+ padding-left: 0;+ }++ &:last-child {+ padding-right: 0;+ }+ }+ }+ }+}diff --git a/plugins/discourse-ai/config/locales/client.en.yml b/plugins/discourse-ai/config/locales/client.en.ymlindex 9ebd2851c59..bbdd17c537e 100644--- a/plugins/discourse-ai/config/locales/client.en.yml+++ b/plugins/discourse-ai/config/locales/client.en.yml@@ -380,12 +380,12 @@ en:awaiting_staff: "Awaiting staff approval"default_llm:- title: "Default LLM model"- description: "The default LLM model to use for all AI features. This will be used if no LLM is specified in the feature configuration or agent. If no default LLM is specified, the last created LLM will be used."+ title: "Default language model"+ description: "Used by any AI feature or agent that doesn't specify its own language model. If none is set, the most recently added language model is used."llm_selector:none: "None"- saved: "Default LLM model updated successfully"+ saved: "Default language model saved"features:short_title: "Features"@@ -1170,15 +1170,18 @@ en:title: "Create new credential"decision_models:- short_title: "Decision models"- description: "Models that answer typed questions about content (yes/no, choice, score) with probabilities, faster and cheaper than an LLM."- create_new: "New decision model"- no_decision_models: "No decision models yet"seeded_description: "Pre-configured model"manage: "Manage decision models"- back: "Back to decision models"start_from: "Start from"no_preset: "None"+ preset_descriptions:+ none: "Settings for any compatible decision model endpoint"+ jev-latest: "TypeSafe's hosted decision model, text only"+ jev-latest-vision: "TypeSafe's hosted decision model with experimental image support"+ vllm-sr-d3: "Open-source multimodal decision model, self-hosted with vLLM"+ cloudflare-clef: "Cloudflare's open-source multimodal decision model on Workers AI"+ cloudflare-clef-flash: "Smaller, faster version of Clef on Workers AI"+ gpt-6-luna: "OpenAI's decision model on the Decisions API, with image support"display_name: "Name"model: "Model"provider: "Provider"@@ -1284,6 +1287,44 @@ en:one: "Discovered %{count} tool using protocol %{version}."other: "Discovered %{count} tools using protocol %{version}."+ models:+ short_title: "Models"+ description: "Connect the models that power AI features and workflows."+ new: "New model"+ back: "Back to models"+ back_to_types: "Back to model types"+ empty: "You haven't set up any models yet"+ name: "Name"+ type: "Type"+ provider: "Provider"+ edit: "Edit"+ choose_type: "What kind of model do you want to add?"+ select_type: "Select"+ types:+ llm: "Large language"+ embedding: "Embedding"+ decision: "Decision"+ type_titles:+ llm: "Large language model"+ embedding: "Embedding model"+ decision: "Decision model"+ type_descriptions:+ llm: "Generates text for features like the AI bot, summaries, and the AI helper"+ embedding: "Turns content into vectors for semantic search and related topics"+ decision: "Answers typed questions about content (yes/no, choice, score) with probabilities, for use in workflows"+ type_filters:+ llm: "Large language models"+ embedding: "Embedding models"+ decision: "Decision models"+ templates:+ llm: "Choose a language model template"+ embedding: "Choose an embedding template"+ decision: "Choose a decision model template"+ filters:+ all: "All types"+ text: "Filter by name or provider"+ no_results: "No models match your filters"+ reset: "Reset filters"llms:short_title: "LLMs"no_llms: "No LLMs yet"@@ -1558,6 +1599,15 @@ en:empty: "You haven't setup embeddings yet"presets: "Select a preset..."configure_manually: "Configure manually"+ preset_descriptions:+ manual: "Settings for any embedding service, including self-hosted ones"+ bge-large-en: "Open-source English-only model, self-hosted"+ bge-m3: "Open-source multilingual model for longer content, self-hosted"+ multilingual-e5-large: "Open-source multilingual model, self-hosted"+ gemini-embedding-001: "Google's hosted multilingual model"+ text-embedding-3-large: "OpenAI's most accurate embedding model"+ text-embedding-3-small: "OpenAI's faster, lower-cost embedding model"+ text-embedding-ada-002: "OpenAI's previous-generation model, superseded by text-embedding-3-small"edit: "Edit"seeded_warning: "This is pre-configured on your site and cannot be edited."tests:diff --git a/plugins/discourse-ai/config/locales/server.en.yml b/plugins/discourse-ai/config/locales/server.en.ymlindex 35b1c0fa9b3..5e4f5717341 100644--- a/plugins/discourse-ai/config/locales/server.en.yml+++ b/plugins/discourse-ai/config/locales/server.en.yml@@ -71,7 +71,7 @@ en:ai_ask_ai_report_recipient_groups: "Groups that receive automatic weekly report PMs and can be included in manual report PMs. Reports include users’ questions. Leave empty to keep automatic reports on the dashboard only."discourse_ai_enabled: "Enable the discourse AI plugin."enable_ai_bot_starred_conversations: "Allow users to star AI bot conversations and show them in a Starred sidebar section."- ai_default_llm_model: "The default LLM model to use for all AI features"+ ai_default_llm_model: "The default language model for AI features and agents that don't specify their own"ai_artifact_security: "The AI artifact system generates IFRAMEs with runnable code. Strict mode forces an extra click to run code. Lax mode runs code immediately. Hybrid mode allows user to supply data-ai-artifact-autorun to show right away. Disabled mode disables the artifact system."ai_toxicity_enabled: "Enable the toxicity module."ai_toxicity_inference_service_api_endpoint: "URL where the API is running for the toxicity module"diff --git a/plugins/discourse-ai/config/routes.rb b/plugins/discourse-ai/config/routes.rbindex 63f312ae202..dbf3c430aca 100644--- a/plugins/discourse-ai/config/routes.rb+++ b/plugins/discourse-ai/config/routes.rb@@ -190,6 +190,9 @@ Discourse::Application.routes.draw doget "/rag-document-fragments/files/status",to: "discourse_ai/admin/rag_document_fragments#indexing_status_check"+ get "/ai-models" => "admin/plugins#index"+ get "/ai-models/new" => "admin/plugins#index"+get "/ai-usage", to: "discourse_ai/admin/ai_usage#show"get "/ai-usage-report", to: "discourse_ai/admin/ai_usage#report"get "/ai-logs", to: "discourse_ai/admin/ai_logs#index"diff --git a/plugins/discourse-ai/spec/system/admin_ai_decision_models_spec.rb b/plugins/discourse-ai/spec/system/admin_ai_decision_models_spec.rbindex b13b0b1699b..c77fd5a2e2a 100644--- a/plugins/discourse-ai/spec/system/admin_ai_decision_models_spec.rb+++ b/plugins/discourse-ai/spec/system/admin_ai_decision_models_spec.rb@@ -7,6 +7,7 @@ RSpec.describe "Managing decision models" dobefore doenable_current_plugin+ SiteSetting.enable_discourse_workflows = truesign_in(admin)end@@ -37,9 +38,11 @@ RSpec.describe "Managing decision models" doit "creates from a preset and tests the model" doDiscourseAi::Decisions.with_canned_answers(greeting: 0.97, red_image: 0.99) do- visit "/admin/plugins/discourse-ai/ai-decision-models"- find(".ai-decision-models-list-editor__empty-new-btn").click- form.field("preset").select("vllm-sr-d3")+ visit "/admin/plugins/discourse-ai/ai-models"+ find(".ai-models-list__new-button").click+ find("[data-model-type='decision'] button").click+ find("[data-template-id='vllm-sr-d3'] button").click+ expect(form.field("preset")).to have_value("vllm-sr-d3")form.field("url").fill_in("https://d3.example.com/v1/systemone")form.submit@@ -58,7 +61,7 @@ RSpec.describe "Managing decision models" dotext: "yes: 97%",)find(".back-button").click- expect(page).to have_css(".ai-decision-models-list-editor__row", text: "d3")+ expect(page).to have_css(".ai-models-list__row[data-model-type='decision']", text: "d3")endendenddiff --git a/plugins/discourse-ai/spec/system/ai_moderation/ai_spam_spec.rb b/plugins/discourse-ai/spec/system/ai_moderation/ai_spam_spec.rbindex ae80851c46d..5ce1cc0a7f4 100644--- a/plugins/discourse-ai/spec/system/ai_moderation/ai_spam_spec.rb+++ b/plugins/discourse-ai/spec/system/ai_moderation/ai_spam_spec.rb@@ -43,7 +43,7 @@ RSpec.describe "AI Spam Configuration" doexpect(AiModerationSetting.spam.custom_instructions).to eq("Test spam detection instructions")- visit "/admin/plugins/discourse-ai/ai-llms"+ visit "/admin/plugins/discourse-ai/ai-models"expect(find(".ai-llm-list-editor__usages")).to have_content(I18n.t("js.discourse_ai.llms.usage.ai_spam"),diff --git a/plugins/discourse-ai/spec/system/embeddings/ai_embedding_definition_spec.rb b/plugins/discourse-ai/spec/system/embeddings/ai_embedding_definition_spec.rbindex 1571abeb2d3..a0c07dc0b66 100644--- a/plugins/discourse-ai/spec/system/embeddings/ai_embedding_definition_spec.rb+++ b/plugins/discourse-ai/spec/system/embeddings/ai_embedding_definition_spec.rb@@ -15,11 +15,11 @@ RSpec.describe "Managing Embeddings configurations" doit "correctly sets defaults" dopreset = "text-embedding-3-small"- visit "/admin/plugins/discourse-ai/ai-embeddings"+ visit "/admin/plugins/discourse-ai/ai-models"- find(".ai-embeddings-list-editor__new-button").click()-- find("[data-preset-id='text-embedding-3-small'] button").click()+ find(".ai-models-list__new-button").click()+ find("[data-model-type='embedding'] button").click()+ find("[data-template-id='text-embedding-3-small'] button").click()secret_selector = PageObjects::Components::SelectKit.new(".ai-secret-selector__dropdown")secret_selector.expand@@ -27,7 +27,7 @@ RSpec.describe "Managing Embeddings configurations" doform.submit- expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-embeddings")+ expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-models")embedding_def = EmbeddingDefinition.order(:id).lastexpect(embedding_def.ai_secret_id).to eq(ai_secret.id)@@ -46,11 +46,11 @@ RSpec.describe "Managing Embeddings configurations" doendit "supports manual config" do- visit "/admin/plugins/discourse-ai/ai-embeddings"-- find(".ai-embeddings-list-editor__new-button").click()+ visit "/admin/plugins/discourse-ai/ai-models"- find("[data-preset-id='manual'] button").click()+ find(".ai-models-list__new-button").click()+ find("[data-model-type='embedding'] button").click()+ find("[data-template-id='manual'] button").click()form.field("display_name").fill_in("text-embedding-3-small")form.field("provider").select(EmbeddingDefinition::OPEN_AI)@@ -73,7 +73,7 @@ RSpec.describe "Managing Embeddings configurations" doform.submit- expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-embeddings")+ expect(page).to have_current_path("/admin/plugins/discourse-ai/ai-models")embedding_def = EmbeddingDefinition.order(:id).lastdiff --git a/plugins/discourse-ai/spec/system/llms/ai_llm_spec.rb b/plugins/discourse-ai/spec/system/llms/ai_llm_spec.rbindex 89287a23070..1a4ff1cab32 100644--- a/plugins/discourse-ai/spec/system/llms/ai_llm_spec.rb+++ b/plugins/discourse-ai/spec/system/llms/ai_llm_spec.rb@@ -14,9 +14,9 @@ RSpec.describe "Managing LLM configurations" doendit "correctly sets defaults" do- visit "/admin/plugins/discourse-ai/ai-llms"+ visit "/admin/plugins/discourse-ai/ai-models/new?type=llm"- find("[data-llm-id='anthropic-claude-opus-5'] button").click()+ find("[data-template-id='anthropic-claude-opus-5'] button").click()secret_selector = PageObjects::Components::SelectKit.new(".ai-secret-selector__dropdown")secret_selector.expand@@ -46,11 +46,15 @@ RSpec.describe "Managing LLM configurations" doit "manually configures an LLM" dollm_count = LlmModel.count- visit "/admin/plugins/discourse-ai/ai-llms"+ visit "/admin/plugins/discourse-ai/ai-models"expect(page_header).to be_visible- find("[data-llm-id='none'] button").click()+ find(".ai-models-list__new-button").click()+ expect(page_header).to be_hidden++ find("[data-model-type='llm'] button").click()+ find("[data-template-id='none'] button").click()expect(page_header).to be_hidden@@ -78,13 +82,10 @@ RSpec.describe "Managing LLM configurations" doform.field("max_output_tokens").fill_in(2001)form.submit- # should go to llm list and see the llms correctly configured- page.go_back+ # should go to the models list and see the llms correctly configured+ visit "/admin/plugins/discourse-ai/ai-models"- expect(page).to have_selector(- ".ai-llms-list-editor__configured .ai-llm-list__row",- text: "Self-hosted LLM",- )+ expect(page).to have_selector(".ai-models-list .ai-llm-list__row", text: "Self-hosted LLM")llm.reloadexpect(llm.display_name).to eq("Self-hosted LLM")@@ -114,7 +115,7 @@ RSpec.describe "Managing LLM configurations" dotarget: "script",)- visit "/admin/plugins/discourse-ai/ai-llms"+ visit "/admin/plugins/discourse-ai/ai-models"within("[data-llm-id='#{llm_model.name}'] .ai-llm-list-editor__usages") doexpect(page).to have_link(@@ -143,8 +144,8 @@ RSpec.describe "Managing LLM configurations" doendit "correctly changes the provider params" do- visit "/admin/plugins/discourse-ai/ai-llms"- find("[data-llm-id='none'] button").click()+ visit "/admin/plugins/discourse-ai/ai-models/new?type=llm"+ find("[data-template-id='none'] button").click()form.field("provider").select("vllm")expect(form).to have_field_with_name("provider_params.disable_system_prompt")@@ -159,8 +160,8 @@ RSpec.describe "Managing LLM configurations" doendit "updates if the url can be edited" do- visit "/admin/plugins/discourse-ai/ai-llms"- find("[data-llm-id='none'] button").click()+ visit "/admin/plugins/discourse-ai/ai-models/new?type=llm"+ find("[data-template-id='none'] button").click()form.field("provider").select("vllm")expect(form).to have_field_with_name("url")@@ -209,7 +210,7 @@ RSpec.describe "Managing LLM configurations" dofab!(:llm_model, :seeded_model)it "shows the provider as CDCK in the UI" do- visit "/admin/plugins/discourse-ai/ai-llms"+ visit "/admin/plugins/discourse-ai/ai-models"expect(page).to have_css("[data-llm-id='cdck-hosted']",text: I18n.t("js.discourse_ai.llms.providers.CDCK"),@@ -217,12 +218,12 @@ RSpec.describe "Managing LLM configurations" doendit "seeded LLM has a description" do- visit "/admin/plugins/discourse-ai/ai-llms"+ visit "/admin/plugins/discourse-ai/ai-models"desc = I18n.t("js.discourse_ai.llms.preseeded_model_description", model: llm_model.name)expect(page).to have_css(- "[data-llm-id='#{llm_model.name}'] .ai-llm-list__description",+ "[data-llm-id='#{llm_model.name}'] .ai-models-list__description",text: desc,)enddiff --git a/plugins/discourse-ai/test/javascripts/integration/components/ai-model-new-test.gjs b/plugins/discourse-ai/test/javascripts/integration/components/ai-model-new-test.gjsnew file mode 100644index 00000000000..4420bc6e8e2--- /dev/null+++ b/plugins/discourse-ai/test/javascripts/integration/components/ai-model-new-test.gjs@@ -0,0 +1,49 @@+import Service from "@ember/service";+import { render } from "@ember/test-helpers";+import { module, test } from "qunit";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import AiModelNew from "discourse/plugins/discourse-ai/discourse/components/ai-model-new";++class AdminPluginNavManagerStub extends Service {+ currentPlugin = { name: "discourse-ai" };+}++module("Integration | Component | AiModelNew", function (hooks) {+ setupRenderingTest(hooks, { stubRouter: true });++ hooks.beforeEach(function () {+ this.owner.unregister("service:admin-plugin-nav-manager");+ this.owner.register(+ "service:admin-plugin-nav-manager",+ AdminPluginNavManagerStub+ );+ });++ test("links each type card to its guide", async function (assert) {+ const empty = { content: [], resultSetMeta: { presets: [] } };++ await render(+ <template>+ <AiModelNew+ @decisionModels={{empty}}+ @embeddings={{empty}}+ @llms={{empty}}+ />+ </template>+ );++ assert+ .dom("[data-model-type='llm'] .admin-section-landing-item__description a")+ .hasAttribute("href", /\/319903$/);+ assert+ .dom(+ "[data-model-type='embedding'] .admin-section-landing-item__description a"+ )+ .hasAttribute("href", /\/259603$/);+ assert+ .dom(+ "[data-model-type='decision'] .admin-section-landing-item__description a"+ )+ .hasAttribute("href", /\/414738$/);+ });+});diff --git a/plugins/discourse-ai/test/javascripts/integration/components/ai-llms-list-editor-test.gjs b/plugins/discourse-ai/test/javascripts/integration/components/ai-models-list-test.gjssimilarity index 53%rename from plugins/discourse-ai/test/javascripts/integration/components/ai-llms-list-editor-test.gjsrename to plugins/discourse-ai/test/javascripts/integration/components/ai-models-list-test.gjsindex 27b7128c39a..d29e9ffba30 100644--- a/plugins/discourse-ai/test/javascripts/integration/components/ai-llms-list-editor-test.gjs+++ b/plugins/discourse-ai/test/javascripts/integration/components/ai-models-list-test.gjs@@ -1,17 +1,21 @@+import { tracked } from "@glimmer/tracking";import Service from "@ember/service";-import { findAll, render } from "@ember/test-helpers";+import { findAll, render, settled } from "@ember/test-helpers";import { module, test } from "qunit";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import pretender, { response } from "discourse/tests/helpers/create-pretender";-import AiLlmsListEditor, {- usageRoute,-} from "discourse/plugins/discourse-ai/discourse/components/ai-llms-list-editor";+import { usageRoute } from "discourse/plugins/discourse-ai/discourse/components/ai-llm-usages";+import AiModelsList from "discourse/plugins/discourse-ai/discourse/components/ai-models-list";++class FilterState {+ @tracked type = null;+}class AdminPluginNavManagerStub extends Service {currentPlugin = { name: "discourse-ai" };}-module("Integration | Component | AiLlmsListEditor", function (hooks) {+module("Integration | Component | AiModelsList", function (hooks) {setupRenderingTest(hooks, { stubRouter: true });hooks.beforeEach(function () {@@ -20,22 +24,6 @@ module("Integration | Component | AiLlmsListEditor", function (hooks) {"service:admin-plugin-nav-manager",AdminPluginNavManagerStub);-- pretender.get("/admin/plugins/discourse-ai/ai-llms.json", () =>- response({ ai_llms: [{ id: 1, display_name: "Test model" }] })- );- pretender.get("/admin/config/site_settings.json", () =>- response({- site_settings: [- {- setting: "ai_default_llm_model",- value: "1",- default: "",- type: "enum",- },- ],- })- );});test("maps supported usages to their admin routes", function (assert) {@@ -98,8 +86,13 @@ module("Integration | Component | AiLlmsListEditor", function (hooks) {],resultSetMeta: { presets: [] },};+ this.embeddings = { content: [], resultSetMeta: { presets: [] } };- await render(<template><AiLlmsListEditor @llms={{this.llms}} /></template>);+ await render(+ <template>+ <AiModelsList @embeddings={{this.embeddings}} @llms={{this.llms}} />+ </template>+ );const usages = findAll(".ai-llm-list-editor__usages li");assert.strictEqual(usages.length, 5, "renders every usage");@@ -139,4 +132,133 @@ module("Integration | Component | AiLlmsListEditor", function (hooks) {"keeps the malformed target label intact");});++ test("lists every model type and filters by type", async function (assert) {+ this.llms = {+ content: [+ {+ id: 1,+ name: "test-model",+ display_name: "Test model",+ provider: "fake",+ },+ ],+ resultSetMeta: { presets: [] },+ };+ this.embeddings = {+ content: [{ id: 2, display_name: "Test embedding", provider: "open_ai" }],+ resultSetMeta: { presets: [] },+ };+ this.decisionModels = {+ content: [+ { id: 3, display_name: "Test decision", provider: "system_one" },+ {+ id: -1,+ display_name: "Seeded decision",+ provider: "system_one",+ seeded: true,+ },+ ],+ resultSetMeta: { presets: [] },+ };+ const state = new FilterState();++ await render(+ <template>+ <AiModelsList+ @decisionModels={{this.decisionModels}}+ @embeddings={{this.embeddings}}+ @llms={{this.llms}}+ @type={{state.type}}+ />+ </template>+ );++ assert.dom(".ai-models-list__row[data-model-type='llm']").exists();+ assert.dom(".ai-models-list__row[data-model-type='embedding']").exists();+ assert+ .dom(".ai-models-list__row[data-model-type='decision']")+ .exists({ count: 2 });+ assert+ .dom("[data-model-id='-1'] .ai-models-list__edit-button")+ .doesNotExist("seeded decision models are read-only");+ assert+ .dom(+ ".ai-models-list__row[data-model-type='embedding'] .ai-models-list__type"+ )+ .includesText("Embedding");++ state.type = "embedding";+ await settled();++ assert.dom(".ai-models-list__row").exists({ count: 1 });+ assert.dom(".ai-models-list__row[data-model-type='embedding']").exists();+ });++ test("hides decision models when none are passed", async function (assert) {+ this.llms = { content: [], resultSetMeta: { presets: [] } };+ this.embeddings = {+ content: [{ id: 2, display_name: "Test embedding", provider: "open_ai" }],+ resultSetMeta: { presets: [] },+ };++ await render(+ <template>+ <AiModelsList @embeddings={{this.embeddings}} @llms={{this.llms}} />+ </template>+ );++ assert+ .dom(".ai-models-list__type-filter option[value='decision']")+ .doesNotExist();+ });++ test("shows the default LLM setting only when filtered to LLMs", async function (assert) {+ pretender.get("/admin/plugins/discourse-ai/ai-llms.json", () =>+ response({ ai_llms: [{ id: 1, display_name: "Test model" }] })+ );+ pretender.get("/admin/config/site_settings.json", () =>+ response({+ site_settings: [+ {+ setting: "ai_default_llm_model",+ value: "1",+ default: "",+ type: "enum",+ },+ ],+ })+ );++ this.llms = {+ content: [+ {+ id: 1,+ name: "test-model",+ display_name: "Test model",+ provider: "fake",+ },+ ],+ resultSetMeta: { presets: [] },+ };+ this.embeddings = { content: [], resultSetMeta: { presets: [] } };+ const state = new FilterState();++ await render(+ <template>+ <AiModelsList+ @embeddings={{this.embeddings}}+ @llms={{this.llms}}+ @type={{state.type}}+ />+ </template>+ );++ assert.dom(".ai-configure-default-llm").doesNotExist();++ state.type = "llm";+ await settled();++ assert.dom(".ai-configure-default-llm").exists();+ });});