This commit is contained in:
2026-11-08 20:08:53 +08:00
parent 7526a5fe4d
commit 9b924747c5
2692 changed files with 394867 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
import { patch } from "@web/core/utils/patch";
import { _t } from "@web/core/l10n/translation";
import { useService } from "@web/core/utils/hooks";
import { SocialPostMessageField } from "@social/js/fields/social_post_message_field";
patch(SocialPostMessageField.prototype, {
setup() {
super.setup();
this.aiChatLauncher = useService("aiChatLauncher");
},
async onAiClick() {
const data = {
field_name: `You are writing on this field: ${this.props.name}`,
accounts: this.props.record.data.account_ids.records.map((r) => r.data.display_name),
post_size_limit: this.props.record.data.max_post_length_per_media,
current_post_content: this.props.record.data[this.props.name],
};
if (this.props.socialMediaType) {
data.media = `You are writing a post for ${this.props.socialMediaType} specifically`;
}
await this.aiChatLauncher.launchAIChat({
interfaceKey: "text_field_social",
context: { ai_social_post_values: data },
aiSpecialActions: {
insert: async (content) => {
// remove the web sources before inserting
const contentToInsert = content.cloneNode(true);
for (const link of contentToInsert.querySelectorAll("a")) {
link.remove();
}
let oldContent = this.props.record.data[this.props.name] || "";
if (oldContent.length) {
oldContent += " ";
}
await this.props.record.update({
[this.props.name]: oldContent + contentToInsert.textContent,
});
this.messageValue.set(oldContent + contentToInsert.textContent);
},
selectPreviousInsertion: (selectionId) => false,
},
channelTitle: _t("Social Post Editor"),
aiChatSourceId: this.props.record.id,
});
},
});

View File

@@ -0,0 +1,8 @@
.o_social_post_message_field {
[data-icon='o_ai_icon']::before {
filter: none !important;
}
a:has([data-icon='o_ai_icon']) {
pointer-events: initial;
}
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-inherit="social.SocialPostMessageField" t-inherit-mode="extension">
<xpath expr="//*[hasclass('o_field_input_buttons')]" position="inside">
<a href="#" class="p-2" data-hotkey="G" t-on-click="() => this.onAiClick()" title="Generate a Post with AI">
<span class="oi-fw o_ai_icon_color d-inline-block me-1" data-icon="o_ai_icon"/>
</a>
</xpath>
</t>
</templates>