create-browser-app 0.1.7__tar.gz → 0.1.9__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: create-browser-app
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: Start your Stagehand project with a single command
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env python3
2
+ import urllib.request
3
+ from typing import Dict, List, Optional
4
+ from dataclasses import dataclass
5
+
6
+ @dataclass
7
+ class TemplateInfo:
8
+ name: str
9
+ url: str
10
+
11
+ GITHUB_TEMPLATES: List[TemplateInfo] = [
12
+ TemplateInfo(
13
+ name="example",
14
+ url="https://raw.githubusercontent.com/browserbase/stagehand-python/main/examples/example.py",
15
+ ),
16
+ TemplateInfo(
17
+ name="cua-example",
18
+ url="https://raw.githubusercontent.com/browserbase/stagehand-python/main/examples/cua-example.py",
19
+ ),
20
+ TemplateInfo(
21
+ name="form-filling",
22
+ url="https://raw.githubusercontent.com/browserbase/templates/refs/heads/dev/python/form-filling/index.py",
23
+ ),
24
+ TemplateInfo(
25
+ name="gift-finder",
26
+ url="https://raw.githubusercontent.com/browserbase/templates/refs/heads/dev/python/gift-finder/index.py",
27
+ ),
28
+ TemplateInfo(
29
+ name="pickleball",
30
+ url="https://raw.githubusercontent.com/browserbase/templates/refs/heads/dev/python/pickleball/index.py",
31
+ ),
32
+ TemplateInfo(
33
+ name="license-verification",
34
+ url="https://raw.githubusercontent.com/browserbase/templates/refs/heads/dev/python/license-verification/index.py",
35
+ ),
36
+ TemplateInfo(
37
+ name="context",
38
+ url="https://raw.githubusercontent.com/browserbase/templates/refs/heads/dev/python/context/index.py",
39
+ ),
40
+ TemplateInfo(
41
+ name="proxies",
42
+ url="https://raw.githubusercontent.com/browserbase/templates/refs/heads/dev/python/proxies/index.py",
43
+ ),
44
+ ]
45
+
46
+ def get_template_by_name(name: str) -> Optional[TemplateInfo]:
47
+ """Get a specific template by name."""
48
+ for template in GITHUB_TEMPLATES:
49
+ if template.name == name:
50
+ return template
51
+ return None
52
+
53
+ def fetch_template_content(template: TemplateInfo) -> Optional[str]:
54
+ """Fetch the content of a specific template from GitHub."""
55
+ try:
56
+ req = urllib.request.Request(template.url)
57
+ req.add_header("User-Agent", "create-browser-app-py")
58
+
59
+ with urllib.request.urlopen(req) as response:
60
+ if response.status != 200:
61
+ return None
62
+ return response.read().decode("utf-8")
63
+ except Exception:
64
+ return None
65
+
66
+ def get_available_templates() -> List[str]:
67
+ """Get a list of available template names."""
68
+ default_templates = ["basic"]
69
+ github_templates = [t.name for t in GITHUB_TEMPLATES]
70
+ return default_templates + github_templates
71
+
72
+ def list_templates() -> List[str]:
73
+ """Get a list of template names."""
74
+ return get_available_templates()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: create-browser-app
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: Start your Stagehand project with a single command
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "create-browser-app"
7
- version = "0.1.7"
7
+ version = "0.1.9"
8
8
  description = "Start your Stagehand project with a single command"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -1,75 +0,0 @@
1
- #!/usr/bin/env python3
2
- import urllib.request
3
- import json
4
- from typing import Dict, List, Optional
5
- from pathlib import Path
6
- import base64
7
-
8
- GITHUB_API_BASE = "https://api.github.com"
9
- REPO_OWNER = "browserbase"
10
- REPO_NAME = "stagehand-python"
11
- EXAMPLES_PATH = "examples"
12
-
13
- def get_available_templates() -> List[Dict[str, str]]:
14
- """Fetch list of available templates from GitHub repository."""
15
- try:
16
- url = f"{GITHUB_API_BASE}/repos/{REPO_OWNER}/{REPO_NAME}/contents/{EXAMPLES_PATH}"
17
- req = urllib.request.Request(url)
18
- req.add_header("Accept", "application/vnd.github.v3+json")
19
- req.add_header("User-Agent", "create-browser-app-py")
20
-
21
- with urllib.request.urlopen(req) as response:
22
- data = json.loads(response.read().decode())
23
-
24
- templates = []
25
- for item in data:
26
- if item["type"] == "file" and item["name"].endswith(".py"):
27
- # Keep the original name without replacing underscores
28
- template_name = item["name"].replace(".py", "")
29
- templates.append({
30
- "name": template_name,
31
- "filename": item["name"],
32
- "url": item["download_url"],
33
- "api_url": item["url"]
34
- })
35
-
36
- return templates
37
- except Exception as e:
38
- print(f"Error fetching templates: {e}")
39
- return []
40
-
41
- def fetch_template_content(template_info: Dict[str, str]) -> Optional[str]:
42
- """Fetch the content of a specific template from GitHub."""
43
- try:
44
- url = template_info.get("api_url", template_info.get("url"))
45
- req = urllib.request.Request(url)
46
- req.add_header("Accept", "application/vnd.github.v3+json")
47
- req.add_header("User-Agent", "create-browser-app-py")
48
-
49
- with urllib.request.urlopen(req) as response:
50
- data = json.loads(response.read().decode())
51
-
52
- if "content" in data:
53
- content = base64.b64decode(data["content"]).decode("utf-8")
54
- else:
55
- # Fallback to direct download
56
- with urllib.request.urlopen(template_info["url"]) as response:
57
- content = response.read().decode("utf-8")
58
-
59
- return content
60
- except Exception as e:
61
- print(f"Error fetching template content: {e}")
62
- return None
63
-
64
- def get_template_by_name(name: str) -> Optional[Dict[str, str]]:
65
- """Get a specific template by name."""
66
- templates = get_available_templates()
67
- for template in templates:
68
- if template["name"] == name:
69
- return template
70
- return None
71
-
72
- def list_templates() -> List[str]:
73
- """Get a list of template names."""
74
- templates = get_available_templates()
75
- return [t["name"] for t in templates]