FIX: unable to share conversations with persona user (#479)
Persona users are still bots, but we were not properly accounting for it and share icon was not showing up. This depends on a core change that adds .topic to transformed posts
This commit is contained in:
parent
a5fe941e6a
commit
becbe01f68
|
@ -56,9 +56,5 @@ async function generateClipboard(topic, fromPostNumber, toPostNumber) {
|
||||||
|
|
||||||
const text = buffer.join("\n");
|
const text = buffer.join("\n");
|
||||||
|
|
||||||
if (window.discourseAiTestClipboard) {
|
|
||||||
window.discourseAiClipboard = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,6 +143,8 @@ function initializePersonaDecorator(api) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MAX_PERSONA_USER_ID = -1200;
|
||||||
|
|
||||||
function initializeShareButton(api) {
|
function initializeShareButton(api) {
|
||||||
const currentUser = api.getCurrentUser();
|
const currentUser = api.getCurrentUser();
|
||||||
if (!currentUser || !currentUser.ai_enabled_chat_bots) {
|
if (!currentUser || !currentUser.ai_enabled_chat_bots) {
|
||||||
|
@ -159,13 +161,20 @@ function initializeShareButton(api) {
|
||||||
};
|
};
|
||||||
|
|
||||||
api.addPostMenuButton("share", (post) => {
|
api.addPostMenuButton("share", (post) => {
|
||||||
// very hacky and ugly, but there is no `.topic` in attrs
|
// for backwards compat so we don't break if topic is undefined
|
||||||
|
if (post.topic?.archetype !== "private_message") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!currentUser.ai_enabled_chat_bots.any(
|
!currentUser.ai_enabled_chat_bots.any(
|
||||||
(bot) => post.username === bot.username
|
(bot) => post.username === bot.username
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return;
|
// special handling for personas (persona bot users start at ID -1200 and go down)
|
||||||
|
if (post.user_id > MAX_PERSONA_USER_ID) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -15,7 +15,7 @@ module DiscourseAi
|
||||||
- Discourse Helper Bot understand *markdown* and responds in Discourse **markdown**.
|
- Discourse Helper Bot understand *markdown* and responds in Discourse **markdown**.
|
||||||
- Discourse Helper Bot has access to the search function on meta.discourse.org and can help you find answers to your questions.
|
- Discourse Helper Bot has access to the search function on meta.discourse.org and can help you find answers to your questions.
|
||||||
- Discourse Helper Bot ALWAYS backs up answers with actual search results from meta.discourse.org, even if the information is in your training set
|
- Discourse Helper Bot ALWAYS backs up answers with actual search results from meta.discourse.org, even if the information is in your training set
|
||||||
- Discourse Helper Bot does not use the word siscourse in searches, search function is restricted to Discourse Meta and Discourse specific discussions
|
- Discourse Helper Bot does not use the word Discourse in searches, search function is restricted to Discourse Meta and Discourse specific discussions
|
||||||
- Discourse Helper Bot understands that search is keyword based (terms are joined using AND) and that it is important to simplify search terms to find things.
|
- Discourse Helper Bot understands that search is keyword based (terms are joined using AND) and that it is important to simplify search terms to find things.
|
||||||
- Discourse Helper Bot understands that users often badly phrase and misspell words, it will compensate for that by guessing what user means.
|
- Discourse Helper Bot understands that users often badly phrase and misspell words, it will compensate for that by guessing what user means.
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ RSpec.describe "Share conversation", type: :system do
|
||||||
posts
|
posts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let(:cdp) { PageObjects::CDP.new }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
SiteSetting.ai_bot_enabled = true
|
SiteSetting.ai_bot_enabled = true
|
||||||
SiteSetting.ai_bot_enabled_chat_bots = "gpt-4"
|
SiteSetting.ai_bot_enabled_chat_bots = "gpt-4"
|
||||||
|
@ -35,26 +37,62 @@ RSpec.describe "Share conversation", type: :system do
|
||||||
bot_user.update!(username: "gpt-4")
|
bot_user.update!(username: "gpt-4")
|
||||||
|
|
||||||
Group.refresh_automatic_groups!
|
Group.refresh_automatic_groups!
|
||||||
pm
|
|
||||||
pm_posts
|
cdp.allow_clipboard
|
||||||
|
page.execute_script("window.navigator.clipboard.writeText('')")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can share a conversation with a persona user" do
|
||||||
|
clip_text = nil
|
||||||
|
|
||||||
|
persona = Fabricate(:ai_persona, name: "Tester")
|
||||||
|
persona.create_user!
|
||||||
|
|
||||||
|
Fabricate(:post, topic: pm, user: admin, raw: "How do I do stuff?")
|
||||||
|
Fabricate(:post, topic: pm, user: persona.user, raw: "No idea")
|
||||||
|
|
||||||
|
visit(pm.url)
|
||||||
|
|
||||||
|
find("#post_2 .post-action-menu__share").click
|
||||||
|
|
||||||
|
try_until_success do
|
||||||
|
clip_text = cdp.read_clipboard
|
||||||
|
expect(clip_text).not_to eq("")
|
||||||
|
end
|
||||||
|
|
||||||
|
conversation = (<<~TEXT).strip
|
||||||
|
<details class='ai-quote'>
|
||||||
|
<summary>
|
||||||
|
<span>This is my special PM</span>
|
||||||
|
<span title='Conversation with AI'>AI</span>
|
||||||
|
</summary>
|
||||||
|
|
||||||
|
**ai_sharer:**
|
||||||
|
|
||||||
|
How do I do stuff?
|
||||||
|
|
||||||
|
**Tester_bot:**
|
||||||
|
|
||||||
|
No idea
|
||||||
|
</details>
|
||||||
|
TEXT
|
||||||
|
|
||||||
|
expect(conversation).to eq(clip_text)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can share a conversation" do
|
it "can share a conversation" do
|
||||||
clip_text = nil
|
clip_text = nil
|
||||||
|
|
||||||
visit(pm.url)
|
pm
|
||||||
|
pm_posts
|
||||||
|
|
||||||
# clipboard functionality is extremely hard to test
|
visit(pm.url)
|
||||||
# we would need special permissions in chrome driver to enable full access
|
|
||||||
# instead we use a secret variable to signal that we want to store clipboard
|
|
||||||
# data in window.discourseAiClipboard
|
|
||||||
page.execute_script("window.discourseAiTestClipboard = true")
|
|
||||||
|
|
||||||
find("#post_2 .post-action-menu__share").click
|
find("#post_2 .post-action-menu__share").click
|
||||||
|
|
||||||
try_until_success do
|
try_until_success do
|
||||||
clip_text = page.evaluate_script("window.discourseAiClipboard")
|
clip_text = cdp.read_clipboard
|
||||||
expect(clip_text).to be_present
|
expect(clip_text).not_to eq("")
|
||||||
end
|
end
|
||||||
|
|
||||||
conversation = (<<~TEXT).strip
|
conversation = (<<~TEXT).strip
|
||||||
|
@ -76,16 +114,15 @@ RSpec.describe "Share conversation", type: :system do
|
||||||
|
|
||||||
expect(conversation).to eq(clip_text)
|
expect(conversation).to eq(clip_text)
|
||||||
|
|
||||||
# Test modal functionality as well
|
page.execute_script("window.navigator.clipboard.writeText('')")
|
||||||
page.evaluate_script("window.discourseAiClipboard = null")
|
|
||||||
|
|
||||||
find("#post_6 .post-action-menu__share").click
|
find("#post_6 .post-action-menu__share").click
|
||||||
find(".ai-share-modal__slider input").set("2")
|
find(".ai-share-modal__slider input").set("2")
|
||||||
find(".ai-share-modal button.btn-primary").click
|
find(".ai-share-modal button.btn-primary").click
|
||||||
|
|
||||||
try_until_success do
|
try_until_success do
|
||||||
clip_text = page.evaluate_script("window.discourseAiClipboard")
|
clip_text = cdp.read_clipboard
|
||||||
expect(clip_text).to be_present
|
expect(clip_text).not_to eq("")
|
||||||
end
|
end
|
||||||
|
|
||||||
conversation = (<<~TEXT).strip
|
conversation = (<<~TEXT).strip
|
||||||
|
|
Loading…
Reference in New Issue