Skip to content

Open-source SEO, GEO, and marketing skills for AI agents.

refactor(notfair-cmo): remove create-agent button + modal from sidebar

Yuting Zhongc2d3685c8fdb
diff --git a/notfair-cmo/src/components/app-sidebar.tsx b/notfair-cmo/src/components/app-sidebar.tsx
index 3d56c73d..4b86891b 100644
--- a/notfair-cmo/src/components/app-sidebar.tsx
+++ b/notfair-cmo/src/components/app-sidebar.tsx
@@ -28,7 +28,6 @@ import { TEMPLATES } from "@/server/agent-templates";
import { projectHref } from "@/lib/project-href";
import { ProjectSwitcher } from "./project-switcher";
import { AgentNav } from "./agent-nav";
-import { CreateAgentButton } from "./create-agent-button";
import { ApprovalsLiveBadge } from "./live-badge";
type NavItem = {
@@ -81,10 +80,7 @@ export async function AppSidebar() {
<SidebarContent>
{active && (
<SidebarGroup>
- <SidebarGroupLabel className="flex items-center justify-between">
- <span>Agents</span>
- <CreateAgentButton projectSlug={active.slug} />
- </SidebarGroupLabel>
+ <SidebarGroupLabel>Agents</SidebarGroupLabel>
<SidebarGroupContent>
<AgentNav
projectSlug={active.slug}
diff --git a/notfair-cmo/src/components/create-agent-button.test.tsx b/notfair-cmo/src/components/create-agent-button.test.tsx
deleted file mode 100644
index 6fb067c4..00000000
--- a/notfair-cmo/src/components/create-agent-button.test.tsx
+++ /dev/null
@@ -1,77 +0,0 @@
-// @vitest-environment jsdom
-import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
-import { render, screen, fireEvent, cleanup } from "@testing-library/react";
-
-const dialogCalls: Array<{ open: boolean; projectSlug: string }> = [];
-
-vi.mock("./create-agent-dialog", () => ({
- CreateAgentDialog: ({
- open,
- onOpenChange,
- projectSlug,
- }: {
- open: boolean;
- onOpenChange: (o: boolean) => void;
- projectSlug: string;
- }) => {
- dialogCalls.push({ open, projectSlug });
- return open ? (
- <div data-testid="dialog-stub">
- dialog-open-for-{projectSlug}
- <button onClick={() => onOpenChange(false)}>close</button>
- </div>
- ) : null;
- },
-}));
-
-import { CreateAgentButton } from "./create-agent-button";
-
-beforeEach(() => {
- dialogCalls.length = 0;
-});
-
-afterEach(() => {
- cleanup();
-});
-
-describe("CreateAgentButton", () => {
- it("renders a plus button with an accessible name", () => {
- render(<CreateAgentButton projectSlug="proj" />);
- expect(
- screen.getByRole("button", { name: /create or clone agent/i }),
- ).toBeInTheDocument();
- });
-
- it("starts with the dialog closed", () => {
- render(<CreateAgentButton projectSlug="proj" />);
- expect(screen.queryByTestId("dialog-stub")).not.toBeInTheDocument();
- expect(dialogCalls.at(-1)?.open).toBe(false);
- });
-
- it("opens the dialog when the button is clicked", () => {
- render(<CreateAgentButton projectSlug="proj" />);
- fireEvent.click(
- screen.getByRole("button", { name: /create or clone agent/i }),
- );
- expect(screen.getByTestId("dialog-stub")).toBeInTheDocument();
- expect(screen.getByText("dialog-open-for-proj")).toBeInTheDocument();
- });
-
- it("forwards the projectSlug prop to the dialog", () => {
- render(<CreateAgentButton projectSlug="alpha-beta" />);
- fireEvent.click(
- screen.getByRole("button", { name: /create or clone agent/i }),
- );
- expect(dialogCalls.at(-1)?.projectSlug).toBe("alpha-beta");
- });
-
- it("closes the dialog when the child fires onOpenChange(false)", () => {
- render(<CreateAgentButton projectSlug="proj" />);
- fireEvent.click(
- screen.getByRole("button", { name: /create or clone agent/i }),
- );
- expect(screen.getByTestId("dialog-stub")).toBeInTheDocument();
- fireEvent.click(screen.getByText("close"));
- expect(screen.queryByTestId("dialog-stub")).not.toBeInTheDocument();
- });
-});
diff --git a/notfair-cmo/src/components/create-agent-button.tsx b/notfair-cmo/src/components/create-agent-button.tsx
deleted file mode 100644
index 472dc68a..00000000
--- a/notfair-cmo/src/components/create-agent-button.tsx
+++ /dev/null
@@ -1,32 +0,0 @@
-"use client";
-
-import { useState } from "react";
-import { Plus } from "lucide-react";
-import { CreateAgentDialog } from "./create-agent-dialog";
-
-type Props = {
- /** Active project slug — used as the agent_id prefix in the name input. */
- projectSlug: string;
-};
-
-export function CreateAgentButton({ projectSlug }: Props) {
- const [open, setOpen] = useState(false);
- return (
- <>
- <button
- type="button"
- onClick={() => setOpen(true)}
- className="flex size-5 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
- title="Create or clone agent"
- aria-label="Create or clone agent"
- >
- <Plus className="size-3.5" />
- </button>
- <CreateAgentDialog
- open={open}
- onOpenChange={setOpen}
- projectSlug={projectSlug}
- />
- </>
- );
-}
diff --git a/notfair-cmo/src/components/create-agent-dialog.test.tsx b/notfair-cmo/src/components/create-agent-dialog.test.tsx
deleted file mode 100644
index c94717f8..00000000
--- a/notfair-cmo/src/components/create-agent-dialog.test.tsx
+++ /dev/null
@@ -1,291 +0,0 @@
-// @vitest-environment jsdom
-import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
-import { render, screen, fireEvent, waitFor, cleanup } from "@testing-library/react";
-
-const router = {
- push: vi.fn(),
- refresh: vi.fn(),
-};
-
-const listOpenClawAgentsAction = vi.fn();
-const listProjectAgentsAction = vi.fn();
-const createAgentAction = vi.fn();
-const cloneAgentAction = vi.fn();
-
-const toast = {
- success: vi.fn(),
- error: vi.fn(),
-};
-
-vi.mock("next/navigation", () => ({
- useRouter: () => router,
-}));
-
-vi.mock("@/server/actions/agents", () => ({
- listOpenClawAgentsAction: (...args: unknown[]) =>
- listOpenClawAgentsAction(...args),
- listProjectAgentsAction: (...args: unknown[]) =>
- listProjectAgentsAction(...args),
- createAgentAction: (...args: unknown[]) => createAgentAction(...args),
- cloneAgentAction: (...args: unknown[]) => cloneAgentAction(...args),
-}));
-
-vi.mock("sonner", () => ({
- toast: {
- success: (...args: unknown[]) => toast.success(...args),
- error: (...args: unknown[]) => toast.error(...args),
- },
-}));
-
-vi.mock("./disable-source-crons-dialog", () => ({
- DisableSourceCronsDialog: ({
- sourceLabel,
- sourceCrons,
- onDone,
- }: {
- sourceLabel: string;
- sourceCrons: Array<{ id: string }>;
- onDone: () => void;
- }) => (
- <div data-testid="disable-source-crons-dialog">
- from {sourceLabel} with {sourceCrons.length} crons
- <button onClick={onDone}>finish</button>
- </div>
- ),
-}));
-
-import { CreateAgentDialog } from "./create-agent-dialog";
-
-const choices = [
- {
- agent_id: "other-cmo",
- display_name: "Other CMO",
- in_current_project: false,
- },
- {
- agent_id: "proj-existing",
- display_name: "Existing",
- in_current_project: true,
- },
-];
-
-const projectAgents = [
- { agent_id: "proj-existing", slug: "existing", display_name: "Existing" },
-];
-
-beforeEach(() => {
- router.push.mockReset();
- router.refresh.mockReset();
- listOpenClawAgentsAction.mockReset();
- listProjectAgentsAction.mockReset();
- createAgentAction.mockReset();
- cloneAgentAction.mockReset();
- toast.success.mockReset();
- toast.error.mockReset();
- listOpenClawAgentsAction.mockResolvedValue({ ok: true, data: choices });
- listProjectAgentsAction.mockResolvedValue({ ok: true, data: projectAgents });
-});
-
-afterEach(() => {
- cleanup();
-});
-
-describe("CreateAgentDialog — create mode", () => {
- it("renders nothing visible when closed", () => {
- const onOpenChange = vi.fn();
- render(
- <CreateAgentDialog open={false} onOpenChange={onOpenChange} projectSlug="proj" />,
- );
- expect(screen.queryByText("New agent")).not.toBeInTheDocument();
- });
-
- it("renders create-mode UI with the project prefix when open", () => {
- render(
- <CreateAgentDialog open onOpenChange={vi.fn()} projectSlug="proj" />,
- );
- expect(screen.getByText("New agent")).toBeInTheDocument();
- expect(screen.getByText("proj-")).toBeInTheDocument();
- expect(screen.getByLabelText(/Agent name/i)).toBeInTheDocument();
- });
-
- it("disables Create when the name is empty", () => {
- render(<CreateAgentDialog open onOpenChange={vi.fn()} projectSlug="proj" />);
- expect(
- screen.getByRole("button", { name: /create agent/i }),
- ).toBeDisabled();
- });
-
- it("flags an in-project name collision and disables Create", async () => {
- render(<CreateAgentDialog open onOpenChange={vi.fn()} projectSlug="proj" />);
- await waitFor(() => expect(listProjectAgentsAction).toHaveBeenCalled());
- const input = screen.getByLabelText(/Agent name/i);
- fireEvent.change(input, { target: { value: "existing" } });
- await waitFor(() =>
- expect(
- screen.getByText(/already exists in this project/i),
- ).toBeInTheDocument(),
- );
- expect(
- screen.getByRole("button", { name: /create agent/i }),
- ).toBeDisabled();
- });
-
- it("flags an invalid (reserved) name", async () => {
- render(<CreateAgentDialog open onOpenChange={vi.fn()} projectSlug="proj" />);
- const input = screen.getByLabelText(/Agent name/i);
- fireEvent.change(input, { target: { value: "settings" } });
- await waitFor(() =>
- expect(screen.getByText(/invalid name/i)).toBeInTheDocument(),
- );
- expect(
- screen.getByRole("button", { name: /create agent/i }),
- ).toBeDisabled();
- });
-
- it("calls createAgentAction on submit and routes to the new agent", async () => {
- createAgentAction.mockResolvedValue({
- ok: true,
- data: { slug: "new-agent" },
- });
- const onOpenChange = vi.fn();
- render(
- <CreateAgentDialog open onOpenChange={onOpenChange} projectSlug="proj" />,
- );
- await waitFor(() => expect(listProjectAgentsAction).toHaveBeenCalled());
- fireEvent.change(screen.getByLabelText(/Agent name/i), {
- target: { value: "new-agent" },
- });
- fireEvent.click(screen.getByRole("button", { name: /create agent/i }));
- await waitFor(() =>
- expect(createAgentAction).toHaveBeenCalledWith({
- display_name: "new-agent",
- }),
- );
- await waitFor(() => expect(onOpenChange).toHaveBeenCalledWith(false));
- await waitFor(() =>
- expect(router.push).toHaveBeenCalledWith("/proj/agents/new-agent/chat"),
- );
- });
-
- it("toasts the server error when create fails", async () => {
- createAgentAction.mockResolvedValue({ ok: false, error: "denied" });
- render(<CreateAgentDialog open onOpenChange={vi.fn()} projectSlug="proj" />);
- await waitFor(() => expect(listProjectAgentsAction).toHaveBeenCalled());
- fireEvent.change(screen.getByLabelText(/Agent name/i), {
- target: { value: "new-agent" },
- });
- fireEvent.click(screen.getByRole("button", { name: /create agent/i }));
- await waitFor(() => expect(toast.error).toHaveBeenCalledWith("denied"));
- });
-
- it("closes when Cancel is clicked", () => {
- const onOpenChange = vi.fn();
- render(
- <CreateAgentDialog open onOpenChange={onOpenChange} projectSlug="proj" />,
- );
- fireEvent.click(screen.getByRole("button", { name: /cancel/i }));
- expect(onOpenChange).toHaveBeenCalledWith(false);
- });
-});
-
-describe("CreateAgentDialog — clone mode", () => {
- function openInCloneMode() {
- render(<CreateAgentDialog open onOpenChange={vi.fn()} projectSlug="proj" />);
- fireEvent.click(screen.getByRole("button", { name: /clone existing/i }));
- }
-
- it("shows the source picker once choices have loaded", async () => {
- openInCloneMode();
- await waitFor(() => expect(listOpenClawAgentsAction).toHaveBeenCalled());
- expect(await screen.findByLabelText(/source agent/i)).toBeInTheDocument();
- });
-
- it("renders a loading indicator while fetching the catalog", async () => {
- listOpenClawAgentsAction.mockImplementation(() => new Promise(() => {}));
- listProjectAgentsAction.mockImplementation(() => new Promise(() => {}));
- openInCloneMode();
- expect(await screen.findByText(/loading agents/i)).toBeInTheDocument();
- });
-
- it("renders the error message when the catalog fails to load", async () => {
- listOpenClawAgentsAction.mockResolvedValue({ ok: false, error: "boom" });
- openInCloneMode();
- expect(await screen.findByText("boom")).toBeInTheDocument();
- });
-
- it("disables Clone when source not picked or name is empty", async () => {
- openInCloneMode();
- await waitFor(() => expect(listOpenClawAgentsAction).toHaveBeenCalled());
- expect(
- screen.getByRole("button", { name: /clone agent/i }),
- ).toBeDisabled();
- });
-
- it("invokes cloneAgentAction with the chosen source and name", async () => {
- cloneAgentAction.mockResolvedValue({
- ok: true,
- data: { new_slug: "clone-x", new_agent_id: "proj-clone-x", source_crons: [] },
- });
- const onOpenChange = vi.fn();
- render(<CreateAgentDialog open onOpenChange={onOpenChange} projectSlug="proj" />);
- fireEvent.click(screen.getByRole("button", { name: /clone existing/i }));
- await waitFor(() => expect(listOpenClawAgentsAction).toHaveBeenCalled());
- fireEvent.change(await screen.findByLabelText(/source agent/i), {
- target: { value: "other-cmo" },
- });
- fireEvent.change(screen.getByLabelText(/new agent name/i), {
- target: { value: "clone-x" },
- });
- fireEvent.click(screen.getByRole("button", { name: /clone agent/i }));
- await waitFor(() =>
- expect(cloneAgentAction).toHaveBeenCalledWith({
- source_agent_id: "other-cmo",
- new_display_name: "clone-x",
- }),
- );
- await waitFor(() => expect(onOpenChange).toHaveBeenCalledWith(false));
- await waitFor(() =>
- expect(router.push).toHaveBeenCalledWith("/proj/agents/clone-x/chat"),
- );
- });
-
- it("opens the disable-crons follow-up dialog when the source had crons", async () => {
- cloneAgentAction.mockResolvedValue({
- ok: true,
- data: {
- new_slug: "clone-x",
- new_agent_id: "proj-clone-x",
- source_crons: [{ id: "c1" }, { id: "c2" }],
- },
- });
- render(<CreateAgentDialog open onOpenChange={vi.fn()} projectSlug="proj" />);
- fireEvent.click(screen.getByRole("button", { name: /clone existing/i }));
- await waitFor(() => expect(listOpenClawAgentsAction).toHaveBeenCalled());
- fireEvent.change(await screen.findByLabelText(/source agent/i), {
- target: { value: "other-cmo" },
- });
- fireEvent.change(screen.getByLabelText(/new agent name/i), {
- target: { value: "clone-x" },
- });
- fireEvent.click(screen.getByRole("button", { name: /clone agent/i }));
- const followUp = await screen.findByTestId("disable-source-crons-dialog");
- expect(followUp).toBeInTheDocument();
- expect(followUp.textContent).toMatch(/Other CMO/i);
- expect(followUp.textContent).toMatch(/2 crons/i);
- });
-
- it("toasts a server error when clone fails", async () => {
- cloneAgentAction.mockResolvedValue({ ok: false, error: "no space" });
- render(<CreateAgentDialog open onOpenChange={vi.fn()} projectSlug="proj" />);
- fireEvent.click(screen.getByRole("button", { name: /clone existing/i }));
- await waitFor(() => expect(listOpenClawAgentsAction).toHaveBeenCalled());
- fireEvent.change(await screen.findByLabelText(/source agent/i), {
- target: { value: "other-cmo" },
- });
- fireEvent.change(screen.getByLabelText(/new agent name/i), {
- target: { value: "clone-x" },
- });
- fireEvent.click(screen.getByRole("button", { name: /clone agent/i }));
- await waitFor(() => expect(toast.error).toHaveBeenCalledWith("no space"));
- });
-});
diff --git a/notfair-cmo/src/components/create-agent-dialog.tsx b/notfair-cmo/src/components/create-agent-dialog.tsx
deleted file mode 100644
index 98717a9d..00000000
--- a/notfair-cmo/src/components/create-agent-dialog.tsx
+++ /dev/null
@@ -1,402 +0,0 @@
-"use client";
-
-import { useEffect, useState, useTransition } from "react";
-import { useRouter } from "next/navigation";
-import { Loader2, Sparkles, Copy } from "lucide-react";
-import { toast } from "sonner";
-import { Button } from "@/components/ui/button";
-import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
-} from "@/components/ui/dialog";
-import { Label } from "@/components/ui/label";
-import { cn } from "@/lib/utils";
-import {
- listOpenClawAgentsAction,
- listProjectAgentsAction,
- createAgentAction,
- cloneAgentAction,
- type AgentChoice,
-} from "@/server/actions/agents";
-import { slugify } from "@/lib/slug";
-import { projectHref } from "@/lib/project-href";
-import type { CloneAgentResult } from "@/server/agents/clone";
-import { DisableSourceCronsDialog } from "./disable-source-crons-dialog";
-
-type Mode = "create" | "clone";
-
-type Props = {
- open: boolean;
- onOpenChange: (open: boolean) => void;
- /** Active project slug; rendered as the prefix on the new-agent name input. */
- projectSlug: string;
-};
-
-export function CreateAgentDialog({ open, onOpenChange, projectSlug }: Props) {
- const router = useRouter();
- const [mode, setMode] = useState<Mode>("create");
- const [name, setName] = useState("");
- const [sourceId, setSourceId] = useState("");
- const [choices, setChoices] = useState<AgentChoice[]>([]);
- const [loadingChoices, setLoadingChoices] = useState(false);
- const [choicesError, setChoicesError] = useState<string | null>(null);
- const [projectSlugs, setProjectSlugs] = useState<Set<string>>(new Set());
- const [pending, startTransition] = useTransition();
-
- const [postClone, setPostClone] = useState<{
- result: CloneAgentResult;
- sourceLabel: string;
- } | null>(null);
-
- useEffect(() => {
- if (!open) {
- setMode("create");
- setName("");
- setSourceId("");
- return;
- }
- setLoadingChoices(true);
- (async () => {
- // Load both: full agent catalog (for the clone dropdown) and the
- // current project's agents (for name-uniqueness validation).
- const [allRes, projectRes] = await Promise.all([
- listOpenClawAgentsAction(),
- listProjectAgentsAction(),
- ]);
- if (allRes.ok) setChoices(allRes.data);
- else setChoicesError(allRes.error);
- if (projectRes.ok) {
- setProjectSlugs(new Set(projectRes.data.map((a) => a.slug)));
- }
- setLoadingChoices(false);
- })();
- }, [open]);
-
- const selectedSource = choices.find((c) => c.agent_id === sourceId);
-
- // Compute the slug the typed name would produce so we can validate against
- // existing project agents inline (instead of bouncing through the server).
- const trimmedName = name.trim();
- const slugAttempt = trimmedName ? slugify(trimmedName) : null;
- const derivedSlug = slugAttempt && slugAttempt.ok ? slugAttempt.slug : null;
- const slugInvalidReason =
- slugAttempt && !slugAttempt.ok ? slugAttempt.reason : null;
- const nameCollision = !!derivedSlug && projectSlugs.has(derivedSlug);
-
- function onSubmit() {
- if (mode === "create") {
- if (!name.trim()) {
- toast.error("Please enter an agent name.");
- return;
- }
- startTransition(async () => {
- const r = await createAgentAction({ display_name: name.trim() });
- if (!r.ok) {
- toast.error(r.error);
- return;
- }
- toast.success(`Created ${name.trim()}`);
- onOpenChange(false);
- router.push(projectHref(projectSlug, `/agents/${r.data.slug}/chat`));
- router.refresh();
- });
- return;
- }
- // Clone mode
- if (!sourceId) {
- toast.error("Please pick a source agent.");
- return;
- }
- const displayName = name.trim();
- if (!displayName) {
- toast.error("Please give the cloned agent a name.");
- return;
- }
- startTransition(async () => {
- const r = await cloneAgentAction({
- source_agent_id: sourceId,
- new_display_name: displayName,
- });
- if (!r.ok) {
- toast.error(r.error);
- return;
- }
- toast.success(
- `Cloned ${selectedSource?.display_name ?? sourceId} → ${displayName}`,
- );
- onOpenChange(false);
- // Surface the disable-source-crons follow-up if there were any.
- if (r.data.source_crons.length > 0) {
- setPostClone({ result: r.data, sourceLabel: selectedSource?.display_name ?? sourceId });
- } else {
- // Send the user straight into the new agent.
- router.push(projectHref(projectSlug, `/agents/${r.data.new_slug}/chat`));
- }
- router.refresh();
- });
- }
-
- return (
- <>
- <Dialog open={open} onOpenChange={onOpenChange}>
- <DialogContent className="max-w-md">
- <DialogHeader>
- <DialogTitle>New agent</DialogTitle>
- <DialogDescription>
- Add a fresh agent to this project, or clone one of the existing agents.
- </DialogDescription>
- </DialogHeader>
-
- <div
- className="inline-flex items-center gap-1 rounded-lg border bg-muted/40 p-1"
- role="tablist"
- >
- <ModeButton
- active={mode === "create"}
- onClick={() => setMode("create")}
- icon={<Sparkles className="size-3.5" />}
- label="Create new"
- />
- <ModeButton
- active={mode === "clone"}
- onClick={() => setMode("clone")}
- icon={<Copy className="size-3.5" />}
- label="Clone existing"
- />
- </div>
-
- {mode === "create" ? (
- <div className="space-y-2">
- <Label htmlFor="new-agent-name">Agent name</Label>
- <PrefixedInput
- id="new-agent-name"
- prefix={`${projectSlug}-`}
- placeholder="content-writer"
- value={name}
- onChange={setName}
- disabled={pending}
- autoFocus
- invalid={nameCollision || !!slugInvalidReason}
- />
- <NameHint
- derivedSlug={derivedSlug}
- collision={nameCollision}
- invalidReason={slugInvalidReason}
- defaultHint="Becomes the URL slug too (lowercased, hyphenated)."
- />
- </div>
- ) : (
- <div className="space-y-3">
- <div className="space-y-2">
- <Label htmlFor="clone-source">Source agent</Label>
- {loadingChoices ? (
- <div className="flex items-center gap-2 text-xs text-muted-foreground">
- <Loader2 className="size-3 animate-spin" /> Loading agents…
- </div>
- ) : choicesError ? (
- <div className="text-xs text-destructive">{choicesError}</div>
- ) : (
- <select
- id="clone-source"
- value={sourceId}
- onChange={(e) => setSourceId(e.target.value)}
- disabled={pending}
- className="h-9 w-full rounded-md border bg-background px-3 text-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
- >
- <option value="">Pick one…</option>
- {choices.map((c) => (
- <option key={c.agent_id} value={c.agent_id}>
- {c.display_name}
- {c.display_name !== c.agent_id ? ` · ${c.agent_id}` : ""}
- {c.in_current_project ? " (in this project)" : ""}
- </option>
- ))}
- </select>
- )}
- {selectedSource && (
- <p className="text-[11px] text-muted-foreground">
- Copies workspace files, chat threads, and cron jobs. Cron jobs will be
- renamed to match this project.
- </p>
- )}
- </div>
- <div className="space-y-2">
- <Label htmlFor="clone-name">
- New agent name <span className="text-destructive">*</span>
- </Label>
- <PrefixedInput
- id="clone-name"
- prefix={`${projectSlug}-`}
- placeholder="supa-backup"
- value={name}
- onChange={setName}
- disabled={pending}
- invalid={nameCollision || !!slugInvalidReason}
- />
- <NameHint
- derivedSlug={derivedSlug}
- collision={nameCollision}
- invalidReason={slugInvalidReason}
- defaultHint="Must be unique within this project."
- />
- </div>
- </div>
- )}
-
- <DialogFooter className="gap-2 sm:gap-2">
- <Button type="button" variant="outline" onClick={() => onOpenChange(false)} disabled={pending}>
- Cancel
- </Button>
- <Button
- type="button"
- onClick={onSubmit}
- disabled={
- pending ||
- nameCollision ||
- !!slugInvalidReason ||
- (mode === "create" && !name.trim()) ||
- (mode === "clone" && (!sourceId || !name.trim()))
- }
- >
- {pending ? (
- <>
- <Loader2 className="mr-1.5 size-3.5 animate-spin" />
- {mode === "clone" ? "Cloning…" : "Creating…"}
- </>
- ) : mode === "clone" ? (
- "Clone agent"
- ) : (
- "Create agent"
- )}
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
-
- {postClone && (
- <DisableSourceCronsDialog
- open
- onOpenChange={(o) => !o && setPostClone(null)}
- sourceLabel={postClone.sourceLabel}
- newAgentId={postClone.result.new_agent_id}
- sourceCrons={postClone.result.source_crons}
- onDone={() => {
- router.push(
- projectHref(projectSlug, `/agents/${postClone.result.new_slug}/chat`),
- );
- router.refresh();
- }}
- />
- )}
- </>
- );
-}
-
-function PrefixedInput({
- id,
- prefix,
- value,
- onChange,
- placeholder,
- disabled,
- autoFocus,
- invalid,
-}: {
- id: string;
- prefix: string;
- value: string;
- onChange: (next: string) => void;
- placeholder?: string;
- disabled?: boolean;
- autoFocus?: boolean;
- invalid?: boolean;
-}) {
- return (
- <div
- className={cn(
- "flex h-9 items-stretch overflow-hidden rounded-md border bg-background text-sm shadow-sm focus-within:ring-1 focus-within:ring-ring",
- invalid && "border-destructive focus-within:ring-destructive",
- disabled && "opacity-50",
- )}
- >
- <span
- className="select-none border-r bg-muted/50 px-2.5 font-mono text-[12px] text-muted-foreground flex items-center"
- aria-hidden
- >
- {prefix}
- </span>
- <input
- id={id}
- type="text"
- value={value}
- onChange={(e) => onChange(e.target.value)}
- placeholder={placeholder}
- disabled={disabled}
- autoFocus={autoFocus}
- aria-invalid={invalid || undefined}
- className="flex-1 bg-transparent px-2 font-mono text-[13px] placeholder:text-muted-foreground/60 focus-visible:outline-none disabled:cursor-not-allowed"
- />
- </div>
- );
-}
-
-function NameHint({
- derivedSlug,
- collision,
- invalidReason,
- defaultHint,
-}: {
- derivedSlug: string | null;
- collision: boolean;
- invalidReason: string | null;
- defaultHint: string;
-}) {
- if (invalidReason) {
- return (
- <p className="text-[11px] text-destructive">
- Invalid name: {invalidReason}
- </p>
- );
- }
- if (collision && derivedSlug) {
- return (
- <p className="text-[11px] text-destructive">
- An agent named &ldquo;{derivedSlug}&rdquo; already exists in this project.
- Pick a different name.
- </p>
- );
- }
- return <p className="text-[11px] text-muted-foreground">{defaultHint}</p>;
-}
-
-function ModeButton({
- active,
- onClick,
- icon,
- label,
-}: {
- active: boolean;
- onClick: () => void;
- icon: React.ReactNode;
- label: string;
-}) {
- return (
- <button
- type="button"
- onClick={onClick}
- className={cn(
- "flex items-center gap-1.5 rounded-md px-3 py-1 text-xs font-medium transition-colors",
- active
- ? "bg-background text-foreground shadow-sm"
- : "text-muted-foreground hover:text-foreground",
- )}
- >
- {icon}
- {label}
- </button>
- );
-}