Skip to content

Commit 7918ce8

Browse files
author
stlc-bot
committed
feat(monitors): support browser actions on page monitors (#1365)
Stainless-Generated-From: 026570fcbaed73c709e2ca29aaa5eec6acfcbe7b
1 parent 1a159d4 commit 7918ce8

8 files changed

Lines changed: 500 additions & 4 deletions

‎src/context/dev/types/monitor_create_params.py‎

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22

33
from __future__ import annotations
44

5-
from typing import Dict, List, Union, Optional
6-
from typing_extensions import Literal, Required, TypeAlias, TypedDict
5+
from typing import Dict, List, Union, Iterable, Optional
6+
from typing_extensions import Literal, Required, Annotated, TypeAlias, TypedDict
77

88
from .._types import SequenceNotStr
9+
from .._utils import PropertyInfo
910
from .retry_config_param import RetryConfigParam
1011

1112
__all__ = [
1213
"MonitorCreateParams",
1314
"Target",
1415
"TargetMonitorsPageTarget",
16+
"TargetMonitorsPageTargetAction",
17+
"TargetMonitorsPageTargetActionWebScrapeWaitAction",
18+
"TargetMonitorsPageTargetActionWebScrapePerformAction",
19+
"TargetMonitorsPageTargetActionWebScrapeScrollAction",
1520
"TargetMonitorsSitemapTarget",
1621
"TargetMonitorsExtractTarget",
1722
"ChangeDetection",
@@ -53,6 +58,60 @@ class MonitorCreateParams(TypedDict, total=False):
5358
"""Webhook destination and delivery settings. Null means no webhook is configured."""
5459

5560

61+
class TargetMonitorsPageTargetActionWebScrapeWaitAction(TypedDict, total=False):
62+
"""Pause for a fixed number of milliseconds before continuing to the next action."""
63+
64+
do: Required[Literal["wait"]]
65+
"""Use `wait` to pause for a fixed duration."""
66+
67+
time_ms: Required[Annotated[int, PropertyInfo(alias="timeMs")]]
68+
"""Time to pause in milliseconds before the next action."""
69+
70+
71+
class TargetMonitorsPageTargetActionWebScrapePerformAction(TypedDict, total=False):
72+
"""Resolve and perform one natural-language browser action."""
73+
74+
action: Required[str]
75+
"""One browser instruction, such as clicking a button or entering text."""
76+
77+
do: Required[Literal["perform"]]
78+
"""Use `perform` for a plain-language browser instruction."""
79+
80+
81+
class TargetMonitorsPageTargetActionWebScrapeScrollAction(TypedDict, total=False):
82+
"""
83+
Scroll the page or a selected scrollable container, waiting adaptively for content and dimensions to settle after each iteration.
84+
"""
85+
86+
do: Required[Literal["scroll"]]
87+
"""Use `scroll` to move through the page or a container."""
88+
89+
amount: Union[int, Literal["viewport", "max"]]
90+
"""Pixels per scroll, one visible viewport, or the current scroll boundary.
91+
92+
Defaults to viewport.
93+
"""
94+
95+
container: str
96+
"""CSS selector for the first matching scroll container. Defaults to the page."""
97+
98+
direction: Literal["up", "down", "left", "right"]
99+
"""Direction to scroll. Defaults to down."""
100+
101+
max_scrolls: Annotated[int, PropertyInfo(alias="maxScrolls")]
102+
"""Maximum scroll iterations.
103+
104+
Stops early when scrolling and scrollable extent stop changing. Defaults to 1.
105+
"""
106+
107+
108+
TargetMonitorsPageTargetAction: TypeAlias = Union[
109+
TargetMonitorsPageTargetActionWebScrapeWaitAction,
110+
TargetMonitorsPageTargetActionWebScrapePerformAction,
111+
TargetMonitorsPageTargetActionWebScrapeScrollAction,
112+
]
113+
114+
56115
class TargetMonitorsPageTarget(TypedDict, total=False):
57116
"""Watch a single web page.
58117
@@ -65,6 +124,13 @@ class TargetMonitorsPageTarget(TypedDict, total=False):
65124
url: Required[str]
66125
"""Public HTTP(S) page URL to monitor."""
67126

127+
actions: Optional[Iterable[TargetMonitorsPageTargetAction]]
128+
"""
129+
Optional browser actions executed in array order after the page loads, before
130+
content is captured, on every run. Requires a paid plan. Maximum: 5 actions.
131+
Changes create a new baseline.
132+
"""
133+
68134
exclude_selectors: SequenceNotStr[str]
69135
"""Remove matching regions after inclusions. Changes create a new baseline."""
70136

‎src/context/dev/types/monitor_create_response.py‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"ChangeDetectionMonitorsSemanticChangeDetection",
1818
"Target",
1919
"TargetMonitorsPageTarget",
20+
"TargetMonitorsPageTargetAction",
21+
"TargetMonitorsPageTargetActionWebScrapeWaitAction",
22+
"TargetMonitorsPageTargetActionWebScrapePerformAction",
23+
"TargetMonitorsPageTargetActionWebScrapeScrollAction",
2024
"TargetMonitorsSitemapTarget",
2125
"TargetMonitorsExtractTarget",
2226
"Baseline",
@@ -59,6 +63,63 @@ class ChangeDetectionMonitorsSemanticChangeDetection(BaseModel):
5963
]
6064

6165

66+
class TargetMonitorsPageTargetActionWebScrapeWaitAction(BaseModel):
67+
"""Pause for a fixed number of milliseconds before continuing to the next action."""
68+
69+
do: Literal["wait"]
70+
"""Use `wait` to pause for a fixed duration."""
71+
72+
time_ms: int = FieldInfo(alias="timeMs")
73+
"""Time to pause in milliseconds before the next action."""
74+
75+
76+
class TargetMonitorsPageTargetActionWebScrapePerformAction(BaseModel):
77+
"""Resolve and perform one natural-language browser action."""
78+
79+
action: str
80+
"""One browser instruction, such as clicking a button or entering text."""
81+
82+
do: Literal["perform"]
83+
"""Use `perform` for a plain-language browser instruction."""
84+
85+
86+
class TargetMonitorsPageTargetActionWebScrapeScrollAction(BaseModel):
87+
"""
88+
Scroll the page or a selected scrollable container, waiting adaptively for content and dimensions to settle after each iteration.
89+
"""
90+
91+
do: Literal["scroll"]
92+
"""Use `scroll` to move through the page or a container."""
93+
94+
amount: Union[int, Literal["viewport", "max"], None] = None
95+
"""Pixels per scroll, one visible viewport, or the current scroll boundary.
96+
97+
Defaults to viewport.
98+
"""
99+
100+
container: Optional[str] = None
101+
"""CSS selector for the first matching scroll container. Defaults to the page."""
102+
103+
direction: Optional[Literal["up", "down", "left", "right"]] = None
104+
"""Direction to scroll. Defaults to down."""
105+
106+
max_scrolls: Optional[int] = FieldInfo(alias="maxScrolls", default=None)
107+
"""Maximum scroll iterations.
108+
109+
Stops early when scrolling and scrollable extent stop changing. Defaults to 1.
110+
"""
111+
112+
113+
TargetMonitorsPageTargetAction: TypeAlias = Annotated[
114+
Union[
115+
TargetMonitorsPageTargetActionWebScrapeWaitAction,
116+
TargetMonitorsPageTargetActionWebScrapePerformAction,
117+
TargetMonitorsPageTargetActionWebScrapeScrollAction,
118+
],
119+
PropertyInfo(discriminator="do"),
120+
]
121+
122+
62123
class TargetMonitorsPageTarget(BaseModel):
63124
"""Watch a single web page.
64125
@@ -71,6 +132,13 @@ class TargetMonitorsPageTarget(BaseModel):
71132
url: str
72133
"""Public HTTP(S) page URL to monitor."""
73134

135+
actions: Optional[List[TargetMonitorsPageTargetAction]] = None
136+
"""
137+
Optional browser actions executed in array order after the page loads, before
138+
content is captured, on every run. Requires a paid plan. Maximum: 5 actions.
139+
Changes create a new baseline.
140+
"""
141+
74142
exclude_selectors: Optional[List[str]] = None
75143
"""Remove matching regions after inclusions. Changes create a new baseline."""
76144

‎src/context/dev/types/monitor_list_response.py‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
"DataSchedule",
2020
"DataTarget",
2121
"DataTargetMonitorsPageTarget",
22+
"DataTargetMonitorsPageTargetAction",
23+
"DataTargetMonitorsPageTargetActionWebScrapeWaitAction",
24+
"DataTargetMonitorsPageTargetActionWebScrapePerformAction",
25+
"DataTargetMonitorsPageTargetActionWebScrapeScrollAction",
2226
"DataTargetMonitorsSitemapTarget",
2327
"DataTargetMonitorsExtractTarget",
2428
"DataBaseline",
@@ -81,6 +85,63 @@ class DataSchedule(BaseModel):
8185
"""Time unit used with `frequency` to set the run interval."""
8286

8387

88+
class DataTargetMonitorsPageTargetActionWebScrapeWaitAction(BaseModel):
89+
"""Pause for a fixed number of milliseconds before continuing to the next action."""
90+
91+
do: Literal["wait"]
92+
"""Use `wait` to pause for a fixed duration."""
93+
94+
time_ms: int = FieldInfo(alias="timeMs")
95+
"""Time to pause in milliseconds before the next action."""
96+
97+
98+
class DataTargetMonitorsPageTargetActionWebScrapePerformAction(BaseModel):
99+
"""Resolve and perform one natural-language browser action."""
100+
101+
action: str
102+
"""One browser instruction, such as clicking a button or entering text."""
103+
104+
do: Literal["perform"]
105+
"""Use `perform` for a plain-language browser instruction."""
106+
107+
108+
class DataTargetMonitorsPageTargetActionWebScrapeScrollAction(BaseModel):
109+
"""
110+
Scroll the page or a selected scrollable container, waiting adaptively for content and dimensions to settle after each iteration.
111+
"""
112+
113+
do: Literal["scroll"]
114+
"""Use `scroll` to move through the page or a container."""
115+
116+
amount: Union[int, Literal["viewport", "max"], None] = None
117+
"""Pixels per scroll, one visible viewport, or the current scroll boundary.
118+
119+
Defaults to viewport.
120+
"""
121+
122+
container: Optional[str] = None
123+
"""CSS selector for the first matching scroll container. Defaults to the page."""
124+
125+
direction: Optional[Literal["up", "down", "left", "right"]] = None
126+
"""Direction to scroll. Defaults to down."""
127+
128+
max_scrolls: Optional[int] = FieldInfo(alias="maxScrolls", default=None)
129+
"""Maximum scroll iterations.
130+
131+
Stops early when scrolling and scrollable extent stop changing. Defaults to 1.
132+
"""
133+
134+
135+
DataTargetMonitorsPageTargetAction: TypeAlias = Annotated[
136+
Union[
137+
DataTargetMonitorsPageTargetActionWebScrapeWaitAction,
138+
DataTargetMonitorsPageTargetActionWebScrapePerformAction,
139+
DataTargetMonitorsPageTargetActionWebScrapeScrollAction,
140+
],
141+
PropertyInfo(discriminator="do"),
142+
]
143+
144+
84145
class DataTargetMonitorsPageTarget(BaseModel):
85146
"""Watch a single web page.
86147
@@ -93,6 +154,13 @@ class DataTargetMonitorsPageTarget(BaseModel):
93154
url: str
94155
"""Public HTTP(S) page URL to monitor."""
95156

157+
actions: Optional[List[DataTargetMonitorsPageTargetAction]] = None
158+
"""
159+
Optional browser actions executed in array order after the page loads, before
160+
content is captured, on every run. Requires a paid plan. Maximum: 5 actions.
161+
Changes create a new baseline.
162+
"""
163+
96164
exclude_selectors: Optional[List[str]] = None
97165
"""Remove matching regions after inclusions. Changes create a new baseline."""
98166

‎src/context/dev/types/monitor_retrieve_response.py‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"ChangeDetectionMonitorsSemanticChangeDetection",
1818
"Target",
1919
"TargetMonitorsPageTarget",
20+
"TargetMonitorsPageTargetAction",
21+
"TargetMonitorsPageTargetActionWebScrapeWaitAction",
22+
"TargetMonitorsPageTargetActionWebScrapePerformAction",
23+
"TargetMonitorsPageTargetActionWebScrapeScrollAction",
2024
"TargetMonitorsSitemapTarget",
2125
"TargetMonitorsExtractTarget",
2226
"Baseline",
@@ -59,6 +63,63 @@ class ChangeDetectionMonitorsSemanticChangeDetection(BaseModel):
5963
]
6064

6165

66+
class TargetMonitorsPageTargetActionWebScrapeWaitAction(BaseModel):
67+
"""Pause for a fixed number of milliseconds before continuing to the next action."""
68+
69+
do: Literal["wait"]
70+
"""Use `wait` to pause for a fixed duration."""
71+
72+
time_ms: int = FieldInfo(alias="timeMs")
73+
"""Time to pause in milliseconds before the next action."""
74+
75+
76+
class TargetMonitorsPageTargetActionWebScrapePerformAction(BaseModel):
77+
"""Resolve and perform one natural-language browser action."""
78+
79+
action: str
80+
"""One browser instruction, such as clicking a button or entering text."""
81+
82+
do: Literal["perform"]
83+
"""Use `perform` for a plain-language browser instruction."""
84+
85+
86+
class TargetMonitorsPageTargetActionWebScrapeScrollAction(BaseModel):
87+
"""
88+
Scroll the page or a selected scrollable container, waiting adaptively for content and dimensions to settle after each iteration.
89+
"""
90+
91+
do: Literal["scroll"]
92+
"""Use `scroll` to move through the page or a container."""
93+
94+
amount: Union[int, Literal["viewport", "max"], None] = None
95+
"""Pixels per scroll, one visible viewport, or the current scroll boundary.
96+
97+
Defaults to viewport.
98+
"""
99+
100+
container: Optional[str] = None
101+
"""CSS selector for the first matching scroll container. Defaults to the page."""
102+
103+
direction: Optional[Literal["up", "down", "left", "right"]] = None
104+
"""Direction to scroll. Defaults to down."""
105+
106+
max_scrolls: Optional[int] = FieldInfo(alias="maxScrolls", default=None)
107+
"""Maximum scroll iterations.
108+
109+
Stops early when scrolling and scrollable extent stop changing. Defaults to 1.
110+
"""
111+
112+
113+
TargetMonitorsPageTargetAction: TypeAlias = Annotated[
114+
Union[
115+
TargetMonitorsPageTargetActionWebScrapeWaitAction,
116+
TargetMonitorsPageTargetActionWebScrapePerformAction,
117+
TargetMonitorsPageTargetActionWebScrapeScrollAction,
118+
],
119+
PropertyInfo(discriminator="do"),
120+
]
121+
122+
62123
class TargetMonitorsPageTarget(BaseModel):
63124
"""Watch a single web page.
64125
@@ -71,6 +132,13 @@ class TargetMonitorsPageTarget(BaseModel):
71132
url: str
72133
"""Public HTTP(S) page URL to monitor."""
73134

135+
actions: Optional[List[TargetMonitorsPageTargetAction]] = None
136+
"""
137+
Optional browser actions executed in array order after the page loads, before
138+
content is captured, on every run. Requires a paid plan. Maximum: 5 actions.
139+
Changes create a new baseline.
140+
"""
141+
74142
exclude_selectors: Optional[List[str]] = None
75143
"""Remove matching regions after inclusions. Changes create a new baseline."""
76144

0 commit comments

Comments
 (0)