|
| 1 | +import React from "react"; |
| 2 | +import { Badge, Card, Spinner } from "@stackforge/ui"; |
| 3 | +import type { AgentState } from "../hooks/useJobStream"; |
| 4 | + |
| 5 | +const AGENT_META: Record<string, { icon: string; label: string; description: string }> = { |
| 6 | + planner: { icon: "📋", label: "Planner", description: "Defines project structure and tech stack" }, |
| 7 | + schema: { icon: "🗄️", label: "Schema", description: "Designs database entities and relationships" }, |
| 8 | + api: { icon: "⚡", label: "API", description: "Plans API routes and endpoints" }, |
| 9 | + frontend: { icon: "🎨", label: "Frontend", description: "Creates frontend pages and components" }, |
| 10 | + devops: { icon: "🚀", label: "DevOps", description: "Sets up CI/CD, Docker, and deployment" }, |
| 11 | + reviewer: { icon: "🔍", label: "Reviewer", description: "Reviews the entire blueprint for quality" }, |
| 12 | +}; |
| 13 | + |
| 14 | +export function AgentCard({ agent }: { agent: AgentState }) { |
| 15 | + const meta = AGENT_META[agent.name] ?? { icon: "🤖", label: agent.name, description: "" }; |
| 16 | + |
| 17 | + const borderColor = |
| 18 | + agent.status === "running" |
| 19 | + ? "rgba(56, 189, 248, 0.3)" |
| 20 | + : agent.status === "completed" |
| 21 | + ? "rgba(52, 211, 153, 0.2)" |
| 22 | + : agent.status === "failed" |
| 23 | + ? "rgba(244, 63, 94, 0.2)" |
| 24 | + : "#23232f"; |
| 25 | + |
| 26 | + return ( |
| 27 | + <Card |
| 28 | + hover={false} |
| 29 | + style={{ |
| 30 | + padding: "18px 20px", |
| 31 | + borderColor, |
| 32 | + borderRadius: "14px", |
| 33 | + animation: agent.status === "running" ? "pulse-glow 2s ease-in-out infinite" : undefined, |
| 34 | + transition: "all 350ms cubic-bezier(0.4, 0, 0.2, 1)", |
| 35 | + }} |
| 36 | + > |
| 37 | + <div style={{ display: "flex", alignItems: "center", gap: "14px" }}> |
| 38 | + {/* Icon */} |
| 39 | + <div |
| 40 | + style={{ |
| 41 | + width: "42px", |
| 42 | + height: "42px", |
| 43 | + borderRadius: "12px", |
| 44 | + background: |
| 45 | + agent.status === "running" |
| 46 | + ? "rgba(56, 189, 248, 0.1)" |
| 47 | + : agent.status === "completed" |
| 48 | + ? "rgba(52, 211, 153, 0.1)" |
| 49 | + : "rgba(92, 92, 111, 0.1)", |
| 50 | + display: "flex", |
| 51 | + alignItems: "center", |
| 52 | + justifyContent: "center", |
| 53 | + fontSize: "20px", |
| 54 | + flexShrink: 0, |
| 55 | + }} |
| 56 | + > |
| 57 | + {agent.status === "running" ? <Spinner size={18} color="#38bdf8" /> : meta.icon} |
| 58 | + </div> |
| 59 | + |
| 60 | + {/* Info */} |
| 61 | + <div style={{ flex: 1, minWidth: 0 }}> |
| 62 | + <div style={{ display: "flex", alignItems: "center", gap: "10px", marginBottom: "4px" }}> |
| 63 | + <span style={{ fontSize: "15px", fontWeight: 600 }}>{meta.label}</span> |
| 64 | + <Badge status={agent.status} /> |
| 65 | + </div> |
| 66 | + <p style={{ fontSize: "13px", color: "#9898a8", margin: 0 }}>{meta.description}</p> |
| 67 | + </div> |
| 68 | + |
| 69 | + {/* Duration / details */} |
| 70 | + <div style={{ textAlign: "right", flexShrink: 0 }}> |
| 71 | + {agent.durationMs != null && ( |
| 72 | + <span style={{ fontSize: "13px", color: "#9898a8", fontVariantNumeric: "tabular-nums" }}> |
| 73 | + {(agent.durationMs / 1000).toFixed(1)}s |
| 74 | + </span> |
| 75 | + )} |
| 76 | + {agent.totalTokens != null && ( |
| 77 | + <div style={{ fontSize: "11px", color: "#5c5c6f", marginTop: "2px" }}> |
| 78 | + {agent.totalTokens.toLocaleString()} tokens |
| 79 | + </div> |
| 80 | + )} |
| 81 | + {agent.error && ( |
| 82 | + <span style={{ fontSize: "12px", color: "#f43f5e" }}>{agent.error}</span> |
| 83 | + )} |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + </Card> |
| 87 | + ); |
| 88 | +} |
0 commit comments