diff --git a/apps/web/src/components/agents/AgentEditor.tsx b/apps/web/src/components/agents/AgentEditor.tsx index b0207edc3614e..2f435540436d7 100644 --- a/apps/web/src/components/agents/AgentEditor.tsx +++ b/apps/web/src/components/agents/AgentEditor.tsx @@ -1,4 +1,4 @@ -import { CheckIcon } from "lucide-react"; +import { CheckIcon, PipetteIcon } from "lucide-react"; import { Combobox, ComboboxTrigger, @@ -8,17 +8,25 @@ import { ComboboxItem, ComboboxEmpty, } from "../ui/combobox"; -import { SelectButton } from "../ui/select"; +import { + Select, + SelectButton, + SelectItem, + SelectPopup, + SelectTrigger, + SelectValue, +} from "../ui/select"; import { Switch } from "../ui/switch"; -import { agentModelOptions, presetProviderLabel } from "./agentModelCatalog"; +import { Button } from "../ui/button"; +import { Checkbox } from "../ui/checkbox"; +import { Input } from "../ui/input"; +import { Label } from "../ui/label"; +import { Textarea } from "../ui/textarea"; +import { Alert, AlertDescription } from "../ui/alert"; +import { agentModelOptions, agentThinkingChoices, presetProviderLabel } from "./agentModelCatalog"; import type { AgentSkill, McpGatewayProfile, ServerProvider } from "@t3tools/contracts"; import { agentNameKey, MCP_GATEWAY_RUNTIME_MODE_LABELS } from "@t3tools/contracts"; -import { - agentColors, - agentHasAdvancedSettings, - defaultAgentColor, - soleOption, -} from "./agents.logic"; +import { agentColors, defaultAgentColor, soleOption } from "./agents.logic"; import { agentIconFieldsToSave, normalizeAgentTags, @@ -28,8 +36,16 @@ import { import { AgentIconPicker } from "./AgentIconPicker"; import { AgentTagsField } from "./AgentTagsField"; import { AGENT_PRESET_SETUP_NOTE } from "./AgentPresetPicker"; -import { useRef, useState, type CSSProperties } from "react"; -import { Dialog, DialogPopup, DialogTitle, DialogDescription } from "../ui/dialog"; +import { useId, useRef, useState, type CSSProperties, type ReactNode } from "react"; +import { + Dialog, + DialogDescription, + DialogFooter, + DialogHeader, + DialogPanel, + DialogPopup, + DialogTitle, +} from "../ui/dialog"; import { randomUUID } from "../../lib/utils"; import { findIdenticalSkill, @@ -38,6 +54,43 @@ import { } from "@t3tools/shared/agentPresets"; const emptySkills: ReadonlyArray = []; +const PROVIDER_DEFAULT = ""; + +function FormSection({ title, children }: { title: string; children: ReactNode }) { + const id = useId(); + return ( +
+

+ {title} +

+ {children} +
+ ); +} + +/** Label over control, with an optional hint under it. */ +function FormField({ + label, + htmlFor, + hint, + children, +}: { + label: ReactNode; + htmlFor?: string; + hint?: ReactNode; + children: ReactNode; +}) { + return ( +
+ + {children} + {hint &&

{hint}

} +
+ ); +} const PRESET_SKILL_PREFIX = "preset:"; export function AgentEditor({ @@ -114,9 +167,6 @@ export function AgentEditor({ const [pickedIcon, setPickedIcon] = useState(null); const iconId = pickedIcon ?? resolveAgentIconId(profile ?? preset); const [tags, setTags] = useState>(profile?.tags ?? preset?.tags ?? []); - const [advancedOpen, setAdvancedOpen] = useState( - () => profile !== null && agentHasAdvancedSettings(profile, profiles), - ); const [description, setDescription] = useState(profile?.description ?? preset?.description ?? ""); const [name, setName] = useState(profile?.name ?? preset?.name ?? ""); const [providerLabel, setProviderLabel] = useState( @@ -160,6 +210,25 @@ export function AgentEditor({ (models.filter((item) => item.name === model).length === 1 ? models.find((item) => item.name === model) : undefined); + const ids = useId(); + const providerOptions = [...new Set([...providerLabels, ...(provider ? [provider] : [])])]; + const modelItems = [ + ...(model && !selectedModel + ? [{ value: model, label: `${model} (unavailable)`, disabled: true }] + : []), + ...models.map((option) => ({ + value: option.slug, + label: `${option.name} (${option.slug})`, + disabled: false, + })), + ]; + const thinkingItems = [ + { value: PROVIDER_DEFAULT, label: "Provider default" }, + ...agentThinkingChoices(selectedModel, thinking.trim()), + ]; + const customColor = !agentColors.includes(color); + const swatchClass = + "relative size-6 shrink-0 cursor-pointer rounded-full aria-pressed:ring-2 aria-pressed:ring-foreground aria-pressed:ring-inset data-selected:ring-2 data-selected:ring-foreground data-selected:ring-inset"; return ( - -
- - {profile ? "Edit agent" : preset ? `Create agent from ${preset.name}` : "Create agent"} - - - Name a specialist and choose its model. It starts working when you give it a task. - - {preset && ( -
-

{AGENT_PRESET_SETUP_NOTE}

- {preset.setupNotes.length > 0 && ( -
    - {preset.setupNotes.map((note) => ( -
  • {note}
  • - ))} -
- )} - {!skillsAvailable && preset.skills.length > 0 && ( -

Update T3 Code on this machine to add this preset’s skills.

+ +
{ + event.preventDefault(); + if (nameTaken) return; + setSaving(true); + setError(""); + const normalizedTags = normalizeAgentTags(tags); + const now = new Date().toISOString(); + try { + const saved = await onSave( + { + profileId: profile?.profileId ?? randomUUID(), + name: name.trim(), + description: description.trim(), + systemPrompt, + skillIds: skillIds.filter((id) => !id.startsWith(PRESET_SKILL_PREFIX)), + ...(includeUserSkills ? {} : { includeUserSkills: false }), + color, + ...agentIconFieldsToSave(profile ?? preset, pickedIcon), + ...(normalizedTags.length ? { tags: normalizedTags } : {}), + revision: profile?.revision ?? 1, + providerLabel: provider, + modelLabel: selectedModel?.slug ?? model, + ...(thinking.trim() ? { reasoningEffort: thinking.trim() } : {}), + runtimeMode, + interactionMode, + ...(environmentIds.length ? { environmentIds } : {}), + createdAt: profile?.createdAt ?? now, + updatedAt: now, + }, + presetSkills.filter( + (skill, index) => + skillIds.includes(presetSkillIds[index]!) && + (presetSkillIds[index]!.startsWith(PRESET_SKILL_PREFIX) || + skill.choice?.kind === "update"), + ), + ); + if (saved) onClose(); + else setError("Could not save the agent. Check your connection and try again."); + } catch (cause) { + setError(cause instanceof Error ? cause.message : "Could not save agent."); + } + setSaving(false); + }} + > + + + {profile + ? "Edit agent" + : preset + ? `Create agent from ${preset.name}` + : "Create agent"} + + + Name a specialist and choose its model. It starts working when you give it a task. + + + +
+ {preset && ( + + +

{AGENT_PRESET_SETUP_NOTE}

+ {preset.setupNotes.length > 0 && ( +
    + {preset.setupNotes.map((note) => ( +
  • {note}
  • + ))} +
+ )} + {!skillsAvailable && preset.skills.length > 0 && ( +

+ Update T3 Code on this machine to add this preset’s skills. +

+ )} +
+
)} -
- )} - { - event.preventDefault(); - if (nameTaken) return; - setSaving(true); - setError(""); - const normalizedTags = normalizeAgentTags(tags); - // oxlint-disable-next-line react/purity -- captures the save time inside the submit handler (oxc#27309) - const now = new Date().toISOString(); - try { - const saved = await onSave( - { - profileId: profile?.profileId ?? randomUUID(), - name: name.trim(), - description: description.trim(), - systemPrompt, - skillIds: skillIds.filter((id) => !id.startsWith(PRESET_SKILL_PREFIX)), - ...(includeUserSkills ? {} : { includeUserSkills: false }), - color, - ...agentIconFieldsToSave(profile ?? preset, pickedIcon), - ...(normalizedTags.length ? { tags: normalizedTags } : {}), - revision: profile?.revision ?? 1, - providerLabel: provider, - modelLabel: selectedModel?.slug ?? model, - ...(thinking.trim() ? { reasoningEffort: thinking.trim() } : {}), - runtimeMode, - interactionMode, - ...(environmentIds.length ? { environmentIds } : {}), - createdAt: profile?.createdAt ?? now, - updatedAt: now, - }, - presetSkills.filter( - (skill, index) => - skillIds.includes(presetSkillIds[index]!) && - (presetSkillIds[index]!.startsWith(PRESET_SKILL_PREFIX) || - skill.choice?.kind === "update"), - ), - ); - if (saved) onClose(); - else setError("Could not save the agent. Check your connection and try again."); - } catch (cause) { - setError(cause instanceof Error ? cause.message : "Could not save agent."); - } - setSaving(false); - }} - > -
- - -
- {nameTaken && ( -

- Another agent is already called “{name.trim()}”. Names ignore case. -

- )} - -
-
+
+ {nameTaken && ( +

+ Another agent is already called “{name.trim()}”. Names ignore case. +

)} - - - -
- {preset && model === preset.model.model && !selectedModel && ( -

- {providerLabels.includes(provider) - ? `${model} isn’t available from ${provider}.` - : `${provider} isn’t installed on a connected machine.`}{" "} - Choose an available provider and model to save this agent. -

- )} -
setAdvancedOpen(event.currentTarget.open)} - > - Advanced -
- -
- Color -
- setColor(event.target.value)} - /> + + +
+ +
{agentColors.map((value) => (
-