Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat: add email sent event to conversation timeline

Gus597576c5b42c
diff --git a/src/cli/daemon/execenv/context.ts b/src/cli/daemon/execenv/context.ts
index 833042f3a..6764d8ca8 100644
--- a/src/cli/daemon/execenv/context.ts
+++ b/src/cli/daemon/execenv/context.ts
@@ -61,10 +61,9 @@ those json are sorted by datetime in asc order.
## RULES
- DM task prompts include a \`sender\` object with the workspace member's name, email, and whether they are the agent owner (\`is_owner\`). Use this to personalize your responses.
- Read @memory.md(if exists) before your action.
-- When you start a new task, read the last ~10 lines of today's timeline to understand what has been asked and done recently.
- - if you don't know the current datetime, obtain the current datetime first.
- When user ask you something you don't have in your current context, try to read the timeline jsonl files for answer (today or previous days).
- Use grep tool to search in the context timeline jsonls if you have clean and focus keywords to recall.
+ - if you don't know the current datetime, obtain the current datetime first.
- When access other local projects, make sure you read the CLAUDE.md/AGENTS.md file under the project root dir to understand the requirements.
`;
@@ -111,8 +110,8 @@ ${task.agent.instructions}
content += `\n## Your Colleagues
Below are your direct colleagues. You can reach them via email.
-**Important:** When communicating with a colleague, always reply to the existing email thread instead of composing a new email. This keeps the full conversation context visible to your colleague so they can pick up where you left off.
-
+**Important:**
+- When communicating with a colleague on the previous topics, always reply to the existing email thread instead of composing a new email. This keeps the full conversation context visible to your colleague so they can pick up where you left off. For a new topic, you can just start a new email.
`;
for (let i = 0; i < task.agent.colleagues.length; i++) {
const c = task.agent.colleagues[i];
diff --git a/src/shared/src/types.ts b/src/shared/src/types.ts
index f54a47ada..3581cdb0b 100644
--- a/src/shared/src/types.ts
+++ b/src/shared/src/types.ts
@@ -243,6 +243,7 @@ export type WsMessage =
| { type: "task.updated"; taskId: string; agentId: string; status: string }
| { type: "task.messages"; taskId: string; messages: TaskMessage[] }
| { type: "email.received"; agentId: string }
+ | { type: "email.sent"; agentId: string }
| { type: "artifact.uploaded"; conversationId: string; artifact: Artifact }
| { type: "followup.dispatched"; conversationId: string; message: Message; task: TaskApi }
| { type: "followup.created"; conversationId: string; message: Message }
diff --git a/src/web/src/app/(app)/w/[slug]/agents/[id]/email/page.tsx b/src/web/src/app/(app)/w/[slug]/agents/[id]/email/page.tsx
index 390606651..a205f641f 100644
--- a/src/web/src/app/(app)/w/[slug]/agents/[id]/email/page.tsx
+++ b/src/web/src/app/(app)/w/[slug]/agents/[id]/email/page.tsx
@@ -42,7 +42,14 @@ export default function AgentEmailPage() {
const agent = agents.find((a) => a.id === agentId);
const isMobile = useIsMobile();
- const [folder, setFolder] = useState<Folder>("inbox");
+ const [folder, _setFolder] = useState<Folder>("inbox");
+ const switchFolder = useCallback((f: Folder) => {
+ _setFolder(f);
+ setEmails([]);
+ setSelectedId(null);
+ setBody(null);
+ setComposing(false);
+ }, []);
const [emails, setEmails] = useState<Email[]>([]);
const unreadCount = useMemo(() => emails.filter(e => e.status === "unread").length, [emails]);
const [loading, setLoading] = useState(true);
@@ -96,15 +103,15 @@ export default function AgentEmailPage() {
}, [agentId, workspaceId]);
useEffect(() => {
- setSelectedId(null);
- setBody(null);
- setComposing(false);
loadEmails(folder, activeAddress);
}, [folder, activeAddress, loadEmails]);
useEffect(() => {
return subscribeWs((msg) => {
- if (msg.type === "email.received" && msg.agentId === agentId) {
+ if (
+ (msg.type === "email.received" && msg.agentId === agentId) ||
+ (msg.type === "email.sent" && msg.agentId === agentId)
+ ) {
loadEmails(folder, activeAddress);
}
});
@@ -188,7 +195,7 @@ export default function AgentEmailPage() {
await sendEmail(agentId, to, subject, htmlBody, workspaceId, attachments.length > 0 ? attachments : undefined, threading, activeAccountId);
toast.success("Email sent");
setComposing(false);
- setFolder("sent");
+ switchFolder("sent");
return true;
} catch {
toast.error("Failed to send email");
@@ -336,7 +343,7 @@ export default function AgentEmailPage() {
<nav className="flex flex-col gap-0.5 px-2">
<button
type="button"
- onClick={() => setFolder("inbox")}
+ onClick={() => switchFolder("inbox")}
className={cn(
"flex items-center gap-2 rounded-lg px-2.5 py-1.5 text-sm transition-colors cursor-pointer",
folder === "inbox"
@@ -354,7 +361,7 @@ export default function AgentEmailPage() {
</button>
<button
type="button"
- onClick={() => setFolder("sent")}
+ onClick={() => switchFolder("sent")}
className={cn(
"flex items-center gap-2 rounded-lg px-2.5 py-1.5 text-sm transition-colors cursor-pointer",
folder === "sent"
@@ -367,7 +374,7 @@ export default function AgentEmailPage() {
</button>
<button
type="button"
- onClick={() => setFolder("untrust")}
+ onClick={() => switchFolder("untrust")}
className={cn(
"flex items-center gap-2 rounded-lg px-2.5 py-1.5 text-sm transition-colors cursor-pointer",
folder === "untrust"
@@ -419,17 +426,26 @@ export default function AgentEmailPage() {
>
<div className="flex items-center justify-between gap-2 mb-0.5">
<p className={cn(
- "text-sm truncate flex items-center gap-1.5",
+ "text-sm truncate",
email.status === "unread" ? "font-semibold" : "font-medium text-muted-foreground"
)}>
- {email.status === "unread" && (
- <span className="size-1.5 rounded-full bg-blue-500 shrink-0" />
- )}
{folder === "sent" ? email.to_email : email.from_email}
</p>
- <span className="text-xs text-muted-foreground shrink-0">
- {relativeTime(email.created_at)}
- </span>
+ <div className="flex items-center gap-1.5 shrink-0">
+ {folder !== "sent" && (
+ <span className={cn(
+ "text-[10px] rounded-full px-1.5 py-0.5 leading-none font-medium",
+ email.status === "unread"
+ ? "bg-blue-500/15 text-blue-600 dark:text-blue-400"
+ : "bg-muted text-muted-foreground"
+ )}>
+ {email.status === "unread" ? "unread" : "read"}
+ </span>
+ )}
+ <span className="text-xs text-muted-foreground">
+ {relativeTime(email.created_at)}
+ </span>
+ </div>
</div>
<p className={cn(
"text-[13px] truncate",
@@ -714,7 +730,7 @@ export default function AgentEmailPage() {
<button
key={f.id}
type="button"
- onClick={() => setFolder(f.id)}
+ onClick={() => switchFolder(f.id)}
className={cn(
"px-2.5 py-1 rounded-md text-xs font-medium transition-colors",
folder === f.id
diff --git a/src/web/src/app/api/email/send/route.ts b/src/web/src/app/api/email/send/route.ts
index fffe7bd23..c76107d0f 100644
--- a/src/web/src/app/api/email/send/route.ts
+++ b/src/web/src/app/api/email/send/route.ts
@@ -7,6 +7,37 @@ import { withAuth } from "@/lib/middleware/auth";
import { withWorkspaceMember } from "@/lib/middleware/workspace";
import { writeJSON, writeError, parseBody } from "@/lib/middleware/helpers";
import { emailToResponse } from "@/lib/api/responses";
+import { broadcastToUser } from "@/lib/broadcast";
+
+async function broadcastEmailSentEvent(
+ db: Parameters<typeof queries.message.createMessage>[0],
+ conversationId: string,
+ ownerId: string,
+ agentId: string,
+ to: string,
+ subject: string,
+) {
+ const eventContent = `Email sent to ${to}: ${subject}`;
+ const eventMsg = await queries.message.createMessage(db, {
+ conversationId,
+ role: "event",
+ content: eventContent,
+ });
+ broadcastToUser(ownerId, {
+ type: "conversation.message",
+ conversationId,
+ message: {
+ id: eventMsg.id,
+ conversation_id: eventMsg.conversationId,
+ role: eventMsg.role as "event",
+ content: eventMsg.content,
+ task_id: eventMsg.taskId,
+ attachment_ids: null,
+ created_at: eventMsg.createdAt,
+ },
+ }).catch(() => {});
+ broadcastToUser(ownerId, { type: "email.sent", agentId }).catch(() => {});
+}
export const POST = withAuth(async (req: NextRequest, ctx) => {
const ws = await withWorkspaceMember(req, ctx);
@@ -149,6 +180,9 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
conversationId: validatedConversationId,
});
}
+ if (agent.ownerId) {
+ await broadcastEmailSentEvent(db, validatedConversationId, agent.ownerId, body.agentId, body.to, body.subject);
+ }
}
return writeJSON(emailToResponse(email));
@@ -221,6 +255,9 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
conversationId: validatedConversationId,
});
}
+ if (agent.ownerId) {
+ await broadcastEmailSentEvent(db, validatedConversationId, agent.ownerId, body.agentId, body.to, body.subject);
+ }
}
return writeJSON(emailToResponse(email));