fix
Browse filesFiles changed (2)
- backend_api.py+30-3
- backend_parsers.py+12-9
519 unmodified lines520521522523524525526527528529519 unmodified linestry:original_code = code# Special handling for transformers.js - preserve === markersif language == "transformers.js":# Don't clean transformers.js code - it needs the === markersreturn code# Special handling for ComfyUI JSONif language == "comfyui":519 unmodified lines520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556519 unmodified linestry:original_code = code# Special handling for transformers.js - extract only the === sectionsif language == "transformers.js":# Find the first === markerfirst_marker = code.find('===')if first_marker == -1:# No markers found, return as-isreturn code# Find the last code section end (after the last ===)# Look for the last === markerlast_marker_start = code.rfind('===')if last_marker_start == -1:return code# Find the end of the last code section# This is typically followed by explanatory text starting with --- or multiple newlinescode_after_last_marker = code[last_marker_start:]# Find where the actual code section ends (look for --- or excessive explanatory text)end_markers = ['---', '\n\n\nThis ', '\n\n\n✨', '\n\n\n🎨', '\n\n\n🚀']code_end = len(code)for end_marker in end_markers:pos = code.find(end_marker, last_marker_start)if pos != -1 and pos < code_end:code_end = pos# Extract from first === to end of codecleaned_code = code[first_marker:code_end].strip()return cleaned_code# Special handling for ComfyUI JSONif language == "comfyui":
17 unmodified lines181920212223242526272829303199 unmodified lines13113213313413513613713813917 unmodified linesprint(f"[Parser] Received code length: {len(code)} characters")print(f"[Parser] First 200 chars: {code[:200]}")# Auto-fix: If code doesn't start with === index.html ===, add itcode_stripped = code.strip()if not code_stripped.startswith('==='):print("[Parser] Auto-fixing: Adding missing === index.html === marker")code = '=== index.html ===\n' + codecode_stripped = code.strip()else:print("[Parser] Code starts with === marker, proceeding normally")# Check if code starts with HTML instead of markers (common LLM mistake)if code_stripped.startswith('<!DOCTYPE') or code_stripped.startswith('<html'):99 unmodified linesif not (files['index.html'] and files['index.js'] and files['style.css']):# Use regex to extract sections - match === markers with optional whitespace and newlines# Fixed lookahead to allow any whitespace (not just \n) before next === markerhtml_fallback = re.search(r'===\s*index\.html\s*===\s*[\r\n]*([\s\S]+?)(?=\s*===\s*index\.js\s*===|$)', code, re.IGNORECASE)js_fallback = re.search(r'===\s*index\.js\s*===\s*[\r\n]*([\s\S]+?)(?=\s*===\s*style\.css\s*===|$)', code, re.IGNORECASE)css_fallback = re.search(r'===\s*style\.css\s*===\s*[\r\n]*([\s\S]+?)$', code, re.IGNORECASE)print(f"[Parser] Fallback extraction - HTML found: {bool(html_fallback)}, JS found: {bool(js_fallback)}, CSS found: {bool(css_fallback)}")17 unmodified lines18192021222324252627282999 unmodified lines12913013113213313413513613713813914014114217 unmodified linesprint(f"[Parser] Received code length: {len(code)} characters")print(f"[Parser] First 200 chars: {code[:200]}")# Check if code has === markerscode_stripped = code.strip()if '===' in code_stripped:print("[Parser] Code contains === markers, proceeding with parsing")else:print("[Parser] WARNING: No === markers found in code")# Check if code starts with HTML instead of markers (common LLM mistake)if code_stripped.startswith('<!DOCTYPE') or code_stripped.startswith('<html'):99 unmodified linesif not (files['index.html'] and files['index.js'] and files['style.css']):# Use regex to extract sections - match === markers with optional whitespace and newlines# Fixed lookahead to allow any whitespace (not just \n) before next === marker# Also support alternative names: styles.css or style.css, app.js or index.jshtml_fallback = re.search(r'===\s*index\.html\s*===\s*[\r\n]*([\s\S]+?)(?=\s*===|$)', code, re.IGNORECASE)# Try both index.js and app.jsjs_fallback = re.search(r'===\s*(?:index\.js|app\.js)\s*===\s*[\r\n]*([\s\S]+?)(?=\s*===|$)', code, re.IGNORECASE)# Try both style.css and styles.csscss_fallback = re.search(r'===\s*(?:style\.css|styles\.css)\s*===\s*[\r\n]*([\s\S]+?)$', code, re.IGNORECASE)print(f"[Parser] Fallback extraction - HTML found: {bool(html_fallback)}, JS found: {bool(js_fallback)}, CSS found: {bool(css_fallback)}")
backend_api.py+30-3
backend_parsers.py+12-9