import { cached, tracked } from "@glimmer/tracking"; import BasicTopicList from "discourse/components/basic-topic-list"; import { withPluginApi } from "discourse/lib/plugin-api"; import icon from "discourse-common/helpers/d-icon"; import i18n from "discourse-common/helpers/i18n"; const RelatedTopics = ; export default { name: "discourse-ai-related-topics", initialize(container) { const settings = container.lookup("service:site-settings"); if ( !settings.ai_embeddings_enabled || !settings.ai_embeddings_semantic_related_topics_enabled ) { return; } withPluginApi("1.37.2", (api) => { api.registerMoreTopicsTab({ id: "related-topics", name: i18n("discourse_ai.related_topics.pill"), icon: "discourse-sparkles", component: RelatedTopics, condition: ({ topic }) => topic.relatedTopics?.length, }); api.modifyClass( "model:topic", (Superclass) => class extends Superclass { @tracked related_topics; relatedTopicsCache = []; @cached get relatedTopics() { // Used to keep related topics when a user scrolls up from the // bottom of the topic and then scrolls back down if (this.related_topics) { this.relatedTopicsCache = this.related_topics; } return this.relatedTopicsCache?.map((topic) => this.store.createRecord("topic", topic) ); } } ); api.modifyClass( "model:post-stream", (Superclass) => class extends Superclass { _setSuggestedTopics(result) { super._setSuggestedTopics(...arguments); this.topic.related_topics = result.related_topics; } } ); }); }, };