mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +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
@@ -5,11 +5,11 @@ import { useAppContext } from '@/hooks/useAppContext';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
export function FloatingChatButton() {
|
||||
const { isOpen, setIsOpen, isPoppedOut, hasUnread } = useGlobalChat();
|
||||
const { isOpen, setIsOpen, hasUnread } = useGlobalChat();
|
||||
const { config } = useAppContext();
|
||||
|
||||
// Don't render if disabled in settings or if popped out
|
||||
if (config.globalChatEnabled === false || isPoppedOut) {
|
||||
// Don't render if disabled in settings
|
||||
if (config.globalChatEnabled === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, useRef, useEffect, useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { X, Minimize2, ExternalLink, Trash2, Copy, Check, ChevronDown, ArrowUp, Square, Loader2 } from 'lucide-react';
|
||||
import { X, Minimize2, Trash2, Copy, Check, ChevronDown, ArrowUp, Square, Loader2 } from 'lucide-react';
|
||||
import { Streamdown } from 'streamdown';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
@@ -89,24 +89,24 @@ export function GlobalChatPane() {
|
||||
stopGeneration,
|
||||
clearMessages,
|
||||
setIsOpen,
|
||||
setIsPoppedOut,
|
||||
providerModel,
|
||||
setProviderModel,
|
||||
} = useGlobalChat();
|
||||
const { config } = useAppContext();
|
||||
const { settings, addRecentlyUsedModel } = useAISettings();
|
||||
const { settings } = useAISettings();
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
const [input, setInput] = useState('');
|
||||
const [providerModel, setProviderModel] = useState(() => settings.recentlyUsedModels?.[0] || '');
|
||||
const [showScrollToBottom, setShowScrollToBottom] = useState(false);
|
||||
const scrollAreaRef = useRef<HTMLDivElement>(null);
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
// Sync provider model with settings
|
||||
// Initialize provider model from settings if not set
|
||||
useEffect(() => {
|
||||
if (!providerModel && settings.recentlyUsedModels?.length) {
|
||||
setProviderModel(settings.recentlyUsedModels[0]);
|
||||
}
|
||||
}, [providerModel, settings.recentlyUsedModels]);
|
||||
}, [providerModel, settings.recentlyUsedModels, setProviderModel]);
|
||||
|
||||
// Auto-scroll to bottom when new messages arrive
|
||||
useEffect(() => {
|
||||
@@ -141,12 +141,11 @@ export function GlobalChatPane() {
|
||||
const messageContent = input.trim();
|
||||
setInput('');
|
||||
|
||||
addRecentlyUsedModel(providerModel);
|
||||
await sendMessage(messageContent, providerModel);
|
||||
|
||||
// Focus back on textarea
|
||||
textareaRef.current?.focus();
|
||||
}, [input, isLoading, providerModel, addRecentlyUsedModel, sendMessage]);
|
||||
}, [input, isLoading, providerModel, sendMessage]);
|
||||
|
||||
const handleKeyDown = useCallback((e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey && !isMobile) {
|
||||
@@ -155,65 +154,6 @@ export function GlobalChatPane() {
|
||||
}
|
||||
}, [handleSend, isMobile]);
|
||||
|
||||
const handlePopOut = useCallback(() => {
|
||||
// Open in a new window
|
||||
const width = 400;
|
||||
const height = 600;
|
||||
const left = window.screen.width - width - 50;
|
||||
const top = 50;
|
||||
|
||||
const popoutWindow = window.open(
|
||||
'',
|
||||
'shakespeare-global-chat',
|
||||
`width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`
|
||||
);
|
||||
|
||||
if (popoutWindow) {
|
||||
// Copy styles and render chat in new window
|
||||
popoutWindow.document.write(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Shakespeare Chat</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: system-ui, sans-serif;
|
||||
background: #1a1a1a;
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
}
|
||||
.message {
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="message">
|
||||
<p>Chat window opened!</p>
|
||||
<p>Return to the main Shakespeare window to continue chatting.</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
|
||||
setIsPoppedOut(true);
|
||||
setIsOpen(false);
|
||||
|
||||
// Handle window close
|
||||
const checkClosed = setInterval(() => {
|
||||
if (popoutWindow.closed) {
|
||||
setIsPoppedOut(false);
|
||||
clearInterval(checkClosed);
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
}, [setIsPoppedOut, setIsOpen]);
|
||||
|
||||
// Don't render if disabled or not open
|
||||
if (config.globalChatEnabled === false || !isOpen) {
|
||||
return null;
|
||||
@@ -365,19 +305,6 @@ export function GlobalChatPane() {
|
||||
<TooltipContent>{t('clearChat')}</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={handlePopOut}
|
||||
>
|
||||
<ExternalLink className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{t('popOutChat')}</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
|
||||
@@ -4,6 +4,7 @@ import { GlobalChatContext, type GlobalChatMessage } from '@/contexts/GlobalChat
|
||||
import { useAISettings } from '@/hooks/useAISettings';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||
import { parseProviderModel } from '@/lib/parseProviderModel';
|
||||
import { createAIClient } from '@/lib/ai-client';
|
||||
|
||||
@@ -24,11 +25,13 @@ export function GlobalChatProvider({ children }: GlobalChatProviderProps) {
|
||||
const [messages, setMessages] = useState<GlobalChatMessage[]>([]);
|
||||
const [isOpen, setIsOpenInternal] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isPoppedOut, setIsPoppedOut] = useState(false);
|
||||
const [hasUnread, setHasUnread] = useState(false);
|
||||
const abortControllerRef = useRef<AbortController | null>(null);
|
||||
const isOpenRef = useRef(false);
|
||||
|
||||
// Separate model storage for global chat (independent from project chat)
|
||||
const [globalChatModel, setGlobalChatModel] = useLocalStorage<string>('shakespeare-global-chat-model', '');
|
||||
|
||||
const { settings } = useAISettings();
|
||||
const { config } = useAppContext();
|
||||
const { user } = useCurrentUser();
|
||||
@@ -194,13 +197,13 @@ export function GlobalChatProvider({ children }: GlobalChatProviderProps) {
|
||||
messages,
|
||||
isOpen,
|
||||
isLoading,
|
||||
isPoppedOut,
|
||||
hasUnread,
|
||||
providerModel: globalChatModel,
|
||||
setProviderModel: setGlobalChatModel,
|
||||
sendMessage,
|
||||
stopGeneration,
|
||||
clearMessages,
|
||||
setIsOpen,
|
||||
setIsPoppedOut,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -11,13 +11,13 @@ export interface GlobalChatContextType {
|
||||
messages: GlobalChatMessage[];
|
||||
isOpen: boolean;
|
||||
isLoading: boolean;
|
||||
isPoppedOut: boolean;
|
||||
hasUnread: boolean;
|
||||
providerModel: string;
|
||||
setProviderModel: (model: string) => void;
|
||||
sendMessage: (content: string, providerModel: string) => Promise<void>;
|
||||
stopGeneration: () => void;
|
||||
clearMessages: () => void;
|
||||
setIsOpen: (open: boolean) => void;
|
||||
setIsPoppedOut: (poppedOut: boolean) => void;
|
||||
}
|
||||
|
||||
export const GlobalChatContext = createContext<GlobalChatContextType | undefined>(undefined);
|
||||
@@ -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