Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
Fix select-and-edit losing the element reference on imported projects
Abi Raja3aebd3c37d98
diff --git a/backend/prompts/prompt_types.py b/backend/prompts/prompt_types.pyindex 08020652..68324199 100644--- a/backend/prompts/prompt_types.py+++ b/backend/prompts/prompt_types.py@@ -1,14 +1,20 @@from typing import List, Literal, TypedDict-class UserTurnInput(TypedDict):- """Normalized current user turn payload from the request."""-+class _UserTurnInputRequired(TypedDict):text: strimages: List[str]videos: List[str]+class UserTurnInput(_UserTurnInputRequired, total=False):+ """Normalized current user turn payload from the request."""++ # Full instruction for the model when it differs from the display text+ # (e.g. includes the selected-element reference, built by the frontend).+ full_text: str++class PromptHistoryMessage(TypedDict):"""Explicit role-based message structure for edit history."""diff --git a/backend/prompts/request_parsing.py b/backend/prompts/request_parsing.pyindex 6ac7f81a..b54bfdfd 100644--- a/backend/prompts/request_parsing.py+++ b/backend/prompts/request_parsing.py@@ -16,12 +16,18 @@ def parse_prompt_content(raw_prompt: object) -> UserTurnInput:prompt_dict = cast(dict[str, object], raw_prompt)text = prompt_dict.get("text")- return {+ parsed: UserTurnInput = {"text": text if isinstance(text, str) else "","images": _to_string_list(prompt_dict.get("images")),"videos": _to_string_list(prompt_dict.get("videos")),}+ full_text = prompt_dict.get("fullText")+ if isinstance(full_text, str) and full_text.strip():+ parsed["full_text"] = full_text++ return parsed+def parse_prompt_history(raw_history: object) -> List[PromptHistoryMessage]:if not isinstance(raw_history, list):diff --git a/backend/prompts/update/from_file_snapshot.py b/backend/prompts/update/from_file_snapshot.pyindex cc79be40..937b6df6 100644--- a/backend/prompts/update/from_file_snapshot.py+++ b/backend/prompts/update/from_file_snapshot.py@@ -17,7 +17,13 @@ def build_update_prompt_from_file_snapshot(design_system: str | None = None,) -> Prompt:path = file_state.get("path", "index.html")- request_text = prompt.get("text", "").strip() or "Apply the requested update."+ # full_text carries the complete model-facing instruction (e.g. with the+ # selected-element reference); text is the user-typed display string.+ request_text = (+ prompt.get("full_text", "").strip()+ or prompt.get("text", "").strip()+ or "Apply the requested update."+ )selected_stack = build_selected_stack_policy(stack)image_policy = build_user_image_policy(image_generation_enabled)design_system_block = build_design_system_prompt_block(design_system)diff --git a/backend/tests/test_update_from_file_snapshot.py b/backend/tests/test_update_from_file_snapshot.pynew file mode 100644index 00000000..163111f1--- /dev/null+++ b/backend/tests/test_update_from_file_snapshot.py@@ -0,0 +1,60 @@+from typing import Any, cast++from prompts.message_builder import Prompt+from prompts.request_parsing import parse_prompt_content+from prompts.update.from_file_snapshot import build_update_prompt_from_file_snapshot+++FILE_STATE = {"path": "index.html", "content": "<html><body><button>Buy</button></body></html>"}+++def _user_text(prompt_messages: Prompt) -> str:+ content = prompt_messages[1].get("content")+ if isinstance(content, str):+ return content+ parts = cast(list[dict[str, Any]], content)+ return cast(str, parts[0]["text"])+++def test_snapshot_prompt_prefers_full_text_over_display_text() -> None:+ prompt = parse_prompt_content(+ {+ "text": "Make this button red",+ "fullText": 'Make this button red\n\nApply the change to this element: <button class="btn">Buy</button>',+ "images": [],+ "videos": [],+ }+ )++ messages = build_update_prompt_from_file_snapshot(+ stack="html_tailwind",+ prompt=prompt,+ file_state=FILE_STATE,+ image_generation_enabled=False,+ )++ text = _user_text(messages)+ assert '<button class="btn">Buy</button>' in text+++def test_snapshot_prompt_falls_back_to_display_text() -> None:+ prompt = parse_prompt_content(+ {"text": "Make the header blue", "images": [], "videos": []}+ )++ messages = build_update_prompt_from_file_snapshot(+ stack="html_tailwind",+ prompt=prompt,+ file_state=FILE_STATE,+ image_generation_enabled=False,+ )++ assert "Make the header blue" in _user_text(messages)+++def test_parse_prompt_content_ignores_blank_full_text() -> None:+ prompt = parse_prompt_content(+ {"text": "Hello", "fullText": " ", "images": [], "videos": []}+ )++ assert "full_text" not in promptdiff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex 3fe11fd2..20040e26 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -678,6 +678,7 @@ function App() {inputMode,prompt: {text: updateInstruction,+ fullText: modifiedUpdateInstruction,images: updateImages,videos: [],selectedElementHtml,diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex 1c715ba0..8a70ef76 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -57,7 +57,10 @@ export interface PromptAsset {}export interface PromptContent {- text: string;+ text: string; // What the user typed (displayed in the UI)+ // Full instruction for the model when it differs from `text`+ // (e.g. includes the selected-element reference)+ fullText?: string;images: string[]; // Array of data URLsvideos?: string[]; // Array of data URLsselectedElementHtml?: string; // Raw HTML of selected element (for display only)