diff --git a/apps/api/src/services/notification.ts b/apps/api/src/services/notification.ts index d5d680b5f3..7839fdbd2d 100644 --- a/apps/api/src/services/notification.ts +++ b/apps/api/src/services/notification.ts @@ -71,7 +71,7 @@ function getStub(env: NotificationEnv, userId: string): DurableObjectStub import('./pages/ProjectFiles'), 'ProjectFiles'); const ProjectInvite = lazyNamed(() => import('./pages/ProjectInvite'), 'ProjectInvite'); const ProjectLibrary = lazyNamed(() => import('./pages/ProjectLibrary'), 'ProjectLibrary'); -const ProjectNotifications = lazyNamed( - () => import('./pages/ProjectNotifications'), - 'ProjectNotifications' -); +const Inbox = lazyNamed(() => import('./pages/inbox'), 'Inbox'); +const ProjectInbox = lazyNamed(() => import('./pages/inbox'), 'ProjectInbox'); const ProjectProfiles = lazyNamed(() => import('./pages/ProjectProfiles'), 'ProjectProfiles'); const Projects = lazyNamed(() => import('./pages/Projects'), 'Projects'); const ProjectSettings = lazyNamed(loadProjectSettings, 'ProjectSettings'); @@ -305,6 +303,7 @@ export default function App() { }> } /> )} /> + )} /> )} /> )} /> )} /> @@ -371,7 +370,12 @@ export default function App() { )} /> )} /> - )} /> + )} /> + {/* The project Notifications page became the inbox's Updates chip. */} + } + /> )} /> )} /> )} /> diff --git a/apps/web/src/components/AppShell.tsx b/apps/web/src/components/AppShell.tsx index 8c6e79b033..a005b12291 100644 --- a/apps/web/src/components/AppShell.tsx +++ b/apps/web/src/components/AppShell.tsx @@ -14,6 +14,7 @@ import { Outlet, useLocation, useNavigate } from 'react-router'; import { useGlobalCommandPalette } from '../hooks/useGlobalCommandPalette'; import { useIsMobile } from '../hooks/useIsMobile'; +import { useNotificationSocket } from '../hooks/useNotificationSocket'; import { useProjectList } from '../hooks/useProjectData'; import { useSamSettings } from '../hooks/useSamSettings'; import { signOut } from '../lib/auth'; @@ -30,6 +31,7 @@ import { useAuth } from './AuthProvider'; import { CredentialHealthNavItem } from './CredentialHealthNavItem'; import { GlobalAudioPlayer } from './GlobalAudioPlayer'; import { GlobalCommandPalette } from './GlobalCommandPalette'; +import { useInboxCount } from './inbox/useInbox'; import { MobileNavDrawer, type MobileNavItem } from './MobileNavDrawer'; import { extractProjectId, getGlobalNavItems, PROJECT_NAV_ITEMS } from './NavSidebar'; import { OnboardingProvider } from './onboarding'; @@ -165,36 +167,38 @@ export function AppShell({ children }: AppShellProps) { // Detect project context from URL (excludes reserved paths like /projects/new) const projectId = extractProjectId(location.pathname); - const mobileNavItems = useMemo((): MobileNavItem[] => { - if (projectId) { - return PROJECT_NAV_ITEMS.map((item) => ({ - label: item.label, - path: `/projects/${projectId}/${item.path}`, - icon: item.icon, - })); - } - const items: MobileNavItem[] = getGlobalNavItems(sam.enabled).map((item) => ({ - label: item.label, - path: item.path, - icon: item.icon, - })); - if (isSuperadmin) { - items.push({ label: 'Admin', path: '/admin', icon: }); - } - return items; - }, [isSuperadmin, projectId, sam.enabled]); + // One notification socket for the app: its events refresh the inbox counts and lists (and the + // Updates chip), so nothing polls. + useNotificationSocket(); + + // The phone drawer shows the same inbox counts as the desktop nav (nav parity, rule 15). + const globalInboxCount = useInboxCount(null).data?.needsYou; + const projectInboxCount = useInboxCount(projectId ?? null).data?.needsYou; const mobileGlobalNavItems = useMemo((): MobileNavItem[] => { const items: MobileNavItem[] = getGlobalNavItems(sam.enabled).map((item) => ({ label: item.label, path: item.path, icon: item.icon, + count: item.inboxCount ? globalInboxCount : undefined, })); if (isSuperadmin) { items.push({ label: 'Admin', path: '/admin', icon: }); } return items; - }, [isSuperadmin, sam.enabled]); + }, [globalInboxCount, isSuperadmin, sam.enabled]); + + const mobileNavItems = useMemo((): MobileNavItem[] => { + if (projectId) { + return PROJECT_NAV_ITEMS.map((item) => ({ + label: item.label, + path: `/projects/${projectId}/${item.path}`, + icon: item.icon, + count: item.inboxCount ? projectInboxCount : undefined, + })); + } + return mobileGlobalNavItems; + }, [mobileGlobalNavItems, projectId, projectInboxCount]); const handleProjectNavigate = useCallback( (path: string) => { diff --git a/apps/web/src/components/MobileNavDrawer.tsx b/apps/web/src/components/MobileNavDrawer.tsx index 3230ef1203..1ee5d6a33e 100644 --- a/apps/web/src/components/MobileNavDrawer.tsx +++ b/apps/web/src/components/MobileNavDrawer.tsx @@ -20,6 +20,8 @@ export interface MobileNavItem { label: string; path: string; icon?: ReactNode; + /** Items waiting on the user (the inbox), shown as an amber count. */ + count?: number; } interface MobileNavDrawerProps { @@ -93,6 +95,8 @@ export function MobileNavDrawer({ icon={item.icon} current={isNavItemActive(item.path, currentPath)} onClick={() => onNavigate(item.path)} + count={item.count} + countTone="attention" size="lg" /> )); @@ -120,7 +124,9 @@ export function MobileNavDrawer({ )}
-

{user.name || 'User'}

+

+ {user.name || 'User'} +

{user.email}

{showGlobalNav ? ( <> diff --git a/apps/web/src/components/NavSidebar.tsx b/apps/web/src/components/NavSidebar.tsx index 5d8a802f2c..a5921d7dff 100644 --- a/apps/web/src/components/NavSidebar.tsx +++ b/apps/web/src/components/NavSidebar.tsx @@ -2,13 +2,13 @@ import { NavItem as GlassNavItem, NavLabel } from '@simple-agent-manager/ui'; import { ArrowLeft, ArrowRight, - Bell, Bot, Brain, FileCode, FolderKanban, FolderOpen, Home, + Inbox, LayoutDashboard, Lightbulb, Map, @@ -29,17 +29,21 @@ import { useLocation } from 'react-router'; import { useSamSettings } from '../hooks/useSamSettings'; import { useAuth } from './AuthProvider'; +import { useInboxCount } from './inbox/useInbox'; import { useOnboarding } from './onboarding'; export interface NavItem { label: string; path: string; icon: React.ReactNode; + /** Shows the inbox count (all projects in the global nav, this project in the project nav). */ + inboxCount?: true; } /** Global nav items shown when NOT inside a project */ export const GLOBAL_NAV_ITEMS: NavItem[] = [ { label: 'Home', path: '/dashboard', icon: }, + { label: 'Inbox', path: '/inbox', icon: , inboxCount: true }, { label: 'Chats', path: '/chats', icon: }, { label: 'Projects', path: '/projects', icon: }, { label: 'Map', path: '/account-map', icon: }, @@ -65,6 +69,8 @@ export const PROJECT_NAV_ITEMS: NavItem[] = [ // the index route); until then the project still opens in Chat. { label: 'Overview', path: 'overview', icon: }, { label: 'Chat', path: 'chat', icon: }, + // The inbox replaced the project Notifications page (its FYI list is the Updates chip). + { label: 'Inbox', path: 'inbox', icon: , inboxCount: true }, // { label: 'Agent', path: 'agent', icon: }, // Hidden — experimental, not ready for users yet // MessageSquareQuote, not MessageSquare: Chat already owns the plain speech // bubble, and two bubbles side by side in the same rail are indistinguishable @@ -75,7 +81,6 @@ export const PROJECT_NAV_ITEMS: NavItem[] = [ { label: 'Ideas', path: 'ideas', icon: }, { label: 'Deployments', path: 'deployments', icon: }, { label: 'Agent Context', path: 'agent-context', icon: }, - { label: 'Notifications', path: 'notifications', icon: }, // One item for everything that starts work on its own (it replaced Events and Triggers). { label: 'Automation', path: 'automation', icon: }, { label: 'Profiles', path: 'profiles', icon: }, @@ -138,6 +143,8 @@ export function NavSidebar({ const projectId = extractProjectId(location.pathname); const insideProject = Boolean(projectId); + const globalInboxCount = useInboxCount(null).data?.needsYou; + const projectInboxCount = useInboxCount(projectId ?? null).data?.needsYou; const projectToggleRef = useRef(null); const globalToggleRef = useRef(null); const restoreToggleFocus = useRef(false); @@ -153,7 +160,7 @@ export function NavSidebar({ onToggleGlobalNav?.(); }; - const renderItem = (item: NavItem, to: string, active: boolean) => ( + const renderItem = (item: NavItem, to: string, active: boolean, inboxCount?: number) => ( ); @@ -236,7 +245,8 @@ export function NavSidebar({ renderItem( item, `/projects/${projectId}/${item.path}`, - isProjectSubActive(item.path, projectId, location.pathname) + isProjectSubActive(item.path, projectId, location.pathname), + projectInboxCount ) )} @@ -262,7 +272,7 @@ export function NavSidebar({ {/* Global nav items */} {globalItems.map((item) => - renderItem(item, item.path, isActive(item.path, location.pathname)) + renderItem(item, item.path, isActive(item.path, location.pathname), globalInboxCount) )} {onboardingResume} @@ -289,7 +299,7 @@ export function NavSidebar({ className={`flex min-h-0 flex-1 flex-col gap-0.5 overflow-y-auto px-3 py-2 ${className ?? ''}`} > {globalItems.map((item) => - renderItem(item, item.path, isActive(item.path, location.pathname)) + renderItem(item, item.path, isActive(item.path, location.pathname), globalInboxCount) )} {onboardingResume} diff --git a/apps/web/src/components/NotificationCenter.tsx b/apps/web/src/components/NotificationCenter.tsx deleted file mode 100644 index d2760bf113..0000000000 --- a/apps/web/src/components/NotificationCenter.tsx +++ /dev/null @@ -1,397 +0,0 @@ -import type { NotificationResponse } from '@simple-agent-manager/shared'; -import { Alert, Button, IconButton, paneClassName } from '@simple-agent-manager/ui'; -import { Bell, CheckCheck, Loader2 } from 'lucide-react'; -import { Suspense, useCallback, useEffect, useMemo, useRef, useState } from 'react'; -import { createPortal } from 'react-dom'; -import { useNavigate } from 'react-router'; - -import { useNotifications } from '../hooks/useNotifications'; -import { usePushSubscription } from '../hooks/usePushSubscription'; -import { maybeJsonRecord } from '../lib/runtime-validation'; -import { useAuth } from './AuthProvider'; -import { attentionRequest } from './notifications/attention-request'; -import { ATTENTION_TYPES } from './notifications/notification-type-config'; -import { NotificationGroup, NotificationItem } from './notifications/NotificationItem'; -import { NotificationQuestionDialog } from './notifications/question-dialog-loader'; - -function pushInvitationDismissedKey(userId: string): string { - return `sam-push-invitation-dismissed-${userId}`; -} - -type FilterTab = 'attention' | 'updates' | 'all'; - -export function NotificationCenter() { - const [isOpen, setIsOpen] = useState(false); - const [question, setQuestion] = useState(null); - const [activeTab, setActiveTab] = useState('attention'); - const [panelStyle, setPanelStyle] = useState({}); - const { user } = useAuth(); - const dismissalKey = pushInvitationDismissedKey(user?.id ?? 'anonymous'); - const [pushInvitationDismissed, setPushInvitationDismissed] = useState(false); - const panelRef = useRef(null); - const buttonRef = useRef(null); - const navigate = useNavigate(); - - const { - notifications, - unreadCount, - loading, - markRead, - markAllRead, - dismiss, - loadMore, - hasMore, - refresh, - } = useNotifications(); - const push = usePushSubscription(); - - useEffect(() => { - setPushInvitationDismissed(localStorage.getItem(dismissalKey) === 'true'); - }, [dismissalKey]); - - // Position the panel relative to the bell button - useEffect(() => { - if (!isOpen || !buttonRef.current) return; - const rect = buttonRef.current.getBoundingClientRect(); - const isMobile = window.innerWidth < 640; - if (isMobile) { - setPanelStyle({ top: rect.bottom + 8 }); - } else { - setPanelStyle({ top: rect.bottom + 8, left: rect.left }); - } - }, [isOpen]); - - // Close on click outside - useEffect(() => { - if (!isOpen) return; - - const handleClickOutside = (e: MouseEvent) => { - if ( - panelRef.current && - !panelRef.current.contains(e.target as Node) && - buttonRef.current && - !buttonRef.current.contains(e.target as Node) - ) { - setIsOpen(false); - } - }; - - // Close on escape - const handleEscape = (e: KeyboardEvent) => { - if (e.key === 'Escape') setIsOpen(false); - }; - - document.addEventListener('mousedown', handleClickOutside); - document.addEventListener('keydown', handleEscape); - return () => { - document.removeEventListener('mousedown', handleClickOutside); - document.removeEventListener('keydown', handleEscape); - }; - }, [isOpen]); - - const handleNotificationClick = useCallback( - (notification: NotificationResponse) => { - if (!notification.readAt) { - markRead(notification.id); - } - if (attentionRequest(notification).readable) { - setQuestion(notification); - setIsOpen(false); - return; - } - if (notification.actionUrl && notification.actionUrl.startsWith('/')) { - navigate(notification.actionUrl); - setIsOpen(false); - } - }, - [markRead, navigate] - ); - - const filteredNotifications = useMemo(() => { - if (activeTab === 'attention') return notifications.filter((n) => ATTENTION_TYPES.has(n.type)); - if (activeTab === 'updates') return notifications.filter((n) => !ATTENTION_TYPES.has(n.type)); - return notifications; - }, [notifications, activeTab]); - - const attentionUnreadCount = useMemo( - () => notifications.filter((n) => ATTENTION_TYPES.has(n.type) && !n.readAt).length, - [notifications] - ); - - const updatesUnreadCount = useMemo( - () => notifications.filter((n) => !ATTENTION_TYPES.has(n.type) && !n.readAt).length, - [notifications] - ); - - const shouldInvitePush = - notifications.some( - (notification) => notification.type === 'needs_input' && !notification.dismissedAt - ) && - push.supported && - !push.isLoading && - !push.isSubscribed && - push.permission !== 'denied' && - !pushInvitationDismissed; - - const dismissPushInvitation = () => { - localStorage.setItem(dismissalKey, 'true'); - setPushInvitationDismissed(true); - }; - - // Group notifications by project when multiple projects exist - const { groups, shouldGroup } = useMemo(() => { - const projectIds = new Set(filteredNotifications.map((n) => n.projectId ?? 'none')); - if (projectIds.size <= 1) { - return { groups: [], shouldGroup: false }; - } - - const groupMap = new Map< - string, - { projectId: string | null; projectName: string; notifications: NotificationResponse[] } - >(); - for (const n of filteredNotifications) { - const key = n.projectId ?? 'none'; - let group = groupMap.get(key); - if (!group) { - const metadataProjectName = maybeJsonRecord(n.metadata)?.projectName; - const projectName = - typeof metadataProjectName === 'string' - ? metadataProjectName - : n.projectId - ? `Project ${n.projectId.slice(0, 8)}` - : 'General'; - group = { projectId: n.projectId, projectName, notifications: [] }; - groupMap.set(key, group); - } - group.notifications.push(n); - } - return { groups: Array.from(groupMap.values()), shouldGroup: true }; - }, [filteredNotifications]); - - const notificationButtonLabel = [ - 'Notifications', - attentionUnreadCount > 0 ? ` (${attentionUnreadCount} need attention)` : '', - unreadCount > 0 ? `, ${unreadCount} total unread` : '', - ].join(''); - - return ( -
- {/* Bell Button */} - setIsOpen(!isOpen)} - label={notificationButtonLabel} - icon={} - count={attentionUnreadCount > 99 ? '99+' : attentionUnreadCount || undefined} - countTone="attention" - showTooltip={false} - /> - - {question && ( - - { - setQuestion(null); - buttonRef.current?.focus(); - }} - onResolved={() => void refresh()} - /> - - )} - {/* Notification Panel — portaled to body to escape sidebar stacking context */} - {isOpen && - createPortal( -
- {/* Header */} -
-

Notifications

-
- {unreadCount > 0 && ( - - )} -
-
- - {/* Filter Tabs */} -
{ - const tabIds: FilterTab[] = ['attention', 'updates', 'all']; - const idx = tabIds.indexOf(activeTab); - if (e.key === 'ArrowRight') { - e.preventDefault(); - setActiveTab(tabIds[(idx + 1) % tabIds.length] ?? activeTab); - } else if (e.key === 'ArrowLeft') { - e.preventDefault(); - setActiveTab(tabIds[(idx - 1 + tabIds.length) % tabIds.length] ?? activeTab); - } - }} - > - {[ - { id: 'attention' as const, label: 'Attention', badge: attentionUnreadCount }, - { id: 'updates' as const, label: 'Updates', badge: updatesUnreadCount }, - { id: 'all' as const, label: 'All', badge: 0 }, - ].map(({ id, label, badge }) => ( - - ))} -
- - {shouldInvitePush && ( -
- -
-

- Get agent questions on this device even when SAM is closed. -

- {push.error && ( -

- {push.error} -

- )} -
- - -
-
-
-
- )} - - {/* Notification List */} -
- {loading && notifications.length === 0 ? ( -
- -
- ) : filteredNotifications.length === 0 ? ( -
- - - {activeTab === 'attention' - ? 'Nothing needs your attention' - : activeTab === 'updates' - ? 'No updates' - : 'No notifications yet'} - - {activeTab === 'attention' && ( - - Items needing your input or action appear here - - )} -
- ) : shouldGroup ? ( - <> - {groups.map((group) => ( - void refresh()} - onViewInProject={(pid) => { - navigate(`/projects/${pid}/notifications`); - setIsOpen(false); - }} - /> - ))} - {hasMore && ( - - )} - - ) : ( - <> - {filteredNotifications.map((notification) => ( - handleNotificationClick(notification)} - onDismiss={(e) => { - e.stopPropagation(); - dismiss(notification.id); - }} - onMarkRead={(e) => { - e.stopPropagation(); - markRead(notification.id); - }} - onViewInProject={ - notification.projectId - ? () => { - navigate(`/projects/${notification.projectId}/notifications`); - setIsOpen(false); - } - : undefined - } - onResolved={() => void refresh()} - /> - ))} - {hasMore && ( - - )} - - )} -
-
, - document.body - )} -
- ); -} diff --git a/apps/web/src/components/global-command-palette-navigation-items.tsx b/apps/web/src/components/global-command-palette-navigation-items.tsx index 87ec8303f0..787329420d 100644 --- a/apps/web/src/components/global-command-palette-navigation-items.tsx +++ b/apps/web/src/components/global-command-palette-navigation-items.tsx @@ -10,6 +10,7 @@ import { Gauge, Github, Home, + Inbox, Key, KeyRound, LayoutDashboard, @@ -31,6 +32,7 @@ import type { NavItem } from './global-command-palette-types'; export function buildNavigationItems(isSuperadmin: boolean): NavItem[] { const items: NavItem[] = [ { id: 'nav-dashboard', label: 'Home', path: '/dashboard', icon: }, + { id: 'nav-inbox', label: 'Inbox', path: '/inbox', icon: }, { id: 'nav-chats', label: 'Chats', path: '/chats', icon: }, { id: 'nav-projects', diff --git a/apps/web/src/components/inbox/InboxAnswerControls.tsx b/apps/web/src/components/inbox/InboxAnswerControls.tsx new file mode 100644 index 0000000000..7e1a7762d5 --- /dev/null +++ b/apps/web/src/components/inbox/InboxAnswerControls.tsx @@ -0,0 +1,404 @@ +import type { InboxItem } from '@simple-agent-manager/shared'; +import { Button } from '@simple-agent-manager/ui'; +import { MessageSquare, RefreshCw } from 'lucide-react'; +import { useEffect, useRef, useState } from 'react'; +import { Link, useNavigate } from 'react-router'; + +import { answerInboxItem } from '../../lib/api'; +import { projectChatPath } from '../../lib/project-routes'; +import { AttentionAnswerControls } from '../notifications/AttentionAnswerControls'; +import { ApprovalDecisionButtons } from '../operations-approvals/ApprovalItem'; +import { PermissionOptions } from '../project-message-view/AcpPermissionOptions'; +import { SecretRequestForm } from '../project-message-view/tool-cards/SecretRequestForm'; +import { useSecretRequest } from '../project-message-view/tool-cards/useSecretRequest'; +import type { + PermissionDetail, + PermissionOption, +} from '../project-message-view/useAcpPermissionCard'; +import { + deliveryNote, + errorText, + type InboxAnswerHandlers, + isStaleInboxError, + type useInboxPermissionDetail, + useInboxSend, +} from './inbox-actions'; +import { + type InboxErrorActionModel, + isIrreversibleApproval, + readErrorActions, +} from './inbox-model'; + +/** What the agent wants to run lives in the body; only the buttons are pinned. */ +export function InboxPermissionSummary({ detail }: { detail: PermissionDetail | null }) { + if (!detail) return null; + return ( +
+ + {detail.title} + + {detail.description && ( + + {detail.description} + + )} +
+ ); +} + +function OpenChatButton({ item, label }: { item: InboxItem; label: string }) { + if (!item.sessionId) return null; + return ( + +