初始提交
This commit is contained in:
81
ai/static/tests/mock_server/mock_models/ai_agent.js
Normal file
81
ai/static/tests/mock_server/mock_models/ai_agent.js
Normal file
@@ -0,0 +1,81 @@
|
||||
import { Store } from "@mail/../tests/mock_server/store";
|
||||
|
||||
import { Command, fields, models } from "@web/../tests/web_test_helpers";
|
||||
|
||||
export class AIAgent extends models.ServerModel {
|
||||
_name = "ai.agent";
|
||||
|
||||
name = fields.Char();
|
||||
allowed_agent_ids = fields.Many2many({ relation: "ai.agent" });
|
||||
partner_id = fields.Many2one({
|
||||
relation: "res.partner",
|
||||
});
|
||||
subtitle = fields.Char();
|
||||
image_128 = fields.Binary();
|
||||
system_prompt = fields.Text();
|
||||
sources_ids = fields.One2many({
|
||||
relation: "ai.agent.source",
|
||||
relation_field: "ai_agent_id",
|
||||
});
|
||||
|
||||
_store_agent_fields(res) {
|
||||
res.extend(["partner_id", "subtitle", "name"]);
|
||||
// Python derives xml_id from ir.model.data; test agents are created without one, so it
|
||||
// resolves to false (ir.model.data is not mocked).
|
||||
res.attr("xml_id", false);
|
||||
res.attr("sources_ids");
|
||||
}
|
||||
|
||||
action_launch_ai_chat(interface_key, res_model = null, res_id = null) {
|
||||
const agentPartnerId = this.env["res.partner"].create({ name: "Test AI Agent" });
|
||||
const agent = this.env["ai.agent"].browse(
|
||||
this.env["ai.agent"].create({ name: "Test AI Agent", partner_id: agentPartnerId }),
|
||||
);
|
||||
const channel = this.env["discuss.channel"].browse(agent._create_ai_chat_channel());
|
||||
const composer = this.env["ai.composer"].browse(
|
||||
this.env["ai.composer"].create({ interface_key }),
|
||||
);
|
||||
this.env["ai.session"].create({
|
||||
agent_id: agent[0].id,
|
||||
ai_composer_id: composer[0].id,
|
||||
channel_id: channel[0].id,
|
||||
res_model: res_model || false,
|
||||
res_id: res_id || false,
|
||||
});
|
||||
const store = new Store();
|
||||
store.add(channel, (res) => {
|
||||
res.attr("are_prompts_from_local_storage", false);
|
||||
res.from_method("_store_channel_fields");
|
||||
});
|
||||
return {
|
||||
ai_channel_id: channel[0].id,
|
||||
data: store.as_dict(),
|
||||
model_has_thread: null,
|
||||
};
|
||||
}
|
||||
|
||||
/** @param {import("@mail/../tests/mock_server/mock_models/res_partner").ResPartner} partner */
|
||||
_create_ai_chat_channel() {
|
||||
const agent = this[0];
|
||||
return this.env["discuss.channel"].create({
|
||||
name: agent.name,
|
||||
channel_type: "ai_chat",
|
||||
channel_member_ids: [
|
||||
Command.create({
|
||||
partner_id: this.env.user.partner_id,
|
||||
}),
|
||||
Command.create({
|
||||
partner_id: agent.partner_id,
|
||||
}),
|
||||
],
|
||||
ai_agent_id: agent.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class AIAgentSource extends models.ServerModel {
|
||||
_name = "ai.agent.source";
|
||||
|
||||
ai_agent_id = fields.Many2one({ relation: "ai.agent" });
|
||||
name = fields.Char();
|
||||
}
|
||||
14
ai/static/tests/mock_server/mock_models/ai_composer.js
Normal file
14
ai/static/tests/mock_server/mock_models/ai_composer.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { fields, models } from "@web/../tests/web_test_helpers";
|
||||
|
||||
export class AIComposer extends models.ServerModel {
|
||||
_name = "ai.composer";
|
||||
|
||||
ai_agent_id = fields.Many2one({ relation: "ai.agent" });
|
||||
interface_key = fields.Selection({
|
||||
selection: [["test_interface_key", "Test Interface Key"]],
|
||||
});
|
||||
|
||||
_store_composer_fields(res) {
|
||||
res.attr("interface_key");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { models } from "@web/../tests/web_test_helpers";
|
||||
|
||||
export class AIPromptButton extends models.ServerModel {
|
||||
_name = "ai.prompt.button";
|
||||
}
|
||||
39
ai/static/tests/mock_server/mock_models/ai_session.js
Normal file
39
ai/static/tests/mock_server/mock_models/ai_session.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { fields, models } from "@web/../tests/web_test_helpers";
|
||||
|
||||
export class AISession extends models.ServerModel {
|
||||
_name = "ai.session";
|
||||
|
||||
agent_id = fields.Many2one({ relation: "ai.agent" });
|
||||
parent_session_id = fields.Many2one({ relation: "ai.session" });
|
||||
ai_composer_id = fields.Many2one({ relation: "ai.composer" });
|
||||
channel_id = fields.Many2one({ relation: "discuss.channel" });
|
||||
res_id = fields.Generic();
|
||||
res_model = fields.Generic();
|
||||
user_input_request = fields.Generic();
|
||||
external_pending_tool = fields.Generic();
|
||||
loop_state = fields.Generic({ default: "ready" });
|
||||
resume_token = fields.Generic();
|
||||
|
||||
_store_session_fields(res) {
|
||||
res.one("agent_id", "_store_agent_fields");
|
||||
res.one("parent_session_id", []);
|
||||
res.attr("res_model");
|
||||
res.attr("res_id");
|
||||
res.one("ai_composer_id", "_store_composer_fields");
|
||||
res.attr("config", {
|
||||
enable_think_longer: false,
|
||||
enable_web_search: false,
|
||||
enable_resources_only: false,
|
||||
auto_confirm: false,
|
||||
show_agent_steps: false,
|
||||
});
|
||||
res.attr("config_rules", {
|
||||
enable_web_search: { enable_resources_only: false },
|
||||
enable_resources_only: { enable_web_search: false },
|
||||
});
|
||||
res.attr("userInputRequest", (session) => session.user_input_request || false);
|
||||
res.attr("external_pending_tool", (session) => Boolean(session.external_pending_tool));
|
||||
res.attr("loop_state");
|
||||
res.attr("resume_token");
|
||||
}
|
||||
}
|
||||
34
ai/static/tests/mock_server/mock_models/discuss_channel.js
Normal file
34
ai/static/tests/mock_server/mock_models/discuss_channel.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { mailModels } from "@mail/../tests/mail_test_helpers";
|
||||
import { fields } from "@web/../tests/web_test_helpers";
|
||||
|
||||
export class DiscussChannel extends mailModels.DiscussChannel {
|
||||
ai_agent_id = fields.Many2one({ relation: "ai.agent" });
|
||||
ai_session_ids = fields.One2many({ relation: "ai.session", relation_field: "channel_id" });
|
||||
|
||||
_store_channel_fields(res) {
|
||||
super._store_channel_fields(res);
|
||||
this._store_ai_fields(res);
|
||||
}
|
||||
|
||||
_store_ai_fields(res) {
|
||||
const isAiAgentChannel = (c) => this._ai_agent_channel_types().includes(c.channel_type);
|
||||
res.one("ai_agent_id", "_store_agent_fields", { predicate: isAiAgentChannel, sudo: true });
|
||||
res.many("ai_session_ids", "_store_session_fields", {
|
||||
predicate: isAiAgentChannel,
|
||||
sudo: true,
|
||||
});
|
||||
res.one("suggestedAiChannel", [], {
|
||||
predicate: (channel) =>
|
||||
channel.channel_type === "ai_chat" && !channel.message_ids?.length,
|
||||
value: (channel) => this.browse(channel.id)._get_suggested_ai_channel(),
|
||||
});
|
||||
}
|
||||
|
||||
_get_suggested_ai_channel() {
|
||||
return this.env["discuss.channel"].browse();
|
||||
}
|
||||
|
||||
_ai_agent_channel_types() {
|
||||
return ["ai_chat"];
|
||||
}
|
||||
}
|
||||
24
ai/static/tests/mock_server/mock_models/res_partner.js
Normal file
24
ai/static/tests/mock_server/mock_models/res_partner.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import { fields, models } from "@web/../tests/web_test_helpers";
|
||||
|
||||
export class Partner extends models.Model {
|
||||
name = fields.Char();
|
||||
foo = fields.Char();
|
||||
|
||||
_records = [{ id: 1, name: "dummy record", foo: "yop" }];
|
||||
_views = {
|
||||
kanban: `
|
||||
<kanban>
|
||||
<templates>
|
||||
<t t-name="card">
|
||||
<field name="foo"/>
|
||||
</t>
|
||||
</templates>
|
||||
</kanban>
|
||||
`,
|
||||
list: `
|
||||
<list>
|
||||
<field name="foo"/>
|
||||
</list>
|
||||
`,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user