push
This commit is contained in:
68
dn_ai/static/src/assistant.js
Normal file
68
dn_ai/static/src/assistant.js
Normal file
@@ -0,0 +1,68 @@
|
||||
/** @odoo-module **/
|
||||
import { Component, proxy } from "@odoo/owl";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { user } from "@web/core/user";
|
||||
|
||||
/**
|
||||
* Bottom-right entry point for the AI assistant.
|
||||
*
|
||||
* The button no longer owns a chat UI: it opens the conversation in the native
|
||||
* `mail.ChatWindow` (see `ai_chat_launcher.js`), which is what the Enterprise
|
||||
* assistant does as well. Everything the previous floating panel had to
|
||||
* reimplement — message rendering, markdown tables, attachment previews, the
|
||||
* composer, folding, position memory — now comes from `mail` itself.
|
||||
*
|
||||
* It stays a fixed action button rather than a systray item: a systray entry
|
||||
* lives inside the navbar and collapses into the burger menu on small screens,
|
||||
* where the icon then "disappears".
|
||||
*/
|
||||
export class DnAiAssistant extends Component {
|
||||
static template = "dn_ai.Assistant";
|
||||
|
||||
setup() {
|
||||
this.store = useService("mail.store");
|
||||
this.launcher = useService("dn_ai.chat_launcher");
|
||||
this.state = proxy({ busy: false });
|
||||
}
|
||||
|
||||
get title() {
|
||||
return _t("Ask AI");
|
||||
}
|
||||
|
||||
get isAvailable() {
|
||||
return user.isRegularUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Step aside while the chat hub owns this corner.
|
||||
*
|
||||
* Native chat windows and their folded bubbles are anchored bottom-right,
|
||||
* exactly where this button lives. Hiding the button while one is on
|
||||
* screen avoids covering the composer; it comes back as soon as the user
|
||||
* closes the conversation.
|
||||
*/
|
||||
get isHidden() {
|
||||
const hub = this.store.chatHub;
|
||||
return hub.opened.length + hub.folded.length > 0;
|
||||
}
|
||||
|
||||
async onClick() {
|
||||
if (this.state.busy) {
|
||||
return;
|
||||
}
|
||||
this.state.busy = true;
|
||||
try {
|
||||
await this.launcher.openDefault();
|
||||
} catch (error) {
|
||||
this.launcher.reportError(error);
|
||||
} finally {
|
||||
this.state.busy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registry.category("main_components").add("dn_ai.assistant", {
|
||||
Component: DnAiAssistant,
|
||||
});
|
||||
Reference in New Issue
Block a user