MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / Desktop

Class Desktop

tests/lib/tools/toolsets/_computer_fakes.py:33–71  ·  view source on GitHub ↗

The desktop both fakes drive: the cursor, a call log, and what each member hands back.

Source from the content-addressed store, hash-verified

31
32
33class Desktop:
34 """The desktop both fakes drive: the cursor, a call log, and what each member hands back."""
35
36 def __init__(self) -> None:
37 self.cursor = (0, 0)
38 self.calls: list[str] = []
39 self.inputs: list[Any] = []
40 self.contexts: list[BetaToolsetCallContext] = []
41 self.fail: dict[str, BaseException] = {}
42 self.results: dict[str, Any] = {} # a member name -> the result to hand back instead of the usual one
43
44 def do(self, name: str, context: BetaToolsetCallContext, input: Any) -> Any:
45 self.calls.append(name)
46 self.inputs.append(input)
47 self.contexts.append(context)
48 if name in self.fail:
49 raise self.fail[name]
50 return self.results.get(name)
51
52 # member bodies -------------------------------------------------------------------------
53
54 def screenshot(self, context: BetaToolsetCallContext, input: BetaComputerScreenshotInput) -> BetaScreenshotResult:
55 return self.do("screenshot", context, input) or BetaScreenshotResult(data=PNG)
56
57 def zoom(self, context: BetaToolsetCallContext, input: BetaComputerZoomInput) -> BetaScreenshotResult:
58 return self.do("zoom", context, input) or BetaScreenshotResult(data=PNG, media_type="image/jpeg")
59
60 def cursor_position(
61 self, context: BetaToolsetCallContext, input: BetaComputerCursorPositionInput
62 ) -> BetaComputerCursorPositionResult:
63 x, y = self.cursor
64 return self.do("cursor_position", context, input) or BetaComputerCursorPositionResult(x=x, y=y)
65
66 def mouse_move(self, context: BetaToolsetCallContext, input: BetaComputerMouseMoveInput) -> str | None:
67 self.cursor = (input.coordinate[0], input.coordinate[1])
68 return self.do("mouse_move", context, input)
69
70 def action(self, name: str, context: BetaToolsetCallContext, input: Any) -> Any:
71 return self.do(name, context, input) # a pure action may hand back one line of text
72
73
74def approve(context: object) -> bool: # noqa: ARG001

Calls

no outgoing calls