Skip to content

Commit

Permalink
[front] - fix(conversations): render conversations with archived agen…
Browse files Browse the repository at this point in the history
…ts (#8900)

* [front/lib/api/assistant] - fix: ensure only active or latest agent versions are fetched

 - Modify fetchWorkspaceAgentConfigurationsWithoutActions to return either active versions if they exist, or otherwise the latest versions
 - Implement reduction logic to group agents by sId and select the correct version to return based on status and existence in the accumulator

* [front/lib/api/assistant] - refactor: optimize fetching agent configurations

 - Implement a more efficient SQL query to directly fetch the necessary agent configurations
 - Remove the previous post-processing logic in favor of database-level aggregation and sorting

* [front/lib/api/assistant] - refactor: optimize agent configurations query

 - Include option to fetch all versions of agent configurations
 - Modify query to retrieve only latest versions of agent configurations using Sequelize ORM instead of raw query
  • Loading branch information
JulesBelveze authored and overmode committed Nov 27, 2024
1 parent 1e01080 commit a50fa25
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions front/lib/api/assistant/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,35 @@ async function fetchWorkspaceAgentConfigurationsWithoutActions(
});
default:
if (typeof agentsGetView === "object" && "agentIds" in agentsGetView) {
return AgentConfiguration.findAll({
if (agentsGetView.allVersions) {
return AgentConfiguration.findAll({
where: {
workspaceId: owner.id,
sId: agentsGetView.agentIds.filter((id) => !isGlobalAgentId(id)),
},
order: [["version", "DESC"]],
});
}
const latestVersions = (await AgentConfiguration.findAll({
attributes: [
"sId",
[Sequelize.fn("MAX", Sequelize.col("version")), "max_version"],
],
where: {
workspaceId: owner.id,
...(agentPrefix ? { name: { [Op.iLike]: `${agentPrefix}%` } } : {}),
sId: agentsGetView.agentIds.filter((id) => !isGlobalAgentId(id)),
...(agentsGetView.allVersions ? {} : { status: "active" }),
},
group: ["sId"],
raw: true,
})) as unknown as { sId: string; max_version: number }[];

return AgentConfiguration.findAll({
where: {
workspaceId: owner.id,
sId: latestVersions.map((v) => v.sId),
version: {
[Op.in]: latestVersions.map((v) => v.max_version),
},
},
order: [["version", "DESC"]],
});
Expand Down

0 comments on commit a50fa25

Please sign in to comment.