Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

refactor(frontend): per-page headers for settings, extract SettingsSidebar

Sergey Kozyrenko73c5500bb23b
diff --git a/frontend/src/components/layouts/settings-layout.tsx b/frontend/src/components/layouts/settings-layout.tsx
index 4ef13ef0..603716e0 100644
--- a/frontend/src/components/layouts/settings-layout.tsx
+++ b/frontend/src/components/layouts/settings-layout.tsx
@@ -1,182 +1,17 @@
-import { ArrowLeft, FileText, Key, Plug, Settings as SettingsIcon, User } from 'lucide-react';
-import { useMemo, useState } from 'react';
-import { NavLink, Outlet, useLocation, useParams } from 'react-router-dom';
+import { Outlet } from 'react-router-dom';
-import { Separator } from '@/components/ui/separator';
-import {
- Sidebar,
- SidebarContent,
- SidebarFooter,
- SidebarGroup,
- SidebarGroupContent,
- SidebarHeader,
- SidebarInset,
- SidebarMenu,
- SidebarMenuButton,
- SidebarMenuItem,
- SidebarProvider,
- SidebarTrigger,
-} from '@/components/ui/sidebar';
-import { routes } from '@/lib/routes';
-import { getSafeReturnUrl } from '@/lib/utils/auth';
-
-export interface MenuItem {
- icon?: React.ReactNode;
- id: string;
- path: string;
- title: string;
-}
-
-interface SettingsSidebarMenuItemProps {
- item: MenuItem;
-}
-
-const menuItems: readonly MenuItem[] = [
- {
- icon: <User className="size-4" />,
- id: 'account',
- path: routes.settings.account,
- title: 'Account',
- },
- {
- icon: <Plug className="size-4" />,
- id: 'providers',
- path: routes.settings.providers,
- title: 'Providers',
- },
- {
- icon: <FileText className="size-4" />,
- id: 'prompts',
- path: routes.settings.prompts,
- title: 'Prompts',
- },
- {
- icon: <Key className="size-4" />,
- id: 'api-tokens',
- path: routes.settings.apiTokens,
- title: 'API Tokens',
- },
-] as const;
-
-function SettingsHeader() {
- const location = useLocation();
- const params = useParams();
-
- const title = useMemo(() => {
- const path = location.pathname;
-
- if (path === '/settings/providers/new') {
- return 'Create Provider';
- }
-
- if (path.startsWith('/settings/providers/') && params.providerId && params.providerId !== 'new') {
- return 'Edit Provider';
- }
-
- if (path === '/settings/prompts/new') {
- return 'Create Prompt';
- }
-
- if (path.startsWith('/settings/prompts/') && params.promptId && params.promptId !== 'new') {
- return 'Edit Prompt';
- }
-
- const activeItem = menuItems.find((item) => path.startsWith(item.path));
-
- return activeItem?.title ?? 'Settings';
- }, [location.pathname, params]);
-
- return (
- <header className="flex h-16 shrink-0 items-center gap-2 border-b px-4">
- <SidebarTrigger className="-ml-1" />
- <Separator
- className="mr-2 h-4"
- orientation="vertical"
- />
- <h1 className="text-lg font-semibold">{title}</h1>
- </header>
- );
-}
+import { SettingsSidebar } from '@/components/layouts/settings-sidebar';
+import { SidebarInset, SidebarProvider } from '@/components/ui/sidebar';
function SettingsLayout() {
- const location = useLocation();
- const [returnUrl] = useState(() =>
- getSafeReturnUrl((location.state as null | { from?: string })?.from ?? null, routes.flows),
- );
-
return (
<SidebarProvider>
- <div className="flex h-screen w-full overflow-hidden">
- <SettingsSidebar returnUrl={returnUrl} />
- <SidebarInset className="flex flex-1 flex-col">
- <SettingsHeader />
- <main className="min-h-0 flex-1 overflow-auto p-4">
- <Outlet />
- </main>
- </SidebarInset>
- </div>
+ <SettingsSidebar />
+ <SidebarInset>
+ <Outlet />
+ </SidebarInset>
</SidebarProvider>
);
}
-function SettingsSidebar({ returnUrl }: { returnUrl: string }) {
- return (
- <Sidebar collapsible="icon">
- <SidebarHeader>
- <SidebarMenu>
- <SidebarMenuItem className="flex items-center gap-2">
- <div className="flex aspect-square size-8 items-center justify-center">
- <SettingsIcon className="size-6" />
- </div>
- <div className="grid flex-1 text-left leading-tight">
- <span className="truncate font-semibold">Settings</span>
- </div>
- </SidebarMenuItem>
- </SidebarMenu>
- </SidebarHeader>
- <SidebarContent>
- <SidebarGroup>
- <SidebarGroupContent>
- <SidebarMenu>
- {menuItems.map((item) => (
- <SettingsSidebarMenuItem
- item={item}
- key={item.id}
- />
- ))}
- </SidebarMenu>
- </SidebarGroupContent>
- </SidebarGroup>
- </SidebarContent>
- <SidebarFooter>
- <SidebarMenuButton asChild>
- <NavLink to={returnUrl}>
- <ArrowLeft className="size-4" />
- Back to App
- </NavLink>
- </SidebarMenuButton>
- </SidebarFooter>
- </Sidebar>
- );
-}
-
-function SettingsSidebarMenuItem({ item }: SettingsSidebarMenuItemProps) {
- const location = useLocation();
- const isActive = location.pathname.startsWith(item.path);
-
- return (
- <SidebarMenuItem>
- <SidebarMenuButton
- asChild
- isActive={isActive}
- >
- <NavLink to={item.path}>
- {item.icon}
- {item.title}
- </NavLink>
- </SidebarMenuButton>
- </SidebarMenuItem>
- );
-}
-
export default SettingsLayout;
diff --git a/frontend/src/components/layouts/settings-page-header.tsx b/frontend/src/components/layouts/settings-page-header.tsx
new file mode 100644
index 00000000..a64dee15
--- /dev/null
+++ b/frontend/src/components/layouts/settings-page-header.tsx
@@ -0,0 +1,34 @@
+import type { ReactNode } from 'react';
+
+import { Breadcrumb, BreadcrumbItem, BreadcrumbList, BreadcrumbPage } from '@/components/ui/breadcrumb';
+import { Separator } from '@/components/ui/separator';
+import { SidebarTrigger } from '@/components/ui/sidebar';
+
+interface SettingsPageHeaderProps {
+ actions?: ReactNode;
+ icon?: ReactNode;
+ title: ReactNode;
+}
+
+export function SettingsPageHeader({ actions, icon, title }: SettingsPageHeaderProps) {
+ return (
+ <header className="bg-background sticky top-0 z-10 flex h-12 w-full shrink-0 items-center gap-2 border-b transition-[width,height] ease-linear group-has-data-[collapsible=icon]/sidebar-wrapper:h-12">
+ <div className="flex min-w-0 flex-1 items-center gap-2 px-4">
+ <SidebarTrigger className="-ml-1 shrink-0" />
+ <Separator
+ className="h-4 shrink-0"
+ orientation="vertical"
+ />
+ <Breadcrumb className="min-w-0 flex-1">
+ <BreadcrumbList className="min-w-0 flex-nowrap">
+ <BreadcrumbItem className="min-w-0 gap-2">
+ {icon}
+ <BreadcrumbPage className="min-w-0 truncate">{title}</BreadcrumbPage>
+ </BreadcrumbItem>
+ </BreadcrumbList>
+ </Breadcrumb>
+ </div>
+ {actions ? <div className="flex shrink-0 items-center gap-2 px-4">{actions}</div> : null}
+ </header>
+ );
+}
diff --git a/frontend/src/components/layouts/settings-layout.test.tsx b/frontend/src/components/layouts/settings-sidebar.test.tsx
similarity index 55%
rename from frontend/src/components/layouts/settings-layout.test.tsx
rename to frontend/src/components/layouts/settings-sidebar.test.tsx
index 3d78649f..3a443218 100644
--- a/frontend/src/components/layouts/settings-layout.test.tsx
+++ b/frontend/src/components/layouts/settings-sidebar.test.tsx
@@ -3,25 +3,25 @@ import userEvent from '@testing-library/user-event';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
import { describe, expect, it } from 'vitest';
-import SettingsLayout from './settings-layout';
+import { SidebarProvider } from '@/components/ui/sidebar';
-function renderAt(entry: { pathname: string; state?: unknown }) {
+import { SettingsSidebar } from './settings-sidebar';
+
+function renderSidebar(entry: { pathname: string; state?: unknown }) {
return render(
<MemoryRouter initialEntries={[entry]}>
+ <SidebarProvider>
+ <SettingsSidebar />
+ </SidebarProvider>
<Routes>
<Route
- element={<SettingsLayout />}
- path="/settings"
- >
- <Route
- element={<div>account</div>}
- path="account"
- />
- <Route
- element={<div>providers</div>}
- path="providers"
- />
- </Route>
+ element={<div>account</div>}
+ path="/settings/account"
+ />
+ <Route
+ element={<div>providers</div>}
+ path="/settings/providers"
+ />
</Routes>
</MemoryRouter>,
);
@@ -29,22 +29,22 @@ function renderAt(entry: { pathname: string; state?: unknown }) {
const backToApp = () => screen.getByRole('link', { name: /Back to App/ });
-describe('SettingsLayout "Back to App"', () => {
+describe('SettingsSidebar "Back to App"', () => {
it('returns to the page the user came from', () => {
- renderAt({ pathname: '/settings/account', state: { from: '/dashboard' } });
+ renderSidebar({ pathname: '/settings/account', state: { from: '/dashboard' } });
expect(backToApp()).toHaveAttribute('href', '/dashboard');
});
it('falls back to /flows when there is no origin', () => {
- renderAt({ pathname: '/settings/account' });
+ renderSidebar({ pathname: '/settings/account' });
expect(backToApp()).toHaveAttribute('href', '/flows');
});
it('keeps the origin after switching settings sub-tabs (which drop location.state)', async () => {
const user = userEvent.setup();
- renderAt({ pathname: '/settings/account', state: { from: '/dashboard' } });
+ renderSidebar({ pathname: '/settings/account', state: { from: '/dashboard' } });
await user.click(screen.getByRole('link', { name: 'Providers' }));
diff --git a/frontend/src/components/layouts/settings-sidebar.tsx b/frontend/src/components/layouts/settings-sidebar.tsx
new file mode 100644
index 00000000..1a21e66e
--- /dev/null
+++ b/frontend/src/components/layouts/settings-sidebar.tsx
@@ -0,0 +1,122 @@
+import type { ReactNode } from 'react';
+
+import { ArrowLeft, FileText, Key, Plug, Settings as SettingsIcon, User } from 'lucide-react';
+import { useState } from 'react';
+import { NavLink, useLocation } from 'react-router-dom';
+
+import {
+ Sidebar,
+ SidebarContent,
+ SidebarFooter,
+ SidebarGroup,
+ SidebarGroupContent,
+ SidebarHeader,
+ SidebarMenu,
+ SidebarMenuButton,
+ SidebarMenuItem,
+} from '@/components/ui/sidebar';
+import { routes } from '@/lib/routes';
+import { getSafeReturnUrl } from '@/lib/utils/auth';
+
+export interface MenuItem {
+ icon?: ReactNode;
+ id: string;
+ path: string;
+ title: string;
+}
+
+interface SettingsSidebarMenuItemProps {
+ item: MenuItem;
+}
+
+const menuItems: readonly MenuItem[] = [
+ {
+ icon: <User className="size-4" />,
+ id: 'account',
+ path: routes.settings.account,
+ title: 'Account',
+ },
+ {
+ icon: <Plug className="size-4" />,
+ id: 'providers',
+ path: routes.settings.providers,
+ title: 'Providers',
+ },
+ {
+ icon: <FileText className="size-4" />,
+ id: 'prompts',
+ path: routes.settings.prompts,
+ title: 'Prompts',
+ },
+ {
+ icon: <Key className="size-4" />,
+ id: 'api-tokens',
+ path: routes.settings.apiTokens,
+ title: 'API Tokens',
+ },
+] as const;
+
+export function SettingsSidebar() {
+ const location = useLocation();
+ const [returnUrl] = useState(() =>
+ getSafeReturnUrl((location.state as null | { from?: string })?.from ?? null, routes.flows),
+ );
+
+ return (
+ <Sidebar collapsible="icon">
+ <SidebarHeader>
+ <SidebarMenu>
+ <SidebarMenuItem className="flex items-center gap-2">
+ <div className="flex aspect-square size-8 items-center justify-center">
+ <SettingsIcon className="size-6" />
+ </div>
+ <div className="grid flex-1 text-left leading-tight">
+ <span className="truncate font-semibold">Settings</span>
+ </div>
+ </SidebarMenuItem>
+ </SidebarMenu>
+ </SidebarHeader>
+ <SidebarContent>
+ <SidebarGroup>
+ <SidebarGroupContent>
+ <SidebarMenu>
+ {menuItems.map((item) => (
+ <SettingsSidebarMenuItem
+ item={item}
+ key={item.id}
+ />
+ ))}
+ </SidebarMenu>
+ </SidebarGroupContent>
+ </SidebarGroup>
+ </SidebarContent>
+ <SidebarFooter>
+ <SidebarMenuButton asChild>
+ <NavLink to={returnUrl}>
+ <ArrowLeft className="size-4" />
+ Back to App
+ </NavLink>
+ </SidebarMenuButton>
+ </SidebarFooter>
+ </Sidebar>
+ );
+}
+
+function SettingsSidebarMenuItem({ item }: SettingsSidebarMenuItemProps) {
+ const location = useLocation();
+ const isActive = location.pathname.startsWith(item.path);
+
+ return (
+ <SidebarMenuItem>
+ <SidebarMenuButton
+ asChild
+ isActive={isActive}
+ >
+ <NavLink to={item.path}>
+ {item.icon}
+ {item.title}
+ </NavLink>
+ </SidebarMenuButton>
+ </SidebarMenuItem>
+ );
+}
diff --git a/frontend/src/pages/settings/settings-account.test.tsx b/frontend/src/pages/settings/settings-account.test.tsx
index c0356b5e..6d672100 100644
--- a/frontend/src/pages/settings/settings-account.test.tsx
+++ b/frontend/src/pages/settings/settings-account.test.tsx
@@ -8,11 +8,22 @@ vi.mock('@/providers/user-provider', () => ({
useUser: () => ({ authInfo: authState.value, patchUser: vi.fn(), refreshAuthInfo: vi.fn() }),
}));
+import { SidebarProvider } from '@/components/ui/sidebar';
+
import SettingsAccount from './settings-account';
const localUser = { created_at: '2026-01-15T00:00:00Z', mail: '[email protected]', name: 'Local User', type: 'local' };
const githubUser = { mail: '[email protected]', name: 'GH User', provider: 'github', type: 'oauth' };
+// SettingsAccount renders its own SettingsPageHeader (a SidebarTrigger), which
+// needs SidebarProvider context — the real app always mounts it inside one.
+const renderAccount = () =>
+ render(
+ <SidebarProvider>
+ <SettingsAccount />
+ </SidebarProvider>,
+ );
+
beforeEach(() => {
authState.value = null;
});
@@ -25,7 +36,7 @@ describe('SettingsAccount gating', () => {
it('exposes name, email and password for a local account', () => {
authState.value = { user: localUser };
- render(<SettingsAccount />);
+ renderAccount();
expect(screen.getByText('Local account')).toBeInTheDocument();
expect(screen.getByText('Password')).toBeInTheDocument();
@@ -39,14 +50,14 @@ describe('SettingsAccount gating', () => {
['𠀋 Lin', '𠀋'],
])('uses the first whole code point of %s as the avatar initial', (name, expected) => {
authState.value = { user: { mail: '[email protected]', name, type: 'local' } };
- render(<SettingsAccount />);
+ renderAccount();
expect(screen.getByText(expected)).toBeInTheDocument();
});
it('hides password and email editing for an OAuth account but keeps the name editable', () => {
authState.value = { user: githubUser };
- render(<SettingsAccount />);
+ renderAccount();
expect(screen.getByText('GitHub')).toBeInTheDocument();
expect(screen.getByText('Linked from your GitHub.')).toBeInTheDocument();
@@ -56,19 +67,19 @@ describe('SettingsAccount gating', () => {
it('labels an unknown provider by its raw name, then a generic fallback', () => {
authState.value = { user: { mail: '[email protected]', name: 'X', provider: 'gitlab', type: 'oauth' } };
- const { unmount } = render(<SettingsAccount />);
+ const { unmount } = renderAccount();
expect(screen.getByText('gitlab')).toBeInTheDocument();
unmount();
authState.value = { user: { mail: '[email protected]', name: 'Y', type: 'oauth' } };
- render(<SettingsAccount />);
+ renderAccount();
expect(screen.getByText('OAuth account')).toBeInTheDocument();
});
it('opens the name form on Change for an OAuth user', async () => {
const user = userEvent.setup();
authState.value = { user: githubUser };
- render(<SettingsAccount />);
+ renderAccount();
await user.click(screen.getByRole('button', { name: 'Change' }));
@@ -78,7 +89,7 @@ describe('SettingsAccount gating', () => {
it('keeps an open section and its draft when another section is opened', async () => {
const user = userEvent.setup();
authState.value = { user: localUser };
- render(<SettingsAccount />);
+ renderAccount();
const [firstChangeButton] = screen.getAllByRole('button', { name: 'Change' });
diff --git a/frontend/src/pages/settings/settings-account.tsx b/frontend/src/pages/settings/settings-account.tsx
index 50b4f0c2..6916778c 100644
--- a/frontend/src/pages/settings/settings-account.tsx
+++ b/frontend/src/pages/settings/settings-account.tsx
@@ -3,6 +3,7 @@ import { enUS } from 'date-fns/locale';
import { Lock, Mail, User } from 'lucide-react';
import { useState } from 'react';
+import { SettingsPageHeader } from '@/components/layouts/settings-page-header';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
@@ -49,94 +50,67 @@ function SettingsAccount() {
: 'OAuth account';
return (
- <div className="mx-auto flex max-w-2xl flex-col gap-4">
- <Card>
- <CardHeader className="flex-row items-center gap-4">
- <div className="bg-muted text-foreground flex size-12 shrink-0 items-center justify-center rounded-lg text-lg font-semibold">
- {initial}
- </div>
- <div className="flex flex-1 flex-col gap-0.5">
- <CardTitle className="truncate">{displayName}</CardTitle>
- {memberSince && <CardDescription>Member since {memberSince}</CardDescription>}
- </div>
- <Badge variant="secondary">{accountLabel}</Badge>
- </CardHeader>
- </Card>
-
- <Card>
- <CardHeader className="flex-row items-start justify-between gap-4">
- <div className="grid gap-1.5">
- <CardTitle>Display name</CardTitle>
- <CardDescription>The name shown across the app.</CardDescription>
- </div>
- {!editingSections.has('name') && (
- <Button
- onClick={() => startEditing('name')}
- size="sm"
- variant="outline"
- >
- Change
- </Button>
- )}
- </CardHeader>
- <CardContent>
- {editingSections.has('name') ? (
- <NameChangeForm
- onCancel={() => stopEditing('name')}
- onSuccess={() => stopEditing('name')}
- />
- ) : (
- <div className="text-muted-foreground flex items-center gap-2 text-sm">
- <User className="size-4 shrink-0" />
- <span className="truncate">{displayName}</span>
+ <>
+ <SettingsPageHeader
+ icon={<User className="size-4 shrink-0" />}
+ title="Account"
+ />
+ <div className="mx-auto flex w-full max-w-2xl flex-col gap-4 p-4">
+ <Card>
+ <CardHeader className="flex-row items-center gap-4">
+ <div className="bg-muted text-foreground flex size-12 shrink-0 items-center justify-center rounded-lg text-lg font-semibold">
+ {initial}
</div>
- )}
- </CardContent>
- </Card>
+ <div className="flex flex-1 flex-col gap-0.5">
+ <CardTitle className="truncate">{displayName}</CardTitle>
+ {memberSince && <CardDescription>Member since {memberSince}</CardDescription>}
+ </div>
+ <Badge variant="secondary">{accountLabel}</Badge>
+ </CardHeader>
+ </Card>
- <Card>
- <CardHeader className="flex-row items-start justify-between gap-4">
- <div className="grid gap-1.5">
- <CardTitle>Email address</CardTitle>
- <CardDescription>
- {isLocal ? 'The email you use to sign in.' : `Linked from your ${accountLabel}.`}
- </CardDescription>
- </div>
- {isLocal && !editingSections.has('email') && (
- <Button
- onClick={() => startEditing('email')}
- size="sm"
- variant="outline"
- >
- Change
- </Button>
- )}
- </CardHeader>
- <CardContent>
- {isLocal && editingSections.has('email') ? (
- <EmailChangeForm
- onCancel={() => stopEditing('email')}
- onSuccess={() => stopEditing('email')}
- />
- ) : (
- <div className="text-muted-foreground flex items-center gap-2 text-sm">
- <Mail className="size-4 shrink-0" />
- <span className="truncate">{user.mail}</span>
+ <Card>
+ <CardHeader className="flex-row items-start justify-between gap-4">
+ <div className="grid gap-1.5">
+ <CardTitle>Display name</CardTitle>
+ <CardDescription>The name shown across the app.</CardDescription>
</div>
- )}
- </CardContent>
- </Card>
+ {!editingSections.has('name') && (
+ <Button
+ onClick={() => startEditing('name')}
+ size="sm"
+ variant="outline"
+ >
+ Change
+ </Button>
+ )}
+ </CardHeader>
+ <CardContent>
+ {editingSections.has('name') ? (
+ <NameChangeForm
+ onCancel={() => stopEditing('name')}
+ onSuccess={() => stopEditing('name')}
+ />
+ ) : (
+ <div className="text-muted-foreground flex items-center gap-2 text-sm">
+ <User className="size-4 shrink-0" />
+ <span className="truncate">{displayName}</span>
+ </div>
+ )}
+ </CardContent>
+ </Card>
- {isLocal && (
<Card>
<CardHeader className="flex-row items-start justify-between gap-4">
<div className="grid gap-1.5">
- <CardTitle>Password</CardTitle>
- <CardDescription>Change your account password.</CardDescription>
+ <CardTitle>Email address</CardTitle>
+ <CardDescription>
+ {isLocal ? 'The email you use to sign in.' : `Linked from your ${accountLabel}.`}
+ </CardDescription>
</div>
- {!editingSections.has('password') && (
+ {isLocal && !editingSections.has('email') && (
<Button
- onClick={() => startEditing('password')}
+ onClick={() => startEditing('email')}
size="sm"
variant="outline"
>
@@ -145,22 +119,55 @@ function SettingsAccount() {
)}
</CardHeader>
<CardContent>
- {editingSections.has('password') ? (
- <PasswordChangeForm
- buttonSize="sm"
- onCancel={() => stopEditing('password')}
- onSuccess={() => stopEditing('password')}
+ {isLocal && editingSections.has('email') ? (
+ <EmailChangeForm
+ onCancel={() => stopEditing('email')}
+ onSuccess={() => stopEditing('email')}
/>
) : (
<div className="text-muted-foreground flex items-center gap-2 text-sm">
- <Lock className="size-4 shrink-0" />
- <span>••••••••••••</span>
+ <Mail className="size-4 shrink-0" />
+ <span className="truncate">{user.mail}</span>
</div>
)}
</CardContent>
</Card>
- )}
- </div>
+
+ {isLocal && (
+ <Card>
+ <CardHeader className="flex-row items-start justify-between gap-4">
+ <div className="grid gap-1.5">
+ <CardTitle>Password</CardTitle>
+ <CardDescription>Change your account password.</CardDescription>
+ </div>
+ {!editingSections.has('password') && (
+ <Button
+ onClick={() => startEditing('password')}
+ size="sm"
+ variant="outline"
+ >
+ Change
+ </Button>
+ )}
+ </CardHeader>
+ <CardContent>
+ {editingSections.has('password') ? (
+ <PasswordChangeForm
+ buttonSize="sm"
+ onCancel={() => stopEditing('password')}
+ onSuccess={() => stopEditing('password')}
+ />
+ ) : (
+ <div className="text-muted-foreground flex items-center gap-2 text-sm">
+ <Lock className="size-4 shrink-0" />
+ <span>••••••••••••</span>
+ </div>
+ )}
+ </CardContent>
+ </Card>
+ )}
+ </div>
+ </>
);
}
diff --git a/frontend/src/pages/settings/settings-api-tokens.tsx b/frontend/src/pages/settings/settings-api-tokens.tsx
index 0c16cc70..83286702 100644
--- a/frontend/src/pages/settings/settings-api-tokens.tsx
+++ b/frontend/src/pages/settings/settings-api-tokens.tsx
@@ -25,6 +25,7 @@ import * as z from 'zod';
import type { ApiTokenFragmentFragment } from '@/graphql/types';
+import { SettingsPageHeader } from '@/components/layouts/settings-page-header';
import ConfirmationDialog from '@/components/shared/confirmation-dialog';
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
import { Badge } from '@/components/ui/badge';
@@ -840,29 +841,42 @@ function SettingsAPITokens() {
[deletingToken, handleCopyTokenId, handleDeleteDialogOpen, handleEdit, isDeleteLoading],
);
+ const pageHeader = (
+ <SettingsPageHeader
+ icon={<Key className="size-4 shrink-0" />}
+ title="API Tokens"
+ />
+ );
+
if (isLoading) {
return (
- <div className="flex flex-col gap-4">
- <SettingsAPITokensHeader onCreateClick={handleCreateNew} />
- <StatusCard
- description="Please wait while we fetch your API tokens"
- icon={<Loader2 className="text-muted-foreground size-16 animate-spin" />}
- title="Loading tokens..."
- />
- </div>
+ <>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-4 p-4">
+ <SettingsAPITokensHeader onCreateClick={handleCreateNew} />
+ <StatusCard
+ description="Please wait while we fetch your API tokens"
+ icon={<Loader2 className="text-muted-foreground size-16 animate-spin" />}
+ title="Loading tokens..."
+ />
+ </div>
+ </>
);
}
if (error) {
return (
- <div className="flex flex-col gap-4">
- <SettingsAPITokensHeader onCreateClick={handleCreateNew} />
- <Alert variant="destructive">
- <AlertCircle className="size-4" />
- <AlertTitle>Error loading tokens</AlertTitle>
- <AlertDescription>{error.message}</AlertDescription>
- </Alert>
- </div>
+ <>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-4 p-4">
+ <SettingsAPITokensHeader onCreateClick={handleCreateNew} />
+ <Alert variant="destructive">
+ <AlertCircle className="size-4" />
+ <AlertTitle>Error loading tokens</AlertTitle>
+ <AlertDescription>{error.message}</AlertDescription>
+ </Alert>
+ </div>
+ </>
);
}
@@ -870,109 +884,115 @@ function SettingsAPITokens() {
if (tokens.length === 0 && !creatingToken) {
return (
- <div className="flex flex-col gap-4">
- <SettingsAPITokensHeader onCreateClick={handleCreateNew} />
- <StatusCard
- action={
- <Button
- onClick={handleCreateNew}
- variant="secondary"
- >
- <Plus className="size-4" />
- Create Token
- </Button>
- }
- description="Create your first API token to access PentAGI programmatically"
- icon={<Key className="text-muted-foreground size-8" />}
- title="No API tokens configured"
- />
- </div>
+ <>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-4 p-4">
+ <SettingsAPITokensHeader onCreateClick={handleCreateNew} />
+ <StatusCard
+ action={
+ <Button
+ onClick={handleCreateNew}
+ variant="secondary"
+ >
+ <Plus className="size-4" />
+ Create Token
+ </Button>
+ }
+ description="Create your first API token to access PentAGI programmatically"
+ icon={<Key className="text-muted-foreground size-8" />}
+ title="No API tokens configured"
+ />
+ </div>
+ </>
);
}
return (
- <div className="flex flex-col gap-4">
- <SettingsAPITokensHeader onCreateClick={handleCreateNew} />
-
- {(createError || updateError || deleteError || deleteErrorMessage) && (
- <Alert variant="destructive">
- <AlertCircle className="size-4" />
- <AlertTitle>Error</AlertTitle>
- <AlertDescription>
- {createError?.message || updateError?.message || deleteError?.message || deleteErrorMessage}
- </AlertDescription>
- </Alert>
- )}
-
- <DataTable<APIToken>
- columns={columns}
- data={creatingToken ? [createNewTokenPlaceholder, ...tokens] : tokens}
- empty={{ entityName: 'API tokens' }}
- filterPlaceholder="Filter tokens..."
- filterValue={filter}
- onFilterChange={setFilter}
- onPageChange={handlePageChange}
- pageIndex={currentPage}
- renderRowContextMenu={renderRowContextMenu}
- />
-
- <Dialog
- onOpenChange={setShowTokenDialog}
- open={showTokenDialog}
- >
- <DialogContent>
- <DialogHeader>
- <DialogTitle>API Token Created</DialogTitle>
- <DialogDescription>
- Copy this token now. You won't be able to see it again for security reasons.
- </DialogDescription>
- </DialogHeader>
- <div className="bg-muted rounded p-4">
- <code className="text-sm break-all">{tokenSecret}</code>
- </div>
- <div className="flex gap-2">
- <Button
- className="flex-1"
- onClick={async () => {
- if (tokenSecret) {
- const success = await copyToClipboard(tokenSecret);
-
- if (success) {
- toast.success('Token copied to clipboard');
- } else {
- toast.error('Failed to copy token to clipboard');
+ <>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-4 p-4">
+ <SettingsAPITokensHeader onCreateClick={handleCreateNew} />
+
+ {(createError || updateError || deleteError || deleteErrorMessage) && (
+ <Alert variant="destructive">
+ <AlertCircle className="size-4" />
+ <AlertTitle>Error</AlertTitle>
+ <AlertDescription>
+ {createError?.message || updateError?.message || deleteError?.message || deleteErrorMessage}
+ </AlertDescription>
+ </Alert>
+ )}
+
+ <DataTable<APIToken>
+ columns={columns}
+ data={creatingToken ? [createNewTokenPlaceholder, ...tokens] : tokens}
+ empty={{ entityName: 'API tokens' }}
+ filterPlaceholder="Filter tokens..."
+ filterValue={filter}
+ onFilterChange={setFilter}
+ onPageChange={handlePageChange}
+ pageIndex={currentPage}
+ renderRowContextMenu={renderRowContextMenu}
+ />
+
+ <Dialog
+ onOpenChange={setShowTokenDialog}
+ open={showTokenDialog}
+ >
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>API Token Created</DialogTitle>
+ <DialogDescription>
+ Copy this token now. You won't be able to see it again for security reasons.
+ </DialogDescription>
+ </DialogHeader>
+ <div className="bg-muted rounded p-4">
+ <code className="text-sm break-all">{tokenSecret}</code>
+ </div>
+ <div className="flex gap-2">
+ <Button
+ className="flex-1"
+ onClick={async () => {
+ if (tokenSecret) {
+ const success = await copyToClipboard(tokenSecret);
+
+ if (success) {
+ toast.success('Token copied to clipboard');
+ } else {
+ toast.error('Failed to copy token to clipboard');
+ }
}
- }
- }}
- variant="secondary"
- >
- <Copy className="size-4" />
- Copy Token
- </Button>
- <Button
- className="flex-1"
- onClick={() => {
- setShowTokenDialog(false);
- setTokenSecret(null);
- }}
- variant="outline"
- >
- Close
- </Button>
- </div>
- </DialogContent>
- </Dialog>
-
- <ConfirmationDialog
- cancelText="Cancel"
- confirmText="Delete"
- handleConfirm={() => handleDelete(deletingToken?.tokenId)}
- handleOpenChange={setIsDeleteDialogOpen}
- isOpen={isDeleteDialogOpen}
- itemName={deletingToken?.name || deletingToken?.tokenId}
- itemType="token"
- />
- </div>
+ }}
+ variant="secondary"
+ >
+ <Copy className="size-4" />
+ Copy Token
+ </Button>
+ <Button
+ className="flex-1"
+ onClick={() => {
+ setShowTokenDialog(false);
+ setTokenSecret(null);
+ }}
+ variant="outline"
+ >
+ Close
+ </Button>
+ </div>
+ </DialogContent>
+ </Dialog>
+
+ <ConfirmationDialog
+ cancelText="Cancel"
+ confirmText="Delete"
+ handleConfirm={() => handleDelete(deletingToken?.tokenId)}
+ handleOpenChange={setIsDeleteDialogOpen}
+ isOpen={isDeleteDialogOpen}
+ itemName={deletingToken?.name || deletingToken?.tokenId}
+ itemType="token"
+ />
+ </div>
+ </>
);
}
diff --git a/frontend/src/pages/settings/settings-prompt.tsx b/frontend/src/pages/settings/settings-prompt.tsx
index 57ffcb0d..c9811c5c 100644
--- a/frontend/src/pages/settings/settings-prompt.tsx
+++ b/frontend/src/pages/settings/settings-prompt.tsx
@@ -6,6 +6,7 @@ import {
CheckCircle,
Code,
FileDiff,
+ FileText,
Loader2,
RotateCcw,
Save,
@@ -35,6 +36,7 @@ import type {
type AgentPrompt = AgentPrompts;
type AgentPrompts = { human?: DefaultPrompt; system: DefaultPrompt };
+import { SettingsPageHeader } from '@/components/layouts/settings-page-header';
import ConfirmationDialog from '@/components/shared/confirmation-dialog';
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
import { Button } from '@/components/ui/button';
@@ -576,14 +578,25 @@ function SettingsPrompt() {
}
};
+ const isNew = promptId === 'new';
+ const pageHeader = (
+ <SettingsPageHeader
+ icon={<FileText className="size-4 shrink-0" />}
+ title={isNew ? 'Create Prompt' : 'Edit Prompt'}
+ />
+ );
+
if (loading) {
return (
<>
- <StatusCard
- description="Please wait while we fetch prompt information"
- icon={<Loader2 className="text-muted-foreground size-16 animate-spin" />}
- title="Loading prompt data..."
- />
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-4 p-4">
+ <StatusCard
+ description="Please wait while we fetch prompt information"
+ icon={<Loader2 className="text-muted-foreground size-16 animate-spin" />}
+ title="Loading prompt data..."
+ />
+ </div>
</>
);
}
@@ -591,11 +604,14 @@ function SettingsPrompt() {
if (error) {
return (
<>
- <Alert variant="destructive">
- <AlertCircle className="size-4" />
- <AlertTitle>Error loading prompt data</AlertTitle>
- <AlertDescription>{error.message}</AlertDescription>
- </Alert>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-4 p-4">
+ <Alert variant="destructive">
+ <AlertCircle className="size-4" />
+ <AlertTitle>Error loading prompt data</AlertTitle>
+ <AlertDescription>{error.message}</AlertDescription>
+ </Alert>
+ </div>
</>
);
}
@@ -603,13 +619,16 @@ function SettingsPrompt() {
if (!promptInfo) {
return (
<>
- <Alert variant="destructive">
- <AlertCircle className="size-4" />
- <AlertTitle>Prompt not found</AlertTitle>
- <AlertDescription>
- The prompt "{promptId}" could not be found or is not supported for editing.
- </AlertDescription>
- </Alert>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-4 p-4">
+ <Alert variant="destructive">
+ <AlertCircle className="size-4" />
+ <AlertTitle>Prompt not found</AlertTitle>
+ <AlertDescription>
+ The prompt "{promptId}" could not be found or is not supported for editing.
+ </AlertDescription>
+ </Alert>
+ </div>
</>
);
}
@@ -700,96 +719,57 @@ function SettingsPrompt() {
const mutationError = createError || updateError || deleteError || validateError || submitError;
return (
- <div className="flex flex-col gap-4">
- <div className="flex flex-col gap-2">
- <h2 className="flex items-center gap-2 text-lg font-semibold">
- {promptInfo.type === 'agent' ? (
- <Bot className="text-muted-foreground size-5" />
- ) : (
- <Wrench className="text-muted-foreground size-5" />
- )}
- {promptInfo.displayName}
- </h2>
+ <>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-4 p-4">
+ <div className="flex flex-col gap-2">
+ <h2 className="flex items-center gap-2 text-lg font-semibold">
+ {promptInfo.type === 'agent' ? (
+ <Bot className="text-muted-foreground size-5" />
+ ) : (
+ <Wrench className="text-muted-foreground size-5" />
+ )}
+ {promptInfo.displayName}
+ </h2>
- <div className="text-muted-foreground">
- {promptInfo.type === 'agent'
- ? 'Configure prompts for this AI agent'
- : 'Configure the prompt for this tool'}
+ <div className="text-muted-foreground">
+ {promptInfo.type === 'agent'
+ ? 'Configure prompts for this AI agent'
+ : 'Configure the prompt for this tool'}
+ </div>
</div>
- </div>
- <Tabs
- className="w-full"
- defaultValue="system"
- onValueChange={(value) => setActiveTab(value as 'human' | 'system')}
- >
- <TabsList>
- <TabsTrigger value="system">
- <div className="flex items-center gap-2">
- <Code className="size-4" />
- System Prompt
- </div>
- </TabsTrigger>
- {promptInfo.type === 'agent' && promptInfo.hasHuman && (
- <TabsTrigger value="human">
+ <Tabs
+ className="w-full"
+ defaultValue="system"
+ onValueChange={(value) => setActiveTab(value as 'human' | 'system')}
+ >
+ <TabsList>
+ <TabsTrigger value="system">
<div className="flex items-center gap-2">
- <User className="size-4" />
- Human Prompt
+ <Code className="size-4" />
+ System Prompt
</div>
</TabsTrigger>
- )}
- </TabsList>
-
- <TabsContent
- className="mt-4"
- value="system"
- >
- <Form {...systemForm}>
- <form
- className="flex flex-col gap-6"
- id="system-prompt-form"
- onSubmit={systemForm.handleSubmit(handleSystemSubmit)}
- >
- {/* Error Alert */}
- {mutationError && (
- <Alert variant="destructive">
- <AlertCircle className="size-4" />
- <AlertTitle>Error</AlertTitle>
- <AlertDescription>
- {typeof mutationError !== 'string' ? (
- mutationError.message
- ) : (
- <div className="whitespace-pre-line">{mutationError}</div>
- )}
- </AlertDescription>
- </Alert>
- )}
-
- {/* System Template Field */}
- <FormTextareaItem
- control={systemForm.control}
- disabled={isLoading}
- name="template"
- placeholder={
- promptInfo.type === 'tool'
- ? 'Enter the tool template...'
- : 'Enter the system prompt template...'
- }
- />
- </form>
- </Form>
- </TabsContent>
+ {promptInfo.type === 'agent' && promptInfo.hasHuman && (
+ <TabsTrigger value="human">
+ <div className="flex items-center gap-2">
+ <User className="size-4" />
+ Human Prompt
+ </div>
+ </TabsTrigger>
+ )}
+ </TabsList>
- {promptInfo.type === 'agent' && promptInfo.hasHuman && (
<TabsContent
- className="mt-6"
- value="human"
+ className="mt-4"
+ value="system"
>
- <Form {...humanForm}>
+ <Form {...systemForm}>
<form
className="flex flex-col gap-6"
- id="human-prompt-form"
- onSubmit={humanForm.handleSubmit(handleHumanSubmit)}
+ id="system-prompt-form"
+ onSubmit={systemForm.handleSubmit(handleSystemSubmit)}
>
{/* Error Alert */}
{mutationError && (
@@ -806,212 +786,254 @@ function SettingsPrompt() {
</Alert>
)}
- {/* Human Template Field */}
+ {/* System Template Field */}
<FormTextareaItem
- control={humanForm.control}
+ control={systemForm.control}
disabled={isLoading}
name="template"
- placeholder="Enter the human prompt template..."
+ placeholder={
+ promptInfo.type === 'tool'
+ ? 'Enter the tool template...'
+ : 'Enter the system prompt template...'
+ }
/>
</form>
</Form>
</TabsContent>
- )}
- </Tabs>
-
- {/* Sticky footer with variables and buttons */}
- <div className="bg-background sticky -bottom-4 -mx-4 mt-4 -mb-4 border-t p-4 shadow-lg">
- {/* Variables */}
- {variablesData && (
- <Variables
- currentTemplate={variablesData.currentTemplate}
- onVariableClick={handleVariableClickCallback}
- variables={variablesData.variables}
- />
- )}
-
- {/* Action buttons */}
- <div className="flex items-center">
- <div className="flex gap-2">
- {/* Reset button - only show when user has custom prompt */}
- {((activeTab === 'system' && promptInfo?.userSystemPrompt) ||
- (activeTab === 'human' && promptInfo?.userHumanPrompt)) && (
- <>
- <Button
- disabled={isLoading}
- onClick={handleReset}
- type="button"
- variant="destructive"
- >
- {isDeleteLoading ? <Loader2 className="size-4 animate-spin" /> : <RotateCcw />}
- {isDeleteLoading ? 'Resetting...' : 'Reset'}
- </Button>
- <Button
- disabled={isLoading}
- onClick={() => setIsDiffDialogOpen(true)}
- type="button"
- variant="outline"
- >
- <FileDiff className="size-4" />
- Diff
- </Button>
- </>
- )}
- <Button
- disabled={isLoading}
- onClick={handleValidate}
- type="button"
- variant="outline"
+ {promptInfo.type === 'agent' && promptInfo.hasHuman && (
+ <TabsContent
+ className="mt-6"
+ value="human"
>
- {isValidateLoading ? (
- <Loader2 className="size-4 animate-spin" />
- ) : (
- <CheckCircle className="size-4" />
- )}
- {isValidateLoading ? 'Validating...' : 'Validate'}
- </Button>
- </div>
+ <Form {...humanForm}>
+ <form
+ className="flex flex-col gap-6"
+ id="human-prompt-form"
+ onSubmit={humanForm.handleSubmit(handleHumanSubmit)}
+ >
+ {/* Error Alert */}
+ {mutationError && (
+ <Alert variant="destructive">
+ <AlertCircle className="size-4" />
+ <AlertTitle>Error</AlertTitle>
+ <AlertDescription>
+ {typeof mutationError !== 'string' ? (
+ mutationError.message
+ ) : (
+ <div className="whitespace-pre-line">{mutationError}</div>
+ )}
+ </AlertDescription>
+ </Alert>
+ )}
+
+ {/* Human Template Field */}
+ <FormTextareaItem
+ control={humanForm.control}
+ disabled={isLoading}
+ name="template"
+ placeholder="Enter the human prompt template..."
+ />
+ </form>
+ </Form>
+ </TabsContent>
+ )}
+ </Tabs>
+
+ {/* Sticky footer with variables and buttons */}
+ <div className="bg-background sticky -bottom-4 -mx-4 mt-4 -mb-4 border-t p-4 shadow-lg">
+ {/* Variables */}
+ {variablesData && (
+ <Variables
+ currentTemplate={variablesData.currentTemplate}
+ onVariableClick={handleVariableClickCallback}
+ variables={variablesData.variables}
+ />
+ )}
- <div className="ml-auto flex gap-2">
- <Button
- disabled={isLoading}
- onClick={handleBack}
- type="button"
- variant="outline"
- >
- Cancel
- </Button>
- {activeTab === 'system' && (
- <FormSubmitButton
- form="system-prompt-form"
- icon={<Save className="size-4" />}
- loading={isLoading}
- variant="secondary"
+ {/* Action buttons */}
+ <div className="flex items-center">
+ <div className="flex gap-2">
+ {/* Reset button - only show when user has custom prompt */}
+ {((activeTab === 'system' && promptInfo?.userSystemPrompt) ||
+ (activeTab === 'human' && promptInfo?.userHumanPrompt)) && (
+ <>
+ <Button
+ disabled={isLoading}
+ onClick={handleReset}
+ type="button"
+ variant="destructive"
+ >
+ {isDeleteLoading ? <Loader2 className="size-4 animate-spin" /> : <RotateCcw />}
+ {isDeleteLoading ? 'Resetting...' : 'Reset'}
+ </Button>
+
+ <Button
+ disabled={isLoading}
+ onClick={() => setIsDiffDialogOpen(true)}
+ type="button"
+ variant="outline"
+ >
+ <FileDiff className="size-4" />
+ Diff
+ </Button>
+ </>
+ )}
+ <Button
+ disabled={isLoading}
+ onClick={handleValidate}
+ type="button"
+ variant="outline"
>
- {isLoading ? 'Saving...' : 'Save Changes'}
- </FormSubmitButton>
- )}
- {activeTab === 'human' && promptInfo?.type === 'agent' && promptInfo?.hasHuman && (
- <FormSubmitButton
- form="human-prompt-form"
- icon={<Save className="size-4" />}
- loading={isLoading}
- variant="secondary"
+ {isValidateLoading ? (
+ <Loader2 className="size-4 animate-spin" />
+ ) : (
+ <CheckCircle className="size-4" />
+ )}
+ {isValidateLoading ? 'Validating...' : 'Validate'}
+ </Button>
+ </div>
+
+ <div className="ml-auto flex gap-2">
+ <Button
+ disabled={isLoading}
+ onClick={handleBack}
+ type="button"
+ variant="outline"
>
- {isLoading ? 'Saving...' : 'Save Changes'}
- </FormSubmitButton>
- )}
+ Cancel
+ </Button>
+ {activeTab === 'system' && (
+ <FormSubmitButton
+ form="system-prompt-form"
+ icon={<Save className="size-4" />}
+ loading={isLoading}
+ variant="secondary"
+ >
+ {isLoading ? 'Saving...' : 'Save Changes'}
+ </FormSubmitButton>
+ )}
+ {activeTab === 'human' && promptInfo?.type === 'agent' && promptInfo?.hasHuman && (
+ <FormSubmitButton
+ form="human-prompt-form"
+ icon={<Save className="size-4" />}
+ loading={isLoading}
+ variant="secondary"
+ >
+ {isLoading ? 'Saving...' : 'Save Changes'}
+ </FormSubmitButton>
+ )}
+ </div>
</div>
</div>
- </div>
- {/* Reset Confirmation Dialog */}
- <ConfirmationDialog
- cancelText="Cancel"
- cancelVariant="outline"
- confirmIcon={<RotateCcw />}
- confirmText="Reset"
- confirmVariant="destructive"
- description="Are you sure you want to reset this prompt to its default value? This action cannot be undone."
- handleConfirm={handleConfirmReset}
- handleOpenChange={setResetDialogOpen}
- isOpen={resetDialogOpen}
- itemName={`${activeTab} prompt`}
- itemType="template"
- title="Reset Prompt"
- />
-
- {/* Leave Confirmation Dialog */}
- <ConfirmationDialog
- cancelText="Stay"
- confirmIcon={undefined}
- confirmText="Leave"
- confirmVariant="destructive"
- description="You have unsaved changes. Are you sure you want to leave without saving?"
- handleConfirm={handleConfirmLeave}
- handleOpenChange={handleLeaveDialogOpenChange}
- isOpen={isLeaveDialogOpen}
- title="Discard changes?"
- />
-
- {/* Validation Results Dialog */}
- <Dialog
- onOpenChange={setValidationDialogOpen}
- open={validationDialogOpen}
- >
- <DialogContent className="max-w-2xl">
- <DialogHeader>
- <DialogTitle className="flex items-center gap-2">
- <AlertCircle className="size-5" />
- Validation Results
- </DialogTitle>
- <DialogDescription>
- The validation result for the {activeTab} prompt template.
- </DialogDescription>
- </DialogHeader>
-
- {validationResult && (
- <div className="flex flex-col gap-4">
- <Alert variant={validationResult.result ? 'default' : 'destructive'}>
- {validationResult.result === 'success' ? (
- <CheckCircle className="size-4 text-green-500!" />
- ) : (
- <XCircle className="size-4 text-red-500!" />
- )}
- <AlertTitle>
- {validationResult.result === 'success' ? 'Valid Template' : 'Validation Error'}
- </AlertTitle>
- <AlertDescription>
- <div className="whitespace-pre-line">
- {validationResult.message}
- {validationResult.details && (
- <div className="mt-2">
- <strong>Details:</strong> {validationResult.details}
- </div>
- )}
- {validationResult.line && (
- <div className="mt-1">
- <strong>Line:</strong> {validationResult.line}
- </div>
- )}
- </div>
- </AlertDescription>
- </Alert>
-
- <div className="flex justify-end">
- <Button onClick={() => setValidationDialogOpen(false)}>Close</Button>
+ {/* Reset Confirmation Dialog */}
+ <ConfirmationDialog
+ cancelText="Cancel"
+ cancelVariant="outline"
+ confirmIcon={<RotateCcw />}
+ confirmText="Reset"
+ confirmVariant="destructive"
+ description="Are you sure you want to reset this prompt to its default value? This action cannot be undone."
+ handleConfirm={handleConfirmReset}
+ handleOpenChange={setResetDialogOpen}
+ isOpen={resetDialogOpen}
+ itemName={`${activeTab} prompt`}
+ itemType="template"
+ title="Reset Prompt"
+ />
+
+ {/* Leave Confirmation Dialog */}
+ <ConfirmationDialog
+ cancelText="Stay"
+ confirmIcon={undefined}
+ confirmText="Leave"
+ confirmVariant="destructive"
+ description="You have unsaved changes. Are you sure you want to leave without saving?"
+ handleConfirm={handleConfirmLeave}
+ handleOpenChange={handleLeaveDialogOpenChange}
+ isOpen={isLeaveDialogOpen}
+ title="Discard changes?"
+ />
+
+ {/* Validation Results Dialog */}
+ <Dialog
+ onOpenChange={setValidationDialogOpen}
+ open={validationDialogOpen}
+ >
+ <DialogContent className="max-w-2xl">
+ <DialogHeader>
+ <DialogTitle className="flex items-center gap-2">
+ <AlertCircle className="size-5" />
+ Validation Results
+ </DialogTitle>
+ <DialogDescription>
+ The validation result for the {activeTab} prompt template.
+ </DialogDescription>
+ </DialogHeader>
+
+ {validationResult && (
+ <div className="flex flex-col gap-4">
+ <Alert variant={validationResult.result ? 'default' : 'destructive'}>
+ {validationResult.result === 'success' ? (
+ <CheckCircle className="size-4 text-green-500!" />
+ ) : (
+ <XCircle className="size-4 text-red-500!" />
+ )}
+ <AlertTitle>
+ {validationResult.result === 'success' ? 'Valid Template' : 'Validation Error'}
+ </AlertTitle>
+ <AlertDescription>
+ <div className="whitespace-pre-line">
+ {validationResult.message}
+ {validationResult.details && (
+ <div className="mt-2">
+ <strong>Details:</strong> {validationResult.details}
+ </div>
+ )}
+ {validationResult.line && (
+ <div className="mt-1">
+ <strong>Line:</strong> {validationResult.line}
+ </div>
+ )}
+ </div>
+ </AlertDescription>
+ </Alert>
+
+ <div className="flex justify-end">
+ <Button onClick={() => setValidationDialogOpen(false)}>Close</Button>
+ </div>
</div>
+ )}
+ </DialogContent>
+ </Dialog>
+
+ {/* Diff Dialog */}
+ <Dialog
+ onOpenChange={setIsDiffDialogOpen}
+ open={isDiffDialogOpen}
+ >
+ <DialogContent className="max-w-7xl">
+ <DialogHeader>
+ <DialogTitle className="flex items-center gap-2">
+ <FileDiff className="size-5" />
+ Diff
+ </DialogTitle>
+ <DialogDescription>Changes between current value and default template.</DialogDescription>
+ </DialogHeader>
+ <div className="max-h-[70vh] overflow-auto">
+ <ReactDiffViewer
+ newValue={currentTemplate}
+ oldValue={defaultTemplate}
+ splitView
+ styles={diffStyles}
+ useDarkTheme
+ />
</div>
- )}
- </DialogContent>
- </Dialog>
-
- {/* Diff Dialog */}
- <Dialog
- onOpenChange={setIsDiffDialogOpen}
- open={isDiffDialogOpen}
- >
- <DialogContent className="max-w-7xl">
- <DialogHeader>
- <DialogTitle className="flex items-center gap-2">
- <FileDiff className="size-5" />
- Diff
- </DialogTitle>
- <DialogDescription>Changes between current value and default template.</DialogDescription>
- </DialogHeader>
- <div className="max-h-[70vh] overflow-auto">
- <ReactDiffViewer
- newValue={currentTemplate}
- oldValue={defaultTemplate}
- splitView
- styles={diffStyles}
- useDarkTheme
- />
- </div>
- </DialogContent>
- </Dialog>
- </div>
+ </DialogContent>
+ </Dialog>
+ </div>
+ </>
);
}
diff --git a/frontend/src/pages/settings/settings-prompts.tsx b/frontend/src/pages/settings/settings-prompts.tsx
index 5b4e3362..9331216c 100644
--- a/frontend/src/pages/settings/settings-prompts.tsx
+++ b/frontend/src/pages/settings/settings-prompts.tsx
@@ -8,6 +8,7 @@ import {
Bot,
Code,
Ellipsis,
+ FileText,
Loader2,
Pencil,
RotateCcw,
@@ -16,7 +17,7 @@ import {
User,
Wrench,
} from 'lucide-react';
-import { Fragment, useState } from 'react';
+import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import type { DefaultPromptFragmentFragment as DefaultPrompt, PromptType } from '@/graphql/types';
@@ -24,6 +25,7 @@ import type { DefaultPromptFragmentFragment as DefaultPrompt, PromptType } from
type AgentPrompt = AgentPrompts;
type AgentPrompts = { human?: DefaultPrompt; system: DefaultPrompt };
+import { SettingsPageHeader } from '@/components/layouts/settings-page-header';
import ConfirmationDialog from '@/components/shared/confirmation-dialog';
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
import { Badge } from '@/components/ui/badge';
@@ -777,29 +779,42 @@ function SettingsPrompts() {
</>
);
+ const pageHeader = (
+ <SettingsPageHeader
+ icon={<FileText className="size-4 shrink-0" />}
+ title="Prompts"
+ />
+ );
+
if (isLoading) {
return (
- <div className="flex flex-col gap-4">
- <SettingsPromptsHeader />
- <StatusCard
- description="Please wait while we fetch your prompt templates"
- icon={<Loader2 className="text-muted-foreground size-16 animate-spin" />}
- title="Loading prompts..."
- />
- </div>
+ <>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-6 p-4">
+ <SettingsPromptsHeader />
+ <StatusCard
+ description="Please wait while we fetch your prompt templates"
+ icon={<Loader2 className="text-muted-foreground size-16 animate-spin" />}
+ title="Loading prompts..."
+ />
+ </div>
+ </>
);
}
if (error) {
return (
- <div className="flex flex-col gap-4">
- <SettingsPromptsHeader />
- <Alert variant="destructive">
- <AlertCircle className="size-4" />
- <AlertTitle>Error loading prompts</AlertTitle>
- <AlertDescription>{error.message}</AlertDescription>
- </Alert>
- </div>
+ <>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-6 p-4">
+ <SettingsPromptsHeader />
+ <Alert variant="destructive">
+ <AlertCircle className="size-4" />
+ <AlertTitle>Error loading prompts</AlertTitle>
+ <AlertDescription>{error.message}</AlertDescription>
+ </Alert>
+ </div>
+ </>
);
}
@@ -808,20 +823,24 @@ function SettingsPrompts() {
if (agentPrompts.length === 0 && toolPrompts.length === 0) {
return (
- <div className="flex flex-col gap-4">
- <SettingsPromptsHeader />
- <StatusCard
- description="Prompt templates could not be loaded"
- icon={<Settings className="text-muted-foreground size-8" />}
- title="No prompts available"
- />
- </div>
+ <>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-6 p-4">
+ <SettingsPromptsHeader />
+ <StatusCard
+ description="Prompt templates could not be loaded"
+ icon={<Settings className="text-muted-foreground size-8" />}
+ title="No prompts available"
+ />
+ </div>
+ </>
);
}
return (
- <Fragment>
- <div className="flex flex-col gap-6">
+ <>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-6 p-4">
<SettingsPromptsHeader />
{agentPrompts.length > 0 && (
@@ -887,7 +906,7 @@ function SettingsPrompts() {
isOpen={resetDialogOpen}
title={`Reset ${resetOperation?.displayName || 'Prompt'}`}
/>
- </Fragment>
+ </>
);
}
diff --git a/frontend/src/pages/settings/settings-providers.tsx b/frontend/src/pages/settings/settings-providers.tsx
index 6b38f4f7..4cd5a9ae 100644
--- a/frontend/src/pages/settings/settings-providers.tsx
+++ b/frontend/src/pages/settings/settings-providers.tsx
@@ -1,13 +1,14 @@
import type { ColumnDef, Row } from '@tanstack/react-table';
import { useMutation, useQuery } from '@apollo/client/react';
-import { AlertCircle, ChevronDown, Copy, Ellipsis, Loader2, Pencil, Plus, Settings, Trash } from 'lucide-react';
+import { AlertCircle, ChevronDown, Copy, Ellipsis, Loader2, Pencil, Plug, Plus, Settings, Trash } from 'lucide-react';
import { useCallback, useMemo, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import type { ProviderConfigFragmentFragment } from '@/graphql/types';
import { providerIcons } from '@/components/icons/provider-icon';
+import { SettingsPageHeader } from '@/components/layouts/settings-page-header';
import ConfirmationDialog from '@/components/shared/confirmation-dialog';
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
import { Badge } from '@/components/ui/badge';
@@ -340,29 +341,42 @@ function SettingsProviders() {
[deletingProvider, handleProviderClone, handleProviderDeleteDialogOpen, handleProviderEdit, isDeleteLoading],
);
+ const pageHeader = (
+ <SettingsPageHeader
+ icon={<Plug className="size-4 shrink-0" />}
+ title="Providers"
+ />
+ );
+
if (isLoading) {
return (
- <div className="flex flex-col gap-4">
- <SettingsProvidersHeader />
- <StatusCard
- description="Please wait while we fetch your provider configurations"
- icon={<Loader2 className="text-muted-foreground size-16 animate-spin" />}
- title="Loading providers..."
- />
- </div>
+ <>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-4 p-4">
+ <SettingsProvidersHeader />
+ <StatusCard
+ description="Please wait while we fetch your provider configurations"
+ icon={<Loader2 className="text-muted-foreground size-16 animate-spin" />}
+ title="Loading providers..."
+ />
+ </div>
+ </>
);
}
if (error) {
return (
- <div className="flex flex-col gap-4">
- <SettingsProvidersHeader />
- <Alert variant="destructive">
- <AlertCircle className="size-4" />
- <AlertTitle>Error loading providers</AlertTitle>
- <AlertDescription>{error.message}</AlertDescription>
- </Alert>
- </div>
+ <>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-4 p-4">
+ <SettingsProvidersHeader />
+ <Alert variant="destructive">
+ <AlertCircle className="size-4" />
+ <AlertTitle>Error loading providers</AlertTitle>
+ <AlertDescription>{error.message}</AlertDescription>
+ </Alert>
+ </div>
+ </>
);
}
@@ -370,62 +384,68 @@ function SettingsProviders() {
if (providers.length === 0) {
return (
- <div className="flex flex-col gap-4">
- <SettingsProvidersHeader />
- <StatusCard
- action={
- <Button
- onClick={() => navigate(routes.settings.newProvider())}
- variant="secondary"
- >
- <Plus className="size-4" />
- Add Provider
- </Button>
- }
- description="Get started by adding your first language model provider"
- icon={<Settings className="text-muted-foreground size-8" />}
- title="No providers configured"
- />
- </div>
+ <>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-4 p-4">
+ <SettingsProvidersHeader />
+ <StatusCard
+ action={
+ <Button
+ onClick={() => navigate(routes.settings.newProvider())}
+ variant="secondary"
+ >
+ <Plus className="size-4" />
+ Add Provider
+ </Button>
+ }
+ description="Get started by adding your first language model provider"
+ icon={<Settings className="text-muted-foreground size-8" />}
+ title="No providers configured"
+ />
+ </div>
+ </>
);
}
return (
- <div className="flex flex-col gap-4">
- <SettingsProvidersHeader />
-
- {/* Delete Error Alert */}
- {(deleteError || deleteErrorMessage) && (
- <Alert variant="destructive">
- <AlertCircle className="size-4" />
- <AlertTitle>Error deleting provider</AlertTitle>
- <AlertDescription>{deleteError?.message || deleteErrorMessage}</AlertDescription>
- </Alert>
- )}
-
- <DataTable<Provider>
- columns={columns}
- data={providers}
- empty={{ entityName: 'providers' }}
- filterPlaceholder="Filter providers..."
- filterValue={filter}
- onFilterChange={setFilter}
- onPageChange={handlePageChange}
- pageIndex={currentPage}
- renderRowContextMenu={renderRowContextMenu}
- renderSubComponent={renderSubComponent}
- />
-
- <ConfirmationDialog
- cancelText="Cancel"
- confirmText="Delete"
- handleConfirm={() => handleProviderDelete(deletingProvider?.id)}
- handleOpenChange={setIsDeleteDialogOpen}
- isOpen={isDeleteDialogOpen}
- itemName={deletingProvider?.name}
- itemType="provider"
- />
- </div>
+ <>
+ {pageHeader}
+ <div className="flex flex-1 flex-col gap-4 p-4">
+ <SettingsProvidersHeader />
+
+ {/* Delete Error Alert */}
+ {(deleteError || deleteErrorMessage) && (
+ <Alert variant="destructive">
+ <AlertCircle className="size-4" />
+ <AlertTitle>Error deleting provider</AlertTitle>
+ <AlertDescription>{deleteError?.message || deleteErrorMessage}</AlertDescription>
+ </Alert>
+ )}
+
+ <DataTable<Provider>
+ columns={columns}
+ data={providers}
+ empty={{ entityName: 'providers' }}
+ filterPlaceholder="Filter providers..."
+ filterValue={filter}
+ onFilterChange={setFilter}
+ onPageChange={handlePageChange}
+ pageIndex={currentPage}
+ renderRowContextMenu={renderRowContextMenu}
+ renderSubComponent={renderSubComponent}
+ />
+
+ <ConfirmationDialog
+ cancelText="Cancel"
+ confirmText="Delete"
+ handleConfirm={() => handleProviderDelete(deletingProvider?.id)}
+ handleOpenChange={setIsDeleteDialogOpen}
+ isOpen={isDeleteDialogOpen}
+ itemName={deletingProvider?.name}
+ itemType="provider"
+ />
+ </div>
+ </>
);
}