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
fix: email pull
Gus1d16d12ea41b
diff --git a/src/cli/commands/email.test.ts b/src/cli/commands/email.test.tsindex cac5f5999..532f20765 100644--- a/src/cli/commands/email.test.ts+++ b/src/cli/commands/email.test.ts@@ -249,7 +249,7 @@ describe("email pull output structure", () => {});describe("email status validation", () => {- const VALID_STATUSES = ["unread", "read", "archived"];+ const VALID_STATUSES = ["unread", "read", "archived", "sent"];it("accepts valid status values", () => {for (const s of VALID_STATUSES) {diff --git a/src/cli/commands/email.ts b/src/cli/commands/email.tsindex c8c4178a6..10c942749 100644--- a/src/cli/commands/email.ts+++ b/src/cli/commands/email.ts@@ -25,7 +25,7 @@ interface EmailResponse {created_at: string;}-const VALID_STATUSES = ["unread", "read", "archived"];+const VALID_STATUSES = ["unread", "read", "archived", "sent"];const EMAIL_BASE = "/tmp/alook-emails";const MIME_BY_EXT: Record<string, string> = {diff --git a/src/cli/daemon/execenv/__tests__/context.test.ts b/src/cli/daemon/execenv/__tests__/context.test.tsindex 89e835065..775e9b2d5 100644--- a/src/cli/daemon/execenv/__tests__/context.test.ts+++ b/src/cli/daemon/execenv/__tests__/context.test.ts@@ -42,13 +42,62 @@ describe("buildInstructionContent", () => {it("uses agent name in opening line when provided", () => {const task = makeTask({ agent: { name: "My Assistant", instructions: "" } });const content = buildInstructionContent(task);- expect(content).toMatch(/^You're My Assistant in the Alook Platform\./);+ expect(content).toContain("You're My Assistant in the Alook Platform.");});it("falls back to 'Alook Agent' when agent is undefined", () => {const task = makeTask({ agent: undefined });const content = buildInstructionContent(task);- expect(content).toMatch(/^You're Alook Agent in the Alook Platform\./);+ expect(content).toContain("You're Alook Agent in the Alook Platform.");+ });++ it("includes agent email in opening line", () => {+ const task = makeTask({+ agent: { name: "Aria", instructions: "", emailHandle: "aria" },+ });+ const content = buildInstructionContent(task);+ expect(content).toContain("You're Aria ([email protected]) in the Alook Platform.");+ });++ it("omits email parenthetical when no email configured", () => {+ const task = makeTask({+ agent: { name: "Aria", instructions: "" },+ });+ const content = buildInstructionContent(task);+ expect(content).toContain("You're Aria in the Alook Platform.");+ expect(content).not.toContain("You're Aria (");+ });++ it("includes owner name and email", () => {+ const task = makeTask({+ agent: { name: "Aria", instructions: "", userName: "Gustavo", userEmail: "[email protected]" },+ });+ const content = buildInstructionContent(task);+ expect(content).toContain("Your owner and creator is Gustavo ([email protected]).");+ });++ it("includes owner email without name when name is not available", () => {+ const task = makeTask({+ agent: { name: "Aria", instructions: "", userEmail: "[email protected]" },+ });+ const content = buildInstructionContent(task);+ expect(content).toContain("Your owner and creator is ([email protected]).");+ });++ it("omits owner sentence when no owner info available", () => {+ const task = makeTask({+ agent: { name: "Aria", instructions: "" },+ });+ const content = buildInstructionContent(task);+ expect(content).not.toContain("owner and creator");+ });++ it("uses custom email address when no alook handle", () => {+ const task = makeTask({+ agent: { name: "Aria", instructions: "", emailAddresses: ["[email protected]"] },+ });+ const content = buildInstructionContent(task);+ expect(content).toContain("You're Aria ([email protected]) in the Alook Platform.");});});diff --git a/src/cli/daemon/execenv/context.test.ts b/src/cli/daemon/execenv/context.test.tsindex cb838fa8d..a3fc08873 100644--- a/src/cli/daemon/execenv/context.test.ts+++ b/src/cli/daemon/execenv/context.test.ts@@ -63,24 +63,24 @@ describe("buildInstructionContent email tool injection", () => {expect(content).not.toContain("email send --agent_id");});- it("includes owner email when user email is provided", () => {+ it("includes owner email in opening line when user email is provided", () => {const task = makeTask({agent: { name: "test", instructions: "do stuff", emailHandle: "myagent", userEmail: "[email protected]" },});const content = buildInstructionContent(task);expect(content).toContain("'[email protected]' (default, Alook platform address)");- expect(content).toContain("Your owner's email address is '[email protected]'");+ expect(content).toContain("Your owner and creator is ([email protected]).");});- it("omits owner email line when user email is not provided", () => {+ it("omits owner sentence when user email is not provided", () => {const task = makeTask({agent: { name: "test", instructions: "do stuff", emailHandle: "myagent" },});const content = buildInstructionContent(task);expect(content).toContain("'[email protected]' (default, Alook platform address)");- expect(content).not.toContain("owner's email");+ expect(content).not.toContain("owner and creator");});it("omits email tool section when agent has no email handle", () => {diff --git a/src/cli/daemon/execenv/context.ts b/src/cli/daemon/execenv/context.tsindex 6b2c60be4..1b4f16646 100644--- a/src/cli/daemon/execenv/context.ts+++ b/src/cli/daemon/execenv/context.ts@@ -69,7 +69,17 @@ those json are sorted by datetime in asc order.export function buildInstructionContent(task: Task): string {const displayName = task.agent?.name || "Alook Agent";- let content = `You're ${displayName} in the Alook Platform.\n${SYSTEM_PROMPT_BODY}`;+ const alookAddr = task.agent?.emailHandle ? toAlookAddress(task.agent.emailHandle) : null;+ const customAddrs = (task.agent?.emailAddresses ?? []).filter((a) => a !== alookAddr);+ const primaryEmail = alookAddr ?? customAddrs[0] ?? null;++ let agentLine = `You're ${displayName}${primaryEmail ? ` (${primaryEmail})` : ""} in the Alook Platform.`;+ if (task.agent?.userName || task.agent?.userEmail) {+ const ownerParts = [task.agent.userName, task.agent.userEmail ? `(${task.agent.userEmail})` : null].filter(Boolean).join(" ");+ agentLine += ` Your owner and creator is ${ownerParts}.`;+ }++ let content = `${agentLine}\n${SYSTEM_PROMPT_BODY}`;if (task.agent?.instructions) {content += `## BIG BOSS Instructions@@ -84,15 +94,11 @@ You can communicate with the world through Alook CLI.Your alook agent id is '${task.agentId}'. remember this, most of alook cli will requires you input your agent id.`;- const alookAddr = task.agent?.emailHandle ? toAlookAddress(task.agent.emailHandle) : null;- const customAddrs = (task.agent?.emailAddresses ?? []).filter((a) => a !== alookAddr);-if (alookAddr || customAddrs.length > 0) {const lines: string[] = [];if (alookAddr) lines.push(`- '${alookAddr}' (default, Alook platform address)`);for (const a of customAddrs) lines.push(`- '${a}' (custom IMAP/SMTP mailbox)`);- content += `Your email addresses:\n${lines.join("\n")}-${task.agent?.userEmail ? `Your owner's email address is '${task.agent.userEmail}'.` : ""}+ content += `Your email addresses:\n${lines.join("\n")}\n### Emails---diff --git a/src/cli/daemon/types.ts b/src/cli/daemon/types.tsindex d0f23a942..d7734ac49 100644--- a/src/cli/daemon/types.ts+++ b/src/cli/daemon/types.ts@@ -35,6 +35,7 @@ export interface TaskAgentData {emailHandle?: string | null;emailAddresses?: string[];userEmail?: string | null;+ userName?: string | null;runtimeConfig?: Record<string, unknown>;}@@ -122,7 +123,7 @@ export function fromApiTask(api: import("@alook/shared").TaskApi): Task {contextKey: api.context_key ?? null,context: (api.context as Record<string, unknown>) ?? undefined,agent: api.agent- ? { name: api.agent.name, instructions: api.agent.instructions, emailHandle: api.agent.email_handle ?? undefined, emailAddresses: api.agent.email_addresses ?? [], userEmail: api.agent.user_email ?? undefined, runtimeConfig: api.agent.runtime_config ?? undefined }+ ? { name: api.agent.name, instructions: api.agent.instructions, emailHandle: api.agent.email_handle ?? undefined, emailAddresses: api.agent.email_addresses ?? [], userEmail: api.agent.user_email ?? undefined, userName: api.agent.user_name ?? undefined, runtimeConfig: api.agent.runtime_config ?? undefined }: undefined,sender: api.sender? { name: api.sender.name, email: api.sender.email, isOwner: api.sender.is_owner }diff --git a/src/shared/src/db/queries/email.ts b/src/shared/src/db/queries/email.tsindex d4bb20041..436d19a74 100644--- a/src/shared/src/db/queries/email.ts+++ b/src/shared/src/db/queries/email.ts@@ -5,7 +5,7 @@ import type { EmailDirection } from "../../types";export async function createEmail(db: Database,- data: { agentId: string; workspaceId: string; fromEmail: string; toEmail: string; subject: string; r2Key: string; isWhitelisted: boolean; forwarded: boolean; direction: EmailDirection; messageId?: string; inReplyTo?: string; references?: string; htmlBody?: string; attachments?: string }+ data: { agentId: string; workspaceId: string; fromEmail: string; toEmail: string; subject: string; r2Key: string; isWhitelisted: boolean; forwarded: boolean; direction: EmailDirection; messageId?: string; inReplyTo?: string; references?: string; htmlBody?: string; attachments?: string; status?: string }) {const rows = await db.insert(emails).values(data).returning();return rows[0]!;diff --git a/src/shared/src/schemas.ts b/src/shared/src/schemas.tsindex fc57530e8..442ec2d10 100644--- a/src/shared/src/schemas.ts+++ b/src/shared/src/schemas.ts@@ -52,6 +52,7 @@ export const TaskAgentDataApiSchema = z.object({email_handle: z.string().nullable().optional(),email_addresses: z.array(z.string()).default([]),user_email: z.string().nullable().optional(),+ user_name: z.string().nullable().optional(),});export type TaskAgentDataApi = z.infer<typeof TaskAgentDataApiSchema>;@@ -428,7 +429,7 @@ export const SendEmailRequestSchema = z.object({export type SendEmailRequest = z.infer<typeof SendEmailRequestSchema>;export const UpdateEmailStatusRequestSchema = z.object({- status: z.enum(["unread", "read", "archived"]),+ status: z.enum(["unread", "read", "archived", "sent"]),});export type UpdateEmailStatusRequest = z.infer<typeof UpdateEmailStatusRequestSchemadiff --git a/src/web/src/app/api/daemon/tasks/poll/route.ts b/src/web/src/app/api/daemon/tasks/poll/route.tsindex 3d4547b2f..8f854ee49 100644--- a/src/web/src/app/api/daemon/tasks/poll/route.ts+++ b/src/web/src/app/api/daemon/tasks/poll/route.ts@@ -111,6 +111,16 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {}}+ // Resolve owner name+ let ownerName: string | null = null;+ if (agent?.ownerId) {+ if (!userCache.has(agent.ownerId)) {+ const u = await queries.user.getUser(db, agent.ownerId);+ userCache.set(agent.ownerId, u ? { name: u.name, email: u.email } : null);+ }+ ownerName = userCache.get(agent.ownerId)?.name ?? null;+ }+// Resolve sender identity for DM tasks onlylet sender: { name: string; email: string; is_owner: boolean } | null = null;if (task.type === "user_dm_message" && task.conversationId) {@@ -142,6 +152,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {email_handle: agent.emailHandle || null,email_addresses: emailAddresses,user_email: ctx.email || null,+ user_name: ownerName,}: null,});diff --git a/src/web/src/app/api/email/route.ts b/src/web/src/app/api/email/route.tsindex 93547e092..b59ad4cca 100644--- a/src/web/src/app/api/email/route.ts+++ b/src/web/src/app/api/email/route.ts@@ -7,7 +7,7 @@ import { withWorkspaceMember } from "@/lib/middleware/workspace";import { writeJSON, writeError } from "@/lib/middleware/helpers";import { emailToResponse } from "@/lib/api/responses";-const VALID_STATUSES = ["unread", "read", "archived"];+const VALID_STATUSES = ["unread", "read", "archived", "sent"];export const GET = withAuth(async (req: NextRequest, ctx) => {const ws = await withWorkspaceMember(req, ctx);@@ -38,8 +38,10 @@ export const GET = withAuth(async (req: NextRequest, ctx) => {emailList = await queries.email.getSentEmails(db, agentId, agentEmail, ws.workspaceId, status);} else if (folder === "untrust" && agentEmail) {emailList = await queries.email.getRejectedEmails(db, agentId, agentEmail, ws.workspaceId, status);- } else {+ } else if (folder === "all") {emailList = await queries.email.getEmailsByAgent(db, agentId, ws.workspaceId, status);+ } else {+ emailList = await queries.email.getInboxEmails(db, agentId, agentEmail, ws.workspaceId, status);}return writeJSON(emailList.map(emailToResponse));diff --git a/src/web/src/app/api/email/send/route.ts b/src/web/src/app/api/email/send/route.tsindex d8606d72f..fffe7bd23 100644--- a/src/web/src/app/api/email/send/route.ts+++ b/src/web/src/app/api/email/send/route.ts@@ -137,6 +137,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {htmlBody,attachments: JSON.stringify(attachments),direction: "outbound",+ status: "sent",});if (validatedConversationId) {@@ -208,6 +209,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {htmlBody: body.htmlBody || "",attachments: JSON.stringify(attachments),direction: "outbound",+ status: "sent",});if (validatedConversationId && emailResult.messageId) {diff --git a/src/web/src/components/agent-chat/agent-chat-view.tsx b/src/web/src/components/agent-chat/agent-chat-view.tsxindex 5197b3c0f..7a4ee4249 100644--- a/src/web/src/components/agent-chat/agent-chat-view.tsx+++ b/src/web/src/components/agent-chat/agent-chat-view.tsx@@ -1281,7 +1281,7 @@ export function AgentChatView() {variant="ghost"size="icon-sm"onClick={handleNap}- disabled={napping || !conversation || !currentConvHasMessages}+ disabled={napping || !conversation || !currentConvHasMessages || isTaskActive}className="rounded-lg text-muted-foreground/60 hover:text-foreground transition-colors duration-200">{napping ? (@@ -1293,7 +1293,7 @@ export function AgentChatView() {</span>)} /><TooltipContent side="top">- {currentConvHasMessages ? "Take a nap" : `${agentName} is well-rested and ready to go`}+ {isTaskActive ? "Wait for the task to finish" : currentConvHasMessages ? "Take a nap" : `${agentName} is well-rested and ready to go`}</TooltipContent></Tooltip><Tooltip>