Skip to content

Commit 562d231

Browse files
OhYeeclaude
andcommitted
fix: 扩展 config 透传修复至所有资源模块与 endpoint 调用点
问题,但同模式在其他资源模块依然存在:调用方一路向下传递 config,但在 ResourceClass.__get_client() 这一层被静默丢弃,导致下层 Client / DataAPI 以空 config 构造 base URL,最终抛出 "account id is not set"。 本次扩展同样修复至 6 个资源模块和 endpoint 调用点: - agent_runtime/runtime: __get_client() 新增 config 形参并转发到 AgentRuntimeClient,14 处调用全部补齐 config 实参 - agent_runtime/endpoint: __get_client() 已接受 config 但 12 处调用未传, 逐一修正;同时修复实例方法 get_async 调用 get_by_id_async 时漏传 config 的同类问题 - credential/credential: 同 runtime 修复模式 - knowledgebase/knowledgebase: 同 runtime 修复模式 - memory_collection/memory_collection: 同 runtime 修复模式 - model/model_service: 同 runtime 修复模式 - model/model_proxy: 同 runtime 修复模式 实际改动只发生在 __*_async_template.py 源文件上,同步版本通过 make codegen 重新生成,确保与 #88 已修复的 sandbox 模块保持完全一致的写法。 收益:调用方在 ResourceClass.method(config=cfg) 处提供的 config 现在能 完整传到 base URL 构造、auth、headers 全链路,不再因 __get_client 层丢失 而触发 account_id 缺失或落到错误 endpoint 的问题。 Change-Id: Iff7177062d1ad574f9a65eb663aff70e670e7fcd Co-developed-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: OhYee <oyohyee@oyohyee.com>
1 parent 8582d6d commit 562d231

14 files changed

Lines changed: 205 additions & 159 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)
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)
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)
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)
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).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)
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).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)
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).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).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).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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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).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).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)
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)
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)