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.

Files changed (90) hide show
  1. sentience/__init__.py +120 -6
  2. sentience/_extension_loader.py +156 -1
  3. sentience/action_executor.py +217 -0
  4. sentience/actions.py +758 -30
  5. sentience/agent.py +806 -293
  6. sentience/agent_config.py +3 -0
  7. sentience/agent_runtime.py +840 -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 +89 -1141
  12. sentience/backends/__init__.py +137 -0
  13. sentience/backends/actions.py +372 -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 +483 -0
  21. sentience/base_agent.py +95 -0
  22. sentience/browser.py +678 -39
  23. sentience/browser_evaluator.py +299 -0
  24. sentience/canonicalization.py +207 -0
  25. sentience/cloud_tracing.py +507 -42
  26. sentience/constants.py +6 -0
  27. sentience/conversational_agent.py +77 -43
  28. sentience/cursor_policy.py +142 -0
  29. sentience/element_filter.py +136 -0
  30. sentience/expect.py +98 -2
  31. sentience/extension/background.js +56 -185
  32. sentience/extension/content.js +150 -287
  33. sentience/extension/injected_api.js +1088 -1368
  34. sentience/extension/manifest.json +1 -1
  35. sentience/extension/pkg/sentience_core.d.ts +22 -22
  36. sentience/extension/pkg/sentience_core.js +275 -433
  37. sentience/extension/pkg/sentience_core_bg.wasm +0 -0
  38. sentience/extension/release.json +47 -47
  39. sentience/failure_artifacts.py +241 -0
  40. sentience/formatting.py +9 -53
  41. sentience/inspector.py +183 -1
  42. sentience/integrations/__init__.py +6 -0
  43. sentience/integrations/langchain/__init__.py +12 -0
  44. sentience/integrations/langchain/context.py +18 -0
  45. sentience/integrations/langchain/core.py +326 -0
  46. sentience/integrations/langchain/tools.py +180 -0
  47. sentience/integrations/models.py +46 -0
  48. sentience/integrations/pydanticai/__init__.py +15 -0
  49. sentience/integrations/pydanticai/deps.py +20 -0
  50. sentience/integrations/pydanticai/toolset.py +468 -0
  51. sentience/llm_interaction_handler.py +191 -0
  52. sentience/llm_provider.py +765 -66
  53. sentience/llm_provider_utils.py +120 -0
  54. sentience/llm_response_builder.py +153 -0
  55. sentience/models.py +595 -3
  56. sentience/ordinal.py +280 -0
  57. sentience/overlay.py +109 -2
  58. sentience/protocols.py +228 -0
  59. sentience/query.py +67 -5
  60. sentience/read.py +95 -3
  61. sentience/recorder.py +223 -3
  62. sentience/schemas/trace_v1.json +128 -9
  63. sentience/screenshot.py +48 -2
  64. sentience/sentience_methods.py +86 -0
  65. sentience/snapshot.py +599 -55
  66. sentience/snapshot_diff.py +126 -0
  67. sentience/text_search.py +120 -5
  68. sentience/trace_event_builder.py +148 -0
  69. sentience/trace_file_manager.py +197 -0
  70. sentience/trace_indexing/index_schema.py +95 -7
  71. sentience/trace_indexing/indexer.py +105 -48
  72. sentience/tracer_factory.py +120 -9
  73. sentience/tracing.py +172 -8
  74. sentience/utils/__init__.py +40 -0
  75. sentience/utils/browser.py +46 -0
  76. sentience/{utils.py → utils/element.py} +3 -42
  77. sentience/utils/formatting.py +59 -0
  78. sentience/verification.py +618 -0
  79. sentience/visual_agent.py +2058 -0
  80. sentience/wait.py +68 -2
  81. {sentienceapi-0.90.16.dist-info → sentienceapi-0.98.0.dist-info}/METADATA +199 -40
  82. sentienceapi-0.98.0.dist-info/RECORD +92 -0
  83. sentience/extension/test-content.js +0 -4
  84. sentienceapi-0.90.16.dist-info/RECORD +0 -50
  85. {sentienceapi-0.90.16.dist-info → sentienceapi-0.98.0.dist-info}/WHEEL +0 -0
  86. {sentienceapi-0.90.16.dist-info → sentienceapi-0.98.0.dist-info}/entry_points.txt +0 -0
  87. {sentienceapi-0.90.16.dist-info → sentienceapi-0.98.0.dist-info}/licenses/LICENSE +0 -0
  88. {sentienceapi-0.90.16.dist-info → sentienceapi-0.98.0.dist-info}/licenses/LICENSE-APACHE +0 -0
  89. {sentienceapi-0.90.16.dist-info → sentienceapi-0.98.0.dist-info}/licenses/LICENSE-MIT +0 -0
  90. {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
- from typing import Any, Literal
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