@@ -3,7 +3,7 @@ import { tracked } from "@glimmer/tracking";
33import { array , concat , fn , hash } from " @ember/helper" ;
44import { action } from " @ember/object" ;
55import { service } from " @ember/service" ;
6- import { gt } from " truth-helpers" ;
6+ import { and , gt } from " truth-helpers" ;
77import Form from " discourse/components/form" ;
88import { popupAjaxError } from " discourse/lib/ajax-error" ;
99import { i18n } from " discourse-i18n" ;
@@ -29,13 +29,14 @@ export default class AiToolEditorForm extends Component {
2929 ];
3030
3131 get formData () {
32- const parameters = this .args .editingModel .parameters ?? [];
33- parameters .forEach ((parameter ) => {
34- parameter .isEnum = !! parameter .enum ? .length ;
35- parameter .enum ?? = [];
36- });
32+ const parameters = (this .args .editingModel .parameters ?? []).map (
33+ (parameter ) => ({
34+ ... parameter,
35+ isEnum: !! parameter .enum ? .length ,
36+ enum : (parameter .enum ?? = []),
37+ })
38+ );
3739
38- // TODO: add enum only if parameters.enum is true
3940 return {
4041 name: this .args .editingModel .name || " " ,
4142 tool_name: this .args .editingModel .tool_name || " " ,
@@ -262,36 +263,42 @@ export default class AiToolEditorForm extends Component {
262263
263264 {{#if collectionData.isEnum }}
264265 <row.Col @ size ={{ 8 }} >
265- <form.Button
266- @ icon =" plus"
267- @ label =" discourse_ai.tools.add_enum_value"
268- @ action ={{fn
269- form.addItemToCollection
270- ( concat " parameters." index " .enum" )
271- " "
272- }}
273- />
274-
275266 <collection.Collection @ name =" enum" as | child childIndex | >
276267 <form.Container class =" ai-tool-parameter__enum-values" >
277268 <child.Field
278269 @ title ={{i18n " discourse_ai.tools.enum_value" }}
270+ @ validation =" required"
279271 as | field |
280272 >
281273 <field.Input />
282- </child.Field >
283-
284- {{#if ( gt collectionData.enum.length 0 ) }}
285- <form.Button
286- class =" btn-danger"
287- @ icon =" trash-can"
288- @ action ={{fn child.remove childIndex }}
289- />
290- {{/if }}
291274
275+ {{#if
276+ ( and
277+ ( gt collectionData.enum.length 1 ) ( gt childIndex 0 )
278+ )
279+ }}
280+ <form.Button
281+ class =" btn-danger"
282+ @ icon =" trash-can"
283+ @ action ={{fn child.remove childIndex }}
284+ />
285+ {{/if }}
286+ </child.Field >
292287 </form.Container >
293288 </collection.Collection >
294289 </row.Col >
290+
291+ <row.Col @ size ={{ 8 }} >
292+ <form.Button
293+ @ icon =" plus"
294+ @ label =" discourse_ai.tools.add_enum_value"
295+ @ action ={{fn
296+ form.addItemToCollection
297+ ( concat " parameters." index " .enum" )
298+ " "
299+ }}
300+ />
301+ </row.Col >
295302 {{/if }}
296303 </form.Row >
297304 <form.Row as | row | >
@@ -314,12 +321,7 @@ export default class AiToolEditorForm extends Component {
314321 form.addItemToCollection
315322 " parameters"
316323 ( hash
317- name =" "
318- type =" string"
319- description =" "
320- required =false
321- enum =true
322- enum =( array )
324+ name =" " type =" string" description =" " required =false isEnum =false
323325 )
324326 }}
325327 />
0 commit comments