predev-api 0.12.0__tar.gz → 1.0.0__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.
- {predev_api-0.12.0/predev_api.egg-info → predev_api-1.0.0}/PKG-INFO +18 -18
- {predev_api-0.12.0 → predev_api-1.0.0}/README.md +17 -17
- {predev_api-0.12.0 → predev_api-1.0.0}/predev_api/__init__.py +1 -1
- {predev_api-0.12.0 → predev_api-1.0.0}/predev_api/client.py +64 -14
- {predev_api-0.12.0 → predev_api-1.0.0/predev_api.egg-info}/PKG-INFO +18 -18
- {predev_api-0.12.0 → predev_api-1.0.0}/setup.py +1 -1
- {predev_api-0.12.0 → predev_api-1.0.0}/LICENSE +0 -0
- {predev_api-0.12.0 → predev_api-1.0.0}/MANIFEST.in +0 -0
- {predev_api-0.12.0 → predev_api-1.0.0}/predev_api/exceptions.py +0 -0
- {predev_api-0.12.0 → predev_api-1.0.0}/predev_api.egg-info/SOURCES.txt +0 -0
- {predev_api-0.12.0 → predev_api-1.0.0}/predev_api.egg-info/dependency_links.txt +0 -0
- {predev_api-0.12.0 → predev_api-1.0.0}/predev_api.egg-info/requires.txt +0 -0
- {predev_api-0.12.0 → predev_api-1.0.0}/predev_api.egg-info/top_level.txt +0 -0
- {predev_api-0.12.0 → predev_api-1.0.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: predev-api
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: Python client for the Pre.dev Architect API - Generate comprehensive software specifications
|
|
5
5
|
Home-page: https://github.com/predotdev/predev-api
|
|
6
6
|
Author: Pre.dev
|
|
@@ -502,7 +502,7 @@ For issues, questions, or contributions, please visit the [GitHub repository](ht
|
|
|
502
502
|
|
|
503
503
|
## Browser Tasks
|
|
504
504
|
|
|
505
|
-
Run browser automation —
|
|
505
|
+
Run browser automation — navigate, interact, and/or extract data from any web page. Each task navigates a URL, performs actions, and optionally returns typed JSON.
|
|
506
506
|
|
|
507
507
|
### Quick start
|
|
508
508
|
|
|
@@ -511,7 +511,7 @@ from predev_api import PredevAPI
|
|
|
511
511
|
|
|
512
512
|
client = PredevAPI(api_key="your_api_key")
|
|
513
513
|
|
|
514
|
-
result = client.
|
|
514
|
+
result = client.browser_agent([
|
|
515
515
|
{
|
|
516
516
|
"url": "https://news.ycombinator.com",
|
|
517
517
|
"instruction": "Extract the top 5 stories",
|
|
@@ -542,7 +542,7 @@ for story in result["results"][0]["data"]["stories"]:
|
|
|
542
542
|
#### 1. Sync (default) — wait for completion
|
|
543
543
|
|
|
544
544
|
```python
|
|
545
|
-
result = client.
|
|
545
|
+
result = client.browser_agent([
|
|
546
546
|
{"url": "https://example.com", "output": {"type": "object", "properties": {"heading": {"type": "string"}}}}
|
|
547
547
|
])
|
|
548
548
|
print(result["results"][0]["data"]) # {'heading': 'Example Domain'}
|
|
@@ -554,7 +554,7 @@ print(result["totalCreditsUsed"]) # 0.1
|
|
|
554
554
|
Yields events as the agent runs. Good for showing progress in a UI.
|
|
555
555
|
|
|
556
556
|
```python
|
|
557
|
-
for msg in client.
|
|
557
|
+
for msg in client.browser_agent(tasks, stream=True):
|
|
558
558
|
e, d = msg["event"], msg["data"]
|
|
559
559
|
if e == "task_event":
|
|
560
560
|
# navigation | screenshot | plan | action | validation | done
|
|
@@ -574,11 +574,11 @@ Returns the batch ID immediately. Use for long-running batches or background job
|
|
|
574
574
|
```python
|
|
575
575
|
import time
|
|
576
576
|
|
|
577
|
-
r = client.
|
|
577
|
+
r = client.browser_agent(tasks, run_async=True)
|
|
578
578
|
# {"id": "batch_abc", "status": "processing", "completed": 0, "total": 3}
|
|
579
579
|
|
|
580
580
|
while True:
|
|
581
|
-
state = client.
|
|
581
|
+
state = client.get_browser_agent(r["id"])
|
|
582
582
|
print(f"{state['completed']}/{state['total']}")
|
|
583
583
|
for done in state["results"]:
|
|
584
584
|
print(f" ✓ {done['url']} -> {done.get('data')}")
|
|
@@ -600,27 +600,27 @@ Each task's behavior is determined by which fields are set:
|
|
|
600
600
|
|
|
601
601
|
### Retrieving a batch with the full timeline
|
|
602
602
|
|
|
603
|
-
Every task records navigation, screenshots, LLM plans, actions, validations. Retrieve for audit, replay, or debugging
|
|
603
|
+
Every task records navigation, screenshots, LLM plans, actions, validations. Retrieve for audit, replay, or debugging. Screenshots are uploaded to a CDN during execution — retrieved events contain `data["url"]`, not base64.
|
|
604
604
|
|
|
605
605
|
```python
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
details = client.get_browser_tasks(batch_id, include_events=True)
|
|
606
|
+
details = client.get_browser_agent(batch_id, include_events=True)
|
|
609
607
|
for result in details["results"]:
|
|
610
608
|
for ev in result.get("events", []):
|
|
611
609
|
if ev["type"] == "screenshot":
|
|
612
|
-
|
|
613
|
-
|
|
610
|
+
# ev["data"]["url"] is a permanent CDN URL. Use directly in an <img>.
|
|
611
|
+
print(f"Iter {ev.get('iteration')} screenshot:", ev["data"]["url"])
|
|
614
612
|
elif ev["type"] == "plan":
|
|
615
613
|
print(f"Iter {ev.get('iteration')} plan: {ev['data'].get('notes')}")
|
|
616
614
|
```
|
|
617
615
|
|
|
616
|
+
> **Note:** The live SSE stream (`stream=True`) still sends screenshots inline as base64 (`ev["data"]["base64"]`) so live UIs render instantly. The retrieval path (`get_browser_agent`) always returns CDN URLs.
|
|
617
|
+
|
|
618
618
|
### Parallel batch example
|
|
619
619
|
|
|
620
620
|
```python
|
|
621
621
|
# Scrape 100 URLs with 20 browsers in parallel
|
|
622
622
|
urls = [...100 urls...]
|
|
623
|
-
result = client.
|
|
623
|
+
result = client.browser_agent(
|
|
624
624
|
[{"url": u, "output": {"type": "object", "properties": {"title": {"type": "string"}}}} for u in urls],
|
|
625
625
|
concurrency=20
|
|
626
626
|
)
|
|
@@ -631,10 +631,10 @@ print(f"{result['completed']}/{result['total']} done in {result['totalCreditsUse
|
|
|
631
631
|
|
|
632
632
|
| Method | Returns | Use when |
|
|
633
633
|
|---|---|---|
|
|
634
|
-
| `
|
|
635
|
-
| `
|
|
636
|
-
| `
|
|
637
|
-
| `
|
|
634
|
+
| `browser_agent(tasks, concurrency=N)` | dict | Default — wait for completion |
|
|
635
|
+
| `browser_agent(tasks, stream=True)` | iterator of SSE dicts | Live UI showing execution timeline |
|
|
636
|
+
| `browser_agent(tasks, run_async=True)` | dict (empty results, returned immediately) | Long batches, background jobs |
|
|
637
|
+
| `get_browser_agent(batch_id, include_events=False)` | dict | Poll progress or retrieve a completed batch |
|
|
638
638
|
|
|
639
639
|
### Task result statuses
|
|
640
640
|
|
|
@@ -462,7 +462,7 @@ For issues, questions, or contributions, please visit the [GitHub repository](ht
|
|
|
462
462
|
|
|
463
463
|
## Browser Tasks
|
|
464
464
|
|
|
465
|
-
Run browser automation —
|
|
465
|
+
Run browser automation — navigate, interact, and/or extract data from any web page. Each task navigates a URL, performs actions, and optionally returns typed JSON.
|
|
466
466
|
|
|
467
467
|
### Quick start
|
|
468
468
|
|
|
@@ -471,7 +471,7 @@ from predev_api import PredevAPI
|
|
|
471
471
|
|
|
472
472
|
client = PredevAPI(api_key="your_api_key")
|
|
473
473
|
|
|
474
|
-
result = client.
|
|
474
|
+
result = client.browser_agent([
|
|
475
475
|
{
|
|
476
476
|
"url": "https://news.ycombinator.com",
|
|
477
477
|
"instruction": "Extract the top 5 stories",
|
|
@@ -502,7 +502,7 @@ for story in result["results"][0]["data"]["stories"]:
|
|
|
502
502
|
#### 1. Sync (default) — wait for completion
|
|
503
503
|
|
|
504
504
|
```python
|
|
505
|
-
result = client.
|
|
505
|
+
result = client.browser_agent([
|
|
506
506
|
{"url": "https://example.com", "output": {"type": "object", "properties": {"heading": {"type": "string"}}}}
|
|
507
507
|
])
|
|
508
508
|
print(result["results"][0]["data"]) # {'heading': 'Example Domain'}
|
|
@@ -514,7 +514,7 @@ print(result["totalCreditsUsed"]) # 0.1
|
|
|
514
514
|
Yields events as the agent runs. Good for showing progress in a UI.
|
|
515
515
|
|
|
516
516
|
```python
|
|
517
|
-
for msg in client.
|
|
517
|
+
for msg in client.browser_agent(tasks, stream=True):
|
|
518
518
|
e, d = msg["event"], msg["data"]
|
|
519
519
|
if e == "task_event":
|
|
520
520
|
# navigation | screenshot | plan | action | validation | done
|
|
@@ -534,11 +534,11 @@ Returns the batch ID immediately. Use for long-running batches or background job
|
|
|
534
534
|
```python
|
|
535
535
|
import time
|
|
536
536
|
|
|
537
|
-
r = client.
|
|
537
|
+
r = client.browser_agent(tasks, run_async=True)
|
|
538
538
|
# {"id": "batch_abc", "status": "processing", "completed": 0, "total": 3}
|
|
539
539
|
|
|
540
540
|
while True:
|
|
541
|
-
state = client.
|
|
541
|
+
state = client.get_browser_agent(r["id"])
|
|
542
542
|
print(f"{state['completed']}/{state['total']}")
|
|
543
543
|
for done in state["results"]:
|
|
544
544
|
print(f" ✓ {done['url']} -> {done.get('data')}")
|
|
@@ -560,27 +560,27 @@ Each task's behavior is determined by which fields are set:
|
|
|
560
560
|
|
|
561
561
|
### Retrieving a batch with the full timeline
|
|
562
562
|
|
|
563
|
-
Every task records navigation, screenshots, LLM plans, actions, validations. Retrieve for audit, replay, or debugging
|
|
563
|
+
Every task records navigation, screenshots, LLM plans, actions, validations. Retrieve for audit, replay, or debugging. Screenshots are uploaded to a CDN during execution — retrieved events contain `data["url"]`, not base64.
|
|
564
564
|
|
|
565
565
|
```python
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
details = client.get_browser_tasks(batch_id, include_events=True)
|
|
566
|
+
details = client.get_browser_agent(batch_id, include_events=True)
|
|
569
567
|
for result in details["results"]:
|
|
570
568
|
for ev in result.get("events", []):
|
|
571
569
|
if ev["type"] == "screenshot":
|
|
572
|
-
|
|
573
|
-
|
|
570
|
+
# ev["data"]["url"] is a permanent CDN URL. Use directly in an <img>.
|
|
571
|
+
print(f"Iter {ev.get('iteration')} screenshot:", ev["data"]["url"])
|
|
574
572
|
elif ev["type"] == "plan":
|
|
575
573
|
print(f"Iter {ev.get('iteration')} plan: {ev['data'].get('notes')}")
|
|
576
574
|
```
|
|
577
575
|
|
|
576
|
+
> **Note:** The live SSE stream (`stream=True`) still sends screenshots inline as base64 (`ev["data"]["base64"]`) so live UIs render instantly. The retrieval path (`get_browser_agent`) always returns CDN URLs.
|
|
577
|
+
|
|
578
578
|
### Parallel batch example
|
|
579
579
|
|
|
580
580
|
```python
|
|
581
581
|
# Scrape 100 URLs with 20 browsers in parallel
|
|
582
582
|
urls = [...100 urls...]
|
|
583
|
-
result = client.
|
|
583
|
+
result = client.browser_agent(
|
|
584
584
|
[{"url": u, "output": {"type": "object", "properties": {"title": {"type": "string"}}}} for u in urls],
|
|
585
585
|
concurrency=20
|
|
586
586
|
)
|
|
@@ -591,10 +591,10 @@ print(f"{result['completed']}/{result['total']} done in {result['totalCreditsUse
|
|
|
591
591
|
|
|
592
592
|
| Method | Returns | Use when |
|
|
593
593
|
|---|---|---|
|
|
594
|
-
| `
|
|
595
|
-
| `
|
|
596
|
-
| `
|
|
597
|
-
| `
|
|
594
|
+
| `browser_agent(tasks, concurrency=N)` | dict | Default — wait for completion |
|
|
595
|
+
| `browser_agent(tasks, stream=True)` | iterator of SSE dicts | Live UI showing execution timeline |
|
|
596
|
+
| `browser_agent(tasks, run_async=True)` | dict (empty results, returned immediately) | Long batches, background jobs |
|
|
597
|
+
| `get_browser_agent(batch_id, include_events=False)` | dict | Poll progress or retrieve a completed batch |
|
|
598
598
|
|
|
599
599
|
### Task result statuses
|
|
600
600
|
|
|
@@ -608,27 +608,27 @@ class PredevAPI:
|
|
|
608
608
|
except requests.RequestException as e:
|
|
609
609
|
raise PredevAPIError(f"Request failed: {str(e)}") from e
|
|
610
610
|
|
|
611
|
-
def
|
|
611
|
+
def get_browser_agent(
|
|
612
612
|
self,
|
|
613
613
|
batch_id: str,
|
|
614
614
|
include_events: bool = False
|
|
615
615
|
) -> Dict[str, Any]:
|
|
616
616
|
"""
|
|
617
|
-
Get the status + results of a browser
|
|
617
|
+
Get the status + results of a browser-agent batch by ID.
|
|
618
618
|
|
|
619
|
-
Works for both in-progress and completed batches - use with
|
|
619
|
+
Works for both in-progress and completed batches - use with run_async=True
|
|
620
620
|
submissions to poll for progress. Set include_events=True to get the
|
|
621
621
|
full timeline (screenshots, plans, actions, validations) for each task.
|
|
622
622
|
|
|
623
623
|
Args:
|
|
624
|
-
batch_id: The batch ID returned from
|
|
624
|
+
batch_id: The batch ID returned from browser_agent()
|
|
625
625
|
include_events: Include full event timeline (can be large due to screenshots)
|
|
626
626
|
|
|
627
627
|
Returns:
|
|
628
628
|
Dict with id, total, completed, results, totalCost, totalCreditsUsed, status
|
|
629
629
|
"""
|
|
630
630
|
qs = "?includeEvents=true" if include_events else ""
|
|
631
|
-
url = f"{self.base_url}/
|
|
631
|
+
url = f"{self.base_url}/browser-agent/{batch_id}{qs}"
|
|
632
632
|
try:
|
|
633
633
|
response = requests.get(url, headers=self.headers, timeout=60)
|
|
634
634
|
self._handle_response(response)
|
|
@@ -636,7 +636,55 @@ class PredevAPI:
|
|
|
636
636
|
except requests.RequestException as e:
|
|
637
637
|
raise PredevAPIError(f"Request failed: {str(e)}") from e
|
|
638
638
|
|
|
639
|
-
def
|
|
639
|
+
def list_browser_agents(
|
|
640
|
+
self,
|
|
641
|
+
limit: Optional[int] = None,
|
|
642
|
+
skip: Optional[int] = None,
|
|
643
|
+
status: Optional[str] = None
|
|
644
|
+
) -> Dict[str, Any]:
|
|
645
|
+
"""
|
|
646
|
+
List browser-agent runs for the authenticated caller. Sorted by most recent.
|
|
647
|
+
|
|
648
|
+
Args:
|
|
649
|
+
limit: Page size (1-100, default 20)
|
|
650
|
+
skip: Offset for pagination
|
|
651
|
+
status: Optional filter ('processing' | 'completed')
|
|
652
|
+
|
|
653
|
+
Returns:
|
|
654
|
+
Dict with keys: batches, total, hasMore
|
|
655
|
+
"""
|
|
656
|
+
params: Dict[str, Any] = {}
|
|
657
|
+
if limit is not None:
|
|
658
|
+
params["limit"] = limit
|
|
659
|
+
if skip is not None:
|
|
660
|
+
params["skip"] = skip
|
|
661
|
+
if status is not None:
|
|
662
|
+
params["status"] = status
|
|
663
|
+
url = f"{self.base_url}/list-browser-agents"
|
|
664
|
+
try:
|
|
665
|
+
response = requests.get(url, headers=self.headers, params=params, timeout=60)
|
|
666
|
+
self._handle_response(response)
|
|
667
|
+
return response.json()
|
|
668
|
+
except requests.RequestException as e:
|
|
669
|
+
raise PredevAPIError(f"Request failed: {str(e)}") from e
|
|
670
|
+
|
|
671
|
+
def browser_agent_status(self) -> Dict[str, Any]:
|
|
672
|
+
"""
|
|
673
|
+
Caller's live queue snapshot. Useful for watching in-flight work
|
|
674
|
+
against the per-user queue cap (1000 live tasks).
|
|
675
|
+
|
|
676
|
+
Returns:
|
|
677
|
+
Dict with keys: userId, running, claimed, pending, total, cap
|
|
678
|
+
"""
|
|
679
|
+
url = f"{self.base_url}/browser-agent-status"
|
|
680
|
+
try:
|
|
681
|
+
response = requests.get(url, headers=self.headers, timeout=30)
|
|
682
|
+
self._handle_response(response)
|
|
683
|
+
return response.json()
|
|
684
|
+
except requests.RequestException as e:
|
|
685
|
+
raise PredevAPIError(f"Request failed: {str(e)}") from e
|
|
686
|
+
|
|
687
|
+
def browser_agent(
|
|
640
688
|
self,
|
|
641
689
|
tasks: List[Dict[str, Any]],
|
|
642
690
|
concurrency: Optional[int] = None,
|
|
@@ -644,7 +692,7 @@ class PredevAPI:
|
|
|
644
692
|
run_async: bool = False
|
|
645
693
|
) -> Union[Dict[str, Any], Iterator[Dict[str, Any]]]:
|
|
646
694
|
"""
|
|
647
|
-
Run browser automation tasks - scrape data, fill forms, navigate pages.
|
|
695
|
+
Run browser-agent automation tasks - scrape data, fill forms, navigate pages.
|
|
648
696
|
|
|
649
697
|
Always pass an array of tasks (even for a single task). Each task has a
|
|
650
698
|
url and optional instruction, input, and output schema.
|
|
@@ -658,6 +706,8 @@ class PredevAPI:
|
|
|
658
706
|
concurrency: Parallel browsers (default 5, max 20)
|
|
659
707
|
stream: If True, returns an iterator of SSE events instead of
|
|
660
708
|
waiting for all tasks to complete
|
|
709
|
+
run_async: If True, returns immediately with the batch id; poll
|
|
710
|
+
get_browser_agent(id) for progress.
|
|
661
711
|
|
|
662
712
|
Returns:
|
|
663
713
|
Without stream: Dict with id, total, completed, results, totalCost, totalCreditsUsed
|
|
@@ -669,20 +719,20 @@ class PredevAPI:
|
|
|
669
719
|
|
|
670
720
|
Example:
|
|
671
721
|
>>> # Standard mode
|
|
672
|
-
>>> result = client.
|
|
722
|
+
>>> result = client.browser_agent([
|
|
673
723
|
... {"url": "https://example.com", "output": {"type": "object", "properties": {"heading": {"type": "string"}}}}
|
|
674
724
|
... ])
|
|
675
725
|
>>> print(result["results"][0]["data"])
|
|
676
726
|
>>>
|
|
677
727
|
>>> # Stream mode
|
|
678
|
-
>>> for msg in client.
|
|
728
|
+
>>> for msg in client.browser_agent([...], stream=True):
|
|
679
729
|
... if msg["event"] == "done":
|
|
680
730
|
... print("Done:", msg["data"]["totalCreditsUsed"], "credits")
|
|
681
731
|
"""
|
|
682
732
|
if stream:
|
|
683
|
-
return self.
|
|
733
|
+
return self._browser_agent_stream(tasks, concurrency)
|
|
684
734
|
|
|
685
|
-
url = f"{self.base_url}/
|
|
735
|
+
url = f"{self.base_url}/browser-agent"
|
|
686
736
|
payload: Dict[str, Any] = {"tasks": tasks}
|
|
687
737
|
if concurrency is not None:
|
|
688
738
|
payload["concurrency"] = concurrency
|
|
@@ -701,13 +751,13 @@ class PredevAPI:
|
|
|
701
751
|
except requests.RequestException as e:
|
|
702
752
|
raise PredevAPIError(f"Request failed: {str(e)}") from e
|
|
703
753
|
|
|
704
|
-
def
|
|
754
|
+
def _browser_agent_stream(
|
|
705
755
|
self,
|
|
706
756
|
tasks: List[Dict[str, Any]],
|
|
707
757
|
concurrency: Optional[int] = None
|
|
708
758
|
) -> Iterator[Dict[str, Any]]:
|
|
709
|
-
"""SSE streaming implementation for
|
|
710
|
-
url = f"{self.base_url}/
|
|
759
|
+
"""SSE streaming implementation for browser_agent."""
|
|
760
|
+
url = f"{self.base_url}/browser-agent"
|
|
711
761
|
payload: Dict[str, Any] = {"tasks": tasks, "stream": True}
|
|
712
762
|
if concurrency is not None:
|
|
713
763
|
payload["concurrency"] = concurrency
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: predev-api
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: Python client for the Pre.dev Architect API - Generate comprehensive software specifications
|
|
5
5
|
Home-page: https://github.com/predotdev/predev-api
|
|
6
6
|
Author: Pre.dev
|
|
@@ -502,7 +502,7 @@ For issues, questions, or contributions, please visit the [GitHub repository](ht
|
|
|
502
502
|
|
|
503
503
|
## Browser Tasks
|
|
504
504
|
|
|
505
|
-
Run browser automation —
|
|
505
|
+
Run browser automation — navigate, interact, and/or extract data from any web page. Each task navigates a URL, performs actions, and optionally returns typed JSON.
|
|
506
506
|
|
|
507
507
|
### Quick start
|
|
508
508
|
|
|
@@ -511,7 +511,7 @@ from predev_api import PredevAPI
|
|
|
511
511
|
|
|
512
512
|
client = PredevAPI(api_key="your_api_key")
|
|
513
513
|
|
|
514
|
-
result = client.
|
|
514
|
+
result = client.browser_agent([
|
|
515
515
|
{
|
|
516
516
|
"url": "https://news.ycombinator.com",
|
|
517
517
|
"instruction": "Extract the top 5 stories",
|
|
@@ -542,7 +542,7 @@ for story in result["results"][0]["data"]["stories"]:
|
|
|
542
542
|
#### 1. Sync (default) — wait for completion
|
|
543
543
|
|
|
544
544
|
```python
|
|
545
|
-
result = client.
|
|
545
|
+
result = client.browser_agent([
|
|
546
546
|
{"url": "https://example.com", "output": {"type": "object", "properties": {"heading": {"type": "string"}}}}
|
|
547
547
|
])
|
|
548
548
|
print(result["results"][0]["data"]) # {'heading': 'Example Domain'}
|
|
@@ -554,7 +554,7 @@ print(result["totalCreditsUsed"]) # 0.1
|
|
|
554
554
|
Yields events as the agent runs. Good for showing progress in a UI.
|
|
555
555
|
|
|
556
556
|
```python
|
|
557
|
-
for msg in client.
|
|
557
|
+
for msg in client.browser_agent(tasks, stream=True):
|
|
558
558
|
e, d = msg["event"], msg["data"]
|
|
559
559
|
if e == "task_event":
|
|
560
560
|
# navigation | screenshot | plan | action | validation | done
|
|
@@ -574,11 +574,11 @@ Returns the batch ID immediately. Use for long-running batches or background job
|
|
|
574
574
|
```python
|
|
575
575
|
import time
|
|
576
576
|
|
|
577
|
-
r = client.
|
|
577
|
+
r = client.browser_agent(tasks, run_async=True)
|
|
578
578
|
# {"id": "batch_abc", "status": "processing", "completed": 0, "total": 3}
|
|
579
579
|
|
|
580
580
|
while True:
|
|
581
|
-
state = client.
|
|
581
|
+
state = client.get_browser_agent(r["id"])
|
|
582
582
|
print(f"{state['completed']}/{state['total']}")
|
|
583
583
|
for done in state["results"]:
|
|
584
584
|
print(f" ✓ {done['url']} -> {done.get('data')}")
|
|
@@ -600,27 +600,27 @@ Each task's behavior is determined by which fields are set:
|
|
|
600
600
|
|
|
601
601
|
### Retrieving a batch with the full timeline
|
|
602
602
|
|
|
603
|
-
Every task records navigation, screenshots, LLM plans, actions, validations. Retrieve for audit, replay, or debugging
|
|
603
|
+
Every task records navigation, screenshots, LLM plans, actions, validations. Retrieve for audit, replay, or debugging. Screenshots are uploaded to a CDN during execution — retrieved events contain `data["url"]`, not base64.
|
|
604
604
|
|
|
605
605
|
```python
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
details = client.get_browser_tasks(batch_id, include_events=True)
|
|
606
|
+
details = client.get_browser_agent(batch_id, include_events=True)
|
|
609
607
|
for result in details["results"]:
|
|
610
608
|
for ev in result.get("events", []):
|
|
611
609
|
if ev["type"] == "screenshot":
|
|
612
|
-
|
|
613
|
-
|
|
610
|
+
# ev["data"]["url"] is a permanent CDN URL. Use directly in an <img>.
|
|
611
|
+
print(f"Iter {ev.get('iteration')} screenshot:", ev["data"]["url"])
|
|
614
612
|
elif ev["type"] == "plan":
|
|
615
613
|
print(f"Iter {ev.get('iteration')} plan: {ev['data'].get('notes')}")
|
|
616
614
|
```
|
|
617
615
|
|
|
616
|
+
> **Note:** The live SSE stream (`stream=True`) still sends screenshots inline as base64 (`ev["data"]["base64"]`) so live UIs render instantly. The retrieval path (`get_browser_agent`) always returns CDN URLs.
|
|
617
|
+
|
|
618
618
|
### Parallel batch example
|
|
619
619
|
|
|
620
620
|
```python
|
|
621
621
|
# Scrape 100 URLs with 20 browsers in parallel
|
|
622
622
|
urls = [...100 urls...]
|
|
623
|
-
result = client.
|
|
623
|
+
result = client.browser_agent(
|
|
624
624
|
[{"url": u, "output": {"type": "object", "properties": {"title": {"type": "string"}}}} for u in urls],
|
|
625
625
|
concurrency=20
|
|
626
626
|
)
|
|
@@ -631,10 +631,10 @@ print(f"{result['completed']}/{result['total']} done in {result['totalCreditsUse
|
|
|
631
631
|
|
|
632
632
|
| Method | Returns | Use when |
|
|
633
633
|
|---|---|---|
|
|
634
|
-
| `
|
|
635
|
-
| `
|
|
636
|
-
| `
|
|
637
|
-
| `
|
|
634
|
+
| `browser_agent(tasks, concurrency=N)` | dict | Default — wait for completion |
|
|
635
|
+
| `browser_agent(tasks, stream=True)` | iterator of SSE dicts | Live UI showing execution timeline |
|
|
636
|
+
| `browser_agent(tasks, run_async=True)` | dict (empty results, returned immediately) | Long batches, background jobs |
|
|
637
|
+
| `get_browser_agent(batch_id, include_events=False)` | dict | Poll progress or retrieve a completed batch |
|
|
638
638
|
|
|
639
639
|
### Task result statuses
|
|
640
640
|
|
|
@@ -9,7 +9,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|
|
9
9
|
|
|
10
10
|
setup(
|
|
11
11
|
name="predev-api",
|
|
12
|
-
version="0.
|
|
12
|
+
version="1.0.0",
|
|
13
13
|
author="Pre.dev",
|
|
14
14
|
author_email="support@pre.dev",
|
|
15
15
|
description="Python client for the Pre.dev Architect API - Generate comprehensive software specifications",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|