Skip to content

Commit

Permalink
Agent configurations: 1 query instead of 3 at new conversation page l…
Browse files Browse the repository at this point in the history
…oading (#9425)

* Agent configurations: 1 query instead of 3 at new conversation page loading

* lint
  • Loading branch information
spolu authored Dec 16, 2024
1 parent 143e777 commit 20fc569
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ export function AssistantBrowserContainer({
}
const scrollDistance = scrollContainerElement.getBoundingClientRect().top;

// If the input bar is already in view, set the mention directly. We leave
// a little margin, -2 instead of 0, since the autoscroll below can
// sometimes scroll a bit over 0, to -0.3 or -0.5, in which case if there
// is a clic on a visible assistant we still want this condition to
// trigger.
// If the input bar is already in view, set the mention directly. We leave a little margin, -2
// instead of 0, since the autoscroll below can sometimes scroll a bit over 0, to -0.3 or
// -0.5, in which case if there is a clic on a visible assistant we still want this condition
// to trigger.
if (scrollDistance > -2) {
return onAgentConfigurationClick(agent.sId);
}

// Otherwise, scroll to the input bar and set the ref (mention will be set via intersection observer).
// Otherwise, scroll to the input bar and set the ref (mention will be set via intersection
// observer).
scrollContainerElement.scrollIntoView({ behavior: "smooth" });

setAssistantToMention(agent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import InputBarContainer, {
import { InputBarContext } from "@app/components/assistant/conversation/input_bar/InputBarContext";
import { useFileUploaderService } from "@app/hooks/useFileUploaderService";
import type { DustError } from "@app/lib/error";
import { useAgentConfigurations } from "@app/lib/swr/assistants";
import { useProgressiveAgentConfigurations } from "@app/lib/swr/assistants";
import { useConversation } from "@app/lib/swr/conversations";
import { classNames } from "@app/lib/utils";

Expand Down Expand Up @@ -83,9 +83,8 @@ export function AssistantInputBar({
});

const { agentConfigurations: baseAgentConfigurations } =
useAgentConfigurations({
useProgressiveAgentConfigurations({
workspaceId: owner.sId,
agentsGetView: "list",
});

// Files upload.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
import { compareAgentsForSort } from "@dust-tt/types";
import { useMemo } from "react";

import { useAgentConfigurations } from "@app/lib/swr/assistants";
import { useProgressiveAgentConfigurations } from "@app/lib/swr/assistants";

function makeEditorSuggestions(
agentConfigurations: LightAgentConfigurationType[]
Expand All @@ -25,9 +25,8 @@ const useAssistantSuggestions = (
inListAgentConfigurations: LightAgentConfigurationType[],
owner: WorkspaceType
) => {
const { agentConfigurations } = useAgentConfigurations({
const { agentConfigurations } = useProgressiveAgentConfigurations({
workspaceId: owner.sId,
agentsGetView: "list",
});

// `useMemo` will ensure that suggestions is only recalculated
Expand Down
38 changes: 19 additions & 19 deletions front/lib/swr/assistants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,17 @@ export function useProgressiveAgentConfigurations({
workspaceId: string;
disabled?: boolean;
}) {
const {
agentConfigurations: initialAgentConfigurations,
isAgentConfigurationsLoading: isInitialAgentConfigurationsLoading,
} = useAgentConfigurations({
workspaceId,
agentsGetView: "list",
limit: 24,
includes: ["usage"],
disabled,
revalidate: false,
});
// const {
// agentConfigurations: initialAgentConfigurations,
// isAgentConfigurationsLoading: isInitialAgentConfigurationsLoading,
// } = useAgentConfigurations({
// workspaceId,
// agentsGetView: "list",
// limit: 24,
// includes: ["usage"],
// disabled,
// revalidate: false,
// });

const {
agentConfigurations: agentConfigurationsWithAuthors,
Expand All @@ -173,16 +173,16 @@ export function useProgressiveAgentConfigurations({
disabled,
});

const isLoading =
isInitialAgentConfigurationsLoading ||
isAgentConfigurationsWithAuthorsLoading;
const agentConfigurations = isAgentConfigurationsWithAuthorsLoading
? initialAgentConfigurations
: agentConfigurationsWithAuthors;
// const isLoading =
// isInitialAgentConfigurationsLoading ||
// isAgentConfigurationsWithAuthorsLoading;
// const agentConfigurations = isAgentConfigurationsWithAuthorsLoading
// ? initialAgentConfigurations
// : agentConfigurationsWithAuthors;

return {
agentConfigurations,
isLoading,
agentConfigurations: agentConfigurationsWithAuthors,
isLoading: isAgentConfigurationsWithAuthorsLoading,
mutate,
mutateRegardlessOfQueryParams,
};
Expand Down

0 comments on commit 20fc569

Please sign in to comment.