-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCopilotClientOptions.java
More file actions
349 lines (318 loc) · 9.89 KB
/
CopilotClientOptions.java
File metadata and controls
349 lines (318 loc) · 9.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package com.github.copilot.sdk.json;
import java.util.Map;
import java.util.logging.Logger;
import com.fasterxml.jackson.annotation.JsonInclude;
/**
* Configuration options for creating a
* {@link com.github.copilot.sdk.CopilotClient}.
* <p>
* This class provides a fluent API for configuring how the client connects to
* and manages the Copilot CLI server. All setter methods return {@code this}
* for method chaining.
*
* <h2>Example Usage</h2>
*
* <pre>{@code
* var options = new CopilotClientOptions().setCliPath("/usr/local/bin/copilot").setLogLevel("debug")
* .setAutoStart(true);
*
* var client = new CopilotClient(options);
* }</pre>
*
* @see com.github.copilot.sdk.CopilotClient
* @since 1.0.0
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CopilotClientOptions {
private String cliPath;
private String[] cliArgs;
private String cwd;
private int port;
private boolean useStdio = true;
private String cliUrl;
private String logLevel = "info";
private boolean autoStart = true;
private boolean autoRestart = true;
private Map<String, String> environment;
private Logger logger;
private String githubToken;
private Boolean useLoggedInUser;
/**
* Gets the path to the Copilot CLI executable.
*
* @return the CLI path, or {@code null} to use "copilot" from PATH
*/
public String getCliPath() {
return cliPath;
}
/**
* Sets the path to the Copilot CLI executable.
*
* @param cliPath
* the path to the CLI executable, or {@code null} to use "copilot"
* from PATH
* @return this options instance for method chaining
*/
public CopilotClientOptions setCliPath(String cliPath) {
this.cliPath = cliPath;
return this;
}
/**
* Gets the extra CLI arguments.
*
* @return the extra arguments to pass to the CLI
*/
public String[] getCliArgs() {
return cliArgs;
}
/**
* Sets extra arguments to pass to the CLI process.
* <p>
* These arguments are prepended before SDK-managed flags.
*
* @param cliArgs
* the extra arguments to pass
* @return this options instance for method chaining
*/
public CopilotClientOptions setCliArgs(String[] cliArgs) {
this.cliArgs = cliArgs;
return this;
}
/**
* Gets the working directory for the CLI process.
*
* @return the working directory path
*/
public String getCwd() {
return cwd;
}
/**
* Sets the working directory for the CLI process.
*
* @param cwd
* the working directory path
* @return this options instance for method chaining
*/
public CopilotClientOptions setCwd(String cwd) {
this.cwd = cwd;
return this;
}
/**
* Gets the TCP port for the CLI server.
*
* @return the port number, or 0 for a random port
*/
public int getPort() {
return port;
}
/**
* Sets the TCP port for the CLI server to listen on.
* <p>
* This is only used when {@link #isUseStdio()} is {@code false}.
*
* @param port
* the port number, or 0 for a random port
* @return this options instance for method chaining
*/
public CopilotClientOptions setPort(int port) {
this.port = port;
return this;
}
/**
* Returns whether to use stdio transport instead of TCP.
*
* @return {@code true} to use stdio (default), {@code false} to use TCP
*/
public boolean isUseStdio() {
return useStdio;
}
/**
* Sets whether to use stdio transport instead of TCP.
* <p>
* Stdio transport is more efficient and is the default. TCP transport can be
* useful for debugging or connecting to remote servers.
*
* @param useStdio
* {@code true} to use stdio, {@code false} to use TCP
* @return this options instance for method chaining
*/
public CopilotClientOptions setUseStdio(boolean useStdio) {
this.useStdio = useStdio;
return this;
}
/**
* Gets the URL of an existing CLI server to connect to.
*
* @return the CLI server URL, or {@code null} to spawn a new process
*/
public String getCliUrl() {
return cliUrl;
}
/**
* Sets the URL of an existing CLI server to connect to.
* <p>
* When provided, the client will not spawn a CLI process but will connect to
* the specified URL instead. Format: "host:port" or "http://host:port".
* <p>
* <strong>Note:</strong> This is mutually exclusive with
* {@link #setUseStdio(boolean)} and {@link #setCliPath(String)}.
*
* @param cliUrl
* the CLI server URL to connect to
* @return this options instance for method chaining
*/
public CopilotClientOptions setCliUrl(String cliUrl) {
this.cliUrl = cliUrl;
return this;
}
/**
* Gets the log level for the CLI process.
*
* @return the log level (default: "info")
*/
public String getLogLevel() {
return logLevel;
}
/**
* Sets the log level for the CLI process.
* <p>
* Valid levels include: "error", "warn", "info", "debug", "trace".
*
* @param logLevel
* the log level
* @return this options instance for method chaining
*/
public CopilotClientOptions setLogLevel(String logLevel) {
this.logLevel = logLevel;
return this;
}
/**
* Returns whether the client should automatically start the server.
*
* @return {@code true} to auto-start (default), {@code false} for manual start
*/
public boolean isAutoStart() {
return autoStart;
}
/**
* Sets whether the client should automatically start the CLI server when the
* first request is made.
*
* @param autoStart
* {@code true} to auto-start, {@code false} for manual start
* @return this options instance for method chaining
*/
public CopilotClientOptions setAutoStart(boolean autoStart) {
this.autoStart = autoStart;
return this;
}
/**
* Returns whether the client should automatically restart the server on crash.
*
* @return {@code true} to auto-restart (default), {@code false} otherwise
*/
public boolean isAutoRestart() {
return autoRestart;
}
/**
* Sets whether the client should automatically restart the CLI server if it
* crashes unexpectedly.
*
* @param autoRestart
* {@code true} to auto-restart, {@code false} otherwise
* @return this options instance for method chaining
*/
public CopilotClientOptions setAutoRestart(boolean autoRestart) {
this.autoRestart = autoRestart;
return this;
}
/**
* Gets the environment variables for the CLI process.
*
* @return the environment variables map
*/
public Map<String, String> getEnvironment() {
return environment;
}
/**
* Sets environment variables to pass to the CLI process.
* <p>
* When set, these environment variables replace the inherited environment.
*
* @param environment
* the environment variables map
* @return this options instance for method chaining
*/
public CopilotClientOptions setEnvironment(Map<String, String> environment) {
this.environment = environment;
return this;
}
/**
* Gets the custom logger for the client.
*
* @return the logger instance
*/
public Logger getLogger() {
return logger;
}
/**
* Sets a custom logger for the client.
*
* @param logger
* the logger instance to use
* @return this options instance for method chaining
*/
public CopilotClientOptions setLogger(Logger logger) {
this.logger = logger;
return this;
}
/**
* Gets the GitHub token for authentication.
*
* @return the GitHub token, or {@code null} to use other authentication methods
*/
public String getGithubToken() {
return githubToken;
}
/**
* Sets the GitHub token to use for authentication.
* <p>
* When provided, the token is passed to the CLI server via environment
* variable. This takes priority over other authentication methods.
*
* @param githubToken
* the GitHub token
* @return this options instance for method chaining
*/
public CopilotClientOptions setGithubToken(String githubToken) {
this.githubToken = githubToken;
return this;
}
/**
* Returns whether to use the logged-in user for authentication.
*
* @return {@code true} to use logged-in user auth, {@code false} to use only
* explicit tokens, or {@code null} to use default behavior
*/
public Boolean getUseLoggedInUser() {
return useLoggedInUser;
}
/**
* Sets whether to use the logged-in user for authentication.
* <p>
* When true, the CLI server will attempt to use stored OAuth tokens or gh CLI
* auth. When false, only explicit tokens (githubToken or environment variables)
* are used. Default: true (but defaults to false when githubToken is provided).
*
* @param useLoggedInUser
* {@code true} to use logged-in user auth, {@code false} otherwise
* @return this options instance for method chaining
*/
public CopilotClientOptions setUseLoggedInUser(Boolean useLoggedInUser) {
this.useLoggedInUser = useLoggedInUser;
return this;
}
}