import React, { useEffect, useMemo, useState } from "react";
import type { AgentCapabilities, ToolsetMeta } from "../types";
import { api } from "../api/client";
import {
personaColumnStyle,
personaGridStyle,
presetTabStyle,
sectionBoxStyle,
sectionTitleStyle,
skillChipStyle,
toolChipStyle,
} from "./modalStyles";
const PRESET_TABS = ["chat", "lean", "full"] as const;
type PresetTab = (typeof PRESET_TABS)[number];
interface Props {
agentId: string;
toolsets: ToolsetMeta[];
soul?: string;
memory?: string;
}
function PersonaBlock({ label, text }: { label: string; text: string }) {
const empty = !text.trim();
return (
{label}
{empty ? (empty) : text}
);
}
export function AgentToolsPreview({ agentId, toolsets, soul, memory }: Props) {
const [caps, setCaps] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const [tab, setTab] = useState("lean");
useEffect(() => {
let cancelled = false;
setLoading(true);
setError(null);
api.agents.capabilities(agentId)
.then((data) => {
if (cancelled) return;
setCaps(data);
const def = data.default_preset;
if (def === "chat" || def === "lean" || def === "full") setTab(def);
})
.catch((e: Error) => { if (!cancelled) setError(e.message); })
.finally(() => { if (!cancelled) setLoading(false); });
return () => { cancelled = true; };
}, [agentId]);
const labels = useMemo(
() => Object.fromEntries(toolsets.map((t) => [t.name, t.label])),
[toolsets],
);
const skillBundles = useMemo(() => {
if (!caps) return [];
return [...caps.skill_bundles].sort((a, b) => {
if (a.count > 0 && b.count === 0) return -1;
if (a.count === 0 && b.count > 0) return 1;
return a.bundle.localeCompare(b.bundle);
});
}, [caps]);
if (loading) {
return (
Loading profile…
);
}
if (error || !caps) {
return (
{error ?? "Could not load capabilities"}
);
}
const enabledSet = new Set(caps.presets[tab] ?? []);
const showPersona = soul !== undefined || memory !== undefined;
return (
<>
{showPersona && (
Persona
{soul !== undefined && (
)}
{memory !== undefined && (
)}
)}
Tools
{caps.source === "profile" ? "Profile presets" : "Global presets"}
{caps.profile_disabled_toolsets.length > 0
? ` · blocks ${caps.profile_disabled_toolsets.join(", ")}`
: ""}
{PRESET_TABS.map((id) => (
))}
{toolsets.map((t) => (
{labels[t.name] ?? t.label}
))}
{skillBundles.length > 0 && (
Skill categories
({caps.skill_count} installed)
{skillBundles.map((b) => (
0)} title={
b.count > 0 ? b.skills.slice(0, 8).join(", ") : "No skills in this category"
}>
{b.bundle}
0 ? 0.85 : 0.55 }}>
({b.count})
))}
)}
>
);
}