-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathplaywright_base_tool.py
More file actions
57 lines (48 loc) · 1.8 KB
/
Copy pathplaywright_base_tool.py
File metadata and controls
57 lines (48 loc) · 1.8 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
from typing import Any
from askui.models.shared.tool_tags import ToolTags
from askui.models.shared.tools import ToolWithAgentOS
from askui.tools.agent_os import AgentOs
from askui.tools.agent_os_type_error import AgentOsTypeError
from askui.tools.android.agent_os import AndroidAgentOs
from askui.tools.playwright.agent_os import PlaywrightAgentOs
class PlaywrightBaseTool(ToolWithAgentOS):
"""Tool base class that has an the Playwright AgentOs available."""
def __init__(
self,
agent_os: AgentOs | None = None,
required_tags: list[str] | None = None,
**kwargs: Any,
) -> None:
super().__init__(
required_tags=[ToolTags.PLAYWRIGHT.value] + (required_tags or []),
agent_os=agent_os,
**kwargs,
)
@property
def agent_os(self) -> PlaywrightAgentOs:
"""Get the agent OS.
Returns:
PlaywrightAgentOs: The Playwright agent OS instance.
"""
agent_os = super().agent_os
if not isinstance(agent_os, PlaywrightAgentOs):
raise AgentOsTypeError(
expected_type=PlaywrightAgentOs,
actual_type=type(agent_os),
)
return agent_os
@agent_os.setter
def agent_os(self, agent_os: AgentOs | AndroidAgentOs | PlaywrightAgentOs) -> None:
"""Set the agent OS.
Args:
agent_os (AgentOs | AndroidAgentOs | PlaywrightAgentOs): The agent OS
instance to set.
Raises:
TypeError: If the agent OS is not an `PlaywrightAgentOs` instance.
"""
if not isinstance(agent_os, PlaywrightAgentOs):
raise AgentOsTypeError(
expected_type=PlaywrightAgentOs,
actual_type=type(agent_os),
)
self._agent_os = agent_os