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

Commit 4b4e93b

Browse files
committed
DEV: remove redundant check_name implementation for the tool_name field
1 parent 27f6a41 commit 4b4e93b

File tree

8 files changed

+8
-120
lines changed

8 files changed

+8
-120
lines changed

app/controllers/discourse_ai/admin/ai_tools_controller.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ def destroy
4545
end
4646
end
4747

48-
def check_name
49-
tool_name = params.require(:tool_name)
50-
51-
render json: DiscourseAi::ToolNameChecker.new(tool_name).check
52-
end
53-
5448
def test
5549
if params[:id].present?
5650
ai_tool = AiTool.find(params[:id])

app/services/discourse_ai/tool_name_checker.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { TrackedArray, TrackedObject } from "@ember-compat/tracked-built-ins";
2-
import { ajax } from "discourse/lib/ajax";
32
import RestModel from "discourse/models/rest";
43

54
const CREATE_ATTRIBUTES = [
@@ -17,11 +16,6 @@ const CREATE_ATTRIBUTES = [
1716
];
1817

1918
export default class AiTool extends RestModel {
20-
static checkName(name) {
21-
return ajax("/admin/plugins/discourse-ai/ai-tools/check-name", {
22-
data: { tool_name: name },
23-
});
24-
}
2519
createProperties() {
2620
return this.getProperties(CREATE_ATTRIBUTES);
2721
}

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

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@ import { action } from "@ember/object";
66
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
77
import didUpdate from "@ember/render-modifiers/modifiers/did-update";
88
import { service } from "@ember/service";
9-
import { isEmpty } from "@ember/utils";
109
import AceEditor from "discourse/components/ace-editor";
1110
import BackButton from "discourse/components/back-button";
1211
import DButton from "discourse/components/d-button";
1312
import DTooltip from "discourse/components/d-tooltip";
14-
import InputTip from "discourse/components/input-tip";
1513
import withEventValue from "discourse/helpers/with-event-value";
1614
import { popupAjaxError } from "discourse/lib/ajax-error";
17-
import discourseDebounce from "discourse-common/lib/debounce";
1815
import I18n from "discourse-i18n";
1916
import ComboBox from "select-kit/components/combo-box";
20-
import AiTool from "../admin/models/ai-tool";
2117
import AiToolParameterEditor from "./ai-tool-parameter-editor";
2218
import AiToolTestModal from "./modal/ai-tool-test-modal";
2319
import RagOptions from "./rag-options";
@@ -34,15 +30,11 @@ export default class AiToolEditor extends Component {
3430
@service store;
3531
@service siteSettings;
3632

37-
@tracked toolName = null;
3833
@tracked isSaving = false;
3934
@tracked editingModel = null;
4035
@tracked showDelete = false;
4136
@tracked selectedPreset = null;
4237

43-
@tracked disableSave = null;
44-
@tracked nameValidation = null;
45-
4638
get presets() {
4739
return this.args.presets.map((preset) => {
4840
return {
@@ -60,7 +52,6 @@ export default class AiToolEditor extends Component {
6052
updateModel() {
6153
this.editingModel = this.args.model.workingCopy();
6254
this.showDelete = !this.args.model.isNew;
63-
this.toolName = this.editingModel.tool_name;
6455
}
6556

6657
@action
@@ -69,7 +60,6 @@ export default class AiToolEditor extends Component {
6960
this.editingModel = this.store
7061
.createRecord("ai-tool", this.selectedPreset)
7162
.workingCopy();
72-
7363
this.showDelete = false;
7464
}
7565

@@ -86,34 +76,6 @@ export default class AiToolEditor extends Component {
8676
}
8777
}
8878

89-
@action
90-
validateAndUpdateToolName(value) {
91-
// Skip validation if name hasn't changed
92-
if (value === this.jobName) {
93-
this._failedInputValidation("");
94-
this.disableSave = false;
95-
return;
96-
}
97-
98-
this.editingModel.tool_name = value;
99-
100-
if (value === undefined) {
101-
return this._failedInputValidation();
102-
}
103-
104-
if (isEmpty(value)) {
105-
return this._failedInputValidation(
106-
I18n.t("discourse_ai.tools.new.tool_name.blank")
107-
);
108-
}
109-
110-
this._checkToolNameDebounced();
111-
112-
return this._failedInputValidation(
113-
I18n.t("discourse_ai.tools.new.tool_name.checking")
114-
);
115-
}
116-
11779
_checkToolNameDebounced() {
11880
discourseDebounce(this, this._checkToolName, 500);
11981
}
@@ -200,20 +162,6 @@ export default class AiToolEditor extends Component {
200162
});
201163
}
202164

203-
get disableSaveButton() {
204-
return this.disableSave || this.isSaving;
205-
}
206-
207-
_failedInputValidation(reason) {
208-
this.disableSave = true;
209-
const options = { failed: true };
210-
if (reason) {
211-
options.reason = reason;
212-
}
213-
this.nameValidation = options;
214-
return options;
215-
}
216-
217165
<template>
218166
<BackButton
219167
@route="adminPlugins.show.discourse-ai-tools"
@@ -260,7 +208,10 @@ export default class AiToolEditor extends Component {
260208
<div class="control-group">
261209
<label>{{I18n.t "discourse_ai.tools.tool_name"}}</label>
262210
<input
263-
{{on "input" (withEventValue this.validateAndUpdateToolName)}}
211+
{{on
212+
"input"
213+
(withEventValue (fn (mut this.editingModel.tool_name)))
214+
}}
264215
value={{this.editingModel.tool_name}}
265216
type="text"
266217
class="ai-tool-editor__tool_name"
@@ -269,7 +220,6 @@ export default class AiToolEditor extends Component {
269220
@icon="question-circle"
270221
@content={{I18n.t "discourse_ai.tools.tool_name_help"}}
271222
/>
272-
<InputTip @validation={{this.nameValidation}} />
273223
</div>
274224

275225
<div class="control-group">
@@ -335,7 +285,7 @@ export default class AiToolEditor extends Component {
335285
<DButton
336286
@action={{this.save}}
337287
@label="discourse_ai.tools.save"
338-
@disabled={{this.disableSaveButton}}
288+
@disabled={{this.isSaving}}
339289
class="btn-primary ai-tool-editor__save"
340290
/>
341291

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default class AiToolListEditor extends Component {
2222
class="btn btn-small btn-primary ai-tool-list-editor__new-button"
2323
>
2424
{{icon "plus"}}
25-
<span>{{I18n.t "discourse_ai.tools.new.title"}}</span>
25+
<span>{{I18n.t "discourse_ai.tools.new"}}</span>
2626
</LinkTo>
2727
</div>
2828

config/locales/client.en.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ en:
211211
tools:
212212
back: "Back"
213213
short_title: "Tools"
214+
new: "New tool"
214215
name: "Name"
215216
name_help: "Name will show up in the Discourse UI and is the short identifier you will use to find the tool in various settings, it should be distinct (it is required)"
216217
tool_name: "Tool Name"
@@ -241,12 +242,6 @@ en:
241242
title: "Test AI Tool"
242243
run: "Run Test"
243244
result: "Test Result"
244-
new:
245-
title: "New Tool"
246-
tool_name:
247-
blank: "Tool name cannot be blank"
248-
checking: "Checking tool name…"
249-
available: "Tool name is available"
250245

251246
llms:
252247
short_title: "LLMs"

config/routes.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@
5151
only: %i[index create show update destroy],
5252
path: "ai-tools",
5353
controller: "discourse_ai/admin/ai_tools",
54-
) do
55-
collection do
56-
post :test
57-
get "check-name" => "discourse_ai/admin/ai_tools#check_name"
58-
end
59-
end
54+
) { post :test, on: :collection }
6055

6156
post "/ai-personas/:id/create-user", to: "discourse_ai/admin/ai_personas#create_user"
6257

spec/services/discourse_ai/tool_name_checker_spec.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)