Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat: welcome chat, chat quote, and auto-pin leader agent (#63)

Gener329ee9e8391c
diff --git a/src/web/src/app/api/studios/route.test.ts b/src/web/src/app/api/studios/route.test.ts
index 6c618578b..43eebe034 100644
--- a/src/web/src/app/api/studios/route.test.ts
+++ b/src/web/src/app/api/studios/route.test.ts
@@ -47,6 +47,9 @@ vi.mock("@alook/shared", async () => {
conversation: {
createConversation: (...args: unknown[]) => mockCreateConversation(...args),
},
+ agentPin: {
+ pinAgent: vi.fn(),
+ },
},
};
});
@@ -232,7 +235,7 @@ describe("POST /api/studios", () => {
);
});
- it("enqueues welcome email only for leader", async () => {
+ it("enqueues welcome email and welcome chat for leader", async () => {
const req = new NextRequest("http://localhost/api/studios", {
method: "POST",
body: JSON.stringify({
@@ -245,8 +248,8 @@ describe("POST /api/studios", () => {
await POST(req, {});
- expect(mockCreateConversation).toHaveBeenCalledTimes(1);
- expect(mockEnqueueTask).toHaveBeenCalledTimes(1);
+ expect(mockCreateConversation).toHaveBeenCalledTimes(2); // welcome email + welcome chat
+ expect(mockEnqueueTask).toHaveBeenCalledTimes(2);
expect(mockEnqueueTask).toHaveBeenCalledWith(
"agent-1",
expect.any(String),
diff --git a/src/web/src/app/api/studios/route.ts b/src/web/src/app/api/studios/route.ts
index f12c9e868..1fbd5561a 100644
--- a/src/web/src/app/api/studios/route.ts
+++ b/src/web/src/app/api/studios/route.ts
@@ -232,6 +232,17 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
}
}
+ // Pin leader agent by default
+ try {
+ await queries.agentPin.pinAgent(db, {
+ agentId: leaderAgent.id,
+ workspaceId: ws.workspaceId,
+ userId: ctx.userId,
+ });
+ } catch {
+ // Best-effort
+ }
+
// Enqueue welcome email for leader only
const leaderRuntime = runtimeCache.get(body.members.find((m) => m.role === "leader")!.runtime_id);
@@ -266,6 +277,38 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
}
}
+ // Enqueue welcome chat for leader (DM conversation)
+ if (leaderAgent && leaderRuntime && isOnline(leaderRuntime.machineLastSeenAt)) {
+ try {
+ const teammatesList = createdAgents
+ .filter((a) => a.id !== leaderAgent.id)
+ .map((a) => `- ${a.name} (${a.emailHandle}@alook.ai), role: ${a.role}`)
+ .join("\n");
+
+ const welcomeChatPrompt = createdAgents.length === 1
+ ? `You have just been created by your owner (${ctx.email}). Please introduce yourself as "${leaderAgent.name}" in this chat. 1) Introduce yourself warmly — your name and what you can help with. 2) Briefly introduce the Alook platform. 3) Let them know they can chat with you directly or email you anytime. Be warm, professional, and concise. Reply in the same language as your owner's name or email suggests.`
+ : `You have just been created as the lead of a new AI studio by your owner (${ctx.email}). Your teammates are:\n${teammatesList}\n\nPlease introduce yourself and all your teammates in this chat. Include: 1) Your name. 2) Each teammate's name and what they handle. 3) How the team works together — you coordinate and delegate to specialists. 4) Let them know they can chat with you directly to assign work. Be warm, professional, and concise. Reply in the same language as your owner's name or email suggests.`;
+
+ const dmConv = await queries.conversation.createConversation(db, {
+ workspaceId: ws.workspaceId,
+ agentId: leaderAgent.id,
+ userId: ctx.userId,
+ title: `Welcome`,
+ type: TASK_TYPES.USER_DM_MESSAGE,
+ });
+ const taskService2 = new TaskService(db);
+ await taskService2.enqueueTask(
+ leaderAgent.id,
+ dmConv.id,
+ ws.workspaceId,
+ welcomeChatPrompt,
+ TASK_TYPES.USER_DM_MESSAGE,
+ );
+ } catch {
+ // Best-effort
+ }
+ }
+
// Fetch final agents for response
const agents = await queries.agent.listAgents(db, ws.workspaceId, ctx.userId);
const studioAgents = agents.filter((a) => createdAgents.some((ca) => ca.id === a.id));
diff --git a/src/web/src/components/agent-chat/agent-chat-view.tsx b/src/web/src/components/agent-chat/agent-chat-view.tsx
index db61ce7af..349e326cb 100644
--- a/src/web/src/components/agent-chat/agent-chat-view.tsx
+++ b/src/web/src/components/agent-chat/agent-chat-view.tsx
@@ -35,7 +35,7 @@ import { toast } from "sonner";
import { cn } from "@/lib/utils";
import { Skeleton } from "@/components/ui/skeleton";
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
-import { ArrowUp, BedDouble, Box, Calendar, CircleDot, FileText, Loader2, Mail, Mic, Paperclip, Square, X } from "lucide-react";
+import { ArrowUp, BedDouble, Box, Calendar, CircleDot, FileText, Loader2, Mail, MessageSquareQuote, Mic, Paperclip, Square, X } from "lucide-react";
import { useSpeechRecognition } from "@/hooks/use-speech-recognition";
import { useMentionPopup } from "@/hooks/use-mention-popup";
import { MentionPopup } from "@/components/agent-chat/mention-popup";
@@ -362,6 +362,8 @@ export function AgentChatView() {
const [renderNow] = useState(() => Date.now());
const [pendingFilesByMessage, setPendingFilesByMessage] = useState<Map<string, File[]>>(() => new Map());
+ const [quotedText, setQuotedText] = useState<string | null>(null);
+ const [selectionPopup, setSelectionPopup] = useState<{ text: string; x: number; y: number } | null>(null);
const handleSpeechResult = useCallback((text: string) => {
setInput((prev) => (prev ? prev + " " + text : text));
@@ -974,6 +976,42 @@ export function AgentChatView() {
setPendingFiles((prev) => prev.filter((_, i) => i !== index));
}, []);
+ const handleTextSelect = useCallback(() => {
+ const selection = window.getSelection();
+ if (!selection || selection.isCollapsed || !selection.rangeCount) {
+ setSelectionPopup(null);
+ return;
+ }
+ const text = selection.toString().trim();
+ if (!text) { setSelectionPopup(null); return; }
+ // Only allow quoting from assistant message bubbles
+ const range = selection.getRangeAt(0);
+ const container = range.commonAncestorContainer instanceof HTMLElement
+ ? range.commonAncestorContainer
+ : range.commonAncestorContainer.parentElement;
+ if (!container?.closest("[data-quote-source]")) {
+ setSelectionPopup(null);
+ return;
+ }
+ const rects = range.getClientRects();
+ const lastRect = rects[rects.length - 1] || range.getBoundingClientRect();
+ setSelectionPopup({ text, x: lastRect.right, y: lastRect.top - 4 });
+ }, []);
+
+ useEffect(() => {
+ document.addEventListener("selectionchange", handleTextSelect);
+ return () => document.removeEventListener("selectionchange", handleTextSelect);
+ }, [handleTextSelect]);
+
+ const handleQuoteSelection = useCallback(() => {
+ if (selectionPopup) {
+ setQuotedText(selectionPopup.text);
+ setSelectionPopup(null);
+ window.getSelection()?.removeAllRanges();
+ textareaRef.current?.focus();
+ }
+ }, [selectionPopup]);
+
const [dragging, setDragging] = useState(false);
const dragCounter = useRef(0);
@@ -1080,16 +1118,22 @@ export function AgentChatView() {
};
const handleSend = async () => {
- const content = input.trim();
- if ((!content && pendingFiles.length === 0) || sending || !conversation) return;
- if (!content) {
+ const rawContent = input.trim();
+ if ((!rawContent && pendingFiles.length === 0) || sending || !conversation) return;
+ if (!rawContent) {
toast.error("Please type a message");
return;
}
+ // Prepend quoted text as blockquote if present
+ const content = quotedText
+ ? `> ${quotedText.split("\n").join("\n> ")}\n\n${rawContent}`
+ : rawContent;
+
const filesToSend = [...pendingFiles];
setInput("");
setPendingFiles([]);
+ setQuotedText(null);
setSending(true);
const taskActive = !!activeTask && !["completed", "failed", "cancelled", "superseded"].includes(activeTask.status);
@@ -1312,6 +1356,19 @@ export function AgentChatView() {
return (
<>
+ {/* Floating quote button on text selection */}
+ {selectionPopup && (
+ <button
+ type="button"
+ className="fixed z-50 flex items-center gap-1 px-2 py-1 rounded-md bg-popover border shadow-md text-xs text-popover-foreground hover:bg-accent transition-colors"
+ style={{ left: selectionPopup.x, top: selectionPopup.y, transform: "translate(-100%, -100%)" }}
+ onMouseDown={(e) => e.preventDefault()}
+ onClick={handleQuoteSelection}
+ >
+ <MessageSquareQuote className="size-3" />
+ Quote
+ </button>
+ )}
{/* Messages */}
<div
className="flex-1 overflow-y-auto overflow-x-hidden px-3 md:px-5 thin-scrollbar"
@@ -1464,7 +1521,7 @@ export function AgentChatView() {
</div>
);
})() : !hasTaskStream ? (
- <div className="flex justify-start" {...(msg.task_id ? { "data-task-id": msg.task_id } : {})}>
+ <div className="flex justify-start" data-quote-source {...(msg.task_id ? { "data-task-id": msg.task_id } : {})}>
<div className="markdown max-w-full min-w-0 px-1 py-1 text-base text-foreground">
<Streamdown controls={{ code: { copy: true, download: false }, table: { copy: true, download: false, fullscreen: true } }} linkSafety={{ enabled: false }} allowedTags={MENTION_ALLOWED_TAGS} literalTagContent={MENTION_LITERAL_TAGS} components={MENTION_COMPONENTS}>{highlightMentions(msg.content, agents)}</Streamdown>
</div>
@@ -1518,6 +1575,23 @@ export function AgentChatView() {
<p className="text-sm text-muted-foreground font-medium">Drop files here</p>
</div>
)}
+ {quotedText && (
+ <div className="flex items-center gap-2 px-3.5 pt-2.5 pb-1 border-b border-border/50">
+ <div className="flex-1 min-w-0 flex items-start gap-2">
+ <MessageSquareQuote className="size-3.5 shrink-0 mt-0.5 text-muted-foreground" />
+ <p className="text-xs text-muted-foreground truncate">
+ {quotedText.slice(0, 120)}{quotedText.length > 120 ? "..." : ""}
+ </p>
+ </div>
+ <button
+ type="button"
+ onClick={() => setQuotedText(null)}
+ className="shrink-0 p-0.5 rounded-sm hover:bg-muted-foreground/20 transition-colors text-muted-foreground"
+ >
+ <X className="size-3.5" />
+ </button>
+ </div>
+ )}
<MentionPopup
isOpen={mentionPopup.isOpen}
relatedAgents={mentionPopup.relatedAgents}