sentienceapi 0.95.0__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.
- sentience/__init__.py +253 -0
- sentience/_extension_loader.py +195 -0
- sentience/action_executor.py +215 -0
- sentience/actions.py +1020 -0
- sentience/agent.py +1181 -0
- sentience/agent_config.py +46 -0
- sentience/agent_runtime.py +424 -0
- sentience/asserts/__init__.py +70 -0
- sentience/asserts/expect.py +621 -0
- sentience/asserts/query.py +383 -0
- sentience/async_api.py +108 -0
- sentience/backends/__init__.py +137 -0
- sentience/backends/actions.py +343 -0
- sentience/backends/browser_use_adapter.py +241 -0
- sentience/backends/cdp_backend.py +393 -0
- sentience/backends/exceptions.py +211 -0
- sentience/backends/playwright_backend.py +194 -0
- sentience/backends/protocol.py +216 -0
- sentience/backends/sentience_context.py +469 -0
- sentience/backends/snapshot.py +427 -0
- sentience/base_agent.py +196 -0
- sentience/browser.py +1215 -0
- sentience/browser_evaluator.py +299 -0
- sentience/canonicalization.py +207 -0
- sentience/cli.py +130 -0
- sentience/cloud_tracing.py +807 -0
- sentience/constants.py +6 -0
- sentience/conversational_agent.py +543 -0
- sentience/element_filter.py +136 -0
- sentience/expect.py +188 -0
- sentience/extension/background.js +104 -0
- sentience/extension/content.js +161 -0
- sentience/extension/injected_api.js +914 -0
- sentience/extension/manifest.json +36 -0
- sentience/extension/pkg/sentience_core.d.ts +51 -0
- sentience/extension/pkg/sentience_core.js +323 -0
- sentience/extension/pkg/sentience_core_bg.wasm +0 -0
- sentience/extension/pkg/sentience_core_bg.wasm.d.ts +10 -0
- sentience/extension/release.json +115 -0
- sentience/formatting.py +15 -0
- sentience/generator.py +202 -0
- sentience/inspector.py +367 -0
- sentience/llm_interaction_handler.py +191 -0
- sentience/llm_provider.py +875 -0
- sentience/llm_provider_utils.py +120 -0
- sentience/llm_response_builder.py +153 -0
- sentience/models.py +846 -0
- sentience/ordinal.py +280 -0
- sentience/overlay.py +222 -0
- sentience/protocols.py +228 -0
- sentience/query.py +303 -0
- sentience/read.py +188 -0
- sentience/recorder.py +589 -0
- sentience/schemas/trace_v1.json +335 -0
- sentience/screenshot.py +100 -0
- sentience/sentience_methods.py +86 -0
- sentience/snapshot.py +706 -0
- sentience/snapshot_diff.py +126 -0
- sentience/text_search.py +262 -0
- sentience/trace_event_builder.py +148 -0
- sentience/trace_file_manager.py +197 -0
- sentience/trace_indexing/__init__.py +27 -0
- sentience/trace_indexing/index_schema.py +199 -0
- sentience/trace_indexing/indexer.py +414 -0
- sentience/tracer_factory.py +322 -0
- sentience/tracing.py +449 -0
- sentience/utils/__init__.py +40 -0
- sentience/utils/browser.py +46 -0
- sentience/utils/element.py +257 -0
- sentience/utils/formatting.py +59 -0
- sentience/utils.py +296 -0
- sentience/verification.py +380 -0
- sentience/visual_agent.py +2058 -0
- sentience/wait.py +139 -0
- sentienceapi-0.95.0.dist-info/METADATA +984 -0
- sentienceapi-0.95.0.dist-info/RECORD +82 -0
- sentienceapi-0.95.0.dist-info/WHEEL +5 -0
- sentienceapi-0.95.0.dist-info/entry_points.txt +2 -0
- sentienceapi-0.95.0.dist-info/licenses/LICENSE +24 -0
- sentienceapi-0.95.0.dist-info/licenses/LICENSE-APACHE +201 -0
- sentienceapi-0.95.0.dist-info/licenses/LICENSE-MIT +21 -0
- sentienceapi-0.95.0.dist-info/top_level.txt +1 -0
sentience/wait.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Wait functionality - wait_for element matching selector
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import asyncio
|
|
8
|
+
import time
|
|
9
|
+
|
|
10
|
+
from .browser import AsyncSentienceBrowser, SentienceBrowser
|
|
11
|
+
from .models import SnapshotOptions, WaitResult
|
|
12
|
+
from .query import find
|
|
13
|
+
from .snapshot import snapshot, snapshot_async
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def wait_for(
|
|
17
|
+
browser: SentienceBrowser,
|
|
18
|
+
selector: str | dict,
|
|
19
|
+
timeout: float = 10.0,
|
|
20
|
+
interval: float | None = None,
|
|
21
|
+
use_api: bool | None = None,
|
|
22
|
+
) -> WaitResult:
|
|
23
|
+
"""
|
|
24
|
+
Wait for element matching selector to appear
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
browser: SentienceBrowser instance
|
|
28
|
+
selector: String DSL or dict query
|
|
29
|
+
timeout: Maximum time to wait (seconds)
|
|
30
|
+
interval: Polling interval (seconds). If None, auto-detects:
|
|
31
|
+
- 0.25s for local extension (use_api=False, fast)
|
|
32
|
+
- 1.5s for remote API (use_api=True or default, network latency)
|
|
33
|
+
use_api: Force use of server-side API if True, local extension if False.
|
|
34
|
+
If None, uses API if api_key is set, otherwise uses local extension.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
WaitResult
|
|
38
|
+
"""
|
|
39
|
+
# Auto-detect optimal interval based on API usage
|
|
40
|
+
if interval is None:
|
|
41
|
+
# Determine if using API
|
|
42
|
+
will_use_api = use_api if use_api is not None else (browser.api_key is not None)
|
|
43
|
+
if will_use_api:
|
|
44
|
+
interval = 1.5 # Longer interval for API calls (network latency)
|
|
45
|
+
else:
|
|
46
|
+
interval = 0.25 # Shorter interval for local extension (fast)
|
|
47
|
+
|
|
48
|
+
start_time = time.time()
|
|
49
|
+
|
|
50
|
+
while time.time() - start_time < timeout:
|
|
51
|
+
# Take snapshot (may be local extension or remote API)
|
|
52
|
+
snap = snapshot(browser, SnapshotOptions(use_api=use_api))
|
|
53
|
+
|
|
54
|
+
# Try to find element
|
|
55
|
+
element = find(snap, selector)
|
|
56
|
+
|
|
57
|
+
if element:
|
|
58
|
+
duration_ms = int((time.time() - start_time) * 1000)
|
|
59
|
+
return WaitResult(
|
|
60
|
+
found=True,
|
|
61
|
+
element=element,
|
|
62
|
+
duration_ms=duration_ms,
|
|
63
|
+
timeout=False,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
# Wait before next poll
|
|
67
|
+
time.sleep(interval)
|
|
68
|
+
|
|
69
|
+
# Timeout
|
|
70
|
+
duration_ms = int((time.time() - start_time) * 1000)
|
|
71
|
+
return WaitResult(
|
|
72
|
+
found=False,
|
|
73
|
+
element=None,
|
|
74
|
+
duration_ms=duration_ms,
|
|
75
|
+
timeout=True,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
async def wait_for_async(
|
|
80
|
+
browser: AsyncSentienceBrowser,
|
|
81
|
+
selector: str | dict,
|
|
82
|
+
timeout: float = 10.0,
|
|
83
|
+
interval: float | None = None,
|
|
84
|
+
use_api: bool | None = None,
|
|
85
|
+
) -> WaitResult:
|
|
86
|
+
"""
|
|
87
|
+
Wait for element matching selector to appear (async)
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
browser: AsyncSentienceBrowser instance
|
|
91
|
+
selector: String DSL or dict query
|
|
92
|
+
timeout: Maximum time to wait (seconds)
|
|
93
|
+
interval: Polling interval (seconds). If None, auto-detects:
|
|
94
|
+
- 0.25s for local extension (use_api=False, fast)
|
|
95
|
+
- 1.5s for remote API (use_api=True or default, network latency)
|
|
96
|
+
use_api: Force use of server-side API if True, local extension if False.
|
|
97
|
+
If None, uses API if api_key is set, otherwise uses local extension.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
WaitResult
|
|
101
|
+
"""
|
|
102
|
+
# Auto-detect optimal interval based on API usage
|
|
103
|
+
if interval is None:
|
|
104
|
+
# Determine if using API
|
|
105
|
+
will_use_api = use_api if use_api is not None else (browser.api_key is not None)
|
|
106
|
+
if will_use_api:
|
|
107
|
+
interval = 1.5 # Longer interval for API calls (network latency)
|
|
108
|
+
else:
|
|
109
|
+
interval = 0.25 # Shorter interval for local extension (fast)
|
|
110
|
+
|
|
111
|
+
start_time = time.time()
|
|
112
|
+
|
|
113
|
+
while time.time() - start_time < timeout:
|
|
114
|
+
# Take snapshot (may be local extension or remote API)
|
|
115
|
+
snap = await snapshot_async(browser, SnapshotOptions(use_api=use_api))
|
|
116
|
+
|
|
117
|
+
# Try to find element
|
|
118
|
+
element = find(snap, selector)
|
|
119
|
+
|
|
120
|
+
if element:
|
|
121
|
+
duration_ms = int((time.time() - start_time) * 1000)
|
|
122
|
+
return WaitResult(
|
|
123
|
+
found=True,
|
|
124
|
+
element=element,
|
|
125
|
+
duration_ms=duration_ms,
|
|
126
|
+
timeout=False,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
# Wait before next poll
|
|
130
|
+
await asyncio.sleep(interval)
|
|
131
|
+
|
|
132
|
+
# Timeout
|
|
133
|
+
duration_ms = int((time.time() - start_time) * 1000)
|
|
134
|
+
return WaitResult(
|
|
135
|
+
found=False,
|
|
136
|
+
element=None,
|
|
137
|
+
duration_ms=duration_ms,
|
|
138
|
+
timeout=True,
|
|
139
|
+
)
|