2024-03-12 01:51:41 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2023-05-18 02:10:08 -04:00
|
|
|
import Composer from "discourse/models/composer";
|
|
|
|
import I18n from "I18n";
|
2024-03-12 01:51:41 -04:00
|
|
|
import ShareFullTopicModal from "../components/modal/share-full-topic-modal";
|
|
|
|
|
2024-11-12 13:46:17 -05:00
|
|
|
const MAX_PERSONA_USER_ID = -1200;
|
|
|
|
|
|
|
|
export function isPostFromAiBot(post, currentUser) {
|
|
|
|
return (
|
|
|
|
post.user_id <= MAX_PERSONA_USER_ID ||
|
|
|
|
!!currentUser?.ai_enabled_chat_bots?.any(
|
|
|
|
(bot) => post.username === bot.username
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-03-12 01:51:41 -04:00
|
|
|
export function showShareConversationModal(modal, topicId) {
|
|
|
|
ajax(`/discourse-ai/ai-bot/shared-ai-conversations/preview/${topicId}.json`)
|
|
|
|
.then((payload) => {
|
|
|
|
modal.show(ShareFullTopicModal, { model: payload });
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
}
|
2023-05-18 02:10:08 -04:00
|
|
|
|
2023-08-16 16:29:58 -04:00
|
|
|
export function composeAiBotMessage(targetBot, composer) {
|
|
|
|
const currentUser = composer.currentUser;
|
|
|
|
|
|
|
|
let botUsername = currentUser.ai_enabled_chat_bots.find(
|
|
|
|
(bot) => bot.model_name === targetBot
|
|
|
|
).username;
|
2023-05-18 02:10:08 -04:00
|
|
|
|
|
|
|
composer.focusComposer({
|
|
|
|
fallbackToNewTopic: true,
|
|
|
|
openOpts: {
|
|
|
|
action: Composer.PRIVATE_MESSAGE,
|
|
|
|
recipients: botUsername,
|
|
|
|
topicTitle: I18n.t("discourse_ai.ai_bot.default_pm_prefix"),
|
|
|
|
archetypeId: "private_message",
|
2024-02-02 15:09:34 -05:00
|
|
|
draftKey: "private_message_ai",
|
2023-05-18 02:10:08 -04:00
|
|
|
hasGroups: false,
|
|
|
|
warningsDisabled: true,
|
2024-02-02 15:09:34 -05:00
|
|
|
skipDraftCheck: true,
|
2023-05-18 02:10:08 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|