sentienceapi 0.90.12__py3-none-any.whl → 0.92.2__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.

Potentially problematic release.


This version of sentienceapi might be problematic. Click here for more details.

Files changed (63) hide show
  1. sentience/__init__.py +14 -5
  2. sentience/_extension_loader.py +40 -0
  3. sentience/action_executor.py +215 -0
  4. sentience/actions.py +408 -25
  5. sentience/agent.py +804 -310
  6. sentience/agent_config.py +3 -0
  7. sentience/async_api.py +101 -0
  8. sentience/base_agent.py +95 -0
  9. sentience/browser.py +594 -25
  10. sentience/browser_evaluator.py +299 -0
  11. sentience/cloud_tracing.py +458 -36
  12. sentience/conversational_agent.py +79 -45
  13. sentience/element_filter.py +136 -0
  14. sentience/expect.py +98 -2
  15. sentience/extension/background.js +56 -185
  16. sentience/extension/content.js +117 -289
  17. sentience/extension/injected_api.js +799 -1374
  18. sentience/extension/manifest.json +1 -1
  19. sentience/extension/pkg/sentience_core.js +190 -396
  20. sentience/extension/pkg/sentience_core_bg.wasm +0 -0
  21. sentience/extension/release.json +47 -47
  22. sentience/formatting.py +9 -53
  23. sentience/inspector.py +183 -1
  24. sentience/llm_interaction_handler.py +191 -0
  25. sentience/llm_provider.py +256 -28
  26. sentience/llm_provider_utils.py +120 -0
  27. sentience/llm_response_builder.py +153 -0
  28. sentience/models.py +66 -1
  29. sentience/overlay.py +109 -2
  30. sentience/protocols.py +228 -0
  31. sentience/query.py +1 -1
  32. sentience/read.py +95 -3
  33. sentience/recorder.py +223 -3
  34. sentience/schemas/trace_v1.json +102 -9
  35. sentience/screenshot.py +48 -2
  36. sentience/sentience_methods.py +86 -0
  37. sentience/snapshot.py +309 -64
  38. sentience/snapshot_diff.py +141 -0
  39. sentience/text_search.py +119 -5
  40. sentience/trace_event_builder.py +129 -0
  41. sentience/trace_file_manager.py +197 -0
  42. sentience/trace_indexing/index_schema.py +95 -7
  43. sentience/trace_indexing/indexer.py +117 -14
  44. sentience/tracer_factory.py +119 -6
  45. sentience/tracing.py +172 -8
  46. sentience/utils/__init__.py +40 -0
  47. sentience/utils/browser.py +46 -0
  48. sentience/utils/element.py +257 -0
  49. sentience/utils/formatting.py +59 -0
  50. sentience/utils.py +1 -1
  51. sentience/visual_agent.py +2056 -0
  52. sentience/wait.py +70 -4
  53. {sentienceapi-0.90.12.dist-info → sentienceapi-0.92.2.dist-info}/METADATA +61 -22
  54. sentienceapi-0.92.2.dist-info/RECORD +65 -0
  55. sentienceapi-0.92.2.dist-info/licenses/LICENSE +24 -0
  56. sentienceapi-0.92.2.dist-info/licenses/LICENSE-APACHE +201 -0
  57. sentienceapi-0.92.2.dist-info/licenses/LICENSE-MIT +21 -0
  58. sentience/extension/test-content.js +0 -4
  59. sentienceapi-0.90.12.dist-info/RECORD +0 -46
  60. sentienceapi-0.90.12.dist-info/licenses/LICENSE.md +0 -43
  61. {sentienceapi-0.90.12.dist-info → sentienceapi-0.92.2.dist-info}/WHEEL +0 -0
  62. {sentienceapi-0.90.12.dist-info → sentienceapi-0.92.2.dist-info}/entry_points.txt +0 -0
  63. {sentienceapi-0.90.12.dist-info → sentienceapi-0.92.2.dist-info}/top_level.txt +0 -0
sentience/agent_config.py CHANGED
@@ -41,3 +41,6 @@ class AgentConfig:
41
41
  capture_screenshots: bool = True
42
42
  screenshot_format: str = "jpeg" # "png" or "jpeg"
43
43
  screenshot_quality: int = 80 # 1-100 (for JPEG only)
44
+
45
+ # Visual overlay options
46
+ show_overlay: bool = False # Show green bbox overlay in browser
sentience/async_api.py ADDED
@@ -0,0 +1,101 @@
1
+ """
2
+ Async API for Sentience SDK - Convenience re-exports
3
+
4
+ This module re-exports all async functions for backward compatibility and developer convenience.
5
+ You can also import directly from their respective modules:
6
+
7
+ # Option 1: From async_api (recommended for convenience)
8
+ from sentience.async_api import (
9
+ AsyncSentienceBrowser,
10
+ snapshot_async,
11
+ click_async,
12
+ wait_for_async,
13
+ screenshot_async,
14
+ find_text_rect_async,
15
+ # ... all async functions in one place
16
+ )
17
+
18
+ # Option 2: From respective modules (also works)
19
+ from sentience.browser import AsyncSentienceBrowser
20
+ from sentience.snapshot import snapshot_async
21
+ from sentience.actions import click_async
22
+ """
23
+
24
+ # ========== Actions (Phase 1) ==========
25
+ # Re-export async action functions from actions.py
26
+ from sentience.actions import click_async, click_rect_async, press_async, type_text_async
27
+
28
+ # ========== Phase 2C: Agent Layer ==========
29
+ # Re-export async agent classes from agent.py and base_agent.py
30
+ from sentience.agent import SentienceAgentAsync
31
+ from sentience.base_agent import BaseAgentAsync
32
+
33
+ # ========== Browser ==========
34
+ # Re-export AsyncSentienceBrowser from browser.py (moved there for better organization)
35
+ from sentience.browser import AsyncSentienceBrowser
36
+
37
+ # Re-export async expect functions from expect.py
38
+ from sentience.expect import ExpectationAsync, expect_async
39
+ from sentience.inspector import InspectorAsync, inspect_async
40
+
41
+ # Re-export async overlay functions from overlay.py
42
+ from sentience.overlay import clear_overlay_async, show_overlay_async
43
+
44
+ # ========== Query Functions (Pure Functions - No Async Needed) ==========
45
+ # Re-export query functions (pure functions, no async needed)
46
+ from sentience.query import find, query
47
+
48
+ # ========== Phase 2B: Supporting Utilities ==========
49
+ # Re-export async read function from read.py
50
+ from sentience.read import read_async
51
+
52
+ # ========== Phase 2D: Developer Tools ==========
53
+ # Re-export async recorder and inspector from their modules
54
+ from sentience.recorder import RecorderAsync, record_async
55
+
56
+ # Re-export async screenshot function from screenshot.py
57
+ from sentience.screenshot import screenshot_async
58
+
59
+ # ========== Snapshot (Phase 1) ==========
60
+ # Re-export async snapshot functions from snapshot.py
61
+ from sentience.snapshot import snapshot_async
62
+
63
+ # Re-export async text search function from text_search.py
64
+ from sentience.text_search import find_text_rect_async
65
+
66
+ # ========== Phase 2A: Core Utilities ==========
67
+ # Re-export async wait function from wait.py
68
+ from sentience.wait import wait_for_async
69
+
70
+ __all__ = [
71
+ # Browser
72
+ "AsyncSentienceBrowser", # Re-exported from browser.py
73
+ # Snapshot (Phase 1)
74
+ "snapshot_async", # Re-exported from snapshot.py
75
+ # Actions (Phase 1)
76
+ "click_async", # Re-exported from actions.py
77
+ "type_text_async", # Re-exported from actions.py
78
+ "press_async", # Re-exported from actions.py
79
+ "click_rect_async", # Re-exported from actions.py
80
+ # Phase 2A: Core Utilities
81
+ "wait_for_async", # Re-exported from wait.py
82
+ "screenshot_async", # Re-exported from screenshot.py
83
+ "find_text_rect_async", # Re-exported from text_search.py
84
+ # Phase 2B: Supporting Utilities
85
+ "read_async", # Re-exported from read.py
86
+ "show_overlay_async", # Re-exported from overlay.py
87
+ "clear_overlay_async", # Re-exported from overlay.py
88
+ "expect_async", # Re-exported from expect.py
89
+ "ExpectationAsync", # Re-exported from expect.py
90
+ # Phase 2C: Agent Layer
91
+ "SentienceAgentAsync", # Re-exported from agent.py
92
+ "BaseAgentAsync", # Re-exported from base_agent.py
93
+ # Phase 2D: Developer Tools
94
+ "RecorderAsync", # Re-exported from recorder.py
95
+ "record_async", # Re-exported from recorder.py
96
+ "InspectorAsync", # Re-exported from inspector.py
97
+ "inspect_async", # Re-exported from inspector.py
98
+ # Query Functions
99
+ "find", # Re-exported from query.py
100
+ "query", # Re-exported from query.py
101
+ ]
sentience/base_agent.py CHANGED
@@ -1,3 +1,5 @@
1
+ from typing import Optional
2
+
1
3
  """
2
4
  BaseAgent: Abstract base class for all Sentience agents
3
5
  Defines the interface that all agent implementations must follow
@@ -99,3 +101,96 @@ class BaseAgent(ABC):
99
101
  >>> # filtered now contains only relevant elements
100
102
  """
101
103
  return snapshot.elements
104
+
105
+
106
+ class BaseAgentAsync(ABC):
107
+ """
108
+ Abstract base class for all async Sentience agents.
109
+
110
+ Provides a standard interface for:
111
+ - Executing natural language goals (act)
112
+ - Tracking execution history
113
+ - Monitoring token usage
114
+ - Filtering elements based on goals
115
+
116
+ Subclasses must implement:
117
+ - act(): Execute a natural language goal (async)
118
+ - get_history(): Return execution history
119
+ - get_token_stats(): Return token usage statistics
120
+ - clear_history(): Reset history and token counters
121
+
122
+ Subclasses can override:
123
+ - filter_elements(): Customize element filtering logic
124
+ """
125
+
126
+ @abstractmethod
127
+ async def act(self, goal: str, **kwargs) -> AgentActionResult:
128
+ """
129
+ Execute a natural language goal using the agent (async).
130
+
131
+ Args:
132
+ goal: Natural language instruction (e.g., "Click the login button")
133
+ **kwargs: Additional parameters (implementation-specific)
134
+
135
+ Returns:
136
+ AgentActionResult with execution details
137
+
138
+ Raises:
139
+ RuntimeError: If execution fails after retries
140
+ """
141
+ pass
142
+
143
+ @abstractmethod
144
+ def get_history(self) -> list[ActionHistory]:
145
+ """
146
+ Get the execution history of all actions taken.
147
+
148
+ Returns:
149
+ List of ActionHistory entries
150
+ """
151
+ pass
152
+
153
+ @abstractmethod
154
+ def get_token_stats(self) -> TokenStats:
155
+ """
156
+ Get token usage statistics for the agent session.
157
+
158
+ Returns:
159
+ TokenStats with cumulative token counts
160
+ """
161
+ pass
162
+
163
+ @abstractmethod
164
+ def clear_history(self) -> None:
165
+ """
166
+ Clear execution history and reset token counters.
167
+
168
+ This resets the agent to a clean state.
169
+ """
170
+ pass
171
+
172
+ def filter_elements(self, snapshot: Snapshot, goal: str | None = None) -> list[Element]:
173
+ """
174
+ Filter elements from a snapshot based on goal context.
175
+
176
+ Default implementation returns all elements unchanged.
177
+ Subclasses can override to implement custom filtering logic
178
+ such as:
179
+ - Removing irrelevant elements based on goal keywords
180
+ - Boosting importance of matching elements
181
+ - Filtering by role, size, or visual properties
182
+
183
+ Args:
184
+ snapshot: Current page snapshot
185
+ goal: User's goal (can inform filtering strategy)
186
+
187
+ Returns:
188
+ Filtered list of elements (default: all elements)
189
+
190
+ Example:
191
+ >>> agent = SentienceAgentAsync(browser, llm)
192
+ >>> snap = await snapshot_async(browser)
193
+ >>> filtered = agent.filter_elements(snap, goal="Click login")
194
+ >>> # filtered now contains only relevant elements
195
+ """
196
+ return snapshot.elements