mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Add Quilly to the homepage
This commit is contained in:
4 files changed
+56
-60
No files matched your search
+37
-46
@@ -7,12 +7,11 @@ import { useFS } from '@/hooks/useFS';
|
||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useAISettings } from '@/hooks/useAISettings';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { AppLayout } from '@/components/AppLayout';
|
||||
import { OnboardingDialog } from '@/components/OnboardingDialog';
|
||||
import { Act1Dialog } from '@/components/Act1Dialog';
|
||||
import { Quilly } from '@/components/Quilly';
|
||||
import { DotAI } from '@/lib/DotAI';
|
||||
import { parseProviderModel } from '@/lib/parseProviderModel';
|
||||
import type { AIMessage } from '@/lib/SessionManager';
|
||||
import { saveFileToTmp } from '@/lib/fileUtils';
|
||||
import type OpenAI from 'openai';
|
||||
@@ -20,7 +19,6 @@ import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { ModelSelector } from '@/components/ModelSelector';
|
||||
import { FileAttachment } from '@/components/ui/file-attachment';
|
||||
import { ToastAction } from '@/components/ui/toast';
|
||||
import { Plus } from 'lucide-react';
|
||||
import { useSeoMeta } from '@unhead/react';
|
||||
|
||||
@@ -36,7 +34,6 @@ export default function Index() {
|
||||
const { fs } = useFS();
|
||||
const { generateProjectId, isLoading: isGeneratingId } = useAIProjectId();
|
||||
const { settings, addRecentlyUsedModel } = useAISettings();
|
||||
const { toast } = useToast();
|
||||
const [providerModel, setProviderModel] = useState(() => {
|
||||
// Initialize with first recently used model if available, otherwise empty
|
||||
return settings.recentlyUsedModels?.[0] || '';
|
||||
@@ -44,45 +41,11 @@ export default function Index() {
|
||||
const isMobile = useIsMobile();
|
||||
const [attachedFiles, setAttachedFiles] = useState<File[]>([]);
|
||||
const [isDragOver, setIsDragOver] = useState(false);
|
||||
const [quillyError, setQuillyError] = useState<Error | null>(null);
|
||||
|
||||
// Check if any providers are configured
|
||||
const hasProvidersConfigured = settings.providers.length > 0;
|
||||
|
||||
// Check for API key failures and show appropriate toast
|
||||
const checkForKeyFailure = (error: unknown): boolean => {
|
||||
// Check for authentication errors
|
||||
// Note: useAIProjectId re-throws OpenAI errors as generic Error objects
|
||||
const isAuthError = error instanceof Error && error.message === '401 No auth credentials found';
|
||||
|
||||
if (isAuthError) {
|
||||
// Get provider name inline
|
||||
let providerName = 'Provider';
|
||||
try {
|
||||
const { provider } = parseProviderModel(providerModel, settings.providers);
|
||||
providerName = provider.id.charAt(0).toUpperCase() + provider.id.slice(1);
|
||||
} catch {
|
||||
// Keep default 'Provider'
|
||||
}
|
||||
|
||||
toast({
|
||||
title: t('apiAuthenticationFailed'),
|
||||
description: t('invalidApiKey', { provider: providerName }),
|
||||
variant: 'destructive',
|
||||
action: (
|
||||
<ToastAction
|
||||
altText={t('checkApiKeySettings')}
|
||||
onClick={() => navigate('/settings/ai')}
|
||||
>
|
||||
{t('checkApiKeySettings')}
|
||||
</ToastAction>
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
return isAuthError;
|
||||
};
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (!providerModel && settings.recentlyUsedModels?.length) {
|
||||
setProviderModel(settings.recentlyUsedModels[0]);
|
||||
@@ -196,6 +159,27 @@ export default function Index() {
|
||||
}
|
||||
};
|
||||
|
||||
// Quilly handlers
|
||||
const handleQuillyDismiss = () => {
|
||||
setQuillyError(null);
|
||||
};
|
||||
|
||||
const handleQuillyNewChat = () => {
|
||||
// Clear current prompt and start fresh
|
||||
setPrompt('');
|
||||
setStoredPrompt('');
|
||||
setAttachedFiles([]);
|
||||
setQuillyError(null);
|
||||
};
|
||||
|
||||
const handleQuillyOpenModelSelector = () => {
|
||||
// Focus on model selector or open AI settings if no providers
|
||||
if (!hasProvidersConfigured) {
|
||||
setShowOnboarding(true);
|
||||
}
|
||||
setQuillyError(null);
|
||||
};
|
||||
|
||||
const handleCreateProject = async () => {
|
||||
if (!prompt.trim() || !providerModel.trim()) return;
|
||||
|
||||
@@ -270,13 +254,7 @@ export default function Index() {
|
||||
navigate(`/project/${project.id}?${searchParams.toString()}`);
|
||||
} catch (error) {
|
||||
console.error('Failed to create project:', error);
|
||||
if (!checkForKeyFailure(error)) {
|
||||
toast({
|
||||
title: "Project Creation Failed",
|
||||
description: error instanceof Error ? error.message : "An unexpected error occurred",
|
||||
variant: "destructive",
|
||||
});
|
||||
}
|
||||
setQuillyError(error instanceof Error ? error : new Error("An unexpected error occurred"));
|
||||
} finally {
|
||||
setIsCreating(false);
|
||||
}
|
||||
@@ -299,6 +277,19 @@ export default function Index() {
|
||||
</div>
|
||||
|
||||
<div className="mb-8 md:mb-12">
|
||||
{/* Quilly Helper - shows when there are errors */}
|
||||
{quillyError && (
|
||||
<div className="mb-4">
|
||||
<Quilly
|
||||
error={quillyError}
|
||||
onDismiss={handleQuillyDismiss}
|
||||
onNewChat={handleQuillyNewChat}
|
||||
onOpenModelSelector={handleQuillyOpenModelSelector}
|
||||
providerModel={providerModel}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Chat Input Container - matching the ChatPane style */}
|
||||
<div
|
||||
className={`relative rounded-2xl border border-input bg-background shadow-sm focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 transition-all ${isDragOver ? 'border-primary bg-primary/5 ring-2 ring-primary/20' : ''
|
||||
|
||||
Reference in new issue
Block a user