import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; import { action } from "@ember/object"; import didInsert from "@ember/render-modifiers/modifiers/did-insert"; import { inject as service } from "@ember/service"; import icon from "discourse-common/helpers/d-icon"; import { bind } from "discourse-common/utils/decorators"; import I18n from "discourse-i18n"; export default class RagUploadProgress extends Component { @service messageBus; @tracked updatedProgress = null; willDestroy() { super.willDestroy(...arguments); this.messageBus.unsubscribe( `/discourse-ai/ai-persona-rag/${this.args.upload.id}` ); } @action trackProgress() { this.messageBus.subscribe( `/discourse-ai/ai-persona-rag/${this.args.upload.id}`, this.onIndexingUpdate ); } @bind onIndexingUpdate(data) { // Order not guaranteed. Discard old updates. if ( !this.updatedProgress || data.total === 0 || this.updatedProgress.left > data.left ) { this.updatedProgress = data; } } get calculateProgress() { if (this.progress.total === 0) { return 0; } return Math.ceil((this.progress.indexed * 100) / this.progress.total); } get fullyIndexed() { return ( this.progress && this.progress.total !== 0 && this.progress.left === 0 ); } get progress() { if (this.updatedProgress) { return this.updatedProgress; } else if (this.args.ragIndexingStatuses) { return this.args.ragIndexingStatuses[this.args.upload.id]; } else { return []; } } }