Skip to content

Commit

Permalink
Renamed batch to page, minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
overmode committed Jan 2, 2025
1 parent d16a392 commit f77e057
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 60 deletions.
1 change: 0 additions & 1 deletion front/components/assistant_builder/AssistantBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ export default function AssistantBuilder({
size="sm"
variant="outline"
tooltip="Inspect feedback and performance"
disabled={!agentConfigurationId}
/>
)}
{/* Template Button */}
Expand Down
112 changes: 53 additions & 59 deletions front/components/assistant_builder/AssistantBuilderPreviewDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ import {
useAgentConfigurationHistory,
} from "@app/lib/swr/assistants";
import { useUser } from "@app/lib/swr/user";
import { timeAgoFrom } from "@app/lib/utils";
import { formatTimestampToFriendlyDate, timeAgoFrom } from "@app/lib/utils";
import type { FetchAssistantTemplateResponse } from "@app/pages/api/w/[wId]/assistant/builder/templates/[tId]";

const FEEDBACKS_BATCH_SIZE = 50;
const FEEDBACKS_PAGE_SIZE = 50;

interface AssistantBuilderRightPanelProps {
screen: BuilderScreen;
Expand Down Expand Up @@ -122,40 +122,35 @@ export default function AssistantBuilderRightPanel({

return (
<div className="flex h-full flex-col">
{/* The agentConfigurationId is truthy iff not a new assistant */}
{(template || agentConfigurationId) && (
<div className="shrink-0 bg-white pt-5">
<Tabs
value={rightPanelStatus.tab ?? "Preview"}
onValueChange={(t) =>
openRightPanelTab(t as AssistantBuilderRightPanelTab)
}
className="hidden lg:flex"
>
<TabsList className="inline-flex h-10 items-center gap-2 border-b border-separator">
{template && (
<TabsTrigger
value="Template"
label="Template"
icon={MagicIcon}
/>
)}
{agentConfigurationId && (
<TabsTrigger
value="Performance"
label="Performance"
icon={LightbulbIcon}
/>
)}
<div className="shrink-0 bg-white pt-5">
<Tabs
value={rightPanelStatus.tab ?? "Preview"}
onValueChange={(t) =>
openRightPanelTab(t as AssistantBuilderRightPanelTab)
}
className="hidden lg:flex"
>
<TabsList className="inline-flex items-center gap-2 border-b border-separator">
{template && (
<TabsTrigger value="Template" label="Template" icon={MagicIcon} />
)}
{/* The agentConfigurationId is truthy iff not a new assistant */}
{agentConfigurationId && (
<TabsTrigger
value="Preview"
label="Preview"
icon={ChatBubbleBottomCenterTextIcon}
value="Performance"
label="Performance"
icon={LightbulbIcon}
/>
</TabsList>
</Tabs>
</div>
)}
)}
<TabsTrigger
value="Preview"
label="Preview"
icon={ChatBubbleBottomCenterTextIcon}
/>
</TabsList>
</Tabs>
</div>

<div
className={cn(
"grow-1 mb-5 h-full overflow-y-auto border-structure-200",
Expand Down Expand Up @@ -302,7 +297,7 @@ export default function AssistantBuilderRightPanel({
<Page.SectionHeader title="Feedback" />
<FeedbacksSection
owner={owner}
assistantId={agentConfigurationId}
agentConfigurationId={agentConfigurationId}
/>
</div>
)}
Expand Down Expand Up @@ -418,42 +413,44 @@ const TemplateDropDownMenu = ({

const FeedbacksSection = ({
owner,
assistantId,
agentConfigurationId,
}: {
owner: LightWorkspaceType;
assistantId: string;
agentConfigurationId: string;
}) => {
// Used for pagination's lastValue: BatchId -> LastFeedbackId
const [lastIdForBatches, setLastIdForBatches] = useState<
Record<number, number>
>({});
// Used for pagination's lastValue: page index -> last feedback id in page
const [lastIdForPage, setLastIdForPage] = useState<Record<number, number>>(
{}
);

const [paginationState, setPaginationState] = useState<PaginationState>({
pageIndex: 0,
pageSize: FEEDBACKS_BATCH_SIZE,
pageSize: FEEDBACKS_PAGE_SIZE,
});

// Decreasing version, paginated decreasing id.
const { agentConfigurationFeedbacks, isAgentConfigurationFeedbacksLoading } =
useAgentConfigurationFeedbacksByDescVersion({
workspaceId: owner.sId,
agentConfigurationId: assistantId ?? "",
agentConfigurationId: agentConfigurationId ?? "",
withMetadata: true,
paginationParams: {
limit: FEEDBACKS_BATCH_SIZE,
limit: FEEDBACKS_PAGE_SIZE,
lastValue:
paginationState.pageIndex === 0
? undefined
: lastIdForBatches[paginationState.pageIndex - 1],
: lastIdForPage[paginationState.pageIndex - 1],
orderColumn: "id",
orderDirection: "desc",
},
disabled: !agentConfigurationId,
});

const { agentConfigurationHistory, isAgentConfigurationHistoryLoading } =
useAgentConfigurationHistory({
workspaceId: owner.sId,
agentConfigurationId: assistantId,
agentConfigurationId: agentConfigurationId,
disabled: !agentConfigurationId,
});

const handleSetPagination = useCallback(
Expand All @@ -465,7 +462,7 @@ const FeedbacksSection = ({
) {
return;
}
setLastIdForBatches((prev) => ({
setLastIdForPage((prev) => ({
...prev,
...{
[paginationState.pageIndex]:
Expand All @@ -479,7 +476,7 @@ const FeedbacksSection = ({
[agentConfigurationFeedbacks, paginationState.pageIndex]
);

const firstAgentConfigurationInBatch = useMemo(
const firstAgentConfigurationInPage = useMemo(
() =>
agentConfigurationHistory?.find(
(c) =>
Expand All @@ -504,7 +501,7 @@ const FeedbacksSection = ({
return <div className="mt-3 text-sm text-element-900">No feedbacks.</div>;
}

if (!agentConfigurationHistory || !firstAgentConfigurationInBatch) {
if (!agentConfigurationHistory || !firstAgentConfigurationInPage) {
return (
<div className="mt-3 text-sm text-element-900">
Error loading the previous agent versions.
Expand All @@ -516,10 +513,10 @@ const FeedbacksSection = ({
<div>
<div className="mb-2 flex flex-col">
<AgentConfigurationVersionHeader
agentConfiguration={firstAgentConfigurationInBatch}
agentConfigurationVersion={firstAgentConfigurationInBatch?.version}
agentConfiguration={firstAgentConfigurationInPage}
agentConfigurationVersion={firstAgentConfigurationInPage?.version}
isLatestVersion={
firstAgentConfigurationInBatch?.version ===
firstAgentConfigurationInPage?.version ===
agentConfigurationHistory[0].version
}
/>
Expand Down Expand Up @@ -591,13 +588,8 @@ function AgentConfigurationVersionHeader({
if (!config.versionCreatedAt) {
return `v${config.version}`;
}
return new Date(config.versionCreatedAt).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
hour: "numeric",
minute: "numeric",
});
const versionDate = new Date(config.versionCreatedAt);
return formatTimestampToFriendlyDate(versionDate.getTime(), "long");
},
[isLatestVersion]
);
Expand All @@ -621,6 +613,8 @@ function FeedbackCard({
const conversationUrl =
feedback.conversationId &&
feedback.messageId &&
// IMPORTANT: We need to check if the conversation is shared before displaying it.
// This check is redundant: the conversationId is null if the conversation is not shared.
feedback.isConversationShared
? `${process.env.NEXT_PUBLIC_DUST_CLIENT_FACING_URL}/w/${owner.sId}/assistant/${feedback.conversationId}#${feedback.messageId}`
: null;
Expand Down
1 change: 1 addition & 0 deletions front/lib/resources/agent_message_feedback_resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export class AgentMessageFeedbackResource extends BaseResource<AgentMessageFeedb
},
],
order: [
// Necessary because a feedback can be given at any time on a message linked to an old version.
["agentConfigurationVersion", "DESC"],
[
paginationParams.orderColumn,
Expand Down

0 comments on commit f77e057

Please sign in to comment.