Skip to content

Commit

Permalink
Added changes to models from the feedback loop PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas committed Dec 16, 2024
1 parent 9f31109 commit c0f2ac9
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion front/lib/models/assistant/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ export class AgentMessage extends BaseModel<AgentMessage> {
declare agentConfigurationVersion: number;

declare agentMessageContents?: NonAttribute<AgentMessageContent[]>;

// Handle to models linked to this agent message
declare message?: NonAttribute<Message>;
declare feedbacks?: NonAttribute<AgentMessageFeedback[]>;
}

AgentMessage.init(
Expand Down Expand Up @@ -303,6 +307,13 @@ export class AgentMessageFeedback extends BaseModel<AgentMessageFeedback> {

declare thumbDirection: AgentMessageFeedbackDirection;
declare content: string | null;

declare agentMessage: NonAttribute<AgentMessage>;
declare user: NonAttribute<UserModel>;

// Make it easier to get the conversationId and messageId
declare conversationId: NonAttribute<Conversation["sId"] | undefined>;
declare messageId: NonAttribute<Message["sId"] | undefined>;
}

AgentMessageFeedback.init(
Expand Down Expand Up @@ -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<Message> {
declare createdAt: CreationOptional<Date>;
Expand All @@ -388,6 +405,9 @@ export class Message extends BaseModel<Message> {
declare agentMessage?: NonAttribute<AgentMessage>;
declare contentFragment?: NonAttribute<ContentFragmentModel>;
declare reactions?: NonAttribute<MessageReaction[]>;

// Handle to conversation linked to this message
declare conversation?: NonAttribute<Conversation>;
}

Message.init(
Expand Down Expand Up @@ -486,7 +506,7 @@ Message.belongsTo(UserMessage, {
});

AgentMessage.hasOne(Message, {
as: "agentMessage",
as: "message",
foreignKey: { name: "agentMessageId", allowNull: true },
});
Message.belongsTo(AgentMessage, {
Expand Down

0 comments on commit c0f2ac9

Please sign in to comment.