Skip to content

Commit

Permalink
Reverting naming change, added default ids to agent configuration for…
Browse files Browse the repository at this point in the history
… global agent
  • Loading branch information
overmode committed Dec 30, 2024
1 parent d3b6547 commit d1ec676
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
10 changes: 6 additions & 4 deletions front/lib/models/assistant/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ export class AgentMessage extends BaseModel<AgentMessage> {
declare agentConfigurationVersion: number;

declare agentMessageContents?: NonAttribute<AgentMessageContent[]>;

declare message?: NonAttribute<Message>;
// This points to the message associated with the agent message
declare agentMessage?: NonAttribute<Message>;
declare feedbacks?: NonAttribute<AgentMessageFeedback[]>;
}

Expand Down Expand Up @@ -379,7 +379,9 @@ AgentMessage.hasMany(AgentMessageFeedback, {
UserModel.hasMany(AgentMessageFeedback, {
onDelete: "SET NULL",
});
AgentMessageFeedback.belongsTo(UserModel);
AgentMessageFeedback.belongsTo(UserModel, {
as: "user",
});
AgentMessageFeedback.belongsTo(AgentMessage, {
as: "agentMessage",
});
Expand Down Expand Up @@ -505,7 +507,7 @@ Message.belongsTo(UserMessage, {
});

AgentMessage.hasOne(Message, {
as: "message",
as: "agentMessage",
foreignKey: { name: "agentMessageId", allowNull: true },
});
Message.belongsTo(AgentMessage, {
Expand Down
38 changes: 18 additions & 20 deletions front/lib/resources/agent_message_feedback_resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class AgentMessageFeedbackResource extends BaseResource<AgentMessageFeedb
include: [
{
model: Message,
as: "message",
as: "agentMessage",
attributes: ["id", "sId"],
include: [
{
Expand Down Expand Up @@ -177,13 +177,15 @@ export class AgentMessageFeedbackResource extends BaseResource<AgentMessageFeedb
(
feedback
): feedback is AgentMessageFeedback & {
agentMessage: { message: Message & { conversation: Conversation } };
} => !!feedback.agentMessage?.message?.conversation
agentMessage: {
agentMessage: Message & { conversation: Conversation };
};
} => !!feedback.agentMessage?.agentMessage?.conversation
)
.map((feedback) => {
return {
id: feedback.id,
messageId: feedback.agentMessage.message.sId,
messageId: feedback.agentMessage.agentMessage.sId,
agentMessageId: feedback.agentMessageId,
userId: feedback.userId,
thumbDirection: feedback.thumbDirection,
Expand All @@ -198,7 +200,7 @@ export class AgentMessageFeedbackResource extends BaseResource<AgentMessageFeedb
...(withMetadata && {
// This field is sensitive, it allows accessing the conversation
conversationId: feedback.isConversationShared
? feedback.agentMessage.message.conversation.sId
? feedback.agentMessage.agentMessage.conversation.sId
: null,
userName: feedback.user.name,
userEmail: feedback.user.email,
Expand Down Expand Up @@ -290,20 +292,12 @@ export class AgentMessageFeedbackResource extends BaseResource<AgentMessageFeedb
agentConfigurationVersion: number;
};
feedback: AgentMessageFeedbackResource | null;
} & ( // Either the agent is not global and has a configuration
| {
agentConfiguration: Pick<
AgentConfigurationType,
"id" | "sId" | "version"
>;
isGlobalAgent: false;
}
// Or the agent is global and has no configuration
| {
agentConfiguration: null;
isGlobalAgent: true;
}
),
agentConfiguration: Pick<
AgentConfigurationType,
"id" | "sId" | "version"
>;
isGlobalAgent: boolean;
},
Error
>
> {
Expand Down Expand Up @@ -368,7 +362,11 @@ export class AgentMessageFeedbackResource extends BaseResource<AgentMessageFeedb
message.agentMessage.agentConfigurationVersion,
},
feedback: agentMessageFeedbackResource,
agentConfiguration: null,
agentConfiguration: {
id: -1,
sId: message.agentMessage.agentConfigurationId,
version: message.agentMessage.agentConfigurationVersion,
},
isGlobalAgent: true,
});
}
Expand Down

0 comments on commit d1ec676

Please sign in to comment.