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

Commit 1c3db80

Browse files
committed
implement all new changes client side
1 parent 799a5a7 commit 1c3db80

File tree

8 files changed

+139
-38
lines changed

8 files changed

+139
-38
lines changed

app/models/ai_persona.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ def class_instance
137137
instance_attributes[attr] = value
138138
end
139139

140+
instance_attributes[:username] = user&.username_lower
141+
140142
if persona_class
141143
instance_attributes.each do |key, value|
142144
# description/name are localized

assets/javascripts/discourse/admin/models/ai-persona.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const CREATE_ATTRIBUTES = [
1515
"top_p",
1616
"temperature",
1717
"user_id",
18-
"mentionable",
1918
"default_llm",
19+
"force_default_llm",
2020
"user",
2121
"max_context_posts",
2222
"vision_enabled",
@@ -29,6 +29,10 @@ const CREATE_ATTRIBUTES = [
2929
"allow_chat",
3030
"tool_details",
3131
"forced_tool_count",
32+
"allow_personal_messages",
33+
"allow_topic_mentions",
34+
"allow_chat_channel_mentions",
35+
"allow_chat_direct_messages",
3236
];
3337

3438
const SYSTEM_ATTRIBUTES = [
@@ -38,8 +42,8 @@ const SYSTEM_ATTRIBUTES = [
3842
"system",
3943
"priority",
4044
"user_id",
41-
"mentionable",
4245
"default_llm",
46+
"force_default_llm",
4347
"user",
4448
"max_context_posts",
4549
"vision_enabled",
@@ -49,8 +53,11 @@ const SYSTEM_ATTRIBUTES = [
4953
"rag_chunk_overlap_tokens",
5054
"rag_conversation_chunks",
5155
"question_consolidator_llm",
52-
"allow_chat",
5356
"tool_details",
57+
"allow_personal_messages",
58+
"allow_topic_mentions",
59+
"allow_chat_channel_mentions",
60+
"allow_chat_direct_messages",
5461
];
5562

5663
class ToolOption {

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

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default class PersonaEditor extends Component {
4444
@tracked selectedTools = [];
4545
@tracked selectedToolNames = [];
4646
@tracked forcedToolNames = [];
47+
@tracked hasDefaultLlm = false;
4748

4849
get chatPluginEnabled() {
4950
return this.siteSettings.chat_enabled;
@@ -81,6 +82,7 @@ export default class PersonaEditor extends Component {
8182
@action
8283
updateModel() {
8384
this.editingModel = this.args.model.workingCopy();
85+
this.hasDefaultLlm = !!this.editingModel.default_llm;
8486
this.showDelete = !this.args.model.isNew && !this.args.model.system;
8587
this.maxPixelsValue = this.findClosestPixelValue(
8688
this.editingModel.vision_max_pixels
@@ -183,8 +185,10 @@ export default class PersonaEditor extends Component {
183185
set mappedDefaultLlm(value) {
184186
if (value === "blank") {
185187
this.editingModel.default_llm = null;
188+
this.hasDefaultLlm = false;
186189
} else {
187190
this.editingModel.default_llm = value;
191+
this.hasDefaultLlm = true;
188192
}
189193
}
190194

@@ -344,6 +348,16 @@ export default class PersonaEditor extends Component {
344348
@content={{I18n.t "discourse_ai.ai_persona.default_llm_help"}}
345349
/>
346350
</div>
351+
{{#if this.hasDefaultLlm}}
352+
<div class="control-group">
353+
<label>
354+
<Input
355+
@type="checkbox"
356+
@checked={{this.editingModel.force_default_llm}}
357+
/>
358+
{{I18n.t "discourse_ai.ai_persona.force_default_llm"}}</label>
359+
</div>
360+
{{/if}}
347361
{{#unless @model.isNew}}
348362
<div class="control-group">
349363
<label>{{I18n.t "discourse_ai.ai_persona.user"}}</label>
@@ -429,33 +443,73 @@ export default class PersonaEditor extends Component {
429443
disabled={{this.editingModel.system}}
430444
/>
431445
</div>
446+
<div class="control-group ai-persona-editor__allow_personal_messages">
447+
<label>
448+
<Input
449+
@type="checkbox"
450+
@checked={{this.editingModel.allow_personal_messages}}
451+
/>
452+
{{I18n.t "discourse_ai.ai_persona.allow_personal_messages"}}</label>
453+
<DTooltip
454+
@icon="question-circle"
455+
@content={{I18n.t
456+
"discourse_ai.ai_persona.allow_personal_messages_help"
457+
}}
458+
/>
459+
</div>
432460
{{#if this.editingModel.user}}
461+
<div class="control-group ai-persona-editor__allow_topic_mentions">
462+
<label>
463+
<Input
464+
@type="checkbox"
465+
@checked={{this.editingModel.allow_topic_mentions}}
466+
/>
467+
{{I18n.t "discourse_ai.ai_persona.allow_topic_mentions"}}</label>
468+
<DTooltip
469+
@icon="question-circle"
470+
@content={{I18n.t
471+
"discourse_ai.ai_persona.allow_topic_mentions_help"
472+
}}
473+
/>
474+
</div>
433475
{{#if this.chatPluginEnabled}}
434-
<div class="control-group ai-persona-editor__allow_chat">
476+
<div
477+
class="control-group ai-persona-editor__allow_chat_direct_messages"
478+
>
435479
<label>
436480
<Input
437481
@type="checkbox"
438-
@checked={{this.editingModel.allow_chat}}
482+
@checked={{this.editingModel.allow_chat_direct_messages}}
439483
/>
440-
{{I18n.t "discourse_ai.ai_persona.allow_chat"}}</label>
484+
{{I18n.t
485+
"discourse_ai.ai_persona.allow_chat_direct_messages"
486+
}}</label>
441487
<DTooltip
442488
@icon="question-circle"
443-
@content={{I18n.t "discourse_ai.ai_persona.allow_chat_help"}}
489+
@content={{I18n.t
490+
"discourse_ai.ai_persona.allow_chat_direct_messages_help"
491+
}}
444492
/>
445493
</div>
446-
{{/if}}
447-
<div class="control-group ai-persona-editor__mentionable">
448-
<label>
449-
<Input
450-
@type="checkbox"
451-
@checked={{this.editingModel.mentionable}}
494+
<div
495+
class="control-group ai-persona-editor__allow_chat_channel_mentions"
496+
>
497+
<label>
498+
<Input
499+
@type="checkbox"
500+
@checked={{this.editingModel.allow_chat_channel_mentions}}
501+
/>
502+
{{I18n.t
503+
"discourse_ai.ai_persona.allow_chat_channel_mentions"
504+
}}</label>
505+
<DTooltip
506+
@icon="question-circle"
507+
@content={{I18n.t
508+
"discourse_ai.ai_persona.allow_chat_channel_mentions_help"
509+
}}
452510
/>
453-
{{I18n.t "discourse_ai.ai_persona.mentionable"}}</label>
454-
<DTooltip
455-
@icon="question-circle"
456-
@content={{I18n.t "discourse_ai.ai_persona.mentionable_help"}}
457-
/>
458-
</div>
511+
</div>
512+
{{/if}}
459513
{{/if}}
460514
<div class="control-group ai-persona-editor__tool-details">
461515
<label>

assets/javascripts/discourse/connectors/composer-fields/persona-llm-selector.gjs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default class BotSelector extends Component {
3232
@service currentUser;
3333
@service siteSettings;
3434
@tracked llm;
35+
@tracked allowLLMSelector = true;
3536

3637
STORE_NAMESPACE = "discourse_ai_persona_selector_";
3738
LLM_STORE_NAMESPACE = "discourse_ai_llm_selector_";
@@ -54,6 +55,7 @@ export default class BotSelector extends Component {
5455
}
5556

5657
this.composer.metaData = { ai_persona_id: this._value };
58+
this.setAllowLLMSelector();
5759

5860
let llm = this.preferredLlmStore.getObject("id");
5961
llm = llm || this.llmOptions[0].id;
@@ -93,6 +95,15 @@ export default class BotSelector extends Component {
9395
this._value = newValue;
9496
this.preferredPersonaStore.setObject({ key: "id", value: newValue });
9597
this.composer.metaData = { ai_persona_id: newValue };
98+
this.setAllowLLMSelector();
99+
}
100+
101+
setAllowLLMSelector() {
102+
const persona = this.currentUser.ai_enabled_personas.find(
103+
(innerPersona) => innerPersona.id === this._value
104+
);
105+
106+
this.allowLLMSelector = !persona?.force_default_llm;
96107
}
97108

98109
get currentLlm() {
@@ -105,7 +116,15 @@ export default class BotSelector extends Component {
105116
(bot) => bot.model_name === this.llm
106117
).username;
107118
this.preferredLlmStore.setObject({ key: "id", value: newValue });
108-
this.composer.set("targetRecipients", botUsername);
119+
if (this.allowLLMSelector) {
120+
this.composer.set("targetRecipients", botUsername);
121+
} else {
122+
123+
const persona = this.currentUser.ai_enabled_personas.find(
124+
(innerPersona) => innerPersona.id === this._value
125+
);
126+
this.composer.set("targetRecipients", persona.username || "");
127+
}
109128
}
110129

111130
get llmOptions() {
@@ -131,14 +150,16 @@ export default class BotSelector extends Component {
131150
@options={{hash icon="robot" filterable=this.filterable}}
132151
/>
133152
</div>
134-
<div class="llm-selector">
135-
<DropdownSelectBox
136-
class="persona-llm-selector__llm-dropdown"
137-
@value={{this.currentLlm}}
138-
@content={{this.llmOptions}}
139-
@options={{hash icon="globe"}}
140-
/>
141-
</div>
153+
{{#if this.allowLLMSelector}}
154+
<div class="llm-selector">
155+
<DropdownSelectBox
156+
class="persona-llm-selector__llm-dropdown"
157+
@value={{this.currentLlm}}
158+
@content={{this.llmOptions}}
159+
@options={{hash icon="globe"}}
160+
/>
161+
</div>
162+
{{/if}}
142163
</div>
143164
</template>
144165
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@
6868

6969
&__tool-details,
7070
&__vision_enabled,
71-
&__allow_chat,
72-
&__priority,
73-
&__mentionable {
71+
&__allow_chat_direct_messages,
72+
&__allow_chat_channel_mentions,
73+
&__allow_topic_mentions,
74+
&__allow_personal_messages,
75+
&__force_default_llm,
76+
&__priority {
7477
display: flex;
7578
align-items: center;
7679
}

config/locales/client.en.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,15 @@ en:
148148
question_consolidator_llm_help: The language model to use for the question consolidator, you may choose a less powerful model to save costs.
149149
system_prompt: System Prompt
150150
forced_tool_strategy: Forced Tool Strategy
151-
allow_chat: "Allow Chat"
152-
allow_chat_help: "If enabled, users in allowed groups can DM this persona"
151+
allow_chat_direct_messages: "Allow Chat Direct Messages"
152+
allow_chat_direct_messages_help: "If enabled, users in allowed groups can send direct messages to this persona."
153+
allow_chat_channel_mentions: "Allow Chat Channel Mentions"
154+
allow_chat_channel_mentions_help: "If enabled, users in allowed groups can mention this persona in chat channels."
155+
allow_personal_messages: "Allow Personal Messages"
156+
allow_personal_messages_help: "If enabled, users in allowed groups can send personal messages to this persona."
157+
allow_topic_mentions: "Allow Topic Mentions"
158+
allow_topic_mentions_help: "If enabled, users in allowed groups can mention this persona in topics."
159+
force_default_llm: "Force Default Language Model to be used unconditionally"
153160
save: Save
154161
saved: AI Persona Saved
155162
enabled: "Enabled?"

lib/ai_bot/entry_point.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ class EntryPoint
88
Bot = Struct.new(:id, :name, :llm)
99

1010
def self.all_bot_ids
11-
AiPersona.persona_users.map { |persona| persona[:user_id] }.concat(
12-
LlmModel.where(enabled_chat_bot: true).pluck(:user_id),
13-
)
11+
AiPersona
12+
.persona_users
13+
.map { |persona| persona[:user_id] }
14+
.concat(LlmModel.where(enabled_chat_bot: true).pluck(:user_id))
1415
end
1516

1617
def self.find_participant_in(participant_ids)
@@ -107,7 +108,13 @@ def inject_into(plugin)
107108
DiscourseAi::AiBot::Personas::Persona
108109
.all(user: scope.user)
109110
.map do |persona|
110-
{ id: persona.id, name: persona.name, description: persona.description }
111+
{
112+
id: persona.id,
113+
name: persona.name,
114+
description: persona.description,
115+
force_default_llm: persona.force_default_llm,
116+
username: persona.username
117+
}
111118
end
112119
end
113120

spec/lib/modules/ai_bot/entry_point_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
expect(serializer[:current_user][:can_debug_ai_bot_conversations]).to eq(true)
3636
end
3737

38-
it "adds information about forcint default llm to current_user_serializer" do
38+
it "adds information about forcing default llm to current_user_serializer" do
3939
Group.refresh_automatic_groups!
4040

4141
persona =

0 commit comments

Comments
 (0)