support more anthropic actions (#2257)

This commit is contained in:
Shuchang Zheng
2025-04-30 18:42:44 +08:00
committed by GitHub
parent f932d7d704
commit 1a33810f09
4 changed files with 369 additions and 130 deletions

View File

@@ -1,6 +1,6 @@
from datetime import datetime
from enum import StrEnum
from typing import Annotated, Any, Type, TypeVar
from typing import Annotated, Any, Literal, Type, TypeVar
import structlog
from litellm import ConfigDict
@@ -28,12 +28,14 @@ class ActionType(StrEnum):
RELOAD_PAGE = "reload_page"
EXTRACT = "extract"
VERIFICATION_CODE = "verification_code"
SCROLL = "scroll"
KEYPRESS = "keypress"
TYPE = "type"
MOVE = "move"
DRAG = "drag"
VERIFICATION_CODE = "verification_code"
LEFT_MOUSE = "left_mouse"
def is_web_action(self) -> bool:
return self in [
@@ -271,8 +273,8 @@ class ExtractAction(Action):
class ScrollAction(Action):
action_type: ActionType = ActionType.SCROLL
x: int
y: int
x: int | None = None
y: int | None = None
scroll_x: int
scroll_y: int
@@ -280,6 +282,8 @@ class ScrollAction(Action):
class KeypressAction(Action):
action_type: ActionType = ActionType.KEYPRESS
keys: list[str] = []
hold: bool = False
duration: int = 0
class MoveAction(Action):
@@ -290,8 +294,8 @@ class MoveAction(Action):
class DragAction(Action):
action_type: ActionType = ActionType.DRAG
start_x: int
start_y: int
start_x: int | None = None
start_y: int | None = None
path: list[tuple[int, int]] = []
@@ -300,6 +304,13 @@ class VerificationCodeAction(Action):
verification_code: str
class LeftMouseAction(Action):
action_type: ActionType = ActionType.LEFT_MOUSE
direction: Literal["down", "up"]
x: int | None = None
y: int | None = None
class ScrapeResult(BaseModel):
"""
Scraped response from a webpage, including: