Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

feat: add delete confirmation dialog to Sessions list with hover menu (#743)

Govinda Vashishthaffbb2395dc24
diff --git a/.changeset/session-list-delete-menu.md b/.changeset/session-list-delete-menu.md
new file mode 100644
index 000000000..85b93b8d5
--- /dev/null
+++ b/.changeset/session-list-delete-menu.md
@@ -0,0 +1,5 @@
+---
+'@truefoundry/trueforge-ui': patch
+---
+
+Add a hover ellipsis delete menu with confirmation dialog on Sessions list rows.
diff --git a/packages/trueforge-ui/src/atoms/AgentOverflowMenu.tsx b/packages/trueforge-ui/src/atoms/AgentOverflowMenu.tsx
index 66ab7be54..0f588ffab 100644
--- a/packages/trueforge-ui/src/atoms/AgentOverflowMenu.tsx
+++ b/packages/trueforge-ui/src/atoms/AgentOverflowMenu.tsx
@@ -93,6 +93,7 @@ export function AgentOverflowMenu({
const handleDelete = async () => {
if (!canDelete || builder == null || typeof builder.deleteAgent !== 'function') return;
+ setPending(null);
setBusy(true);
try {
await builder.deleteAgent({ agentName });
@@ -101,7 +102,6 @@ export function AgentOverflowMenu({
title: 'Agent deleted',
description: `“${agentName}” was deleted.`,
});
- setPending(null);
onDeleted?.();
} catch (caught) {
toaster?.showError(caught);
@@ -211,9 +211,10 @@ export function AgentOverflowMenu({
<Dialog open onOpenChange={open => !open && closePending()} aria-label="Delete agent" className="max-w-md">
<DialogContent>
<DialogHeader>
- <DialogTitle>Delete agent?</DialogTitle>
+ <DialogTitle>Delete agent</DialogTitle>
<p className="text-text-secondary text-sm">
- “{agentName}” will be permanently deleted. This cannot be undone.
+ “{agentName}” will be permanently deleted, including any schedules for this agent. This cannot be
+ undone.
</p>
</DialogHeader>
</DialogContent>
diff --git a/packages/trueforge-ui/src/atoms/agent-details/AgentSessionListRow.tsx b/packages/trueforge-ui/src/atoms/agent-details/AgentSessionListRow.tsx
index 4ebe63184..2e41323ee 100644
--- a/packages/trueforge-ui/src/atoms/agent-details/AgentSessionListRow.tsx
+++ b/packages/trueforge-ui/src/atoms/agent-details/AgentSessionListRow.tsx
@@ -1,9 +1,12 @@
'use client';
import { Icon } from '../../icons/Icon.js';
+import { useSlot } from '../../theme/SlotsProvider.js';
import { formatSessionListMetrics } from '../../utils/sessionDisplayFormat.js';
+import { auiButtonClass } from '../lib/buttonClasses.js';
import { cn } from '../lib/cn.js';
import { formatRelativeShort } from '../lib/threadListMeta.js';
+import { DropdownMenu, DropdownMenuItem } from '../primitives/DropdownMenu.js';
import { Tooltip } from '../primitives/Tooltip.js';
import type { AgentSessionListRowProps } from './types.js';
@@ -15,30 +18,76 @@ export function AgentSessionListRow({
metrics,
active,
onSelect,
+ onRequestDelete,
+ canDelete = true,
}: AgentSessionListRowProps) {
+ const PermissionGuard = useSlot('PermissionGuard');
const relative = formatRelativeShort(new Date(lastActivityAt));
return (
- <button
- type="button"
- onClick={onSelect}
+ <div
data-active={active || undefined}
className={cn(
- 'flex w-full flex-col gap-2 border-b border-border px-4 py-3 text-left transition-colors',
+ 'group flex w-full flex-col border-b border-border transition-colors',
active ? 'bg-dropdown-selected-item-bg' : 'hover:bg-ghost-button-hover',
)}
>
- <span className="flex items-start justify-between gap-2">
- <span className="line-clamp-2 text-sm font-medium text-text-primary">{title}</span>
- {sourceType === 'schedule' ? (
- <Tooltip content="Scheduled Session">
- <span aria-label="Scheduled run" className="mt-0.5 inline-flex shrink-0">
- <Icon name="calendar" className="size-3.5 text-primary-button-bg" />
- </span>
- </Tooltip>
+ <div className="flex items-center gap-2 px-4 pt-3">
+ <button type="button" onClick={onSelect} className="flex min-w-0 flex-1 items-center gap-1 text-left">
+ <span className="truncate text-sm font-medium text-text-primary">{title}</span>
+ {sourceType === 'schedule' ? (
+ <Tooltip content="Scheduled Session">
+ <span aria-label="Scheduled run" className="inline-flex shrink-0">
+ <Icon name="calendar" className="size-3.5 text-primary-button-bg" />
+ </span>
+ </Tooltip>
+ ) : null}
+ </button>
+ {onRequestDelete != null ? (
+ <div
+ className={cn(
+ 'ml-auto shrink-0 transition-opacity',
+ // Visible below md; md+ hide until hover/focus/open (same pattern as ThreadListRow).
+ // md: variants survive host Tailwind tree-shaking.
+ 'md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100 md:group-has-[[aria-expanded=true]]:opacity-100',
+ )}
+ onClick={event => event.stopPropagation()}
+ onKeyDown={event => event.stopPropagation()}
+ >
+ <DropdownMenu
+ align="end"
+ className="min-w-40"
+ trigger={
+ <button
+ type="button"
+ className={auiButtonClass({ variant: 'ghost', size: 'icon', className: 'size-7' })}
+ aria-label={`Actions for ${title}`}
+ >
+ <Icon name="ellipsis" />
+ </button>
+ }
+ >
+ <PermissionGuard allowed={canDelete}>
+ <DropdownMenuItem
+ className="whitespace-nowrap text-failure-bg focus-visible:text-failure-bg"
+ onClick={() => {
+ if (canDelete) onRequestDelete();
+ }}
+ >
+ <Icon name="trash" className="size-3.5" />
+ Delete
+ </DropdownMenuItem>
+ </PermissionGuard>
+ </DropdownMenu>
+ </div>
) : null}
- </span>
- <span className="flex items-end justify-between gap-2 text-xs text-text-secondary">
+ </div>
+
+ <button
+ type="button"
+ onClick={onSelect}
+ className="flex w-full items-end justify-between gap-2 px-4 pt-2 pb-3 text-left text-xs text-text-secondary"
+ >
<span className="flex min-w-0 items-center gap-1">
{agentName != null ? (
<>
@@ -50,8 +99,8 @@ export function AgentSessionListRow({
<span>{relative}</span>
</span>
<span className="shrink-0 tabular-nums">{formatSessionListMetrics(metrics)}</span>
- </span>
- </button>
+ </button>
+ </div>
);
}
diff --git a/packages/trueforge-ui/src/atoms/agent-details/AgentSessions.tsx b/packages/trueforge-ui/src/atoms/agent-details/AgentSessions.tsx
index 843618d03..b951d5bb5 100644
--- a/packages/trueforge-ui/src/atoms/agent-details/AgentSessions.tsx
+++ b/packages/trueforge-ui/src/atoms/agent-details/AgentSessions.tsx
@@ -3,6 +3,7 @@
import { useCallback, useEffect, useMemo, useRef, useState, type ComponentType } from 'react';
import { Group, Panel, Separator } from 'react-resizable-panels';
+import { useToasterOptional } from '../../containers/ToasterContainer.js';
import { useResourcePermissions } from '../../hooks/useResourcePermissions.js';
import { useSessionShareSearch } from '../../hooks/useSessionShareSearch.js';
import { Icon } from '../../icons/Icon.js';
@@ -17,6 +18,8 @@ import { sessionTimeRangeFromCreatedAt } from '../../utils/sessionShareUrl.js';
import { EmptyScreen } from '../EmptyScreen.js';
import { cn } from '../lib/cn.js';
import { sessionIsCreateAgent } from '../lib/sessionCreateAgent.js';
+import { Button } from '../primitives/Button.js';
+import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '../primitives/Dialog.js';
import { Skeleton } from '../primitives/Skeleton.js';
import type { AgentSessionsProps } from './types.js';
@@ -41,14 +44,10 @@ function entrySourceType(entry: SessionListEntry): 'schedule' | undefined {
export function AgentSessions({ agentId, startTimestamp, endTimestamp, shareView }: AgentSessionsProps) {
const sessionsServer = useAgentSessionsServer();
const chatServer = useServer();
+ const toaster = useToasterOptional();
const shell = useOptionalShellMode();
const routes = useOptionalResolvedRoutes();
const { sessionId: selectedSessionId, updateShareSearch } = useSessionShareSearch();
- const { allows } = useResourcePermissions({
- resourceType: 'session',
- resourceIds: selectedSessionId == null ? [] : [selectedSessionId],
- });
- const canResume = allows(selectedSessionId, 'MANAGE');
const AgentSessionListRow = useSlot('AgentSessionListRow');
const AgentSessionDetailHeader = useSlot('AgentSessionDetailHeader');
@@ -68,6 +67,19 @@ export function AgentSessions({ agentId, startTimestamp, endTimestamp, shareView
const [detailSession, setDetailSession] = useState<Session>();
const [detailLoading, setDetailLoading] = useState(false);
const [detailFailed, setDetailFailed] = useState(false);
+ const [pendingDelete, setPendingDelete] = useState<SessionListEntry | null>(null);
+
+ const canDeleteSession = typeof chatServer.deleteSession === 'function';
+ const permissionResourceIds = useMemo(() => {
+ const ids = new Set(entries.map(entry => entry.id));
+ if (selectedSessionId != null && selectedSessionId.length > 0) ids.add(selectedSessionId);
+ return [...ids];
+ }, [entries, selectedSessionId]);
+ const { allows } = useResourcePermissions({
+ resourceType: 'session',
+ resourceIds: permissionResourceIds,
+ });
+ const canResume = allows(selectedSessionId, 'MANAGE');
const listRequest = useMemo(
() => ({
@@ -205,6 +217,20 @@ export function AgentSessions({ agentId, startTimestamp, endTimestamp, shareView
updateShareSearch({ sessionId: null });
};
+ const handleDelete = async (entry: SessionListEntry) => {
+ if (!allows(entry.id, 'DELETE') || typeof chatServer.deleteSession !== 'function') return;
+ setPendingDelete(null);
+ try {
+ await chatServer.deleteSession({ sessionId: entry.id });
+ setEntries(current => current.filter(item => item.id !== entry.id));
+ if (selectedSessionId === entry.id) {
+ updateShareSearch({ sessionId: null });
+ }
+ } catch (caught) {
+ toaster?.showError(caught);
+ }
+ };
+
const selectedEntry = entries.find(entry => entry.id === selectedSessionId);
const selectedTitle =
detailSession != null
@@ -287,6 +313,12 @@ export function AgentSessions({ agentId, startTimestamp, endTimestamp, shareView
metrics={entry.metrics}
active={entry.id === selectedSessionId}
onSelect={() => selectSession(entry)}
+ {...(canDeleteSession
+ ? {
+ onRequestDelete: () => setPendingDelete(entry),
+ canDelete: allows(entry.id, 'DELETE'),
+ }
+ : {})}
/>
))
)}
@@ -368,6 +400,38 @@ export function AgentSessions({ agentId, startTimestamp, endTimestamp, shareView
)}
</section>
</Panel>
+
+ {pendingDelete != null ? (
+ <Dialog
+ open
+ onOpenChange={open => {
+ if (!open) setPendingDelete(null);
+ }}
+ aria-label="Delete session"
+ className="max-w-md"
+ >
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Delete session</DialogTitle>
+ <p className="text-text-secondary text-sm">
+ “{sessionTitle(pendingDelete)}” will be permanently deleted. This cannot be undone.
+ </p>
+ </DialogHeader>
+ </DialogContent>
+ <DialogFooter>
+ <Button.Secondary type="button" onClick={() => setPendingDelete(null)}>
+ Cancel
+ </Button.Secondary>
+ <Button.Destructive
+ type="button"
+ disabled={!allows(pendingDelete.id, 'DELETE')}
+ onClick={() => void handleDelete(pendingDelete)}
+ >
+ Delete
+ </Button.Destructive>
+ </DialogFooter>
+ </Dialog>
+ ) : null}
</Group>
);
}
diff --git a/packages/trueforge-ui/src/atoms/agent-details/types.ts b/packages/trueforge-ui/src/atoms/agent-details/types.ts
index b6e306d7d..04b463fed 100644
--- a/packages/trueforge-ui/src/atoms/agent-details/types.ts
+++ b/packages/trueforge-ui/src/atoms/agent-details/types.ts
@@ -32,6 +32,10 @@ export type AgentSessionListRowProps = {
};
active: boolean;
onSelect: () => void;
+ /** Opens delete confirmation; does not call the API. */
+ onRequestDelete?: () => void;
+ /** When false, Delete is disabled via PermissionGuard. Defaults to true. */
+ canDelete?: boolean;
};
export type AgentSessionDetailHeaderProps = {
diff --git a/packages/trueforge-ui/test/atoms/AgentDetailsPage.test.tsx b/packages/trueforge-ui/test/atoms/AgentDetailsPage.test.tsx
index ddd8bedb0..8b48d7d1f 100644
--- a/packages/trueforge-ui/test/atoms/AgentDetailsPage.test.tsx
+++ b/packages/trueforge-ui/test/atoms/AgentDetailsPage.test.tsx
@@ -214,6 +214,15 @@ describe('AgentDetailsPage', () => {
fireEvent.click(screen.getByRole('menuitem', { name: 'Delete' }));
expect(screen.getByRole('dialog', { name: 'Delete agent' })).toBeInTheDocument();
+ expect(screen.getByText(/including any schedules for this agent/)).toBeInTheDocument();
+ expect(deleteAgent).not.toHaveBeenCalled();
+
+ fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
+ expect(screen.queryByRole('dialog', { name: 'Delete agent' })).not.toBeInTheDocument();
+ expect(deleteAgent).not.toHaveBeenCalled();
+
+ fireEvent.click(screen.getByRole('button', { name: 'Actions for release-notes-writer' }));
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Delete' }));
fireEvent.click(screen.getByRole('button', { name: 'Delete' }));
await waitFor(() => {
diff --git a/packages/trueforge-ui/test/atoms/AgentsLibrary.test.tsx b/packages/trueforge-ui/test/atoms/AgentsLibrary.test.tsx
index d127739ce..48d6bbf4e 100644
--- a/packages/trueforge-ui/test/atoms/AgentsLibrary.test.tsx
+++ b/packages/trueforge-ui/test/atoms/AgentsLibrary.test.tsx
@@ -308,7 +308,7 @@ describe('AgentsLibrary', () => {
expect(screen.getByRole('heading', { name: 'Agents' })).toBeInTheDocument();
});
- it('deletes an agent after confirm and stays on the library', async () => {
+ it('deletes an agent only after the confirmation dialog is accepted', async () => {
const deleteAgent = vi.fn(async () => {});
const server = createMockAgentUIServer({
searchAgents: vi.fn(async () => [
@@ -331,6 +331,15 @@ describe('AgentsLibrary', () => {
fireEvent.click(screen.getByRole('menuitem', { name: 'Delete' }));
expect(screen.getByRole('dialog', { name: 'Delete agent' })).toBeInTheDocument();
+ expect(screen.getByText(/including any schedules for this agent/)).toBeInTheDocument();
+ expect(deleteAgent).not.toHaveBeenCalled();
+
+ fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
+ expect(screen.queryByRole('dialog', { name: 'Delete agent' })).not.toBeInTheDocument();
+ expect(deleteAgent).not.toHaveBeenCalled();
+
+ fireEvent.click(screen.getByRole('button', { name: 'Actions for writer' }));
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Delete' }));
fireEvent.click(screen.getByRole('button', { name: 'Delete' }));
await waitFor(() => {
diff --git a/packages/trueforge-ui/test/atoms/SessionsPage.test.tsx b/packages/trueforge-ui/test/atoms/SessionsPage.test.tsx
index f79bd3cb7..0350033d3 100644
--- a/packages/trueforge-ui/test/atoms/SessionsPage.test.tsx
+++ b/packages/trueforge-ui/test/atoms/SessionsPage.test.tsx
@@ -1,11 +1,17 @@
// @vitest-environment jsdom
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
-import { afterEach, describe, expect, it, vi } from 'vitest';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { SessionsPage } from '@/atoms/agent-details/SessionsPage.js';
import { ServerProvider } from '@/server/ServerContext.js';
import { ShellModeProvider } from '@/server/ShellModeContext.js';
-import type { Session, SessionEventItem, SessionListEntry } from '@/server/types.js';
+import type {
+ ListPermissionsResponse,
+ PermissionsServer,
+ Session,
+ SessionEventItem,
+ SessionListEntry,
+} from '@/server/types.js';
import { SlotsProvider } from '@/theme/SlotsProvider.js';
import { DEFAULT_SESSION_TIME_WINDOW_MS, SESSION_TIME_BUFFER_MS } from '@/utils/sessionShareUrl.js';
import { toDateTimeLocalValue } from '@/utils/sessionTimePresets.js';
@@ -36,6 +42,40 @@ type ListSessionsRequest = {
endTimestamp?: string;
};
+const originalShowModal = Object.getOwnPropertyDescriptor(HTMLDialogElement.prototype, 'showModal');
+const originalClose = Object.getOwnPropertyDescriptor(HTMLDialogElement.prototype, 'close');
+
+beforeEach(() => {
+ Object.defineProperty(HTMLDialogElement.prototype, 'showModal', {
+ configurable: true,
+ value: function showModal(this: HTMLDialogElement) {
+ this.open = true;
+ },
+ });
+ Object.defineProperty(HTMLDialogElement.prototype, 'close', {
+ configurable: true,
+ value: function close(this: HTMLDialogElement) {
+ this.open = false;
+ this.dispatchEvent(new Event('close'));
+ },
+ });
+});
+
+afterEach(() => {
+ vi.restoreAllMocks();
+ window.history.replaceState(null, '', '/');
+ if (originalShowModal === undefined) {
+ Reflect.deleteProperty(HTMLDialogElement.prototype, 'showModal');
+ } else {
+ Object.defineProperty(HTMLDialogElement.prototype, 'showModal', originalShowModal);
+ }
+ if (originalClose === undefined) {
+ Reflect.deleteProperty(HTMLDialogElement.prototype, 'close');
+ } else {
+ Object.defineProperty(HTMLDialogElement.prototype, 'close', originalClose);
+ }
+});
+
function renderPage({
listSessions = vi.fn(async (_req?: ListSessionsRequest) => ({ data: [namedRow, draftRow] })),
listSessionEvents = vi.fn(async () => ({ data: [] as SessionEventItem[] })),
@@ -46,10 +86,14 @@ function renderPage({
createdAt: namedRow.createdAt,
updatedAt: namedRow.updatedAt,
})),
+ deleteSession,
+ permissions,
}: {
listSessions?: (req?: ListSessionsRequest) => Promise<{ data: SessionListEntry[] }>;
listSessionEvents?: () => Promise<{ data: SessionEventItem[] }>;
getSession?: () => Promise<Session>;
+ deleteSession?: (req: { sessionId: string }) => Promise<void>;
+ permissions?: PermissionsServer;
} = {}) {
const server = createMockAgentUIServer({
getSession,
@@ -57,6 +101,8 @@ function renderPage({
{ agentId: 'agent-1', name: 'release-notes-writer', agentSpec: { model: { name: 'openai/gpt-5.1' } } },
]),
sessions: { getAgent: vi.fn(), getCodeSnippets: vi.fn(), listSessions, listSessionEvents },
+ ...(deleteSession == null ? {} : { deleteSession }),
+ ...(permissions == null ? {} : { permissions }),
});
render(
<SlotsProvider>
@@ -67,15 +113,10 @@ function renderPage({
</ServerProvider>
</SlotsProvider>,
);
- return { listSessions, listSessionEvents, getSession };
+ return { listSessions, listSessionEvents, getSession, deleteSession };
}
describe('SessionsPage', () => {
- afterEach(() => {
- vi.restoreAllMocks();
- window.history.replaceState(null, '', '/');
- });
-
it('lists all user sessions without agent_id and applies the default time window', async () => {
const { listSessions } = renderPage();
expect(await screen.findByRole('heading', { name: 'Agent Sessions' })).toBeInTheDocument();
@@ -201,4 +242,47 @@ describe('SessionsPage', () => {
expect(resizer.querySelector('.w-px')).toBeInTheDocument();
expect(screen.getByRole('heading', { name: 'Named session' })).toBeInTheDocument();
});
+
+ it('deletes only after the confirmation dialog is accepted', async () => {
+ const deleteSession = vi.fn(async () => undefined);
+ renderPage({ deleteSession });
+
+ fireEvent.click(await screen.findByRole('button', { name: 'Actions for Named session' }));
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Delete' }));
+
+ expect(screen.getByRole('dialog', { name: 'Delete session' })).toBeInTheDocument();
+ expect(deleteSession).not.toHaveBeenCalled();
+
+ fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
+ expect(screen.queryByRole('dialog', { name: 'Delete session' })).not.toBeInTheDocument();
+ expect(deleteSession).not.toHaveBeenCalled();
+
+ fireEvent.click(screen.getByRole('button', { name: 'Actions for Named session' }));
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Delete' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Delete' }));
+
+ await waitFor(() => {
+ expect(deleteSession).toHaveBeenCalledWith({ sessionId: 'sess-1' });
+ });
+ expect(screen.queryByText('Named session')).not.toBeInTheDocument();
+ expect(screen.getByText('Draft session')).toBeInTheDocument();
+ });
+
+ it('disables Delete without session DELETE permission', async () => {
+ const deleteSession = vi.fn(async () => undefined);
+ renderPage({
+ deleteSession,
+ permissions: {
+ listPermissions: vi.fn(async (): Promise<ListPermissionsResponse> => ({
+ data: { type: 'session', permissions: { 'sess-1': [], 'sess-draft': ['DELETE'] } },
+ })),
+ },
+ });
+
+ fireEvent.click(await screen.findByRole('button', { name: 'Actions for Named session' }));
+ await waitFor(() => {
+ expect(screen.getByRole('menuitem', { name: 'Delete' })).toBeDisabled();
+ });
+ expect(deleteSession).not.toHaveBeenCalled();
+ });
});