Skip to content

Commit 3a29950

Browse files
feat(api): api update
1 parent 0204e2c commit 3a29950

7 files changed

Lines changed: 131 additions & 17 deletions

File tree

‎.stats.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 41
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-7e6b2353ee8631f506bd8ef7657f1684cddf84805c01d89c691d7f98c42127f7.yml
3-
openapi_spec_hash: b63b980d90fc9c2b896b2739a8e15a59
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-bf7ffa610bd4a02ea5bcb157521d17a041a48f78d87bf8fe8d812d3cbb87b489.yml
3+
openapi_spec_hash: 90142d96969dea44c46a01abb683c426
44
config_hash: 0fb0ceca5946298c416cec0cca5260c7

‎src/context/dev/resources/web.py‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def extract(
7171
*,
7272
schema: Dict[str, object],
7373
url: str,
74+
actions: Iterable[web_extract_params.Action] | Omit = omit,
7475
fact_check: bool | Omit = omit,
7576
follow_subdomains: bool | Omit = omit,
7677
include_frames: bool | Omit = omit,
@@ -96,13 +97,19 @@ def extract(
9697
relevant internal links, and extract structured data from the selected pages.
9798
9899
Args:
99-
schema: JSON Schema for the returned data object. TypeScript Zod users can pass a JSON
100-
Schema generated from a Zod object; Python users can pass the equivalent JSON
101-
Schema object.
100+
schema: JSON Schema for the returned data object. Image fields such as `image_urls` or
101+
`product_photos` automatically make page image references available to
102+
extraction, so product data and photos can be returned in one call. TypeScript
103+
Zod users can pass a JSON Schema generated from a Zod object; Python users can
104+
pass the equivalent JSON Schema object.
102105
103106
url: The starting website URL to crawl and extract from. Must include http:// or
104107
https://.
105108
109+
actions: Optional browser actions executed in order on the requested page after it loads
110+
and before extraction. Requires a paid plan. When actions are provided and
111+
stopAfterMs is omitted, the crawl budget defaults to 110000 ms.
112+
106113
fact_check: When true, every returned value must be grounded in facts stated on the page;
107114
fields that cannot be supported by the page are returned as null/empty. When
108115
false (default), the model may make reasonable inferences and derivations from
@@ -130,7 +137,8 @@ def extract(
130137
exchange for more stable output on animated pages.
131138
132139
stop_after_ms: Soft time budget for the crawl in milliseconds. Min: 10000 (10s). Max: 110000
133-
(110s). Default: 80000 (80s).
140+
(110s). Defaults to 80000 (80s), or 110000 (110s) when browser actions are
141+
provided.
134142
135143
tags: Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.
136144
@@ -155,6 +163,7 @@ def extract(
155163
{
156164
"schema": schema,
157165
"url": url,
166+
"actions": actions,
158167
"fact_check": fact_check,
159168
"follow_subdomains": follow_subdomains,
160169
"include_frames": include_frames,
@@ -2311,6 +2320,7 @@ async def extract(
23112320
*,
23122321
schema: Dict[str, object],
23132322
url: str,
2323+
actions: Iterable[web_extract_params.Action] | Omit = omit,
23142324
fact_check: bool | Omit = omit,
23152325
follow_subdomains: bool | Omit = omit,
23162326
include_frames: bool | Omit = omit,
@@ -2336,13 +2346,19 @@ async def extract(
23362346
relevant internal links, and extract structured data from the selected pages.
23372347
23382348
Args:
2339-
schema: JSON Schema for the returned data object. TypeScript Zod users can pass a JSON
2340-
Schema generated from a Zod object; Python users can pass the equivalent JSON
2341-
Schema object.
2349+
schema: JSON Schema for the returned data object. Image fields such as `image_urls` or
2350+
`product_photos` automatically make page image references available to
2351+
extraction, so product data and photos can be returned in one call. TypeScript
2352+
Zod users can pass a JSON Schema generated from a Zod object; Python users can
2353+
pass the equivalent JSON Schema object.
23422354
23432355
url: The starting website URL to crawl and extract from. Must include http:// or
23442356
https://.
23452357
2358+
actions: Optional browser actions executed in order on the requested page after it loads
2359+
and before extraction. Requires a paid plan. When actions are provided and
2360+
stopAfterMs is omitted, the crawl budget defaults to 110000 ms.
2361+
23462362
fact_check: When true, every returned value must be grounded in facts stated on the page;
23472363
fields that cannot be supported by the page are returned as null/empty. When
23482364
false (default), the model may make reasonable inferences and derivations from
@@ -2370,7 +2386,8 @@ async def extract(
23702386
exchange for more stable output on animated pages.
23712387
23722388
stop_after_ms: Soft time budget for the crawl in milliseconds. Min: 10000 (10s). Max: 110000
2373-
(110s). Default: 80000 (80s).
2389+
(110s). Defaults to 80000 (80s), or 110000 (110s) when browser actions are
2390+
provided.
23742391
23752392
tags: Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.
23762393
@@ -2395,6 +2412,7 @@ async def extract(
23952412
{
23962413
"schema": schema,
23972414
"url": url,
2415+
"actions": actions,
23982416
"fact_check": fact_check,
23992417
"follow_subdomains": follow_subdomains,
24002418
"include_frames": include_frames,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ class Product(BaseModel):
4545
target_audience: List[str]
4646
"""Target audience for the product (array of strings)"""
4747

48+
availability: Optional[
49+
Literal[
50+
"in_stock", "out_of_stock", "limited_availability", "preorder", "backorder", "made_to_order", "discontinued"
51+
]
52+
] = None
53+
"""Normalized stock or ordering availability"""
54+
4855
billing_frequency: Optional[Literal["monthly", "yearly", "one_time", "usage_based"]] = None
4956
"""Billing frequency for the product"""
5057

@@ -54,6 +61,11 @@ class Product(BaseModel):
5461
currency: Optional[str] = None
5562
"""Currency code for the price (e.g., USD, EUR)"""
5663

64+
dimensions: Optional[List[str]] = None
65+
"""
66+
Dimension statements shown for the product, preserving labels, values, and units
67+
"""
68+
5769
image_url: Optional[str] = None
5870
"""URL to the product image"""
5971

@@ -63,6 +75,9 @@ class Product(BaseModel):
6375
pricing_model: Optional[Literal["per_seat", "flat", "tiered", "freemium", "custom"]] = None
6476
"""Pricing model for the product"""
6577

78+
regular_price: Optional[float] = None
79+
"""Original or regular price before a displayed discount"""
80+
6681
url: Optional[str] = None
6782
"""URL to the product page"""
6883

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ class Product(BaseModel):
4343
target_audience: List[str]
4444
"""Target audience for the product (array of strings)"""
4545

46+
availability: Optional[
47+
Literal[
48+
"in_stock", "out_of_stock", "limited_availability", "preorder", "backorder", "made_to_order", "discontinued"
49+
]
50+
] = None
51+
"""Normalized stock or ordering availability"""
52+
4653
billing_frequency: Optional[Literal["monthly", "yearly", "one_time", "usage_based"]] = None
4754
"""Billing frequency for the product"""
4855

@@ -52,6 +59,11 @@ class Product(BaseModel):
5259
currency: Optional[str] = None
5360
"""Currency code for the price (e.g., USD, EUR)"""
5461

62+
dimensions: Optional[List[str]] = None
63+
"""
64+
Dimension statements shown for the product, preserving labels, values, and units
65+
"""
66+
5567
image_url: Optional[str] = None
5668
"""URL to the product image"""
5769

@@ -61,6 +73,9 @@ class Product(BaseModel):
6173
pricing_model: Optional[Literal["per_seat", "flat", "tiered", "freemium", "custom"]] = None
6274
"""Pricing model for the product"""
6375

76+
regular_price: Optional[float] = None
77+
"""Original or regular price before a displayed discount"""
78+
6479
url: Optional[str] = None
6580
"""URL to the product page"""
6681

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

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22

33
from __future__ import annotations
44

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

88
from .._types import SequenceNotStr
99
from .._utils import PropertyInfo
1010

11-
__all__ = ["WebExtractParams", "Pdf"]
11+
__all__ = ["WebExtractParams", "Action", "ActionWebScrapeWaitAction", "ActionWebScrapePerformAction", "Pdf"]
1212

1313

1414
class WebExtractParams(TypedDict, total=False):
1515
schema: Required[Dict[str, object]]
1616
"""JSON Schema for the returned data object.
1717
18-
TypeScript Zod users can pass a JSON Schema generated from a Zod object; Python
19-
users can pass the equivalent JSON Schema object.
18+
Image fields such as `image_urls` or `product_photos` automatically make page
19+
image references available to extraction, so product data and photos can be
20+
returned in one call. TypeScript Zod users can pass a JSON Schema generated from
21+
a Zod object; Python users can pass the equivalent JSON Schema object.
2022
"""
2123

2224
url: Required[str]
@@ -25,6 +27,13 @@ class WebExtractParams(TypedDict, total=False):
2527
Must include http:// or https://.
2628
"""
2729

30+
actions: Iterable[Action]
31+
"""
32+
Optional browser actions executed in order on the requested page after it loads
33+
and before extraction. Requires a paid plan. When actions are provided and
34+
stopAfterMs is omitted, the crawl budget defaults to 110000 ms.
35+
"""
36+
2837
fact_check: Annotated[bool, PropertyInfo(alias="factCheck")]
2938
"""
3039
When true, every returned value must be grounded in facts stated on the page;
@@ -74,7 +83,8 @@ class WebExtractParams(TypedDict, total=False):
7483
stop_after_ms: Annotated[int, PropertyInfo(alias="stopAfterMs")]
7584
"""Soft time budget for the crawl in milliseconds.
7685
77-
Min: 10000 (10s). Max: 110000 (110s). Default: 80000 (80s).
86+
Min: 10000 (10s). Max: 110000 (110s). Defaults to 80000 (80s), or 110000 (110s)
87+
when browser actions are provided.
7888
"""
7989

8090
tags: SequenceNotStr[str]
@@ -94,6 +104,25 @@ class WebExtractParams(TypedDict, total=False):
94104
"""
95105

96106

107+
class ActionWebScrapeWaitAction(TypedDict, total=False):
108+
"""Pause for a fixed number of milliseconds before continuing to the next action."""
109+
110+
do: Required[Literal["wait"]]
111+
112+
time_ms: Required[Annotated[int, PropertyInfo(alias="timeMs")]]
113+
114+
115+
class ActionWebScrapePerformAction(TypedDict, total=False):
116+
"""Resolve and perform one natural-language browser action."""
117+
118+
action: Required[str]
119+
120+
do: Required[Literal["perform"]]
121+
122+
123+
Action: TypeAlias = Union[ActionWebScrapeWaitAction, ActionWebScrapePerformAction]
124+
125+
97126
class Pdf(TypedDict, total=False):
98127
end: int
99128
"""Last 1-based PDF page to parse.

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
from typing import Dict, List, Optional
4+
from typing_extensions import Literal
45

56
from pydantic import Field as FieldInfo
67

78
from .._models import BaseModel
89

9-
__all__ = ["WebExtractResponse", "Metadata", "KeyMetadata"]
10+
__all__ = ["WebExtractResponse", "Metadata", "MetadataActionsApplied", "KeyMetadata"]
11+
12+
13+
class MetadataActionsApplied(BaseModel):
14+
instruction: str
15+
16+
status: Literal["applied", "failed", "skipped"]
17+
"""Applied means the requested page state was visibly verified.
18+
19+
Failed means it was not verified. Skipped means it was not attempted.
20+
"""
21+
22+
completion_evidence: Optional[str] = FieldInfo(alias="completionEvidence", default=None)
23+
"""Visible page evidence used to verify an applied action."""
24+
25+
duration_ms: Optional[float] = FieldInfo(alias="durationMs", default=None)
26+
27+
error: Optional[str] = None
28+
29+
method: Optional[str] = None
30+
31+
target_description: Optional[str] = FieldInfo(alias="targetDescription", default=None)
1032

1133

1234
class Metadata(BaseModel):
@@ -26,6 +48,9 @@ class Metadata(BaseModel):
2648

2749
num_urls: int = FieldInfo(alias="numUrls")
2850

51+
actions_applied: Optional[List[MetadataActionsApplied]] = FieldInfo(alias="actionsApplied", default=None)
52+
"""One verified outcome per requested browser action, in request order."""
53+
2954

3055
class KeyMetadata(BaseModel):
3156
"""Metadata about the API key used for the request.

‎tests/api_resources/test_web.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ def test_method_extract_with_all_params(self, client: ContextDev) -> None:
5454
"additionalProperties": "bar",
5555
},
5656
url="https://example.com",
57+
actions=[
58+
{
59+
"do": "wait",
60+
"time_ms": 0,
61+
}
62+
],
5763
fact_check=True,
5864
follow_subdomains=True,
5965
include_frames=True,
@@ -701,6 +707,12 @@ async def test_method_extract_with_all_params(self, async_client: AsyncContextDe
701707
"additionalProperties": "bar",
702708
},
703709
url="https://example.com",
710+
actions=[
711+
{
712+
"do": "wait",
713+
"time_ms": 0,
714+
}
715+
],
704716
fact_check=True,
705717
follow_subdomains=True,
706718
include_frames=True,

0 commit comments

Comments
 (0)