forked from github/copilot-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSessionConfig.java
More file actions
312 lines (285 loc) · 8.94 KB
/
SessionConfig.java
File metadata and controls
312 lines (285 loc) · 8.94 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package com.github.copilot.sdk.json;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonInclude;
/**
* Configuration for creating a new Copilot session.
* <p>
* This class provides options for customizing session behavior, including model
* selection, tool registration, system message customization, and more. All
* setter methods return {@code this} for method chaining.
*
* <h2>Example Usage</h2>
*
* <pre>{@code
* var config = new SessionConfig().setModel("gpt-5").setStreaming(true).setSystemMessage(
* new SystemMessageConfig().setMode(SystemMessageMode.APPEND).setContent("Be concise in your responses."));
*
* var session = client.createSession(config).get();
* }</pre>
*
* @see com.github.copilot.sdk.CopilotClient#createSession(SessionConfig)
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SessionConfig {
private String sessionId;
private String model;
private List<ToolDefinition> tools;
private SystemMessageConfig systemMessage;
private List<String> availableTools;
private List<String> excludedTools;
private ProviderConfig provider;
private PermissionHandler onPermissionRequest;
private boolean streaming;
private Map<String, Object> mcpServers;
private List<CustomAgentConfig> customAgents;
/**
* Gets the custom session ID.
*
* @return the session ID, or {@code null} to generate automatically
*/
public String getSessionId() {
return sessionId;
}
/**
* Sets a custom session ID.
* <p>
* If not provided, a unique session ID will be generated automatically.
*
* @param sessionId
* the custom session ID
* @return this config instance for method chaining
*/
public SessionConfig setSessionId(String sessionId) {
this.sessionId = sessionId;
return this;
}
/**
* Gets the AI model to use.
*
* @return the model name
*/
public String getModel() {
return model;
}
/**
* Sets the AI model to use for this session.
* <p>
* Examples: "gpt-5", "claude-sonnet-4.5", "o3-mini".
*
* @param model
* the model name
* @return this config instance for method chaining
*/
public SessionConfig setModel(String model) {
this.model = model;
return this;
}
/**
* Gets the custom tools for this session.
*
* @return the list of tool definitions
*/
public List<ToolDefinition> getTools() {
return tools;
}
/**
* Sets custom tools that the assistant can invoke during the session.
* <p>
* Tools allow the assistant to call back into your application to perform
* actions or retrieve information.
*
* @param tools
* the list of tool definitions
* @return this config instance for method chaining
* @see ToolDefinition
*/
public SessionConfig setTools(List<ToolDefinition> tools) {
this.tools = tools;
return this;
}
/**
* Gets the system message configuration.
*
* @return the system message config
*/
public SystemMessageConfig getSystemMessage() {
return systemMessage;
}
/**
* Sets the system message configuration.
* <p>
* The system message controls the behavior and personality of the assistant.
* Use {@link com.github.copilot.sdk.SystemMessageMode#APPEND} to add
* instructions while preserving default behavior, or
* {@link com.github.copilot.sdk.SystemMessageMode#REPLACE} to fully customize.
*
* @param systemMessage
* the system message configuration
* @return this config instance for method chaining
* @see SystemMessageConfig
*/
public SessionConfig setSystemMessage(SystemMessageConfig systemMessage) {
this.systemMessage = systemMessage;
return this;
}
/**
* Gets the list of allowed tool names.
*
* @return the list of available tool names
*/
public List<String> getAvailableTools() {
return availableTools;
}
/**
* Sets the list of tool names that are allowed in this session.
* <p>
* When specified, only tools in this list will be available to the assistant.
*
* @param availableTools
* the list of allowed tool names
* @return this config instance for method chaining
*/
public SessionConfig setAvailableTools(List<String> availableTools) {
this.availableTools = availableTools;
return this;
}
/**
* Gets the list of excluded tool names.
*
* @return the list of excluded tool names
*/
public List<String> getExcludedTools() {
return excludedTools;
}
/**
* Sets the list of tool names to exclude from this session.
* <p>
* Tools in this list will not be available to the assistant.
*
* @param excludedTools
* the list of tool names to exclude
* @return this config instance for method chaining
*/
public SessionConfig setExcludedTools(List<String> excludedTools) {
this.excludedTools = excludedTools;
return this;
}
/**
* Gets the custom API provider configuration.
*
* @return the provider configuration
*/
public ProviderConfig getProvider() {
return provider;
}
/**
* Sets a custom API provider for BYOK (Bring Your Own Key) scenarios.
* <p>
* This allows using your own OpenAI, Azure OpenAI, or other compatible API
* endpoints instead of the default Copilot backend.
*
* @param provider
* the provider configuration
* @return this config instance for method chaining
* @see ProviderConfig
*/
public SessionConfig setProvider(ProviderConfig provider) {
this.provider = provider;
return this;
}
/**
* Gets the permission request handler.
*
* @return the permission handler
*/
public PermissionHandler getOnPermissionRequest() {
return onPermissionRequest;
}
/**
* Sets a handler for permission requests from the assistant.
* <p>
* When the assistant needs permission to perform certain actions, this handler
* will be invoked to approve or deny the request.
*
* @param onPermissionRequest
* the permission handler
* @return this config instance for method chaining
* @see PermissionHandler
*/
public SessionConfig setOnPermissionRequest(PermissionHandler onPermissionRequest) {
this.onPermissionRequest = onPermissionRequest;
return this;
}
/**
* Returns whether streaming is enabled.
*
* @return {@code true} if streaming is enabled
*/
public boolean isStreaming() {
return streaming;
}
/**
* Sets whether to enable streaming of response chunks.
* <p>
* When enabled, the session will emit {@code AssistantMessageDeltaEvent} events
* as the response is generated, allowing for real-time display of partial
* responses.
*
* @param streaming
* {@code true} to enable streaming
* @return this config instance for method chaining
*/
public SessionConfig setStreaming(boolean streaming) {
this.streaming = streaming;
return this;
}
/**
* Gets the MCP server configurations.
*
* @return the MCP servers map
*/
public Map<String, Object> getMcpServers() {
return mcpServers;
}
/**
* Sets MCP (Model Context Protocol) server configurations.
* <p>
* MCP servers extend the assistant's capabilities by providing additional
* context sources and tools.
*
* @param mcpServers
* the MCP servers configuration map
* @return this config instance for method chaining
*/
public SessionConfig setMcpServers(Map<String, Object> mcpServers) {
this.mcpServers = mcpServers;
return this;
}
/**
* Gets the custom agent configurations.
*
* @return the list of custom agent configurations
*/
public List<CustomAgentConfig> getCustomAgents() {
return customAgents;
}
/**
* Sets custom agent configurations.
* <p>
* Custom agents allow extending the assistant with specialized behaviors and
* capabilities.
*
* @param customAgents
* the list of custom agent configurations
* @return this config instance for method chaining
* @see CustomAgentConfig
*/
public SessionConfig setCustomAgents(List<CustomAgentConfig> customAgents) {
this.customAgents = customAgents;
return this;
}
}