|
7 | 7 |
|
8 | 8 | import asyncio |
9 | 9 | import time # noqa: F401 |
10 | | -from typing import Optional |
| 10 | +from typing import Dict, Literal, Optional, overload, Tuple, Union |
11 | 11 |
|
12 | 12 | from agentrun.sandbox.api.aio_data import AioDataAPI |
13 | 13 | from agentrun.sandbox.model import CodeLanguage, TemplateType |
| 14 | +from agentrun.utils.config import Config |
14 | 15 | from agentrun.utils.exception import ServerError |
15 | 16 | from agentrun.utils.log import logger |
16 | 17 |
|
@@ -453,13 +454,79 @@ async def check_health_async(self): |
453 | 454 | # Browser API Methods |
454 | 455 | # ======================================== |
455 | 456 |
|
456 | | - def get_cdp_url(self, record: Optional[bool] = False): |
457 | | - """Get CDP WebSocket URL for browser automation.""" |
458 | | - return self.data_api.get_cdp_url(record=record) |
| 457 | + @overload |
| 458 | + def get_cdp_url( |
| 459 | + self, |
| 460 | + record: Optional[bool] = False, |
| 461 | + *, |
| 462 | + with_headers: Literal[True], |
| 463 | + config: Optional[Config] = None, |
| 464 | + ) -> Tuple[str, Dict[str, str]]: |
| 465 | + ... |
| 466 | + |
| 467 | + @overload |
| 468 | + def get_cdp_url( |
| 469 | + self, |
| 470 | + record: Optional[bool] = False, |
| 471 | + *, |
| 472 | + with_headers: Literal[False] = False, |
| 473 | + config: Optional[Config] = None, |
| 474 | + ) -> str: |
| 475 | + ... |
| 476 | + |
| 477 | + def get_cdp_url( |
| 478 | + self, |
| 479 | + record: Optional[bool] = False, |
| 480 | + *, |
| 481 | + with_headers: bool = False, |
| 482 | + config: Optional[Config] = None, |
| 483 | + ) -> Union[str, Tuple[str, Dict[str, str]]]: |
| 484 | + """Get CDP WebSocket URL for browser automation. |
| 485 | +
|
| 486 | + Args: |
| 487 | + record: Whether to enable recording / 是否启用录制 |
| 488 | + with_headers: If True, return (url, headers) tuple with authentication headers. |
| 489 | + 当为 True 时,返回 (url, headers) 元组,包含鉴权头信息。 |
| 490 | + config: Optional config override / 可选的配置覆盖 |
| 491 | + """ |
| 492 | + return self.data_api.get_cdp_url(record=record, with_headers=with_headers, config=config) # type: ignore[call-overload] |
459 | 493 |
|
460 | | - def get_vnc_url(self, record: Optional[bool] = False): |
461 | | - """Get VNC WebSocket URL for live view.""" |
462 | | - return self.data_api.get_vnc_url(record=record) |
| 494 | + @overload |
| 495 | + def get_vnc_url( |
| 496 | + self, |
| 497 | + record: Optional[bool] = False, |
| 498 | + *, |
| 499 | + with_headers: Literal[True], |
| 500 | + config: Optional[Config] = None, |
| 501 | + ) -> Tuple[str, Dict[str, str]]: |
| 502 | + ... |
| 503 | + |
| 504 | + @overload |
| 505 | + def get_vnc_url( |
| 506 | + self, |
| 507 | + record: Optional[bool] = False, |
| 508 | + *, |
| 509 | + with_headers: Literal[False] = False, |
| 510 | + config: Optional[Config] = None, |
| 511 | + ) -> str: |
| 512 | + ... |
| 513 | + |
| 514 | + def get_vnc_url( |
| 515 | + self, |
| 516 | + record: Optional[bool] = False, |
| 517 | + *, |
| 518 | + with_headers: bool = False, |
| 519 | + config: Optional[Config] = None, |
| 520 | + ) -> Union[str, Tuple[str, Dict[str, str]]]: |
| 521 | + """Get VNC WebSocket URL for live view. |
| 522 | +
|
| 523 | + Args: |
| 524 | + record: Whether to enable recording / 是否启用录制 |
| 525 | + with_headers: If True, return (url, headers) tuple with authentication headers. |
| 526 | + 当为 True 时,返回 (url, headers) 元组,包含鉴权头信息。 |
| 527 | + config: Optional config override / 可选的配置覆盖 |
| 528 | + """ |
| 529 | + return self.data_api.get_vnc_url(record=record, with_headers=with_headers, config=config) # type: ignore[call-overload] |
463 | 530 |
|
464 | 531 | def sync_playwright(self, record: Optional[bool] = False): |
465 | 532 | """Get synchronous Playwright browser instance.""" |
|
0 commit comments