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/read.py ADDED
@@ -0,0 +1,188 @@
1
+ """
2
+ Read page content - supports raw HTML, text, and markdown formats
3
+ """
4
+
5
+ from typing import Literal
6
+
7
+ from .browser import AsyncSentienceBrowser, SentienceBrowser
8
+ from .models import ReadResult
9
+
10
+
11
+ def read(
12
+ browser: SentienceBrowser,
13
+ output_format: Literal["raw", "text", "markdown"] = "raw",
14
+ enhance_markdown: bool = True,
15
+ ) -> ReadResult:
16
+ """
17
+ Read page content as raw HTML, text, or markdown
18
+
19
+ Args:
20
+ browser: SentienceBrowser instance
21
+ output_format: Output format - "raw" (default, returns HTML for external processing),
22
+ "text" (plain text), or "markdown" (lightweight or enhanced markdown).
23
+ enhance_markdown: If True and output_format is "markdown", uses markdownify for better conversion.
24
+ If False, uses the extension's lightweight markdown converter.
25
+
26
+ Returns:
27
+ dict with:
28
+ - status: "success" or "error"
29
+ - url: Current page URL
30
+ - format: "raw", "text", or "markdown"
31
+ - content: Page content as string
32
+ - length: Content length in characters
33
+ - error: Error message if status is "error"
34
+
35
+ Examples:
36
+ # Get raw HTML (default) - can be used with markdownify for better conversion
37
+ result = read(browser)
38
+ html_content = result["content"]
39
+
40
+ # Get high-quality markdown (uses markdownify internally)
41
+ result = read(browser, output_format="markdown")
42
+ markdown = result["content"]
43
+
44
+ # Get plain text
45
+ result = read(browser, output_format="text")
46
+ text = result["content"]
47
+ """
48
+ if not browser.page:
49
+ raise RuntimeError("Browser not started. Call browser.start() first.")
50
+
51
+ if output_format == "markdown" and enhance_markdown:
52
+ # Get raw HTML from the extension first
53
+ raw_html_result = browser.page.evaluate(
54
+ """
55
+ (options) => {
56
+ return window.sentience.read(options);
57
+ }
58
+ """,
59
+ {"format": "raw"},
60
+ )
61
+
62
+ if raw_html_result.get("status") == "success":
63
+ html_content = raw_html_result["content"]
64
+ try:
65
+ # Use markdownify for enhanced markdown conversion
66
+ from markdownify import MarkdownifyError, markdownify
67
+
68
+ markdown_content = markdownify(html_content, heading_style="ATX", wrap=True)
69
+ return {
70
+ "status": "success",
71
+ "url": raw_html_result["url"],
72
+ "format": "markdown",
73
+ "content": markdown_content,
74
+ "length": len(markdown_content),
75
+ }
76
+ except ImportError:
77
+ print(
78
+ "Warning: 'markdownify' not installed. Install with 'pip install markdownify' for enhanced markdown. Falling back to extension's markdown."
79
+ )
80
+ except MarkdownifyError as e:
81
+ print(f"Warning: markdownify failed ({e}), falling back to extension's markdown.")
82
+ except Exception as e:
83
+ print(
84
+ f"Warning: An unexpected error occurred with markdownify ({e}), falling back to extension's markdown."
85
+ )
86
+
87
+ # If not enhanced markdown, or fallback, call extension with requested format
88
+ result = browser.page.evaluate(
89
+ """
90
+ (options) => {
91
+ return window.sentience.read(options);
92
+ }
93
+ """,
94
+ {"format": output_format},
95
+ )
96
+
97
+ # Convert dict result to ReadResult model
98
+ return ReadResult(**result)
99
+
100
+
101
+ async def read_async(
102
+ browser: AsyncSentienceBrowser,
103
+ output_format: Literal["raw", "text", "markdown"] = "raw",
104
+ enhance_markdown: bool = True,
105
+ ) -> ReadResult:
106
+ """
107
+ Read page content as raw HTML, text, or markdown (async)
108
+
109
+ Args:
110
+ browser: AsyncSentienceBrowser instance
111
+ output_format: Output format - "raw" (default, returns HTML for external processing),
112
+ "text" (plain text), or "markdown" (lightweight or enhanced markdown).
113
+ enhance_markdown: If True and output_format is "markdown", uses markdownify for better conversion.
114
+ If False, uses the extension's lightweight markdown converter.
115
+
116
+ Returns:
117
+ dict with:
118
+ - status: "success" or "error"
119
+ - url: Current page URL
120
+ - format: "raw", "text", or "markdown"
121
+ - content: Page content as string
122
+ - length: Content length in characters
123
+ - error: Error message if status is "error"
124
+
125
+ Examples:
126
+ # Get raw HTML (default) - can be used with markdownify for better conversion
127
+ result = await read_async(browser)
128
+ html_content = result["content"]
129
+
130
+ # Get high-quality markdown (uses markdownify internally)
131
+ result = await read_async(browser, output_format="markdown")
132
+ markdown = result["content"]
133
+
134
+ # Get plain text
135
+ result = await read_async(browser, output_format="text")
136
+ text = result["content"]
137
+ """
138
+ if not browser.page:
139
+ raise RuntimeError("Browser not started. Call await browser.start() first.")
140
+
141
+ if output_format == "markdown" and enhance_markdown:
142
+ # Get raw HTML from the extension first
143
+ raw_html_result = await browser.page.evaluate(
144
+ """
145
+ (options) => {
146
+ return window.sentience.read(options);
147
+ }
148
+ """,
149
+ {"format": "raw"},
150
+ )
151
+
152
+ if raw_html_result.get("status") == "success":
153
+ html_content = raw_html_result["content"]
154
+ try:
155
+ # Use markdownify for enhanced markdown conversion
156
+ from markdownify import MarkdownifyError, markdownify
157
+
158
+ markdown_content = markdownify(html_content, heading_style="ATX", wrap=True)
159
+ return {
160
+ "status": "success",
161
+ "url": raw_html_result["url"],
162
+ "format": "markdown",
163
+ "content": markdown_content,
164
+ "length": len(markdown_content),
165
+ }
166
+ except ImportError:
167
+ print(
168
+ "Warning: 'markdownify' not installed. Install with 'pip install markdownify' for enhanced markdown. Falling back to extension's markdown."
169
+ )
170
+ except MarkdownifyError as e:
171
+ print(f"Warning: markdownify failed ({e}), falling back to extension's markdown.")
172
+ except Exception as e:
173
+ print(
174
+ f"Warning: An unexpected error occurred with markdownify ({e}), falling back to extension's markdown."
175
+ )
176
+
177
+ # If not enhanced markdown, or fallback, call extension with requested format
178
+ result = await browser.page.evaluate(
179
+ """
180
+ (options) => {
181
+ return window.sentience.read(options);
182
+ }
183
+ """,
184
+ {"format": output_format},
185
+ )
186
+
187
+ # Convert dict result to ReadResult model
188
+ return ReadResult(**result)