fix
Browse filesFiles changed (3)
206 unmodified lines207208209210211212698 unmodified lines91191291391491591691791891911 unmodified lines931932933934935936937938939940941942943944945946947948949950206 unmodified linesrequirements: Optional[str] = Noneexisting_repo_id: Optional[str] = None # For updating existing spacescommit_message: Optional[str] = Noneclass AuthStatus(BaseModel):698 unmodified linessession_token = authorization.replace("Bearer ", "") if authorization else Noneexisting_repo_id = request.existing_repo_id# ALWAYS check session for previously deployed spaces (even if frontend provides existing_repo_id)# This ensures we catch spaces that were deployed in this sessionif session_token and session_token in user_sessions:session = user_sessions[session_token]# Ensure deployed_spaces exists (for backward compatibility with old sessions)11 unmodified linesif space.get("language") == request.language:session_space_id = space.get("repo_id")print(f"[Deploy] ✅ Found existing space in session for {request.language}: {session_space_id}")# Use session space if no explicit existing_repo_id provided, OR if they matchif not existing_repo_id:existing_repo_id = session_space_idprint(f"[Deploy] Using session space: {existing_repo_id}")elif existing_repo_id != session_space_id:# Frontend and session disagree - trust the session (more recent)print(f"[Deploy] ⚠️ Frontend provided {existing_repo_id} but session has {session_space_id}. Using session.")existing_repo_id = session_space_idbreakif not existing_repo_id:print(f"[Deploy] ⚠️ No existing space found for language: {request.language}")else:print(f"[Deploy] ⚠️ No session found. session_token: {session_token[:10] if session_token else 'None'}")# Use the standalone deployment functionprint(f"[Deploy] ========== CALLING deploy_to_huggingface_space ==========")206 unmodified lines207208209210211212213698 unmodified lines91291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195211 unmodified lines964965966967968969970971972973974975976206 unmodified linesrequirements: Optional[str] = Noneexisting_repo_id: Optional[str] = None # For updating existing spacescommit_message: Optional[str] = Nonehistory: List[Dict] = [] # Chat history for tracking deployed spacesclass AuthStatus(BaseModel):698 unmodified linessession_token = authorization.replace("Bearer ", "") if authorization else Noneexisting_repo_id = request.existing_repo_id# PRIORITY 1: Check history for deployed/imported spaces (like Gradio version does)# This is more reliable than session tracking since history persists in frontendif request.history and auth.username:print(f"[Deploy] Checking history for deployed spaces ({len(request.history)} messages)...")for msg in request.history:role = msg.get('role', '')content = msg.get('content', '')# Check for deployment confirmationsif role == 'assistant' and ('✅ Deployed!' in content or '✅ Updated!' in content):import rematch = re.search(r'huggingface\.co/spaces/([^/\s\)]+/[^/\s\)]+)', content)if match:history_space_id = match.group(1)print(f"[Deploy] ✅ Found deployed space in history: {history_space_id}")if not existing_repo_id:existing_repo_id = history_space_idbreak# Check for importselif role == 'user' and 'import' in content.lower():import rematch = re.search(r'huggingface\.co/spaces/([^/\s\)]+/[^/\s\)]+)', content)if match:imported_space = match.group(1)# Only use if user owns itif imported_space.startswith(f"{auth.username}/"):print(f"[Deploy] ✅ Found imported space in history (user owns it): {imported_space}")if not existing_repo_id:existing_repo_id = imported_spacebreak# PRIORITY 2: Check session for previously deployed spaces (fallback)# This helps when history isn't passed from frontendif not existing_repo_id and session_token and session_token in user_sessions:session = user_sessions[session_token]# Ensure deployed_spaces exists (for backward compatibility with old sessions)11 unmodified linesif space.get("language") == request.language:session_space_id = space.get("repo_id")print(f"[Deploy] ✅ Found existing space in session for {request.language}: {session_space_id}")existing_repo_id = session_space_idbreakif not existing_repo_id:print(f"[Deploy] ⚠️ No existing space found for language: {request.language}")elif not existing_repo_id:print(f"[Deploy] ⚠️ No session found and no history provided. session_token: {session_token[:10] if session_token else 'None'}")# Use the standalone deployment functionprint(f"[Deploy] ========== CALLING deploy_to_huggingface_space ==========")
438 unmodified lines43944044144244344410 unmodified lines455456457458459460461438 unmodified linesconst deployRequest: any = {code: generatedCode,language: selectedLanguage,};// Only include optional fields if they have values10 unmodified linesspace_name: deployRequest.space_name,language: deployRequest.language,has_code: !!deployRequest.code,code_length: deployRequest.code?.length});console.log('[Deploy] Full request object:', JSON.stringify(deployRequest, null, 2).substring(0, 500));438 unmodified lines43944044144244344444510 unmodified lines456457458459460461462463438 unmodified linesconst deployRequest: any = {code: generatedCode,language: selectedLanguage,history: messages.map(msg => ({ role: msg.role, content: msg.content })) // Pass full chat history};// Only include optional fields if they have values10 unmodified linesspace_name: deployRequest.space_name,language: deployRequest.language,has_code: !!deployRequest.code,code_length: deployRequest.code?.length,history_length: deployRequest.history?.length});console.log('[Deploy] Full request object:', JSON.stringify(deployRequest, null, 2).substring(0, 500));
48 unmodified lines49505152535448 unmodified linesrequirements?: string;existing_repo_id?: string; // For updating existing spacescommit_message?: string;}export interface DeploymentResponse {48 unmodified lines4950515253545548 unmodified linesrequirements?: string;existing_repo_id?: string; // For updating existing spacescommit_message?: string;history?: Array<{role: string; content: string}>; // Chat history for tracking}export interface DeploymentResponse {
backend_api.py+39-13
frontend/src/app/page.tsx+3-1
frontend/src/types/index.ts+1