import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; import { Input } from "@ember/component"; import { action } from "@ember/object"; import { later } from "@ember/runloop"; import { inject as service } from "@ember/service"; import DButton from "discourse/components/d-button"; import { popupAjaxError } from "discourse/lib/ajax-error"; import i18n from "discourse-common/helpers/i18n"; import I18n from "discourse-i18n"; import ComboBox from "select-kit/components/combo-box"; import DTooltip from "float-kit/components/d-tooltip"; export default class AiLlmEditor extends Component { @service toasts; @service router; @tracked isSaving = false; get selectedProviders() { const t = (provName) => { return I18n.t(`discourse_ai.llms.providers.${provName}`); }; return this.args.llms.resultSetMeta.providers.map((prov) => { return { id: prov, name: t(prov) }; }); } @action async save() { this.isSaving = true; const isNew = this.args.model.isNew; try { await this.args.model.save(); if (isNew) { this.args.llms.addObject(this.args.model); this.router.transitionTo( "adminPlugins.show.discourse-ai-llms.show", this.args.model ); } else { this.toasts.success({ data: { message: I18n.t("discourse_ai.llms.saved") }, duration: 2000, }); } } catch (e) { popupAjaxError(e); } finally { later(() => { this.isSaving = false; }, 1000); } } }