feat: AI description - Backend for adding translation objects to EventType model (#17657)
* feat: AI description - DB model + frontend + backend (fetch only) * fix types and add validation to backend * improve log * improve * import type * add EventTypeTranslationRepository * fix replexica error * fix replexica error * fix * fix test * wip * wip * add createManyDescriptionTranslations method * improve logic * refactor * update replexica type * improve typing * Renamed descriptionTranslations to fieldTranslations * log errors in replexica service * handle translations in background * don't create, upsert instead * make sure that description is updated * simplify * fix * Update packages/trpc/server/routers/viewer/eventTypes/update.handler.ts * improve filter logic in frontend * implement background job using Tasker * update schema * update schema again * rename * rename id to uid * add migration * fix type * update * update schema and migration sql * fix migration * fix type check * fix type check 2 * improve find logic in EventMeta * add more validation * add logger * rename * upgrade replexica/sdk to 0.7.0 * upgrade replexica to 0.7.0 * use batchLocalizeText * add comments * override browser locale if user is a signed in calcom user * fix type in replexica * fix migration sql * fix type * use dynamic import * do not use batchLocalizeText * fix * add more validations * fix type error * address comment * update locales * update locales --------- Co-authored-by: Keith Williams <[email protected]>
This commit is contained in:
1 parent
93489709a8
commit
62976a4c77
14 files changed
+290
-22
No files matched your search
@@ -7,13 +7,14 @@ import {
|
||||
allowDisablingAttendeeConfirmationEmails,
|
||||
allowDisablingHostConfirmationEmails,
|
||||
} from "@calcom/features/ee/workflows/lib/allowDisablingStandardEmails";
|
||||
import tasker from "@calcom/features/tasker";
|
||||
import { validateIntervalLimitOrder } from "@calcom/lib";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { getTranslation } from "@calcom/lib/server";
|
||||
import { validateBookerLayouts } from "@calcom/lib/validateBookerLayouts";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { WorkflowTriggerEvents } from "@calcom/prisma/client";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import { SchedulingType, EventTypeAutoTranslatedField } from "@calcom/prisma/enums";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
@@ -36,6 +37,7 @@ type User = {
|
||||
};
|
||||
selectedCalendars: SessionUser["selectedCalendars"];
|
||||
organizationId: number | null;
|
||||
locale: string;
|
||||
};
|
||||
|
||||
type UpdateOptions = {
|
||||
@@ -76,6 +78,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
|
||||
aiPhoneCallConfig,
|
||||
isRRWeightsEnabled,
|
||||
autoTranslateDescriptionEnabled,
|
||||
description: newDescription,
|
||||
...rest
|
||||
} = input;
|
||||
|
||||
@@ -83,6 +86,12 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
|
||||
where: { id },
|
||||
select: {
|
||||
title: true,
|
||||
description: true,
|
||||
fieldTranslations: {
|
||||
select: {
|
||||
field: true,
|
||||
},
|
||||
},
|
||||
isRRWeightsEnabled: true,
|
||||
hosts: {
|
||||
select: {
|
||||
@@ -153,10 +162,17 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
|
||||
ensureUniqueBookingFields(bookingFields);
|
||||
ensureEmailOrPhoneNumberIsPresent(bookingFields);
|
||||
|
||||
if (autoTranslateDescriptionEnabled && !ctx.user.organizationId) {
|
||||
logger.error(
|
||||
"Auto-translating description requires an organization. This should not happen - UI controls should prevent this state."
|
||||
);
|
||||
}
|
||||
|
||||
const data: Prisma.EventTypeUpdateInput = {
|
||||
...rest,
|
||||
// autoTranslate feature is allowed for org users only
|
||||
autoTranslateDescriptionEnabled: !!(ctx.user.organizationId && autoTranslateDescriptionEnabled),
|
||||
description: newDescription,
|
||||
bookingFields,
|
||||
isRRWeightsEnabled,
|
||||
rrSegmentQueryValue:
|
||||
@@ -480,6 +496,27 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
|
||||
}
|
||||
}
|
||||
|
||||
// Logic for updating `fieldTranslations`
|
||||
// user has no description translations OR user is changing the description
|
||||
const descriptionTranslationsNeeded =
|
||||
eventType.fieldTranslations.filter((trans) => trans.field === EventTypeAutoTranslatedField.DESCRIPTION)
|
||||
.length === 0 || newDescription;
|
||||
const description = newDescription ?? eventType.description;
|
||||
|
||||
if (
|
||||
ctx.user.organizationId &&
|
||||
autoTranslateDescriptionEnabled &&
|
||||
descriptionTranslationsNeeded &&
|
||||
description
|
||||
) {
|
||||
await tasker.create("translateEventTypeDescription", {
|
||||
eventTypeId: id,
|
||||
description,
|
||||
userLocale: ctx.user.locale,
|
||||
userId: ctx.user.id,
|
||||
});
|
||||
}
|
||||
|
||||
const updatedEventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
|
||||
slug: true,
|
||||
schedulingType: true,
|
||||
|
||||
Reference in new issue
Block a user