On this page
The five project-scoped variant-preset mutations mirroring the client store, with client-minted ids, apply-or-reject guards, and validated meta-snapshot undo records.
#server.src.pixelweaver.variant_ops
#server.src.pixelweaver.variant_ops
Project-scoped variant-preset mutations (the five preset-mutating commands).
A faithful, MCP-agnostic mirror of the client variant-state.svelte.ts store (plain ProjectState + params in, meta_snapshot record out -- exactly like frame_tag_ops / level_ops). Each function does a read-modify-write on project.variant_presets (the client-canonical VariantPreset[] list) against a deep copy and returns a meta_snapshot undo record for the variant_presets project attribute (before/after the whole list), applied by undo_history.
Design rules honored: - Client-minted ids: add_preset replays the id the client minted (stabilize-in-execute); add_generated_presets replays the WHOLE computed presets (id + name + groupOverrides) the client embedded -- the client computes with crypto / Math.random the server cannot reproduce, so the server replays the RESULT verbatim (the preview_randomize pattern). - Apply-or-reject: the mutators hard-error when their target preset is missing rather than silently no-op (a forwarded mutation only fires after the client changed its local state, so a missing target is a real divergence). - Validated writes: every commit routes through set_variant_presets so the stored list is always schema-valid and id-unique.
#add_preset
def add_preset(project: ProjectState, *, preset_id: str, name: str) -> dict[str, Any]Append a fresh, empty preset (client-minted id embedded). Mirror of addPreset.
#remove_preset
def remove_preset(project: ProjectState, *, preset_id: str) -> dict[str, Any]Remove a preset by id. Mirror of removePreset (hard error if missing).
#set_color_override
def set_color_override(project: ProjectState, *, preset_id: str, group_id: str, original_color: str, new_color: str) -> dict[str, Any]Set one group's original->replacement color override. Mirror of setColorOverride.
#remove_color_override
def remove_color_override(project: ProjectState, *, preset_id: str, group_id: str, original_color: str) -> dict[str, Any]Remove one color override (empties collapse). Mirror of removeColorOverride.
Missing group/color is a no-op (matches the client), but a missing PRESET is a hard error (apply-or-reject -- the forwarded command targets a preset the client just mutated, so its absence server-side is a real divergence).
#add_generated_presets
def add_generated_presets(project: ProjectState, *, presets: list[dict[str, Any]]) -> dict[str, Any]Append the client-computed presets verbatim (generate_variants result).
The client generates variants with crypto ids + Math.random HSV shifts the server cannot reproduce, so it embeds the WHOLE resulting presets (the preview_randomize pattern) and the server replays them. Each embedded preset is structurally validated and must not collide with an existing id. An empty list is a valid no-op (the client hit a guard -- no target / empty palette / too-few presets for interpolation -- but still forwarded).