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/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)
|