import { useState } from "react"; import { SettingsCard, SettingsInput, SettingsRow, SettingsSection, SettingsSwitch } from "@getpaseo/plugin/client/ui"; import type { PluginTheme } from "@getpaseo/plugin"; import { CLI_FAMILY_IDS, isCliFamilyId } from "../../../shared/cli-families.js"; import type { ProviderCatalogOutput } from "../../../shared/rpc.js"; import { TIMEOUT_MS, type PromptKitSettings } from "../../../shared/settings.js"; import type { SettingsPatch } from "../draft.js"; import { Button } from "../ui/button.js"; import { ProviderMapCard } from "./provider-map-card.js"; import { describeTimeout } from "../validation.js"; type Providers = ProviderCatalogOutput["providers"]; export interface AdvancedSectionProps { theme: PluginTheme; values: PromptKitSettings; providers: Providers | null; disabled: boolean; epoch: number; patch(update: SettingsPatch): void; } const NONE = ""; /** Timeout, debug log, per-provider maps. Collapsed by default. */ export function AdvancedSection({ theme, values, providers, disabled, epoch, patch }: AdvancedSectionProps) { const [open, setOpen] = useState(false); const timeout = describeTimeout(values.timeoutMs); return ( setOpen((current) => !current)} testID="prompt-kit-advanced-toggle" /> } > {open ? ( <> { const parsed = Number(text.trim()); patch({ timeoutMs: Number.isFinite(parsed) ? parsed : Number.NaN }); }} /> patch({ debugLog: next })} /> {values.transport === "cli" ? ( ({ label: family, value: family }))} emptyTargetsLabel="No CLI family is available." errorFor={(providerId, family) => isCliFamilyId(family) ? null : `"${family}" is not a supported CLI.` } disabled={disabled} onSet={(providerId, family) => patch((current) => ({ providerCli: isCliFamilyId(family) ? { ...current.providerCli, [providerId]: family } : current.providerCli, })) } onRemove={(providerId) => patch((current) => { const next = { ...current.providerCli }; delete next[providerId]; return { providerCli: next }; }) } /> ) : ( ({ label: endpoint.label, value: endpoint.id }))} emptyTargetsLabel="Add an endpoint above first." disabled={disabled} onSet={(providerId, endpointId) => patch((current) => ({ apiEndpointByProvider: { ...current.apiEndpointByProvider, [providerId]: endpointId }, })) } onRemove={(providerId) => patch((current) => { const next = { ...current.apiEndpointByProvider }; delete next[providerId]; return { apiEndpointByProvider: next }; }) } /> )} ) : ( )} ); }