CoolFace
Apppublic

Ar-Srivas/BitWise_CSS_env

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
models.py127 linesDownload Raw Back to root
1# Copyright (c) Meta Platforms, Inc. and affiliates.2# All rights reserved.3#4# This source code is licensed under the BSD-style license found in the5# LICENSE file in the root directory of this source tree.6 7"""8Data models for the Css Env Environment.9 10The css_env environment is a simple test environment that echoes back messages.11"""12 13from openenv.core.env_server.types import Action, Observation14from pydantic import BaseModel, Field15 16from typing import Optional, Literal, Dict, List17 18class CssAction(Action):19    """20    Structured action for modifying CSS.21    """22 23    action_type: Literal[24        "replace_color",25        "fix_spacing",26        "fix_typography",27        "fix_contrast",28        "add_breakpoint",29        "remove_rule"30    ] = Field(..., description="Type of CSS transformation")31 32    target: str = Field(33        ...,34        description=(35            "Target of the action. Examples:\n"36            "- replace_color: old color value (e.g. '#1a73e7')\n"37            "- fix_spacing: 'selector.property' (e.g. '.card.margin')\n"38            "- fix_typography: 'selector.property'\n"39            "- fix_contrast: selector (e.g. '.text')\n"40            "- add_breakpoint: breakpoint value (e.g. '768px')\n"41            "- remove_rule: selector (e.g. '.unused-class')"42        )43    )44 45    value: Optional[str] = Field(46        default=None,47        description=(48            "New value for the action. Examples:\n"49            "- replace_color: new color (e.g. '#1a6fe0')\n"50            "- fix_spacing: '16px'\n"51            "- fix_typography: '18px'\n"52            "- fix_contrast: 'fg_color,bg_color'\n"53            "- add_breakpoint: CSS rule block\n"54            "- remove_rule: None"55        )56    )57 58 59class CssObservation(Observation):60    """61    Observation returned to the agent.62    """63 64    html: str = Field(..., description="HTML of the component")65 66    css: str = Field(..., description="Current CSS stylesheet")67 68    tokens: Dict = Field(69        ...,70        description="Design system tokens (colors, spacing, typography, breakpoints)"71    )72 73    violations: Optional[List[Dict[str, str]]] = Field(74        default=None,75        description="List of violations (only present in easy task)"76    )77 78    scores: Optional[Dict[str, float]] = Field(79        default=None,80        description="Latest grader scores by rubric name"81    )82 83    score: Optional[float] = Field(84        default=None,85        description="Task score in [0, 1] based on the minimum grader score"86    )87 88    success: Optional[bool] = Field(89        default=None,90        description="True only when all grader scores exceed the task threshold"91    )92 93    changed: Optional[bool] = Field(94        default=None,95        description="Whether this action changed CSS content"96    )97 98    no_op_action: Optional[bool] = Field(99        default=None,100        description="True when old and new CSS are identical"101    )102 103    repeated_action: Optional[bool] = Field(104        default=None,105        description="True when this action matches the previous action signature"106    )107 108    terminated_by_max_steps: Optional[bool] = Field(109        default=None,110        description="True when episode ended due to step limit before success"111    )112 113 114class GradeResult(BaseModel):115    """Structured grade payload for environment-level grading."""116 117    score: float = Field(..., description="Overall weighted score in [0, 1]")118 119    breakdown: Dict[str, float] = Field(120        default_factory=dict,121        description="Per-component grader scores included in the active rubric",122    )123 124    details: Dict[str, str] = Field(125        default_factory=dict,126        description="Human-readable explanation per grading component",127    )