Replace one file in a design
update_variation_fileReplace the code of a SINGLE file that already exists in a design variation, leaving every other file and all content untouched. It never creates a file: to add a NEW page you wrote, use add_page with code. Use this for targeted code edits — a colour, a layout tweak, one section — instead of resending the whole design through import_design_variation, which burns a variation slot and re-uploads everything. Start from the current code returned by read_design (requires source:read) — send the COMPLETE file, not a fragment. The patched file is run through the same validation a full import gets; if it fails, NOTHING is written and the issues come back. On success the edit is recorded in version history (version in the response) so it shows in list_versions and can be undone with restore_version; a history_warning means it saved but was not recorded. Omit index to patch the site's active design. PAGE DRAFTS: pass the draft's slug (from create_page_draft / list_page_drafts) as file and its design's index to edit the draft instead of the live page. A draft must keep reading its own text (content.<content_key>); code that reads the live page's key is refused, because the draft would then edit the live page.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Complete new TSX for that file — same authoring contract as create_site_from_design | |
| file | Yes | File name or slug to replace, e.g. "Header", "/" for the homepage, or a page draft's slug such as "/about--draft-7f2a" | |
| index | No | Variation index from list_variations. Defaults to the active design. | |
| site_id | Yes | The site to patch | |
| user_goal | No | Optional: the user's goal behind this call, in one short sentence of plain words (e.g. "add a page so customers can book tables"). No names, emails or other personal details. | |
| expected_row_version | No | The `row_version` read_design returned. The edit is refused with a conflict if the design changed since. Required to remove live menu links (navigation/footer). |