forked from github/copilot-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResumeSessionConfig.java
More file actions
650 lines (595 loc) · 19.5 KB
/
ResumeSessionConfig.java
File metadata and controls
650 lines (595 loc) · 19.5 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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package com.github.copilot.sdk.json;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.github.copilot.sdk.generated.SessionEvent;
/**
* Configuration for resuming an existing Copilot session.
* <p>
* This class provides options for configuring a resumed session, including tool
* registration, provider configuration, and streaming. All setter methods
* return {@code this} for method chaining.
*
* <h2>Example Usage</h2>
*
* <pre>{@code
* var config = new ResumeSessionConfig().setStreaming(true).setTools(List.of(myTool));
*
* var session = client.resumeSession(sessionId, config).get();
* }</pre>
*
* @see com.github.copilot.sdk.CopilotClient#resumeSession(String,
* ResumeSessionConfig)
* @since 1.0.0
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResumeSessionConfig {
private String clientName;
private String model;
private List<ToolDefinition> tools;
private SystemMessageConfig systemMessage;
private List<String> availableTools;
private List<String> excludedTools;
private ProviderConfig provider;
private String reasoningEffort;
private PermissionHandler onPermissionRequest;
private UserInputHandler onUserInputRequest;
private SessionHooks hooks;
private String workingDirectory;
private String configDir;
private boolean disableResume;
private boolean streaming;
private Map<String, Object> mcpServers;
private List<CustomAgentConfig> customAgents;
private String agent;
private List<String> skillDirectories;
private List<String> disabledSkills;
private InfiniteSessionConfig infiniteSessions;
private Consumer<SessionEvent> onEvent;
private List<CommandDefinition> commands;
private ElicitationHandler onElicitationRequest;
/**
* Gets the AI model to use.
*
* @return the model name
*/
public String getModel() {
return model;
}
/**
* Sets the AI model to use for the resumed session.
* <p>
* Can change the model when resuming an existing session.
*
* @param model
* the model name
* @return this config for method chaining
*/
public ResumeSessionConfig setModel(String model) {
this.model = model;
return this;
}
/**
* Gets the client name used to identify the application using the SDK.
*
* @return the client name, or {@code null} if not set
*/
public String getClientName() {
return clientName;
}
/**
* Sets the client name to identify the application using the SDK.
* <p>
* This value is included in the User-Agent header for API requests.
*
* @param clientName
* the client name
* @return this config for method chaining
*/
public ResumeSessionConfig setClientName(String clientName) {
this.clientName = clientName;
return this;
}
/**
* Gets the custom tools for this session.
*
* @return the list of tool definitions
*/
public List<ToolDefinition> getTools() {
return tools == null ? null : Collections.unmodifiableList(tools);
}
/**
* Sets custom tools that the assistant can invoke during the session.
*
* @param tools
* the list of tool definitions
* @return this config for method chaining
* @see ToolDefinition
*/
public ResumeSessionConfig 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.
*
* @param systemMessage
* the system message configuration
* @return this config for method chaining
* @see SystemMessageConfig
*/
public ResumeSessionConfig 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 == null ? null : Collections.unmodifiableList(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.
* Takes precedence over excluded tools.
*
* @param availableTools
* the list of allowed tool names
* @return this config for method chaining
*/
public ResumeSessionConfig 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 == null ? null : Collections.unmodifiableList(excludedTools);
}
/**
* Sets the list of tool names to exclude from this session.
* <p>
* Tools in this list will not be available to the assistant. Ignored if
* available tools is specified.
*
* @param excludedTools
* the list of tool names to exclude
* @return this config for method chaining
*/
public ResumeSessionConfig 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 scenarios.
*
* @param provider
* the provider configuration
* @return this config for method chaining
* @see ProviderConfig
*/
public ResumeSessionConfig setProvider(ProviderConfig provider) {
this.provider = provider;
return this;
}
/**
* Gets the reasoning effort level.
*
* @return the reasoning effort level ("low", "medium", "high", or "xhigh")
*/
public String getReasoningEffort() {
return reasoningEffort;
}
/**
* Sets the reasoning effort level for models that support it.
* <p>
* Valid values: "low", "medium", "high", "xhigh".
*
* @param reasoningEffort
* the reasoning effort level
* @return this config for method chaining
*/
public ResumeSessionConfig setReasoningEffort(String reasoningEffort) {
this.reasoningEffort = reasoningEffort;
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.
*
* @param onPermissionRequest
* the permission handler
* @return this config for method chaining
* @see PermissionHandler
*/
public ResumeSessionConfig setOnPermissionRequest(PermissionHandler onPermissionRequest) {
this.onPermissionRequest = onPermissionRequest;
return this;
}
/**
* Gets the user input request handler.
*
* @return the user input handler
*/
public UserInputHandler getOnUserInputRequest() {
return onUserInputRequest;
}
/**
* Sets a handler for user input requests from the agent.
*
* @param onUserInputRequest
* the user input handler
* @return this config for method chaining
* @see UserInputHandler
*/
public ResumeSessionConfig setOnUserInputRequest(UserInputHandler onUserInputRequest) {
this.onUserInputRequest = onUserInputRequest;
return this;
}
/**
* Gets the hook handlers configuration.
*
* @return the session hooks
*/
public SessionHooks getHooks() {
return hooks;
}
/**
* Sets hook handlers for session lifecycle events.
*
* @param hooks
* the hooks configuration
* @return this config for method chaining
* @see SessionHooks
*/
public ResumeSessionConfig setHooks(SessionHooks hooks) {
this.hooks = hooks;
return this;
}
/**
* Gets the working directory for the session.
*
* @return the working directory path
*/
public String getWorkingDirectory() {
return workingDirectory;
}
/**
* Sets the working directory for the session.
*
* @param workingDirectory
* the working directory path
* @return this config for method chaining
*/
public ResumeSessionConfig setWorkingDirectory(String workingDirectory) {
this.workingDirectory = workingDirectory;
return this;
}
/**
* Gets the configuration directory path.
*
* @return the configuration directory path
*/
public String getConfigDir() {
return configDir;
}
/**
* Sets the configuration directory path.
* <p>
* Override the default configuration directory location.
*
* @param configDir
* the configuration directory path
* @return this config for method chaining
*/
public ResumeSessionConfig setConfigDir(String configDir) {
this.configDir = configDir;
return this;
}
/**
* Returns whether the resume event is disabled.
*
* @return {@code true} if the session.resume event is suppressed
*/
public boolean isDisableResume() {
return disableResume;
}
/**
* Sets whether to disable the session.resume event.
* <p>
* When true, the session.resume event is not emitted.
*
* @param disableResume
* {@code true} to suppress the resume event
* @return this config for method chaining
*/
public ResumeSessionConfig setDisableResume(boolean disableResume) {
this.disableResume = disableResume;
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.
*
* @param streaming
* {@code true} to enable streaming
* @return this config for method chaining
*/
public ResumeSessionConfig 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 == null ? null : Collections.unmodifiableMap(mcpServers);
}
/**
* Sets MCP (Model Context Protocol) server configurations.
*
* @param mcpServers
* the MCP servers configuration map
* @return this config for method chaining
*/
public ResumeSessionConfig 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 == null ? null : Collections.unmodifiableList(customAgents);
}
/**
* Sets custom agent configurations.
*
* @param customAgents
* the list of custom agent configurations
* @return this config for method chaining
* @see CustomAgentConfig
*/
public ResumeSessionConfig setCustomAgents(List<CustomAgentConfig> customAgents) {
this.customAgents = customAgents;
return this;
}
/**
* Gets the name of the custom agent to activate at session start.
*
* @return the agent name, or {@code null} if not set
*/
public String getAgent() {
return agent;
}
/**
* Sets the name of the custom agent to activate when the session starts.
* <p>
* Must match the name of one of the agents in {@link #setCustomAgents(List)}.
*
* @param agent
* the agent name to pre-select
* @return this config for method chaining
*/
public ResumeSessionConfig setAgent(String agent) {
this.agent = agent;
return this;
}
/**
* Gets the skill directories.
*
* @return the list of skill directory paths
*/
public List<String> getSkillDirectories() {
return skillDirectories == null ? null : Collections.unmodifiableList(skillDirectories);
}
/**
* Sets directories containing skill definitions.
*
* @param skillDirectories
* the list of skill directory paths
* @return this config for method chaining
*/
public ResumeSessionConfig setSkillDirectories(List<String> skillDirectories) {
this.skillDirectories = skillDirectories;
return this;
}
/**
* Gets the disabled skills.
*
* @return the list of disabled skill names
*/
public List<String> getDisabledSkills() {
return disabledSkills == null ? null : Collections.unmodifiableList(disabledSkills);
}
/**
* Sets skills that should be disabled for this session.
*
* @param disabledSkills
* the list of skill names to disable
* @return this config for method chaining
*/
public ResumeSessionConfig setDisabledSkills(List<String> disabledSkills) {
this.disabledSkills = disabledSkills;
return this;
}
/**
* Gets the infinite session configuration.
*
* @return the infinite session config
*/
public InfiniteSessionConfig getInfiniteSessions() {
return infiniteSessions;
}
/**
* Sets the infinite session configuration for persistent workspaces and
* automatic compaction.
*
* @param infiniteSessions
* the infinite session configuration
* @return this config for method chaining
* @see InfiniteSessionConfig
*/
public ResumeSessionConfig setInfiniteSessions(InfiniteSessionConfig infiniteSessions) {
this.infiniteSessions = infiniteSessions;
return this;
}
/**
* Gets the event handler registered before the session.resume RPC is issued.
*
* @return the event handler, or {@code null} if not set
*/
public Consumer<SessionEvent> getOnEvent() {
return onEvent;
}
/**
* Sets an event handler that is registered on the session before the
* {@code session.resume} RPC is issued.
* <p>
* Equivalent to calling
* {@link com.github.copilot.sdk.CopilotSession#on(Consumer)} immediately after
* resumption, but executes earlier in the lifecycle so no events are missed.
*
* @param onEvent
* the event handler to register before session resumption
* @return this config for method chaining
*/
public ResumeSessionConfig setOnEvent(Consumer<SessionEvent> onEvent) {
this.onEvent = onEvent;
return this;
}
/**
* Gets the slash commands registered for this session.
*
* @return the list of command definitions, or {@code null}
*/
public List<CommandDefinition> getCommands() {
return commands == null ? null : Collections.unmodifiableList(commands);
}
/**
* Sets slash commands registered for this session.
* <p>
* When the CLI has a TUI, each command appears as {@code /name} for the user to
* invoke. The handler is called when the user executes the command.
*
* @param commands
* the list of command definitions
* @return this config for method chaining
* @see CommandDefinition
*/
public ResumeSessionConfig setCommands(List<CommandDefinition> commands) {
this.commands = commands;
return this;
}
/**
* Gets the elicitation request handler.
*
* @return the elicitation handler, or {@code null}
*/
public ElicitationHandler getOnElicitationRequest() {
return onElicitationRequest;
}
/**
* Sets a handler for elicitation requests from the server or MCP tools.
* <p>
* When provided, the server will route elicitation requests to this handler and
* report elicitation as a supported capability.
*
* @param onElicitationRequest
* the elicitation handler
* @return this config for method chaining
* @see ElicitationHandler
*/
public ResumeSessionConfig setOnElicitationRequest(ElicitationHandler onElicitationRequest) {
this.onElicitationRequest = onElicitationRequest;
return this;
}
/**
* Creates a shallow clone of this {@code ResumeSessionConfig} instance.
* <p>
* Mutable collection properties are copied into new collection instances so
* that modifications to those collections on the clone do not affect the
* original. Other reference-type properties (like provider configuration,
* system messages, hooks, infinite session configuration, and handlers) are not
* deep-cloned; the original and the clone will share those objects.
*
* @return a clone of this config instance
*/
@Override
public ResumeSessionConfig clone() {
ResumeSessionConfig copy = new ResumeSessionConfig();
copy.clientName = this.clientName;
copy.model = this.model;
copy.tools = this.tools != null ? new ArrayList<>(this.tools) : null;
copy.systemMessage = this.systemMessage;
copy.availableTools = this.availableTools != null ? new ArrayList<>(this.availableTools) : null;
copy.excludedTools = this.excludedTools != null ? new ArrayList<>(this.excludedTools) : null;
copy.provider = this.provider;
copy.reasoningEffort = this.reasoningEffort;
copy.onPermissionRequest = this.onPermissionRequest;
copy.onUserInputRequest = this.onUserInputRequest;
copy.hooks = this.hooks;
copy.workingDirectory = this.workingDirectory;
copy.configDir = this.configDir;
copy.disableResume = this.disableResume;
copy.streaming = this.streaming;
copy.mcpServers = this.mcpServers != null ? new java.util.HashMap<>(this.mcpServers) : null;
copy.customAgents = this.customAgents != null ? new ArrayList<>(this.customAgents) : null;
copy.agent = this.agent;
copy.skillDirectories = this.skillDirectories != null ? new ArrayList<>(this.skillDirectories) : null;
copy.disabledSkills = this.disabledSkills != null ? new ArrayList<>(this.disabledSkills) : null;
copy.infiniteSessions = this.infiniteSessions;
copy.onEvent = this.onEvent;
copy.commands = this.commands != null ? new ArrayList<>(this.commands) : null;
copy.onElicitationRequest = this.onElicitationRequest;
return copy;
}
}