Skip to content
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
4 changes: 3 additions & 1 deletion site/src/pages/AgentsPage/AgentChatPage.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const AgentChatPageLayout: FC = () => {
requestUnarchiveAgent: () => {},
requestPinAgent: () => {},
requestUnpinAgent: () => {},
isArchiving: false,
archivingChatId: undefined,
onRegenerateTitle: () => {},
regeneratingTitleChatIds: [],
isSidebarCollapsed: false,
Expand Down Expand Up @@ -1477,7 +1479,7 @@ export const CompletedWithDiffPanel: Story = {
// Verify menu items are rendered.
const body = within(document.body);
await waitFor(() => {
expect(body.getByText("Archive Agent")).toBeInTheDocument();
expect(body.getByText("Archive agent")).toBeInTheDocument();
});
// Workspace items moved to the workspace pill popover.
expect(body.queryByText("Open in Cursor")).not.toBeInTheDocument();
Expand Down
49 changes: 38 additions & 11 deletions site/src/pages/AgentsPage/AgentChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,11 @@ const AgentChatPage: FC = () => {
requestArchiveAgent,
requestArchiveAndDeleteWorkspace,
requestUnarchiveAgent,
onRegenerateTitle,
requestPinAgent,
requestUnpinAgent,
isArchiving,
archivingChatId,
onOpenRenameDialog,
regeneratingTitleChatIds,
isSidebarCollapsed,
onToggleSidebarCollapsed,
Expand Down Expand Up @@ -974,7 +978,6 @@ const AgentChatPage: FC = () => {
has_more: chatMessagesQuery.data?.pages.at(-1)?.has_more ?? false,
}
: undefined;
const isRegenerateTitleDisabled = isArchived || isRegeneratingThisChat;
const chatLastModelConfigID = chatRecord?.last_model_config_id;

// Destructure mutation results directly so the React Compiler
Expand Down Expand Up @@ -1282,6 +1285,30 @@ const AgentChatPage: FC = () => {
requestUnarchiveAgent(agentId);
};

const handlePinAgentAction = () => {
if (!agentId || isArchived) {
return;
}
requestPinAgent(agentId);
};

const handleUnpinAgentAction = () => {
if (!agentId || isArchived) {
return;
}
requestUnpinAgent(agentId);
};

const handleOpenRenameDialogAction =
onOpenRenameDialog && chatRecord
? () => {
if (isArchived) {
return;
}
onOpenRenameDialog(chatRecord);
}
: undefined;

// Signal ready only after the store has synced fetched messages,
// so the DOM actually contains them when the parent scrolls.
const chatReadyFiredRef = useRef<string | null>(null);
Expand Down Expand Up @@ -1534,13 +1561,6 @@ const AgentChatPage: FC = () => {
});
}

const handleRegenerateTitle = () => {
if (!agentId || isRegenerateTitleDisabled || !onRegenerateTitle) {
return;
}
onRegenerateTitle(agentId);
};

const handleSendAskUserQuestionResponse = async (message: string) => {
await submitChatTurn({
message,
Expand Down Expand Up @@ -1658,9 +1678,16 @@ const AgentChatPage: FC = () => {
handleArchiveAndDeleteWorkspaceAction={
handleArchiveAndDeleteWorkspaceAction
}
handleRegenerateTitle={handleRegenerateTitle}
handlePinAgentAction={handlePinAgentAction}
handleUnpinAgentAction={handleUnpinAgentAction}
handleOpenRenameDialogAction={handleOpenRenameDialogAction}
isArchivingThisChat={
isArchiving &&
(archivingChatId === undefined || archivingChatId === agentId)
}
isPinned={(chatRecord?.pin_order ?? 0) > 0}
isChildChat={parentChatID !== undefined}
isRegeneratingTitle={isRegeneratingThisChat}
isRegenerateTitleDisabled={isRegenerateTitleDisabled}
urlTransform={urlTransform}
scrollContainerRef={scrollContainerRef}
scrollToBottomRef={scrollToBottomRef}
Expand Down
30 changes: 19 additions & 11 deletions site/src/pages/AgentsPage/AgentChatPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,17 @@ interface AgentChatPageViewProps {
onImplementPlan?: () => Promise<void> | void;
onSendAskUserQuestionResponse?: (message: string) => Promise<void> | void;

// Archive actions.
// Chat actions.
handleArchiveAgentAction: () => void;
handleUnarchiveAgentAction: () => void;
handleArchiveAndDeleteWorkspaceAction: () => void;
handleRegenerateTitle?: () => void;
handlePinAgentAction?: () => void;
handleUnpinAgentAction?: () => void;
handleOpenRenameDialogAction?: () => void;
isPinned?: boolean;
isChildChat?: boolean;
isArchivingThisChat?: boolean;
isRegeneratingTitle?: boolean;
isRegenerateTitleDisabled?: boolean;

// Scroll container ref.
scrollContainerRef: RefObject<HTMLDivElement | null>;
Expand Down Expand Up @@ -358,9 +362,13 @@ export const AgentChatPageView: FC<AgentChatPageViewProps> = ({
handleArchiveAgentAction,
handleUnarchiveAgentAction,
handleArchiveAndDeleteWorkspaceAction,
handleRegenerateTitle,
handlePinAgentAction,
handleUnpinAgentAction,
handleOpenRenameDialogAction,
isPinned,
isChildChat,
isArchivingThisChat,
isRegeneratingTitle,
isRegenerateTitleDisabled,
scrollContainerRef,
scrollToBottomRef,
hasMoreMessages,
Expand Down Expand Up @@ -837,11 +845,13 @@ export const AgentChatPageView: FC<AgentChatPageViewProps> = ({
onArchiveAndDeleteWorkspace={
handleArchiveAndDeleteWorkspaceAction
}
{...(handleRegenerateTitle
? { onRegenerateTitle: handleRegenerateTitle }
: {})}
onPinAgent={handlePinAgentAction}
onUnpinAgent={handleUnpinAgentAction}
onOpenRenameDialog={handleOpenRenameDialogAction}
isPinned={isPinned}
isChildChat={isChildChat}
isArchiving={isArchivingThisChat}
isRegeneratingTitle={isRegeneratingTitle}
isRegenerateTitleDisabled={isRegenerateTitleDisabled}
hasWorkspace={Boolean(workspace)}
isArchived={isArchived}
diffStatusData={diffStatusData}
Expand Down Expand Up @@ -1080,7 +1090,6 @@ export const AgentChatPageLoadingView: FC<AgentChatPageLoadingViewProps> = ({
}}
onArchiveAgent={() => {}}
onUnarchiveAgent={() => {}}
onRegenerateTitle={() => {}}
onArchiveAndDeleteWorkspace={() => {}}
hasWorkspace={false}
isSidebarCollapsed={isSidebarCollapsed}
Expand Down Expand Up @@ -1158,7 +1167,6 @@ export const AgentChatPageNotFoundView: FC<AgentChatPageNotFoundViewProps> = ({
}}
onArchiveAgent={() => {}}
onUnarchiveAgent={() => {}}
onRegenerateTitle={() => {}}
onArchiveAndDeleteWorkspace={() => {}}
hasWorkspace={false}
isSidebarCollapsed={isSidebarCollapsed}
Expand Down
2 changes: 2 additions & 0 deletions site/src/pages/AgentsPage/AgentEmbedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ const AgentEmbedPage: FC = () => {
requestPinAgent: () => {},
requestUnpinAgent: () => {},
requestArchiveAndDeleteWorkspace,
isArchiving: false,
archivingChatId: undefined,
// Title regeneration is not supported in embed mode.
regeneratingTitleChatIds: [],
isSidebarCollapsed,
Expand Down
1 change: 0 additions & 1 deletion site/src/pages/AgentsPage/AgentsPageView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ const AgentTopBarRouteElement = () => {
panel={{ showSidebarPanel: false, onToggleSidebar: fn() }}
onArchiveAgent={fn()}
onArchiveAndDeleteWorkspace={fn()}
onRegenerateTitle={fn()}
onUnarchiveAgent={fn()}
isSidebarCollapsed={isSidebarCollapsed}
onToggleSidebarCollapsed={onToggleSidebarCollapsed}
Expand Down
16 changes: 15 additions & 1 deletion site/src/pages/AgentsPage/AgentsPageView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type FC, type RefObject, useRef } from "react";
import { type FC, type RefObject, useRef, useState } from "react";
import { Outlet, useLocation } from "react-router";
import type * as TypesGen from "#/api/typesGenerated";
import { cn } from "#/utils/cn";
Expand Down Expand Up @@ -26,8 +26,12 @@ export interface AgentsOutletContext {
requestPinAgent: (chatId: string) => void;
requestUnpinAgent: (chatId: string) => void;
requestReorderPinnedAgent?: (chatId: string, pinOrder: number) => void;
isArchiving: boolean;
archivingChatId: string | undefined;
onRegenerateTitle?: (chatId: string) => void;
onRenameTitle?: (chatId: string, title: string) => Promise<void>;
/** Opens the shared rename dialog so both menus drive the same instance. */
onOpenRenameDialog?: (chat: TypesGen.Chat) => void;
regeneratingTitleChatIds: readonly string[];
isSidebarCollapsed: boolean;
onToggleSidebarCollapsed: () => void;
Expand Down Expand Up @@ -142,6 +146,11 @@ export const AgentsPageView: FC<AgentsPageViewProps> = ({

const scrollContainerRef = useRef<HTMLDivElement | null>(null);

// State for the shared rename-chat dialog. Lifted here so both the
// sidebar menu and the chat top bar open the same dialog instance.
const [chatPendingRename, setChatPendingRename] =
useState<TypesGen.Chat | null>(null);

const outletContextValue: AgentsOutletContext = {
chatErrorReasons,
setChatErrorReason,
Expand All @@ -152,9 +161,12 @@ export const AgentsPageView: FC<AgentsPageViewProps> = ({
requestPinAgent,
requestUnpinAgent,
requestReorderPinnedAgent,
isArchiving,
archivingChatId,
onRegenerateTitle: (chatId: string) => {
onRegenerateTitle(chatId).catch(() => {});
},
onOpenRenameDialog: setChatPendingRename,
regeneratingTitleChatIds,
isSidebarCollapsed,
onToggleSidebarCollapsed,
Expand Down Expand Up @@ -194,6 +206,8 @@ export const AgentsPageView: FC<AgentsPageViewProps> = ({
onReorderPinnedAgent={requestReorderPinnedAgent}
onRenameTitle={onRenameTitle}
onProposeTitle={onProposeTitle}
chatPendingRename={chatPendingRename}
onChatPendingRenameChange={setChatPendingRename}
regeneratingTitleChatIds={regeneratingTitleChatIds}
onBeforeNewAgent={handleNewAgent}
isSearchDialogOpen={isSearchDialogOpen}
Expand Down
110 changes: 110 additions & 0 deletions site/src/pages/AgentsPage/components/ChatActionsMenuItems.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import {
ArchiveIcon,
ArchiveRestoreIcon,
PinIcon,
PinOffIcon,
SquarePenIcon,
Trash2Icon,
} from "lucide-react";
import type { FC } from "react";
import type {
ContextMenuItem,
ContextMenuSeparator,
} from "#/components/ContextMenu/ContextMenu";
import type {
DropdownMenuItem,
DropdownMenuSeparator,
} from "#/components/DropdownMenu/DropdownMenu";

type ItemComponent = typeof DropdownMenuItem | typeof ContextMenuItem;
type SeparatorComponent =
| typeof DropdownMenuSeparator
| typeof ContextMenuSeparator;

interface ChatActionsMenuItemsProps {
readonly isArchived: boolean;
readonly isPinned: boolean;
readonly isChildChat: boolean;
readonly hasWorkspace: boolean;
readonly isArchiving?: boolean;
readonly onPinAgent?: () => void;
readonly onUnpinAgent?: () => void;
readonly onArchiveAgent: () => void;
readonly onUnarchiveAgent: () => void;
readonly onArchiveAndDeleteWorkspace: () => void;
/** When omitted, the "Rename chat" item is hidden. */
readonly onOpenRenameDialog?: () => void;
readonly Item: ItemComponent;
readonly Separator: SeparatorComponent;
}

export const ChatActionsMenuItems: FC<ChatActionsMenuItemsProps> = ({
isArchived,
isPinned,
isChildChat,
hasWorkspace,
isArchiving = false,
onPinAgent,
onUnpinAgent,
onArchiveAgent,
onUnarchiveAgent,
onArchiveAndDeleteWorkspace,
onOpenRenameDialog,
Item,
Separator,
}) => {
return (
<>
{!isArchived && !isChildChat && onPinAgent && onUnpinAgent && (
<Item onSelect={isPinned ? onUnpinAgent : onPinAgent}>
{isPinned ? (
<>
<PinOffIcon className="size-3.5" />
Unpin agent
</>
) : (
<>
<PinIcon className="size-3.5" />
Pin agent
</>
)}
</Item>
)}
{isArchived ? (
<Item disabled={isArchiving} onSelect={onUnarchiveAgent}>
<ArchiveRestoreIcon className="size-3.5" />
Unarchive agent
</Item>
) : (
<>
{onOpenRenameDialog && (
<Item onSelect={onOpenRenameDialog}>
<SquarePenIcon className="size-3.5" />
Rename chat
</Item>
)}
{(onOpenRenameDialog ||
(!isChildChat && onPinAgent && onUnpinAgent)) && <Separator />}
<Item
className="text-content-destructive focus:text-content-destructive"
disabled={isArchiving}
onSelect={onArchiveAgent}
>
<ArchiveIcon className="size-3.5" />
Archive agent
</Item>
{hasWorkspace && (
<Item
className="text-content-destructive focus:text-content-destructive"
disabled={isArchiving}
onSelect={onArchiveAndDeleteWorkspace}
>
<Trash2Icon className="size-3.5" />
Archive & delete workspace
</Item>
)}
</>
)}
</>
);
};
Loading
Loading