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

Commit cc72e09

Browse files
committed
Refactor the constructor of the AiPersonaSelector to split the logic into smaller chunks
1 parent 7fcbb0e commit cc72e09

File tree

1 file changed

+40
-32
lines changed

1 file changed

+40
-32
lines changed

assets/javascripts/discourse/components/ai-persona-llm-selector.gjs

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,8 @@ export default class AiPersonaLlmSelector extends Component {
2020
super(...arguments);
2121

2222
if (this.botOptions?.length) {
23-
let personaId = this.keyValueStore.getItem(PERSONA_SELECTOR_KEY);
24-
25-
this._value = this.botOptions[0].id;
26-
if (personaId) {
27-
personaId = parseInt(personaId, 10);
28-
if (this.botOptions.any((bot) => bot.id === personaId)) {
29-
this._value = personaId;
30-
}
31-
}
32-
33-
this.args.setPersonaId(this._value);
34-
this.setAllowLLMSelector();
35-
36-
if (this.hasLlmSelector) {
37-
let llm = this.keyValueStore.getItem(LLM_SELECTOR_KEY);
38-
39-
const llmOption =
40-
this.llmOptions.find((innerLlmOption) => innerLlmOption.id === llm) ||
41-
this.llmOptions[0];
42-
43-
if (llmOption) {
44-
llm = llmOption.id;
45-
} else {
46-
llm = "";
47-
}
48-
49-
if (llm) {
50-
next(() => {
51-
this.currentLlm = llm;
52-
});
53-
}
54-
}
23+
this.#loadStoredPersona();
24+
this.#loadStoredLlm();
5525

5626
next(() => {
5727
this.resetTargetRecipients();
@@ -160,6 +130,44 @@ export default class AiPersonaLlmSelector extends Component {
160130
return this.allowLLMSelector && this.llmOptions.length > 1;
161131
}
162132

133+
#loadStoredPersona() {
134+
let personaId = this.keyValueStore.getItem(PERSONA_SELECTOR_KEY);
135+
136+
this._value = this.botOptions[0].id;
137+
if (personaId) {
138+
personaId = parseInt(personaId, 10);
139+
if (this.botOptions.any((bot) => bot.id === personaId)) {
140+
this._value = personaId;
141+
}
142+
}
143+
144+
this.args.setPersonaId(this._value);
145+
}
146+
147+
#loadStoredLlm() {
148+
this.setAllowLLMSelector();
149+
150+
if (this.hasLlmSelector) {
151+
let llm = this.keyValueStore.getItem(LLM_SELECTOR_KEY);
152+
153+
const llmOption =
154+
this.llmOptions.find((innerLlmOption) => innerLlmOption.id === llm) ||
155+
this.llmOptions[0];
156+
157+
if (llmOption) {
158+
llm = llmOption.id;
159+
} else {
160+
llm = "";
161+
}
162+
163+
if (llm) {
164+
next(() => {
165+
this.currentLlm = llm;
166+
});
167+
}
168+
}
169+
}
170+
163171
<template>
164172
<div class="persona-llm-selector">
165173
<div class="persona-llm-selector__selection-wrapper gpt-persona">

0 commit comments

Comments
 (0)