Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit d689bcd

Browse files
committed
WIP: add features to persona list, and other style updates
1 parent cab3983 commit d689bcd

File tree

4 files changed

+83
-17
lines changed

4 files changed

+83
-17
lines changed

app/controllers/discourse_ai/admin/ai_personas_controller.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@ class AiPersonasController < ::Admin::AdminController
88
before_action :find_ai_persona, only: %i[edit update destroy create_user]
99

1010
def index
11+
features_by_persona_id = DiscourseAi::Features.features.group_by { |f| f[:persona]&.id }
12+
1113
ai_personas =
12-
AiPersona.ordered.map do |persona|
13-
# we use a special serializer here cause names and descriptions are
14-
# localized for system personas
15-
LocalizedAiPersonaSerializer.new(persona, root: false)
16-
end
14+
AiPersona
15+
.ordered
16+
.includes(:user, :uploads)
17+
.map do |persona|
18+
LocalizedAiPersonaSerializer.new(
19+
persona,
20+
root: false,
21+
features_by_persona_id: features_by_persona_id,
22+
)
23+
end
24+
1725
tools =
1826
DiscourseAi::Personas::Persona.all_available_tools.map do |tool|
1927
AiToolSerializer.new(tool, root: false)
2028
end
29+
2130
AiTool
2231
.where(enabled: true)
2332
.each do |tool|
@@ -31,10 +40,12 @@ def index
3140
),
3241
}
3342
end
43+
3444
llms =
3545
DiscourseAi::Configuration::LlmEnumerator.values_for_serialization(
3646
allowed_seeded_llm_ids: SiteSetting.ai_bot_allowed_seeded_models_map,
3747
)
48+
3849
render json: {
3950
ai_personas: ai_personas,
4051
meta: {

app/serializers/localized_ai_persona_serializer.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
class LocalizedAiPersonaSerializer < ApplicationSerializer
44
root "ai_persona"
55

6+
def initialize(object, options = {})
7+
@features_by_persona_id = options.delete(:features_by_persona_id)
8+
super(object, options)
9+
end
10+
611
attributes :id,
712
:name,
813
:description,
@@ -32,7 +37,8 @@ class LocalizedAiPersonaSerializer < ApplicationSerializer
3237
:allow_personal_messages,
3338
:force_default_llm,
3439
:response_format,
35-
:examples
40+
:examples,
41+
:features
3642

3743
has_one :user, serializer: BasicUserSerializer, embed: :object
3844
has_many :rag_uploads, serializer: UploadSerializer, embed: :object
@@ -48,4 +54,19 @@ def name
4854
def description
4955
object.class_instance.description
5056
end
57+
58+
def features
59+
return [] unless @features_by_persona_id.is_a?(Hash)
60+
61+
Array(@features_by_persona_id[object.id]).map do |feature|
62+
{ id: feature[:id], name: feature[:name] }
63+
end
64+
rescue => e
65+
Rails.logger.warn("Persona serializer error: #{e.class} - #{e.message}")
66+
[]
67+
end
68+
69+
def include_features?
70+
@features_by_persona_id.is_a?(Hash)
71+
end
5172
end

assets/javascripts/discourse/components/ai-persona-list-editor.gjs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import Component from "@glimmer/component";
2-
import { fn } from "@ember/helper";
3-
import { on } from "@ember/modifier";
42
import { action } from "@ember/object";
53
import { LinkTo } from "@ember/routing";
64
import { service } from "@ember/service";
75
import DBreadcrumbsItem from "discourse/components/d-breadcrumbs-item";
6+
import DButton from "discourse/components/d-button";
87
import DPageSubheader from "discourse/components/d-page-subheader";
9-
import DToggleSwitch from "discourse/components/d-toggle-switch";
108
import concatClass from "discourse/helpers/concat-class";
9+
import icon from "discourse/helpers/d-icon";
1110
import { popupAjaxError } from "discourse/lib/ajax-error";
1211
import { i18n } from "discourse-i18n";
1312
import AdminConfigAreaEmptyList from "admin/components/admin-config-area-empty-list";
@@ -61,37 +60,47 @@ export default class AiPersonaListEditor extends Component {
6160
<thead>
6261
<tr>
6362
<th>{{i18n "discourse_ai.ai_persona.name"}}</th>
64-
<th>{{i18n "discourse_ai.ai_persona.list.enabled"}}</th>
65-
<th></th>
63+
<th>{{i18n "discourse_ai.features.short_title"}}</th>
6664
</tr>
6765
</thead>
6866
<tbody>
6967
{{#each @personas as |persona|}}
68+
{{log persona}}
7069
<tr
7170
data-persona-id={{persona.id}}
7271
class={{concatClass
7372
"ai-persona-list__row d-admin-row__content"
74-
(if persona.priority "priority")
73+
(if persona.priority "--priority")
74+
(if persona.enabled "--enabled")
7575
}}
7676
>
7777
<td class="d-admin-row__overview">
7878
<div class="ai-persona-list__name-with-description">
7979
<div class="ai-persona-list__name">
8080
<strong>
8181
{{persona.name}}
82+
{{#if persona.enabled}}{{icon "check"}}{{/if}}
8283
</strong>
8384
</div>
8485
<div class="ai-persona-list__description">
8586
{{persona.description}}
8687
</div>
8788
</div>
8889
</td>
89-
<td class="d-admin-row__detail">
90-
<DToggleSwitch
91-
@state={{persona.enabled}}
92-
{{on "click" (fn this.toggleEnabled persona)}}
93-
/>
90+
91+
<td class="d-admin-row__features">
92+
{{#each persona.features as |feature|}}
93+
{{log persona}}
94+
<DButton
95+
class="btn-flat btn-small ai-persona-list__row-item-feature"
96+
@translatedLabel={{feature.name}}
97+
@route="adminPlugins.show.discourse-ai-features.edit"
98+
@routeModels={{feature.id}}
99+
/>
100+
{{/each}}
101+
94102
</td>
103+
95104
<td class="d-admin-row__controls">
96105
<LinkTo
97106
@route="adminPlugins.show.discourse-ai-personas.edit"

assets/stylesheets/modules/ai-bot/common/ai-persona.scss

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,31 @@
2121
li.disabled {
2222
opacity: 0.5;
2323
}
24+
25+
.ai-persona-list {
26+
&__row-item-feature {
27+
padding: 0;
28+
margin-right: 0.5em;
29+
text-align: left;
30+
}
31+
32+
&__name {
33+
.d-icon {
34+
color: var(--success);
35+
font-size: var(--font-down-1);
36+
}
37+
}
38+
39+
&__row {
40+
&:hover {
41+
background: transparent;
42+
}
43+
44+
&__overview {
45+
padding-left: var(--space-2);
46+
}
47+
}
48+
}
2449
}
2550

2651
.ai-persona-tool-option-editor {

0 commit comments

Comments
 (0)