Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
feat: configurable unread inbox type filter with external-only email support
Gus0b6e425afbaf
diff --git a/src/shared/src/db/queries/inbox.ts b/src/shared/src/db/queries/inbox.tsindex 2bc9a8287..118c3f6d3 100644--- a/src/shared/src/db/queries/inbox.ts+++ b/src/shared/src/db/queries/inbox.ts@@ -6,13 +6,16 @@ export async function listUnreadConversations(db: Database,userId: string,workspaceId: string,- opts?: { limit?: number; before?: string }+ opts?: { limit?: number; before?: string; types?: string[] }) {const limit = opts?.limit ?? 30;const beforeClause = opts?.before? sql`AND t.completed_at < ${opts.before}`: sql``;+ const types = opts?.types?.length ? opts.types : ["user_dm_message"];+ const typePlaceholders = sql.join(types.map(t => sql`${t}`), sql`, `);+const rows = await db.all<{id: string;agent_id: string;@@ -60,17 +63,19 @@ export async function listUnreadConversations(WHERE t.workspace_id = ${workspaceId}AND t.parent_task_id IS NULLAND t.trace_id IS NOT NULL- AND t.type IN ('user_dm_message', 'calendar_event')+ AND t.type IN (${typePlaceholders})AND t.status IN ('completed', 'failed')AND t.completed_at > COALESCE(crs.last_read_at, '1970-01-01T00:00:00.000Z')+ AND NOT (t.type = 'email_notification' AND COALESCE(json_extract(t.context, '$.isInternal'), 0) = 1)AND t.id = (SELECT id FROM agent_task_queueWHERE workspace_id = ${workspaceId}AND conversation_id = c.idAND parent_task_id IS NULLAND trace_id IS NOT NULL- AND type IN ('user_dm_message', 'calendar_event')+ AND type IN (${typePlaceholders})AND status IN ('completed', 'failed')+ AND NOT (type = 'email_notification' AND COALESCE(json_extract(context, '$.isInternal'), 0) = 1)ORDER BY completed_at DESC LIMIT 1)${beforeClause}@@ -88,7 +93,11 @@ export async function getUnreadCount(db: Database,userId: string,workspaceId: string,+ types?: string[],) {+ const validTypes = types?.length ? types : ["user_dm_message"];+ const typePlaceholders = sql.join(validTypes.map(t => sql`${t}`), sql`, `);+const rows = await db.all<{ count: number }>(sql`SELECT COUNT(DISTINCT t.conversation_id) AS countFROM agent_task_queue t@@ -101,9 +110,10 @@ export async function getUnreadCount(WHERE t.workspace_id = ${workspaceId}AND t.parent_task_id IS NULLAND t.trace_id IS NOT NULL- AND t.type IN ('user_dm_message', 'calendar_event')+ AND t.type IN (${typePlaceholders})AND t.status IN ('completed', 'failed')AND t.completed_at > COALESCE(crs.last_read_at, '1970-01-01T00:00:00.000Z')+ AND NOT (t.type = 'email_notification' AND COALESCE(json_extract(t.context, '$.isInternal'), 0) = 1)`);return rows[0]?.count ?? 0;diff --git a/src/shared/src/schemas.ts b/src/shared/src/schemas.tsindex 01bdfa839..68fa7a4e8 100644--- a/src/shared/src/schemas.ts+++ b/src/shared/src/schemas.ts@@ -570,6 +570,7 @@ export const EmailNotifyRequestSchema = z.object({attachments: z.string().optional(),traceId: z.string().optional(),sourceTaskId: z.string().optional(),+ isInternal: z.boolean().optional().default(false),});export type EmailNotifyRequest = z.infer<typeof EmailNotifyRequestSchema>;diff --git a/src/web/src/app/(app)/w/[slug]/unread/page.tsx b/src/web/src/app/(app)/w/[slug]/unread/page.tsxindex ef67c8e7c..a8f42040a 100644--- a/src/web/src/app/(app)/w/[slug]/unread/page.tsx+++ b/src/web/src/app/(app)/w/[slug]/unread/page.tsx@@ -7,8 +7,18 @@ import { useAgentContext } from "@/contexts/agent-context";import { listInboxItems, markAllInboxRead, type InboxItem } from "@/lib/api";import { useInboxCount } from "@/contexts/inbox-count-context";import { Skeleton } from "@/components/ui/skeleton";-import { Inbox } from "lucide-react";+import { Popover, PopoverTrigger, PopoverContent } from "@/components/ui/popover";+import { Checkbox } from "@/components/ui/checkbox";+import { Inbox, ListFilter, CheckCheck } from "lucide-react";import { AvatarRenderer, parseAvatarUrl } from "@/components/avatar";+import {+ INBOX_FILTER_TYPES,+ INBOX_FILTER_LABELS,+ MANDATORY_INBOX_TYPES,+ getInboxFilterTypes,+ setInboxFilterTypes,+ type InboxFilterType,+} from "@/lib/inbox-filter";import type { WsMessage } from "@alook/shared";const INBOX_LIMIT = 30;@@ -53,6 +63,7 @@ function AgentAvatar({ name, avatarUrl, size = 32 }: { name?: string | null; avaconst TYPE_LABELS: Record<string, string> = {user_dm_message: "DM",calendar_event: "Calendar",+ email_notification: "Email",};function TypeBadge({ type }: { type: string | null }) {@@ -132,14 +143,17 @@ export default function InboxPage() {const [loading, setLoading] = useState(true);const [hasMore, setHasMore] = useState(false);const [loadingMore, setLoadingMore] = useState(false);+ const [filterTypes, setFilterTypes] = useState<InboxFilterType[]>(getInboxFilterTypes);const scrollRef = useRef<HTMLDivElement>(null);const isFetchingRef = useRef(false);+ const filterTypesRef = useRef(filterTypes);+ filterTypesRef.current = filterTypes;const loadInitial = useCallback(async (opts?: { silent?: boolean }) => {if (!opts?.silent) setLoading(true);try {- const result = await listInboxItems(workspaceId, { limit: INBOX_LIMIT });+ const result = await listInboxItems(workspaceId, { limit: INBOX_LIMIT, types: filterTypesRef.current });setItems(result.items);setHasMore(result.has_more);} catch {@@ -188,6 +202,7 @@ export default function InboxPage() {const result = await listInboxItems(workspaceId, {limit: INBOX_LIMIT,before: oldest.latest_response_at,+ types: filterTypesRef.current,});if (result.items.length === 0) {setHasMore(false);@@ -225,6 +240,19 @@ export default function InboxPage() {}}, [workspaceId, loadInitial, refreshInboxCount]);+ const handleFilterToggle = useCallback((type: InboxFilterType, checked: boolean) => {+ const next = checked+ ? [...filterTypesRef.current, type]+ : filterTypesRef.current.filter((t) => t !== type);+ setFilterTypes(next);+ setInboxFilterTypes(next);+ filterTypesRef.current = next;+ loadInitial();+ refreshInboxCount();+ }, [loadInitial, refreshInboxCount]);++ const activeFilterCount = filterTypes.length - MANDATORY_INBOX_TYPES.length;+return (<div className="flex flex-col h-full"><div className="flex items-center justify-between border-b border-border/50 px-3 md:px-5 py-2.5 gap-3">@@ -235,13 +263,46 @@ export default function InboxPage() {</p></div><div className="flex items-center gap-2">+ <Popover>+ <PopoverTrigger+ className="flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer"+ >+ <ListFilter className="size-3.5" />+ <span>Filter</span>+ {activeFilterCount > 0 && (+ <span className="size-4 flex items-center justify-center rounded-full bg-primary text-primary-foreground text-[10px] font-medium leading-none">+ {activeFilterCount}+ </span>+ )}+ </PopoverTrigger>+ <PopoverContent side="bottom" align="end" className="w-48">+ <p className="text-xs font-medium text-muted-foreground mb-2">Show in inbox:</p>+ <div className="flex flex-col gap-2">+ {INBOX_FILTER_TYPES.map((type) => {+ const isMandatory = MANDATORY_INBOX_TYPES.includes(type);+ const isChecked = filterTypes.includes(type);+ return (+ <label key={type} className="flex items-center gap-2 cursor-pointer">+ <Checkbox+ checked={isChecked}+ disabled={isMandatory}+ onCheckedChange={(checked) => handleFilterToggle(type, !!checked)}+ />+ <span className="text-sm">{INBOX_FILTER_LABELS[type]}</span>+ </label>+ );+ })}+ </div>+ </PopoverContent>+ </Popover>{!loading && items.length > 0 && (<buttontype="button"onClick={handleMarkAllRead}- className="text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer"+ className="flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer">- Mark all as read+ <CheckCheck className="size-3.5" />+ <span>Mark all as read</span></button>)}</div>diff --git a/src/web/src/app/api/email/notify/route.ts b/src/web/src/app/api/email/notify/route.tsindex 8cdb0001e..7b87f926f 100644--- a/src/web/src/app/api/email/notify/route.ts+++ b/src/web/src/app/api/email/notify/route.ts@@ -126,6 +126,7 @@ export async function POST(req: NextRequest) {const taskService = new TaskService(db)const context: Record<string, unknown> = { conversationType };if (dmUser) context.dmUser = dmUser;+ if (body.isInternal) context.isInternal = true;const traceId = body.traceId || ("tr_" + nanoid());const parentTaskId = body.traceId ? (body.sourceTaskId || null) : null;const task = await taskService.enqueueTask(agent.id, conversationId, agent.workspaceId, prompt, TASK_TYPES.EMAIL_NOTIFICATION, { contextKey: conversationId, context, traceId, parentTaskId })diff --git a/src/web/src/app/api/email/send/route.ts b/src/web/src/app/api/email/send/route.tsindex ddf83609a..862c0f014 100644--- a/src/web/src/app/api/email/send/route.ts+++ b/src/web/src/app/api/email/send/route.ts@@ -144,6 +144,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {messageId,inReplyTo: body.inReplyTo ?? "",references: body.references ?? "",+ isInternal: true,...(body.traceId ? { traceId: body.traceId } : {}),...(body.sourceTaskId ? { sourceTaskId: body.sourceTaskId } : {}),});diff --git a/src/web/src/app/api/inbox/count/route.ts b/src/web/src/app/api/inbox/count/route.tsindex 49a998daa..0a89b601f 100644--- a/src/web/src/app/api/inbox/count/route.ts+++ b/src/web/src/app/api/inbox/count/route.ts@@ -13,7 +13,14 @@ export const GET = withAuth(async (req: NextRequest, ctx) => {const { env } = getCloudflareContext();const db = getDb((env as Env).DB);- const count = await queries.inbox.getUnreadCount(db, ctx.userId, ws.workspaceId);+ const VALID_TYPES = ["user_dm_message", "calendar_event", "email_notification"];+ const typesParam = req.nextUrl.searchParams.get("types");+ const types = typesParam+ ? typesParam.split(",").filter((t) => VALID_TYPES.includes(t))+ : [];+ const validTypes = types.length > 0 ? types : ["user_dm_message"];++ const count = await queries.inbox.getUnreadCount(db, ctx.userId, ws.workspaceId, validTypes);return writeJSON({ count });});diff --git a/src/web/src/app/api/inbox/route.ts b/src/web/src/app/api/inbox/route.tsindex b5b3ef6b8..967a7a6ef 100644--- a/src/web/src/app/api/inbox/route.ts+++ b/src/web/src/app/api/inbox/route.ts@@ -21,7 +21,14 @@ export const GET = withAuth(async (req: NextRequest, ctx) => {return NextResponse.json({ error: "invalid before timestamp" }, { status: 400 });}- const result = await queries.inbox.listUnreadConversations(db, ctx.userId, ws.workspaceId, { limit, before });+ const VALID_TYPES = ["user_dm_message", "calendar_event", "email_notification"];+ const typesParam = req.nextUrl.searchParams.get("types");+ const types = typesParam+ ? typesParam.split(",").filter((t) => VALID_TYPES.includes(t))+ : [];+ const validTypes = types.length > 0 ? types : ["user_dm_message"];++ const result = await queries.inbox.listUnreadConversations(db, ctx.userId, ws.workspaceId, { limit, before, types: validTypes });return writeJSON({ items: result.items, has_more: result.hasMore });});diff --git a/src/web/src/contexts/inbox-count-context.tsx b/src/web/src/contexts/inbox-count-context.tsxindex 68b22a8a2..6a363789c 100644--- a/src/web/src/contexts/inbox-count-context.tsx+++ b/src/web/src/contexts/inbox-count-context.tsx@@ -13,6 +13,7 @@ import { getInboxCount } from "@/lib/api";import { useAgentContext } from "@/contexts/agent-context";import { useWorkspace } from "@/contexts/workspace-context";import { sendTaskNotification } from "@/lib/browser-notification";+import { getInboxFilterTypes } from "@/lib/inbox-filter";import type { WsMessage } from "@alook/shared";interface InboxCountContextValue {@@ -40,7 +41,8 @@ export function InboxCountProvider({ children }: { children: ReactNode }) {agentsRef.current = agents;const refresh = useCallback(() => {- getInboxCount(workspaceId).then((r) => {+ const types = getInboxFilterTypes();+ getInboxCount(workspaceId, { types }).then((r) => {const prev = prevCountRef.current;prevCountRef.current = r.count;setCount(r.count);diff --git a/src/web/src/lib/api.ts b/src/web/src/lib/api.tsindex 232493e84..d15f89499 100644--- a/src/web/src/lib/api.ts+++ b/src/web/src/lib/api.ts@@ -1061,18 +1061,22 @@ export interface InboxItem {export const listInboxItems = (workspaceId: string,- opts?: { limit?: number; before?: string }+ opts?: { limit?: number; before?: string; types?: string[] }) => {const extra: Record<string, string> = {};if (opts?.limit) extra.limit = String(opts.limit);if (opts?.before) extra.before = opts.before;+ if (opts?.types?.length) extra.types = opts.types.join(",");return apiFetch<{ items: InboxItem[]; has_more: boolean }>(`/api/inbox${wsQuery(workspaceId, extra)}`);};-export const getInboxCount = (workspaceId: string) =>- apiFetch<{ count: number }>(`/api/inbox/count${wsQuery(workspaceId)}`);+export const getInboxCount = (workspaceId: string, opts?: { types?: string[] }) => {+ const extra: Record<string, string> = {};+ if (opts?.types?.length) extra.types = opts.types.join(",");+ return apiFetch<{ count: number }>(`/api/inbox/count${wsQuery(workspaceId, extra)}`);+};export const markInboxRead = (conversationId: string, workspaceId: string) =>apiFetch<void>(`/api/inbox/read${wsQuery(workspaceId)}`, {diff --git a/src/web/src/lib/inbox-filter.ts b/src/web/src/lib/inbox-filter.tsnew file mode 100644index 000000000..5f1d185c3--- /dev/null+++ b/src/web/src/lib/inbox-filter.ts@@ -0,0 +1,46 @@+const STORAGE_KEY = "inbox-filter-types";++export const INBOX_FILTER_TYPES = [+ "user_dm_message",+ "calendar_event",+ "email_notification",+] as const;++export type InboxFilterType = (typeof INBOX_FILTER_TYPES)[number];++export const INBOX_FILTER_LABELS: Record<InboxFilterType, string> = {+ user_dm_message: "DM",+ calendar_event: "Calendar",+ email_notification: "Email",+};++export const DEFAULT_INBOX_TYPES: InboxFilterType[] = ["user_dm_message"];++export const MANDATORY_INBOX_TYPES: InboxFilterType[] = ["user_dm_message"];++export function getInboxFilterTypes(): InboxFilterType[] {+ if (typeof window === "undefined") return DEFAULT_INBOX_TYPES;+ try {+ const raw = localStorage.getItem(STORAGE_KEY);+ if (!raw) return DEFAULT_INBOX_TYPES;+ const parsed = JSON.parse(raw) as string[];+ const valid = parsed.filter((t): t is InboxFilterType =>+ INBOX_FILTER_TYPES.includes(t as InboxFilterType),+ );+ if (valid.length === 0) return DEFAULT_INBOX_TYPES;+ for (const m of MANDATORY_INBOX_TYPES) {+ if (!valid.includes(m)) valid.unshift(m);+ }+ return valid;+ } catch {+ return DEFAULT_INBOX_TYPES;+ }+}++export function setInboxFilterTypes(types: InboxFilterType[]): void {+ const withMandatory = [...types];+ for (const m of MANDATORY_INBOX_TYPES) {+ if (!withMandatory.includes(m)) withMandatory.unshift(m);+ }+ localStorage.setItem(STORAGE_KEY, JSON.stringify(withMandatory));+}