@@ -3,27 +3,24 @@ import { tracked } from "@glimmer/tracking";
33import { hash } from " @ember/helper" ;
44import { next } from " @ember/runloop" ;
55import { service } from " @ember/service" ;
6- import KeyValueStore from " discourse/lib/key-value-store" ;
76import { i18n } from " discourse-i18n" ;
87import DropdownSelectBox from " select-kit/components/dropdown-select-box" ;
98
9+ const PERSONA_SELECTOR_KEY = " ai_persona_selector_id" ;
10+ const LLM_SELECTOR_KEY = " ai_llm_selector_id" ;
11+
1012export default class AiPersonaLlmSelector extends Component {
1113 @service currentUser;
14+ @service keyValueStore;
1215
1316 @tracked llm;
1417 @tracked allowLLMSelector = true ;
1518
16- STORE_NAMESPACE = " discourse_ai_persona_selector_" ;
17- LLM_STORE_NAMESPACE = " discourse_ai_llm_selector_" ;
18-
19- preferredPersonaStore = new KeyValueStore (this .STORE_NAMESPACE );
20- preferredLlmStore = new KeyValueStore (this .LLM_STORE_NAMESPACE );
21-
2219 constructor () {
2320 super (... arguments );
2421
25- if (this .botOptions && this . botOptions .length ) {
26- let personaId = this .preferredPersonaStore . getObject ( " id " );
22+ if (this .botOptions ? .length ) {
23+ let personaId = this .keyValueStore . getItem ( PERSONA_SELECTOR_KEY );
2724
2825 this ._value = this .botOptions [0 ].id ;
2926 if (personaId) {
@@ -37,7 +34,7 @@ export default class AiPersonaLlmSelector extends Component {
3734 this .setAllowLLMSelector ();
3835
3936 if (this .hasLlmSelector ) {
40- let llm = this .preferredLlmStore . getObject ( " id " );
37+ let llm = this .keyValueStore . getItem ( LLM_SELECTOR_KEY );
4138
4239 const llmOption =
4340 this .llmOptions .find ((innerLlmOption ) => innerLlmOption .id === llm) ||
@@ -98,7 +95,7 @@ export default class AiPersonaLlmSelector extends Component {
9895
9996 set value (newValue ) {
10097 this ._value = newValue;
101- this .preferredPersonaStore . setObject ({ key : " id " , value : newValue } );
98+ this .keyValueStore . setItem ( PERSONA_SELECTOR_KEY , newValue);
10299 this .args .setPersonaId (newValue);
103100 this .setAllowLLMSelector ();
104101 this .resetTargetRecipients ();
@@ -123,7 +120,7 @@ export default class AiPersonaLlmSelector extends Component {
123120
124121 set currentLlm (newValue ) {
125122 this .llm = newValue;
126- this .preferredLlmStore . setObject ({ key : " id " , value : newValue } );
123+ this .keyValueStore . setItem ( LLM_SELECTOR_KEY , newValue);
127124
128125 this .resetTargetRecipients ();
129126 }
0 commit comments