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

Commit cb107de

Browse files
committed
WIP: enum values
1 parent fd09595 commit cb107de

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import Component from "@glimmer/component";
22
import { tracked } from "@glimmer/tracking";
3-
import { fn, hash } from "@ember/helper";
3+
import { array, fn, hash } from "@ember/helper";
44
import { action } from "@ember/object";
55
import { service } from "@ember/service";
6+
import { gt } from "truth-helpers";
67
import Form from "discourse/components/form";
78
import { popupAjaxError } from "discourse/lib/ajax-error";
89
import { i18n } from "discourse-i18n";
@@ -28,12 +29,15 @@ export default class AiToolEditorForm extends Component {
2829
];
2930

3031
get formData() {
32+
// TODO: add enumData only if parameters.enum is true
3133
return {
3234
name: this.args.editingModel.name || "",
3335
tool_name: this.args.editingModel.tool_name || "",
3436
description: this.args.editingModel.description || "",
3537
summary: this.args.editingModel.summary || "",
36-
parameters: this.args.editingModel.parameters || [],
38+
parameters: this.args.editingModel.parameters || [
39+
{ enumData: ["foo", "bar"] },
40+
],
3741
script: this.args.editingModel.script || "",
3842
rag_uploads: this.args.editingModel.rag_uploads || [],
3943
};
@@ -237,7 +241,38 @@ export default class AiToolEditorForm extends Component {
237241
</row.Col>
238242

239243
{{#if collectionData.enum}}
240-
HANDLE IS ENUM
244+
<row.Col @size={{8}}>
245+
<collection.Collection @name="enumData" as |child childIndex|>
246+
<form.Container class="ai-tool-parameter__enum-values">
247+
<child.Field
248+
@name="enumValue"
249+
@title={{i18n "discourse_ai.tools.enum_value"}}
250+
as |field|
251+
>
252+
<field.Input />
253+
</child.Field>
254+
255+
{{#if (gt collectionData.enumData.length 1)}}
256+
<form.Button
257+
class="btn-danger"
258+
@icon="trash-can"
259+
@action={{fn child.remove childIndex}}
260+
/>
261+
{{/if}}
262+
263+
<form.Button
264+
@icon="plus"
265+
@label="discourse_ai.tools.add_enum_value"
266+
@action={{fn
267+
form.addItemToCollection
268+
"enumData"
269+
(array "")
270+
}}
271+
/>
272+
</form.Container>
273+
274+
</collection.Collection>
275+
</row.Col>
241276
{{/if}}
242277
</form.Row>
243278
<form.Row as |row|>

assets/stylesheets/modules/ai-bot/common/ai-tools.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@
1111
}
1212
}
1313

14+
.ai-tool-parameter__enum-values {
15+
.form-kit__container-content {
16+
display: grid;
17+
grid-template-columns: 1fr auto;
18+
19+
.form-kit__button.btn-icon-text {
20+
justify-self: start;
21+
grid-column: 1 / -1;
22+
}
23+
}
24+
25+
&:last-child {
26+
border-bottom: 1px solid var(--primary-low);
27+
padding-bottom: 2rem;
28+
}
29+
}
30+
1431
.ai-tool-editor {
1532
max-width: 80%;
1633
position: relative;

0 commit comments

Comments
 (0)