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 active tasks floating panel on canvas and UI polish
Gusb4f699951efd
diff --git a/src/shared/src/db/queries/task.ts b/src/shared/src/db/queries/task.tsindex 106d1c73d..5780130a0 100644--- a/src/shared/src/db/queries/task.ts+++ b/src/shared/src/db/queries/task.ts@@ -450,6 +450,34 @@ export async function listActiveTaskCountsByWorkspace(.groupBy(agentTaskQueue.agentId);}+export async function listActiveTasksByWorkspace(+ db: Database,+ workspaceId: string+) {+ return db+ .select({+ id: agentTaskQueue.id,+ agentId: agentTaskQueue.agentId,+ prompt: agentTaskQueue.prompt,+ status: agentTaskQueue.status,+ type: agentTaskQueue.type,+ conversationId: agentTaskQueue.conversationId,+ createdAt: agentTaskQueue.createdAt,+ channel: conversation.channel,+ })+ .from(agentTaskQueue)+ .leftJoin(conversation, eq(agentTaskQueue.conversationId, conversation.id))+ .where(+ and(+ eq(agentTaskQueue.workspaceId, workspaceId),+ inArray(agentTaskQueue.status, ["queued", "dispatched", "running"]),+ ne(agentTaskQueue.type, TASK_TYPES.KILL_TASK)+ )+ )+ .orderBy(desc(agentTaskQueue.createdAt))+ .limit(50);+}+export async function listActiveTasksByAgent(db: Database,agentId: string,diff --git a/src/web/src/app/(app)/w/[slug]/home/page.tsx b/src/web/src/app/(app)/w/[slug]/home/page.tsxindex 21bfe02d6..4c5c464e8 100644--- a/src/web/src/app/(app)/w/[slug]/home/page.tsx+++ b/src/web/src/app/(app)/w/[slug]/home/page.tsx@@ -41,6 +41,7 @@ import { ApiError } from "@/lib/errors";import { AgentNode, type AgentNodeData } from "@/components/canvas/agent-node";import { LinkEdge } from "@/components/canvas/link-edge";import { LinkSidecar } from "@/components/canvas/link-sidecar";+import { ActiveTasksFloat } from "@/components/canvas/active-tasks-float";import { getAutoLayout } from "@/components/canvas/auto-layout";const nodeTypes = { agent: AgentNode };@@ -411,6 +412,8 @@ function AgentCanvas() {onSave={handleSidecarSave}onDelete={handleSidecarDelete}/>++ <ActiveTasksFloat /></div>);}diff --git a/src/web/src/app/api/agents/active-tasks/route.ts b/src/web/src/app/api/agents/active-tasks/route.tsnew file mode 100644index 000000000..582ce59f3--- /dev/null+++ b/src/web/src/app/api/agents/active-tasks/route.ts@@ -0,0 +1,32 @@+import { getCloudflareContext } from "@opennextjs/cloudflare";+import { queries } from "@alook/shared";+import { getDb } from "@/lib/db";+import { withAuth } from "@/lib/middleware/auth";+import { withWorkspaceMember } from "@/lib/middleware/workspace";+import { writeJSON } 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 = getDb((env as Env).DB);++ const tasks = await queries.task.listActiveTasksByWorkspace(db, ws.workspaceId);+ const agents = await queries.agent.listAgents(db, ws.workspaceId, ctx.userId);+ const agentMap = new Map(agents.map((a) => [a.id, { name: a.name, avatarUrl: a.avatarUrl }]));++ return writeJSON({+ tasks: tasks.map((t) => ({+ id: t.id,+ agent_id: t.agentId,+ agent: agentMap.get(t.agentId) ?? null,+ prompt: t.prompt,+ status: t.status,+ type: t.type,+ conversation_id: t.conversationId,+ channel: t.channel ?? "default",+ created_at: t.createdAt,+ })),+ });+});diff --git a/src/web/src/app/globals.css b/src/web/src/app/globals.cssindex f239a3e98..5461c4e18 100644--- a/src/web/src/app/globals.css+++ b/src/web/src/app/globals.css@@ -1325,11 +1325,9 @@/* ── Sidebar easter egg: logo click → agents pop ── */@keyframes sidebar-agent-pop {- 0% { transform: scale(1) translateY(0) rotate(0); }- 25% { transform: scale(1.15) translateY(-6px) rotate(-5deg); }- 50% { transform: scale(0.92) translateY(1px) rotate(3deg); }- 75% { transform: scale(1.05) translateY(-2px) rotate(-1deg); }- 100% { transform: scale(1) translateY(0) rotate(0); }+ 0% { transform: translateX(0) scale(1) rotate(0); }+ 28% { transform: translateX(25px) scale(1.08) rotate(-6deg); }+ 100% { transform: translateX(0) scale(1) rotate(0); }}.sidebar-agent-pop {animation: sidebar-agent-pop 500ms cubic-bezier(0.34, 1.56, 0.64, 1) both;diff --git a/src/web/src/components/agent-chat/agent-chat-view.tsx b/src/web/src/components/agent-chat/agent-chat-view.tsxindex 29bbf9035..b605dd9d1 100644--- a/src/web/src/components/agent-chat/agent-chat-view.tsx+++ b/src/web/src/components/agent-chat/agent-chat-view.tsx@@ -507,6 +507,7 @@ export function AgentChatView() {loadingMoreRef.current = true;setLoadingMore(true);const el = scrollRef.current;+ const wasOverflowing = el ? el.scrollHeight > el.clientHeight : false;const prevScrollHeight = el?.scrollHeight ?? 0;try {@@ -578,9 +579,15 @@ export function AgentChatView() {});}+ flushSync(() => setLoadingMore(false));+if (el) {- const newScrollHeight = el.scrollHeight;- el.scrollTop = newScrollHeight - prevScrollHeight;+ if (wasOverflowing) {+ const newScrollHeight = el.scrollHeight;+ el.scrollTop = newScrollHeight - prevScrollHeight;+ } else {+ el.scrollTop = el.scrollHeight;+ }}} catch {toast.error("Failed to load older messages");@@ -1103,7 +1110,7 @@ export function AgentChatView() {<>{/* Messages */}<div- className="flex-1 overflow-y-auto overflow-x-hidden px-3 md:px-5 thin-scrollbar"+ className="flex-1 overflow-y-auto overflow-x-hidden px-3 md:px-5 thin-scrollbar [overflow-anchor:none]"ref={scrollRef}onScroll={handleScroll}onClick={(e) => {diff --git a/src/web/src/components/app-sidebar.tsx b/src/web/src/components/app-sidebar.tsxindex f1efa1588..d956191e5 100644--- a/src/web/src/components/app-sidebar.tsx+++ b/src/web/src/components/app-sidebar.tsx@@ -231,7 +231,7 @@ export function AppSidebar({ onNavigate }: { onNavigate?: () => void } = {}) {);return (- <nav className="flex h-full w-14 flex-col items-center pt-1 pb-2 gap-0.5">+ <nav className={cn("flex h-full w-14 flex-col items-center pt-1 pb-2 gap-0.5", wiggling && "relative z-10")}>{/* Top — logo (easter egg: click to wake agents) */}<div className="pb-1.5 mb-1"><div@@ -280,7 +280,7 @@ export function AppSidebar({ onNavigate }: { onNavigate?: () => void } = {}) {</div>{/* Agent avatars */}- <div className="flex flex-1 w-full flex-col items-center gap-1.5 overflow-y-auto py-1 scrollbar-none">+ <div className={cn("flex flex-1 w-full flex-col items-center gap-1.5 py-1 scrollbar-none", wiggling ? "overflow-visible" : "overflow-y-auto")}>{loading ? (<Skeleton className="size-10 rounded-xl" />) : (diff --git a/src/web/src/components/avatar/avatar-parts.tsx b/src/web/src/components/avatar/avatar-parts.tsxindex 5a8888dda..c278774e8 100644--- a/src/web/src/components/avatar/avatar-parts.tsx+++ b/src/web/src/components/avatar/avatar-parts.tsx@@ -297,9 +297,11 @@ export function AvatarRenderer({ config, size = 200, className }: AvatarRendererstyle={{ display: "block" }}><rect x="0" y="0" width="200" height="200" rx="56" fill={bgColor} />- <g data-avatar-shape="">{sh.render()}</g>- {ey && <g transform={`translate(${cx}, ${eyeY})`}><g data-avatar-eyes="">{ey.render(eyeDx)}</g></g>}- {no && <g transform={`translate(${cx}, ${cy + 5})`}><g data-avatar-nose="">{no.render()}</g></g>}+ <g transform="translate(100,100) scale(0.85) translate(-100,-100)">+ <g data-avatar-shape="">{sh.render()}</g>+ {ey && <g transform={`translate(${cx}, ${eyeY})`}><g data-avatar-eyes="">{ey.render(eyeDx)}</g></g>}+ {no && <g transform={`translate(${cx}, ${cy + 5})`}><g data-avatar-nose="">{no.render()}</g></g>}+ </g></svg>);}diff --git a/src/web/src/components/canvas/active-tasks-float.tsx b/src/web/src/components/canvas/active-tasks-float.tsxnew file mode 100644index 000000000..3d3a3e49e--- /dev/null+++ b/src/web/src/components/canvas/active-tasks-float.tsx@@ -0,0 +1,164 @@+"use client";++import { useState, useRef, useEffect } from "react";+import Link from "next/link";+import { X, Minus } from "lucide-react";+import { useAgentContext } from "@/contexts/agent-context";+import { useWorkspace } from "@/contexts/workspace-context";+import { useIsMobile } from "@/hooks/use-mobile";+import { AvatarRenderer, parseAvatarUrl } from "@/components/avatar";+import type { WorkspaceActiveTask } from "@/lib/api";++function relativeTime(dateStr: string): string {+ const date = new Date(dateStr);+ const now = new Date();+ const diffMs = now.getTime() - date.getTime();+ const diffMin = Math.floor(diffMs / 60000);+ if (diffMin < 1) return "just now";+ if (diffMin < 60) return `${diffMin}m ago`;+ const diffHrs = Math.floor(diffMin / 60);+ if (diffHrs < 24) return `${diffHrs}h ago`;+ const diffDays = Math.floor(diffHrs / 24);+ if (diffDays < 7) return `${diffDays}d ago`;+ return date.toLocaleDateString(undefined, { month: "short", day: "numeric" });+}++function AgentAvatar({ name, avatarUrl, size = 20 }: { name?: string; avatarUrl?: string | null; size?: number }) {+ const config = parseAvatarUrl(avatarUrl);+ if (config) return <AvatarRenderer config={config} size={size} className="rounded-full shrink-0" />;+ return (+ <span+ className="flex items-center justify-center rounded-full bg-secondary text-[7px] font-medium shrink-0"+ style={{ width: size, height: size }}+ >+ {(name ?? "?").charAt(0).toUpperCase()}+ </span>+ );+}++function TaskRow({ task, slug }: { task: WorkspaceActiveTask; slug: string }) {+ const isRunning = task.status === "running";++ return (+ <Link+ href={`/w/${slug}/agents/${task.agent_id}?task=${task.id}&conv=${task.conversation_id}`}+ className="flex items-center gap-2.5 px-3 py-2 hover:bg-accent/50 transition-colors cursor-pointer rounded-md"+ >+ <div className="relative shrink-0">+ <AgentAvatar name={task.agent?.name} avatarUrl={task.agent?.avatarUrl} size={24} />+ <span+ className={`absolute -bottom-0.5 -right-0.5 size-2 rounded-full ring-2 ring-background ${+ isRunning ? "bg-primary animate-pulse" : "bg-muted-foreground/40"+ }`}+ />+ </div>+ <div className="flex-1 min-w-0">+ <div className="flex items-center gap-1.5 leading-tight">+ <span className="text-sm font-medium truncate">+ {task.agent?.name ?? "Unknown"}+ </span>+ <span className="text-xs text-muted-foreground shrink-0">+ #{task.channel}+ </span>+ </div>+ <p className="text-xs text-muted-foreground truncate leading-tight">+ {task.prompt}+ </p>+ </div>+ <span className="text-xs text-muted-foreground whitespace-nowrap shrink-0">+ {relativeTime(task.created_at)}+ </span>+ </Link>+ );+}++export function ActiveTasksFloat() {+ const { activeTaskDetails } = useAgentContext();+ const { slug } = useWorkspace();+ const isMobile = useIsMobile();+ const [minimized, setMinimized] = useState(false);+ const [dismissed, setDismissed] = useState(false);+ const prevTaskIdsRef = useRef<Set<string>>(new Set());++ const tasks = activeTaskDetails;+ const taskCount = tasks.length;++ useEffect(() => {+ if (taskCount === 0) {+ prevTaskIdsRef.current = new Set();+ return;+ }+ const currentIds = new Set(tasks.map((t) => t.id));+ const hasNewTask = tasks.some((t) => !prevTaskIdsRef.current.has(t.id));+ if (hasNewTask && dismissed) {+ setDismissed(false);+ }+ prevTaskIdsRef.current = currentIds;+ }, [tasks, taskCount, dismissed]);++ if (isMobile || taskCount === 0) return null;++ if (dismissed) {+ return (+ <button+ type="button"+ onClick={() => setDismissed(false)}+ className="absolute bottom-4 right-4 z-10 flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-background/90 backdrop-blur-sm ring-1 ring-foreground/8 shadow-sm text-xs font-medium text-muted-foreground hover:text-foreground transition-colors animate-[fade-up_300ms_ease-out_both]"+ >+ <span className="size-1.5 rounded-full bg-primary animate-pulse" />+ {taskCount} active+ </button>+ );+ }++ return (+ <div+ role="region"+ aria-label="Active tasks"+ className="absolute bottom-4 right-4 z-10 w-[320px] rounded-lg ring-1 ring-foreground/8 shadow-sm bg-background/90 backdrop-blur-sm animate-[fade-up_300ms_ease-out_both]"+ >+ <div className="flex items-center justify-between px-3 py-2 border-b border-border/50">+ <div className="flex items-center gap-2 text-sm font-medium" aria-live="polite">+ <span className="size-1.5 rounded-full bg-primary animate-pulse" />+ <span>+ {taskCount} task{taskCount !== 1 ? "s" : ""} active+ </span>+ </div>+ <div className="flex items-center gap-0.5">+ <button+ type="button"+ aria-label={minimized ? "Expand tasks" : "Minimize tasks"}+ className="size-6 rounded-md flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-accent transition-colors"+ onClick={() => setMinimized((v) => !v)}+ >+ <Minus className="size-3.5" />+ </button>+ <button+ type="button"+ aria-label="Close tasks panel"+ className="size-6 rounded-md flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-accent transition-colors"+ onClick={() => setDismissed(true)}+ >+ <X className="size-3.5" />+ </button>+ </div>+ </div>++ {!minimized && (+ <div className="max-h-[300px] overflow-y-auto thin-scrollbar py-1">+ {tasks.slice(0, 8).map((task) => (+ <TaskRow key={task.id} task={task} slug={slug} />+ ))}+ {taskCount > 8 && (+ <Link+ href={`/w/${slug}/traces?status=active`}+ className="block text-xs text-muted-foreground hover:text-foreground text-center py-1.5 transition-colors"+ >+ View all {taskCount} tasks+ </Link>+ )}+ </div>+ )}+ </div>+ );+}diff --git a/src/web/src/contexts/agent-context.tsx b/src/web/src/contexts/agent-context.tsxindex 136b6d16e..57fded78f 100644--- a/src/web/src/contexts/agent-context.tsx+++ b/src/web/src/contexts/agent-context.tsx@@ -18,12 +18,14 @@ import {createMachineToken,deleteMachine,listAgentActiveTaskCounts,+ listWorkspaceActiveTasks,listAgentPins,pinAgent as pinAgentApi,unpinAgent as unpinAgentApi,reorderAgentPins,reorderUnpinnedAgents,type AgentPin,+ type WorkspaceActiveTask,} from "@/lib/api";import type { AgentRuntime as Runtime } from "@alook/shared";import { toast } from "sonner";@@ -44,6 +46,7 @@ interface AgentContextValue {runtimes: Runtime[];loading: boolean;activeTaskCounts: Record<string, number>;+ activeTaskDetails: WorkspaceActiveTask[];pins: Map<string, { created_at: string; position: number }>;reload: () => Promise<void>;subscribeWs: (fn: WsSubscriber) => () => void;@@ -79,6 +82,8 @@ export function AgentProvider({const [runtimes, setRuntimes] = useState<Runtime[]>([]);const [loading, setLoading] = useState(true);const [activeTaskCounts, setActiveTaskCounts] = useState<Record<string, number>>({});+ const [activeTaskDetails, setActiveTaskDetails] = useState<WorkspaceActiveTask[]>([]);+ const hasActiveTasksRef = useRef(false);const [pins, setPins] = useState<Map<string, { created_at: string; position: number }>>(new Map());const [unpinnedOrder, setUnpinnedOrder] = useState<Map<string, number>>(new Map());const loadedRef = useRef(false);@@ -90,12 +95,39 @@ export function AgentProvider({return () => { subscribersRef.current.delete(fn); };}, []);+ const isFetchingRef = useRef(false);+const fetchTaskCounts = useCallback(async () => {+ if (isFetchingRef.current) return;+ isFetchingRef.current = true;try {- const res = await listAgentActiveTaskCounts(workspaceId);- if (taskCountsMountedRef.current) setActiveTaskCounts(res.counts);+ if (hasActiveTasksRef.current) {+ const res = await listWorkspaceActiveTasks(workspaceId);+ if (!taskCountsMountedRef.current) return;+ setActiveTaskDetails(res.tasks);+ const counts: Record<string, number> = {};+ for (const t of res.tasks) {+ counts[t.agent_id] = (counts[t.agent_id] ?? 0) + 1;+ }+ setActiveTaskCounts(counts);+ hasActiveTasksRef.current = res.tasks.length > 0;+ } else {+ const res = await listAgentActiveTaskCounts(workspaceId);+ if (!taskCountsMountedRef.current) return;+ setActiveTaskCounts(res.counts);+ const hasAny = Object.values(res.counts).some((n) => n > 0);+ if (hasAny) {+ hasActiveTasksRef.current = true;+ const detailed = await listWorkspaceActiveTasks(workspaceId);+ if (taskCountsMountedRef.current) setActiveTaskDetails(detailed.tasks);+ } else {+ setActiveTaskDetails([]);+ }+ }} catch {// ignore+ } finally {+ isFetchingRef.current = false;}}, [workspaceId]);@@ -325,6 +357,7 @@ export function AgentProvider({runtimes,loading,activeTaskCounts,+ activeTaskDetails,pins,reload,subscribeWs,diff --git a/src/web/src/lib/api.ts b/src/web/src/lib/api.tsindex d21c9ae97..e8792d1e3 100644--- a/src/web/src/lib/api.ts+++ b/src/web/src/lib/api.ts@@ -429,6 +429,21 @@ export interface ActiveTask {export const listAgentActiveTasks = (agentId: string, workspaceId: string) =>apiFetch<{ tasks: ActiveTask[] }>(`/api/agents/${agentId}/active-tasks${wsQuery(workspaceId)}`);+export interface WorkspaceActiveTask {+ id: string;+ agent_id: string;+ agent: { name: string; avatarUrl: string | null } | null;+ prompt: string;+ status: string;+ type: string;+ conversation_id: string;+ channel: string;+ created_at: string;+}++export const listWorkspaceActiveTasks = (workspaceId: string) =>+ apiFetch<{ tasks: WorkspaceActiveTask[] }>(`/api/agents/active-tasks${wsQuery(workspaceId)}`);+// Activityexport interface ActivityTask {id: string;