Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

feat(ui): Inbox hover popover + full inbox view + SSE subscription

cyh4f7cbe09aaa2
diff --git a/ui/src/App.tsx b/ui/src/App.tsx
index 90e928476..364a566f2 100644
--- a/ui/src/App.tsx
+++ b/ui/src/App.tsx
@@ -23,6 +23,7 @@ import { StatusProvider } from './context/StatusContext';
import { ApiProvider, useApi } from './context/ApiContext';
import { ToastProvider } from './context/ToastContext';
import { ThemeProvider } from './context/ThemeContext';
+import { WorkbenchInboxProvider } from './context/WorkbenchInboxContext';
import { AgentationToggle } from './components/AgentationToggle';
import { useEffect, useState } from 'react';
import type { ReactNode } from 'react';
@@ -177,10 +178,12 @@ function App() {
<StatusProvider>
<ToastProvider>
<ApiProvider>
- <BrowserRouter>
- <AppRoutes />
- </BrowserRouter>
- <AgentationToggle />
+ <WorkbenchInboxProvider>
+ <BrowserRouter>
+ <AppRoutes />
+ </BrowserRouter>
+ <AgentationToggle />
+ </WorkbenchInboxProvider>
</ApiProvider>
</ToastProvider>
</StatusProvider>
diff --git a/ui/src/components/workbench/InboxPage.tsx b/ui/src/components/workbench/InboxPage.tsx
index 5b3a20185..57704ac31 100644
--- a/ui/src/components/workbench/InboxPage.tsx
+++ b/ui/src/components/workbench/InboxPage.tsx
@@ -1,6 +1,213 @@
-import { Inbox } from 'lucide-react';
-import { WorkbenchModulePlaceholder } from './WorkbenchModulePlaceholder';
+import { useMemo, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+import { useNavigate } from 'react-router-dom';
+import { ArrowRight, CheckCheck, Filter, Inbox, MessageSquareReply, RefreshCw } from 'lucide-react';
+import clsx from 'clsx';
-export const InboxPage: React.FC = () => (
- <WorkbenchModulePlaceholder icon={<Inbox className="size-6" />} i18nPrefix="workbench.modules.inbox" />
-);
+import { useWorkbenchInbox } from '../../context/WorkbenchInboxContext';
+import type { WorkbenchMessage } from '../../context/ApiContext';
+
+function formatRelativeTime(iso: string): string {
+ if (!iso) return '';
+ const then = new Date(iso).getTime();
+ if (Number.isNaN(then)) return '';
+ const diff = (Date.now() - then) / 1000;
+ if (diff < 60) return 'just now';
+ if (diff < 3600) return `${Math.floor(diff / 60)} min ago`;
+ if (diff < 86400) return `${Math.floor(diff / 3600)} h ago`;
+ return `${Math.floor(diff / 86400)} d ago`;
+}
+
+type FilterMode = 'unread' | 'all';
+
+export const InboxPage: React.FC = () => {
+ const { t } = useTranslation();
+ const navigate = useNavigate();
+ const { recentMessages, totalUnread, refresh, markRead, loading } = useWorkbenchInbox();
+ const [filter, setFilter] = useState<FilterMode>('unread');
+
+ const visible = useMemo(() => {
+ if (filter === 'all') return recentMessages;
+ return recentMessages.filter((m) => m.author === 'agent' && !m.read_at);
+ }, [filter, recentMessages]);
+
+ const onRowOpen = (message: WorkbenchMessage) => {
+ // Per-session chat route lands in commit 12. For now we stay on the
+ // inbox and just mark the message read so the unread state stops
+ // pestering the user.
+ if (message.session_id && !message.read_at) {
+ markRead(message.session_id);
+ }
+ };
+
+ const onMarkAllRead = async () => {
+ const sessionsToMark = new Set<string>();
+ for (const m of recentMessages) {
+ if (m.author === 'agent' && !m.read_at && m.session_id) {
+ sessionsToMark.add(m.session_id);
+ }
+ }
+ await Promise.all(Array.from(sessionsToMark).map((id) => markRead(id)));
+ };
+
+ return (
+ <div className="mx-auto flex w-full max-w-4xl flex-col gap-6 py-2">
+ {/* Header */}
+ <div className="flex items-center gap-4">
+ <div className="flex size-12 shrink-0 items-center justify-center rounded-2xl border border-mint/30 bg-mint/[0.08] text-mint shadow-[0_0_24px_-6px_rgba(91,255,160,0.5)]">
+ <Inbox className="size-5" />
+ </div>
+ <div className="flex flex-1 flex-col">
+ <div className="font-mono text-[10px] font-bold uppercase tracking-[0.18em] text-mint">
+ {t('workbench.inbox.eyebrow')}
+ </div>
+ <h1 className="text-2xl font-bold text-foreground">{t('workbench.inbox.title')}</h1>
+ <p className="text-[13px] text-muted">
+ {t('workbench.inbox.headerCount', { unread: totalUnread, total: recentMessages.length })}
+ </p>
+ </div>
+ <button
+ type="button"
+ onClick={() => refresh()}
+ disabled={loading}
+ className={clsx(
+ 'flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-[12px] font-medium transition',
+ loading
+ ? 'cursor-wait border-border bg-foreground/[0.02] text-muted'
+ : 'border-border-strong text-foreground hover:bg-foreground/[0.04]',
+ )}
+ >
+ <RefreshCw className={clsx('size-3.5', loading && 'animate-spin')} />
+ {t('workbench.inbox.refresh')}
+ </button>
+ </div>
+
+ {/* Toolbar */}
+ <div className="flex items-center gap-2">
+ <div className="inline-flex items-center gap-1 rounded-lg border border-border-strong bg-surface-2 p-0.5">
+ {([
+ { key: 'unread', label: t('workbench.inbox.filterUnread') },
+ { key: 'all', label: t('workbench.inbox.filterAll') },
+ ] as { key: FilterMode; label: string }[]).map(({ key, label }) => (
+ <button
+ key={key}
+ type="button"
+ onClick={() => setFilter(key)}
+ className={clsx(
+ 'flex items-center gap-1.5 rounded-md px-3 py-1.5 text-[12px] font-semibold transition',
+ filter === key
+ ? 'bg-mint/[0.10] text-mint shadow-[0_0_12px_-4px_rgba(91,255,160,0.5)]'
+ : 'text-muted hover:text-foreground',
+ )}
+ >
+ <Filter className="size-3" />
+ {label}
+ </button>
+ ))}
+ </div>
+ <div className="flex-1" />
+ <button
+ type="button"
+ onClick={onMarkAllRead}
+ disabled={totalUnread === 0}
+ className={clsx(
+ 'flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-[12px] font-semibold transition',
+ totalUnread === 0
+ ? 'cursor-not-allowed border-border bg-foreground/[0.02] text-muted'
+ : 'border-mint/30 bg-mint/[0.06] text-mint hover:bg-mint/[0.12]',
+ )}
+ >
+ <CheckCheck className="size-3.5" />
+ {t('workbench.inbox.markAllRead')}
+ </button>
+ </div>
+
+ {/* Empty state */}
+ {visible.length === 0 ? (
+ <div className="flex flex-col items-center gap-3 rounded-2xl border border-dashed border-border bg-surface px-6 py-16 text-center">
+ <CheckCheck className="size-8 text-mint" />
+ <div className="text-[15px] font-semibold text-foreground">
+ {filter === 'unread' ? t('workbench.inbox.allClearTitle') : t('workbench.inbox.emptyTitle')}
+ </div>
+ <div className="max-w-md text-[12.5px] text-muted">
+ {filter === 'unread' ? t('workbench.inbox.allClearBody') : t('workbench.inbox.emptyBody')}
+ </div>
+ </div>
+ ) : (
+ <div className="flex flex-col gap-3">
+ {visible.map((m) => {
+ const unread = m.author === 'agent' && !m.read_at;
+ const projectId = m.scope_id ? m.scope_id.split('::').pop() : null;
+ const sessionLabel = (m.metadata?.session_title as string | undefined) || m.session_id || '—';
+ return (
+ <article
+ key={m.id}
+ className={clsx(
+ 'flex flex-col gap-3 rounded-xl border p-4 transition',
+ unread
+ ? 'border-mint/30 bg-mint/[0.05] shadow-[0_0_24px_-12px_rgba(91,255,160,0.4)]'
+ : 'border-border bg-surface',
+ )}
+ >
+ <div className="flex items-center gap-2 text-[11px]">
+ <span className="inline-flex items-center gap-1 rounded-md border border-border-strong bg-surface-2 px-2 py-0.5 font-mono font-semibold text-cyan">
+ {projectId || 'avibe'}
+ </span>
+ <span className="text-muted">·</span>
+ <span className="flex-1 truncate text-[13px] font-semibold text-foreground">
+ {sessionLabel}
+ </span>
+ <span className="font-mono text-muted">{formatRelativeTime(m.created_at)}</span>
+ </div>
+
+ <div className="flex flex-col gap-1">
+ <div className="flex items-center gap-2 text-[10px]">
+ <span className={clsx('font-bold uppercase tracking-wider', m.author === 'agent' ? 'text-mint' : 'text-cyan')}>
+ {m.author === 'agent' ? t('workbench.inbox.agent') : t('workbench.inbox.you')}
+ </span>
+ </div>
+ <p className={clsx('text-[13px] leading-relaxed', unread ? 'text-foreground' : 'text-muted')}>
+ {m.text || '—'}
+ </p>
+ </div>
+
+ <div className="flex items-center gap-2">
+ <button
+ type="button"
+ onClick={() => onRowOpen(m)}
+ className="inline-flex items-center gap-1.5 rounded-md border border-mint/30 bg-mint/[0.06] px-3 py-1.5 text-[11px] font-semibold text-mint transition hover:bg-mint/[0.12]"
+ >
+ {t('workbench.inbox.openSession')}
+ <ArrowRight className="size-3" />
+ </button>
+ {unread && (
+ <button
+ type="button"
+ onClick={() => m.session_id && markRead(m.session_id)}
+ className="inline-flex items-center gap-1.5 rounded-md border border-border-strong px-3 py-1.5 text-[11px] font-medium text-foreground transition hover:bg-foreground/[0.04]"
+ >
+ <MessageSquareReply className="size-3" />
+ {t('workbench.inbox.markRead')}
+ </button>
+ )}
+ </div>
+ </article>
+ );
+ })}
+ </div>
+ )}
+
+ {/* Footer placeholder — pagination via before_id arrives once the
+ inbox accrues real volume. */}
+ {visible.length > 0 && (
+ <button
+ type="button"
+ onClick={() => navigate('/')}
+ className="self-center text-[11px] text-muted hover:text-foreground"
+ >
+ {t('workbench.inbox.backToCanvas')}
+ </button>
+ )}
+ </div>
+ );
+};
diff --git a/ui/src/components/workbench/WorkbenchSidebar.tsx b/ui/src/components/workbench/WorkbenchSidebar.tsx
index f274dde8e..c8ac67e55 100644
--- a/ui/src/components/workbench/WorkbenchSidebar.tsx
+++ b/ui/src/components/workbench/WorkbenchSidebar.tsx
@@ -1,17 +1,30 @@
+import { useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { NavLink } from 'react-router-dom';
-import { Activity, Bot, ChevronRight, Folder, Inbox, KeyRound, Plus, WandSparkles } from 'lucide-react';
+import { NavLink, useNavigate } from 'react-router-dom';
+import {
+ Activity,
+ ArrowRight,
+ Bot,
+ CheckCheck,
+ ChevronRight,
+ Folder,
+ Inbox,
+ KeyRound,
+ Plus,
+ WandSparkles,
+} from 'lucide-react';
import clsx from 'clsx';
import type { LucideIcon } from 'lucide-react';
+import { useWorkbenchInbox } from '../../context/WorkbenchInboxContext';
+import type { WorkbenchMessage } from '../../context/ApiContext';
+
interface CapabilityNavItem {
to: string;
i18nKey: string;
icon: LucideIcon;
}
-// Order mirrors design.pen DnkGJ — capability modules below the global
-// inbox entry, projects beneath that.
const CAPABILITY_NAV: CapabilityNavItem[] = [
{ to: '/agents', i18nKey: 'workbench.nav.agents', icon: Bot },
{ to: '/skills', i18nKey: 'workbench.nav.skills', icon: WandSparkles },
@@ -19,34 +32,227 @@ const CAPABILITY_NAV: CapabilityNavItem[] = [
{ to: '/vaults', i18nKey: 'workbench.nav.vaults', icon: KeyRound },
];
-// Inbox + 4 capabilities + Projects header for the workbench-mode sidebar
-// middle. Brand and bottom controls live in AppShell so the chrome stays
-// consistent across modes. Project data and the Inbox hover popover are
-// staged in by later commits — commit 02 only ships the entries themselves.
+// 360px floating popover that opens when the user hovers the Inbox entry.
+// Mirrors design.pen KmQ1L — header + a few rows + footer "open full inbox"
+// link. Pure presentational; data comes from <WorkbenchInboxProvider>.
+const InboxHoverPopover: React.FC<{
+ visible: boolean;
+ messages: WorkbenchMessage[];
+ totalUnread: number;
+ onItemClick: (message: WorkbenchMessage) => void;
+ onMarkAllRead: () => void;
+ onMouseEnter: () => void;
+ onMouseLeave: () => void;
+}> = ({ visible, messages, totalUnread, onItemClick, onMarkAllRead, onMouseEnter, onMouseLeave }) => {
+ const { t } = useTranslation();
+ const navigate = useNavigate();
+ if (!visible) return null;
+ const shown = messages.slice(0, 5);
+ const isUnread = (m: WorkbenchMessage) => m.author === 'agent' && !m.read_at;
+ return (
+ <div
+ role="dialog"
+ aria-label={t('workbench.inbox.title')}
+ onMouseEnter={onMouseEnter}
+ onMouseLeave={onMouseLeave}
+ className="absolute left-full top-0 z-50 ml-3 flex w-[360px] flex-col gap-2.5 rounded-2xl border border-border-strong bg-surface-2 p-3.5 shadow-[0_24px_64px_-12px_rgba(0,0,0,0.6)]"
+ >
+ <div className="flex items-start gap-2">
+ <div className="flex flex-1 flex-col">
+ <div className="text-[13px] font-bold text-foreground">{t('workbench.inbox.title')}</div>
+ <div className="text-[10px] text-muted">
+ {t('workbench.inbox.headerCount', { unread: totalUnread, total: messages.length })}
+ </div>
+ </div>
+ <button
+ type="button"
+ onClick={onMarkAllRead}
+ disabled={totalUnread === 0}
+ className={clsx(
+ 'rounded-md border px-2 py-1 text-[10px] font-medium transition',
+ totalUnread === 0
+ ? 'cursor-not-allowed border-border bg-foreground/[0.02] text-muted'
+ : 'border-border-strong text-foreground hover:bg-foreground/[0.04]',
+ )}
+ >
+ {t('workbench.inbox.markAllRead')}
+ </button>
+ </div>
+
+ {shown.length === 0 ? (
+ <div className="rounded-lg border border-dashed border-border px-3 py-6 text-center text-[12px] text-muted">
+ {t('workbench.inbox.empty')}
+ </div>
+ ) : (
+ <div className="flex flex-col gap-1">
+ {shown.map((m) => {
+ const unread = isUnread(m);
+ const projectId = m.scope_id ? m.scope_id.split('::').pop() : null;
+ return (
+ <button
+ key={m.id}
+ type="button"
+ onClick={() => onItemClick(m)}
+ className={clsx(
+ 'flex flex-col gap-1.5 rounded-lg px-3 py-2.5 text-left transition',
+ unread
+ ? 'border-l-2 border-mint bg-mint/[0.06] hover:bg-mint/[0.10]'
+ : 'hover:bg-foreground/[0.04]',
+ )}
+ >
+ <div className="flex items-center gap-1.5 text-[10px]">
+ <span className="truncate font-mono font-semibold text-cyan">{projectId || 'avibe'}</span>
+ <span className="text-muted">·</span>
+ <span className="flex-1 truncate font-semibold text-foreground">
+ {m.metadata?.session_title as string | undefined || m.session_id}
+ </span>
+ <span className="font-mono text-muted">
+ {formatRelativeTime(m.created_at)}
+ </span>
+ </div>
+ <div
+ className={clsx(
+ 'line-clamp-2 text-[11.5px] leading-relaxed',
+ unread ? 'text-foreground' : 'text-muted',
+ )}
+ >
+ {m.text || '—'}
+ </div>
+ </button>
+ );
+ })}
+ </div>
+ )}
+
+ <button
+ type="button"
+ onClick={() => navigate('/inbox')}
+ className="flex items-center justify-center gap-1.5 rounded-md pt-1 text-[11px] font-medium text-cyan hover:underline"
+ >
+ {t('workbench.inbox.viewAll')}
+ <ArrowRight className="size-3" />
+ </button>
+ </div>
+ );
+};
+
+// Render an ISO timestamp as a Slack-ish relative label (2m / 14m / 3h / 1d).
+// Browser-side only; keeps the popover snappy without pulling a date lib.
+function formatRelativeTime(iso: string): string {
+ if (!iso) return '';
+ const then = new Date(iso).getTime();
+ if (Number.isNaN(then)) return '';
+ const diff = (Date.now() - then) / 1000;
+ if (diff < 60) return 'now';
+ if (diff < 3600) return `${Math.floor(diff / 60)}m`;
+ if (diff < 86400) return `${Math.floor(diff / 3600)}h`;
+ return `${Math.floor(diff / 86400)}d`;
+}
+
export const WorkbenchSidebar: React.FC = () => {
const { t } = useTranslation();
+ const navigate = useNavigate();
+ const { totalUnread, recentMessages, markRead } = useWorkbenchInbox();
+ const [popoverOpen, setPopoverOpen] = useState(false);
+ const closeTimer = useRef<number | null>(null);
+
+ // Small open/close delays so the popover doesn't flicker as the cursor
+ // brushes through the inbox row on its way somewhere else, and survives
+ // the gap between the row and the popover body.
+ const openPopover = () => {
+ if (closeTimer.current !== null) {
+ window.clearTimeout(closeTimer.current);
+ closeTimer.current = null;
+ }
+ setPopoverOpen(true);
+ };
+ const queueClose = () => {
+ if (closeTimer.current !== null) {
+ window.clearTimeout(closeTimer.current);
+ }
+ closeTimer.current = window.setTimeout(() => {
+ setPopoverOpen(false);
+ closeTimer.current = null;
+ }, 180);
+ };
+ useEffect(() => {
+ return () => {
+ if (closeTimer.current !== null) window.clearTimeout(closeTimer.current);
+ };
+ }, []);
+
+ const onItemClick = (message: WorkbenchMessage) => {
+ setPopoverOpen(false);
+ // Chat-per-session route lands in commit 12; for now we send the user
+ // to the full inbox so the click goes somewhere meaningful.
+ navigate('/inbox');
+ if (message.session_id && !message.read_at) {
+ markRead(message.session_id);
+ }
+ };
+
+ const onMarkAllRead = async () => {
+ // Mark every session with at least one unread agent message as read.
+ // Cheaper than a dedicated endpoint for now since we already know the
+ // candidate session ids from recentMessages.
+ const sessionsToMark = new Set<string>();
+ for (const m of recentMessages) {
+ if (m.author === 'agent' && !m.read_at && m.session_id) {
+ sessionsToMark.add(m.session_id);
+ }
+ }
+ await Promise.all(Array.from(sessionsToMark).map((id) => markRead(id)));
+ };
+
+ const badge = useMemo(() => {
+ if (totalUnread <= 0) return null;
+ return totalUnread > 99 ? '99+' : String(totalUnread);
+ }, [totalUnread]);
return (
<div className="flex flex-col gap-4">
- <NavLink
- to="/inbox"
- className={({ isActive }) =>
- clsx(
- 'group flex items-center gap-2.5 rounded-lg border px-3 py-2.5 text-[13px] font-semibold transition-colors',
- isActive
- ? 'border-mint/30 bg-mint/[0.08] text-foreground shadow-[0_0_16px_-4px_rgba(91,255,160,0.5)]'
- : 'border-border-strong text-foreground hover:bg-foreground/[0.04]'
- )
- }
+ {/* Inbox entry — hover opens the floating popover. The wrapper element
+ owns the group's hover state so moving from the row into the popover
+ stays inside the open zone. */}
+ <div
+ className="relative"
+ onMouseEnter={openPopover}
+ onMouseLeave={queueClose}
>
- {({ isActive }) => (
- <>
- <Inbox className={clsx('size-4', isActive ? 'text-mint' : 'text-foreground')} />
- <span className="flex-1">{t('workbench.nav.inbox')}</span>
- <ChevronRight className="size-3.5 text-muted opacity-0 transition-opacity group-hover:opacity-100" />
- </>
- )}
- </NavLink>
+ <NavLink
+ to="/inbox"
+ className={({ isActive }) =>
+ clsx(
+ 'group flex items-center gap-2.5 rounded-lg border px-3 py-2.5 text-[13px] font-semibold transition-colors',
+ isActive
+ ? 'border-mint/30 bg-mint/[0.08] text-foreground shadow-[0_0_16px_-4px_rgba(91,255,160,0.5)]'
+ : 'border-border-strong text-foreground hover:bg-foreground/[0.04]',
+ )
+ }
+ >
+ {({ isActive }) => (
+ <>
+ <Inbox className={clsx('size-4', isActive ? 'text-mint' : 'text-foreground')} />
+ <span className="flex-1">{t('workbench.nav.inbox')}</span>
+ {badge && (
+ <span className="inline-flex min-w-[1.25rem] items-center justify-center rounded-full bg-mint px-1.5 py-0.5 font-mono text-[9px] font-bold text-[#080812] shadow-[0_0_10px_-2px_rgba(91,255,160,0.7)]">
+ {badge}
+ </span>
+ )}
+ <ChevronRight className="size-3.5 text-muted opacity-0 transition-opacity group-hover:opacity-100" />
+ </>
+ )}
+ </NavLink>
+ <InboxHoverPopover
+ visible={popoverOpen}
+ messages={recentMessages}
+ totalUnread={totalUnread}
+ onItemClick={onItemClick}
+ onMarkAllRead={onMarkAllRead}
+ onMouseEnter={openPopover}
+ onMouseLeave={queueClose}
+ />
+ </div>
<div className="flex flex-col gap-2">
<div className="px-1 font-mono text-[10px] font-bold uppercase tracking-[0.18em] text-muted">
@@ -62,7 +268,7 @@ export const WorkbenchSidebar: React.FC = () => {
'group flex items-center gap-2.5 rounded-lg px-3 py-2.5 text-[13px] font-medium transition-colors',
isActive
? 'border border-mint/30 bg-mint/[0.08] text-foreground shadow-[0_0_16px_-4px_rgba(91,255,160,0.5)]'
- : 'border border-transparent text-muted hover:bg-foreground/[0.04] hover:text-foreground'
+ : 'border border-transparent text-muted hover:bg-foreground/[0.04] hover:text-foreground',
)
}
>
@@ -86,7 +292,6 @@ export const WorkbenchSidebar: React.FC = () => {
type="button"
aria-label={t('workbench.addProject')}
className="flex size-5 items-center justify-center rounded-md border border-border-strong text-foreground transition hover:bg-foreground/[0.04]"
- // Wired up in commit 05 (projects REST + folder picker).
disabled
>
<Plus className="size-3" />
@@ -100,3 +305,9 @@ export const WorkbenchSidebar: React.FC = () => {
</div>
);
};
+
+// Re-export for tests / future inbox-specific UIs.
+export { InboxHoverPopover };
+// Silence the import that exists only for the un-used CheckCheck icon —
+// it'll be wired into the full Inbox view in commit 09 too.
+void CheckCheck;
diff --git a/ui/src/context/WorkbenchInboxContext.tsx b/ui/src/context/WorkbenchInboxContext.tsx
new file mode 100644
index 000000000..add1dab7f
--- /dev/null
+++ b/ui/src/context/WorkbenchInboxContext.tsx
@@ -0,0 +1,121 @@
+import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
+import type { ReactNode } from 'react';
+
+import { useApi } from './ApiContext';
+import type { WorkbenchMessage } from './ApiContext';
+
+interface InboxState {
+ /** Per-scope unread counts (only agent-authored messages count). */
+ unreadByScope: Record<string, number>;
+ /** Sum of ``unreadByScope`` — cached so consumers don't re-derive. */
+ totalUnread: number;
+ /** Recent agent messages across all sessions (reverse-chronological). */
+ recentMessages: WorkbenchMessage[];
+ loading: boolean;
+ refresh: () => Promise<void>;
+ markRead: (sessionId: string, untilMessageId?: string) => Promise<void>;
+}
+
+const WorkbenchInboxContext = createContext<InboxState | undefined>(undefined);
+
+/** Provider that owns the Inbox state shared across WorkbenchSidebar + InboxPage.
+ *
+ * Connects to ``/api/events`` once on mount and updates state in place when
+ * new messages or unread-count changes arrive. The provider value is memoized
+ * per [[feedback_react_context_value_memoize]] so consumer ``useEffect``
+ * hooks that depend on context functions don't re-fire on every parent
+ * render. */
+export const WorkbenchInboxProvider = ({ children }: { children: ReactNode }) => {
+ const api = useApi();
+ const [unreadByScope, setUnreadByScope] = useState<Record<string, number>>({});
+ const [recentMessages, setRecentMessages] = useState<WorkbenchMessage[]>([]);
+ const [loading, setLoading] = useState(false);
+ // Avoid duplicate refresh-on-first-mount during StrictMode double-invoke.
+ const initialFetched = useRef(false);
+
+ const refresh = useCallback(async () => {
+ setLoading(true);
+ try {
+ const result = await api.listInbox({ platform: 'avibe', limit: 30 });
+ setRecentMessages(result.messages);
+ setUnreadByScope(result.unread_counts);
+ } catch (err) {
+ console.error('[inbox] refresh failed', err);
+ } finally {
+ setLoading(false);
+ }
+ }, [api]);
+
+ const markRead = useCallback(
+ async (sessionId: string, untilMessageId?: string) => {
+ const result = await api.markSessionRead(sessionId, untilMessageId);
+ setUnreadByScope(result.unread_counts);
+ },
+ [api],
+ );
+
+ useEffect(() => {
+ if (!initialFetched.current) {
+ initialFetched.current = true;
+ refresh();
+ }
+ const disconnect = api.connectWorkbenchEvents({
+ onMessageNew: (message) => {
+ // Only agent turns belong on the inbox feed — the user's own
+ // messages don't need to come back as "new" notifications.
+ if (message.author !== 'agent' || message.platform !== 'avibe') return;
+ setRecentMessages((prev) => {
+ // Skip duplicates if the REST POST optimistic update already
+ // added the row (rare for agent-authored events, but defensive).
+ if (prev.some((m) => m.id === message.id)) return prev;
+ return [message, ...prev].slice(0, 30);
+ });
+ if (!message.read_at && message.scope_id) {
+ setUnreadByScope((prev) => ({
+ ...prev,
+ [message.scope_id as string]: (prev[message.scope_id as string] ?? 0) + 1,
+ }));
+ }
+ },
+ onInboxUnreadChanged: (data) => {
+ if (data?.unread_counts) {
+ setUnreadByScope(data.unread_counts);
+ }
+ },
+ onError: (err) => {
+ // Browser EventSource will auto-reconnect; keep this as a log
+ // entry rather than a crash so the workbench stays usable when
+ // the dev proxy is restarting / etc.
+ console.debug('[inbox] sse error', err);
+ },
+ });
+ return disconnect;
+ }, [api, refresh]);
+
+ const totalUnread = useMemo(
+ () => Object.values(unreadByScope).reduce((sum, n) => sum + (n || 0), 0),
+ [unreadByScope],
+ );
+
+ const value = useMemo<InboxState>(
+ () => ({
+ unreadByScope,
+ totalUnread,
+ recentMessages,
+ loading,
+ refresh,
+ markRead,
+ }),
+ [unreadByScope, totalUnread, recentMessages, loading, refresh, markRead],
+ );
+
+ return <WorkbenchInboxContext.Provider value={value}>{children}</WorkbenchInboxContext.Provider>;
+};
+
+export const useWorkbenchInbox = (): InboxState => {
+ const ctx = useContext(WorkbenchInboxContext);
+ if (ctx === undefined) {
+ throw new Error('useWorkbenchInbox must be used inside <WorkbenchInboxProvider>');
+ }
+ return ctx;
+};
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index f98819ac8..a2289e584 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -407,6 +407,26 @@
"harness": "Harness",
"vaults": "Vaults"
},
+ "inbox": {
+ "eyebrow": "Inbox",
+ "title": "Inbox",
+ "headerCount": "{{unread}} unread · {{total}} total",
+ "markAllRead": "Mark all read",
+ "markRead": "Mark read",
+ "viewAll": "Open full inbox",
+ "openSession": "Open session",
+ "refresh": "Refresh",
+ "filterUnread": "Unread",
+ "filterAll": "All",
+ "empty": "Nothing in your inbox yet — agent replies will surface here.",
+ "emptyTitle": "Inbox is empty",
+ "emptyBody": "When an agent posts back from a session, it shows up here.",
+ "allClearTitle": "All caught up",
+ "allClearBody": "No unread agent messages right now. Switch to \"All\" to browse history.",
+ "backToCanvas": "Back to canvas",
+ "agent": "Agent",
+ "you": "You"
+ },
"modules": {
"comingSoonEyebrow": "Coming soon",
"comingSoon": "The full screen lands in a later commit; the route is reserved so the sidebar entry navigates somewhere stable.",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index c005b09f1..94f6aac64 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -407,6 +407,26 @@
"harness": "Harness",
"vaults": "Vaults"
},
+ "inbox": {
+ "eyebrow": "收件箱",
+ "title": "收件箱",
+ "headerCount": "{{unread}} 条未读 · {{total}} 条全部",
+ "markAllRead": "全部已读",
+ "markRead": "标记已读",
+ "viewAll": "查看完整收件箱",
+ "openSession": "打开会话",
+ "refresh": "刷新",
+ "filterUnread": "未读",
+ "filterAll": "全部",
+ "empty": "收件箱还是空的 — Agent 回复会出现在这里。",
+ "emptyTitle": "收件箱是空的",
+ "emptyBody": "当 Agent 从某个会话回过来,就会显示在这里。",
+ "allClearTitle": "全部看完了",
+ "allClearBody": "当前没有未读的 Agent 消息。切到\"全部\"可以浏览历史。",
+ "backToCanvas": "回到画布",
+ "agent": "Agent",
+ "you": "我"
+ },
"modules": {
"comingSoonEyebrow": "即将就位",
"comingSoon": "完整页面在后续 commit 接入,先占住路由让侧栏点击有地方落。",