Skip to content

Commit 0c17ce2

Browse files
feat(api): allow setting a name and tags on a pool-acquired browser session
1 parent 6812116 commit 0c17ce2

4 files changed

Lines changed: 62 additions & 4 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: 117
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-9d489e3e43edfa64a754d4281241718e01c85d9a82ef3687df12bbd3c4ff5b42.yml
3-
openapi_spec_hash: a953cafb7f40ec8495dbd7df8bab8bad
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-662a9d6352d842f37e06e0197a61fe10850483302650713345d45780b3128343.yml
3+
openapi_spec_hash: e65977d16d95d48c75d02a1133131149
44
config_hash: bb7acce8576a50dd449b0c8f58ef0f1d

src/kernel/resources/browser_pools.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
)
2727
from ..pagination import SyncOffsetPagination, AsyncOffsetPagination
2828
from .._base_client import AsyncPaginator, make_request_options
29+
from ..types.tags_param import TagsParam
2930
from ..types.browser_pool import BrowserPool
3031
from ..types.browser_pool_acquire_response import BrowserPoolAcquireResponse
3132
from ..types.shared_params.browser_profile import BrowserProfile
@@ -417,6 +418,8 @@ def acquire(
417418
id_or_name: str,
418419
*,
419420
acquire_timeout_seconds: int | Omit = omit,
421+
name: str | Omit = omit,
422+
tags: TagsParam | Omit = omit,
420423
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
421424
# The extra values given here take precedence over values defined on the client or passed to this method.
422425
extra_headers: Headers | None = None,
@@ -436,6 +439,15 @@ def acquire(
436439
calculated time it would take to fill the pool at the currently configured fill
437440
rate.
438441
442+
name: Optional human-readable name for the acquired browser session, used to find it
443+
later in the dashboard. Must be unique among active sessions within the pool's
444+
project. Applies to this lease only and is cleared when the browser is released
445+
back to the pool.
446+
447+
tags: Optional user-defined key-value tags for the acquired browser session, used to
448+
find and group sessions later. Applies to this lease only and are cleared when
449+
the browser is released back to the pool. Up to 50 pairs.
450+
439451
extra_headers: Send extra headers
440452
441453
extra_query: Add additional query parameters to the request
@@ -449,7 +461,11 @@ def acquire(
449461
return self._post(
450462
path_template("/browser_pools/{id_or_name}/acquire", id_or_name=id_or_name),
451463
body=maybe_transform(
452-
{"acquire_timeout_seconds": acquire_timeout_seconds},
464+
{
465+
"acquire_timeout_seconds": acquire_timeout_seconds,
466+
"name": name,
467+
"tags": tags,
468+
},
453469
browser_pool_acquire_params.BrowserPoolAcquireParams,
454470
),
455471
options=make_request_options(
@@ -923,6 +939,8 @@ async def acquire(
923939
id_or_name: str,
924940
*,
925941
acquire_timeout_seconds: int | Omit = omit,
942+
name: str | Omit = omit,
943+
tags: TagsParam | Omit = omit,
926944
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
927945
# The extra values given here take precedence over values defined on the client or passed to this method.
928946
extra_headers: Headers | None = None,
@@ -942,6 +960,15 @@ async def acquire(
942960
calculated time it would take to fill the pool at the currently configured fill
943961
rate.
944962
963+
name: Optional human-readable name for the acquired browser session, used to find it
964+
later in the dashboard. Must be unique among active sessions within the pool's
965+
project. Applies to this lease only and is cleared when the browser is released
966+
back to the pool.
967+
968+
tags: Optional user-defined key-value tags for the acquired browser session, used to
969+
find and group sessions later. Applies to this lease only and are cleared when
970+
the browser is released back to the pool. Up to 50 pairs.
971+
945972
extra_headers: Send extra headers
946973
947974
extra_query: Add additional query parameters to the request
@@ -955,7 +982,11 @@ async def acquire(
955982
return await self._post(
956983
path_template("/browser_pools/{id_or_name}/acquire", id_or_name=id_or_name),
957984
body=await async_maybe_transform(
958-
{"acquire_timeout_seconds": acquire_timeout_seconds},
985+
{
986+
"acquire_timeout_seconds": acquire_timeout_seconds,
987+
"name": name,
988+
"tags": tags,
989+
},
959990
browser_pool_acquire_params.BrowserPoolAcquireParams,
960991
),
961992
options=make_request_options(

src/kernel/types/browser_pool_acquire_params.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from typing_extensions import TypedDict
66

7+
from .tags_param import TagsParam
8+
79
__all__ = ["BrowserPoolAcquireParams"]
810

911

@@ -14,3 +16,18 @@ class BrowserPoolAcquireParams(TypedDict, total=False):
1416
Defaults to the calculated time it would take to fill the pool at the currently
1517
configured fill rate.
1618
"""
19+
20+
name: str
21+
"""
22+
Optional human-readable name for the acquired browser session, used to find it
23+
later in the dashboard. Must be unique among active sessions within the pool's
24+
project. Applies to this lease only and is cleared when the browser is released
25+
back to the pool.
26+
"""
27+
28+
tags: TagsParam
29+
"""
30+
Optional user-defined key-value tags for the acquired browser session, used to
31+
find and group sessions later. Applies to this lease only and are cleared when
32+
the browser is released back to the pool. Up to 50 pairs.
33+
"""

tests/api_resources/test_browser_pools.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ def test_method_acquire_with_all_params(self, client: Kernel) -> None:
309309
browser_pool = client.browser_pools.acquire(
310310
id_or_name="id_or_name",
311311
acquire_timeout_seconds=0,
312+
name="checkout-flow-1",
313+
tags={
314+
"team": "backend",
315+
"env": "staging",
316+
},
312317
)
313318
assert_matches_type(BrowserPoolAcquireResponse, browser_pool, path=["response"])
314319

@@ -738,6 +743,11 @@ async def test_method_acquire_with_all_params(self, async_client: AsyncKernel) -
738743
browser_pool = await async_client.browser_pools.acquire(
739744
id_or_name="id_or_name",
740745
acquire_timeout_seconds=0,
746+
name="checkout-flow-1",
747+
tags={
748+
"team": "backend",
749+
"env": "staging",
750+
},
741751
)
742752
assert_matches_type(BrowserPoolAcquireResponse, browser_pool, path=["response"])
743753

0 commit comments

Comments
 (0)