2023-04-19 16:57:31 -04:00
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
|
|
|
import showModal from "discourse/lib/show-modal";
|
|
|
|
|
|
|
|
function initializeTopicSummary(api) {
|
|
|
|
api.modifyClass("component:scrolling-post-stream", {
|
2023-04-25 07:19:57 -04:00
|
|
|
pluginId: "discourse-ai",
|
|
|
|
|
2023-04-19 16:57:31 -04:00
|
|
|
showAiSummary() {
|
|
|
|
showModal("ai-summary").setProperties({
|
|
|
|
targetId: this.posts["posts"][0].topic_id,
|
|
|
|
targetType: "topic",
|
|
|
|
allowTimeframe: false,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
api.addTopicSummaryCallback((html, attrs, widget) => {
|
|
|
|
html.push(
|
|
|
|
widget.attach("button", {
|
|
|
|
className: "btn btn-primary topic-ai-summarization",
|
|
|
|
icon: "magic",
|
|
|
|
title: "discourse_ai.summarization.title",
|
|
|
|
label: "discourse_ai.summarization.title",
|
|
|
|
action: "showAiSummary",
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
return html;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
2023-04-25 07:19:57 -04:00
|
|
|
name: "discourse-ai-topic-summary",
|
2023-04-19 16:57:31 -04:00
|
|
|
|
|
|
|
initialize(container) {
|
2023-05-18 11:34:49 -04:00
|
|
|
const user = container.lookup("service:current-user");
|
2023-04-19 16:57:31 -04:00
|
|
|
|
2023-05-18 11:34:49 -04:00
|
|
|
if (user) {
|
|
|
|
const settings = container.lookup("service:site-settings");
|
|
|
|
const summarizationEnabled =
|
|
|
|
settings.discourse_ai_enabled && settings.ai_summarization_enabled;
|
|
|
|
|
|
|
|
if (summarizationEnabled) {
|
|
|
|
withPluginApi("1.6.0", initializeTopicSummary);
|
|
|
|
}
|
2023-04-19 16:57:31 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|