Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

merge: resolve conflicts with main branch monorepo extraction

yushenf9a430e10033
diff --cc apps/web/app/(dashboard)/layout.tsx
index eeb4fada37,bb96558a8e..8b4a696458
--- a/apps/web/app/(dashboard)/layout.tsx
+++ b/apps/web/app/(dashboard)/layout.tsx
@@@ -3,12 -3,14 +3,15 @@@
import { useEffect } from "react";
import { useRouter, usePathname } from "next/navigation";
import { MulticaIcon } from "@/components/multica-icon";
- import { useNavigationStore } from "@/features/navigation";
- import { SidebarProvider, SidebarInset } from "@/components/ui/sidebar";
- import { useAuthStore } from "@/features/auth";
- import { useWorkspaceStore } from "@/features/workspace";
+ import { useNavigationStore } from "@multica/core/navigation";
+ import { SidebarProvider, SidebarInset } from "@multica/ui/components/ui/sidebar";
+ import { useAuthStore } from "@/platform/auth";
+ import { useWorkspaceStore } from "@/platform/workspace";
+ import { WorkspaceIdProvider } from "@multica/core/hooks";
+ import { ModalRegistry } from "@multica/views/modals/registry";
+ import { SearchCommand } from "@/features/search";
import { AppSidebar } from "./_components/app-sidebar";
+import { ChatFab, ChatWindow } from "@/features/chat";
export default function DashboardLayout({
children,
@@@ -53,12 -58,7 +59,13 @@@
</div>
)}
</SidebarInset>
+ {workspace && (
+ <>
+ <ChatWindow />
+ <ChatFab />
+ </>
+ )}
+ <SearchCommand />
</SidebarProvider>
);
}
diff --cc apps/web/core/chat/mutations.ts
index 567ef4e5ec,0000000000..6b5a7355c5
mode 100644,000000..100644
--- a/apps/web/core/chat/mutations.ts
+++ b/apps/web/core/chat/mutations.ts
@@@ -1,64 -1,0 +1,64 @@@
+import { useMutation, useQueryClient } from "@tanstack/react-query";
- import { api } from "@/shared/api";
- import { useWorkspaceId } from "@core/hooks";
++import { api } from "@/platform/api";
++import { useWorkspaceId } from "@multica/core/hooks";
+import { chatKeys } from "./queries";
- import type { ChatMessage } from "@/shared/types";
++import type { ChatMessage } from "@multica/core/types";
+
+export function useCreateChatSession() {
+ const qc = useQueryClient();
+ const wsId = useWorkspaceId();
+
+ return useMutation({
+ mutationFn: (data: { agent_id: string; title?: string }) =>
+ api.createChatSession(data),
+ onSettled: () => {
+ qc.invalidateQueries({ queryKey: chatKeys.sessions(wsId) });
+ },
+ });
+}
+
+export function useArchiveChatSession() {
+ const qc = useQueryClient();
+ const wsId = useWorkspaceId();
+
+ return useMutation({
+ mutationFn: (sessionId: string) => api.archiveChatSession(sessionId),
+ onSettled: () => {
+ qc.invalidateQueries({ queryKey: chatKeys.sessions(wsId) });
+ },
+ });
+}
+
+export function useSendChatMessage(sessionId: string) {
+ const qc = useQueryClient();
+
+ return useMutation({
+ mutationFn: (content: string) => api.sendChatMessage(sessionId, content),
+ onMutate: async (content) => {
+ await qc.cancelQueries({ queryKey: chatKeys.messages(sessionId) });
+ const prev = qc.getQueryData<ChatMessage[]>(chatKeys.messages(sessionId));
+
+ // Optimistic: add user message immediately.
+ const optimistic: ChatMessage = {
+ id: `optimistic-${Date.now()}`,
+ chat_session_id: sessionId,
+ role: "user",
+ content,
+ task_id: null,
+ created_at: new Date().toISOString(),
+ };
+ qc.setQueryData<ChatMessage[]>(chatKeys.messages(sessionId), (old) =>
+ old ? [...old, optimistic] : [optimistic],
+ );
+ return { prev };
+ },
+ onError: (_err, _vars, ctx) => {
+ if (ctx?.prev) {
+ qc.setQueryData(chatKeys.messages(sessionId), ctx.prev);
+ }
+ },
+ onSettled: () => {
+ qc.invalidateQueries({ queryKey: chatKeys.messages(sessionId) });
+ },
+ });
+}
diff --cc apps/web/core/chat/queries.ts
index f957f8817b,0000000000..73b003c2ee
mode 100644,000000..100644
--- a/apps/web/core/chat/queries.ts
+++ b/apps/web/core/chat/queries.ts
@@@ -1,32 -1,0 +1,32 @@@
+import { queryOptions } from "@tanstack/react-query";
- import { api } from "@/shared/api";
++import { api } from "@/platform/api";
+
+export const chatKeys = {
+ all: (wsId: string) => ["chat", wsId] as const,
+ sessions: (wsId: string) => [...chatKeys.all(wsId), "sessions"] as const,
+ session: (wsId: string, id: string) => [...chatKeys.all(wsId), "session", id] as const,
+ messages: (sessionId: string) => ["chat", "messages", sessionId] as const,
+};
+
+export function chatSessionsOptions(wsId: string) {
+ return queryOptions({
+ queryKey: chatKeys.sessions(wsId),
+ queryFn: () => api.listChatSessions(),
+ });
+}
+
+export function chatSessionOptions(wsId: string, id: string) {
+ return queryOptions({
+ queryKey: chatKeys.session(wsId, id),
+ queryFn: () => api.getChatSession(id),
+ enabled: !!id,
+ });
+}
+
+export function chatMessagesOptions(sessionId: string) {
+ return queryOptions({
+ queryKey: chatKeys.messages(sessionId),
+ queryFn: () => api.listChatMessages(sessionId),
+ enabled: !!sessionId,
+ });
+}
diff --cc apps/web/core/chat/ws-updaters.ts
index 381be83986,0000000000..e72d0525bd
mode 100644,000000..100644
--- a/apps/web/core/chat/ws-updaters.ts
+++ b/apps/web/core/chat/ws-updaters.ts
@@@ -1,19 -1,0 +1,19 @@@
+import type { QueryClient } from "@tanstack/react-query";
- import type { ChatMessage } from "@/shared/types";
++import type { ChatMessage } from "@multica/core/types";
+import { chatKeys } from "./queries";
+
+export function onChatMessageCreated(
+ qc: QueryClient,
+ sessionId: string,
+ message: ChatMessage,
+) {
+ qc.setQueryData<ChatMessage[]>(chatKeys.messages(sessionId), (old) => {
+ if (!old) return old;
+ if (old.some((m) => m.id === message.id)) return old;
+ return [...old, message];
+ });
+}
+
+export function onChatDone(qc: QueryClient, sessionId: string) {
+ qc.invalidateQueries({ queryKey: chatKeys.messages(sessionId) });
+}
diff --cc apps/web/features/chat/components/chat-fab.tsx
index 96ad6e3b9f,0000000000..4b90c85103
mode 100644,000000..100644
--- a/apps/web/features/chat/components/chat-fab.tsx
+++ b/apps/web/features/chat/components/chat-fab.tsx
@@@ -1,19 -1,0 +1,21 @@@
+"use client";
+
- import { Button } from "@/components/ui/button";
- import { MessageCircle } from "lucide-react";
++import { Send } from "lucide-react";
+import { useChatStore } from "../store";
+
+export function ChatFab() {
++ const isOpen = useChatStore((s) => s.isOpen);
+ const toggle = useChatStore((s) => s.toggle);
+
++ if (isOpen) return null;
++
+ return (
- <Button
++ <button
+ onClick={toggle}
- size="icon"
- className="fixed bottom-6 right-6 z-50 size-12 rounded-full shadow-lg bg-purple-600 hover:bg-purple-700 text-white"
++ className="fixed bottom-4 right-4 z-50 flex items-center gap-2 rounded-full border bg-background px-4 py-2 text-sm font-medium text-muted-foreground shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground"
+ >
- <MessageCircle className="size-5" />
- </Button>
++ <Send className="size-3.5" />
++ Ask Multica
++ </button>
+ );
+}
diff --cc apps/web/features/chat/components/chat-input.tsx
index a2f0881b69,0000000000..d964a508fe
mode 100644,000000..100644
--- a/apps/web/features/chat/components/chat-input.tsx
+++ b/apps/web/features/chat/components/chat-input.tsx
@@@ -1,57 -1,0 +1,71 @@@
+"use client";
+
+import { useState, useRef, useCallback } from "react";
- import { Button } from "@/components/ui/button";
- import { Textarea } from "@/components/ui/textarea";
- import { SendHorizontal } from "lucide-react";
++import { ArrowUp } from "lucide-react";
+
+interface ChatInputProps {
+ onSend: (content: string) => void;
+ disabled?: boolean;
+}
+
+export function ChatInput({ onSend, disabled }: ChatInputProps) {
+ const [value, setValue] = useState("");
+ const textareaRef = useRef<HTMLTextAreaElement>(null);
+
+ const handleSend = useCallback(() => {
+ const trimmed = value.trim();
+ if (!trimmed || disabled) return;
+ onSend(trimmed);
+ setValue("");
++ if (textareaRef.current) {
++ textareaRef.current.style.height = "auto";
++ }
+ textareaRef.current?.focus();
+ }, [value, disabled, onSend]);
+
+ const handleKeyDown = useCallback(
- (e: React.KeyboardEvent) => {
++ (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
+ if (e.key === "Enter" && !e.shiftKey) {
+ e.preventDefault();
+ handleSend();
+ }
+ },
+ [handleSend],
+ );
+
++ const handleInput = useCallback(() => {
++ const el = textareaRef.current;
++ if (!el) return;
++ el.style.height = "auto";
++ el.style.height = Math.min(el.scrollHeight, 120) + "px";
++ }, []);
++
+ return (
- <div className="flex items-end gap-2 border-t p-3">
- <Textarea
- ref={textareaRef}
- value={value}
- onChange={(e) => setValue(e.target.value)}
- onKeyDown={handleKeyDown}
- placeholder="Send a message..."
- disabled={disabled}
- className="min-h-[40px] max-h-[120px] resize-none"
- rows={1}
- />
- <Button
- size="icon"
- onClick={handleSend}
- disabled={disabled || !value.trim()}
- className="shrink-0"
- >
- <SendHorizontal className="size-4" />
- </Button>
++ <div className="border-t bg-muted/30 p-3">
++ <div className="rounded-lg border bg-background">
++ <textarea
++ ref={textareaRef}
++ value={value}
++ onChange={(e) => {
++ setValue(e.target.value);
++ handleInput();
++ }}
++ onKeyDown={handleKeyDown}
++ placeholder="Ask Multica..."
++ disabled={disabled}
++ className="block w-full resize-none bg-transparent px-3 pt-3 pb-2 text-sm placeholder:text-muted-foreground focus:outline-none disabled:opacity-50"
++ rows={1}
++ />
++ <div className="flex items-center justify-end px-2 pb-2">
++ <button
++ onClick={handleSend}
++ disabled={disabled || !value.trim()}
++ className="flex size-7 items-center justify-center rounded-full bg-foreground text-background transition-opacity hover:opacity-80 disabled:opacity-30"
++ >
++ <ArrowUp className="size-4" />
++ </button>
++ </div>
++ </div>
+ </div>
+ );
+}
diff --cc apps/web/features/chat/components/chat-message-list.tsx
index 19c8716e26,0000000000..91a67b0b69
mode 100644,000000..100644
--- a/apps/web/features/chat/components/chat-message-list.tsx
+++ b/apps/web/features/chat/components/chat-message-list.tsx
@@@ -1,92 -1,0 +1,92 @@@
+"use client";
+
+import { useEffect, useRef } from "react";
- import { cn } from "@/lib/utils";
- import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
++import { cn } from "@multica/ui/lib/utils";
++import { Avatar, AvatarFallback, AvatarImage } from "@multica/ui/components/ui/avatar";
+import { Bot, Loader2 } from "lucide-react";
- import type { ChatMessage } from "@/shared/types";
- import type { Agent } from "@/shared/types";
++import type { ChatMessage, Agent } from "@multica/core/types";
+
+interface ChatMessageListProps {
+ messages: ChatMessage[];
+ agent: Agent | null;
+ streamingContent: string;
+ isWaiting: boolean;
+}
+
+export function ChatMessageList({
+ messages,
+ agent,
+ streamingContent,
+ isWaiting,
+}: ChatMessageListProps) {
+ const bottomRef = useRef<HTMLDivElement>(null);
+
+ useEffect(() => {
+ bottomRef.current?.scrollIntoView({ behavior: "smooth" });
+ }, [messages, streamingContent]);
+
+ return (
- <div className="flex-1 overflow-y-auto p-3 space-y-3">
++ <div className="flex-1 overflow-y-auto px-4 py-3 space-y-4">
+ {messages.map((msg) => (
+ <MessageBubble key={msg.id} message={msg} agent={agent} />
+ ))}
+ {streamingContent && (
- <div className="flex items-start gap-2">
++ <div className="flex items-start gap-3">
+ <AgentAvatar agent={agent} />
- <div className="rounded-lg bg-muted px-3 py-2 text-sm max-w-[85%] whitespace-pre-wrap">
++ <div className="min-w-0 flex-1 text-sm leading-relaxed whitespace-pre-wrap">
+ {streamingContent}
+ </div>
+ </div>
+ )}
+ {isWaiting && !streamingContent && (
- <div className="flex items-start gap-2">
++ <div className="flex items-start gap-3">
+ <AgentAvatar agent={agent} />
- <div className="rounded-lg bg-muted px-3 py-2 text-sm">
++ <div className="flex items-center pt-1">
+ <Loader2 className="size-4 animate-spin text-muted-foreground" />
+ </div>
+ </div>
+ )}
+ <div ref={bottomRef} />
+ </div>
+ );
+}
+
+function MessageBubble({
+ message,
+ agent,
+}: {
+ message: ChatMessage;
+ agent: Agent | null;
+}) {
+ const isUser = message.role === "user";
+
++ if (isUser) {
++ return (
++ <div className="flex justify-end">
++ <div className="rounded-2xl bg-primary px-3.5 py-2 text-sm text-primary-foreground max-w-[85%]">
++ {message.content}
++ </div>
++ </div>
++ );
++ }
++
+ return (
- <div
- className={cn("flex items-start gap-2", isUser && "flex-row-reverse")}
- >
- {!isUser && <AgentAvatar agent={agent} />}
- <div
- className={cn(
- "rounded-lg px-3 py-2 text-sm max-w-[85%] whitespace-pre-wrap",
- isUser
- ? "bg-primary text-primary-foreground"
- : "bg-muted",
- )}
- >
++ <div className="flex items-start gap-3">
++ <AgentAvatar agent={agent} />
++ <div className="min-w-0 flex-1 text-sm leading-relaxed whitespace-pre-wrap">
+ {message.content}
+ </div>
+ </div>
+ );
+}
+
+function AgentAvatar({ agent }: { agent: Agent | null }) {
+ return (
- <Avatar className="size-7 shrink-0">
++ <Avatar className="size-6 shrink-0 mt-0.5">
+ {agent?.avatar_url && <AvatarImage src={agent.avatar_url} />}
+ <AvatarFallback className="bg-purple-100 text-purple-700">
- <Bot className="size-3.5" />
++ <Bot className="size-3" />
+ </AvatarFallback>
+ </Avatar>
+ );
+}
diff --cc apps/web/features/chat/components/chat-window.tsx
index bd4271f53f,0000000000..a513f98ace
mode 100644,000000..100644
--- a/apps/web/features/chat/components/chat-window.tsx
+++ b/apps/web/features/chat/components/chat-window.tsx
@@@ -1,188 -1,0 +1,287 @@@
+"use client";
+
+import { useCallback, useEffect } from "react";
+import { useQuery, useQueryClient } from "@tanstack/react-query";
- import { X, Bot } from "lucide-react";
- import { Button } from "@/components/ui/button";
- import { Card } from "@/components/ui/card";
- import { useWorkspaceId } from "@core/hooks";
- import { agentListOptions } from "@core/workspace/queries";
- import { chatMessagesOptions, chatKeys } from "@core/chat/queries";
++import { X, Minus, Maximize2, Send, ChevronDown, Bot } from "lucide-react";
++import { Avatar, AvatarFallback, AvatarImage } from "@multica/ui/components/ui/avatar";
++import {
++ DropdownMenu,
++ DropdownMenuContent,
++ DropdownMenuItem,
++ DropdownMenuTrigger,
++} from "@multica/ui/components/ui/dropdown-menu";
++import { useWorkspaceId } from "@multica/core/hooks";
++import { agentListOptions } from "@multica/core/workspace/queries";
++import { chatMessagesOptions, chatKeys } from "@/core/chat/queries";
+import {
+ useCreateChatSession,
+ useSendChatMessage,
- } from "@core/chat/mutations";
++} from "@/core/chat/mutations";
+import { useChatStore } from "../store";
+import { ChatMessageList } from "./chat-message-list";
+import { ChatInput } from "./chat-input";
- import { useWS } from "@/features/realtime";
- import type { TaskMessagePayload, ChatDonePayload } from "@/shared/types";
++import { useWS } from "@multica/core/realtime";
++import type { TaskMessagePayload, ChatDonePayload, Agent } from "@multica/core/types";
+
+export function ChatWindow() {
+ const wsId = useWorkspaceId();
+ const isOpen = useChatStore((s) => s.isOpen);
+ const activeSessionId = useChatStore((s) => s.activeSessionId);
+ const pendingTaskId = useChatStore((s) => s.pendingTaskId);
+ const streamingContent = useChatStore((s) => s.streamingContent);
++ const selectedAgentId = useChatStore((s) => s.selectedAgentId);
+ const setOpen = useChatStore((s) => s.setOpen);
+ const setActiveSession = useChatStore((s) => s.setActiveSession);
+ const setPendingTask = useChatStore((s) => s.setPendingTask);
+ const appendStreaming = useChatStore((s) => s.appendStreamingContent);
+ const clearStreaming = useChatStore((s) => s.clearStreamingContent);
++ const setSelectedAgentId = useChatStore((s) => s.setSelectedAgentId);
+
+ const { data: agents = [] } = useQuery(agentListOptions(wsId));
+ const { data: messages = [] } = useQuery(
+ chatMessagesOptions(activeSessionId ?? ""),
+ );
+
+ const qc = useQueryClient();
+ const createSession = useCreateChatSession();
+ const sendMessage = useSendChatMessage(activeSessionId ?? "");
+
- // Pick the first non-archived agent as default chat target.
- const defaultAgent = agents.find((a) => !a.archived_at) ?? null;
- const activeAgent = activeSessionId
- ? agents.find((a) =>
- messages.length > 0
- ? true // we'll match by session later
- : a.id === defaultAgent?.id,
- ) ?? defaultAgent
- : defaultAgent;
++ const availableAgents = agents.filter((a) => !a.archived_at);
++
++ // Resolve selected agent: stored preference → first available
++ const activeAgent =
++ availableAgents.find((a) => a.id === selectedAgentId) ??
++ availableAgents[0] ??
++ null;
+
+ // Subscribe to task:message for streaming.
+ const { subscribe } = useWS();
+
+ useEffect(() => {
+ if (!pendingTaskId) return;
+
+ const unsubMessage = subscribe("task:message", (payload) => {
+ const p = payload as TaskMessagePayload;
+ if (p.task_id !== pendingTaskId) return;
+ if (p.type === "text" && p.content) {
+ appendStreaming(p.content);
+ }
+ });
+
+ const unsubDone = subscribe("chat:done", (payload) => {
+ const p = payload as ChatDonePayload;
+ if (p.task_id !== pendingTaskId) return;
- // Agent finished — save the streamed content as an assistant message.
+ const content = useChatStore.getState().streamingContent;
+ if (content && activeSessionId) {
+ qc.invalidateQueries({
+ queryKey: chatKeys.messages(activeSessionId),
+ });
+ }
+ clearStreaming();
+ setPendingTask(null);
+ });
+
- // Also listen for task:completed / task:failed as fallback.
+ const unsubCompleted = subscribe("task:completed", (payload) => {
+ const p = payload as { task_id: string };
+ if (p.task_id !== pendingTaskId) return;
+ if (activeSessionId) {
+ qc.invalidateQueries({
+ queryKey: chatKeys.messages(activeSessionId),
+ });
+ }
+ clearStreaming();
+ setPendingTask(null);
+ });
+
+ const unsubFailed = subscribe("task:failed", (payload) => {
+ const p = payload as { task_id: string };
+ if (p.task_id !== pendingTaskId) return;
+ clearStreaming();
+ setPendingTask(null);
+ });
+
+ return () => {
+ unsubMessage();
+ unsubDone();
+ unsubCompleted();
+ unsubFailed();
+ };
+ }, [
+ pendingTaskId,
+ activeSessionId,
+ subscribe,
+ appendStreaming,
+ clearStreaming,
+ setPendingTask,
+ qc,
+ ]);
+
+ const handleSend = useCallback(
+ async (content: string) => {
- if (!defaultAgent) return;
++ if (!activeAgent) return;
+
+ let sessionId = activeSessionId;
+
- // Create session if none exists.
+ if (!sessionId) {
+ const session = await createSession.mutateAsync({
- agent_id: defaultAgent.id,
++ agent_id: activeAgent.id,
+ title: content.slice(0, 50),
+ });
+ sessionId = session.id;
+ setActiveSession(sessionId);
+ }
+
- // Need to update the mutation's sessionId — we'll use a direct API call
- // since useSendChatMessage is bound to the initial sessionId.
- const { task_id } = await (await import("@/shared/api")).api.sendChatMessage(
++ const { task_id } = await (await import("@/platform/api")).api.sendChatMessage(
+ sessionId,
+ content,
+ );
- // Optimistic add.
+ qc.invalidateQueries({ queryKey: chatKeys.messages(sessionId) });
+ setPendingTask(task_id);
+ clearStreaming();
+ },
+ [
+ activeSessionId,
- defaultAgent,
++ activeAgent,
+ createSession,
+ setActiveSession,
+ setPendingTask,
+ clearStreaming,
+ qc,
+ ],
+ );
+
++ const handleSelectAgent = useCallback(
++ (agent: Agent) => {
++ setSelectedAgentId(agent.id);
++ // Reset session when switching agent
++ setActiveSession(null);
++ },
++ [setSelectedAgentId, setActiveSession],
++ );
++
+ if (!isOpen) return null;
+
++ const hasMessages = messages.length > 0 || !!streamingContent;
++
+ return (
- <Card className="fixed bottom-20 right-6 z-50 flex flex-col w-96 h-[500px] shadow-xl border overflow-hidden">
++ <div className="fixed bottom-4 right-4 z-50 flex flex-col w-[420px] h-[600px] rounded-xl border bg-background shadow-2xl overflow-hidden">
+ {/* Header */}
- <div className="flex items-center justify-between border-b px-4 py-3">
- <div className="flex items-center gap-2">
- <Bot className="size-4 text-purple-600" />
- <span className="text-sm font-medium">
- {activeAgent?.name ?? "Chat"}
- </span>
++ <div className="flex items-center justify-between border-b px-4 py-2.5">
++ <AgentSelector
++ agents={availableAgents}
++ activeAgent={activeAgent}
++ onSelect={handleSelectAgent}
++ />
++ <div className="flex items-center gap-0.5">
++ <button
++ onClick={() => setOpen(false)}
++ className="flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground"
++ >
++ <Minus className="size-3.5" />
++ </button>
++ <button
++ className="flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground"
++ >
++ <Maximize2 className="size-3.5" />
++ </button>
++ <button
++ onClick={() => {
++ setOpen(false);
++ setActiveSession(null);
++ }}
++ className="flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground"
++ >
++ <X className="size-3.5" />
++ </button>
+ </div>
- <Button
- variant="ghost"
- size="icon"
- className="size-7"
- onClick={() => setOpen(false)}
- >
- <X className="size-4" />
- </Button>
+ </div>
+
- {/* Messages */}
- <ChatMessageList
- messages={messages}
- agent={activeAgent}
- streamingContent={streamingContent}
- isWaiting={!!pendingTaskId}
- />
++ {/* Messages or Empty State */}
++ {hasMessages ? (
++ <ChatMessageList
++ messages={messages}
++ agent={activeAgent}
++ streamingContent={streamingContent}
++ isWaiting={!!pendingTaskId}
++ />
++ ) : (
++ <EmptyState agentName={activeAgent?.name} />
++ )}
+
+ {/* Input */}
+ <ChatInput onSend={handleSend} disabled={!!pendingTaskId} />
- </Card>
++ </div>
++ );
++}
++
++function AgentSelector({
++ agents,
++ activeAgent,
++ onSelect,
++}: {
++ agents: Agent[];
++ activeAgent: Agent | null;
++ onSelect: (agent: Agent) => void;
++}) {
++ if (!activeAgent) {
++ return <span className="text-sm text-muted-foreground">No agents</span>;
++ }
++
++ if (agents.length <= 1) {
++ return (
++ <div className="flex items-center gap-2">
++ <AgentAvatarSmall agent={activeAgent} />
++ <span className="text-sm font-medium">{activeAgent.name}</span>
++ </div>
++ );
++ }
++
++ return (
++ <DropdownMenu>
++ <DropdownMenuTrigger className="flex items-center gap-2 rounded-md px-1.5 py-1 -ml-1.5 transition-colors hover:bg-accent">
++ <AgentAvatarSmall agent={activeAgent} />
++ <span className="text-sm font-medium">{activeAgent.name}</span>
++ <ChevronDown className="size-3 text-muted-foreground" />
++ </DropdownMenuTrigger>
++ <DropdownMenuContent align="start">
++ {agents.map((agent) => (
++ <DropdownMenuItem
++ key={agent.id}
++ onClick={() => onSelect(agent)}
++ className="flex items-center gap-2"
++ >
++ <AgentAvatarSmall agent={agent} />
++ <span>{agent.name}</span>
++ </DropdownMenuItem>
++ ))}
++ </DropdownMenuContent>
++ </DropdownMenu>
++ );
++}
++
++function AgentAvatarSmall({ agent }: { agent: Agent }) {
++ return (
++ <Avatar className="size-5">
++ {agent.avatar_url && <AvatarImage src={agent.avatar_url} />}
++ <AvatarFallback className="bg-purple-100 text-purple-700 text-[10px]">
++ <Bot className="size-3" />
++ </AvatarFallback>
++ </Avatar>
++ );
++}
++
++function EmptyState({ agentName }: { agentName?: string }) {
++ return (
++ <div className="flex flex-1 flex-col items-center justify-center gap-4 px-8">
++ <Send className="size-8 text-muted-foreground/50" />
++ <div className="text-center">
++ <h3 className="text-base font-semibold">Welcome to Multica</h3>
++ <p className="mt-1 text-sm text-muted-foreground">
++ {agentName
++ ? `Chat with ${agentName} or ask anything`
++ : "Ask anything or tell Multica what you need"}
++ </p>
++ </div>
++ </div>
+ );
+}
diff --cc apps/web/features/chat/store.ts
index b2b1476a38,0000000000..3e45cb204e
mode 100644,000000..100644
--- a/apps/web/features/chat/store.ts
+++ b/apps/web/features/chat/store.ts
@@@ -1,28 -1,0 +1,42 @@@
+import { create } from "zustand";
+
++const AGENT_STORAGE_KEY = "multica:chat:selectedAgentId";
++
++function readStoredAgentId(): string | null {
++ if (typeof window === "undefined") return null;
++ return localStorage.getItem(AGENT_STORAGE_KEY);
++}
++
+interface ChatState {
+ isOpen: boolean;
+ activeSessionId: string | null;
+ pendingTaskId: string | null;
+ streamingContent: string;
++ selectedAgentId: string | null;
+ setOpen: (open: boolean) => void;
+ toggle: () => void;
+ setActiveSession: (id: string | null) => void;
+ setPendingTask: (taskId: string | null) => void;
+ appendStreamingContent: (text: string) => void;
+ clearStreamingContent: () => void;
++ setSelectedAgentId: (id: string) => void;
+}
+
+export const useChatStore = create<ChatState>((set) => ({
+ isOpen: false,
+ activeSessionId: null,
+ pendingTaskId: null,
+ streamingContent: "",
++ selectedAgentId: readStoredAgentId(),
+ setOpen: (open) => set({ isOpen: open }),
+ toggle: () => set((s) => ({ isOpen: !s.isOpen })),
+ setActiveSession: (id) => set({ activeSessionId: id }),
+ setPendingTask: (taskId) => set({ pendingTaskId: taskId }),
+ appendStreamingContent: (text) =>
+ set((s) => ({ streamingContent: s.streamingContent + text })),
+ clearStreamingContent: () => set({ streamingContent: "" }),
++ setSelectedAgentId: (id) => {
++ localStorage.setItem(AGENT_STORAGE_KEY, id);
++ set({ selectedAgentId: id });
++ },
+}));
diff --cc packages/core/api/client.ts
index 73fecb9c35,079d26843f..d04cf1d01a
--- a/packages/core/api/client.ts
+++ b/packages/core/api/client.ts
@@@ -35,11 -36,13 +36,16 @@@ import type
TimelineEntry,
TaskMessagePayload,
Attachment,
+ ChatSession,
+ ChatMessage,
+ SendChatMessageResponse,
- } from "@/shared/types";
- import { type Logger, noopLogger } from "@/shared/logger";
+ } from "../types";
+ import { type Logger, noopLogger } from "../logger";
+
+ export interface ApiClientOptions {
+ logger?: Logger;
+ onUnauthorized?: () => void;
+ }
export interface LoginResponse {
token: string;
diff --cc packages/core/provider.tsx
index 41331d2e94,41331d2e94..a75512d7f7
--- a/packages/core/provider.tsx
+++ b/packages/core/provider.tsx
@@@ -6,12 -6,12 +6,14 @@@ import { ReactQueryDevtools } from "@ta
import { createQueryClient } from "./query-client";
import type { ReactNode } from "react";
++const showDevtools = process.env.NEXT_PUBLIC_DEVTOOLS !== "false";
++
export function QueryProvider({ children }: { children: ReactNode }) {
const [queryClient] = useState(createQueryClient);
return (
<QueryClientProvider client={queryClient}>
{children}
-- <ReactQueryDevtools initialIsOpen={false} />
++ {showDevtools && <ReactQueryDevtools initialIsOpen={false} />}
</QueryClientProvider>
);
}
diff --cc packages/core/types/chat.ts
index f7f6fb9bc9,0000000000..f7f6fb9bc9
mode 100644,000000..100644
--- a/packages/core/types/chat.ts
+++ b/packages/core/types/chat.ts
diff --cc packages/core/types/index.ts
index bb2d359cb5,7838d7c782..78492339b5
--- a/packages/core/types/index.ts
+++ b/packages/core/types/index.ts
@@@ -29,4 -29,4 +29,5 @@@ export type { IssueSubscriber } from ".
export type * from "./events";
export type * from "./api";
export type { Attachment } from "./attachment";
+export type { ChatSession, ChatMessage, SendChatMessageResponse } from "./chat";
+ export type { StorageAdapter } from "./storage";
diff --cc server/cmd/server/router.go
index 1c36aebf4d,0eb897fe20..7c57e1086c
--- a/server/cmd/server/router.go
+++ b/server/cmd/server/router.go
@@@ -232,24 -233,15 +233,27 @@@ func NewRouter(pool *pgxpool.Pool, hub
// Runtimes
r.Route("/api/runtimes", func(r chi.Router) {
r.Get("/", h.ListAgentRuntimes)
- r.Get("/{runtimeId}/usage", h.GetRuntimeUsage)
- r.Get("/{runtimeId}/activity", h.GetRuntimeTaskActivity)
- r.Post("/{runtimeId}/ping", h.InitiatePing)
- r.Get("/{runtimeId}/ping/{pingId}", h.GetPing)
- r.Post("/{runtimeId}/update", h.InitiateUpdate)
- r.Get("/{runtimeId}/update/{updateId}", h.GetUpdate)
+ r.Route("/{runtimeId}", func(r chi.Router) {
+ r.Get("/usage", h.GetRuntimeUsage)
+ r.Get("/activity", h.GetRuntimeTaskActivity)
+ r.Post("/ping", h.InitiatePing)
+ r.Get("/ping/{pingId}", h.GetPing)
+ r.Post("/update", h.InitiateUpdate)
+ r.Get("/update/{updateId}", h.GetUpdate)
+ r.Delete("/", h.DeleteAgentRuntime)
+ })
+ })
+
+ // Chat
+ r.Route("/api/chat/sessions", func(r chi.Router) {
+ r.Post("/", h.CreateChatSession)
+ r.Get("/", h.ListChatSessions)
+ r.Route("/{sessionId}", func(r chi.Router) {
+ r.Get("/", h.GetChatSession)
+ r.Delete("/", h.ArchiveChatSession)
+ r.Post("/messages", h.SendChatMessage)
+ r.Get("/messages", h.ListChatMessages)
+ })
})
// Inbox