update import and deploy
Browse filesFiles changed (3)
16 unmodified lines1718192021225 unmodified lines282930313233342 unmodified lines373839404142108 unmodified lines1511521531541551561571581591601611621631641651661671 unmodified line16917017117217317417510 unmodified lines18618718818919019119219319419519619719819916 unmodified linesconst [selectedModel, setSelectedModel] = useState('gemini-3.0-pro');const [isGenerating, setIsGenerating] = useState(false);const [isAuthenticated, setIsAuthenticated] = useState(false);// Mobile view state: 'chat', 'editor', or 'settings'const [mobileView, setMobileView] = useState<'chat' | 'editor' | 'settings'>('editor');5 unmodified linesreturn () => clearInterval(interval);}, []);const checkAuth = () => {const authenticated = checkIsAuthenticated();setIsAuthenticated(authenticated);2 unmodified linesconst token = getStoredToken();if (token) {apiClient.setToken(token);}}};108 unmodified linesreturn;}const spaceName = prompt('Enter HuggingFace Space name (or leave empty for auto-generated):');if (spaceName === null) return; // User cancelledtry {const response = await apiClient.deploy({code: generatedCode,space_name: spaceName || undefined,language: selectedLanguage,});if (response.success) {// Open the space URL in a new tabwindow.open(response.space_url, '_blank');1 unmodified lineconst isDev = response.dev_mode;const message = isDev? 'π Opening HuggingFace Spaces creation page...\nPlease complete the space setup in the new tab.': `β Deployed successfully!\n\nOpening: ${response.space_url}`;alert(message);} else {alert(`Deployment failed: ${response.message}`);10 unmodified lines}};const handleImport = (code: string, language: Language) => {setGeneratedCode(code);setSelectedLanguage(language);// Add messages that include the imported code so LLM can see itconst userMessage: Message = {role: 'user',content: `I imported a ${language} project. Here's the code that was imported.`,timestamp: new Date().toISOString(),};16 unmodified lines17181920212223245 unmodified lines303132333435362 unmodified lines39404142434445464748495051525354108 unmodified lines1631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212221 unmodified line22422522622722822923023123210 unmodified lines24324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427516 unmodified linesconst [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 spaceconst [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 linesreturn () => clearInterval(interval);}, []);const checkAuth = async () => {const authenticated = checkIsAuthenticated();setIsAuthenticated(authenticated);2 unmodified linesconst token = getStoredToken();if (token) {apiClient.setToken(token);// Get username from auth statustry {const authStatus = await apiClient.getAuthStatus();if (authStatus.username) {setUsername(authStatus.username);}} catch (error) {console.error('Failed to get username:', error);}}}};108 unmodified linesreturn;}// 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 {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 backif (response.repo_id) {setCurrentRepoId(response.repo_id);}// Add deployment message to chatconst 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 tabwindow.open(response.space_url, '_blank');1 unmodified lineconst 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}`;alert(message);} else {alert(`Deployment failed: ${response.message}`);10 unmodified lines}};const handleImport = (code: string, language: Language, importUrl?: string) => {setGeneratedCode(code);setSelectedLanguage(language);// Extract repo_id from import URL if providedif (importUrl) {const spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);if (spaceMatch) {const importedRepoId = spaceMatch[1];// 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);}}}// Add messages that include the imported code so LLM can see itconst userMessage: Message = {role: 'user',content: importUrl? `Imported Space from ${importUrl}`: `I imported a ${language} project. Here's the code that was imported.`,timestamp: new Date().toISOString(),};
10 unmodified lines1112131415161765 unmodified lines8384858687888910 unmodified linesonModelChange: (modelId: string) => void;onDeploy: () => void;onClear: () => void;onImport?: (code: string, language: Language) => void;isGenerating: boolean;}65 unmodified lines// Call the onImport callback if providedif (onImport && result.code) {onImport(result.code, result.language || 'html');}// Close modal and reset10 unmodified lines1112131415161765 unmodified lines8384858687888910 unmodified linesonModelChange: (modelId: string) => void;onDeploy: () => void;onClear: () => void;onImport?: (code: string, language: Language, importUrl?: string) => void;isGenerating: boolean;}65 unmodified lines// Call the onImport callback if providedif (onImport && result.code) {onImport(result.code, result.language || 'html', importUrl);}// Close modal and reset
46 unmodified lines4748495051521 unmodified line54555657585946 unmodified linesspace_name?: string;language: string;requirements?: string;}export interface DeploymentResponse {1 unmodified linespace_url?: string;message: string;dev_mode?: boolean;}export type Language = 'html' | 'gradio' | 'transformers.js' | 'streamlit' | 'comfyui' | 'react';46 unmodified lines47484950515253541 unmodified line5657585960616246 unmodified linesspace_name?: string;language: string;requirements?: string;existing_repo_id?: string; // For updating existing spacescommit_message?: string;}export interface DeploymentResponse {1 unmodified linespace_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