44
55package com .github .copilot .sdk .json ;
66
7+ import java .util .Arrays ;
8+ import java .util .HashMap ;
79import java .util .List ;
810import java .util .Map ;
911import java .util .Objects ;
@@ -105,24 +107,35 @@ public CopilotClientOptions setAutoStart(boolean autoStart) {
105107
106108 /**
107109 * Gets the extra CLI arguments.
110+ * <p>
111+ * Returns a shallow copy of the internal array, or {@code null} if no arguments
112+ * have been set.
108113 *
109- * @return the extra arguments to pass to the CLI
114+ * @return a copy of the extra arguments, or {@code null}
110115 */
111116 public String [] getCliArgs () {
112- return cliArgs ;
117+ return cliArgs != null ? Arrays . copyOf ( cliArgs , cliArgs . length ) : null ;
113118 }
114119
115120 /**
116121 * Sets extra arguments to pass to the CLI process.
117122 * <p>
118- * These arguments are prepended before SDK-managed flags.
123+ * These arguments are prepended before SDK-managed flags. A shallow copy of the
124+ * provided array is stored. If {@code null} or empty, the existing arguments
125+ * are cleared.
119126 *
120127 * @param cliArgs
121- * the extra arguments to pass
128+ * the extra arguments to pass, or {@code null}/empty to clear
122129 * @return this options instance for method chaining
123130 */
124131 public CopilotClientOptions setCliArgs (String [] cliArgs ) {
125- this .cliArgs = Objects .requireNonNull (cliArgs , "cliArgs must not be null" );
132+ if (cliArgs == null || cliArgs .length == 0 ) {
133+ if (this .cliArgs != null ) {
134+ this .cliArgs = new String [0 ];
135+ }
136+ } else {
137+ this .cliArgs = Arrays .copyOf (cliArgs , cliArgs .length );
138+ }
126139 return this ;
127140 }
128141
@@ -166,8 +179,11 @@ public String getCliUrl() {
166179 * {@link #setUseStdio(boolean)} and {@link #setCliPath(String)}.
167180 *
168181 * @param cliUrl
169- * the CLI server URL to connect to
182+ * the CLI server URL to connect to (must not be {@code null} or
183+ * empty)
170184 * @return this options instance for method chaining
185+ * @throws IllegalArgumentException
186+ * if {@code cliUrl} is {@code null} or empty
171187 */
172188 public CopilotClientOptions setCliUrl (String cliUrl ) {
173189 this .cliUrl = Objects .requireNonNull (cliUrl , "cliUrl must not be null" );
@@ -187,8 +203,10 @@ public String getCwd() {
187203 * Sets the working directory for the CLI process.
188204 *
189205 * @param cwd
190- * the working directory path
206+ * the working directory path (must not be {@code null} or empty)
191207 * @return this options instance for method chaining
208+ * @throws IllegalArgumentException
209+ * if {@code cwd} is {@code null} or empty
192210 */
193211 public CopilotClientOptions setCwd (String cwd ) {
194212 this .cwd = Objects .requireNonNull (cwd , "cwd must not be null" );
@@ -197,24 +215,35 @@ public CopilotClientOptions setCwd(String cwd) {
197215
198216 /**
199217 * Gets the environment variables for the CLI process.
218+ * <p>
219+ * Returns a shallow copy of the internal map, or {@code null} if no environment
220+ * has been set.
200221 *
201- * @return the environment variables map
222+ * @return a copy of the environment variables map, or {@code null}
202223 */
203224 public Map <String , String > getEnvironment () {
204- return environment ;
225+ return environment != null ? new HashMap <>( environment ) : null ;
205226 }
206227
207228 /**
208229 * Sets environment variables to pass to the CLI process.
209230 * <p>
210- * When set, these environment variables replace the inherited environment.
231+ * When set, these environment variables replace the inherited environment. A
232+ * shallow copy of the provided map is stored. If {@code null} or empty, the
233+ * existing environment is cleared.
211234 *
212235 * @param environment
213- * the environment variables map
236+ * the environment variables map, or {@code null}/empty to clear
214237 * @return this options instance for method chaining
215238 */
216239 public CopilotClientOptions setEnvironment (Map <String , String > environment ) {
217- this .environment = Objects .requireNonNull (environment , "environment must not be null" );
240+ if (environment == null || environment .isEmpty ()) {
241+ if (this .environment != null ) {
242+ this .environment .clear ();
243+ }
244+ } else {
245+ this .environment = new HashMap <>(environment );
246+ }
218247 return this ;
219248 }
220249
@@ -261,8 +290,10 @@ public String getGitHubToken() {
261290 * variable. This takes priority over other authentication methods.
262291 *
263292 * @param gitHubToken
264- * the GitHub token
293+ * the GitHub token (must not be {@code null} or empty)
265294 * @return this options instance for method chaining
295+ * @throws IllegalArgumentException
296+ * if {@code gitHubToken} is {@code null} or empty
266297 */
267298 public CopilotClientOptions setGitHubToken (String gitHubToken ) {
268299 this .gitHubToken = Objects .requireNonNull (gitHubToken , "gitHubToken must not be null" );
@@ -309,8 +340,10 @@ public String getLogLevel() {
309340 * Valid levels include: "error", "warn", "info", "debug", "trace".
310341 *
311342 * @param logLevel
312- * the log level
343+ * the log level (must not be {@code null} or empty)
313344 * @return this options instance for method chaining
345+ * @throws IllegalArgumentException
346+ * if {@code logLevel} is {@code null} or empty
314347 */
315348 public CopilotClientOptions setLogLevel (String logLevel ) {
316349 this .logLevel = Objects .requireNonNull (logLevel , "logLevel must not be null" );
@@ -334,8 +367,11 @@ public Supplier<CompletableFuture<List<ModelInfo>>> getOnListModels() {
334367 * available from your custom provider.
335368 *
336369 * @param onListModels
337- * the handler that returns the list of available models
370+ * the handler that returns the list of available models (must not be
371+ * {@code null})
338372 * @return this options instance for method chaining
373+ * @throws IllegalArgumentException
374+ * if {@code onListModels} is {@code null}
339375 */
340376 public CopilotClientOptions setOnListModels (Supplier <CompletableFuture <List <ModelInfo >>> onListModels ) {
341377 this .onListModels = Objects .requireNonNull (onListModels , "onListModels must not be null" );
@@ -407,13 +443,16 @@ public Boolean getUseLoggedInUser() {
407443 * When true, the CLI server will attempt to use stored OAuth tokens or gh CLI
408444 * auth. When false, only explicit tokens (gitHubToken or environment variables)
409445 * are used. Default: true (but defaults to false when gitHubToken is provided).
446+ * <p>
447+ * Passing {@code null} is equivalent to passing {@link Boolean#FALSE}.
410448 *
411449 * @param useLoggedInUser
412- * {@code true} to use logged-in user auth, {@code false} otherwise
450+ * {@code true} to use logged-in user auth, {@code false} or
451+ * {@code null} otherwise
413452 * @return this options instance for method chaining
414453 */
415454 public CopilotClientOptions setUseLoggedInUser (Boolean useLoggedInUser ) {
416- this .useLoggedInUser = useLoggedInUser ;
455+ this .useLoggedInUser = useLoggedInUser != null ? useLoggedInUser : Boolean . FALSE ;
417456 return this ;
418457 }
419458
0 commit comments