@@ -13,7 +13,6 @@ import DTooltip from "discourse/components/d-tooltip";
1313import withEventValue from " discourse/helpers/with-event-value" ;
1414import { popupAjaxError } from " discourse/lib/ajax-error" ;
1515import { i18n } from " discourse-i18n" ;
16- import ComboBox from " select-kit/components/combo-box" ;
1716import AiToolParameterEditor from " ./ai-tool-parameter-editor" ;
1817import AiToolTestModal from " ./modal/ai-tool-test-modal" ;
1918import RagOptions from " ./rag-options" ;
@@ -33,34 +32,26 @@ export default class AiToolEditor extends Component {
3332 @tracked isSaving = false ;
3433 @tracked editingModel = null ;
3534 @tracked showDelete = false ;
36- @tracked selectedPreset = null ;
3735
38- get presets () {
39- return this .args .presets .map ((preset ) => {
40- return {
41- name: preset .preset_name ,
42- id: preset .preset_id ,
43- };
44- });
45- }
36+ get selectedPreset () {
37+ if (! this .args .selectedPreset ) {
38+ return null ;
39+ }
4640
47- get showPresets () {
48- return ! this .selectedPreset && this .args .model .isNew ;
41+ return this .args .presets .findBy (" preset_id" , this .args .selectedPreset );
4942 }
5043
5144 @action
5245 updateModel () {
53- this .editingModel = this .args .model .workingCopy ();
54- this .showDelete = ! this .args .model .isNew ;
55- }
56-
57- @action
58- configurePreset () {
59- this .selectedPreset = this .args .presets .findBy (" preset_id" , this .presetId );
60- this .editingModel = this .store
61- .createRecord (" ai-tool" , this .selectedPreset )
62- .workingCopy ();
63- this .showDelete = false ;
46+ if (this .args .model .isNew ) {
47+ this .editingModel = this .store
48+ .createRecord (" ai-tool" , this .selectedPreset )
49+ .workingCopy ();
50+ this .showDelete = false ;
51+ } else {
52+ this .editingModel = this .args .model .workingCopy ();
53+ this .showDelete = ! this .args .model .isNew ;
54+ }
6455 }
6556
6657 @action
@@ -148,138 +139,116 @@ export default class AiToolEditor extends Component {
148139 {{didUpdate this . updateModel @ model.id}}
149140 class =" form-horizontal ai-tool-editor"
150141 >
151- {{#if this . showPresets }}
142+ <div class =" control-group" >
143+ <label >{{i18n " discourse_ai.tools.name" }} </label >
144+ <input
145+ {{on " input" ( withEventValue ( fn ( mut this . editingModel.name) ) ) }}
146+ value ={{this .editingModel.name }}
147+ type =" text"
148+ class =" ai-tool-editor__name"
149+ />
150+ <DTooltip
151+ @ icon =" circle-question"
152+ @ content ={{i18n " discourse_ai.tools.name_help" }}
153+ />
154+ </div >
155+
156+ <div class =" control-group" >
157+ <label >{{i18n " discourse_ai.tools.tool_name" }} </label >
158+ <input
159+ {{on " input" ( withEventValue ( fn ( mut this . editingModel.tool_name) ) ) }}
160+ value ={{this .editingModel.tool_name }}
161+ type =" text"
162+ class =" ai-tool-editor__tool_name"
163+ />
164+ <DTooltip
165+ @ icon =" circle-question"
166+ @ content ={{i18n " discourse_ai.tools.tool_name_help" }}
167+ />
168+ </div >
169+
170+ <div class =" control-group" >
171+ <label >{{i18n " discourse_ai.tools.description" }} </label >
172+ <textarea
173+ {{on
174+ " input"
175+ ( withEventValue ( fn ( mut this . editingModel.description) ) )
176+ }}
177+ placeholder ={{i18n " discourse_ai.tools.description_help" }}
178+ class =" ai-tool-editor__description input-xxlarge"
179+ >{{this .editingModel.description }} </textarea >
180+ </div >
181+
182+ <div class =" control-group" >
183+ <label >{{i18n " discourse_ai.tools.summary" }} </label >
184+ <input
185+ {{on " input" ( withEventValue ( fn ( mut this . editingModel.summary) ) ) }}
186+ value ={{this .editingModel.summary }}
187+ type =" text"
188+ class =" ai-tool-editor__summary input-xxlarge"
189+ />
190+ <DTooltip
191+ @ icon =" circle-question"
192+ @ content ={{i18n " discourse_ai.tools.summary_help" }}
193+ />
194+ </div >
195+
196+ <div class =" control-group" >
197+ <label >{{i18n " discourse_ai.tools.parameters" }} </label >
198+ <AiToolParameterEditor @ parameters ={{this .editingModel.parameters }} />
199+ </div >
200+
201+ <div class =" control-group" >
202+ <label >{{i18n " discourse_ai.tools.script" }} </label >
203+ <AceEditor
204+ @ content ={{this .editingModel.script }}
205+ @ onChange ={{fn ( mut this . editingModel.script) }}
206+ @ mode ={{ACE_EDITOR_MODE }}
207+ @ theme ={{ACE_EDITOR_THEME }}
208+ @ editorId =" ai-tool-script-editor"
209+ />
210+ </div >
211+
212+ {{#if this . siteSettings.ai_embeddings_enabled }}
152213 <div class =" control-group" >
153- <label > {{ i18n " discourse_ai.tools.presets " }} </ label >
154- < ComboBox
155- @ value ={{this .presetId }}
156- @ content ={{this .presets }}
157- class = " ai-tool-editor__presets "
214+ <RagUploader
215+ @ target = {{ this .editingModel }}
216+ @ updateUploads ={{this .updateUploads }}
217+ @ onRemove ={{this .removeUpload }}
218+ @ allowImages = {{ @ settings.rag_images_enabled }}
158219 />
159220 </div >
221+ <RagOptions
222+ @ model ={{this .editingModel }}
223+ @ llms ={{@ llms }}
224+ @ allowImages ={{@ settings.rag_images_enabled }}
225+ />
226+ {{/if }}
160227
161- <div class =" control-group ai-llm-editor__action_panel" >
228+ <div class =" control-group ai-tool-editor__action_panel" >
229+ {{#unless @ model.isNew }}
162230 <DButton
163- @ action ={{this .configurePreset }}
164- @ label =" discourse_ai.tools.next.title"
165- class =" ai-tool-editor__next"
166- />
167- </div >
168- {{else }}
169- <div class =" control-group" >
170- <label >{{i18n " discourse_ai.tools.name" }} </label >
171- <input
172- {{on " input" ( withEventValue ( fn ( mut this . editingModel.name) ) ) }}
173- value ={{this .editingModel.name }}
174- type =" text"
175- class =" ai-tool-editor__name"
176- />
177- <DTooltip
178- @ icon =" circle-question"
179- @ content ={{i18n " discourse_ai.tools.name_help" }}
180- />
181- </div >
182-
183- <div class =" control-group" >
184- <label >{{i18n " discourse_ai.tools.tool_name" }} </label >
185- <input
186- {{on
187- " input"
188- ( withEventValue ( fn ( mut this . editingModel.tool_name) ) )
189- }}
190- value ={{this .editingModel.tool_name }}
191- type =" text"
192- class =" ai-tool-editor__tool_name"
193- />
194- <DTooltip
195- @ icon =" circle-question"
196- @ content ={{i18n " discourse_ai.tools.tool_name_help" }}
197- />
198- </div >
199-
200- <div class =" control-group" >
201- <label >{{i18n " discourse_ai.tools.description" }} </label >
202- <textarea
203- {{on
204- " input"
205- ( withEventValue ( fn ( mut this . editingModel.description) ) )
206- }}
207- placeholder ={{i18n " discourse_ai.tools.description_help" }}
208- class =" ai-tool-editor__description input-xxlarge"
209- >{{this .editingModel.description }} </textarea >
210- </div >
211-
212- <div class =" control-group" >
213- <label >{{i18n " discourse_ai.tools.summary" }} </label >
214- <input
215- {{on " input" ( withEventValue ( fn ( mut this . editingModel.summary) ) ) }}
216- value ={{this .editingModel.summary }}
217- type =" text"
218- class =" ai-tool-editor__summary input-xxlarge"
219- />
220- <DTooltip
221- @ icon =" circle-question"
222- @ content ={{i18n " discourse_ai.tools.summary_help" }}
231+ @ action ={{this .openTestModal }}
232+ @ label =" discourse_ai.tools.test"
233+ class =" ai-tool-editor__test-button"
223234 />
224- </ div >
235+ {{/ unless }}
225236
226- <div class =" control-group" >
227- <label >{{i18n " discourse_ai.tools.parameters" }} </label >
228- <AiToolParameterEditor @ parameters ={{this .editingModel.parameters }} />
229- </div >
230-
231- <div class =" control-group" >
232- <label >{{i18n " discourse_ai.tools.script" }} </label >
233- <AceEditor
234- @ content ={{this .editingModel.script }}
235- @ onChange ={{fn ( mut this . editingModel.script) }}
236- @ mode ={{ACE_EDITOR_MODE }}
237- @ theme ={{ACE_EDITOR_THEME }}
238- @ editorId =" ai-tool-script-editor"
239- />
240- </div >
241-
242- {{#if this . siteSettings.ai_embeddings_enabled }}
243- <div class =" control-group" >
244- <RagUploader
245- @ target ={{this .editingModel }}
246- @ updateUploads ={{this .updateUploads }}
247- @ onRemove ={{this .removeUpload }}
248- @ allowImages ={{@ settings.rag_images_enabled }}
249- />
250- </div >
251- <RagOptions
252- @ model ={{this .editingModel }}
253- @ llms ={{@ llms }}
254- @ allowImages ={{@ settings.rag_images_enabled }}
255- />
256- {{/if }}
257-
258- <div class =" control-group ai-tool-editor__action_panel" >
259- {{#unless @ model.isNew }}
260- <DButton
261- @ action ={{this .openTestModal }}
262- @ label =" discourse_ai.tools.test"
263- class =" ai-tool-editor__test-button"
264- />
265- {{/unless }}
237+ <DButton
238+ @ action ={{this .save }}
239+ @ label =" discourse_ai.tools.save"
240+ @ disabled ={{this .isSaving }}
241+ class =" btn-primary ai-tool-editor__save"
242+ />
266243
244+ {{#if this . showDelete }}
267245 <DButton
268- @ action ={{this .save }}
269- @ label =" discourse_ai.tools.save"
270- @ disabled ={{this .isSaving }}
271- class =" btn-primary ai-tool-editor__save"
246+ @ action ={{this .delete }}
247+ @ label =" discourse_ai.tools.delete"
248+ class =" btn-danger ai-tool-editor__delete"
272249 />
273-
274- {{#if this . showDelete }}
275- <DButton
276- @ action ={{this .delete }}
277- @ label =" discourse_ai.tools.delete"
278- class =" btn-danger ai-tool-editor__delete"
279- />
280- {{/if }}
281- </div >
282- {{/if }}
250+ {{/if }}
251+ </div >
283252 </form >
284253 </template >
285254}
0 commit comments