mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Shakespeare
This commit is contained in:
14 files changed
+2405
-8
No files matched your search
+5
-1
@@ -4,13 +4,17 @@ import { ScrollToTop } from "./components/ScrollToTop";
|
||||
import Index from "./pages/Index";
|
||||
import { NIP19Page } from "./pages/NIP19Page";
|
||||
import NotFound from "./pages/NotFound";
|
||||
import { ShakespeareHome } from "./pages/ShakespeareHome";
|
||||
import { ProjectView } from "./pages/ProjectView";
|
||||
|
||||
export function AppRouter() {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<ScrollToTop />
|
||||
<Routes>
|
||||
<Route path="/" element={<Index />} />
|
||||
<Route path="/" element={<ShakespeareHome />} />
|
||||
<Route path="/project/:projectId" element={<ProjectView />} />
|
||||
<Route path="/legacy" element={<Index />} />
|
||||
{/* NIP-19 route for npub1, note1, naddr1, nevent1, nprofile1 */}
|
||||
<Route path="/:nip19" element={<NIP19Page />} />
|
||||
{/* ADD ALL CUSTOM ROUTES ABOVE THE CATCH-ALL "*" ROUTE */}
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
import { useState, useRef, useEffect } from 'react';
|
||||
import { createAIChat } from '@/lib/ai-chat';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { Send, Bot, User } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface Message {
|
||||
id: string;
|
||||
role: 'user' | 'assistant';
|
||||
content: string;
|
||||
timestamp: Date;
|
||||
toolCalls?: any[];
|
||||
}
|
||||
|
||||
interface ChatPaneProps {
|
||||
projectId: string;
|
||||
projectName: string;
|
||||
}
|
||||
|
||||
export function ChatPane({ projectId, projectName }: ChatPaneProps) {
|
||||
const [messages, setMessages] = useState<Message[]>([]);
|
||||
const [input, setInput] = useState('');
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const scrollAreaRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
// Add welcome message
|
||||
setMessages([
|
||||
{
|
||||
id: 'welcome',
|
||||
role: 'assistant',
|
||||
content: `Hello! I'm here to help you build "${projectName}". I can help you edit files, add new features, and build your Nostr website. What would you like to work on?`,
|
||||
timestamp: new Date(),
|
||||
},
|
||||
]);
|
||||
}, [projectName]);
|
||||
|
||||
useEffect(() => {
|
||||
if (scrollAreaRef.current) {
|
||||
scrollAreaRef.current.scrollTop = scrollAreaRef.current.scrollHeight;
|
||||
}
|
||||
}, [messages]);
|
||||
|
||||
const handleSend = async () => {
|
||||
if (!input.trim() || isLoading) return;
|
||||
|
||||
const userMessage: Message = {
|
||||
id: Date.now().toString(),
|
||||
role: 'user',
|
||||
content: input,
|
||||
timestamp: new Date(),
|
||||
};
|
||||
|
||||
setMessages((prev) => [...prev, userMessage]);
|
||||
setInput('');
|
||||
setIsLoading(true);
|
||||
|
||||
try {
|
||||
const aiMessages = [
|
||||
...messages.map((msg) => ({
|
||||
role: msg.role,
|
||||
content: msg.content,
|
||||
})),
|
||||
{ role: 'user' as const, content: input },
|
||||
];
|
||||
|
||||
const result = await createAIChat(projectId, aiMessages);
|
||||
|
||||
let assistantContent = '';
|
||||
const toolCalls: any[] = [];
|
||||
|
||||
for await (const part of result.fullStream) {
|
||||
if (part.type === 'text-delta') {
|
||||
assistantContent += part.textDelta;
|
||||
} else if (part.type === 'tool-call') {
|
||||
toolCalls.push(part);
|
||||
} else if (part.type === 'tool-result') {
|
||||
// Handle tool results if needed
|
||||
}
|
||||
}
|
||||
|
||||
const assistantMessage: Message = {
|
||||
id: (Date.now() + 1).toString(),
|
||||
role: 'assistant',
|
||||
content: assistantContent || 'I completed the requested changes.',
|
||||
timestamp: new Date(),
|
||||
toolCalls,
|
||||
};
|
||||
|
||||
setMessages((prev) => [...prev, assistantMessage]);
|
||||
} catch (error) {
|
||||
console.error('AI chat error:', error);
|
||||
const errorMessage: Message = {
|
||||
id: (Date.now() + 1).toString(),
|
||||
role: 'assistant',
|
||||
content: 'Sorry, I encountered an error. Please try again.',
|
||||
timestamp: new Date(),
|
||||
};
|
||||
setMessages((prev) => [...prev, errorMessage]);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
handleSend();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-col">
|
||||
<div className="border-b px-4 py-3">
|
||||
<h2 className="font-semibold">AI Assistant</h2>
|
||||
<p className="text-sm text-muted-foreground">Chat to build your project</p>
|
||||
</div>
|
||||
|
||||
<ScrollArea className="flex-1 p-4" ref={scrollAreaRef}>
|
||||
<div className="space-y-4">
|
||||
{messages.map((message) => (
|
||||
<div
|
||||
key={message.id}
|
||||
className={cn(
|
||||
'flex gap-3',
|
||||
message.role === 'user' ? 'justify-end' : 'justify-start'
|
||||
)}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
'flex gap-2 max-w-[80%]',
|
||||
message.role === 'user' ? 'flex-row-reverse' : 'flex-row'
|
||||
)}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
'w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0',
|
||||
message.role === 'user'
|
||||
? 'bg-primary text-primary-foreground'
|
||||
: 'bg-muted'
|
||||
)}
|
||||
>
|
||||
{message.role === 'user' ? (
|
||||
<User className="h-4 w-4" />
|
||||
) : (
|
||||
<Bot className="h-4 w-4" />
|
||||
)}
|
||||
</div>
|
||||
<Card
|
||||
className={cn(
|
||||
'px-4 py-2',
|
||||
message.role === 'user'
|
||||
? 'bg-primary text-primary-foreground'
|
||||
: 'bg-muted'
|
||||
)}
|
||||
>
|
||||
<div className="whitespace-pre-wrap text-sm">
|
||||
{message.content}
|
||||
</div>
|
||||
{message.toolCalls && message.toolCalls.length > 0 && (
|
||||
<div className="mt-2 text-xs opacity-75">
|
||||
Used {message.toolCalls.length} tool{message.toolCalls.length !== 1 ? 's' : ''}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{isLoading && (
|
||||
<div className="flex gap-2">
|
||||
<div className="w-8 h-8 rounded-full bg-muted flex items-center justify-center flex-shrink-0">
|
||||
<Bot className="h-4 w-4" />
|
||||
</div>
|
||||
<Card className="px-4 py-2 bg-muted">
|
||||
<div className="flex space-x-1">
|
||||
<div className="h-2 w-2 bg-current rounded-full animate-bounce [animation-delay:-0.3s]"></div>
|
||||
<div className="h-2 w-2 bg-current rounded-full animate-bounce [animation-delay:-0.15s]"></div>
|
||||
<div className="h-2 w-2 bg-current rounded-full animate-bounce"></div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
<div className="border-t p-4">
|
||||
<div className="flex gap-2">
|
||||
<Textarea
|
||||
value={input}
|
||||
onChange={(e) => setInput(e.target.value)}
|
||||
onKeyDown={handleKeyDown}
|
||||
placeholder="Ask me to add features, edit files, or build your project..."
|
||||
className="min-h-[60px] resize-none"
|
||||
disabled={isLoading}
|
||||
/>
|
||||
<Button
|
||||
onClick={handleSend}
|
||||
disabled={!input.trim() || isLoading}
|
||||
className="self-end"
|
||||
size="icon"
|
||||
>
|
||||
<Send className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Save, Loader2 } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface FileEditorProps {
|
||||
filePath: string;
|
||||
content: string;
|
||||
onSave: (content: string) => void;
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
export function FileEditor({ filePath, content, onSave, isLoading }: FileEditorProps) {
|
||||
const [editedContent, setEditedContent] = useState(content);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [hasChanges, setHasChanges] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setEditedContent(content);
|
||||
setHasChanges(false);
|
||||
}, [content, filePath]);
|
||||
|
||||
useEffect(() => {
|
||||
setHasChanges(editedContent !== content);
|
||||
}, [editedContent, content]);
|
||||
|
||||
const handleSave = async () => {
|
||||
setIsSaving(true);
|
||||
try {
|
||||
await onSave(editedContent);
|
||||
setHasChanges(false);
|
||||
} catch (error) {
|
||||
console.error('Failed to save file:', error);
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const getLanguageFromPath = (path: string): string => {
|
||||
const extension = path.split('.').pop()?.toLowerCase();
|
||||
const languageMap: Record<string, string> = {
|
||||
js: 'javascript',
|
||||
jsx: 'javascript',
|
||||
ts: 'typescript',
|
||||
tsx: 'typescript',
|
||||
html: 'html',
|
||||
css: 'css',
|
||||
json: 'json',
|
||||
md: 'markdown',
|
||||
py: 'python',
|
||||
java: 'java',
|
||||
cpp: 'cpp',
|
||||
c: 'c',
|
||||
sh: 'bash',
|
||||
yml: 'yaml',
|
||||
yaml: 'yaml',
|
||||
};
|
||||
return languageMap[extension || ''] || 'text';
|
||||
};
|
||||
|
||||
const getMonospaceFont = () => {
|
||||
return 'font-mono text-sm';
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-col">
|
||||
<CardHeader className="border-b py-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle className="text-base">{filePath}</CardTitle>
|
||||
<div className="flex items-center space-x-2">
|
||||
{hasChanges && (
|
||||
<span className="text-sm text-muted-foreground">Unsaved changes</span>
|
||||
)}
|
||||
<Button
|
||||
onClick={handleSave}
|
||||
disabled={!hasChanges || isSaving || isLoading}
|
||||
size="sm"
|
||||
>
|
||||
{isSaving ? (
|
||||
<>
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
Saving...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Save className="mr-2 h-4 w-4" />
|
||||
Save
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-xs text-muted-foreground mt-1">
|
||||
Language: {getLanguageFromPath(filePath)}
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="flex-1 p-0">
|
||||
{isLoading ? (
|
||||
<div className="flex items-center justify-center h-full">
|
||||
<div className="animate-spin rounded-full h-6 w-6 border-b-2 border-primary"></div>
|
||||
</div>
|
||||
) : (
|
||||
<Textarea
|
||||
value={editedContent}
|
||||
onChange={(e) => setEditedContent(e.target.value)}
|
||||
className={cn(
|
||||
'w-full h-full resize-none border-0 rounded-none',
|
||||
'focus:outline-none focus:ring-0',
|
||||
getMonospaceFont()
|
||||
)}
|
||||
placeholder={`// Edit ${filePath}...`}
|
||||
spellCheck={false}
|
||||
/>
|
||||
)}
|
||||
</CardContent>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { fsManager } from '@/lib/fs';
|
||||
import { ChevronRight, ChevronDown, File, Folder } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface FileTreeProps {
|
||||
projectId: string;
|
||||
onFileSelect: (filePath: string) => void;
|
||||
selectedFile: string | null;
|
||||
}
|
||||
|
||||
interface FileNode {
|
||||
name: string;
|
||||
path: string;
|
||||
type: 'file' | 'directory';
|
||||
children?: FileNode[];
|
||||
isOpen?: boolean;
|
||||
}
|
||||
|
||||
export function FileTree({ projectId, onFileSelect, selectedFile }: FileTreeProps) {
|
||||
const [tree, setTree] = useState<FileNode[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
loadFileTree();
|
||||
}, [projectId]);
|
||||
|
||||
const loadFileTree = async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const structure = await buildFileTree(projectId, '');
|
||||
setTree(structure);
|
||||
} catch (error) {
|
||||
console.error('Failed to load file tree:', error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const buildFileTree = async (projectId: string, dirPath: string): Promise<FileNode[]> => {
|
||||
const items = await fsManager.listFiles(projectId, dirPath);
|
||||
const nodes: FileNode[] = [];
|
||||
|
||||
for (const item of items) {
|
||||
const itemPath = dirPath ? `${dirPath}/${item}` : item;
|
||||
const fullPath = `${fsManager['dir']}/${projectId}/${itemPath}`;
|
||||
|
||||
try {
|
||||
const stat = await fsManager['fs'].promises.stat(fullPath);
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
const children = await buildFileTree(projectId, itemPath);
|
||||
nodes.push({
|
||||
name: item,
|
||||
path: itemPath,
|
||||
type: 'directory',
|
||||
children,
|
||||
isOpen: false,
|
||||
});
|
||||
} else {
|
||||
nodes.push({
|
||||
name: item,
|
||||
path: itemPath,
|
||||
type: 'file',
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
// Skip inaccessible items
|
||||
}
|
||||
}
|
||||
|
||||
return nodes.sort((a, b) => {
|
||||
if (a.type !== b.type) {
|
||||
return a.type === 'directory' ? -1 : 1;
|
||||
}
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
};
|
||||
|
||||
const toggleDirectory = (path: string) => {
|
||||
const toggleNode = (nodes: FileNode[]): FileNode[] => {
|
||||
return nodes.map(node => {
|
||||
if (node.path === path && node.type === 'directory') {
|
||||
return { ...node, isOpen: !node.isOpen };
|
||||
}
|
||||
if (node.children) {
|
||||
return { ...node, children: toggleNode(node.children) };
|
||||
}
|
||||
return node;
|
||||
});
|
||||
};
|
||||
|
||||
setTree(prev => toggleNode(prev));
|
||||
};
|
||||
|
||||
const handleFileClick = (filePath: string, type: 'file' | 'directory') => {
|
||||
if (type === 'file') {
|
||||
onFileSelect(filePath);
|
||||
} else {
|
||||
toggleDirectory(filePath);
|
||||
}
|
||||
};
|
||||
|
||||
const renderNode = (node: FileNode, depth: number = 0) => {
|
||||
const isSelected = selectedFile === node.path;
|
||||
|
||||
return (
|
||||
<div key={node.path}>
|
||||
<div
|
||||
className={cn(
|
||||
'flex items-center gap-2 px-2 py-1 cursor-pointer hover:bg-muted rounded',
|
||||
isSelected && 'bg-muted',
|
||||
depth > 0 && 'ml-4'
|
||||
)}
|
||||
onClick={() => handleFileClick(node.path, node.type)}
|
||||
style={{ paddingLeft: `${8 + depth * 16}px` }}
|
||||
>
|
||||
{node.type === 'directory' ? (
|
||||
<>
|
||||
{node.isOpen ? (
|
||||
<ChevronDown className="h-4 w-4 flex-shrink-0" />
|
||||
) : (
|
||||
<ChevronRight className="h-4 w-4 flex-shrink-0" />
|
||||
)}
|
||||
<Folder className="h-4 w-4 text-blue-500 flex-shrink-0" />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="w-4" /> {/* Spacer for alignment */}
|
||||
<File className="h-4 w-4 text-gray-500 flex-shrink-0" />
|
||||
</>
|
||||
)}
|
||||
<span className="text-sm truncate">{node.name}</span>
|
||||
</div>
|
||||
|
||||
{node.type === 'directory' && node.isOpen && node.children && (
|
||||
<div>
|
||||
{node.children.map(child => renderNode(child, depth + 1))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="p-4">
|
||||
<div className="space-y-2">
|
||||
{[...Array(5)].map((_, i) => (
|
||||
<div key={i} className="h-6 bg-muted rounded animate-pulse"></div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-2">
|
||||
{tree.length === 0 ? (
|
||||
<div className="text-center text-sm text-muted-foreground py-8">
|
||||
No files found
|
||||
</div>
|
||||
) : (
|
||||
tree.map(node => renderNode(node))
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { fsManager } from '@/lib/fs';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { FileTree } from './FileTree';
|
||||
import { FileEditor } from './FileEditor';
|
||||
|
||||
interface PreviewPaneProps {
|
||||
projectId: string;
|
||||
activeTab: 'preview' | 'code';
|
||||
}
|
||||
|
||||
export function PreviewPane({ projectId, activeTab }: PreviewPaneProps) {
|
||||
const [selectedFile, setSelectedFile] = useState<string | null>(null);
|
||||
const [fileContent, setFileContent] = useState<string>('');
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedFile) {
|
||||
loadFileContent(selectedFile);
|
||||
}
|
||||
}, [selectedFile, projectId]);
|
||||
|
||||
const loadFileContent = async (filePath: string) => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const content = await fsManager.readFile(projectId, filePath);
|
||||
setFileContent(content);
|
||||
} catch (error) {
|
||||
console.error('Failed to load file:', error);
|
||||
setFileContent('');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleFileSelect = (filePath: string) => {
|
||||
setSelectedFile(filePath);
|
||||
};
|
||||
|
||||
const handleFileSave = async (content: string) => {
|
||||
if (!selectedFile) return;
|
||||
|
||||
try {
|
||||
await fsManager.writeFile(projectId, selectedFile, content);
|
||||
setFileContent(content);
|
||||
} catch (error) {
|
||||
console.error('Failed to save file:', error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="h-full">
|
||||
<Tabs value={activeTab} className="h-full">
|
||||
<TabsContent value="preview" className="h-full mt-0">
|
||||
<div className="h-full flex items-center justify-center bg-muted">
|
||||
<div className="text-center">
|
||||
<h3 className="text-lg font-semibold mb-2">Project Preview</h3>
|
||||
<p className="text-muted-foreground mb-4">
|
||||
Your project will be built and displayed here
|
||||
</p>
|
||||
<div className="bg-background border rounded-lg p-8 max-w-md">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Vite build integration coming soon...
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="code" className="h-full mt-0">
|
||||
<div className="h-full flex">
|
||||
<div className="w-1/3 border-r">
|
||||
<div className="p-4 border-b">
|
||||
<h3 className="font-semibold">File Explorer</h3>
|
||||
</div>
|
||||
<ScrollArea className="h-[calc(100%-60px)]">
|
||||
<FileTree
|
||||
projectId={projectId}
|
||||
onFileSelect={handleFileSelect}
|
||||
selectedFile={selectedFile}
|
||||
/>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
|
||||
<div className="flex-1">
|
||||
{selectedFile ? (
|
||||
<FileEditor
|
||||
filePath={selectedFile}
|
||||
content={fileContent}
|
||||
onSave={handleFileSave}
|
||||
isLoading={isLoading}
|
||||
/>
|
||||
) : (
|
||||
<div className="h-full flex items-center justify-center">
|
||||
<div className="text-center">
|
||||
<p className="text-muted-foreground">
|
||||
Select a file from the explorer to edit
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import { openai } from '@ai-sdk/openai';
|
||||
import { streamText, tool } from 'ai';
|
||||
import { z } from 'zod';
|
||||
import { aiTools } from './ai-tools';
|
||||
|
||||
const fileOperationSchema = z.object({
|
||||
projectId: z.string(),
|
||||
filePath: z.string(),
|
||||
content: z.string().optional(),
|
||||
});
|
||||
|
||||
const buildSchema = z.object({
|
||||
projectId: z.string(),
|
||||
});
|
||||
|
||||
export async function createAIChat(projectId: string, messages: any[]) {
|
||||
const result = await streamText({
|
||||
model: openai('gpt-4-turbo-preview'),
|
||||
messages,
|
||||
tools: {
|
||||
readFile: tool({
|
||||
description: 'Read the contents of a file in the project',
|
||||
parameters: fileOperationSchema,
|
||||
execute: async ({ projectId, filePath }) => {
|
||||
return await aiTools.executeOperation({
|
||||
type: 'read',
|
||||
projectId,
|
||||
filePath,
|
||||
});
|
||||
},
|
||||
}),
|
||||
writeFile: tool({
|
||||
description: 'Write content to a file in the project',
|
||||
parameters: fileOperationSchema,
|
||||
execute: async ({ projectId, filePath, content }) => {
|
||||
return await aiTools.executeOperation({
|
||||
type: 'write',
|
||||
projectId,
|
||||
filePath,
|
||||
content: content || '',
|
||||
});
|
||||
},
|
||||
}),
|
||||
deleteFile: tool({
|
||||
description: 'Delete a file from the project',
|
||||
parameters: fileOperationSchema,
|
||||
execute: async ({ projectId, filePath }) => {
|
||||
return await aiTools.executeOperation({
|
||||
type: 'delete',
|
||||
projectId,
|
||||
filePath,
|
||||
});
|
||||
},
|
||||
}),
|
||||
listFiles: tool({
|
||||
description: 'List files in a directory',
|
||||
parameters: fileOperationSchema,
|
||||
execute: async ({ projectId, filePath }) => {
|
||||
return await aiTools.executeOperation({
|
||||
type: 'list',
|
||||
projectId,
|
||||
filePath,
|
||||
});
|
||||
},
|
||||
}),
|
||||
fileExists: tool({
|
||||
description: 'Check if a file exists',
|
||||
parameters: fileOperationSchema,
|
||||
execute: async ({ projectId, filePath }) => {
|
||||
return await aiTools.executeOperation({
|
||||
type: 'exists',
|
||||
projectId,
|
||||
filePath,
|
||||
});
|
||||
},
|
||||
}),
|
||||
buildProject: tool({
|
||||
description: 'Build the project using Vite',
|
||||
parameters: buildSchema,
|
||||
execute: async ({ projectId }) => {
|
||||
return await aiTools.executeOperation({
|
||||
type: 'build',
|
||||
projectId,
|
||||
});
|
||||
},
|
||||
}),
|
||||
getProjectStructure: tool({
|
||||
description: 'Get the complete file structure of the project',
|
||||
parameters: buildSchema,
|
||||
execute: async ({ projectId }) => {
|
||||
return await aiTools.getProjectStructure(projectId);
|
||||
},
|
||||
}),
|
||||
searchFiles: tool({
|
||||
description: 'Search for files containing specific text',
|
||||
parameters: z.object({
|
||||
projectId: z.string(),
|
||||
query: z.string(),
|
||||
}),
|
||||
execute: async ({ projectId, query }) => {
|
||||
return await aiTools.searchFiles(projectId, query);
|
||||
},
|
||||
}),
|
||||
},
|
||||
system: `You are an AI assistant helping users build custom Nostr websites. You have access to tools that allow you to read, write, and manage files in the project, as well as build the project.
|
||||
|
||||
Key capabilities:
|
||||
- Read and write files in the project
|
||||
- List directory contents
|
||||
- Check if files exist
|
||||
- Build the project using Vite
|
||||
- Get project structure overview
|
||||
- Search through files
|
||||
|
||||
Guidelines:
|
||||
- Always check if files exist before writing to avoid overwriting
|
||||
- Provide helpful explanations of what you're doing
|
||||
- Suggest improvements and best practices
|
||||
- Use modern React patterns and TypeScript
|
||||
- Follow Nostr protocol standards when relevant
|
||||
- Ensure the project builds successfully
|
||||
|
||||
The project uses:
|
||||
- React 18 with TypeScript
|
||||
- Vite for building
|
||||
- TailwindCSS for styling
|
||||
- Nostrify for Nostr integration
|
||||
- shadcn/ui components
|
||||
|
||||
When creating new components or pages, follow the existing patterns in the codebase.`
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
import { fsManager } from './fs';
|
||||
|
||||
export interface FileOperation {
|
||||
type: 'read' | 'write' | 'delete' | 'list' | 'exists';
|
||||
projectId: string;
|
||||
filePath: string;
|
||||
content?: string;
|
||||
}
|
||||
|
||||
export interface BuildOperation {
|
||||
type: 'build';
|
||||
projectId: string;
|
||||
}
|
||||
|
||||
export type AIToolOperation = FileOperation | BuildOperation;
|
||||
|
||||
export class AITools {
|
||||
async executeOperation(operation: AIToolOperation): Promise<any> {
|
||||
try {
|
||||
switch (operation.type) {
|
||||
case 'read':
|
||||
return await this.readFile(operation.projectId, operation.filePath);
|
||||
|
||||
case 'write':
|
||||
if (!operation.content) {
|
||||
throw new Error('Content is required for write operations');
|
||||
}
|
||||
await this.writeFile(operation.projectId, operation.filePath, operation.content);
|
||||
return { success: true, message: 'File written successfully' };
|
||||
|
||||
case 'delete':
|
||||
await this.deleteFile(operation.projectId, operation.filePath);
|
||||
return { success: true, message: 'File deleted successfully' };
|
||||
|
||||
case 'list':
|
||||
return await this.listFiles(operation.projectId, operation.filePath);
|
||||
|
||||
case 'exists':
|
||||
return await this.fileExists(operation.projectId, operation.filePath);
|
||||
|
||||
case 'build':
|
||||
return await this.buildProject(operation.projectId);
|
||||
|
||||
default:
|
||||
throw new Error(`Unknown operation type: ${(operation as any).type}`);
|
||||
}
|
||||
} catch (error) {
|
||||
return { error: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
private async readFile(projectId: string, filePath: string): Promise<string> {
|
||||
return await fsManager.readFile(projectId, filePath);
|
||||
}
|
||||
|
||||
private async writeFile(projectId: string, filePath: string, content: string): Promise<void> {
|
||||
await fsManager.writeFile(projectId, filePath, content);
|
||||
}
|
||||
|
||||
private async deleteFile(projectId: string, filePath: string): Promise<void> {
|
||||
await fsManager.deleteFile(projectId, filePath);
|
||||
}
|
||||
|
||||
private async listFiles(projectId: string, dirPath: string = ''): Promise<string[]> {
|
||||
return await fsManager.listFiles(projectId, dirPath);
|
||||
}
|
||||
|
||||
private async fileExists(projectId: string, filePath: string): Promise<boolean> {
|
||||
return await fsManager.fileExists(projectId, filePath);
|
||||
}
|
||||
|
||||
private async buildProject(projectId: string): Promise<any> {
|
||||
// TODO: Implement Vite build in browser
|
||||
// For now, return a stub
|
||||
return {
|
||||
success: true,
|
||||
message: 'Build started (stub implementation)',
|
||||
url: `/preview/${projectId}`
|
||||
};
|
||||
}
|
||||
|
||||
async getProjectStructure(projectId: string): Promise<any> {
|
||||
const structure: any = {};
|
||||
|
||||
async function buildStructure(currentPath: string, obj: any) {
|
||||
const items = await fsManager.listFiles(projectId, currentPath);
|
||||
|
||||
for (const item of items) {
|
||||
const itemPath = currentPath ? `${currentPath}/${item}` : item;
|
||||
const fullPath = `${fsManager['dir']}/${projectId}/${itemPath}`;
|
||||
|
||||
try {
|
||||
const stat = await fsManager['fs'].promises.stat(fullPath);
|
||||
if (stat.isDirectory()) {
|
||||
obj[item] = {};
|
||||
await buildStructure(itemPath, obj[item]);
|
||||
} else {
|
||||
obj[item] = 'file';
|
||||
}
|
||||
} catch (error) {
|
||||
// Skip inaccessible items
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await buildStructure('', structure);
|
||||
return structure;
|
||||
}
|
||||
|
||||
async searchFiles(projectId: string, query: string): Promise<Array<{path: string, content: string}>> {
|
||||
const results: Array<{path: string, content: string}> = [];
|
||||
|
||||
async function searchDirectory(dirPath: string) {
|
||||
const items = await fsManager.listFiles(projectId, dirPath);
|
||||
|
||||
for (const item of items) {
|
||||
const itemPath = dirPath ? `${dirPath}/${item}` : item;
|
||||
const fullPath = `${fsManager['dir']}/${projectId}/${itemPath}`;
|
||||
|
||||
try {
|
||||
const stat = await fsManager['fs'].promises.stat(fullPath);
|
||||
if (stat.isDirectory()) {
|
||||
await searchDirectory(itemPath);
|
||||
} else {
|
||||
const content = await fsManager.readFile(projectId, itemPath);
|
||||
if (content.toLowerCase().includes(query.toLowerCase())) {
|
||||
results.push({ path: itemPath, content });
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Skip inaccessible files
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await searchDirectory('');
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
export const aiTools = new AITools();
|
||||
+261
@@ -0,0 +1,261 @@
|
||||
import LightningFS from '@isomorphic-git/lightning-fs';
|
||||
import git from 'isomorphic-git';
|
||||
import http from 'isomorphic-git/http/web';
|
||||
import { Buffer } from 'buffer';
|
||||
|
||||
// Polyfill Buffer for browser
|
||||
if (typeof window !== 'undefined') {
|
||||
(window as any).Buffer = Buffer;
|
||||
}
|
||||
|
||||
export interface Project {
|
||||
id: string;
|
||||
name: string;
|
||||
path: string;
|
||||
createdAt: Date;
|
||||
lastModified: Date;
|
||||
}
|
||||
|
||||
export class FileSystemManager {
|
||||
private fs: LightningFS;
|
||||
private dir: string;
|
||||
|
||||
constructor() {
|
||||
this.fs = new LightningFS('shakespeare-fs');
|
||||
this.dir = '/projects';
|
||||
}
|
||||
|
||||
async init() {
|
||||
try {
|
||||
await this.fs.promises.mkdir(this.dir);
|
||||
} catch (error) {
|
||||
// Directory might already exist
|
||||
}
|
||||
}
|
||||
|
||||
async createProject(name: string): Promise<Project> {
|
||||
const id = this.generateProjectId(name);
|
||||
const projectPath = `${this.dir}/${id}`;
|
||||
|
||||
await this.fs.promises.mkdir(projectPath);
|
||||
|
||||
const project: Project = {
|
||||
id,
|
||||
name,
|
||||
path: projectPath,
|
||||
createdAt: new Date(),
|
||||
lastModified: new Date(),
|
||||
};
|
||||
|
||||
// Save project metadata
|
||||
await this.fs.promises.writeFile(
|
||||
`${projectPath}/.project.json`,
|
||||
JSON.stringify(project, null, 2)
|
||||
);
|
||||
|
||||
// Clone the template
|
||||
await this.cloneTemplate(projectPath);
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
async cloneTemplate(projectPath: string) {
|
||||
const templateUrl = 'https://relay.ngit.dev/npub1q3sle0kvfsehgsuexttt3ugjd8xdklxfwwkh559wxckmzddywnws6cd26p/mkstack.git';
|
||||
|
||||
try {
|
||||
await git.clone({
|
||||
fs: this.fs,
|
||||
http,
|
||||
dir: projectPath,
|
||||
url: templateUrl,
|
||||
singleBranch: true,
|
||||
depth: 1,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to clone template:', error);
|
||||
// Create basic structure if clone fails
|
||||
await this.createBasicStructure(projectPath);
|
||||
}
|
||||
}
|
||||
|
||||
async createBasicStructure(projectPath: string) {
|
||||
const files = {
|
||||
'package.json': JSON.stringify({
|
||||
name: 'shakespeare-project',
|
||||
version: '0.1.0',
|
||||
type: 'module',
|
||||
scripts: {
|
||||
dev: 'vite',
|
||||
build: 'vite build',
|
||||
preview: 'vite preview'
|
||||
},
|
||||
dependencies: {
|
||||
react: '^18.2.0',
|
||||
'react-dom': '^18.2.0'
|
||||
},
|
||||
devDependencies: {
|
||||
'@types/react': '^18.2.0',
|
||||
'@types/react-dom': '^18.2.0',
|
||||
'@vitejs/plugin-react': '^4.0.0',
|
||||
vite: '^4.4.0'
|
||||
}
|
||||
}, null, 2),
|
||||
'index.html': `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Shakespeare Project</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
</html>`,
|
||||
'src/main.jsx': `import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App.jsx'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
)`,
|
||||
'src/App.jsx': `import React from 'react'
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
<h1>Welcome to your Shakespeare project!</h1>
|
||||
<p>This is a basic React app template.</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default App`,
|
||||
'vite.config.js': `import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})`
|
||||
};
|
||||
|
||||
for (const [filename, content] of Object.entries(files)) {
|
||||
const filePath = `${projectPath}/${filename}`;
|
||||
const dir = filePath.split('/').slice(0, -1).join('/');
|
||||
try {
|
||||
await this.fs.promises.mkdir(dir);
|
||||
} catch (error) {
|
||||
// Directory might already exist
|
||||
}
|
||||
await this.fs.promises.writeFile(filePath, content);
|
||||
}
|
||||
}
|
||||
|
||||
async getProjects(): Promise<Project[]> {
|
||||
try {
|
||||
const projectDirs = await this.fs.promises.readdir(this.dir);
|
||||
const projects: Project[] = [];
|
||||
|
||||
for (const dir of projectDirs) {
|
||||
const projectPath = `${this.dir}/${dir}`;
|
||||
const projectFile = `${projectPath}/.project.json`;
|
||||
|
||||
try {
|
||||
const projectData = await this.fs.promises.readFile(projectFile, 'utf8');
|
||||
const project = JSON.parse(projectData);
|
||||
projects.push({
|
||||
...project,
|
||||
createdAt: new Date(project.createdAt),
|
||||
lastModified: new Date(project.lastModified),
|
||||
});
|
||||
} catch (error) {
|
||||
// Skip invalid projects
|
||||
}
|
||||
}
|
||||
|
||||
return projects.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async getProject(id: string): Promise<Project | null> {
|
||||
try {
|
||||
const projectFile = `${this.dir}/${id}/.project.json`;
|
||||
const projectData = await this.fs.promises.readFile(projectFile, 'utf8');
|
||||
const project = JSON.parse(projectData);
|
||||
return {
|
||||
...project,
|
||||
createdAt: new Date(project.createdAt),
|
||||
lastModified: new Date(project.lastModified),
|
||||
};
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async readFile(projectId: string, filePath: string): Promise<string> {
|
||||
const fullPath = `${this.dir}/${projectId}/${filePath}`;
|
||||
return await this.fs.promises.readFile(fullPath, 'utf8');
|
||||
}
|
||||
|
||||
async writeFile(projectId: string, filePath: string, content: string): Promise<void> {
|
||||
const fullPath = `${this.dir}/${projectId}/${filePath}`;
|
||||
const dir = fullPath.split('/').slice(0, -1).join('/');
|
||||
await this.fs.promises.mkdir(dir, { recursive: true });
|
||||
await this.fs.promises.writeFile(fullPath, content);
|
||||
|
||||
// Update last modified
|
||||
await this.updateProjectLastModified(projectId);
|
||||
}
|
||||
|
||||
async deleteFile(projectId: string, filePath: string): Promise<void> {
|
||||
const fullPath = `${this.dir}/${projectId}/${filePath}`;
|
||||
await this.fs.promises.unlink(fullPath);
|
||||
await this.updateProjectLastModified(projectId);
|
||||
}
|
||||
|
||||
async listFiles(projectId: string, dirPath: string = ''): Promise<string[]> {
|
||||
const fullPath = `${this.dir}/${projectId}/${dirPath}`;
|
||||
try {
|
||||
return await this.fs.promises.readdir(fullPath);
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async fileExists(projectId: string, filePath: string): Promise<boolean> {
|
||||
try {
|
||||
const fullPath = `${this.dir}/${projectId}/${filePath}`;
|
||||
await this.fs.promises.stat(fullPath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private generateProjectId(name: string): string {
|
||||
const timestamp = Date.now().toString(36);
|
||||
const slug = name
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/^-+|-+$/g, '');
|
||||
return `${slug}-${timestamp}`;
|
||||
}
|
||||
|
||||
private async updateProjectLastModified(projectId: string): Promise<void> {
|
||||
try {
|
||||
const projectFile = `${this.dir}/${projectId}/.project.json`;
|
||||
const projectData = await this.fs.promises.readFile(projectFile, 'utf8');
|
||||
const project = JSON.parse(projectData);
|
||||
project.lastModified = new Date().toISOString();
|
||||
await this.fs.promises.writeFile(projectFile, JSON.stringify(project, null, 2));
|
||||
} catch (error) {
|
||||
// Ignore errors updating last modified
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const fsManager = new FileSystemManager();
|
||||
@@ -0,0 +1,104 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { fsManager, type Project } from '@/lib/fs';
|
||||
import { ChatPane } from '@/components/Shakespeare/ChatPane';
|
||||
import { PreviewPane } from '@/components/Shakespeare/PreviewPane';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { ArrowLeft } from 'lucide-react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
export function ProjectView() {
|
||||
const { projectId } = useParams<{ projectId: string }>();
|
||||
const [project, setProject] = useState<Project | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [activeTab, setActiveTab] = useState<'preview' | 'code'>('preview');
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
loadProject();
|
||||
}, [projectId]);
|
||||
|
||||
const loadProject = async () => {
|
||||
if (!projectId) return;
|
||||
|
||||
try {
|
||||
const projectData = await fsManager.getProject(projectId);
|
||||
setProject(projectData);
|
||||
} catch (error) {
|
||||
console.error('Failed to load project:', error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="min-h-screen bg-background flex items-center justify-center">
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary"></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!project) {
|
||||
return (
|
||||
<div className="min-h-screen bg-background flex items-center justify-center">
|
||||
<div className="text-center">
|
||||
<h1 className="text-2xl font-bold mb-2">Project Not Found</h1>
|
||||
<Button onClick={() => navigate('/')} variant="outline">
|
||||
<ArrowLeft className="mr-2 h-4 w-4" />
|
||||
Back to Home
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-screen flex flex-col bg-background">
|
||||
<header className="border-b px-4 py-3 flex items-center justify-between">
|
||||
<div className="flex items-center space-x-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => navigate('/')}
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<div>
|
||||
<h1 className="text-lg font-semibold">{project.name}</h1>
|
||||
<p className="text-sm text-muted-foreground">{project.id}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex space-x-2">
|
||||
<Button
|
||||
variant={activeTab === 'preview' ? 'default' : 'ghost'}
|
||||
size="sm"
|
||||
onClick={() => setActiveTab('preview')}
|
||||
>
|
||||
Preview
|
||||
</Button>
|
||||
<Button
|
||||
variant={activeTab === 'code' ? 'default' : 'ghost'}
|
||||
size="sm"
|
||||
onClick={() => setActiveTab('code')}
|
||||
>
|
||||
Code
|
||||
</Button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="flex-1 flex overflow-hidden">
|
||||
<div className="w-1/3 border-r">
|
||||
<ChatPane projectId={project.id} projectName={project.name} />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<PreviewPane
|
||||
projectId={project.id}
|
||||
activeTab={activeTab}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { fsManager, type Project } from '@/lib/fs';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Plus, Folder } from 'lucide-react';
|
||||
|
||||
export function ShakespeareHome() {
|
||||
const [prompt, setPrompt] = useState('');
|
||||
const [projects, setProjects] = useState<Project[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isCreating, setIsCreating] = useState(false);
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
loadProjects();
|
||||
}, []);
|
||||
|
||||
const loadProjects = async () => {
|
||||
try {
|
||||
await fsManager.init();
|
||||
const projectList = await fsManager.getProjects();
|
||||
setProjects(projectList);
|
||||
} catch (error) {
|
||||
console.error('Failed to load projects:', error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCreateProject = async () => {
|
||||
if (!prompt.trim()) return;
|
||||
|
||||
setIsCreating(true);
|
||||
try {
|
||||
const project = await fsManager.createProject(prompt.trim());
|
||||
navigate(`/project/${project.id}`);
|
||||
} catch (error) {
|
||||
console.error('Failed to create project:', error);
|
||||
} finally {
|
||||
setIsCreating(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleProjectClick = (projectId: string) => {
|
||||
navigate(`/project/${projectId}`);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-background">
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<div className="max-w-4xl mx-auto">
|
||||
<div className="text-center mb-12">
|
||||
<h1 className="text-4xl font-bold mb-4">Shakespeare</h1>
|
||||
<p className="text-xl text-muted-foreground mb-2">
|
||||
Build custom Nostr websites with AI assistance
|
||||
</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
<a href="https://soapbox.pub/mkstack" className="hover:underline">
|
||||
Vibed with MKStack
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="mb-12">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Create a New Project</CardTitle>
|
||||
<CardDescription>
|
||||
Describe what kind of Nostr website you want to build
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<Textarea
|
||||
placeholder="e.g., Create a farming equipment marketplace for local farmers to buy and sell tractors, tools, and supplies..."
|
||||
value={prompt}
|
||||
onChange={(e) => setPrompt(e.target.value)}
|
||||
className="min-h-[100px]"
|
||||
disabled={isCreating}
|
||||
/>
|
||||
<Button
|
||||
onClick={handleCreateProject}
|
||||
disabled={!prompt.trim() || isCreating}
|
||||
className="w-full"
|
||||
size="lg"
|
||||
>
|
||||
{isCreating ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"></div>
|
||||
Creating Project...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Create Project
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2 className="text-2xl font-semibold mb-6">Your Projects</h2>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{[...Array(6)].map((_, i) => (
|
||||
<Card key={i}>
|
||||
<CardContent className="p-6">
|
||||
<Skeleton className="h-4 w-3/4 mb-2" />
|
||||
<Skeleton className="h-3 w-1/2" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
) : projects.length === 0 ? (
|
||||
<div className="text-center py-12">
|
||||
<Folder className="mx-auto h-12 w-12 text-muted-foreground mb-4" />
|
||||
<p className="text-muted-foreground">No projects yet. Create your first project above!</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{projects.map((project) => (
|
||||
<Card
|
||||
key={project.id}
|
||||
className="cursor-pointer hover:shadow-lg transition-shadow"
|
||||
onClick={() => handleProjectClick(project.id)}
|
||||
>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-lg">{project.name}</CardTitle>
|
||||
<CardDescription>
|
||||
Created {project.createdAt.toLocaleDateString()}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Last modified {project.lastModified.toLocaleDateString()}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user