sentienceapi 0.90.17__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 +153 -0
- sentience/_extension_loader.py +40 -0
- sentience/actions.py +837 -0
- sentience/agent.py +1246 -0
- sentience/agent_config.py +43 -0
- sentience/async_api.py +101 -0
- sentience/base_agent.py +194 -0
- sentience/browser.py +1037 -0
- sentience/cli.py +130 -0
- sentience/cloud_tracing.py +382 -0
- sentience/conversational_agent.py +509 -0
- sentience/expect.py +188 -0
- sentience/extension/background.js +233 -0
- sentience/extension/content.js +298 -0
- sentience/extension/injected_api.js +1473 -0
- sentience/extension/manifest.json +36 -0
- sentience/extension/pkg/sentience_core.d.ts +51 -0
- sentience/extension/pkg/sentience_core.js +529 -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/extension/test-content.js +4 -0
- sentience/formatting.py +59 -0
- sentience/generator.py +202 -0
- sentience/inspector.py +365 -0
- sentience/llm_provider.py +637 -0
- sentience/models.py +412 -0
- sentience/overlay.py +222 -0
- sentience/query.py +303 -0
- sentience/read.py +185 -0
- sentience/recorder.py +589 -0
- sentience/schemas/trace_v1.json +216 -0
- sentience/screenshot.py +100 -0
- sentience/snapshot.py +516 -0
- sentience/text_search.py +290 -0
- sentience/trace_indexing/__init__.py +27 -0
- sentience/trace_indexing/index_schema.py +111 -0
- sentience/trace_indexing/indexer.py +357 -0
- sentience/tracer_factory.py +211 -0
- sentience/tracing.py +285 -0
- sentience/utils.py +296 -0
- sentience/wait.py +137 -0
- sentienceapi-0.90.17.dist-info/METADATA +917 -0
- sentienceapi-0.90.17.dist-info/RECORD +50 -0
- sentienceapi-0.90.17.dist-info/WHEEL +5 -0
- sentienceapi-0.90.17.dist-info/entry_points.txt +2 -0
- sentienceapi-0.90.17.dist-info/licenses/LICENSE +24 -0
- sentienceapi-0.90.17.dist-info/licenses/LICENSE-APACHE +201 -0
- sentienceapi-0.90.17.dist-info/licenses/LICENSE-MIT +21 -0
- sentienceapi-0.90.17.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
{
|
|
2
|
+
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273122615",
|
|
3
|
+
"assets_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273122615/assets",
|
|
4
|
+
"upload_url": "https://uploads.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273122615/assets{?name,label}",
|
|
5
|
+
"html_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/tag/v2.0.7",
|
|
6
|
+
"id": 273122615,
|
|
7
|
+
"author": {
|
|
8
|
+
"login": "github-actions[bot]",
|
|
9
|
+
"id": 41898282,
|
|
10
|
+
"node_id": "MDM6Qm90NDE4OTgyODI=",
|
|
11
|
+
"avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4",
|
|
12
|
+
"gravatar_id": "",
|
|
13
|
+
"url": "https://api.github.com/users/github-actions%5Bbot%5D",
|
|
14
|
+
"html_url": "https://github.com/apps/github-actions",
|
|
15
|
+
"followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers",
|
|
16
|
+
"following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}",
|
|
17
|
+
"gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}",
|
|
18
|
+
"starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}",
|
|
19
|
+
"subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions",
|
|
20
|
+
"organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs",
|
|
21
|
+
"repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos",
|
|
22
|
+
"events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}",
|
|
23
|
+
"received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events",
|
|
24
|
+
"type": "Bot",
|
|
25
|
+
"user_view_type": "public",
|
|
26
|
+
"site_admin": false
|
|
27
|
+
},
|
|
28
|
+
"node_id": "RE_kwDOQshiJ84QR4U3",
|
|
29
|
+
"tag_name": "v2.0.7",
|
|
30
|
+
"target_commitish": "main",
|
|
31
|
+
"name": "Release v2.0.7",
|
|
32
|
+
"draft": false,
|
|
33
|
+
"immutable": false,
|
|
34
|
+
"prerelease": false,
|
|
35
|
+
"created_at": "2025-12-29T03:56:13Z",
|
|
36
|
+
"updated_at": "2025-12-29T03:57:09Z",
|
|
37
|
+
"published_at": "2025-12-29T03:57:08Z",
|
|
38
|
+
"assets": [
|
|
39
|
+
{
|
|
40
|
+
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/assets/333966751",
|
|
41
|
+
"id": 333966751,
|
|
42
|
+
"node_id": "RA_kwDOQshiJ84T5-2f",
|
|
43
|
+
"name": "extension-files.tar.gz",
|
|
44
|
+
"label": "",
|
|
45
|
+
"uploader": {
|
|
46
|
+
"login": "github-actions[bot]",
|
|
47
|
+
"id": 41898282,
|
|
48
|
+
"node_id": "MDM6Qm90NDE4OTgyODI=",
|
|
49
|
+
"avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4",
|
|
50
|
+
"gravatar_id": "",
|
|
51
|
+
"url": "https://api.github.com/users/github-actions%5Bbot%5D",
|
|
52
|
+
"html_url": "https://github.com/apps/github-actions",
|
|
53
|
+
"followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers",
|
|
54
|
+
"following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}",
|
|
55
|
+
"gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}",
|
|
56
|
+
"starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}",
|
|
57
|
+
"subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions",
|
|
58
|
+
"organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs",
|
|
59
|
+
"repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos",
|
|
60
|
+
"events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}",
|
|
61
|
+
"received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events",
|
|
62
|
+
"type": "Bot",
|
|
63
|
+
"user_view_type": "public",
|
|
64
|
+
"site_admin": false
|
|
65
|
+
},
|
|
66
|
+
"content_type": "application/gzip",
|
|
67
|
+
"state": "uploaded",
|
|
68
|
+
"size": 78091,
|
|
69
|
+
"digest": "sha256:e281f8b755b61da4b8015d6172064aa9a337c14133ceceff4ab29199ee53307e",
|
|
70
|
+
"download_count": 6,
|
|
71
|
+
"created_at": "2025-12-29T03:57:09Z",
|
|
72
|
+
"updated_at": "2025-12-29T03:57:09Z",
|
|
73
|
+
"browser_download_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/download/v2.0.7/extension-files.tar.gz"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/assets/333966752",
|
|
77
|
+
"id": 333966752,
|
|
78
|
+
"node_id": "RA_kwDOQshiJ84T5-2g",
|
|
79
|
+
"name": "extension-package.zip",
|
|
80
|
+
"label": "",
|
|
81
|
+
"uploader": {
|
|
82
|
+
"login": "github-actions[bot]",
|
|
83
|
+
"id": 41898282,
|
|
84
|
+
"node_id": "MDM6Qm90NDE4OTgyODI=",
|
|
85
|
+
"avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4",
|
|
86
|
+
"gravatar_id": "",
|
|
87
|
+
"url": "https://api.github.com/users/github-actions%5Bbot%5D",
|
|
88
|
+
"html_url": "https://github.com/apps/github-actions",
|
|
89
|
+
"followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers",
|
|
90
|
+
"following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}",
|
|
91
|
+
"gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}",
|
|
92
|
+
"starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}",
|
|
93
|
+
"subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions",
|
|
94
|
+
"organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs",
|
|
95
|
+
"repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos",
|
|
96
|
+
"events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}",
|
|
97
|
+
"received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events",
|
|
98
|
+
"type": "Bot",
|
|
99
|
+
"user_view_type": "public",
|
|
100
|
+
"site_admin": false
|
|
101
|
+
},
|
|
102
|
+
"content_type": "application/zip",
|
|
103
|
+
"state": "uploaded",
|
|
104
|
+
"size": 80179,
|
|
105
|
+
"digest": "sha256:a025edeb8b6d05bfb25c57f913b68507060653ecbdf616000a46df4cb8dec377",
|
|
106
|
+
"download_count": 0,
|
|
107
|
+
"created_at": "2025-12-29T03:57:09Z",
|
|
108
|
+
"updated_at": "2025-12-29T03:57:09Z",
|
|
109
|
+
"browser_download_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/download/v2.0.7/extension-package.zip"
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
"tarball_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/tarball/v2.0.7",
|
|
113
|
+
"zipball_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/zipball/v2.0.7",
|
|
114
|
+
"body": "**Full Changelog**: https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/compare/v2.0.6...v2.0.7"
|
|
115
|
+
}
|
sentience/formatting.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Snapshot formatting utilities for LLM prompts.
|
|
3
|
+
|
|
4
|
+
Provides functions to convert Sentience snapshots into text format suitable
|
|
5
|
+
for LLM consumption.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import List
|
|
9
|
+
|
|
10
|
+
from .models import Snapshot
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def format_snapshot_for_llm(snap: Snapshot, limit: int = 50) -> str:
|
|
14
|
+
"""
|
|
15
|
+
Convert snapshot elements to text format for LLM consumption.
|
|
16
|
+
|
|
17
|
+
This is the canonical way Sentience formats DOM state for LLMs.
|
|
18
|
+
The format includes element ID, role, text preview, visual cues,
|
|
19
|
+
position, and importance score.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
snap: Snapshot object with elements
|
|
23
|
+
limit: Maximum number of elements to include (default: 50)
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
Formatted string with one element per line
|
|
27
|
+
|
|
28
|
+
Example:
|
|
29
|
+
>>> snap = snapshot(browser)
|
|
30
|
+
>>> formatted = format_snapshot_for_llm(snap, limit=10)
|
|
31
|
+
>>> print(formatted)
|
|
32
|
+
[1] <button> "Sign In" {PRIMARY,CLICKABLE} @ (100,50) (Imp:10)
|
|
33
|
+
[2] <input> "Email address" @ (100,100) (Imp:8)
|
|
34
|
+
...
|
|
35
|
+
"""
|
|
36
|
+
lines: list[str] = []
|
|
37
|
+
|
|
38
|
+
for el in snap.elements[:limit]:
|
|
39
|
+
# Build visual cues string
|
|
40
|
+
cues = []
|
|
41
|
+
if getattr(el.visual_cues, "is_primary", False):
|
|
42
|
+
cues.append("PRIMARY")
|
|
43
|
+
if getattr(el.visual_cues, "is_clickable", False):
|
|
44
|
+
cues.append("CLICKABLE")
|
|
45
|
+
|
|
46
|
+
cues_str = f" {{{','.join(cues)}}}" if cues else ""
|
|
47
|
+
|
|
48
|
+
# Format text preview (truncate to 50 chars)
|
|
49
|
+
text_preview = el.text or ""
|
|
50
|
+
if len(text_preview) > 50:
|
|
51
|
+
text_preview = text_preview[:50] + "..."
|
|
52
|
+
|
|
53
|
+
# Build element line: [ID] <role> "text" {cues} @ (x,y) (Imp:score)
|
|
54
|
+
lines.append(
|
|
55
|
+
f'[{el.id}] <{el.role}> "{text_preview}"{cues_str} '
|
|
56
|
+
f"@ ({int(el.bbox.x)},{int(el.bbox.y)}) (Imp:{el.importance})"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
return "\n".join(lines)
|
sentience/generator.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Script Generator - converts trace into executable code
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .recorder import Trace, TraceStep
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ScriptGenerator:
|
|
9
|
+
"""Generates Python or TypeScript code from a trace"""
|
|
10
|
+
|
|
11
|
+
def __init__(self, trace: Trace):
|
|
12
|
+
self.trace = trace
|
|
13
|
+
|
|
14
|
+
def generate_python(self) -> str:
|
|
15
|
+
"""Generate Python script from trace"""
|
|
16
|
+
lines = [
|
|
17
|
+
'"""',
|
|
18
|
+
f"Generated script from trace: {self.trace.start_url}",
|
|
19
|
+
f"Created: {self.trace.created_at}",
|
|
20
|
+
'"""',
|
|
21
|
+
"",
|
|
22
|
+
"from sentience import SentienceBrowser, snapshot, find, click, type_text, press",
|
|
23
|
+
"",
|
|
24
|
+
"def main():",
|
|
25
|
+
" with SentienceBrowser(headless=False) as browser:",
|
|
26
|
+
f' browser.page.goto("{self.trace.start_url}")',
|
|
27
|
+
' browser.page.wait_for_load_state("networkidle")',
|
|
28
|
+
"",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
for step in self.trace.steps:
|
|
32
|
+
lines.extend(self._generate_python_step(step, indent=" "))
|
|
33
|
+
|
|
34
|
+
lines.extend(
|
|
35
|
+
[
|
|
36
|
+
"",
|
|
37
|
+
'if __name__ == "__main__":',
|
|
38
|
+
" main()",
|
|
39
|
+
]
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
return "\n".join(lines)
|
|
43
|
+
|
|
44
|
+
def generate_typescript(self) -> str:
|
|
45
|
+
"""Generate TypeScript script from trace"""
|
|
46
|
+
lines = [
|
|
47
|
+
"/**",
|
|
48
|
+
f" * Generated script from trace: {self.trace.start_url}",
|
|
49
|
+
f" * Created: {self.trace.created_at}",
|
|
50
|
+
" */",
|
|
51
|
+
"",
|
|
52
|
+
"import { SentienceBrowser, snapshot, find, click, typeText, press } from './src';",
|
|
53
|
+
"",
|
|
54
|
+
"async function main() {",
|
|
55
|
+
" const browser = new SentienceBrowser(undefined, false);",
|
|
56
|
+
"",
|
|
57
|
+
" try {",
|
|
58
|
+
" await browser.start();",
|
|
59
|
+
f" await browser.getPage().goto('{self.trace.start_url}');",
|
|
60
|
+
" await browser.getPage().waitForLoadState('networkidle');",
|
|
61
|
+
"",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
for step in self.trace.steps:
|
|
65
|
+
lines.extend(self._generate_typescript_step(step, indent=" "))
|
|
66
|
+
|
|
67
|
+
lines.extend(
|
|
68
|
+
[
|
|
69
|
+
" } finally {",
|
|
70
|
+
" await browser.close();",
|
|
71
|
+
" }",
|
|
72
|
+
"}",
|
|
73
|
+
"",
|
|
74
|
+
"main().catch(console.error);",
|
|
75
|
+
]
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
return "\n".join(lines)
|
|
79
|
+
|
|
80
|
+
def _generate_python_step(self, step: TraceStep, indent: str = "") -> list[str]:
|
|
81
|
+
"""Generate Python code for a single step"""
|
|
82
|
+
lines = []
|
|
83
|
+
|
|
84
|
+
if step.type == "navigation":
|
|
85
|
+
lines.append(f"{indent}# Navigate to {step.url}")
|
|
86
|
+
lines.append(f'{indent}browser.page.goto("{step.url}")')
|
|
87
|
+
lines.append(f'{indent}browser.page.wait_for_load_state("networkidle")')
|
|
88
|
+
|
|
89
|
+
elif step.type == "click":
|
|
90
|
+
if step.selector:
|
|
91
|
+
# Use semantic selector
|
|
92
|
+
lines.append(f"{indent}# Click: {step.selector}")
|
|
93
|
+
lines.append(f"{indent}snap = snapshot(browser)")
|
|
94
|
+
lines.append(f'{indent}element = find(snap, "{step.selector}")')
|
|
95
|
+
lines.append(f"{indent}if element:")
|
|
96
|
+
lines.append(f"{indent} click(browser, element.id)")
|
|
97
|
+
lines.append(f"{indent}else:")
|
|
98
|
+
lines.append(f'{indent} raise Exception("Element not found: {step.selector}")')
|
|
99
|
+
elif step.element_id is not None:
|
|
100
|
+
# Fallback to element ID
|
|
101
|
+
lines.append(f"{indent}# TODO: replace with semantic selector")
|
|
102
|
+
lines.append(f"{indent}click(browser, {step.element_id})")
|
|
103
|
+
lines.append("")
|
|
104
|
+
|
|
105
|
+
elif step.type == "type":
|
|
106
|
+
if step.selector:
|
|
107
|
+
lines.append(f"{indent}# Type into: {step.selector}")
|
|
108
|
+
lines.append(f"{indent}snap = snapshot(browser)")
|
|
109
|
+
lines.append(f'{indent}element = find(snap, "{step.selector}")')
|
|
110
|
+
lines.append(f"{indent}if element:")
|
|
111
|
+
lines.append(f'{indent} type_text(browser, element.id, "{step.text}")')
|
|
112
|
+
lines.append(f"{indent}else:")
|
|
113
|
+
lines.append(f'{indent} raise Exception("Element not found: {step.selector}")')
|
|
114
|
+
elif step.element_id is not None:
|
|
115
|
+
lines.append(f"{indent}# TODO: replace with semantic selector")
|
|
116
|
+
lines.append(f'{indent}type_text(browser, {step.element_id}, "{step.text}")')
|
|
117
|
+
lines.append("")
|
|
118
|
+
|
|
119
|
+
elif step.type == "press":
|
|
120
|
+
lines.append(f"{indent}# Press key: {step.key}")
|
|
121
|
+
lines.append(f'{indent}press(browser, "{step.key}")')
|
|
122
|
+
lines.append("")
|
|
123
|
+
|
|
124
|
+
return lines
|
|
125
|
+
|
|
126
|
+
def _generate_typescript_step(self, step: TraceStep, indent: str = "") -> list[str]:
|
|
127
|
+
"""Generate TypeScript code for a single step"""
|
|
128
|
+
lines = []
|
|
129
|
+
|
|
130
|
+
if step.type == "navigation":
|
|
131
|
+
lines.append(f"{indent}// Navigate to {step.url}")
|
|
132
|
+
lines.append(f"{indent}await browser.getPage().goto('{step.url}');")
|
|
133
|
+
lines.append(f"{indent}await browser.getPage().waitForLoadState('networkidle');")
|
|
134
|
+
|
|
135
|
+
elif step.type == "click":
|
|
136
|
+
if step.selector:
|
|
137
|
+
lines.append(f"{indent}// Click: {step.selector}")
|
|
138
|
+
lines.append(f"{indent}const snap = await snapshot(browser);")
|
|
139
|
+
lines.append(f"{indent}const element = find(snap, '{step.selector}');")
|
|
140
|
+
lines.append(f"{indent}if (element) {{")
|
|
141
|
+
lines.append(f"{indent} await click(browser, element.id);")
|
|
142
|
+
lines.append(f"{indent}}} else {{")
|
|
143
|
+
lines.append(f"{indent} throw new Error('Element not found: {step.selector}');")
|
|
144
|
+
lines.append(f"{indent}}}")
|
|
145
|
+
elif step.element_id is not None:
|
|
146
|
+
lines.append(f"{indent}// TODO: replace with semantic selector")
|
|
147
|
+
lines.append(f"{indent}await click(browser, {step.element_id});")
|
|
148
|
+
lines.append("")
|
|
149
|
+
|
|
150
|
+
elif step.type == "type":
|
|
151
|
+
if step.selector:
|
|
152
|
+
lines.append(f"{indent}// Type into: {step.selector}")
|
|
153
|
+
lines.append(f"{indent}const snap = await snapshot(browser);")
|
|
154
|
+
lines.append(f"{indent}const element = find(snap, '{step.selector}');")
|
|
155
|
+
lines.append(f"{indent}if (element) {{")
|
|
156
|
+
lines.append(f"{indent} await typeText(browser, element.id, '{step.text}');")
|
|
157
|
+
lines.append(f"{indent}}} else {{")
|
|
158
|
+
lines.append(f"{indent} throw new Error('Element not found: {step.selector}');")
|
|
159
|
+
lines.append(f"{indent}}}")
|
|
160
|
+
elif step.element_id is not None:
|
|
161
|
+
lines.append(f"{indent}// TODO: replace with semantic selector")
|
|
162
|
+
lines.append(f"{indent}await typeText(browser, {step.element_id}, '{step.text}');")
|
|
163
|
+
lines.append("")
|
|
164
|
+
|
|
165
|
+
elif step.type == "press":
|
|
166
|
+
lines.append(f"{indent}// Press key: {step.key}")
|
|
167
|
+
lines.append(f"{indent}await press(browser, '{step.key}');")
|
|
168
|
+
lines.append("")
|
|
169
|
+
|
|
170
|
+
return lines
|
|
171
|
+
|
|
172
|
+
def save_python(self, filepath: str) -> None:
|
|
173
|
+
"""Generate and save Python script"""
|
|
174
|
+
code = self.generate_python()
|
|
175
|
+
with open(filepath, "w") as f:
|
|
176
|
+
f.write(code)
|
|
177
|
+
|
|
178
|
+
def save_typescript(self, filepath: str) -> None:
|
|
179
|
+
"""Generate and save TypeScript script"""
|
|
180
|
+
code = self.generate_typescript()
|
|
181
|
+
with open(filepath, "w") as f:
|
|
182
|
+
f.write(code)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def generate(trace: Trace, language: str = "py") -> str:
|
|
186
|
+
"""
|
|
187
|
+
Generate script from trace
|
|
188
|
+
|
|
189
|
+
Args:
|
|
190
|
+
trace: Trace object
|
|
191
|
+
language: 'py' or 'ts'
|
|
192
|
+
|
|
193
|
+
Returns:
|
|
194
|
+
Generated code as string
|
|
195
|
+
"""
|
|
196
|
+
generator = ScriptGenerator(trace)
|
|
197
|
+
if language == "py":
|
|
198
|
+
return generator.generate_python()
|
|
199
|
+
elif language == "ts":
|
|
200
|
+
return generator.generate_typescript()
|
|
201
|
+
else:
|
|
202
|
+
raise ValueError(f"Unsupported language: {language}. Use 'py' or 'ts'")
|