mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b64692833 | ||
|
|
d3e5402dbe | ||
|
|
1dc0cf4529 | ||
|
|
509a088b84 | ||
|
|
8c95f7c0b5 | ||
|
|
944fee7256 | ||
|
|
0f17aa8c7c |
No files matched your search
@@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
import { useState, useRef, useEffect, useCallback } from 'react';
|
import { useState, useRef, useEffect } from 'react';
|
||||||
import { CoreMessage, generateText, CoreUserMessage, CoreAssistantMessage, CoreToolMessage, generateId } from 'ai';
|
import { CoreMessage, generateText, CoreUserMessage, CoreAssistantMessage, CoreToolMessage, generateId } from 'ai';
|
||||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
import { Send, Settings, Play, CloudUpload, Loader2 } from 'lucide-react';
|
import { Send, Settings, Play, CloudUpload, Loader2 } from 'lucide-react';
|
||||||
@@ -29,22 +28,15 @@ interface ChatPaneProps {
|
|||||||
type AIMessage = (CoreUserMessage | CoreAssistantMessage | CoreToolMessage) & { id: string };
|
type AIMessage = (CoreUserMessage | CoreAssistantMessage | CoreToolMessage) & { id: string };
|
||||||
|
|
||||||
export function ChatPane({ projectId, projectName }: ChatPaneProps) {
|
export function ChatPane({ projectId, projectName }: ChatPaneProps) {
|
||||||
const [messages, setMessages] = useLocalStorage<AIMessage[]>(
|
const [messages, setMessages] = useState<AIMessage[]>([]);
|
||||||
`shakespeare-chat-${projectId}`,
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
const [input, setInput] = useState('');
|
const [input, setInput] = useState('');
|
||||||
const [isLoading, setIsLoading] = useLocalStorage<boolean>(
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
`shakespeare-loading-${projectId}`,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
const [isBuildLoading, setIsBuildLoading] = useState(false);
|
const [isBuildLoading, setIsBuildLoading] = useState(false);
|
||||||
const [isDeployLoading, setIsDeployLoading] = useState(false);
|
const [isDeployLoading, setIsDeployLoading] = useState(false);
|
||||||
const scrollAreaRef = useRef<HTMLDivElement>(null);
|
const scrollAreaRef = useRef<HTMLDivElement>(null);
|
||||||
const { settings, isConfigured } = useAISettings();
|
const { settings, isConfigured } = useAISettings();
|
||||||
const { fs: browserFS } = useFS();
|
const { fs: browserFS } = useFS();
|
||||||
const { runtime } = useJSRuntime();
|
const { runtime } = useJSRuntime();
|
||||||
const abortControllerRef = useRef<AbortController | null>(null);
|
|
||||||
|
|
||||||
// Keep-alive functionality to prevent tab throttling during AI processing
|
// Keep-alive functionality to prevent tab throttling during AI processing
|
||||||
const { updateMetadata } = useKeepAlive({
|
const { updateMetadata } = useKeepAlive({
|
||||||
@@ -60,20 +52,20 @@ export function ChatPane({ projectId, projectName }: ChatPaneProps) {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
const addMessage = useCallback((message: AIMessage) => {
|
const addMessage = (message: AIMessage) => {
|
||||||
setMessages((prev) => {
|
setMessages((prev) => {
|
||||||
const messageMap = new Map(prev.map(m => [m.id, m])).set(message.id, message);
|
const messageMap = new Map(prev.map(m => [m.id, m])).set(message.id, message);
|
||||||
return Array.from(messageMap.values());
|
return Array.from(messageMap.values());
|
||||||
});
|
});
|
||||||
}, [setMessages]);
|
};
|
||||||
|
|
||||||
const addMessages = useCallback((newMessages: AIMessage[]) => {
|
const addMessages = (newMessages: AIMessage[]) => {
|
||||||
setMessages((prev) => {
|
setMessages((prev) => {
|
||||||
const messageMap = new Map(prev.map(m => [m.id, m]));
|
const messageMap = new Map(prev.map(m => [m.id, m]));
|
||||||
newMessages.forEach(msg => messageMap.set(msg.id, msg));
|
newMessages.forEach(msg => messageMap.set(msg.id, msg));
|
||||||
return Array.from(messageMap.values());
|
return Array.from(messageMap.values());
|
||||||
});
|
});
|
||||||
}, [setMessages]);
|
};
|
||||||
|
|
||||||
const runBuild = async () => {
|
const runBuild = async () => {
|
||||||
if (isBuildLoading) return;
|
if (isBuildLoading) return;
|
||||||
@@ -185,123 +177,13 @@ BASE_DOMAIN=nostrdeploy.com`);
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Add welcome message only if there are no existing messages
|
// Add welcome message
|
||||||
if (messages.length === 0) {
|
|
||||||
addMessage({
|
addMessage({
|
||||||
id: generateId(),
|
id: generateId(),
|
||||||
role: 'assistant',
|
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?`,
|
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?`,
|
||||||
});
|
});
|
||||||
}
|
}, [projectName, projectId]);
|
||||||
|
|
||||||
// Resume interrupted AI processing if we were loading
|
|
||||||
if (isLoading && messages.length > 0) {
|
|
||||||
const lastMessage = messages[messages.length - 1];
|
|
||||||
if (lastMessage?.role === 'user') {
|
|
||||||
// We have an incomplete conversation - resume processing
|
|
||||||
// Define resume function inline to avoid circular dependency
|
|
||||||
const resumeProcessing = async () => {
|
|
||||||
if (!isConfigured || messages.length === 0) return;
|
|
||||||
|
|
||||||
const lastMsg = messages[messages.length - 1];
|
|
||||||
if (lastMsg?.role !== 'user') return;
|
|
||||||
|
|
||||||
setIsLoading(true);
|
|
||||||
updateMetadata('Shakespeare', `Resuming processing for ${projectName}...`);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const aiMessages: AIMessage[] = messages;
|
|
||||||
// Use a direct implementation instead of createAIChat to avoid circular dependency
|
|
||||||
if (!isConfigured) {
|
|
||||||
throw new Error('AI settings not configured');
|
|
||||||
}
|
|
||||||
|
|
||||||
const abortController = new AbortController();
|
|
||||||
abortControllerRef.current = abortController;
|
|
||||||
|
|
||||||
// Create a custom fetch function for the AI provider
|
|
||||||
const customFetch = async (url: string, options: RequestInit) => {
|
|
||||||
const signal = AbortSignal.any([
|
|
||||||
options.signal || new AbortController().signal,
|
|
||||||
abortController.signal
|
|
||||||
]);
|
|
||||||
|
|
||||||
return fetch(url, {
|
|
||||||
...options,
|
|
||||||
signal,
|
|
||||||
headers: {
|
|
||||||
...options.headers,
|
|
||||||
'Authorization': `Bearer ${settings.apiKey}`,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const { createOpenAI } = await import('@ai-sdk/openai');
|
|
||||||
const openai = createOpenAI({
|
|
||||||
baseURL: settings.baseUrl,
|
|
||||||
apiKey: settings.apiKey,
|
|
||||||
fetch: settings.baseUrl.includes('openrouter.ai') ? customFetch : undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
const provider = openai(settings.model);
|
|
||||||
const cwd = `/projects/${projectId}`;
|
|
||||||
|
|
||||||
await generateText({
|
|
||||||
model: provider,
|
|
||||||
messages: aiMessages,
|
|
||||||
maxSteps: 100,
|
|
||||||
abortSignal: abortController.signal,
|
|
||||||
onStepFinish(stepResult) {
|
|
||||||
console.log(stepResult);
|
|
||||||
addMessages(stepResult.response.messages);
|
|
||||||
|
|
||||||
const lastMsg = stepResult.response.messages[stepResult.response.messages.length - 1];
|
|
||||||
if (lastMsg?.role === 'tool') {
|
|
||||||
const toolName = lastMsg.content?.[0]?.toolName;
|
|
||||||
if (toolName) {
|
|
||||||
updateMetadata('Shakespeare', `Working on ${projectName} - ${toolName}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
tools: {
|
|
||||||
git_commit: new GitCommitTool(browserFS, cwd),
|
|
||||||
text_editor_view: new TextEditorViewTool(browserFS, cwd),
|
|
||||||
text_editor_write: new TextEditorWriteTool(browserFS, cwd),
|
|
||||||
text_editor_str_replace: new TextEditorStrReplaceTool(browserFS, cwd),
|
|
||||||
npm_add_package: new NpmAddPackageTool(browserFS, cwd),
|
|
||||||
npm_remove_package: new NpmRemovePackageTool(browserFS, cwd),
|
|
||||||
},
|
|
||||||
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 and manage npm packages.`
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('AI resume error:', error);
|
|
||||||
if (error instanceof Error && error.name !== 'AbortError') {
|
|
||||||
const errorMessage: AIMessage = {
|
|
||||||
id: generateId(),
|
|
||||||
role: 'assistant',
|
|
||||||
content: error.message,
|
|
||||||
};
|
|
||||||
addMessage(errorMessage);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
resumeProcessing();
|
|
||||||
} else {
|
|
||||||
// Loading flag is stale, clear it
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanup abort controller on unmount
|
|
||||||
return () => {
|
|
||||||
if (abortControllerRef.current) {
|
|
||||||
abortControllerRef.current.abort();
|
|
||||||
abortControllerRef.current = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, [projectName, projectId, messages, isLoading, addMessage, setIsLoading, isConfigured, settings, browserFS, updateMetadata, addMessages]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (scrollAreaRef.current && messages) {
|
if (scrollAreaRef.current && messages) {
|
||||||
@@ -322,19 +204,10 @@ BASE_DOMAIN=nostrdeploy.com`);
|
|||||||
throw new Error('AI settings not configured');
|
throw new Error('AI settings not configured');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new abort controller for this request
|
|
||||||
abortControllerRef.current = new AbortController();
|
|
||||||
|
|
||||||
// Create a custom fetch function for the AI provider
|
// Create a custom fetch function for the AI provider
|
||||||
const customFetch = async (url: string, options: RequestInit) => {
|
const customFetch = async (url: string, options: RequestInit) => {
|
||||||
const signal = AbortSignal.any([
|
|
||||||
options.signal || new AbortController().signal,
|
|
||||||
abortControllerRef.current!.signal
|
|
||||||
]);
|
|
||||||
|
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
...options,
|
...options,
|
||||||
signal,
|
|
||||||
headers: {
|
headers: {
|
||||||
...options.headers,
|
...options.headers,
|
||||||
'Authorization': `Bearer ${settings.apiKey}`,
|
'Authorization': `Bearer ${settings.apiKey}`,
|
||||||
@@ -357,7 +230,6 @@ BASE_DOMAIN=nostrdeploy.com`);
|
|||||||
model: provider,
|
model: provider,
|
||||||
messages,
|
messages,
|
||||||
maxSteps: 100,
|
maxSteps: 100,
|
||||||
abortSignal: abortControllerRef.current.signal,
|
|
||||||
onStepFinish(stepResult) {
|
onStepFinish(stepResult) {
|
||||||
console.log(stepResult);
|
console.log(stepResult);
|
||||||
addMessages(stepResult.response.messages);
|
addMessages(stepResult.response.messages);
|
||||||
@@ -411,9 +283,7 @@ When creating new components or pages, follow the existing patterns in the codeb
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSend = async () => {
|
||||||
|
|
||||||
const handleSend = useCallback(async () => {
|
|
||||||
if (!input.trim() || isLoading) return;
|
if (!input.trim() || isLoading) return;
|
||||||
|
|
||||||
const userMessage: AIMessage = {
|
const userMessage: AIMessage = {
|
||||||
@@ -433,19 +303,16 @@ When creating new components or pages, follow the existing patterns in the codeb
|
|||||||
await createAIChat(projectId, aiMessages);
|
await createAIChat(projectId, aiMessages);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('AI chat error:', error);
|
console.error('AI chat error:', error);
|
||||||
if (error instanceof Error && error.name !== 'AbortError') {
|
|
||||||
const errorMessage: AIMessage = {
|
const errorMessage: AIMessage = {
|
||||||
id: generateId(),
|
id: generateId(),
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
content: error.message,
|
content: error instanceof Error ? error.message : 'Sorry, I encountered an error. Please try again.',
|
||||||
};
|
};
|
||||||
addMessage(errorMessage);
|
addMessage(errorMessage);
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
abortControllerRef.current = null;
|
|
||||||
}
|
}
|
||||||
}, [input, isLoading, messages, projectId, projectName, addMessage, setIsLoading]);
|
};
|
||||||
|
|
||||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||||
if (e.key === 'Enter' && !e.shiftKey) {
|
if (e.key === 'Enter' && !e.shiftKey) {
|
||||||
|
|||||||
@@ -24,72 +24,72 @@ export function AISettingsStep({ onNext, onPrevious, onSkip }: AISettingsStepPro
|
|||||||
const isValid = localSettings.apiKey.trim() && localSettings.baseUrl.trim() && localSettings.model.trim();
|
const isValid = localSettings.apiKey.trim() && localSettings.baseUrl.trim() && localSettings.model.trim();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-2 sm:space-y-4 mb-3 sm:mb-0">
|
||||||
<div className="text-center space-y-2">
|
<div className="text-center space-y-1 sm:space-y-1.5">
|
||||||
<div className="flex justify-center mb-2">
|
<div className="flex justify-center mb-0.5 sm:mb-1">
|
||||||
<Bot className="h-8 w-8 text-primary" />
|
<Bot className="h-5 w-5 sm:h-6 sm:w-6 text-primary" />
|
||||||
</div>
|
</div>
|
||||||
<h1 className="text-2xl font-bold bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">
|
<h1 className="text-base sm:text-lg md:text-xl font-bold bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent leading-tight">
|
||||||
Configure AI Settings
|
Configure AI Settings
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-sm text-muted-foreground max-w-lg mx-auto">
|
<p className="text-xs sm:text-sm text-muted-foreground max-w-md mx-auto px-2">
|
||||||
Set up your AI provider to start building with AI assistance.
|
Set up your AI provider to start building with AI assistance.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Card className="max-w-lg mx-auto">
|
<Card className="max-w-md sm:max-w-lg md:max-w-lg mx-auto">
|
||||||
<CardHeader className="pb-3">
|
<CardHeader className="pb-2 sm:pb-3">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-1.5 sm:gap-2">
|
||||||
<Settings className="h-4 w-4 text-primary" />
|
<Settings className="h-3.5 w-3.5 sm:h-4 sm:w-4 text-primary" />
|
||||||
<CardTitle className="text-lg">AI Provider</CardTitle>
|
<CardTitle className="text-base sm:text-lg">AI Provider</CardTitle>
|
||||||
</div>
|
</div>
|
||||||
<CardDescription className="text-xs">
|
<CardDescription className="text-[10px] sm:text-xs">
|
||||||
We recommend OpenRouter for easy setup
|
We recommend OpenRouter for easy setup
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="space-y-4">
|
<CardContent className="space-y-2 sm:space-y-3">
|
||||||
<div className="space-y-3">
|
<div className="space-y-2 sm:space-y-3">
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<Label htmlFor="apiKey" className="text-sm">API Key *</Label>
|
<Label htmlFor="apiKey" className="text-xs sm:text-sm">API Key *</Label>
|
||||||
<Input
|
<Input
|
||||||
id="apiKey"
|
id="apiKey"
|
||||||
type="password"
|
type="password"
|
||||||
placeholder="sk-... or your-api-key"
|
placeholder="sk-... or your-api-key"
|
||||||
value={localSettings.apiKey}
|
value={localSettings.apiKey}
|
||||||
onChange={(e) => setLocalSettings({ ...localSettings, apiKey: e.target.value })}
|
onChange={(e) => setLocalSettings({ ...localSettings, apiKey: e.target.value })}
|
||||||
className="font-mono text-sm h-9"
|
className="font-mono text-xs sm:text-sm h-8 sm:h-9"
|
||||||
/>
|
/>
|
||||||
<p className="text-xs text-muted-foreground">
|
<p className="text-[10px] sm:text-xs text-muted-foreground">
|
||||||
Stored locally, never shared
|
Stored locally, never shared
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<Label htmlFor="baseUrl" className="text-sm">Base URL *</Label>
|
<Label htmlFor="baseUrl" className="text-xs sm:text-sm">Base URL *</Label>
|
||||||
<Input
|
<Input
|
||||||
id="baseUrl"
|
id="baseUrl"
|
||||||
placeholder="https://openrouter.ai/api/v1"
|
placeholder="https://openrouter.ai/api/v1"
|
||||||
value={localSettings.baseUrl}
|
value={localSettings.baseUrl}
|
||||||
onChange={(e) => setLocalSettings({ ...localSettings, baseUrl: e.target.value })}
|
onChange={(e) => setLocalSettings({ ...localSettings, baseUrl: e.target.value })}
|
||||||
className="text-sm h-9"
|
className="text-xs sm:text-sm h-8 sm:h-9"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<Label htmlFor="model" className="text-sm">Model *</Label>
|
<Label htmlFor="model" className="text-xs sm:text-sm">Model *</Label>
|
||||||
<Input
|
<Input
|
||||||
id="model"
|
id="model"
|
||||||
placeholder="anthropic/claude-sonnet-4"
|
placeholder="anthropic/claude-sonnet-4"
|
||||||
value={localSettings.model}
|
value={localSettings.model}
|
||||||
onChange={(e) => setLocalSettings({ ...localSettings, model: e.target.value })}
|
onChange={(e) => setLocalSettings({ ...localSettings, model: e.target.value })}
|
||||||
className="text-sm h-9"
|
className="text-xs sm:text-sm h-8 sm:h-9"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<div className="flex justify-center gap-3 pt-2">
|
<div className="flex justify-center gap-2 sm:gap-3 pt-1 sm:pt-2">
|
||||||
<Button
|
<Button
|
||||||
onClick={onPrevious}
|
onClick={onPrevious}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
@@ -115,7 +115,7 @@ export function AISettingsStep({ onNext, onPrevious, onSkip }: AISettingsStepPro
|
|||||||
onClick={onSkip}
|
onClick={onSkip}
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="text-muted-foreground text-xs h-7"
|
className="text-muted-foreground text-[10px] sm:text-xs h-6 sm:h-7"
|
||||||
>
|
>
|
||||||
Skip for now
|
Skip for now
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ interface OnboardingDialogProps {
|
|||||||
currentStep: number;
|
currentStep: number;
|
||||||
onNextStep: () => void;
|
onNextStep: () => void;
|
||||||
onPreviousStep: () => void;
|
onPreviousStep: () => void;
|
||||||
|
initialPrompt?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const STEPS = [
|
const STEPS = [
|
||||||
@@ -28,7 +29,8 @@ export function OnboardingDialog({
|
|||||||
onComplete,
|
onComplete,
|
||||||
currentStep: propCurrentStep,
|
currentStep: propCurrentStep,
|
||||||
onNextStep,
|
onNextStep,
|
||||||
onPreviousStep
|
onPreviousStep,
|
||||||
|
initialPrompt = ''
|
||||||
}: OnboardingDialogProps) {
|
}: OnboardingDialogProps) {
|
||||||
const [localStep, setLocalStep] = useState(propCurrentStep);
|
const [localStep, setLocalStep] = useState(propCurrentStep);
|
||||||
|
|
||||||
@@ -88,6 +90,7 @@ export function OnboardingDialog({
|
|||||||
onPrevious={handlePrevious}
|
onPrevious={handlePrevious}
|
||||||
onComplete={handleComplete}
|
onComplete={handleComplete}
|
||||||
onProjectCreated={onProjectCreated}
|
onProjectCreated={onProjectCreated}
|
||||||
|
initialPrompt={initialPrompt}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
@@ -97,25 +100,25 @@ export function OnboardingDialog({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent className="max-w-4xl max-h-[85vh] overflow-y-auto p-0">
|
<DialogContent className="max-w-lg w-[95vw] max-h-[90vh] overflow-y-auto p-0 sm:max-w-xl md:max-w-4xl">
|
||||||
<div className="sticky top-0 bg-background border-b p-6 pb-4 z-10">
|
<div className="sticky top-0 bg-background border-b p-4 sm:p-5 pb-3 z-10">
|
||||||
<DialogTitle className="sr-only">Getting Started Onboarding</DialogTitle>
|
<DialogTitle className="sr-only">Getting Started Onboarding</DialogTitle>
|
||||||
<DialogDescription className="sr-only">Complete the onboarding process to get started with Shakespeare</DialogDescription>
|
<DialogDescription className="sr-only">Complete the onboarding process to get started with Shakespeare</DialogDescription>
|
||||||
<div className="space-y-2">
|
<div className="space-y-1.5">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<h2 className="text-lg font-semibold">Getting Started</h2>
|
<h2 className="text-base sm:text-lg font-semibold">Getting Started</h2>
|
||||||
<span className="text-sm text-muted-foreground">
|
<span className="text-xs sm:text-sm text-muted-foreground">
|
||||||
Step {currentStep + 1} of {STEPS.length}
|
{currentStep + 1} / {STEPS.length}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Progress value={progress} className="h-2" />
|
<Progress value={progress} className="h-1.5" />
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between text-xs text-muted-foreground">
|
<div className="grid grid-cols-3 gap-2 text-[10px] sm:text-xs text-muted-foreground">
|
||||||
{STEPS.map((step, index) => (
|
{STEPS.map((step, index) => (
|
||||||
<span
|
<span
|
||||||
key={step.id}
|
key={step.id}
|
||||||
className={index <= currentStep ? 'text-primary font-medium' : ''}
|
className={`text-center ${index <= currentStep ? 'text-primary font-medium' : ''} truncate`}
|
||||||
>
|
>
|
||||||
{step.title}
|
{step.title}
|
||||||
</span>
|
</span>
|
||||||
@@ -124,7 +127,7 @@ export function OnboardingDialog({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="p-6 pt-4">
|
<div className="px-2 sm:p-6">
|
||||||
{renderStep()}
|
{renderStep()}
|
||||||
</div>
|
</div>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|||||||
@@ -11,10 +11,11 @@ interface ProjectStepProps {
|
|||||||
onPrevious: () => void;
|
onPrevious: () => void;
|
||||||
onComplete: () => void;
|
onComplete: () => void;
|
||||||
onProjectCreated?: (projectId: string) => void;
|
onProjectCreated?: (projectId: string) => void;
|
||||||
|
initialPrompt?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ProjectStep({ onPrevious, onComplete, onProjectCreated }: ProjectStepProps) {
|
export function ProjectStep({ onPrevious, onComplete, onProjectCreated, initialPrompt = '' }: ProjectStepProps) {
|
||||||
const [prompt, setPrompt] = useState('');
|
const [prompt, setPrompt] = useState(initialPrompt);
|
||||||
const [isCreating, setIsCreating] = useState(false);
|
const [isCreating, setIsCreating] = useState(false);
|
||||||
const projectsManager = useProjectsManager();
|
const projectsManager = useProjectsManager();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -36,50 +37,50 @@ export function ProjectStep({ onPrevious, onComplete, onProjectCreated }: Projec
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-3 sm:space-y-6 pb-4">
|
||||||
<div className="text-center space-y-4">
|
<div className="text-center space-y-1 sm:space-y-4">
|
||||||
<div className="flex justify-center mb-2">
|
<div className="flex justify-center mb-0.5 sm:mb-2">
|
||||||
<Sparkles className="h-8 w-8 text-primary" />
|
<Sparkles className="h-5 w-5 sm:h-8 sm:w-8 text-primary" />
|
||||||
</div>
|
</div>
|
||||||
<h1 className="text-3xl font-bold bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">
|
<h1 className="text-base sm:text-2xl md:text-3xl font-bold bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent leading-tight">
|
||||||
Create Your First Project
|
Create Your First Project
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-base text-muted-foreground max-w-2xl mx-auto">
|
<p className="text-xs sm:text-base text-muted-foreground max-w-md sm:max-w-2xl mx-auto px-2">
|
||||||
Our AI will help you create it step by step.
|
Our AI will help you create it step by step.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Card className="max-w-2xl mx-auto">
|
<Card className="max-w-md sm:max-w-2xl md:max-w-2xl mx-auto">
|
||||||
<CardHeader>
|
<CardHeader className="pb-3 sm:pb-4">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-1.5 sm:gap-2">
|
||||||
<Sparkles className="h-5 w-5 text-primary" />
|
<Sparkles className="h-4 w-4 sm:h-5 sm:w-5 text-primary" />
|
||||||
<CardTitle>Project Description</CardTitle>
|
<CardTitle className="text-base sm:text-lg">Project Description</CardTitle>
|
||||||
</div>
|
</div>
|
||||||
<CardDescription>
|
<CardDescription className="text-xs sm:text-sm">
|
||||||
Be as detailed as possible about what you want to build
|
Be as detailed as possible about what you want to build
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="space-y-4">
|
<CardContent className="space-y-3 sm:space-y-4">
|
||||||
<Textarea
|
<Textarea
|
||||||
placeholder="e.g., Create a farming equipment marketplace for local farmers to buy and sell tractors, tools, and supplies. Include user profiles, product listings with images, search functionality, and direct messaging between buyers and sellers..."
|
placeholder="e.g., Create a farming equipment marketplace for local farmers to buy and sell tractors, tools, and supplies. Include user profiles, product listings with images, search functionality, and direct messaging between buyers and sellers..."
|
||||||
value={prompt}
|
value={prompt}
|
||||||
onChange={(e) => setPrompt(e.target.value)}
|
onChange={(e) => setPrompt(e.target.value)}
|
||||||
className="min-h-[125px] text-sm leading-relaxed"
|
className="min-h-[175px] sm:min-h-[100px] sm:min-h-[125px] text-xs sm:text-sm leading-relaxed"
|
||||||
disabled={isCreating}
|
disabled={isCreating}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="hidden sm:block space-y-1.5 sm:space-y-2">
|
||||||
<h3 className="font-medium text-sm">Example prompts:</h3>
|
<h3 className="font-medium text-xs sm:text-sm">Example prompts:</h3>
|
||||||
<ul className="text-xs text-muted-foreground space-y-1">
|
<ul className="text-[10px] sm:text-xs text-muted-foreground space-y-0.5 sm:space-y-1">
|
||||||
<li>• "Build a social media platform for photographers to share their work and connect with clients"</li>
|
<li>• "Build a social media platform for photographers"</li>
|
||||||
<li>• "Create a blog platform with markdown support and Nostr-based comments"</li>
|
<li>• "Create a blog with markdown and Nostr comments"</li>
|
||||||
<li>• "Design a marketplace for vintage clothing with categories, filters, and user ratings"</li>
|
<li>• "Design a marketplace with categories and ratings"</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<div className="flex flex-col items-center gap-2 pt-4">
|
<div className="flex flex-col items-center gap-2 pt-2 sm:pt-4">
|
||||||
<Button
|
<Button
|
||||||
onClick={handleCreateProject}
|
onClick={handleCreateProject}
|
||||||
disabled={!prompt.trim() || isCreating}
|
disabled={!prompt.trim() || isCreating}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ interface WelcomeStepProps {
|
|||||||
|
|
||||||
export function WelcomeStep({ onNext, onSkip }: WelcomeStepProps) {
|
export function WelcomeStep({ onNext, onSkip }: WelcomeStepProps) {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6 p-4">
|
||||||
<div className="text-center space-y-4">
|
<div className="text-center space-y-4">
|
||||||
<div className="text-6xl mb-4">🎭</div>
|
<div className="text-6xl mb-4">🎭</div>
|
||||||
<h1 className="text-3xl font-bold bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">
|
<h1 className="text-3xl font-bold bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">
|
||||||
@@ -20,7 +20,7 @@ export function WelcomeStep({ onNext, onSkip }: WelcomeStepProps) {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid md:grid-cols-3 gap-4 max-w-4xl mx-auto">
|
<div className="hidden md:grid md:grid-cols-3 gap-4 max-w-4xl mx-auto">
|
||||||
<Card className="text-center">
|
<Card className="text-center">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<div className="flex justify-center mb-2">
|
<div className="flex justify-center mb-2">
|
||||||
|
|||||||
+49
-7
@@ -3,6 +3,7 @@ import { useNavigate } from 'react-router-dom';
|
|||||||
import { type Project } from '@/lib/ProjectsManager';
|
import { type Project } from '@/lib/ProjectsManager';
|
||||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||||
import { useOnboarding } from '@/hooks/useOnboarding';
|
import { useOnboarding } from '@/hooks/useOnboarding';
|
||||||
|
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||||
import { ProjectSidebar } from '@/components/ProjectSidebar';
|
import { ProjectSidebar } from '@/components/ProjectSidebar';
|
||||||
import { OnboardingDialog } from '@/components/onboarding';
|
import { OnboardingDialog } from '@/components/onboarding';
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ export default function Index() {
|
|||||||
const [projects, setProjects] = useState<Project[]>([]);
|
const [projects, setProjects] = useState<Project[]>([]);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [isCreating, setIsCreating] = useState(false);
|
const [isCreating, setIsCreating] = useState(false);
|
||||||
|
const [storedPrompt, setStoredPrompt] = useLocalStorage('shakespeare-draft-prompt', '');
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const projectsManager = useProjectsManager();
|
const projectsManager = useProjectsManager();
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
@@ -32,6 +34,7 @@ export default function Index() {
|
|||||||
handlePreviousStep,
|
handlePreviousStep,
|
||||||
handleCompleteOnboarding,
|
handleCompleteOnboarding,
|
||||||
} = useOnboarding();
|
} = useOnboarding();
|
||||||
|
|
||||||
const [isSidebarVisible, setIsSidebarVisible] = useState(() => {
|
const [isSidebarVisible, setIsSidebarVisible] = useState(() => {
|
||||||
// Check if we're on mobile immediately to set correct initial state
|
// Check if we're on mobile immediately to set correct initial state
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
@@ -61,9 +64,26 @@ export default function Index() {
|
|||||||
loadProjects();
|
loadProjects();
|
||||||
}, [loadProjects]);
|
}, [loadProjects]);
|
||||||
|
|
||||||
|
// Restore prompt from local storage on mount
|
||||||
|
useEffect(() => {
|
||||||
|
if (storedPrompt) {
|
||||||
|
setPrompt(storedPrompt);
|
||||||
|
}
|
||||||
|
}, [storedPrompt]);
|
||||||
|
|
||||||
|
// Sync prompt with local storage
|
||||||
|
const handlePromptChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
|
const newPrompt = e.target.value;
|
||||||
|
setPrompt(newPrompt);
|
||||||
|
setStoredPrompt(newPrompt);
|
||||||
|
};
|
||||||
|
|
||||||
const handleCreateProject = async () => {
|
const handleCreateProject = async () => {
|
||||||
if (!prompt.trim()) return;
|
if (!prompt.trim()) return;
|
||||||
|
|
||||||
|
// Clear stored prompt when creating project
|
||||||
|
setStoredPrompt('');
|
||||||
|
|
||||||
setIsCreating(true);
|
setIsCreating(true);
|
||||||
try {
|
try {
|
||||||
const project = await projectsManager.createProject(prompt.trim());
|
const project = await projectsManager.createProject(prompt.trim());
|
||||||
@@ -91,6 +111,7 @@ export default function Index() {
|
|||||||
<div className="min-h-dvh bg-gradient-to-br from-primary/5 to-accent/5">
|
<div className="min-h-dvh bg-gradient-to-br from-primary/5 to-accent/5">
|
||||||
{/* Mobile Header */}
|
{/* Mobile Header */}
|
||||||
<header className="border-b bg-gradient-to-r from-primary/10 via-accent/5 to-primary/10 backdrop-blur px-4 py-3 flex items-center justify-between">
|
<header className="border-b bg-gradient-to-r from-primary/10 via-accent/5 to-primary/10 backdrop-blur px-4 py-3 flex items-center justify-between">
|
||||||
|
{projects.length > 0 ? (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
@@ -98,14 +119,17 @@ export default function Index() {
|
|||||||
>
|
>
|
||||||
<Menu className="h-4 w-4" />
|
<Menu className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
) : (
|
||||||
|
<div className="w-8" /> /* Spacer when no sidebar */
|
||||||
|
)}
|
||||||
<h1 className="text-lg font-semibold bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">
|
<h1 className="text-lg font-semibold bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">
|
||||||
Shakespeare
|
Shakespeare
|
||||||
</h1>
|
</h1>
|
||||||
<div className="w-8" /> {/* Spacer */}
|
<div className="w-8" /> {/* Spacer */}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
{/* Mobile Sidebar Overlay */}
|
{/* Mobile Sidebar Overlay - only show if user has projects */}
|
||||||
{isSidebarVisible && (
|
{projects.length > 0 && isSidebarVisible && (
|
||||||
<div className="fixed inset-0 z-50 bg-background/80 backdrop-blur-sm">
|
<div className="fixed inset-0 z-50 bg-background/80 backdrop-blur-sm">
|
||||||
{/* Backdrop - only covers the area not occupied by the sidebar */}
|
{/* Backdrop - only covers the area not occupied by the sidebar */}
|
||||||
<div
|
<div
|
||||||
@@ -172,7 +196,7 @@ export default function Index() {
|
|||||||
<Textarea
|
<Textarea
|
||||||
placeholder="e.g., Create a farming equipment marketplace for local farmers to buy and sell tractors, tools, and supplies..."
|
placeholder="e.g., Create a farming equipment marketplace for local farmers to buy and sell tractors, tools, and supplies..."
|
||||||
value={prompt}
|
value={prompt}
|
||||||
onChange={(e) => setPrompt(e.target.value)}
|
onChange={handlePromptChange}
|
||||||
className="min-h-[120px] touch-action-manipulation overscroll-contain text-base leading-relaxed"
|
className="min-h-[120px] touch-action-manipulation overscroll-contain text-base leading-relaxed"
|
||||||
disabled={isCreating}
|
disabled={isCreating}
|
||||||
/>
|
/>
|
||||||
@@ -254,6 +278,20 @@ export default function Index() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<OnboardingDialog
|
||||||
|
open={isOnboardingOpen}
|
||||||
|
onOpenChange={setIsOnboardingOpen}
|
||||||
|
currentStep={currentStep}
|
||||||
|
onNextStep={handleNextStep}
|
||||||
|
onPreviousStep={handlePreviousStep}
|
||||||
|
onComplete={handleCompleteOnboarding}
|
||||||
|
initialPrompt={storedPrompt}
|
||||||
|
onProjectCreated={(projectId) => {
|
||||||
|
console.log('Project created during onboarding:', projectId);
|
||||||
|
setStoredPrompt('');
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -267,13 +305,16 @@ export default function Index() {
|
|||||||
onNextStep={handleNextStep}
|
onNextStep={handleNextStep}
|
||||||
onPreviousStep={handlePreviousStep}
|
onPreviousStep={handlePreviousStep}
|
||||||
onComplete={handleCompleteOnboarding}
|
onComplete={handleCompleteOnboarding}
|
||||||
|
initialPrompt={storedPrompt}
|
||||||
onProjectCreated={(projectId) => {
|
onProjectCreated={(projectId) => {
|
||||||
// Handle project creation during onboarding
|
// Handle project creation during onboarding
|
||||||
console.log('Project created during onboarding:', projectId);
|
console.log('Project created during onboarding:', projectId);
|
||||||
|
setStoredPrompt(''); // Clear stored prompt after project creation
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div className="h-screen flex bg-background">
|
<div className="h-screen flex bg-background">
|
||||||
{/* Fixed Sidebar */}
|
{/* Fixed Sidebar - only show if user has created projects */}
|
||||||
|
{projects.length > 0 && (
|
||||||
<div className={cn("w-80 border-r bg-sidebar transition-all duration-300", isSidebarVisible ? "block" : "hidden")}>
|
<div className={cn("w-80 border-r bg-sidebar transition-all duration-300", isSidebarVisible ? "block" : "hidden")}>
|
||||||
<ProjectSidebar
|
<ProjectSidebar
|
||||||
selectedProject={null}
|
selectedProject={null}
|
||||||
@@ -281,12 +322,13 @@ export default function Index() {
|
|||||||
className="h-full"
|
className="h-full"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Main Content Area */}
|
{/* Main Content Area */}
|
||||||
<div className="flex-1 flex flex-col overflow-hidden bg-background">
|
<div className="flex-1 flex flex-col overflow-hidden bg-background">
|
||||||
<div className="min-h-full bg-gradient-to-br from-primary/5 to-accent/5">
|
<div className="min-h-full bg-gradient-to-br from-primary/5 to-accent/5">
|
||||||
{/* Header */}
|
{/* Header - only show toggle button if user has projects */}
|
||||||
{!isSidebarVisible && (
|
{!isSidebarVisible && projects.length > 0 && (
|
||||||
<header className="border-b bg-gradient-to-r from-primary/10 via-accent/5 to-primary/10 backdrop-blur px-4 py-3 flex items-center">
|
<header className="border-b bg-gradient-to-r from-primary/10 via-accent/5 to-primary/10 backdrop-blur px-4 py-3 flex items-center">
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
@@ -339,7 +381,7 @@ export default function Index() {
|
|||||||
<Textarea
|
<Textarea
|
||||||
placeholder="e.g., Create a farming equipment marketplace for local farmers to buy and sell tractors, tools, and supplies..."
|
placeholder="e.g., Create a farming equipment marketplace for local farmers to buy and sell tractors, tools, and supplies..."
|
||||||
value={prompt}
|
value={prompt}
|
||||||
onChange={(e) => setPrompt(e.target.value)}
|
onChange={handlePromptChange}
|
||||||
className="min-h-[120px] touch-action-manipulation overscroll-contain text-base leading-relaxed"
|
className="min-h-[120px] touch-action-manipulation overscroll-contain text-base leading-relaxed"
|
||||||
disabled={isCreating}
|
disabled={isCreating}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in new issue
Block a user