ai*
This commit is contained in:
56
ai_agentic/static/tests/command_palette.test.js
Normal file
56
ai_agentic/static/tests/command_palette.test.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import { test } from "@odoo/hoot";
|
||||
import { makeMockServer, getService } from "@web/../tests/web_test_helpers";
|
||||
import {
|
||||
triggerHotkey,
|
||||
start,
|
||||
insertText,
|
||||
contains,
|
||||
click,
|
||||
} from "@mail/../tests/mail_test_helpers";
|
||||
import { defineAIModels } from "@ai/../tests/ai_test_helpers";
|
||||
|
||||
defineAIModels();
|
||||
|
||||
test.tags("desktop");
|
||||
test("[text composer] can open chat with @agent in command palette with focused composer", async () => {
|
||||
const mockServer = await makeMockServer();
|
||||
|
||||
const partnerId = mockServer.env["res.partner"].create({
|
||||
name: "Test agent",
|
||||
active: false,
|
||||
});
|
||||
mockServer.env["ai.agent"].create({
|
||||
name: "Test agent",
|
||||
partner_id: partnerId,
|
||||
});
|
||||
|
||||
await start();
|
||||
triggerHotkey("control+k");
|
||||
await insertText(".o_command_palette_search input", "@");
|
||||
await contains(".o_command_category>.text-uppercase", { text: "Agents" });
|
||||
await insertText(".o_command_palette_search input[placeholder='Search conversations']", "Test agent");
|
||||
await click(".o_command:has([data-icon='settings'])", { text: "Test agent" });
|
||||
await contains("input.o-mail-DiscussContent-threadName:value(Test agent)");
|
||||
await contains(".o-mail-Composer.o-focused");
|
||||
});
|
||||
|
||||
test.tags("desktop", "html composer");
|
||||
test("can open chat with @agent in command palette with focused composer", async () => {
|
||||
const mockServer = await makeMockServer();
|
||||
const partnerId = mockServer.env["res.partner"].create({
|
||||
name: "AI Agent",
|
||||
});
|
||||
mockServer.env["ai.agent"].create({
|
||||
name: "Test Agent",
|
||||
partner_id: partnerId,
|
||||
});
|
||||
await start();
|
||||
const composerService = getService("mail.composer");
|
||||
composerService.setHtmlComposer();
|
||||
triggerHotkey("control+k");
|
||||
await insertText(".o_command_palette_search input", "@");
|
||||
await insertText(".o_command_palette_search input[placeholder='Search conversations']", "AI Agent");
|
||||
await click(".o_command:has([data-icon='settings'])", { text: "AI Agent" });
|
||||
await contains("input.o-mail-DiscussContent-threadName:value(AI Agent)");
|
||||
await contains(".o-mail-Composer.o-focused");
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
import { messagingMenuHelpers } from "@mail/../tests/mock_server/controllers/discuss/messaging_menu";
|
||||
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
// Mirrors `ai_agentic/controllers/messaging_menu.py` (AIAgenticMessagingMenuController):
|
||||
// registers the Automation tab on top of the AI chat one.
|
||||
|
||||
patch(messagingMenuHelpers, {
|
||||
_get_menu_tab_domain(env, tab_id) {
|
||||
if (tab_id.startsWith("ai-automation:")) {
|
||||
// the mock discuss.channel has no `from_ai_automation` field:
|
||||
// the base ai_chat domain is close enough for the counters
|
||||
const agentId = Number(tab_id.split(":")[1]);
|
||||
return [
|
||||
["channel_type", "=", "ai_chat"],
|
||||
["ai_agent_id", "=", agentId],
|
||||
];
|
||||
}
|
||||
return super._get_menu_tab_domain(env, tab_id);
|
||||
},
|
||||
_get_menu_tab_filter_domain(env, tab_id, filter_id) {
|
||||
if (tab_id.startsWith("ai-automation:") && filter_id === "ai_automation_unread") {
|
||||
return [["self_member_id.is_unread", "=", true]];
|
||||
}
|
||||
return super._get_menu_tab_filter_domain(env, tab_id, filter_id);
|
||||
},
|
||||
});
|
||||
33
ai_agentic/static/tests/mock_server/mock_models/ai_agent.js
Normal file
33
ai_agentic/static/tests/mock_server/mock_models/ai_agent.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import { AIAgent } from "@ai/../tests/mock_server/mock_models/ai_agent";
|
||||
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
|
||||
// Mirrors `ai_agentic/models/ai_agent.py` `open_agent_chat`.
|
||||
|
||||
patch(AIAgent.prototype, {
|
||||
open_agent_chat(idOrIds) {
|
||||
const agent = this.browse(idOrIds)[0];
|
||||
const session = this.env["ai.session"]
|
||||
._filter([
|
||||
["agent_id", "=", agent.id],
|
||||
["ai_composer_id", "=", false],
|
||||
])
|
||||
.find((session) => {
|
||||
const channel = this.env["discuss.channel"].browse(session.channel_id)[0];
|
||||
return channel.channel_type === "ai_chat" && !channel.message_ids?.length;
|
||||
});
|
||||
let channelId = session?.channel_id;
|
||||
if (!channelId) {
|
||||
channelId = this.browse(agent.id)._create_ai_chat_channel();
|
||||
this.env["ai.session"].create({ agent_id: agent.id, channel_id: channelId });
|
||||
}
|
||||
return {
|
||||
type: "ir.actions.client",
|
||||
tag: "mail.action_discuss",
|
||||
context: {
|
||||
active_id: `discuss.channel_${channelId}`,
|
||||
scoped_ai_agent_id: agent.id,
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user