update import and deploy
Browse filesFiles changed (3)
16 unmodified lines17181920212223245 unmodified lines30313231333435362 unmodified lines39404142434445464748495051525354108 unmodified lines1631641651661671681691701711721731741751761771781791801811821831841851861871881891541551901911921931941951961971601981992002012022032042052062072082092102112122132142152162172182192202212221 unmodified line22422522622722817222923023123210 unmodified lines24324424518924624724824925025125225325425525625725825926026126226326426526626726826927027119627227327427516 unmodified lines const [selectedModel, setSelectedModel] = useState('gemini-3.0-pro'); const [isGenerating, setIsGenerating] = useState(false); const [isAuthenticated, setIsAuthenticated] = useState(false); const [currentRepoId, setCurrentRepoId] = useState<string | null>(null); // Track imported/deployed space const [username, setUsername] = useState<string | null>(null); // Track current user // Mobile view state: 'chat', 'editor', or 'settings' const [mobileView, setMobileView] = useState<'chat' | 'editor' | 'settings'>('editor');5 unmodified lines return () => clearInterval(interval); }, []);
const checkAuth = () => { const checkAuth = async () => { const authenticated = checkIsAuthenticated(); setIsAuthenticated(authenticated); 2 unmodified lines const token = getStoredToken(); if (token) { apiClient.setToken(token); // Get username from auth status try { const authStatus = await apiClient.getAuthStatus(); if (authStatus.username) { setUsername(authStatus.username); } } catch (error) { console.error('Failed to get username:', error); } } } };108 unmodified lines return; }
// Determine if we're updating an existing space or creating a new one let existingRepoId = currentRepoId; let actionMessage = 'Deploy'; // If we have a current repo, check if user owns it if (currentRepoId && username) { const ownsSpace = currentRepoId.startsWith(`${username}/`); if (ownsSpace) { actionMessage = 'Update'; const confirmUpdate = confirm(`Update existing space: ${currentRepoId}?`); if (!confirmUpdate) { existingRepoId = null; // Create new space instead actionMessage = 'Deploy'; } } else { // User doesn't own the imported space, create a new one existingRepoId = null; actionMessage = 'Deploy'; } }
// Only prompt for space name if creating new space let spaceName = undefined; if (!existingRepoId) { const spaceName = prompt('Enter HuggingFace Space name (or leave empty for auto-generated):'); if (spaceName === null) return; // User cancelled const input = prompt('Enter HuggingFace Space name (or leave empty for auto-generated):'); if (input === null) return; // User cancelled spaceName = input || undefined; }
try { const response = await apiClient.deploy({ code: generatedCode, space_name: spaceName || undefined, space_name: spaceName, language: selectedLanguage, existing_repo_id: existingRepoId || undefined, commit_message: existingRepoId ? 'Update via AnyCoder' : undefined, });
if (response.success) { // Update current repo ID if we got one back if (response.repo_id) { setCurrentRepoId(response.repo_id); } // Add deployment message to chat const deployMessage: Message = { role: 'assistant', content: existingRepoId ? `β
Updated space: ${response.space_url}` : `β
Deployed to: ${response.space_url}`, timestamp: new Date().toISOString(), }; setMessages((prev) => [...prev, deployMessage]); // Open the space URL in a new tab window.open(response.space_url, '_blank'); 1 unmodified line const isDev = response.dev_mode; const message = isDev ? 'π Opening HuggingFace Spaces creation page...\nPlease complete the space setup in the new tab.' : existingRepoId ? `β
Updated successfully!\n\nOpening: ${response.space_url}` : `β
Deployed successfully!\n\nOpening: ${response.space_url}`; : `β
Deployed successfully!\n\nOpening: ${response.space_url}`; alert(message); } else { alert(`Deployment failed: ${response.message}`);10 unmodified lines } };
const handleImport = (code: string, language: Language) => { const handleImport = (code: string, language: Language, importUrl?: string) => { setGeneratedCode(code); setSelectedLanguage(language); // Extract repo_id from import URL if provided if (importUrl) { const spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/); if (spaceMatch) { const importedRepoId = spaceMatch[1]; // Only set as current repo if user owns it if (username && importedRepoId.startsWith(`${username}/`)) { setCurrentRepoId(importedRepoId); console.log('[Import] Set current repo to:', importedRepoId); } else { // User doesn't own the imported space, clear current repo setCurrentRepoId(null); console.log('[Import] User does not own imported space:', importedRepoId); } } } // Add messages that include the imported code so LLM can see it const userMessage: Message = { role: 'user', content: importUrl ? `Imported Space from ${importUrl}` content: `I imported a ${language} project. Here's the code that was imported.`, : `I imported a ${language} project. Here's the code that was imported.`, timestamp: new Date().toISOString(), }; 10 unmodified lines111213141415161765 unmodified lines838485868687888910 unmodified lines onModelChange: (modelId: string) => void; onDeploy: () => void; onClear: () => void; onImport?: (code: string, language: Language) => void; onImport?: (code: string, language: Language, importUrl?: string) => void; isGenerating: boolean;}
65 unmodified lines // Call the onImport callback if provided if (onImport && result.code) { onImport(result.code, result.language || 'html'); onImport(result.code, result.language || 'html', importUrl); } // Close modal and reset46 unmodified lines47484950515253541 unmodified line5657585960616246 unmodified lines space_name?: string; language: string; requirements?: string; existing_repo_id?: string; // For updating existing spaces commit_message?: string;}
export interface DeploymentResponse {1 unmodified line space_url?: string; message: string; dev_mode?: boolean; repo_id?: string;}
export type Language = 'html' | 'gradio' | 'transformers.js' | 'streamlit' | 'comfyui' | 'react';frontend/src/app/page.tsx+83-7
frontend/src/components/ControlPanel.tsx+2-2
frontend/src/types/index.ts+3