"use client"; import { IconAlertCircle, IconRefresh, IconTerminal2 } from "@tabler/icons-react"; import { NoAuthPanel, ProbingPanel } from "@/components/settings/profile-status-panels"; import { Button } from "@kandev/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "@kandev/ui/dialog"; import { Input } from "@kandev/ui/input"; import { Label } from "@kandev/ui/label"; import { Skeleton } from "@kandev/ui/skeleton"; import { Switch } from "@kandev/ui/switch"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { ModeCombobox } from "@/components/settings/mode-combobox"; import { ModelCombobox } from "@/components/settings/model-combobox"; import { useAgentCapabilities } from "@/hooks/domains/settings/use-dynamic-models"; import { PERMISSION_KEYS, type PermissionKey } from "@/lib/agent-permissions"; import { CLIFlagsField } from "@/components/settings/cli-flags-field"; import type { CLIFlag, CommandEntry, ModelConfig, ModeEntry, ModelEntry, PermissionSetting, PassthroughConfig, } from "@/lib/types/http"; export type ProfileFormData = { name: string; model: string; mode: string; cli_passthrough: boolean; cli_flags: CLIFlag[]; } & Record; export type ProfileFormFieldsProps = { profile: ProfileFormData; onChange: (patch: Partial) => void; modelConfig: ModelConfig; permissionSettings: Record; passthroughConfig: PassthroughConfig | null; agentName: string; onRemove?: () => void; canRemove?: boolean; variant?: "default" | "compact"; hideNameField?: boolean; lockPassthrough?: boolean; /** * When true, the custom-flag list + Add form on CLIFlagsField is * hidden. Curated predefined toggles still render. Used by the * onboarding flow to keep the first-run UI narrow. */ hideCustomCLIFlags?: boolean; }; type PermissionToggleProps = { profile: ProfileFormData; onChange: (patch: Partial) => void; permissionSettings: Record; passthroughConfig: PassthroughConfig | null; variant: "default" | "compact"; lockPassthrough?: boolean; }; function PermissionToggles({ profile, onChange, permissionSettings, passthroughConfig, variant, lockPassthrough, }: PermissionToggleProps) { const isCompact = variant === "compact"; const switchSize = isCompact ? ("sm" as const) : ("default" as const); if (isCompact) { return ( <> {PERMISSION_KEYS.map((key) => { const setting = permissionSettings[key]; if (!setting?.supported) return null; if (setting.apply_method === "cli_flag") return null; return (

{setting.description}

onChange({ [key]: checked })} />
); })} {passthroughConfig?.supported && (

{passthroughConfig.description}

onChange({ cli_passthrough: checked })} disabled={lockPassthrough} />
)} ); } return (
{PERMISSION_KEYS.map((key) => { const setting = permissionSettings[key]; if (!setting?.supported) return null; if (setting.apply_method === "cli_flag") return null; return (

{setting.description}

onChange({ [key]: checked })} />
); })} {passthroughConfig?.supported && (

{passthroughConfig.description}

onChange({ cli_passthrough: checked })} disabled={lockPassthrough} />
)}
); } function capabilityStatusMessage(modelConfig: ModelConfig): string | null { switch (modelConfig.status) { case "probing": return "Checking agent capabilities…"; case "auth_required": return "Authentication required. Run the agent CLI in your terminal to authenticate, then refresh."; case "not_installed": return "Agent CLI not installed."; case "failed": return "Probe failed. Check agent logs for details."; default: return null; } } function CapabilityStatusMessage({ modelConfig }: { modelConfig: ModelConfig }) { const msg = capabilityStatusMessage(modelConfig); if (!msg) return null; return (

{msg}

); } function RefreshCapabilitiesButton({ onRefresh, isLoading, error, }: { onRefresh: () => Promise; isLoading: boolean; error: string | null; }) { return (

Refresh agent capabilities (models + modes)

{error && (

Failed to refresh: {error}

)}
); } function ModelPicker({ profile, models, currentModelId, onChange, }: { profile: ProfileFormData; models: ModelEntry[]; currentModelId: string | undefined; onChange: (patch: Partial) => void; }) { return ( onChange({ model: value })} models={models} currentModelId={currentModelId} placeholder="Select a model..." /> ); } function ModePicker({ profile, modes, currentModeId, onChange, }: { profile: ProfileFormData; modes: ModeEntry[]; currentModeId: string | undefined; onChange: (patch: Partial) => void; }) { return ( onChange({ mode: value })} modes={modes} currentModeId={currentModeId} /> ); } function CommandsButton({ commands }: { commands: CommandEntry[] }) { if (commands.length === 0) return null; return ( Available slash commands Type these during a session chat to invoke them — e.g. /init.
{commands.map((c) => (
/{c.name} {c.description && (

{c.description}

)}
))}
); } function CapabilitiesRow({ profile, models, modes, commands, currentModelId, currentModeId, onChange, isCompact, isLoading, onRefresh, error, modelConfig, agentName, }: { profile: ProfileFormData; models: ModelEntry[]; modes: ModeEntry[]; commands: CommandEntry[]; currentModelId: string | undefined; currentModeId: string | undefined; onChange: (patch: Partial) => void; isCompact: boolean; isLoading: boolean; onRefresh: () => Promise; error: string | null; modelConfig: ModelConfig; agentName: string; }) { const hasModes = modes.length > 0; const activeMode = hasModes ? modes.find((m) => m.id === (profile.mode || currentModeId || modes[0]?.id)) : undefined; const labelCls = isCompact ? "text-xs text-muted-foreground" : undefined; const gapCls = isCompact ? "space-y-1.5" : "space-y-2"; if (isLoading && models.length === 0) { return (
); } const status = modelConfig.status; if (status === "probing") { return ; } if (status === "auth_required" || status === "not_installed") { return ( ); } return (
{hasModes && (
)}
{activeMode?.description && (

{activeMode.description}

)} {commands.length > 0 && }
); } function NameField({ profile, onChange, canRemove, onRemove, }: { profile: ProfileFormData; onChange: (patch: Partial) => void; canRemove?: boolean; onRemove?: () => void; }) { return (
onChange({ name: event.target.value })} placeholder="Default profile" />
{canRemove && onRemove && ( )}
); } export function ProfileFormFields({ profile, onChange, modelConfig, permissionSettings, passthroughConfig, agentName, onRemove, canRemove = false, variant = "default", hideNameField = false, lockPassthrough = false, hideCustomCLIFlags = false, }: ProfileFormFieldsProps) { const isCompact = variant === "compact"; const caps = useAgentCapabilities(agentName, modelConfig); return (
{!hideNameField && ( )} onChange({ cli_flags: next })} permissionSettings={permissionSettings} variant={variant} hideCustomFlags={hideCustomCLIFlags} />
); }