Skip to content

Commit

Permalink
0;276;0cfix: don't show global agent in WS view (#3291)
Browse files Browse the repository at this point in the history
Co-authored-by: Henry Fontanier <[email protected]>
  • Loading branch information
fontanierh and Henry Fontanier authored Jan 18, 2024
1 parent 0890603 commit 0cc78d8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
48 changes: 43 additions & 5 deletions front/lib/api/assistant/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ export async function getAgentConfigurations<V extends "light" | "full">({
}): Promise<
V extends "light" ? LightAgentConfigurationType[] : AgentConfigurationType[]
> {
// {agentId: string} view: get a specific agent configuration.
// list view: specific to a user. Get all agents that are in the user's list (either they created it and it is private, or via AgentUserRelation).
// {conversationId: string} view: specific to a conversation. Get all agents that are in the user's list + workspace/published agents in the current conversation.
// all view: workspace + published agents (not private ones), eg. for agent gallery
// workspace view: only workspace agents (not published ones)
// published view: only published agents (not workspace ones)
// global view: only global agents (not workspace or published ones)
// admin_internal view: all agents, including private ones => this is only for internal use (eg poke). Requires superuser or admin auth.

const owner = auth.workspace();
if (!owner || !auth.isUser()) {
throw new Error("Unexpected `auth` without `workspace`.");
Expand All @@ -105,12 +114,39 @@ export async function getAgentConfigurations<V extends "light" | "full">({
throw new Error("List view is specific to a user.");
}

const globalAgentsIds =
typeof agentsGetView === "object" && "agentId" in agentsGetView
? [agentsGetView.agentId].filter((id) => isGlobalAgentId(id))
: undefined;
const globalAgentIdsToFetch: string[] | undefined = (() => {
switch (agentsGetView) {
case "workspace":
// No global agents in workspace view.
return [];
case "global":
case "list":
case "all":
case "admin_internal":
case "published":
// All global agents in global, list, all, admin_internal, published views.
return undefined;
default:
if (
typeof agentsGetView === "object" &&
"conversationId" in agentsGetView
) {
// 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 [];
}
assertNever(agentsGetView);
}
})();

let globalAgentsPromise = getGlobalAgents(auth, globalAgentsIds).then(
let globalAgentsPromise = getGlobalAgents(auth, globalAgentIdsToFetch).then(
(globals) =>
globals.filter(
(a) =>
Expand All @@ -120,9 +156,11 @@ export async function getAgentConfigurations<V extends "light" | "full">({
);

if (agentsGetView === "global") {
// Only global agents in global view.`
return globalAgentsPromise;
}

// If not in global view, filter out global agents that are not active.
globalAgentsPromise = globalAgentsPromise.then((globals) =>
globals.filter((a) => a.status === "active")
);
Expand Down
4 changes: 4 additions & 0 deletions front/lib/api/assistant/global_agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,10 @@ export async function getGlobalAgents(
throw new Error("Invalid agentIds.");
}

if (agentIds !== undefined && agentIds.length === 0) {
return [];
}

const owner = auth.workspace();
if (!owner) {
throw new Error("Cannot find Global Agent Configuration: no workspace.");
Expand Down

0 comments on commit 0cc78d8

Please sign in to comment.