|
106 | 106 | from playwright._impl._fetch import APIRequestContext |
107 | 107 | from playwright._impl._locator import FrameLocator, Locator |
108 | 108 | from playwright._impl._network import WebSocket |
| 109 | + from playwright._impl._page_agent import PageAgent |
109 | 110 |
|
110 | 111 |
|
111 | 112 | class LocatorHandler: |
@@ -1117,6 +1118,45 @@ def workers(self) -> List["Worker"]: |
1117 | 1118 | def request(self) -> "APIRequestContext": |
1118 | 1119 | return self.context.request |
1119 | 1120 |
|
| 1121 | + async def agent( |
| 1122 | + self, |
| 1123 | + provider: Dict[str, Any] = None, |
| 1124 | + cache: Dict[str, str] = None, |
| 1125 | + maxTokens: int = None, |
| 1126 | + maxTurns: int = None, |
| 1127 | + secrets: Dict[str, str] = None, |
| 1128 | + systemPrompt: str = None, |
| 1129 | + ) -> "PageAgent": |
| 1130 | + from playwright._impl._page_agent import PageAgent |
| 1131 | + |
| 1132 | + params: Dict[str, Any] = {} |
| 1133 | + if provider is not None: |
| 1134 | + if "api" in provider: |
| 1135 | + params["api"] = provider["api"] |
| 1136 | + if "apiEndpoint" in provider: |
| 1137 | + params["apiEndpoint"] = provider["apiEndpoint"] |
| 1138 | + if "apiKey" in provider: |
| 1139 | + params["apiKey"] = provider["apiKey"] |
| 1140 | + if "model" in provider: |
| 1141 | + params["model"] = provider["model"] |
| 1142 | + if cache is not None: |
| 1143 | + if "cacheFile" in cache: |
| 1144 | + params["cacheFile"] = cache["cacheFile"] |
| 1145 | + if "cacheOutFile" in cache: |
| 1146 | + params["cacheOutFile"] = cache["cacheOutFile"] |
| 1147 | + if maxTokens is not None: |
| 1148 | + params["maxTokens"] = maxTokens |
| 1149 | + if maxTurns is not None: |
| 1150 | + params["maxTurns"] = maxTurns |
| 1151 | + if secrets is not None: |
| 1152 | + params["secrets"] = [ |
| 1153 | + {"name": name, "value": value} for name, value in secrets.items() |
| 1154 | + ] |
| 1155 | + if systemPrompt is not None: |
| 1156 | + params["systemPrompt"] = systemPrompt |
| 1157 | + result = await self._channel.send_return_as_dict("agent", None, params) |
| 1158 | + return from_channel(result["agent"]) |
| 1159 | + |
1120 | 1160 | async def pause(self) -> None: |
1121 | 1161 | default_navigation_timeout = ( |
1122 | 1162 | self._browser_context._timeout_settings.default_navigation_timeout() |
|
0 commit comments