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