File size: 5,590 Bytes
c453128 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | 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 (
<div style={{ display: "flex", flexDirection: "column", minWidth: 0 }}>
<div style={{ ...sectionTitleStyle, marginBottom: 5 }}>{label}</div>
<div style={personaColumnStyle}>
{empty ? <span style={{ color: "var(--text-dim)", fontStyle: "italic" }}>(empty)</span> : text}
</div>
</div>
);
}
export function AgentToolsPreview({ agentId, toolsets, soul, memory }: Props) {
const [caps, setCaps] = useState<AgentCapabilities | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [tab, setTab] = useState<PresetTab>("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 (
<div style={{ fontSize: 11, color: "var(--text-dim)", padding: "8px 0" }}>
Loading profile…
</div>
);
}
if (error || !caps) {
return (
<div style={{ fontSize: 11, color: "#ff8080", padding: "8px 0" }}>
{error ?? "Could not load capabilities"}
</div>
);
}
const enabledSet = new Set(caps.presets[tab] ?? []);
const showPersona = soul !== undefined || memory !== undefined;
return (
<>
{showPersona && (
<div style={sectionBoxStyle}>
<div style={sectionTitleStyle}>Persona</div>
<div style={personaGridStyle}>
{soul !== undefined && (
<PersonaBlock label="SOUL.md — personality & instructions" text={soul} />
)}
{memory !== undefined && (
<PersonaBlock label="MEMORY.md — persistent notes" text={memory} />
)}
</div>
</div>
)}
<div style={sectionBoxStyle}>
<div style={{
display: "flex", alignItems: "center", justifyContent: "space-between",
marginBottom: 8, gap: 8, flexWrap: "wrap",
}}>
<div style={sectionTitleStyle}>Tools</div>
<div style={{ fontSize: 10, color: "var(--text-dim)" }}>
{caps.source === "profile" ? "Profile presets" : "Global presets"}
{caps.profile_disabled_toolsets.length > 0
? ` · blocks ${caps.profile_disabled_toolsets.join(", ")}`
: ""}
</div>
</div>
<div style={{ display: "flex", gap: 4, marginBottom: 10 }}>
{PRESET_TABS.map((id) => (
<button
key={id}
type="button"
onClick={() => setTab(id)}
style={presetTabStyle(tab === id)}
>
{id}
{caps.default_preset === id && (
<span style={{ marginLeft: 4, fontSize: 9, opacity: 0.75 }}>default</span>
)}
</button>
))}
</div>
<div style={{ display: "flex", flexWrap: "wrap", gap: 5, marginBottom: skillBundles.length ? 0 : undefined }}>
{toolsets.map((t) => (
<span
key={t.name}
title={(t.tools ?? [t.name]).join(", ")}
style={toolChipStyle(enabledSet.has(t.name))}
>
{labels[t.name] ?? t.label}
</span>
))}
</div>
</div>
{skillBundles.length > 0 && (
<div style={sectionBoxStyle}>
<div style={sectionTitleStyle}>
Skill categories
<span style={{ fontWeight: 400, marginLeft: 6, textTransform: "none", letterSpacing: 0 }}>
({caps.skill_count} installed)
</span>
</div>
<div style={{ display: "flex", flexWrap: "wrap", gap: 5 }}>
{skillBundles.map((b) => (
<span key={b.bundle} style={skillChipStyle(b.count > 0)} title={
b.count > 0 ? b.skills.slice(0, 8).join(", ") : "No skills in this category"
}>
{b.bundle}
<span style={{ marginLeft: 4, opacity: b.count > 0 ? 0.85 : 0.55 }}>
({b.count})
</span>
</span>
))}
</div>
</div>
)}
</>
);
}
|