diff --git a/front/lib/models/assistant/conversation.ts b/front/lib/models/assistant/conversation.ts index cae554ffc2ba..972df3338039 100644 --- a/front/lib/models/assistant/conversation.ts +++ b/front/lib/models/assistant/conversation.ts @@ -244,6 +244,10 @@ export class AgentMessage extends BaseModel { declare agentConfigurationVersion: number; declare agentMessageContents?: NonAttribute; + + // Handle to models linked to this agent message + declare message?: NonAttribute; + declare feedbacks?: NonAttribute; } AgentMessage.init( @@ -303,6 +307,13 @@ export class AgentMessageFeedback extends BaseModel { declare thumbDirection: AgentMessageFeedbackDirection; declare content: string | null; + + declare agentMessage: NonAttribute; + declare user: NonAttribute; + + // Make it easier to get the conversationId and messageId + declare conversationId: NonAttribute; + declare messageId: NonAttribute; } AgentMessageFeedback.init( @@ -361,11 +372,17 @@ Workspace.hasMany(AgentMessageFeedback, { onDelete: "RESTRICT", }); AgentMessage.hasMany(AgentMessageFeedback, { + as: "feedbacks", onDelete: "RESTRICT", }); UserModel.hasMany(AgentMessageFeedback, { onDelete: "SET NULL", }); +AgentMessageFeedback.belongsTo(UserModel); +AgentMessageFeedback.belongsTo(AgentMessage, { + as: "agentMessage", + foreignKey: { name: "agentMessageId", allowNull: false }, +}); export class Message extends BaseModel { declare createdAt: CreationOptional; @@ -388,6 +405,9 @@ export class Message extends BaseModel { declare agentMessage?: NonAttribute; declare contentFragment?: NonAttribute; declare reactions?: NonAttribute; + + // Handle to conversation linked to this message + declare conversation?: NonAttribute; } Message.init( @@ -486,7 +506,7 @@ Message.belongsTo(UserMessage, { }); AgentMessage.hasOne(Message, { - as: "agentMessage", + as: "message", foreignKey: { name: "agentMessageId", allowNull: true }, }); Message.belongsTo(AgentMessage, {