import type { ReactNode } from "react" import { useTranslation } from "react-i18next" import { type CoreConfigForm, DM_SCOPE_OPTIONS, type LauncherForm, } from "@/components/config/form-model" import { Field, SwitchCardField } from "@/components/shared-form" import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card" import { Input } from "@/components/ui/input" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { Textarea } from "@/components/ui/textarea" type UpdateCoreField = ( key: K, value: CoreConfigForm[K], ) => void type UpdateLauncherField = ( key: K, value: LauncherForm[K], ) => void interface ConfigSectionCardProps { title: string description?: string children: ReactNode } function ConfigSectionCard({ title, description, children, }: ConfigSectionCardProps) { return ( {title} {description && {description}}
{children}
) } interface AgentDefaultsSectionProps { form: CoreConfigForm onFieldChange: UpdateCoreField } export function AgentDefaultsSection({ form, onFieldChange, }: AgentDefaultsSectionProps) { const { t } = useTranslation() return ( onFieldChange("workspace", e.target.value)} placeholder="~/.picoclaw/workspace" /> onFieldChange("restrictToWorkspace", checked) } /> onFieldChange("allowRemote", checked)} /> onFieldChange("maxTokens", e.target.value)} /> onFieldChange("contextWindow", e.target.value)} placeholder="131072" /> onFieldChange("maxToolIterations", e.target.value)} /> onFieldChange("summarizeMessageThreshold", e.target.value) } /> onFieldChange("summarizeTokenPercent", e.target.value) } /> ) } interface RuntimeSectionProps { form: CoreConfigForm onFieldChange: UpdateCoreField } export function RuntimeSection({ form, onFieldChange }: RuntimeSectionProps) { const { t } = useTranslation() const selectedDmScopeOption = DM_SCOPE_OPTIONS.find( (scope) => scope.value === form.dmScope, ) return ( onFieldChange("heartbeatEnabled", checked) } /> {form.heartbeatEnabled && ( onFieldChange("heartbeatInterval", e.target.value)} /> )} ) } interface LauncherSectionProps { launcherForm: LauncherForm onFieldChange: UpdateLauncherField disabled: boolean } export function LauncherSection({ launcherForm, onFieldChange, disabled, }: LauncherSectionProps) { const { t } = useTranslation() return ( onFieldChange("publicAccess", checked)} /> onFieldChange("port", e.target.value)} />