Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

refactor(frontend): remove copilot loading mini-game (#13374)

Ubbe32507a23e303
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/AgentSavedCard/AgentSavedCard.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/AgentSavedCard/AgentSavedCard.tsx
index 63ba76db99..da8d85844f 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/AgentSavedCard/AgentSavedCard.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/AgentSavedCard/AgentSavedCard.tsx
@@ -4,7 +4,7 @@ import { Button } from "@/components/atoms/Button/Button";
import { Text } from "@/components/atoms/Text/Text";
import { BookOpenIcon, PencilSimpleIcon } from "@phosphor-icons/react";
import Image from "next/image";
-import sparklesImg from "../MiniGame/assets/sparkles.png";
+import sparklesImg from "./assets/sparkles.png";
import { useCopilotChatActions } from "../CopilotChatActionsProvider/useCopilotChatActions";
interface Props {
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/MiniGame/assets/sparkles.png b/autogpt_platform/frontend/src/app/(platform)/copilot/components/AgentSavedCard/assets/sparkles.png
similarity index 100%
rename from autogpt_platform/frontend/src/app/(platform)/copilot/components/MiniGame/assets/sparkles.png
rename to autogpt_platform/frontend/src/app/(platform)/copilot/components/AgentSavedCard/assets/sparkles.png
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/MiniGame/MiniGame.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/MiniGame/MiniGame.tsx
deleted file mode 100644
index 9a1ae86c48..0000000000
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/MiniGame/MiniGame.tsx
+++ /dev/null
@@ -1,50 +0,0 @@
-"use client";
-
-import { useMiniGame } from "./useMiniGame";
-
-function Key({ children }: { children: React.ReactNode }) {
- return <strong>[{children}]</strong>;
-}
-
-export function MiniGame() {
- const { canvasRef, activeMode, showOverlay, score, highScore, onContinue } =
- useMiniGame();
-
- let overlayText: string | undefined;
- let buttonLabel = "Continue";
- if (activeMode === "idle") {
- buttonLabel = "Start";
- } else if (activeMode === "over") {
- overlayText = `Score: ${score} / Record: ${highScore}`;
- buttonLabel = "Retry";
- }
-
- return (
- <div className="flex flex-col gap-2">
- <p className="text-sm font-medium text-purple-500">
- <Key>WASD</Key> to move
- </p>
- <div className="relative w-full overflow-hidden rounded-md border border-accent bg-background text-foreground">
- <canvas
- ref={canvasRef}
- tabIndex={0}
- className="block w-full outline-none"
- />
- {showOverlay && (
- <div className="absolute inset-0 flex flex-col items-center justify-center gap-3 bg-black/40">
- {overlayText && (
- <p className="text-lg font-bold text-white">{overlayText}</p>
- )}
- <button
- type="button"
- onClick={onContinue}
- className="rounded-md bg-white px-4 py-2 text-sm font-semibold text-zinc-800 shadow-md transition-colors hover:bg-zinc-100"
- >
- {buttonLabel}
- </button>
- </div>
- )}
- </div>
- </div>
- );
-}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/MiniGame/useMiniGame.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/MiniGame/useMiniGame.ts
deleted file mode 100644
index a12055d445..0000000000
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/MiniGame/useMiniGame.ts
+++ /dev/null
@@ -1,443 +0,0 @@
-import { useEffect, useRef, useState } from "react";
-
-/* ------------------------------------------------------------------ */
-/* Constants */
-/* ------------------------------------------------------------------ */
-
-const CANVAS_HEIGHT = 150;
-const CELL_SIZE = 10;
-const TICK_MS = 120;
-const STORAGE_KEY = "copilot-minigame-highscore";
-
-const COLOR_BG = "#E8EAF6";
-const COLOR_SNAKE = "#263238";
-const COLOR_SNAKE_HEAD = "#1a1a2e";
-const COLOR_FOOD = "#a855f7";
-const COLOR_GRID = "rgba(0,0,0,0.04)";
-
-/* ------------------------------------------------------------------ */
-/* Types */
-/* ------------------------------------------------------------------ */
-
-interface Point {
- x: number;
- y: number;
-}
-
-type Direction = "up" | "down" | "left" | "right";
-
-interface GameState {
- snake: Point[];
- food: Point;
- dir: Direction;
- nextDir: Direction;
- score: number;
- highScore: number;
- running: boolean;
- over: boolean;
- cols: number;
- rows: number;
-}
-
-/* ------------------------------------------------------------------ */
-/* Helpers */
-/* ------------------------------------------------------------------ */
-
-function readHighScore(): number {
- try {
- return parseInt(localStorage.getItem(STORAGE_KEY) || "0", 10) || 0;
- } catch {
- return 0;
- }
-}
-
-function writeHighScore(score: number) {
- try {
- localStorage.setItem(STORAGE_KEY, String(score));
- } catch {
- /* noop */
- }
-}
-
-function spawnFood(cols: number, rows: number, snake: Point[]): Point | null {
- const occupied = new Set(snake.map((p) => `${p.x},${p.y}`));
- const free: Point[] = [];
- for (let x = 0; x < cols; x++) {
- for (let y = 0; y < rows; y++) {
- if (!occupied.has(`${x},${y}`)) free.push({ x, y });
- }
- }
- if (free.length === 0) return null;
- return free[Math.floor(Math.random() * free.length)];
-}
-
-function makeState(cols: number, rows: number): GameState {
- const cx = Math.floor(cols / 2);
- const cy = Math.floor(rows / 2);
- const snake: Point[] = [];
- for (let i = 0; i < 40; i++) {
- snake.push({ x: cx - i, y: cy });
- }
- return {
- snake,
- food: spawnFood(cols, rows, snake)!,
- dir: "right",
- nextDir: "right",
- score: 0,
- highScore: readHighScore(),
- running: false,
- over: false,
- cols,
- rows,
- };
-}
-
-const OPPOSITE: Record<Direction, Direction> = {
- up: "down",
- down: "up",
- left: "right",
- right: "left",
-};
-
-function tick(s: GameState) {
- if (!s.running || s.over) return;
-
- // Apply queued direction (prevent 180-degree turns)
- if (s.nextDir !== OPPOSITE[s.dir]) {
- s.dir = s.nextDir;
- }
-
- const head = s.snake[0];
- let nx = head.x;
- let ny = head.y;
-
- switch (s.dir) {
- case "up":
- ny--;
- break;
- case "down":
- ny++;
- break;
- case "left":
- nx--;
- break;
- case "right":
- nx++;
- break;
- }
-
- // Wrap around walls (Nokia style)
- if (nx < 0) nx = s.cols - 1;
- if (nx >= s.cols) nx = 0;
- if (ny < 0) ny = s.rows - 1;
- if (ny >= s.rows) ny = 0;
-
- // Self-collision
- for (const seg of s.snake) {
- if (seg.x === nx && seg.y === ny) {
- s.over = true;
- s.running = false;
- if (s.score > s.highScore) {
- s.highScore = s.score;
- writeHighScore(s.score);
- }
- return;
- }
- }
-
- s.snake.unshift({ x: nx, y: ny });
-
- // Eat food
- if (nx === s.food.x && ny === s.food.y) {
- s.score++;
- const newFood = spawnFood(s.cols, s.rows, s.snake);
- if (newFood) {
- s.food = newFood;
- } else {
- // Grid full — player wins
- s.over = true;
- s.running = false;
- if (s.score > s.highScore) {
- s.highScore = s.score;
- writeHighScore(s.score);
- }
- }
- } else {
- s.snake.pop();
- }
-}
-
-/* ------------------------------------------------------------------ */
-/* Drawing */
-/* ------------------------------------------------------------------ */
-
-function draw(
- ctx: CanvasRenderingContext2D,
- s: GameState,
- w: number,
- h: number,
-) {
- ctx.fillStyle = COLOR_BG;
- ctx.fillRect(0, 0, w, h);
-
- const offsetX = Math.floor((w - s.cols * CELL_SIZE) / 2);
- const offsetY = Math.floor((h - s.rows * CELL_SIZE) / 2);
-
- // Grid
- ctx.strokeStyle = COLOR_GRID;
- ctx.lineWidth = 0.5;
- for (let x = 0; x <= s.cols; x++) {
- ctx.beginPath();
- ctx.moveTo(offsetX + x * CELL_SIZE, offsetY);
- ctx.lineTo(offsetX + x * CELL_SIZE, offsetY + s.rows * CELL_SIZE);
- ctx.stroke();
- }
- for (let y = 0; y <= s.rows; y++) {
- ctx.beginPath();
- ctx.moveTo(offsetX, offsetY + y * CELL_SIZE);
- ctx.lineTo(offsetX + s.cols * CELL_SIZE, offsetY + y * CELL_SIZE);
- ctx.stroke();
- }
-
- // Border
- ctx.strokeStyle = "rgba(0,0,0,0.15)";
- ctx.lineWidth = 1;
- ctx.strokeRect(offsetX, offsetY, s.cols * CELL_SIZE, s.rows * CELL_SIZE);
-
- // Snake body
- for (let i = 1; i < s.snake.length; i++) {
- const seg = s.snake[i];
- const alpha = 0.9 - (i / s.snake.length) * 0.4;
- ctx.fillStyle = COLOR_SNAKE;
- ctx.globalAlpha = alpha;
- ctx.beginPath();
- ctx.roundRect(
- offsetX + seg.x * CELL_SIZE + 1,
- offsetY + seg.y * CELL_SIZE + 1,
- CELL_SIZE - 2,
- CELL_SIZE - 2,
- 2,
- );
- ctx.fill();
- }
- ctx.globalAlpha = 1;
-
- // Snake head
- const head = s.snake[0];
- ctx.fillStyle = COLOR_SNAKE_HEAD;
- ctx.beginPath();
- ctx.roundRect(
- offsetX + head.x * CELL_SIZE + 0.5,
- offsetY + head.y * CELL_SIZE + 0.5,
- CELL_SIZE - 1,
- CELL_SIZE - 1,
- 2,
- );
- ctx.fill();
-
- // Food
- ctx.fillStyle = COLOR_FOOD;
- ctx.beginPath();
- ctx.arc(
- offsetX + s.food.x * CELL_SIZE + CELL_SIZE / 2,
- offsetY + s.food.y * CELL_SIZE + CELL_SIZE / 2,
- CELL_SIZE / 2 - 1,
- 0,
- Math.PI * 2,
- );
- ctx.fill();
-
- // Score HUD
- ctx.save();
- ctx.fillStyle = COLOR_SNAKE;
- ctx.globalAlpha = 0.5;
- ctx.font = "bold 11px monospace";
- ctx.textAlign = "right";
- ctx.fillText(`Score: ${s.score}`, w - 12, 20);
- ctx.fillText(`Best: ${s.highScore}`, w - 12, 34);
- ctx.restore();
-}
-
-/* ------------------------------------------------------------------ */
-/* Hook */
-/* ------------------------------------------------------------------ */
-
-export function useMiniGame() {
- const canvasRef = useRef<HTMLCanvasElement>(null);
- const stateRef = useRef<GameState | null>(null);
- const rafRef = useRef(0);
- const tickTimerRef = useRef(0);
- const startedRef = useRef(false);
- const [activeMode, setActiveMode] = useState<"idle" | "run" | "over">("idle");
- const [showOverlay, setShowOverlay] = useState(true);
- const [score, setScore] = useState(0);
- const [highScore, setHighScore] = useState(0);
-
- useEffect(() => {
- const canvas = canvasRef.current;
- if (!canvas) return;
-
- const container = canvas.parentElement;
- if (container) {
- canvas.width = container.clientWidth;
- canvas.height = CANVAS_HEIGHT;
- }
-
- const cols = Math.floor(canvas.width / CELL_SIZE);
- const rows = Math.floor(CANVAS_HEIGHT / CELL_SIZE);
- stateRef.current = makeState(cols, rows);
-
- let prevPhase = "";
-
- function onKeyDown(e: KeyboardEvent) {
- const s = stateRef.current;
- if (!s || s.over) return;
-
- let handled = true;
- switch (e.code) {
- case "KeyW":
- case "ArrowUp":
- s.nextDir = "up";
- break;
- case "KeyS":
- case "ArrowDown":
- s.nextDir = "down";
- break;
- case "KeyA":
- case "ArrowLeft":
- s.nextDir = "left";
- break;
- case "KeyD":
- case "ArrowRight":
- s.nextDir = "right";
- break;
- default:
- handled = false;
- }
- if (handled) e.preventDefault();
- }
-
- function onClick() {
- canvas?.focus();
- }
-
- // Game tick (fixed interval)
- tickTimerRef.current = window.setInterval(() => {
- const s = stateRef.current;
- if (!s) return;
- tick(s);
- }, TICK_MS);
-
- // Render loop
- function loop() {
- const s = stateRef.current;
- if (!canvas || !s) return;
- const ctx = canvas.getContext("2d");
- if (!ctx) return;
-
- draw(ctx, s, canvas.width, canvas.height);
-
- let phase: string;
- if (s.over) phase = "over";
- else if (!startedRef.current) phase = "idle";
- else phase = "running";
-
- if (phase !== prevPhase) {
- prevPhase = phase;
- switch (phase) {
- case "idle":
- setActiveMode("idle");
- setShowOverlay(true);
- break;
- case "running":
- setActiveMode("run");
- setShowOverlay(false);
- break;
- case "over":
- setActiveMode("over");
- setScore(s.score);
- setHighScore(s.highScore);
- setShowOverlay(true);
- break;
- }
- }
-
- rafRef.current = requestAnimationFrame(loop);
- }
-
- rafRef.current = requestAnimationFrame(loop);
-
- canvas.addEventListener("click", onClick);
- canvas.addEventListener("keydown", onKeyDown);
-
- const observer = new ResizeObserver((entries) => {
- for (const entry of entries) {
- canvas.width = entry.contentRect.width;
- canvas.height = CANVAS_HEIGHT;
- if (stateRef.current) {
- const s = stateRef.current;
- const newCols = Math.floor(canvas.width / CELL_SIZE);
- const newRows = Math.floor(CANVAS_HEIGHT / CELL_SIZE);
- s.cols = newCols;
- s.rows = newRows;
-
- // Wrap snake segments that are now outside the smaller grid
- // and deduplicate so overlapping segments don't corrupt state
- const seen = new Set<string>();
- const deduped: Point[] = [];
- for (const seg of s.snake) {
- seg.x = ((seg.x % newCols) + newCols) % newCols;
- seg.y = ((seg.y % newRows) + newRows) % newRows;
- const key = `${seg.x},${seg.y}`;
- if (!seen.has(key)) {
- seen.add(key);
- deduped.push(seg);
- }
- }
- s.snake = deduped;
-
- // Respawn food if it landed outside the new bounds
- if (s.food.x >= newCols || s.food.y >= newRows) {
- s.food = spawnFood(newCols, newRows, s.snake) ?? {
- x: s.food.x % newCols,
- y: s.food.y % newRows,
- };
- }
- }
- }
- });
- if (container) observer.observe(container);
-
- return () => {
- cancelAnimationFrame(rafRef.current);
- clearInterval(tickTimerRef.current);
- canvas.removeEventListener("click", onClick);
- canvas.removeEventListener("keydown", onKeyDown);
- observer.disconnect();
- };
- }, []);
-
- function onContinue() {
- const s = stateRef.current;
- const canvas = canvasRef.current;
- if (!s || !canvas) return;
-
- if (s.over) {
- const hs = s.highScore;
- const cols = Math.floor(canvas.width / CELL_SIZE);
- const rows = Math.floor(CANVAS_HEIGHT / CELL_SIZE);
- stateRef.current = makeState(cols, rows);
- stateRef.current.highScore = hs;
- stateRef.current.running = true;
- startedRef.current = true;
- } else if (!s.running) {
- s.running = true;
- startedRef.current = true;
- }
-
- setShowOverlay(false);
- canvas.focus();
- }
-
- return { canvasRef, activeMode, showOverlay, score, highScore, onContinue };
-}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/CreateAgent/CreateAgent.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/CreateAgent/CreateAgent.tsx
index b2f639f0fd..44ff70fda8 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/CreateAgent/CreateAgent.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/CreateAgent/CreateAgent.tsx
@@ -9,11 +9,9 @@ import {
ContentCardDescription,
ContentCodeBlock,
ContentGrid,
- ContentHint,
ContentMessage,
} from "../../components/ToolAccordion/AccordionContent";
import { ToolAccordion } from "../../components/ToolAccordion/ToolAccordion";
-import { MiniGame } from "../../components/MiniGame/MiniGame";
import { SuggestedGoalCard } from "./components/SuggestedGoalCard";
import {
AccordionIcon,
@@ -44,23 +42,14 @@ interface Props {
function getAccordionMeta(output: CreateAgentToolOutput | null) {
const icon = <AccordionIcon />;
- if (!output) {
- return {
- icon,
- title:
- "Creating agent, this may take a few minutes. Play while you wait.",
- expanded: true,
- };
- }
-
- if (isAgentPreviewOutput(output)) {
+ if (output && isAgentPreviewOutput(output)) {
return {
icon,
title: output.agent_name,
description: `${output.node_count} block${output.node_count === 1 ? "" : "s"}`,
};
}
- if (isSuggestedGoalOutput(output)) {
+ if (output && isSuggestedGoalOutput(output)) {
return {
icon,
title: "Goal needs refinement",
@@ -84,10 +73,6 @@ export function CreateAgentTool({ part }: Props) {
const isOperating = !output;
- // Show accordion for operating state and successful outputs, but not for errors
- // (errors are shown inline so they get replaced when retrying)
- const hasExpandableContent = !isError;
-
function handleUseSuggestedGoal(goal: string) {
onSend(`Please create an agent with this goal: ${goal}`);
}
@@ -124,42 +109,35 @@ export function CreateAgentTool({ part }: Props) {
/>
)}
- {hasExpandableContent && !(output && isAgentSavedOutput(output)) && (
- <ToolAccordion {...getAccordionMeta(output)}>
- {isOperating && (
- <ContentGrid>
- <MiniGame />
- <ContentHint>
- This could take a few minutes — play while you wait!
- </ContentHint>
- </ContentGrid>
- )}
-
- {output && isAgentPreviewOutput(output) && (
- <ContentGrid>
- <ContentMessage>{output.message}</ContentMessage>
- {output.description?.trim() && (
- <ContentCardDescription>
- {output.description}
- </ContentCardDescription>
- )}
- <ContentCodeBlock>
- {truncateText(formatMaybeJson(output.agent_json), 1600)}
- </ContentCodeBlock>
- </ContentGrid>
- )}
-
- {output && isSuggestedGoalOutput(output) && (
- <SuggestedGoalCard
- message={output.message}
- suggestedGoal={output.suggested_goal}
- reason={output.reason}
- goalType={output.goal_type ?? "vague"}
- onUseSuggestedGoal={handleUseSuggestedGoal}
- />
- )}
- </ToolAccordion>
- )}
+ {output &&
+ !isError &&
+ (isAgentPreviewOutput(output) || isSuggestedGoalOutput(output)) && (
+ <ToolAccordion {...getAccordionMeta(output)}>
+ {isAgentPreviewOutput(output) && (
+ <ContentGrid>
+ <ContentMessage>{output.message}</ContentMessage>
+ {output.description?.trim() && (
+ <ContentCardDescription>
+ {output.description}
+ </ContentCardDescription>
+ )}
+ <ContentCodeBlock>
+ {truncateText(formatMaybeJson(output.agent_json), 1600)}
+ </ContentCodeBlock>
+ </ContentGrid>
+ )}
+
+ {isSuggestedGoalOutput(output) && (
+ <SuggestedGoalCard
+ message={output.message}
+ suggestedGoal={output.suggested_goal}
+ reason={output.reason}
+ goalType={output.goal_type ?? "vague"}
+ onUseSuggestedGoal={handleUseSuggestedGoal}
+ />
+ )}
+ </ToolAccordion>
+ )}
{output && isAgentSavedOutput(output) && (
<AgentSavedCard
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/CreateAgent/__tests__/CreateAgent.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/CreateAgent/__tests__/CreateAgent.test.tsx
new file mode 100644
index 0000000000..3528d63c4d
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/CreateAgent/__tests__/CreateAgent.test.tsx
@@ -0,0 +1,74 @@
+import { render, normalizeWhitespace } from "@/tests/integrations/test-utils";
+import { describe, expect, it, vi } from "vitest";
+import { CreateAgentTool, type CreateAgentToolPart } from "../CreateAgent";
+
+vi.mock(
+ "../../../components/CopilotChatActionsProvider/useCopilotChatActions",
+ () => ({
+ useCopilotChatActions: () => ({ onSend: vi.fn(), chatSurface: "copilot" }),
+ }),
+);
+
+function makePart(
+ overrides: Partial<CreateAgentToolPart> = {},
+): CreateAgentToolPart {
+ return {
+ type: "tool-create_agent",
+ toolCallId: "call-create-1",
+ state: "input-streaming",
+ input: {},
+ ...overrides,
+ };
+}
+
+describe("CreateAgentTool", () => {
+ it("shows the plain loading line (no mini-game) while operating", () => {
+ const { container } = render(<CreateAgentTool part={makePart()} />);
+
+ expect(normalizeWhitespace(container)).toContain(
+ "Creating agent, this might take a minute",
+ );
+ expect(normalizeWhitespace(container)).not.toContain("Play while you wait");
+ expect(normalizeWhitespace(container)).not.toContain("WASD");
+ });
+
+ it("renders the agent preview accordion once a preview output arrives", () => {
+ const { container } = render(
+ <CreateAgentTool
+ part={makePart({
+ state: "output-available",
+ output: {
+ type: "agent_builder_preview",
+ agent_name: "News Summarizer",
+ node_count: 3,
+ message: "Here is your agent",
+ agent_json: "{}",
+ description: "Summarizes the news",
+ },
+ })}
+ />,
+ );
+
+ expect(normalizeWhitespace(container)).toContain("News Summarizer");
+ expect(normalizeWhitespace(container)).toContain("3 blocks");
+ });
+
+ it("renders the suggested-goal card when the goal needs refinement", () => {
+ const { container } = render(
+ <CreateAgentTool
+ part={makePart({
+ state: "output-available",
+ output: {
+ type: "suggested_goal",
+ message: "Your goal is a bit vague",
+ suggested_goal: "Summarize tech news every morning",
+ reason: "More specific",
+ goal_type: "vague",
+ },
+ })}
+ />,
+ );
+
+ expect(normalizeWhitespace(container)).toContain("Goal needs refinement");
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/CreateAgent/__tests__/helpers.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/CreateAgent/__tests__/helpers.test.ts
new file mode 100644
index 0000000000..f8b6f4818e
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/CreateAgent/__tests__/helpers.test.ts
@@ -0,0 +1,57 @@
+import { describe, expect, it } from "vitest";
+import type { ToolUIPart } from "ai";
+import { getAnimationText } from "../helpers";
+
+type Part = {
+ state: ToolUIPart["state"];
+ input?: unknown;
+ output?: unknown;
+};
+
+const LOADING = "Creating agent, this might take a minute";
+
+describe("CreateAgent getAnimationText", () => {
+ it("returns the loading copy while streaming input", () => {
+ expect(getAnimationText({ state: "input-streaming" })).toBe(LOADING);
+ expect(getAnimationText({ state: "input-available" })).toBe(LOADING);
+ });
+
+ it("returns the loading copy when output is unparseable", () => {
+ expect(
+ getAnimationText({ state: "output-available", output: "not json" }),
+ ).toBe(LOADING);
+ });
+
+ it("falls back to the loading copy for unknown states", () => {
+ expect(
+ getAnimationText({ state: "partial-output" } as unknown as Part),
+ ).toBe(LOADING);
+ });
+
+ it("describes recognized outputs", () => {
+ expect(
+ getAnimationText({
+ state: "output-available",
+ output: { type: "agent_builder_saved", agent_name: "Bot" },
+ }),
+ ).toBe("Saved Bot");
+ expect(
+ getAnimationText({
+ state: "output-available",
+ output: { type: "agent_builder_preview", agent_name: "Bot" },
+ }),
+ ).toBe('Preview "Bot"');
+ expect(
+ getAnimationText({
+ state: "output-available",
+ output: { type: "suggested_goal", suggested_goal: "x" },
+ }),
+ ).toBe("Goal needs refinement");
+ });
+
+ it("returns the error copy on error states", () => {
+ expect(getAnimationText({ state: "output-error" })).toBe(
+ "Error creating agent",
+ );
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/CreateAgent/helpers.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/CreateAgent/helpers.tsx
index bd4c258cd1..553bfcbc6c 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/CreateAgent/helpers.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/CreateAgent/helpers.tsx
@@ -95,10 +95,10 @@ export function getAnimationText(part: {
switch (part.state) {
case "input-streaming":
case "input-available":
- return "Creating a new agent";
+ return "Creating agent, this might take a minute";
case "output-available": {
const output = parseOutput(part.output);
- if (!output) return "Creating a new agent";
+ if (!output) return "Creating agent, this might take a minute";
if (isAgentSavedOutput(output)) return `Saved ${output.agent_name}`;
if (isAgentPreviewOutput(output)) return `Preview "${output.agent_name}"`;
if (isSuggestedGoalOutput(output)) return "Goal needs refinement";
@@ -107,7 +107,7 @@ export function getAnimationText(part: {
case "output-error":
return "Error creating agent";
default:
- return "Creating a new agent";
+ return "Creating agent, this might take a minute";
}
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/EditAgent/EditAgent.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/EditAgent/EditAgent.tsx
index 357b1595b0..444f0e6647 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/EditAgent/EditAgent.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/EditAgent/EditAgent.tsx
@@ -4,13 +4,11 @@ import type { ToolUIPart } from "ai";
import { AgentSavedCard } from "../../components/AgentSavedCard/AgentSavedCard";
import { useCopilotChatActions } from "../../components/CopilotChatActionsProvider/useCopilotChatActions";
import { ToolErrorCard } from "../../components/ToolErrorCard/ToolErrorCard";
-import { MiniGame } from "../../components/MiniGame/MiniGame";
import { MorphingTextAnimation } from "../../components/MorphingTextAnimation/MorphingTextAnimation";
import {
ContentCardDescription,
ContentCodeBlock,
ContentGrid,
- ContentHint,
ContentMessage,
} from "../../components/ToolAccordion/AccordionContent";
import { ToolAccordion } from "../../components/ToolAccordion/ToolAccordion";
@@ -48,15 +46,7 @@ function getAccordionMeta(output: EditAgentToolOutput | null): {
} {
const icon = <AccordionIcon />;
- if (!output) {
- return {
- icon,
- title: "Editing agent, this may take a few minutes. Play while you wait.",
- expanded: true,
- };
- }
-
- if (isAgentPreviewOutput(output)) {
+ if (output && isAgentPreviewOutput(output)) {
return {
icon,
title: output.agent_name,
@@ -78,10 +68,6 @@ export function EditAgentTool({ part }: Props) {
const isOperating = !output;
- // Show accordion for operating state and successful outputs, but not for errors
- // (errors are shown inline so they get replaced when retrying)
- const hasExpandableContent = !isError;
-
return (
<div className="py-2">
{isOperating && (
@@ -109,30 +95,19 @@ export function EditAgentTool({ part }: Props) {
/>
)}
- {hasExpandableContent && !(output && isAgentSavedOutput(output)) && (
+ {output && !isError && isAgentPreviewOutput(output) && (
<ToolAccordion {...getAccordionMeta(output)}>
- {isOperating && (
- <ContentGrid>
- <MiniGame />
- <ContentHint>
- This could take a few minutes — play while you wait!
- </ContentHint>
- </ContentGrid>
- )}
-
- {output && isAgentPreviewOutput(output) && (
- <ContentGrid>
- <ContentMessage>{output.message}</ContentMessage>
- {output.description?.trim() && (
- <ContentCardDescription>
- {output.description}
- </ContentCardDescription>
- )}
- <ContentCodeBlock>
- {truncateText(formatMaybeJson(output.agent_json), 1600)}
- </ContentCodeBlock>
- </ContentGrid>
- )}
+ <ContentGrid>
+ <ContentMessage>{output.message}</ContentMessage>
+ {output.description?.trim() && (
+ <ContentCardDescription>
+ {output.description}
+ </ContentCardDescription>
+ )}
+ <ContentCodeBlock>
+ {truncateText(formatMaybeJson(output.agent_json), 1600)}
+ </ContentCodeBlock>
+ </ContentGrid>
</ToolAccordion>
)}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/EditAgent/__tests__/EditAgent.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/EditAgent/__tests__/EditAgent.test.tsx
new file mode 100644
index 0000000000..6912707158
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/EditAgent/__tests__/EditAgent.test.tsx
@@ -0,0 +1,55 @@
+import { render, normalizeWhitespace } from "@/tests/integrations/test-utils";
+import { describe, expect, it, vi } from "vitest";
+import { EditAgentTool, type EditAgentToolPart } from "../EditAgent";
+
+vi.mock(
+ "../../../components/CopilotChatActionsProvider/useCopilotChatActions",
+ () => ({
+ useCopilotChatActions: () => ({ onSend: vi.fn(), chatSurface: "copilot" }),
+ }),
+);
+
+function makePart(
+ overrides: Partial<EditAgentToolPart> = {},
+): EditAgentToolPart {
+ return {
+ type: "tool-edit_agent",
+ toolCallId: "call-edit-1",
+ state: "input-streaming",
+ input: {},
+ ...overrides,
+ };
+}
+
+describe("EditAgentTool", () => {
+ it("shows the plain loading line (no mini-game) while operating", () => {
+ const { container } = render(<EditAgentTool part={makePart()} />);
+
+ expect(normalizeWhitespace(container)).toContain(
+ "Editing agent, this might take a minute",
+ );
+ expect(normalizeWhitespace(container)).not.toContain("Play while you wait");
+ expect(normalizeWhitespace(container)).not.toContain("WASD");
+ });
+
+ it("renders the agent preview accordion once a preview output arrives", () => {
+ const { container } = render(
+ <EditAgentTool
+ part={makePart({
+ state: "output-available",
+ output: {
+ type: "agent_builder_preview",
+ agent_name: "Updated Agent",
+ node_count: 1,
+ message: "Here is your updated agent",
+ agent_json: "{}",
+ description: "Now with a new step",
+ },
+ })}
+ />,
+ );
+
+ expect(normalizeWhitespace(container)).toContain("Updated Agent");
+ expect(normalizeWhitespace(container)).toContain("1 block");
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/EditAgent/__tests__/helpers.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/EditAgent/__tests__/helpers.test.ts
new file mode 100644
index 0000000000..71859acb54
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/EditAgent/__tests__/helpers.test.ts
@@ -0,0 +1,51 @@
+import { describe, expect, it } from "vitest";
+import type { ToolUIPart } from "ai";
+import { getAnimationText } from "../helpers";
+
+type Part = {
+ state: ToolUIPart["state"];
+ input?: unknown;
+ output?: unknown;
+};
+
+const LOADING = "Editing agent, this might take a minute";
+
+describe("EditAgent getAnimationText", () => {
+ it("returns the loading copy while streaming input", () => {
+ expect(getAnimationText({ state: "input-streaming" })).toBe(LOADING);
+ expect(getAnimationText({ state: "input-available" })).toBe(LOADING);
+ });
+
+ it("returns the loading copy when output is unparseable", () => {
+ expect(
+ getAnimationText({ state: "output-available", output: "not json" }),
+ ).toBe(LOADING);
+ });
+
+ it("falls back to the loading copy for unknown states", () => {
+ expect(
+ getAnimationText({ state: "partial-output" } as unknown as Part),
+ ).toBe(LOADING);
+ });
+
+ it("describes recognized outputs", () => {
+ expect(
+ getAnimationText({
+ state: "output-available",
+ output: { type: "agent_builder_saved", agent_name: "Bot" },
+ }),
+ ).toBe('Saved "Bot"');
+ expect(
+ getAnimationText({
+ state: "output-available",
+ output: { type: "agent_builder_preview", agent_name: "Bot" },
+ }),
+ ).toBe('Preview "Bot"');
+ });
+
+ it("returns the error copy on error states", () => {
+ expect(getAnimationText({ state: "output-error" })).toBe(
+ "Error editing agent",
+ );
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/EditAgent/helpers.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/EditAgent/helpers.tsx
index 8c1f037ab8..a555cd5baf 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/EditAgent/helpers.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/EditAgent/helpers.tsx
@@ -83,10 +83,10 @@ export function getAnimationText(part: {
switch (part.state) {
case "input-streaming":
case "input-available":
- return "Editing the agent";
+ return "Editing agent, this might take a minute";
case "output-available": {
const output = parseOutput(part.output);
- if (!output) return "Editing the agent";
+ if (!output) return "Editing agent, this might take a minute";
if (isAgentSavedOutput(output)) return `Saved "${output.agent_name}"`;
if (isAgentPreviewOutput(output)) return `Preview "${output.agent_name}"`;
return "Error editing agent";
@@ -94,7 +94,7 @@ export function getAnimationText(part: {
case "output-error":
return "Error editing agent";
default:
- return "Editing the agent";
+ return "Editing agent, this might take a minute";
}
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/RunAgent.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/RunAgent.tsx
index 870174fba7..fe641e5848 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/RunAgent.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/RunAgent.tsx
@@ -2,18 +2,13 @@
import type { ToolUIPart } from "ai";
import { MorphingTextAnimation } from "../../components/MorphingTextAnimation/MorphingTextAnimation";
-import { ScaleLoader } from "../../components/ScaleLoader/ScaleLoader";
import { ToolAccordion } from "../../components/ToolAccordion/ToolAccordion";
-import {
- ContentGrid,
- ContentHint,
- ContentMessage,
-} from "../../components/ToolAccordion/AccordionContent";
-import { MiniGame } from "../../components/MiniGame/MiniGame";
+import { ContentMessage } from "../../components/ToolAccordion/AccordionContent";
import {
getAccordionMeta,
getAnimationText,
getRunAgentToolOutput,
+ getStreamingLoadingText,
isRunAgentAgentDetailsOutput,
isRunAgentAgentOutputResponse,
isRunAgentErrorOutput,
@@ -108,18 +103,10 @@ export function RunAgentTool({ part }: Props) {
)}
{isStreaming && !output && (
- <ToolAccordion
- icon={<ScaleLoader size={14} />}
- title="Running agent, this may take a few minutes. Play while you wait."
- expanded={true}
- >
- <ContentGrid>
- <MiniGame />
- <ContentHint>
- This could take a few minutes — play while you wait!
- </ContentHint>
- </ContentGrid>
- </ToolAccordion>
+ <div className="flex items-center gap-2 text-sm text-muted-foreground">
+ <ToolIcon isStreaming isError={isError} />
+ <MorphingTextAnimation text={getStreamingLoadingText(part)} />
+ </div>
)}
{setupRequirementsOutput && (
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/__tests__/RunAgent.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/__tests__/RunAgent.test.tsx
index 75e790c047..2ac6a56313 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/__tests__/RunAgent.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/__tests__/RunAgent.test.tsx
@@ -6,7 +6,11 @@ vi.mock("@sentry/nextjs", async (importOriginal) => ({
}));
import * as Sentry from "@sentry/nextjs";
-import { render, screen } from "@/tests/integrations/test-utils";
+import {
+ render,
+ screen,
+ normalizeWhitespace,
+} from "@/tests/integrations/test-utils";
import { RunAgentTool, type RunAgentToolPart } from "../RunAgent";
function makePart(overrides: Partial<RunAgentToolPart> = {}): RunAgentToolPart {
@@ -19,6 +23,36 @@ function makePart(overrides: Partial<RunAgentToolPart> = {}): RunAgentToolPart {
};
}
+describe("RunAgentTool streaming state", () => {
+ it("shows the plain loading line (no mini-game) while streaming", () => {
+ const { container } = render(
+ <RunAgentTool part={makePart({ state: "input-streaming" })} />,
+ );
+
+ expect(normalizeWhitespace(container)).toContain(
+ "Running agent, this might take a minute",
+ );
+ expect(normalizeWhitespace(container)).not.toContain("Play while you wait");
+ expect(normalizeWhitespace(container)).not.toContain("WASD");
+ });
+
+ it("shows the scheduling loading line when the input is a schedule", () => {
+ const { container } = render(
+ <RunAgentTool
+ part={makePart({
+ state: "input-streaming",
+ input: { agent_id: "a1", cron: "0 0 * * *" },
+ })}
+ />,
+ );
+
+ expect(normalizeWhitespace(container)).toContain(
+ "Scheduling agent, this might take a minute",
+ );
+ expect(normalizeWhitespace(container)).not.toContain("Running agent");
+ });
+});
+
describe("RunAgentTool corrupted output", () => {
beforeEach(() => {
vi.clearAllMocks();
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/helpers.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/helpers.tsx
index 703663eac1..46dac24081 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/helpers.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunAgent/helpers.tsx
@@ -170,6 +170,16 @@ export function getAnimationText(part: {
}
}
+export function getStreamingLoadingText(part: { input?: unknown }): string {
+ const input = part.input as RunAgentInput | undefined;
+ const isSchedule = Boolean(
+ input?.schedule_name?.trim() || input?.cron?.trim(),
+ );
+ return isSchedule
+ ? "Scheduling agent, this might take a minute"
+ : "Running agent, this might take a minute";
+}
+
export function ToolIcon({
isStreaming,
isError,
diff --git a/autogpt_platform/frontend/src/tests/integrations/test-utils.tsx b/autogpt_platform/frontend/src/tests/integrations/test-utils.tsx
index c708f1c4e6..4438b0546f 100644
--- a/autogpt_platform/frontend/src/tests/integrations/test-utils.tsx
+++ b/autogpt_platform/frontend/src/tests/integrations/test-utils.tsx
@@ -38,5 +38,11 @@ function customRender(
return render(ui, { wrapper: TestProviders, ...options });
}
+// MorphingTextAnimation renders one span per character and uses a non-breaking
+// space for spaces, so normalize all whitespace before asserting on the text.
+function normalizeWhitespace(container: HTMLElement): string {
+ return (container.textContent ?? "").replace(/\s+/g, " ").trim();
+}
+
export * from "@testing-library/react";
-export { customRender as render };
+export { customRender as render, normalizeWhitespace };