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: add whitelist comonpent
Gusbee835ad6e81
diff --git a/src/shared/src/db/queries/whitelist.ts b/src/shared/src/db/queries/whitelist.tsindex 922fbafaa..00f933983 100644--- a/src/shared/src/db/queries/whitelist.ts+++ b/src/shared/src/db/queries/whitelist.ts@@ -18,8 +18,18 @@ export async function addWhitelist(db: Database, agentId: string, workspaceId: sreturn rows[0] ?? null;}-export async function removeWhitelist(db: Database, id: string) {- await db.delete(agentWhitelist).where(eq(agentWhitelist.id, id));+export async function removeWhitelist(db: Database, id: string, agentId: string, workspaceId: string) {+ const rows = await db+ .delete(agentWhitelist)+ .where(+ and(+ eq(agentWhitelist.id, id),+ eq(agentWhitelist.agentId, agentId),+ eq(agentWhitelist.workspaceId, workspaceId),+ )+ )+ .returning();+ return rows[0] ?? null;}export async function isWhitelisted(db: Database, agentId: string, workspaceId: string, email: string): Promise<boolean> {diff --git a/src/shared/src/index.ts b/src/shared/src/index.tsindex 73e3fd67f..9e4147780 100644--- a/src/shared/src/index.ts+++ b/src/shared/src/index.ts@@ -96,6 +96,7 @@ export {UpdateCalendarEventRequestSchema,DeleteCalendarEventRequestSchema,CalendarEventApiSchema,+ AddWhitelistRequestSchema,} from "./schemas";export type {@@ -119,6 +120,7 @@ export type {UpdateCalendarEventRequestInput,DeleteCalendarEventRequestInput,CalendarEventApi,+ AddWhitelistRequest,} from "./schemas";// Databasediff --git a/src/shared/src/schemas.ts b/src/shared/src/schemas.tsindex 5e730469d..9ee2c93dc 100644--- a/src/shared/src/schemas.ts+++ b/src/shared/src/schemas.ts@@ -291,3 +291,12 @@ export const CalendarEventApiSchema = z.object({updated_at: z.string(),});export type CalendarEventApi = z.infer<typeof CalendarEventApiSchema>;++// ---------------------------------------------------------------------------+// Whitelist request schema+// ---------------------------------------------------------------------------++export const AddWhitelistRequestSchema = z.object({+ email: z.string().email(),+});+export type AddWhitelistRequest = z.infer<typeof AddWhitelistRequestSchema>;diff --git a/src/web/src/app/api/agents/[id]/whitelist/[whitelistId]/route.test.ts b/src/web/src/app/api/agents/[id]/whitelist/[whitelistId]/route.test.tsnew file mode 100644index 000000000..351825423--- /dev/null+++ b/src/web/src/app/api/agents/[id]/whitelist/[whitelistId]/route.test.ts@@ -0,0 +1,65 @@+import { NextRequest } from "next/server";++vi.mock("@opennextjs/cloudflare", () => ({+ getCloudflareContext: vi.fn(() => ({ env: { DB: {} } })),+}));++const mockRemoveWhitelist = vi.fn();++vi.mock("@alook/shared", () => ({+ createDb: vi.fn(() => ({})),+ queries: {+ whitelist: {+ removeWhitelist: (...args: unknown[]) => mockRemoveWhitelist(...args),+ },+ },+}));++vi.mock("@/lib/middleware/auth", () => ({+ withAuth: vi.fn((handler: any) => async (req: any, ctx?: any) => {+ const params = ctx?.params instanceof Promise ? await ctx.params : ctx?.params;+ return handler(req, { userId: "u1", email: "[email protected]", params });+ }),+}));++vi.mock("@/lib/middleware/workspace", () => ({+ withWorkspaceMember: vi.fn(async () => ({ workspaceId: "w1" })),+}));++import { DELETE } from "./route";++beforeEach(() => vi.clearAllMocks());++describe("DELETE /api/agents/[id]/whitelist/[whitelistId]", () => {+ it("removes entry and returns 204", async () => {+ mockRemoveWhitelist.mockResolvedValue({ id: "wl1", email: "[email protected]" });++ const req = new NextRequest("http://localhost/api/agents/a1/whitelist/wl1", {+ method: "DELETE",+ });+ const ctx = { params: Promise.resolve({ id: "a1", whitelistId: "wl1" }) };+ const res = await DELETE(req, ctx);++ expect(res.status).toBe(204);+ expect(mockRemoveWhitelist).toHaveBeenCalledWith(+ expect.anything(),+ "wl1",+ "a1",+ "w1",+ );+ });++ it("returns 404 for non-existent entry", async () => {+ mockRemoveWhitelist.mockResolvedValue(null);++ const req = new NextRequest("http://localhost/api/agents/a1/whitelist/wl999", {+ method: "DELETE",+ });+ const ctx = { params: Promise.resolve({ id: "a1", whitelistId: "wl999" }) };+ const res = await DELETE(req, ctx);+ const body = await res.json();++ expect(res.status).toBe(404);+ expect(body.error).toBe("whitelist entry not found");+ });+});diff --git a/src/web/src/app/api/agents/[id]/whitelist/[whitelistId]/route.ts b/src/web/src/app/api/agents/[id]/whitelist/[whitelistId]/route.tsnew file mode 100644index 000000000..a6f083c47--- /dev/null+++ b/src/web/src/app/api/agents/[id]/whitelist/[whitelistId]/route.ts@@ -0,0 +1,22 @@+import { getCloudflareContext } from "@opennextjs/cloudflare"+import { createDb, queries } from "@alook/shared"+import { withAuth } from "@/lib/middleware/auth"+import { withWorkspaceMember } from "@/lib/middleware/workspace"+import { writeError } from "@/lib/middleware/helpers"++export const DELETE = withAuth(async (req, ctx) => {+ const ws = await withWorkspaceMember(req, ctx);+ if (ws instanceof Response) return ws;++ const { env } = getCloudflareContext();+ const db = createDb((env as Env).DB);++ const agentId = ctx.params?.id;+ const whitelistId = ctx.params?.whitelistId;+ if (!agentId || !whitelistId) return writeError("missing required params", 400);++ const removed = await queries.whitelist.removeWhitelist(db, whitelistId, agentId, ws.workspaceId);+ if (!removed) return writeError("whitelist entry not found", 404);++ return new Response(null, { status: 204 });+});diff --git a/src/web/src/app/api/agents/[id]/whitelist/route.test.ts b/src/web/src/app/api/agents/[id]/whitelist/route.test.tsnew file mode 100644index 000000000..2980a813e--- /dev/null+++ b/src/web/src/app/api/agents/[id]/whitelist/route.test.ts@@ -0,0 +1,191 @@+import { NextRequest } from "next/server";++vi.mock("@opennextjs/cloudflare", () => ({+ getCloudflareContext: vi.fn(() => ({ env: { DB: {} } })),+}));++const mockGetAgent = vi.fn();+const mockGetWhitelist = vi.fn();+const mockAddWhitelist = vi.fn();++vi.mock("@alook/shared", () => ({+ createDb: vi.fn(() => ({})),+ queries: {+ agent: {+ getAgent: (...args: unknown[]) => mockGetAgent(...args),+ },+ whitelist: {+ getWhitelist: (...args: unknown[]) => mockGetWhitelist(...args),+ addWhitelist: (...args: unknown[]) => mockAddWhitelist(...args),+ },+ },+ AddWhitelistRequestSchema: {+ parse(data: unknown) {+ const { z } = require("zod");+ return z.object({ email: z.string().email() }).parse(data);+ },+ },+}));++vi.mock("@/lib/middleware/auth", () => ({+ withAuth: vi.fn((handler: any) => async (req: any, ctx?: any) => {+ const params = ctx?.params instanceof Promise ? await ctx.params : ctx?.params;+ return handler(req, { userId: "u1", email: "[email protected]", params });+ }),+}));++vi.mock("@/lib/middleware/workspace", () => ({+ withWorkspaceMember: vi.fn(async () => ({ workspaceId: "w1" })),+}));++import { GET, POST } from "./route";++beforeEach(() => vi.clearAllMocks());++describe("GET /api/agents/[id]/whitelist", () => {+ it("returns whitelist entries", async () => {+ mockGetAgent.mockResolvedValue({ id: "a1" });+ mockGetWhitelist.mockResolvedValue([+ { id: "wl1", email: "[email protected]", createdAt: "2024-01-01T00:00:00.000Z" },+ { id: "wl2", email: "[email protected]", createdAt: "2024-01-02T00:00:00.000Z" },+ ]);++ const req = new NextRequest("http://localhost/api/agents/a1/whitelist");+ const ctx = { params: Promise.resolve({ id: "a1" }) };+ const res = await GET(req, ctx);+ const body = await res.json();++ expect(res.status).toBe(200);+ expect(body).toHaveLength(2);+ expect(body[0]).toEqual({ id: "wl1", email: "[email protected]", created_at: "2024-01-01T00:00:00Z" });+ expect(body[1]).toEqual({ id: "wl2", email: "[email protected]", created_at: "2024-01-02T00:00:00Z" });+ });++ it("returns empty array when no entries", async () => {+ mockGetAgent.mockResolvedValue({ id: "a1" });+ mockGetWhitelist.mockResolvedValue([]);++ const req = new NextRequest("http://localhost/api/agents/a1/whitelist");+ const ctx = { params: Promise.resolve({ id: "a1" }) };+ const res = await GET(req, ctx);+ const body = await res.json();++ expect(res.status).toBe(200);+ expect(body).toEqual([]);+ });++ it("returns 404 when agent not found", async () => {+ mockGetAgent.mockResolvedValue(null);++ const req = new NextRequest("http://localhost/api/agents/a1/whitelist");+ const ctx = { params: Promise.resolve({ id: "a1" }) };+ const res = await GET(req, ctx);+ const body = await res.json();++ expect(res.status).toBe(404);+ expect(body.error).toBe("agent not found");+ });+});++describe("POST /api/agents/[id]/whitelist", () => {+ it("adds email and returns 201", async () => {+ mockGetAgent.mockResolvedValue({ id: "a1" });+ mockAddWhitelist.mockResolvedValue({+ id: "wl1",+ email: "[email protected]",+ createdAt: "2024-01-01T00:00:00.000Z",+ });++ const req = new NextRequest("http://localhost/api/agents/a1/whitelist", {+ method: "POST",+ body: JSON.stringify({ email: "[email protected]" }),+ });+ const ctx = { params: Promise.resolve({ id: "a1" }) };+ const res = await POST(req, ctx);+ const body = await res.json();++ expect(res.status).toBe(201);+ expect(body).toEqual({ id: "wl1", email: "[email protected]", created_at: "2024-01-01T00:00:00Z" });+ });++ it("rejects invalid email with 400", async () => {+ mockGetAgent.mockResolvedValue({ id: "a1" });++ const req = new NextRequest("http://localhost/api/agents/a1/whitelist", {+ method: "POST",+ body: JSON.stringify({ email: "not-an-email" }),+ });+ const ctx = { params: Promise.resolve({ id: "a1" }) };+ const res = await POST(req, ctx);++ expect(res.status).toBe(400);+ });++ it("rejects missing email with 400", async () => {+ mockGetAgent.mockResolvedValue({ id: "a1" });++ const req = new NextRequest("http://localhost/api/agents/a1/whitelist", {+ method: "POST",+ body: JSON.stringify({}),+ });+ const ctx = { params: Promise.resolve({ id: "a1" }) };+ const res = await POST(req, ctx);++ expect(res.status).toBe(400);+ });++ it("normalizes email to lowercase", async () => {+ mockGetAgent.mockResolvedValue({ id: "a1" });+ mockAddWhitelist.mockResolvedValue({+ id: "wl1",+ email: "[email protected]",+ createdAt: "2024-01-01T00:00:00.000Z",+ });++ const req = new NextRequest("http://localhost/api/agents/a1/whitelist", {+ method: "POST",+ body: JSON.stringify({ email: "[email protected]" }),+ });+ const ctx = { params: Promise.resolve({ id: "a1" }) };+ const res = await POST(req, ctx);++ expect(res.status).toBe(201);+ expect(mockAddWhitelist).toHaveBeenCalledWith(+ expect.anything(),+ "a1",+ "w1",+ "[email protected]",+ );+ });++ it("handles duplicate with 409", async () => {+ mockGetAgent.mockResolvedValue({ id: "a1" });+ mockAddWhitelist.mockResolvedValue(null);++ const req = new NextRequest("http://localhost/api/agents/a1/whitelist", {+ method: "POST",+ body: JSON.stringify({ email: "[email protected]" }),+ });+ const ctx = { params: Promise.resolve({ id: "a1" }) };+ const res = await POST(req, ctx);+ const body = await res.json();++ expect(res.status).toBe(409);+ expect(body.error).toBe("email already whitelisted");+ });++ it("returns 404 when agent not found", async () => {+ mockGetAgent.mockResolvedValue(null);++ const req = new NextRequest("http://localhost/api/agents/a1/whitelist", {+ method: "POST",+ body: JSON.stringify({ email: "[email protected]" }),+ });+ const ctx = { params: Promise.resolve({ id: "a1" }) };+ const res = await POST(req, ctx);+ const body = await res.json();++ expect(res.status).toBe(404);+ expect(body.error).toBe("agent not found");+ });+});diff --git a/src/web/src/app/api/agents/[id]/whitelist/route.ts b/src/web/src/app/api/agents/[id]/whitelist/route.tsnew file mode 100644index 000000000..661a2af7d--- /dev/null+++ b/src/web/src/app/api/agents/[id]/whitelist/route.ts@@ -0,0 +1,58 @@+import { getCloudflareContext } from "@opennextjs/cloudflare"+import { createDb, queries, AddWhitelistRequestSchema } from "@alook/shared"+import { withAuth } from "@/lib/middleware/auth"+import { withWorkspaceMember } from "@/lib/middleware/workspace"+import { writeJSON, writeError, parseBody, formatTimestamp } from "@/lib/middleware/helpers"++export const GET = withAuth(async (req, ctx) => {+ const ws = await withWorkspaceMember(req, ctx);+ if (ws instanceof Response) return ws;++ const { env } = getCloudflareContext();+ const db = createDb((env as Env).DB);++ const agentId = ctx.params?.id;+ if (!agentId) return writeError("agent id is required", 400);++ const agent = await queries.agent.getAgent(db, agentId, ws.workspaceId);+ if (!agent) return writeError("agent not found", 404);++ const entries = await queries.whitelist.getWhitelist(db, agentId, ws.workspaceId);+ return writeJSON(+ entries.map((w) => ({+ id: w.id,+ email: w.email,+ created_at: formatTimestamp(w.createdAt),+ }))+ );+});++export const POST = withAuth(async (req, ctx) => {+ const ws = await withWorkspaceMember(req, ctx);+ if (ws instanceof Response) return ws;++ const { env } = getCloudflareContext();+ const db = createDb((env as Env).DB);++ const agentId = ctx.params?.id;+ if (!agentId) return writeError("agent id is required", 400);++ const agent = await queries.agent.getAgent(db, agentId, ws.workspaceId);+ if (!agent) return writeError("agent not found", 404);++ const [body, err] = await parseBody(req, AddWhitelistRequestSchema);+ if (err) return err;++ const email = body.email.toLowerCase();+ const entry = await queries.whitelist.addWhitelist(db, agentId, ws.workspaceId, email);+ if (!entry) return writeError("email already whitelisted", 409);++ return writeJSON(+ {+ id: entry.id,+ email: entry.email,+ created_at: formatTimestamp(entry.createdAt),+ },+ 201+ );+});diff --git a/src/web/src/app/api/agents/route.ts b/src/web/src/app/api/agents/route.tsindex e00bb44f4..8401f5114 100644--- a/src/web/src/app/api/agents/route.ts+++ b/src/web/src/app/api/agents/route.ts@@ -100,6 +100,10 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {emailHandle: emailHandle || null,});+ if (emailHandle && ctx.email) {+ await queries.whitelist.addWhitelist(db, newAgent.id, ws.workspaceId, ctx.email.toLowerCase());+ }+if (isOnline(runtime.machineLastSeenAt)) {const taskService = new TaskService(db);await taskService.reconcileAgentStatus(newAgent.id, ws.workspaceId);diff --git a/src/web/src/app/globals.css b/src/web/src/app/globals.cssindex c431e9f9d..3a05821c3 100644--- a/src/web/src/app/globals.css+++ b/src/web/src/app/globals.css@@ -630,6 +630,36 @@animation: blob-drift-4 28s ease-in-out infinite;}+.gradient-blob-5 {+ width: 550px;+ height: 380px;+ top: 35%;+ left: 15%;+ border-radius: 62% 38% 45% 55% / 50% 62% 38% 50%;+ background: oklch(0.90 0.12 90);+ animation: blob-drift-5 26s ease-in-out infinite;+}++.gradient-blob-6 {+ width: 480px;+ height: 450px;+ top: 30%;+ left: 35%;+ border-radius: 45% 55% 60% 40% / 55% 40% 60% 45%;+ background: oklch(0.90 0.06 250);+ animation: blob-drift-6 32s ease-in-out infinite;+}++.gradient-blob-7 {+ width: 520px;+ height: 360px;+ top: 40%;+ right: 15%;+ border-radius: 55% 45% 38% 62% / 42% 58% 42% 58%;+ background: oklch(0.86 0.14 95);+ animation: blob-drift-7 24s ease-in-out infinite;+}+.dark .gradient-blob-1 {background: oklch(0.38 0.16 290);opacity: 0.65;@@ -650,6 +680,21 @@opacity: 0.55;}+.dark .gradient-blob-5 {+ background: oklch(0.38 0.16 290);+ opacity: 0.55;+}++.dark .gradient-blob-6 {+ background: oklch(0.34 0.14 270);+ opacity: 0.5;+}++.dark .gradient-blob-7 {+ background: oklch(0.36 0.18 310);+ opacity: 0.55;+}+/* Blob 1: top-left corner → drifts toward center, morphs shape */@keyframes blob-drift-1 {0%, 100% {@@ -698,6 +743,42 @@}}+/* Blob 5: center-left, gentle horizontal drift */+@keyframes blob-drift-5 {+ 0%, 100% {+ transform: translate(0, 0) scale(1);+ border-radius: 62% 38% 45% 55% / 50% 62% 38% 50%;+ }+ 50% {+ transform: translate(120px, -80px) scale(1.06);+ border-radius: 38% 62% 55% 45% / 62% 38% 50% 50%;+ }+}++/* Blob 6: center, slow pulsing drift */+@keyframes blob-drift-6 {+ 0%, 100% {+ transform: translate(0, 0) scale(1);+ border-radius: 45% 55% 60% 40% / 55% 40% 60% 45%;+ }+ 50% {+ transform: translate(-100px, 100px) scale(1.04);+ border-radius: 55% 45% 40% 60% / 40% 60% 45% 55%;+ }+}++/* Blob 7: center-right, diagonal drift */+@keyframes blob-drift-7 {+ 0%, 100% {+ transform: translate(0, 0) scale(1);+ border-radius: 55% 45% 38% 62% / 42% 58% 42% 58%;+ }+ 50% {+ transform: translate(-140px, 90px) scale(1.05);+ border-radius: 45% 55% 62% 38% / 58% 42% 58% 42%;+ }+}+/* ── Motion tokens ── */@keyframes fade-up {from {diff --git a/src/web/src/components/agent-edit-form.tsx b/src/web/src/components/agent-edit-form.tsxindex 681de5e6e..44cc1307a 100644--- a/src/web/src/components/agent-edit-form.tsx+++ b/src/web/src/components/agent-edit-form.tsx@@ -1,16 +1,30 @@"use client";-import { useState } from "react";+import { useState, useEffect } from "react";import { Button } from "@/components/ui/button";import { Input } from "@/components/ui/input";import { Label } from "@/components/ui/label";import { Textarea } from "@/components/ui/textarea";+import {+ Sheet,+ SheetTrigger,+ SheetContent,+ SheetTitle,+ SheetBody,+} from "@/components/ui/sheet";import { RuntimeSelect } from "@/components/runtime-select";import type { Agent } from "@alook/shared";import { isValidHandle } from "@alook/shared";import type { AgentRuntime as Runtime } from "@alook/shared";import { cn } from "@/lib/utils";-import { LockIcon } from "lucide-react";+import { LockIcon, XIcon, ChevronRightIcon } from "lucide-react";+import { useWorkspace } from "@/contexts/workspace-context";+import {+ listWhitelist,+ addWhitelistEmail,+ removeWhitelistEmail,+ type WhitelistEntry,+} from "@/lib/api";function nameToHandle(name: string): string {return name@@ -189,6 +203,25 @@ export function AgentEditForm({/></div>+ {agent && agent.email_handle && (+ <WhitelistTrigger agentId={agent.id} />+ )}++ {agent && (+ <div className="rounded-lg border border-border/50 bg-muted/30 px-4 py-3">+ <div className="mb-2.5 flex items-center gap-1.5">+ <LockIcon className="size-3 text-muted-foreground/60" />+ <span className="text-xs font-medium text-muted-foreground/60">Set at creation</span>+ </div>+ <div className="flex items-center justify-between">+ <span className="text-xs text-muted-foreground">Email</span>+ <span className="text-xs text-muted-foreground">+ {agent.email_handle ? `${agent.email_handle}@alook.ai` : "Not configured"}+ </span>+ </div>+ </div>+ )}+<div className="flex items-center gap-2 pt-2"><Buttontype="button"@@ -206,22 +239,162 @@ export function AgentEditForm({{saving ? savingLabel : submitLabel}</Button></div>+ </form>+ </div>+ );+}- {agent && (- <div className="rounded-lg border border-border/50 bg-muted/30 px-4 py-3">- <div className="mb-2.5 flex items-center gap-1.5">- <LockIcon className="size-3 text-muted-foreground/60" />- <span className="text-xs font-medium text-muted-foreground/60">Set at creation</span>+function WhitelistTrigger({ agentId }: { agentId: string }) {+ const { workspaceId } = useWorkspace();+ const [open, setOpen] = useState(false);+ const [whitelist, setWhitelist] = useState<WhitelistEntry[]>([]);+ const [newEmail, setNewEmail] = useState("");+ const [loadingWhitelist, setLoadingWhitelist] = useState(true);+ const [addingEmail, setAddingEmail] = useState(false);+ const [error, setError] = useState<string | null>(null);++ useEffect(() => {+ if (!open) return;+ let cancelled = false;+ setLoadingWhitelist(true);+ listWhitelist(agentId, workspaceId)+ .then((entries) => {+ if (!cancelled) setWhitelist(entries);+ })+ .catch(() => {+ if (!cancelled) setError("Failed to load whitelist");+ })+ .finally(() => {+ if (!cancelled) setLoadingWhitelist(false);+ });+ return () => { cancelled = true; };+ }, [agentId, workspaceId, open]);++ const isValidEmail = newEmail.includes("@") && newEmail.trim().length > 0;++ const handleAdd = async () => {+ if (!isValidEmail || addingEmail) return;+ setAddingEmail(true);+ setError(null);+ try {+ const entry = await addWhitelistEmail(agentId, newEmail.toLowerCase(), workspaceId);+ setWhitelist((prev) => [...prev, entry]);+ setNewEmail("");+ } catch (e: unknown) {+ const msg = e instanceof Error ? e.message : "Failed to add email";+ setError(msg);+ } finally {+ setAddingEmail(false);+ }+ };++ const handleRemove = async (entryId: string) => {+ const prev = whitelist;+ setWhitelist((wl) => wl.filter((w) => w.id !== entryId));+ setError(null);+ try {+ await removeWhitelistEmail(agentId, entryId, workspaceId);+ } catch {+ setWhitelist(prev);+ setError("Failed to remove email");+ }+ };++ return (+ <Sheet open={open} onOpenChange={setOpen}>+ <SheetTrigger+ render={+ <button+ type="button"+ className="flex w-full items-center justify-between rounded-lg border border-border/50 bg-muted/30 px-4 py-3 text-left transition-colors hover:bg-muted/50"+ />+ }+ >+ <div>+ <span className="text-sm font-medium">Allowed Senders</span>+ <p className="text-xs text-muted-foreground">+ {whitelist.length > 0+ ? `${whitelist.length} email${whitelist.length !== 1 ? "s" : ""} whitelisted`+ : "All inbound emails will be forwarded"}+ </p>+ </div>+ <ChevronRightIcon className="size-4 text-muted-foreground" />+ </SheetTrigger>+ <SheetContent+ side="right"+ className="data-[side=right]:inset-y-2 data-[side=right]:right-2 data-[side=right]:h-auto data-[side=right]:rounded-xl data-[side=right]:border data-[side=right]:border-l"+ >+ <SheetTitle className="sr-only">Allowed Senders</SheetTitle>+ <SheetBody className="px-8 pt-10 pb-6">+ <div className="space-y-4">+ <div>+ <h2 className="font-heading text-lg font-semibold">Allowed Senders</h2>+ <p className="text-sm text-muted-foreground mt-1">+ Only emails from these addresses will trigger the agent.+ </p></div>- <div className="flex items-center justify-between">- <span className="text-xs text-muted-foreground">Email</span>- <span className="text-xs text-muted-foreground">- {agent.email_handle ? `${agent.email_handle}@alook.ai` : "Not configured"}- </span>+ <div className="flex items-center gap-2">+ <Input+ value={newEmail}+ onChange={(e) => setNewEmail(e.target.value)}+ onKeyDown={(e) => {+ if (e.key === "Enter") {+ e.preventDefault();+ handleAdd();+ }+ }}+ placeholder="[email protected]"+ type="email"+ className="flex-1"+ />+ <Button+ type="button"+ size="sm"+ variant="secondary"+ disabled={!isValidEmail || addingEmail}+ onClick={handleAdd}+ >+ {addingEmail ? "Adding..." : "Add"}+ </Button></div>+ {error && (+ <p className="text-xs text-destructive">{error}</p>+ )}+ {loadingWhitelist ? (+ <div className="space-y-2">+ {[1, 2, 3].map((i) => (+ <span+ key={i}+ className="block h-8 animate-pulse rounded-md bg-muted"+ />+ ))}+ </div>+ ) : whitelist.length === 0 ? (+ <p className="text-sm text-muted-foreground py-4 text-center">+ No allowed senders — all inbound emails will be forwarded.+ </p>+ ) : (+ <div className="space-y-1.5">+ {whitelist.map((entry) => (+ <div+ key={entry.id}+ className="flex items-center justify-between rounded-md border border-border/50 px-3 py-2"+ >+ <span className="text-sm">{entry.email}</span>+ <button+ type="button"+ onClick={() => handleRemove(entry.id)}+ className="rounded-full p-1 text-muted-foreground hover:bg-destructive/10 hover:text-destructive transition-colors"+ >+ <XIcon className="size-3.5" />+ </button>+ </div>+ ))}+ </div>+ )}</div>- )}- </form>- </div>+ </SheetBody>+ </SheetContent>+ </Sheet>);}diff --git a/src/web/src/components/gradient-background.tsx b/src/web/src/components/gradient-background.tsxindex af5e43149..932117e52 100644--- a/src/web/src/components/gradient-background.tsx+++ b/src/web/src/components/gradient-background.tsx@@ -18,6 +18,12 @@ export function GradientBackground() {<div className="gradient-blob gradient-blob-3" />{/* Blob 4 — warm sand, bottom-left → center */}<div className="gradient-blob gradient-blob-4" />+ {/* Blob 5 — warm amber, center-left */}+ <div className="gradient-blob gradient-blob-5" />+ {/* Blob 6 — cool periwinkle, center */}+ <div className="gradient-blob gradient-blob-6" />+ {/* Blob 7 — cream rose, center-right */}+ <div className="gradient-blob gradient-blob-7" />{/* Noise texture overlay */}<svg className="absolute inset-0 w-full h-full opacity-[0.25] mix-blend-multiply dark:mix-blend-overlay pointer-events-none"><filter id={filterId}>diff --git a/src/web/src/lib/api.ts b/src/web/src/lib/api.tsindex e02288afb..064f0fae1 100644--- a/src/web/src/lib/api.ts+++ b/src/web/src/lib/api.ts@@ -296,6 +296,27 @@ export const deleteCalendarEvent = (: {}),});+// Whitelist+export interface WhitelistEntry {+ id: string;+ email: string;+ created_at: string;+}++export const listWhitelist = (agentId: string, workspaceId: string) =>+ apiFetch<WhitelistEntry[]>(`/api/agents/${agentId}/whitelist${wsQuery(workspaceId)}`);++export const addWhitelistEmail = (agentId: string, email: string, workspaceId: string) =>+ apiFetch<WhitelistEntry>(`/api/agents/${agentId}/whitelist${wsQuery(workspaceId)}`, {+ method: "POST",+ body: JSON.stringify({ email }),+ });++export const removeWhitelistEmail = (agentId: string, whitelistId: string, workspaceId: string) =>+ apiFetch<void>(`/api/agents/${agentId}/whitelist/${whitelistId}${wsQuery(workspaceId)}`, {+ method: "DELETE",+ });+// Auth (Better Auth — redirect helpers only, actual auth via Better Auth client)export const signOut = async () => {if (typeof window !== "undefined") {diff --git a/src/web/src/test/e2e/whitelist-crud.test.ts b/src/web/src/test/e2e/whitelist-crud.test.tsnew file mode 100644index 000000000..a7505ed7c--- /dev/null+++ b/src/web/src/test/e2e/whitelist-crud.test.ts@@ -0,0 +1,128 @@+import { describe, it, expect, beforeAll, afterAll } from "vitest"+import { seedTestData, cleanupTestData, type TestSeed } from "../helpers/seed"+import { tokenRequest } from "../helpers/auth"++let seed: TestSeed+let seedB: TestSeed++beforeAll(() => {+ seed = seedTestData()+ seedB = seedTestData()+})+afterAll(() => {+ cleanupTestData(seed)+ cleanupTestData(seedB)+})++describe("whitelist CRUD", () => {+ let addedEntryId: string++ it("GET /api/agents/:id/whitelist returns seeded entry", async () => {+ const res = await tokenRequest(+ `/api/agents/${seed.agentId}/whitelist?workspace_id=${seed.workspaceId}`,+ seed.machineToken,+ )+ expect(res.status).toBe(200)+ const data = await res.json() as Array<Record<string, unknown>>+ expect(Array.isArray(data)).toBe(true)+ expect(data).toHaveLength(1)+ expect(data[0].id).toBe(seed.whitelistId)+ expect(data[0].email).toBe(`${seed.userId}@test.local`)+ })++ it("POST /api/agents/:id/whitelist adds new email", async () => {+ const res = await tokenRequest(+ `/api/agents/${seed.agentId}/whitelist?workspace_id=${seed.workspaceId}`,+ seed.machineToken,+ {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ email: "[email protected]" }),+ },+ )+ expect(res.status).toBe(201)+ const data = await res.json() as Record<string, unknown>+ expect(data.email).toBe("[email protected]")+ expect(data.id).toBeTruthy()+ addedEntryId = data.id as string+ })++ it("GET /api/agents/:id/whitelist now returns both entries", async () => {+ const res = await tokenRequest(+ `/api/agents/${seed.agentId}/whitelist?workspace_id=${seed.workspaceId}`,+ seed.machineToken,+ )+ expect(res.status).toBe(200)+ const data = await res.json() as Array<Record<string, unknown>>+ expect(data).toHaveLength(2)+ expect(data.some((e) => e.id === seed.whitelistId)).toBe(true)+ expect(data.some((e) => e.id === addedEntryId)).toBe(true)+ })++ it("DELETE /api/agents/:id/whitelist/:whitelistId removes entry", async () => {+ const res = await tokenRequest(+ `/api/agents/${seed.agentId}/whitelist/${addedEntryId}?workspace_id=${seed.workspaceId}`,+ seed.machineToken,+ { method: "DELETE" },+ )+ expect(res.status).toBe(204)+ })++ it("GET /api/agents/:id/whitelist returns only seeded entry after delete", async () => {+ const res = await tokenRequest(+ `/api/agents/${seed.agentId}/whitelist?workspace_id=${seed.workspaceId}`,+ seed.machineToken,+ )+ expect(res.status).toBe(200)+ const data = await res.json() as Array<Record<string, unknown>>+ expect(data).toHaveLength(1)+ expect(data[0].id).toBe(seed.whitelistId)+ })++ it("POST /api/agents/:id/whitelist returns 409 for duplicate", async () => {+ const res = await tokenRequest(+ `/api/agents/${seed.agentId}/whitelist?workspace_id=${seed.workspaceId}`,+ seed.machineToken,+ {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ email: `${seed.userId}@test.local` }),+ },+ )+ expect(res.status).toBe(409)+ })++ it("POST /api/agents/:id/whitelist normalizes to lowercase", async () => {+ const res = await tokenRequest(+ `/api/agents/${seed.agentId}/whitelist?workspace_id=${seed.workspaceId}`,+ seed.machineToken,+ {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ email: "[email protected]" }),+ },+ )+ expect(res.status).toBe(201)+ const data = await res.json() as Record<string, unknown>+ expect(data.email).toBe("[email protected]")+ })++ it("GET /api/agents/:id/whitelist returns 404 for nonexistent agent", async () => {+ const res = await tokenRequest(+ `/api/agents/nonexistent/whitelist?workspace_id=${seed.workspaceId}`,+ seed.machineToken,+ )+ expect(res.status).toBe(404)+ })+})++describe("whitelist workspace isolation", () => {+ it("DELETE with valid whitelistId but wrong workspace returns 404", async () => {+ const res = await tokenRequest(+ `/api/agents/${seedB.agentId}/whitelist/${seed.whitelistId}?workspace_id=${seedB.workspaceId}`,+ seedB.machineToken,+ { method: "DELETE" },+ )+ expect(res.status).toBe(404)+ })+})diff --git a/src/web/src/test/helpers/seed.ts b/src/web/src/test/helpers/seed.tsindex 0877b9aeb..96b5cd274 100644--- a/src/web/src/test/helpers/seed.ts+++ b/src/web/src/test/helpers/seed.ts@@ -12,6 +12,7 @@ export interface TestSeed {/** Raw machine token (starts with al_) */machineToken: stringmachineTokenId: string+ whitelistId: string}function nanoid() {@@ -46,7 +47,7 @@ export function seedTestData(): TestSeed {sql(`INSERT INTO machine_token (id, user_id, workspace_id, token, name, status, created_at) VALUES ('${machineTokenId}', '${userId}', '${workspaceId}', '${rawToken}', 'test-token', 'active', '${now}')`)sql(`INSERT INTO agent_whitelist (id, agent_id, workspace_id, email, created_at) VALUES ('${whitelistId}', '${agentId}', '${workspaceId}', '${userId}@test.local', '${now}')`)- return { userId, workspaceId, memberId, runtimeId, daemonId, agentId, agentEmailHandle: emailHandle, machineToken: rawToken, machineTokenId }+ return { userId, workspaceId, memberId, runtimeId, daemonId, agentId, agentEmailHandle: emailHandle, machineToken: rawToken, machineTokenId, whitelistId }}/**