44
55import os
66from typing import TYPE_CHECKING , Any , Mapping
7+
8+ ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
9+ # Keep the generated client thin: all runtime patch logic lives in `_custom`.
710from typing_extensions import Self , Literal , override
811
912import httpx
3033 SyncAPIClient ,
3134 AsyncAPIClient ,
3235)
33-
34- ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
35- # Keep the generated client thin: all runtime patch logic lives in `_custom`.
3636from ._custom .session import install_stainless_session_patches
3737from ._custom .sea_server import (
3838 copy_local_mode_kwargs ,
7272
7373
7474class Stagehand (SyncAPIClient ):
75+ ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
7576 # client options
7677 browserbase_api_key : str | None
7778 browserbase_project_id : str | None
7879 model_api_key : str | None
79- ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
8080 # These are assigned indirectly by `configure_client_base_url(...)` so the
8181 # generated class still exposes typed local-mode state for `copy()` and tests.
8282 _server_mode : Literal ["remote" , "local" ]
@@ -90,6 +90,7 @@ class Stagehand(SyncAPIClient):
9090 _sea_server : SeaServerManager | None
9191 ### </END CUSTOM CODE>
9292
93+ ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
9394 def __init__ (
9495 self ,
9596 * ,
@@ -143,7 +144,6 @@ def __init__(
143144
144145 self .model_api_key = model_api_key
145146
146- ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
147147 # Centralize local-mode state hydration and base-url selection in `_custom`
148148 # so no constructor branching lives in the generated client.
149149 base_url = configure_client_base_url (
@@ -159,7 +159,7 @@ def __init__(
159159 base_url = base_url ,
160160 model_api_key = model_api_key ,
161161 )
162- ### </END CUSTOM CODE>
162+ ### </END CUSTOM CODE>
163163
164164 super ().__init__ (
165165 version = __version__ ,
@@ -174,26 +174,24 @@ def __init__(
174174
175175 self ._default_stream_cls = Stream
176176
177+ ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
177178 @override
178179 def _prepare_options (self , options : FinalRequestOptions ) -> FinalRequestOptions :
179- ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
180180 # Start the local SEA server lazily on first request instead of at client
181181 # construction time, then swap the base URL to the started process.
182182 local_base_url = prepare_sync_client_base_url (self )
183183 if local_base_url is not None :
184184 self .base_url = local_base_url
185- ### </END CUSTOM CODE>
186185 return super ()._prepare_options (options )
187186
188187 @override
189188 def close (self ) -> None :
190189 try :
191190 super ().close ()
192191 finally :
193- ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
194192 # Tear down the managed SEA process after HTTP resources close.
195193 close_sync_client_sea_server (self )
196- ### </END CUSTOM CODE>
194+ ### </END CUSTOM CODE>
197195
198196 @cached_property
199197 def sessions (self ) -> SessionsResource :
@@ -219,6 +217,7 @@ def qs(self) -> Querystring:
219217 def auth_headers (self ) -> dict [str , str ]:
220218 return {** self ._bb_api_key_auth , ** self ._bb_project_id_auth , ** self ._llm_model_api_key_auth }
221219
220+ ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
222221 @property
223222 def _bb_api_key_auth (self ) -> dict [str , str ]:
224223 browserbase_api_key = self .browserbase_api_key
@@ -244,7 +243,9 @@ def default_headers(self) -> dict[str, str | Omit]:
244243 "X-Stainless-Async" : "false" ,
245244 ** self ._custom_headers ,
246245 }
246+ ### </END CUSTOM CODE>
247247
248+ ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
248249 def copy (
249250 self ,
250251 * ,
@@ -301,7 +302,6 @@ def copy(
301302 max_retries = max_retries if is_given (max_retries ) else self .max_retries ,
302303 default_headers = headers ,
303304 default_query = params ,
304- ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
305305 # Preserve local-mode configuration when cloning the client without
306306 # duplicating that branching logic in generated code.
307307 ** copy_local_mode_kwargs (
@@ -315,12 +315,12 @@ def copy(
315315 local_ready_timeout_s = local_ready_timeout_s ,
316316 local_shutdown_on_close = local_shutdown_on_close ,
317317 ),
318- ### </END CUSTOM CODE>
319318 ** _extra_kwargs ,
320319 )
320+ ### </END CUSTOM CODE>
321321
322322 # Alias for `copy` for nicer inline usage, e.g.
323- # client.with_options(timeout=10).foo.start (...)
323+ # client.with_options(timeout=10).foo.create (...)
324324 with_options = copy
325325
326326 @override
@@ -358,11 +358,11 @@ def _make_status_error(
358358
359359
360360class AsyncStagehand (AsyncAPIClient ):
361+ ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
361362 # client options
362363 browserbase_api_key : str | None
363364 browserbase_project_id : str | None
364365 model_api_key : str | None
365- ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
366366 # These are assigned indirectly by `configure_client_base_url(...)` so the
367367 # generated class still exposes typed local-mode state for `copy()` and tests.
368368 _server_mode : Literal ["remote" , "local" ]
@@ -376,6 +376,7 @@ class AsyncStagehand(AsyncAPIClient):
376376 _sea_server : SeaServerManager | None
377377 ### </END CUSTOM CODE>
378378
379+ ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
379380 def __init__ (
380381 self ,
381382 * ,
@@ -429,7 +430,6 @@ def __init__(
429430
430431 self .model_api_key = model_api_key
431432
432- ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
433433 # Centralize local-mode state hydration and base-url selection in `_custom`
434434 # so no constructor branching lives in the generated client.
435435 base_url = configure_client_base_url (
@@ -445,7 +445,7 @@ def __init__(
445445 base_url = base_url ,
446446 model_api_key = model_api_key ,
447447 )
448- ### </END CUSTOM CODE>
448+ ### </END CUSTOM CODE>
449449
450450 super ().__init__ (
451451 version = __version__ ,
@@ -460,26 +460,24 @@ def __init__(
460460
461461 self ._default_stream_cls = AsyncStream
462462
463+ ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
463464 @override
464465 async def _prepare_options (self , options : FinalRequestOptions ) -> FinalRequestOptions :
465- ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
466466 # Start the local SEA server lazily on first request instead of at client
467467 # construction time, then swap the base URL to the started process.
468468 local_base_url = await prepare_async_client_base_url (self )
469469 if local_base_url is not None :
470470 self .base_url = local_base_url
471- ### </END CUSTOM CODE>
472471 return await super ()._prepare_options (options )
473472
474473 @override
475474 async def close (self ) -> None :
476475 try :
477476 await super ().close ()
478477 finally :
479- ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
480478 # Tear down the managed SEA process after HTTP resources close.
481479 await close_async_client_sea_server (self )
482- ### </END CUSTOM CODE>
480+ ### </END CUSTOM CODE>
483481
484482 @cached_property
485483 def sessions (self ) -> AsyncSessionsResource :
@@ -505,6 +503,7 @@ def qs(self) -> Querystring:
505503 def auth_headers (self ) -> dict [str , str ]:
506504 return {** self ._bb_api_key_auth , ** self ._bb_project_id_auth , ** self ._llm_model_api_key_auth }
507505
506+ ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
508507 @property
509508 def _bb_api_key_auth (self ) -> dict [str , str ]:
510509 browserbase_api_key = self .browserbase_api_key
@@ -530,7 +529,9 @@ def default_headers(self) -> dict[str, str | Omit]:
530529 "X-Stainless-Async" : f"async:{ get_async_library ()} " ,
531530 ** self ._custom_headers ,
532531 }
532+ ### </END CUSTOM CODE>
533533
534+ ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
534535 def copy (
535536 self ,
536537 * ,
@@ -587,7 +588,6 @@ def copy(
587588 max_retries = max_retries if is_given (max_retries ) else self .max_retries ,
588589 default_headers = headers ,
589590 default_query = params ,
590- ### <CUSTOM CODE HANDWRITTEN BY STAGEHAND TEAM (not codegen)>
591591 # Preserve local-mode configuration when cloning the client without
592592 # duplicating that branching logic in generated code.
593593 ** copy_local_mode_kwargs (
@@ -601,12 +601,12 @@ def copy(
601601 local_ready_timeout_s = local_ready_timeout_s ,
602602 local_shutdown_on_close = local_shutdown_on_close ,
603603 ),
604- ### </END CUSTOM CODE>
605604 ** _extra_kwargs ,
606605 )
606+ ### </END CUSTOM CODE>
607607
608608 # Alias for `copy` for nicer inline usage, e.g.
609- # client.with_options(timeout=10).foo.start (...)
609+ # client.with_options(timeout=10).foo.create (...)
610610 with_options = copy
611611
612612 @override
0 commit comments