11import Component from " @glimmer/component" ;
22import { tracked } from " @glimmer/tracking" ;
3- import { array , fn , hash } from " @ember/helper" ;
3+ import { array , concat , fn , hash } from " @ember/helper" ;
44import { action } from " @ember/object" ;
55import { service } from " @ember/service" ;
66import { gt } from " truth-helpers" ;
@@ -29,20 +29,35 @@ export default class AiToolEditorForm extends Component {
2929 ];
3030
3131 get formData () {
32- // TODO: add enumData only if parameters.enum is true
32+ const parameters = this .args .editingModel .parameters ?? [];
33+ parameters .forEach ((parameter ) => {
34+ parameter .isEnum = !! parameter .enum ? .length ;
35+ parameter .enum ?? = [];
36+ });
37+
38+ // TODO: add enum only if parameters.enum is true
3339 return {
3440 name: this .args .editingModel .name || " " ,
3541 tool_name: this .args .editingModel .tool_name || " " ,
3642 description: this .args .editingModel .description || " " ,
3743 summary: this .args .editingModel .summary || " " ,
38- parameters: this .args .editingModel .parameters || [
39- { enumData: [" foo" , " bar" ] },
40- ],
44+ parameters,
4145 script: this .args .editingModel .script || " " ,
4246 rag_uploads: this .args .editingModel .rag_uploads || [],
4347 };
4448 }
4549
50+ @action
51+ toggleIsEnum (value , { name, parentName, set }) {
52+ if (value) {
53+ set (` ${ parentName} .enum` , [" " ]);
54+ } else {
55+ set (` ${ parentName} .enum` , []);
56+ }
57+
58+ set (name, value);
59+ }
60+
4661 @action
4762 async save (data ) {
4863 this .isSaving = true ;
@@ -235,42 +250,46 @@ export default class AiToolEditorForm extends Component {
235250 </row.Col >
236251
237252 <row.Col >
238- <collection.Field @ name =" enum" @ title =" Enum" as | field | >
253+ <collection.Field
254+ @ name =" isEnum"
255+ @ title =" Enum"
256+ @ onSet ={{this .toggleIsEnum }}
257+ as | field |
258+ >
239259 <field.Checkbox />
240260 </collection.Field >
241261 </row.Col >
242262
243- {{#if collectionData.enum }}
263+ {{#if collectionData.isEnum }}
244264 <row.Col @ size ={{ 8 }} >
245- <collection.Collection @ name =" enumData" as | child childIndex | >
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+
275+ <collection.Collection @ name =" enum" as | child childIndex | >
246276 <form.Container class =" ai-tool-parameter__enum-values" >
247277 <child.Field
248- @ name =" enumValue"
249278 @ title ={{i18n " discourse_ai.tools.enum_value" }}
250279 as | field |
251280 >
252281 <field.Input />
253282 </child.Field >
254283
255- {{#if ( gt collectionData.enumData .length 1 ) }}
284+ {{#if ( gt collectionData.enum .length 0 ) }}
256285 <form.Button
257286 class =" btn-danger"
258287 @ icon =" trash-can"
259288 @ action ={{fn child.remove childIndex }}
260289 />
261290 {{/if }}
262291
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- />
272292 </form.Container >
273-
274293 </collection.Collection >
275294 </row.Col >
276295 {{/if }}
@@ -294,7 +313,14 @@ export default class AiToolEditorForm extends Component {
294313 @ action ={{fn
295314 form.addItemToCollection
296315 " parameters"
297- ( hash name =" " type =" string" description =" " required =false enum =false )
316+ ( hash
317+ name =" "
318+ type =" string"
319+ description =" "
320+ required =false
321+ enum =true
322+ enum =( array )
323+ )
298324 }}
299325 />
300326
0 commit comments