Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rerevert: [Agent Configurations] Allow fetching multiple agent configurations by sIds #7578

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 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 All @@ -232,7 +227,7 @@ async function fetchGlobalAgentConfigurationForView(

// Workspace agent configurations.

async function fetchAgentConfigurationsForView(
async function fetchWorkspaceAgentConfigurationsWithoutActions(
auth: Authenticator,
{
agentPrefix,
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((id) => !isGlobalAgentId(id)),
Copy link
Contributor Author

@philipperolet philipperolet Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the forgotten ! was here. rest of the PR is the same apart from renaming a function

},
order: [["version", "DESC"]],
...(agentsGetView.allVersions ? {} : { limit: 1 }),
Expand Down Expand Up @@ -407,13 +399,14 @@ async function fetchWorkspaceAgentConfigurationsForView(
) {
const user = auth.user();

const agentConfigurations = await fetchAgentConfigurationsForView(auth, {
agentPrefix,
agentsGetView,
limit,
owner,
sort,
});
const agentConfigurations =
await fetchWorkspaceAgentConfigurationsWithoutActions(auth, {
agentPrefix,
agentsGetView,
limit,
owner,
sort,
});

const configurationIds = agentConfigurations.map((a) => a.id);
const configurationSIds = agentConfigurations.map((a) => a.sId);
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
Loading