2626from volcengine .Credentials import Credentials
2727from volcengine .ServiceInfo import ServiceInfo
2828
29- from agentkit .utils .ve_sign import (
30- get_volc_ak_sk_region ,
31- ensure_x_custom_source_header ,
29+ from agentkit .platform import (
30+ VolcConfiguration ,
31+ resolve_credentials ,
32+ resolve_endpoint ,
3233)
34+ from agentkit .utils .ve_sign import ensure_x_custom_source_header
3335
3436T = TypeVar ("T" )
3537
@@ -62,52 +64,61 @@ class BaseServiceClient(Service):
6264
6365 Subclasses should:
6466 1. Override API_ACTIONS with their API action configurations
65- 2. Implement _get_service_config() to provide service-specific configuration
6667 """
6768
6869 # Subclasses should override this with their API action configurations
6970 API_ACTIONS : Dict [str , Union [str , ApiConfig ]] = {}
7071
7172 def __init__ (
7273 self ,
74+ service : str ,
7375 access_key : str = "" ,
7476 secret_key : str = "" ,
7577 region : str = "" ,
7678 session_token : str = "" ,
7779 service_name : str = "" ,
78- credential_env_prefix : str = "" ,
80+ platform_config : Optional [ VolcConfiguration ] = None ,
7981 header : Optional [Dict [str , Any ]] = None ,
8082 ) -> None :
8183 """
8284 Initialize the service client.
8385
8486 Args:
87+ service: Logical service name for signing and endpoint resolution
8588 access_key: Volcengine access key
8689 secret_key: Volcengine secret key
87- region: Volcengine region
90+ region: Volcengine region override for endpoint
8891 session_token: Optional session token
8992 service_name: Service name for logging
90- credential_env_prefix: Environment variable prefix for credentials (e.g., 'AGENTKIT', 'IAM')
93+ platform_config: Optional platform-level configuration overrides
9194 """
92- # Validate and get credentials
93- if not any ([access_key , secret_key , region ]):
94- access_key , secret_key , region = get_volc_ak_sk_region (
95- credential_env_prefix
96- )
97- else :
98- if not all ([access_key , secret_key , region ]):
99- raise ValueError (
100- f"Error creating { service_name } instance: "
101- "missing access key, secret key or region"
102- )
95+ if platform_config is None :
96+ platform_config = VolcConfiguration ()
97+
98+ creds = resolve_credentials (
99+ service = service ,
100+ explicit_access_key = access_key or None ,
101+ explicit_secret_key = secret_key or None ,
102+ platform_config = platform_config ,
103+ )
104+
105+ ep = resolve_endpoint (
106+ service = service ,
107+ region = region or None ,
108+ platform_config = platform_config ,
109+ )
103110
104- # Store credentials and service info
105- self .access_key = access_key
106- self .secret_key = secret_key
107- self .region = region
111+ self .access_key = creds .access_key
112+ self .secret_key = creds .secret_key
113+ self .region = ep .region
108114 self .session_token = session_token
109115 self .service_name = service_name
110116
117+ self .host = ep .host
118+ self .api_version = ep .api_version
119+ self .service = ep .service
120+ self .scheme = ep .scheme
121+
111122 if header is None :
112123 effective_header : Dict [str , Any ] = {"Accept" : "application/json" }
113124 else :
@@ -116,14 +127,6 @@ def __init__(
116127 effective_header = {"Accept" : "application/json" , ** effective_header }
117128
118129 effective_header = ensure_x_custom_source_header (effective_header )
119-
120- # Get service-specific configuration from subclass
121- config = self ._get_service_config ()
122- self .host = config ["host" ]
123- self .api_version = config ["api_version" ]
124- self .service = config ["service" ]
125- self .scheme = config .get ("scheme" , "https" )
126-
127130 # Create ServiceInfo
128131 self .service_info = ServiceInfo (
129132 host = self .host ,
@@ -145,20 +148,9 @@ def __init__(
145148
146149 # Initialize parent Service class
147150 Service .__init__ (self , service_info = self .service_info , api_info = self .api_info )
148-
149- def _get_service_config (self ) -> Dict [str , str ]:
150- """
151- Get service-specific configuration.
152-
153- Subclasses must override this method to provide:
154- - host: API endpoint host
155- - api_version: API version string
156- - service: Service name for signing
157-
158- Returns:
159- Dictionary with 'host', 'api_version', and 'service' keys
160- """
161- raise NotImplementedError ("Subclasses must implement _get_service_config()" )
151+ # need setting ak/sk after initializing Service to avoid volcengine SDK bugs
152+ self .set_ak (self .access_key )
153+ self .set_sk (self .secret_key )
162154
163155 def _build_api_info (self ) -> Dict [str , ApiInfo ]:
164156 """
0 commit comments