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

Commit 42faa6b

Browse files
committed
DEV: Select tool presets via DMenu instead
1 parent cb5785c commit 42faa6b

File tree

5 files changed

+148
-151
lines changed

5 files changed

+148
-151
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import DiscourseRoute from "discourse/routes/discourse";
22

33
export default class DiscourseAiToolsNewRoute extends DiscourseRoute {
4+
beforeModel(transition) {
5+
this.preset = transition.to.queryParams.presetId || "empty_tool";
6+
}
7+
48
async model() {
59
return this.store.createRecord("ai-tool");
610
}
711

812
setupController(controller) {
913
super.setupController(...arguments);
1014
const toolsModel = this.modelFor("adminPlugins.show.discourse-ai-tools");
11-
1215
controller.set("allTools", toolsModel);
1316
controller.set("presets", toolsModel.resultSetMeta.presets);
1417
controller.set("llms", toolsModel.resultSetMeta.llms);
1518
controller.set("settings", toolsModel.resultSetMeta.settings);
19+
controller.set("selectedPreset", this.preset);
1620
}
1721
}

admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-ai-tools/new.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
@presets={{this.presets}}
66
@llms={{this.llms}}
77
@settings={{this.settings}}
8+
@selectedPreset={{this.selectedPreset}}
89
/>
910
</section>

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

Lines changed: 114 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import DTooltip from "discourse/components/d-tooltip";
1313
import withEventValue from "discourse/helpers/with-event-value";
1414
import { popupAjaxError } from "discourse/lib/ajax-error";
1515
import { i18n } from "discourse-i18n";
16-
import ComboBox from "select-kit/components/combo-box";
1716
import AiToolParameterEditor from "./ai-tool-parameter-editor";
1817
import AiToolTestModal from "./modal/ai-tool-test-modal";
1918
import 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
}

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import Component from "@glimmer/component";
2+
import { array, fn } from "@ember/helper";
3+
import { action } from "@ember/object";
24
import { LinkTo } from "@ember/routing";
35
import { service } from "@ember/service";
6+
import { eq } from "truth-helpers";
47
import DBreadcrumbsItem from "discourse/components/d-breadcrumbs-item";
58
import DButton from "discourse/components/d-button";
69
import DPageSubheader from "discourse/components/d-page-subheader";
@@ -11,6 +14,23 @@ import DMenu from "float-kit/components/d-menu";
1114

1215
export default class AiToolListEditor extends Component {
1316
@service adminPluginNavManager;
17+
@service router;
18+
19+
get lastIndexOfPresets() {
20+
return this.args.tools.resultSetMeta.presets.length - 1;
21+
}
22+
23+
@action
24+
routeToNewTool(preset) {
25+
return this.router.transitionTo(
26+
"adminPlugins.show.discourse-ai-tools.new",
27+
{
28+
queryParams: {
29+
presetId: preset.preset_id,
30+
},
31+
}
32+
);
33+
}
1434

1535
<template>
1636
<DBreadcrumbsItem
@@ -28,19 +48,25 @@ export default class AiToolListEditor extends Component {
2848
@triggerClass="btn-primary btn-small"
2949
@label={{i18n "discourse_ai.tools.new"}}
3050
@icon="plus"
51+
@placement="bottom-end"
3152
>
3253
<:content>
33-
{{! TODO add action to dropdown button that prefills editor }}
3454
<DropdownMenu as |dropdown|>
35-
{{#each @tools.resultSetMeta.presets as |preset|}}
55+
{{#each @tools.resultSetMeta.presets as |preset index|}}
56+
{{#if (eq index this.lastIndexOfPresets)}}
57+
<dropdown.divider />
58+
{{/if}}
59+
3660
<dropdown.item>
3761
<DButton
3862
@translatedLabel={{preset.preset_name}}
63+
@action={{fn this.routeToNewTool preset}}
3964
class="btn-transparent"
4065
/>
4166
</dropdown.item>
4267
{{/each}}
4368
</DropdownMenu>
69+
4470
</:content>
4571
</DMenu>
4672
</:actions>

config/locales/client.en.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,7 @@ en:
327327
test: "Run test"
328328
delete: "Delete"
329329
saved: "Tool saved"
330-
presets: "Select a preset..."
331330
confirm_delete: "Are you sure you want to delete this tool?"
332-
next:
333-
title: "Next"
334331
test_modal:
335332
title: "Test AI tool"
336333
run: "Run test"

0 commit comments

Comments
 (0)