2023-04-04 10:24:09 -04:00
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
|
|
|
import showModal from "discourse/lib/show-modal";
|
|
|
|
import { action } from "@ember/object";
|
|
|
|
|
|
|
|
function initializeChatChannelSummary(api) {
|
|
|
|
const chat = api.container.lookup("service:chat");
|
|
|
|
if (chat) {
|
|
|
|
api.registerChatComposerButton?.({
|
|
|
|
translatedLabel: "discourse_ai.summarization.title",
|
|
|
|
id: "chat_channel_summary",
|
2023-04-20 11:11:24 -04:00
|
|
|
icon: "discourse-sparkles",
|
2023-04-04 10:24:09 -04:00
|
|
|
action: "showChannelSummary",
|
|
|
|
position: "dropdown",
|
|
|
|
});
|
|
|
|
|
|
|
|
api.modifyClass("component:chat-composer", {
|
|
|
|
pluginId: "discourse-ai",
|
|
|
|
|
|
|
|
@action
|
|
|
|
showChannelSummary() {
|
2023-04-19 16:57:31 -04:00
|
|
|
showModal("ai-summary").setProperties({
|
2023-04-25 05:25:07 -04:00
|
|
|
targetId: this.args.channel.id,
|
2023-04-19 16:57:31 -04:00
|
|
|
targetType: "chat_channel",
|
|
|
|
allowTimeframe: true,
|
2023-04-04 10:24:09 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
2023-04-25 07:19:57 -04:00
|
|
|
name: "discourse-ai-chat-channel-summary",
|
2023-04-04 10:24:09 -04:00
|
|
|
|
|
|
|
initialize(container) {
|
2023-04-25 07:19:57 -04:00
|
|
|
const settings = container.lookup("service:site-settings");
|
2023-04-04 10:24:09 -04:00
|
|
|
const summarizationEnabled =
|
|
|
|
settings.discourse_ai_enabled && settings.ai_summarization_enabled;
|
|
|
|
|
|
|
|
if (summarizationEnabled) {
|
|
|
|
withPluginApi("1.6.0", initializeChatChannelSummary);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|