mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Fix global chat issues and move chat system prompt setting
1. Fixed user message not appearing in global chat 2. Made project chat and global chat remember separate models - Added separate localStorage storage for global chat model - Project chat continues to use recentlyUsedModels from AISettings - Global chat now stores its model independently 3. Moved Chat System Prompt setting from Preferences to System Settings 4. Removed chat pop-out functionality - Removed isPoppedOut state from GlobalChatContext - Removed handlePopOut function from GlobalChatPane - Removed pop-out button from desktop chat header - Removed isPoppedOut check from FloatingChatButton
This commit is contained in:
1 parent
477d055797
commit
0c4de2e2c0
6 files changed
+85
-186
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import { useState, useMemo } from "react";
|
||||
import { Settings2, ArrowLeft, ChevronDown, Edit, RotateCcw } from "lucide-react";
|
||||
import { Settings2, ArrowLeft } from "lucide-react";
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
@@ -7,40 +6,16 @@ import { ThemePicker } from "@/components/ThemePicker";
|
||||
import { LanguagePicker } from "@/components/LanguagePicker";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { useIsMobile } from "@/hooks/useIsMobile";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useAppContext } from "@/hooks/useAppContext";
|
||||
|
||||
// Default system prompt for global chat
|
||||
const DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT = `You are a helpful AI assistant. You're here to have a friendly conversation and help answer questions on any topic.
|
||||
|
||||
Keep your responses concise but informative. Be friendly and conversational.`;
|
||||
|
||||
export function Preferences() {
|
||||
const { t } = useTranslation();
|
||||
const isMobile = useIsMobile();
|
||||
const navigate = useNavigate();
|
||||
const { config, defaultConfig, updateConfig } = useAppContext();
|
||||
const [showAdvanced, setShowAdvanced] = useState(false);
|
||||
const [chatSystemPromptInput, setChatSystemPromptInput] = useState(
|
||||
config.globalChatSystemPrompt || DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT
|
||||
);
|
||||
|
||||
// Check if chat system prompt differs from default
|
||||
const isChatSystemPromptModified = useMemo(() =>
|
||||
(config.globalChatSystemPrompt || DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT) !== DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT,
|
||||
[config.globalChatSystemPrompt]);
|
||||
|
||||
const restoreChatSystemPrompt = () => {
|
||||
setChatSystemPromptInput(DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT);
|
||||
updateConfig((current) => {
|
||||
const { globalChatSystemPrompt, ...rest } = current;
|
||||
return rest;
|
||||
});
|
||||
};
|
||||
const { config, updateConfig } = useAppContext();
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-6">
|
||||
@@ -150,76 +125,6 @@ export function Preferences() {
|
||||
{t('globalChatEnabledDescription')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Advanced Global Chat Settings */}
|
||||
{config.globalChatEnabled !== false && (
|
||||
<div className="space-y-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowAdvanced(!showAdvanced)}
|
||||
className="flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<span>{t('advanced')}</span>
|
||||
<ChevronDown
|
||||
className={`h-4 w-4 transition-transform ${showAdvanced ? 'rotate-180' : ''}`}
|
||||
/>
|
||||
</button>
|
||||
|
||||
{showAdvanced && (
|
||||
<div className="space-y-3">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label className="text-sm font-medium">{t('globalChatSystemPrompt')}</Label>
|
||||
{isChatSystemPromptModified && (
|
||||
<div className="h-2 w-2 rounded-full bg-yellow-500" title={t('modified')} />
|
||||
)}
|
||||
</div>
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="chat-system-prompt" className="border rounded-lg">
|
||||
<AccordionTrigger className="px-3 py-2 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<Edit className="h-3.5 w-3.5" />
|
||||
<span className="text-sm">{t('globalChatSystemPrompt')}</span>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-3 pb-3">
|
||||
<div className="space-y-2">
|
||||
<Textarea
|
||||
placeholder="Enter system prompt..."
|
||||
value={chatSystemPromptInput}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setChatSystemPromptInput(value);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
globalChatSystemPrompt: value,
|
||||
}));
|
||||
}}
|
||||
className="font-mono text-xs min-h-[150px]"
|
||||
/>
|
||||
{isChatSystemPromptModified && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={restoreChatSystemPrompt}
|
||||
className="w-full"
|
||||
>
|
||||
<RotateCcw className="h-3.5 w-3.5 mr-2" />
|
||||
{t('restoreToDefault')}
|
||||
</Button>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('globalChatSystemPromptDescription')}
|
||||
</p>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Settings, ArrowLeft, RefreshCw, Trash2, XCircle, Loader2, RotateCcw, Cog, Globe, Image, Code, Monitor, Award, Bug, FolderTree, Terminal as TerminalIcon } from "lucide-react";
|
||||
import { Settings, ArrowLeft, RefreshCw, Trash2, XCircle, Loader2, RotateCcw, Cog, Globe, Image, Code, Monitor, Award, Bug, FolderTree, Terminal as TerminalIcon, MessageCircle } from "lucide-react";
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
|
||||
import { useIsMobile } from "@/hooks/useIsMobile";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
@@ -13,6 +14,11 @@ import { useOffline } from "@/hooks/useOffline";
|
||||
import { useToast } from "@/hooks/useToast";
|
||||
import { Terminal } from "@/components/Terminal";
|
||||
|
||||
// Default system prompt for global chat
|
||||
const DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT = `You are a helpful AI assistant. You're here to have a friendly conversation and help answer questions on any topic.
|
||||
|
||||
Keep your responses concise but informative. Be friendly and conversational.`;
|
||||
|
||||
export function SystemSettings() {
|
||||
const { t } = useTranslation();
|
||||
const isMobile = useIsMobile();
|
||||
@@ -32,6 +38,9 @@ export function SystemSettings() {
|
||||
const [fsPathPluginsInput, setFsPathPluginsInput] = useState(config.fsPathPlugins);
|
||||
const [fsPathTemplatesInput, setFsPathTemplatesInput] = useState(config.fsPathTemplates);
|
||||
const [sentryDsnInput, setSentryDsnInput] = useState(config.sentryDsn);
|
||||
const [chatSystemPromptInput, setChatSystemPromptInput] = useState(
|
||||
config.globalChatSystemPrompt || DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT
|
||||
);
|
||||
|
||||
// Check which settings differ from defaults
|
||||
const isModified = useMemo(() => ({
|
||||
@@ -47,6 +56,7 @@ export function SystemSettings() {
|
||||
fsPathPlugins: config.fsPathPlugins !== defaultConfig.fsPathPlugins,
|
||||
fsPathTemplates: config.fsPathTemplates !== defaultConfig.fsPathTemplates,
|
||||
sentryDsn: config.sentryDsn !== defaultConfig.sentryDsn,
|
||||
globalChatSystemPrompt: (config.globalChatSystemPrompt || DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT) !== DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT,
|
||||
}), [config, defaultConfig]);
|
||||
|
||||
// Restore functions - clear the value from config to use the default
|
||||
@@ -156,6 +166,14 @@ export function SystemSettings() {
|
||||
});
|
||||
};
|
||||
|
||||
const restoreChatSystemPrompt = () => {
|
||||
setChatSystemPromptInput(DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT);
|
||||
updateConfig((current) => {
|
||||
const { globalChatSystemPrompt, ...rest } = current;
|
||||
return rest;
|
||||
});
|
||||
};
|
||||
|
||||
// Service Worker state
|
||||
const [swState, setSwState] = useState<string>('');
|
||||
const [isUpdatingSW, setIsUpdatingSW] = useState(false);
|
||||
@@ -952,6 +970,52 @@ export function SystemSettings() {
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* Chat System Prompt Configuration */}
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="chat-system-prompt">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<MessageCircle className="h-4 w-4 text-muted-foreground" />
|
||||
<h4 className="text-sm font-medium">{t('globalChatSystemPrompt')}</h4>
|
||||
{isModified.globalChatSystemPrompt && (
|
||||
<div className="h-2 w-2 rounded-full bg-yellow-500" title={t('modified')} />
|
||||
)}
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="py-1 space-y-2">
|
||||
<Textarea
|
||||
placeholder="Enter system prompt..."
|
||||
value={chatSystemPromptInput}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setChatSystemPromptInput(value);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
globalChatSystemPrompt: value,
|
||||
}));
|
||||
}}
|
||||
className="font-mono text-xs min-h-[150px]"
|
||||
/>
|
||||
{isModified.globalChatSystemPrompt && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={restoreChatSystemPrompt}
|
||||
className="w-full"
|
||||
>
|
||||
<RotateCcw className="h-4 w-4 mr-2" />
|
||||
{t('restoreToDefault')}
|
||||
</Button>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('globalChatSystemPromptDescription')}
|
||||
</p>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* Terminal */}
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="terminal">
|
||||
|
||||
Reference in new issue
Block a user