import Component from "@glimmer/component"; import { fn } from "@ember/helper"; import { on } from "@ember/modifier"; import { action } from "@ember/object"; import { TrackedArray, TrackedObject } from "@ember-compat/tracked-built-ins"; import DButton from "discourse/components/d-button"; import withEventValue from "discourse/helpers/with-event-value"; import I18n from "discourse-i18n"; import ComboBox from "select-kit/components/combo-box"; const PARAMETER_TYPES = [ { name: "string", id: "string" }, { name: "number", id: "number" }, { name: "boolean", id: "boolean" }, { name: "array", id: "array" }, ]; export default class AiToolParameterEditor extends Component { @action addParameter() { this.args.parameters.push( new TrackedObject({ name: "", description: "", type: "string", required: false, enum: null, }) ); } @action removeParameter(parameter) { const index = this.args.parameters.indexOf(parameter); this.args.parameters.splice(index, 1); } @action toggleRequired(parameter, event) { parameter.required = event.target.checked; } @action toggleEnum(parameter) { if (parameter.enum) { parameter.enum = null; } else { this.addEnumValue(parameter); } } @action addEnumValue(parameter) { parameter.enum ||= new TrackedArray(); parameter.enum.push(""); } @action removeEnumValue(parameter, index) { parameter.enum.splice(index, 1); if (parameter.enum.length === 0) { parameter.enum = null; } } @action updateEnumValue(parameter, index, event) { parameter.enum[index] = event.target.value; } }