-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
103 lines (88 loc) · 2.71 KB
/
models.py
File metadata and controls
103 lines (88 loc) · 2.71 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
from enum import Enum
from pydantic import BaseModel, Field
from typing import Literal, Optional, List, Dict, Any, Union
from typing_extensions import Annotated
class AppContext(Enum):
UNKNOWN = "unknown"
SEARCH = "search"
PRODUCT_LIST = "product_list"
PRODUCT_DETAIL = "product_detail"
CART = "cart"
PAYMENT = "payment"
LOGIN = "login"
# Rest of your models remain the same...
class UIElement(BaseModel):
uid: int
resource_id: Optional[str] = None
text: Optional[str] = None
content_desc: Optional[str] = None
class_name: Optional[str] = Field(None, alias='class')
bounds: tuple[int, int, int, int]
center: tuple[int, int]
clickable: bool
scrollable: bool
semantic_role: Optional[str] = None
class DeviceState(BaseModel):
activity_name: str
package_name: str
elements: List[UIElement]
class SemanticState(BaseModel):
activity_name: str
package_name: str
elements: List[UIElement]
app_context: AppContext
detected_patterns: List[str]
confidence: float
class SubTask(BaseModel):
id: str
goal: str
verification: str
max_attempts: int = 3
attempts: int = 0
status: Literal["pending", "in_progress", "completed", "failed"] = "pending"
class TaskPlan(BaseModel):
main_goal: str
subtasks: List[SubTask]
current_subtask_index: int = 0
context: Dict[str, Any] = {}
class AgentMemory(BaseModel):
session_id: str
previous_actions: List[Dict] = []
completed_subtasks: List[str] = []
current_context: Dict[str, Any] = {}
navigation_stack: List[str] = []
extracted_data: Dict[str, Any] = {}
class TapAction(BaseModel):
action: Literal['tap'] = 'tap'
uid: int
explanation: str
class TypeAction(BaseModel):
action: Literal['type'] = 'type'
uid: int
text: str
explanation: str
class SwipeAction(BaseModel):
action: Literal['swipe'] = 'swipe'
uid: Optional[int] = None
direction: Literal['up', 'down', 'left', 'right']
distance: str
explanation: str
class NavigateAction(BaseModel):
action: Literal['navigate'] = 'navigate'
url: str
explanation: str
class BackAction(BaseModel):
action: Literal['back'] = 'back'
explanation: str
class OpenAppAction(BaseModel):
action: Literal['open_app'] = 'open_app'
app_name: str
package_name: Optional[str] = None
explanation: str
class FinishAction(BaseModel):
action: Literal['finish'] = 'finish'
explanation: str
Action = Annotated[
Union[TapAction, TypeAction, SwipeAction, NavigateAction, BackAction, OpenAppAction, FinishAction],
Field(discriminator='action')
]