初始提交

This commit is contained in:
2026-11-04 19:58:07 +08:00
commit 53b7d22429
829 changed files with 469986 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
import { patch } from "@web/core/utils/patch";
import { FormController } from "@web/views/form/form_controller";
import { useService } from "@web/core/utils/hooks";
import { onWillDestroy, onMounted, useListener } from "@odoo/owl";
import { aiChannelBus } from "@ai/utils/ai_channel_bus";
patch(FormController.prototype, {
setup() {
super.setup();
this.aiChatLauncher = useService("aiChatLauncher");
const openAiChat = (ev) => this.openAiChat(ev.detail.origin);
useListener(this.env.bus, "AI:OPEN_AI_CHAT", openAiChat);
onMounted(() =>
aiChannelBus.trigger("AI: Update Target Record", {
recordModel: this.model.root.resModel,
recordId: this.model.root.resId,
targetRecord: this.model.root,
})
);
onWillDestroy(() =>
aiChannelBus.trigger("AI: Update Target Record", {
targetRecord: undefined,
})
);
},
async openAiChat(interfaceKey) {
// save to allow to get messages from backend
if (!this.mailStore || !(await this.model.root.save())) {
return;
}
const channel = await this.aiChatLauncher.launchAIChat({
interfaceKey,
channelTitle: this.displayName(),
recordModel: this.model.root.resModel,
recordId: this.model.root.resId,
originalRecordData: this.model.root.data,
originalRecordFields: this.model.root.fields,
aiChatSourceId: this.model.root.resId,
aiSpecialActions: this.aiSpecialActions,
});
channel.targetRecord = this.model.root;
},
get aiSpecialActions() {
return {};
},
async onPagerUpdate({ offset, resIds }) {
const result = await super.onPagerUpdate({ offset, resIds });
aiChannelBus.trigger("AI: Update Target Record", {
recordModel: this.model.root.resModel,
recordId: this.model.root.resId,
targetRecord: this.model.root,
});
return result;
},
});

View File

@@ -0,0 +1,35 @@
import { Component } from "@odoo/owl";
import { registry } from "@web/core/registry";
import { user } from "@web/core/user";
import { useService } from "@web/core/utils/hooks";
export default class SystrayAction extends Component {
static template = "ai.SystrayAction";
setup() {
super.setup();
this.actionService = useService("action");
this.aiChatLauncher = useService("aiChatLauncher");
}
async onClickLaunchAIChat() {
const currentController = this.actionService.currentController;
if (currentController?.view?.type === "form") {
this.env.bus.trigger("AI:OPEN_AI_CHAT", { origin: "chatter_ai_button" });
return;
}
this.aiChatLauncher.launchAIChat({
interfaceKey: "systray_ai_button",
});
}
}
registry.category("systray").add(
"ai.systray_action",
{
Component: SystrayAction,
// A light user has no AI chat: it is not meant to drive the database.
isDisplayed: () => user.isRegularUser,
},
{ sequence: 30 }
);

View File

@@ -0,0 +1,4 @@
.ai-systray-icon {
height: 18px;
}

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="ai.SystrayAction">
<button class="o_nav_entry"
t-on-click="this.onClickLaunchAIChat" title="Ask AI" data-hotkey="a">
<img class="ai-systray-icon" src="/ai/static/description/icon.png" alt="AI" />
</button>
</t>
</templates>