mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
029f3f6c58 | ||
|
|
1f685296de | ||
|
|
e0accea7ab |
+33
-156
@@ -4,8 +4,6 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||||
import { useAIProjectId } from '@/hooks/useAIProjectId';
|
import { useAIProjectId } from '@/hooks/useAIProjectId';
|
||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
|
||||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
|
||||||
import { useAISettings } from '@/hooks/useAISettings';
|
import { useAISettings } from '@/hooks/useAISettings';
|
||||||
import { useAppContext } from '@/hooks/useAppContext';
|
import { useAppContext } from '@/hooks/useAppContext';
|
||||||
import { AppLayout } from '@/components/AppLayout';
|
import { AppLayout } from '@/components/AppLayout';
|
||||||
@@ -16,11 +14,7 @@ import { Quilly } from '@/components/Quilly';
|
|||||||
import { DotAI } from '@/lib/DotAI';
|
import { DotAI } from '@/lib/DotAI';
|
||||||
import type { AIMessage } from '@/lib/SessionManager';
|
import type { AIMessage } from '@/lib/SessionManager';
|
||||||
import { buildMessageContent } from '@/lib/buildMessageContent';
|
import { buildMessageContent } from '@/lib/buildMessageContent';
|
||||||
import { Button } from '@/components/ui/button';
|
import { ChatInput } from '@/components/Shakespeare/ChatInput';
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
|
||||||
import { ModelSelector } from '@/components/ModelSelector';
|
|
||||||
import { FileAttachment } from '@/components/ui/file-attachment';
|
|
||||||
import { ArrowUp } from 'lucide-react';
|
|
||||||
import { useSeoMeta } from '@unhead/react';
|
import { useSeoMeta } from '@unhead/react';
|
||||||
import { ShakespeareLogo } from '@/components/ShakespeareLogo';
|
import { ShakespeareLogo } from '@/components/ShakespeareLogo';
|
||||||
import { AppShowcase } from '@/components/AppShowcase';
|
import { AppShowcase } from '@/components/AppShowcase';
|
||||||
@@ -29,9 +23,7 @@ import { useToast } from '@/hooks/useToast';
|
|||||||
export default function Index() {
|
export default function Index() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const [prompt, setPrompt] = useState('');
|
|
||||||
const [isCreating, setIsCreating] = useState(false);
|
const [isCreating, setIsCreating] = useState(false);
|
||||||
const [storedPrompt, setStoredPrompt] = useLocalStorage('shakespeare-draft-prompt', '');
|
|
||||||
const [showOnboarding, setShowOnboarding] = useState(false);
|
const [showOnboarding, setShowOnboarding] = useState(false);
|
||||||
const [showAct1Dialog, setShowAct1Dialog] = useState(false);
|
const [showAct1Dialog, setShowAct1Dialog] = useState(false);
|
||||||
const [showGiftCardDialog, setShowGiftCardDialog] = useState(false);
|
const [showGiftCardDialog, setShowGiftCardDialog] = useState(false);
|
||||||
@@ -48,10 +40,9 @@ export default function Index() {
|
|||||||
// Initialize with first recently used model if available, otherwise empty
|
// Initialize with first recently used model if available, otherwise empty
|
||||||
return settings.recentlyUsedModels?.[0] || '';
|
return settings.recentlyUsedModels?.[0] || '';
|
||||||
});
|
});
|
||||||
const isMobile = useIsMobile();
|
|
||||||
const [attachedFiles, setAttachedFiles] = useState<File[]>([]);
|
|
||||||
const [isDragOver, setIsDragOver] = useState(false);
|
const [isDragOver, setIsDragOver] = useState(false);
|
||||||
const [quillyError, setQuillyError] = useState<Error | null>(null);
|
const [quillyError, setQuillyError] = useState<Error | null>(null);
|
||||||
|
const [isModelSelectorOpen, setIsModelSelectorOpen] = useState(false);
|
||||||
|
|
||||||
// Check if any providers are configured
|
// Check if any providers are configured
|
||||||
const hasProvidersConfigured = settings.providers.length > 0;
|
const hasProvidersConfigured = settings.providers.length > 0;
|
||||||
@@ -67,12 +58,6 @@ export default function Index() {
|
|||||||
description: 'Build custom apps with AI assistance using Shakespeare, an AI-powered development environment.',
|
description: 'Build custom apps with AI assistance using Shakespeare, an AI-powered development environment.',
|
||||||
});
|
});
|
||||||
|
|
||||||
// Restore prompt from local storage on mount
|
|
||||||
useEffect(() => {
|
|
||||||
if (storedPrompt) {
|
|
||||||
setPrompt(storedPrompt);
|
|
||||||
}
|
|
||||||
}, [storedPrompt]);
|
|
||||||
|
|
||||||
// Check for Act 1 users and show welcome dialog
|
// Check for Act 1 users and show welcome dialog
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -106,21 +91,6 @@ export default function Index() {
|
|||||||
}
|
}
|
||||||
}, [location, navigate]);
|
}, [location, navigate]);
|
||||||
|
|
||||||
// Sync prompt with local storage
|
|
||||||
const handlePromptChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
||||||
const newPrompt = e.target.value;
|
|
||||||
setPrompt(newPrompt);
|
|
||||||
setStoredPrompt(newPrompt);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFileSelect = (file: File) => {
|
|
||||||
setAttachedFiles(prev => [...prev, file]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFileRemove = (fileToRemove: File) => {
|
|
||||||
setAttachedFiles(prev => prev.filter(file => file !== fileToRemove));
|
|
||||||
};
|
|
||||||
|
|
||||||
// Drag and drop handlers
|
// Drag and drop handlers
|
||||||
const handleDragEnter = (e: React.DragEvent) => {
|
const handleDragEnter = (e: React.DragEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -154,41 +124,10 @@ export default function Index() {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
setIsDragOver(false);
|
setIsDragOver(false);
|
||||||
|
|
||||||
if (isCreating || isGeneratingId || !providerModel.trim()) return;
|
|
||||||
|
|
||||||
const files = Array.from(e.dataTransfer.files);
|
|
||||||
if (files.length === 0) return;
|
|
||||||
|
|
||||||
// Add all files without validation
|
|
||||||
setAttachedFiles(prev => [...prev, ...files]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle keyboard shortcuts (physical keyboards only)
|
// Handle textarea focus - show onboarding if no providers configured
|
||||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
const handleTextareaFocus = () => {
|
||||||
if (e.key === 'Enter') {
|
|
||||||
// On mobile devices, always allow Enter to create new lines
|
|
||||||
// since there's no Shift key available for multi-line input
|
|
||||||
if (isMobile) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.shiftKey) {
|
|
||||||
// Shift+Enter on desktop: Allow new line (default behavior)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enter without Shift on desktop: Submit only if no newlines exist in prompt and model is selected
|
|
||||||
if (!prompt.includes('\n') && providerModel.trim()) {
|
|
||||||
e.preventDefault();
|
|
||||||
handleCreateProject();
|
|
||||||
}
|
|
||||||
// If prompt contains newlines or no model selected, allow Enter to create new line (default behavior)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Handle textarea click - show onboarding if no providers configured
|
|
||||||
const handleTextareaClick = () => {
|
|
||||||
if (!hasProvidersConfigured) {
|
if (!hasProvidersConfigured) {
|
||||||
setShowOnboarding(true);
|
setShowOnboarding(true);
|
||||||
}
|
}
|
||||||
@@ -200,10 +139,7 @@ export default function Index() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleQuillyNewChat = () => {
|
const handleQuillyNewChat = () => {
|
||||||
// Clear current prompt and start fresh
|
// Clear error - ChatInput manages its own state
|
||||||
setPrompt('');
|
|
||||||
setStoredPrompt('');
|
|
||||||
setAttachedFiles([]);
|
|
||||||
setQuillyError(null);
|
setQuillyError(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -215,23 +151,21 @@ export default function Index() {
|
|||||||
setQuillyError(null);
|
setQuillyError(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCreateProject = async () => {
|
const handleSend = async (input: string, files: File[]) => {
|
||||||
if (!prompt.trim() || !providerModel.trim()) return;
|
if (!input.trim() && files.length === 0) return;
|
||||||
|
if (!providerModel.trim()) return;
|
||||||
// Clear stored prompt when creating project
|
|
||||||
setStoredPrompt('');
|
|
||||||
|
|
||||||
setIsCreating(true);
|
setIsCreating(true);
|
||||||
try {
|
try {
|
||||||
// Use AI to generate project ID
|
// Use AI to generate project ID
|
||||||
const projectId = await generateProjectId(providerModel, prompt.trim());
|
const projectId = await generateProjectId(providerModel, input.trim());
|
||||||
|
|
||||||
// Add model to recently used when creating project with AI
|
// Add model to recently used when creating project with AI
|
||||||
addRecentlyUsedModel(providerModel.trim());
|
addRecentlyUsedModel(providerModel.trim());
|
||||||
|
|
||||||
// Create project with AI-generated ID and handle template update errors
|
// Create project with AI-generated ID and handle template update errors
|
||||||
const project = await projectsManager.createProject(
|
const project = await projectsManager.createProject(
|
||||||
prompt.trim(),
|
input.trim(),
|
||||||
config.projectTemplate,
|
config.projectTemplate,
|
||||||
projectId,
|
projectId,
|
||||||
() => {
|
() => {
|
||||||
@@ -247,8 +181,8 @@ export default function Index() {
|
|||||||
// Build message content from input and attached files
|
// Build message content from input and attached files
|
||||||
// Images are converted to base64-encoded data URLs
|
// Images are converted to base64-encoded data URLs
|
||||||
const messageContent = await buildMessageContent(
|
const messageContent = await buildMessageContent(
|
||||||
prompt.trim(),
|
input.trim(),
|
||||||
attachedFiles,
|
files,
|
||||||
fs,
|
fs,
|
||||||
undefined
|
undefined
|
||||||
);
|
);
|
||||||
@@ -263,9 +197,6 @@ export default function Index() {
|
|||||||
};
|
};
|
||||||
await dotAI.setHistory(sessionName, [initialMessage]);
|
await dotAI.setHistory(sessionName, [initialMessage]);
|
||||||
|
|
||||||
// Clear attached files after successful creation
|
|
||||||
setAttachedFiles([]);
|
|
||||||
|
|
||||||
// Navigate to the project with autostart parameter and model
|
// Navigate to the project with autostart parameter and model
|
||||||
const searchParams = new URLSearchParams({
|
const searchParams = new URLSearchParams({
|
||||||
autostart: 'true',
|
autostart: 'true',
|
||||||
@@ -289,7 +220,7 @@ export default function Index() {
|
|||||||
<div className="max-w-4xl mx-auto">
|
<div className="max-w-4xl mx-auto">
|
||||||
<div className="text-center mb-8 md:mb-12">
|
<div className="text-center mb-8 md:mb-12">
|
||||||
<div className="mb-4 md:mb-6">
|
<div className="mb-4 md:mb-6">
|
||||||
<ShakespeareLogo className="w-20 h-20 md:w-24 md:h-24 mx-auto" />
|
<ShakespeareLogo className={`w-20 h-20 md:w-24 md:h-24 mx-auto transition-transform duration-300 ${isCreating || isGeneratingId ? 'animate-spin' : ''}`} />
|
||||||
</div>
|
</div>
|
||||||
<h1 className="text-3xl md:text-4xl font-bold mb-3 md:mb-4 bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">
|
<h1 className="text-3xl md:text-4xl font-bold mb-3 md:mb-4 bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">
|
||||||
{t('buildNostrApps')}
|
{t('buildNostrApps')}
|
||||||
@@ -313,84 +244,30 @@ export default function Index() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Chat Input Container - matching the ChatPane style */}
|
{/* Chat Input */}
|
||||||
<div
|
<ChatInput
|
||||||
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' : ''
|
isLoading={isCreating || isGeneratingId}
|
||||||
}`}
|
isConfigured={hasProvidersConfigured}
|
||||||
|
providerModel={providerModel}
|
||||||
|
onProviderModelChange={setProviderModel}
|
||||||
|
onSend={handleSend}
|
||||||
|
onStop={() => {
|
||||||
|
// No-op for Index page - project creation can't be stopped
|
||||||
|
}}
|
||||||
|
onFocus={handleTextareaFocus}
|
||||||
|
onFirstInteraction={() => {
|
||||||
|
// No-op for Index page
|
||||||
|
}}
|
||||||
|
isModelSelectorOpen={isModelSelectorOpen}
|
||||||
|
onModelSelectorOpenChange={setIsModelSelectorOpen}
|
||||||
|
contextUsagePercentage={0}
|
||||||
|
totalCost={0}
|
||||||
|
isDragOver={isDragOver}
|
||||||
onDragEnter={handleDragEnter}
|
onDragEnter={handleDragEnter}
|
||||||
onDragOver={handleDragOver}
|
onDragOver={handleDragOver}
|
||||||
onDragLeave={handleDragLeave}
|
onDragLeave={handleDragLeave}
|
||||||
onDrop={handleDrop}
|
onDrop={handleDrop}
|
||||||
>
|
/>
|
||||||
<Textarea
|
|
||||||
placeholder={
|
|
||||||
!hasProvidersConfigured
|
|
||||||
? t('examplePrompt')
|
|
||||||
: !providerModel.trim()
|
|
||||||
? t('selectModelToDescribe')
|
|
||||||
: t('examplePrompt')
|
|
||||||
}
|
|
||||||
value={prompt}
|
|
||||||
onChange={handlePromptChange}
|
|
||||||
onKeyDown={handleKeyDown}
|
|
||||||
onClick={handleTextareaClick}
|
|
||||||
className="min-h-[120px] max-h-64 resize-none border-0 bg-transparent px-4 py-3 pb-16 text-sm focus-visible:ring-0 focus-visible:ring-offset-0 placeholder:text-muted-foreground"
|
|
||||||
disabled={isCreating || isGeneratingId || (hasProvidersConfigured && !providerModel.trim())}
|
|
||||||
rows={4}
|
|
||||||
style={{
|
|
||||||
height: 'auto',
|
|
||||||
minHeight: '120px'
|
|
||||||
}}
|
|
||||||
onInput={(e) => {
|
|
||||||
const target = e.target as HTMLTextAreaElement;
|
|
||||||
target.style.height = 'auto';
|
|
||||||
target.style.height = Math.min(target.scrollHeight, 256) + 'px';
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Bottom Controls Row */}
|
|
||||||
<div className="absolute bottom-3 left-3 right-3 flex items-center justify-end gap-4 overflow-hidden">
|
|
||||||
{/* File Attachment */}
|
|
||||||
<FileAttachment
|
|
||||||
className="mr-auto"
|
|
||||||
onFileSelect={handleFileSelect}
|
|
||||||
onFileRemove={handleFileRemove}
|
|
||||||
selectedFiles={attachedFiles}
|
|
||||||
disabled={isCreating || isGeneratingId}
|
|
||||||
multiple={true}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Model Selector - always show to allow configuration */}
|
|
||||||
<div className="overflow-hidden">
|
|
||||||
<ModelSelector
|
|
||||||
value={providerModel}
|
|
||||||
onChange={setProviderModel}
|
|
||||||
className="w-full"
|
|
||||||
disabled={isCreating || isGeneratingId}
|
|
||||||
placeholder={t('chooseModel')}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Create Project Button */}
|
|
||||||
<Button
|
|
||||||
onClick={handleCreateProject}
|
|
||||||
disabled={
|
|
||||||
!prompt.trim() ||
|
|
||||||
isCreating ||
|
|
||||||
isGeneratingId ||
|
|
||||||
(hasProvidersConfigured && !providerModel.trim())
|
|
||||||
}
|
|
||||||
size="sm"
|
|
||||||
className="size-8 [&_svg]:size-5 rounded-full p-0"
|
|
||||||
>
|
|
||||||
{isCreating || isGeneratingId ? (
|
|
||||||
<div className="animate-spin rounded-full h-3 w-3 border-b-2 border-white" />
|
|
||||||
) : (
|
|
||||||
<ArrowUp />
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user