diff --git a/src/App.tsx b/src/App.tsx
index a85f19c1..c8c4dd06 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -28,6 +28,9 @@ import { DynamicFavicon } from '@/components/DynamicFavicon';
import { OfflineIndicator } from '@/components/OfflineIndicator';
import { PWAUpdatePrompt } from '@/components/PWAUpdatePrompt';
import { ErrorBoundary } from '@/components/ErrorBoundary';
+import { GlobalChatProvider } from '@/components/GlobalChatProvider';
+import { FloatingChatButton } from '@/components/FloatingChatButton';
+import { GlobalChatPane } from '@/components/GlobalChatPane';
import AppRouter from './AppRouter';
@@ -177,15 +180,19 @@ export function App() {
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/FloatingChatButton.tsx b/src/components/FloatingChatButton.tsx
new file mode 100644
index 00000000..84610143
--- /dev/null
+++ b/src/components/FloatingChatButton.tsx
@@ -0,0 +1,38 @@
+import { MessageCircle } from 'lucide-react';
+import { Button } from '@/components/ui/button';
+import { useGlobalChat } from '@/hooks/useGlobalChat';
+import { useAppContext } from '@/hooks/useAppContext';
+import { cn } from '@/lib/utils';
+
+export function FloatingChatButton() {
+ const { isOpen, setIsOpen, isPoppedOut, messages } = useGlobalChat();
+ const { config } = useAppContext();
+
+ // Don't render if disabled in settings or if popped out
+ if (config.globalChatEnabled === false || isPoppedOut) {
+ return null;
+ }
+
+ return (
+
+ );
+}
diff --git a/src/components/GlobalChatPane.tsx b/src/components/GlobalChatPane.tsx
new file mode 100644
index 00000000..94d85956
--- /dev/null
+++ b/src/components/GlobalChatPane.tsx
@@ -0,0 +1,483 @@
+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 { Streamdown } from 'streamdown';
+import { Button } from '@/components/ui/button';
+import { Textarea } from '@/components/ui/textarea';
+import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
+import { ModelSelector } from '@/components/ModelSelector';
+import { useGlobalChat } from '@/hooks/useGlobalChat';
+import { useAppContext } from '@/hooks/useAppContext';
+import { useAISettings } from '@/hooks/useAISettings';
+import { useIsMobile } from '@/hooks/useIsMobile';
+import { useTheme } from '@/hooks/useTheme';
+import { cn } from '@/lib/utils';
+import type { GlobalChatMessage } from '@/contexts/GlobalChatContext';
+
+// Message component with copy functionality
+function ChatMessage({ message }: { message: GlobalChatMessage }) {
+ const [copied, setCopied] = useState(false);
+ const { displayTheme } = useTheme();
+ const isUser = message.role === 'user';
+
+ const handleCopy = useCallback(async () => {
+ try {
+ await navigator.clipboard.writeText(message.content);
+ setCopied(true);
+ setTimeout(() => setCopied(false), 2000);
+ } catch (error) {
+ console.error('Failed to copy:', error);
+ }
+ }, [message.content]);
+
+ return (
+
+
+ {isUser ? (
+
{message.content}
+ ) : (
+
+
+ {message.content || '...'}
+
+
+ )}
+
+ {/* Copy button - shows on hover */}
+
+
+
+ );
+}
+
+export function GlobalChatPane() {
+ const { t } = useTranslation();
+ const {
+ messages,
+ isOpen,
+ isLoading,
+ sendMessage,
+ stopGeneration,
+ clearMessages,
+ setIsOpen,
+ setIsPoppedOut,
+ } = useGlobalChat();
+ const { config } = useAppContext();
+ const { settings, addRecentlyUsedModel } = useAISettings();
+ const isMobile = useIsMobile();
+
+ const [input, setInput] = useState('');
+ const [providerModel, setProviderModel] = useState(() => settings.recentlyUsedModels?.[0] || '');
+ const [showScrollToBottom, setShowScrollToBottom] = useState(false);
+ const scrollAreaRef = useRef(null);
+ const textareaRef = useRef(null);
+
+ // Sync provider model with settings
+ useEffect(() => {
+ if (!providerModel && settings.recentlyUsedModels?.length) {
+ setProviderModel(settings.recentlyUsedModels[0]);
+ }
+ }, [providerModel, settings.recentlyUsedModels]);
+
+ // Auto-scroll to bottom when new messages arrive
+ useEffect(() => {
+ if (scrollAreaRef.current) {
+ const container = scrollAreaRef.current;
+ const isNearBottom = container.scrollTop + container.clientHeight >= container.scrollHeight - 100;
+
+ if (isNearBottom || messages.length <= 1) {
+ container.scrollTop = container.scrollHeight;
+ }
+ }
+ }, [messages]);
+
+ // Handle scroll to show/hide scroll-to-bottom button
+ const handleScroll = useCallback(() => {
+ if (scrollAreaRef.current) {
+ const container = scrollAreaRef.current;
+ const isNearBottom = container.scrollTop + container.clientHeight >= container.scrollHeight - 100;
+ setShowScrollToBottom(!isNearBottom && messages.length > 0);
+ }
+ }, [messages.length]);
+
+ const scrollToBottom = useCallback(() => {
+ if (scrollAreaRef.current) {
+ scrollAreaRef.current.scrollTop = scrollAreaRef.current.scrollHeight;
+ }
+ }, []);
+
+ const handleSend = useCallback(async () => {
+ if (!input.trim() || isLoading || !providerModel) return;
+
+ const messageContent = input.trim();
+ setInput('');
+
+ addRecentlyUsedModel(providerModel);
+ await sendMessage(messageContent, providerModel);
+
+ // Focus back on textarea
+ textareaRef.current?.focus();
+ }, [input, isLoading, providerModel, addRecentlyUsedModel, sendMessage]);
+
+ const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
+ if (e.key === 'Enter' && !e.shiftKey && !isMobile) {
+ e.preventDefault();
+ handleSend();
+ }
+ }, [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(`
+
+
+
+ Shakespeare Chat
+
+
+
+
+
Chat window opened!
+
Return to the main Shakespeare window to continue chatting.
+
+
+
+ `);
+
+ 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;
+ }
+
+ const hasProviders = settings.providers.length > 0;
+
+ // Mobile: Full screen drawer from bottom
+ if (isMobile) {
+ return (
+
+ {/* Header */}
+
+
{t('globalChat')}
+
+ {messages.length > 0 && (
+
+
+
+
+ {t('clearChat')}
+
+ )}
+
+
+
+
+ {/* Messages */}
+
+ {messages.length === 0 ? (
+
+
+
{t('globalChatWelcome')}
+
{t('globalChatDescription')}
+
+
+ ) : (
+ messages.map((message) => (
+
+ ))
+ )}
+
+ {isLoading && messages[messages.length - 1]?.role !== 'assistant' && (
+
+ )}
+
+
+ {/* Scroll to bottom button */}
+ {showScrollToBottom && (
+
+ )}
+
+ {/* Input */}
+
+
+ );
+ }
+
+ // Desktop: Floating panel
+ return (
+
+ {/* Header */}
+
+
{t('globalChat')}
+
+ {messages.length > 0 && (
+
+
+
+
+ {t('clearChat')}
+
+ )}
+
+
+
+
+ {t('popOutChat')}
+
+
+
+
+
+ {t('minimizeChat')}
+
+
+
+
+ {/* Messages */}
+
+ {messages.length === 0 ? (
+
+
+
{t('globalChatWelcome')}
+
{t('globalChatDescription')}
+
+
+ ) : (
+ messages.map((message) => (
+
+ ))
+ )}
+
+ {isLoading && messages[messages.length - 1]?.role !== 'assistant' && (
+
+ )}
+
+
+ {/* Scroll to bottom button */}
+ {showScrollToBottom && (
+
+
+
+ )}
+
+ {/* Input */}
+
+
+ );
+}
diff --git a/src/components/GlobalChatProvider.tsx b/src/components/GlobalChatProvider.tsx
new file mode 100644
index 00000000..81bb6b85
--- /dev/null
+++ b/src/components/GlobalChatProvider.tsx
@@ -0,0 +1,192 @@
+import { useState, useCallback, useRef, type ReactNode } from 'react';
+import OpenAI from 'openai';
+import { GlobalChatContext, type GlobalChatMessage } from '@/contexts/GlobalChatContext';
+import { useAISettings } from '@/hooks/useAISettings';
+import { useAppContext } from '@/hooks/useAppContext';
+import { useCurrentUser } from '@/hooks/useCurrentUser';
+import { parseProviderModel } from '@/lib/parseProviderModel';
+import { createAIClient } from '@/lib/ai-client';
+
+// Maximum context size in characters (approximately 50k tokens worth)
+// This leaves room for the system prompt and response
+const MAX_CONTEXT_CHARS = 150000;
+
+// 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.`;
+
+interface GlobalChatProviderProps {
+ children: ReactNode;
+}
+
+export function GlobalChatProvider({ children }: GlobalChatProviderProps) {
+ const [messages, setMessages] = useState([]);
+ const [isOpen, setIsOpen] = useState(false);
+ const [isLoading, setIsLoading] = useState(false);
+ const [isPoppedOut, setIsPoppedOut] = useState(false);
+ const abortControllerRef = useRef(null);
+
+ const { settings } = useAISettings();
+ const { config } = useAppContext();
+ const { user } = useCurrentUser();
+
+ // Trim messages from the top when context gets too long
+ const trimMessages = useCallback((msgs: GlobalChatMessage[]): GlobalChatMessage[] => {
+ let totalChars = msgs.reduce((sum, msg) => sum + msg.content.length, 0);
+
+ if (totalChars <= MAX_CONTEXT_CHARS) {
+ return msgs;
+ }
+
+ // Remove messages from the beginning until we're under the limit
+ const trimmedMessages = [...msgs];
+ while (trimmedMessages.length > 1 && totalChars > MAX_CONTEXT_CHARS) {
+ const removed = trimmedMessages.shift();
+ if (removed) {
+ totalChars -= removed.content.length;
+ }
+ }
+
+ return trimmedMessages;
+ }, []);
+
+ const sendMessage = useCallback(async (content: string, providerModel: string) => {
+ if (!content.trim() || isLoading) return;
+
+ // Parse provider and model
+ const { providerId, modelId } = parseProviderModel(providerModel);
+ const provider = settings.providers.find(p => p.id === providerId);
+
+ if (!provider) {
+ console.error('Provider not found:', providerId);
+ return;
+ }
+
+ // Create user message
+ const userMessage: GlobalChatMessage = {
+ id: crypto.randomUUID(),
+ role: 'user',
+ content: content.trim(),
+ timestamp: Date.now(),
+ };
+
+ // Add user message and trim if necessary
+ setMessages(prev => trimMessages([...prev, userMessage]));
+ setIsLoading(true);
+
+ // Create abort controller for this request
+ abortControllerRef.current = new AbortController();
+
+ try {
+ // Create AI client
+ const client = createAIClient(provider, config.corsProxy, user?.signer);
+
+ // Build messages for API
+ const systemPrompt = config.globalChatSystemPrompt || DEFAULT_GLOBAL_CHAT_SYSTEM_PROMPT;
+
+ const apiMessages: OpenAI.Chat.Completions.ChatCompletionMessageParam[] = [
+ { role: 'system', content: systemPrompt },
+ ...messages.map(msg => ({
+ role: msg.role as 'user' | 'assistant',
+ content: msg.content,
+ })),
+ { role: 'user', content: content.trim() },
+ ];
+
+ // Create assistant message placeholder
+ const assistantMessage: GlobalChatMessage = {
+ id: crypto.randomUUID(),
+ role: 'assistant',
+ content: '',
+ timestamp: Date.now(),
+ };
+
+ setMessages(prev => [...prev, assistantMessage]);
+
+ // Stream the response
+ const stream = await client.chat.completions.create({
+ model: modelId,
+ messages: apiMessages,
+ stream: true,
+ }, {
+ signal: abortControllerRef.current.signal,
+ });
+
+ let fullContent = '';
+
+ for await (const chunk of stream) {
+ const delta = chunk.choices[0]?.delta?.content || '';
+ fullContent += delta;
+
+ // Update the assistant message with streamed content
+ setMessages(prev => {
+ const updated = [...prev];
+ const lastMessage = updated[updated.length - 1];
+ if (lastMessage && lastMessage.role === 'assistant') {
+ lastMessage.content = fullContent;
+ }
+ return updated;
+ });
+ }
+
+ // Final trim after response is complete
+ setMessages(prev => trimMessages(prev));
+
+ } catch (error) {
+ if (error instanceof Error && error.name === 'AbortError') {
+ // User stopped generation, keep partial response
+ return;
+ }
+
+ console.error('Global chat error:', error);
+
+ // Add error message
+ const errorMessage: GlobalChatMessage = {
+ id: crypto.randomUUID(),
+ role: 'assistant',
+ content: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
+ timestamp: Date.now(),
+ };
+
+ setMessages(prev => {
+ // Remove empty assistant message if exists
+ const filtered = prev.filter(m => m.role !== 'assistant' || m.content.trim());
+ return [...filtered, errorMessage];
+ });
+ } finally {
+ setIsLoading(false);
+ abortControllerRef.current = null;
+ }
+ }, [config.corsProxy, config.globalChatSystemPrompt, isLoading, messages, settings.providers, trimMessages, user?.signer]);
+
+ const stopGeneration = useCallback(() => {
+ if (abortControllerRef.current) {
+ abortControllerRef.current.abort();
+ abortControllerRef.current = null;
+ setIsLoading(false);
+ }
+ }, []);
+
+ const clearMessages = useCallback(() => {
+ setMessages([]);
+ }, []);
+
+ return (
+
+ {children}
+
+ );
+}
diff --git a/src/contexts/AppContext.ts b/src/contexts/AppContext.ts
index 68ad6c78..a3bbb78b 100644
--- a/src/contexts/AppContext.ts
+++ b/src/contexts/AppContext.ts
@@ -57,6 +57,10 @@ export interface AppConfig {
sentryEnabled: boolean;
/** System prompt EJS template */
systemPrompt?: string;
+ /** Whether the global floating chat is enabled */
+ globalChatEnabled?: boolean;
+ /** Custom system prompt for global chat */
+ globalChatSystemPrompt?: string;
}
export interface AppContextType {
diff --git a/src/contexts/GlobalChatContext.ts b/src/contexts/GlobalChatContext.ts
new file mode 100644
index 00000000..d93b25fd
--- /dev/null
+++ b/src/contexts/GlobalChatContext.ts
@@ -0,0 +1,22 @@
+import { createContext } from 'react';
+
+export interface GlobalChatMessage {
+ id: string;
+ role: 'user' | 'assistant';
+ content: string;
+ timestamp: number;
+}
+
+export interface GlobalChatContextType {
+ messages: GlobalChatMessage[];
+ isOpen: boolean;
+ isLoading: boolean;
+ isPoppedOut: boolean;
+ sendMessage: (content: string, providerModel: string) => Promise;
+ stopGeneration: () => void;
+ clearMessages: () => void;
+ setIsOpen: (open: boolean) => void;
+ setIsPoppedOut: (poppedOut: boolean) => void;
+}
+
+export const GlobalChatContext = createContext(undefined);
diff --git a/src/hooks/useGlobalChat.ts b/src/hooks/useGlobalChat.ts
new file mode 100644
index 00000000..d8f7b4d1
--- /dev/null
+++ b/src/hooks/useGlobalChat.ts
@@ -0,0 +1,10 @@
+import { useContext } from 'react';
+import { GlobalChatContext, type GlobalChatContextType } from '@/contexts/GlobalChatContext';
+
+export function useGlobalChat(): GlobalChatContextType {
+ const context = useContext(GlobalChatContext);
+ if (!context) {
+ throw new Error('useGlobalChat must be used within a GlobalChatProvider');
+ }
+ return context;
+}
diff --git a/src/locales/en.json b/src/locales/en.json
index 3de166bf..784edce5 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -524,5 +524,17 @@
"templateDeleted": "Template Deleted",
"templateDeletedDescription": "Project template '{{name}}' has been deleted.",
"noTemplatesConfigured": "No project templates configured yet. Add a template to get started.",
- "atLeastOneTemplateRequired": "At least one template is required"
+ "atLeastOneTemplateRequired": "At least one template is required",
+ "globalChat": "Chat",
+ "globalChatWelcome": "Hi there! 👋",
+ "globalChatDescription": "Ask me anything. I'm here to help with questions, ideas, and conversation.",
+ "clearChat": "Clear chat",
+ "popOutChat": "Pop out",
+ "minimizeChat": "Minimize",
+ "typeMessage": "Type a message...",
+ "configureAIFirst": "Configure AI provider first",
+ "globalChatEnabled": "Floating Chat Button",
+ "globalChatEnabledDescription": "Show a floating chat button for quick AI conversations",
+ "globalChatSystemPrompt": "Chat System Prompt",
+ "globalChatSystemPromptDescription": "Custom system prompt for the floating chat assistant"
}
diff --git a/src/locales/ha.json b/src/locales/ha.json
index 0e1f8494..87eff953 100644
--- a/src/locales/ha.json
+++ b/src/locales/ha.json
@@ -431,5 +431,17 @@
"modified": "An Canza",
"restoreToDefault": "Mayar da asali",
"restoredToDefault": "An Mayar da Asali",
- "terminal": "Terminal"
+ "terminal": "Terminal",
+ "globalChat": "Tattaunawa",
+ "globalChatWelcome": "Sannu! 👋",
+ "globalChatDescription": "Tambayi komai. Ina nan don taimaka da tambayoyi, ra'ayoyi, da tattaunawa.",
+ "clearChat": "Share tattaunawa",
+ "popOutChat": "Fitar da waje",
+ "minimizeChat": "Ragewa",
+ "typeMessage": "Rubuta sako...",
+ "configureAIFirst": "Da fari ka saita mai ba da AI",
+ "globalChatEnabled": "Maballin Tattaunawa Mai Yawo",
+ "globalChatEnabledDescription": "Nuna maballin tattaunawa mai yawo don saurin tattaunawa da AI",
+ "globalChatSystemPrompt": "Jagorar Tsarin Tattaunawa",
+ "globalChatSystemPromptDescription": "Jagorar tsarin da aka keɓe don mataimakin tattaunawa mai yawo"
}
diff --git a/src/locales/ig.json b/src/locales/ig.json
index bb561264..5bba5af2 100644
--- a/src/locales/ig.json
+++ b/src/locales/ig.json
@@ -428,5 +428,17 @@
"modified": "Gbanwere",
"restoreToDefault": "Weghachi na nke mbụ",
"restoredToDefault": "Weghachiri na Nke Mbụ",
- "terminal": "Terminal"
+ "terminal": "Terminal",
+ "globalChat": "Nkata",
+ "globalChatWelcome": "Ndewo! 👋",
+ "globalChatDescription": "Jụọ ihe ọ bụla. Anọ m ebe a inyere gị aka na ajụjụ, echiche, na nkata.",
+ "clearChat": "Kpochapụ nkata",
+ "popOutChat": "Wepụta",
+ "minimizeChat": "Belata",
+ "typeMessage": "Dee ozi...",
+ "configureAIFirst": "Bụrụ ụzọ hazie onye na-enye AI",
+ "globalChatEnabled": "Bọtịnụ Nkata Na-epupụta",
+ "globalChatEnabledDescription": "Gosi bọtịnụ nkata na-epupụta maka nkata AI ngwa ngwa",
+ "globalChatSystemPrompt": "Usoro Nkata",
+ "globalChatSystemPromptDescription": "Usoro nke gị maka onye enyemaka nkata na-epupụta"
}
diff --git a/src/locales/pt.json b/src/locales/pt.json
index 0e178635..a12b8444 100644
--- a/src/locales/pt.json
+++ b/src/locales/pt.json
@@ -440,5 +440,17 @@
"modified": "Modificado",
"restoreToDefault": "Restaurar para padrão",
"restoredToDefault": "Restaurado para Padrão",
- "terminal": "Terminal"
+ "terminal": "Terminal",
+ "globalChat": "Chat",
+ "globalChatWelcome": "Olá! 👋",
+ "globalChatDescription": "Pergunte-me qualquer coisa. Estou aqui para ajudar com perguntas, ideias e conversas.",
+ "clearChat": "Limpar chat",
+ "popOutChat": "Destacar",
+ "minimizeChat": "Minimizar",
+ "typeMessage": "Digite uma mensagem...",
+ "configureAIFirst": "Configure o provedor de IA primeiro",
+ "globalChatEnabled": "Botão de Chat Flutuante",
+ "globalChatEnabledDescription": "Mostrar um botão de chat flutuante para conversas rápidas com IA",
+ "globalChatSystemPrompt": "Prompt do Sistema do Chat",
+ "globalChatSystemPromptDescription": "Prompt do sistema personalizado para o assistente de chat flutuante"
}
diff --git a/src/locales/yo.json b/src/locales/yo.json
index 9941194d..8bd093d0 100644
--- a/src/locales/yo.json
+++ b/src/locales/yo.json
@@ -428,5 +428,17 @@
"modified": "Ti Yipada",
"restoreToDefault": "Pada si atilẹwa",
"restoredToDefault": "Ti Pada si Atilẹwa",
- "terminal": "Terminal"
+ "terminal": "Terminal",
+ "globalChat": "Ibanisọrọ",
+ "globalChatWelcome": "Pẹlẹ o! 👋",
+ "globalChatDescription": "Beere ohunkohun. Mo wa nibi lati ran ọ lọwọ pẹlu awọn ibeere, awọn ero, ati ibaraẹnisọrọ.",
+ "clearChat": "Pa ibanisọrọ rẹ",
+ "popOutChat": "Ya jade",
+ "minimizeChat": "Din ku",
+ "typeMessage": "Tẹ ifiranṣẹ...",
+ "configureAIFirst": "Ṣeto olupese AI ni akọkọ",
+ "globalChatEnabled": "Bọtini Ibanisọrọ Ti O N Lọ",
+ "globalChatEnabledDescription": "Fi bọtini ibanisọrọ ti o n lọ han fun ibaraẹnisọrọ AI ni iyara",
+ "globalChatSystemPrompt": "Itọsọna Eto Ibanisọrọ",
+ "globalChatSystemPromptDescription": "Itọsọna eto aṣa fun oluranlọwọ ibanisọrọ ti o n lọ"
}
diff --git a/src/locales/zh.json b/src/locales/zh.json
index 6977a6ed..0704d49f 100644
--- a/src/locales/zh.json
+++ b/src/locales/zh.json
@@ -440,5 +440,17 @@
"modified": "已修改",
"restoreToDefault": "恢复默认值",
"restoredToDefault": "已恢复默认值",
- "terminal": "终端"
+ "terminal": "终端",
+ "globalChat": "聊天",
+ "globalChatWelcome": "你好! 👋",
+ "globalChatDescription": "随便问我什么。我在这里帮助回答问题、提供想法和进行对话。",
+ "clearChat": "清除聊天",
+ "popOutChat": "弹出窗口",
+ "minimizeChat": "最小化",
+ "typeMessage": "输入消息...",
+ "configureAIFirst": "请先配置AI提供商",
+ "globalChatEnabled": "浮动聊天按钮",
+ "globalChatEnabledDescription": "显示浮动聊天按钮以便快速AI对话",
+ "globalChatSystemPrompt": "聊天系统提示",
+ "globalChatSystemPromptDescription": "浮动聊天助手的自定义系统提示"
}
diff --git a/src/pages/Preferences.tsx b/src/pages/Preferences.tsx
index 7e4935fb..313889df 100644
--- a/src/pages/Preferences.tsx
+++ b/src/pages/Preferences.tsx
@@ -1,4 +1,5 @@
-import { Settings2, ArrowLeft } from "lucide-react";
+import { useState, useMemo } from "react";
+import { Settings2, ArrowLeft, ChevronDown, Edit, RotateCcw } from "lucide-react";
import { useTranslation } from 'react-i18next';
import { Button } from "@/components/ui/button";
import { Card, CardContent } from "@/components/ui/card";
@@ -6,15 +7,40 @@ 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, updateConfig } = useAppContext();
+ 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;
+ });
+ };
return (
@@ -98,6 +124,102 @@ export function Preferences() {
{t('shareErrorReportsDescription')}
+
+
+
+ {/* Global Chat Settings */}
+
+
+
+
+
+
{
+ updateConfig((current) => ({
+ ...current,
+ globalChatEnabled: checked,
+ }));
+ }}
+ />
+
+
+ {t('globalChatEnabledDescription')}
+
+
+
+ {/* Advanced Global Chat Settings */}
+ {config.globalChatEnabled !== false && (
+
+
+
+ {showAdvanced && (
+
+
+
+
+ {isChatSystemPromptModified && (
+
+ )}
+
+
+
+
+
+
+ {t('globalChatSystemPrompt')}
+
+
+
+
+
+
+
+
+
+ )}
+
+ )}