ai*
This commit is contained in:
38
ai_timesheet_grid/static/src/timesheets_assistant.js
Normal file
38
ai_timesheet_grid/static/src/timesheets_assistant.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { rpc } from "@web/core/network/rpc";
|
||||
import { useDebounced } from "@web/core/utils/timing";
|
||||
import { TimesheetsAssistant } from "@timesheet_grid/components/aw_timesheet/aw_timesheet";
|
||||
|
||||
patch(TimesheetsAssistant.prototype, {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.debouncedUpdateDescription = useDebounced(
|
||||
this._updateDescriptionWithAI.bind(this),
|
||||
800
|
||||
);
|
||||
},
|
||||
|
||||
async _updateDescriptionWithAI(name) {
|
||||
let description = name;
|
||||
try {
|
||||
const summary = await rpc("/ai/get_direct_response", {
|
||||
interface_key: "timesheet_assistant_ai",
|
||||
prompt:
|
||||
"Summarize the following timesheet activities into one short description. " +
|
||||
"Return only the summary.\n\n" +
|
||||
name,
|
||||
});
|
||||
description = summary?.trim() || name;
|
||||
this.currentRecord.update({ name: description });
|
||||
} catch {}
|
||||
},
|
||||
|
||||
/** @override */
|
||||
async updateRecordInForm() {
|
||||
await super.updateRecordInForm();
|
||||
if (!this.model.isAgentAvailable || this.state.selectedRows.size < 2 || !this.currentRecord) {
|
||||
return;
|
||||
}
|
||||
this.debouncedUpdateDescription(this.selectedData.name);
|
||||
},
|
||||
});
|
||||
11
ai_timesheet_grid/static/src/timesheets_assistant_model.js
Normal file
11
ai_timesheet_grid/static/src/timesheets_assistant_model.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { TimesheetAssistantModel } from "@timesheet_grid/components/aw_timesheet/aw_timesheet_model";
|
||||
|
||||
patch(TimesheetAssistantModel.prototype, {
|
||||
/** @override */
|
||||
async loadAssistantData() {
|
||||
const data = await super.loadAssistantData();
|
||||
this.isAgentAvailable = data.is_agent_available;
|
||||
return data;
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user