"use client";
import { IconDownload, IconLoader2 } from "@tabler/icons-react";
import { Button } from "@kandev/ui/button";
import { Card, CardContent } from "@kandev/ui/card";
import { AgentLogo } from "@/components/agent-logo";
import type { InstallJob } from "@/lib/api";
import type { AvailableAgent } from "@/lib/types/http";
type InstallStatus = InstallJob["status"] | "idle";
function installButtonContent(status: InstallStatus): {
icon: "spinner" | "download";
label: string;
} {
switch (status) {
case "queued":
return { icon: "spinner", label: "Queued…" };
case "running":
return { icon: "spinner", label: "Installing…" };
case "failed":
return { icon: "download", label: "Retry" };
default:
return { icon: "download", label: "Install" };
}
}
function InstallButton({
agentName,
status,
onInstall,
}: {
agentName: string;
status: InstallStatus;
onInstall: (name: string) => void;
}) {
const isInFlight = status === "queued" || status === "running";
const btn = installButtonContent(status);
return (
);
}
/**
* Card shown under "Available to Install" on the Agents settings page. While a
* job is queued/running it shows a live log streamed via the agent.install.*
* WS events. On failure it surfaces the install script's output + error.
*/
export function InstallAgentCard({
agent,
job,
scriptSlot,
onInstall,
}: {
agent: AvailableAgent;
job: InstallJob | undefined;
/** The copy-and-script row, rendered above the Install button by the parent. */
scriptSlot?: React.ReactNode;
onInstall: (name: string) => void;
}) {
const status: InstallStatus = job?.status ?? "idle";
const failed = status === "failed";
const showLog = Boolean(job?.output) && (status === "queued" || status === "running" || failed);
return (
{agent.description && (
{agent.description}
)}
{scriptSlot}
{agent.install_script && (
)}
{showLog && (
{job?.output}
)}
{failed && job?.error && (
{job.error}
)}
);
}