sentienceapi 0.90.16__py3-none-any.whl → 0.98.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 +120 -6
- sentience/_extension_loader.py +156 -1
- sentience/action_executor.py +217 -0
- sentience/actions.py +758 -30
- sentience/agent.py +806 -293
- sentience/agent_config.py +3 -0
- sentience/agent_runtime.py +840 -0
- sentience/asserts/__init__.py +70 -0
- sentience/asserts/expect.py +621 -0
- sentience/asserts/query.py +383 -0
- sentience/async_api.py +89 -1141
- sentience/backends/__init__.py +137 -0
- sentience/backends/actions.py +372 -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 +483 -0
- sentience/base_agent.py +95 -0
- sentience/browser.py +678 -39
- sentience/browser_evaluator.py +299 -0
- sentience/canonicalization.py +207 -0
- sentience/cloud_tracing.py +507 -42
- sentience/constants.py +6 -0
- sentience/conversational_agent.py +77 -43
- sentience/cursor_policy.py +142 -0
- sentience/element_filter.py +136 -0
- sentience/expect.py +98 -2
- sentience/extension/background.js +56 -185
- sentience/extension/content.js +150 -287
- sentience/extension/injected_api.js +1088 -1368
- sentience/extension/manifest.json +1 -1
- sentience/extension/pkg/sentience_core.d.ts +22 -22
- sentience/extension/pkg/sentience_core.js +275 -433
- sentience/extension/pkg/sentience_core_bg.wasm +0 -0
- sentience/extension/release.json +47 -47
- sentience/failure_artifacts.py +241 -0
- sentience/formatting.py +9 -53
- sentience/inspector.py +183 -1
- sentience/integrations/__init__.py +6 -0
- sentience/integrations/langchain/__init__.py +12 -0
- sentience/integrations/langchain/context.py +18 -0
- sentience/integrations/langchain/core.py +326 -0
- sentience/integrations/langchain/tools.py +180 -0
- sentience/integrations/models.py +46 -0
- sentience/integrations/pydanticai/__init__.py +15 -0
- sentience/integrations/pydanticai/deps.py +20 -0
- sentience/integrations/pydanticai/toolset.py +468 -0
- sentience/llm_interaction_handler.py +191 -0
- sentience/llm_provider.py +765 -66
- sentience/llm_provider_utils.py +120 -0
- sentience/llm_response_builder.py +153 -0
- sentience/models.py +595 -3
- sentience/ordinal.py +280 -0
- sentience/overlay.py +109 -2
- sentience/protocols.py +228 -0
- sentience/query.py +67 -5
- sentience/read.py +95 -3
- sentience/recorder.py +223 -3
- sentience/schemas/trace_v1.json +128 -9
- sentience/screenshot.py +48 -2
- sentience/sentience_methods.py +86 -0
- sentience/snapshot.py +599 -55
- sentience/snapshot_diff.py +126 -0
- sentience/text_search.py +120 -5
- sentience/trace_event_builder.py +148 -0
- sentience/trace_file_manager.py +197 -0
- sentience/trace_indexing/index_schema.py +95 -7
- sentience/trace_indexing/indexer.py +105 -48
- sentience/tracer_factory.py +120 -9
- sentience/tracing.py +172 -8
- sentience/utils/__init__.py +40 -0
- sentience/utils/browser.py +46 -0
- sentience/{utils.py → utils/element.py} +3 -42
- sentience/utils/formatting.py +59 -0
- sentience/verification.py +618 -0
- sentience/visual_agent.py +2058 -0
- sentience/wait.py +68 -2
- {sentienceapi-0.90.16.dist-info → sentienceapi-0.98.0.dist-info}/METADATA +199 -40
- sentienceapi-0.98.0.dist-info/RECORD +92 -0
- sentience/extension/test-content.js +0 -4
- sentienceapi-0.90.16.dist-info/RECORD +0 -50
- {sentienceapi-0.90.16.dist-info → sentienceapi-0.98.0.dist-info}/WHEEL +0 -0
- {sentienceapi-0.90.16.dist-info → sentienceapi-0.98.0.dist-info}/entry_points.txt +0 -0
- {sentienceapi-0.90.16.dist-info → sentienceapi-0.98.0.dist-info}/licenses/LICENSE +0 -0
- {sentienceapi-0.90.16.dist-info → sentienceapi-0.98.0.dist-info}/licenses/LICENSE-APACHE +0 -0
- {sentienceapi-0.90.16.dist-info → sentienceapi-0.98.0.dist-info}/licenses/LICENSE-MIT +0 -0
- {sentienceapi-0.90.16.dist-info → sentienceapi-0.98.0.dist-info}/top_level.txt +0 -0
sentience/screenshot.py
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Screenshot functionality - standalone screenshot capture
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import base64
|
|
6
|
+
from typing import Any, Literal, Optional
|
|
6
7
|
|
|
7
|
-
from .browser import SentienceBrowser
|
|
8
|
+
from .browser import AsyncSentienceBrowser, SentienceBrowser
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
def screenshot(
|
|
@@ -52,3 +53,48 @@ def screenshot(
|
|
|
52
53
|
# Return as data URL
|
|
53
54
|
mime_type = "image/png" if format == "png" else "image/jpeg"
|
|
54
55
|
return f"data:{mime_type};base64,{base64_data}"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def screenshot_async(
|
|
59
|
+
browser: AsyncSentienceBrowser,
|
|
60
|
+
format: Literal["png", "jpeg"] = "png",
|
|
61
|
+
quality: int | None = None,
|
|
62
|
+
) -> str:
|
|
63
|
+
"""
|
|
64
|
+
Capture screenshot of current page (async)
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
browser: AsyncSentienceBrowser instance
|
|
68
|
+
format: Image format - "png" or "jpeg"
|
|
69
|
+
quality: JPEG quality (1-100), only used for JPEG format
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
Base64-encoded screenshot data URL (e.g., "data:image/png;base64,...")
|
|
73
|
+
|
|
74
|
+
Raises:
|
|
75
|
+
RuntimeError: If browser not started
|
|
76
|
+
ValueError: If quality is invalid for JPEG
|
|
77
|
+
"""
|
|
78
|
+
if not browser.page:
|
|
79
|
+
raise RuntimeError("Browser not started. Call await browser.start() first.")
|
|
80
|
+
|
|
81
|
+
if format == "jpeg" and quality is not None:
|
|
82
|
+
if not (1 <= quality <= 100):
|
|
83
|
+
raise ValueError("Quality must be between 1 and 100 for JPEG format")
|
|
84
|
+
|
|
85
|
+
# Use Playwright's screenshot with base64 encoding
|
|
86
|
+
screenshot_options: dict[str, Any] = {
|
|
87
|
+
"type": format,
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if format == "jpeg" and quality is not None:
|
|
91
|
+
screenshot_options["quality"] = quality
|
|
92
|
+
|
|
93
|
+
# Capture screenshot as base64
|
|
94
|
+
# Playwright returns bytes when encoding is not specified, so we encode manually
|
|
95
|
+
image_bytes = await browser.page.screenshot(**screenshot_options)
|
|
96
|
+
base64_data = base64.b64encode(image_bytes).decode("utf-8")
|
|
97
|
+
|
|
98
|
+
# Return as data URL
|
|
99
|
+
mime_type = "image/png" if format == "png" else "image/jpeg"
|
|
100
|
+
return f"data:{mime_type};base64,{base64_data}"
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Enums for Sentience API methods and agent actions.
|
|
3
|
+
|
|
4
|
+
This module provides type-safe enums for:
|
|
5
|
+
1. window.sentience API methods (extension-level)
|
|
6
|
+
2. Agent action types (high-level automation commands)
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from enum import Enum
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SentienceMethod(str, Enum):
|
|
13
|
+
"""
|
|
14
|
+
Enum for window.sentience API methods.
|
|
15
|
+
|
|
16
|
+
These are the actual methods available on the window.sentience object
|
|
17
|
+
injected by the Chrome extension.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
# Core snapshot and element discovery
|
|
21
|
+
SNAPSHOT = "snapshot"
|
|
22
|
+
"""Take a snapshot of the current page with element geometry and metadata."""
|
|
23
|
+
|
|
24
|
+
# Element interaction
|
|
25
|
+
CLICK = "click"
|
|
26
|
+
"""Click an element by its ID from the snapshot registry."""
|
|
27
|
+
|
|
28
|
+
# Content extraction
|
|
29
|
+
READ = "read"
|
|
30
|
+
"""Read page content as raw HTML, text, or markdown."""
|
|
31
|
+
|
|
32
|
+
FIND_TEXT_RECT = "findTextRect"
|
|
33
|
+
"""Find exact pixel coordinates of text occurrences on the page."""
|
|
34
|
+
|
|
35
|
+
# Visual overlay
|
|
36
|
+
SHOW_OVERLAY = "showOverlay"
|
|
37
|
+
"""Show visual overlay highlighting elements with importance scores."""
|
|
38
|
+
|
|
39
|
+
CLEAR_OVERLAY = "clearOverlay"
|
|
40
|
+
"""Clear the visual overlay."""
|
|
41
|
+
|
|
42
|
+
# Developer tools
|
|
43
|
+
START_RECORDING = "startRecording"
|
|
44
|
+
"""Start recording mode for golden set collection (developer tool)."""
|
|
45
|
+
|
|
46
|
+
def __str__(self) -> str:
|
|
47
|
+
"""Return the method name as a string."""
|
|
48
|
+
return self.value
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class AgentAction(str, Enum):
|
|
52
|
+
"""
|
|
53
|
+
Enum for high-level agent action types.
|
|
54
|
+
|
|
55
|
+
These are the action commands that agents can execute. They may use
|
|
56
|
+
one or more window.sentience methods or Playwright APIs directly.
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
# Element interaction
|
|
60
|
+
CLICK = "click"
|
|
61
|
+
"""Click an element by ID. Uses window.sentience.click() or Playwright mouse.click()."""
|
|
62
|
+
|
|
63
|
+
TYPE = "type"
|
|
64
|
+
"""Type text into an input element. Uses Playwright keyboard.type() directly."""
|
|
65
|
+
|
|
66
|
+
PRESS = "press"
|
|
67
|
+
"""Press a keyboard key (Enter, Escape, Tab, etc.). Uses Playwright keyboard.press()."""
|
|
68
|
+
|
|
69
|
+
# Navigation
|
|
70
|
+
NAVIGATE = "navigate"
|
|
71
|
+
"""Navigate to a URL. Uses Playwright page.goto() directly."""
|
|
72
|
+
|
|
73
|
+
SCROLL = "scroll"
|
|
74
|
+
"""Scroll the page or an element. Uses Playwright page.mouse.wheel() or element.scrollIntoView()."""
|
|
75
|
+
|
|
76
|
+
# Completion
|
|
77
|
+
FINISH = "finish"
|
|
78
|
+
"""Signal that the agent task is complete. No browser action, just status update."""
|
|
79
|
+
|
|
80
|
+
# Wait/verification
|
|
81
|
+
WAIT = "wait"
|
|
82
|
+
"""Wait for a condition or duration. Uses Playwright wait_for_* methods."""
|
|
83
|
+
|
|
84
|
+
def __str__(self) -> str:
|
|
85
|
+
"""Return the action name as a string."""
|
|
86
|
+
return self.value
|