"use client"; import { IconPencil, IconPlus, IconTrash } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { Label } from "@kandev/ui/label"; import { Separator } from "@kandev/ui/separator"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue, } from "@kandev/ui/select"; import { ModelCombobox } from "@/components/settings/model-combobox"; import type { UtilityAgent, InferenceAgent } from "@/lib/api/domains/utility-api"; const USE_DEFAULT = "__USE_DEFAULT__"; export type ModelOption = { value: string; label: string; agentName: string; modelName: string }; type ModelGroup = { agentName: string; models: ModelOption[] }; function groupModelsByAgent(models: ModelOption[]): ModelGroup[] { const map = new Map(); for (const m of models) { const list = map.get(m.agentName); if (list) list.push(m); else map.set(m.agentName, [m]); } return Array.from(map, ([agentName, items]) => ({ agentName, models: items })); } // Default model selector section type DefaultModelSectionProps = { inferenceAgents: InferenceAgent[]; defaultAgentId: string; defaultModel: string; onDefaultChange: (agentId: string, model: string) => void; }; export function DefaultModelSection({ inferenceAgents, defaultAgentId, defaultModel, onDefaultChange, }: DefaultModelSectionProps) { const selectedAgent = inferenceAgents.find((a) => a.id === defaultAgentId); const modelOptions = selectedAgent?.models ?? []; const currentModelId = modelOptions.find((m) => m.is_default)?.id; return (

Default utility agent model

Select the default model used by all built-in utility actions.

onDefaultChange(defaultAgentId, v)} models={modelOptions} currentModelId={currentModelId} placeholder="Select model..." disabled={!defaultAgentId} />
); } // Builtin action row type BuiltinActionRowProps = { agent: UtilityAgent; allModels: ModelOption[]; defaultLabel: string; onModelChange: (agent: UtilityAgent, value: string) => void; onEdit: (agent: UtilityAgent) => void; }; export function BuiltinActionRow({ agent, allModels, defaultLabel, onModelChange, onEdit, }: BuiltinActionRowProps) { const currentValue = agent.agent_id && agent.model ? `${agent.agent_id}|${agent.model}` : USE_DEFAULT; return (
{agent.name}

{agent.description}

); } // Custom agent row type CustomAgentRowProps = { agent: UtilityAgent; onEdit: (agent: UtilityAgent) => void; onDelete: (agent: UtilityAgent) => void; }; export function CustomAgentRow({ agent, onEdit, onDelete }: CustomAgentRowProps) { return (
{agent.name}

{agent.description}

{agent.model || "Not configured"}
); } // Per-action overrides section type PerActionOverridesSectionProps = { builtins: UtilityAgent[]; allModels: ModelOption[]; defaultModel: string; onModelChange: (agent: UtilityAgent, value: string) => void; onEdit: (agent: UtilityAgent) => void; }; export function PerActionOverridesSection({ builtins, allModels, defaultModel, onModelChange, onEdit, }: PerActionOverridesSectionProps) { if (builtins.length === 0) return null; const defaultLabel = defaultModel ? `Default (${defaultModel})` : "Default"; return (

Actions

{builtins.map((agent) => ( ))}
); } // Custom agents section type CustomAgentsSectionProps = { agents: UtilityAgent[]; onAdd: () => void; onEdit: (agent: UtilityAgent) => void; onDelete: (agent: UtilityAgent) => void; }; export function CustomAgentsSection({ agents, onAdd, onEdit, onDelete }: CustomAgentsSectionProps) { return (

Custom utility agents

Create your own utility agents with custom prompts.

{agents.length === 0 && (

No custom utility agents.

)} {agents.length > 0 && (
{agents.map((agent) => ( ))}
)}
); } // Export the USE_DEFAULT constant export { USE_DEFAULT };