88import com .alibaba .dashscope .agentstudio .resource .Skills ;
99import com .alibaba .dashscope .agentstudio .resource .Vaults ;
1010import com .alibaba .dashscope .protocol .ConnectionOptions ;
11- import com .alibaba .dashscope .utils .Constants ;
1211import java .io .Closeable ;
1312import java .util .concurrent .CompletableFuture ;
14- import java .util .concurrent .ExecutorService ;
15- import java .util .concurrent .ForkJoinPool ;
1613import java .util .function .Supplier ;
1714
1815public class AgentStudioClient implements Closeable {
@@ -23,61 +20,34 @@ public class AgentStudioClient implements Closeable {
2320 private final Vaults vaults ;
2421 private final Files files ;
2522 private final String baseUrl ;
26- private final ExecutorService asyncExecutor ;
2723
28- /** All from env vars: DASHSCOPE_API_KEY, DASHSCOPE_WORKSPACE, DASHSCOPE_API_REGION. */
2924 public AgentStudioClient () {
3025 this (null , null , null , null , null );
3126 }
3227
33- /**
34- * Workspace only, apiKey from DASHSCOPE_API_KEY env var.
35- *
36- * @param workspace workspace ID (required)
37- */
3828 public AgentStudioClient (String workspace ) {
3929 this (null , null , workspace , null , null );
4030 }
4131
42- /**
43- * Most common: apiKey + workspace for production.
44- *
45- * @param apiKey API Key (or set DASHSCOPE_API_KEY env var)
46- * @param workspace workspace ID (required)
47- */
4832 public AgentStudioClient (String apiKey , String workspace ) {
4933 this (apiKey , null , workspace , null , null );
5034 }
5135
52- /**
53- * Full constructor — prefer {@link #builder()} for readability.
54- *
55- * @param apiKey API Key (nullable → read from DASHSCOPE_API_KEY)
56- * @param baseUrl full base URL (nullable → use workspace + region)
57- * @param workspace workspace ID (required if baseUrl is null)
58- * @param region region (nullable → default cn-beijing)
59- * @param connectionOptions timeout / retry config (nullable)
60- */
6136 public AgentStudioClient (
6237 String apiKey ,
6338 String baseUrl ,
6439 String workspace ,
6540 String region ,
6641 ConnectionOptions connectionOptions ) {
67- if (apiKey != null && !apiKey .isEmpty ()) {
68- Constants .apiKey = apiKey ;
69- }
7042 this .baseUrl = resolveBaseUrl (baseUrl , workspace , region );
71- this .agents = new Agents (this .baseUrl , connectionOptions );
72- this .sessions = new Sessions (this .baseUrl , connectionOptions );
73- this .environments = new Environments (this .baseUrl , connectionOptions );
74- this .skills = new Skills (this .baseUrl , connectionOptions );
75- this .vaults = new Vaults (this .baseUrl , connectionOptions );
76- this .files = new Files (this .baseUrl , connectionOptions );
77- this .asyncExecutor = ForkJoinPool .commonPool ();
43+ this .agents = new Agents (this .baseUrl , connectionOptions , apiKey );
44+ this .sessions = new Sessions (this .baseUrl , connectionOptions , apiKey );
45+ this .environments = new Environments (this .baseUrl , connectionOptions , apiKey );
46+ this .files = new Files (this .baseUrl , connectionOptions , apiKey );
47+ this .skills = new Skills (this .baseUrl , connectionOptions , apiKey , this .files );
48+ this .vaults = new Vaults (this .baseUrl , connectionOptions , apiKey );
7849 }
7950
80- /** Builder for advanced use cases (pre-env baseUrl, custom region, etc.). */
8151 public static Builder builder () {
8252 return new Builder ();
8353 }
@@ -147,26 +117,15 @@ public String getBaseUrl() {
147117 return baseUrl ;
148118 }
149119
150- ExecutorService getAsyncExecutor () {
151- return asyncExecutor ;
152- }
153-
154- /**
155- * Run any sync SDK call asynchronously.
156- *
157- * <pre>{@code
158- * client.async(() -> client.agents().create(param))
159- * .thenAccept(agent -> System.out.println(agent.getId()));
160- * }</pre>
161- */
162120 public <T > CompletableFuture <T > async (Supplier <T > supplier ) {
163- return CompletableFuture .supplyAsync (supplier , asyncExecutor );
121+ return CompletableFuture .supplyAsync (supplier );
164122 }
165123
166124 @ Override
167125 public void close () {
168126 sessions .events ().close ();
169- asyncExecutor .shutdownNow ();
127+ skills .close ();
128+ files .close ();
170129 }
171130
172131 private static String resolveBaseUrl (String explicitUrl , String workspace , String region ) {
@@ -180,22 +139,6 @@ private static String resolveBaseUrl(String explicitUrl, String workspace, Strin
180139 if (envUrl != null && !envUrl .isEmpty ()) {
181140 return envUrl ;
182141 }
183- String ws = workspace ;
184- if (ws == null || ws .isEmpty ()) {
185- ws = System .getenv (AgentStudioConstants .ENV_WORKSPACE );
186- }
187- if (ws == null || ws .isEmpty ()) {
188- throw new IllegalArgumentException (
189- "workspace is required. Pass it to the constructor, "
190- + "set DASHSCOPE_WORKSPACE env var, or set DASHSCOPE_AGENTSTUDIO_URL." );
191- }
192- String r = region ;
193- if (r == null || r .isEmpty ()) {
194- r = System .getenv (AgentStudioConstants .ENV_REGION );
195- }
196- if (r == null || r .isEmpty ()) {
197- r = AgentStudioConstants .DEFAULT_REGION ;
198- }
199- return String .format (AgentStudioConstants .BASE_URL_TEMPLATE , ws , r );
142+ return AgentStudioConstants .resolveBaseUrl (workspace , region );
200143 }
201144}
0 commit comments