Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(web): app pages (home, agents, chat, runtimes)

Gener3cb398702485
diff --git a/src/web/src/app/(app)/agents/[id]/page.tsx b/src/web/src/app/(app)/agents/[id]/page.tsx
new file mode 100644
index 000000000..70eefadda
--- /dev/null
+++ b/src/web/src/app/(app)/agents/[id]/page.tsx
@@ -0,0 +1,330 @@
+"use client";
+
+import { useEffect, useState, useCallback } from "react";
+import { useParams, useRouter } from "next/navigation";
+import { useAgentContext } from "@/contexts/agent-context";
+import { listAgentConversations, deleteConversation } from "@/lib/api";
+import type { Conversation } from "@alook/shared";
+import { Button } from "@/components/ui/button";
+import { ConfirmDialog } from "@/components/ui/confirm-dialog";
+import { AgentEditForm } from "@/components/agent-edit-form";
+import { cn } from "@/lib/utils";
+import { toast } from "sonner";
+import { Plus, Loader2, Trash2, Pencil, X } from "lucide-react";
+
+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 formatDate(dateStr: string): string {
+ return new Date(dateStr).toLocaleDateString(undefined, {
+ month: "short",
+ day: "numeric",
+ hour: "numeric",
+ minute: "2-digit",
+ });
+}
+
+export default function AgentDetailPage() {
+ const params = useParams();
+ const router = useRouter();
+ const agentId = params.id as string;
+ const {
+ agents,
+ runtimes,
+ chatWithAgent,
+ handleDeleteAgent,
+ handleUpdateAgent,
+ } = useAgentContext();
+
+ const agent = agents.find((a) => a.id === agentId);
+
+ const [conversations, setConversations] = useState<Conversation[]>([]);
+ const [loading, setLoading] = useState(true);
+ const [creating, setCreating] = useState(false);
+
+ // Delete conversation state
+ const [deleteTarget, setDeleteTarget] = useState<Conversation | null>(null);
+ const [deleting, setDeleting] = useState(false);
+
+ // Delete agent state
+ const [agentConfirmOpen, setAgentConfirmOpen] = useState(false);
+ const [agentDeleting, setAgentDeleting] = useState(false);
+
+ // Inline edit state
+ const [editing, setEditing] = useState(false);
+ const [saving, setSaving] = useState(false);
+
+ const loadConversations = useCallback(async () => {
+ try {
+ const convs = await listAgentConversations(agentId);
+ setConversations(convs);
+ } catch {
+ toast.error("Failed to load sessions");
+ } finally {
+ setLoading(false);
+ }
+ }, [agentId]);
+
+ useEffect(() => {
+ loadConversations();
+ }, [loadConversations]);
+
+ const handleNewSession = async () => {
+ setCreating(true);
+ try {
+ const conversationId = await chatWithAgent(agentId);
+ if (conversationId) {
+ router.push(`/chat/${conversationId}?agent=${agentId}`);
+ }
+ } finally {
+ setCreating(false);
+ }
+ };
+
+ const handleDeleteConversation = async () => {
+ if (!deleteTarget) return;
+ setDeleting(true);
+ try {
+ await deleteConversation(deleteTarget.id);
+ setConversations((prev) =>
+ prev.filter((c) => c.id !== deleteTarget.id)
+ );
+ setDeleteTarget(null);
+ } catch {
+ toast.error("Failed to delete session");
+ } finally {
+ setDeleting(false);
+ }
+ };
+
+ const runtime = agent
+ ? runtimes.find((r) => r.id === agent.runtime_id)
+ : null;
+ const isOnline = runtime?.status === "online";
+
+ return (
+ <>
+ {/* Navbar — same pattern as chat page */}
+ <div className="flex items-center justify-between border-b border-border/50 px-5 py-2.5">
+ <div className="flex items-center gap-2 min-w-0">
+ {agent && (
+ <span
+ title={isOnline ? "Runtime online" : "Runtime offline"}
+ className={cn(
+ "size-2 rounded-full shrink-0",
+ isOnline ? "bg-status-online" : "bg-status-offline"
+ )}
+ />
+ )}
+ <h1 className="text-sm font-medium truncate">
+ {agent?.name || "Agent"}
+ </h1>
+ {editing && (
+ <span className="text-xs text-muted-foreground">/ Settings</span>
+ )}
+ </div>
+ {agent && (
+ <div className="flex items-center gap-0.5 shrink-0">
+ {editing ? (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-xs text-muted-foreground h-7 gap-1 px-2"
+ onClick={() => setEditing(false)}
+ >
+ <X className="size-3" />
+ Cancel
+ </Button>
+ ) : (
+ <>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-xs text-muted-foreground h-7 gap-1 px-2"
+ onClick={() => setEditing(true)}
+ >
+ <Pencil className="size-3" />
+ Edit
+ </Button>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-xs text-muted-foreground h-7 px-2 hover:text-destructive"
+ onClick={() => setAgentConfirmOpen(true)}
+ >
+ <Trash2 className="size-3" />
+ Remove
+ </Button>
+ </>
+ )}
+ </div>
+ )}
+ </div>
+
+ {editing && agent ? (
+ <AgentEditForm
+ agent={agent}
+ runtimes={runtimes}
+ saving={saving}
+ onCancel={() => setEditing(false)}
+ onSave={async (data) => {
+ setSaving(true);
+ try {
+ const ok = await handleUpdateAgent(agent.id, data);
+ if (ok) setEditing(false);
+ return ok;
+ } finally {
+ setSaving(false);
+ }
+ }}
+ />
+ ) : (
+ /* Session list */
+ <div className="flex-1 overflow-y-auto px-5">
+ <div className="mx-auto max-w-2xl py-6">
+ {/* Agent description */}
+ {agent?.description && (
+ <p className="text-base text-muted-foreground mb-6">
+ {agent.description}
+ </p>
+ )}
+
+ {/* Sessions header */}
+ <div className="flex items-center justify-between mb-4">
+ <h2 className="text-xs font-medium text-muted-foreground uppercase tracking-wider">
+ Sessions
+ </h2>
+ <Button
+ size="sm"
+ className="h-7 text-xs gap-1"
+ onClick={handleNewSession}
+ disabled={creating}
+ >
+ {creating ? (
+ <Loader2 className="size-3 animate-spin" />
+ ) : (
+ <Plus className="size-3" />
+ )}
+ New Session
+ </Button>
+ </div>
+
+ {loading ? (
+ <div className="flex items-center justify-center py-20">
+ <Loader2 className="size-5 animate-spin text-muted-foreground" />
+ </div>
+ ) : conversations.length === 0 ? (
+ /* Empty state */
+ <div className="text-center py-20 animate-[fade-up_400ms_ease-out_both]">
+ <p className="text-sm text-muted-foreground">
+ No sessions yet.
+ </p>
+ <p className="text-xs text-muted-foreground/60 mt-1">
+ Start a new session to begin chatting with this agent.
+ </p>
+ </div>
+ ) : (
+ /* Session rows */
+ <div className="space-y-2">
+ {conversations.map((conv) => (
+ <div
+ key={conv.id}
+ role="button"
+ tabIndex={0}
+ onClick={() =>
+ router.push(`/chat/${conv.id}?agent=${agentId}`)
+ }
+ onKeyDown={(e) => {
+ if (e.key === "Enter" || e.key === " ") {
+ e.preventDefault();
+ router.push(`/chat/${conv.id}?agent=${agentId}`);
+ }
+ }}
+ className="group w-full text-left rounded-lg border border-border/50 bg-background/50 px-4 py-3 transition-colors duration-200 hover:bg-accent/50 cursor-pointer"
+ >
+ <div className="flex items-start justify-between gap-3">
+ <div className="min-w-0 flex-1">
+ <p className="text-sm font-medium truncate">
+ {conv.title || (
+ <span className="text-muted-foreground">
+ Untitled &middot; {relativeTime(conv.created_at)}
+ </span>
+ )}
+ </p>
+ <p className="text-xs text-muted-foreground mt-0.5">
+ {formatDate(conv.created_at)}
+ {conv.message_count !== undefined && (
+ <>
+ {" "}&middot;{" "}
+ {conv.message_count}{" "}
+ {conv.message_count === 1 ? "message" : "messages"}
+ </>
+ )}
+ </p>
+ </div>
+ <button
+ type="button"
+ title="Delete session"
+ onClick={(e) => {
+ e.stopPropagation();
+ setDeleteTarget(conv);
+ }}
+ className="opacity-0 group-hover:opacity-100 transition-opacity duration-200 p-1 rounded hover:bg-destructive/10 hover:text-destructive text-muted-foreground"
+ >
+ <Trash2 className="size-3.5" />
+ </button>
+ </div>
+ </div>
+ ))}
+ </div>
+ )}
+ </div>
+ </div>
+ )}
+
+ {/* Delete session confirmation */}
+ <ConfirmDialog
+ open={!!deleteTarget}
+ onOpenChange={(open) => {
+ if (!open) setDeleteTarget(null);
+ }}
+ title="Delete session"
+ description={`This will permanently delete "${deleteTarget?.title || "Untitled"}" and all its messages.`}
+ loading={deleting}
+ onConfirm={handleDeleteConversation}
+ />
+
+ {/* Delete agent confirmation */}
+ {agent && (
+ <ConfirmDialog
+ open={agentConfirmOpen}
+ onOpenChange={setAgentConfirmOpen}
+ title="Remove agent"
+ description={`This will permanently delete "${agent.name}" and all its conversations.`}
+ loading={agentDeleting}
+ onConfirm={async () => {
+ setAgentDeleting(true);
+ try {
+ const ok = await handleDeleteAgent(agent.id);
+ if (ok) router.push("/home");
+ } finally {
+ setAgentDeleting(false);
+ setAgentConfirmOpen(false);
+ }
+ }}
+ />
+ )}
+ </>
+ );
+}
diff --git a/src/web/src/app/(app)/agents/new/page.tsx b/src/web/src/app/(app)/agents/new/page.tsx
new file mode 100644
index 000000000..ad338d73f
--- /dev/null
+++ b/src/web/src/app/(app)/agents/new/page.tsx
@@ -0,0 +1,57 @@
+"use client";
+
+import { useState } from "react";
+import { useRouter } from "next/navigation";
+import { useAgentContext } from "@/contexts/agent-context";
+import { AgentEditForm } from "@/components/agent-edit-form";
+
+export default function CreateAgentPage() {
+ const router = useRouter();
+ const {
+ runtimes,
+ handleCreateAgent,
+ chatWithAgent,
+ getFirstOnlineRuntimeId,
+ } = useAgentContext();
+
+ const [saving, setSaving] = useState(false);
+
+ return (
+ <>
+ <div className="flex items-center border-b border-border/50 px-5 py-2.5">
+ <h1 className="text-sm font-medium">Create Agent</h1>
+ </div>
+
+ <AgentEditForm
+ runtimes={runtimes}
+ defaultRuntimeId={getFirstOnlineRuntimeId()}
+ saving={saving}
+ submitLabel="Create"
+ savingLabel="Creating..."
+ onCancel={() => router.back()}
+ onSave={async (data) => {
+ setSaving(true);
+ try {
+ const agent = await handleCreateAgent({
+ name: data.name,
+ description: data.description || undefined,
+ instructions: data.instructions || undefined,
+ runtime_id: data.runtime_id,
+ });
+ if (agent) {
+ const conversationId = await chatWithAgent(agent.id);
+ if (conversationId) {
+ router.push(`/chat/${conversationId}?agent=${agent.id}`);
+ } else {
+ router.push("/home");
+ }
+ }
+ return !!agent;
+ } finally {
+ setSaving(false);
+ }
+ }}
+ />
+ </>
+ );
+}
diff --git a/src/web/src/app/(app)/agents/page.tsx b/src/web/src/app/(app)/agents/page.tsx
new file mode 100644
index 000000000..f7c38b949
--- /dev/null
+++ b/src/web/src/app/(app)/agents/page.tsx
@@ -0,0 +1,14 @@
+"use client";
+
+import { useEffect } from "react";
+import { useRouter } from "next/navigation";
+
+export default function AgentsRedirect() {
+ const router = useRouter();
+
+ useEffect(() => {
+ router.replace("/home");
+ }, [router]);
+
+ return null;
+}
diff --git a/src/web/src/app/(app)/chat/[id]/page.tsx b/src/web/src/app/(app)/chat/[id]/page.tsx
new file mode 100644
index 000000000..b5a12c472
--- /dev/null
+++ b/src/web/src/app/(app)/chat/[id]/page.tsx
@@ -0,0 +1,439 @@
+"use client";
+
+import { useEffect, useState, useRef, useCallback } from "react";
+import { useParams, useRouter, useSearchParams } from "next/navigation";
+import { useAgentContext } from "@/contexts/agent-context";
+import { Button } from "@/components/ui/button";
+import { Badge } from "@/components/ui/badge";
+import { ConfirmDialog } from "@/components/ui/confirm-dialog";
+import { AgentEditForm } from "@/components/agent-edit-form";
+import {
+ getConversation,
+ listMessages,
+ sendMessage,
+ getTask,
+ getTaskMessages,
+} from "@/lib/api";
+import type { Conversation, Message, TaskMessage } from "@alook/shared";
+import type { Task } from "@/lib/api";
+import { toast } from "sonner";
+import { cn } from "@/lib/utils";
+import { ArrowUp, Loader2, Pencil, Trash2, X } from "lucide-react";
+import { Streamdown } from "streamdown";
+
+export default function ChatPage() {
+ const params = useParams();
+ const router = useRouter();
+ const searchParams = useSearchParams();
+ const conversationId = params.id as string;
+ const { agents, runtimes, handleDeleteAgent, handleUpdateAgent } =
+ useAgentContext();
+
+ const agentId = searchParams.get("agent");
+ const agent = agents.find((a) => a.id === agentId);
+
+ const [conversation, setConversation] = useState<Conversation | null>(null);
+ const [confirmOpen, setConfirmOpen] = useState(false);
+ const [deleting, setDeleting] = useState(false);
+ const [messages, setMessages] = useState<Message[]>([]);
+ const [input, setInput] = useState("");
+ const [sending, setSending] = useState(false);
+ const [activeTask, setActiveTask] = useState<Task | null>(null);
+ const [taskMessages, setTaskMessages] = useState<TaskMessage[]>([]);
+ const [loading, setLoading] = useState(true);
+ const [connectionLost, setConnectionLost] = useState(false);
+
+ // Inline edit state
+ const [editing, setEditing] = useState(false);
+ const [saving, setSaving] = useState(false);
+
+ const scrollRef = useRef<HTMLDivElement>(null);
+ const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
+ const lastSeqRef = useRef(0);
+ const pollFailures = useRef(0);
+
+ const scrollToBottom = useCallback(() => {
+ setTimeout(() => {
+ scrollRef.current?.scrollTo({
+ top: scrollRef.current.scrollHeight,
+ behavior: "smooth",
+ });
+ }, 50);
+ }, []);
+
+ useEffect(() => {
+ async function load() {
+ try {
+ const [conv, msgs] = await Promise.all([
+ getConversation(conversationId),
+ listMessages(conversationId),
+ ]);
+ setConversation(conv);
+ setMessages(msgs);
+ } catch {
+ toast.error("Conversation not found");
+ router.push("/home");
+ } finally {
+ setLoading(false);
+ }
+ }
+ load();
+ }, [conversationId, router]);
+
+ useEffect(() => {
+ scrollToBottom();
+ }, [messages, taskMessages, scrollToBottom]);
+
+ const startPolling = useCallback(
+ (taskId: string) => {
+ if (pollRef.current) clearInterval(pollRef.current);
+ lastSeqRef.current = 0;
+ pollFailures.current = 0;
+ setConnectionLost(false);
+
+ pollRef.current = setInterval(async () => {
+ try {
+ const [task, tmsgs] = await Promise.all([
+ getTask(taskId),
+ getTaskMessages(taskId, lastSeqRef.current || undefined),
+ ]);
+
+ pollFailures.current = 0;
+ setConnectionLost(false);
+ setActiveTask(task);
+
+ if (tmsgs.length > 0) {
+ setTaskMessages((prev) => [...prev, ...tmsgs]);
+ lastSeqRef.current = Math.max(
+ ...tmsgs.map((m) => m.seq),
+ lastSeqRef.current
+ );
+ }
+
+ if (task.status === "completed" || task.status === "failed") {
+ if (pollRef.current) clearInterval(pollRef.current);
+ pollRef.current = null;
+
+ try {
+ const updatedMessages = await listMessages(conversationId);
+ setMessages(updatedMessages);
+ } catch {
+ toast.error("Failed to refresh messages");
+ }
+ setActiveTask(null);
+ setTaskMessages([]);
+ }
+ } catch {
+ pollFailures.current += 1;
+ if (pollFailures.current >= 3) {
+ setConnectionLost(true);
+ }
+ if (pollFailures.current >= 10) {
+ if (pollRef.current) clearInterval(pollRef.current);
+ pollRef.current = null;
+ toast.error("Lost connection to agent");
+ }
+ }
+ }, 1000);
+ },
+ [conversationId]
+ );
+
+ useEffect(() => {
+ return () => {
+ if (pollRef.current) clearInterval(pollRef.current);
+ };
+ }, []);
+
+ const handleSend = async () => {
+ const content = input.trim();
+ if (!content || sending) return;
+
+ setInput("");
+ setSending(true);
+
+ const optimistic: Message = {
+ id: `temp-${Date.now()}`,
+ conversation_id: conversationId,
+ role: "user",
+ content,
+ created_at: new Date().toISOString(),
+ };
+ setMessages((prev) => [...prev, optimistic]);
+
+ try {
+ const { message, task } = await sendMessage(conversationId, content);
+ setMessages((prev) =>
+ prev.map((m) => (m.id === optimistic.id ? message : m))
+ );
+ setActiveTask(task);
+ setTaskMessages([]);
+ startPolling(task.id);
+ } catch (err) {
+ setMessages((prev) => prev.filter((m) => m.id !== optimistic.id));
+ setInput(content);
+ toast.error(
+ err instanceof Error ? err.message : "Failed to send message"
+ );
+ } finally {
+ setSending(false);
+ }
+ };
+
+ const handleKeyDown = (e: React.KeyboardEvent) => {
+ if (e.key === "Enter" && !e.shiftKey) {
+ e.preventDefault();
+ handleSend();
+ }
+ };
+
+ if (loading) {
+ return (
+ <div className="flex flex-1 items-center justify-center">
+ <Loader2 className="size-5 animate-spin text-muted-foreground" />
+ </div>
+ );
+ }
+
+ return (
+ <>
+ {/* Agent navbar — stable regardless of edit/chat view */}
+ <div className="flex items-center justify-between border-b border-border/50 px-5 py-2.5">
+ <div className="flex items-center gap-2 min-w-0">
+ {agent && (() => {
+ const runtime = runtimes.find((r) => r.id === agent.runtime_id);
+ const isOnline = runtime?.status === "online";
+ return (
+ <span
+ title={isOnline ? "Runtime online" : "Runtime offline"}
+ className={cn(
+ "size-2 rounded-full shrink-0",
+ isOnline ? "bg-status-online" : "bg-status-offline"
+ )}
+ />
+ );
+ })()}
+ <h1
+ className={cn(
+ "text-sm font-medium truncate",
+ agentId && "cursor-pointer hover:opacity-70 transition-opacity duration-200"
+ )}
+ onClick={() => agentId && router.push(`/agents/${agentId}`)}
+ >
+ {agent?.name || "Agent"}
+ </h1>
+ {!editing && conversation?.title && (
+ <span className="text-xs text-muted-foreground truncate">
+ / {conversation.title}
+ </span>
+ )}
+ {editing && (
+ <span className="text-xs text-muted-foreground">/ Settings</span>
+ )}
+ </div>
+ {agent && (
+ <div className="flex items-center gap-0.5 shrink-0">
+ {editing ? (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-xs text-muted-foreground h-7 gap-1 px-2"
+ onClick={() => setEditing(false)}
+ >
+ <X className="size-3" />
+ Cancel
+ </Button>
+ ) : (
+ <>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-xs text-muted-foreground h-7 gap-1 px-2"
+ onClick={() => setEditing(true)}
+ >
+ <Pencil className="size-3" />
+ Edit
+ </Button>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-xs text-muted-foreground h-7 px-2 hover:text-destructive"
+ onClick={() => setConfirmOpen(true)}
+ >
+ <Trash2 className="size-3" />
+ Remove
+ </Button>
+ </>
+ )}
+ </div>
+ )}
+ </div>
+
+ {editing && agent ? (
+ <AgentEditForm
+ agent={agent}
+ runtimes={runtimes}
+ saving={saving}
+ onCancel={() => setEditing(false)}
+ onSave={async (data) => {
+ setSaving(true);
+ try {
+ const ok = await handleUpdateAgent(agent.id, data);
+ if (ok) setEditing(false);
+ return ok;
+ } finally {
+ setSaving(false);
+ }
+ }}
+ />
+ ) : (
+ <>
+ {/* Messages */}
+ <div className="flex-1 overflow-y-auto px-5" ref={scrollRef}>
+ <div className="mx-auto max-w-2xl py-6 space-y-4">
+ {messages.length === 0 && !activeTask && (
+ <p className="text-center text-muted-foreground py-20 text-sm">
+ Send a message to start chatting with the agent.
+ </p>
+ )}
+
+ {messages.map((msg) => (
+ <div
+ key={msg.id}
+ className={`flex ${msg.role === "user" ? "justify-end" : "justify-start"}`}
+ >
+ {msg.role === "user" ? (
+ <div className="max-w-[80%] rounded-lg px-4 py-2 bg-primary text-primary-foreground whitespace-pre-wrap">
+ {msg.content}
+ </div>
+ ) : (
+ <div className="markdown max-w-full px-1 py-1 text-base text-foreground">
+ <Streamdown>{msg.content}</Streamdown>
+ </div>
+ )}
+ </div>
+ ))}
+
+ {activeTask && (
+ <div className="rounded-lg border bg-muted/50 p-4 space-y-2">
+ <div className="flex items-center gap-2">
+ <Badge variant="secondary">
+ {activeTask.status === "running"
+ ? "Agent working..."
+ : activeTask.status}
+ </Badge>
+ </div>
+ {taskMessages.length > 0 && (
+ <div className="mt-2 max-h-60 overflow-y-auto rounded-lg bg-muted/30 p-3 font-mono text-xs space-y-1">
+ {taskMessages.map((tm) => (
+ <div key={tm.id} className="text-muted-foreground">
+ {tm.type === "tool-use" && (
+ <span className="text-primary">
+ [tool] {tm.tool}
+ </span>
+ )}
+ {tm.type === "tool-result" && (
+ <span className="text-accent-foreground">
+ [result] {tm.output || tm.content}
+ </span>
+ )}
+ {tm.type === "text" && <span>{tm.content}</span>}
+ {tm.type === "thinking" && (
+ <span className="italic opacity-60">
+ {tm.content}
+ </span>
+ )}
+ {!["tool-use", "tool-result", "text", "thinking"].includes(
+ tm.type
+ ) && (
+ <span>
+ [{tm.type}] {tm.content}
+ </span>
+ )}
+ </div>
+ ))}
+ </div>
+ )}
+ {activeTask.status === "failed" && activeTask.error && (
+ <p className="text-sm text-destructive">
+ {activeTask.error}
+ </p>
+ )}
+ {connectionLost && (
+ <p className="text-xs text-muted-foreground animate-pulse">
+ Connection lost — retrying...
+ </p>
+ )}
+ </div>
+ )}
+ </div>
+ </div>
+
+ {/* Input */}
+ <div className="px-5 py-3">
+ <div className="mx-auto max-w-2xl">
+ <div
+ className={cn(
+ "relative flex flex-col rounded-xl border bg-background/60 transition-colors duration-200",
+ "focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50",
+ (sending || !!activeTask) && "opacity-50"
+ )}
+ >
+ <textarea
+ value={input}
+ onChange={(e) => setInput(e.target.value)}
+ onKeyDown={handleKeyDown}
+ placeholder="Type a message..."
+ rows={1}
+ disabled={sending || !!activeTask}
+ className={cn(
+ "field-sizing-content w-full resize-none bg-transparent px-3.5 pt-2.5 text-base outline-none",
+ "placeholder:text-muted-foreground disabled:cursor-not-allowed",
+ "min-h-[38px] max-h-[200px]"
+ )}
+ />
+ <div className="flex items-center justify-end px-2 pb-2 pt-0.5">
+ <Button
+ size="icon-sm"
+ onClick={handleSend}
+ disabled={!input.trim() || sending || !!activeTask}
+ className={cn(
+ "rounded-lg transition-opacity duration-200",
+ !input.trim() && "opacity-40"
+ )}
+ >
+ {sending ? (
+ <Loader2 className="size-3.5 animate-spin" />
+ ) : (
+ <ArrowUp className="size-3.5" />
+ )}
+ </Button>
+ </div>
+ </div>
+ </div>
+ </div>
+ </>
+ )}
+
+ {agent && (
+ <ConfirmDialog
+ open={confirmOpen}
+ onOpenChange={setConfirmOpen}
+ title="Remove agent"
+ description={`This will permanently delete "${agent.name}" and all its conversations.`}
+ loading={deleting}
+ onConfirm={async () => {
+ setDeleting(true);
+ try {
+ const ok = await handleDeleteAgent(agent.id);
+ if (ok) router.push("/home");
+ } finally {
+ setDeleting(false);
+ setConfirmOpen(false);
+ }
+ }}
+ />
+ )}
+ </>
+ );
+}
diff --git a/src/web/src/app/(app)/home/page.tsx b/src/web/src/app/(app)/home/page.tsx
new file mode 100644
index 000000000..3ef3a282c
--- /dev/null
+++ b/src/web/src/app/(app)/home/page.tsx
@@ -0,0 +1,74 @@
+"use client";
+
+import { useEffect, useRef } from "react";
+import { useRouter } from "next/navigation";
+import { useAgentContext } from "@/contexts/agent-context";
+import { Button } from "@/components/ui/button";
+import { Loader2 } from "lucide-react";
+
+export default function HomePage() {
+ const router = useRouter();
+ const { agents, runtimes, loading } = useAgentContext();
+ const redirectedRef = useRef(false);
+
+ // Auto-redirect to first agent's detail page
+ useEffect(() => {
+ if (loading || redirectedRef.current) return;
+ if (agents.length === 0) return;
+
+ redirectedRef.current = true;
+ const sorted = [...agents].sort((a, b) => a.name.localeCompare(b.name));
+ const first = sorted[0];
+ router.replace(`/agents/${first.id}`);
+ }, [agents, loading, router]);
+
+ if (loading) {
+ return (
+ <div className="flex flex-1 items-center justify-center">
+ <Loader2 className="size-5 animate-spin text-muted-foreground" />
+ </div>
+ );
+ }
+
+ // Redirecting to first agent chat
+ if (agents.length > 0) {
+ return (
+ <div className="flex flex-1 items-center justify-center">
+ <Loader2 className="size-5 animate-spin text-muted-foreground" />
+ </div>
+ );
+ }
+
+ // Empty state — no agents
+ const hasMachines = runtimes.length > 0;
+
+ return (
+ <div className="flex flex-1 items-center justify-center">
+ <div className="text-center animate-[fade-up_400ms_ease-out_both]">
+ {hasMachines ? (
+ <>
+ <p className="text-muted-foreground text-sm">No agents yet.</p>
+ <Button
+ size="sm"
+ className="mt-4"
+ onClick={() => router.push("/agents/new")}
+ >
+ Create Agent
+ </Button>
+ </>
+ ) : (
+ <>
+ <p className="text-muted-foreground text-sm">No machines yet.</p>
+ <Button
+ size="sm"
+ className="mt-4"
+ onClick={() => router.push("/runtimes")}
+ >
+ Connect Machine
+ </Button>
+ </>
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/src/web/src/app/(app)/runtimes/page.tsx b/src/web/src/app/(app)/runtimes/page.tsx
new file mode 100644
index 000000000..bcbf015a9
--- /dev/null
+++ b/src/web/src/app/(app)/runtimes/page.tsx
@@ -0,0 +1,364 @@
+"use client";
+
+import { useState, useRef, useEffect, useCallback } from "react";
+import { useAgentContext } from "@/contexts/agent-context";
+import { Button } from "@/components/ui/button";
+import { Badge } from "@/components/ui/badge";
+import {
+ Card,
+ CardHeader,
+ CardTitle,
+ CardAction,
+ CardContent,
+} from "@/components/ui/card";
+import {
+ Sheet,
+ SheetContent,
+ SheetHeader,
+ SheetTitle,
+ SheetDescription,
+ SheetBody,
+} from "@/components/ui/sheet";
+import { ConfirmDialog } from "@/components/ui/confirm-dialog";
+import { toast } from "sonner";
+import { Loader2, Monitor, Plus } from "lucide-react";
+import type { Runtime } from "@/lib/api";
+
+function ConnectMachineSteps({
+ generatedToken,
+ generatingToken,
+ onGenerateToken,
+}: {
+ generatedToken: string;
+ generatingToken: boolean;
+ onGenerateToken: () => void;
+}) {
+ const hasTriggered = useRef(false);
+ useEffect(() => {
+ if (!generatedToken && !generatingToken && !hasTriggered.current) {
+ hasTriggered.current = true;
+ onGenerateToken();
+ }
+ }, [generatedToken, generatingToken, onGenerateToken]);
+
+ const copyToClipboard = (text: string) => {
+ navigator.clipboard.writeText(text);
+ toast("Copied to clipboard");
+ };
+
+ return (
+ <div className="space-y-6">
+ {/* Step 1 */}
+ <div className="space-y-2">
+ <p className="text-xs font-medium flex items-center gap-2">
+ <span className="flex items-center justify-center size-5 rounded-full bg-foreground text-background text-[10px] font-semibold">
+ 1
+ </span>
+ Register your CLI
+ </p>
+ <p className="text-xs text-muted-foreground pl-7">
+ Run this in your terminal to link your machine.
+ </p>
+ {generatingToken ? (
+ <div className="pl-7">
+ <div className="rounded-md bg-muted p-2.5 font-mono text-xs text-muted-foreground animate-pulse">
+ Generating token...
+ </div>
+ </div>
+ ) : generatedToken ? (
+ <div className="pl-7 space-y-2">
+ <div
+ className="rounded-md bg-muted p-2.5 font-mono text-xs text-muted-foreground cursor-pointer hover:bg-muted/80 transition-colors"
+ onClick={() =>
+ copyToClipboard(
+ `npx @alook/cli register --token ${generatedToken}`
+ )
+ }
+ title="Click to copy"
+ >
+ npx @alook/cli register --token{" "}
+ <span className="text-foreground/70">
+ {generatedToken.slice(0, 12)}...
+ </span>
+ </div>
+ <Button
+ size="sm"
+ onClick={() => {
+ navigator.clipboard.writeText(
+ `npx @alook/cli register --token ${generatedToken}`
+ );
+ toast("Copied to clipboard");
+ }}
+ className="w-full"
+ >
+ Copy Command
+ </Button>
+ </div>
+ ) : null}
+ </div>
+
+ {/* Step 2 */}
+ <div
+ className={`space-y-2 ${!generatedToken ? "opacity-40 pointer-events-none" : ""}`}
+ >
+ <p className="text-xs font-medium flex items-center gap-2">
+ <span className="flex items-center justify-center size-5 rounded-full bg-foreground text-background text-[10px] font-semibold">
+ 2
+ </span>
+ Start the daemon
+ </p>
+ <p className="text-xs text-muted-foreground pl-7">
+ The daemon connects your local agents to Alook.
+ </p>
+ <div
+ className="ml-7 rounded-md bg-muted p-2.5 font-mono text-xs text-muted-foreground cursor-pointer hover:bg-muted/80 transition-colors"
+ onClick={() =>
+ copyToClipboard("npx @alook/cli daemon start --foreground")
+ }
+ title="Click to copy"
+ >
+ npx @alook/cli daemon start --foreground
+ </div>
+ </div>
+
+ </div>
+ );
+}
+
+export default function RuntimesPage() {
+ const { runtimes, loading, handleGenerateToken, handleDeleteMachine, reload } =
+ useAgentContext();
+
+ const [sheetOpen, setSheetOpen] = useState(false);
+ const [generatedToken, setGeneratedToken] = useState("");
+ const [generatingToken, setGeneratingToken] = useState(false);
+
+ const [confirmOpen, setConfirmOpen] = useState(false);
+ const [confirmTitle, setConfirmTitle] = useState("");
+ const [confirmDescription, setConfirmDescription] = useState("");
+ const [confirmLoading, setConfirmLoading] = useState(false);
+ const confirmAction = useRef<(() => Promise<void>) | null>(null);
+
+ useEffect(() => {
+ reload();
+ }, [reload]);
+
+ const openConfirm = (
+ title: string,
+ description: string,
+ action: () => Promise<void>
+ ) => {
+ setConfirmTitle(title);
+ setConfirmDescription(description);
+ confirmAction.current = action;
+ setConfirmOpen(true);
+ };
+
+ const handleConfirm = async () => {
+ if (!confirmAction.current) return;
+ setConfirmLoading(true);
+ try {
+ await confirmAction.current();
+ } finally {
+ setConfirmLoading(false);
+ setConfirmOpen(false);
+ confirmAction.current = null;
+ }
+ };
+
+ const onGenerateToken = useCallback(async () => {
+ setGeneratingToken(true);
+ try {
+ const token = await handleGenerateToken();
+ if (token) setGeneratedToken(token);
+ } finally {
+ setGeneratingToken(false);
+ }
+ }, [handleGenerateToken]);
+
+ // Group runtimes by machine
+ const machines = new Map<
+ string,
+ { deviceInfo: string; name: string; runtimes: Runtime[] }
+ >();
+ for (const rt of runtimes) {
+ const key = rt.daemon_id || rt.id;
+ if (!machines.has(key)) {
+ machines.set(key, {
+ deviceInfo: typeof rt.device_info === "string" ? rt.device_info : "",
+ name: rt.name || "",
+ runtimes: [],
+ });
+ }
+ machines.get(key)!.runtimes.push(rt);
+ }
+
+ if (loading) {
+ return (
+ <div className="flex flex-1 items-center justify-center">
+ <Loader2 className="size-5 animate-spin text-muted-foreground" />
+ </div>
+ );
+ }
+
+ return (
+ <>
+ {/* Title bar */}
+ <div className="flex items-center justify-between border-b border-border/50 px-5 py-2.5">
+ <div className="flex items-center gap-3">
+ <h1 className="text-sm font-medium">Runtimes</h1>
+ <p className="text-xs text-muted-foreground">
+ Your machines and their agent runtimes.
+ </p>
+ </div>
+ <Button
+ size="sm"
+ variant="outline"
+ onClick={() => {
+ setGeneratedToken("");
+ setSheetOpen(true);
+ }}
+ disabled={generatingToken}
+ >
+ <Plus className="size-3.5" />
+ New machine
+ </Button>
+ </div>
+
+ <div className="flex-1 overflow-y-auto px-5 py-5">
+ {runtimes.length === 0 ? (
+ <div className="flex flex-1 items-center justify-center py-12">
+ <div className="text-center animate-[fade-up_400ms_ease-out_both]">
+ <p className="text-muted-foreground text-sm">
+ No machines connected.
+ </p>
+ <p className="text-xs text-muted-foreground mt-2 max-w-xs mx-auto">
+ Connect a machine to start running agents locally.
+ </p>
+ <Button
+ size="sm"
+ className="mt-5"
+ onClick={() => {
+ setGeneratedToken("");
+ setSheetOpen(true);
+ }}
+ >
+ Connect Machine
+ </Button>
+ </div>
+ </div>
+ ) : (
+ <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
+ {Array.from(machines.entries()).map(([daemonId, machine]) => {
+ const displayName =
+ machine.deviceInfo || machine.name || daemonId;
+ return (
+ <Card key={daemonId} size="sm" className="group">
+ <CardHeader>
+ <div className="flex items-center gap-2">
+ <Monitor className="size-4 text-muted-foreground shrink-0" />
+ <CardTitle className="truncate">
+ {displayName}
+ </CardTitle>
+ </div>
+ <CardAction>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-xs text-muted-foreground h-6 px-2 hover:text-destructive opacity-0 group-hover:opacity-100 transition-opacity"
+ onClick={() => {
+ openConfirm(
+ "Remove machine",
+ `This will remove "${displayName}" and all its runtimes. Agents using these runtimes will be unlinked.`,
+ async () => {
+ await handleDeleteMachine(daemonId);
+ }
+ );
+ }}
+ >
+ Remove
+ </Button>
+ </CardAction>
+ </CardHeader>
+ <CardContent>
+ <div className="space-y-2">
+ {machine.runtimes.map((runtime) => (
+ <div
+ key={runtime.id}
+ className="flex items-center justify-between gap-2"
+ >
+ <div className="min-w-0">
+ <p className="text-xs font-medium truncate">
+ {runtime.provider}
+ {runtime.metadata?.version ? (
+ <span className="ml-1.5 font-normal text-muted-foreground">
+ {String(runtime.metadata.version)}
+ </span>
+ ) : null}
+ </p>
+ <p className="text-xs text-muted-foreground tabular-nums">
+ {new Date(
+ runtime.last_seen_at
+ ).toLocaleString()}
+ </p>
+ </div>
+ <Badge
+ variant={
+ runtime.status === "online"
+ ? "default"
+ : "outline"
+ }
+ className="shrink-0"
+ >
+ {runtime.status}
+ </Badge>
+ </div>
+ ))}
+ </div>
+ </CardContent>
+ </Card>
+ );
+ })}
+ </div>
+ )}
+ </div>
+
+ {/* Connect machine sheet */}
+ <Sheet
+ open={sheetOpen}
+ onOpenChange={(open) => {
+ setSheetOpen(open);
+ if (!open) {
+ setGeneratedToken("");
+ }
+ }}
+ >
+ <SheetContent 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">
+ <SheetHeader>
+ <SheetTitle>Connect a machine</SheetTitle>
+ <SheetDescription>
+ Your machine runs AI agents locally using Claude Code, Codex, or
+ OpenCode.
+ </SheetDescription>
+ </SheetHeader>
+ <SheetBody>
+ <ConnectMachineSteps
+ generatedToken={generatedToken}
+ generatingToken={generatingToken}
+ onGenerateToken={onGenerateToken}
+ />
+ </SheetBody>
+ </SheetContent>
+ </Sheet>
+
+ <ConfirmDialog
+ open={confirmOpen}
+ onOpenChange={setConfirmOpen}
+ title={confirmTitle}
+ description={confirmDescription}
+ loading={confirmLoading}
+ onConfirm={handleConfirm}
+ />
+ </>
+ );
+}
diff --git a/src/web/src/app/page.tsx b/src/web/src/app/page.tsx
new file mode 100644
index 000000000..1d1cf1bda
--- /dev/null
+++ b/src/web/src/app/page.tsx
@@ -0,0 +1,8 @@
+import { getSession } from "@/lib/session";
+import { redirect } from "next/navigation";
+
+export default async function Page() {
+ const session = await getSession();
+ if (session) redirect("/home");
+ redirect("/sign-in");
+}