11import os
22from contextlib import AbstractAsyncContextManager , asynccontextmanager
3- from typing import AsyncGenerator , AsyncIterator , Callable , Optional
3+ from typing import AsyncIterator , Callable , Optional
44
55from httpx import ASGITransport , AsyncClient , Timeout
66from loguru import logger
@@ -60,11 +60,12 @@ async def _resolve_cloud_token(config) -> str:
6060 )
6161
6262
63+ @asynccontextmanager
6364async def _cloud_client (
6465 config ,
6566 timeout : Timeout ,
6667 workspace : Optional [str ] = None ,
67- ) -> AsyncGenerator [AsyncClient , None ]:
68+ ) -> AsyncIterator [AsyncClient ]:
6869 """Create a cloud proxy client with resolved credentials."""
6970 token = await _resolve_cloud_token (config )
7071 proxy_base_url = f"{ config .cloud_host } /proxy"
@@ -139,7 +140,7 @@ async def get_client(
139140
140141 if _force_cloud_mode ():
141142 logger .info ("Explicit cloud routing enabled - using cloud proxy client" )
142- async for client in _cloud_client (config , timeout , workspace = workspace ):
143+ async with _cloud_client (config , timeout , workspace = workspace ) as client :
143144 yield client
144145 return
145146
@@ -152,7 +153,7 @@ async def get_client(
152153 if project_mode == ProjectMode .CLOUD :
153154 logger .info (f"Project '{ project_name } ' is cloud mode - using cloud proxy client" )
154155 try :
155- async for client in _cloud_client (config , timeout , workspace = workspace ):
156+ async with _cloud_client (config , timeout , workspace = workspace ) as client :
156157 yield client
157158 except RuntimeError as exc :
158159 raise RuntimeError (
0 commit comments