Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(web): wire Hub sidebar, real chat messaging, and layout integration
Naiyuan Qing53199918689c
diff --git a/apps/web/app/components/chat.tsx b/apps/web/app/components/chat.tsxindex 80775fc7d2..ce455e6a40 100644--- a/apps/web/app/components/chat.tsx+++ b/apps/web/app/components/chat.tsx@@ -1,85 +1,104 @@"use client";-import { useRef, useState, useCallback } from "react";+import { useRef, useCallback } from "react";import { SidebarTrigger } from "@multica/ui/components/ui/sidebar";-import { Button } from "@multica/ui/components/ui/button";+import { Badge } from "@multica/ui/components/ui/badge";import { ChatInput } from "@multica/ui/components/chat-input";import { MemoizedMarkdown } from "@multica/ui/components/markdown";import { useMessages } from "../hooks/use-messages";-import { useDeviceId } from "../hooks/use-device-id";+import { useGateway } from "../hooks/use-gateway";+import { useHub } from "../hooks/use-hub";+import { useActiveAgent } from "../hooks/use-active-agent";import { useScrollFade } from "../hooks/use-scroll-fade";import { cn } from "@multica/ui/lib/utils";-import { HugeiconsIcon } from "@hugeicons/react";-import { Copy01Icon, CheckmarkCircle02Icon } from "@hugeicons/core-free-icons";-import { toast } from "@multica/ui/components/ui/sonner";++const STATE_VARIANT: Record<string, "default" | "secondary" | "destructive" | "outline"> = {+ registered: "default",+ connected: "secondary",+ connecting: "secondary",+ disconnected: "destructive",+}export function Chat() {- const deviceId = useDeviceId();- const messages = useMessages();- const mainRef = useRef<HTMLElement>(null);- const fadeStyle = useScrollFade(mainRef);- const [copied, setCopied] = useState(false);+ const activeAgentId = useActiveAgent((s) => s.activeAgentId)+ const { messages, addUserMessage, addAssistantMessage } = useMessages()+ const { hub } = useHub()++ const { state: gwState, send } = useGateway({+ onMessage: (msg) => {+ const payload = msg.payload as { agentId?: string; content?: string }+ if (payload?.agentId && payload?.content) {+ addAssistantMessage(payload.content, payload.agentId)+ }+ },+ })++ const handleSend = useCallback((text: string) => {+ if (!hub?.hubId || !activeAgentId) return+ addUserMessage(text, activeAgentId)+ send(hub.hubId, "message", { agentId: activeAgentId, content: text })+ }, [hub?.hubId, activeAgentId, addUserMessage, send])- const handleCopy = useCallback(async () => {- if (!deviceId) return;- await navigator.clipboard.writeText(deviceId);- setCopied(true);- toast.success("Device ID copied");- setTimeout(() => setCopied(false), 2000);- }, [deviceId]);+ const filtered = activeAgentId+ ? messages.filter(m => m.agentId === activeAgentId)+ : []++ const canSend = gwState === "registered" && !!activeAgentId++ const mainRef = useRef<HTMLElement>(null)+ const fadeStyle = useScrollFade(mainRef)return (<div className="h-dvh flex flex-col overflow-hidden w-full"><header className="flex items-center gap-2 p-2"><SidebarTrigger />- <span className="text-xs text-muted-foreground font-mono">- {deviceId || "\u00A0"}- </span>- {deviceId && (- <Button- variant="ghost"- size="icon-xs"- onClick={handleCopy}- aria-label="Copy device ID"- >- <HugeiconsIcon- icon={copied ? CheckmarkCircle02Icon : Copy01Icon}- strokeWidth={2}- className={cn("size-3", copied && "text-green-500")}- />- </Button>+ <Badge variant={STATE_VARIANT[gwState] ?? "outline"} className="text-xs">+ {gwState}+ </Badge>+ {activeAgentId && (+ <span className="text-xs text-muted-foreground font-mono">+ Agent: {activeAgentId.slice(0, 8)}...+ </span>)}</header><main ref={mainRef} className="flex-1 overflow-y-auto min-h-0" style={fadeStyle}>- <div className="px-4 py-6 space-y-6 max-w-4xl mx-auto">- {messages.map((msg) => (- <div- key={msg.id}- className={cn(- "flex",- msg.role === "user" ? "justify-end" : "justify-start"- )}- >+ {!activeAgentId ? (+ <div className="flex items-center justify-center h-full text-muted-foreground text-sm">+ Select an agent to start chatting+ </div>+ ) : filtered.length === 0 ? (+ <div className="flex items-center justify-center h-full text-muted-foreground text-sm">+ Send a message to start the conversation+ </div>+ ) : (+ <div className="px-4 py-6 space-y-6 max-w-4xl mx-auto">+ {filtered.map((msg) => (<div+ key={msg.id}className={cn(- "max-w-[85%] rounded-2xl px-4 py-3",- msg.role === "user"- ? "bg-muted"- : ""+ "flex",+ msg.role === "user" ? "justify-end" : "justify-start")}>- <MemoizedMarkdown mode="minimal" id={msg.id}>- {msg.content}- </MemoizedMarkdown>+ <div+ className={cn(+ "max-w-[85%] rounded-2xl px-4 py-3",+ msg.role === "user" ? "bg-muted" : ""+ )}+ >+ <MemoizedMarkdown mode="minimal" id={msg.id}>+ {msg.content}+ </MemoizedMarkdown>+ </div></div>- </div>- ))}- </div>+ ))}+ </div>+ )}</main><footer className="w-full p-2 pt-1 max-w-4xl mx-auto">- <ChatInput />+ <ChatInput onSubmit={handleSend} disabled={!canSend} /></footer></div>);diff --git a/apps/web/app/components/hub-sidebar.tsx b/apps/web/app/components/hub-sidebar.tsxnew file mode 100644index 0000000000..d71c897e2b--- /dev/null+++ b/apps/web/app/components/hub-sidebar.tsx@@ -0,0 +1,101 @@+"use client"++import {+ SidebarGroup,+ SidebarGroupLabel,+ SidebarGroupAction,+ SidebarGroupContent,+ SidebarMenu,+ SidebarMenuItem,+ SidebarMenuButton,+ SidebarMenuAction,+} from "@multica/ui/components/ui/sidebar"+import { Button } from "@multica/ui/components/ui/button"+import { HugeiconsIcon } from "@hugeicons/react"+import { PlusSignIcon, Delete02Icon, Loading03Icon } from "@hugeicons/core-free-icons"+import { useHub } from "../hooks/use-hub"+import { useActiveAgent } from "../hooks/use-active-agent"++const STATUS_DOT: Record<string, string> = {+ connected: "bg-green-500",+ loading: "bg-yellow-500 animate-pulse",+ error: "bg-red-500",+ idle: "bg-muted-foreground",+}++const STATUS_LABEL: Record<string, string> = {+ connected: "Connected",+ loading: "Connecting...",+ error: "Disconnected",+ idle: "Idle",+}++export function HubSidebar() {+ const { status, hub, agents, fetchHub, createAgent, deleteAgent } = useHub()+ const activeAgentId = useActiveAgent((s) => s.activeAgentId)+ const setActiveAgentId = useActiveAgent((s) => s.setActiveAgentId)++ return (+ <>+ <SidebarGroup>+ <SidebarGroupLabel>Hub</SidebarGroupLabel>+ <SidebarGroupContent>+ <div className="flex items-center gap-2 px-2 py-1 text-sm">+ <span className={`size-2 rounded-full shrink-0 ${STATUS_DOT[status]}`} />+ <span className="text-muted-foreground">{STATUS_LABEL[status]}</span>+ </div>+ {status === "connected" && hub && (+ <div className="px-2 text-xs text-muted-foreground font-mono truncate">+ {hub.hubId.slice(0, 8)}...+ </div>+ )}+ {status === "error" && (+ <div className="px-2 pt-1">+ <Button variant="outline" size="sm" onClick={fetchHub} className="w-full text-xs">+ Retry+ </Button>+ </div>+ )}+ </SidebarGroupContent>+ </SidebarGroup>++ {status === "connected" && (+ <SidebarGroup>+ <SidebarGroupLabel>Agents</SidebarGroupLabel>+ <SidebarGroupAction onClick={createAgent} title="Create agent">+ <HugeiconsIcon icon={PlusSignIcon} strokeWidth={2} className="size-4" />+ </SidebarGroupAction>+ <SidebarGroupContent>+ <SidebarMenu>+ {agents.length === 0 && (+ <div className="px-2 py-2 text-xs text-muted-foreground">+ No agents+ </div>+ )}+ {agents.map(agent => (+ <SidebarMenuItem key={agent.id}>+ <SidebarMenuButton+ isActive={agent.id === activeAgentId}+ onClick={() => setActiveAgentId(agent.id)}+ className="font-mono text-xs"+ >+ {agent.id.slice(0, 8)}...+ </SidebarMenuButton>+ <SidebarMenuAction+ onClick={() => {+ if (activeAgentId === agent.id) setActiveAgentId(null)+ deleteAgent(agent.id)+ }}+ title="Delete agent"+ >+ <HugeiconsIcon icon={Delete02Icon} strokeWidth={2} className="size-3.5" />+ </SidebarMenuAction>+ </SidebarMenuItem>+ ))}+ </SidebarMenu>+ </SidebarGroupContent>+ </SidebarGroup>+ )}+ </>+ )+}diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsxindex 5fa8112b2e..579809dadc 100644--- a/apps/web/app/layout.tsx+++ b/apps/web/app/layout.tsx@@ -4,11 +4,11 @@ import "@multica/ui/globals.css";import {SidebarProvider,SidebarInset,- SidebarTrigger,} from "@multica/ui/components/ui/sidebar";import { AppSidebar } from "@multica/ui/components/app-sidebar";import { ThemeProvider } from "@multica/ui/components/theme-provider";import { Toaster } from "@multica/ui/components/ui/sonner";+import { HubSidebar } from "./components/hub-sidebar";const inter = Inter({ subsets: ["latin"], variable: "--font-sans" });@@ -33,12 +33,6 @@ export const metadata: Metadata = {description: "Distributed AI agent framework",};-const NAV_ITEMS = [- { title: "Home", url: "#" },- { title: "Documents", url: "#" },- { title: "Settings", url: "#" },-];-export default function RootLayout({children,}: Readonly<{@@ -56,7 +50,9 @@ export default function RootLayout({disableTransitionOnChange><SidebarProvider>- <AppSidebar items={NAV_ITEMS} />+ <AppSidebar>+ <HubSidebar />+ </AppSidebar><SidebarInset><div className="flex h-dvh overflow-hidden">{children}</div></SidebarInset>