From 0a191be435639c20053a1035545faf145604ce9f Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 1 Dec 2025 16:12:21 -0600 Subject: [PATCH] Let the system prompt be managed on the AI settings page --- src/locales/en.json | 2 +- src/pages/AISettings.tsx | 76 +++++++++++++++++++++++++++++++++++- src/pages/SystemSettings.tsx | 60 ---------------------------- 3 files changed, 75 insertions(+), 63 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index bc059552..4acb4b97 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -63,7 +63,7 @@ "shareErrorReports": "Share error reports", "shareErrorReportsDescription": "Help improve this app by automatically sending crash and error reports.", "systemPrompt": "System Prompt", - "systemPromptDescription": "Customize the AI assistant's system prompt using Jinja-like template syntax. This controls the assistant's behavior and knowledge.", + "systemPromptDescription": "AI system prompt controlling the assistant's behavior and knowledge.", "english": "English", "portuguese": "Portuguese", "chinese": "Chinese", diff --git a/src/pages/AISettings.tsx b/src/pages/AISettings.tsx index 575525f2..32dcb3ef 100644 --- a/src/pages/AISettings.tsx +++ b/src/pages/AISettings.tsx @@ -1,6 +1,6 @@ -import { useState } from 'react'; +import { useState, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; -import { Check, Bot, ArrowLeft, Trash2, GripVertical, ChevronDown } from 'lucide-react'; +import { Check, Bot, ArrowLeft, Trash2, GripVertical, ChevronDown, RotateCcw, FileText } from 'lucide-react'; import { DndContext, closestCenter, @@ -25,6 +25,7 @@ import { Input } from '@/components/ui/input'; import { PasswordInput } from '@/components/ui/password-input'; import { Label } from '@/components/ui/label'; import { Checkbox } from '@/components/ui/checkbox'; +import { Textarea } from '@/components/ui/textarea'; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; import { Card, CardContent } from '@/components/ui/card'; import { CreditsBadge } from '@/components/CreditsBadge'; @@ -34,6 +35,7 @@ import { Separator } from '@/components/ui/separator'; import { useAISettings } from '@/hooks/useAISettings'; import { useIsMobile } from '@/hooks/useIsMobile'; import { useCurrentUser } from '@/hooks/useCurrentUser'; +import { useAppContext } from '@/hooks/useAppContext'; import { useNavigate, Link } from 'react-router-dom'; import type { AIProvider } from '@/contexts/AISettingsContext'; import { AI_PROVIDER_PRESETS, type PresetProvider } from '@/lib/aiProviderPresets'; @@ -41,6 +43,7 @@ import { ExternalFavicon } from '@/components/ExternalFavicon'; import { MCPServersSection } from '@/components/MCPServersSection'; import { PluginsSection } from '@/components/PluginsSection'; import { ProjectTemplatesSection } from '@/components/ProjectTemplatesSection'; +import { defaultSystemPrompt } from '@/lib/system'; interface SortableProviderItemProps { provider: AIProvider; @@ -180,6 +183,7 @@ export function AISettings() { const isMobile = useIsMobile(); const navigate = useNavigate(); const { user } = useCurrentUser(); + const { config, defaultConfig, updateConfig } = useAppContext(); const [customProviderName, setCustomProviderName] = useState(''); const [customBaseURL, setCustomBaseURL] = useState(''); const [customApiKey, setCustomApiKey] = useState(''); @@ -189,6 +193,22 @@ export function AISettings() { const [presetTermsAgreements, setPresetTermsAgreements] = useState>({}); const [activeCreditsDialog, setActiveCreditsDialog] = useState(null); const [showAdvanced, setShowAdvanced] = useState(false); + const [systemPromptInput, setSystemPromptInput] = useState(config.systemPrompt || defaultSystemPrompt); + + // Check if system prompt differs from default + const isSystemPromptModified = useMemo(() => + (config.systemPrompt || defaultSystemPrompt) !== (defaultConfig.systemPrompt || defaultSystemPrompt), + [config, defaultConfig] + ); + + const restoreSystemPrompt = () => { + const defaultValue = defaultSystemPrompt; + setSystemPromptInput(defaultValue); + updateConfig((current) => { + const { systemPrompt, ...rest } = current; + return rest; + }); + }; const sensors = useSensors( useSensor(PointerSensor), @@ -599,6 +619,58 @@ export function AISettings() { {/* Plugins Section */} + + + {/* System Prompt Configuration */} +
+
+
+ +

{t('systemPrompt')}

+ {isSystemPromptModified && ( +
+ )} +
+

+ {t('systemPromptDescription')} +

+
+ + + + {t('systemPrompt')} + + +
+