22
33from __future__ import annotations
44
5- from typing import Dict , List , Iterable , Optional
5+ from typing import Dict , List , Iterable , Optional , TypedDict
66
77import httpx
88
2828from ..types .shared_params .launch_parameters import LaunchParameters
2929from ..types .shared_params .code_mount_parameters import CodeMountParameters
3030
31- __all__ = ["BlueprintsResource" , "AsyncBlueprintsResource" ]
31+
32+ # Type for request arguments that combine polling config with additional request options
33+ class BlueprintRequestArgs (TypedDict , total = False ):
34+ polling_config : PollingConfig | None
35+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
36+ # The extra values given here take precedence over values defined on the client or passed to this method.
37+ extra_headers : Headers | None
38+ extra_query : Query | None
39+ extra_body : Body | None
40+ timeout : float | httpx .Timeout | None | NotGiven
41+
42+
43+ __all__ = ["BlueprintsResource" , "AsyncBlueprintsResource" , "BlueprintRequestArgs" ]
3244
3345
3446class BlueprintsResource (SyncAPIResource ):
@@ -188,13 +200,10 @@ def await_build_complete(
188200 PollingTimeout: If polling times out before blueprint is built
189201 RunloopError: If blueprint enters a non-built terminal state
190202 """
203+
191204 def retrieve_blueprint () -> BlueprintView :
192205 return self .retrieve (
193- id ,
194- extra_headers = extra_headers ,
195- extra_query = extra_query ,
196- extra_body = extra_body ,
197- timeout = timeout
206+ id , extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
198207 )
199208
200209 def is_done_building (blueprint : BlueprintView ) -> bool :
@@ -203,25 +212,23 @@ def is_done_building(blueprint: BlueprintView) -> bool:
203212 blueprint = poll_until (retrieve_blueprint , is_done_building , polling_config )
204213
205214 if blueprint .status != "build_complete" :
206- raise RunloopError (
207- f"Blueprint entered non-built terminal state: { blueprint .status } "
208- )
215+ raise RunloopError (f"Blueprint entered non-built terminal state: { blueprint .status } " )
209216
210217 return blueprint
211218
212219 def create_and_await_build_complete (
213220 self ,
214221 * ,
215222 create_args : blueprint_create_params .BlueprintCreateParams ,
216- polling_config : PollingConfig | None = None ,
223+ request_args : BlueprintRequestArgs | None = None ,
217224 ) -> BlueprintView :
218225 """Create a new Blueprint and wait for it to finish building.
219226
220227 This is a wrapper around the `create` method that waits for the blueprint to finish building.
221228
222229 Args:
223230 create_args: Arguments to pass to the `create` method. See the `create` method for detailed documentation.
224- polling_config : Optional polling configuration
231+ request_args : Optional request arguments including polling configuration and additional request options
225232
226233 Returns:
227234 The built blueprint
@@ -233,9 +240,16 @@ def create_and_await_build_complete(
233240 # Pass all create_args to the underlying create method
234241 blueprint = self .create (** create_args )
235242
243+ if request_args is None :
244+ request_args = {}
245+
236246 return self .await_build_complete (
237247 blueprint .id ,
238- polling_config = polling_config ,
248+ polling_config = request_args .get ("polling_config" , None ),
249+ extra_headers = request_args .get ("extra_headers" , None ),
250+ extra_query = request_args .get ("extra_query" , None ),
251+ extra_body = request_args .get ("extra_body" , None ),
252+ timeout = request_args .get ("timeout" , None ),
239253 )
240254
241255 def list (
@@ -563,7 +577,7 @@ async def retrieve(
563577 ),
564578 cast_to = BlueprintView ,
565579 )
566-
580+
567581 async def await_build_complete (
568582 self ,
569583 id : str ,
@@ -593,13 +607,10 @@ async def await_build_complete(
593607 PollingTimeout: If polling times out before blueprint is built
594608 RunloopError: If blueprint enters a non-built terminal state
595609 """
610+
596611 async def retrieve_blueprint () -> BlueprintView :
597612 return await self .retrieve (
598- id ,
599- extra_headers = extra_headers ,
600- extra_query = extra_query ,
601- extra_body = extra_body ,
602- timeout = timeout
613+ id , extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
603614 )
604615
605616 def is_done_building (blueprint : BlueprintView ) -> bool :
@@ -608,25 +619,23 @@ def is_done_building(blueprint: BlueprintView) -> bool:
608619 blueprint = await async_poll_until (retrieve_blueprint , is_done_building , polling_config )
609620
610621 if blueprint .status != "build_complete" :
611- raise RunloopError (
612- f"Blueprint entered non-built terminal state: { blueprint .status } "
613- )
622+ raise RunloopError (f"Blueprint entered non-built terminal state: { blueprint .status } " )
614623
615624 return blueprint
616625
617626 async def create_and_await_build_complete (
618627 self ,
619628 * ,
620629 create_args : blueprint_create_params .BlueprintCreateParams ,
621- polling_config : PollingConfig | None = None ,
630+ request_args : BlueprintRequestArgs | None = None ,
622631 ) -> BlueprintView :
623632 """Create a new Blueprint and wait for it to finish building.
624633
625634 This is a wrapper around the `create` method that waits for the blueprint to finish building.
626635
627636 Args:
628637 create_args: Arguments to pass to the `create` method. See the `create` method for detailed documentation.
629- polling_config : Optional polling configuration
638+ request_args : Optional request arguments including polling configuration and additional request options
630639
631640 Returns:
632641 The built blueprint
@@ -638,9 +647,17 @@ async def create_and_await_build_complete(
638647 # Pass all create_args to the underlying create method
639648 blueprint = await self .create (** create_args )
640649
650+ # Extract polling config and other request args
651+ if request_args is None :
652+ request_args = {}
653+
641654 return await self .await_build_complete (
642655 blueprint .id ,
643- polling_config = polling_config ,
656+ polling_config = request_args .get ("polling_config" , None ),
657+ extra_headers = request_args .get ("extra_headers" , None ),
658+ extra_query = request_args .get ("extra_query" , None ),
659+ extra_body = request_args .get ("extra_body" , None ),
660+ timeout = request_args .get ("timeout" , None ),
644661 )
645662
646663 def list (
0 commit comments