update
Browse filesFiles changed (2)
231 unmodified lines23223323423523623723839 unmodified lines2782792802812822831 unmodified line285286287288289290291363 unmodified lines65565665765865966066166234 unmodified lines697698699700701702703704705706707231 unmodified lines}};const handleSendMessage = async (message: string, overrideLanguage?: Language, overrideModel?: string) => {if (!isAuthenticated) {alert('Please sign in with HuggingFace first! Click the "Sign in with Hugging Face" button in the header.');return;39 unmodified linessetGeneratedCode('');// Prepare request with enhanced query that includes current codeconst request: CodeGenerationRequest = {query: enhancedMessage,language: language,1 unmodified lineprovider: 'auto',history: messages.map((m) => [m.role, m.content]),agent_mode: false,existing_repo_id: currentRepoId || undefined, // Pass duplicated/imported space ID for auto-deploy};const assistantMessage: Message = {363 unmodified lines// Only set as current repo if user owns itif (username && importedRepoId.startsWith(`${username}/`)) {setCurrentRepoId(importedRepoId);console.log('[Import] β β β SETTING currentRepoId to:', importedRepoId);} else {// User doesn't own the imported space, clear current reposetCurrentRepoId(null);34 unmodified lines};// Handle landing page prompt submissionconst handleLandingPageStart = async (prompt: string, language: Language, modelId: string) => {// Hide landing page immediately for smooth transitionsetShowLandingPage(false);// Send the message with the selected language and modelawait handleSendMessage(prompt, language, modelId);};// Resize handlers for chat sidebar (desktop only)231 unmodified lines23223323423523623723839 unmodified lines2782792802812822832842852862872882892902912921 unmodified line294295296297298299300363 unmodified lines66466566666766866967067167267334 unmodified lines708709710711712713714715716717718719231 unmodified lines}};const handleSendMessage = async (message: string, overrideLanguage?: Language, overrideModel?: string, overrideRepoId?: string) => {if (!isAuthenticated) {alert('Please sign in with HuggingFace first! Click the "Sign in with Hugging Face" button in the header.');return;39 unmodified linessetGeneratedCode('');// Prepare request with enhanced query that includes current code// Use overrideRepoId if provided (from import/duplicate), otherwise use currentRepoId from stateconst effectiveRepoId = overrideRepoId || currentRepoId || undefined;console.log('[SendMessage] ========== GENERATION REQUEST ==========');console.log('[SendMessage] overrideRepoId:', overrideRepoId);console.log('[SendMessage] currentRepoId:', currentRepoId);console.log('[SendMessage] effectiveRepoId (will use):', effectiveRepoId);console.log('[SendMessage] ==========================================');const request: CodeGenerationRequest = {query: enhancedMessage,language: language,1 unmodified lineprovider: 'auto',history: messages.map((m) => [m.role, m.content]),agent_mode: false,existing_repo_id: effectiveRepoId, // Pass duplicated/imported space ID for auto-deploy};const assistantMessage: Message = {363 unmodified lines// Only set as current repo if user owns itif (username && importedRepoId.startsWith(`${username}/`)) {console.log('[Import] β β β BEFORE setCurrentRepoId - currentRepoId was:', currentRepoId);setCurrentRepoId(importedRepoId);console.log('[Import] β β β CALLED setCurrentRepoId with:', importedRepoId);console.log('[Import] β β β Note: State update is async, currentRepoId will update later');} else {// User doesn't own the imported space, clear current reposetCurrentRepoId(null);34 unmodified lines};// Handle landing page prompt submissionconst handleLandingPageStart = async (prompt: string, language: Language, modelId: string, repoId?: string) => {// Hide landing page immediately for smooth transitionsetShowLandingPage(false);// Send the message with the selected language and model// Pass repoId if provided (for imported/duplicated spaces)await handleSendMessage(prompt, language, modelId, repoId);};// Resize handlers for chat sidebar (desktop only)
14 unmodified lines15161718192021312 unmodified lines33433533633733833934034134211 unmodified lines35435535635735835936014 unmodified linesimport type { OAuthUserInfo } from '@/lib/auth';interface LandingPageProps {onStart: (prompt: string, language: Language, modelId: string) => void;onImport?: (code: string, language: Language, importUrl?: string) => void;isAuthenticated: boolean;initialLanguage?: Language;312 unmodified lines// Import code and trigger AI redesign (don't duplicate yet)if (onImport && onStart) {onImport(result.code, result.language || 'html', redesignUrl);// Send redesign prompt with code contextsetTimeout(async () => {const redesignPrompt = `I have existing code in the editor that I imported from ${redesignUrl}. Please redesign it to make it look better with minimal components needed, mobile friendly, and modern design.11 unmodified lines${createPR ? '\n\nNote: After generating the redesign, I will create a Pull Request on the original space.' : '\n\nNote: After generating the redesign, I can deploy to a new space or duplicate the original space.'}`;if (onStart) {onStart(redesignPrompt, result.language || 'html', selectedModel);}if (createPR) {14 unmodified lines15161718192021312 unmodified lines33433533633733833934034134234334411 unmodified lines35635735835936036136236336436536614 unmodified linesimport type { OAuthUserInfo } from '@/lib/auth';interface LandingPageProps {onStart: (prompt: string, language: Language, modelId: string, repoId?: string) => void;onImport?: (code: string, language: Language, importUrl?: string) => void;isAuthenticated: boolean;initialLanguage?: Language;312 unmodified lines// Import code and trigger AI redesign (don't duplicate yet)if (onImport && onStart) {// First import the code (this will set currentRepoId in the parent)onImport(result.code, result.language || 'html', redesignUrl);// Send redesign prompt with code context// Pass the repoId directly to avoid React state timing issuessetTimeout(async () => {const redesignPrompt = `I have existing code in the editor that I imported from ${redesignUrl}. Please redesign it to make it look better with minimal components needed, mobile friendly, and modern design.11 unmodified lines${createPR ? '\n\nNote: After generating the redesign, I will create a Pull Request on the original space.' : '\n\nNote: After generating the redesign, I can deploy to a new space or duplicate the original space.'}`;if (onStart) {// Extract repo ID from URL to pass directly (avoids state timing issues)const spaceMatch = redesignUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);const extractedRepoId = spaceMatch ? spaceMatch[1] : undefined;console.log('[Redesign] Passing repoId to onStart:', extractedRepoId);onStart(redesignPrompt, result.language || 'html', selectedModel, extractedRepoId);}if (createPR) {
frontend/src/app/page.tsx+17-5
frontend/src/components/LandingPage.tsx+8-2