Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions agentrun/sandbox/__sandbox_async_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ class Sandbox(BaseModel):
"""配置对象,用于子类的 data_api 初始化 / Config object for data_api initialization"""

@classmethod
def __get_client(cls):
def __get_client(cls, config: Optional[Config] = None):
"""获取 Sandbox 客户端"""
from .client import SandboxClient

return SandboxClient()
return SandboxClient(config=config)

@classmethod
@overload
Expand Down Expand Up @@ -180,7 +180,7 @@ async def create_async(
)

# 创建 Sandbox(返回基类实例)
base_sandbox = await cls.__get_client().create_sandbox_async(
base_sandbox = await cls.__get_client(config=config).create_sandbox_async(
template_name=template_name,
sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds,
sandbox_id=sandbox_id,
Expand Down Expand Up @@ -231,7 +231,7 @@ async def stop_by_id_async(
"""
if sandbox_id is None:
raise ValueError("sandbox_id is required")
return await cls.__get_client().stop_sandbox_async(
return await cls.__get_client(config=config).stop_sandbox_async(
sandbox_id, config=config
)

Expand All @@ -250,7 +250,7 @@ async def delete_by_id_async(
"""
if sandbox_id is None:
raise ValueError("sandbox_id is required")
return await cls.__get_client().delete_sandbox_async(
return await cls.__get_client(config=config).delete_sandbox_async(
sandbox_id, config=config
)

Expand All @@ -269,7 +269,7 @@ async def list_async(
Returns:
ListSandboxesOutput: Sandbox 列表结果
"""
return await cls.__get_client().list_sandboxes_async(input, config)
return await cls.__get_client(config=config).list_sandboxes_async(input, config)

@classmethod
@overload
Expand Down Expand Up @@ -337,7 +337,7 @@ async def connect_async(
raise ValueError("sandbox_id is required")

# 先获取 sandbox 信息
sandbox = await cls.__get_client().get_sandbox_async(
sandbox = await cls.__get_client(config=config).get_sandbox_async(
sandbox_id, config=config
)

Expand Down Expand Up @@ -396,7 +396,7 @@ async def create_template_async(
"""
if input.template_type is None:
raise ValueError("template_type is required")
return await cls.__get_client().create_template_async(
return await cls.__get_client(config=config).create_template_async(
input, config=config
)

Expand All @@ -415,7 +415,7 @@ async def get_template_async(
"""
if template_name is None:
raise ValueError("template_name is required")
return await cls.__get_client().get_template_async(
return await cls.__get_client(config=config).get_template_async(
template_name, config=config
)

Expand All @@ -438,7 +438,7 @@ async def update_template_async(
"""
if template_name is None:
raise ValueError("template_name is required")
return await cls.__get_client().update_template_async(
return await cls.__get_client(config=config).update_template_async(
template_name, input, config=config
)

Expand All @@ -457,7 +457,7 @@ async def delete_template_async(
"""
if template_name is None:
raise ValueError("template_name is required")
return await cls.__get_client().delete_template_async(
return await cls.__get_client(config=config).delete_template_async(
template_name, config=config
)

Expand All @@ -476,7 +476,7 @@ async def list_templates_async(
Returns:
List[Template]: Template 列表
"""
return await cls.__get_client().list_templates_async(
return await cls.__get_client(config=config).list_templates_async(
input, config=config
)

Expand Down
44 changes: 22 additions & 22 deletions agentrun/sandbox/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ class Sandbox(BaseModel):
"""配置对象,用于子类的 data_api 初始化 / Config object for data_api initialization"""

@classmethod
def __get_client(cls):
def __get_client(cls, config: Optional[Config] = None):
"""获取 Sandbox 客户端"""
from .client import SandboxClient

return SandboxClient()
return SandboxClient(config=config)

@classmethod
@overload
Expand Down Expand Up @@ -250,7 +250,7 @@ async def create_async(
)

# 创建 Sandbox(返回基类实例)
base_sandbox = await cls.__get_client().create_sandbox_async(
base_sandbox = await cls.__get_client(config=config).create_sandbox_async(
template_name=template_name,
sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds,
sandbox_id=sandbox_id,
Expand Down Expand Up @@ -326,7 +326,7 @@ def create(
)

# 创建 Sandbox(返回基类实例)
base_sandbox = cls.__get_client().create_sandbox(
base_sandbox = cls.__get_client(config=config).create_sandbox(
template_name=template_name,
sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds,
sandbox_id=sandbox_id,
Expand Down Expand Up @@ -377,7 +377,7 @@ async def stop_by_id_async(
"""
if sandbox_id is None:
raise ValueError("sandbox_id is required")
return await cls.__get_client().stop_sandbox_async(
return await cls.__get_client(config=config).stop_sandbox_async(
sandbox_id, config=config
)

Expand All @@ -394,7 +394,7 @@ def stop_by_id(cls, sandbox_id: str, config: Optional[Config] = None):
"""
if sandbox_id is None:
raise ValueError("sandbox_id is required")
return cls.__get_client().stop_sandbox(sandbox_id, config=config)
return cls.__get_client(config=config).stop_sandbox(sandbox_id, config=config)

@classmethod
async def delete_by_id_async(
Expand All @@ -411,7 +411,7 @@ async def delete_by_id_async(
"""
if sandbox_id is None:
raise ValueError("sandbox_id is required")
return await cls.__get_client().delete_sandbox_async(
return await cls.__get_client(config=config).delete_sandbox_async(
sandbox_id, config=config
)

Expand All @@ -428,7 +428,7 @@ def delete_by_id(cls, sandbox_id: str, config: Optional[Config] = None):
"""
if sandbox_id is None:
raise ValueError("sandbox_id is required")
return cls.__get_client().delete_sandbox(sandbox_id, config=config)
return cls.__get_client(config=config).delete_sandbox(sandbox_id, config=config)

@classmethod
async def list_async(
Expand All @@ -445,7 +445,7 @@ async def list_async(
Returns:
ListSandboxesOutput: Sandbox 列表结果
"""
return await cls.__get_client().list_sandboxes_async(input, config)
return await cls.__get_client(config=config).list_sandboxes_async(input, config)

@classmethod
def list(
Expand All @@ -462,7 +462,7 @@ def list(
Returns:
ListSandboxesOutput: Sandbox 列表结果
"""
return cls.__get_client().list_sandboxes(input, config)
return cls.__get_client(config=config).list_sandboxes(input, config)

@classmethod
@overload
Expand Down Expand Up @@ -570,7 +570,7 @@ async def connect_async(
raise ValueError("sandbox_id is required")

# 先获取 sandbox 信息
sandbox = await cls.__get_client().get_sandbox_async(
sandbox = await cls.__get_client(config=config).get_sandbox_async(
sandbox_id, config=config
)

Expand Down Expand Up @@ -640,7 +640,7 @@ def connect(
raise ValueError("sandbox_id is required")

# 先获取 sandbox 信息
sandbox = cls.__get_client().get_sandbox(sandbox_id, config=config)
sandbox = cls.__get_client(config=config).get_sandbox(sandbox_id, config=config)

resolved_type = template_type
if resolved_type is None:
Expand Down Expand Up @@ -695,7 +695,7 @@ async def create_template_async(
"""
if input.template_type is None:
raise ValueError("template_type is required")
return await cls.__get_client().create_template_async(
return await cls.__get_client(config=config).create_template_async(
input, config=config
)

Expand All @@ -714,7 +714,7 @@ def create_template(
"""
if input.template_type is None:
raise ValueError("template_type is required")
return cls.__get_client().create_template(input, config=config)
return cls.__get_client(config=config).create_template(input, config=config)

@classmethod
async def get_template_async(
Expand All @@ -731,7 +731,7 @@ async def get_template_async(
"""
if template_name is None:
raise ValueError("template_name is required")
return await cls.__get_client().get_template_async(
return await cls.__get_client(config=config).get_template_async(
template_name, config=config
)

Expand All @@ -750,7 +750,7 @@ def get_template(
"""
if template_name is None:
raise ValueError("template_name is required")
return cls.__get_client().get_template(template_name, config=config)
return cls.__get_client(config=config).get_template(template_name, config=config)

@classmethod
async def update_template_async(
Expand All @@ -771,7 +771,7 @@ async def update_template_async(
"""
if template_name is None:
raise ValueError("template_name is required")
return await cls.__get_client().update_template_async(
return await cls.__get_client(config=config).update_template_async(
template_name, input, config=config
)

Expand All @@ -794,7 +794,7 @@ def update_template(
"""
if template_name is None:
raise ValueError("template_name is required")
return cls.__get_client().update_template(
return cls.__get_client(config=config).update_template(
template_name, input, config=config
)

Expand All @@ -813,7 +813,7 @@ async def delete_template_async(
"""
if template_name is None:
raise ValueError("template_name is required")
return await cls.__get_client().delete_template_async(
return await cls.__get_client(config=config).delete_template_async(
template_name, config=config
)

Expand All @@ -832,7 +832,7 @@ def delete_template(
"""
if template_name is None:
raise ValueError("template_name is required")
return cls.__get_client().delete_template(template_name, config=config)
return cls.__get_client(config=config).delete_template(template_name, config=config)

@classmethod
async def list_templates_async(
Expand All @@ -849,7 +849,7 @@ async def list_templates_async(
Returns:
List[Template]: Template 列表
"""
return await cls.__get_client().list_templates_async(
return await cls.__get_client(config=config).list_templates_async(
input, config=config
)

Expand All @@ -868,7 +868,7 @@ def list_templates(
Returns:
List[Template]: Template 列表
"""
return cls.__get_client().list_templates(input, config=config)
return cls.__get_client(config=config).list_templates(input, config=config)

async def get_async(self):
if self.sandbox_id is None:
Expand Down
16 changes: 8 additions & 8 deletions agentrun/utils/__data_api_async_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ async def get_async(
"""
return await self._make_request_async(
"GET",
self.with_path(path, query=query),
self.with_path(path, query=query, config=config),
headers=headers,
config=config,
)
Expand Down Expand Up @@ -470,7 +470,7 @@ async def post_async(

return await self._make_request_async(
"POST",
self.with_path(path, query=query),
self.with_path(path, query=query, config=config),
data=data,
headers=headers,
config=config,
Expand Down Expand Up @@ -501,7 +501,7 @@ async def put_async(
"""
return await self._make_request_async(
"PUT",
self.with_path(path, query=query),
self.with_path(path, query=query, config=config),
data=data,
headers=headers,
config=config,
Expand Down Expand Up @@ -532,7 +532,7 @@ async def patch_async(
"""
return await self._make_request_async(
"PATCH",
self.with_path(path, query=query),
self.with_path(path, query=query, config=config),
data=data,
headers=headers,
config=config,
Expand Down Expand Up @@ -561,7 +561,7 @@ async def delete_async(
"""
return await self._make_request_async(
"DELETE",
self.with_path(path, query=query),
self.with_path(path, query=query, config=config),
headers=headers,
config=config,
)
Expand Down Expand Up @@ -601,7 +601,7 @@ async def post_file_async(

filename = os.path.basename(local_file_path)

url = self.with_path(path, query=query)
url = self.with_path(path, query=query, config=config)
req_headers = self.config.get_headers()
req_headers.update(headers or {})
# Apply authentication (may modify URL, headers, and query)
Expand Down Expand Up @@ -656,7 +656,7 @@ async def get_file_async(
Examples:
>>> await client.get_file_async("/files", save_path="/local/data.csv", query={"path": "/remote/file.csv"})
"""
url = self.with_path(path, query=query)
url = self.with_path(path, query=query, config=config)
req_headers = self.config.get_headers()
req_headers.update(headers or {})
# Apply authentication (may modify URL, headers, and query)
Expand Down Expand Up @@ -707,7 +707,7 @@ async def get_video_async(
Examples:
>>> await client.get_video_async("/videos", save_path="/local/video.mkv", query={"path": "/remote/video.mp4"})
"""
url = self.with_path(path, query=query)
url = self.with_path(path, query=query, config=config)
req_headers = self.config.get_headers()
req_headers.update(headers or {})
# Apply authentication (may modify URL, headers, and query)
Expand Down
Loading