Skip to content

Commit 5523af3

Browse files
authored
Merge pull request #88 from Serverless-Devs/copilot/fix-sandbox-delete-config-issue
Fix config not propagated to data-plane URL construction in DataAPI, Sandbox.__get_client(), and all resource modules
2 parents eee4e8b + a31ba3b commit 5523af3

23 files changed

Lines changed: 367 additions & 227 deletions

agentrun/agent_runtime/__endpoint_async_template.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async def create_by_id_async(
6767
ResourceNotExistError: Agent Runtime 不存在 / Agent Runtime does not exist
6868
HTTPError: HTTP 请求错误 / HTTP request error
6969
"""
70-
cli = cls.__get_client()
70+
cli = cls.__get_client(config=config)
7171
return await cli.create_endpoint_async(
7272
agent_runtime_id,
7373
input,
@@ -95,7 +95,7 @@ async def delete_by_id_async(
9595
ResourceNotExistError: 资源不存在 / Resource does not exist
9696
HTTPError: HTTP 请求错误 / HTTP request error
9797
"""
98-
cli = cls.__get_client()
98+
cli = cls.__get_client(config=config)
9999
return await cli.delete_endpoint_async(
100100
agent_runtime_id,
101101
endpoint_id,
@@ -125,7 +125,7 @@ async def update_by_id_async(
125125
ResourceNotExistError: 资源不存在 / Resource does not exist
126126
HTTPError: HTTP 请求错误 / HTTP request error
127127
"""
128-
cli = cls.__get_client()
128+
cli = cls.__get_client(config=config)
129129
return await cli.update_endpoint_async(
130130
agent_runtime_id,
131131
endpoint_id,
@@ -154,7 +154,7 @@ async def get_by_id_async(
154154
ResourceNotExistError: 资源不存在 / Resource does not exist
155155
HTTPError: HTTP 请求错误 / HTTP request error
156156
"""
157-
cli = cls.__get_client()
157+
cli = cls.__get_client(config=config)
158158
return await cli.get_endpoint_async(
159159
agent_runtime_id,
160160
endpoint_id,
@@ -191,7 +191,7 @@ async def _list_page_async(
191191
"agent_runtime_id is required for listing endpoints"
192192
)
193193

194-
return await cls.__get_client().list_endpoints_async(
194+
return await cls.__get_client(config=config).list_endpoints_async(
195195
agent_runtime_id,
196196
AgentRuntimeEndpointListInput(
197197
page_number=page_input.page_number,
@@ -219,7 +219,7 @@ async def list_by_id_async(
219219
Raises:
220220
HTTPError: HTTP 请求错误 / HTTP request error
221221
"""
222-
cli = cls.__get_client()
222+
cli = cls.__get_client(config=config)
223223

224224
endpoints: List[AgentRuntimeEndpoint] = []
225225
page = 1
@@ -339,7 +339,9 @@ async def get_async(self, config: Optional[Config] = None):
339339
)
340340

341341
result = await self.get_by_id_async(
342-
self.agent_runtime_id, self.agent_runtime_endpoint_id
342+
self.agent_runtime_id,
343+
self.agent_runtime_endpoint_id,
344+
config=config,
343345
)
344346
self.update_self(result)
345347
return self

agentrun/agent_runtime/__runtime_async_template.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,18 @@ class AgentRuntime(
4646
_data_api: Dict[str, AgentRuntimeDataAPI] = {}
4747

4848
@classmethod
49-
def __get_client(cls):
49+
def __get_client(cls, config: Optional[Config] = None):
5050
"""获取客户端实例 / Get client instance
5151
52+
Args:
53+
config: 配置对象,可选 / Configuration object, optional
54+
5255
Returns:
5356
AgentRuntimeClient: 客户端实例 / Client instance
5457
"""
5558
from .client import AgentRuntimeClient
5659

57-
return AgentRuntimeClient()
60+
return AgentRuntimeClient(config=config)
5861

5962
@classmethod
6063
async def create_async(
@@ -74,7 +77,7 @@ async def create_async(
7477
ResourceAlreadyExistError: 资源已存在 / Resource already exists
7578
HTTPError: HTTP 请求错误 / HTTP request error
7679
"""
77-
return await cls.__get_client().create_async(input, config=config)
80+
return await cls.__get_client(config=config).create_async(input, config=config)
7881

7982
@classmethod
8083
async def delete_by_id_async(cls, id: str, config: Optional[Config] = None):
@@ -94,7 +97,7 @@ async def delete_by_id_async(cls, id: str, config: Optional[Config] = None):
9497
ResourceNotExistError: 资源不存在 / Resource does not exist
9598
HTTPError: HTTP 请求错误 / HTTP request error
9699
"""
97-
cli = cls.__get_client()
100+
cli = cls.__get_client(config=config)
98101

99102
# 删除所有的 endpoint / Delete all endpoints
100103
endpoints = await cli.list_endpoints_async(id, config=config)
@@ -133,7 +136,9 @@ async def update_by_id_async(
133136
ResourceNotExistError: 资源不存在 / Resource does not exist
134137
HTTPError: HTTP 请求错误 / HTTP request error
135138
"""
136-
return await cls.__get_client().update_async(id, input, config=config)
139+
return await cls.__get_client(config=config).update_async(
140+
id, input, config=config
141+
)
137142

138143
@classmethod
139144
async def get_by_id_async(cls, id: str, config: Optional[Config] = None):
@@ -150,13 +155,13 @@ async def get_by_id_async(cls, id: str, config: Optional[Config] = None):
150155
ResourceNotExistError: 资源不存在 / Resource does not exist
151156
HTTPError: HTTP 请求错误 / HTTP request error
152157
"""
153-
return await cls.__get_client().get_async(id, config=config)
158+
return await cls.__get_client(config=config).get_async(id, config=config)
154159

155160
@classmethod
156161
async def _list_page_async(
157162
cls, page_input: PageableInput, config: Config | None = None, **kwargs
158163
):
159-
return await cls.__get_client().list_async(
164+
return await cls.__get_client(config=config).list_async(
160165
input=AgentRuntimeListInput(
161166
**kwargs,
162167
**page_input.model_dump(),
@@ -197,7 +202,7 @@ async def list_async(cls, config: Optional[Config] = None):
197202
Raises:
198203
HTTPError: HTTP 请求错误 / HTTP request error
199204
"""
200-
cli = cls.__get_client()
205+
cli = cls.__get_client(config=config)
201206

202207
runtimes: List[AgentRuntime] = []
203208
page = 1
@@ -294,7 +299,7 @@ async def list_versions_by_id_async(
294299
agent_runtime_id: str,
295300
config: Optional[Config] = None,
296301
):
297-
cli = cls.__get_client()
302+
cli = cls.__get_client(config=config)
298303

299304
versions: List[AgentRuntimeVersion] = []
300305
page = 1

agentrun/agent_runtime/endpoint.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async def create_by_id_async(
7777
ResourceNotExistError: Agent Runtime 不存在 / Agent Runtime does not exist
7878
HTTPError: HTTP 请求错误 / HTTP request error
7979
"""
80-
cli = cls.__get_client()
80+
cli = cls.__get_client(config=config)
8181
return await cli.create_endpoint_async(
8282
agent_runtime_id,
8383
input,
@@ -106,7 +106,7 @@ def create_by_id(
106106
ResourceNotExistError: Agent Runtime 不存在 / Agent Runtime does not exist
107107
HTTPError: HTTP 请求错误 / HTTP request error
108108
"""
109-
cli = cls.__get_client()
109+
cli = cls.__get_client(config=config)
110110
return cli.create_endpoint(
111111
agent_runtime_id,
112112
input,
@@ -134,7 +134,7 @@ async def delete_by_id_async(
134134
ResourceNotExistError: 资源不存在 / Resource does not exist
135135
HTTPError: HTTP 请求错误 / HTTP request error
136136
"""
137-
cli = cls.__get_client()
137+
cli = cls.__get_client(config=config)
138138
return await cli.delete_endpoint_async(
139139
agent_runtime_id,
140140
endpoint_id,
@@ -162,7 +162,7 @@ def delete_by_id(
162162
ResourceNotExistError: 资源不存在 / Resource does not exist
163163
HTTPError: HTTP 请求错误 / HTTP request error
164164
"""
165-
cli = cls.__get_client()
165+
cli = cls.__get_client(config=config)
166166
return cli.delete_endpoint(
167167
agent_runtime_id,
168168
endpoint_id,
@@ -192,7 +192,7 @@ async def update_by_id_async(
192192
ResourceNotExistError: 资源不存在 / Resource does not exist
193193
HTTPError: HTTP 请求错误 / HTTP request error
194194
"""
195-
cli = cls.__get_client()
195+
cli = cls.__get_client(config=config)
196196
return await cli.update_endpoint_async(
197197
agent_runtime_id,
198198
endpoint_id,
@@ -223,7 +223,7 @@ def update_by_id(
223223
ResourceNotExistError: 资源不存在 / Resource does not exist
224224
HTTPError: HTTP 请求错误 / HTTP request error
225225
"""
226-
cli = cls.__get_client()
226+
cli = cls.__get_client(config=config)
227227
return cli.update_endpoint(
228228
agent_runtime_id,
229229
endpoint_id,
@@ -252,7 +252,7 @@ async def get_by_id_async(
252252
ResourceNotExistError: 资源不存在 / Resource does not exist
253253
HTTPError: HTTP 请求错误 / HTTP request error
254254
"""
255-
cli = cls.__get_client()
255+
cli = cls.__get_client(config=config)
256256
return await cli.get_endpoint_async(
257257
agent_runtime_id,
258258
endpoint_id,
@@ -280,7 +280,7 @@ def get_by_id(
280280
ResourceNotExistError: 资源不存在 / Resource does not exist
281281
HTTPError: HTTP 请求错误 / HTTP request error
282282
"""
283-
cli = cls.__get_client()
283+
cli = cls.__get_client(config=config)
284284
return cli.get_endpoint(
285285
agent_runtime_id,
286286
endpoint_id,
@@ -317,7 +317,7 @@ async def _list_page_async(
317317
"agent_runtime_id is required for listing endpoints"
318318
)
319319

320-
return await cls.__get_client().list_endpoints_async(
320+
return await cls.__get_client(config=config).list_endpoints_async(
321321
agent_runtime_id,
322322
AgentRuntimeEndpointListInput(
323323
page_number=page_input.page_number,
@@ -356,7 +356,7 @@ def _list_page(
356356
"agent_runtime_id is required for listing endpoints"
357357
)
358358

359-
return cls.__get_client().list_endpoints(
359+
return cls.__get_client(config=config).list_endpoints(
360360
agent_runtime_id,
361361
AgentRuntimeEndpointListInput(
362362
page_number=page_input.page_number,
@@ -384,7 +384,7 @@ async def list_by_id_async(
384384
Raises:
385385
HTTPError: HTTP 请求错误 / HTTP request error
386386
"""
387-
cli = cls.__get_client()
387+
cli = cls.__get_client(config=config)
388388

389389
endpoints: List[AgentRuntimeEndpoint] = []
390390
page = 1
@@ -429,7 +429,7 @@ def list_by_id(cls, agent_runtime_id: str, config: Optional[Config] = None):
429429
Raises:
430430
HTTPError: HTTP 请求错误 / HTTP request error
431431
"""
432-
cli = cls.__get_client()
432+
cli = cls.__get_client(config=config)
433433

434434
endpoints: List[AgentRuntimeEndpoint] = []
435435
page = 1
@@ -615,7 +615,9 @@ async def get_async(self, config: Optional[Config] = None):
615615
)
616616

617617
result = await self.get_by_id_async(
618-
self.agent_runtime_id, self.agent_runtime_endpoint_id
618+
self.agent_runtime_id,
619+
self.agent_runtime_endpoint_id,
620+
config=config,
619621
)
620622
self.update_self(result)
621623
return self
@@ -644,7 +646,9 @@ def get(self, config: Optional[Config] = None):
644646
)
645647

646648
result = self.get_by_id(
647-
self.agent_runtime_id, self.agent_runtime_endpoint_id
649+
self.agent_runtime_id,
650+
self.agent_runtime_endpoint_id,
651+
config=config,
648652
)
649653
self.update_self(result)
650654
return self

0 commit comments

Comments
 (0)