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.

Files changed (82) hide show
  1. sentience/__init__.py +253 -0
  2. sentience/_extension_loader.py +195 -0
  3. sentience/action_executor.py +215 -0
  4. sentience/actions.py +1020 -0
  5. sentience/agent.py +1181 -0
  6. sentience/agent_config.py +46 -0
  7. sentience/agent_runtime.py +424 -0
  8. sentience/asserts/__init__.py +70 -0
  9. sentience/asserts/expect.py +621 -0
  10. sentience/asserts/query.py +383 -0
  11. sentience/async_api.py +108 -0
  12. sentience/backends/__init__.py +137 -0
  13. sentience/backends/actions.py +343 -0
  14. sentience/backends/browser_use_adapter.py +241 -0
  15. sentience/backends/cdp_backend.py +393 -0
  16. sentience/backends/exceptions.py +211 -0
  17. sentience/backends/playwright_backend.py +194 -0
  18. sentience/backends/protocol.py +216 -0
  19. sentience/backends/sentience_context.py +469 -0
  20. sentience/backends/snapshot.py +427 -0
  21. sentience/base_agent.py +196 -0
  22. sentience/browser.py +1215 -0
  23. sentience/browser_evaluator.py +299 -0
  24. sentience/canonicalization.py +207 -0
  25. sentience/cli.py +130 -0
  26. sentience/cloud_tracing.py +807 -0
  27. sentience/constants.py +6 -0
  28. sentience/conversational_agent.py +543 -0
  29. sentience/element_filter.py +136 -0
  30. sentience/expect.py +188 -0
  31. sentience/extension/background.js +104 -0
  32. sentience/extension/content.js +161 -0
  33. sentience/extension/injected_api.js +914 -0
  34. sentience/extension/manifest.json +36 -0
  35. sentience/extension/pkg/sentience_core.d.ts +51 -0
  36. sentience/extension/pkg/sentience_core.js +323 -0
  37. sentience/extension/pkg/sentience_core_bg.wasm +0 -0
  38. sentience/extension/pkg/sentience_core_bg.wasm.d.ts +10 -0
  39. sentience/extension/release.json +115 -0
  40. sentience/formatting.py +15 -0
  41. sentience/generator.py +202 -0
  42. sentience/inspector.py +367 -0
  43. sentience/llm_interaction_handler.py +191 -0
  44. sentience/llm_provider.py +875 -0
  45. sentience/llm_provider_utils.py +120 -0
  46. sentience/llm_response_builder.py +153 -0
  47. sentience/models.py +846 -0
  48. sentience/ordinal.py +280 -0
  49. sentience/overlay.py +222 -0
  50. sentience/protocols.py +228 -0
  51. sentience/query.py +303 -0
  52. sentience/read.py +188 -0
  53. sentience/recorder.py +589 -0
  54. sentience/schemas/trace_v1.json +335 -0
  55. sentience/screenshot.py +100 -0
  56. sentience/sentience_methods.py +86 -0
  57. sentience/snapshot.py +706 -0
  58. sentience/snapshot_diff.py +126 -0
  59. sentience/text_search.py +262 -0
  60. sentience/trace_event_builder.py +148 -0
  61. sentience/trace_file_manager.py +197 -0
  62. sentience/trace_indexing/__init__.py +27 -0
  63. sentience/trace_indexing/index_schema.py +199 -0
  64. sentience/trace_indexing/indexer.py +414 -0
  65. sentience/tracer_factory.py +322 -0
  66. sentience/tracing.py +449 -0
  67. sentience/utils/__init__.py +40 -0
  68. sentience/utils/browser.py +46 -0
  69. sentience/utils/element.py +257 -0
  70. sentience/utils/formatting.py +59 -0
  71. sentience/utils.py +296 -0
  72. sentience/verification.py +380 -0
  73. sentience/visual_agent.py +2058 -0
  74. sentience/wait.py +139 -0
  75. sentienceapi-0.95.0.dist-info/METADATA +984 -0
  76. sentienceapi-0.95.0.dist-info/RECORD +82 -0
  77. sentienceapi-0.95.0.dist-info/WHEEL +5 -0
  78. sentienceapi-0.95.0.dist-info/entry_points.txt +2 -0
  79. sentienceapi-0.95.0.dist-info/licenses/LICENSE +24 -0
  80. sentienceapi-0.95.0.dist-info/licenses/LICENSE-APACHE +201 -0
  81. sentienceapi-0.95.0.dist-info/licenses/LICENSE-MIT +21 -0
  82. 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
+ )