Skip to content

Commit

Permalink
[Assistant views] Remove 'assistant-search' & '{conversationId}' views (
Browse files Browse the repository at this point in the history
#8109)

* [Assistant views] Remove 'assistant-search' & '{conversationId}' views

Description
---
- Removes 'assistant-search' view, which was actually exactly the same
as "list". The comment indicating inactive global agents were returned
was erroneous

- Removes '{conversationId}' view, since:
 - it was actually only used in AssistantSuggestion, not anywhere else;
 - the view didn't actually work, it was ~equivalent to list;
 - the use case it was supposed to enable, viewing a shared
 conversation with somebody else's personal assistant, is already
somewhat working: user can view conversation but not mention assistant
or see its details which is kind of fine.

We could aim in a follow-up PR to reinstate the conversation view
cleanly; that would require more work and is IMO not a priority.

Risks
---
Low, since it's just a view change. Tested locally. Regarding conversationId:
- handled all explicit calls
- looked for agentsGetView with potential implicit `agentsGetView: { conversationId }`: there are
  - the internal api `asisstant/agent_configurations`, which is only called via swr's `useAgentConfigurations`
	 => checked it does not use conversationId (since it also takes agentsGetView as param)
  - the v1 api DustApi.getAgentsConfiguration call => here also, conversationId not used

Deploy
---
front

* clean last convid occurence

* fix linting
  • Loading branch information
philipperolet authored Oct 22, 2024
1 parent e564ee9 commit 84b3cae
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function AgentSuggestion({
}: AgentSuggestionProps) {
const { agentConfigurations } = useAgentConfigurations({
workspaceId: owner.sId,
agentsGetView: { conversationId: conversationId },
agentsGetView: "list",
includes: ["authors", "usage"],
});
const sendNotification = useContext(SendNotificationsContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function AssistantInputBar({
const { agentConfigurations: baseAgentConfigurations } =
useAgentConfigurations({
workspaceId: owner.sId,
agentsGetView: "assistants-search",
agentsGetView: "list",
});

// Files upload.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const useAssistantSuggestions = (
) => {
const { agentConfigurations } = useAgentConfigurations({
workspaceId: owner.sId,
agentsGetView: "assistants-search",
agentsGetView: "list",
});

// `useMemo` will ensure that suggestions is only recalculated
Expand Down
30 changes: 1 addition & 29 deletions front/lib/api/assistant/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,8 @@ function determineGlobalAgentIdsToFetch(
case "list":
case "all":
case "admin_internal":
case "assistants-search":
return undefined; // undefined means all global agents will be fetched
default:
if (
typeof agentsGetView === "object" &&
"conversationId" in agentsGetView
) {
// All global agents in conversation view.
return undefined;
}
if (typeof agentsGetView === "object" && "agentIds" in agentsGetView) {
return agentsGetView.agentIds.filter(isGlobalAgentId);
}
Expand Down Expand Up @@ -303,7 +295,6 @@ async function fetchWorkspaceAgentConfigurationsWithoutActions(
where: baseConditionsAndScopesIn(["published"]),
});

case "assistants-search":
case "list":
const user = auth.user();

Expand Down Expand Up @@ -339,22 +330,6 @@ async function fetchWorkspaceAgentConfigurationsWithoutActions(
order: [["version", "DESC"]],
...(agentsGetView.allVersions ? {} : { limit: 1 }),
});
} else if (
typeof agentsGetView === "object" &&
"conversationId" in agentsGetView
) {
const user = auth.user();

return AgentConfiguration.findAll({
...baseAgentsSequelizeQuery,
where: {
...baseWhereConditions,
[Op.or]: [
{ scope: { [Op.in]: ["workspace", "published"] } },
{ authorId: user?.id },
],
},
});
}
assertNever(agentsGetView);
}
Expand Down Expand Up @@ -547,10 +522,7 @@ export async function getAgentConfigurations<V extends "light" | "full">({
throw new Error("Archived view is for dust superusers only.");
}

if (
(agentsGetView === "list" || agentsGetView === "assistants-search") &&
!user
) {
if (agentsGetView === "list" && !user) {
throw new Error(
"`list` or `assistants-search` view is specific to a user."
);
Expand Down
8 changes: 2 additions & 6 deletions front/lib/swr/assistants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ export function useAgentConfigurations({
const params = new URLSearchParams();
if (typeof agentsGetView === "string") {
params.append("view", agentsGetView);
} else {
if (agentsGetView && "conversationId" in agentsGetView) {
params.append("conversationId", agentsGetView.conversationId);
}
}
if (includes.includes("usage")) {
params.append("withUsage", "true");
Expand Down Expand Up @@ -157,7 +153,7 @@ export function useProgressiveAgentConfigurations({
isAgentConfigurationsLoading: isInitialAgentConfigurationsLoading,
} = useAgentConfigurations({
workspaceId,
agentsGetView: "assistants-search",
agentsGetView: "list",
limit: 24,
includes: ["usage"],
disabled,
Expand All @@ -171,7 +167,7 @@ export function useProgressiveAgentConfigurations({
mutateRegardlessOfQueryParams,
} = useAgentConfigurations({
workspaceId,
agentsGetView: "assistants-search",
agentsGetView: "list",
includes: ["authors", "usage"],
disabled,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function handler(
case "GET": {
const agentConfigurations = await getAgentConfigurations({
auth,
agentsGetView: auth.user() ? "assistants-search" : "all",
agentsGetView: auth.user() ? "list" : "all",
variant: "light",
});
return res.status(200).json({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,9 @@ async function handler(
});
}

const { view, conversationId, limit, withUsage, withAuthors, sort } =
const { view, limit, withUsage, withAuthors, sort } =
queryValidation.right;
const viewParam = view
? view
: conversationId
? { conversationId }
: "all";
const viewParam = view ? view : "all";
if (viewParam === "admin_internal" && !auth.isDustSuperUser()) {
return apiError(req, res, {
status_code: 404,
Expand Down
2 changes: 1 addition & 1 deletion front/pages/w/[wId]/builder/assistants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function WorkspaceAssistants({
const { agentConfigurations: searchableAgentConfigurations } =
useAgentConfigurations({
workspaceId: owner.sId,
agentsGetView: assistantSearch ? "assistants-search" : null,
agentsGetView: assistantSearch ? "list" : null,
});

const filteredAgents = (
Expand Down
2 changes: 0 additions & 2 deletions types/src/front/api_handlers/internal/agent_configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ export const GetAgentConfigurationsQuerySchema = t.type({
t.literal("global"),
t.literal("admin_internal"),
t.literal("all"),
t.literal("assistants-search"),
t.undefined,
]),
conversationId: t.union([t.string, t.undefined]),
withUsage: t.union([t.literal("true"), t.literal("false"), t.undefined]),
withAuthors: t.union([t.literal("true"), t.literal("false"), t.undefined]),
limit: t.union([LimitCodec, t.undefined]),
Expand Down
7 changes: 0 additions & 7 deletions types/src/front/assistant/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,8 @@ export type AgentConfigurationScope =
* 'views':
* - 'list': Retrieves all active agents accessible to the user
* - {agentIds: string}: Retrieves specific agents by their sIds.
* - {conversationId: string}: like 'list', plus the agents mentioned in the
* conversation with the provided id. This can be useful to share
* conversations with personal agents
* - 'all': All non-private agents (so combines workspace, published and global
* agents); used e.g. for non-user calls such as API
* - 'assistants-search': retrieves all global agents including inactive ones,
* all workspace, all published and the user's private agents.
* - 'workspace': Retrieves all agents exclusively with a 'workspace' scope.
* - 'published': Retrieves all agents exclusively with a 'published' scope.
* - 'global': Retrieves all agents exclusively with a 'global' scope.
Expand All @@ -115,9 +110,7 @@ export type AgentConfigurationScope =
export type AgentsGetViewType =
| { agentIds: string[]; allVersions?: boolean }
| "list"
| { conversationId: string }
| "all"
| "assistants-search"
| "workspace"
| "published"
| "global"
Expand Down
11 changes: 9 additions & 2 deletions types/src/shared/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import { redisClient } from "../shared/redis_client";

// if caching big objects, there is a possible race condition (mulitple calls to
// caching), therefore, we use a lock
export function cacheWithRedis<T extends (...args: any[]) => Promise<any>>(

/* eslint-disable @typescript-eslint/no-explicit-any */
export function cacheWithRedis<
T extends (...args: any[]) => Promise<Awaited<ReturnType<T>>>
>(
fn: T,
resolver: (...args: Parameters<T>) => string,
ttlMs: number,
redisUri?: string,
lockCaching?: boolean
): (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>>> {
): (
...args: Parameters<T>
) => Promise<Awaited<ReturnType<T>>> | Promise<ReturnType<T>> {
if (ttlMs > 60 * 60 * 24 * 1000) {
throw new Error("ttlMs should be less than 24 hours");
}
Expand Down Expand Up @@ -70,6 +76,7 @@ export function cacheWithRedis<T extends (...args: any[]) => Promise<any>>(
}
};
}
/* eslint-enable @typescript-eslint/no-explicit-any */

const locks: Record<string, (() => void)[]> = {};

Expand Down

0 comments on commit 84b3cae

Please sign in to comment.