b6848712f8
Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
230 lines
7.7 KiB
TypeScript
230 lines
7.7 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import Link from "@/components/routing/app-link";
|
|
import { IconLoader2, IconLock, IconSettings } from "@tabler/icons-react";
|
|
import { Badge } from "@kandev/ui/badge";
|
|
import { Button } from "@kandev/ui/button";
|
|
import { Card, CardContent } from "@kandev/ui/card";
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip";
|
|
import { AgentLogo } from "@/components/agent-logo";
|
|
import { AgentLoginDialog } from "@/components/settings/agent-login-dialog";
|
|
import { AgentRuntimeUpdateControl } from "@/components/settings/agent-runtime-update-control";
|
|
import { HostShellDialog } from "@/components/settings/host-shell-dialog";
|
|
import type { AgentUpdateJob, AgentUpdatePreview, InstallJob } from "@/lib/api";
|
|
import type { Agent, AgentDiscovery, RuntimeUpdate } from "@/lib/types/http";
|
|
|
|
type Props = {
|
|
agent: AgentDiscovery;
|
|
savedAgent: Agent | undefined;
|
|
displayName: string;
|
|
/** Capability status from the host utility probe ("ok", "auth_required", etc.). */
|
|
capabilityStatus?: string;
|
|
runtimeUpdate?: RuntimeUpdate;
|
|
updateJob?: AgentUpdateJob;
|
|
installJob?: InstallJob;
|
|
onPreview?: (agentName: string) => Promise<AgentUpdatePreview>;
|
|
onUpdate?: (agentName: string) => Promise<AgentUpdateJob>;
|
|
/**
|
|
* Called when the auth/shell dialog closes so the page can refresh
|
|
* discovery + availability. Without this the yellow lock stays put even
|
|
* after a successful sign-in, making the recovery flow look broken.
|
|
*/
|
|
onAuthComplete?: () => void;
|
|
};
|
|
|
|
function InstalledAgentIdentity({
|
|
agent,
|
|
displayName,
|
|
configured,
|
|
probing,
|
|
authRequired,
|
|
loginAvailable,
|
|
onAuthClick,
|
|
}: {
|
|
agent: AgentDiscovery;
|
|
displayName: string;
|
|
configured: boolean;
|
|
probing: boolean;
|
|
authRequired: boolean;
|
|
loginAvailable: boolean;
|
|
onAuthClick: () => void;
|
|
}) {
|
|
const { t } = useTranslation();
|
|
return (
|
|
<div className="space-y-1">
|
|
<div className="flex min-w-0 flex-wrap items-center gap-2">
|
|
<AgentLogo agentName={agent.name} size={20} className="shrink-0" />
|
|
<h4 className="min-w-0 truncate font-medium">{displayName}</h4>
|
|
{agent.supports_mcp && <Badge variant="secondary">MCP</Badge>}
|
|
{configured && <Badge variant="outline">{t("agents:configured")}</Badge>}
|
|
<div className="ml-auto flex shrink-0 items-center gap-1">
|
|
{probing && (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span
|
|
data-testid={`probing-icon-${agent.name}`}
|
|
className="flex items-center text-muted-foreground cursor-help"
|
|
aria-label={t("agents:checkingAuthentication")}
|
|
>
|
|
<IconLoader2 className="h-3.5 w-3.5 animate-spin" />
|
|
</span>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{t("agents:checkingCapabilitiesAndAuth")}</TooltipContent>
|
|
</Tooltip>
|
|
)}
|
|
{authRequired && (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<button
|
|
type="button"
|
|
onClick={onAuthClick}
|
|
data-testid={`auth-icon-${agent.name}`}
|
|
className="flex items-center gap-1 rounded-md px-1.5 py-0.5 text-xs text-amber-500 cursor-pointer hover:bg-amber-500/10"
|
|
aria-label={t("agents:authenticationRequired")}
|
|
>
|
|
<IconLock className="h-3.5 w-3.5" />
|
|
</button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>
|
|
{loginAvailable
|
|
? t("agents:authRequiredOpenLoginTerminal")
|
|
: t("agents:authRequiredOpenShell")}
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
)}
|
|
</div>
|
|
</div>
|
|
<p
|
|
className="text-xs text-muted-foreground line-clamp-2 min-h-[2rem]"
|
|
title={agent.matched_path ?? undefined}
|
|
>
|
|
{agent.matched_path ? t("agents:detectedAt", { path: agent.matched_path }) : ""}
|
|
</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Card rendered under "Installed Agents" - links to the agent profile
|
|
* editor and surfaces a yellow lock icon when the capability probe reports
|
|
* `auth_required`. Clicking the lock opens a PTY login dialog if the agent
|
|
* type has a registered LoginCommand.
|
|
*/
|
|
export function InstalledAgentCard({
|
|
agent,
|
|
savedAgent,
|
|
displayName,
|
|
capabilityStatus,
|
|
runtimeUpdate,
|
|
updateJob,
|
|
installJob,
|
|
onPreview,
|
|
onUpdate,
|
|
onAuthComplete,
|
|
}: Props) {
|
|
const { t } = useTranslation();
|
|
const configured = Boolean(savedAgent && savedAgent.profiles.length > 0);
|
|
const hasAgentRecord = Boolean(savedAgent);
|
|
const [loginOpen, setLoginOpen] = useState(false);
|
|
const [shellOpen, setShellOpen] = useState(false);
|
|
const authRequired = capabilityStatus === "auth_required";
|
|
const probing = capabilityStatus === "probing";
|
|
const loginAvailable = Boolean(agent.login_command);
|
|
|
|
// Either we have a registered login command (open the dedicated login PTY)
|
|
// or we don't (open a plain host shell so the user can explore via
|
|
// `<agent> --help`, run their own auth recipe, etc.).
|
|
const handleAuthClick = () => {
|
|
if (loginAvailable) setLoginOpen(true);
|
|
else setShellOpen(true);
|
|
};
|
|
|
|
return (
|
|
<Card className="flex min-w-0 flex-col">
|
|
<CardContent className="py-4 flex min-w-0 flex-col gap-3 flex-1">
|
|
<InstalledAgentIdentity
|
|
agent={agent}
|
|
displayName={displayName}
|
|
configured={configured}
|
|
probing={probing}
|
|
authRequired={authRequired}
|
|
loginAvailable={loginAvailable}
|
|
onAuthClick={handleAuthClick}
|
|
/>
|
|
<div className="mt-auto flex items-center gap-2">
|
|
<Button
|
|
size="sm"
|
|
className="h-11 min-h-11 flex-1 cursor-pointer sm:h-7 sm:min-h-7"
|
|
asChild
|
|
>
|
|
<Link
|
|
href={
|
|
hasAgentRecord
|
|
? `/settings/agents/${encodeURIComponent(agent.name)}?mode=create`
|
|
: `/settings/agents/${encodeURIComponent(agent.name)}`
|
|
}
|
|
>
|
|
<IconSettings className="mr-2 h-4 w-4" />
|
|
{hasAgentRecord ? t("agents:createNewProfile") : t("agents:setupProfile")}
|
|
</Link>
|
|
</Button>
|
|
{runtimeUpdate?.supported && onPreview && onUpdate && (
|
|
<AgentRuntimeUpdateControl
|
|
agentName={agent.name}
|
|
displayName={displayName}
|
|
runtimeUpdate={runtimeUpdate}
|
|
job={updateJob}
|
|
installJob={installJob}
|
|
onPreview={onPreview}
|
|
onUpdate={onUpdate}
|
|
/>
|
|
)}
|
|
</div>
|
|
<AuthDialogs
|
|
agent={agent}
|
|
loginOpen={loginOpen}
|
|
setLoginOpen={setLoginOpen}
|
|
shellOpen={shellOpen}
|
|
setShellOpen={setShellOpen}
|
|
loginAvailable={loginAvailable}
|
|
onAuthComplete={onAuthComplete}
|
|
/>
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
}
|
|
|
|
function AuthDialogs({
|
|
agent,
|
|
loginOpen,
|
|
setLoginOpen,
|
|
shellOpen,
|
|
setShellOpen,
|
|
loginAvailable,
|
|
onAuthComplete,
|
|
}: {
|
|
agent: AgentDiscovery;
|
|
loginOpen: boolean;
|
|
setLoginOpen: (open: boolean) => void;
|
|
shellOpen: boolean;
|
|
setShellOpen: (open: boolean) => void;
|
|
loginAvailable: boolean;
|
|
onAuthComplete?: () => void;
|
|
}) {
|
|
if (loginAvailable) {
|
|
return (
|
|
<AgentLoginDialog
|
|
open={loginOpen}
|
|
onOpenChange={setLoginOpen}
|
|
agentName={agent.name}
|
|
description={agent.login_command?.description}
|
|
command={agent.login_command?.cmd}
|
|
onLoginSuccess={onAuthComplete}
|
|
/>
|
|
);
|
|
}
|
|
return <HostShellDialog open={shellOpen} onOpenChange={setShellOpen} onClose={onAuthComplete} />;
|
|
}
|