optexity-browser-use 0.9.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. browser_use/__init__.py +157 -0
  2. browser_use/actor/__init__.py +11 -0
  3. browser_use/actor/element.py +1175 -0
  4. browser_use/actor/mouse.py +134 -0
  5. browser_use/actor/page.py +561 -0
  6. browser_use/actor/playground/flights.py +41 -0
  7. browser_use/actor/playground/mixed_automation.py +54 -0
  8. browser_use/actor/playground/playground.py +236 -0
  9. browser_use/actor/utils.py +176 -0
  10. browser_use/agent/cloud_events.py +282 -0
  11. browser_use/agent/gif.py +424 -0
  12. browser_use/agent/judge.py +170 -0
  13. browser_use/agent/message_manager/service.py +473 -0
  14. browser_use/agent/message_manager/utils.py +52 -0
  15. browser_use/agent/message_manager/views.py +98 -0
  16. browser_use/agent/prompts.py +413 -0
  17. browser_use/agent/service.py +2316 -0
  18. browser_use/agent/system_prompt.md +185 -0
  19. browser_use/agent/system_prompt_flash.md +10 -0
  20. browser_use/agent/system_prompt_no_thinking.md +183 -0
  21. browser_use/agent/views.py +743 -0
  22. browser_use/browser/__init__.py +41 -0
  23. browser_use/browser/cloud/cloud.py +203 -0
  24. browser_use/browser/cloud/views.py +89 -0
  25. browser_use/browser/events.py +578 -0
  26. browser_use/browser/profile.py +1158 -0
  27. browser_use/browser/python_highlights.py +548 -0
  28. browser_use/browser/session.py +3225 -0
  29. browser_use/browser/session_manager.py +399 -0
  30. browser_use/browser/video_recorder.py +162 -0
  31. browser_use/browser/views.py +200 -0
  32. browser_use/browser/watchdog_base.py +260 -0
  33. browser_use/browser/watchdogs/__init__.py +0 -0
  34. browser_use/browser/watchdogs/aboutblank_watchdog.py +253 -0
  35. browser_use/browser/watchdogs/crash_watchdog.py +335 -0
  36. browser_use/browser/watchdogs/default_action_watchdog.py +2729 -0
  37. browser_use/browser/watchdogs/dom_watchdog.py +817 -0
  38. browser_use/browser/watchdogs/downloads_watchdog.py +1277 -0
  39. browser_use/browser/watchdogs/local_browser_watchdog.py +461 -0
  40. browser_use/browser/watchdogs/permissions_watchdog.py +43 -0
  41. browser_use/browser/watchdogs/popups_watchdog.py +143 -0
  42. browser_use/browser/watchdogs/recording_watchdog.py +126 -0
  43. browser_use/browser/watchdogs/screenshot_watchdog.py +62 -0
  44. browser_use/browser/watchdogs/security_watchdog.py +280 -0
  45. browser_use/browser/watchdogs/storage_state_watchdog.py +335 -0
  46. browser_use/cli.py +2359 -0
  47. browser_use/code_use/__init__.py +16 -0
  48. browser_use/code_use/formatting.py +192 -0
  49. browser_use/code_use/namespace.py +665 -0
  50. browser_use/code_use/notebook_export.py +276 -0
  51. browser_use/code_use/service.py +1340 -0
  52. browser_use/code_use/system_prompt.md +574 -0
  53. browser_use/code_use/utils.py +150 -0
  54. browser_use/code_use/views.py +171 -0
  55. browser_use/config.py +505 -0
  56. browser_use/controller/__init__.py +3 -0
  57. browser_use/dom/enhanced_snapshot.py +161 -0
  58. browser_use/dom/markdown_extractor.py +169 -0
  59. browser_use/dom/playground/extraction.py +312 -0
  60. browser_use/dom/playground/multi_act.py +32 -0
  61. browser_use/dom/serializer/clickable_elements.py +200 -0
  62. browser_use/dom/serializer/code_use_serializer.py +287 -0
  63. browser_use/dom/serializer/eval_serializer.py +478 -0
  64. browser_use/dom/serializer/html_serializer.py +212 -0
  65. browser_use/dom/serializer/paint_order.py +197 -0
  66. browser_use/dom/serializer/serializer.py +1170 -0
  67. browser_use/dom/service.py +825 -0
  68. browser_use/dom/utils.py +129 -0
  69. browser_use/dom/views.py +906 -0
  70. browser_use/exceptions.py +5 -0
  71. browser_use/filesystem/__init__.py +0 -0
  72. browser_use/filesystem/file_system.py +619 -0
  73. browser_use/init_cmd.py +376 -0
  74. browser_use/integrations/gmail/__init__.py +24 -0
  75. browser_use/integrations/gmail/actions.py +115 -0
  76. browser_use/integrations/gmail/service.py +225 -0
  77. browser_use/llm/__init__.py +155 -0
  78. browser_use/llm/anthropic/chat.py +242 -0
  79. browser_use/llm/anthropic/serializer.py +312 -0
  80. browser_use/llm/aws/__init__.py +36 -0
  81. browser_use/llm/aws/chat_anthropic.py +242 -0
  82. browser_use/llm/aws/chat_bedrock.py +289 -0
  83. browser_use/llm/aws/serializer.py +257 -0
  84. browser_use/llm/azure/chat.py +91 -0
  85. browser_use/llm/base.py +57 -0
  86. browser_use/llm/browser_use/__init__.py +3 -0
  87. browser_use/llm/browser_use/chat.py +201 -0
  88. browser_use/llm/cerebras/chat.py +193 -0
  89. browser_use/llm/cerebras/serializer.py +109 -0
  90. browser_use/llm/deepseek/chat.py +212 -0
  91. browser_use/llm/deepseek/serializer.py +109 -0
  92. browser_use/llm/exceptions.py +29 -0
  93. browser_use/llm/google/__init__.py +3 -0
  94. browser_use/llm/google/chat.py +542 -0
  95. browser_use/llm/google/serializer.py +120 -0
  96. browser_use/llm/groq/chat.py +229 -0
  97. browser_use/llm/groq/parser.py +158 -0
  98. browser_use/llm/groq/serializer.py +159 -0
  99. browser_use/llm/messages.py +238 -0
  100. browser_use/llm/models.py +271 -0
  101. browser_use/llm/oci_raw/__init__.py +10 -0
  102. browser_use/llm/oci_raw/chat.py +443 -0
  103. browser_use/llm/oci_raw/serializer.py +229 -0
  104. browser_use/llm/ollama/chat.py +97 -0
  105. browser_use/llm/ollama/serializer.py +143 -0
  106. browser_use/llm/openai/chat.py +264 -0
  107. browser_use/llm/openai/like.py +15 -0
  108. browser_use/llm/openai/serializer.py +165 -0
  109. browser_use/llm/openrouter/chat.py +211 -0
  110. browser_use/llm/openrouter/serializer.py +26 -0
  111. browser_use/llm/schema.py +176 -0
  112. browser_use/llm/views.py +48 -0
  113. browser_use/logging_config.py +330 -0
  114. browser_use/mcp/__init__.py +18 -0
  115. browser_use/mcp/__main__.py +12 -0
  116. browser_use/mcp/client.py +544 -0
  117. browser_use/mcp/controller.py +264 -0
  118. browser_use/mcp/server.py +1114 -0
  119. browser_use/observability.py +204 -0
  120. browser_use/py.typed +0 -0
  121. browser_use/sandbox/__init__.py +41 -0
  122. browser_use/sandbox/sandbox.py +637 -0
  123. browser_use/sandbox/views.py +132 -0
  124. browser_use/screenshots/__init__.py +1 -0
  125. browser_use/screenshots/service.py +52 -0
  126. browser_use/sync/__init__.py +6 -0
  127. browser_use/sync/auth.py +357 -0
  128. browser_use/sync/service.py +161 -0
  129. browser_use/telemetry/__init__.py +51 -0
  130. browser_use/telemetry/service.py +112 -0
  131. browser_use/telemetry/views.py +101 -0
  132. browser_use/tokens/__init__.py +0 -0
  133. browser_use/tokens/custom_pricing.py +24 -0
  134. browser_use/tokens/mappings.py +4 -0
  135. browser_use/tokens/service.py +580 -0
  136. browser_use/tokens/views.py +108 -0
  137. browser_use/tools/registry/service.py +572 -0
  138. browser_use/tools/registry/views.py +174 -0
  139. browser_use/tools/service.py +1675 -0
  140. browser_use/tools/utils.py +82 -0
  141. browser_use/tools/views.py +100 -0
  142. browser_use/utils.py +670 -0
  143. optexity_browser_use-0.9.5.dist-info/METADATA +344 -0
  144. optexity_browser_use-0.9.5.dist-info/RECORD +147 -0
  145. optexity_browser_use-0.9.5.dist-info/WHEEL +4 -0
  146. optexity_browser_use-0.9.5.dist-info/entry_points.txt +3 -0
  147. optexity_browser_use-0.9.5.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,174 @@
1
+ from collections.abc import Callable
2
+ from typing import TYPE_CHECKING, Any
3
+
4
+ from pydantic import BaseModel, ConfigDict
5
+
6
+ from browser_use.browser import BrowserSession
7
+ from browser_use.filesystem.file_system import FileSystem
8
+ from browser_use.llm.base import BaseChatModel
9
+
10
+ if TYPE_CHECKING:
11
+ pass
12
+
13
+
14
+ class RegisteredAction(BaseModel):
15
+ """Model for a registered action"""
16
+
17
+ name: str
18
+ description: str
19
+ function: Callable
20
+ param_model: type[BaseModel]
21
+
22
+ # filters: provide specific domains to determine whether the action should be available on the given URL or not
23
+ domains: list[str] | None = None # e.g. ['*.google.com', 'www.bing.com', 'yahoo.*]
24
+
25
+ model_config = ConfigDict(arbitrary_types_allowed=True)
26
+
27
+ def prompt_description(self) -> str:
28
+ """Get a description of the action for the prompt in unstructured format"""
29
+ schema = self.param_model.model_json_schema()
30
+ params = []
31
+
32
+ if 'properties' in schema:
33
+ for param_name, param_info in schema['properties'].items():
34
+ # Build parameter description
35
+ param_desc = param_name
36
+
37
+ # Add type information if available
38
+ if 'type' in param_info:
39
+ param_type = param_info['type']
40
+ param_desc += f'={param_type}'
41
+
42
+ # Add description as comment if available
43
+ if 'description' in param_info:
44
+ param_desc += f' ({param_info["description"]})'
45
+
46
+ params.append(param_desc)
47
+
48
+ # Format: action_name: Description. (param1=type, param2=type, ...)
49
+ if params:
50
+ return f'{self.name}: {self.description}. ({", ".join(params)})'
51
+ else:
52
+ return f'{self.name}: {self.description}'
53
+
54
+
55
+ class ActionModel(BaseModel):
56
+ """Base model for dynamically created action models"""
57
+
58
+ # this will have all the registered actions, e.g.
59
+ # click_element = param_model = ClickElementParams
60
+ # done = param_model = None
61
+ #
62
+ model_config = ConfigDict(arbitrary_types_allowed=True, extra='forbid')
63
+
64
+ def get_index(self) -> int | None:
65
+ """Get the index of the action"""
66
+ # {'clicked_element': {'index':5}}
67
+ params = self.model_dump(exclude_unset=True).values()
68
+ if not params:
69
+ return None
70
+ for param in params:
71
+ if param is not None and 'index' in param:
72
+ return param['index']
73
+ return None
74
+
75
+ def set_index(self, index: int):
76
+ """Overwrite the index of the action"""
77
+ # Get the action name and params
78
+ action_data = self.model_dump(exclude_unset=True)
79
+ action_name = next(iter(action_data.keys()))
80
+ action_params = getattr(self, action_name)
81
+
82
+ # Update the index directly on the model
83
+ if hasattr(action_params, 'index'):
84
+ action_params.index = index
85
+
86
+
87
+ class ActionRegistry(BaseModel):
88
+ """Model representing the action registry"""
89
+
90
+ actions: dict[str, RegisteredAction] = {}
91
+
92
+ @staticmethod
93
+ def _match_domains(domains: list[str] | None, url: str) -> bool:
94
+ """
95
+ Match a list of domain glob patterns against a URL.
96
+
97
+ Args:
98
+ domains: A list of domain patterns that can include glob patterns (* wildcard)
99
+ url: The URL to match against
100
+
101
+ Returns:
102
+ True if the URL's domain matches the pattern, False otherwise
103
+ """
104
+
105
+ if domains is None or not url:
106
+ return True
107
+
108
+ # Use the centralized URL matching logic from utils
109
+ from browser_use.utils import match_url_with_domain_pattern
110
+
111
+ for domain_pattern in domains:
112
+ if match_url_with_domain_pattern(url, domain_pattern):
113
+ return True
114
+ return False
115
+
116
+ def get_prompt_description(self, page_url: str | None = None) -> str:
117
+ """Get a description of all actions for the prompt
118
+
119
+ Args:
120
+ page_url: If provided, filter actions by URL using domain filters.
121
+
122
+ Returns:
123
+ A string description of available actions.
124
+ - If page is None: return only actions with no page_filter and no domains (for system prompt)
125
+ - If page is provided: return only filtered actions that match the current page (excluding unfiltered actions)
126
+ """
127
+ if page_url is None:
128
+ # For system prompt (no URL provided), include only actions with no filters
129
+ return '\n'.join(action.prompt_description() for action in self.actions.values() if action.domains is None)
130
+
131
+ # only include filtered actions for the current page URL
132
+ filtered_actions = []
133
+ for action in self.actions.values():
134
+ if not action.domains:
135
+ # skip actions with no filters, they are already included in the system prompt
136
+ continue
137
+
138
+ # Check domain filter
139
+ if self._match_domains(action.domains, page_url):
140
+ filtered_actions.append(action)
141
+
142
+ return '\n'.join(action.prompt_description() for action in filtered_actions)
143
+
144
+
145
+ class SpecialActionParameters(BaseModel):
146
+ """Model defining all special parameters that can be injected into actions"""
147
+
148
+ model_config = ConfigDict(arbitrary_types_allowed=True)
149
+
150
+ # optional user-provided context object passed down from Agent(context=...)
151
+ # e.g. can contain anything, external db connections, file handles, queues, runtime config objects, etc.
152
+ # that you might want to be able to access quickly from within many of your actions
153
+ # browser-use code doesn't use this at all, we just pass it down to your actions for convenience
154
+ context: Any | None = None
155
+
156
+ # browser-use session object, can be used to create new tabs, navigate, access CDP
157
+ browser_session: BrowserSession | None = None
158
+
159
+ # Current page URL for filtering and context
160
+ page_url: str | None = None
161
+
162
+ # CDP client for direct Chrome DevTools Protocol access
163
+ cdp_client: Any | None = None # CDPClient type from cdp_use
164
+
165
+ # extra injected config if the action asks for these arg names
166
+ page_extraction_llm: BaseChatModel | None = None
167
+ file_system: FileSystem | None = None
168
+ available_file_paths: list[str] | None = None
169
+ has_sensitive_data: bool = False
170
+
171
+ @classmethod
172
+ def get_browser_requiring_params(cls) -> set[str]:
173
+ """Get parameter names that require browser_session"""
174
+ return {'browser_session', 'cdp_client', 'page_url'}