Skip to content

Commit 8582d6d

Browse files
CopilotOhYee
andcommitted
Fix DataAPI config propagation to with_path and Sandbox.__get_client() config forwarding
Agent-Logs-Url: https://github.com/Serverless-Devs/agentrun-sdk-python/sessions/0e50b98f-f5e7-4961-a4fc-b9669d0ee8af Co-authored-by: OhYee <13498329+OhYee@users.noreply.github.com> Signed-off-by: OhYee <oyohyee@oyohyee.com>
1 parent 1c4a05a commit 8582d6d

4 files changed

Lines changed: 58 additions & 58 deletions

File tree

agentrun/sandbox/__sandbox_async_template.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ class Sandbox(BaseModel):
7474
"""配置对象,用于子类的 data_api 初始化 / Config object for data_api initialization"""
7575

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

81-
return SandboxClient()
81+
return SandboxClient(config=config)
8282

8383
@classmethod
8484
@overload
@@ -180,7 +180,7 @@ async def create_async(
180180
)
181181

182182
# 创建 Sandbox(返回基类实例)
183-
base_sandbox = await cls.__get_client().create_sandbox_async(
183+
base_sandbox = await cls.__get_client(config=config).create_sandbox_async(
184184
template_name=template_name,
185185
sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds,
186186
sandbox_id=sandbox_id,
@@ -231,7 +231,7 @@ async def stop_by_id_async(
231231
"""
232232
if sandbox_id is None:
233233
raise ValueError("sandbox_id is required")
234-
return await cls.__get_client().stop_sandbox_async(
234+
return await cls.__get_client(config=config).stop_sandbox_async(
235235
sandbox_id, config=config
236236
)
237237

@@ -250,7 +250,7 @@ async def delete_by_id_async(
250250
"""
251251
if sandbox_id is None:
252252
raise ValueError("sandbox_id is required")
253-
return await cls.__get_client().delete_sandbox_async(
253+
return await cls.__get_client(config=config).delete_sandbox_async(
254254
sandbox_id, config=config
255255
)
256256

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

274274
@classmethod
275275
@overload
@@ -337,7 +337,7 @@ async def connect_async(
337337
raise ValueError("sandbox_id is required")
338338

339339
# 先获取 sandbox 信息
340-
sandbox = await cls.__get_client().get_sandbox_async(
340+
sandbox = await cls.__get_client(config=config).get_sandbox_async(
341341
sandbox_id, config=config
342342
)
343343

@@ -396,7 +396,7 @@ async def create_template_async(
396396
"""
397397
if input.template_type is None:
398398
raise ValueError("template_type is required")
399-
return await cls.__get_client().create_template_async(
399+
return await cls.__get_client(config=config).create_template_async(
400400
input, config=config
401401
)
402402

@@ -415,7 +415,7 @@ async def get_template_async(
415415
"""
416416
if template_name is None:
417417
raise ValueError("template_name is required")
418-
return await cls.__get_client().get_template_async(
418+
return await cls.__get_client(config=config).get_template_async(
419419
template_name, config=config
420420
)
421421

@@ -438,7 +438,7 @@ async def update_template_async(
438438
"""
439439
if template_name is None:
440440
raise ValueError("template_name is required")
441-
return await cls.__get_client().update_template_async(
441+
return await cls.__get_client(config=config).update_template_async(
442442
template_name, input, config=config
443443
)
444444

@@ -457,7 +457,7 @@ async def delete_template_async(
457457
"""
458458
if template_name is None:
459459
raise ValueError("template_name is required")
460-
return await cls.__get_client().delete_template_async(
460+
return await cls.__get_client(config=config).delete_template_async(
461461
template_name, config=config
462462
)
463463

@@ -476,7 +476,7 @@ async def list_templates_async(
476476
Returns:
477477
List[Template]: Template 列表
478478
"""
479-
return await cls.__get_client().list_templates_async(
479+
return await cls.__get_client(config=config).list_templates_async(
480480
input, config=config
481481
)
482482

agentrun/sandbox/sandbox.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ class Sandbox(BaseModel):
8484
"""配置对象,用于子类的 data_api 初始化 / Config object for data_api initialization"""
8585

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

91-
return SandboxClient()
91+
return SandboxClient(config=config)
9292

9393
@classmethod
9494
@overload
@@ -250,7 +250,7 @@ async def create_async(
250250
)
251251

252252
# 创建 Sandbox(返回基类实例)
253-
base_sandbox = await cls.__get_client().create_sandbox_async(
253+
base_sandbox = await cls.__get_client(config=config).create_sandbox_async(
254254
template_name=template_name,
255255
sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds,
256256
sandbox_id=sandbox_id,
@@ -326,7 +326,7 @@ def create(
326326
)
327327

328328
# 创建 Sandbox(返回基类实例)
329-
base_sandbox = cls.__get_client().create_sandbox(
329+
base_sandbox = cls.__get_client(config=config).create_sandbox(
330330
template_name=template_name,
331331
sandbox_idle_timeout_seconds=sandbox_idle_timeout_seconds,
332332
sandbox_id=sandbox_id,
@@ -377,7 +377,7 @@ async def stop_by_id_async(
377377
"""
378378
if sandbox_id is None:
379379
raise ValueError("sandbox_id is required")
380-
return await cls.__get_client().stop_sandbox_async(
380+
return await cls.__get_client(config=config).stop_sandbox_async(
381381
sandbox_id, config=config
382382
)
383383

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

399399
@classmethod
400400
async def delete_by_id_async(
@@ -411,7 +411,7 @@ async def delete_by_id_async(
411411
"""
412412
if sandbox_id is None:
413413
raise ValueError("sandbox_id is required")
414-
return await cls.__get_client().delete_sandbox_async(
414+
return await cls.__get_client(config=config).delete_sandbox_async(
415415
sandbox_id, config=config
416416
)
417417

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

433433
@classmethod
434434
async def list_async(
@@ -445,7 +445,7 @@ async def list_async(
445445
Returns:
446446
ListSandboxesOutput: Sandbox 列表结果
447447
"""
448-
return await cls.__get_client().list_sandboxes_async(input, config)
448+
return await cls.__get_client(config=config).list_sandboxes_async(input, config)
449449

450450
@classmethod
451451
def list(
@@ -462,7 +462,7 @@ def list(
462462
Returns:
463463
ListSandboxesOutput: Sandbox 列表结果
464464
"""
465-
return cls.__get_client().list_sandboxes(input, config)
465+
return cls.__get_client(config=config).list_sandboxes(input, config)
466466

467467
@classmethod
468468
@overload
@@ -570,7 +570,7 @@ async def connect_async(
570570
raise ValueError("sandbox_id is required")
571571

572572
# 先获取 sandbox 信息
573-
sandbox = await cls.__get_client().get_sandbox_async(
573+
sandbox = await cls.__get_client(config=config).get_sandbox_async(
574574
sandbox_id, config=config
575575
)
576576

@@ -640,7 +640,7 @@ def connect(
640640
raise ValueError("sandbox_id is required")
641641

642642
# 先获取 sandbox 信息
643-
sandbox = cls.__get_client().get_sandbox(sandbox_id, config=config)
643+
sandbox = cls.__get_client(config=config).get_sandbox(sandbox_id, config=config)
644644

645645
resolved_type = template_type
646646
if resolved_type is None:
@@ -695,7 +695,7 @@ async def create_template_async(
695695
"""
696696
if input.template_type is None:
697697
raise ValueError("template_type is required")
698-
return await cls.__get_client().create_template_async(
698+
return await cls.__get_client(config=config).create_template_async(
699699
input, config=config
700700
)
701701

@@ -714,7 +714,7 @@ def create_template(
714714
"""
715715
if input.template_type is None:
716716
raise ValueError("template_type is required")
717-
return cls.__get_client().create_template(input, config=config)
717+
return cls.__get_client(config=config).create_template(input, config=config)
718718

719719
@classmethod
720720
async def get_template_async(
@@ -731,7 +731,7 @@ async def get_template_async(
731731
"""
732732
if template_name is None:
733733
raise ValueError("template_name is required")
734-
return await cls.__get_client().get_template_async(
734+
return await cls.__get_client(config=config).get_template_async(
735735
template_name, config=config
736736
)
737737

@@ -750,7 +750,7 @@ def get_template(
750750
"""
751751
if template_name is None:
752752
raise ValueError("template_name is required")
753-
return cls.__get_client().get_template(template_name, config=config)
753+
return cls.__get_client(config=config).get_template(template_name, config=config)
754754

755755
@classmethod
756756
async def update_template_async(
@@ -771,7 +771,7 @@ async def update_template_async(
771771
"""
772772
if template_name is None:
773773
raise ValueError("template_name is required")
774-
return await cls.__get_client().update_template_async(
774+
return await cls.__get_client(config=config).update_template_async(
775775
template_name, input, config=config
776776
)
777777

@@ -794,7 +794,7 @@ def update_template(
794794
"""
795795
if template_name is None:
796796
raise ValueError("template_name is required")
797-
return cls.__get_client().update_template(
797+
return cls.__get_client(config=config).update_template(
798798
template_name, input, config=config
799799
)
800800

@@ -813,7 +813,7 @@ async def delete_template_async(
813813
"""
814814
if template_name is None:
815815
raise ValueError("template_name is required")
816-
return await cls.__get_client().delete_template_async(
816+
return await cls.__get_client(config=config).delete_template_async(
817817
template_name, config=config
818818
)
819819

@@ -832,7 +832,7 @@ def delete_template(
832832
"""
833833
if template_name is None:
834834
raise ValueError("template_name is required")
835-
return cls.__get_client().delete_template(template_name, config=config)
835+
return cls.__get_client(config=config).delete_template(template_name, config=config)
836836

837837
@classmethod
838838
async def list_templates_async(
@@ -849,7 +849,7 @@ async def list_templates_async(
849849
Returns:
850850
List[Template]: Template 列表
851851
"""
852-
return await cls.__get_client().list_templates_async(
852+
return await cls.__get_client(config=config).list_templates_async(
853853
input, config=config
854854
)
855855

@@ -868,7 +868,7 @@ def list_templates(
868868
Returns:
869869
List[Template]: Template 列表
870870
"""
871-
return cls.__get_client().list_templates(input, config=config)
871+
return cls.__get_client(config=config).list_templates(input, config=config)
872872

873873
async def get_async(self):
874874
if self.sandbox_id is None:

agentrun/utils/__data_api_async_template.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ async def get_async(
435435
"""
436436
return await self._make_request_async(
437437
"GET",
438-
self.with_path(path, query=query),
438+
self.with_path(path, query=query, config=config),
439439
headers=headers,
440440
config=config,
441441
)
@@ -470,7 +470,7 @@ async def post_async(
470470

471471
return await self._make_request_async(
472472
"POST",
473-
self.with_path(path, query=query),
473+
self.with_path(path, query=query, config=config),
474474
data=data,
475475
headers=headers,
476476
config=config,
@@ -501,7 +501,7 @@ async def put_async(
501501
"""
502502
return await self._make_request_async(
503503
"PUT",
504-
self.with_path(path, query=query),
504+
self.with_path(path, query=query, config=config),
505505
data=data,
506506
headers=headers,
507507
config=config,
@@ -532,7 +532,7 @@ async def patch_async(
532532
"""
533533
return await self._make_request_async(
534534
"PATCH",
535-
self.with_path(path, query=query),
535+
self.with_path(path, query=query, config=config),
536536
data=data,
537537
headers=headers,
538538
config=config,
@@ -561,7 +561,7 @@ async def delete_async(
561561
"""
562562
return await self._make_request_async(
563563
"DELETE",
564-
self.with_path(path, query=query),
564+
self.with_path(path, query=query, config=config),
565565
headers=headers,
566566
config=config,
567567
)
@@ -601,7 +601,7 @@ async def post_file_async(
601601

602602
filename = os.path.basename(local_file_path)
603603

604-
url = self.with_path(path, query=query)
604+
url = self.with_path(path, query=query, config=config)
605605
req_headers = self.config.get_headers()
606606
req_headers.update(headers or {})
607607
# Apply authentication (may modify URL, headers, and query)
@@ -656,7 +656,7 @@ async def get_file_async(
656656
Examples:
657657
>>> await client.get_file_async("/files", save_path="/local/data.csv", query={"path": "/remote/file.csv"})
658658
"""
659-
url = self.with_path(path, query=query)
659+
url = self.with_path(path, query=query, config=config)
660660
req_headers = self.config.get_headers()
661661
req_headers.update(headers or {})
662662
# Apply authentication (may modify URL, headers, and query)
@@ -707,7 +707,7 @@ async def get_video_async(
707707
Examples:
708708
>>> await client.get_video_async("/videos", save_path="/local/video.mkv", query={"path": "/remote/video.mp4"})
709709
"""
710-
url = self.with_path(path, query=query)
710+
url = self.with_path(path, query=query, config=config)
711711
req_headers = self.config.get_headers()
712712
req_headers.update(headers or {})
713713
# Apply authentication (may modify URL, headers, and query)

0 commit comments

Comments
 (0)