fix
Browse filesFiles changed (2)
158 unmodified lines15916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321414 unmodified lines2292302312322332342357 unmodified lines24324424524624724824911 unmodified lines2612622632642652662671 unmodified line2692702712722732742752762772782792802812822832842852 unmodified lines2882892902912922935 unmodified lines299300301302303304305158 unmodified linesconst handleDeploy = async () => {if (!generatedCode) {alert('No code to deploy! Generate some code first.');return;}// Determine if we're updating an existing space or creating a new onelet existingRepoId = currentRepoId;let actionMessage = 'Deploy';// If we have a current repo, check if user owns itif (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 insteadactionMessage = 'Deploy';}} else {// User doesn't own the imported space, create a new oneexistingRepoId = null;actionMessage = 'Deploy';}}// Only prompt for space name if creating new spacelet spaceName = undefined;if (!existingRepoId) {const input = prompt('Enter HuggingFace Space name (or leave empty for auto-generated):');if (input === null) return; // User cancelledspaceName = input || undefined;}try {console.log('[Deploy] Deploying with params:', {language: selectedLanguage,space_name: spaceName,existing_repo_id: existingRepoId,currentRepoId: currentRepoId,username: username,code_length: generatedCode.length});const response = await apiClient.deploy({code: generatedCode,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 back14 unmodified linesrole: 'assistant',content: existingRepoId? `β Updated space: ${response.space_url}`: `β Deployed to: ${response.space_url}`,timestamp: new Date().toISOString(),};setMessages((prev) => [...prev, deployMessage]);7 unmodified lines? 'π 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}`;alert(message);} else {alert(`Deployment failed: ${response.message}`);11 unmodified lines};const handleImport = (code: string, language: Language, importUrl?: string) => {console.log('[Import] Importing project:', { language, importUrl, username });setGeneratedCode(code);setSelectedLanguage(language);1 unmodified lineif (importUrl) {const spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);console.log('[Import] Regex match result:', spaceMatch);if (spaceMatch) {const importedRepoId = spaceMatch[1];console.log('[Import] Extracted repo_id:', importedRepoId, 'Username:', username);// Only set as current repo if user owns itif (username && importedRepoId.startsWith(`${username}/`)) {setCurrentRepoId(importedRepoId);console.log('[Import] β Set current repo to:', importedRepoId);} else {// User doesn't own the imported space, clear current reposetCurrentRepoId(null);console.log('[Import] β οΈ User does not own imported space:', importedRepoId, '(username:', username, ')');}} else {console.log('[Import] β οΈ Could not extract repo_id from URL:', importUrl);2 unmodified linesconsole.log('[Import] No import URL provided');}// Add messages that include the imported code so LLM can see itconst userMessage: Message = {role: 'user',5 unmodified linesconst assistantMessage: Message = {role: 'assistant',content: `β I've loaded your ${language} project. The code is now in the editor. You can ask me to:\n\nβ’ Modify existing features\nβ’ Add new functionality\nβ’ Fix bugs or improve code\nβ’ Explain how it works\nβ’ Deploy it to HuggingFace Spaces\n\nWhat would you like me to help you with?`,timestamp: new Date().toISOString(),};158 unmodified lines15916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221314 unmodified lines2282292302312322332347 unmodified lines24224324424524624724811 unmodified lines2602612622632642652662672682692702711 unmodified line2732742752762772782792802812822832842852862872882892902912922932942952962972982993003013022 unmodified lines3053063073083093103113125 unmodified lines318319320321322323324158 unmodified linesconst handleDeploy = async () => {if (!generatedCode) {alert('No code to publish! Generate some code first.');return;}// Determine if we're updating an existing space or creating a new onelet existingRepoId = currentRepoId;// If we have a current repo, check if user owns itif (currentRepoId && username) {const ownsSpace = currentRepoId.startsWith(`${username}/`);if (ownsSpace) {// Update existing space without askingconsole.log('[Deploy] Updating existing space:', currentRepoId);} else {// User doesn't own the imported space, create a new oneexistingRepoId = null;console.log('[Deploy] Creating new space (user does not own imported space)');}} else {console.log('[Deploy] Creating new space (no current repo)');}// Auto-generate space name (never prompt user)let spaceName = undefined; // undefined = backend will auto-generatetry {console.log('[Deploy] ========== DEPLOY START ==========');console.log('[Deploy] Current username:', username);console.log('[Deploy] Current repo ID (state):', currentRepoId);console.log('[Deploy] Existing repo ID (var):', existingRepoId);console.log('[Deploy] Space name:', spaceName);console.log('[Deploy] Language:', selectedLanguage);console.log('[Deploy] Code length:', generatedCode.length);console.log('[Deploy] ========================================');const deployRequest = {code: generatedCode,space_name: spaceName,language: selectedLanguage,existing_repo_id: existingRepoId || undefined,commit_message: existingRepoId ? 'Update via AnyCoder' : undefined,};console.log('[Deploy] π Sending request to backend:', JSON.stringify({...deployRequest,code: `${deployRequest.code.substring(0, 100)}... (${deployRequest.code.length} chars)`}, null, 2));const response = await apiClient.deploy(deployRequest);if (response.success) {// Update current repo ID if we got one back14 unmodified linesrole: 'assistant',content: existingRepoId? `β Updated space: ${response.space_url}`: `β Published to: ${response.space_url}`,timestamp: new Date().toISOString(),};setMessages((prev) => [...prev, deployMessage]);7 unmodified lines? 'π Opening HuggingFace Spaces creation page...\nPlease complete the space setup in the new tab.': existingRepoId? `β Updated successfully!\n\nOpening: ${response.space_url}`: `β Published successfully!\n\nOpening: ${response.space_url}`;alert(message);} else {alert(`Deployment failed: ${response.message}`);11 unmodified lines};const handleImport = (code: string, language: Language, importUrl?: string) => {console.log('[Import] ========== IMPORT START ==========');console.log('[Import] Language:', language);console.log('[Import] Import URL:', importUrl);console.log('[Import] Current username:', username);console.log('[Import] Current repo before import:', currentRepoId);setGeneratedCode(code);setSelectedLanguage(language);1 unmodified lineif (importUrl) {const spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);console.log('[Import] Regex match result:', spaceMatch);if (spaceMatch) {const importedRepoId = spaceMatch[1];const importedUsername = importedRepoId.split('/')[0];console.log('[Import] ========================================');console.log('[Import] Extracted repo_id:', importedRepoId);console.log('[Import] Imported username:', importedUsername);console.log('[Import] Logged-in username:', username);console.log('[Import] Ownership check:', importedUsername === username);console.log('[Import] ========================================');// 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);if (!username) {console.log('[Import] β οΈβ οΈβ οΈ USERNAME IS NULL - Cannot set repo ownership!');} else {console.log('[Import] β οΈ User does not own imported space:', importedRepoId, '(username:', username, ')');}}} else {console.log('[Import] β οΈ Could not extract repo_id from URL:', importUrl);2 unmodified linesconsole.log('[Import] No import URL provided');}console.log('[Import] ========== IMPORT END ==========');// Add messages that include the imported code so LLM can see itconst userMessage: Message = {role: 'user',5 unmodified linesconst assistantMessage: Message = {role: 'assistant',content: `β I've loaded your ${language} project. The code is now in the editor. You can ask me to:\n\nβ’ Modify existing features\nβ’ Add new functionality\nβ’ Fix bugs or improve code\nβ’ Explain how it works\nβ’ Publish it to HuggingFace Spaces\n\nWhat would you like me to help you with?`,timestamp: new Date().toISOString(),};
175 unmodified lines17617717817918018118212 unmodified lines195196197198199200201175 unmodified linesclassName="w-full px-4 py-3.5 bg-[#007aff] text-white text-sm rounded-xl hover:bg-[#0051d5] disabled:opacity-50 disabled:cursor-not-allowed transition-all font-semibold flex items-center justify-center space-x-2 shadow-md active:scale-95"><span>π</span><span>Deploy</span></button><buttononClick={onClear}12 unmodified lines<li>β’ Import projects from HF/GitHub</li><li>β’ Be specific in your requirements</li><li>β’ Try different AI models</li><li>β’ Deploy to HF Spaces</li></ul></div>175 unmodified lines17617717817918018118212 unmodified lines195196197198199200201175 unmodified linesclassName="w-full px-4 py-3.5 bg-[#007aff] text-white text-sm rounded-xl hover:bg-[#0051d5] disabled:opacity-50 disabled:cursor-not-allowed transition-all font-semibold flex items-center justify-center space-x-2 shadow-md active:scale-95"><span>π</span><span>Publish</span></button><buttononClick={onClear}12 unmodified lines<li>β’ Import projects from HF/GitHub</li><li>β’ Be specific in your requirements</li><li>β’ Try different AI models</li><li>β’ Publish to HF Spaces</li></ul></div>
frontend/src/app/page.tsx+52-33
frontend/src/components/ControlPanel.tsx+2-2