From ba5c9605fc5641bf28feacb258b016286dae96a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Mon, 16 Nov 2026 04:31:14 +0000 Subject: [PATCH 01/13] task: add inbox slice C web task --- tasks/active/2026-11-16-inbox-slice-c-web.md | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tasks/active/2026-11-16-inbox-slice-c-web.md diff --git a/tasks/active/2026-11-16-inbox-slice-c-web.md b/tasks/active/2026-11-16-inbox-slice-c-web.md new file mode 100644 index 0000000000..14927066ec --- /dev/null +++ b/tasks/active/2026-11-16-inbox-slice-c-web.md @@ -0,0 +1,55 @@ +# Inbox slice C: the Inbox in the web app + +SAM task `01M7H9HB8DFJVS28HK0F7TFSBQ`, spec idea `01M7G03ZCQ6TM6CMEYDRKQ8ST9` (section 4.1, slice C in section 6), channel `feature.inbox`. +Merge authorized by the owner through production (2026-11-16). + +## Problem + +Slice A (PR #2776) shipped the inbox backend: one list of every ask an agent makes of a person, across projects. People still see agent asks only through the notification bell panel and the notification question dialog. Slice C puts the inbox in the web app and replaces the bell panel. + +## Research findings + +- Types: `packages/shared/src/types/inbox.ts` (InboxItem, InboxAnswerSpec, INBOX_FILTERS: needs_you, blocking, tasks, reviews, archived). No `updates` filter: Updates is the existing notification list. +- REST: `apps/api/src/routes/inbox.ts`. Writes need the app Origin and JSON (the shared `request()` sends JSON + credentials). Closed items answer with 409 (`conflict`), missing/foreign 404. +- Answer paths (`packages/operations/src/inbox-write-core.ts`): ask/question `{answer}`, interaction `{optionId}|{decline}`, secret `{secret}|{decline}` (web only), approval `{decision}`, acknowledge `{}`/`{answer}`. Archive per store: interaction → deny; ask → closed + agent told. +- Permission items carry no options: the options come from `getAcpInteractionDetail` (`useAcpPermissionCard.ts`). Secret items need the request + existing value from `getSecretRequest` (as `SecretRequestCard`). +- Bell: `NotificationCenter.tsx` mounted in `DesktopSidebar` and `MobileAppBar` (only one per viewport). It owns the notification socket via `useNotifications` (only caller). Question dialog: `NotificationQuestionDialog` (+ loader, `NotificationItem`, `attention-request.ts`) used only by the bell and `ProjectNotifications`. +- `AttentionAnswerControls` is also used by the chat `HumanInputCard`: extend, do not fork. +- `AcpPermissionCard` buttons live in `PermissionOptions`; `ApprovalItem` buttons are an inline `actions` block. +- Nav: `PROJECT_NAV_ITEMS` / `getGlobalNavItems` in `NavSidebar.tsx` feed desktop; `AppShell` maps the same lists into `MobileNavDrawer` (needs a count field). Command palette has "Go to Notifications". +- `isFullBleedRoute` (`lib/shell-routes.ts`) decides whether the page lays its own panes. +- Query client default `refetchOnWindowFocus: false`: inbox queries must opt in. +- Public docs: `apps/www/src/content/docs/docs/guides/notifications.md`, `chat-features.md`, `collaboration.md`; screenshot spec `docs-screenshots-notifications.spec.ts`; audits `notification-question-audit.spec.ts`, `notification-tabs-audit.spec.ts`. +- F1 (PR #2775) also edits `PROJECT_NAV_ITEMS` and `isFullBleedRoute`: expect a trivial rebase conflict; do not edit `pages/project-overview/`. + +## Checklist + +- [ ] API client `lib/api/inbox.ts` + query options `lib/query-options/inbox.ts` (identity-scoped keys, focus refetch, no polling) +- [ ] Hooks: `useInboxCount`, `useInboxList` (infinite), `useInboxItem`; socket `notification.new`/`updated` invalidates inbox queries +- [ ] Split `PermissionOptions` (exported, inline/pinned layout) out of `AcpPermissionCard`; chat card unchanged in behaviour +- [ ] Split `ApprovalDecisionButtons` out of `ApprovalItem`; Admin + chat card unchanged +- [ ] `AttentionAnswerControls`: injectable submit, "Type a different answer" beside options, radio list + pinned Send above five options, pinned layout +- [ ] Inbox row, chip row (Needs you, Blocking, Tasks, Reviews, Updates; Archived in ⋯ menu; active chip scrolls into view), stacks, empty state, Updates list +- [ ] Item view: meta line, title, reason, link chips, collapsed Context, pinned controls per answer spec, Archive + Open chat in top bar, previous/next, stack counter +- [ ] Auto-advance after answer with one-line receipt; stale item closes itself; failed answer keeps item with error +- [ ] Archive with Undo window, then send; pending archive flushed on navigation/unmount/pagehide (keepalive) +- [ ] Pages `/inbox` and `/projects/:id/inbox` (lazy, full-bleed); phone list → item full screen; desktop list beside item +- [ ] Nav: Inbox in global nav and project nav (replaces project Notifications) with counts, desktop and phone drawer; command palette entry +- [ ] Inbox icon in the bell slot: desktop popover with safe one-tap answers + Open inbox; phone link to page +- [ ] Remove NotificationCenter, NotificationQuestionDialog (+loader), NotificationItem, attention-request, ProjectNotifications; redirect `/projects/:id/notifications` +- [ ] Unit/behavioural tests (answer each kind, archive with/without Undo, failed answer, stale item, last-of-stack → next stack, last overall → empty, nav counts) +- [ ] Rule 82: typed chat cards still render for every harness after the split +- [ ] Playwright audit 375/1280 with stress data; screenshots posted on PR +- [ ] Docs: notifications/chat-features/collaboration guides; docs screenshot spec +- [ ] Interface handoff on feature.inbox + +## Acceptance criteria + +- Inbox reachable from global nav, project nav and the inbox icon on desktop and phone, each with its count. +- Every item kind opens and answers (or shows read-only) through the slice A routes; the agent gets the outcome. +- Answering advances to the next item with a receipt; last of a stack → next stack; last overall → empty state. +- Archive shows Undo; undone archives send nothing; pending archives are sent on navigation and tab close. +- Counts refresh on load, on focus and on notification socket events; no interval polling. +- Refetches never unmount the list or the open item. +- Old bell panel and question dialog removed; push, preferences and settings page stay. +- Staging: real agent `request_human_input` + `request_secret`, one answered and one archived from the inbox at phone and desktop sizes, agent receives both. From 0a99f49bf64aa9f8e954d59cc011ff2da4639c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Mon, 16 Nov 2026 04:43:24 +0000 Subject: [PATCH 02/13] feat(web): inbox pages, nav, quick view and pinned answer controls (slice C) Co-Authored-By: Claude Opus 5.5 --- apps/web/src/App.tsx | 14 +- apps/web/src/components/AppShell.tsx | 42 +- apps/web/src/components/MobileNavDrawer.tsx | 12 +- apps/web/src/components/NavSidebar.tsx | 22 +- .../web/src/components/NotificationCenter.tsx | 397 ------------ ...lobal-command-palette-navigation-items.tsx | 2 + .../components/inbox/InboxAnswerControls.tsx | 418 +++++++++++++ apps/web/src/components/inbox/InboxButton.tsx | 101 +++ .../src/components/inbox/InboxFilterBar.tsx | 122 ++++ .../src/components/inbox/InboxItemView.tsx | 258 ++++++++ .../src/components/inbox/InboxPushInvite.tsx | 65 ++ .../src/components/inbox/InboxQuickView.tsx | 185 ++++++ apps/web/src/components/inbox/InboxRow.tsx | 189 ++++++ .../src/components/inbox/InboxUpdatesList.tsx | 156 +++++ apps/web/src/components/inbox/inbox-model.ts | 231 +++++++ apps/web/src/components/inbox/useInbox.ts | 155 +++++ apps/web/src/components/inbox/useInboxWalk.ts | 241 +++++++ .../notifications/AttentionAnswerControls.tsx | 195 ++++-- .../notifications/NotificationItem.tsx | 226 ------- .../NotificationQuestionDialog.tsx | 260 -------- .../notifications/attention-request.ts | 19 - .../notifications/notification-type-config.ts | 40 +- .../notifications/question-dialog-loader.ts | 9 - .../operations-approvals/ApprovalItem.tsx | 67 +- .../AcpPermissionCard.tsx | 34 +- .../AcpPermissionOptions.tsx | 61 ++ .../useAcpPermissionCard.ts | 3 +- .../src/components/shell/DesktopSidebar.tsx | 6 +- .../web/src/components/shell/MobileAppBar.tsx | 6 +- .../src/hooks/useCommandPaletteContext.tsx | 4 +- apps/web/src/hooks/useNotifications.ts | 12 +- apps/web/src/lib/api/inbox.ts | 78 +++ apps/web/src/lib/api/index.ts | 7 + apps/web/src/lib/query-options/inbox.ts | 59 ++ apps/web/src/lib/query-options/index.ts | 6 + apps/web/src/lib/shell-routes.ts | 5 +- apps/web/src/pages/ProjectNotifications.tsx | 304 --------- apps/web/src/pages/inbox/InboxPage.tsx | 274 ++++++++ apps/web/src/pages/inbox/index.tsx | 13 + .../notification-question-audit.spec.ts | 258 -------- .../notification-tabs-audit.spec.ts | 396 ------------ .../components/notification-badge.test.ts | 133 ---- .../components/notification-grouping.test.tsx | 591 ------------------ .../notification-question-dialog.test.tsx | 153 ----- .../components/notification-types.test.tsx | 220 ------- apps/web/tests/unit/lib/theme-tokens.test.ts | 6 +- .../unit/pages/project-notifications.test.tsx | 288 --------- 47 files changed, 2932 insertions(+), 3411 deletions(-) delete mode 100644 apps/web/src/components/NotificationCenter.tsx create mode 100644 apps/web/src/components/inbox/InboxAnswerControls.tsx create mode 100644 apps/web/src/components/inbox/InboxButton.tsx create mode 100644 apps/web/src/components/inbox/InboxFilterBar.tsx create mode 100644 apps/web/src/components/inbox/InboxItemView.tsx create mode 100644 apps/web/src/components/inbox/InboxPushInvite.tsx create mode 100644 apps/web/src/components/inbox/InboxQuickView.tsx create mode 100644 apps/web/src/components/inbox/InboxRow.tsx create mode 100644 apps/web/src/components/inbox/InboxUpdatesList.tsx create mode 100644 apps/web/src/components/inbox/inbox-model.ts create mode 100644 apps/web/src/components/inbox/useInbox.ts create mode 100644 apps/web/src/components/inbox/useInboxWalk.ts delete mode 100644 apps/web/src/components/notifications/NotificationItem.tsx delete mode 100644 apps/web/src/components/notifications/NotificationQuestionDialog.tsx delete mode 100644 apps/web/src/components/notifications/attention-request.ts delete mode 100644 apps/web/src/components/notifications/question-dialog-loader.ts create mode 100644 apps/web/src/components/project-message-view/AcpPermissionOptions.tsx create mode 100644 apps/web/src/lib/api/inbox.ts create mode 100644 apps/web/src/lib/query-options/inbox.ts delete mode 100644 apps/web/src/pages/ProjectNotifications.tsx create mode 100644 apps/web/src/pages/inbox/InboxPage.tsx create mode 100644 apps/web/src/pages/inbox/index.tsx delete mode 100644 apps/web/tests/playwright/notification-question-audit.spec.ts delete mode 100644 apps/web/tests/playwright/notification-tabs-audit.spec.ts delete mode 100644 apps/web/tests/unit/components/notification-badge.test.ts delete mode 100644 apps/web/tests/unit/components/notification-grouping.test.tsx delete mode 100644 apps/web/tests/unit/components/notification-question-dialog.test.tsx delete mode 100644 apps/web/tests/unit/components/notification-types.test.tsx delete mode 100644 apps/web/tests/unit/pages/project-notifications.test.tsx diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index ab06158e01..4dedd35846 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -134,10 +134,8 @@ const ProjectCommentReader = lazyNamed( const ProjectFiles = lazyNamed(() => 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'); @@ -307,6 +305,7 @@ export default function App() { }> } /> )} /> + )} /> )} /> )} /> )} /> @@ -372,7 +371,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..bd7c4e2dfc 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 { useNotifications } from '../hooks/useNotifications'; 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 new-notification events refresh the inbox counts + // and lists (and the Updates chip), so nothing polls. + useNotifications(); + + // 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 bc7ef10690..d456696ac0 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, Lightbulb, Map, MessageSquare, @@ -28,17 +28,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: }, @@ -61,6 +65,8 @@ export function getGlobalNavItems(samEnabled: boolean): NavItem[] { /** Project sub-nav items — paths are relative to /projects/:id/ */ export const PROJECT_NAV_ITEMS: NavItem[] = [ { 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 @@ -71,7 +77,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: }, @@ -134,6 +139,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); @@ -149,7 +156,7 @@ export function NavSidebar({ onToggleGlobalNav?.(); }; - const renderItem = (item: NavItem, to: string, active: boolean) => ( + const renderItem = (item: NavItem, to: string, active: boolean, inboxCount?: number) => ( ); @@ -232,7 +241,8 @@ export function NavSidebar({ renderItem( item, `/projects/${projectId}/${item.path}`, - isProjectSubActive(item.path, projectId, location.pathname) + isProjectSubActive(item.path, projectId, location.pathname), + projectInboxCount ) )} @@ -258,7 +268,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} @@ -285,7 +295,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..7d10e80e21 --- /dev/null +++ b/apps/web/src/components/inbox/InboxAnswerControls.tsx @@ -0,0 +1,418 @@ +import { + type InboxActionResponse, + type InboxItem, + OPERATIONS_IRREVERSIBLE_ACTIONS, + type OperationsAction, +} from '@simple-agent-manager/shared'; +import { Button } from '@simple-agent-manager/ui'; +import { useQuery } from '@tanstack/react-query'; +import { MessageSquare, RefreshCw } from 'lucide-react'; +import { useEffect, useRef, useState } from 'react'; +import { Link } from 'react-router'; + +import { useQueryScope } from '../../hooks/useQueryScope'; +import { answerInboxItem, getSecretRequest } from '../../lib/api'; +import { ApiClientError } from '../../lib/api/client'; +import { projectChatPath } from '../../lib/project-routes'; +import { projectQueryKeys } from '../../lib/query-options/projects'; +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 { + type PermissionDetail, + type PermissionOption, + usePermissionDetail, +} from '../project-message-view/useAcpPermissionCard'; + +/** The item was answered or closed somewhere else (409), or is gone (404). */ +export function isStaleInboxError(error: unknown): boolean { + return error instanceof ApiClientError && (error.status === 404 || error.status === 409); +} + +function errorText(error: unknown, fallback: string): string { + return error instanceof Error && error.message ? error.message : fallback; +} + +function deliveryNote(response: InboxActionResponse): string { + return response.agentNotified ? '' : ' · the agent will be told shortly'; +} + +export interface InboxAnswerHandlers { + /** The answer was accepted: show `receipt` and move on. */ + onAnswered: (receipt: string) => void; + /** Answered or closed elsewhere: close this item. */ + onStale: () => void; +} + +/** Secure permission detail (title, description, options) for a live permission item. */ +export function useInboxPermissionDetail(item: InboxItem) { + const spec = item.answerSpec; + const live = + spec.type === 'interaction' && + spec.interactionKind === 'permission' && + Boolean(spec.interactionId && item.sessionId) && + item.status === 'open' && + item.canAct; + return usePermissionDetail({ + projectId: item.projectId, + sessionId: item.sessionId ?? '', + interactionId: spec.type === 'interaction' ? (spec.interactionId ?? '') : '', + mayReveal: live, + }); +} + +/** 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 ( + +