Skip to content

Commit a60fa2b

Browse files
feat: Accept browser session name on all /browsers/{id_or_name} sub-resource routes
Stainless-Generated-From: c2d7f09673a4d607dd628011d15d4a531c152d8e
1 parent b4e537e commit a60fa2b

37 files changed

Lines changed: 1809 additions & 946 deletions

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
configured_endpoints: 145
1+
configured_endpoints: 147

api.md

Lines changed: 66 additions & 44 deletions
Large diffs are not rendered by default.

src/kernel/resources/browsers/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
LogsResourceWithStreamingResponse,
1717
AsyncLogsResourceWithStreamingResponse,
1818
)
19+
from .webmcp import (
20+
WebmcpResource,
21+
AsyncWebmcpResource,
22+
WebmcpResourceWithRawResponse,
23+
AsyncWebmcpResourceWithRawResponse,
24+
WebmcpResourceWithStreamingResponse,
25+
AsyncWebmcpResourceWithStreamingResponse,
26+
)
1927
from .process import (
2028
ProcessResource,
2129
AsyncProcessResource,
@@ -108,6 +116,12 @@
108116
"AsyncPlaywrightResourceWithRawResponse",
109117
"PlaywrightResourceWithStreamingResponse",
110118
"AsyncPlaywrightResourceWithStreamingResponse",
119+
"WebmcpResource",
120+
"AsyncWebmcpResource",
121+
"WebmcpResourceWithRawResponse",
122+
"AsyncWebmcpResourceWithRawResponse",
123+
"WebmcpResourceWithStreamingResponse",
124+
"AsyncWebmcpResourceWithStreamingResponse",
111125
"BrowsersResource",
112126
"AsyncBrowsersResource",
113127
"BrowsersResourceWithRawResponse",

src/kernel/resources/browsers/browsers.py

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
FsResourceWithStreamingResponse,
2525
AsyncFsResourceWithStreamingResponse,
2626
)
27+
from .webmcp import (
28+
WebmcpResource,
29+
AsyncWebmcpResource,
30+
WebmcpResourceWithRawResponse,
31+
AsyncWebmcpResourceWithRawResponse,
32+
WebmcpResourceWithStreamingResponse,
33+
AsyncWebmcpResourceWithStreamingResponse,
34+
)
2735
from ...types import (
2836
BrowserMemoryRequest,
2937
browser_curl_params,
@@ -148,6 +156,11 @@ def playwright(self) -> PlaywrightResource:
148156
"""Execute Playwright code against the browser instance."""
149157
return PlaywrightResource(self._client)
150158

159+
@cached_property
160+
def webmcp(self) -> WebmcpResource:
161+
"""Discover and invoke native page tools across the browser instance."""
162+
return WebmcpResource(self._client)
163+
151164
@cached_property
152165
def with_raw_response(self) -> BrowsersResourceWithRawResponse:
153166
"""
@@ -527,7 +540,7 @@ def list(
527540

528541
def curl(
529542
self,
530-
id: str,
543+
id_or_name: str,
531544
*,
532545
url: str,
533546
body: str | Omit = omit,
@@ -568,10 +581,10 @@ def curl(
568581
569582
timeout: Override the client-level default timeout for this request, in seconds
570583
"""
571-
if not id:
572-
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
584+
if not id_or_name:
585+
raise ValueError(f"Expected a non-empty value for `id_or_name` but received {id_or_name!r}")
573586
return self._post(
574-
path_template("/browsers/{id}/curl", id=id),
587+
path_template("/browsers/{id_or_name}/curl", id_or_name=id_or_name),
575588
body=maybe_transform(
576589
{
577590
"url": url,
@@ -683,7 +696,7 @@ def delete_by_id(
683696

684697
def load_extensions(
685698
self,
686-
id: str,
699+
id_or_name: str,
687700
*,
688701
extensions: Iterable[browser_load_extensions_params.Extension],
689702
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -708,8 +721,8 @@ def load_extensions(
708721
709722
timeout: Override the client-level default timeout for this request, in seconds
710723
"""
711-
if not id:
712-
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
724+
if not id_or_name:
725+
raise ValueError(f"Expected a non-empty value for `id_or_name` but received {id_or_name!r}")
713726
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
714727
body = deepcopy_with_paths({"extensions": extensions}, [["extensions", "<array>", "zip_file"]])
715728
files = extract_files(cast(Mapping[str, object], body), paths=[["extensions", "<array>", "zip_file"]])
@@ -718,7 +731,7 @@ def load_extensions(
718731
# multipart/form-data; boundary=---abc--
719732
extra_headers["Content-Type"] = "multipart/form-data"
720733
return self._post(
721-
path_template("/browsers/{id}/extensions", id=id),
734+
path_template("/browsers/{id_or_name}/extensions", id_or_name=id_or_name),
722735
body=maybe_transform(body, browser_load_extensions_params.BrowserLoadExtensionsParams),
723736
files=files,
724737
options=make_request_options(
@@ -768,6 +781,11 @@ def playwright(self) -> AsyncPlaywrightResource:
768781
"""Execute Playwright code against the browser instance."""
769782
return AsyncPlaywrightResource(self._client)
770783

784+
@cached_property
785+
def webmcp(self) -> AsyncWebmcpResource:
786+
"""Discover and invoke native page tools across the browser instance."""
787+
return AsyncWebmcpResource(self._client)
788+
771789
@cached_property
772790
def with_raw_response(self) -> AsyncBrowsersResourceWithRawResponse:
773791
"""
@@ -1147,7 +1165,7 @@ def list(
11471165

11481166
async def curl(
11491167
self,
1150-
id: str,
1168+
id_or_name: str,
11511169
*,
11521170
url: str,
11531171
body: str | Omit = omit,
@@ -1188,10 +1206,10 @@ async def curl(
11881206
11891207
timeout: Override the client-level default timeout for this request, in seconds
11901208
"""
1191-
if not id:
1192-
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
1209+
if not id_or_name:
1210+
raise ValueError(f"Expected a non-empty value for `id_or_name` but received {id_or_name!r}")
11931211
return await self._post(
1194-
path_template("/browsers/{id}/curl", id=id),
1212+
path_template("/browsers/{id_or_name}/curl", id_or_name=id_or_name),
11951213
body=await async_maybe_transform(
11961214
{
11971215
"url": url,
@@ -1303,7 +1321,7 @@ async def delete_by_id(
13031321

13041322
async def load_extensions(
13051323
self,
1306-
id: str,
1324+
id_or_name: str,
13071325
*,
13081326
extensions: Iterable[browser_load_extensions_params.Extension],
13091327
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@@ -1328,8 +1346,8 @@ async def load_extensions(
13281346
13291347
timeout: Override the client-level default timeout for this request, in seconds
13301348
"""
1331-
if not id:
1332-
raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
1349+
if not id_or_name:
1350+
raise ValueError(f"Expected a non-empty value for `id_or_name` but received {id_or_name!r}")
13331351
extra_headers = {"Accept": "*/*", **(extra_headers or {})}
13341352
body = deepcopy_with_paths({"extensions": extensions}, [["extensions", "<array>", "zip_file"]])
13351353
files = extract_files(cast(Mapping[str, object], body), paths=[["extensions", "<array>", "zip_file"]])
@@ -1338,7 +1356,7 @@ async def load_extensions(
13381356
# multipart/form-data; boundary=---abc--
13391357
extra_headers["Content-Type"] = "multipart/form-data"
13401358
return await self._post(
1341-
path_template("/browsers/{id}/extensions", id=id),
1359+
path_template("/browsers/{id_or_name}/extensions", id_or_name=id_or_name),
13421360
body=await async_maybe_transform(body, browser_load_extensions_params.BrowserLoadExtensionsParams),
13431361
files=files,
13441362
options=make_request_options(
@@ -1411,6 +1429,11 @@ def playwright(self) -> PlaywrightResourceWithRawResponse:
14111429
"""Execute Playwright code against the browser instance."""
14121430
return PlaywrightResourceWithRawResponse(self._browsers.playwright)
14131431

1432+
@cached_property
1433+
def webmcp(self) -> WebmcpResourceWithRawResponse:
1434+
"""Discover and invoke native page tools across the browser instance."""
1435+
return WebmcpResourceWithRawResponse(self._browsers.webmcp)
1436+
14141437

14151438
class AsyncBrowsersResourceWithRawResponse:
14161439
def __init__(self, browsers: AsyncBrowsersResource) -> None:
@@ -1475,6 +1498,11 @@ def playwright(self) -> AsyncPlaywrightResourceWithRawResponse:
14751498
"""Execute Playwright code against the browser instance."""
14761499
return AsyncPlaywrightResourceWithRawResponse(self._browsers.playwright)
14771500

1501+
@cached_property
1502+
def webmcp(self) -> AsyncWebmcpResourceWithRawResponse:
1503+
"""Discover and invoke native page tools across the browser instance."""
1504+
return AsyncWebmcpResourceWithRawResponse(self._browsers.webmcp)
1505+
14781506

14791507
class BrowsersResourceWithStreamingResponse:
14801508
def __init__(self, browsers: BrowsersResource) -> None:
@@ -1539,6 +1567,11 @@ def playwright(self) -> PlaywrightResourceWithStreamingResponse:
15391567
"""Execute Playwright code against the browser instance."""
15401568
return PlaywrightResourceWithStreamingResponse(self._browsers.playwright)
15411569

1570+
@cached_property
1571+
def webmcp(self) -> WebmcpResourceWithStreamingResponse:
1572+
"""Discover and invoke native page tools across the browser instance."""
1573+
return WebmcpResourceWithStreamingResponse(self._browsers.webmcp)
1574+
15421575

15431576
class AsyncBrowsersResourceWithStreamingResponse:
15441577
def __init__(self, browsers: AsyncBrowsersResource) -> None:
@@ -1602,3 +1635,8 @@ def computer(self) -> AsyncComputerResourceWithStreamingResponse:
16021635
def playwright(self) -> AsyncPlaywrightResourceWithStreamingResponse:
16031636
"""Execute Playwright code against the browser instance."""
16041637
return AsyncPlaywrightResourceWithStreamingResponse(self._browsers.playwright)
1638+
1639+
@cached_property
1640+
def webmcp(self) -> AsyncWebmcpResourceWithStreamingResponse:
1641+
"""Discover and invoke native page tools across the browser instance."""
1642+
return AsyncWebmcpResourceWithStreamingResponse(self._browsers.webmcp)

0 commit comments

Comments
 (0)