import { useQuery } from "@tanstack/react-query"; import { api } from "../lib/api"; import { AgentIdenticon } from "./AgentIdenticon"; import { ChatPanel } from "./ChatPanel"; import { Button } from "./ui/button"; import { Sheet, SheetContent, SheetDescription, SheetTitle } from "./ui/sheet"; import { Skeleton } from "./ui/skeleton"; interface TaskChatDrawerProps { open: boolean; onOpenChange: (open: boolean) => void; taskId: string | null; task?: any; showOverlay?: boolean; className?: string; } export function TaskChatDrawer({ open, onOpenChange, taskId, task, showOverlay = true, className }: TaskChatDrawerProps) { const requiresFetch = open && !!taskId && !task; const { data: fetchedTask, error, isLoading, } = useQuery({ queryKey: ["task", taskId], queryFn: () => api.tasks.get(taskId!), enabled: requiresFetch, }); if (!taskId) return null; const currentTask = fetchedTask ?? task; const agentName = currentTask?.agent_name ?? "agent"; // An AMA-bound task (new ak runner) carries the ama.sessionId annotation and // renders through the AMA path; an un-upgraded ak's legacy daemon has no such // annotation and renders through its tunnel relay session. const annotations = currentTask?.metadata?.annotations && typeof currentTask.metadata.annotations === "object" ? currentTask.metadata.annotations : {}; const amaSessionId = typeof annotations["ama.sessionId"] === "string" ? (annotations["ama.sessionId"] as string) : null; const relaySessionId = currentTask?.active_session_id ?? null; return ( Chat with {agentName} Chat panel
{currentTask?.agent_public_key ? ( ) : ( )} {agentName}
{isLoading ? (
) : error ? (
Unable to load task chat.
) : ( )}
); }