import { SettingsAction, SettingsCard, SettingsRow, SettingsSection, SettingsSwitch } from "@getpaseo/plugin/client/ui"; import type { ActionSummary, ActionsListOutput } from "../../../shared/rpc.js"; import type { PromptKitSettings } from "../../../shared/settings.js"; import { MAX_ENABLED_ACTIONS, enabledActions } from "../../actions/enabled.js"; import type { SettingsPatch } from "../draft.js"; export interface ActionsSectionProps { /** Null while the registry has not answered yet. */ actions: readonly ActionSummary[] | null; /** Packs the registry refused, e.g. a custom action reusing a bundled id. */ rejected: ActionsListOutput["rejected"]; error: string | null; values: PromptKitSettings; disabled: boolean; patch(update: SettingsPatch): void; reload(): void; } function hintFor(action: ActionSummary): string { return action.custom ? `Custom · ${action.description}` : action.description; } /** Per-action enable switches, at most `MAX_ENABLED_ACTIONS` on; a lone action has no switch. */ export function ActionsSection({ actions, rejected, error, values, disabled, patch, reload }: ActionsSectionProps) { const enabledCount = actions === null ? 0 : enabledActions(actions, values).length; return ( {error !== null ? ( ) : actions === null ? ( ) : actions.length === 0 ? ( ) : actions.length === 1 && enabledCount === 1 ? ( ) : ( actions.map((action) => { const on = enabledActions([action], values).length === 1; const full = !on && enabledCount >= MAX_ENABLED_ACTIONS; return ( patch((current) => ({ actionEnabled: { ...current.actionEnabled, [action.id]: next }, })) } /> ); }) )} {rejected.map((entry) => ( ))} ); }