Skip to content

Commit

Permalink
Revert "Revert "[Agent Configurations] Allow fetching multiple agent …
Browse files Browse the repository at this point in the history
…configur…"

This reverts commit 63ab116.
  • Loading branch information
philipperolet committed Sep 20, 2024
1 parent 63ab116 commit a60b57c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
22 changes: 7 additions & 15 deletions front/lib/api/assistant/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export async function getAgentConfiguration(
): Promise<AgentConfigurationType | null> {
const res = await getAgentConfigurations({
auth,
agentsGetView: { agentId },
agentsGetView: { agentIds: [agentId] },
variant: "full",
});
return res[0] || null;
Expand Down Expand Up @@ -159,7 +159,7 @@ export async function getLightAgentConfiguration(
): Promise<LightAgentConfigurationType | null> {
const res = await getAgentConfigurations({
auth,
agentsGetView: { agentId },
agentsGetView: { agentIds: [agentId] },
variant: "light",
});
return res[0] || null;
Expand Down Expand Up @@ -189,13 +189,8 @@ function determineGlobalAgentIdsToFetch(
// All global agents in conversation view.
return undefined;
}
if (typeof agentsGetView === "object" && "agentId" in agentsGetView) {
if (isGlobalAgentId(agentsGetView.agentId)) {
// In agentId view, only get the global agent with the provided id if it is a global agent.
return [agentsGetView.agentId];
}
// In agentId view, don't get any global agents if it is not a global agent.
return [];
if (typeof agentsGetView === "object" && "agentIds" in agentsGetView) {
return agentsGetView.agentIds.filter(isGlobalAgentId);
}
assertNever(agentsGetView);
}
Expand All @@ -220,7 +215,7 @@ async function fetchGlobalAgentConfigurationForView(

if (
agentsGetView === "global" ||
(typeof agentsGetView === "object" && "agentId" in agentsGetView)
(typeof agentsGetView === "object" && "agentIds" in agentsGetView)
) {
// All global agents in global and agent views.
return matchingGlobalAgents;
Expand Down Expand Up @@ -331,15 +326,12 @@ async function fetchAgentConfigurationsForView(
});

default:
if (typeof agentsGetView === "object" && "agentId" in agentsGetView) {
if (isGlobalAgentId(agentsGetView.agentId)) {
return Promise.resolve([]);
}
if (typeof agentsGetView === "object" && "agentIds" in agentsGetView) {
return AgentConfiguration.findAll({
where: {
workspaceId: owner.id,
...(agentPrefix ? { name: { [Op.iLike]: `${agentPrefix}%` } } : {}),
sId: agentsGetView.agentId,
sId: agentsGetView.agentIds.filter(isGlobalAgentId),
},
order: [["version", "DESC"]],
...(agentsGetView.allVersions ? {} : { limit: 1 }),
Expand Down
16 changes: 6 additions & 10 deletions front/lib/api/assistant/participants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import type {
AgentParticipantType,
ConversationParticipantsType,
ConversationWithoutContentType,
LightAgentConfigurationType,
ModelId,
Result,
UserParticipantType,
} from "@dust-tt/types";
import { Err, formatUserFullName, Ok } from "@dust-tt/types";
import { Op } from "sequelize";

import { getAgentConfiguration } from "@app/lib/api/assistant/configuration";
import { getAgentConfigurations } from "@app/lib/api/assistant/configuration";
import type { Authenticator } from "@app/lib/auth";
import {
AgentMessage,
Expand Down Expand Up @@ -44,14 +43,11 @@ async function fetchAllAgentsById(
auth: Authenticator,
agentConfigurationIds: string[]
): Promise<AgentParticipantType[]> {
// TODO(2024-3-25 flav) Support fetching many agents by id.
const agents = (
await Promise.all(
agentConfigurationIds.map((agentConfigId) => {
return getAgentConfiguration(auth, agentConfigId);
})
)
).filter((a) => a !== null) as LightAgentConfigurationType[];
const agents = await getAgentConfigurations({
auth,
agentsGetView: { agentIds: agentConfigurationIds },
variant: "light",
});

return agents.map((a) => ({
configurationId: a.sId,
Expand Down
2 changes: 1 addition & 1 deletion front/pages/poke/[wId]/assistants/[aId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getServerSideProps = withSuperUserAuthRequirements<{

const agentConfigurations = await getAgentConfigurations({
auth,
agentsGetView: { agentId: aId, allVersions: true },
agentsGetView: { agentIds: [aId], allVersions: true },
variant: "full",
});

Expand Down
4 changes: 2 additions & 2 deletions types/src/front/assistant/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export type AgentUserListStatus = "in-list" | "not-in-list";
* private agents, agents from the workspace and global scope, plus any
* published agents they've added to their list (refer to
* AgentUserRelationTable).
* - {agentId: string}: Retrieves a single agent by its ID.
* - {agentIds: string}: Retrieves specific agents by their sIds.
* - {conversationId: string}: all agent from the user's list view, plus the
* agents mentioned in the conversation with the provided Id.
* - 'all': Combines workspace and published agents, excluding private agents.
Expand All @@ -120,7 +120,7 @@ export type AgentUserListStatus = "in-list" | "not-in-list";
* authorization.
*/
export type AgentsGetViewType =
| { agentId: string; allVersions?: boolean }
| { agentIds: string[]; allVersions?: boolean }
| "list"
| { conversationId: string }
| "all"
Expand Down

0 comments on commit a60b57c

Please sign in to comment.